]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.7.6-201302061907.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.7.6-201302061907.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index 74c25c8..deadba2 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38 -.*
39 +.[^g]*
40 +.gen*
41 .*.d
42 .mm
43 53c700_d.h
44 @@ -69,6 +75,7 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48 +PERF*
49 SCCS
50 System.map*
51 TAGS
52 @@ -80,6 +87,7 @@ aic7*seq.h*
53 aicasm
54 aicdb.h*
55 altivec*.c
56 +ashldi3.S
57 asm-offsets.h
58 asm_offsets.h
59 autoconf.h*
60 @@ -92,19 +100,24 @@ bounds.h
61 bsetup
62 btfixupprep
63 build
64 +builtin-policy.h
65 bvmlinux
66 bzImage*
67 capability_names.h
68 capflags.c
69 classlist.h*
70 +clut_vga16.c
71 +common-cmds.h
72 comp*.log
73 compile.h*
74 conf
75 config
76 config-*
77 config_data.h*
78 +config.c
79 config.mak
80 config.mak.autogen
81 +config.tmp
82 conmakehash
83 consolemap_deftbl.c*
84 cpustr.h
85 @@ -115,9 +128,11 @@ devlist.h*
86 dnotify_test
87 docproc
88 dslm
89 +dtc-lexer.lex.c
90 elf2ecoff
91 elfconfig.h*
92 evergreen_reg_safe.h
93 +exception_policy.conf
94 fixdep
95 flask.h
96 fore200e_mkfirm
97 @@ -125,12 +140,15 @@ fore200e_pca_fw.c*
98 gconf
99 gconf.glade.h
100 gen-devlist
101 +gen-kdb_cmds.c
102 gen_crc32table
103 gen_init_cpio
104 generated
105 genheaders
106 genksyms
107 *_gray256.c
108 +hash
109 +hid-example
110 hpet_example
111 hugepage-mmap
112 hugepage-shm
113 @@ -145,14 +163,14 @@ int32.c
114 int4.c
115 int8.c
116 kallsyms
117 -kconfig
118 +kern_constants.h
119 keywords.c
120 ksym.c*
121 ksym.h*
122 kxgettext
123 lex.c
124 lex.*.c
125 -linux
126 +lib1funcs.S
127 logo_*.c
128 logo_*_clut224.c
129 logo_*_mono.c
130 @@ -162,14 +180,15 @@ mach-types.h
131 machtypes.h
132 map
133 map_hugetlb
134 -media
135 mconf
136 +mdp
137 miboot*
138 mk_elfconfig
139 mkboot
140 mkbugboot
141 mkcpustr
142 mkdep
143 +mkpiggy
144 mkprep
145 mkregtable
146 mktables
147 @@ -186,6 +205,8 @@ oui.c*
148 page-types
149 parse.c
150 parse.h
151 +parse-events*
152 +pasyms.h
153 patches*
154 pca200e.bin
155 pca200e_ecd.bin2
156 @@ -195,6 +216,7 @@ perf-archive
157 piggyback
158 piggy.gzip
159 piggy.S
160 +pmu-*
161 pnmtologo
162 ppc_defs.h*
163 pss_boot.h
164 @@ -204,7 +226,10 @@ r200_reg_safe.h
165 r300_reg_safe.h
166 r420_reg_safe.h
167 r600_reg_safe.h
168 +realmode.lds
169 +realmode.relocs
170 recordmcount
171 +regdb.c
172 relocs
173 rlim_names.h
174 rn50_reg_safe.h
175 @@ -214,8 +239,11 @@ series
176 setup
177 setup.bin
178 setup.elf
179 +size_overflow_hash.h
180 sImage
181 +slabinfo
182 sm_tbl*
183 +sortextable
184 split-include
185 syscalltab.h
186 tables.c
187 @@ -225,6 +253,7 @@ tftpboot.img
188 timeconst.h
189 times.h*
190 trix_boot.h
191 +user_constants.h
192 utsrelease.h*
193 vdso-syms.lds
194 vdso.lds
195 @@ -236,13 +265,17 @@ vdso32.lds
196 vdso32.so.dbg
197 vdso64.lds
198 vdso64.so.dbg
199 +vdsox32.lds
200 +vdsox32-syms.lds
201 version.h*
202 vmImage
203 vmlinux
204 vmlinux-*
205 vmlinux.aout
206 vmlinux.bin.all
207 +vmlinux.bin.bz2
208 vmlinux.lds
209 +vmlinux.relocs
210 vmlinuz
211 voffset.h
212 vsyscall.lds
213 @@ -250,9 +283,11 @@ vsyscall_32.lds
214 wanxlfw.inc
215 uImage
216 unifdef
217 +utsrelease.h
218 wakeup.bin
219 wakeup.elf
220 wakeup.lds
221 zImage*
222 zconf.hash.c
223 +zconf.lex.c
224 zoffset.h
225 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
226 index 9776f06..18b1856 100644
227 --- a/Documentation/kernel-parameters.txt
228 +++ b/Documentation/kernel-parameters.txt
229 @@ -905,6 +905,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
230 gpt [EFI] Forces disk with valid GPT signature but
231 invalid Protective MBR to be treated as GPT.
232
233 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
234 + ignore grsecurity's /proc restrictions
235 +
236 hashdist= [KNL,NUMA] Large hashes allocated during boot
237 are distributed across NUMA nodes. Defaults on
238 for 64-bit NUMA, off otherwise.
239 @@ -2082,6 +2085,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
240 the specified number of seconds. This is to be used if
241 your oopses keep scrolling off the screen.
242
243 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
244 + virtualization environments that don't cope well with the
245 + expand down segment used by UDEREF on X86-32 or the frequent
246 + page table updates on X86-64.
247 +
248 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
249 +
250 pcbit= [HW,ISDN]
251
252 pcd. [PARIDE]
253 diff --git a/Makefile b/Makefile
254 index b6de2ea..5ba90ee 100644
255 --- a/Makefile
256 +++ b/Makefile
257 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
258
259 HOSTCC = gcc
260 HOSTCXX = g++
261 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
262 -HOSTCXXFLAGS = -O2
263 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
264 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
265 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
266
267 # Decide whether to build built-in, modular, or both.
268 # Normally, just do built-in.
269 @@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
270 # Rules shared between *config targets and build targets
271
272 # Basic helpers built in scripts/
273 -PHONY += scripts_basic
274 -scripts_basic:
275 +PHONY += scripts_basic gcc-plugins
276 +scripts_basic: gcc-plugins
277 $(Q)$(MAKE) $(build)=scripts/basic
278 $(Q)rm -f .tmp_quiet_recordmcount
279
280 @@ -575,6 +576,60 @@ else
281 KBUILD_CFLAGS += -O2
282 endif
283
284 +ifndef DISABLE_PAX_PLUGINS
285 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
286 +ifneq ($(PLUGINCC),)
287 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
288 +ifndef CONFIG_UML
289 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
290 +endif
291 +endif
292 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
293 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
294 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
295 +endif
296 +ifdef CONFIG_KALLOCSTAT_PLUGIN
297 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
298 +endif
299 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
300 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
301 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
302 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
303 +endif
304 +ifdef CONFIG_CHECKER_PLUGIN
305 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
306 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
307 +endif
308 +endif
309 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
310 +ifdef CONFIG_PAX_SIZE_OVERFLOW
311 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
312 +endif
313 +ifdef CONFIG_PAX_LATENT_ENTROPY
314 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
315 +endif
316 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
317 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
318 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
319 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
320 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
321 +ifeq ($(KBUILD_EXTMOD),)
322 +gcc-plugins:
323 + $(Q)$(MAKE) $(build)=tools/gcc
324 +else
325 +gcc-plugins: ;
326 +endif
327 +else
328 +gcc-plugins:
329 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
330 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
331 +else
332 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
333 +endif
334 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
335 +endif
336 +endif
337 +
338 include $(srctree)/arch/$(SRCARCH)/Makefile
339
340 ifdef CONFIG_READABLE_ASM
341 @@ -731,7 +786,7 @@ export mod_sign_cmd
342
343
344 ifeq ($(KBUILD_EXTMOD),)
345 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
346 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
347
348 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
349 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
350 @@ -778,6 +833,8 @@ endif
351
352 # The actual objects are generated when descending,
353 # make sure no implicit rule kicks in
354 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
355 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
356 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
357
358 # Handle descending into subdirectories listed in $(vmlinux-dirs)
359 @@ -787,7 +844,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
360 # Error messages still appears in the original language
361
362 PHONY += $(vmlinux-dirs)
363 -$(vmlinux-dirs): prepare scripts
364 +$(vmlinux-dirs): gcc-plugins prepare scripts
365 $(Q)$(MAKE) $(build)=$@
366
367 # Store (new) KERNELRELASE string in include/config/kernel.release
368 @@ -831,6 +888,7 @@ prepare0: archprepare FORCE
369 $(Q)$(MAKE) $(build)=.
370
371 # All the preparing..
372 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
373 prepare: prepare0
374
375 # Generate some files
376 @@ -938,6 +996,8 @@ all: modules
377 # using awk while concatenating to the final file.
378
379 PHONY += modules
380 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
381 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
382 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
383 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
384 @$(kecho) ' Building modules, stage 2.';
385 @@ -953,7 +1013,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
386
387 # Target to prepare building external modules
388 PHONY += modules_prepare
389 -modules_prepare: prepare scripts
390 +modules_prepare: gcc-plugins prepare scripts
391
392 # Target to install modules
393 PHONY += modules_install
394 @@ -1013,7 +1073,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
395 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
396 signing_key.priv signing_key.x509 x509.genkey \
397 extra_certificates signing_key.x509.keyid \
398 - signing_key.x509.signer
399 + signing_key.x509.signer tools/gcc/size_overflow_hash.h
400
401 # clean - Delete most, but leave enough to build external modules
402 #
403 @@ -1053,6 +1113,7 @@ distclean: mrproper
404 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
405 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
406 -o -name '.*.rej' \
407 + -o -name '.*.rej' -o -name '*.so' \
408 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
409 -type f -print | xargs rm -f
410
411 @@ -1213,6 +1274,8 @@ PHONY += $(module-dirs) modules
412 $(module-dirs): crmodverdir $(objtree)/Module.symvers
413 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
414
415 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(module-dirs)
418 @$(kecho) ' Building modules, stage 2.';
419 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
420 @@ -1349,17 +1412,21 @@ else
421 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
422 endif
423
424 -%.s: %.c prepare scripts FORCE
425 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427 +%.s: %.c gcc-plugins prepare scripts FORCE
428 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
429 %.i: %.c prepare scripts FORCE
430 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
431 -%.o: %.c prepare scripts FORCE
432 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434 +%.o: %.c gcc-plugins prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436 %.lst: %.c prepare scripts FORCE
437 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
438 -%.s: %.S prepare scripts FORCE
439 +%.s: %.S gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 -%.o: %.S prepare scripts FORCE
442 +%.o: %.S gcc-plugins prepare scripts FORCE
443 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
444 %.symtypes: %.c prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 @@ -1369,11 +1436,15 @@ endif
447 $(cmd_crmodverdir)
448 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
449 $(build)=$(build-dir)
450 -%/: prepare scripts FORCE
451 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
452 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
453 +%/: gcc-plugins prepare scripts FORCE
454 $(cmd_crmodverdir)
455 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
456 $(build)=$(build-dir)
457 -%.ko: prepare scripts FORCE
458 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
459 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
460 +%.ko: gcc-plugins prepare scripts FORCE
461 $(cmd_crmodverdir)
462 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
463 $(build)=$(build-dir) $(@:.ko=.o)
464 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
465 index c2cbe4f..f7264b4 100644
466 --- a/arch/alpha/include/asm/atomic.h
467 +++ b/arch/alpha/include/asm/atomic.h
468 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
469 #define atomic_dec(v) atomic_sub(1,(v))
470 #define atomic64_dec(v) atomic64_sub(1,(v))
471
472 +#define atomic64_read_unchecked(v) atomic64_read(v)
473 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
474 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
475 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
476 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
477 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
478 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
479 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
480 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
481 +
482 #define smp_mb__before_atomic_dec() smp_mb()
483 #define smp_mb__after_atomic_dec() smp_mb()
484 #define smp_mb__before_atomic_inc() smp_mb()
485 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
486 index ad368a9..fbe0f25 100644
487 --- a/arch/alpha/include/asm/cache.h
488 +++ b/arch/alpha/include/asm/cache.h
489 @@ -4,19 +4,19 @@
490 #ifndef __ARCH_ALPHA_CACHE_H
491 #define __ARCH_ALPHA_CACHE_H
492
493 +#include <linux/const.h>
494
495 /* Bytes per L1 (data) cache line. */
496 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
497 -# define L1_CACHE_BYTES 64
498 # define L1_CACHE_SHIFT 6
499 #else
500 /* Both EV4 and EV5 are write-through, read-allocate,
501 direct-mapped, physical.
502 */
503 -# define L1_CACHE_BYTES 32
504 # define L1_CACHE_SHIFT 5
505 #endif
506
507 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
508 #define SMP_CACHE_BYTES L1_CACHE_BYTES
509
510 #endif
511 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
512 index 968d999..d36b2df 100644
513 --- a/arch/alpha/include/asm/elf.h
514 +++ b/arch/alpha/include/asm/elf.h
515 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
516
517 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
518
519 +#ifdef CONFIG_PAX_ASLR
520 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
521 +
522 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
523 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
524 +#endif
525 +
526 /* $0 is set by ld.so to a pointer to a function which might be
527 registered using atexit. This provides a mean for the dynamic
528 linker to call DT_FINI functions for shared libraries that have
529 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
530 index bc2a0da..8ad11ee 100644
531 --- a/arch/alpha/include/asm/pgalloc.h
532 +++ b/arch/alpha/include/asm/pgalloc.h
533 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
534 pgd_set(pgd, pmd);
535 }
536
537 +static inline void
538 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539 +{
540 + pgd_populate(mm, pgd, pmd);
541 +}
542 +
543 extern pgd_t *pgd_alloc(struct mm_struct *mm);
544
545 static inline void
546 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
547 index 81a4342..348b927 100644
548 --- a/arch/alpha/include/asm/pgtable.h
549 +++ b/arch/alpha/include/asm/pgtable.h
550 @@ -102,6 +102,17 @@ struct vm_area_struct;
551 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
552 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
553 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
554 +
555 +#ifdef CONFIG_PAX_PAGEEXEC
556 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
557 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
558 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
559 +#else
560 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
561 +# define PAGE_COPY_NOEXEC PAGE_COPY
562 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
563 +#endif
564 +
565 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
566
567 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
568 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
569 index 2fd00b7..cfd5069 100644
570 --- a/arch/alpha/kernel/module.c
571 +++ b/arch/alpha/kernel/module.c
572 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
573
574 /* The small sections were sorted to the end of the segment.
575 The following should definitely cover them. */
576 - gp = (u64)me->module_core + me->core_size - 0x8000;
577 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
578 got = sechdrs[me->arch.gotsecindex].sh_addr;
579
580 for (i = 0; i < n; i++) {
581 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
582 index 14db93e..47bed62 100644
583 --- a/arch/alpha/kernel/osf_sys.c
584 +++ b/arch/alpha/kernel/osf_sys.c
585 @@ -1295,16 +1295,16 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
586 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
587
588 static unsigned long
589 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
590 - unsigned long limit)
591 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
592 + unsigned long limit, unsigned long flags)
593 {
594 struct vm_area_struct *vma = find_vma(current->mm, addr);
595 -
596 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
597 while (1) {
598 /* At this point: (!vma || addr < vma->vm_end). */
599 if (limit - len < addr)
600 return -ENOMEM;
601 - if (!vma || addr + len <= vma->vm_start)
602 + if (check_heap_stack_gap(vma, addr, len, offset))
603 return addr;
604 addr = vma->vm_end;
605 vma = vma->vm_next;
606 @@ -1340,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
607 merely specific addresses, but regions of memory -- perhaps
608 this feature should be incorporated into all ports? */
609
610 +#ifdef CONFIG_PAX_RANDMMAP
611 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
612 +#endif
613 +
614 if (addr) {
615 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
616 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
617 if (addr != (unsigned long) -ENOMEM)
618 return addr;
619 }
620
621 /* Next, try allocating at TASK_UNMAPPED_BASE. */
622 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
623 - len, limit);
624 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
625 +
626 if (addr != (unsigned long) -ENOMEM)
627 return addr;
628
629 /* Finally, try allocating in low memory. */
630 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
631 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
632
633 return addr;
634 }
635 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
636 index 0c4132d..88f0d53 100644
637 --- a/arch/alpha/mm/fault.c
638 +++ b/arch/alpha/mm/fault.c
639 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
640 __reload_thread(pcb);
641 }
642
643 +#ifdef CONFIG_PAX_PAGEEXEC
644 +/*
645 + * PaX: decide what to do with offenders (regs->pc = fault address)
646 + *
647 + * returns 1 when task should be killed
648 + * 2 when patched PLT trampoline was detected
649 + * 3 when unpatched PLT trampoline was detected
650 + */
651 +static int pax_handle_fetch_fault(struct pt_regs *regs)
652 +{
653 +
654 +#ifdef CONFIG_PAX_EMUPLT
655 + int err;
656 +
657 + do { /* PaX: patched PLT emulation #1 */
658 + unsigned int ldah, ldq, jmp;
659 +
660 + err = get_user(ldah, (unsigned int *)regs->pc);
661 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
662 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
663 +
664 + if (err)
665 + break;
666 +
667 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
668 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
669 + jmp == 0x6BFB0000U)
670 + {
671 + unsigned long r27, addr;
672 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
673 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
674 +
675 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
676 + err = get_user(r27, (unsigned long *)addr);
677 + if (err)
678 + break;
679 +
680 + regs->r27 = r27;
681 + regs->pc = r27;
682 + return 2;
683 + }
684 + } while (0);
685 +
686 + do { /* PaX: patched PLT emulation #2 */
687 + unsigned int ldah, lda, br;
688 +
689 + err = get_user(ldah, (unsigned int *)regs->pc);
690 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
691 + err |= get_user(br, (unsigned int *)(regs->pc+8));
692 +
693 + if (err)
694 + break;
695 +
696 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
697 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
698 + (br & 0xFFE00000U) == 0xC3E00000U)
699 + {
700 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
701 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
702 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
703 +
704 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
705 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
706 + return 2;
707 + }
708 + } while (0);
709 +
710 + do { /* PaX: unpatched PLT emulation */
711 + unsigned int br;
712 +
713 + err = get_user(br, (unsigned int *)regs->pc);
714 +
715 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
716 + unsigned int br2, ldq, nop, jmp;
717 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
718 +
719 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
720 + err = get_user(br2, (unsigned int *)addr);
721 + err |= get_user(ldq, (unsigned int *)(addr+4));
722 + err |= get_user(nop, (unsigned int *)(addr+8));
723 + err |= get_user(jmp, (unsigned int *)(addr+12));
724 + err |= get_user(resolver, (unsigned long *)(addr+16));
725 +
726 + if (err)
727 + break;
728 +
729 + if (br2 == 0xC3600000U &&
730 + ldq == 0xA77B000CU &&
731 + nop == 0x47FF041FU &&
732 + jmp == 0x6B7B0000U)
733 + {
734 + regs->r28 = regs->pc+4;
735 + regs->r27 = addr+16;
736 + regs->pc = resolver;
737 + return 3;
738 + }
739 + }
740 + } while (0);
741 +#endif
742 +
743 + return 1;
744 +}
745 +
746 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
747 +{
748 + unsigned long i;
749 +
750 + printk(KERN_ERR "PAX: bytes at PC: ");
751 + for (i = 0; i < 5; i++) {
752 + unsigned int c;
753 + if (get_user(c, (unsigned int *)pc+i))
754 + printk(KERN_CONT "???????? ");
755 + else
756 + printk(KERN_CONT "%08x ", c);
757 + }
758 + printk("\n");
759 +}
760 +#endif
761
762 /*
763 * This routine handles page faults. It determines the address,
764 @@ -133,8 +251,29 @@ retry:
765 good_area:
766 si_code = SEGV_ACCERR;
767 if (cause < 0) {
768 - if (!(vma->vm_flags & VM_EXEC))
769 + if (!(vma->vm_flags & VM_EXEC)) {
770 +
771 +#ifdef CONFIG_PAX_PAGEEXEC
772 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
773 + goto bad_area;
774 +
775 + up_read(&mm->mmap_sem);
776 + switch (pax_handle_fetch_fault(regs)) {
777 +
778 +#ifdef CONFIG_PAX_EMUPLT
779 + case 2:
780 + case 3:
781 + return;
782 +#endif
783 +
784 + }
785 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
786 + do_group_exit(SIGKILL);
787 +#else
788 goto bad_area;
789 +#endif
790 +
791 + }
792 } else if (!cause) {
793 /* Allow reads even for write-only mappings */
794 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
795 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
796 index c79f61f..9ac0642 100644
797 --- a/arch/arm/include/asm/atomic.h
798 +++ b/arch/arm/include/asm/atomic.h
799 @@ -17,17 +17,35 @@
800 #include <asm/barrier.h>
801 #include <asm/cmpxchg.h>
802
803 +#ifdef CONFIG_GENERIC_ATOMIC64
804 +#include <asm-generic/atomic64.h>
805 +#endif
806 +
807 #define ATOMIC_INIT(i) { (i) }
808
809 #ifdef __KERNEL__
810
811 +#define _ASM_EXTABLE(from, to) \
812 +" .pushsection __ex_table,\"a\"\n"\
813 +" .align 3\n" \
814 +" .long " #from ", " #to"\n" \
815 +" .popsection"
816 +
817 /*
818 * On ARM, ordinary assignment (str instruction) doesn't clear the local
819 * strex/ldrex monitor on some implementations. The reason we can use it for
820 * atomic_set() is the clrex or dummy strex done on every exception return.
821 */
822 #define atomic_read(v) (*(volatile int *)&(v)->counter)
823 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
824 +{
825 + return v->counter;
826 +}
827 #define atomic_set(v,i) (((v)->counter) = (i))
828 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
829 +{
830 + v->counter = i;
831 +}
832
833 #if __LINUX_ARM_ARCH__ >= 6
834
835 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
836 int result;
837
838 __asm__ __volatile__("@ atomic_add\n"
839 +"1: ldrex %1, [%3]\n"
840 +" adds %0, %1, %4\n"
841 +
842 +#ifdef CONFIG_PAX_REFCOUNT
843 +" bvc 3f\n"
844 +"2: bkpt 0xf103\n"
845 +"3:\n"
846 +#endif
847 +
848 +" strex %1, %0, [%3]\n"
849 +" teq %1, #0\n"
850 +" bne 1b"
851 +
852 +#ifdef CONFIG_PAX_REFCOUNT
853 +"\n4:\n"
854 + _ASM_EXTABLE(2b, 4b)
855 +#endif
856 +
857 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
858 + : "r" (&v->counter), "Ir" (i)
859 + : "cc");
860 +}
861 +
862 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
863 +{
864 + unsigned long tmp;
865 + int result;
866 +
867 + __asm__ __volatile__("@ atomic_add_unchecked\n"
868 "1: ldrex %0, [%3]\n"
869 " add %0, %0, %4\n"
870 " strex %1, %0, [%3]\n"
871 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
872 smp_mb();
873
874 __asm__ __volatile__("@ atomic_add_return\n"
875 +"1: ldrex %1, [%3]\n"
876 +" adds %0, %1, %4\n"
877 +
878 +#ifdef CONFIG_PAX_REFCOUNT
879 +" bvc 3f\n"
880 +" mov %0, %1\n"
881 +"2: bkpt 0xf103\n"
882 +"3:\n"
883 +#endif
884 +
885 +" strex %1, %0, [%3]\n"
886 +" teq %1, #0\n"
887 +" bne 1b"
888 +
889 +#ifdef CONFIG_PAX_REFCOUNT
890 +"\n4:\n"
891 + _ASM_EXTABLE(2b, 4b)
892 +#endif
893 +
894 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
895 + : "r" (&v->counter), "Ir" (i)
896 + : "cc");
897 +
898 + smp_mb();
899 +
900 + return result;
901 +}
902 +
903 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
904 +{
905 + unsigned long tmp;
906 + int result;
907 +
908 + smp_mb();
909 +
910 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
911 "1: ldrex %0, [%3]\n"
912 " add %0, %0, %4\n"
913 " strex %1, %0, [%3]\n"
914 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
915 int result;
916
917 __asm__ __volatile__("@ atomic_sub\n"
918 +"1: ldrex %1, [%3]\n"
919 +" subs %0, %1, %4\n"
920 +
921 +#ifdef CONFIG_PAX_REFCOUNT
922 +" bvc 3f\n"
923 +"2: bkpt 0xf103\n"
924 +"3:\n"
925 +#endif
926 +
927 +" strex %1, %0, [%3]\n"
928 +" teq %1, #0\n"
929 +" bne 1b"
930 +
931 +#ifdef CONFIG_PAX_REFCOUNT
932 +"\n4:\n"
933 + _ASM_EXTABLE(2b, 4b)
934 +#endif
935 +
936 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
937 + : "r" (&v->counter), "Ir" (i)
938 + : "cc");
939 +}
940 +
941 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
942 +{
943 + unsigned long tmp;
944 + int result;
945 +
946 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
947 "1: ldrex %0, [%3]\n"
948 " sub %0, %0, %4\n"
949 " strex %1, %0, [%3]\n"
950 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
951 smp_mb();
952
953 __asm__ __volatile__("@ atomic_sub_return\n"
954 -"1: ldrex %0, [%3]\n"
955 -" sub %0, %0, %4\n"
956 +"1: ldrex %1, [%3]\n"
957 +" subs %0, %1, %4\n"
958 +
959 +#ifdef CONFIG_PAX_REFCOUNT
960 +" bvc 3f\n"
961 +" mov %0, %1\n"
962 +"2: bkpt 0xf103\n"
963 +"3:\n"
964 +#endif
965 +
966 " strex %1, %0, [%3]\n"
967 " teq %1, #0\n"
968 " bne 1b"
969 +
970 +#ifdef CONFIG_PAX_REFCOUNT
971 +"\n4:\n"
972 + _ASM_EXTABLE(2b, 4b)
973 +#endif
974 +
975 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
976 : "r" (&v->counter), "Ir" (i)
977 : "cc");
978 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
979 return oldval;
980 }
981
982 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
983 +{
984 + unsigned long oldval, res;
985 +
986 + smp_mb();
987 +
988 + do {
989 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
990 + "ldrex %1, [%3]\n"
991 + "mov %0, #0\n"
992 + "teq %1, %4\n"
993 + "strexeq %0, %5, [%3]\n"
994 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
995 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
996 + : "cc");
997 + } while (res);
998 +
999 + smp_mb();
1000 +
1001 + return oldval;
1002 +}
1003 +
1004 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1005 {
1006 unsigned long tmp, tmp2;
1007 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1008
1009 return val;
1010 }
1011 +
1012 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1013 +{
1014 + return atomic_add_return(i, v);
1015 +}
1016 +
1017 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1018 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1019 +{
1020 + (void) atomic_add_return(i, v);
1021 +}
1022
1023 static inline int atomic_sub_return(int i, atomic_t *v)
1024 {
1025 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1026 return val;
1027 }
1028 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1029 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1030 +{
1031 + (void) atomic_sub_return(i, v);
1032 +}
1033
1034 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1035 {
1036 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1037 return ret;
1038 }
1039
1040 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1041 +{
1042 + return atomic_cmpxchg(v, old, new);
1043 +}
1044 +
1045 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1046 {
1047 unsigned long flags;
1048 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1049 #endif /* __LINUX_ARM_ARCH__ */
1050
1051 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1052 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1053 +{
1054 + return xchg(&v->counter, new);
1055 +}
1056
1057 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1058 {
1059 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1060 }
1061
1062 #define atomic_inc(v) atomic_add(1, v)
1063 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1064 +{
1065 + atomic_add_unchecked(1, v);
1066 +}
1067 #define atomic_dec(v) atomic_sub(1, v)
1068 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1069 +{
1070 + atomic_sub_unchecked(1, v);
1071 +}
1072
1073 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1074 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1075 +{
1076 + return atomic_add_return_unchecked(1, v) == 0;
1077 +}
1078 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1079 #define atomic_inc_return(v) (atomic_add_return(1, v))
1080 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1081 +{
1082 + return atomic_add_return_unchecked(1, v);
1083 +}
1084 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1085 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1086
1087 @@ -241,6 +428,14 @@ typedef struct {
1088 u64 __aligned(8) counter;
1089 } atomic64_t;
1090
1091 +#ifdef CONFIG_PAX_REFCOUNT
1092 +typedef struct {
1093 + u64 __aligned(8) counter;
1094 +} atomic64_unchecked_t;
1095 +#else
1096 +typedef atomic64_t atomic64_unchecked_t;
1097 +#endif
1098 +
1099 #define ATOMIC64_INIT(i) { (i) }
1100
1101 static inline u64 atomic64_read(const atomic64_t *v)
1102 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1103 return result;
1104 }
1105
1106 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1107 +{
1108 + u64 result;
1109 +
1110 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1111 +" ldrexd %0, %H0, [%1]"
1112 + : "=&r" (result)
1113 + : "r" (&v->counter), "Qo" (v->counter)
1114 + );
1115 +
1116 + return result;
1117 +}
1118 +
1119 static inline void atomic64_set(atomic64_t *v, u64 i)
1120 {
1121 u64 tmp;
1122 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1123 : "cc");
1124 }
1125
1126 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1127 +{
1128 + u64 tmp;
1129 +
1130 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1131 +"1: ldrexd %0, %H0, [%2]\n"
1132 +" strexd %0, %3, %H3, [%2]\n"
1133 +" teq %0, #0\n"
1134 +" bne 1b"
1135 + : "=&r" (tmp), "=Qo" (v->counter)
1136 + : "r" (&v->counter), "r" (i)
1137 + : "cc");
1138 +}
1139 +
1140 static inline void atomic64_add(u64 i, atomic64_t *v)
1141 {
1142 u64 result;
1143 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1144 __asm__ __volatile__("@ atomic64_add\n"
1145 "1: ldrexd %0, %H0, [%3]\n"
1146 " adds %0, %0, %4\n"
1147 +" adcs %H0, %H0, %H4\n"
1148 +
1149 +#ifdef CONFIG_PAX_REFCOUNT
1150 +" bvc 3f\n"
1151 +"2: bkpt 0xf103\n"
1152 +"3:\n"
1153 +#endif
1154 +
1155 +" strexd %1, %0, %H0, [%3]\n"
1156 +" teq %1, #0\n"
1157 +" bne 1b"
1158 +
1159 +#ifdef CONFIG_PAX_REFCOUNT
1160 +"\n4:\n"
1161 + _ASM_EXTABLE(2b, 4b)
1162 +#endif
1163 +
1164 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1165 + : "r" (&v->counter), "r" (i)
1166 + : "cc");
1167 +}
1168 +
1169 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1170 +{
1171 + u64 result;
1172 + unsigned long tmp;
1173 +
1174 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1175 +"1: ldrexd %0, %H0, [%3]\n"
1176 +" adds %0, %0, %4\n"
1177 " adc %H0, %H0, %H4\n"
1178 " strexd %1, %0, %H0, [%3]\n"
1179 " teq %1, #0\n"
1180 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1181
1182 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1183 {
1184 - u64 result;
1185 - unsigned long tmp;
1186 + u64 result, tmp;
1187
1188 smp_mb();
1189
1190 __asm__ __volatile__("@ atomic64_add_return\n"
1191 +"1: ldrexd %1, %H1, [%3]\n"
1192 +" adds %0, %1, %4\n"
1193 +" adcs %H0, %H1, %H4\n"
1194 +
1195 +#ifdef CONFIG_PAX_REFCOUNT
1196 +" bvc 3f\n"
1197 +" mov %0, %1\n"
1198 +" mov %H0, %H1\n"
1199 +"2: bkpt 0xf103\n"
1200 +"3:\n"
1201 +#endif
1202 +
1203 +" strexd %1, %0, %H0, [%3]\n"
1204 +" teq %1, #0\n"
1205 +" bne 1b"
1206 +
1207 +#ifdef CONFIG_PAX_REFCOUNT
1208 +"\n4:\n"
1209 + _ASM_EXTABLE(2b, 4b)
1210 +#endif
1211 +
1212 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1213 + : "r" (&v->counter), "r" (i)
1214 + : "cc");
1215 +
1216 + smp_mb();
1217 +
1218 + return result;
1219 +}
1220 +
1221 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1222 +{
1223 + u64 result;
1224 + unsigned long tmp;
1225 +
1226 + smp_mb();
1227 +
1228 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1229 "1: ldrexd %0, %H0, [%3]\n"
1230 " adds %0, %0, %4\n"
1231 " adc %H0, %H0, %H4\n"
1232 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1233 __asm__ __volatile__("@ atomic64_sub\n"
1234 "1: ldrexd %0, %H0, [%3]\n"
1235 " subs %0, %0, %4\n"
1236 +" sbcs %H0, %H0, %H4\n"
1237 +
1238 +#ifdef CONFIG_PAX_REFCOUNT
1239 +" bvc 3f\n"
1240 +"2: bkpt 0xf103\n"
1241 +"3:\n"
1242 +#endif
1243 +
1244 +" strexd %1, %0, %H0, [%3]\n"
1245 +" teq %1, #0\n"
1246 +" bne 1b"
1247 +
1248 +#ifdef CONFIG_PAX_REFCOUNT
1249 +"\n4:\n"
1250 + _ASM_EXTABLE(2b, 4b)
1251 +#endif
1252 +
1253 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1254 + : "r" (&v->counter), "r" (i)
1255 + : "cc");
1256 +}
1257 +
1258 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1259 +{
1260 + u64 result;
1261 + unsigned long tmp;
1262 +
1263 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1264 +"1: ldrexd %0, %H0, [%3]\n"
1265 +" subs %0, %0, %4\n"
1266 " sbc %H0, %H0, %H4\n"
1267 " strexd %1, %0, %H0, [%3]\n"
1268 " teq %1, #0\n"
1269 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1270
1271 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1272 {
1273 - u64 result;
1274 - unsigned long tmp;
1275 + u64 result, tmp;
1276
1277 smp_mb();
1278
1279 __asm__ __volatile__("@ atomic64_sub_return\n"
1280 -"1: ldrexd %0, %H0, [%3]\n"
1281 -" subs %0, %0, %4\n"
1282 -" sbc %H0, %H0, %H4\n"
1283 +"1: ldrexd %1, %H1, [%3]\n"
1284 +" subs %0, %1, %4\n"
1285 +" sbcs %H0, %H1, %H4\n"
1286 +
1287 +#ifdef CONFIG_PAX_REFCOUNT
1288 +" bvc 3f\n"
1289 +" mov %0, %1\n"
1290 +" mov %H0, %H1\n"
1291 +"2: bkpt 0xf103\n"
1292 +"3:\n"
1293 +#endif
1294 +
1295 " strexd %1, %0, %H0, [%3]\n"
1296 " teq %1, #0\n"
1297 " bne 1b"
1298 +
1299 +#ifdef CONFIG_PAX_REFCOUNT
1300 +"\n4:\n"
1301 + _ASM_EXTABLE(2b, 4b)
1302 +#endif
1303 +
1304 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1305 : "r" (&v->counter), "r" (i)
1306 : "cc");
1307 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1308 return oldval;
1309 }
1310
1311 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1312 +{
1313 + u64 oldval;
1314 + unsigned long res;
1315 +
1316 + smp_mb();
1317 +
1318 + do {
1319 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1320 + "ldrexd %1, %H1, [%3]\n"
1321 + "mov %0, #0\n"
1322 + "teq %1, %4\n"
1323 + "teqeq %H1, %H4\n"
1324 + "strexdeq %0, %5, %H5, [%3]"
1325 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1326 + : "r" (&ptr->counter), "r" (old), "r" (new)
1327 + : "cc");
1328 + } while (res);
1329 +
1330 + smp_mb();
1331 +
1332 + return oldval;
1333 +}
1334 +
1335 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1336 {
1337 u64 result;
1338 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1339
1340 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1341 {
1342 - u64 result;
1343 - unsigned long tmp;
1344 + u64 result, tmp;
1345
1346 smp_mb();
1347
1348 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1349 -"1: ldrexd %0, %H0, [%3]\n"
1350 -" subs %0, %0, #1\n"
1351 -" sbc %H0, %H0, #0\n"
1352 +"1: ldrexd %1, %H1, [%3]\n"
1353 +" subs %0, %1, #1\n"
1354 +" sbcs %H0, %H1, #0\n"
1355 +
1356 +#ifdef CONFIG_PAX_REFCOUNT
1357 +" bvc 3f\n"
1358 +" mov %0, %1\n"
1359 +" mov %H0, %H1\n"
1360 +"2: bkpt 0xf103\n"
1361 +"3:\n"
1362 +#endif
1363 +
1364 " teq %H0, #0\n"
1365 -" bmi 2f\n"
1366 +" bmi 4f\n"
1367 " strexd %1, %0, %H0, [%3]\n"
1368 " teq %1, #0\n"
1369 " bne 1b\n"
1370 -"2:"
1371 +"4:\n"
1372 +
1373 +#ifdef CONFIG_PAX_REFCOUNT
1374 + _ASM_EXTABLE(2b, 4b)
1375 +#endif
1376 +
1377 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1378 : "r" (&v->counter)
1379 : "cc");
1380 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1381 " teq %0, %5\n"
1382 " teqeq %H0, %H5\n"
1383 " moveq %1, #0\n"
1384 -" beq 2f\n"
1385 +" beq 4f\n"
1386 " adds %0, %0, %6\n"
1387 -" adc %H0, %H0, %H6\n"
1388 +" adcs %H0, %H0, %H6\n"
1389 +
1390 +#ifdef CONFIG_PAX_REFCOUNT
1391 +" bvc 3f\n"
1392 +"2: bkpt 0xf103\n"
1393 +"3:\n"
1394 +#endif
1395 +
1396 " strexd %2, %0, %H0, [%4]\n"
1397 " teq %2, #0\n"
1398 " bne 1b\n"
1399 -"2:"
1400 +"4:\n"
1401 +
1402 +#ifdef CONFIG_PAX_REFCOUNT
1403 + _ASM_EXTABLE(2b, 4b)
1404 +#endif
1405 +
1406 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1407 : "r" (&v->counter), "r" (u), "r" (a)
1408 : "cc");
1409 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1410
1411 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1412 #define atomic64_inc(v) atomic64_add(1LL, (v))
1413 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1414 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1415 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1416 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1417 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1418 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1419 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1420 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1421 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1422 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1423 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1424 index 75fe66b..ba3dee4 100644
1425 --- a/arch/arm/include/asm/cache.h
1426 +++ b/arch/arm/include/asm/cache.h
1427 @@ -4,8 +4,10 @@
1428 #ifndef __ASMARM_CACHE_H
1429 #define __ASMARM_CACHE_H
1430
1431 +#include <linux/const.h>
1432 +
1433 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1434 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1435 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1436
1437 /*
1438 * Memory returned by kmalloc() may be used for DMA, so we must make
1439 @@ -24,5 +26,6 @@
1440 #endif
1441
1442 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1443 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1444
1445 #endif
1446 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1447 index e1489c5..d418304 100644
1448 --- a/arch/arm/include/asm/cacheflush.h
1449 +++ b/arch/arm/include/asm/cacheflush.h
1450 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1451 void (*dma_unmap_area)(const void *, size_t, int);
1452
1453 void (*dma_flush_range)(const void *, const void *);
1454 -};
1455 +} __no_const;
1456
1457 /*
1458 * Select the calling method
1459 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1460 index 7eb18c1..e38b6d2 100644
1461 --- a/arch/arm/include/asm/cmpxchg.h
1462 +++ b/arch/arm/include/asm/cmpxchg.h
1463 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1464
1465 #define xchg(ptr,x) \
1466 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1467 +#define xchg_unchecked(ptr,x) \
1468 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1469
1470 #include <asm-generic/cmpxchg-local.h>
1471
1472 diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1473 index ab98fdd..6b19938 100644
1474 --- a/arch/arm/include/asm/delay.h
1475 +++ b/arch/arm/include/asm/delay.h
1476 @@ -24,9 +24,9 @@ extern struct arm_delay_ops {
1477 void (*delay)(unsigned long);
1478 void (*const_udelay)(unsigned long);
1479 void (*udelay)(unsigned long);
1480 -} arm_delay_ops;
1481 +} *arm_delay_ops;
1482
1483 -#define __delay(n) arm_delay_ops.delay(n)
1484 +#define __delay(n) arm_delay_ops->delay(n)
1485
1486 /*
1487 * This function intentionally does not exist; if you see references to
1488 @@ -47,8 +47,8 @@ extern void __bad_udelay(void);
1489 * first constant multiplications gets optimized away if the delay is
1490 * a constant)
1491 */
1492 -#define __udelay(n) arm_delay_ops.udelay(n)
1493 -#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1494 +#define __udelay(n) arm_delay_ops->udelay(n)
1495 +#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1496
1497 #define udelay(n) \
1498 (__builtin_constant_p(n) ? \
1499 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1500 index 38050b1..9d90e8b 100644
1501 --- a/arch/arm/include/asm/elf.h
1502 +++ b/arch/arm/include/asm/elf.h
1503 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1504 the loader. We need to make sure that it is out of the way of the program
1505 that it will "exec", and that there is sufficient room for the brk. */
1506
1507 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1508 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1509 +
1510 +#ifdef CONFIG_PAX_ASLR
1511 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1512 +
1513 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1514 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1515 +#endif
1516
1517 /* When the program starts, a1 contains a pointer to a function to be
1518 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1519 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1520 extern void elf_set_personality(const struct elf32_hdr *);
1521 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1522
1523 -struct mm_struct;
1524 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1525 -#define arch_randomize_brk arch_randomize_brk
1526 -
1527 #endif
1528 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1529 index 83eb2f7..ed77159 100644
1530 --- a/arch/arm/include/asm/kmap_types.h
1531 +++ b/arch/arm/include/asm/kmap_types.h
1532 @@ -4,6 +4,6 @@
1533 /*
1534 * This is the "bare minimum". AIO seems to require this.
1535 */
1536 -#define KM_TYPE_NR 16
1537 +#define KM_TYPE_NR 17
1538
1539 #endif
1540 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1541 index 9e614a1..3302cca 100644
1542 --- a/arch/arm/include/asm/mach/dma.h
1543 +++ b/arch/arm/include/asm/mach/dma.h
1544 @@ -22,7 +22,7 @@ struct dma_ops {
1545 int (*residue)(unsigned int, dma_t *); /* optional */
1546 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1547 const char *type;
1548 -};
1549 +} __do_const;
1550
1551 struct dma_struct {
1552 void *addr; /* single DMA address */
1553 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1554 index 195ac2f..2272f0d 100644
1555 --- a/arch/arm/include/asm/mach/map.h
1556 +++ b/arch/arm/include/asm/mach/map.h
1557 @@ -34,6 +34,9 @@ struct map_desc {
1558 #define MT_MEMORY_ITCM 13
1559 #define MT_MEMORY_SO 14
1560 #define MT_MEMORY_DMA_READY 15
1561 +#define MT_MEMORY_R 16
1562 +#define MT_MEMORY_RW 17
1563 +#define MT_MEMORY_RX 18
1564
1565 #ifdef CONFIG_MMU
1566 extern void iotable_init(struct map_desc *, int);
1567 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1568 index 53426c6..c7baff3 100644
1569 --- a/arch/arm/include/asm/outercache.h
1570 +++ b/arch/arm/include/asm/outercache.h
1571 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1572 #endif
1573 void (*set_debug)(unsigned long);
1574 void (*resume)(void);
1575 -};
1576 +} __no_const;
1577
1578 #ifdef CONFIG_OUTER_CACHE
1579
1580 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1581 index 812a494..71fc0b6 100644
1582 --- a/arch/arm/include/asm/page.h
1583 +++ b/arch/arm/include/asm/page.h
1584 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1585 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1586 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1587 unsigned long vaddr, struct vm_area_struct *vma);
1588 -};
1589 +} __no_const;
1590
1591 #ifdef MULTI_USER
1592 extern struct cpu_user_fns cpu_user;
1593 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1594 index 943504f..84d0f84 100644
1595 --- a/arch/arm/include/asm/pgalloc.h
1596 +++ b/arch/arm/include/asm/pgalloc.h
1597 @@ -17,6 +17,7 @@
1598 #include <asm/processor.h>
1599 #include <asm/cacheflush.h>
1600 #include <asm/tlbflush.h>
1601 +#include <asm/system_info.h>
1602
1603 #define check_pgt_cache() do { } while (0)
1604
1605 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1606 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1607 }
1608
1609 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1610 +{
1611 + pud_populate(mm, pud, pmd);
1612 +}
1613 +
1614 #else /* !CONFIG_ARM_LPAE */
1615
1616 /*
1617 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1618 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1619 #define pmd_free(mm, pmd) do { } while (0)
1620 #define pud_populate(mm,pmd,pte) BUG()
1621 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1622
1623 #endif /* CONFIG_ARM_LPAE */
1624
1625 @@ -126,6 +133,16 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1626 __free_page(pte);
1627 }
1628
1629 +static inline void __pmd_update(pmd_t *pmdp, pmdval_t prot)
1630 +{
1631 + pmdval_t pmdval = pmd_val(*pmdp) | prot;
1632 + pmdp[0] = __pmd(pmdval);
1633 +#ifndef CONFIG_ARM_LPAE
1634 + pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
1635 +#endif
1636 + flush_pmd_entry(pmdp);
1637 +}
1638 +
1639 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1640 pmdval_t prot)
1641 {
1642 @@ -155,7 +172,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1643 static inline void
1644 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1645 {
1646 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1647 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1648 }
1649 #define pmd_pgtable(pmd) pmd_page(pmd)
1650
1651 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1652 index 5cfba15..d437dc2 100644
1653 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1654 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1655 @@ -20,12 +20,15 @@
1656 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1657 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1658 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1659 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* PXN */
1660 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1661 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1662 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1663 +
1664 /*
1665 * - section
1666 */
1667 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0)
1668 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1669 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1670 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1671 @@ -37,6 +40,7 @@
1672 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1673 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1674 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1675 +#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 0))
1676
1677 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1678 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1679 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1680 index 2317a71..1897391 100644
1681 --- a/arch/arm/include/asm/pgtable-2level.h
1682 +++ b/arch/arm/include/asm/pgtable-2level.h
1683 @@ -123,6 +123,7 @@
1684 #define L_PTE_USER (_AT(pteval_t, 1) << 8)
1685 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1686 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1687 +#define L_PTE_PXN (_AT(pteval_t, 1) << 11) /* v7*/
1688
1689 /*
1690 * These are the memory types, defined to be compatible with
1691 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1692 index d795282..d82ff13 100644
1693 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1694 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1695 @@ -32,6 +32,7 @@
1696 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1697 #define PMD_BIT4 (_AT(pmdval_t, 0))
1698 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1699 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1700
1701 /*
1702 * - section
1703 @@ -41,9 +42,11 @@
1704 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1705 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1706 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1707 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1708 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1709 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1710 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1711 +#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 1) << 7)
1712 #define PMD_SECT_TEX(x) (_AT(pmdval_t, 0))
1713
1714 /*
1715 @@ -66,6 +69,7 @@
1716 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1717 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1718 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1719 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1720 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1721
1722 /*
1723 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1724 index b249035..4ab204b 100644
1725 --- a/arch/arm/include/asm/pgtable-3level.h
1726 +++ b/arch/arm/include/asm/pgtable-3level.h
1727 @@ -73,6 +73,7 @@
1728 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1729 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1730 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1731 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1732 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1733 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1734 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1735 @@ -80,6 +81,7 @@
1736 /*
1737 * To be used in assembly code with the upper page attributes.
1738 */
1739 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
1740 #define L_PTE_XN_HIGH (1 << (54 - 32))
1741 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1742
1743 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1744 index 08c1231..1031bb4 100644
1745 --- a/arch/arm/include/asm/pgtable.h
1746 +++ b/arch/arm/include/asm/pgtable.h
1747 @@ -30,6 +30,9 @@
1748 #include <asm/pgtable-2level.h>
1749 #endif
1750
1751 +#define ktla_ktva(addr) (addr)
1752 +#define ktva_ktla(addr) (addr)
1753 +
1754 /*
1755 * Just any arbitrary offset to the start of the vmalloc VM area: the
1756 * current 8MB value just means that there will be a 8MB "hole" after the
1757 @@ -45,6 +48,9 @@
1758 #define LIBRARY_TEXT_START 0x0c000000
1759
1760 #ifndef __ASSEMBLY__
1761 +extern pteval_t __supported_pte_mask;
1762 +extern pmdval_t __supported_pmd_mask;
1763 +
1764 extern void __pte_error(const char *file, int line, pte_t);
1765 extern void __pmd_error(const char *file, int line, pmd_t);
1766 extern void __pgd_error(const char *file, int line, pgd_t);
1767 @@ -53,6 +59,17 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1768 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1769 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1770
1771 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
1772 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1773 +
1774 +#ifdef CONFIG_PAX_KERNEXEC
1775 +static inline unsigned long pax_open_kernel(void) { return 0; /* TODO */ }
1776 +static inline unsigned long pax_close_kernel(void) { return 0; /* TODO */ }
1777 +#else
1778 +static inline unsigned long pax_open_kernel(void) { return 0; }
1779 +static inline unsigned long pax_close_kernel(void) { return 0; }
1780 +#endif
1781 +
1782 /*
1783 * This is the lowest virtual address we can permit any user space
1784 * mapping to be mapped at. This is particularly important for
1785 @@ -63,8 +80,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1786 /*
1787 * The pgprot_* and protection_map entries will be fixed up in runtime
1788 * to include the cachable and bufferable bits based on memory policy,
1789 - * as well as any architecture dependent bits like global/ASID and SMP
1790 - * shared mapping bits.
1791 + * as well as any architecture dependent bits like global/ASID, PXN,
1792 + * and SMP shared mapping bits.
1793 */
1794 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
1795
1796 @@ -242,7 +259,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
1797
1798 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
1799 {
1800 - const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER;
1801 + const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | __supported_pte_mask;
1802 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
1803 return pte;
1804 }
1805 diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
1806 index f3628fb..a0672dd 100644
1807 --- a/arch/arm/include/asm/proc-fns.h
1808 +++ b/arch/arm/include/asm/proc-fns.h
1809 @@ -75,7 +75,7 @@ extern struct processor {
1810 unsigned int suspend_size;
1811 void (*do_suspend)(void *);
1812 void (*do_resume)(void *);
1813 -} processor;
1814 +} __do_const processor;
1815
1816 #ifndef MULTI_CPU
1817 extern void cpu_proc_init(void);
1818 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
1819 index 2e3be16..4dc90fc 100644
1820 --- a/arch/arm/include/asm/smp.h
1821 +++ b/arch/arm/include/asm/smp.h
1822 @@ -106,7 +106,7 @@ struct smp_operations {
1823 int (*cpu_disable)(unsigned int cpu);
1824 #endif
1825 #endif
1826 -};
1827 +} __no_const;
1828
1829 /*
1830 * set platform specific SMP operations
1831 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1832 index 8477b4c..801a6a9 100644
1833 --- a/arch/arm/include/asm/thread_info.h
1834 +++ b/arch/arm/include/asm/thread_info.h
1835 @@ -151,6 +151,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1836 #define TIF_SYSCALL_TRACE 8
1837 #define TIF_SYSCALL_AUDIT 9
1838 #define TIF_SYSCALL_TRACEPOINT 10
1839 +
1840 +/* within 8 bits of TIF_SYSCALL_TRACE
1841 + to meet flexible second operand requirements
1842 +*/
1843 +#define TIF_GRSEC_SETXID 11
1844 +
1845 #define TIF_USING_IWMMXT 17
1846 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1847 #define TIF_RESTORE_SIGMASK 20
1848 @@ -165,9 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1849 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
1850 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1851 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1852 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1853
1854 /* Checks for any syscall work in entry-common.S */
1855 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
1856 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | \
1857 + _TIF_GRSEC_SETXID)
1858
1859 /*
1860 * Change these and you break ASM code in entry-common.S
1861 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1862 index 7e1f760..1af891c 100644
1863 --- a/arch/arm/include/asm/uaccess.h
1864 +++ b/arch/arm/include/asm/uaccess.h
1865 @@ -22,6 +22,8 @@
1866 #define VERIFY_READ 0
1867 #define VERIFY_WRITE 1
1868
1869 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1870 +
1871 /*
1872 * The exception table consists of pairs of addresses: the first is the
1873 * address of an instruction that is allowed to fault, and the second is
1874 @@ -418,8 +420,23 @@ do { \
1875
1876
1877 #ifdef CONFIG_MMU
1878 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1879 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1880 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1881 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1882 +
1883 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1884 +{
1885 + if (!__builtin_constant_p(n))
1886 + check_object_size(to, n, false);
1887 + return ___copy_from_user(to, from, n);
1888 +}
1889 +
1890 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1891 +{
1892 + if (!__builtin_constant_p(n))
1893 + check_object_size(from, n, true);
1894 + return ___copy_to_user(to, from, n);
1895 +}
1896 +
1897 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1898 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1899 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1900 @@ -431,6 +448,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1901
1902 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1903 {
1904 + if ((long)n < 0)
1905 + return n;
1906 +
1907 if (access_ok(VERIFY_READ, from, n))
1908 n = __copy_from_user(to, from, n);
1909 else /* security hole - plug it */
1910 @@ -440,6 +460,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1911
1912 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1913 {
1914 + if ((long)n < 0)
1915 + return n;
1916 +
1917 if (access_ok(VERIFY_WRITE, to, n))
1918 n = __copy_to_user(to, from, n);
1919 return n;
1920 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
1921 index 96ee092..37f1844 100644
1922 --- a/arch/arm/include/uapi/asm/ptrace.h
1923 +++ b/arch/arm/include/uapi/asm/ptrace.h
1924 @@ -73,7 +73,7 @@
1925 * ARMv7 groups of PSR bits
1926 */
1927 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
1928 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
1929 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
1930 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
1931 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
1932
1933 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1934 index 60d3b73..9168db0 100644
1935 --- a/arch/arm/kernel/armksyms.c
1936 +++ b/arch/arm/kernel/armksyms.c
1937 @@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1938 #ifdef CONFIG_MMU
1939 EXPORT_SYMBOL(copy_page);
1940
1941 -EXPORT_SYMBOL(__copy_from_user);
1942 -EXPORT_SYMBOL(__copy_to_user);
1943 +EXPORT_SYMBOL(___copy_from_user);
1944 +EXPORT_SYMBOL(___copy_to_user);
1945 EXPORT_SYMBOL(__clear_user);
1946
1947 EXPORT_SYMBOL(__get_user_1);
1948 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
1949 index 486a15a..d95523a 100644
1950 --- a/arch/arm/kernel/head.S
1951 +++ b/arch/arm/kernel/head.S
1952 @@ -52,7 +52,9 @@
1953 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
1954
1955 .macro pgtbl, rd, phys
1956 - add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
1957 + mov \rd, #TEXT_OFFSET
1958 + sub \rd, #PG_DIR_SIZE
1959 + add \rd, \rd, \phys
1960 .endm
1961
1962 /*
1963 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
1964 index 1e9be5d..b9a75e1 100644
1965 --- a/arch/arm/kernel/module.c
1966 +++ b/arch/arm/kernel/module.c
1967 @@ -37,12 +37,35 @@
1968 #endif
1969
1970 #ifdef CONFIG_MMU
1971 -void *module_alloc(unsigned long size)
1972 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
1973 {
1974 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
1975 - GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
1976 + GFP_KERNEL, prot, -1,
1977 __builtin_return_address(0));
1978 }
1979 +
1980 +void *module_alloc(unsigned long size)
1981 +{
1982 +
1983 +#ifdef CONFIG_PAX_KERNEXEC
1984 + return __module_alloc(size, PAGE_KERNEL);
1985 +#else
1986 + return __module_alloc(size, PAGE_KERNEL_EXEC);
1987 +#endif
1988 +
1989 +}
1990 +
1991 +#ifdef CONFIG_PAX_KERNEXEC
1992 +void module_free_exec(struct module *mod, void *module_region)
1993 +{
1994 + module_free(mod, module_region);
1995 +}
1996 +
1997 +void *module_alloc_exec(unsigned long size)
1998 +{
1999 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2000 +}
2001 +#endif
2002 #endif
2003
2004 int
2005 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2006 index 90084a6..bf4bcfb 100644
2007 --- a/arch/arm/kernel/process.c
2008 +++ b/arch/arm/kernel/process.c
2009 @@ -28,7 +28,6 @@
2010 #include <linux/tick.h>
2011 #include <linux/utsname.h>
2012 #include <linux/uaccess.h>
2013 -#include <linux/random.h>
2014 #include <linux/hw_breakpoint.h>
2015 #include <linux/cpuidle.h>
2016 #include <linux/leds.h>
2017 @@ -256,9 +255,10 @@ void machine_power_off(void)
2018 machine_shutdown();
2019 if (pm_power_off)
2020 pm_power_off();
2021 + BUG();
2022 }
2023
2024 -void machine_restart(char *cmd)
2025 +__noreturn void machine_restart(char *cmd)
2026 {
2027 machine_shutdown();
2028
2029 @@ -451,12 +451,6 @@ unsigned long get_wchan(struct task_struct *p)
2030 return 0;
2031 }
2032
2033 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2034 -{
2035 - unsigned long range_end = mm->brk + 0x02000000;
2036 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2037 -}
2038 -
2039 #ifdef CONFIG_MMU
2040 /*
2041 * The vectors page is always readable from user space for the
2042 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2043 index 739db3a..7f4a272 100644
2044 --- a/arch/arm/kernel/ptrace.c
2045 +++ b/arch/arm/kernel/ptrace.c
2046 @@ -916,6 +916,10 @@ enum ptrace_syscall_dir {
2047 PTRACE_SYSCALL_EXIT,
2048 };
2049
2050 +#ifdef CONFIG_GRKERNSEC_SETXID
2051 +extern void gr_delayed_cred_worker(void);
2052 +#endif
2053 +
2054 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2055 enum ptrace_syscall_dir dir)
2056 {
2057 @@ -923,6 +927,11 @@ static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2058
2059 current_thread_info()->syscall = scno;
2060
2061 +#ifdef CONFIG_GRKERNSEC_SETXID
2062 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2063 + gr_delayed_cred_worker();
2064 +#endif
2065 +
2066 if (!test_thread_flag(TIF_SYSCALL_TRACE))
2067 return scno;
2068
2069 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2070 index da1d1aa..ef9bc58 100644
2071 --- a/arch/arm/kernel/setup.c
2072 +++ b/arch/arm/kernel/setup.c
2073 @@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2074 unsigned int elf_hwcap __read_mostly;
2075 EXPORT_SYMBOL(elf_hwcap);
2076
2077 +pteval_t __supported_pte_mask __read_only;
2078 +pmdval_t __supported_pmd_mask __read_only;
2079
2080 #ifdef MULTI_CPU
2081 -struct processor processor __read_mostly;
2082 +struct processor processor;
2083 #endif
2084 #ifdef MULTI_TLB
2085 -struct cpu_tlb_fns cpu_tlb __read_mostly;
2086 +struct cpu_tlb_fns cpu_tlb __read_only;
2087 #endif
2088 #ifdef MULTI_USER
2089 -struct cpu_user_fns cpu_user __read_mostly;
2090 +struct cpu_user_fns cpu_user __read_only;
2091 #endif
2092 #ifdef MULTI_CACHE
2093 -struct cpu_cache_fns cpu_cache __read_mostly;
2094 +struct cpu_cache_fns cpu_cache __read_only;
2095 #endif
2096 #ifdef CONFIG_OUTER_CACHE
2097 -struct outer_cache_fns outer_cache __read_mostly;
2098 +struct outer_cache_fns outer_cache __read_only;
2099 EXPORT_SYMBOL(outer_cache);
2100 #endif
2101
2102 @@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2103 asm("mrc p15, 0, %0, c0, c1, 4"
2104 : "=r" (mmfr0));
2105 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2106 - (mmfr0 & 0x000000f0) >= 0x00000030)
2107 + (mmfr0 & 0x000000f0) >= 0x00000030) {
2108 cpu_arch = CPU_ARCH_ARMv7;
2109 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2110 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2111 + __supported_pte_mask |= L_PTE_PXN;
2112 + __supported_pmd_mask |= PMD_PXNTABLE;
2113 + }
2114 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2115 (mmfr0 & 0x000000f0) == 0x00000020)
2116 cpu_arch = CPU_ARCH_ARMv6;
2117 else
2118 @@ -455,7 +461,7 @@ static void __init setup_processor(void)
2119 __cpu_architecture = __get_cpu_architecture();
2120
2121 #ifdef MULTI_CPU
2122 - processor = *list->proc;
2123 + memcpy((void *)&processor, list->proc, sizeof processor);
2124 #endif
2125 #ifdef MULTI_TLB
2126 cpu_tlb = *list->tlb;
2127 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2128 index fbc8b26..000ded0 100644
2129 --- a/arch/arm/kernel/smp.c
2130 +++ b/arch/arm/kernel/smp.c
2131 @@ -70,7 +70,7 @@ enum ipi_msg_type {
2132
2133 static DECLARE_COMPLETION(cpu_running);
2134
2135 -static struct smp_operations smp_ops;
2136 +static struct smp_operations smp_ops __read_only;
2137
2138 void __init smp_set_ops(struct smp_operations *ops)
2139 {
2140 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2141 index b0179b8..b54c6c1 100644
2142 --- a/arch/arm/kernel/traps.c
2143 +++ b/arch/arm/kernel/traps.c
2144 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2145 static int die_owner = -1;
2146 static unsigned int die_nest_count;
2147
2148 +extern void gr_handle_kernel_exploit(void);
2149 +
2150 static unsigned long oops_begin(void)
2151 {
2152 int cpu;
2153 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
2154 panic("Fatal exception in interrupt");
2155 if (panic_on_oops)
2156 panic("Fatal exception");
2157 +
2158 + gr_handle_kernel_exploit();
2159 +
2160 if (signr)
2161 do_exit(signr);
2162 }
2163 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
2164 index 36ff15b..75d9e9d 100644
2165 --- a/arch/arm/kernel/vmlinux.lds.S
2166 +++ b/arch/arm/kernel/vmlinux.lds.S
2167 @@ -8,7 +8,11 @@
2168 #include <asm/thread_info.h>
2169 #include <asm/memory.h>
2170 #include <asm/page.h>
2171 -
2172 +
2173 +#ifdef CONFIG_PAX_KERNEXEC
2174 +#include <asm/pgtable.h>
2175 +#endif
2176 +
2177 #define PROC_INFO \
2178 . = ALIGN(4); \
2179 VMLINUX_SYMBOL(__proc_info_begin) = .; \
2180 @@ -90,6 +94,11 @@ SECTIONS
2181 _text = .;
2182 HEAD_TEXT
2183 }
2184 +
2185 +#ifdef CONFIG_PAX_KERNEXEC
2186 + . = ALIGN(1<<SECTION_SHIFT);
2187 +#endif
2188 +
2189 .text : { /* Real text segment */
2190 _stext = .; /* Text and read-only data */
2191 __exception_text_start = .;
2192 @@ -133,6 +142,10 @@ SECTIONS
2193
2194 _etext = .; /* End of text and rodata section */
2195
2196 +#ifdef CONFIG_PAX_KERNEXEC
2197 + . = ALIGN(1<<SECTION_SHIFT);
2198 +#endif
2199 +
2200 #ifndef CONFIG_XIP_KERNEL
2201 . = ALIGN(PAGE_SIZE);
2202 __init_begin = .;
2203 @@ -192,6 +205,11 @@ SECTIONS
2204 . = PAGE_OFFSET + TEXT_OFFSET;
2205 #else
2206 __init_end = .;
2207 +
2208 +#ifdef CONFIG_PAX_KERNEXEC
2209 + . = ALIGN(1<<SECTION_SHIFT);
2210 +#endif
2211 +
2212 . = ALIGN(THREAD_SIZE);
2213 __data_loc = .;
2214 #endif
2215 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
2216 index 66a477a..bee61d3 100644
2217 --- a/arch/arm/lib/copy_from_user.S
2218 +++ b/arch/arm/lib/copy_from_user.S
2219 @@ -16,7 +16,7 @@
2220 /*
2221 * Prototype:
2222 *
2223 - * size_t __copy_from_user(void *to, const void *from, size_t n)
2224 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
2225 *
2226 * Purpose:
2227 *
2228 @@ -84,11 +84,11 @@
2229
2230 .text
2231
2232 -ENTRY(__copy_from_user)
2233 +ENTRY(___copy_from_user)
2234
2235 #include "copy_template.S"
2236
2237 -ENDPROC(__copy_from_user)
2238 +ENDPROC(___copy_from_user)
2239
2240 .pushsection .fixup,"ax"
2241 .align 0
2242 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
2243 index 6ee2f67..d1cce76 100644
2244 --- a/arch/arm/lib/copy_page.S
2245 +++ b/arch/arm/lib/copy_page.S
2246 @@ -10,6 +10,7 @@
2247 * ASM optimised string functions
2248 */
2249 #include <linux/linkage.h>
2250 +#include <linux/const.h>
2251 #include <asm/assembler.h>
2252 #include <asm/asm-offsets.h>
2253 #include <asm/cache.h>
2254 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
2255 index d066df6..df28194 100644
2256 --- a/arch/arm/lib/copy_to_user.S
2257 +++ b/arch/arm/lib/copy_to_user.S
2258 @@ -16,7 +16,7 @@
2259 /*
2260 * Prototype:
2261 *
2262 - * size_t __copy_to_user(void *to, const void *from, size_t n)
2263 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
2264 *
2265 * Purpose:
2266 *
2267 @@ -88,11 +88,11 @@
2268 .text
2269
2270 ENTRY(__copy_to_user_std)
2271 -WEAK(__copy_to_user)
2272 +WEAK(___copy_to_user)
2273
2274 #include "copy_template.S"
2275
2276 -ENDPROC(__copy_to_user)
2277 +ENDPROC(___copy_to_user)
2278 ENDPROC(__copy_to_user_std)
2279
2280 .pushsection .fixup,"ax"
2281 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
2282 index 0dc5385..45833ef 100644
2283 --- a/arch/arm/lib/delay.c
2284 +++ b/arch/arm/lib/delay.c
2285 @@ -28,12 +28,14 @@
2286 /*
2287 * Default to the loop-based delay implementation.
2288 */
2289 -struct arm_delay_ops arm_delay_ops = {
2290 +static struct arm_delay_ops arm_loop_delay_ops = {
2291 .delay = __loop_delay,
2292 .const_udelay = __loop_const_udelay,
2293 .udelay = __loop_udelay,
2294 };
2295
2296 +struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
2297 +
2298 static const struct delay_timer *delay_timer;
2299 static bool delay_calibrated;
2300
2301 @@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
2302 __timer_const_udelay(usecs * UDELAY_MULT);
2303 }
2304
2305 +static struct arm_delay_ops arm_timer_delay_ops = {
2306 + .delay = __timer_delay,
2307 + .const_udelay = __timer_const_udelay,
2308 + .udelay = __timer_udelay,
2309 +};
2310 +
2311 void __init register_current_timer_delay(const struct delay_timer *timer)
2312 {
2313 if (!delay_calibrated) {
2314 @@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
2315 delay_timer = timer;
2316 lpj_fine = timer->freq / HZ;
2317 loops_per_jiffy = lpj_fine;
2318 - arm_delay_ops.delay = __timer_delay;
2319 - arm_delay_ops.const_udelay = __timer_const_udelay;
2320 - arm_delay_ops.udelay = __timer_udelay;
2321 + arm_delay_ops = &arm_timer_delay_ops;
2322 delay_calibrated = true;
2323 } else {
2324 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
2325 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
2326 index 025f742..8432b08 100644
2327 --- a/arch/arm/lib/uaccess_with_memcpy.c
2328 +++ b/arch/arm/lib/uaccess_with_memcpy.c
2329 @@ -104,7 +104,7 @@ out:
2330 }
2331
2332 unsigned long
2333 -__copy_to_user(void __user *to, const void *from, unsigned long n)
2334 +___copy_to_user(void __user *to, const void *from, unsigned long n)
2335 {
2336 /*
2337 * This test is stubbed out of the main function above to keep
2338 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
2339 index 2c6c218..2b87c2d 100644
2340 --- a/arch/arm/mach-kirkwood/common.c
2341 +++ b/arch/arm/mach-kirkwood/common.c
2342 @@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
2343 clk_gate_ops.disable(hw);
2344 }
2345
2346 -static struct clk_ops clk_gate_fn_ops;
2347 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
2348 +{
2349 + return clk_gate_ops.is_enabled(hw);
2350 +}
2351 +
2352 +static struct clk_ops clk_gate_fn_ops = {
2353 + .enable = clk_gate_fn_enable,
2354 + .disable = clk_gate_fn_disable,
2355 + .is_enabled = clk_gate_fn_is_enabled,
2356 +};
2357
2358 static struct clk __init *clk_register_gate_fn(struct device *dev,
2359 const char *name,
2360 @@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
2361 gate_fn->fn_en = fn_en;
2362 gate_fn->fn_dis = fn_dis;
2363
2364 - /* ops is the gate ops, but with our enable/disable functions */
2365 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
2366 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
2367 - clk_gate_fn_ops = clk_gate_ops;
2368 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
2369 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
2370 - }
2371 -
2372 clk = clk_register(dev, &gate_fn->gate.hw);
2373
2374 if (IS_ERR(clk))
2375 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
2376 index d95f727..12f10dd 100644
2377 --- a/arch/arm/mach-omap2/board-n8x0.c
2378 +++ b/arch/arm/mach-omap2/board-n8x0.c
2379 @@ -589,7 +589,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
2380 }
2381 #endif
2382
2383 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
2384 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
2385 .late_init = n8x0_menelaus_late_init,
2386 };
2387
2388 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
2389 index 87cc6d0..fd4f248 100644
2390 --- a/arch/arm/mach-omap2/omap_hwmod.c
2391 +++ b/arch/arm/mach-omap2/omap_hwmod.c
2392 @@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
2393 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
2394 struct omap_hwmod_rst_info *ohri);
2395 int (*init_clkdm)(struct omap_hwmod *oh);
2396 -};
2397 +} __no_const;
2398
2399 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
2400 -static struct omap_hwmod_soc_ops soc_ops;
2401 +static struct omap_hwmod_soc_ops soc_ops __read_only;
2402
2403 /* omap_hwmod_list contains all registered struct omap_hwmods */
2404 static LIST_HEAD(omap_hwmod_list);
2405 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
2406 index 5dbf13f..9be36fd 100644
2407 --- a/arch/arm/mm/fault.c
2408 +++ b/arch/arm/mm/fault.c
2409 @@ -25,6 +25,7 @@
2410 #include <asm/system_misc.h>
2411 #include <asm/system_info.h>
2412 #include <asm/tlbflush.h>
2413 +#include <asm/sections.h>
2414
2415 #include "fault.h"
2416
2417 @@ -138,6 +139,19 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
2418 if (fixup_exception(regs))
2419 return;
2420
2421 +#ifdef CONFIG_PAX_KERNEXEC
2422 + if (fsr & FSR_WRITE) {
2423 + if (((unsigned long)_stext <= addr && addr < init_mm.end_code) || (MODULES_VADDR <= addr && addr < MODULES_END)) {
2424 + if (current->signal->curr_ip)
2425 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2426 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
2427 + else
2428 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2429 + current->comm, task_pid_nr(current), current_uid(), current_euid());
2430 + }
2431 + }
2432 +#endif
2433 +
2434 /*
2435 * No handler, we'll have to terminate things with extreme prejudice.
2436 */
2437 @@ -174,6 +188,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
2438 }
2439 #endif
2440
2441 +#ifdef CONFIG_PAX_PAGEEXEC
2442 + if (fsr & FSR_LNX_PF) {
2443 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
2444 + do_group_exit(SIGKILL);
2445 + }
2446 +#endif
2447 +
2448 tsk->thread.address = addr;
2449 tsk->thread.error_code = fsr;
2450 tsk->thread.trap_no = 14;
2451 @@ -398,6 +419,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
2452 }
2453 #endif /* CONFIG_MMU */
2454
2455 +#ifdef CONFIG_PAX_PAGEEXEC
2456 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2457 +{
2458 + long i;
2459 +
2460 + printk(KERN_ERR "PAX: bytes at PC: ");
2461 + for (i = 0; i < 20; i++) {
2462 + unsigned char c;
2463 + if (get_user(c, (__force unsigned char __user *)pc+i))
2464 + printk(KERN_CONT "?? ");
2465 + else
2466 + printk(KERN_CONT "%02x ", c);
2467 + }
2468 + printk("\n");
2469 +
2470 + printk(KERN_ERR "PAX: bytes at SP-4: ");
2471 + for (i = -1; i < 20; i++) {
2472 + unsigned long c;
2473 + if (get_user(c, (__force unsigned long __user *)sp+i))
2474 + printk(KERN_CONT "???????? ");
2475 + else
2476 + printk(KERN_CONT "%08lx ", c);
2477 + }
2478 + printk("\n");
2479 +}
2480 +#endif
2481 +
2482 /*
2483 * First Level Translation Fault Handler
2484 *
2485 @@ -575,12 +623,41 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
2486 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
2487 struct siginfo info;
2488
2489 +#ifdef CONFIG_PAX_KERNEXEC
2490 + if (!user_mode(regs) && is_xn_fault(ifsr)) {
2491 + if (current->signal->curr_ip)
2492 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2493 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid(),
2494 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2495 + else
2496 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2497 + current->comm, task_pid_nr(current), current_uid(), current_euid(),
2498 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2499 + goto die;
2500 + }
2501 +#endif
2502 +
2503 +#ifdef CONFIG_PAX_REFCOUNT
2504 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
2505 + unsigned int bkpt;
2506 +
2507 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
2508 + current->thread.error_code = ifsr;
2509 + current->thread.trap_no = 0;
2510 + pax_report_refcount_overflow(regs);
2511 + fixup_exception(regs);
2512 + return;
2513 + }
2514 + }
2515 +#endif
2516 +
2517 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
2518 return;
2519
2520 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
2521 inf->name, ifsr, addr);
2522
2523 +die:
2524 info.si_signo = inf->sig;
2525 info.si_errno = 0;
2526 info.si_code = inf->code;
2527 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
2528 index cf08bdf..f1a0383 100644
2529 --- a/arch/arm/mm/fault.h
2530 +++ b/arch/arm/mm/fault.h
2531 @@ -3,6 +3,7 @@
2532
2533 /*
2534 * Fault status register encodings. We steal bit 31 for our own purposes.
2535 + * Set when the FSR value is from an instruction fault.
2536 */
2537 #define FSR_LNX_PF (1 << 31)
2538 #define FSR_WRITE (1 << 11)
2539 @@ -22,6 +23,12 @@ static inline int fsr_fs(unsigned int fsr)
2540 }
2541 #endif
2542
2543 +/* valid for LPAE and !LPAE */
2544 +static inline int is_xn_fault(unsigned int fsr)
2545 +{
2546 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
2547 +}
2548 +
2549 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
2550 unsigned long search_exception_table(unsigned long addr);
2551
2552 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
2553 index ad722f1..46b670e 100644
2554 --- a/arch/arm/mm/init.c
2555 +++ b/arch/arm/mm/init.c
2556 @@ -734,9 +734,43 @@ void __init mem_init(void)
2557
2558 void free_initmem(void)
2559 {
2560 +
2561 +#ifdef CONFIG_PAX_KERNEXEC
2562 + unsigned long addr;
2563 + pgd_t *pgd;
2564 + pud_t *pud;
2565 + pmd_t *pmd;
2566 +#endif
2567 +
2568 #ifdef CONFIG_HAVE_TCM
2569 extern char __tcm_start, __tcm_end;
2570 +#endif
2571
2572 +#ifdef CONFIG_PAX_KERNEXEC
2573 + /* make pages tables, etc before .text NX */
2574 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += PMD_SIZE) {
2575 + pgd = pgd_offset_k(addr);
2576 + pud = pud_offset(pgd, addr);
2577 + pmd = pmd_offset(pud, addr);
2578 + __pmd_update(pmd, PMD_SECT_XN);
2579 + }
2580 + /* make init NX */
2581 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += PMD_SIZE) {
2582 + pgd = pgd_offset_k(addr);
2583 + pud = pud_offset(pgd, addr);
2584 + pmd = pmd_offset(pud, addr);
2585 + __pmd_update(pmd, PMD_SECT_XN);
2586 + }
2587 + /* make kernel code/rodata read-only */
2588 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += PMD_SIZE) {
2589 + pgd = pgd_offset_k(addr);
2590 + pud = pud_offset(pgd, addr);
2591 + pmd = pmd_offset(pud, addr);
2592 + __pmd_update(pmd, PMD_SECT_AP_RDONLY);
2593 + }
2594 +#endif
2595 +
2596 +#ifdef CONFIG_HAVE_TCM
2597 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
2598 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
2599 __phys_to_pfn(__pa(&__tcm_end)),
2600 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
2601 index ce8cb19..b9fe4d7 100644
2602 --- a/arch/arm/mm/mmap.c
2603 +++ b/arch/arm/mm/mmap.c
2604 @@ -72,6 +72,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2605 unsigned long start_addr;
2606 int do_align = 0;
2607 int aliasing = cache_is_vipt_aliasing();
2608 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
2609
2610 /*
2611 * We only need to do colour alignment if either the I or D
2612 @@ -93,6 +94,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2613 if (len > TASK_SIZE)
2614 return -ENOMEM;
2615
2616 +#ifdef CONFIG_PAX_RANDMMAP
2617 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2618 +#endif
2619 +
2620 if (addr) {
2621 if (do_align)
2622 addr = COLOUR_ALIGN(addr, pgoff);
2623 @@ -100,15 +105,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2624 addr = PAGE_ALIGN(addr);
2625
2626 vma = find_vma(mm, addr);
2627 - if (TASK_SIZE - len >= addr &&
2628 - (!vma || addr + len <= vma->vm_start))
2629 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
2630 return addr;
2631 }
2632 if (len > mm->cached_hole_size) {
2633 - start_addr = addr = mm->free_area_cache;
2634 + start_addr = addr = mm->free_area_cache;
2635 } else {
2636 - start_addr = addr = mm->mmap_base;
2637 - mm->cached_hole_size = 0;
2638 + start_addr = addr = mm->mmap_base;
2639 + mm->cached_hole_size = 0;
2640 }
2641
2642 full_search:
2643 @@ -124,14 +128,14 @@ full_search:
2644 * Start a new search - just in case we missed
2645 * some holes.
2646 */
2647 - if (start_addr != TASK_UNMAPPED_BASE) {
2648 - start_addr = addr = TASK_UNMAPPED_BASE;
2649 + if (start_addr != mm->mmap_base) {
2650 + start_addr = addr = mm->mmap_base;
2651 mm->cached_hole_size = 0;
2652 goto full_search;
2653 }
2654 return -ENOMEM;
2655 }
2656 - if (!vma || addr + len <= vma->vm_start) {
2657 + if (check_heap_stack_gap(vma, addr, len, offset)) {
2658 /*
2659 * Remember the place where we stopped the search:
2660 */
2661 @@ -156,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2662 unsigned long addr = addr0;
2663 int do_align = 0;
2664 int aliasing = cache_is_vipt_aliasing();
2665 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
2666
2667 /*
2668 * We only need to do colour alignment if either the I or D
2669 @@ -175,6 +180,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2670 return addr;
2671 }
2672
2673 +#ifdef CONFIG_PAX_RANDMMAP
2674 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2675 +#endif
2676 +
2677 /* requesting a specific address */
2678 if (addr) {
2679 if (do_align)
2680 @@ -182,8 +191,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2681 else
2682 addr = PAGE_ALIGN(addr);
2683 vma = find_vma(mm, addr);
2684 - if (TASK_SIZE - len >= addr &&
2685 - (!vma || addr + len <= vma->vm_start))
2686 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
2687 return addr;
2688 }
2689
2690 @@ -203,7 +211,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2691 /* make sure it can fit in the remaining address space */
2692 if (addr > len) {
2693 vma = find_vma(mm, addr-len);
2694 - if (!vma || addr <= vma->vm_start)
2695 + if (check_heap_stack_gap(vma, addr - len, len, offset))
2696 /* remember the address as a hint for next time */
2697 return (mm->free_area_cache = addr-len);
2698 }
2699 @@ -212,17 +220,17 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2700 goto bottomup;
2701
2702 addr = mm->mmap_base - len;
2703 - if (do_align)
2704 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2705
2706 do {
2707 + if (do_align)
2708 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2709 /*
2710 * Lookup failure means no vma is above this address,
2711 * else if new region fits below vma->vm_start,
2712 * return with success:
2713 */
2714 vma = find_vma(mm, addr);
2715 - if (!vma || addr+len <= vma->vm_start)
2716 + if (check_heap_stack_gap(vma, addr, len, offset))
2717 /* remember the address as a hint for next time */
2718 return (mm->free_area_cache = addr);
2719
2720 @@ -231,10 +239,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2721 mm->cached_hole_size = vma->vm_start - addr;
2722
2723 /* try just below the current vma->vm_start */
2724 - addr = vma->vm_start - len;
2725 - if (do_align)
2726 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2727 - } while (len < vma->vm_start);
2728 + addr = skip_heap_stack_gap(vma, len, offset);
2729 + } while (!IS_ERR_VALUE(addr));
2730
2731 bottomup:
2732 /*
2733 @@ -266,10 +272,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2734
2735 if (mmap_is_legacy()) {
2736 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2737 +
2738 +#ifdef CONFIG_PAX_RANDMMAP
2739 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2740 + mm->mmap_base += mm->delta_mmap;
2741 +#endif
2742 +
2743 mm->get_unmapped_area = arch_get_unmapped_area;
2744 mm->unmap_area = arch_unmap_area;
2745 } else {
2746 mm->mmap_base = mmap_base(random_factor);
2747 +
2748 +#ifdef CONFIG_PAX_RANDMMAP
2749 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2750 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2751 +#endif
2752 +
2753 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2754 mm->unmap_area = arch_unmap_area_topdown;
2755 }
2756 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
2757 index 99b47b9..e4c2969 100644
2758 --- a/arch/arm/mm/mmu.c
2759 +++ b/arch/arm/mm/mmu.c
2760 @@ -227,16 +227,16 @@ static struct mem_type mem_types[] = {
2761 [MT_UNCACHED] = {
2762 .prot_pte = PROT_PTE_DEVICE,
2763 .prot_l1 = PMD_TYPE_TABLE,
2764 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2765 + .prot_sect = PROT_SECT_DEVICE | PMD_SECT_XN,
2766 .domain = DOMAIN_IO,
2767 },
2768 [MT_CACHECLEAN] = {
2769 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2770 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2771 .domain = DOMAIN_KERNEL,
2772 },
2773 #ifndef CONFIG_ARM_LPAE
2774 [MT_MINICLEAN] = {
2775 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
2776 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE | PMD_SECT_AP_RDONLY,
2777 .domain = DOMAIN_KERNEL,
2778 },
2779 #endif
2780 @@ -258,8 +258,26 @@ static struct mem_type mem_types[] = {
2781 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
2782 .domain = DOMAIN_KERNEL,
2783 },
2784 + [MT_MEMORY_R] = {
2785 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY | L_PTE_XN,
2786 + .prot_l1 = PMD_TYPE_TABLE,
2787 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY | PMD_SECT_XN,
2788 + .domain = DOMAIN_KERNEL,
2789 + },
2790 + [MT_MEMORY_RW] = {
2791 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_XN,
2792 + .prot_l1 = PMD_TYPE_TABLE,
2793 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_XN,
2794 + .domain = DOMAIN_KERNEL,
2795 + },
2796 + [MT_MEMORY_RX] = {
2797 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY,
2798 + .prot_l1 = PMD_TYPE_TABLE,
2799 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2800 + .domain = DOMAIN_KERNEL,
2801 + },
2802 [MT_ROM] = {
2803 - .prot_sect = PMD_TYPE_SECT,
2804 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2805 .domain = DOMAIN_KERNEL,
2806 },
2807 [MT_MEMORY_NONCACHED] = {
2808 @@ -273,7 +291,7 @@ static struct mem_type mem_types[] = {
2809 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
2810 L_PTE_XN,
2811 .prot_l1 = PMD_TYPE_TABLE,
2812 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2813 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2814 .domain = DOMAIN_KERNEL,
2815 },
2816 [MT_MEMORY_ITCM] = {
2817 @@ -432,6 +450,8 @@ static void __init build_mem_type_table(void)
2818 * from SVC mode and no access from userspace.
2819 */
2820 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2821 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2822 + mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2823 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2824 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2825 #endif
2826 @@ -450,6 +470,12 @@ static void __init build_mem_type_table(void)
2827 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
2828 mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
2829 mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
2830 + mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_S;
2831 + mem_types[MT_MEMORY_R].prot_pte |= L_PTE_SHARED;
2832 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
2833 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
2834 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
2835 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
2836 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
2837 mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
2838 mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
2839 @@ -487,6 +513,8 @@ static void __init build_mem_type_table(void)
2840 vecs_pgprot |= PTE_EXT_AF;
2841 #endif
2842
2843 + user_pgprot |= __supported_pte_mask;
2844 +
2845 for (i = 0; i < 16; i++) {
2846 pteval_t v = pgprot_val(protection_map[i]);
2847 protection_map[i] = __pgprot(v | user_pgprot);
2848 @@ -503,6 +531,12 @@ static void __init build_mem_type_table(void)
2849 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
2850 mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
2851 mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
2852 + mem_types[MT_MEMORY_R].prot_sect |= ecc_mask | cp->pmd;
2853 + mem_types[MT_MEMORY_R].prot_pte |= kern_pgprot;
2854 + mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
2855 + mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
2856 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
2857 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
2858 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
2859 mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
2860 mem_types[MT_ROM].prot_sect |= cp->pmd;
2861 @@ -1198,8 +1232,37 @@ static void __init map_lowmem(void)
2862 map.pfn = __phys_to_pfn(start);
2863 map.virtual = __phys_to_virt(start);
2864 map.length = end - start;
2865 - map.type = MT_MEMORY;
2866
2867 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
2868 + struct map_desc kernel;
2869 + struct map_desc initmap;
2870 +
2871 + /* when freeing initmem we will make this RW */
2872 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
2873 + initmap.virtual = (unsigned long)__init_begin;
2874 + initmap.length = _sdata - __init_begin;
2875 + initmap.type = MT_MEMORY;
2876 + create_mapping(&initmap);
2877 +
2878 + /* when freeing initmem we will make this RX */
2879 + kernel.pfn = __phys_to_pfn(__pa(_stext));
2880 + kernel.virtual = (unsigned long)_stext;
2881 + kernel.length = __init_begin - _stext;
2882 + kernel.type = MT_MEMORY;
2883 + create_mapping(&kernel);
2884 +
2885 + if (map.virtual < (unsigned long)_stext) {
2886 + map.length = (unsigned long)_stext - map.virtual;
2887 + map.type = MT_MEMORY;
2888 + create_mapping(&map);
2889 + }
2890 +
2891 + map.pfn = __phys_to_pfn(__pa(_sdata));
2892 + map.virtual = (unsigned long)_sdata;
2893 + map.length = end - __pa(_sdata);
2894 + }
2895 +
2896 + map.type = MT_MEMORY_RW;
2897 create_mapping(&map);
2898 }
2899 }
2900 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2901 index ec63e4a..62aa5f1d 100644
2902 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2903 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2904 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2905 value in bridge_virt_base */
2906 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2907 const int win);
2908 -};
2909 +} __no_const;
2910
2911 /*
2912 * Information needed to setup one address mapping.
2913 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2914 index f5144cd..71f6d1f 100644
2915 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2916 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2917 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
2918 int (*started)(unsigned ch);
2919 int (*flush)(unsigned ch);
2920 int (*stop)(unsigned ch);
2921 -};
2922 +} __no_const;
2923
2924 extern void *samsung_dmadev_get_ops(void);
2925 extern void *s3c_dma_get_ops(void);
2926 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2927 index c3a58a1..78fbf54 100644
2928 --- a/arch/avr32/include/asm/cache.h
2929 +++ b/arch/avr32/include/asm/cache.h
2930 @@ -1,8 +1,10 @@
2931 #ifndef __ASM_AVR32_CACHE_H
2932 #define __ASM_AVR32_CACHE_H
2933
2934 +#include <linux/const.h>
2935 +
2936 #define L1_CACHE_SHIFT 5
2937 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2938 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2939
2940 /*
2941 * Memory returned by kmalloc() may be used for DMA, so we must make
2942 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2943 index e2c3287..6c4f98c 100644
2944 --- a/arch/avr32/include/asm/elf.h
2945 +++ b/arch/avr32/include/asm/elf.h
2946 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2947 the loader. We need to make sure that it is out of the way of the program
2948 that it will "exec", and that there is sufficient room for the brk. */
2949
2950 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2951 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2952
2953 +#ifdef CONFIG_PAX_ASLR
2954 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2955 +
2956 +#define PAX_DELTA_MMAP_LEN 15
2957 +#define PAX_DELTA_STACK_LEN 15
2958 +#endif
2959
2960 /* This yields a mask that user programs can use to figure out what
2961 instruction set this CPU supports. This could be done in user space,
2962 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2963 index 479330b..53717a8 100644
2964 --- a/arch/avr32/include/asm/kmap_types.h
2965 +++ b/arch/avr32/include/asm/kmap_types.h
2966 @@ -2,9 +2,9 @@
2967 #define __ASM_AVR32_KMAP_TYPES_H
2968
2969 #ifdef CONFIG_DEBUG_HIGHMEM
2970 -# define KM_TYPE_NR 29
2971 +# define KM_TYPE_NR 30
2972 #else
2973 -# define KM_TYPE_NR 14
2974 +# define KM_TYPE_NR 15
2975 #endif
2976
2977 #endif /* __ASM_AVR32_KMAP_TYPES_H */
2978 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2979 index b2f2d2d..d1c85cb 100644
2980 --- a/arch/avr32/mm/fault.c
2981 +++ b/arch/avr32/mm/fault.c
2982 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2983
2984 int exception_trace = 1;
2985
2986 +#ifdef CONFIG_PAX_PAGEEXEC
2987 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2988 +{
2989 + unsigned long i;
2990 +
2991 + printk(KERN_ERR "PAX: bytes at PC: ");
2992 + for (i = 0; i < 20; i++) {
2993 + unsigned char c;
2994 + if (get_user(c, (unsigned char *)pc+i))
2995 + printk(KERN_CONT "???????? ");
2996 + else
2997 + printk(KERN_CONT "%02x ", c);
2998 + }
2999 + printk("\n");
3000 +}
3001 +#endif
3002 +
3003 /*
3004 * This routine handles page faults. It determines the address and the
3005 * problem, and then passes it off to one of the appropriate routines.
3006 @@ -174,6 +191,16 @@ bad_area:
3007 up_read(&mm->mmap_sem);
3008
3009 if (user_mode(regs)) {
3010 +
3011 +#ifdef CONFIG_PAX_PAGEEXEC
3012 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
3013 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
3014 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
3015 + do_group_exit(SIGKILL);
3016 + }
3017 + }
3018 +#endif
3019 +
3020 if (exception_trace && printk_ratelimit())
3021 printk("%s%s[%d]: segfault at %08lx pc %08lx "
3022 "sp %08lx ecr %lu\n",
3023 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
3024 index 568885a..f8008df 100644
3025 --- a/arch/blackfin/include/asm/cache.h
3026 +++ b/arch/blackfin/include/asm/cache.h
3027 @@ -7,6 +7,7 @@
3028 #ifndef __ARCH_BLACKFIN_CACHE_H
3029 #define __ARCH_BLACKFIN_CACHE_H
3030
3031 +#include <linux/const.h>
3032 #include <linux/linkage.h> /* for asmlinkage */
3033
3034 /*
3035 @@ -14,7 +15,7 @@
3036 * Blackfin loads 32 bytes for cache
3037 */
3038 #define L1_CACHE_SHIFT 5
3039 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3040 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3041 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3042
3043 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
3044 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
3045 index aea2718..3639a60 100644
3046 --- a/arch/cris/include/arch-v10/arch/cache.h
3047 +++ b/arch/cris/include/arch-v10/arch/cache.h
3048 @@ -1,8 +1,9 @@
3049 #ifndef _ASM_ARCH_CACHE_H
3050 #define _ASM_ARCH_CACHE_H
3051
3052 +#include <linux/const.h>
3053 /* Etrax 100LX have 32-byte cache-lines. */
3054 -#define L1_CACHE_BYTES 32
3055 #define L1_CACHE_SHIFT 5
3056 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3057
3058 #endif /* _ASM_ARCH_CACHE_H */
3059 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
3060 index 7caf25d..ee65ac5 100644
3061 --- a/arch/cris/include/arch-v32/arch/cache.h
3062 +++ b/arch/cris/include/arch-v32/arch/cache.h
3063 @@ -1,11 +1,12 @@
3064 #ifndef _ASM_CRIS_ARCH_CACHE_H
3065 #define _ASM_CRIS_ARCH_CACHE_H
3066
3067 +#include <linux/const.h>
3068 #include <arch/hwregs/dma.h>
3069
3070 /* A cache-line is 32 bytes. */
3071 -#define L1_CACHE_BYTES 32
3072 #define L1_CACHE_SHIFT 5
3073 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3074
3075 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
3076
3077 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
3078 index b86329d..6709906 100644
3079 --- a/arch/frv/include/asm/atomic.h
3080 +++ b/arch/frv/include/asm/atomic.h
3081 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
3082 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
3083 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
3084
3085 +#define atomic64_read_unchecked(v) atomic64_read(v)
3086 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3087 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3088 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3089 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3090 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3091 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3092 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3093 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3094 +
3095 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
3096 {
3097 int c, old;
3098 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
3099 index 2797163..c2a401d 100644
3100 --- a/arch/frv/include/asm/cache.h
3101 +++ b/arch/frv/include/asm/cache.h
3102 @@ -12,10 +12,11 @@
3103 #ifndef __ASM_CACHE_H
3104 #define __ASM_CACHE_H
3105
3106 +#include <linux/const.h>
3107
3108 /* bytes per L1 cache line */
3109 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
3110 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3111 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3112
3113 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3114 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3115 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
3116 index 43901f2..0d8b865 100644
3117 --- a/arch/frv/include/asm/kmap_types.h
3118 +++ b/arch/frv/include/asm/kmap_types.h
3119 @@ -2,6 +2,6 @@
3120 #ifndef _ASM_KMAP_TYPES_H
3121 #define _ASM_KMAP_TYPES_H
3122
3123 -#define KM_TYPE_NR 17
3124 +#define KM_TYPE_NR 18
3125
3126 #endif
3127 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
3128 index 385fd30..3aaf4fe 100644
3129 --- a/arch/frv/mm/elf-fdpic.c
3130 +++ b/arch/frv/mm/elf-fdpic.c
3131 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3132 {
3133 struct vm_area_struct *vma;
3134 unsigned long limit;
3135 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
3136
3137 if (len > TASK_SIZE)
3138 return -ENOMEM;
3139 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3140 if (addr) {
3141 addr = PAGE_ALIGN(addr);
3142 vma = find_vma(current->mm, addr);
3143 - if (TASK_SIZE - len >= addr &&
3144 - (!vma || addr + len <= vma->vm_start))
3145 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3146 goto success;
3147 }
3148
3149 @@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3150 for (; vma; vma = vma->vm_next) {
3151 if (addr > limit)
3152 break;
3153 - if (addr + len <= vma->vm_start)
3154 + if (check_heap_stack_gap(vma, addr, len, offset))
3155 goto success;
3156 addr = vma->vm_end;
3157 }
3158 @@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3159 for (; vma; vma = vma->vm_next) {
3160 if (addr > limit)
3161 break;
3162 - if (addr + len <= vma->vm_start)
3163 + if (check_heap_stack_gap(vma, addr, len, offset))
3164 goto success;
3165 addr = vma->vm_end;
3166 }
3167 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
3168 index f4ca594..adc72fd6 100644
3169 --- a/arch/hexagon/include/asm/cache.h
3170 +++ b/arch/hexagon/include/asm/cache.h
3171 @@ -21,9 +21,11 @@
3172 #ifndef __ASM_CACHE_H
3173 #define __ASM_CACHE_H
3174
3175 +#include <linux/const.h>
3176 +
3177 /* Bytes per L1 cache line */
3178 -#define L1_CACHE_SHIFT (5)
3179 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3180 +#define L1_CACHE_SHIFT 5
3181 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3182
3183 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
3184 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
3185 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
3186 index 6e6fe18..a6ae668 100644
3187 --- a/arch/ia64/include/asm/atomic.h
3188 +++ b/arch/ia64/include/asm/atomic.h
3189 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
3190 #define atomic64_inc(v) atomic64_add(1, (v))
3191 #define atomic64_dec(v) atomic64_sub(1, (v))
3192
3193 +#define atomic64_read_unchecked(v) atomic64_read(v)
3194 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3195 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3196 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3197 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3198 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3199 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3200 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3201 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3202 +
3203 /* Atomic operations are already serializing */
3204 #define smp_mb__before_atomic_dec() barrier()
3205 #define smp_mb__after_atomic_dec() barrier()
3206 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
3207 index 988254a..e1ee885 100644
3208 --- a/arch/ia64/include/asm/cache.h
3209 +++ b/arch/ia64/include/asm/cache.h
3210 @@ -1,6 +1,7 @@
3211 #ifndef _ASM_IA64_CACHE_H
3212 #define _ASM_IA64_CACHE_H
3213
3214 +#include <linux/const.h>
3215
3216 /*
3217 * Copyright (C) 1998-2000 Hewlett-Packard Co
3218 @@ -9,7 +10,7 @@
3219
3220 /* Bytes per L1 (data) cache line. */
3221 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
3222 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3223 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3224
3225 #ifdef CONFIG_SMP
3226 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3227 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
3228 index b5298eb..67c6e62 100644
3229 --- a/arch/ia64/include/asm/elf.h
3230 +++ b/arch/ia64/include/asm/elf.h
3231 @@ -42,6 +42,13 @@
3232 */
3233 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
3234
3235 +#ifdef CONFIG_PAX_ASLR
3236 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
3237 +
3238 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3239 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3240 +#endif
3241 +
3242 #define PT_IA_64_UNWIND 0x70000001
3243
3244 /* IA-64 relocations: */
3245 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
3246 index 96a8d92..617a1cf 100644
3247 --- a/arch/ia64/include/asm/pgalloc.h
3248 +++ b/arch/ia64/include/asm/pgalloc.h
3249 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3250 pgd_val(*pgd_entry) = __pa(pud);
3251 }
3252
3253 +static inline void
3254 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3255 +{
3256 + pgd_populate(mm, pgd_entry, pud);
3257 +}
3258 +
3259 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3260 {
3261 return quicklist_alloc(0, GFP_KERNEL, NULL);
3262 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3263 pud_val(*pud_entry) = __pa(pmd);
3264 }
3265
3266 +static inline void
3267 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3268 +{
3269 + pud_populate(mm, pud_entry, pmd);
3270 +}
3271 +
3272 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
3273 {
3274 return quicklist_alloc(0, GFP_KERNEL, NULL);
3275 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
3276 index 815810c..d60bd4c 100644
3277 --- a/arch/ia64/include/asm/pgtable.h
3278 +++ b/arch/ia64/include/asm/pgtable.h
3279 @@ -12,7 +12,7 @@
3280 * David Mosberger-Tang <davidm@hpl.hp.com>
3281 */
3282
3283 -
3284 +#include <linux/const.h>
3285 #include <asm/mman.h>
3286 #include <asm/page.h>
3287 #include <asm/processor.h>
3288 @@ -142,6 +142,17 @@
3289 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3290 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3291 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
3292 +
3293 +#ifdef CONFIG_PAX_PAGEEXEC
3294 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
3295 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3296 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3297 +#else
3298 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3299 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3300 +# define PAGE_COPY_NOEXEC PAGE_COPY
3301 +#endif
3302 +
3303 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
3304 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
3305 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
3306 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
3307 index 54ff557..70c88b7 100644
3308 --- a/arch/ia64/include/asm/spinlock.h
3309 +++ b/arch/ia64/include/asm/spinlock.h
3310 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
3311 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
3312
3313 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
3314 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
3315 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
3316 }
3317
3318 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
3319 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
3320 index 449c8c0..50cdf87 100644
3321 --- a/arch/ia64/include/asm/uaccess.h
3322 +++ b/arch/ia64/include/asm/uaccess.h
3323 @@ -42,6 +42,8 @@
3324 #include <asm/pgtable.h>
3325 #include <asm/io.h>
3326
3327 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3328 +
3329 /*
3330 * For historical reasons, the following macros are grossly misnamed:
3331 */
3332 @@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
3333 static inline unsigned long
3334 __copy_to_user (void __user *to, const void *from, unsigned long count)
3335 {
3336 + if (count > INT_MAX)
3337 + return count;
3338 +
3339 + if (!__builtin_constant_p(count))
3340 + check_object_size(from, count, true);
3341 +
3342 return __copy_user(to, (__force void __user *) from, count);
3343 }
3344
3345 static inline unsigned long
3346 __copy_from_user (void *to, const void __user *from, unsigned long count)
3347 {
3348 + if (count > INT_MAX)
3349 + return count;
3350 +
3351 + if (!__builtin_constant_p(count))
3352 + check_object_size(to, count, false);
3353 +
3354 return __copy_user((__force void __user *) to, from, count);
3355 }
3356
3357 @@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3358 ({ \
3359 void __user *__cu_to = (to); \
3360 const void *__cu_from = (from); \
3361 - long __cu_len = (n); \
3362 + unsigned long __cu_len = (n); \
3363 \
3364 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
3365 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
3366 + if (!__builtin_constant_p(n)) \
3367 + check_object_size(__cu_from, __cu_len, true); \
3368 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
3369 + } \
3370 __cu_len; \
3371 })
3372
3373 @@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3374 ({ \
3375 void *__cu_to = (to); \
3376 const void __user *__cu_from = (from); \
3377 - long __cu_len = (n); \
3378 + unsigned long __cu_len = (n); \
3379 \
3380 __chk_user_ptr(__cu_from); \
3381 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
3382 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
3383 + if (!__builtin_constant_p(n)) \
3384 + check_object_size(__cu_to, __cu_len, false); \
3385 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
3386 + } \
3387 __cu_len; \
3388 })
3389
3390 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
3391 index 24603be..948052d 100644
3392 --- a/arch/ia64/kernel/module.c
3393 +++ b/arch/ia64/kernel/module.c
3394 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
3395 void
3396 module_free (struct module *mod, void *module_region)
3397 {
3398 - if (mod && mod->arch.init_unw_table &&
3399 - module_region == mod->module_init) {
3400 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
3401 unw_remove_unwind_table(mod->arch.init_unw_table);
3402 mod->arch.init_unw_table = NULL;
3403 }
3404 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
3405 }
3406
3407 static inline int
3408 +in_init_rx (const struct module *mod, uint64_t addr)
3409 +{
3410 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
3411 +}
3412 +
3413 +static inline int
3414 +in_init_rw (const struct module *mod, uint64_t addr)
3415 +{
3416 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
3417 +}
3418 +
3419 +static inline int
3420 in_init (const struct module *mod, uint64_t addr)
3421 {
3422 - return addr - (uint64_t) mod->module_init < mod->init_size;
3423 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
3424 +}
3425 +
3426 +static inline int
3427 +in_core_rx (const struct module *mod, uint64_t addr)
3428 +{
3429 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
3430 +}
3431 +
3432 +static inline int
3433 +in_core_rw (const struct module *mod, uint64_t addr)
3434 +{
3435 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
3436 }
3437
3438 static inline int
3439 in_core (const struct module *mod, uint64_t addr)
3440 {
3441 - return addr - (uint64_t) mod->module_core < mod->core_size;
3442 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
3443 }
3444
3445 static inline int
3446 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
3447 break;
3448
3449 case RV_BDREL:
3450 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
3451 + if (in_init_rx(mod, val))
3452 + val -= (uint64_t) mod->module_init_rx;
3453 + else if (in_init_rw(mod, val))
3454 + val -= (uint64_t) mod->module_init_rw;
3455 + else if (in_core_rx(mod, val))
3456 + val -= (uint64_t) mod->module_core_rx;
3457 + else if (in_core_rw(mod, val))
3458 + val -= (uint64_t) mod->module_core_rw;
3459 break;
3460
3461 case RV_LTV:
3462 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
3463 * addresses have been selected...
3464 */
3465 uint64_t gp;
3466 - if (mod->core_size > MAX_LTOFF)
3467 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
3468 /*
3469 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
3470 * at the end of the module.
3471 */
3472 - gp = mod->core_size - MAX_LTOFF / 2;
3473 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
3474 else
3475 - gp = mod->core_size / 2;
3476 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
3477 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
3478 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
3479 mod->arch.gp = gp;
3480 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
3481 }
3482 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
3483 index d9439ef..d0cac6b 100644
3484 --- a/arch/ia64/kernel/sys_ia64.c
3485 +++ b/arch/ia64/kernel/sys_ia64.c
3486 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3487 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
3488 struct mm_struct *mm = current->mm;
3489 struct vm_area_struct *vma;
3490 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3491
3492 if (len > RGN_MAP_LIMIT)
3493 return -ENOMEM;
3494 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3495 if (REGION_NUMBER(addr) == RGN_HPAGE)
3496 addr = 0;
3497 #endif
3498 +
3499 +#ifdef CONFIG_PAX_RANDMMAP
3500 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3501 + addr = mm->free_area_cache;
3502 + else
3503 +#endif
3504 +
3505 if (!addr)
3506 addr = mm->free_area_cache;
3507
3508 @@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3509 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
3510 /* At this point: (!vma || addr < vma->vm_end). */
3511 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
3512 - if (start_addr != TASK_UNMAPPED_BASE) {
3513 + if (start_addr != mm->mmap_base) {
3514 /* Start a new search --- just in case we missed some holes. */
3515 - addr = TASK_UNMAPPED_BASE;
3516 + addr = mm->mmap_base;
3517 goto full_search;
3518 }
3519 return -ENOMEM;
3520 }
3521 - if (!vma || addr + len <= vma->vm_start) {
3522 + if (check_heap_stack_gap(vma, addr, len, offset)) {
3523 /* Remember the address where we stopped this search: */
3524 mm->free_area_cache = addr + len;
3525 return addr;
3526 diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
3527 index c64460b..4d250a6 100644
3528 --- a/arch/ia64/kernel/topology.c
3529 +++ b/arch/ia64/kernel/topology.c
3530 @@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
3531 return NOTIFY_OK;
3532 }
3533
3534 -static struct notifier_block __cpuinitdata cache_cpu_notifier =
3535 +static struct notifier_block cache_cpu_notifier =
3536 {
3537 .notifier_call = cache_cpu_callback
3538 };
3539 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
3540 index 0ccb28f..8992469 100644
3541 --- a/arch/ia64/kernel/vmlinux.lds.S
3542 +++ b/arch/ia64/kernel/vmlinux.lds.S
3543 @@ -198,7 +198,7 @@ SECTIONS {
3544 /* Per-cpu data: */
3545 . = ALIGN(PERCPU_PAGE_SIZE);
3546 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
3547 - __phys_per_cpu_start = __per_cpu_load;
3548 + __phys_per_cpu_start = per_cpu_load;
3549 /*
3550 * ensure percpu data fits
3551 * into percpu page size
3552 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
3553 index 6cf0341..d352594 100644
3554 --- a/arch/ia64/mm/fault.c
3555 +++ b/arch/ia64/mm/fault.c
3556 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
3557 return pte_present(pte);
3558 }
3559
3560 +#ifdef CONFIG_PAX_PAGEEXEC
3561 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3562 +{
3563 + unsigned long i;
3564 +
3565 + printk(KERN_ERR "PAX: bytes at PC: ");
3566 + for (i = 0; i < 8; i++) {
3567 + unsigned int c;
3568 + if (get_user(c, (unsigned int *)pc+i))
3569 + printk(KERN_CONT "???????? ");
3570 + else
3571 + printk(KERN_CONT "%08x ", c);
3572 + }
3573 + printk("\n");
3574 +}
3575 +#endif
3576 +
3577 # define VM_READ_BIT 0
3578 # define VM_WRITE_BIT 1
3579 # define VM_EXEC_BIT 2
3580 @@ -149,8 +166,21 @@ retry:
3581 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
3582 goto bad_area;
3583
3584 - if ((vma->vm_flags & mask) != mask)
3585 + if ((vma->vm_flags & mask) != mask) {
3586 +
3587 +#ifdef CONFIG_PAX_PAGEEXEC
3588 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
3589 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
3590 + goto bad_area;
3591 +
3592 + up_read(&mm->mmap_sem);
3593 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
3594 + do_group_exit(SIGKILL);
3595 + }
3596 +#endif
3597 +
3598 goto bad_area;
3599 + }
3600
3601 /*
3602 * If for any reason at all we couldn't handle the fault, make
3603 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
3604 index 5ca674b..127c3cb 100644
3605 --- a/arch/ia64/mm/hugetlbpage.c
3606 +++ b/arch/ia64/mm/hugetlbpage.c
3607 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3608 unsigned long pgoff, unsigned long flags)
3609 {
3610 struct vm_area_struct *vmm;
3611 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
3612
3613 if (len > RGN_MAP_LIMIT)
3614 return -ENOMEM;
3615 @@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3616 /* At this point: (!vmm || addr < vmm->vm_end). */
3617 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
3618 return -ENOMEM;
3619 - if (!vmm || (addr + len) <= vmm->vm_start)
3620 + if (check_heap_stack_gap(vmm, addr, len, offset))
3621 return addr;
3622 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
3623 }
3624 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
3625 index 082e383..fb7be80 100644
3626 --- a/arch/ia64/mm/init.c
3627 +++ b/arch/ia64/mm/init.c
3628 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
3629 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
3630 vma->vm_end = vma->vm_start + PAGE_SIZE;
3631 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
3632 +
3633 +#ifdef CONFIG_PAX_PAGEEXEC
3634 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
3635 + vma->vm_flags &= ~VM_EXEC;
3636 +
3637 +#ifdef CONFIG_PAX_MPROTECT
3638 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
3639 + vma->vm_flags &= ~VM_MAYEXEC;
3640 +#endif
3641 +
3642 + }
3643 +#endif
3644 +
3645 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
3646 down_write(&current->mm->mmap_sem);
3647 if (insert_vm_struct(current->mm, vma)) {
3648 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
3649 index 40b3ee9..8c2c112 100644
3650 --- a/arch/m32r/include/asm/cache.h
3651 +++ b/arch/m32r/include/asm/cache.h
3652 @@ -1,8 +1,10 @@
3653 #ifndef _ASM_M32R_CACHE_H
3654 #define _ASM_M32R_CACHE_H
3655
3656 +#include <linux/const.h>
3657 +
3658 /* L1 cache line size */
3659 #define L1_CACHE_SHIFT 4
3660 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3661 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3662
3663 #endif /* _ASM_M32R_CACHE_H */
3664 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
3665 index 82abd15..d95ae5d 100644
3666 --- a/arch/m32r/lib/usercopy.c
3667 +++ b/arch/m32r/lib/usercopy.c
3668 @@ -14,6 +14,9 @@
3669 unsigned long
3670 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3671 {
3672 + if ((long)n < 0)
3673 + return n;
3674 +
3675 prefetch(from);
3676 if (access_ok(VERIFY_WRITE, to, n))
3677 __copy_user(to,from,n);
3678 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3679 unsigned long
3680 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
3681 {
3682 + if ((long)n < 0)
3683 + return n;
3684 +
3685 prefetchw(to);
3686 if (access_ok(VERIFY_READ, from, n))
3687 __copy_user_zeroing(to,from,n);
3688 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
3689 index 0395c51..5f26031 100644
3690 --- a/arch/m68k/include/asm/cache.h
3691 +++ b/arch/m68k/include/asm/cache.h
3692 @@ -4,9 +4,11 @@
3693 #ifndef __ARCH_M68K_CACHE_H
3694 #define __ARCH_M68K_CACHE_H
3695
3696 +#include <linux/const.h>
3697 +
3698 /* bytes per L1 cache line */
3699 #define L1_CACHE_SHIFT 4
3700 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
3701 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3702
3703 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
3704
3705 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
3706 index 4efe96a..60e8699 100644
3707 --- a/arch/microblaze/include/asm/cache.h
3708 +++ b/arch/microblaze/include/asm/cache.h
3709 @@ -13,11 +13,12 @@
3710 #ifndef _ASM_MICROBLAZE_CACHE_H
3711 #define _ASM_MICROBLAZE_CACHE_H
3712
3713 +#include <linux/const.h>
3714 #include <asm/registers.h>
3715
3716 #define L1_CACHE_SHIFT 5
3717 /* word-granular cache in microblaze */
3718 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3719 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3720
3721 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3722
3723 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
3724 index 01cc6ba..bcb7a5d 100644
3725 --- a/arch/mips/include/asm/atomic.h
3726 +++ b/arch/mips/include/asm/atomic.h
3727 @@ -21,6 +21,10 @@
3728 #include <asm/cmpxchg.h>
3729 #include <asm/war.h>
3730
3731 +#ifdef CONFIG_GENERIC_ATOMIC64
3732 +#include <asm-generic/atomic64.h>
3733 +#endif
3734 +
3735 #define ATOMIC_INIT(i) { (i) }
3736
3737 /*
3738 @@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3739 */
3740 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
3741
3742 +#define atomic64_read_unchecked(v) atomic64_read(v)
3743 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3744 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3745 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3746 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3747 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3748 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3749 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3750 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3751 +
3752 #endif /* CONFIG_64BIT */
3753
3754 /*
3755 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
3756 index b4db69f..8f3b093 100644
3757 --- a/arch/mips/include/asm/cache.h
3758 +++ b/arch/mips/include/asm/cache.h
3759 @@ -9,10 +9,11 @@
3760 #ifndef _ASM_CACHE_H
3761 #define _ASM_CACHE_H
3762
3763 +#include <linux/const.h>
3764 #include <kmalloc.h>
3765
3766 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
3767 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3768 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3769
3770 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3771 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3772 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
3773 index 455c0ac..ad65fbe 100644
3774 --- a/arch/mips/include/asm/elf.h
3775 +++ b/arch/mips/include/asm/elf.h
3776 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
3777 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
3778 #endif
3779
3780 +#ifdef CONFIG_PAX_ASLR
3781 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3782 +
3783 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3784 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3785 +#endif
3786 +
3787 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
3788 struct linux_binprm;
3789 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3790 int uses_interp);
3791
3792 -struct mm_struct;
3793 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3794 -#define arch_randomize_brk arch_randomize_brk
3795 -
3796 #endif /* _ASM_ELF_H */
3797 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
3798 index c1f6afa..38cc6e9 100644
3799 --- a/arch/mips/include/asm/exec.h
3800 +++ b/arch/mips/include/asm/exec.h
3801 @@ -12,6 +12,6 @@
3802 #ifndef _ASM_EXEC_H
3803 #define _ASM_EXEC_H
3804
3805 -extern unsigned long arch_align_stack(unsigned long sp);
3806 +#define arch_align_stack(x) ((x) & ~0xfUL)
3807
3808 #endif /* _ASM_EXEC_H */
3809 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
3810 index da9bd7d..91aa7ab 100644
3811 --- a/arch/mips/include/asm/page.h
3812 +++ b/arch/mips/include/asm/page.h
3813 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
3814 #ifdef CONFIG_CPU_MIPS32
3815 typedef struct { unsigned long pte_low, pte_high; } pte_t;
3816 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
3817 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
3818 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
3819 #else
3820 typedef struct { unsigned long long pte; } pte_t;
3821 #define pte_val(x) ((x).pte)
3822 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
3823 index 881d18b..cea38bc 100644
3824 --- a/arch/mips/include/asm/pgalloc.h
3825 +++ b/arch/mips/include/asm/pgalloc.h
3826 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3827 {
3828 set_pud(pud, __pud((unsigned long)pmd));
3829 }
3830 +
3831 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3832 +{
3833 + pud_populate(mm, pud, pmd);
3834 +}
3835 #endif
3836
3837 /*
3838 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
3839 index 18806a5..141ffcf 100644
3840 --- a/arch/mips/include/asm/thread_info.h
3841 +++ b/arch/mips/include/asm/thread_info.h
3842 @@ -110,6 +110,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
3843 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
3844 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
3845 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
3846 +/* li takes a 32bit immediate */
3847 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
3848 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
3849
3850 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3851 @@ -125,15 +127,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
3852 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
3853 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
3854 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
3855 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3856 +
3857 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3858
3859 /* work to do in syscall_trace_leave() */
3860 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
3861 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3862
3863 /* work to do on interrupt/exception return */
3864 #define _TIF_WORK_MASK \
3865 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
3866 /* work to do on any return to u-space */
3867 -#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
3868 +#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
3869
3870 #endif /* __KERNEL__ */
3871
3872 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
3873 index 9fdd8bc..4bd7f1a 100644
3874 --- a/arch/mips/kernel/binfmt_elfn32.c
3875 +++ b/arch/mips/kernel/binfmt_elfn32.c
3876 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3877 #undef ELF_ET_DYN_BASE
3878 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3879
3880 +#ifdef CONFIG_PAX_ASLR
3881 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3882 +
3883 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3884 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3885 +#endif
3886 +
3887 #include <asm/processor.h>
3888 #include <linux/module.h>
3889 #include <linux/elfcore.h>
3890 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
3891 index ff44823..97f8906 100644
3892 --- a/arch/mips/kernel/binfmt_elfo32.c
3893 +++ b/arch/mips/kernel/binfmt_elfo32.c
3894 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3895 #undef ELF_ET_DYN_BASE
3896 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3897
3898 +#ifdef CONFIG_PAX_ASLR
3899 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3900 +
3901 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3902 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3903 +#endif
3904 +
3905 #include <asm/processor.h>
3906
3907 /*
3908 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
3909 index 69b17a9..9db82f9 100644
3910 --- a/arch/mips/kernel/process.c
3911 +++ b/arch/mips/kernel/process.c
3912 @@ -478,15 +478,3 @@ unsigned long get_wchan(struct task_struct *task)
3913 out:
3914 return pc;
3915 }
3916 -
3917 -/*
3918 - * Don't forget that the stack pointer must be aligned on a 8 bytes
3919 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
3920 - */
3921 -unsigned long arch_align_stack(unsigned long sp)
3922 -{
3923 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3924 - sp -= get_random_int() & ~PAGE_MASK;
3925 -
3926 - return sp & ALMASK;
3927 -}
3928 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
3929 index 4812c6d..2069554 100644
3930 --- a/arch/mips/kernel/ptrace.c
3931 +++ b/arch/mips/kernel/ptrace.c
3932 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
3933 return arch;
3934 }
3935
3936 +#ifdef CONFIG_GRKERNSEC_SETXID
3937 +extern void gr_delayed_cred_worker(void);
3938 +#endif
3939 +
3940 /*
3941 * Notification of system call entry/exit
3942 * - triggered by current->work.syscall_trace
3943 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3944 /* do the secure computing check first */
3945 secure_computing_strict(regs->regs[2]);
3946
3947 +#ifdef CONFIG_GRKERNSEC_SETXID
3948 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3949 + gr_delayed_cred_worker();
3950 +#endif
3951 +
3952 if (!(current->ptrace & PT_PTRACED))
3953 goto out;
3954
3955 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3956 index 374f66e..1c882a0 100644
3957 --- a/arch/mips/kernel/scall32-o32.S
3958 +++ b/arch/mips/kernel/scall32-o32.S
3959 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3960
3961 stack_done:
3962 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3963 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3964 + li t1, _TIF_SYSCALL_WORK
3965 and t0, t1
3966 bnez t0, syscall_trace_entry # -> yes
3967
3968 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3969 index 169de6a..f594a89 100644
3970 --- a/arch/mips/kernel/scall64-64.S
3971 +++ b/arch/mips/kernel/scall64-64.S
3972 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3973
3974 sd a3, PT_R26(sp) # save a3 for syscall restarting
3975
3976 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3977 + li t1, _TIF_SYSCALL_WORK
3978 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3979 and t0, t1, t0
3980 bnez t0, syscall_trace_entry
3981 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3982 index 86ec03f..1235baf 100644
3983 --- a/arch/mips/kernel/scall64-n32.S
3984 +++ b/arch/mips/kernel/scall64-n32.S
3985 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3986
3987 sd a3, PT_R26(sp) # save a3 for syscall restarting
3988
3989 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3990 + li t1, _TIF_SYSCALL_WORK
3991 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3992 and t0, t1, t0
3993 bnez t0, n32_syscall_trace_entry
3994 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3995 index 53c2d72..3734584 100644
3996 --- a/arch/mips/kernel/scall64-o32.S
3997 +++ b/arch/mips/kernel/scall64-o32.S
3998 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3999 PTR 4b, bad_stack
4000 .previous
4001
4002 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4003 + li t1, _TIF_SYSCALL_WORK
4004 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4005 and t0, t1, t0
4006 bnez t0, trace_a_syscall
4007 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
4008 index ddcec1e..c7f983e 100644
4009 --- a/arch/mips/mm/fault.c
4010 +++ b/arch/mips/mm/fault.c
4011 @@ -27,6 +27,23 @@
4012 #include <asm/highmem.h> /* For VMALLOC_END */
4013 #include <linux/kdebug.h>
4014
4015 +#ifdef CONFIG_PAX_PAGEEXEC
4016 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4017 +{
4018 + unsigned long i;
4019 +
4020 + printk(KERN_ERR "PAX: bytes at PC: ");
4021 + for (i = 0; i < 5; i++) {
4022 + unsigned int c;
4023 + if (get_user(c, (unsigned int *)pc+i))
4024 + printk(KERN_CONT "???????? ");
4025 + else
4026 + printk(KERN_CONT "%08x ", c);
4027 + }
4028 + printk("\n");
4029 +}
4030 +#endif
4031 +
4032 /*
4033 * This routine handles page faults. It determines the address,
4034 * and the problem, and then passes it off to one of the appropriate
4035 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
4036 index 302d779..573314a 100644
4037 --- a/arch/mips/mm/mmap.c
4038 +++ b/arch/mips/mm/mmap.c
4039 @@ -71,6 +71,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4040 struct vm_area_struct *vma;
4041 unsigned long addr = addr0;
4042 int do_color_align;
4043 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4044
4045 if (unlikely(len > TASK_SIZE))
4046 return -ENOMEM;
4047 @@ -95,6 +96,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4048 do_color_align = 1;
4049
4050 /* requesting a specific address */
4051 +
4052 +#ifdef CONFIG_PAX_RANDMMAP
4053 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
4054 +#endif
4055 +
4056 if (addr) {
4057 if (do_color_align)
4058 addr = COLOUR_ALIGN(addr, pgoff);
4059 @@ -102,8 +108,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4060 addr = PAGE_ALIGN(addr);
4061
4062 vma = find_vma(mm, addr);
4063 - if (TASK_SIZE - len >= addr &&
4064 - (!vma || addr + len <= vma->vm_start))
4065 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
4066 return addr;
4067 }
4068
4069 @@ -118,7 +123,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4070 /* At this point: (!vma || addr < vma->vm_end). */
4071 if (TASK_SIZE - len < addr)
4072 return -ENOMEM;
4073 - if (!vma || addr + len <= vma->vm_start)
4074 + if (check_heap_stack_gap(vmm, addr, len, offset))
4075 return addr;
4076 addr = vma->vm_end;
4077 if (do_color_align)
4078 @@ -145,7 +150,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4079 /* make sure it can fit in the remaining address space */
4080 if (likely(addr > len)) {
4081 vma = find_vma(mm, addr - len);
4082 - if (!vma || addr <= vma->vm_start) {
4083 + if (check_heap_stack_gap(vmm, addr - len, len, offset))
4084 /* cache the address as a hint for next time */
4085 return mm->free_area_cache = addr - len;
4086 }
4087 @@ -155,17 +160,17 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4088 goto bottomup;
4089
4090 addr = mm->mmap_base - len;
4091 - if (do_color_align)
4092 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4093
4094 do {
4095 + if (do_color_align)
4096 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4097 /*
4098 * Lookup failure means no vma is above this address,
4099 * else if new region fits below vma->vm_start,
4100 * return with success:
4101 */
4102 vma = find_vma(mm, addr);
4103 - if (likely(!vma || addr + len <= vma->vm_start)) {
4104 + if (check_heap_stack_gap(vmm, addr, len, offset)) {
4105 /* cache the address as a hint for next time */
4106 return mm->free_area_cache = addr;
4107 }
4108 @@ -175,10 +180,8 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4109 mm->cached_hole_size = vma->vm_start - addr;
4110
4111 /* try just below the current vma->vm_start */
4112 - addr = vma->vm_start - len;
4113 - if (do_color_align)
4114 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4115 - } while (likely(len < vma->vm_start));
4116 + addr = skip_heap_stack_gap(vma, len, offset);
4117 + } while (!IS_ERR_VALUE(addr));
4118
4119 bottomup:
4120 /*
4121 @@ -242,30 +245,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4122 mm->unmap_area = arch_unmap_area_topdown;
4123 }
4124 }
4125 -
4126 -static inline unsigned long brk_rnd(void)
4127 -{
4128 - unsigned long rnd = get_random_int();
4129 -
4130 - rnd = rnd << PAGE_SHIFT;
4131 - /* 8MB for 32bit, 256MB for 64bit */
4132 - if (TASK_IS_32BIT_ADDR)
4133 - rnd = rnd & 0x7ffffful;
4134 - else
4135 - rnd = rnd & 0xffffffful;
4136 -
4137 - return rnd;
4138 -}
4139 -
4140 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4141 -{
4142 - unsigned long base = mm->brk;
4143 - unsigned long ret;
4144 -
4145 - ret = PAGE_ALIGN(base + brk_rnd());
4146 -
4147 - if (ret < mm->brk)
4148 - return mm->brk;
4149 -
4150 - return ret;
4151 -}
4152 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
4153 index 967d144..db12197 100644
4154 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
4155 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
4156 @@ -11,12 +11,14 @@
4157 #ifndef _ASM_PROC_CACHE_H
4158 #define _ASM_PROC_CACHE_H
4159
4160 +#include <linux/const.h>
4161 +
4162 /* L1 cache */
4163
4164 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4165 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
4166 -#define L1_CACHE_BYTES 16 /* bytes per entry */
4167 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
4168 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4169 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
4170
4171 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4172 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4173 index bcb5df2..84fabd2 100644
4174 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4175 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4176 @@ -16,13 +16,15 @@
4177 #ifndef _ASM_PROC_CACHE_H
4178 #define _ASM_PROC_CACHE_H
4179
4180 +#include <linux/const.h>
4181 +
4182 /*
4183 * L1 cache
4184 */
4185 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4186 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
4187 -#define L1_CACHE_BYTES 32 /* bytes per entry */
4188 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
4189 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4190 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
4191
4192 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4193 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
4194 index 4ce7a01..449202a 100644
4195 --- a/arch/openrisc/include/asm/cache.h
4196 +++ b/arch/openrisc/include/asm/cache.h
4197 @@ -19,11 +19,13 @@
4198 #ifndef __ASM_OPENRISC_CACHE_H
4199 #define __ASM_OPENRISC_CACHE_H
4200
4201 +#include <linux/const.h>
4202 +
4203 /* FIXME: How can we replace these with values from the CPU...
4204 * they shouldn't be hard-coded!
4205 */
4206
4207 -#define L1_CACHE_BYTES 16
4208 #define L1_CACHE_SHIFT 4
4209 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4210
4211 #endif /* __ASM_OPENRISC_CACHE_H */
4212 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
4213 index af9cf30..2aae9b2 100644
4214 --- a/arch/parisc/include/asm/atomic.h
4215 +++ b/arch/parisc/include/asm/atomic.h
4216 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
4217
4218 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4219
4220 +#define atomic64_read_unchecked(v) atomic64_read(v)
4221 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4222 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4223 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4224 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4225 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4226 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4227 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4228 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4229 +
4230 #endif /* !CONFIG_64BIT */
4231
4232
4233 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
4234 index 47f11c7..3420df2 100644
4235 --- a/arch/parisc/include/asm/cache.h
4236 +++ b/arch/parisc/include/asm/cache.h
4237 @@ -5,6 +5,7 @@
4238 #ifndef __ARCH_PARISC_CACHE_H
4239 #define __ARCH_PARISC_CACHE_H
4240
4241 +#include <linux/const.h>
4242
4243 /*
4244 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
4245 @@ -15,13 +16,13 @@
4246 * just ruin performance.
4247 */
4248 #ifdef CONFIG_PA20
4249 -#define L1_CACHE_BYTES 64
4250 #define L1_CACHE_SHIFT 6
4251 #else
4252 -#define L1_CACHE_BYTES 32
4253 #define L1_CACHE_SHIFT 5
4254 #endif
4255
4256 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4257 +
4258 #ifndef __ASSEMBLY__
4259
4260 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4261 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
4262 index 19f6cb1..6c78cf2 100644
4263 --- a/arch/parisc/include/asm/elf.h
4264 +++ b/arch/parisc/include/asm/elf.h
4265 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
4266
4267 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
4268
4269 +#ifdef CONFIG_PAX_ASLR
4270 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
4271 +
4272 +#define PAX_DELTA_MMAP_LEN 16
4273 +#define PAX_DELTA_STACK_LEN 16
4274 +#endif
4275 +
4276 /* This yields a mask that user programs can use to figure out what
4277 instruction set this CPU supports. This could be done in user space,
4278 but it's not easy, and we've already done it here. */
4279 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
4280 index fc987a1..6e068ef 100644
4281 --- a/arch/parisc/include/asm/pgalloc.h
4282 +++ b/arch/parisc/include/asm/pgalloc.h
4283 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4284 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
4285 }
4286
4287 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4288 +{
4289 + pgd_populate(mm, pgd, pmd);
4290 +}
4291 +
4292 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
4293 {
4294 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
4295 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
4296 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
4297 #define pmd_free(mm, x) do { } while (0)
4298 #define pgd_populate(mm, pmd, pte) BUG()
4299 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
4300
4301 #endif
4302
4303 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
4304 index ee99f23..802b0a1 100644
4305 --- a/arch/parisc/include/asm/pgtable.h
4306 +++ b/arch/parisc/include/asm/pgtable.h
4307 @@ -212,6 +212,17 @@ struct vm_area_struct;
4308 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
4309 #define PAGE_COPY PAGE_EXECREAD
4310 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
4311 +
4312 +#ifdef CONFIG_PAX_PAGEEXEC
4313 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
4314 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4315 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4316 +#else
4317 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4318 +# define PAGE_COPY_NOEXEC PAGE_COPY
4319 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4320 +#endif
4321 +
4322 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
4323 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
4324 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
4325 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
4326 index 4ba2c93..f5e3974 100644
4327 --- a/arch/parisc/include/asm/uaccess.h
4328 +++ b/arch/parisc/include/asm/uaccess.h
4329 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
4330 const void __user *from,
4331 unsigned long n)
4332 {
4333 - int sz = __compiletime_object_size(to);
4334 + size_t sz = __compiletime_object_size(to);
4335 int ret = -EFAULT;
4336
4337 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
4338 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
4339 ret = __copy_from_user(to, from, n);
4340 else
4341 copy_from_user_overflow();
4342 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
4343 index 5e34ccf..672bc9c 100644
4344 --- a/arch/parisc/kernel/module.c
4345 +++ b/arch/parisc/kernel/module.c
4346 @@ -98,16 +98,38 @@
4347
4348 /* three functions to determine where in the module core
4349 * or init pieces the location is */
4350 +static inline int in_init_rx(struct module *me, void *loc)
4351 +{
4352 + return (loc >= me->module_init_rx &&
4353 + loc < (me->module_init_rx + me->init_size_rx));
4354 +}
4355 +
4356 +static inline int in_init_rw(struct module *me, void *loc)
4357 +{
4358 + return (loc >= me->module_init_rw &&
4359 + loc < (me->module_init_rw + me->init_size_rw));
4360 +}
4361 +
4362 static inline int in_init(struct module *me, void *loc)
4363 {
4364 - return (loc >= me->module_init &&
4365 - loc <= (me->module_init + me->init_size));
4366 + return in_init_rx(me, loc) || in_init_rw(me, loc);
4367 +}
4368 +
4369 +static inline int in_core_rx(struct module *me, void *loc)
4370 +{
4371 + return (loc >= me->module_core_rx &&
4372 + loc < (me->module_core_rx + me->core_size_rx));
4373 +}
4374 +
4375 +static inline int in_core_rw(struct module *me, void *loc)
4376 +{
4377 + return (loc >= me->module_core_rw &&
4378 + loc < (me->module_core_rw + me->core_size_rw));
4379 }
4380
4381 static inline int in_core(struct module *me, void *loc)
4382 {
4383 - return (loc >= me->module_core &&
4384 - loc <= (me->module_core + me->core_size));
4385 + return in_core_rx(me, loc) || in_core_rw(me, loc);
4386 }
4387
4388 static inline int in_local(struct module *me, void *loc)
4389 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
4390 }
4391
4392 /* align things a bit */
4393 - me->core_size = ALIGN(me->core_size, 16);
4394 - me->arch.got_offset = me->core_size;
4395 - me->core_size += gots * sizeof(struct got_entry);
4396 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
4397 + me->arch.got_offset = me->core_size_rw;
4398 + me->core_size_rw += gots * sizeof(struct got_entry);
4399
4400 - me->core_size = ALIGN(me->core_size, 16);
4401 - me->arch.fdesc_offset = me->core_size;
4402 - me->core_size += fdescs * sizeof(Elf_Fdesc);
4403 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
4404 + me->arch.fdesc_offset = me->core_size_rw;
4405 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
4406
4407 me->arch.got_max = gots;
4408 me->arch.fdesc_max = fdescs;
4409 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4410
4411 BUG_ON(value == 0);
4412
4413 - got = me->module_core + me->arch.got_offset;
4414 + got = me->module_core_rw + me->arch.got_offset;
4415 for (i = 0; got[i].addr; i++)
4416 if (got[i].addr == value)
4417 goto out;
4418 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4419 #ifdef CONFIG_64BIT
4420 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4421 {
4422 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
4423 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
4424
4425 if (!value) {
4426 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
4427 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4428
4429 /* Create new one */
4430 fdesc->addr = value;
4431 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4432 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4433 return (Elf_Addr)fdesc;
4434 }
4435 #endif /* CONFIG_64BIT */
4436 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
4437
4438 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
4439 end = table + sechdrs[me->arch.unwind_section].sh_size;
4440 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4441 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4442
4443 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
4444 me->arch.unwind_section, table, end, gp);
4445 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
4446 index f76c108..92bad82 100644
4447 --- a/arch/parisc/kernel/sys_parisc.c
4448 +++ b/arch/parisc/kernel/sys_parisc.c
4449 @@ -33,9 +33,11 @@
4450 #include <linux/utsname.h>
4451 #include <linux/personality.h>
4452
4453 -static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4454 +static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
4455 + unsigned long flags)
4456 {
4457 struct vm_area_struct *vma;
4458 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4459
4460 addr = PAGE_ALIGN(addr);
4461
4462 @@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4463 /* At this point: (!vma || addr < vma->vm_end). */
4464 if (TASK_SIZE - len < addr)
4465 return -ENOMEM;
4466 - if (!vma || addr + len <= vma->vm_start)
4467 + if (check_heap_stack_gap(vma, addr, len, offset))
4468 return addr;
4469 addr = vma->vm_end;
4470 }
4471 @@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
4472 return offset & 0x3FF000;
4473 }
4474
4475 -static unsigned long get_shared_area(struct address_space *mapping,
4476 - unsigned long addr, unsigned long len, unsigned long pgoff)
4477 +static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
4478 + unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
4479 {
4480 struct vm_area_struct *vma;
4481 int offset = mapping ? get_offset(mapping) : 0;
4482 + unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4483
4484 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
4485
4486 @@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
4487 /* At this point: (!vma || addr < vma->vm_end). */
4488 if (TASK_SIZE - len < addr)
4489 return -ENOMEM;
4490 - if (!vma || addr + len <= vma->vm_start)
4491 + if (check_heap_stack_gap(vma, addr, len, rand_offset))
4492 return addr;
4493 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
4494 if (addr < vma->vm_end) /* handle wraparound */
4495 @@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4496 if (flags & MAP_FIXED)
4497 return addr;
4498 if (!addr)
4499 - addr = TASK_UNMAPPED_BASE;
4500 + addr = current->mm->mmap_base;
4501
4502 if (filp) {
4503 - addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
4504 + addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
4505 } else if(flags & MAP_SHARED) {
4506 - addr = get_shared_area(NULL, addr, len, pgoff);
4507 + addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
4508 } else {
4509 - addr = get_unshared_area(addr, len);
4510 + addr = get_unshared_area(filp, addr, len, flags);
4511 }
4512 return addr;
4513 }
4514 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
4515 index 45ba99f..8e22c33 100644
4516 --- a/arch/parisc/kernel/traps.c
4517 +++ b/arch/parisc/kernel/traps.c
4518 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
4519
4520 down_read(&current->mm->mmap_sem);
4521 vma = find_vma(current->mm,regs->iaoq[0]);
4522 - if (vma && (regs->iaoq[0] >= vma->vm_start)
4523 - && (vma->vm_flags & VM_EXEC)) {
4524 -
4525 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
4526 fault_address = regs->iaoq[0];
4527 fault_space = regs->iasq[0];
4528
4529 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
4530 index 18162ce..94de376 100644
4531 --- a/arch/parisc/mm/fault.c
4532 +++ b/arch/parisc/mm/fault.c
4533 @@ -15,6 +15,7 @@
4534 #include <linux/sched.h>
4535 #include <linux/interrupt.h>
4536 #include <linux/module.h>
4537 +#include <linux/unistd.h>
4538
4539 #include <asm/uaccess.h>
4540 #include <asm/traps.h>
4541 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
4542 static unsigned long
4543 parisc_acctyp(unsigned long code, unsigned int inst)
4544 {
4545 - if (code == 6 || code == 16)
4546 + if (code == 6 || code == 7 || code == 16)
4547 return VM_EXEC;
4548
4549 switch (inst & 0xf0000000) {
4550 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
4551 }
4552 #endif
4553
4554 +#ifdef CONFIG_PAX_PAGEEXEC
4555 +/*
4556 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
4557 + *
4558 + * returns 1 when task should be killed
4559 + * 2 when rt_sigreturn trampoline was detected
4560 + * 3 when unpatched PLT trampoline was detected
4561 + */
4562 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4563 +{
4564 +
4565 +#ifdef CONFIG_PAX_EMUPLT
4566 + int err;
4567 +
4568 + do { /* PaX: unpatched PLT emulation */
4569 + unsigned int bl, depwi;
4570 +
4571 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
4572 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
4573 +
4574 + if (err)
4575 + break;
4576 +
4577 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
4578 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
4579 +
4580 + err = get_user(ldw, (unsigned int *)addr);
4581 + err |= get_user(bv, (unsigned int *)(addr+4));
4582 + err |= get_user(ldw2, (unsigned int *)(addr+8));
4583 +
4584 + if (err)
4585 + break;
4586 +
4587 + if (ldw == 0x0E801096U &&
4588 + bv == 0xEAC0C000U &&
4589 + ldw2 == 0x0E881095U)
4590 + {
4591 + unsigned int resolver, map;
4592 +
4593 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
4594 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
4595 + if (err)
4596 + break;
4597 +
4598 + regs->gr[20] = instruction_pointer(regs)+8;
4599 + regs->gr[21] = map;
4600 + regs->gr[22] = resolver;
4601 + regs->iaoq[0] = resolver | 3UL;
4602 + regs->iaoq[1] = regs->iaoq[0] + 4;
4603 + return 3;
4604 + }
4605 + }
4606 + } while (0);
4607 +#endif
4608 +
4609 +#ifdef CONFIG_PAX_EMUTRAMP
4610 +
4611 +#ifndef CONFIG_PAX_EMUSIGRT
4612 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
4613 + return 1;
4614 +#endif
4615 +
4616 + do { /* PaX: rt_sigreturn emulation */
4617 + unsigned int ldi1, ldi2, bel, nop;
4618 +
4619 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
4620 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
4621 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
4622 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
4623 +
4624 + if (err)
4625 + break;
4626 +
4627 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
4628 + ldi2 == 0x3414015AU &&
4629 + bel == 0xE4008200U &&
4630 + nop == 0x08000240U)
4631 + {
4632 + regs->gr[25] = (ldi1 & 2) >> 1;
4633 + regs->gr[20] = __NR_rt_sigreturn;
4634 + regs->gr[31] = regs->iaoq[1] + 16;
4635 + regs->sr[0] = regs->iasq[1];
4636 + regs->iaoq[0] = 0x100UL;
4637 + regs->iaoq[1] = regs->iaoq[0] + 4;
4638 + regs->iasq[0] = regs->sr[2];
4639 + regs->iasq[1] = regs->sr[2];
4640 + return 2;
4641 + }
4642 + } while (0);
4643 +#endif
4644 +
4645 + return 1;
4646 +}
4647 +
4648 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4649 +{
4650 + unsigned long i;
4651 +
4652 + printk(KERN_ERR "PAX: bytes at PC: ");
4653 + for (i = 0; i < 5; i++) {
4654 + unsigned int c;
4655 + if (get_user(c, (unsigned int *)pc+i))
4656 + printk(KERN_CONT "???????? ");
4657 + else
4658 + printk(KERN_CONT "%08x ", c);
4659 + }
4660 + printk("\n");
4661 +}
4662 +#endif
4663 +
4664 int fixup_exception(struct pt_regs *regs)
4665 {
4666 const struct exception_table_entry *fix;
4667 @@ -192,8 +303,33 @@ good_area:
4668
4669 acc_type = parisc_acctyp(code,regs->iir);
4670
4671 - if ((vma->vm_flags & acc_type) != acc_type)
4672 + if ((vma->vm_flags & acc_type) != acc_type) {
4673 +
4674 +#ifdef CONFIG_PAX_PAGEEXEC
4675 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
4676 + (address & ~3UL) == instruction_pointer(regs))
4677 + {
4678 + up_read(&mm->mmap_sem);
4679 + switch (pax_handle_fetch_fault(regs)) {
4680 +
4681 +#ifdef CONFIG_PAX_EMUPLT
4682 + case 3:
4683 + return;
4684 +#endif
4685 +
4686 +#ifdef CONFIG_PAX_EMUTRAMP
4687 + case 2:
4688 + return;
4689 +#endif
4690 +
4691 + }
4692 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
4693 + do_group_exit(SIGKILL);
4694 + }
4695 +#endif
4696 +
4697 goto bad_area;
4698 + }
4699
4700 /*
4701 * If for any reason at all we couldn't handle the fault, make
4702 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
4703 index e3b1d41..8e81edf 100644
4704 --- a/arch/powerpc/include/asm/atomic.h
4705 +++ b/arch/powerpc/include/asm/atomic.h
4706 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
4707 return t1;
4708 }
4709
4710 +#define atomic64_read_unchecked(v) atomic64_read(v)
4711 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4712 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4713 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4714 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4715 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4716 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4717 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4718 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4719 +
4720 #endif /* __powerpc64__ */
4721
4722 #endif /* __KERNEL__ */
4723 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
4724 index 9e495c9..b6878e5 100644
4725 --- a/arch/powerpc/include/asm/cache.h
4726 +++ b/arch/powerpc/include/asm/cache.h
4727 @@ -3,6 +3,7 @@
4728
4729 #ifdef __KERNEL__
4730
4731 +#include <linux/const.h>
4732
4733 /* bytes per L1 cache line */
4734 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
4735 @@ -22,7 +23,7 @@
4736 #define L1_CACHE_SHIFT 7
4737 #endif
4738
4739 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4740 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4741
4742 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4743
4744 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
4745 index 6abf0a1..459d0f1 100644
4746 --- a/arch/powerpc/include/asm/elf.h
4747 +++ b/arch/powerpc/include/asm/elf.h
4748 @@ -28,8 +28,19 @@
4749 the loader. We need to make sure that it is out of the way of the program
4750 that it will "exec", and that there is sufficient room for the brk. */
4751
4752 -extern unsigned long randomize_et_dyn(unsigned long base);
4753 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
4754 +#define ELF_ET_DYN_BASE (0x20000000)
4755 +
4756 +#ifdef CONFIG_PAX_ASLR
4757 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
4758 +
4759 +#ifdef __powerpc64__
4760 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
4761 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
4762 +#else
4763 +#define PAX_DELTA_MMAP_LEN 15
4764 +#define PAX_DELTA_STACK_LEN 15
4765 +#endif
4766 +#endif
4767
4768 /*
4769 * Our registers are always unsigned longs, whether we're a 32 bit
4770 @@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
4771 (0x7ff >> (PAGE_SHIFT - 12)) : \
4772 (0x3ffff >> (PAGE_SHIFT - 12)))
4773
4774 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4775 -#define arch_randomize_brk arch_randomize_brk
4776 -
4777 -
4778 #ifdef CONFIG_SPU_BASE
4779 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
4780 #define NT_SPU 1
4781 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
4782 index 8196e9c..d83a9f3 100644
4783 --- a/arch/powerpc/include/asm/exec.h
4784 +++ b/arch/powerpc/include/asm/exec.h
4785 @@ -4,6 +4,6 @@
4786 #ifndef _ASM_POWERPC_EXEC_H
4787 #define _ASM_POWERPC_EXEC_H
4788
4789 -extern unsigned long arch_align_stack(unsigned long sp);
4790 +#define arch_align_stack(x) ((x) & ~0xfUL)
4791
4792 #endif /* _ASM_POWERPC_EXEC_H */
4793 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
4794 index 5acabbd..7ea14fa 100644
4795 --- a/arch/powerpc/include/asm/kmap_types.h
4796 +++ b/arch/powerpc/include/asm/kmap_types.h
4797 @@ -10,7 +10,7 @@
4798 * 2 of the License, or (at your option) any later version.
4799 */
4800
4801 -#define KM_TYPE_NR 16
4802 +#define KM_TYPE_NR 17
4803
4804 #endif /* __KERNEL__ */
4805 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
4806 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
4807 index 8565c25..2865190 100644
4808 --- a/arch/powerpc/include/asm/mman.h
4809 +++ b/arch/powerpc/include/asm/mman.h
4810 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
4811 }
4812 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
4813
4814 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
4815 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
4816 {
4817 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
4818 }
4819 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
4820 index f072e97..b436dee 100644
4821 --- a/arch/powerpc/include/asm/page.h
4822 +++ b/arch/powerpc/include/asm/page.h
4823 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
4824 * and needs to be executable. This means the whole heap ends
4825 * up being executable.
4826 */
4827 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4828 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4829 +#define VM_DATA_DEFAULT_FLAGS32 \
4830 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4831 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4832
4833 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4834 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4835 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
4836 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
4837 #endif
4838
4839 +#define ktla_ktva(addr) (addr)
4840 +#define ktva_ktla(addr) (addr)
4841 +
4842 /*
4843 * Use the top bit of the higher-level page table entries to indicate whether
4844 * the entries we point to contain hugepages. This works because we know that
4845 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
4846 index cd915d6..c10cee8 100644
4847 --- a/arch/powerpc/include/asm/page_64.h
4848 +++ b/arch/powerpc/include/asm/page_64.h
4849 @@ -154,15 +154,18 @@ do { \
4850 * stack by default, so in the absence of a PT_GNU_STACK program header
4851 * we turn execute permission off.
4852 */
4853 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4854 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4855 +#define VM_STACK_DEFAULT_FLAGS32 \
4856 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4857 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4858
4859 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4860 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4861
4862 +#ifndef CONFIG_PAX_PAGEEXEC
4863 #define VM_STACK_DEFAULT_FLAGS \
4864 (is_32bit_task() ? \
4865 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
4866 +#endif
4867
4868 #include <asm-generic/getorder.h>
4869
4870 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
4871 index 292725c..f87ae14 100644
4872 --- a/arch/powerpc/include/asm/pgalloc-64.h
4873 +++ b/arch/powerpc/include/asm/pgalloc-64.h
4874 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
4875 #ifndef CONFIG_PPC_64K_PAGES
4876
4877 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
4878 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
4879
4880 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4881 {
4882 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4883 pud_set(pud, (unsigned long)pmd);
4884 }
4885
4886 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4887 +{
4888 + pud_populate(mm, pud, pmd);
4889 +}
4890 +
4891 #define pmd_populate(mm, pmd, pte_page) \
4892 pmd_populate_kernel(mm, pmd, page_address(pte_page))
4893 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
4894 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4895 #else /* CONFIG_PPC_64K_PAGES */
4896
4897 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
4898 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
4899
4900 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
4901 pte_t *pte)
4902 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
4903 index a9cbd3b..3b67efa 100644
4904 --- a/arch/powerpc/include/asm/pgtable.h
4905 +++ b/arch/powerpc/include/asm/pgtable.h
4906 @@ -2,6 +2,7 @@
4907 #define _ASM_POWERPC_PGTABLE_H
4908 #ifdef __KERNEL__
4909
4910 +#include <linux/const.h>
4911 #ifndef __ASSEMBLY__
4912 #include <asm/processor.h> /* For TASK_SIZE */
4913 #include <asm/mmu.h>
4914 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
4915 index 4aad413..85d86bf 100644
4916 --- a/arch/powerpc/include/asm/pte-hash32.h
4917 +++ b/arch/powerpc/include/asm/pte-hash32.h
4918 @@ -21,6 +21,7 @@
4919 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
4920 #define _PAGE_USER 0x004 /* usermode access allowed */
4921 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
4922 +#define _PAGE_EXEC _PAGE_GUARDED
4923 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
4924 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
4925 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
4926 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
4927 index d24c141..b60696e 100644
4928 --- a/arch/powerpc/include/asm/reg.h
4929 +++ b/arch/powerpc/include/asm/reg.h
4930 @@ -215,6 +215,7 @@
4931 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
4932 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
4933 #define DSISR_NOHPTE 0x40000000 /* no translation found */
4934 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
4935 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
4936 #define DSISR_ISSTORE 0x02000000 /* access was a store */
4937 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
4938 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
4939 index 406b7b9..af63426 100644
4940 --- a/arch/powerpc/include/asm/thread_info.h
4941 +++ b/arch/powerpc/include/asm/thread_info.h
4942 @@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
4943 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
4944 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
4945 #define TIF_SINGLESTEP 8 /* singlestepping active */
4946 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
4947 #define TIF_SECCOMP 10 /* secure computing */
4948 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
4949 #define TIF_NOERROR 12 /* Force successful syscall return */
4950 @@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
4951 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
4952 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
4953 for stack store? */
4954 +#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
4955 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
4956 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
4957
4958 /* as above, but as bit values */
4959 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
4960 @@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
4961 #define _TIF_UPROBE (1<<TIF_UPROBE)
4962 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
4963 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
4964 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
4965 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
4966 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
4967 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
4968 + _TIF_GRSEC_SETXID)
4969
4970 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
4971 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
4972 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
4973 index 4db4959..335e00c 100644
4974 --- a/arch/powerpc/include/asm/uaccess.h
4975 +++ b/arch/powerpc/include/asm/uaccess.h
4976 @@ -13,6 +13,8 @@
4977 #define VERIFY_READ 0
4978 #define VERIFY_WRITE 1
4979
4980 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
4981 +
4982 /*
4983 * The fs value determines whether argument validity checking should be
4984 * performed or not. If get_fs() == USER_DS, checking is performed, with
4985 @@ -318,52 +320,6 @@ do { \
4986 extern unsigned long __copy_tofrom_user(void __user *to,
4987 const void __user *from, unsigned long size);
4988
4989 -#ifndef __powerpc64__
4990 -
4991 -static inline unsigned long copy_from_user(void *to,
4992 - const void __user *from, unsigned long n)
4993 -{
4994 - unsigned long over;
4995 -
4996 - if (access_ok(VERIFY_READ, from, n))
4997 - return __copy_tofrom_user((__force void __user *)to, from, n);
4998 - if ((unsigned long)from < TASK_SIZE) {
4999 - over = (unsigned long)from + n - TASK_SIZE;
5000 - return __copy_tofrom_user((__force void __user *)to, from,
5001 - n - over) + over;
5002 - }
5003 - return n;
5004 -}
5005 -
5006 -static inline unsigned long copy_to_user(void __user *to,
5007 - const void *from, unsigned long n)
5008 -{
5009 - unsigned long over;
5010 -
5011 - if (access_ok(VERIFY_WRITE, to, n))
5012 - return __copy_tofrom_user(to, (__force void __user *)from, n);
5013 - if ((unsigned long)to < TASK_SIZE) {
5014 - over = (unsigned long)to + n - TASK_SIZE;
5015 - return __copy_tofrom_user(to, (__force void __user *)from,
5016 - n - over) + over;
5017 - }
5018 - return n;
5019 -}
5020 -
5021 -#else /* __powerpc64__ */
5022 -
5023 -#define __copy_in_user(to, from, size) \
5024 - __copy_tofrom_user((to), (from), (size))
5025 -
5026 -extern unsigned long copy_from_user(void *to, const void __user *from,
5027 - unsigned long n);
5028 -extern unsigned long copy_to_user(void __user *to, const void *from,
5029 - unsigned long n);
5030 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
5031 - unsigned long n);
5032 -
5033 -#endif /* __powerpc64__ */
5034 -
5035 static inline unsigned long __copy_from_user_inatomic(void *to,
5036 const void __user *from, unsigned long n)
5037 {
5038 @@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
5039 if (ret == 0)
5040 return 0;
5041 }
5042 +
5043 + if (!__builtin_constant_p(n))
5044 + check_object_size(to, n, false);
5045 +
5046 return __copy_tofrom_user((__force void __user *)to, from, n);
5047 }
5048
5049 @@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
5050 if (ret == 0)
5051 return 0;
5052 }
5053 +
5054 + if (!__builtin_constant_p(n))
5055 + check_object_size(from, n, true);
5056 +
5057 return __copy_tofrom_user(to, (__force const void __user *)from, n);
5058 }
5059
5060 @@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
5061 return __copy_to_user_inatomic(to, from, size);
5062 }
5063
5064 +#ifndef __powerpc64__
5065 +
5066 +static inline unsigned long __must_check copy_from_user(void *to,
5067 + const void __user *from, unsigned long n)
5068 +{
5069 + unsigned long over;
5070 +
5071 + if ((long)n < 0)
5072 + return n;
5073 +
5074 + if (access_ok(VERIFY_READ, from, n)) {
5075 + if (!__builtin_constant_p(n))
5076 + check_object_size(to, n, false);
5077 + return __copy_tofrom_user((__force void __user *)to, from, n);
5078 + }
5079 + if ((unsigned long)from < TASK_SIZE) {
5080 + over = (unsigned long)from + n - TASK_SIZE;
5081 + if (!__builtin_constant_p(n - over))
5082 + check_object_size(to, n - over, false);
5083 + return __copy_tofrom_user((__force void __user *)to, from,
5084 + n - over) + over;
5085 + }
5086 + return n;
5087 +}
5088 +
5089 +static inline unsigned long __must_check copy_to_user(void __user *to,
5090 + const void *from, unsigned long n)
5091 +{
5092 + unsigned long over;
5093 +
5094 + if ((long)n < 0)
5095 + return n;
5096 +
5097 + if (access_ok(VERIFY_WRITE, to, n)) {
5098 + if (!__builtin_constant_p(n))
5099 + check_object_size(from, n, true);
5100 + return __copy_tofrom_user(to, (__force void __user *)from, n);
5101 + }
5102 + if ((unsigned long)to < TASK_SIZE) {
5103 + over = (unsigned long)to + n - TASK_SIZE;
5104 + if (!__builtin_constant_p(n))
5105 + check_object_size(from, n - over, true);
5106 + return __copy_tofrom_user(to, (__force void __user *)from,
5107 + n - over) + over;
5108 + }
5109 + return n;
5110 +}
5111 +
5112 +#else /* __powerpc64__ */
5113 +
5114 +#define __copy_in_user(to, from, size) \
5115 + __copy_tofrom_user((to), (from), (size))
5116 +
5117 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
5118 +{
5119 + if ((long)n < 0 || n > INT_MAX)
5120 + return n;
5121 +
5122 + if (!__builtin_constant_p(n))
5123 + check_object_size(to, n, false);
5124 +
5125 + if (likely(access_ok(VERIFY_READ, from, n)))
5126 + n = __copy_from_user(to, from, n);
5127 + else
5128 + memset(to, 0, n);
5129 + return n;
5130 +}
5131 +
5132 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
5133 +{
5134 + if ((long)n < 0 || n > INT_MAX)
5135 + return n;
5136 +
5137 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
5138 + if (!__builtin_constant_p(n))
5139 + check_object_size(from, n, true);
5140 + n = __copy_to_user(to, from, n);
5141 + }
5142 + return n;
5143 +}
5144 +
5145 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
5146 + unsigned long n);
5147 +
5148 +#endif /* __powerpc64__ */
5149 +
5150 extern unsigned long __clear_user(void __user *addr, unsigned long size);
5151
5152 static inline unsigned long clear_user(void __user *addr, unsigned long size)
5153 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
5154 index 4684e33..acc4d19e 100644
5155 --- a/arch/powerpc/kernel/exceptions-64e.S
5156 +++ b/arch/powerpc/kernel/exceptions-64e.S
5157 @@ -715,6 +715,7 @@ storage_fault_common:
5158 std r14,_DAR(r1)
5159 std r15,_DSISR(r1)
5160 addi r3,r1,STACK_FRAME_OVERHEAD
5161 + bl .save_nvgprs
5162 mr r4,r14
5163 mr r5,r15
5164 ld r14,PACA_EXGEN+EX_R14(r13)
5165 @@ -723,8 +724,7 @@ storage_fault_common:
5166 cmpdi r3,0
5167 bne- 1f
5168 b .ret_from_except_lite
5169 -1: bl .save_nvgprs
5170 - mr r5,r3
5171 +1: mr r5,r3
5172 addi r3,r1,STACK_FRAME_OVERHEAD
5173 ld r4,_DAR(r1)
5174 bl .bad_page_fault
5175 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
5176 index 10b658a..e542888 100644
5177 --- a/arch/powerpc/kernel/exceptions-64s.S
5178 +++ b/arch/powerpc/kernel/exceptions-64s.S
5179 @@ -1013,10 +1013,10 @@ handle_page_fault:
5180 11: ld r4,_DAR(r1)
5181 ld r5,_DSISR(r1)
5182 addi r3,r1,STACK_FRAME_OVERHEAD
5183 + bl .save_nvgprs
5184 bl .do_page_fault
5185 cmpdi r3,0
5186 beq+ 12f
5187 - bl .save_nvgprs
5188 mr r5,r3
5189 addi r3,r1,STACK_FRAME_OVERHEAD
5190 lwz r4,_DAR(r1)
5191 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
5192 index 2e3200c..72095ce 100644
5193 --- a/arch/powerpc/kernel/module_32.c
5194 +++ b/arch/powerpc/kernel/module_32.c
5195 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
5196 me->arch.core_plt_section = i;
5197 }
5198 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
5199 - printk("Module doesn't contain .plt or .init.plt sections.\n");
5200 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
5201 return -ENOEXEC;
5202 }
5203
5204 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
5205
5206 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
5207 /* Init, or core PLT? */
5208 - if (location >= mod->module_core
5209 - && location < mod->module_core + mod->core_size)
5210 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
5211 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
5212 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
5213 - else
5214 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
5215 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
5216 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
5217 + else {
5218 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
5219 + return ~0UL;
5220 + }
5221
5222 /* Find this entry, or if that fails, the next avail. entry */
5223 while (entry->jump[0]) {
5224 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
5225 index ba48233..16ac31d 100644
5226 --- a/arch/powerpc/kernel/process.c
5227 +++ b/arch/powerpc/kernel/process.c
5228 @@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
5229 * Lookup NIP late so we have the best change of getting the
5230 * above info out without failing
5231 */
5232 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
5233 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
5234 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
5235 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
5236 #endif
5237 show_stack(current, (unsigned long *) regs->gpr[1]);
5238 if (!user_mode(regs))
5239 @@ -1175,10 +1175,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5240 newsp = stack[0];
5241 ip = stack[STACK_FRAME_LR_SAVE];
5242 if (!firstframe || ip != lr) {
5243 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
5244 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
5245 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
5246 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
5247 - printk(" (%pS)",
5248 + printk(" (%pA)",
5249 (void *)current->ret_stack[curr_frame].ret);
5250 curr_frame--;
5251 }
5252 @@ -1198,7 +1198,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5253 struct pt_regs *regs = (struct pt_regs *)
5254 (sp + STACK_FRAME_OVERHEAD);
5255 lr = regs->link;
5256 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
5257 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
5258 regs->trap, (void *)regs->nip, (void *)lr);
5259 firstframe = 1;
5260 }
5261 @@ -1240,58 +1240,3 @@ void __ppc64_runlatch_off(void)
5262 mtspr(SPRN_CTRLT, ctrl);
5263 }
5264 #endif /* CONFIG_PPC64 */
5265 -
5266 -unsigned long arch_align_stack(unsigned long sp)
5267 -{
5268 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5269 - sp -= get_random_int() & ~PAGE_MASK;
5270 - return sp & ~0xf;
5271 -}
5272 -
5273 -static inline unsigned long brk_rnd(void)
5274 -{
5275 - unsigned long rnd = 0;
5276 -
5277 - /* 8MB for 32bit, 1GB for 64bit */
5278 - if (is_32bit_task())
5279 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
5280 - else
5281 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
5282 -
5283 - return rnd << PAGE_SHIFT;
5284 -}
5285 -
5286 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5287 -{
5288 - unsigned long base = mm->brk;
5289 - unsigned long ret;
5290 -
5291 -#ifdef CONFIG_PPC_STD_MMU_64
5292 - /*
5293 - * If we are using 1TB segments and we are allowed to randomise
5294 - * the heap, we can put it above 1TB so it is backed by a 1TB
5295 - * segment. Otherwise the heap will be in the bottom 1TB
5296 - * which always uses 256MB segments and this may result in a
5297 - * performance penalty.
5298 - */
5299 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
5300 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
5301 -#endif
5302 -
5303 - ret = PAGE_ALIGN(base + brk_rnd());
5304 -
5305 - if (ret < mm->brk)
5306 - return mm->brk;
5307 -
5308 - return ret;
5309 -}
5310 -
5311 -unsigned long randomize_et_dyn(unsigned long base)
5312 -{
5313 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5314 -
5315 - if (ret < base)
5316 - return base;
5317 -
5318 - return ret;
5319 -}
5320 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
5321 index 79d8e56..38ffcbb 100644
5322 --- a/arch/powerpc/kernel/ptrace.c
5323 +++ b/arch/powerpc/kernel/ptrace.c
5324 @@ -1663,6 +1663,10 @@ long arch_ptrace(struct task_struct *child, long request,
5325 return ret;
5326 }
5327
5328 +#ifdef CONFIG_GRKERNSEC_SETXID
5329 +extern void gr_delayed_cred_worker(void);
5330 +#endif
5331 +
5332 /*
5333 * We must return the syscall number to actually look up in the table.
5334 * This can be -1L to skip running any syscall at all.
5335 @@ -1673,6 +1677,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
5336
5337 secure_computing_strict(regs->gpr[0]);
5338
5339 +#ifdef CONFIG_GRKERNSEC_SETXID
5340 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5341 + gr_delayed_cred_worker();
5342 +#endif
5343 +
5344 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
5345 tracehook_report_syscall_entry(regs))
5346 /*
5347 @@ -1707,6 +1716,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
5348 {
5349 int step;
5350
5351 +#ifdef CONFIG_GRKERNSEC_SETXID
5352 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5353 + gr_delayed_cred_worker();
5354 +#endif
5355 +
5356 audit_syscall_exit(regs);
5357
5358 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5359 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
5360 index 804e323..79181c1 100644
5361 --- a/arch/powerpc/kernel/signal_32.c
5362 +++ b/arch/powerpc/kernel/signal_32.c
5363 @@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
5364 /* Save user registers on the stack */
5365 frame = &rt_sf->uc.uc_mcontext;
5366 addr = frame;
5367 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
5368 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5369 if (save_user_regs(regs, frame, 0, 1))
5370 goto badframe;
5371 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
5372 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
5373 index d183f87..1867f1a 100644
5374 --- a/arch/powerpc/kernel/signal_64.c
5375 +++ b/arch/powerpc/kernel/signal_64.c
5376 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
5377 current->thread.fpscr.val = 0;
5378
5379 /* Set up to return from userspace. */
5380 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
5381 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5382 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
5383 } else {
5384 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
5385 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
5386 index 3251840..3f7c77a 100644
5387 --- a/arch/powerpc/kernel/traps.c
5388 +++ b/arch/powerpc/kernel/traps.c
5389 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
5390 return flags;
5391 }
5392
5393 +extern void gr_handle_kernel_exploit(void);
5394 +
5395 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5396 int signr)
5397 {
5398 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5399 panic("Fatal exception in interrupt");
5400 if (panic_on_oops)
5401 panic("Fatal exception");
5402 +
5403 + gr_handle_kernel_exploit();
5404 +
5405 do_exit(signr);
5406 }
5407
5408 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
5409 index 1b2076f..835e4be 100644
5410 --- a/arch/powerpc/kernel/vdso.c
5411 +++ b/arch/powerpc/kernel/vdso.c
5412 @@ -34,6 +34,7 @@
5413 #include <asm/firmware.h>
5414 #include <asm/vdso.h>
5415 #include <asm/vdso_datapage.h>
5416 +#include <asm/mman.h>
5417
5418 #include "setup.h"
5419
5420 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5421 vdso_base = VDSO32_MBASE;
5422 #endif
5423
5424 - current->mm->context.vdso_base = 0;
5425 + current->mm->context.vdso_base = ~0UL;
5426
5427 /* vDSO has a problem and was disabled, just don't "enable" it for the
5428 * process
5429 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5430 vdso_base = get_unmapped_area(NULL, vdso_base,
5431 (vdso_pages << PAGE_SHIFT) +
5432 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
5433 - 0, 0);
5434 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
5435 if (IS_ERR_VALUE(vdso_base)) {
5436 rc = vdso_base;
5437 goto fail_mmapsem;
5438 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
5439 index 5eea6f3..5d10396 100644
5440 --- a/arch/powerpc/lib/usercopy_64.c
5441 +++ b/arch/powerpc/lib/usercopy_64.c
5442 @@ -9,22 +9,6 @@
5443 #include <linux/module.h>
5444 #include <asm/uaccess.h>
5445
5446 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5447 -{
5448 - if (likely(access_ok(VERIFY_READ, from, n)))
5449 - n = __copy_from_user(to, from, n);
5450 - else
5451 - memset(to, 0, n);
5452 - return n;
5453 -}
5454 -
5455 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5456 -{
5457 - if (likely(access_ok(VERIFY_WRITE, to, n)))
5458 - n = __copy_to_user(to, from, n);
5459 - return n;
5460 -}
5461 -
5462 unsigned long copy_in_user(void __user *to, const void __user *from,
5463 unsigned long n)
5464 {
5465 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
5466 return n;
5467 }
5468
5469 -EXPORT_SYMBOL(copy_from_user);
5470 -EXPORT_SYMBOL(copy_to_user);
5471 EXPORT_SYMBOL(copy_in_user);
5472
5473 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
5474 index 0a6b283..7674925 100644
5475 --- a/arch/powerpc/mm/fault.c
5476 +++ b/arch/powerpc/mm/fault.c
5477 @@ -32,6 +32,10 @@
5478 #include <linux/perf_event.h>
5479 #include <linux/magic.h>
5480 #include <linux/ratelimit.h>
5481 +#include <linux/slab.h>
5482 +#include <linux/pagemap.h>
5483 +#include <linux/compiler.h>
5484 +#include <linux/unistd.h>
5485
5486 #include <asm/firmware.h>
5487 #include <asm/page.h>
5488 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
5489 }
5490 #endif
5491
5492 +#ifdef CONFIG_PAX_PAGEEXEC
5493 +/*
5494 + * PaX: decide what to do with offenders (regs->nip = fault address)
5495 + *
5496 + * returns 1 when task should be killed
5497 + */
5498 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5499 +{
5500 + return 1;
5501 +}
5502 +
5503 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5504 +{
5505 + unsigned long i;
5506 +
5507 + printk(KERN_ERR "PAX: bytes at PC: ");
5508 + for (i = 0; i < 5; i++) {
5509 + unsigned int c;
5510 + if (get_user(c, (unsigned int __user *)pc+i))
5511 + printk(KERN_CONT "???????? ");
5512 + else
5513 + printk(KERN_CONT "%08x ", c);
5514 + }
5515 + printk("\n");
5516 +}
5517 +#endif
5518 +
5519 /*
5520 * Check whether the instruction at regs->nip is a store using
5521 * an update addressing form which will update r1.
5522 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
5523 * indicate errors in DSISR but can validly be set in SRR1.
5524 */
5525 if (trap == 0x400)
5526 - error_code &= 0x48200000;
5527 + error_code &= 0x58200000;
5528 else
5529 is_write = error_code & DSISR_ISSTORE;
5530 #else
5531 @@ -367,7 +398,7 @@ good_area:
5532 * "undefined". Of those that can be set, this is the only
5533 * one which seems bad.
5534 */
5535 - if (error_code & 0x10000000)
5536 + if (error_code & DSISR_GUARDED)
5537 /* Guarded storage error. */
5538 goto bad_area;
5539 #endif /* CONFIG_8xx */
5540 @@ -382,7 +413,7 @@ good_area:
5541 * processors use the same I/D cache coherency mechanism
5542 * as embedded.
5543 */
5544 - if (error_code & DSISR_PROTFAULT)
5545 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
5546 goto bad_area;
5547 #endif /* CONFIG_PPC_STD_MMU */
5548
5549 @@ -465,6 +496,23 @@ bad_area:
5550 bad_area_nosemaphore:
5551 /* User mode accesses cause a SIGSEGV */
5552 if (user_mode(regs)) {
5553 +
5554 +#ifdef CONFIG_PAX_PAGEEXEC
5555 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5556 +#ifdef CONFIG_PPC_STD_MMU
5557 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
5558 +#else
5559 + if (is_exec && regs->nip == address) {
5560 +#endif
5561 + switch (pax_handle_fetch_fault(regs)) {
5562 + }
5563 +
5564 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
5565 + do_group_exit(SIGKILL);
5566 + }
5567 + }
5568 +#endif
5569 +
5570 _exception(SIGSEGV, regs, code, address);
5571 return 0;
5572 }
5573 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
5574 index 67a42ed..1c7210c 100644
5575 --- a/arch/powerpc/mm/mmap_64.c
5576 +++ b/arch/powerpc/mm/mmap_64.c
5577 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5578 */
5579 if (mmap_is_legacy()) {
5580 mm->mmap_base = TASK_UNMAPPED_BASE;
5581 +
5582 +#ifdef CONFIG_PAX_RANDMMAP
5583 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5584 + mm->mmap_base += mm->delta_mmap;
5585 +#endif
5586 +
5587 mm->get_unmapped_area = arch_get_unmapped_area;
5588 mm->unmap_area = arch_unmap_area;
5589 } else {
5590 mm->mmap_base = mmap_base();
5591 +
5592 +#ifdef CONFIG_PAX_RANDMMAP
5593 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5594 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5595 +#endif
5596 +
5597 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5598 mm->unmap_area = arch_unmap_area_topdown;
5599 }
5600 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
5601 index 5829d2a..af84242 100644
5602 --- a/arch/powerpc/mm/slice.c
5603 +++ b/arch/powerpc/mm/slice.c
5604 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
5605 if ((mm->task_size - len) < addr)
5606 return 0;
5607 vma = find_vma(mm, addr);
5608 - return (!vma || (addr + len) <= vma->vm_start);
5609 + return check_heap_stack_gap(vma, addr, len, 0);
5610 }
5611
5612 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
5613 @@ -272,7 +272,7 @@ full_search:
5614 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
5615 continue;
5616 }
5617 - if (!vma || addr + len <= vma->vm_start) {
5618 + if (check_heap_stack_gap(vma, addr, len, 0)) {
5619 /*
5620 * Remember the place where we stopped the search:
5621 */
5622 @@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5623 }
5624 }
5625
5626 - addr = mm->mmap_base;
5627 - while (addr > len) {
5628 + if (mm->mmap_base < len)
5629 + addr = -ENOMEM;
5630 + else
5631 + addr = mm->mmap_base - len;
5632 +
5633 + while (!IS_ERR_VALUE(addr)) {
5634 /* Go down by chunk size */
5635 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
5636 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
5637
5638 /* Check for hit with different page size */
5639 mask = slice_range_to_mask(addr, len);
5640 @@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5641 * return with success:
5642 */
5643 vma = find_vma(mm, addr);
5644 - if (!vma || (addr + len) <= vma->vm_start) {
5645 + if (check_heap_stack_gap(vma, addr, len, 0)) {
5646 /* remember the address as a hint for next time */
5647 if (use_cache)
5648 mm->free_area_cache = addr;
5649 @@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5650 mm->cached_hole_size = vma->vm_start - addr;
5651
5652 /* try just below the current vma->vm_start */
5653 - addr = vma->vm_start;
5654 + addr = skip_heap_stack_gap(vma, len, 0);
5655 }
5656
5657 /*
5658 @@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
5659 if (fixed && addr > (mm->task_size - len))
5660 return -EINVAL;
5661
5662 +#ifdef CONFIG_PAX_RANDMMAP
5663 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
5664 + addr = 0;
5665 +#endif
5666 +
5667 /* If hint, make sure it matches our alignment restrictions */
5668 if (!fixed && addr) {
5669 addr = _ALIGN_UP(addr, 1ul << pshift);
5670 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
5671 index c797832..ce575c8 100644
5672 --- a/arch/s390/include/asm/atomic.h
5673 +++ b/arch/s390/include/asm/atomic.h
5674 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
5675 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
5676 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5677
5678 +#define atomic64_read_unchecked(v) atomic64_read(v)
5679 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5680 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5681 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5682 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5683 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5684 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5685 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5686 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5687 +
5688 #define smp_mb__before_atomic_dec() smp_mb()
5689 #define smp_mb__after_atomic_dec() smp_mb()
5690 #define smp_mb__before_atomic_inc() smp_mb()
5691 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
5692 index 4d7ccac..d03d0ad 100644
5693 --- a/arch/s390/include/asm/cache.h
5694 +++ b/arch/s390/include/asm/cache.h
5695 @@ -9,8 +9,10 @@
5696 #ifndef __ARCH_S390_CACHE_H
5697 #define __ARCH_S390_CACHE_H
5698
5699 -#define L1_CACHE_BYTES 256
5700 +#include <linux/const.h>
5701 +
5702 #define L1_CACHE_SHIFT 8
5703 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5704 #define NET_SKB_PAD 32
5705
5706 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5707 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
5708 index 178ff96..8c93bd1 100644
5709 --- a/arch/s390/include/asm/elf.h
5710 +++ b/arch/s390/include/asm/elf.h
5711 @@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
5712 the loader. We need to make sure that it is out of the way of the program
5713 that it will "exec", and that there is sufficient room for the brk. */
5714
5715 -extern unsigned long randomize_et_dyn(unsigned long base);
5716 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
5717 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
5718 +
5719 +#ifdef CONFIG_PAX_ASLR
5720 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
5721 +
5722 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5723 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5724 +#endif
5725
5726 /* This yields a mask that user programs can use to figure out what
5727 instruction set this CPU supports. */
5728 @@ -210,9 +216,6 @@ struct linux_binprm;
5729 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5730 int arch_setup_additional_pages(struct linux_binprm *, int);
5731
5732 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5733 -#define arch_randomize_brk arch_randomize_brk
5734 -
5735 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
5736
5737 #endif
5738 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
5739 index c4a93d6..4d2a9b4 100644
5740 --- a/arch/s390/include/asm/exec.h
5741 +++ b/arch/s390/include/asm/exec.h
5742 @@ -7,6 +7,6 @@
5743 #ifndef __ASM_EXEC_H
5744 #define __ASM_EXEC_H
5745
5746 -extern unsigned long arch_align_stack(unsigned long sp);
5747 +#define arch_align_stack(x) ((x) & ~0xfUL)
5748
5749 #endif /* __ASM_EXEC_H */
5750 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
5751 index 34268df..ea97318 100644
5752 --- a/arch/s390/include/asm/uaccess.h
5753 +++ b/arch/s390/include/asm/uaccess.h
5754 @@ -252,6 +252,10 @@ static inline unsigned long __must_check
5755 copy_to_user(void __user *to, const void *from, unsigned long n)
5756 {
5757 might_fault();
5758 +
5759 + if ((long)n < 0)
5760 + return n;
5761 +
5762 if (access_ok(VERIFY_WRITE, to, n))
5763 n = __copy_to_user(to, from, n);
5764 return n;
5765 @@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
5766 static inline unsigned long __must_check
5767 __copy_from_user(void *to, const void __user *from, unsigned long n)
5768 {
5769 + if ((long)n < 0)
5770 + return n;
5771 +
5772 if (__builtin_constant_p(n) && (n <= 256))
5773 return uaccess.copy_from_user_small(n, from, to);
5774 else
5775 @@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
5776 static inline unsigned long __must_check
5777 copy_from_user(void *to, const void __user *from, unsigned long n)
5778 {
5779 - unsigned int sz = __compiletime_object_size(to);
5780 + size_t sz = __compiletime_object_size(to);
5781
5782 might_fault();
5783 - if (unlikely(sz != -1 && sz < n)) {
5784 +
5785 + if ((long)n < 0)
5786 + return n;
5787 +
5788 + if (unlikely(sz != (size_t)-1 && sz < n)) {
5789 copy_from_user_overflow();
5790 return n;
5791 }
5792 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
5793 index 4610dea..cf0af21 100644
5794 --- a/arch/s390/kernel/module.c
5795 +++ b/arch/s390/kernel/module.c
5796 @@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
5797
5798 /* Increase core size by size of got & plt and set start
5799 offsets for got and plt. */
5800 - me->core_size = ALIGN(me->core_size, 4);
5801 - me->arch.got_offset = me->core_size;
5802 - me->core_size += me->arch.got_size;
5803 - me->arch.plt_offset = me->core_size;
5804 - me->core_size += me->arch.plt_size;
5805 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
5806 + me->arch.got_offset = me->core_size_rw;
5807 + me->core_size_rw += me->arch.got_size;
5808 + me->arch.plt_offset = me->core_size_rx;
5809 + me->core_size_rx += me->arch.plt_size;
5810 return 0;
5811 }
5812
5813 @@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5814 if (info->got_initialized == 0) {
5815 Elf_Addr *gotent;
5816
5817 - gotent = me->module_core + me->arch.got_offset +
5818 + gotent = me->module_core_rw + me->arch.got_offset +
5819 info->got_offset;
5820 *gotent = val;
5821 info->got_initialized = 1;
5822 @@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5823 else if (r_type == R_390_GOTENT ||
5824 r_type == R_390_GOTPLTENT)
5825 *(unsigned int *) loc =
5826 - (val + (Elf_Addr) me->module_core - loc) >> 1;
5827 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
5828 else if (r_type == R_390_GOT64 ||
5829 r_type == R_390_GOTPLT64)
5830 *(unsigned long *) loc = val;
5831 @@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5832 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
5833 if (info->plt_initialized == 0) {
5834 unsigned int *ip;
5835 - ip = me->module_core + me->arch.plt_offset +
5836 + ip = me->module_core_rx + me->arch.plt_offset +
5837 info->plt_offset;
5838 #ifndef CONFIG_64BIT
5839 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
5840 @@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5841 val - loc + 0xffffUL < 0x1ffffeUL) ||
5842 (r_type == R_390_PLT32DBL &&
5843 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
5844 - val = (Elf_Addr) me->module_core +
5845 + val = (Elf_Addr) me->module_core_rx +
5846 me->arch.plt_offset +
5847 info->plt_offset;
5848 val += rela->r_addend - loc;
5849 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5850 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
5851 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
5852 val = val + rela->r_addend -
5853 - ((Elf_Addr) me->module_core + me->arch.got_offset);
5854 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
5855 if (r_type == R_390_GOTOFF16)
5856 *(unsigned short *) loc = val;
5857 else if (r_type == R_390_GOTOFF32)
5858 @@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5859 break;
5860 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
5861 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
5862 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
5863 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
5864 rela->r_addend - loc;
5865 if (r_type == R_390_GOTPC)
5866 *(unsigned int *) loc = val;
5867 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
5868 index cd31ad4..201c5a3 100644
5869 --- a/arch/s390/kernel/process.c
5870 +++ b/arch/s390/kernel/process.c
5871 @@ -283,39 +283,3 @@ unsigned long get_wchan(struct task_struct *p)
5872 }
5873 return 0;
5874 }
5875 -
5876 -unsigned long arch_align_stack(unsigned long sp)
5877 -{
5878 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5879 - sp -= get_random_int() & ~PAGE_MASK;
5880 - return sp & ~0xf;
5881 -}
5882 -
5883 -static inline unsigned long brk_rnd(void)
5884 -{
5885 - /* 8MB for 32bit, 1GB for 64bit */
5886 - if (is_32bit_task())
5887 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
5888 - else
5889 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
5890 -}
5891 -
5892 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5893 -{
5894 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
5895 -
5896 - if (ret < mm->brk)
5897 - return mm->brk;
5898 - return ret;
5899 -}
5900 -
5901 -unsigned long randomize_et_dyn(unsigned long base)
5902 -{
5903 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5904 -
5905 - if (!(current->flags & PF_RANDOMIZE))
5906 - return base;
5907 - if (ret < base)
5908 - return base;
5909 - return ret;
5910 -}
5911 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
5912 index c59a5ef..3fae59c 100644
5913 --- a/arch/s390/mm/mmap.c
5914 +++ b/arch/s390/mm/mmap.c
5915 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5916 */
5917 if (mmap_is_legacy()) {
5918 mm->mmap_base = TASK_UNMAPPED_BASE;
5919 +
5920 +#ifdef CONFIG_PAX_RANDMMAP
5921 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5922 + mm->mmap_base += mm->delta_mmap;
5923 +#endif
5924 +
5925 mm->get_unmapped_area = arch_get_unmapped_area;
5926 mm->unmap_area = arch_unmap_area;
5927 } else {
5928 mm->mmap_base = mmap_base();
5929 +
5930 +#ifdef CONFIG_PAX_RANDMMAP
5931 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5932 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5933 +#endif
5934 +
5935 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5936 mm->unmap_area = arch_unmap_area_topdown;
5937 }
5938 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5939 */
5940 if (mmap_is_legacy()) {
5941 mm->mmap_base = TASK_UNMAPPED_BASE;
5942 +
5943 +#ifdef CONFIG_PAX_RANDMMAP
5944 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5945 + mm->mmap_base += mm->delta_mmap;
5946 +#endif
5947 +
5948 mm->get_unmapped_area = s390_get_unmapped_area;
5949 mm->unmap_area = arch_unmap_area;
5950 } else {
5951 mm->mmap_base = mmap_base();
5952 +
5953 +#ifdef CONFIG_PAX_RANDMMAP
5954 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5955 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5956 +#endif
5957 +
5958 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
5959 mm->unmap_area = arch_unmap_area_topdown;
5960 }
5961 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
5962 index ae3d59f..f65f075 100644
5963 --- a/arch/score/include/asm/cache.h
5964 +++ b/arch/score/include/asm/cache.h
5965 @@ -1,7 +1,9 @@
5966 #ifndef _ASM_SCORE_CACHE_H
5967 #define _ASM_SCORE_CACHE_H
5968
5969 +#include <linux/const.h>
5970 +
5971 #define L1_CACHE_SHIFT 4
5972 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5973 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5974
5975 #endif /* _ASM_SCORE_CACHE_H */
5976 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
5977 index f9f3cd5..58ff438 100644
5978 --- a/arch/score/include/asm/exec.h
5979 +++ b/arch/score/include/asm/exec.h
5980 @@ -1,6 +1,6 @@
5981 #ifndef _ASM_SCORE_EXEC_H
5982 #define _ASM_SCORE_EXEC_H
5983
5984 -extern unsigned long arch_align_stack(unsigned long sp);
5985 +#define arch_align_stack(x) (x)
5986
5987 #endif /* _ASM_SCORE_EXEC_H */
5988 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
5989 index 637970c..0b6556b 100644
5990 --- a/arch/score/kernel/process.c
5991 +++ b/arch/score/kernel/process.c
5992 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
5993
5994 return task_pt_regs(task)->cp0_epc;
5995 }
5996 -
5997 -unsigned long arch_align_stack(unsigned long sp)
5998 -{
5999 - return sp;
6000 -}
6001 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
6002 index ef9e555..331bd29 100644
6003 --- a/arch/sh/include/asm/cache.h
6004 +++ b/arch/sh/include/asm/cache.h
6005 @@ -9,10 +9,11 @@
6006 #define __ASM_SH_CACHE_H
6007 #ifdef __KERNEL__
6008
6009 +#include <linux/const.h>
6010 #include <linux/init.h>
6011 #include <cpu/cache.h>
6012
6013 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6014 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6015
6016 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
6017
6018 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
6019 index afeb710..e8366ef 100644
6020 --- a/arch/sh/mm/mmap.c
6021 +++ b/arch/sh/mm/mmap.c
6022 @@ -49,6 +49,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6023 struct vm_area_struct *vma;
6024 unsigned long start_addr;
6025 int do_colour_align;
6026 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6027
6028 if (flags & MAP_FIXED) {
6029 /* We do not accept a shared mapping if it would violate
6030 @@ -74,8 +75,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6031 addr = PAGE_ALIGN(addr);
6032
6033 vma = find_vma(mm, addr);
6034 - if (TASK_SIZE - len >= addr &&
6035 - (!vma || addr + len <= vma->vm_start))
6036 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6037 return addr;
6038 }
6039
6040 @@ -106,7 +106,7 @@ full_search:
6041 }
6042 return -ENOMEM;
6043 }
6044 - if (likely(!vma || addr + len <= vma->vm_start)) {
6045 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6046 /*
6047 * Remember the place where we stopped the search:
6048 */
6049 @@ -131,6 +131,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6050 struct mm_struct *mm = current->mm;
6051 unsigned long addr = addr0;
6052 int do_colour_align;
6053 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6054
6055 if (flags & MAP_FIXED) {
6056 /* We do not accept a shared mapping if it would violate
6057 @@ -157,8 +158,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6058 addr = PAGE_ALIGN(addr);
6059
6060 vma = find_vma(mm, addr);
6061 - if (TASK_SIZE - len >= addr &&
6062 - (!vma || addr + len <= vma->vm_start))
6063 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6064 return addr;
6065 }
6066
6067 @@ -179,7 +179,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6068 /* make sure it can fit in the remaining address space */
6069 if (likely(addr > len)) {
6070 vma = find_vma(mm, addr-len);
6071 - if (!vma || addr <= vma->vm_start) {
6072 + if (check_heap_stack_gap(vma, addr - len, len, offset)) {
6073 /* remember the address as a hint for next time */
6074 return (mm->free_area_cache = addr-len);
6075 }
6076 @@ -188,18 +188,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6077 if (unlikely(mm->mmap_base < len))
6078 goto bottomup;
6079
6080 - addr = mm->mmap_base-len;
6081 - if (do_colour_align)
6082 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6083 + addr = mm->mmap_base - len;
6084
6085 do {
6086 + if (do_colour_align)
6087 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6088 /*
6089 * Lookup failure means no vma is above this address,
6090 * else if new region fits below vma->vm_start,
6091 * return with success:
6092 */
6093 vma = find_vma(mm, addr);
6094 - if (likely(!vma || addr+len <= vma->vm_start)) {
6095 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6096 /* remember the address as a hint for next time */
6097 return (mm->free_area_cache = addr);
6098 }
6099 @@ -209,10 +209,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6100 mm->cached_hole_size = vma->vm_start - addr;
6101
6102 /* try just below the current vma->vm_start */
6103 - addr = vma->vm_start-len;
6104 - if (do_colour_align)
6105 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6106 - } while (likely(len < vma->vm_start));
6107 + addr = skip_heap_stack_gap(vma, len, offset);
6108 + } while (!IS_ERR_VALUE(addr));
6109
6110 bottomup:
6111 /*
6112 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
6113 index be56a24..443328f 100644
6114 --- a/arch/sparc/include/asm/atomic_64.h
6115 +++ b/arch/sparc/include/asm/atomic_64.h
6116 @@ -14,18 +14,40 @@
6117 #define ATOMIC64_INIT(i) { (i) }
6118
6119 #define atomic_read(v) (*(volatile int *)&(v)->counter)
6120 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6121 +{
6122 + return v->counter;
6123 +}
6124 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
6125 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6126 +{
6127 + return v->counter;
6128 +}
6129
6130 #define atomic_set(v, i) (((v)->counter) = i)
6131 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6132 +{
6133 + v->counter = i;
6134 +}
6135 #define atomic64_set(v, i) (((v)->counter) = i)
6136 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6137 +{
6138 + v->counter = i;
6139 +}
6140
6141 extern void atomic_add(int, atomic_t *);
6142 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
6143 extern void atomic64_add(long, atomic64_t *);
6144 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
6145 extern void atomic_sub(int, atomic_t *);
6146 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
6147 extern void atomic64_sub(long, atomic64_t *);
6148 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
6149
6150 extern int atomic_add_ret(int, atomic_t *);
6151 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
6152 extern long atomic64_add_ret(long, atomic64_t *);
6153 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
6154 extern int atomic_sub_ret(int, atomic_t *);
6155 extern long atomic64_sub_ret(long, atomic64_t *);
6156
6157 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6158 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
6159
6160 #define atomic_inc_return(v) atomic_add_ret(1, v)
6161 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6162 +{
6163 + return atomic_add_ret_unchecked(1, v);
6164 +}
6165 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
6166 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
6167 +{
6168 + return atomic64_add_ret_unchecked(1, v);
6169 +}
6170
6171 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
6172 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
6173
6174 #define atomic_add_return(i, v) atomic_add_ret(i, v)
6175 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6176 +{
6177 + return atomic_add_ret_unchecked(i, v);
6178 +}
6179 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
6180 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6181 +{
6182 + return atomic64_add_ret_unchecked(i, v);
6183 +}
6184
6185 /*
6186 * atomic_inc_and_test - increment and test
6187 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6188 * other cases.
6189 */
6190 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6191 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6192 +{
6193 + return atomic_inc_return_unchecked(v) == 0;
6194 +}
6195 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6196
6197 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
6198 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6199 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
6200
6201 #define atomic_inc(v) atomic_add(1, v)
6202 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
6203 +{
6204 + atomic_add_unchecked(1, v);
6205 +}
6206 #define atomic64_inc(v) atomic64_add(1, v)
6207 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
6208 +{
6209 + atomic64_add_unchecked(1, v);
6210 +}
6211
6212 #define atomic_dec(v) atomic_sub(1, v)
6213 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
6214 +{
6215 + atomic_sub_unchecked(1, v);
6216 +}
6217 #define atomic64_dec(v) atomic64_sub(1, v)
6218 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
6219 +{
6220 + atomic64_sub_unchecked(1, v);
6221 +}
6222
6223 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
6224 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
6225
6226 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6227 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
6228 +{
6229 + return cmpxchg(&v->counter, old, new);
6230 +}
6231 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
6232 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6233 +{
6234 + return xchg(&v->counter, new);
6235 +}
6236
6237 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6238 {
6239 - int c, old;
6240 + int c, old, new;
6241 c = atomic_read(v);
6242 for (;;) {
6243 - if (unlikely(c == (u)))
6244 + if (unlikely(c == u))
6245 break;
6246 - old = atomic_cmpxchg((v), c, c + (a));
6247 +
6248 + asm volatile("addcc %2, %0, %0\n"
6249 +
6250 +#ifdef CONFIG_PAX_REFCOUNT
6251 + "tvs %%icc, 6\n"
6252 +#endif
6253 +
6254 + : "=r" (new)
6255 + : "0" (c), "ir" (a)
6256 + : "cc");
6257 +
6258 + old = atomic_cmpxchg(v, c, new);
6259 if (likely(old == c))
6260 break;
6261 c = old;
6262 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6263 #define atomic64_cmpxchg(v, o, n) \
6264 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6265 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
6266 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6267 +{
6268 + return xchg(&v->counter, new);
6269 +}
6270
6271 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
6272 {
6273 - long c, old;
6274 + long c, old, new;
6275 c = atomic64_read(v);
6276 for (;;) {
6277 - if (unlikely(c == (u)))
6278 + if (unlikely(c == u))
6279 break;
6280 - old = atomic64_cmpxchg((v), c, c + (a));
6281 +
6282 + asm volatile("addcc %2, %0, %0\n"
6283 +
6284 +#ifdef CONFIG_PAX_REFCOUNT
6285 + "tvs %%xcc, 6\n"
6286 +#endif
6287 +
6288 + : "=r" (new)
6289 + : "0" (c), "ir" (a)
6290 + : "cc");
6291 +
6292 + old = atomic64_cmpxchg(v, c, new);
6293 if (likely(old == c))
6294 break;
6295 c = old;
6296 }
6297 - return c != (u);
6298 + return c != u;
6299 }
6300
6301 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6302 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
6303 index 5bb6991..5c2132e 100644
6304 --- a/arch/sparc/include/asm/cache.h
6305 +++ b/arch/sparc/include/asm/cache.h
6306 @@ -7,10 +7,12 @@
6307 #ifndef _SPARC_CACHE_H
6308 #define _SPARC_CACHE_H
6309
6310 +#include <linux/const.h>
6311 +
6312 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
6313
6314 #define L1_CACHE_SHIFT 5
6315 -#define L1_CACHE_BYTES 32
6316 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6317
6318 #ifdef CONFIG_SPARC32
6319 #define SMP_CACHE_BYTES_SHIFT 5
6320 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
6321 index ac74a2c..a9e58af 100644
6322 --- a/arch/sparc/include/asm/elf_32.h
6323 +++ b/arch/sparc/include/asm/elf_32.h
6324 @@ -114,6 +114,13 @@ typedef struct {
6325
6326 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
6327
6328 +#ifdef CONFIG_PAX_ASLR
6329 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
6330 +
6331 +#define PAX_DELTA_MMAP_LEN 16
6332 +#define PAX_DELTA_STACK_LEN 16
6333 +#endif
6334 +
6335 /* This yields a mask that user programs can use to figure out what
6336 instruction set this cpu supports. This can NOT be done in userspace
6337 on Sparc. */
6338 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
6339 index 370ca1e..d4f4a98 100644
6340 --- a/arch/sparc/include/asm/elf_64.h
6341 +++ b/arch/sparc/include/asm/elf_64.h
6342 @@ -189,6 +189,13 @@ typedef struct {
6343 #define ELF_ET_DYN_BASE 0x0000010000000000UL
6344 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
6345
6346 +#ifdef CONFIG_PAX_ASLR
6347 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
6348 +
6349 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
6350 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
6351 +#endif
6352 +
6353 extern unsigned long sparc64_elf_hwcap;
6354 #define ELF_HWCAP sparc64_elf_hwcap
6355
6356 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
6357 index 9b1c36d..209298b 100644
6358 --- a/arch/sparc/include/asm/pgalloc_32.h
6359 +++ b/arch/sparc/include/asm/pgalloc_32.h
6360 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
6361 }
6362
6363 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
6364 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
6365
6366 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
6367 unsigned long address)
6368 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
6369 index bcfe063..b333142 100644
6370 --- a/arch/sparc/include/asm/pgalloc_64.h
6371 +++ b/arch/sparc/include/asm/pgalloc_64.h
6372 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6373 }
6374
6375 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
6376 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
6377
6378 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
6379 {
6380 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
6381 index 6fc1348..390c50a 100644
6382 --- a/arch/sparc/include/asm/pgtable_32.h
6383 +++ b/arch/sparc/include/asm/pgtable_32.h
6384 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
6385 #define PAGE_SHARED SRMMU_PAGE_SHARED
6386 #define PAGE_COPY SRMMU_PAGE_COPY
6387 #define PAGE_READONLY SRMMU_PAGE_RDONLY
6388 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
6389 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
6390 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
6391 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
6392
6393 /* Top-level page directory - dummy used by init-mm.
6394 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
6395
6396 /* xwr */
6397 #define __P000 PAGE_NONE
6398 -#define __P001 PAGE_READONLY
6399 -#define __P010 PAGE_COPY
6400 -#define __P011 PAGE_COPY
6401 +#define __P001 PAGE_READONLY_NOEXEC
6402 +#define __P010 PAGE_COPY_NOEXEC
6403 +#define __P011 PAGE_COPY_NOEXEC
6404 #define __P100 PAGE_READONLY
6405 #define __P101 PAGE_READONLY
6406 #define __P110 PAGE_COPY
6407 #define __P111 PAGE_COPY
6408
6409 #define __S000 PAGE_NONE
6410 -#define __S001 PAGE_READONLY
6411 -#define __S010 PAGE_SHARED
6412 -#define __S011 PAGE_SHARED
6413 +#define __S001 PAGE_READONLY_NOEXEC
6414 +#define __S010 PAGE_SHARED_NOEXEC
6415 +#define __S011 PAGE_SHARED_NOEXEC
6416 #define __S100 PAGE_READONLY
6417 #define __S101 PAGE_READONLY
6418 #define __S110 PAGE_SHARED
6419 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
6420 index 79da178..c2eede8 100644
6421 --- a/arch/sparc/include/asm/pgtsrmmu.h
6422 +++ b/arch/sparc/include/asm/pgtsrmmu.h
6423 @@ -115,6 +115,11 @@
6424 SRMMU_EXEC | SRMMU_REF)
6425 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
6426 SRMMU_EXEC | SRMMU_REF)
6427 +
6428 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
6429 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6430 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6431 +
6432 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
6433 SRMMU_DIRTY | SRMMU_REF)
6434
6435 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
6436 index 9689176..63c18ea 100644
6437 --- a/arch/sparc/include/asm/spinlock_64.h
6438 +++ b/arch/sparc/include/asm/spinlock_64.h
6439 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
6440
6441 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
6442
6443 -static void inline arch_read_lock(arch_rwlock_t *lock)
6444 +static inline void arch_read_lock(arch_rwlock_t *lock)
6445 {
6446 unsigned long tmp1, tmp2;
6447
6448 __asm__ __volatile__ (
6449 "1: ldsw [%2], %0\n"
6450 " brlz,pn %0, 2f\n"
6451 -"4: add %0, 1, %1\n"
6452 +"4: addcc %0, 1, %1\n"
6453 +
6454 +#ifdef CONFIG_PAX_REFCOUNT
6455 +" tvs %%icc, 6\n"
6456 +#endif
6457 +
6458 " cas [%2], %0, %1\n"
6459 " cmp %0, %1\n"
6460 " bne,pn %%icc, 1b\n"
6461 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
6462 " .previous"
6463 : "=&r" (tmp1), "=&r" (tmp2)
6464 : "r" (lock)
6465 - : "memory");
6466 + : "memory", "cc");
6467 }
6468
6469 -static int inline arch_read_trylock(arch_rwlock_t *lock)
6470 +static inline int arch_read_trylock(arch_rwlock_t *lock)
6471 {
6472 int tmp1, tmp2;
6473
6474 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6475 "1: ldsw [%2], %0\n"
6476 " brlz,a,pn %0, 2f\n"
6477 " mov 0, %0\n"
6478 -" add %0, 1, %1\n"
6479 +" addcc %0, 1, %1\n"
6480 +
6481 +#ifdef CONFIG_PAX_REFCOUNT
6482 +" tvs %%icc, 6\n"
6483 +#endif
6484 +
6485 " cas [%2], %0, %1\n"
6486 " cmp %0, %1\n"
6487 " bne,pn %%icc, 1b\n"
6488 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6489 return tmp1;
6490 }
6491
6492 -static void inline arch_read_unlock(arch_rwlock_t *lock)
6493 +static inline void arch_read_unlock(arch_rwlock_t *lock)
6494 {
6495 unsigned long tmp1, tmp2;
6496
6497 __asm__ __volatile__(
6498 "1: lduw [%2], %0\n"
6499 -" sub %0, 1, %1\n"
6500 +" subcc %0, 1, %1\n"
6501 +
6502 +#ifdef CONFIG_PAX_REFCOUNT
6503 +" tvs %%icc, 6\n"
6504 +#endif
6505 +
6506 " cas [%2], %0, %1\n"
6507 " cmp %0, %1\n"
6508 " bne,pn %%xcc, 1b\n"
6509 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
6510 : "memory");
6511 }
6512
6513 -static void inline arch_write_lock(arch_rwlock_t *lock)
6514 +static inline void arch_write_lock(arch_rwlock_t *lock)
6515 {
6516 unsigned long mask, tmp1, tmp2;
6517
6518 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
6519 : "memory");
6520 }
6521
6522 -static void inline arch_write_unlock(arch_rwlock_t *lock)
6523 +static inline void arch_write_unlock(arch_rwlock_t *lock)
6524 {
6525 __asm__ __volatile__(
6526 " stw %%g0, [%0]"
6527 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
6528 : "memory");
6529 }
6530
6531 -static int inline arch_write_trylock(arch_rwlock_t *lock)
6532 +static inline int arch_write_trylock(arch_rwlock_t *lock)
6533 {
6534 unsigned long mask, tmp1, tmp2, result;
6535
6536 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
6537 index 25849ae..924c54b 100644
6538 --- a/arch/sparc/include/asm/thread_info_32.h
6539 +++ b/arch/sparc/include/asm/thread_info_32.h
6540 @@ -49,6 +49,8 @@ struct thread_info {
6541 unsigned long w_saved;
6542
6543 struct restart_block restart_block;
6544 +
6545 + unsigned long lowest_stack;
6546 };
6547
6548 /*
6549 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
6550 index a3fe4dc..cae132a 100644
6551 --- a/arch/sparc/include/asm/thread_info_64.h
6552 +++ b/arch/sparc/include/asm/thread_info_64.h
6553 @@ -63,6 +63,8 @@ struct thread_info {
6554 struct pt_regs *kern_una_regs;
6555 unsigned int kern_una_insn;
6556
6557 + unsigned long lowest_stack;
6558 +
6559 unsigned long fpregs[0] __attribute__ ((aligned(64)));
6560 };
6561
6562 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
6563 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
6564 /* flag bit 6 is available */
6565 #define TIF_32BIT 7 /* 32-bit binary */
6566 -/* flag bit 8 is available */
6567 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
6568 #define TIF_SECCOMP 9 /* secure computing */
6569 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
6570 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
6571 +
6572 /* NOTE: Thread flags >= 12 should be ones we have no interest
6573 * in using in assembly, else we can't use the mask as
6574 * an immediate value in instructions such as andcc.
6575 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
6576 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
6577 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6578 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
6579 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6580
6581 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
6582 _TIF_DO_NOTIFY_RESUME_MASK | \
6583 _TIF_NEED_RESCHED)
6584 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
6585
6586 +#define _TIF_WORK_SYSCALL \
6587 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
6588 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6589 +
6590 +
6591 /*
6592 * Thread-synchronous status.
6593 *
6594 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
6595 index 0167d26..9acd8ed 100644
6596 --- a/arch/sparc/include/asm/uaccess.h
6597 +++ b/arch/sparc/include/asm/uaccess.h
6598 @@ -1,5 +1,13 @@
6599 #ifndef ___ASM_SPARC_UACCESS_H
6600 #define ___ASM_SPARC_UACCESS_H
6601 +
6602 +#ifdef __KERNEL__
6603 +#ifndef __ASSEMBLY__
6604 +#include <linux/types.h>
6605 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
6606 +#endif
6607 +#endif
6608 +
6609 #if defined(__sparc__) && defined(__arch64__)
6610 #include <asm/uaccess_64.h>
6611 #else
6612 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
6613 index 53a28dd..50c38c3 100644
6614 --- a/arch/sparc/include/asm/uaccess_32.h
6615 +++ b/arch/sparc/include/asm/uaccess_32.h
6616 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
6617
6618 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6619 {
6620 - if (n && __access_ok((unsigned long) to, n))
6621 + if ((long)n < 0)
6622 + return n;
6623 +
6624 + if (n && __access_ok((unsigned long) to, n)) {
6625 + if (!__builtin_constant_p(n))
6626 + check_object_size(from, n, true);
6627 return __copy_user(to, (__force void __user *) from, n);
6628 - else
6629 + } else
6630 return n;
6631 }
6632
6633 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
6634 {
6635 + if ((long)n < 0)
6636 + return n;
6637 +
6638 + if (!__builtin_constant_p(n))
6639 + check_object_size(from, n, true);
6640 +
6641 return __copy_user(to, (__force void __user *) from, n);
6642 }
6643
6644 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6645 {
6646 - if (n && __access_ok((unsigned long) from, n))
6647 + if ((long)n < 0)
6648 + return n;
6649 +
6650 + if (n && __access_ok((unsigned long) from, n)) {
6651 + if (!__builtin_constant_p(n))
6652 + check_object_size(to, n, false);
6653 return __copy_user((__force void __user *) to, from, n);
6654 - else
6655 + } else
6656 return n;
6657 }
6658
6659 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
6660 {
6661 + if ((long)n < 0)
6662 + return n;
6663 +
6664 return __copy_user((__force void __user *) to, from, n);
6665 }
6666
6667 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
6668 index 73083e1..2bc62a6 100644
6669 --- a/arch/sparc/include/asm/uaccess_64.h
6670 +++ b/arch/sparc/include/asm/uaccess_64.h
6671 @@ -10,6 +10,7 @@
6672 #include <linux/compiler.h>
6673 #include <linux/string.h>
6674 #include <linux/thread_info.h>
6675 +#include <linux/kernel.h>
6676 #include <asm/asi.h>
6677 #include <asm/spitfire.h>
6678 #include <asm-generic/uaccess-unaligned.h>
6679 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
6680 static inline unsigned long __must_check
6681 copy_from_user(void *to, const void __user *from, unsigned long size)
6682 {
6683 - unsigned long ret = ___copy_from_user(to, from, size);
6684 + unsigned long ret;
6685
6686 + if ((long)size < 0 || size > INT_MAX)
6687 + return size;
6688 +
6689 + if (!__builtin_constant_p(size))
6690 + check_object_size(to, size, false);
6691 +
6692 + ret = ___copy_from_user(to, from, size);
6693 if (unlikely(ret))
6694 ret = copy_from_user_fixup(to, from, size);
6695
6696 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
6697 static inline unsigned long __must_check
6698 copy_to_user(void __user *to, const void *from, unsigned long size)
6699 {
6700 - unsigned long ret = ___copy_to_user(to, from, size);
6701 + unsigned long ret;
6702
6703 + if ((long)size < 0 || size > INT_MAX)
6704 + return size;
6705 +
6706 + if (!__builtin_constant_p(size))
6707 + check_object_size(from, size, true);
6708 +
6709 + ret = ___copy_to_user(to, from, size);
6710 if (unlikely(ret))
6711 ret = copy_to_user_fixup(to, from, size);
6712 return ret;
6713 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
6714 index 6cf591b..b49e65a 100644
6715 --- a/arch/sparc/kernel/Makefile
6716 +++ b/arch/sparc/kernel/Makefile
6717 @@ -3,7 +3,7 @@
6718 #
6719
6720 asflags-y := -ansi
6721 -ccflags-y := -Werror
6722 +#ccflags-y := -Werror
6723
6724 extra-y := head_$(BITS).o
6725
6726 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
6727 index 487bffb..955a925 100644
6728 --- a/arch/sparc/kernel/process_32.c
6729 +++ b/arch/sparc/kernel/process_32.c
6730 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
6731
6732 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
6733 r->psr, r->pc, r->npc, r->y, print_tainted());
6734 - printk("PC: <%pS>\n", (void *) r->pc);
6735 + printk("PC: <%pA>\n", (void *) r->pc);
6736 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6737 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
6738 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
6739 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6740 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
6741 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
6742 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
6743 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
6744
6745 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6746 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
6747 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6748 rw = (struct reg_window32 *) fp;
6749 pc = rw->ins[7];
6750 printk("[%08lx : ", pc);
6751 - printk("%pS ] ", (void *) pc);
6752 + printk("%pA ] ", (void *) pc);
6753 fp = rw->ins[6];
6754 } while (++count < 16);
6755 printk("\n");
6756 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
6757 index c6e0c29..052832b 100644
6758 --- a/arch/sparc/kernel/process_64.c
6759 +++ b/arch/sparc/kernel/process_64.c
6760 @@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
6761 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
6762 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
6763 if (regs->tstate & TSTATE_PRIV)
6764 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
6765 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
6766 }
6767
6768 void show_regs(struct pt_regs *regs)
6769 {
6770 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
6771 regs->tpc, regs->tnpc, regs->y, print_tainted());
6772 - printk("TPC: <%pS>\n", (void *) regs->tpc);
6773 + printk("TPC: <%pA>\n", (void *) regs->tpc);
6774 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
6775 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
6776 regs->u_regs[3]);
6777 @@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
6778 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
6779 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
6780 regs->u_regs[15]);
6781 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
6782 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
6783 show_regwindow(regs);
6784 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
6785 }
6786 @@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
6787 ((tp && tp->task) ? tp->task->pid : -1));
6788
6789 if (gp->tstate & TSTATE_PRIV) {
6790 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
6791 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
6792 (void *) gp->tpc,
6793 (void *) gp->o7,
6794 (void *) gp->i7,
6795 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
6796 index 7ff45e4..a58f271 100644
6797 --- a/arch/sparc/kernel/ptrace_64.c
6798 +++ b/arch/sparc/kernel/ptrace_64.c
6799 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
6800 return ret;
6801 }
6802
6803 +#ifdef CONFIG_GRKERNSEC_SETXID
6804 +extern void gr_delayed_cred_worker(void);
6805 +#endif
6806 +
6807 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6808 {
6809 int ret = 0;
6810 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6811 /* do the secure computing check first */
6812 secure_computing_strict(regs->u_regs[UREG_G1]);
6813
6814 +#ifdef CONFIG_GRKERNSEC_SETXID
6815 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6816 + gr_delayed_cred_worker();
6817 +#endif
6818 +
6819 if (test_thread_flag(TIF_SYSCALL_TRACE))
6820 ret = tracehook_report_syscall_entry(regs);
6821
6822 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6823
6824 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
6825 {
6826 +#ifdef CONFIG_GRKERNSEC_SETXID
6827 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6828 + gr_delayed_cred_worker();
6829 +#endif
6830 +
6831 audit_syscall_exit(regs);
6832
6833 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6834 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
6835 index 0c9b31b..55a8ba6 100644
6836 --- a/arch/sparc/kernel/sys_sparc_32.c
6837 +++ b/arch/sparc/kernel/sys_sparc_32.c
6838 @@ -39,6 +39,7 @@ asmlinkage unsigned long sys_getpagesize(void)
6839 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
6840 {
6841 struct vm_area_struct * vmm;
6842 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
6843
6844 if (flags & MAP_FIXED) {
6845 /* We do not accept a shared mapping if it would violate
6846 @@ -54,7 +55,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6847 if (len > TASK_SIZE - PAGE_SIZE)
6848 return -ENOMEM;
6849 if (!addr)
6850 - addr = TASK_UNMAPPED_BASE;
6851 + addr = current->mm->mmap_base;
6852
6853 if (flags & MAP_SHARED)
6854 addr = COLOUR_ALIGN(addr);
6855 @@ -65,7 +66,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6856 /* At this point: (!vmm || addr < vmm->vm_end). */
6857 if (TASK_SIZE - PAGE_SIZE - len < addr)
6858 return -ENOMEM;
6859 - if (!vmm || addr + len <= vmm->vm_start)
6860 + if (check_heap_stack_gap(vmm, addr, len, offset))
6861 return addr;
6862 addr = vmm->vm_end;
6863 if (flags & MAP_SHARED)
6864 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
6865 index 878ef3d..609e41f 100644
6866 --- a/arch/sparc/kernel/sys_sparc_64.c
6867 +++ b/arch/sparc/kernel/sys_sparc_64.c
6868 @@ -102,12 +102,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6869 unsigned long task_size = TASK_SIZE;
6870 unsigned long start_addr;
6871 int do_color_align;
6872 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6873
6874 if (flags & MAP_FIXED) {
6875 /* We do not accept a shared mapping if it would violate
6876 * cache aliasing constraints.
6877 */
6878 - if ((flags & MAP_SHARED) &&
6879 + if ((filp || (flags & MAP_SHARED)) &&
6880 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
6881 return -EINVAL;
6882 return addr;
6883 @@ -122,6 +123,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6884 if (filp || (flags & MAP_SHARED))
6885 do_color_align = 1;
6886
6887 +#ifdef CONFIG_PAX_RANDMMAP
6888 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6889 +#endif
6890 +
6891 if (addr) {
6892 if (do_color_align)
6893 addr = COLOUR_ALIGN(addr, pgoff);
6894 @@ -129,15 +134,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6895 addr = PAGE_ALIGN(addr);
6896
6897 vma = find_vma(mm, addr);
6898 - if (task_size - len >= addr &&
6899 - (!vma || addr + len <= vma->vm_start))
6900 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6901 return addr;
6902 }
6903
6904 if (len > mm->cached_hole_size) {
6905 - start_addr = addr = mm->free_area_cache;
6906 + start_addr = addr = mm->free_area_cache;
6907 } else {
6908 - start_addr = addr = TASK_UNMAPPED_BASE;
6909 + start_addr = addr = mm->mmap_base;
6910 mm->cached_hole_size = 0;
6911 }
6912
6913 @@ -157,14 +161,14 @@ full_search:
6914 vma = find_vma(mm, VA_EXCLUDE_END);
6915 }
6916 if (unlikely(task_size < addr)) {
6917 - if (start_addr != TASK_UNMAPPED_BASE) {
6918 - start_addr = addr = TASK_UNMAPPED_BASE;
6919 + if (start_addr != mm->mmap_base) {
6920 + start_addr = addr = mm->mmap_base;
6921 mm->cached_hole_size = 0;
6922 goto full_search;
6923 }
6924 return -ENOMEM;
6925 }
6926 - if (likely(!vma || addr + len <= vma->vm_start)) {
6927 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6928 /*
6929 * Remember the place where we stopped the search:
6930 */
6931 @@ -190,6 +194,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6932 unsigned long task_size = STACK_TOP32;
6933 unsigned long addr = addr0;
6934 int do_color_align;
6935 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6936
6937 /* This should only ever run for 32-bit processes. */
6938 BUG_ON(!test_thread_flag(TIF_32BIT));
6939 @@ -198,7 +203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6940 /* We do not accept a shared mapping if it would violate
6941 * cache aliasing constraints.
6942 */
6943 - if ((flags & MAP_SHARED) &&
6944 + if ((filp || (flags & MAP_SHARED)) &&
6945 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
6946 return -EINVAL;
6947 return addr;
6948 @@ -219,8 +224,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6949 addr = PAGE_ALIGN(addr);
6950
6951 vma = find_vma(mm, addr);
6952 - if (task_size - len >= addr &&
6953 - (!vma || addr + len <= vma->vm_start))
6954 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6955 return addr;
6956 }
6957
6958 @@ -241,7 +245,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6959 /* make sure it can fit in the remaining address space */
6960 if (likely(addr > len)) {
6961 vma = find_vma(mm, addr-len);
6962 - if (!vma || addr <= vma->vm_start) {
6963 + if (check_heap_stack_gap(vma, addr - len, len, offset)) {
6964 /* remember the address as a hint for next time */
6965 return (mm->free_area_cache = addr-len);
6966 }
6967 @@ -250,18 +254,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6968 if (unlikely(mm->mmap_base < len))
6969 goto bottomup;
6970
6971 - addr = mm->mmap_base-len;
6972 - if (do_color_align)
6973 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6974 + addr = mm->mmap_base - len;
6975
6976 do {
6977 + if (do_color_align)
6978 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6979 /*
6980 * Lookup failure means no vma is above this address,
6981 * else if new region fits below vma->vm_start,
6982 * return with success:
6983 */
6984 vma = find_vma(mm, addr);
6985 - if (likely(!vma || addr+len <= vma->vm_start)) {
6986 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6987 /* remember the address as a hint for next time */
6988 return (mm->free_area_cache = addr);
6989 }
6990 @@ -271,10 +275,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6991 mm->cached_hole_size = vma->vm_start - addr;
6992
6993 /* try just below the current vma->vm_start */
6994 - addr = vma->vm_start-len;
6995 - if (do_color_align)
6996 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6997 - } while (likely(len < vma->vm_start));
6998 + addr = skip_heap_stack_gap(vma, len, offset);
6999 + } while (!IS_ERR_VALUE(addr));
7000
7001 bottomup:
7002 /*
7003 @@ -373,6 +375,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7004 gap == RLIM_INFINITY ||
7005 sysctl_legacy_va_layout) {
7006 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7007 +
7008 +#ifdef CONFIG_PAX_RANDMMAP
7009 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7010 + mm->mmap_base += mm->delta_mmap;
7011 +#endif
7012 +
7013 mm->get_unmapped_area = arch_get_unmapped_area;
7014 mm->unmap_area = arch_unmap_area;
7015 } else {
7016 @@ -385,6 +393,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7017 gap = (task_size / 6 * 5);
7018
7019 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
7020 +
7021 +#ifdef CONFIG_PAX_RANDMMAP
7022 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7023 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7024 +#endif
7025 +
7026 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7027 mm->unmap_area = arch_unmap_area_topdown;
7028 }
7029 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
7030 index bf23477..b7425a6 100644
7031 --- a/arch/sparc/kernel/syscalls.S
7032 +++ b/arch/sparc/kernel/syscalls.S
7033 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
7034 #endif
7035 .align 32
7036 1: ldx [%g6 + TI_FLAGS], %l5
7037 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7038 + andcc %l5, _TIF_WORK_SYSCALL, %g0
7039 be,pt %icc, rtrap
7040 nop
7041 call syscall_trace_leave
7042 @@ -189,7 +189,7 @@ linux_sparc_syscall32:
7043
7044 srl %i5, 0, %o5 ! IEU1
7045 srl %i2, 0, %o2 ! IEU0 Group
7046 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7047 + andcc %l0, _TIF_WORK_SYSCALL, %g0
7048 bne,pn %icc, linux_syscall_trace32 ! CTI
7049 mov %i0, %l5 ! IEU1
7050 call %l7 ! CTI Group brk forced
7051 @@ -212,7 +212,7 @@ linux_sparc_syscall:
7052
7053 mov %i3, %o3 ! IEU1
7054 mov %i4, %o4 ! IEU0 Group
7055 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7056 + andcc %l0, _TIF_WORK_SYSCALL, %g0
7057 bne,pn %icc, linux_syscall_trace ! CTI Group
7058 mov %i0, %l5 ! IEU0
7059 2: call %l7 ! CTI Group brk forced
7060 @@ -228,7 +228,7 @@ ret_sys_call:
7061
7062 cmp %o0, -ERESTART_RESTARTBLOCK
7063 bgeu,pn %xcc, 1f
7064 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7065 + andcc %l0, _TIF_WORK_SYSCALL, %g0
7066 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
7067
7068 2:
7069 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
7070 index a5785ea..405c5f7 100644
7071 --- a/arch/sparc/kernel/traps_32.c
7072 +++ b/arch/sparc/kernel/traps_32.c
7073 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
7074 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
7075 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
7076
7077 +extern void gr_handle_kernel_exploit(void);
7078 +
7079 void die_if_kernel(char *str, struct pt_regs *regs)
7080 {
7081 static int die_counter;
7082 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7083 count++ < 30 &&
7084 (((unsigned long) rw) >= PAGE_OFFSET) &&
7085 !(((unsigned long) rw) & 0x7)) {
7086 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
7087 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
7088 (void *) rw->ins[7]);
7089 rw = (struct reg_window32 *)rw->ins[6];
7090 }
7091 }
7092 printk("Instruction DUMP:");
7093 instruction_dump ((unsigned long *) regs->pc);
7094 - if(regs->psr & PSR_PS)
7095 + if(regs->psr & PSR_PS) {
7096 + gr_handle_kernel_exploit();
7097 do_exit(SIGKILL);
7098 + }
7099 do_exit(SIGSEGV);
7100 }
7101
7102 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
7103 index b66a779..8e8d66c 100644
7104 --- a/arch/sparc/kernel/traps_64.c
7105 +++ b/arch/sparc/kernel/traps_64.c
7106 @@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
7107 i + 1,
7108 p->trapstack[i].tstate, p->trapstack[i].tpc,
7109 p->trapstack[i].tnpc, p->trapstack[i].tt);
7110 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
7111 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
7112 }
7113 }
7114
7115 @@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
7116
7117 lvl -= 0x100;
7118 if (regs->tstate & TSTATE_PRIV) {
7119 +
7120 +#ifdef CONFIG_PAX_REFCOUNT
7121 + if (lvl == 6)
7122 + pax_report_refcount_overflow(regs);
7123 +#endif
7124 +
7125 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
7126 die_if_kernel(buffer, regs);
7127 }
7128 @@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
7129 void bad_trap_tl1(struct pt_regs *regs, long lvl)
7130 {
7131 char buffer[32];
7132 -
7133 +
7134 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
7135 0, lvl, SIGTRAP) == NOTIFY_STOP)
7136 return;
7137
7138 +#ifdef CONFIG_PAX_REFCOUNT
7139 + if (lvl == 6)
7140 + pax_report_refcount_overflow(regs);
7141 +#endif
7142 +
7143 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
7144
7145 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
7146 @@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
7147 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
7148 printk("%s" "ERROR(%d): ",
7149 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
7150 - printk("TPC<%pS>\n", (void *) regs->tpc);
7151 + printk("TPC<%pA>\n", (void *) regs->tpc);
7152 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
7153 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
7154 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
7155 @@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
7156 smp_processor_id(),
7157 (type & 0x1) ? 'I' : 'D',
7158 regs->tpc);
7159 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
7160 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
7161 panic("Irrecoverable Cheetah+ parity error.");
7162 }
7163
7164 @@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
7165 smp_processor_id(),
7166 (type & 0x1) ? 'I' : 'D',
7167 regs->tpc);
7168 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
7169 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
7170 }
7171
7172 struct sun4v_error_entry {
7173 @@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
7174
7175 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
7176 regs->tpc, tl);
7177 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
7178 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
7179 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
7180 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
7181 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
7182 (void *) regs->u_regs[UREG_I7]);
7183 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
7184 "pte[%lx] error[%lx]\n",
7185 @@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
7186
7187 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
7188 regs->tpc, tl);
7189 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
7190 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
7191 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
7192 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
7193 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
7194 (void *) regs->u_regs[UREG_I7]);
7195 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
7196 "pte[%lx] error[%lx]\n",
7197 @@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
7198 fp = (unsigned long)sf->fp + STACK_BIAS;
7199 }
7200
7201 - printk(" [%016lx] %pS\n", pc, (void *) pc);
7202 + printk(" [%016lx] %pA\n", pc, (void *) pc);
7203 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
7204 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
7205 int index = tsk->curr_ret_stack;
7206 if (tsk->ret_stack && index >= graph) {
7207 pc = tsk->ret_stack[index - graph].ret;
7208 - printk(" [%016lx] %pS\n", pc, (void *) pc);
7209 + printk(" [%016lx] %pA\n", pc, (void *) pc);
7210 graph++;
7211 }
7212 }
7213 @@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
7214 return (struct reg_window *) (fp + STACK_BIAS);
7215 }
7216
7217 +extern void gr_handle_kernel_exploit(void);
7218 +
7219 void die_if_kernel(char *str, struct pt_regs *regs)
7220 {
7221 static int die_counter;
7222 @@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7223 while (rw &&
7224 count++ < 30 &&
7225 kstack_valid(tp, (unsigned long) rw)) {
7226 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
7227 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
7228 (void *) rw->ins[7]);
7229
7230 rw = kernel_stack_up(rw);
7231 @@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7232 }
7233 user_instruction_dump ((unsigned int __user *) regs->tpc);
7234 }
7235 - if (regs->tstate & TSTATE_PRIV)
7236 + if (regs->tstate & TSTATE_PRIV) {
7237 + gr_handle_kernel_exploit();
7238 do_exit(SIGKILL);
7239 + }
7240 do_exit(SIGSEGV);
7241 }
7242 EXPORT_SYMBOL(die_if_kernel);
7243 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
7244 index 8201c25e..072a2a7 100644
7245 --- a/arch/sparc/kernel/unaligned_64.c
7246 +++ b/arch/sparc/kernel/unaligned_64.c
7247 @@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
7248 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
7249
7250 if (__ratelimit(&ratelimit)) {
7251 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
7252 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
7253 regs->tpc, (void *) regs->tpc);
7254 }
7255 }
7256 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
7257 index 8410065f2..4fd4ca22 100644
7258 --- a/arch/sparc/lib/Makefile
7259 +++ b/arch/sparc/lib/Makefile
7260 @@ -2,7 +2,7 @@
7261 #
7262
7263 asflags-y := -ansi -DST_DIV0=0x02
7264 -ccflags-y := -Werror
7265 +#ccflags-y := -Werror
7266
7267 lib-$(CONFIG_SPARC32) += ashrdi3.o
7268 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
7269 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
7270 index 85c233d..68500e0 100644
7271 --- a/arch/sparc/lib/atomic_64.S
7272 +++ b/arch/sparc/lib/atomic_64.S
7273 @@ -17,7 +17,12 @@
7274 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7275 BACKOFF_SETUP(%o2)
7276 1: lduw [%o1], %g1
7277 - add %g1, %o0, %g7
7278 + addcc %g1, %o0, %g7
7279 +
7280 +#ifdef CONFIG_PAX_REFCOUNT
7281 + tvs %icc, 6
7282 +#endif
7283 +
7284 cas [%o1], %g1, %g7
7285 cmp %g1, %g7
7286 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7287 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7288 2: BACKOFF_SPIN(%o2, %o3, 1b)
7289 ENDPROC(atomic_add)
7290
7291 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7292 + BACKOFF_SETUP(%o2)
7293 +1: lduw [%o1], %g1
7294 + add %g1, %o0, %g7
7295 + cas [%o1], %g1, %g7
7296 + cmp %g1, %g7
7297 + bne,pn %icc, 2f
7298 + nop
7299 + retl
7300 + nop
7301 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7302 +ENDPROC(atomic_add_unchecked)
7303 +
7304 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7305 BACKOFF_SETUP(%o2)
7306 1: lduw [%o1], %g1
7307 - sub %g1, %o0, %g7
7308 + subcc %g1, %o0, %g7
7309 +
7310 +#ifdef CONFIG_PAX_REFCOUNT
7311 + tvs %icc, 6
7312 +#endif
7313 +
7314 cas [%o1], %g1, %g7
7315 cmp %g1, %g7
7316 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7317 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7318 2: BACKOFF_SPIN(%o2, %o3, 1b)
7319 ENDPROC(atomic_sub)
7320
7321 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7322 + BACKOFF_SETUP(%o2)
7323 +1: lduw [%o1], %g1
7324 + sub %g1, %o0, %g7
7325 + cas [%o1], %g1, %g7
7326 + cmp %g1, %g7
7327 + bne,pn %icc, 2f
7328 + nop
7329 + retl
7330 + nop
7331 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7332 +ENDPROC(atomic_sub_unchecked)
7333 +
7334 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7335 BACKOFF_SETUP(%o2)
7336 1: lduw [%o1], %g1
7337 - add %g1, %o0, %g7
7338 + addcc %g1, %o0, %g7
7339 +
7340 +#ifdef CONFIG_PAX_REFCOUNT
7341 + tvs %icc, 6
7342 +#endif
7343 +
7344 cas [%o1], %g1, %g7
7345 cmp %g1, %g7
7346 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7347 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7348 2: BACKOFF_SPIN(%o2, %o3, 1b)
7349 ENDPROC(atomic_add_ret)
7350
7351 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7352 + BACKOFF_SETUP(%o2)
7353 +1: lduw [%o1], %g1
7354 + addcc %g1, %o0, %g7
7355 + cas [%o1], %g1, %g7
7356 + cmp %g1, %g7
7357 + bne,pn %icc, 2f
7358 + add %g7, %o0, %g7
7359 + sra %g7, 0, %o0
7360 + retl
7361 + nop
7362 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7363 +ENDPROC(atomic_add_ret_unchecked)
7364 +
7365 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7366 BACKOFF_SETUP(%o2)
7367 1: lduw [%o1], %g1
7368 - sub %g1, %o0, %g7
7369 + subcc %g1, %o0, %g7
7370 +
7371 +#ifdef CONFIG_PAX_REFCOUNT
7372 + tvs %icc, 6
7373 +#endif
7374 +
7375 cas [%o1], %g1, %g7
7376 cmp %g1, %g7
7377 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7378 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
7379 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7380 BACKOFF_SETUP(%o2)
7381 1: ldx [%o1], %g1
7382 - add %g1, %o0, %g7
7383 + addcc %g1, %o0, %g7
7384 +
7385 +#ifdef CONFIG_PAX_REFCOUNT
7386 + tvs %xcc, 6
7387 +#endif
7388 +
7389 casx [%o1], %g1, %g7
7390 cmp %g1, %g7
7391 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7392 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7393 2: BACKOFF_SPIN(%o2, %o3, 1b)
7394 ENDPROC(atomic64_add)
7395
7396 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7397 + BACKOFF_SETUP(%o2)
7398 +1: ldx [%o1], %g1
7399 + addcc %g1, %o0, %g7
7400 + casx [%o1], %g1, %g7
7401 + cmp %g1, %g7
7402 + bne,pn %xcc, 2f
7403 + nop
7404 + retl
7405 + nop
7406 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7407 +ENDPROC(atomic64_add_unchecked)
7408 +
7409 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7410 BACKOFF_SETUP(%o2)
7411 1: ldx [%o1], %g1
7412 - sub %g1, %o0, %g7
7413 + subcc %g1, %o0, %g7
7414 +
7415 +#ifdef CONFIG_PAX_REFCOUNT
7416 + tvs %xcc, 6
7417 +#endif
7418 +
7419 casx [%o1], %g1, %g7
7420 cmp %g1, %g7
7421 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7422 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7423 2: BACKOFF_SPIN(%o2, %o3, 1b)
7424 ENDPROC(atomic64_sub)
7425
7426 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7427 + BACKOFF_SETUP(%o2)
7428 +1: ldx [%o1], %g1
7429 + subcc %g1, %o0, %g7
7430 + casx [%o1], %g1, %g7
7431 + cmp %g1, %g7
7432 + bne,pn %xcc, 2f
7433 + nop
7434 + retl
7435 + nop
7436 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7437 +ENDPROC(atomic64_sub_unchecked)
7438 +
7439 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7440 BACKOFF_SETUP(%o2)
7441 1: ldx [%o1], %g1
7442 - add %g1, %o0, %g7
7443 + addcc %g1, %o0, %g7
7444 +
7445 +#ifdef CONFIG_PAX_REFCOUNT
7446 + tvs %xcc, 6
7447 +#endif
7448 +
7449 casx [%o1], %g1, %g7
7450 cmp %g1, %g7
7451 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7452 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7453 2: BACKOFF_SPIN(%o2, %o3, 1b)
7454 ENDPROC(atomic64_add_ret)
7455
7456 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7457 + BACKOFF_SETUP(%o2)
7458 +1: ldx [%o1], %g1
7459 + addcc %g1, %o0, %g7
7460 + casx [%o1], %g1, %g7
7461 + cmp %g1, %g7
7462 + bne,pn %xcc, 2f
7463 + add %g7, %o0, %g7
7464 + mov %g7, %o0
7465 + retl
7466 + nop
7467 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7468 +ENDPROC(atomic64_add_ret_unchecked)
7469 +
7470 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7471 BACKOFF_SETUP(%o2)
7472 1: ldx [%o1], %g1
7473 - sub %g1, %o0, %g7
7474 + subcc %g1, %o0, %g7
7475 +
7476 +#ifdef CONFIG_PAX_REFCOUNT
7477 + tvs %xcc, 6
7478 +#endif
7479 +
7480 casx [%o1], %g1, %g7
7481 cmp %g1, %g7
7482 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7483 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
7484 index 0c4e35e..745d3e4 100644
7485 --- a/arch/sparc/lib/ksyms.c
7486 +++ b/arch/sparc/lib/ksyms.c
7487 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
7488
7489 /* Atomic counter implementation. */
7490 EXPORT_SYMBOL(atomic_add);
7491 +EXPORT_SYMBOL(atomic_add_unchecked);
7492 EXPORT_SYMBOL(atomic_add_ret);
7493 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
7494 EXPORT_SYMBOL(atomic_sub);
7495 +EXPORT_SYMBOL(atomic_sub_unchecked);
7496 EXPORT_SYMBOL(atomic_sub_ret);
7497 EXPORT_SYMBOL(atomic64_add);
7498 +EXPORT_SYMBOL(atomic64_add_unchecked);
7499 EXPORT_SYMBOL(atomic64_add_ret);
7500 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
7501 EXPORT_SYMBOL(atomic64_sub);
7502 +EXPORT_SYMBOL(atomic64_sub_unchecked);
7503 EXPORT_SYMBOL(atomic64_sub_ret);
7504 EXPORT_SYMBOL(atomic64_dec_if_positive);
7505
7506 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
7507 index 30c3ecc..736f015 100644
7508 --- a/arch/sparc/mm/Makefile
7509 +++ b/arch/sparc/mm/Makefile
7510 @@ -2,7 +2,7 @@
7511 #
7512
7513 asflags-y := -ansi
7514 -ccflags-y := -Werror
7515 +#ccflags-y := -Werror
7516
7517 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
7518 obj-y += fault_$(BITS).o
7519 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
7520 index e98bfda..ea8d221 100644
7521 --- a/arch/sparc/mm/fault_32.c
7522 +++ b/arch/sparc/mm/fault_32.c
7523 @@ -21,6 +21,9 @@
7524 #include <linux/perf_event.h>
7525 #include <linux/interrupt.h>
7526 #include <linux/kdebug.h>
7527 +#include <linux/slab.h>
7528 +#include <linux/pagemap.h>
7529 +#include <linux/compiler.h>
7530
7531 #include <asm/page.h>
7532 #include <asm/pgtable.h>
7533 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
7534 return safe_compute_effective_address(regs, insn);
7535 }
7536
7537 +#ifdef CONFIG_PAX_PAGEEXEC
7538 +#ifdef CONFIG_PAX_DLRESOLVE
7539 +static void pax_emuplt_close(struct vm_area_struct *vma)
7540 +{
7541 + vma->vm_mm->call_dl_resolve = 0UL;
7542 +}
7543 +
7544 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7545 +{
7546 + unsigned int *kaddr;
7547 +
7548 + vmf->page = alloc_page(GFP_HIGHUSER);
7549 + if (!vmf->page)
7550 + return VM_FAULT_OOM;
7551 +
7552 + kaddr = kmap(vmf->page);
7553 + memset(kaddr, 0, PAGE_SIZE);
7554 + kaddr[0] = 0x9DE3BFA8U; /* save */
7555 + flush_dcache_page(vmf->page);
7556 + kunmap(vmf->page);
7557 + return VM_FAULT_MAJOR;
7558 +}
7559 +
7560 +static const struct vm_operations_struct pax_vm_ops = {
7561 + .close = pax_emuplt_close,
7562 + .fault = pax_emuplt_fault
7563 +};
7564 +
7565 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7566 +{
7567 + int ret;
7568 +
7569 + INIT_LIST_HEAD(&vma->anon_vma_chain);
7570 + vma->vm_mm = current->mm;
7571 + vma->vm_start = addr;
7572 + vma->vm_end = addr + PAGE_SIZE;
7573 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7574 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7575 + vma->vm_ops = &pax_vm_ops;
7576 +
7577 + ret = insert_vm_struct(current->mm, vma);
7578 + if (ret)
7579 + return ret;
7580 +
7581 + ++current->mm->total_vm;
7582 + return 0;
7583 +}
7584 +#endif
7585 +
7586 +/*
7587 + * PaX: decide what to do with offenders (regs->pc = fault address)
7588 + *
7589 + * returns 1 when task should be killed
7590 + * 2 when patched PLT trampoline was detected
7591 + * 3 when unpatched PLT trampoline was detected
7592 + */
7593 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7594 +{
7595 +
7596 +#ifdef CONFIG_PAX_EMUPLT
7597 + int err;
7598 +
7599 + do { /* PaX: patched PLT emulation #1 */
7600 + unsigned int sethi1, sethi2, jmpl;
7601 +
7602 + err = get_user(sethi1, (unsigned int *)regs->pc);
7603 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
7604 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
7605 +
7606 + if (err)
7607 + break;
7608 +
7609 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
7610 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
7611 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
7612 + {
7613 + unsigned int addr;
7614 +
7615 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
7616 + addr = regs->u_regs[UREG_G1];
7617 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7618 + regs->pc = addr;
7619 + regs->npc = addr+4;
7620 + return 2;
7621 + }
7622 + } while (0);
7623 +
7624 + do { /* PaX: patched PLT emulation #2 */
7625 + unsigned int ba;
7626 +
7627 + err = get_user(ba, (unsigned int *)regs->pc);
7628 +
7629 + if (err)
7630 + break;
7631 +
7632 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
7633 + unsigned int addr;
7634 +
7635 + if ((ba & 0xFFC00000U) == 0x30800000U)
7636 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7637 + else
7638 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7639 + regs->pc = addr;
7640 + regs->npc = addr+4;
7641 + return 2;
7642 + }
7643 + } while (0);
7644 +
7645 + do { /* PaX: patched PLT emulation #3 */
7646 + unsigned int sethi, bajmpl, nop;
7647 +
7648 + err = get_user(sethi, (unsigned int *)regs->pc);
7649 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
7650 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
7651 +
7652 + if (err)
7653 + break;
7654 +
7655 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7656 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
7657 + nop == 0x01000000U)
7658 + {
7659 + unsigned int addr;
7660 +
7661 + addr = (sethi & 0x003FFFFFU) << 10;
7662 + regs->u_regs[UREG_G1] = addr;
7663 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
7664 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7665 + else
7666 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7667 + regs->pc = addr;
7668 + regs->npc = addr+4;
7669 + return 2;
7670 + }
7671 + } while (0);
7672 +
7673 + do { /* PaX: unpatched PLT emulation step 1 */
7674 + unsigned int sethi, ba, nop;
7675 +
7676 + err = get_user(sethi, (unsigned int *)regs->pc);
7677 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
7678 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
7679 +
7680 + if (err)
7681 + break;
7682 +
7683 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7684 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7685 + nop == 0x01000000U)
7686 + {
7687 + unsigned int addr, save, call;
7688 +
7689 + if ((ba & 0xFFC00000U) == 0x30800000U)
7690 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7691 + else
7692 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7693 +
7694 + err = get_user(save, (unsigned int *)addr);
7695 + err |= get_user(call, (unsigned int *)(addr+4));
7696 + err |= get_user(nop, (unsigned int *)(addr+8));
7697 + if (err)
7698 + break;
7699 +
7700 +#ifdef CONFIG_PAX_DLRESOLVE
7701 + if (save == 0x9DE3BFA8U &&
7702 + (call & 0xC0000000U) == 0x40000000U &&
7703 + nop == 0x01000000U)
7704 + {
7705 + struct vm_area_struct *vma;
7706 + unsigned long call_dl_resolve;
7707 +
7708 + down_read(&current->mm->mmap_sem);
7709 + call_dl_resolve = current->mm->call_dl_resolve;
7710 + up_read(&current->mm->mmap_sem);
7711 + if (likely(call_dl_resolve))
7712 + goto emulate;
7713 +
7714 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7715 +
7716 + down_write(&current->mm->mmap_sem);
7717 + if (current->mm->call_dl_resolve) {
7718 + call_dl_resolve = current->mm->call_dl_resolve;
7719 + up_write(&current->mm->mmap_sem);
7720 + if (vma)
7721 + kmem_cache_free(vm_area_cachep, vma);
7722 + goto emulate;
7723 + }
7724 +
7725 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7726 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7727 + up_write(&current->mm->mmap_sem);
7728 + if (vma)
7729 + kmem_cache_free(vm_area_cachep, vma);
7730 + return 1;
7731 + }
7732 +
7733 + if (pax_insert_vma(vma, call_dl_resolve)) {
7734 + up_write(&current->mm->mmap_sem);
7735 + kmem_cache_free(vm_area_cachep, vma);
7736 + return 1;
7737 + }
7738 +
7739 + current->mm->call_dl_resolve = call_dl_resolve;
7740 + up_write(&current->mm->mmap_sem);
7741 +
7742 +emulate:
7743 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7744 + regs->pc = call_dl_resolve;
7745 + regs->npc = addr+4;
7746 + return 3;
7747 + }
7748 +#endif
7749 +
7750 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7751 + if ((save & 0xFFC00000U) == 0x05000000U &&
7752 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7753 + nop == 0x01000000U)
7754 + {
7755 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7756 + regs->u_regs[UREG_G2] = addr + 4;
7757 + addr = (save & 0x003FFFFFU) << 10;
7758 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7759 + regs->pc = addr;
7760 + regs->npc = addr+4;
7761 + return 3;
7762 + }
7763 + }
7764 + } while (0);
7765 +
7766 + do { /* PaX: unpatched PLT emulation step 2 */
7767 + unsigned int save, call, nop;
7768 +
7769 + err = get_user(save, (unsigned int *)(regs->pc-4));
7770 + err |= get_user(call, (unsigned int *)regs->pc);
7771 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
7772 + if (err)
7773 + break;
7774 +
7775 + if (save == 0x9DE3BFA8U &&
7776 + (call & 0xC0000000U) == 0x40000000U &&
7777 + nop == 0x01000000U)
7778 + {
7779 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
7780 +
7781 + regs->u_regs[UREG_RETPC] = regs->pc;
7782 + regs->pc = dl_resolve;
7783 + regs->npc = dl_resolve+4;
7784 + return 3;
7785 + }
7786 + } while (0);
7787 +#endif
7788 +
7789 + return 1;
7790 +}
7791 +
7792 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7793 +{
7794 + unsigned long i;
7795 +
7796 + printk(KERN_ERR "PAX: bytes at PC: ");
7797 + for (i = 0; i < 8; i++) {
7798 + unsigned int c;
7799 + if (get_user(c, (unsigned int *)pc+i))
7800 + printk(KERN_CONT "???????? ");
7801 + else
7802 + printk(KERN_CONT "%08x ", c);
7803 + }
7804 + printk("\n");
7805 +}
7806 +#endif
7807 +
7808 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
7809 int text_fault)
7810 {
7811 @@ -230,6 +504,24 @@ good_area:
7812 if (!(vma->vm_flags & VM_WRITE))
7813 goto bad_area;
7814 } else {
7815 +
7816 +#ifdef CONFIG_PAX_PAGEEXEC
7817 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
7818 + up_read(&mm->mmap_sem);
7819 + switch (pax_handle_fetch_fault(regs)) {
7820 +
7821 +#ifdef CONFIG_PAX_EMUPLT
7822 + case 2:
7823 + case 3:
7824 + return;
7825 +#endif
7826 +
7827 + }
7828 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
7829 + do_group_exit(SIGKILL);
7830 + }
7831 +#endif
7832 +
7833 /* Allow reads even for write-only mappings */
7834 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
7835 goto bad_area;
7836 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
7837 index 097aee7..5ca6697 100644
7838 --- a/arch/sparc/mm/fault_64.c
7839 +++ b/arch/sparc/mm/fault_64.c
7840 @@ -21,6 +21,9 @@
7841 #include <linux/kprobes.h>
7842 #include <linux/kdebug.h>
7843 #include <linux/percpu.h>
7844 +#include <linux/slab.h>
7845 +#include <linux/pagemap.h>
7846 +#include <linux/compiler.h>
7847
7848 #include <asm/page.h>
7849 #include <asm/pgtable.h>
7850 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
7851 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
7852 regs->tpc);
7853 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
7854 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
7855 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
7856 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
7857 dump_stack();
7858 unhandled_fault(regs->tpc, current, regs);
7859 @@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
7860 show_regs(regs);
7861 }
7862
7863 +#ifdef CONFIG_PAX_PAGEEXEC
7864 +#ifdef CONFIG_PAX_DLRESOLVE
7865 +static void pax_emuplt_close(struct vm_area_struct *vma)
7866 +{
7867 + vma->vm_mm->call_dl_resolve = 0UL;
7868 +}
7869 +
7870 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7871 +{
7872 + unsigned int *kaddr;
7873 +
7874 + vmf->page = alloc_page(GFP_HIGHUSER);
7875 + if (!vmf->page)
7876 + return VM_FAULT_OOM;
7877 +
7878 + kaddr = kmap(vmf->page);
7879 + memset(kaddr, 0, PAGE_SIZE);
7880 + kaddr[0] = 0x9DE3BFA8U; /* save */
7881 + flush_dcache_page(vmf->page);
7882 + kunmap(vmf->page);
7883 + return VM_FAULT_MAJOR;
7884 +}
7885 +
7886 +static const struct vm_operations_struct pax_vm_ops = {
7887 + .close = pax_emuplt_close,
7888 + .fault = pax_emuplt_fault
7889 +};
7890 +
7891 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7892 +{
7893 + int ret;
7894 +
7895 + INIT_LIST_HEAD(&vma->anon_vma_chain);
7896 + vma->vm_mm = current->mm;
7897 + vma->vm_start = addr;
7898 + vma->vm_end = addr + PAGE_SIZE;
7899 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7900 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7901 + vma->vm_ops = &pax_vm_ops;
7902 +
7903 + ret = insert_vm_struct(current->mm, vma);
7904 + if (ret)
7905 + return ret;
7906 +
7907 + ++current->mm->total_vm;
7908 + return 0;
7909 +}
7910 +#endif
7911 +
7912 +/*
7913 + * PaX: decide what to do with offenders (regs->tpc = fault address)
7914 + *
7915 + * returns 1 when task should be killed
7916 + * 2 when patched PLT trampoline was detected
7917 + * 3 when unpatched PLT trampoline was detected
7918 + */
7919 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7920 +{
7921 +
7922 +#ifdef CONFIG_PAX_EMUPLT
7923 + int err;
7924 +
7925 + do { /* PaX: patched PLT emulation #1 */
7926 + unsigned int sethi1, sethi2, jmpl;
7927 +
7928 + err = get_user(sethi1, (unsigned int *)regs->tpc);
7929 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
7930 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
7931 +
7932 + if (err)
7933 + break;
7934 +
7935 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
7936 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
7937 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
7938 + {
7939 + unsigned long addr;
7940 +
7941 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
7942 + addr = regs->u_regs[UREG_G1];
7943 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7944 +
7945 + if (test_thread_flag(TIF_32BIT))
7946 + addr &= 0xFFFFFFFFUL;
7947 +
7948 + regs->tpc = addr;
7949 + regs->tnpc = addr+4;
7950 + return 2;
7951 + }
7952 + } while (0);
7953 +
7954 + do { /* PaX: patched PLT emulation #2 */
7955 + unsigned int ba;
7956 +
7957 + err = get_user(ba, (unsigned int *)regs->tpc);
7958 +
7959 + if (err)
7960 + break;
7961 +
7962 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
7963 + unsigned long addr;
7964 +
7965 + if ((ba & 0xFFC00000U) == 0x30800000U)
7966 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7967 + else
7968 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7969 +
7970 + if (test_thread_flag(TIF_32BIT))
7971 + addr &= 0xFFFFFFFFUL;
7972 +
7973 + regs->tpc = addr;
7974 + regs->tnpc = addr+4;
7975 + return 2;
7976 + }
7977 + } while (0);
7978 +
7979 + do { /* PaX: patched PLT emulation #3 */
7980 + unsigned int sethi, bajmpl, nop;
7981 +
7982 + err = get_user(sethi, (unsigned int *)regs->tpc);
7983 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
7984 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7985 +
7986 + if (err)
7987 + break;
7988 +
7989 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7990 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
7991 + nop == 0x01000000U)
7992 + {
7993 + unsigned long addr;
7994 +
7995 + addr = (sethi & 0x003FFFFFU) << 10;
7996 + regs->u_regs[UREG_G1] = addr;
7997 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
7998 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7999 + else
8000 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8001 +
8002 + if (test_thread_flag(TIF_32BIT))
8003 + addr &= 0xFFFFFFFFUL;
8004 +
8005 + regs->tpc = addr;
8006 + regs->tnpc = addr+4;
8007 + return 2;
8008 + }
8009 + } while (0);
8010 +
8011 + do { /* PaX: patched PLT emulation #4 */
8012 + unsigned int sethi, mov1, call, mov2;
8013 +
8014 + err = get_user(sethi, (unsigned int *)regs->tpc);
8015 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
8016 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
8017 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
8018 +
8019 + if (err)
8020 + break;
8021 +
8022 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8023 + mov1 == 0x8210000FU &&
8024 + (call & 0xC0000000U) == 0x40000000U &&
8025 + mov2 == 0x9E100001U)
8026 + {
8027 + unsigned long addr;
8028 +
8029 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
8030 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
8031 +
8032 + if (test_thread_flag(TIF_32BIT))
8033 + addr &= 0xFFFFFFFFUL;
8034 +
8035 + regs->tpc = addr;
8036 + regs->tnpc = addr+4;
8037 + return 2;
8038 + }
8039 + } while (0);
8040 +
8041 + do { /* PaX: patched PLT emulation #5 */
8042 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
8043 +
8044 + err = get_user(sethi, (unsigned int *)regs->tpc);
8045 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
8046 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
8047 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
8048 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
8049 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
8050 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
8051 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
8052 +
8053 + if (err)
8054 + break;
8055 +
8056 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8057 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
8058 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8059 + (or1 & 0xFFFFE000U) == 0x82106000U &&
8060 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
8061 + sllx == 0x83287020U &&
8062 + jmpl == 0x81C04005U &&
8063 + nop == 0x01000000U)
8064 + {
8065 + unsigned long addr;
8066 +
8067 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
8068 + regs->u_regs[UREG_G1] <<= 32;
8069 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
8070 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
8071 + regs->tpc = addr;
8072 + regs->tnpc = addr+4;
8073 + return 2;
8074 + }
8075 + } while (0);
8076 +
8077 + do { /* PaX: patched PLT emulation #6 */
8078 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
8079 +
8080 + err = get_user(sethi, (unsigned int *)regs->tpc);
8081 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
8082 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
8083 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
8084 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
8085 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
8086 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
8087 +
8088 + if (err)
8089 + break;
8090 +
8091 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8092 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
8093 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8094 + sllx == 0x83287020U &&
8095 + (or & 0xFFFFE000U) == 0x8A116000U &&
8096 + jmpl == 0x81C04005U &&
8097 + nop == 0x01000000U)
8098 + {
8099 + unsigned long addr;
8100 +
8101 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
8102 + regs->u_regs[UREG_G1] <<= 32;
8103 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
8104 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
8105 + regs->tpc = addr;
8106 + regs->tnpc = addr+4;
8107 + return 2;
8108 + }
8109 + } while (0);
8110 +
8111 + do { /* PaX: unpatched PLT emulation step 1 */
8112 + unsigned int sethi, ba, nop;
8113 +
8114 + err = get_user(sethi, (unsigned int *)regs->tpc);
8115 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8116 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8117 +
8118 + if (err)
8119 + break;
8120 +
8121 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8122 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
8123 + nop == 0x01000000U)
8124 + {
8125 + unsigned long addr;
8126 + unsigned int save, call;
8127 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
8128 +
8129 + if ((ba & 0xFFC00000U) == 0x30800000U)
8130 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
8131 + else
8132 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8133 +
8134 + if (test_thread_flag(TIF_32BIT))
8135 + addr &= 0xFFFFFFFFUL;
8136 +
8137 + err = get_user(save, (unsigned int *)addr);
8138 + err |= get_user(call, (unsigned int *)(addr+4));
8139 + err |= get_user(nop, (unsigned int *)(addr+8));
8140 + if (err)
8141 + break;
8142 +
8143 +#ifdef CONFIG_PAX_DLRESOLVE
8144 + if (save == 0x9DE3BFA8U &&
8145 + (call & 0xC0000000U) == 0x40000000U &&
8146 + nop == 0x01000000U)
8147 + {
8148 + struct vm_area_struct *vma;
8149 + unsigned long call_dl_resolve;
8150 +
8151 + down_read(&current->mm->mmap_sem);
8152 + call_dl_resolve = current->mm->call_dl_resolve;
8153 + up_read(&current->mm->mmap_sem);
8154 + if (likely(call_dl_resolve))
8155 + goto emulate;
8156 +
8157 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
8158 +
8159 + down_write(&current->mm->mmap_sem);
8160 + if (current->mm->call_dl_resolve) {
8161 + call_dl_resolve = current->mm->call_dl_resolve;
8162 + up_write(&current->mm->mmap_sem);
8163 + if (vma)
8164 + kmem_cache_free(vm_area_cachep, vma);
8165 + goto emulate;
8166 + }
8167 +
8168 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
8169 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
8170 + up_write(&current->mm->mmap_sem);
8171 + if (vma)
8172 + kmem_cache_free(vm_area_cachep, vma);
8173 + return 1;
8174 + }
8175 +
8176 + if (pax_insert_vma(vma, call_dl_resolve)) {
8177 + up_write(&current->mm->mmap_sem);
8178 + kmem_cache_free(vm_area_cachep, vma);
8179 + return 1;
8180 + }
8181 +
8182 + current->mm->call_dl_resolve = call_dl_resolve;
8183 + up_write(&current->mm->mmap_sem);
8184 +
8185 +emulate:
8186 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8187 + regs->tpc = call_dl_resolve;
8188 + regs->tnpc = addr+4;
8189 + return 3;
8190 + }
8191 +#endif
8192 +
8193 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
8194 + if ((save & 0xFFC00000U) == 0x05000000U &&
8195 + (call & 0xFFFFE000U) == 0x85C0A000U &&
8196 + nop == 0x01000000U)
8197 + {
8198 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8199 + regs->u_regs[UREG_G2] = addr + 4;
8200 + addr = (save & 0x003FFFFFU) << 10;
8201 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8202 +
8203 + if (test_thread_flag(TIF_32BIT))
8204 + addr &= 0xFFFFFFFFUL;
8205 +
8206 + regs->tpc = addr;
8207 + regs->tnpc = addr+4;
8208 + return 3;
8209 + }
8210 +
8211 + /* PaX: 64-bit PLT stub */
8212 + err = get_user(sethi1, (unsigned int *)addr);
8213 + err |= get_user(sethi2, (unsigned int *)(addr+4));
8214 + err |= get_user(or1, (unsigned int *)(addr+8));
8215 + err |= get_user(or2, (unsigned int *)(addr+12));
8216 + err |= get_user(sllx, (unsigned int *)(addr+16));
8217 + err |= get_user(add, (unsigned int *)(addr+20));
8218 + err |= get_user(jmpl, (unsigned int *)(addr+24));
8219 + err |= get_user(nop, (unsigned int *)(addr+28));
8220 + if (err)
8221 + break;
8222 +
8223 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
8224 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8225 + (or1 & 0xFFFFE000U) == 0x88112000U &&
8226 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
8227 + sllx == 0x89293020U &&
8228 + add == 0x8A010005U &&
8229 + jmpl == 0x89C14000U &&
8230 + nop == 0x01000000U)
8231 + {
8232 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8233 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
8234 + regs->u_regs[UREG_G4] <<= 32;
8235 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
8236 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
8237 + regs->u_regs[UREG_G4] = addr + 24;
8238 + addr = regs->u_regs[UREG_G5];
8239 + regs->tpc = addr;
8240 + regs->tnpc = addr+4;
8241 + return 3;
8242 + }
8243 + }
8244 + } while (0);
8245 +
8246 +#ifdef CONFIG_PAX_DLRESOLVE
8247 + do { /* PaX: unpatched PLT emulation step 2 */
8248 + unsigned int save, call, nop;
8249 +
8250 + err = get_user(save, (unsigned int *)(regs->tpc-4));
8251 + err |= get_user(call, (unsigned int *)regs->tpc);
8252 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
8253 + if (err)
8254 + break;
8255 +
8256 + if (save == 0x9DE3BFA8U &&
8257 + (call & 0xC0000000U) == 0x40000000U &&
8258 + nop == 0x01000000U)
8259 + {
8260 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
8261 +
8262 + if (test_thread_flag(TIF_32BIT))
8263 + dl_resolve &= 0xFFFFFFFFUL;
8264 +
8265 + regs->u_regs[UREG_RETPC] = regs->tpc;
8266 + regs->tpc = dl_resolve;
8267 + regs->tnpc = dl_resolve+4;
8268 + return 3;
8269 + }
8270 + } while (0);
8271 +#endif
8272 +
8273 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
8274 + unsigned int sethi, ba, nop;
8275 +
8276 + err = get_user(sethi, (unsigned int *)regs->tpc);
8277 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8278 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8279 +
8280 + if (err)
8281 + break;
8282 +
8283 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8284 + (ba & 0xFFF00000U) == 0x30600000U &&
8285 + nop == 0x01000000U)
8286 + {
8287 + unsigned long addr;
8288 +
8289 + addr = (sethi & 0x003FFFFFU) << 10;
8290 + regs->u_regs[UREG_G1] = addr;
8291 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8292 +
8293 + if (test_thread_flag(TIF_32BIT))
8294 + addr &= 0xFFFFFFFFUL;
8295 +
8296 + regs->tpc = addr;
8297 + regs->tnpc = addr+4;
8298 + return 2;
8299 + }
8300 + } while (0);
8301 +
8302 +#endif
8303 +
8304 + return 1;
8305 +}
8306 +
8307 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8308 +{
8309 + unsigned long i;
8310 +
8311 + printk(KERN_ERR "PAX: bytes at PC: ");
8312 + for (i = 0; i < 8; i++) {
8313 + unsigned int c;
8314 + if (get_user(c, (unsigned int *)pc+i))
8315 + printk(KERN_CONT "???????? ");
8316 + else
8317 + printk(KERN_CONT "%08x ", c);
8318 + }
8319 + printk("\n");
8320 +}
8321 +#endif
8322 +
8323 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
8324 {
8325 struct mm_struct *mm = current->mm;
8326 @@ -341,6 +804,29 @@ retry:
8327 if (!vma)
8328 goto bad_area;
8329
8330 +#ifdef CONFIG_PAX_PAGEEXEC
8331 + /* PaX: detect ITLB misses on non-exec pages */
8332 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
8333 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
8334 + {
8335 + if (address != regs->tpc)
8336 + goto good_area;
8337 +
8338 + up_read(&mm->mmap_sem);
8339 + switch (pax_handle_fetch_fault(regs)) {
8340 +
8341 +#ifdef CONFIG_PAX_EMUPLT
8342 + case 2:
8343 + case 3:
8344 + return;
8345 +#endif
8346 +
8347 + }
8348 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
8349 + do_group_exit(SIGKILL);
8350 + }
8351 +#endif
8352 +
8353 /* Pure DTLB misses do not tell us whether the fault causing
8354 * load/store/atomic was a write or not, it only says that there
8355 * was no match. So in such a case we (carefully) read the
8356 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
8357 index f76f83d..ee0d859 100644
8358 --- a/arch/sparc/mm/hugetlbpage.c
8359 +++ b/arch/sparc/mm/hugetlbpage.c
8360 @@ -34,6 +34,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
8361 struct vm_area_struct * vma;
8362 unsigned long task_size = TASK_SIZE;
8363 unsigned long start_addr;
8364 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8365
8366 if (test_thread_flag(TIF_32BIT))
8367 task_size = STACK_TOP32;
8368 @@ -67,7 +68,7 @@ full_search:
8369 }
8370 return -ENOMEM;
8371 }
8372 - if (likely(!vma || addr + len <= vma->vm_start)) {
8373 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
8374 /*
8375 * Remember the place where we stopped the search:
8376 */
8377 @@ -90,6 +91,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8378 struct vm_area_struct *vma;
8379 struct mm_struct *mm = current->mm;
8380 unsigned long addr = addr0;
8381 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8382
8383 /* This should only ever run for 32-bit processes. */
8384 BUG_ON(!test_thread_flag(TIF_32BIT));
8385 @@ -106,7 +108,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8386 /* make sure it can fit in the remaining address space */
8387 if (likely(addr > len)) {
8388 vma = find_vma(mm, addr-len);
8389 - if (!vma || addr <= vma->vm_start) {
8390 + if (check_heap_stack_gap(vma, addr - len, len, offset)) {
8391 /* remember the address as a hint for next time */
8392 return (mm->free_area_cache = addr-len);
8393 }
8394 @@ -115,16 +117,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8395 if (unlikely(mm->mmap_base < len))
8396 goto bottomup;
8397
8398 - addr = (mm->mmap_base-len) & HPAGE_MASK;
8399 + addr = mm->mmap_base - len;
8400
8401 do {
8402 + addr &= HPAGE_MASK;
8403 /*
8404 * Lookup failure means no vma is above this address,
8405 * else if new region fits below vma->vm_start,
8406 * return with success:
8407 */
8408 vma = find_vma(mm, addr);
8409 - if (likely(!vma || addr+len <= vma->vm_start)) {
8410 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
8411 /* remember the address as a hint for next time */
8412 return (mm->free_area_cache = addr);
8413 }
8414 @@ -134,8 +137,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8415 mm->cached_hole_size = vma->vm_start - addr;
8416
8417 /* try just below the current vma->vm_start */
8418 - addr = (vma->vm_start-len) & HPAGE_MASK;
8419 - } while (likely(len < vma->vm_start));
8420 + addr = skip_heap_stack_gap(vma, len, offset);
8421 + } while (!IS_ERR_VALUE(addr));
8422
8423 bottomup:
8424 /*
8425 @@ -163,6 +166,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8426 struct mm_struct *mm = current->mm;
8427 struct vm_area_struct *vma;
8428 unsigned long task_size = TASK_SIZE;
8429 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8430
8431 if (test_thread_flag(TIF_32BIT))
8432 task_size = STACK_TOP32;
8433 @@ -181,8 +185,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8434 if (addr) {
8435 addr = ALIGN(addr, HPAGE_SIZE);
8436 vma = find_vma(mm, addr);
8437 - if (task_size - len >= addr &&
8438 - (!vma || addr + len <= vma->vm_start))
8439 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8440 return addr;
8441 }
8442 if (mm->get_unmapped_area == arch_get_unmapped_area)
8443 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
8444 index f4500c6..889656c 100644
8445 --- a/arch/tile/include/asm/atomic_64.h
8446 +++ b/arch/tile/include/asm/atomic_64.h
8447 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8448
8449 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8450
8451 +#define atomic64_read_unchecked(v) atomic64_read(v)
8452 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8453 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8454 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8455 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8456 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8457 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8458 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8459 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8460 +
8461 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
8462 #define smp_mb__before_atomic_dec() smp_mb()
8463 #define smp_mb__after_atomic_dec() smp_mb()
8464 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
8465 index a9a5299..0fce79e 100644
8466 --- a/arch/tile/include/asm/cache.h
8467 +++ b/arch/tile/include/asm/cache.h
8468 @@ -15,11 +15,12 @@
8469 #ifndef _ASM_TILE_CACHE_H
8470 #define _ASM_TILE_CACHE_H
8471
8472 +#include <linux/const.h>
8473 #include <arch/chip.h>
8474
8475 /* bytes per L1 data cache line */
8476 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
8477 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8478 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8479
8480 /* bytes per L2 cache line */
8481 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
8482 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
8483 index 9ab078a..d6635c2 100644
8484 --- a/arch/tile/include/asm/uaccess.h
8485 +++ b/arch/tile/include/asm/uaccess.h
8486 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
8487 const void __user *from,
8488 unsigned long n)
8489 {
8490 - int sz = __compiletime_object_size(to);
8491 + size_t sz = __compiletime_object_size(to);
8492
8493 - if (likely(sz == -1 || sz >= n))
8494 + if (likely(sz == (size_t)-1 || sz >= n))
8495 n = _copy_from_user(to, from, n);
8496 else
8497 copy_from_user_overflow();
8498 diff --git a/arch/um/Makefile b/arch/um/Makefile
8499 index 133f7de..1d6f2f1 100644
8500 --- a/arch/um/Makefile
8501 +++ b/arch/um/Makefile
8502 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
8503 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
8504 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
8505
8506 +ifdef CONSTIFY_PLUGIN
8507 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8508 +endif
8509 +
8510 #This will adjust *FLAGS accordingly to the platform.
8511 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
8512
8513 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
8514 index 19e1bdd..3665b77 100644
8515 --- a/arch/um/include/asm/cache.h
8516 +++ b/arch/um/include/asm/cache.h
8517 @@ -1,6 +1,7 @@
8518 #ifndef __UM_CACHE_H
8519 #define __UM_CACHE_H
8520
8521 +#include <linux/const.h>
8522
8523 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
8524 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
8525 @@ -12,6 +13,6 @@
8526 # define L1_CACHE_SHIFT 5
8527 #endif
8528
8529 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8530 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8531
8532 #endif
8533 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
8534 index 2e0a6b1..a64d0f5 100644
8535 --- a/arch/um/include/asm/kmap_types.h
8536 +++ b/arch/um/include/asm/kmap_types.h
8537 @@ -8,6 +8,6 @@
8538
8539 /* No more #include "asm/arch/kmap_types.h" ! */
8540
8541 -#define KM_TYPE_NR 14
8542 +#define KM_TYPE_NR 15
8543
8544 #endif
8545 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
8546 index 5ff53d9..5850cdf 100644
8547 --- a/arch/um/include/asm/page.h
8548 +++ b/arch/um/include/asm/page.h
8549 @@ -14,6 +14,9 @@
8550 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
8551 #define PAGE_MASK (~(PAGE_SIZE-1))
8552
8553 +#define ktla_ktva(addr) (addr)
8554 +#define ktva_ktla(addr) (addr)
8555 +
8556 #ifndef __ASSEMBLY__
8557
8558 struct page;
8559 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
8560 index 0032f92..cd151e0 100644
8561 --- a/arch/um/include/asm/pgtable-3level.h
8562 +++ b/arch/um/include/asm/pgtable-3level.h
8563 @@ -58,6 +58,7 @@
8564 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
8565 #define pud_populate(mm, pud, pmd) \
8566 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
8567 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8568
8569 #ifdef CONFIG_64BIT
8570 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
8571 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
8572 index b6d699c..df7ac1d 100644
8573 --- a/arch/um/kernel/process.c
8574 +++ b/arch/um/kernel/process.c
8575 @@ -387,22 +387,6 @@ int singlestepping(void * t)
8576 return 2;
8577 }
8578
8579 -/*
8580 - * Only x86 and x86_64 have an arch_align_stack().
8581 - * All other arches have "#define arch_align_stack(x) (x)"
8582 - * in their asm/system.h
8583 - * As this is included in UML from asm-um/system-generic.h,
8584 - * we can use it to behave as the subarch does.
8585 - */
8586 -#ifndef arch_align_stack
8587 -unsigned long arch_align_stack(unsigned long sp)
8588 -{
8589 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8590 - sp -= get_random_int() % 8192;
8591 - return sp & ~0xf;
8592 -}
8593 -#endif
8594 -
8595 unsigned long get_wchan(struct task_struct *p)
8596 {
8597 unsigned long stack_page, sp, ip;
8598 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
8599 index ad8f795..2c7eec6 100644
8600 --- a/arch/unicore32/include/asm/cache.h
8601 +++ b/arch/unicore32/include/asm/cache.h
8602 @@ -12,8 +12,10 @@
8603 #ifndef __UNICORE_CACHE_H__
8604 #define __UNICORE_CACHE_H__
8605
8606 -#define L1_CACHE_SHIFT (5)
8607 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8608 +#include <linux/const.h>
8609 +
8610 +#define L1_CACHE_SHIFT 5
8611 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8612
8613 /*
8614 * Memory returned by kmalloc() may be used for DMA, so we must make
8615 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
8616 index 46c3bff..b82f26b 100644
8617 --- a/arch/x86/Kconfig
8618 +++ b/arch/x86/Kconfig
8619 @@ -241,7 +241,7 @@ config X86_HT
8620
8621 config X86_32_LAZY_GS
8622 def_bool y
8623 - depends on X86_32 && !CC_STACKPROTECTOR
8624 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
8625
8626 config ARCH_HWEIGHT_CFLAGS
8627 string
8628 @@ -1033,6 +1033,7 @@ config MICROCODE_OLD_INTERFACE
8629
8630 config X86_MSR
8631 tristate "/dev/cpu/*/msr - Model-specific register support"
8632 + depends on !GRKERNSEC_KMEM
8633 ---help---
8634 This device gives privileged processes access to the x86
8635 Model-Specific Registers (MSRs). It is a character device with
8636 @@ -1056,7 +1057,7 @@ choice
8637
8638 config NOHIGHMEM
8639 bool "off"
8640 - depends on !X86_NUMAQ
8641 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8642 ---help---
8643 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
8644 However, the address space of 32-bit x86 processors is only 4
8645 @@ -1093,7 +1094,7 @@ config NOHIGHMEM
8646
8647 config HIGHMEM4G
8648 bool "4GB"
8649 - depends on !X86_NUMAQ
8650 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8651 ---help---
8652 Select this if you have a 32-bit processor and between 1 and 4
8653 gigabytes of physical RAM.
8654 @@ -1147,7 +1148,7 @@ config PAGE_OFFSET
8655 hex
8656 default 0xB0000000 if VMSPLIT_3G_OPT
8657 default 0x80000000 if VMSPLIT_2G
8658 - default 0x78000000 if VMSPLIT_2G_OPT
8659 + default 0x70000000 if VMSPLIT_2G_OPT
8660 default 0x40000000 if VMSPLIT_1G
8661 default 0xC0000000
8662 depends on X86_32
8663 @@ -1548,6 +1549,7 @@ config SECCOMP
8664
8665 config CC_STACKPROTECTOR
8666 bool "Enable -fstack-protector buffer overflow detection"
8667 + depends on X86_64 || !PAX_MEMORY_UDEREF
8668 ---help---
8669 This option turns on the -fstack-protector GCC feature. This
8670 feature puts, at the beginning of functions, a canary value on
8671 @@ -1605,6 +1607,7 @@ config KEXEC_JUMP
8672 config PHYSICAL_START
8673 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
8674 default "0x1000000"
8675 + range 0x400000 0x40000000
8676 ---help---
8677 This gives the physical address where the kernel is loaded.
8678
8679 @@ -1668,6 +1671,7 @@ config X86_NEED_RELOCS
8680 config PHYSICAL_ALIGN
8681 hex "Alignment value to which kernel should be aligned" if X86_32
8682 default "0x1000000"
8683 + range 0x400000 0x1000000 if PAX_KERNEXEC
8684 range 0x2000 0x1000000
8685 ---help---
8686 This value puts the alignment restrictions on physical address
8687 @@ -1699,9 +1703,10 @@ config HOTPLUG_CPU
8688 Say N if you want to disable CPU hotplug.
8689
8690 config COMPAT_VDSO
8691 - def_bool y
8692 + def_bool n
8693 prompt "Compat VDSO support"
8694 depends on X86_32 || IA32_EMULATION
8695 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
8696 ---help---
8697 Map the 32-bit VDSO to the predictable old-style address too.
8698
8699 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
8700 index f3b86d0..17fd30f 100644
8701 --- a/arch/x86/Kconfig.cpu
8702 +++ b/arch/x86/Kconfig.cpu
8703 @@ -335,7 +335,7 @@ config X86_PPRO_FENCE
8704
8705 config X86_F00F_BUG
8706 def_bool y
8707 - depends on M586MMX || M586TSC || M586 || M486 || M386
8708 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
8709
8710 config X86_INVD_BUG
8711 def_bool y
8712 @@ -359,7 +359,7 @@ config X86_POPAD_OK
8713
8714 config X86_ALIGNMENT_16
8715 def_bool y
8716 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8717 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8718
8719 config X86_INTEL_USERCOPY
8720 def_bool y
8721 @@ -405,7 +405,7 @@ config X86_CMPXCHG64
8722 # generates cmov.
8723 config X86_CMOV
8724 def_bool y
8725 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8726 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8727
8728 config X86_MINIMUM_CPU_FAMILY
8729 int
8730 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
8731 index b322f12..652d0d9 100644
8732 --- a/arch/x86/Kconfig.debug
8733 +++ b/arch/x86/Kconfig.debug
8734 @@ -84,7 +84,7 @@ config X86_PTDUMP
8735 config DEBUG_RODATA
8736 bool "Write protect kernel read-only data structures"
8737 default y
8738 - depends on DEBUG_KERNEL
8739 + depends on DEBUG_KERNEL && BROKEN
8740 ---help---
8741 Mark the kernel read-only data as write-protected in the pagetables,
8742 in order to catch accidental (and incorrect) writes to such const
8743 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
8744
8745 config DEBUG_SET_MODULE_RONX
8746 bool "Set loadable kernel module data as NX and text as RO"
8747 - depends on MODULES
8748 + depends on MODULES && BROKEN
8749 ---help---
8750 This option helps catch unintended modifications to loadable
8751 kernel module's text and read-only data. It also prevents execution
8752 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
8753
8754 config DEBUG_STRICT_USER_COPY_CHECKS
8755 bool "Strict copy size checks"
8756 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
8757 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
8758 ---help---
8759 Enabling this option turns a certain set of sanity checks for user
8760 copy operations into compile time failures.
8761 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
8762 index 05afcca..b6ecb51 100644
8763 --- a/arch/x86/Makefile
8764 +++ b/arch/x86/Makefile
8765 @@ -50,6 +50,7 @@ else
8766 UTS_MACHINE := x86_64
8767 CHECKFLAGS += -D__x86_64__ -m64
8768
8769 + biarch := $(call cc-option,-m64)
8770 KBUILD_AFLAGS += -m64
8771 KBUILD_CFLAGS += -m64
8772
8773 @@ -229,3 +230,12 @@ define archhelp
8774 echo ' FDARGS="..." arguments for the booted kernel'
8775 echo ' FDINITRD=file initrd for the booted kernel'
8776 endef
8777 +
8778 +define OLD_LD
8779 +
8780 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
8781 +*** Please upgrade your binutils to 2.18 or newer
8782 +endef
8783 +
8784 +archprepare:
8785 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
8786 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
8787 index ccce0ed..fd9da25 100644
8788 --- a/arch/x86/boot/Makefile
8789 +++ b/arch/x86/boot/Makefile
8790 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
8791 $(call cc-option, -fno-stack-protector) \
8792 $(call cc-option, -mpreferred-stack-boundary=2)
8793 KBUILD_CFLAGS += $(call cc-option, -m32)
8794 +ifdef CONSTIFY_PLUGIN
8795 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8796 +endif
8797 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8798 GCOV_PROFILE := n
8799
8800 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
8801 index 878e4b9..20537ab 100644
8802 --- a/arch/x86/boot/bitops.h
8803 +++ b/arch/x86/boot/bitops.h
8804 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8805 u8 v;
8806 const u32 *p = (const u32 *)addr;
8807
8808 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8809 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8810 return v;
8811 }
8812
8813 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8814
8815 static inline void set_bit(int nr, void *addr)
8816 {
8817 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8818 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8819 }
8820
8821 #endif /* BOOT_BITOPS_H */
8822 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
8823 index 18997e5..83d9c67 100644
8824 --- a/arch/x86/boot/boot.h
8825 +++ b/arch/x86/boot/boot.h
8826 @@ -85,7 +85,7 @@ static inline void io_delay(void)
8827 static inline u16 ds(void)
8828 {
8829 u16 seg;
8830 - asm("movw %%ds,%0" : "=rm" (seg));
8831 + asm volatile("movw %%ds,%0" : "=rm" (seg));
8832 return seg;
8833 }
8834
8835 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
8836 static inline int memcmp(const void *s1, const void *s2, size_t len)
8837 {
8838 u8 diff;
8839 - asm("repe; cmpsb; setnz %0"
8840 + asm volatile("repe; cmpsb; setnz %0"
8841 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
8842 return diff;
8843 }
8844 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
8845 index 8a84501..b2d165f 100644
8846 --- a/arch/x86/boot/compressed/Makefile
8847 +++ b/arch/x86/boot/compressed/Makefile
8848 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
8849 KBUILD_CFLAGS += $(cflags-y)
8850 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
8851 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
8852 +ifdef CONSTIFY_PLUGIN
8853 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8854 +endif
8855
8856 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8857 GCOV_PROFILE := n
8858 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
8859 index ccae7e2..8ac70be 100644
8860 --- a/arch/x86/boot/compressed/eboot.c
8861 +++ b/arch/x86/boot/compressed/eboot.c
8862 @@ -144,7 +144,6 @@ again:
8863 *addr = max_addr;
8864 }
8865
8866 -free_pool:
8867 efi_call_phys1(sys_table->boottime->free_pool, map);
8868
8869 fail:
8870 @@ -208,7 +207,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
8871 if (i == map_size / desc_size)
8872 status = EFI_NOT_FOUND;
8873
8874 -free_pool:
8875 efi_call_phys1(sys_table->boottime->free_pool, map);
8876 fail:
8877 return status;
8878 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
8879 index ccb2f4a..e49b20e 100644
8880 --- a/arch/x86/boot/compressed/head_32.S
8881 +++ b/arch/x86/boot/compressed/head_32.S
8882 @@ -118,7 +118,7 @@ preferred_addr:
8883 notl %eax
8884 andl %eax, %ebx
8885 #else
8886 - movl $LOAD_PHYSICAL_ADDR, %ebx
8887 + movl $____LOAD_PHYSICAL_ADDR, %ebx
8888 #endif
8889
8890 /* Target address to relocate to for decompression */
8891 @@ -204,7 +204,7 @@ relocated:
8892 * and where it was actually loaded.
8893 */
8894 movl %ebp, %ebx
8895 - subl $LOAD_PHYSICAL_ADDR, %ebx
8896 + subl $____LOAD_PHYSICAL_ADDR, %ebx
8897 jz 2f /* Nothing to be done if loaded at compiled addr. */
8898 /*
8899 * Process relocations.
8900 @@ -212,8 +212,7 @@ relocated:
8901
8902 1: subl $4, %edi
8903 movl (%edi), %ecx
8904 - testl %ecx, %ecx
8905 - jz 2f
8906 + jecxz 2f
8907 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
8908 jmp 1b
8909 2:
8910 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
8911 index 2c4b171..e1fa5b1 100644
8912 --- a/arch/x86/boot/compressed/head_64.S
8913 +++ b/arch/x86/boot/compressed/head_64.S
8914 @@ -91,7 +91,7 @@ ENTRY(startup_32)
8915 notl %eax
8916 andl %eax, %ebx
8917 #else
8918 - movl $LOAD_PHYSICAL_ADDR, %ebx
8919 + movl $____LOAD_PHYSICAL_ADDR, %ebx
8920 #endif
8921
8922 /* Target address to relocate to for decompression */
8923 @@ -273,7 +273,7 @@ preferred_addr:
8924 notq %rax
8925 andq %rax, %rbp
8926 #else
8927 - movq $LOAD_PHYSICAL_ADDR, %rbp
8928 + movq $____LOAD_PHYSICAL_ADDR, %rbp
8929 #endif
8930
8931 /* Target address to relocate to for decompression */
8932 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
8933 index 88f7ff6..ed695dd 100644
8934 --- a/arch/x86/boot/compressed/misc.c
8935 +++ b/arch/x86/boot/compressed/misc.c
8936 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
8937 case PT_LOAD:
8938 #ifdef CONFIG_RELOCATABLE
8939 dest = output;
8940 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
8941 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
8942 #else
8943 dest = (void *)(phdr->p_paddr);
8944 #endif
8945 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
8946 error("Destination address too large");
8947 #endif
8948 #ifndef CONFIG_RELOCATABLE
8949 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
8950 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
8951 error("Wrong destination address");
8952 #endif
8953
8954 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
8955 index 4d3ff03..e4972ff 100644
8956 --- a/arch/x86/boot/cpucheck.c
8957 +++ b/arch/x86/boot/cpucheck.c
8958 @@ -74,7 +74,7 @@ static int has_fpu(void)
8959 u16 fcw = -1, fsw = -1;
8960 u32 cr0;
8961
8962 - asm("movl %%cr0,%0" : "=r" (cr0));
8963 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
8964 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
8965 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
8966 asm volatile("movl %0,%%cr0" : : "r" (cr0));
8967 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
8968 {
8969 u32 f0, f1;
8970
8971 - asm("pushfl ; "
8972 + asm volatile("pushfl ; "
8973 "pushfl ; "
8974 "popl %0 ; "
8975 "movl %0,%1 ; "
8976 @@ -115,7 +115,7 @@ static void get_flags(void)
8977 set_bit(X86_FEATURE_FPU, cpu.flags);
8978
8979 if (has_eflag(X86_EFLAGS_ID)) {
8980 - asm("cpuid"
8981 + asm volatile("cpuid"
8982 : "=a" (max_intel_level),
8983 "=b" (cpu_vendor[0]),
8984 "=d" (cpu_vendor[1]),
8985 @@ -124,7 +124,7 @@ static void get_flags(void)
8986
8987 if (max_intel_level >= 0x00000001 &&
8988 max_intel_level <= 0x0000ffff) {
8989 - asm("cpuid"
8990 + asm volatile("cpuid"
8991 : "=a" (tfms),
8992 "=c" (cpu.flags[4]),
8993 "=d" (cpu.flags[0])
8994 @@ -136,7 +136,7 @@ static void get_flags(void)
8995 cpu.model += ((tfms >> 16) & 0xf) << 4;
8996 }
8997
8998 - asm("cpuid"
8999 + asm volatile("cpuid"
9000 : "=a" (max_amd_level)
9001 : "a" (0x80000000)
9002 : "ebx", "ecx", "edx");
9003 @@ -144,7 +144,7 @@ static void get_flags(void)
9004 if (max_amd_level >= 0x80000001 &&
9005 max_amd_level <= 0x8000ffff) {
9006 u32 eax = 0x80000001;
9007 - asm("cpuid"
9008 + asm volatile("cpuid"
9009 : "+a" (eax),
9010 "=c" (cpu.flags[6]),
9011 "=d" (cpu.flags[1])
9012 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9013 u32 ecx = MSR_K7_HWCR;
9014 u32 eax, edx;
9015
9016 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9017 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9018 eax &= ~(1 << 15);
9019 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9020 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9021
9022 get_flags(); /* Make sure it really did something */
9023 err = check_flags();
9024 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9025 u32 ecx = MSR_VIA_FCR;
9026 u32 eax, edx;
9027
9028 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9029 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9030 eax |= (1<<1)|(1<<7);
9031 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9032 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9033
9034 set_bit(X86_FEATURE_CX8, cpu.flags);
9035 err = check_flags();
9036 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9037 u32 eax, edx;
9038 u32 level = 1;
9039
9040 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9041 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
9042 - asm("cpuid"
9043 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9044 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
9045 + asm volatile("cpuid"
9046 : "+a" (level), "=d" (cpu.flags[0])
9047 : : "ecx", "ebx");
9048 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9049 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9050
9051 err = check_flags();
9052 }
9053 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
9054 index 8c132a6..13e5c96 100644
9055 --- a/arch/x86/boot/header.S
9056 +++ b/arch/x86/boot/header.S
9057 @@ -387,10 +387,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
9058 # single linked list of
9059 # struct setup_data
9060
9061 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
9062 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
9063
9064 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
9065 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
9066 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
9067 +#else
9068 #define VO_INIT_SIZE (VO__end - VO__text)
9069 +#endif
9070 #if ZO_INIT_SIZE > VO_INIT_SIZE
9071 #define INIT_SIZE ZO_INIT_SIZE
9072 #else
9073 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
9074 index db75d07..8e6d0af 100644
9075 --- a/arch/x86/boot/memory.c
9076 +++ b/arch/x86/boot/memory.c
9077 @@ -19,7 +19,7 @@
9078
9079 static int detect_memory_e820(void)
9080 {
9081 - int count = 0;
9082 + unsigned int count = 0;
9083 struct biosregs ireg, oreg;
9084 struct e820entry *desc = boot_params.e820_map;
9085 static struct e820entry buf; /* static so it is zeroed */
9086 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
9087 index 11e8c6e..fdbb1ed 100644
9088 --- a/arch/x86/boot/video-vesa.c
9089 +++ b/arch/x86/boot/video-vesa.c
9090 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
9091
9092 boot_params.screen_info.vesapm_seg = oreg.es;
9093 boot_params.screen_info.vesapm_off = oreg.di;
9094 + boot_params.screen_info.vesapm_size = oreg.cx;
9095 }
9096
9097 /*
9098 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
9099 index 43eda28..5ab5fdb 100644
9100 --- a/arch/x86/boot/video.c
9101 +++ b/arch/x86/boot/video.c
9102 @@ -96,7 +96,7 @@ static void store_mode_params(void)
9103 static unsigned int get_entry(void)
9104 {
9105 char entry_buf[4];
9106 - int i, len = 0;
9107 + unsigned int i, len = 0;
9108 int key;
9109 unsigned int v;
9110
9111 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
9112 index 5b577d5..3c1fed4 100644
9113 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
9114 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
9115 @@ -8,6 +8,8 @@
9116 * including this sentence is retained in full.
9117 */
9118
9119 +#include <asm/alternative-asm.h>
9120 +
9121 .extern crypto_ft_tab
9122 .extern crypto_it_tab
9123 .extern crypto_fl_tab
9124 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
9125 je B192; \
9126 leaq 32(r9),r9;
9127
9128 +#define ret pax_force_retaddr 0, 1; ret
9129 +
9130 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
9131 movq r1,r2; \
9132 movq r3,r4; \
9133 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
9134 index 3470624..201259d 100644
9135 --- a/arch/x86/crypto/aesni-intel_asm.S
9136 +++ b/arch/x86/crypto/aesni-intel_asm.S
9137 @@ -31,6 +31,7 @@
9138
9139 #include <linux/linkage.h>
9140 #include <asm/inst.h>
9141 +#include <asm/alternative-asm.h>
9142
9143 #ifdef __x86_64__
9144 .data
9145 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
9146 pop %r14
9147 pop %r13
9148 pop %r12
9149 + pax_force_retaddr 0, 1
9150 ret
9151 +ENDPROC(aesni_gcm_dec)
9152
9153
9154 /*****************************************************************************
9155 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
9156 pop %r14
9157 pop %r13
9158 pop %r12
9159 + pax_force_retaddr 0, 1
9160 ret
9161 +ENDPROC(aesni_gcm_enc)
9162
9163 #endif
9164
9165 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
9166 pxor %xmm1, %xmm0
9167 movaps %xmm0, (TKEYP)
9168 add $0x10, TKEYP
9169 + pax_force_retaddr_bts
9170 ret
9171
9172 .align 4
9173 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
9174 shufps $0b01001110, %xmm2, %xmm1
9175 movaps %xmm1, 0x10(TKEYP)
9176 add $0x20, TKEYP
9177 + pax_force_retaddr_bts
9178 ret
9179
9180 .align 4
9181 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
9182
9183 movaps %xmm0, (TKEYP)
9184 add $0x10, TKEYP
9185 + pax_force_retaddr_bts
9186 ret
9187
9188 .align 4
9189 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
9190 pxor %xmm1, %xmm2
9191 movaps %xmm2, (TKEYP)
9192 add $0x10, TKEYP
9193 + pax_force_retaddr_bts
9194 ret
9195
9196 /*
9197 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
9198 #ifndef __x86_64__
9199 popl KEYP
9200 #endif
9201 + pax_force_retaddr 0, 1
9202 ret
9203 +ENDPROC(aesni_set_key)
9204
9205 /*
9206 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
9207 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
9208 popl KLEN
9209 popl KEYP
9210 #endif
9211 + pax_force_retaddr 0, 1
9212 ret
9213 +ENDPROC(aesni_enc)
9214
9215 /*
9216 * _aesni_enc1: internal ABI
9217 @@ -1959,6 +1972,7 @@ _aesni_enc1:
9218 AESENC KEY STATE
9219 movaps 0x70(TKEYP), KEY
9220 AESENCLAST KEY STATE
9221 + pax_force_retaddr_bts
9222 ret
9223
9224 /*
9225 @@ -2067,6 +2081,7 @@ _aesni_enc4:
9226 AESENCLAST KEY STATE2
9227 AESENCLAST KEY STATE3
9228 AESENCLAST KEY STATE4
9229 + pax_force_retaddr_bts
9230 ret
9231
9232 /*
9233 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
9234 popl KLEN
9235 popl KEYP
9236 #endif
9237 + pax_force_retaddr 0, 1
9238 ret
9239 +ENDPROC(aesni_dec)
9240
9241 /*
9242 * _aesni_dec1: internal ABI
9243 @@ -2146,6 +2163,7 @@ _aesni_dec1:
9244 AESDEC KEY STATE
9245 movaps 0x70(TKEYP), KEY
9246 AESDECLAST KEY STATE
9247 + pax_force_retaddr_bts
9248 ret
9249
9250 /*
9251 @@ -2254,6 +2272,7 @@ _aesni_dec4:
9252 AESDECLAST KEY STATE2
9253 AESDECLAST KEY STATE3
9254 AESDECLAST KEY STATE4
9255 + pax_force_retaddr_bts
9256 ret
9257
9258 /*
9259 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
9260 popl KEYP
9261 popl LEN
9262 #endif
9263 + pax_force_retaddr 0, 1
9264 ret
9265 +ENDPROC(aesni_ecb_enc)
9266
9267 /*
9268 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9269 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
9270 popl KEYP
9271 popl LEN
9272 #endif
9273 + pax_force_retaddr 0, 1
9274 ret
9275 +ENDPROC(aesni_ecb_dec)
9276
9277 /*
9278 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9279 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
9280 popl LEN
9281 popl IVP
9282 #endif
9283 + pax_force_retaddr 0, 1
9284 ret
9285 +ENDPROC(aesni_cbc_enc)
9286
9287 /*
9288 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9289 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
9290 popl LEN
9291 popl IVP
9292 #endif
9293 + pax_force_retaddr 0, 1
9294 ret
9295 +ENDPROC(aesni_cbc_dec)
9296
9297 #ifdef __x86_64__
9298 .align 16
9299 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
9300 mov $1, TCTR_LOW
9301 MOVQ_R64_XMM TCTR_LOW INC
9302 MOVQ_R64_XMM CTR TCTR_LOW
9303 + pax_force_retaddr_bts
9304 ret
9305
9306 /*
9307 @@ -2554,6 +2582,7 @@ _aesni_inc:
9308 .Linc_low:
9309 movaps CTR, IV
9310 PSHUFB_XMM BSWAP_MASK IV
9311 + pax_force_retaddr_bts
9312 ret
9313
9314 /*
9315 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
9316 .Lctr_enc_ret:
9317 movups IV, (IVP)
9318 .Lctr_enc_just_ret:
9319 + pax_force_retaddr 0, 1
9320 ret
9321 +ENDPROC(aesni_ctr_enc)
9322 #endif
9323 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9324 index 391d245..67f35c2 100644
9325 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
9326 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9327 @@ -20,6 +20,8 @@
9328 *
9329 */
9330
9331 +#include <asm/alternative-asm.h>
9332 +
9333 .file "blowfish-x86_64-asm.S"
9334 .text
9335
9336 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
9337 jnz __enc_xor;
9338
9339 write_block();
9340 + pax_force_retaddr 0, 1
9341 ret;
9342 __enc_xor:
9343 xor_block();
9344 + pax_force_retaddr 0, 1
9345 ret;
9346
9347 .align 8
9348 @@ -188,6 +192,7 @@ blowfish_dec_blk:
9349
9350 movq %r11, %rbp;
9351
9352 + pax_force_retaddr 0, 1
9353 ret;
9354
9355 /**********************************************************************
9356 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
9357
9358 popq %rbx;
9359 popq %rbp;
9360 + pax_force_retaddr 0, 1
9361 ret;
9362
9363 __enc_xor4:
9364 @@ -349,6 +355,7 @@ __enc_xor4:
9365
9366 popq %rbx;
9367 popq %rbp;
9368 + pax_force_retaddr 0, 1
9369 ret;
9370
9371 .align 8
9372 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
9373 popq %rbx;
9374 popq %rbp;
9375
9376 + pax_force_retaddr 0, 1
9377 ret;
9378
9379 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
9380 index 0b33743..7a56206 100644
9381 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
9382 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
9383 @@ -20,6 +20,8 @@
9384 *
9385 */
9386
9387 +#include <asm/alternative-asm.h>
9388 +
9389 .file "camellia-x86_64-asm_64.S"
9390 .text
9391
9392 @@ -229,12 +231,14 @@ __enc_done:
9393 enc_outunpack(mov, RT1);
9394
9395 movq RRBP, %rbp;
9396 + pax_force_retaddr 0, 1
9397 ret;
9398
9399 __enc_xor:
9400 enc_outunpack(xor, RT1);
9401
9402 movq RRBP, %rbp;
9403 + pax_force_retaddr 0, 1
9404 ret;
9405
9406 .global camellia_dec_blk;
9407 @@ -275,6 +279,7 @@ __dec_rounds16:
9408 dec_outunpack();
9409
9410 movq RRBP, %rbp;
9411 + pax_force_retaddr 0, 1
9412 ret;
9413
9414 /**********************************************************************
9415 @@ -468,6 +473,7 @@ __enc2_done:
9416
9417 movq RRBP, %rbp;
9418 popq %rbx;
9419 + pax_force_retaddr 0, 1
9420 ret;
9421
9422 __enc2_xor:
9423 @@ -475,6 +481,7 @@ __enc2_xor:
9424
9425 movq RRBP, %rbp;
9426 popq %rbx;
9427 + pax_force_retaddr 0, 1
9428 ret;
9429
9430 .global camellia_dec_blk_2way;
9431 @@ -517,4 +524,5 @@ __dec2_rounds16:
9432
9433 movq RRBP, %rbp;
9434 movq RXOR, %rbx;
9435 + pax_force_retaddr 0, 1
9436 ret;
9437 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9438 index a41a3aa..bdf5753 100644
9439 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9440 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9441 @@ -23,6 +23,8 @@
9442 *
9443 */
9444
9445 +#include <asm/alternative-asm.h>
9446 +
9447 .file "cast5-avx-x86_64-asm_64.S"
9448
9449 .extern cast5_s1
9450 @@ -293,6 +295,7 @@ __skip_enc:
9451 leaq 3*(2*4*4)(%r11), %rax;
9452 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9453
9454 + pax_force_retaddr 0, 1
9455 ret;
9456
9457 __enc_xor16:
9458 @@ -303,6 +306,7 @@ __enc_xor16:
9459 leaq 3*(2*4*4)(%r11), %rax;
9460 outunpack_xor_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9461
9462 + pax_force_retaddr 0, 1
9463 ret;
9464
9465 .align 16
9466 @@ -369,6 +373,7 @@ __dec_tail:
9467 leaq 3*(2*4*4)(%r11), %rax;
9468 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9469
9470 + pax_force_retaddr 0, 1
9471 ret;
9472
9473 __skip_dec:
9474 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9475 index 218d283..819e6da 100644
9476 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9477 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9478 @@ -23,6 +23,8 @@
9479 *
9480 */
9481
9482 +#include <asm/alternative-asm.h>
9483 +
9484 .file "cast6-avx-x86_64-asm_64.S"
9485
9486 .extern cast6_s1
9487 @@ -324,12 +326,14 @@ __cast6_enc_blk_8way:
9488 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9489 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9490
9491 + pax_force_retaddr 0, 1
9492 ret;
9493
9494 __enc_xor8:
9495 outunpack_xor_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9496 outunpack_xor_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9497
9498 + pax_force_retaddr 0, 1
9499 ret;
9500
9501 .align 16
9502 @@ -380,4 +384,5 @@ cast6_dec_blk_8way:
9503 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9504 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9505
9506 + pax_force_retaddr 0, 1
9507 ret;
9508 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9509 index 6214a9b..1f4fc9a 100644
9510 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
9511 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9512 @@ -1,3 +1,5 @@
9513 +#include <asm/alternative-asm.h>
9514 +
9515 # enter ECRYPT_encrypt_bytes
9516 .text
9517 .p2align 5
9518 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
9519 add %r11,%rsp
9520 mov %rdi,%rax
9521 mov %rsi,%rdx
9522 + pax_force_retaddr 0, 1
9523 ret
9524 # bytesatleast65:
9525 ._bytesatleast65:
9526 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
9527 add %r11,%rsp
9528 mov %rdi,%rax
9529 mov %rsi,%rdx
9530 + pax_force_retaddr
9531 ret
9532 # enter ECRYPT_ivsetup
9533 .text
9534 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
9535 add %r11,%rsp
9536 mov %rdi,%rax
9537 mov %rsi,%rdx
9538 + pax_force_retaddr
9539 ret
9540 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9541 index 504106b..4e50951 100644
9542 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9543 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9544 @@ -24,6 +24,8 @@
9545 *
9546 */
9547
9548 +#include <asm/alternative-asm.h>
9549 +
9550 .file "serpent-avx-x86_64-asm_64.S"
9551 .text
9552
9553 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
9554 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9555 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9556
9557 + pax_force_retaddr
9558 ret;
9559
9560 __enc_xor8:
9561 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9562 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9563
9564 + pax_force_retaddr
9565 ret;
9566
9567 .align 8
9568 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
9569 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9570 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9571
9572 + pax_force_retaddr
9573 ret;
9574 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9575 index 3ee1ff0..cbc568b 100644
9576 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9577 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9578 @@ -24,6 +24,8 @@
9579 *
9580 */
9581
9582 +#include <asm/alternative-asm.h>
9583 +
9584 .file "serpent-sse2-x86_64-asm_64.S"
9585 .text
9586
9587 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
9588 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9589 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9590
9591 + pax_force_retaddr
9592 ret;
9593
9594 __enc_xor8:
9595 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9596 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9597
9598 + pax_force_retaddr
9599 ret;
9600
9601 .align 8
9602 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
9603 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9604 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9605
9606 + pax_force_retaddr
9607 ret;
9608 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
9609 index 49d6987..df66bd4 100644
9610 --- a/arch/x86/crypto/sha1_ssse3_asm.S
9611 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
9612 @@ -28,6 +28,8 @@
9613 * (at your option) any later version.
9614 */
9615
9616 +#include <asm/alternative-asm.h>
9617 +
9618 #define CTX %rdi // arg1
9619 #define BUF %rsi // arg2
9620 #define CNT %rdx // arg3
9621 @@ -104,6 +106,7 @@
9622 pop %r12
9623 pop %rbp
9624 pop %rbx
9625 + pax_force_retaddr 0, 1
9626 ret
9627
9628 .size \name, .-\name
9629 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9630 index 1585abb..4a9af16 100644
9631 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9632 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9633 @@ -23,6 +23,8 @@
9634 *
9635 */
9636
9637 +#include <asm/alternative-asm.h>
9638 +
9639 .file "twofish-avx-x86_64-asm_64.S"
9640 .text
9641
9642 @@ -303,12 +305,14 @@ __twofish_enc_blk_8way:
9643 outunpack_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9644 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9645
9646 + pax_force_retaddr
9647 ret;
9648
9649 __enc_xor8:
9650 outunpack_xor_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9651 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9652
9653 + pax_force_retaddr
9654 ret;
9655
9656 .align 8
9657 @@ -354,4 +358,5 @@ twofish_dec_blk_8way:
9658 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
9659 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
9660
9661 + pax_force_retaddr
9662 ret;
9663 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9664 index 5b012a2..36d5364 100644
9665 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9666 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9667 @@ -20,6 +20,8 @@
9668 *
9669 */
9670
9671 +#include <asm/alternative-asm.h>
9672 +
9673 .file "twofish-x86_64-asm-3way.S"
9674 .text
9675
9676 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
9677 popq %r13;
9678 popq %r14;
9679 popq %r15;
9680 + pax_force_retaddr 0, 1
9681 ret;
9682
9683 __enc_xor3:
9684 @@ -271,6 +274,7 @@ __enc_xor3:
9685 popq %r13;
9686 popq %r14;
9687 popq %r15;
9688 + pax_force_retaddr 0, 1
9689 ret;
9690
9691 .global twofish_dec_blk_3way
9692 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
9693 popq %r13;
9694 popq %r14;
9695 popq %r15;
9696 + pax_force_retaddr 0, 1
9697 ret;
9698
9699 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
9700 index 7bcf3fc..f53832f 100644
9701 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
9702 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
9703 @@ -21,6 +21,7 @@
9704 .text
9705
9706 #include <asm/asm-offsets.h>
9707 +#include <asm/alternative-asm.h>
9708
9709 #define a_offset 0
9710 #define b_offset 4
9711 @@ -268,6 +269,7 @@ twofish_enc_blk:
9712
9713 popq R1
9714 movq $1,%rax
9715 + pax_force_retaddr 0, 1
9716 ret
9717
9718 twofish_dec_blk:
9719 @@ -319,4 +321,5 @@ twofish_dec_blk:
9720
9721 popq R1
9722 movq $1,%rax
9723 + pax_force_retaddr 0, 1
9724 ret
9725 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
9726 index 07b3a68..bd2a388 100644
9727 --- a/arch/x86/ia32/ia32_aout.c
9728 +++ b/arch/x86/ia32/ia32_aout.c
9729 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
9730 unsigned long dump_start, dump_size;
9731 struct user32 dump;
9732
9733 + memset(&dump, 0, sizeof(dump));
9734 +
9735 fs = get_fs();
9736 set_fs(KERNEL_DS);
9737 has_dumped = 1;
9738 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
9739 index efc6a95..95abfe2 100644
9740 --- a/arch/x86/ia32/ia32_signal.c
9741 +++ b/arch/x86/ia32/ia32_signal.c
9742 @@ -163,8 +163,8 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
9743 }
9744 seg = get_fs();
9745 set_fs(KERNEL_DS);
9746 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
9747 - (stack_t __force __user *) &uoss, regs->sp);
9748 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
9749 + (stack_t __force_user *) &uoss, regs->sp);
9750 set_fs(seg);
9751 if (ret >= 0 && uoss_ptr) {
9752 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
9753 @@ -396,7 +396,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
9754 sp -= frame_size;
9755 /* Align the stack pointer according to the i386 ABI,
9756 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
9757 - sp = ((sp + 4) & -16ul) - 4;
9758 + sp = ((sp - 12) & -16ul) - 4;
9759 return (void __user *) sp;
9760 }
9761
9762 @@ -454,7 +454,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
9763 * These are actually not used anymore, but left because some
9764 * gdb versions depend on them as a marker.
9765 */
9766 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9767 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9768 } put_user_catch(err);
9769
9770 if (err)
9771 @@ -496,7 +496,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9772 0xb8,
9773 __NR_ia32_rt_sigreturn,
9774 0x80cd,
9775 - 0,
9776 + 0
9777 };
9778
9779 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
9780 @@ -522,16 +522,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9781
9782 if (ka->sa.sa_flags & SA_RESTORER)
9783 restorer = ka->sa.sa_restorer;
9784 + else if (current->mm->context.vdso)
9785 + /* Return stub is in 32bit vsyscall page */
9786 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
9787 else
9788 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
9789 - rt_sigreturn);
9790 + restorer = &frame->retcode;
9791 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
9792
9793 /*
9794 * Not actually used anymore, but left because some gdb
9795 * versions need it.
9796 */
9797 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9798 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9799 } put_user_catch(err);
9800
9801 err |= copy_siginfo_to_user32(&frame->info, info);
9802 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
9803 index 076745f..ae8f6cb 100644
9804 --- a/arch/x86/ia32/ia32entry.S
9805 +++ b/arch/x86/ia32/ia32entry.S
9806 @@ -15,8 +15,10 @@
9807 #include <asm/irqflags.h>
9808 #include <asm/asm.h>
9809 #include <asm/smap.h>
9810 +#include <asm/pgtable.h>
9811 #include <linux/linkage.h>
9812 #include <linux/err.h>
9813 +#include <asm/alternative-asm.h>
9814
9815 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
9816 #include <linux/elf-em.h>
9817 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
9818 ENDPROC(native_irq_enable_sysexit)
9819 #endif
9820
9821 + .macro pax_enter_kernel_user
9822 + pax_set_fptr_mask
9823 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9824 + call pax_enter_kernel_user
9825 +#endif
9826 + .endm
9827 +
9828 + .macro pax_exit_kernel_user
9829 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9830 + call pax_exit_kernel_user
9831 +#endif
9832 +#ifdef CONFIG_PAX_RANDKSTACK
9833 + pushq %rax
9834 + pushq %r11
9835 + call pax_randomize_kstack
9836 + popq %r11
9837 + popq %rax
9838 +#endif
9839 + .endm
9840 +
9841 +.macro pax_erase_kstack
9842 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
9843 + call pax_erase_kstack
9844 +#endif
9845 +.endm
9846 +
9847 /*
9848 * 32bit SYSENTER instruction entry.
9849 *
9850 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
9851 CFI_REGISTER rsp,rbp
9852 SWAPGS_UNSAFE_STACK
9853 movq PER_CPU_VAR(kernel_stack), %rsp
9854 - addq $(KERNEL_STACK_OFFSET),%rsp
9855 - /*
9856 - * No need to follow this irqs on/off section: the syscall
9857 - * disabled irqs, here we enable it straight after entry:
9858 - */
9859 - ENABLE_INTERRUPTS(CLBR_NONE)
9860 movl %ebp,%ebp /* zero extension */
9861 pushq_cfi $__USER32_DS
9862 /*CFI_REL_OFFSET ss,0*/
9863 @@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
9864 CFI_REL_OFFSET rsp,0
9865 pushfq_cfi
9866 /*CFI_REL_OFFSET rflags,0*/
9867 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
9868 - CFI_REGISTER rip,r10
9869 + orl $X86_EFLAGS_IF,(%rsp)
9870 + GET_THREAD_INFO(%r11)
9871 + movl TI_sysenter_return(%r11), %r11d
9872 + CFI_REGISTER rip,r11
9873 pushq_cfi $__USER32_CS
9874 /*CFI_REL_OFFSET cs,0*/
9875 movl %eax, %eax
9876 - pushq_cfi %r10
9877 + pushq_cfi %r11
9878 CFI_REL_OFFSET rip,0
9879 pushq_cfi %rax
9880 cld
9881 SAVE_ARGS 0,1,0
9882 + pax_enter_kernel_user
9883 +
9884 +#ifdef CONFIG_PAX_RANDKSTACK
9885 + pax_erase_kstack
9886 +#endif
9887 +
9888 + /*
9889 + * No need to follow this irqs on/off section: the syscall
9890 + * disabled irqs, here we enable it straight after entry:
9891 + */
9892 + ENABLE_INTERRUPTS(CLBR_NONE)
9893 /* no need to do an access_ok check here because rbp has been
9894 32bit zero extended */
9895 +
9896 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9897 + mov $PAX_USER_SHADOW_BASE,%r11
9898 + add %r11,%rbp
9899 +#endif
9900 +
9901 ASM_STAC
9902 1: movl (%rbp),%ebp
9903 _ASM_EXTABLE(1b,ia32_badarg)
9904 ASM_CLAC
9905 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9906 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9907 + GET_THREAD_INFO(%r11)
9908 + orl $TS_COMPAT,TI_status(%r11)
9909 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9910 CFI_REMEMBER_STATE
9911 jnz sysenter_tracesys
9912 cmpq $(IA32_NR_syscalls-1),%rax
9913 @@ -162,12 +204,15 @@ sysenter_do_call:
9914 sysenter_dispatch:
9915 call *ia32_sys_call_table(,%rax,8)
9916 movq %rax,RAX-ARGOFFSET(%rsp)
9917 + GET_THREAD_INFO(%r11)
9918 DISABLE_INTERRUPTS(CLBR_NONE)
9919 TRACE_IRQS_OFF
9920 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9921 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
9922 jnz sysexit_audit
9923 sysexit_from_sys_call:
9924 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9925 + pax_exit_kernel_user
9926 + pax_erase_kstack
9927 + andl $~TS_COMPAT,TI_status(%r11)
9928 /* clear IF, that popfq doesn't enable interrupts early */
9929 andl $~0x200,EFLAGS-R11(%rsp)
9930 movl RIP-R11(%rsp),%edx /* User %eip */
9931 @@ -193,6 +238,9 @@ sysexit_from_sys_call:
9932 movl %eax,%esi /* 2nd arg: syscall number */
9933 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
9934 call __audit_syscall_entry
9935 +
9936 + pax_erase_kstack
9937 +
9938 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
9939 cmpq $(IA32_NR_syscalls-1),%rax
9940 ja ia32_badsys
9941 @@ -204,7 +252,7 @@ sysexit_from_sys_call:
9942 .endm
9943
9944 .macro auditsys_exit exit
9945 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9946 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
9947 jnz ia32_ret_from_sys_call
9948 TRACE_IRQS_ON
9949 sti
9950 @@ -215,11 +263,12 @@ sysexit_from_sys_call:
9951 1: setbe %al /* 1 if error, 0 if not */
9952 movzbl %al,%edi /* zero-extend that into %edi */
9953 call __audit_syscall_exit
9954 + GET_THREAD_INFO(%r11)
9955 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
9956 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
9957 cli
9958 TRACE_IRQS_OFF
9959 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9960 + testl %edi,TI_flags(%r11)
9961 jz \exit
9962 CLEAR_RREGS -ARGOFFSET
9963 jmp int_with_check
9964 @@ -237,7 +286,7 @@ sysexit_audit:
9965
9966 sysenter_tracesys:
9967 #ifdef CONFIG_AUDITSYSCALL
9968 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9969 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
9970 jz sysenter_auditsys
9971 #endif
9972 SAVE_REST
9973 @@ -249,6 +298,9 @@ sysenter_tracesys:
9974 RESTORE_REST
9975 cmpq $(IA32_NR_syscalls-1),%rax
9976 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
9977 +
9978 + pax_erase_kstack
9979 +
9980 jmp sysenter_do_call
9981 CFI_ENDPROC
9982 ENDPROC(ia32_sysenter_target)
9983 @@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
9984 ENTRY(ia32_cstar_target)
9985 CFI_STARTPROC32 simple
9986 CFI_SIGNAL_FRAME
9987 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
9988 + CFI_DEF_CFA rsp,0
9989 CFI_REGISTER rip,rcx
9990 /*CFI_REGISTER rflags,r11*/
9991 SWAPGS_UNSAFE_STACK
9992 movl %esp,%r8d
9993 CFI_REGISTER rsp,r8
9994 movq PER_CPU_VAR(kernel_stack),%rsp
9995 + SAVE_ARGS 8*6,0,0
9996 + pax_enter_kernel_user
9997 +
9998 +#ifdef CONFIG_PAX_RANDKSTACK
9999 + pax_erase_kstack
10000 +#endif
10001 +
10002 /*
10003 * No need to follow this irqs on/off section: the syscall
10004 * disabled irqs and here we enable it straight after entry:
10005 */
10006 ENABLE_INTERRUPTS(CLBR_NONE)
10007 - SAVE_ARGS 8,0,0
10008 movl %eax,%eax /* zero extension */
10009 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
10010 movq %rcx,RIP-ARGOFFSET(%rsp)
10011 @@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
10012 /* no need to do an access_ok check here because r8 has been
10013 32bit zero extended */
10014 /* hardware stack frame is complete now */
10015 +
10016 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10017 + mov $PAX_USER_SHADOW_BASE,%r11
10018 + add %r11,%r8
10019 +#endif
10020 +
10021 ASM_STAC
10022 1: movl (%r8),%r9d
10023 _ASM_EXTABLE(1b,ia32_badarg)
10024 ASM_CLAC
10025 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10026 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10027 + GET_THREAD_INFO(%r11)
10028 + orl $TS_COMPAT,TI_status(%r11)
10029 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
10030 CFI_REMEMBER_STATE
10031 jnz cstar_tracesys
10032 cmpq $IA32_NR_syscalls-1,%rax
10033 @@ -319,12 +384,15 @@ cstar_do_call:
10034 cstar_dispatch:
10035 call *ia32_sys_call_table(,%rax,8)
10036 movq %rax,RAX-ARGOFFSET(%rsp)
10037 + GET_THREAD_INFO(%r11)
10038 DISABLE_INTERRUPTS(CLBR_NONE)
10039 TRACE_IRQS_OFF
10040 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10041 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
10042 jnz sysretl_audit
10043 sysretl_from_sys_call:
10044 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10045 + pax_exit_kernel_user
10046 + pax_erase_kstack
10047 + andl $~TS_COMPAT,TI_status(%r11)
10048 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
10049 movl RIP-ARGOFFSET(%rsp),%ecx
10050 CFI_REGISTER rip,rcx
10051 @@ -352,7 +420,7 @@ sysretl_audit:
10052
10053 cstar_tracesys:
10054 #ifdef CONFIG_AUDITSYSCALL
10055 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10056 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10057 jz cstar_auditsys
10058 #endif
10059 xchgl %r9d,%ebp
10060 @@ -366,6 +434,9 @@ cstar_tracesys:
10061 xchgl %ebp,%r9d
10062 cmpq $(IA32_NR_syscalls-1),%rax
10063 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
10064 +
10065 + pax_erase_kstack
10066 +
10067 jmp cstar_do_call
10068 END(ia32_cstar_target)
10069
10070 @@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
10071 CFI_REL_OFFSET rip,RIP-RIP
10072 PARAVIRT_ADJUST_EXCEPTION_FRAME
10073 SWAPGS
10074 - /*
10075 - * No need to follow this irqs on/off section: the syscall
10076 - * disabled irqs and here we enable it straight after entry:
10077 - */
10078 - ENABLE_INTERRUPTS(CLBR_NONE)
10079 movl %eax,%eax
10080 pushq_cfi %rax
10081 cld
10082 /* note the registers are not zero extended to the sf.
10083 this could be a problem. */
10084 SAVE_ARGS 0,1,0
10085 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10086 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10087 + pax_enter_kernel_user
10088 +
10089 +#ifdef CONFIG_PAX_RANDKSTACK
10090 + pax_erase_kstack
10091 +#endif
10092 +
10093 + /*
10094 + * No need to follow this irqs on/off section: the syscall
10095 + * disabled irqs and here we enable it straight after entry:
10096 + */
10097 + ENABLE_INTERRUPTS(CLBR_NONE)
10098 + GET_THREAD_INFO(%r11)
10099 + orl $TS_COMPAT,TI_status(%r11)
10100 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
10101 jnz ia32_tracesys
10102 cmpq $(IA32_NR_syscalls-1),%rax
10103 ja ia32_badsys
10104 @@ -442,6 +520,9 @@ ia32_tracesys:
10105 RESTORE_REST
10106 cmpq $(IA32_NR_syscalls-1),%rax
10107 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
10108 +
10109 + pax_erase_kstack
10110 +
10111 jmp ia32_do_call
10112 END(ia32_syscall)
10113
10114 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
10115 index 86d68d1..f9960fe 100644
10116 --- a/arch/x86/ia32/sys_ia32.c
10117 +++ b/arch/x86/ia32/sys_ia32.c
10118 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
10119 */
10120 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
10121 {
10122 - typeof(ubuf->st_uid) uid = 0;
10123 - typeof(ubuf->st_gid) gid = 0;
10124 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
10125 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
10126 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
10127 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
10128 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
10129 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
10130 mm_segment_t old_fs = get_fs();
10131
10132 set_fs(KERNEL_DS);
10133 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
10134 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
10135 set_fs(old_fs);
10136 if (put_compat_timespec(&t, interval))
10137 return -EFAULT;
10138 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
10139 mm_segment_t old_fs = get_fs();
10140
10141 set_fs(KERNEL_DS);
10142 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
10143 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
10144 set_fs(old_fs);
10145 if (!ret) {
10146 switch (_NSIG_WORDS) {
10147 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
10148 if (copy_siginfo_from_user32(&info, uinfo))
10149 return -EFAULT;
10150 set_fs(KERNEL_DS);
10151 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
10152 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
10153 set_fs(old_fs);
10154 return ret;
10155 }
10156 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
10157 return -EFAULT;
10158
10159 set_fs(KERNEL_DS);
10160 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
10161 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
10162 count);
10163 set_fs(old_fs);
10164
10165 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
10166 index 372231c..a5aa1a1 100644
10167 --- a/arch/x86/include/asm/alternative-asm.h
10168 +++ b/arch/x86/include/asm/alternative-asm.h
10169 @@ -18,6 +18,45 @@
10170 .endm
10171 #endif
10172
10173 +#ifdef KERNEXEC_PLUGIN
10174 + .macro pax_force_retaddr_bts rip=0
10175 + btsq $63,\rip(%rsp)
10176 + .endm
10177 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10178 + .macro pax_force_retaddr rip=0, reload=0
10179 + btsq $63,\rip(%rsp)
10180 + .endm
10181 + .macro pax_force_fptr ptr
10182 + btsq $63,\ptr
10183 + .endm
10184 + .macro pax_set_fptr_mask
10185 + .endm
10186 +#endif
10187 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
10188 + .macro pax_force_retaddr rip=0, reload=0
10189 + .if \reload
10190 + pax_set_fptr_mask
10191 + .endif
10192 + orq %r10,\rip(%rsp)
10193 + .endm
10194 + .macro pax_force_fptr ptr
10195 + orq %r10,\ptr
10196 + .endm
10197 + .macro pax_set_fptr_mask
10198 + movabs $0x8000000000000000,%r10
10199 + .endm
10200 +#endif
10201 +#else
10202 + .macro pax_force_retaddr rip=0, reload=0
10203 + .endm
10204 + .macro pax_force_fptr ptr
10205 + .endm
10206 + .macro pax_force_retaddr_bts rip=0
10207 + .endm
10208 + .macro pax_set_fptr_mask
10209 + .endm
10210 +#endif
10211 +
10212 .macro altinstruction_entry orig alt feature orig_len alt_len
10213 .long \orig - .
10214 .long \alt - .
10215 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
10216 index 58ed6d9..f1cbe58 100644
10217 --- a/arch/x86/include/asm/alternative.h
10218 +++ b/arch/x86/include/asm/alternative.h
10219 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
10220 ".pushsection .discard,\"aw\",@progbits\n" \
10221 DISCARD_ENTRY(1) \
10222 ".popsection\n" \
10223 - ".pushsection .altinstr_replacement, \"ax\"\n" \
10224 + ".pushsection .altinstr_replacement, \"a\"\n" \
10225 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
10226 ".popsection"
10227
10228 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
10229 DISCARD_ENTRY(1) \
10230 DISCARD_ENTRY(2) \
10231 ".popsection\n" \
10232 - ".pushsection .altinstr_replacement, \"ax\"\n" \
10233 + ".pushsection .altinstr_replacement, \"a\"\n" \
10234 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
10235 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
10236 ".popsection"
10237 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
10238 index 3388034..ba52312 100644
10239 --- a/arch/x86/include/asm/apic.h
10240 +++ b/arch/x86/include/asm/apic.h
10241 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
10242
10243 #ifdef CONFIG_X86_LOCAL_APIC
10244
10245 -extern unsigned int apic_verbosity;
10246 +extern int apic_verbosity;
10247 extern int local_apic_timer_c2_ok;
10248
10249 extern int disable_apic;
10250 @@ -391,7 +391,7 @@ struct apic {
10251 */
10252 int (*x86_32_numa_cpu_node)(int cpu);
10253 #endif
10254 -};
10255 +} __do_const;
10256
10257 /*
10258 * Pointer to the local APIC driver in use on this system (there's
10259 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
10260 index 20370c6..a2eb9b0 100644
10261 --- a/arch/x86/include/asm/apm.h
10262 +++ b/arch/x86/include/asm/apm.h
10263 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
10264 __asm__ __volatile__(APM_DO_ZERO_SEGS
10265 "pushl %%edi\n\t"
10266 "pushl %%ebp\n\t"
10267 - "lcall *%%cs:apm_bios_entry\n\t"
10268 + "lcall *%%ss:apm_bios_entry\n\t"
10269 "setc %%al\n\t"
10270 "popl %%ebp\n\t"
10271 "popl %%edi\n\t"
10272 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
10273 __asm__ __volatile__(APM_DO_ZERO_SEGS
10274 "pushl %%edi\n\t"
10275 "pushl %%ebp\n\t"
10276 - "lcall *%%cs:apm_bios_entry\n\t"
10277 + "lcall *%%ss:apm_bios_entry\n\t"
10278 "setc %%bl\n\t"
10279 "popl %%ebp\n\t"
10280 "popl %%edi\n\t"
10281 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
10282 index b6c3b82..b4c077a 100644
10283 --- a/arch/x86/include/asm/atomic.h
10284 +++ b/arch/x86/include/asm/atomic.h
10285 @@ -22,7 +22,18 @@
10286 */
10287 static inline int atomic_read(const atomic_t *v)
10288 {
10289 - return (*(volatile int *)&(v)->counter);
10290 + return (*(volatile const int *)&(v)->counter);
10291 +}
10292 +
10293 +/**
10294 + * atomic_read_unchecked - read atomic variable
10295 + * @v: pointer of type atomic_unchecked_t
10296 + *
10297 + * Atomically reads the value of @v.
10298 + */
10299 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10300 +{
10301 + return (*(volatile const int *)&(v)->counter);
10302 }
10303
10304 /**
10305 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
10306 }
10307
10308 /**
10309 + * atomic_set_unchecked - set atomic variable
10310 + * @v: pointer of type atomic_unchecked_t
10311 + * @i: required value
10312 + *
10313 + * Atomically sets the value of @v to @i.
10314 + */
10315 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10316 +{
10317 + v->counter = i;
10318 +}
10319 +
10320 +/**
10321 * atomic_add - add integer to atomic variable
10322 * @i: integer value to add
10323 * @v: pointer of type atomic_t
10324 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
10325 */
10326 static inline void atomic_add(int i, atomic_t *v)
10327 {
10328 - asm volatile(LOCK_PREFIX "addl %1,%0"
10329 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
10330 +
10331 +#ifdef CONFIG_PAX_REFCOUNT
10332 + "jno 0f\n"
10333 + LOCK_PREFIX "subl %1,%0\n"
10334 + "int $4\n0:\n"
10335 + _ASM_EXTABLE(0b, 0b)
10336 +#endif
10337 +
10338 + : "+m" (v->counter)
10339 + : "ir" (i));
10340 +}
10341 +
10342 +/**
10343 + * atomic_add_unchecked - add integer to atomic variable
10344 + * @i: integer value to add
10345 + * @v: pointer of type atomic_unchecked_t
10346 + *
10347 + * Atomically adds @i to @v.
10348 + */
10349 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
10350 +{
10351 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
10352 : "+m" (v->counter)
10353 : "ir" (i));
10354 }
10355 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
10356 */
10357 static inline void atomic_sub(int i, atomic_t *v)
10358 {
10359 - asm volatile(LOCK_PREFIX "subl %1,%0"
10360 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
10361 +
10362 +#ifdef CONFIG_PAX_REFCOUNT
10363 + "jno 0f\n"
10364 + LOCK_PREFIX "addl %1,%0\n"
10365 + "int $4\n0:\n"
10366 + _ASM_EXTABLE(0b, 0b)
10367 +#endif
10368 +
10369 + : "+m" (v->counter)
10370 + : "ir" (i));
10371 +}
10372 +
10373 +/**
10374 + * atomic_sub_unchecked - subtract integer from atomic variable
10375 + * @i: integer value to subtract
10376 + * @v: pointer of type atomic_unchecked_t
10377 + *
10378 + * Atomically subtracts @i from @v.
10379 + */
10380 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
10381 +{
10382 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
10383 : "+m" (v->counter)
10384 : "ir" (i));
10385 }
10386 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10387 {
10388 unsigned char c;
10389
10390 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
10391 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
10392 +
10393 +#ifdef CONFIG_PAX_REFCOUNT
10394 + "jno 0f\n"
10395 + LOCK_PREFIX "addl %2,%0\n"
10396 + "int $4\n0:\n"
10397 + _ASM_EXTABLE(0b, 0b)
10398 +#endif
10399 +
10400 + "sete %1\n"
10401 : "+m" (v->counter), "=qm" (c)
10402 : "ir" (i) : "memory");
10403 return c;
10404 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10405 */
10406 static inline void atomic_inc(atomic_t *v)
10407 {
10408 - asm volatile(LOCK_PREFIX "incl %0"
10409 + asm volatile(LOCK_PREFIX "incl %0\n"
10410 +
10411 +#ifdef CONFIG_PAX_REFCOUNT
10412 + "jno 0f\n"
10413 + LOCK_PREFIX "decl %0\n"
10414 + "int $4\n0:\n"
10415 + _ASM_EXTABLE(0b, 0b)
10416 +#endif
10417 +
10418 + : "+m" (v->counter));
10419 +}
10420 +
10421 +/**
10422 + * atomic_inc_unchecked - increment atomic variable
10423 + * @v: pointer of type atomic_unchecked_t
10424 + *
10425 + * Atomically increments @v by 1.
10426 + */
10427 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10428 +{
10429 + asm volatile(LOCK_PREFIX "incl %0\n"
10430 : "+m" (v->counter));
10431 }
10432
10433 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
10434 */
10435 static inline void atomic_dec(atomic_t *v)
10436 {
10437 - asm volatile(LOCK_PREFIX "decl %0"
10438 + asm volatile(LOCK_PREFIX "decl %0\n"
10439 +
10440 +#ifdef CONFIG_PAX_REFCOUNT
10441 + "jno 0f\n"
10442 + LOCK_PREFIX "incl %0\n"
10443 + "int $4\n0:\n"
10444 + _ASM_EXTABLE(0b, 0b)
10445 +#endif
10446 +
10447 + : "+m" (v->counter));
10448 +}
10449 +
10450 +/**
10451 + * atomic_dec_unchecked - decrement atomic variable
10452 + * @v: pointer of type atomic_unchecked_t
10453 + *
10454 + * Atomically decrements @v by 1.
10455 + */
10456 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10457 +{
10458 + asm volatile(LOCK_PREFIX "decl %0\n"
10459 : "+m" (v->counter));
10460 }
10461
10462 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
10463 {
10464 unsigned char c;
10465
10466 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
10467 + asm volatile(LOCK_PREFIX "decl %0\n"
10468 +
10469 +#ifdef CONFIG_PAX_REFCOUNT
10470 + "jno 0f\n"
10471 + LOCK_PREFIX "incl %0\n"
10472 + "int $4\n0:\n"
10473 + _ASM_EXTABLE(0b, 0b)
10474 +#endif
10475 +
10476 + "sete %1\n"
10477 : "+m" (v->counter), "=qm" (c)
10478 : : "memory");
10479 return c != 0;
10480 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
10481 {
10482 unsigned char c;
10483
10484 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
10485 + asm volatile(LOCK_PREFIX "incl %0\n"
10486 +
10487 +#ifdef CONFIG_PAX_REFCOUNT
10488 + "jno 0f\n"
10489 + LOCK_PREFIX "decl %0\n"
10490 + "int $4\n0:\n"
10491 + _ASM_EXTABLE(0b, 0b)
10492 +#endif
10493 +
10494 + "sete %1\n"
10495 + : "+m" (v->counter), "=qm" (c)
10496 + : : "memory");
10497 + return c != 0;
10498 +}
10499 +
10500 +/**
10501 + * atomic_inc_and_test_unchecked - increment and test
10502 + * @v: pointer of type atomic_unchecked_t
10503 + *
10504 + * Atomically increments @v by 1
10505 + * and returns true if the result is zero, or false for all
10506 + * other cases.
10507 + */
10508 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10509 +{
10510 + unsigned char c;
10511 +
10512 + asm volatile(LOCK_PREFIX "incl %0\n"
10513 + "sete %1\n"
10514 : "+m" (v->counter), "=qm" (c)
10515 : : "memory");
10516 return c != 0;
10517 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
10518 {
10519 unsigned char c;
10520
10521 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
10522 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
10523 +
10524 +#ifdef CONFIG_PAX_REFCOUNT
10525 + "jno 0f\n"
10526 + LOCK_PREFIX "subl %2,%0\n"
10527 + "int $4\n0:\n"
10528 + _ASM_EXTABLE(0b, 0b)
10529 +#endif
10530 +
10531 + "sets %1\n"
10532 : "+m" (v->counter), "=qm" (c)
10533 : "ir" (i) : "memory");
10534 return c;
10535 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
10536 goto no_xadd;
10537 #endif
10538 /* Modern 486+ processor */
10539 - return i + xadd(&v->counter, i);
10540 + return i + xadd_check_overflow(&v->counter, i);
10541
10542 #ifdef CONFIG_M386
10543 no_xadd: /* Legacy 386 processor */
10544 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
10545 }
10546
10547 /**
10548 + * atomic_add_return_unchecked - add integer and return
10549 + * @i: integer value to add
10550 + * @v: pointer of type atomic_unchecked_t
10551 + *
10552 + * Atomically adds @i to @v and returns @i + @v
10553 + */
10554 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10555 +{
10556 +#ifdef CONFIG_M386
10557 + int __i;
10558 + unsigned long flags;
10559 + if (unlikely(boot_cpu_data.x86 <= 3))
10560 + goto no_xadd;
10561 +#endif
10562 + /* Modern 486+ processor */
10563 + return i + xadd(&v->counter, i);
10564 +
10565 +#ifdef CONFIG_M386
10566 +no_xadd: /* Legacy 386 processor */
10567 + raw_local_irq_save(flags);
10568 + __i = atomic_read_unchecked(v);
10569 + atomic_set_unchecked(v, i + __i);
10570 + raw_local_irq_restore(flags);
10571 + return i + __i;
10572 +#endif
10573 +}
10574 +
10575 +/**
10576 * atomic_sub_return - subtract integer and return
10577 * @v: pointer of type atomic_t
10578 * @i: integer value to subtract
10579 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
10580 }
10581
10582 #define atomic_inc_return(v) (atomic_add_return(1, v))
10583 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10584 +{
10585 + return atomic_add_return_unchecked(1, v);
10586 +}
10587 #define atomic_dec_return(v) (atomic_sub_return(1, v))
10588
10589 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10590 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10591 return cmpxchg(&v->counter, old, new);
10592 }
10593
10594 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10595 +{
10596 + return cmpxchg(&v->counter, old, new);
10597 +}
10598 +
10599 static inline int atomic_xchg(atomic_t *v, int new)
10600 {
10601 return xchg(&v->counter, new);
10602 }
10603
10604 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10605 +{
10606 + return xchg(&v->counter, new);
10607 +}
10608 +
10609 /**
10610 * __atomic_add_unless - add unless the number is already a given value
10611 * @v: pointer of type atomic_t
10612 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
10613 */
10614 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10615 {
10616 - int c, old;
10617 + int c, old, new;
10618 c = atomic_read(v);
10619 for (;;) {
10620 - if (unlikely(c == (u)))
10621 + if (unlikely(c == u))
10622 break;
10623 - old = atomic_cmpxchg((v), c, c + (a));
10624 +
10625 + asm volatile("addl %2,%0\n"
10626 +
10627 +#ifdef CONFIG_PAX_REFCOUNT
10628 + "jno 0f\n"
10629 + "subl %2,%0\n"
10630 + "int $4\n0:\n"
10631 + _ASM_EXTABLE(0b, 0b)
10632 +#endif
10633 +
10634 + : "=r" (new)
10635 + : "0" (c), "ir" (a));
10636 +
10637 + old = atomic_cmpxchg(v, c, new);
10638 if (likely(old == c))
10639 break;
10640 c = old;
10641 @@ -241,6 +458,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10642 }
10643
10644 /**
10645 + * atomic_inc_not_zero_hint - increment if not null
10646 + * @v: pointer of type atomic_t
10647 + * @hint: probable value of the atomic before the increment
10648 + *
10649 + * This version of atomic_inc_not_zero() gives a hint of probable
10650 + * value of the atomic. This helps processor to not read the memory
10651 + * before doing the atomic read/modify/write cycle, lowering
10652 + * number of bus transactions on some arches.
10653 + *
10654 + * Returns: 0 if increment was not done, 1 otherwise.
10655 + */
10656 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
10657 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
10658 +{
10659 + int val, c = hint, new;
10660 +
10661 + /* sanity test, should be removed by compiler if hint is a constant */
10662 + if (!hint)
10663 + return __atomic_add_unless(v, 1, 0);
10664 +
10665 + do {
10666 + asm volatile("incl %0\n"
10667 +
10668 +#ifdef CONFIG_PAX_REFCOUNT
10669 + "jno 0f\n"
10670 + "decl %0\n"
10671 + "int $4\n0:\n"
10672 + _ASM_EXTABLE(0b, 0b)
10673 +#endif
10674 +
10675 + : "=r" (new)
10676 + : "0" (c));
10677 +
10678 + val = atomic_cmpxchg(v, c, new);
10679 + if (val == c)
10680 + return 1;
10681 + c = val;
10682 + } while (c);
10683 +
10684 + return 0;
10685 +}
10686 +
10687 +/**
10688 * atomic_inc_short - increment of a short integer
10689 * @v: pointer to type int
10690 *
10691 @@ -269,14 +529,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
10692 #endif
10693
10694 /* These are x86-specific, used by some header files */
10695 -#define atomic_clear_mask(mask, addr) \
10696 - asm volatile(LOCK_PREFIX "andl %0,%1" \
10697 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
10698 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
10699 +{
10700 + asm volatile(LOCK_PREFIX "andl %1,%0"
10701 + : "+m" (v->counter)
10702 + : "r" (~(mask))
10703 + : "memory");
10704 +}
10705
10706 -#define atomic_set_mask(mask, addr) \
10707 - asm volatile(LOCK_PREFIX "orl %0,%1" \
10708 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
10709 - : "memory")
10710 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10711 +{
10712 + asm volatile(LOCK_PREFIX "andl %1,%0"
10713 + : "+m" (v->counter)
10714 + : "r" (~(mask))
10715 + : "memory");
10716 +}
10717 +
10718 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
10719 +{
10720 + asm volatile(LOCK_PREFIX "orl %1,%0"
10721 + : "+m" (v->counter)
10722 + : "r" (mask)
10723 + : "memory");
10724 +}
10725 +
10726 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10727 +{
10728 + asm volatile(LOCK_PREFIX "orl %1,%0"
10729 + : "+m" (v->counter)
10730 + : "r" (mask)
10731 + : "memory");
10732 +}
10733
10734 /* Atomic operations are already serializing on x86 */
10735 #define smp_mb__before_atomic_dec() barrier()
10736 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
10737 index b154de7..aadebd8 100644
10738 --- a/arch/x86/include/asm/atomic64_32.h
10739 +++ b/arch/x86/include/asm/atomic64_32.h
10740 @@ -12,6 +12,14 @@ typedef struct {
10741 u64 __aligned(8) counter;
10742 } atomic64_t;
10743
10744 +#ifdef CONFIG_PAX_REFCOUNT
10745 +typedef struct {
10746 + u64 __aligned(8) counter;
10747 +} atomic64_unchecked_t;
10748 +#else
10749 +typedef atomic64_t atomic64_unchecked_t;
10750 +#endif
10751 +
10752 #define ATOMIC64_INIT(val) { (val) }
10753
10754 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
10755 @@ -37,21 +45,31 @@ typedef struct {
10756 ATOMIC64_DECL_ONE(sym##_386)
10757
10758 ATOMIC64_DECL_ONE(add_386);
10759 +ATOMIC64_DECL_ONE(add_unchecked_386);
10760 ATOMIC64_DECL_ONE(sub_386);
10761 +ATOMIC64_DECL_ONE(sub_unchecked_386);
10762 ATOMIC64_DECL_ONE(inc_386);
10763 +ATOMIC64_DECL_ONE(inc_unchecked_386);
10764 ATOMIC64_DECL_ONE(dec_386);
10765 +ATOMIC64_DECL_ONE(dec_unchecked_386);
10766 #endif
10767
10768 #define alternative_atomic64(f, out, in...) \
10769 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
10770
10771 ATOMIC64_DECL(read);
10772 +ATOMIC64_DECL(read_unchecked);
10773 ATOMIC64_DECL(set);
10774 +ATOMIC64_DECL(set_unchecked);
10775 ATOMIC64_DECL(xchg);
10776 ATOMIC64_DECL(add_return);
10777 +ATOMIC64_DECL(add_return_unchecked);
10778 ATOMIC64_DECL(sub_return);
10779 +ATOMIC64_DECL(sub_return_unchecked);
10780 ATOMIC64_DECL(inc_return);
10781 +ATOMIC64_DECL(inc_return_unchecked);
10782 ATOMIC64_DECL(dec_return);
10783 +ATOMIC64_DECL(dec_return_unchecked);
10784 ATOMIC64_DECL(dec_if_positive);
10785 ATOMIC64_DECL(inc_not_zero);
10786 ATOMIC64_DECL(add_unless);
10787 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
10788 }
10789
10790 /**
10791 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
10792 + * @p: pointer to type atomic64_unchecked_t
10793 + * @o: expected value
10794 + * @n: new value
10795 + *
10796 + * Atomically sets @v to @n if it was equal to @o and returns
10797 + * the old value.
10798 + */
10799 +
10800 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
10801 +{
10802 + return cmpxchg64(&v->counter, o, n);
10803 +}
10804 +
10805 +/**
10806 * atomic64_xchg - xchg atomic64 variable
10807 * @v: pointer to type atomic64_t
10808 * @n: value to assign
10809 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
10810 }
10811
10812 /**
10813 + * atomic64_set_unchecked - set atomic64 variable
10814 + * @v: pointer to type atomic64_unchecked_t
10815 + * @n: value to assign
10816 + *
10817 + * Atomically sets the value of @v to @n.
10818 + */
10819 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
10820 +{
10821 + unsigned high = (unsigned)(i >> 32);
10822 + unsigned low = (unsigned)i;
10823 + alternative_atomic64(set, /* no output */,
10824 + "S" (v), "b" (low), "c" (high)
10825 + : "eax", "edx", "memory");
10826 +}
10827 +
10828 +/**
10829 * atomic64_read - read atomic64 variable
10830 * @v: pointer to type atomic64_t
10831 *
10832 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
10833 }
10834
10835 /**
10836 + * atomic64_read_unchecked - read atomic64 variable
10837 + * @v: pointer to type atomic64_unchecked_t
10838 + *
10839 + * Atomically reads the value of @v and returns it.
10840 + */
10841 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
10842 +{
10843 + long long r;
10844 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
10845 + return r;
10846 + }
10847 +
10848 +/**
10849 * atomic64_add_return - add and return
10850 * @i: integer value to add
10851 * @v: pointer to type atomic64_t
10852 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
10853 return i;
10854 }
10855
10856 +/**
10857 + * atomic64_add_return_unchecked - add and return
10858 + * @i: integer value to add
10859 + * @v: pointer to type atomic64_unchecked_t
10860 + *
10861 + * Atomically adds @i to @v and returns @i + *@v
10862 + */
10863 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
10864 +{
10865 + alternative_atomic64(add_return_unchecked,
10866 + ASM_OUTPUT2("+A" (i), "+c" (v)),
10867 + ASM_NO_INPUT_CLOBBER("memory"));
10868 + return i;
10869 +}
10870 +
10871 /*
10872 * Other variants with different arithmetic operators:
10873 */
10874 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
10875 return a;
10876 }
10877
10878 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10879 +{
10880 + long long a;
10881 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
10882 + "S" (v) : "memory", "ecx");
10883 + return a;
10884 +}
10885 +
10886 static inline long long atomic64_dec_return(atomic64_t *v)
10887 {
10888 long long a;
10889 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
10890 }
10891
10892 /**
10893 + * atomic64_add_unchecked - add integer to atomic64 variable
10894 + * @i: integer value to add
10895 + * @v: pointer to type atomic64_unchecked_t
10896 + *
10897 + * Atomically adds @i to @v.
10898 + */
10899 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
10900 +{
10901 + __alternative_atomic64(add_unchecked, add_return_unchecked,
10902 + ASM_OUTPUT2("+A" (i), "+c" (v)),
10903 + ASM_NO_INPUT_CLOBBER("memory"));
10904 + return i;
10905 +}
10906 +
10907 +/**
10908 * atomic64_sub - subtract the atomic64 variable
10909 * @i: integer value to subtract
10910 * @v: pointer to type atomic64_t
10911 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
10912 index 0e1cbfc..5623683 100644
10913 --- a/arch/x86/include/asm/atomic64_64.h
10914 +++ b/arch/x86/include/asm/atomic64_64.h
10915 @@ -18,7 +18,19 @@
10916 */
10917 static inline long atomic64_read(const atomic64_t *v)
10918 {
10919 - return (*(volatile long *)&(v)->counter);
10920 + return (*(volatile const long *)&(v)->counter);
10921 +}
10922 +
10923 +/**
10924 + * atomic64_read_unchecked - read atomic64 variable
10925 + * @v: pointer of type atomic64_unchecked_t
10926 + *
10927 + * Atomically reads the value of @v.
10928 + * Doesn't imply a read memory barrier.
10929 + */
10930 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
10931 +{
10932 + return (*(volatile const long *)&(v)->counter);
10933 }
10934
10935 /**
10936 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
10937 }
10938
10939 /**
10940 + * atomic64_set_unchecked - set atomic64 variable
10941 + * @v: pointer to type atomic64_unchecked_t
10942 + * @i: required value
10943 + *
10944 + * Atomically sets the value of @v to @i.
10945 + */
10946 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
10947 +{
10948 + v->counter = i;
10949 +}
10950 +
10951 +/**
10952 * atomic64_add - add integer to atomic64 variable
10953 * @i: integer value to add
10954 * @v: pointer to type atomic64_t
10955 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
10956 */
10957 static inline void atomic64_add(long i, atomic64_t *v)
10958 {
10959 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
10960 +
10961 +#ifdef CONFIG_PAX_REFCOUNT
10962 + "jno 0f\n"
10963 + LOCK_PREFIX "subq %1,%0\n"
10964 + "int $4\n0:\n"
10965 + _ASM_EXTABLE(0b, 0b)
10966 +#endif
10967 +
10968 + : "=m" (v->counter)
10969 + : "er" (i), "m" (v->counter));
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 void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
10980 +{
10981 asm volatile(LOCK_PREFIX "addq %1,%0"
10982 : "=m" (v->counter)
10983 : "er" (i), "m" (v->counter));
10984 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
10985 */
10986 static inline void atomic64_sub(long i, atomic64_t *v)
10987 {
10988 - asm volatile(LOCK_PREFIX "subq %1,%0"
10989 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
10990 +
10991 +#ifdef CONFIG_PAX_REFCOUNT
10992 + "jno 0f\n"
10993 + LOCK_PREFIX "addq %1,%0\n"
10994 + "int $4\n0:\n"
10995 + _ASM_EXTABLE(0b, 0b)
10996 +#endif
10997 +
10998 + : "=m" (v->counter)
10999 + : "er" (i), "m" (v->counter));
11000 +}
11001 +
11002 +/**
11003 + * atomic64_sub_unchecked - subtract the atomic64 variable
11004 + * @i: integer value to subtract
11005 + * @v: pointer to type atomic64_unchecked_t
11006 + *
11007 + * Atomically subtracts @i from @v.
11008 + */
11009 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
11010 +{
11011 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
11012 : "=m" (v->counter)
11013 : "er" (i), "m" (v->counter));
11014 }
11015 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
11016 {
11017 unsigned char c;
11018
11019 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
11020 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
11021 +
11022 +#ifdef CONFIG_PAX_REFCOUNT
11023 + "jno 0f\n"
11024 + LOCK_PREFIX "addq %2,%0\n"
11025 + "int $4\n0:\n"
11026 + _ASM_EXTABLE(0b, 0b)
11027 +#endif
11028 +
11029 + "sete %1\n"
11030 : "=m" (v->counter), "=qm" (c)
11031 : "er" (i), "m" (v->counter) : "memory");
11032 return c;
11033 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
11034 */
11035 static inline void atomic64_inc(atomic64_t *v)
11036 {
11037 + asm volatile(LOCK_PREFIX "incq %0\n"
11038 +
11039 +#ifdef CONFIG_PAX_REFCOUNT
11040 + "jno 0f\n"
11041 + LOCK_PREFIX "decq %0\n"
11042 + "int $4\n0:\n"
11043 + _ASM_EXTABLE(0b, 0b)
11044 +#endif
11045 +
11046 + : "=m" (v->counter)
11047 + : "m" (v->counter));
11048 +}
11049 +
11050 +/**
11051 + * atomic64_inc_unchecked - increment atomic64 variable
11052 + * @v: pointer to type atomic64_unchecked_t
11053 + *
11054 + * Atomically increments @v by 1.
11055 + */
11056 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
11057 +{
11058 asm volatile(LOCK_PREFIX "incq %0"
11059 : "=m" (v->counter)
11060 : "m" (v->counter));
11061 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
11062 */
11063 static inline void atomic64_dec(atomic64_t *v)
11064 {
11065 - asm volatile(LOCK_PREFIX "decq %0"
11066 + asm volatile(LOCK_PREFIX "decq %0\n"
11067 +
11068 +#ifdef CONFIG_PAX_REFCOUNT
11069 + "jno 0f\n"
11070 + LOCK_PREFIX "incq %0\n"
11071 + "int $4\n0:\n"
11072 + _ASM_EXTABLE(0b, 0b)
11073 +#endif
11074 +
11075 + : "=m" (v->counter)
11076 + : "m" (v->counter));
11077 +}
11078 +
11079 +/**
11080 + * atomic64_dec_unchecked - decrement atomic64 variable
11081 + * @v: pointer to type atomic64_t
11082 + *
11083 + * Atomically decrements @v by 1.
11084 + */
11085 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
11086 +{
11087 + asm volatile(LOCK_PREFIX "decq %0\n"
11088 : "=m" (v->counter)
11089 : "m" (v->counter));
11090 }
11091 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
11092 {
11093 unsigned char c;
11094
11095 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
11096 + asm volatile(LOCK_PREFIX "decq %0\n"
11097 +
11098 +#ifdef CONFIG_PAX_REFCOUNT
11099 + "jno 0f\n"
11100 + LOCK_PREFIX "incq %0\n"
11101 + "int $4\n0:\n"
11102 + _ASM_EXTABLE(0b, 0b)
11103 +#endif
11104 +
11105 + "sete %1\n"
11106 : "=m" (v->counter), "=qm" (c)
11107 : "m" (v->counter) : "memory");
11108 return c != 0;
11109 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
11110 {
11111 unsigned char c;
11112
11113 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
11114 + asm volatile(LOCK_PREFIX "incq %0\n"
11115 +
11116 +#ifdef CONFIG_PAX_REFCOUNT
11117 + "jno 0f\n"
11118 + LOCK_PREFIX "decq %0\n"
11119 + "int $4\n0:\n"
11120 + _ASM_EXTABLE(0b, 0b)
11121 +#endif
11122 +
11123 + "sete %1\n"
11124 : "=m" (v->counter), "=qm" (c)
11125 : "m" (v->counter) : "memory");
11126 return c != 0;
11127 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
11128 {
11129 unsigned char c;
11130
11131 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
11132 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
11133 +
11134 +#ifdef CONFIG_PAX_REFCOUNT
11135 + "jno 0f\n"
11136 + LOCK_PREFIX "subq %2,%0\n"
11137 + "int $4\n0:\n"
11138 + _ASM_EXTABLE(0b, 0b)
11139 +#endif
11140 +
11141 + "sets %1\n"
11142 : "=m" (v->counter), "=qm" (c)
11143 : "er" (i), "m" (v->counter) : "memory");
11144 return c;
11145 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
11146 */
11147 static inline long atomic64_add_return(long i, atomic64_t *v)
11148 {
11149 + return i + xadd_check_overflow(&v->counter, i);
11150 +}
11151 +
11152 +/**
11153 + * atomic64_add_return_unchecked - add and return
11154 + * @i: integer value to add
11155 + * @v: pointer to type atomic64_unchecked_t
11156 + *
11157 + * Atomically adds @i to @v and returns @i + @v
11158 + */
11159 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
11160 +{
11161 return i + xadd(&v->counter, i);
11162 }
11163
11164 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
11165 }
11166
11167 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
11168 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
11169 +{
11170 + return atomic64_add_return_unchecked(1, v);
11171 +}
11172 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
11173
11174 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
11175 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
11176 return cmpxchg(&v->counter, old, new);
11177 }
11178
11179 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
11180 +{
11181 + return cmpxchg(&v->counter, old, new);
11182 +}
11183 +
11184 static inline long atomic64_xchg(atomic64_t *v, long new)
11185 {
11186 return xchg(&v->counter, new);
11187 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
11188 */
11189 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
11190 {
11191 - long c, old;
11192 + long c, old, new;
11193 c = atomic64_read(v);
11194 for (;;) {
11195 - if (unlikely(c == (u)))
11196 + if (unlikely(c == u))
11197 break;
11198 - old = atomic64_cmpxchg((v), c, c + (a));
11199 +
11200 + asm volatile("add %2,%0\n"
11201 +
11202 +#ifdef CONFIG_PAX_REFCOUNT
11203 + "jno 0f\n"
11204 + "sub %2,%0\n"
11205 + "int $4\n0:\n"
11206 + _ASM_EXTABLE(0b, 0b)
11207 +#endif
11208 +
11209 + : "=r" (new)
11210 + : "0" (c), "ir" (a));
11211 +
11212 + old = atomic64_cmpxchg(v, c, new);
11213 if (likely(old == c))
11214 break;
11215 c = old;
11216 }
11217 - return c != (u);
11218 + return c != u;
11219 }
11220
11221 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11222 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
11223 index 6dfd019..0c6699f 100644
11224 --- a/arch/x86/include/asm/bitops.h
11225 +++ b/arch/x86/include/asm/bitops.h
11226 @@ -40,7 +40,7 @@
11227 * a mask operation on a byte.
11228 */
11229 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
11230 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
11231 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
11232 #define CONST_MASK(nr) (1 << ((nr) & 7))
11233
11234 /**
11235 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
11236 index b13fe63..0dab13a 100644
11237 --- a/arch/x86/include/asm/boot.h
11238 +++ b/arch/x86/include/asm/boot.h
11239 @@ -11,10 +11,15 @@
11240 #include <asm/pgtable_types.h>
11241
11242 /* Physical address where kernel should be loaded. */
11243 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11244 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11245 + (CONFIG_PHYSICAL_ALIGN - 1)) \
11246 & ~(CONFIG_PHYSICAL_ALIGN - 1))
11247
11248 +#ifndef __ASSEMBLY__
11249 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
11250 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
11251 +#endif
11252 +
11253 /* Minimum kernel alignment, as a power of two */
11254 #ifdef CONFIG_X86_64
11255 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
11256 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
11257 index 48f99f1..d78ebf9 100644
11258 --- a/arch/x86/include/asm/cache.h
11259 +++ b/arch/x86/include/asm/cache.h
11260 @@ -5,12 +5,13 @@
11261
11262 /* L1 cache line size */
11263 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11264 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11265 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11266
11267 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
11268 +#define __read_only __attribute__((__section__(".data..read_only")))
11269
11270 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
11271 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
11272 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
11273
11274 #ifdef CONFIG_X86_VSMP
11275 #ifdef CONFIG_SMP
11276 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
11277 index 9863ee3..4a1f8e1 100644
11278 --- a/arch/x86/include/asm/cacheflush.h
11279 +++ b/arch/x86/include/asm/cacheflush.h
11280 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
11281 unsigned long pg_flags = pg->flags & _PGMT_MASK;
11282
11283 if (pg_flags == _PGMT_DEFAULT)
11284 - return -1;
11285 + return ~0UL;
11286 else if (pg_flags == _PGMT_WC)
11287 return _PAGE_CACHE_WC;
11288 else if (pg_flags == _PGMT_UC_MINUS)
11289 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
11290 index 46fc474..b02b0f9 100644
11291 --- a/arch/x86/include/asm/checksum_32.h
11292 +++ b/arch/x86/include/asm/checksum_32.h
11293 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
11294 int len, __wsum sum,
11295 int *src_err_ptr, int *dst_err_ptr);
11296
11297 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
11298 + int len, __wsum sum,
11299 + int *src_err_ptr, int *dst_err_ptr);
11300 +
11301 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
11302 + int len, __wsum sum,
11303 + int *src_err_ptr, int *dst_err_ptr);
11304 +
11305 /*
11306 * Note: when you get a NULL pointer exception here this means someone
11307 * passed in an incorrect kernel address to one of these functions.
11308 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
11309 int *err_ptr)
11310 {
11311 might_sleep();
11312 - return csum_partial_copy_generic((__force void *)src, dst,
11313 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
11314 len, sum, err_ptr, NULL);
11315 }
11316
11317 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
11318 {
11319 might_sleep();
11320 if (access_ok(VERIFY_WRITE, dst, len))
11321 - return csum_partial_copy_generic(src, (__force void *)dst,
11322 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
11323 len, sum, NULL, err_ptr);
11324
11325 if (len)
11326 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
11327 index 8d871ea..c1a0dc9 100644
11328 --- a/arch/x86/include/asm/cmpxchg.h
11329 +++ b/arch/x86/include/asm/cmpxchg.h
11330 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
11331 __compiletime_error("Bad argument size for cmpxchg");
11332 extern void __xadd_wrong_size(void)
11333 __compiletime_error("Bad argument size for xadd");
11334 +extern void __xadd_check_overflow_wrong_size(void)
11335 + __compiletime_error("Bad argument size for xadd_check_overflow");
11336 extern void __add_wrong_size(void)
11337 __compiletime_error("Bad argument size for add");
11338 +extern void __add_check_overflow_wrong_size(void)
11339 + __compiletime_error("Bad argument size for add_check_overflow");
11340
11341 /*
11342 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
11343 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
11344 __ret; \
11345 })
11346
11347 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
11348 + ({ \
11349 + __typeof__ (*(ptr)) __ret = (arg); \
11350 + switch (sizeof(*(ptr))) { \
11351 + case __X86_CASE_L: \
11352 + asm volatile (lock #op "l %0, %1\n" \
11353 + "jno 0f\n" \
11354 + "mov %0,%1\n" \
11355 + "int $4\n0:\n" \
11356 + _ASM_EXTABLE(0b, 0b) \
11357 + : "+r" (__ret), "+m" (*(ptr)) \
11358 + : : "memory", "cc"); \
11359 + break; \
11360 + case __X86_CASE_Q: \
11361 + asm volatile (lock #op "q %q0, %1\n" \
11362 + "jno 0f\n" \
11363 + "mov %0,%1\n" \
11364 + "int $4\n0:\n" \
11365 + _ASM_EXTABLE(0b, 0b) \
11366 + : "+r" (__ret), "+m" (*(ptr)) \
11367 + : : "memory", "cc"); \
11368 + break; \
11369 + default: \
11370 + __ ## op ## _check_overflow_wrong_size(); \
11371 + } \
11372 + __ret; \
11373 + })
11374 +
11375 /*
11376 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
11377 * Since this is generally used to protect other memory information, we
11378 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
11379 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
11380 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
11381
11382 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
11383 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
11384 +
11385 #define __add(ptr, inc, lock) \
11386 ({ \
11387 __typeof__ (*(ptr)) __ret = (inc); \
11388 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
11389 index 8c297aa..7a90f03 100644
11390 --- a/arch/x86/include/asm/cpufeature.h
11391 +++ b/arch/x86/include/asm/cpufeature.h
11392 @@ -205,7 +205,7 @@
11393 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
11394 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
11395 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
11396 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
11397 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
11398 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
11399 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
11400 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
11401 @@ -379,7 +379,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
11402 ".section .discard,\"aw\",@progbits\n"
11403 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
11404 ".previous\n"
11405 - ".section .altinstr_replacement,\"ax\"\n"
11406 + ".section .altinstr_replacement,\"a\"\n"
11407 "3: movb $1,%0\n"
11408 "4:\n"
11409 ".previous\n"
11410 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
11411 index 8bf1c06..f723dfd 100644
11412 --- a/arch/x86/include/asm/desc.h
11413 +++ b/arch/x86/include/asm/desc.h
11414 @@ -4,6 +4,7 @@
11415 #include <asm/desc_defs.h>
11416 #include <asm/ldt.h>
11417 #include <asm/mmu.h>
11418 +#include <asm/pgtable.h>
11419
11420 #include <linux/smp.h>
11421 #include <linux/percpu.h>
11422 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11423
11424 desc->type = (info->read_exec_only ^ 1) << 1;
11425 desc->type |= info->contents << 2;
11426 + desc->type |= info->seg_not_present ^ 1;
11427
11428 desc->s = 1;
11429 desc->dpl = 0x3;
11430 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11431 }
11432
11433 extern struct desc_ptr idt_descr;
11434 -extern gate_desc idt_table[];
11435 extern struct desc_ptr nmi_idt_descr;
11436 -extern gate_desc nmi_idt_table[];
11437 -
11438 -struct gdt_page {
11439 - struct desc_struct gdt[GDT_ENTRIES];
11440 -} __attribute__((aligned(PAGE_SIZE)));
11441 -
11442 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
11443 +extern gate_desc idt_table[256];
11444 +extern gate_desc nmi_idt_table[256];
11445
11446 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
11447 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
11448 {
11449 - return per_cpu(gdt_page, cpu).gdt;
11450 + return cpu_gdt_table[cpu];
11451 }
11452
11453 #ifdef CONFIG_X86_64
11454 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
11455 unsigned long base, unsigned dpl, unsigned flags,
11456 unsigned short seg)
11457 {
11458 - gate->a = (seg << 16) | (base & 0xffff);
11459 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
11460 + gate->gate.offset_low = base;
11461 + gate->gate.seg = seg;
11462 + gate->gate.reserved = 0;
11463 + gate->gate.type = type;
11464 + gate->gate.s = 0;
11465 + gate->gate.dpl = dpl;
11466 + gate->gate.p = 1;
11467 + gate->gate.offset_high = base >> 16;
11468 }
11469
11470 #endif
11471 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
11472
11473 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
11474 {
11475 + pax_open_kernel();
11476 memcpy(&idt[entry], gate, sizeof(*gate));
11477 + pax_close_kernel();
11478 }
11479
11480 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
11481 {
11482 + pax_open_kernel();
11483 memcpy(&ldt[entry], desc, 8);
11484 + pax_close_kernel();
11485 }
11486
11487 static inline void
11488 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
11489 default: size = sizeof(*gdt); break;
11490 }
11491
11492 + pax_open_kernel();
11493 memcpy(&gdt[entry], desc, size);
11494 + pax_close_kernel();
11495 }
11496
11497 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
11498 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
11499
11500 static inline void native_load_tr_desc(void)
11501 {
11502 + pax_open_kernel();
11503 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
11504 + pax_close_kernel();
11505 }
11506
11507 static inline void native_load_gdt(const struct desc_ptr *dtr)
11508 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
11509 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
11510 unsigned int i;
11511
11512 + pax_open_kernel();
11513 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
11514 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
11515 + pax_close_kernel();
11516 }
11517
11518 #define _LDT_empty(info) \
11519 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
11520 }
11521
11522 #ifdef CONFIG_X86_64
11523 -static inline void set_nmi_gate(int gate, void *addr)
11524 +static inline void set_nmi_gate(int gate, const void *addr)
11525 {
11526 gate_desc s;
11527
11528 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
11529 }
11530 #endif
11531
11532 -static inline void _set_gate(int gate, unsigned type, void *addr,
11533 +static inline void _set_gate(int gate, unsigned type, const void *addr,
11534 unsigned dpl, unsigned ist, unsigned seg)
11535 {
11536 gate_desc s;
11537 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
11538 * Pentium F0 0F bugfix can have resulted in the mapped
11539 * IDT being write-protected.
11540 */
11541 -static inline void set_intr_gate(unsigned int n, void *addr)
11542 +static inline void set_intr_gate(unsigned int n, const void *addr)
11543 {
11544 BUG_ON((unsigned)n > 0xFF);
11545 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
11546 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
11547 /*
11548 * This routine sets up an interrupt gate at directory privilege level 3.
11549 */
11550 -static inline void set_system_intr_gate(unsigned int n, void *addr)
11551 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
11552 {
11553 BUG_ON((unsigned)n > 0xFF);
11554 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
11555 }
11556
11557 -static inline void set_system_trap_gate(unsigned int n, void *addr)
11558 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
11559 {
11560 BUG_ON((unsigned)n > 0xFF);
11561 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
11562 }
11563
11564 -static inline void set_trap_gate(unsigned int n, void *addr)
11565 +static inline void set_trap_gate(unsigned int n, const void *addr)
11566 {
11567 BUG_ON((unsigned)n > 0xFF);
11568 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
11569 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
11570 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
11571 {
11572 BUG_ON((unsigned)n > 0xFF);
11573 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
11574 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
11575 }
11576
11577 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
11578 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
11579 {
11580 BUG_ON((unsigned)n > 0xFF);
11581 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
11582 }
11583
11584 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
11585 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
11586 {
11587 BUG_ON((unsigned)n > 0xFF);
11588 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
11589 }
11590
11591 +#ifdef CONFIG_X86_32
11592 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
11593 +{
11594 + struct desc_struct d;
11595 +
11596 + if (likely(limit))
11597 + limit = (limit - 1UL) >> PAGE_SHIFT;
11598 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
11599 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
11600 +}
11601 +#endif
11602 +
11603 #endif /* _ASM_X86_DESC_H */
11604 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
11605 index 278441f..b95a174 100644
11606 --- a/arch/x86/include/asm/desc_defs.h
11607 +++ b/arch/x86/include/asm/desc_defs.h
11608 @@ -31,6 +31,12 @@ struct desc_struct {
11609 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
11610 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
11611 };
11612 + struct {
11613 + u16 offset_low;
11614 + u16 seg;
11615 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
11616 + unsigned offset_high: 16;
11617 + } gate;
11618 };
11619 } __attribute__((packed));
11620
11621 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
11622 index 3778256..c5d4fce 100644
11623 --- a/arch/x86/include/asm/e820.h
11624 +++ b/arch/x86/include/asm/e820.h
11625 @@ -69,7 +69,7 @@ struct e820map {
11626 #define ISA_START_ADDRESS 0xa0000
11627 #define ISA_END_ADDRESS 0x100000
11628
11629 -#define BIOS_BEGIN 0x000a0000
11630 +#define BIOS_BEGIN 0x000c0000
11631 #define BIOS_END 0x00100000
11632
11633 #define BIOS_ROM_BASE 0xffe00000
11634 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
11635 index 5939f44..f8845f6 100644
11636 --- a/arch/x86/include/asm/elf.h
11637 +++ b/arch/x86/include/asm/elf.h
11638 @@ -243,7 +243,25 @@ extern int force_personality32;
11639 the loader. We need to make sure that it is out of the way of the program
11640 that it will "exec", and that there is sufficient room for the brk. */
11641
11642 +#ifdef CONFIG_PAX_SEGMEXEC
11643 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
11644 +#else
11645 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
11646 +#endif
11647 +
11648 +#ifdef CONFIG_PAX_ASLR
11649 +#ifdef CONFIG_X86_32
11650 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
11651 +
11652 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11653 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11654 +#else
11655 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
11656 +
11657 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11658 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11659 +#endif
11660 +#endif
11661
11662 /* This yields a mask that user programs can use to figure out what
11663 instruction set this CPU supports. This could be done in user space,
11664 @@ -296,16 +314,12 @@ do { \
11665
11666 #define ARCH_DLINFO \
11667 do { \
11668 - if (vdso_enabled) \
11669 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11670 - (unsigned long)current->mm->context.vdso); \
11671 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11672 } while (0)
11673
11674 #define ARCH_DLINFO_X32 \
11675 do { \
11676 - if (vdso_enabled) \
11677 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11678 - (unsigned long)current->mm->context.vdso); \
11679 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11680 } while (0)
11681
11682 #define AT_SYSINFO 32
11683 @@ -320,7 +334,7 @@ else \
11684
11685 #endif /* !CONFIG_X86_32 */
11686
11687 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
11688 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
11689
11690 #define VDSO_ENTRY \
11691 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
11692 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
11693 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
11694 #define compat_arch_setup_additional_pages syscall32_setup_pages
11695
11696 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
11697 -#define arch_randomize_brk arch_randomize_brk
11698 -
11699 /*
11700 * True on X86_32 or when emulating IA32 on X86_64
11701 */
11702 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
11703 index 75ce3f4..882e801 100644
11704 --- a/arch/x86/include/asm/emergency-restart.h
11705 +++ b/arch/x86/include/asm/emergency-restart.h
11706 @@ -13,6 +13,6 @@ enum reboot_type {
11707
11708 extern enum reboot_type reboot_type;
11709
11710 -extern void machine_emergency_restart(void);
11711 +extern void machine_emergency_restart(void) __noreturn;
11712
11713 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
11714 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
11715 index 41ab26e..a88c9e6 100644
11716 --- a/arch/x86/include/asm/fpu-internal.h
11717 +++ b/arch/x86/include/asm/fpu-internal.h
11718 @@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
11719 ({ \
11720 int err; \
11721 asm volatile(ASM_STAC "\n" \
11722 - "1:" #insn "\n\t" \
11723 + "1:" \
11724 + __copyuser_seg \
11725 + #insn "\n\t" \
11726 "2: " ASM_CLAC "\n" \
11727 ".section .fixup,\"ax\"\n" \
11728 "3: movl $-1,%[err]\n" \
11729 @@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
11730 "emms\n\t" /* clear stack tags */
11731 "fildl %P[addr]", /* set F?P to defined value */
11732 X86_FEATURE_FXSAVE_LEAK,
11733 - [addr] "m" (tsk->thread.fpu.has_fpu));
11734 + [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
11735
11736 return fpu_restore_checking(&tsk->thread.fpu);
11737 }
11738 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
11739 index f373046..02653e2 100644
11740 --- a/arch/x86/include/asm/futex.h
11741 +++ b/arch/x86/include/asm/futex.h
11742 @@ -12,6 +12,7 @@
11743 #include <asm/smap.h>
11744
11745 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
11746 + typecheck(u32 __user *, uaddr); \
11747 asm volatile("\t" ASM_STAC "\n" \
11748 "1:\t" insn "\n" \
11749 "2:\t" ASM_CLAC "\n" \
11750 @@ -20,15 +21,16 @@
11751 "\tjmp\t2b\n" \
11752 "\t.previous\n" \
11753 _ASM_EXTABLE(1b, 3b) \
11754 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
11755 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
11756 : "i" (-EFAULT), "0" (oparg), "1" (0))
11757
11758 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
11759 + typecheck(u32 __user *, uaddr); \
11760 asm volatile("\t" ASM_STAC "\n" \
11761 "1:\tmovl %2, %0\n" \
11762 "\tmovl\t%0, %3\n" \
11763 "\t" insn "\n" \
11764 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
11765 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
11766 "\tjnz\t1b\n" \
11767 "3:\t" ASM_CLAC "\n" \
11768 "\t.section .fixup,\"ax\"\n" \
11769 @@ -38,7 +40,7 @@
11770 _ASM_EXTABLE(1b, 4b) \
11771 _ASM_EXTABLE(2b, 4b) \
11772 : "=&a" (oldval), "=&r" (ret), \
11773 - "+m" (*uaddr), "=&r" (tem) \
11774 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
11775 : "r" (oparg), "i" (-EFAULT), "1" (0))
11776
11777 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11778 @@ -65,10 +67,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11779
11780 switch (op) {
11781 case FUTEX_OP_SET:
11782 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
11783 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
11784 break;
11785 case FUTEX_OP_ADD:
11786 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
11787 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
11788 uaddr, oparg);
11789 break;
11790 case FUTEX_OP_OR:
11791 @@ -128,14 +130,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
11792 return -EFAULT;
11793
11794 asm volatile("\t" ASM_STAC "\n"
11795 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
11796 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
11797 "2:\t" ASM_CLAC "\n"
11798 "\t.section .fixup, \"ax\"\n"
11799 "3:\tmov %3, %0\n"
11800 "\tjmp 2b\n"
11801 "\t.previous\n"
11802 _ASM_EXTABLE(1b, 3b)
11803 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
11804 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
11805 : "i" (-EFAULT), "r" (newval), "1" (oldval)
11806 : "memory"
11807 );
11808 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
11809 index eb92a6e..b98b2f4 100644
11810 --- a/arch/x86/include/asm/hw_irq.h
11811 +++ b/arch/x86/include/asm/hw_irq.h
11812 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
11813 extern void enable_IO_APIC(void);
11814
11815 /* Statistics */
11816 -extern atomic_t irq_err_count;
11817 -extern atomic_t irq_mis_count;
11818 +extern atomic_unchecked_t irq_err_count;
11819 +extern atomic_unchecked_t irq_mis_count;
11820
11821 /* EISA */
11822 extern void eisa_set_level_irq(unsigned int irq);
11823 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
11824 index d8e8eef..15b1179 100644
11825 --- a/arch/x86/include/asm/io.h
11826 +++ b/arch/x86/include/asm/io.h
11827 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
11828 return ioremap_nocache(offset, size);
11829 }
11830
11831 -extern void iounmap(volatile void __iomem *addr);
11832 +extern void iounmap(const volatile void __iomem *addr);
11833
11834 extern void set_iounmap_nonlazy(void);
11835
11836 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
11837
11838 #include <linux/vmalloc.h>
11839
11840 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
11841 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
11842 +{
11843 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11844 +}
11845 +
11846 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
11847 +{
11848 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11849 +}
11850 +
11851 /*
11852 * Convert a virtual cached pointer to an uncached pointer
11853 */
11854 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
11855 index bba3cf8..06bc8da 100644
11856 --- a/arch/x86/include/asm/irqflags.h
11857 +++ b/arch/x86/include/asm/irqflags.h
11858 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
11859 sti; \
11860 sysexit
11861
11862 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
11863 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
11864 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
11865 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
11866 +
11867 #else
11868 #define INTERRUPT_RETURN iret
11869 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
11870 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
11871 index d3ddd17..c9fb0cc 100644
11872 --- a/arch/x86/include/asm/kprobes.h
11873 +++ b/arch/x86/include/asm/kprobes.h
11874 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
11875 #define RELATIVEJUMP_SIZE 5
11876 #define RELATIVECALL_OPCODE 0xe8
11877 #define RELATIVE_ADDR_SIZE 4
11878 -#define MAX_STACK_SIZE 64
11879 -#define MIN_STACK_SIZE(ADDR) \
11880 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
11881 - THREAD_SIZE - (unsigned long)(ADDR))) \
11882 - ? (MAX_STACK_SIZE) \
11883 - : (((unsigned long)current_thread_info()) + \
11884 - THREAD_SIZE - (unsigned long)(ADDR)))
11885 +#define MAX_STACK_SIZE 64UL
11886 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
11887
11888 #define flush_insn_slot(p) do { } while (0)
11889
11890 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
11891 index b2e11f4..f293e2e 100644
11892 --- a/arch/x86/include/asm/kvm_host.h
11893 +++ b/arch/x86/include/asm/kvm_host.h
11894 @@ -707,7 +707,7 @@ struct kvm_x86_ops {
11895 int (*check_intercept)(struct kvm_vcpu *vcpu,
11896 struct x86_instruction_info *info,
11897 enum x86_intercept_stage stage);
11898 -};
11899 +} __do_const;
11900
11901 struct kvm_arch_async_pf {
11902 u32 token;
11903 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
11904 index c8bed0d..85c03fd 100644
11905 --- a/arch/x86/include/asm/local.h
11906 +++ b/arch/x86/include/asm/local.h
11907 @@ -10,33 +10,97 @@ typedef struct {
11908 atomic_long_t a;
11909 } local_t;
11910
11911 +typedef struct {
11912 + atomic_long_unchecked_t a;
11913 +} local_unchecked_t;
11914 +
11915 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
11916
11917 #define local_read(l) atomic_long_read(&(l)->a)
11918 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
11919 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
11920 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
11921
11922 static inline void local_inc(local_t *l)
11923 {
11924 - asm volatile(_ASM_INC "%0"
11925 + asm volatile(_ASM_INC "%0\n"
11926 +
11927 +#ifdef CONFIG_PAX_REFCOUNT
11928 + "jno 0f\n"
11929 + _ASM_DEC "%0\n"
11930 + "int $4\n0:\n"
11931 + _ASM_EXTABLE(0b, 0b)
11932 +#endif
11933 +
11934 + : "+m" (l->a.counter));
11935 +}
11936 +
11937 +static inline void local_inc_unchecked(local_unchecked_t *l)
11938 +{
11939 + asm volatile(_ASM_INC "%0\n"
11940 : "+m" (l->a.counter));
11941 }
11942
11943 static inline void local_dec(local_t *l)
11944 {
11945 - asm volatile(_ASM_DEC "%0"
11946 + asm volatile(_ASM_DEC "%0\n"
11947 +
11948 +#ifdef CONFIG_PAX_REFCOUNT
11949 + "jno 0f\n"
11950 + _ASM_INC "%0\n"
11951 + "int $4\n0:\n"
11952 + _ASM_EXTABLE(0b, 0b)
11953 +#endif
11954 +
11955 + : "+m" (l->a.counter));
11956 +}
11957 +
11958 +static inline void local_dec_unchecked(local_unchecked_t *l)
11959 +{
11960 + asm volatile(_ASM_DEC "%0\n"
11961 : "+m" (l->a.counter));
11962 }
11963
11964 static inline void local_add(long i, local_t *l)
11965 {
11966 - asm volatile(_ASM_ADD "%1,%0"
11967 + asm volatile(_ASM_ADD "%1,%0\n"
11968 +
11969 +#ifdef CONFIG_PAX_REFCOUNT
11970 + "jno 0f\n"
11971 + _ASM_SUB "%1,%0\n"
11972 + "int $4\n0:\n"
11973 + _ASM_EXTABLE(0b, 0b)
11974 +#endif
11975 +
11976 + : "+m" (l->a.counter)
11977 + : "ir" (i));
11978 +}
11979 +
11980 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
11981 +{
11982 + asm volatile(_ASM_ADD "%1,%0\n"
11983 : "+m" (l->a.counter)
11984 : "ir" (i));
11985 }
11986
11987 static inline void local_sub(long i, local_t *l)
11988 {
11989 - asm volatile(_ASM_SUB "%1,%0"
11990 + asm volatile(_ASM_SUB "%1,%0\n"
11991 +
11992 +#ifdef CONFIG_PAX_REFCOUNT
11993 + "jno 0f\n"
11994 + _ASM_ADD "%1,%0\n"
11995 + "int $4\n0:\n"
11996 + _ASM_EXTABLE(0b, 0b)
11997 +#endif
11998 +
11999 + : "+m" (l->a.counter)
12000 + : "ir" (i));
12001 +}
12002 +
12003 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
12004 +{
12005 + asm volatile(_ASM_SUB "%1,%0\n"
12006 : "+m" (l->a.counter)
12007 : "ir" (i));
12008 }
12009 @@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
12010 {
12011 unsigned char c;
12012
12013 - asm volatile(_ASM_SUB "%2,%0; sete %1"
12014 + asm volatile(_ASM_SUB "%2,%0\n"
12015 +
12016 +#ifdef CONFIG_PAX_REFCOUNT
12017 + "jno 0f\n"
12018 + _ASM_ADD "%2,%0\n"
12019 + "int $4\n0:\n"
12020 + _ASM_EXTABLE(0b, 0b)
12021 +#endif
12022 +
12023 + "sete %1\n"
12024 : "+m" (l->a.counter), "=qm" (c)
12025 : "ir" (i) : "memory");
12026 return c;
12027 @@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
12028 {
12029 unsigned char c;
12030
12031 - asm volatile(_ASM_DEC "%0; sete %1"
12032 + asm volatile(_ASM_DEC "%0\n"
12033 +
12034 +#ifdef CONFIG_PAX_REFCOUNT
12035 + "jno 0f\n"
12036 + _ASM_INC "%0\n"
12037 + "int $4\n0:\n"
12038 + _ASM_EXTABLE(0b, 0b)
12039 +#endif
12040 +
12041 + "sete %1\n"
12042 : "+m" (l->a.counter), "=qm" (c)
12043 : : "memory");
12044 return c != 0;
12045 @@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
12046 {
12047 unsigned char c;
12048
12049 - asm volatile(_ASM_INC "%0; sete %1"
12050 + asm volatile(_ASM_INC "%0\n"
12051 +
12052 +#ifdef CONFIG_PAX_REFCOUNT
12053 + "jno 0f\n"
12054 + _ASM_DEC "%0\n"
12055 + "int $4\n0:\n"
12056 + _ASM_EXTABLE(0b, 0b)
12057 +#endif
12058 +
12059 + "sete %1\n"
12060 : "+m" (l->a.counter), "=qm" (c)
12061 : : "memory");
12062 return c != 0;
12063 @@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
12064 {
12065 unsigned char c;
12066
12067 - asm volatile(_ASM_ADD "%2,%0; sets %1"
12068 + asm volatile(_ASM_ADD "%2,%0\n"
12069 +
12070 +#ifdef CONFIG_PAX_REFCOUNT
12071 + "jno 0f\n"
12072 + _ASM_SUB "%2,%0\n"
12073 + "int $4\n0:\n"
12074 + _ASM_EXTABLE(0b, 0b)
12075 +#endif
12076 +
12077 + "sets %1\n"
12078 : "+m" (l->a.counter), "=qm" (c)
12079 : "ir" (i) : "memory");
12080 return c;
12081 @@ -132,7 +232,15 @@ static inline long local_add_return(long i, local_t *l)
12082 #endif
12083 /* Modern 486+ processor */
12084 __i = i;
12085 - asm volatile(_ASM_XADD "%0, %1;"
12086 + asm volatile(_ASM_XADD "%0, %1\n"
12087 +
12088 +#ifdef CONFIG_PAX_REFCOUNT
12089 + "jno 0f\n"
12090 + _ASM_MOV "%0,%1\n"
12091 + "int $4\n0:\n"
12092 + _ASM_EXTABLE(0b, 0b)
12093 +#endif
12094 +
12095 : "+r" (i), "+m" (l->a.counter)
12096 : : "memory");
12097 return i + __i;
12098 @@ -147,6 +255,38 @@ no_xadd: /* Legacy 386 processor */
12099 #endif
12100 }
12101
12102 +/**
12103 + * local_add_return_unchecked - add and return
12104 + * @i: integer value to add
12105 + * @l: pointer to type local_unchecked_t
12106 + *
12107 + * Atomically adds @i to @l and returns @i + @l
12108 + */
12109 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
12110 +{
12111 + long __i;
12112 +#ifdef CONFIG_M386
12113 + unsigned long flags;
12114 + if (unlikely(boot_cpu_data.x86 <= 3))
12115 + goto no_xadd;
12116 +#endif
12117 + /* Modern 486+ processor */
12118 + __i = i;
12119 + asm volatile(_ASM_XADD "%0, %1\n"
12120 + : "+r" (i), "+m" (l->a.counter)
12121 + : : "memory");
12122 + return i + __i;
12123 +
12124 +#ifdef CONFIG_M386
12125 +no_xadd: /* Legacy 386 processor */
12126 + local_irq_save(flags);
12127 + __i = local_read_unchecked(l);
12128 + local_set_unchecked(l, i + __i);
12129 + local_irq_restore(flags);
12130 + return i + __i;
12131 +#endif
12132 +}
12133 +
12134 static inline long local_sub_return(long i, local_t *l)
12135 {
12136 return local_add_return(-i, l);
12137 @@ -157,6 +297,8 @@ static inline long local_sub_return(long i, local_t *l)
12138
12139 #define local_cmpxchg(l, o, n) \
12140 (cmpxchg_local(&((l)->a.counter), (o), (n)))
12141 +#define local_cmpxchg_unchecked(l, o, n) \
12142 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
12143 /* Always has a lock prefix */
12144 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
12145
12146 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
12147 index 593e51d..fa69c9a 100644
12148 --- a/arch/x86/include/asm/mman.h
12149 +++ b/arch/x86/include/asm/mman.h
12150 @@ -5,4 +5,14 @@
12151
12152 #include <asm-generic/mman.h>
12153
12154 +#ifdef __KERNEL__
12155 +#ifndef __ASSEMBLY__
12156 +#ifdef CONFIG_X86_32
12157 +#define arch_mmap_check i386_mmap_check
12158 +int i386_mmap_check(unsigned long addr, unsigned long len,
12159 + unsigned long flags);
12160 +#endif
12161 +#endif
12162 +#endif
12163 +
12164 #endif /* _ASM_X86_MMAN_H */
12165 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
12166 index 5f55e69..e20bfb1 100644
12167 --- a/arch/x86/include/asm/mmu.h
12168 +++ b/arch/x86/include/asm/mmu.h
12169 @@ -9,7 +9,7 @@
12170 * we put the segment information here.
12171 */
12172 typedef struct {
12173 - void *ldt;
12174 + struct desc_struct *ldt;
12175 int size;
12176
12177 #ifdef CONFIG_X86_64
12178 @@ -18,7 +18,19 @@ typedef struct {
12179 #endif
12180
12181 struct mutex lock;
12182 - void *vdso;
12183 + unsigned long vdso;
12184 +
12185 +#ifdef CONFIG_X86_32
12186 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
12187 + unsigned long user_cs_base;
12188 + unsigned long user_cs_limit;
12189 +
12190 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
12191 + cpumask_t cpu_user_cs_mask;
12192 +#endif
12193 +
12194 +#endif
12195 +#endif
12196 } mm_context_t;
12197
12198 #ifdef CONFIG_SMP
12199 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
12200 index cdbf367..adb37ac 100644
12201 --- a/arch/x86/include/asm/mmu_context.h
12202 +++ b/arch/x86/include/asm/mmu_context.h
12203 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
12204
12205 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
12206 {
12207 +
12208 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12209 + unsigned int i;
12210 + pgd_t *pgd;
12211 +
12212 + pax_open_kernel();
12213 + pgd = get_cpu_pgd(smp_processor_id());
12214 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
12215 + set_pgd_batched(pgd+i, native_make_pgd(0));
12216 + pax_close_kernel();
12217 +#endif
12218 +
12219 #ifdef CONFIG_SMP
12220 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
12221 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
12222 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12223 struct task_struct *tsk)
12224 {
12225 unsigned cpu = smp_processor_id();
12226 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12227 + int tlbstate = TLBSTATE_OK;
12228 +#endif
12229
12230 if (likely(prev != next)) {
12231 #ifdef CONFIG_SMP
12232 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12233 + tlbstate = this_cpu_read(cpu_tlbstate.state);
12234 +#endif
12235 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12236 this_cpu_write(cpu_tlbstate.active_mm, next);
12237 #endif
12238 cpumask_set_cpu(cpu, mm_cpumask(next));
12239
12240 /* Re-load page tables */
12241 +#ifdef CONFIG_PAX_PER_CPU_PGD
12242 + pax_open_kernel();
12243 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12244 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12245 + pax_close_kernel();
12246 + load_cr3(get_cpu_pgd(cpu));
12247 +#else
12248 load_cr3(next->pgd);
12249 +#endif
12250
12251 /* stop flush ipis for the previous mm */
12252 cpumask_clear_cpu(cpu, mm_cpumask(prev));
12253 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12254 */
12255 if (unlikely(prev->context.ldt != next->context.ldt))
12256 load_LDT_nolock(&next->context);
12257 - }
12258 +
12259 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
12260 + if (!(__supported_pte_mask & _PAGE_NX)) {
12261 + smp_mb__before_clear_bit();
12262 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
12263 + smp_mb__after_clear_bit();
12264 + cpu_set(cpu, next->context.cpu_user_cs_mask);
12265 + }
12266 +#endif
12267 +
12268 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12269 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
12270 + prev->context.user_cs_limit != next->context.user_cs_limit))
12271 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12272 #ifdef CONFIG_SMP
12273 + else if (unlikely(tlbstate != TLBSTATE_OK))
12274 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12275 +#endif
12276 +#endif
12277 +
12278 + }
12279 else {
12280 +
12281 +#ifdef CONFIG_PAX_PER_CPU_PGD
12282 + pax_open_kernel();
12283 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12284 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12285 + pax_close_kernel();
12286 + load_cr3(get_cpu_pgd(cpu));
12287 +#endif
12288 +
12289 +#ifdef CONFIG_SMP
12290 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12291 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
12292
12293 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12294 * tlb flush IPI delivery. We must reload CR3
12295 * to make sure to use no freed page tables.
12296 */
12297 +
12298 +#ifndef CONFIG_PAX_PER_CPU_PGD
12299 load_cr3(next->pgd);
12300 +#endif
12301 +
12302 load_LDT_nolock(&next->context);
12303 +
12304 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
12305 + if (!(__supported_pte_mask & _PAGE_NX))
12306 + cpu_set(cpu, next->context.cpu_user_cs_mask);
12307 +#endif
12308 +
12309 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12310 +#ifdef CONFIG_PAX_PAGEEXEC
12311 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
12312 +#endif
12313 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12314 +#endif
12315 +
12316 }
12317 +#endif
12318 }
12319 -#endif
12320 }
12321
12322 #define activate_mm(prev, next) \
12323 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
12324 index 9eae775..c914fea 100644
12325 --- a/arch/x86/include/asm/module.h
12326 +++ b/arch/x86/include/asm/module.h
12327 @@ -5,6 +5,7 @@
12328
12329 #ifdef CONFIG_X86_64
12330 /* X86_64 does not define MODULE_PROC_FAMILY */
12331 +#define MODULE_PROC_FAMILY ""
12332 #elif defined CONFIG_M386
12333 #define MODULE_PROC_FAMILY "386 "
12334 #elif defined CONFIG_M486
12335 @@ -59,8 +60,20 @@
12336 #error unknown processor family
12337 #endif
12338
12339 -#ifdef CONFIG_X86_32
12340 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
12341 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
12342 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
12343 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
12344 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
12345 +#else
12346 +#define MODULE_PAX_KERNEXEC ""
12347 #endif
12348
12349 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12350 +#define MODULE_PAX_UDEREF "UDEREF "
12351 +#else
12352 +#define MODULE_PAX_UDEREF ""
12353 +#endif
12354 +
12355 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
12356 +
12357 #endif /* _ASM_X86_MODULE_H */
12358 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
12359 index 320f7bb..e89f8f8 100644
12360 --- a/arch/x86/include/asm/page_64_types.h
12361 +++ b/arch/x86/include/asm/page_64_types.h
12362 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
12363
12364 /* duplicated to the one in bootmem.h */
12365 extern unsigned long max_pfn;
12366 -extern unsigned long phys_base;
12367 +extern const unsigned long phys_base;
12368
12369 extern unsigned long __phys_addr(unsigned long);
12370 #define __phys_reloc_hide(x) (x)
12371 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
12372 index a0facf3..c017b15 100644
12373 --- a/arch/x86/include/asm/paravirt.h
12374 +++ b/arch/x86/include/asm/paravirt.h
12375 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
12376 val);
12377 }
12378
12379 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12380 +{
12381 + pgdval_t val = native_pgd_val(pgd);
12382 +
12383 + if (sizeof(pgdval_t) > sizeof(long))
12384 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
12385 + val, (u64)val >> 32);
12386 + else
12387 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
12388 + val);
12389 +}
12390 +
12391 static inline void pgd_clear(pgd_t *pgdp)
12392 {
12393 set_pgd(pgdp, __pgd(0));
12394 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
12395 pv_mmu_ops.set_fixmap(idx, phys, flags);
12396 }
12397
12398 +#ifdef CONFIG_PAX_KERNEXEC
12399 +static inline unsigned long pax_open_kernel(void)
12400 +{
12401 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
12402 +}
12403 +
12404 +static inline unsigned long pax_close_kernel(void)
12405 +{
12406 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
12407 +}
12408 +#else
12409 +static inline unsigned long pax_open_kernel(void) { return 0; }
12410 +static inline unsigned long pax_close_kernel(void) { return 0; }
12411 +#endif
12412 +
12413 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
12414
12415 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
12416 @@ -929,7 +956,7 @@ extern void default_banner(void);
12417
12418 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
12419 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
12420 -#define PARA_INDIRECT(addr) *%cs:addr
12421 +#define PARA_INDIRECT(addr) *%ss:addr
12422 #endif
12423
12424 #define INTERRUPT_RETURN \
12425 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
12426 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
12427 CLBR_NONE, \
12428 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
12429 +
12430 +#define GET_CR0_INTO_RDI \
12431 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
12432 + mov %rax,%rdi
12433 +
12434 +#define SET_RDI_INTO_CR0 \
12435 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
12436 +
12437 +#define GET_CR3_INTO_RDI \
12438 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
12439 + mov %rax,%rdi
12440 +
12441 +#define SET_RDI_INTO_CR3 \
12442 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
12443 +
12444 #endif /* CONFIG_X86_32 */
12445
12446 #endif /* __ASSEMBLY__ */
12447 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
12448 index 142236e..57cf5ea 100644
12449 --- a/arch/x86/include/asm/paravirt_types.h
12450 +++ b/arch/x86/include/asm/paravirt_types.h
12451 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
12452 struct paravirt_callee_save make_pud;
12453
12454 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
12455 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
12456 #endif /* PAGETABLE_LEVELS == 4 */
12457 #endif /* PAGETABLE_LEVELS >= 3 */
12458
12459 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
12460 an mfn. We can tell which is which from the index. */
12461 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
12462 phys_addr_t phys, pgprot_t flags);
12463 +
12464 +#ifdef CONFIG_PAX_KERNEXEC
12465 + unsigned long (*pax_open_kernel)(void);
12466 + unsigned long (*pax_close_kernel)(void);
12467 +#endif
12468 +
12469 };
12470
12471 struct arch_spinlock;
12472 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
12473 index b4389a4..7024269 100644
12474 --- a/arch/x86/include/asm/pgalloc.h
12475 +++ b/arch/x86/include/asm/pgalloc.h
12476 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
12477 pmd_t *pmd, pte_t *pte)
12478 {
12479 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12480 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
12481 +}
12482 +
12483 +static inline void pmd_populate_user(struct mm_struct *mm,
12484 + pmd_t *pmd, pte_t *pte)
12485 +{
12486 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12487 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
12488 }
12489
12490 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
12491
12492 #ifdef CONFIG_X86_PAE
12493 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
12494 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
12495 +{
12496 + pud_populate(mm, pudp, pmd);
12497 +}
12498 #else /* !CONFIG_X86_PAE */
12499 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12500 {
12501 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12502 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
12503 }
12504 +
12505 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12506 +{
12507 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12508 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
12509 +}
12510 #endif /* CONFIG_X86_PAE */
12511
12512 #if PAGETABLE_LEVELS > 3
12513 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12514 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
12515 }
12516
12517 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12518 +{
12519 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
12520 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
12521 +}
12522 +
12523 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
12524 {
12525 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
12526 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
12527 index f2b489c..4f7e2e5 100644
12528 --- a/arch/x86/include/asm/pgtable-2level.h
12529 +++ b/arch/x86/include/asm/pgtable-2level.h
12530 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
12531
12532 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12533 {
12534 + pax_open_kernel();
12535 *pmdp = pmd;
12536 + pax_close_kernel();
12537 }
12538
12539 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12540 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
12541 index 4cc9f2b..5fd9226 100644
12542 --- a/arch/x86/include/asm/pgtable-3level.h
12543 +++ b/arch/x86/include/asm/pgtable-3level.h
12544 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12545
12546 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12547 {
12548 + pax_open_kernel();
12549 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
12550 + pax_close_kernel();
12551 }
12552
12553 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12554 {
12555 + pax_open_kernel();
12556 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
12557 + pax_close_kernel();
12558 }
12559
12560 /*
12561 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
12562 index a1f780d..a3eb32f 100644
12563 --- a/arch/x86/include/asm/pgtable.h
12564 +++ b/arch/x86/include/asm/pgtable.h
12565 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12566
12567 #ifndef __PAGETABLE_PUD_FOLDED
12568 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
12569 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
12570 #define pgd_clear(pgd) native_pgd_clear(pgd)
12571 #endif
12572
12573 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12574
12575 #define arch_end_context_switch(prev) do {} while(0)
12576
12577 +#define pax_open_kernel() native_pax_open_kernel()
12578 +#define pax_close_kernel() native_pax_close_kernel()
12579 #endif /* CONFIG_PARAVIRT */
12580
12581 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
12582 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
12583 +
12584 +#ifdef CONFIG_PAX_KERNEXEC
12585 +static inline unsigned long native_pax_open_kernel(void)
12586 +{
12587 + unsigned long cr0;
12588 +
12589 + preempt_disable();
12590 + barrier();
12591 + cr0 = read_cr0() ^ X86_CR0_WP;
12592 + BUG_ON(cr0 & X86_CR0_WP);
12593 + write_cr0(cr0);
12594 + return cr0 ^ X86_CR0_WP;
12595 +}
12596 +
12597 +static inline unsigned long native_pax_close_kernel(void)
12598 +{
12599 + unsigned long cr0;
12600 +
12601 + cr0 = read_cr0() ^ X86_CR0_WP;
12602 + BUG_ON(!(cr0 & X86_CR0_WP));
12603 + write_cr0(cr0);
12604 + barrier();
12605 + preempt_enable_no_resched();
12606 + return cr0 ^ X86_CR0_WP;
12607 +}
12608 +#else
12609 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
12610 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
12611 +#endif
12612 +
12613 /*
12614 * The following only work if pte_present() is true.
12615 * Undefined behaviour if not..
12616 */
12617 +static inline int pte_user(pte_t pte)
12618 +{
12619 + return pte_val(pte) & _PAGE_USER;
12620 +}
12621 +
12622 static inline int pte_dirty(pte_t pte)
12623 {
12624 return pte_flags(pte) & _PAGE_DIRTY;
12625 @@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
12626 return pte_clear_flags(pte, _PAGE_RW);
12627 }
12628
12629 +static inline pte_t pte_mkread(pte_t pte)
12630 +{
12631 + return __pte(pte_val(pte) | _PAGE_USER);
12632 +}
12633 +
12634 static inline pte_t pte_mkexec(pte_t pte)
12635 {
12636 - return pte_clear_flags(pte, _PAGE_NX);
12637 +#ifdef CONFIG_X86_PAE
12638 + if (__supported_pte_mask & _PAGE_NX)
12639 + return pte_clear_flags(pte, _PAGE_NX);
12640 + else
12641 +#endif
12642 + return pte_set_flags(pte, _PAGE_USER);
12643 +}
12644 +
12645 +static inline pte_t pte_exprotect(pte_t pte)
12646 +{
12647 +#ifdef CONFIG_X86_PAE
12648 + if (__supported_pte_mask & _PAGE_NX)
12649 + return pte_set_flags(pte, _PAGE_NX);
12650 + else
12651 +#endif
12652 + return pte_clear_flags(pte, _PAGE_USER);
12653 }
12654
12655 static inline pte_t pte_mkdirty(pte_t pte)
12656 @@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
12657 #endif
12658
12659 #ifndef __ASSEMBLY__
12660 +
12661 +#ifdef CONFIG_PAX_PER_CPU_PGD
12662 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
12663 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
12664 +{
12665 + return cpu_pgd[cpu];
12666 +}
12667 +#endif
12668 +
12669 #include <linux/mm_types.h>
12670
12671 static inline int pte_none(pte_t pte)
12672 @@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
12673
12674 static inline int pgd_bad(pgd_t pgd)
12675 {
12676 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
12677 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
12678 }
12679
12680 static inline int pgd_none(pgd_t pgd)
12681 @@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
12682 * pgd_offset() returns a (pgd_t *)
12683 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
12684 */
12685 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
12686 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
12687 +
12688 +#ifdef CONFIG_PAX_PER_CPU_PGD
12689 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
12690 +#endif
12691 +
12692 /*
12693 * a shortcut which implies the use of the kernel's pgd, instead
12694 * of a process's
12695 @@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
12696 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
12697 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
12698
12699 +#ifdef CONFIG_X86_32
12700 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
12701 +#else
12702 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
12703 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
12704 +
12705 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12706 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
12707 +#else
12708 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
12709 +#endif
12710 +
12711 +#endif
12712 +
12713 #ifndef __ASSEMBLY__
12714
12715 extern int direct_gbpages;
12716 @@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
12717 * dst and src can be on the same page, but the range must not overlap,
12718 * and must not cross a page boundary.
12719 */
12720 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
12721 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
12722 {
12723 - memcpy(dst, src, count * sizeof(pgd_t));
12724 + pax_open_kernel();
12725 + while (count--)
12726 + *dst++ = *src++;
12727 + pax_close_kernel();
12728 }
12729
12730 +#ifdef CONFIG_PAX_PER_CPU_PGD
12731 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
12732 +#endif
12733 +
12734 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12735 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
12736 +#else
12737 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
12738 +#endif
12739
12740 #include <asm-generic/pgtable.h>
12741 #endif /* __ASSEMBLY__ */
12742 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
12743 index 8faa215..a8a17ea 100644
12744 --- a/arch/x86/include/asm/pgtable_32.h
12745 +++ b/arch/x86/include/asm/pgtable_32.h
12746 @@ -25,9 +25,6 @@
12747 struct mm_struct;
12748 struct vm_area_struct;
12749
12750 -extern pgd_t swapper_pg_dir[1024];
12751 -extern pgd_t initial_page_table[1024];
12752 -
12753 static inline void pgtable_cache_init(void) { }
12754 static inline void check_pgt_cache(void) { }
12755 void paging_init(void);
12756 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12757 # include <asm/pgtable-2level.h>
12758 #endif
12759
12760 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
12761 +extern pgd_t initial_page_table[PTRS_PER_PGD];
12762 +#ifdef CONFIG_X86_PAE
12763 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
12764 +#endif
12765 +
12766 #if defined(CONFIG_HIGHPTE)
12767 #define pte_offset_map(dir, address) \
12768 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
12769 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12770 /* Clear a kernel PTE and flush it from the TLB */
12771 #define kpte_clear_flush(ptep, vaddr) \
12772 do { \
12773 + pax_open_kernel(); \
12774 pte_clear(&init_mm, (vaddr), (ptep)); \
12775 + pax_close_kernel(); \
12776 __flush_tlb_one((vaddr)); \
12777 } while (0)
12778
12779 @@ -75,6 +80,9 @@ do { \
12780
12781 #endif /* !__ASSEMBLY__ */
12782
12783 +#define HAVE_ARCH_UNMAPPED_AREA
12784 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
12785 +
12786 /*
12787 * kern_addr_valid() is (1) for FLATMEM and (0) for
12788 * SPARSEMEM and DISCONTIGMEM
12789 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
12790 index ed5903b..c7fe163 100644
12791 --- a/arch/x86/include/asm/pgtable_32_types.h
12792 +++ b/arch/x86/include/asm/pgtable_32_types.h
12793 @@ -8,7 +8,7 @@
12794 */
12795 #ifdef CONFIG_X86_PAE
12796 # include <asm/pgtable-3level_types.h>
12797 -# define PMD_SIZE (1UL << PMD_SHIFT)
12798 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
12799 # define PMD_MASK (~(PMD_SIZE - 1))
12800 #else
12801 # include <asm/pgtable-2level_types.h>
12802 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
12803 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
12804 #endif
12805
12806 +#ifdef CONFIG_PAX_KERNEXEC
12807 +#ifndef __ASSEMBLY__
12808 +extern unsigned char MODULES_EXEC_VADDR[];
12809 +extern unsigned char MODULES_EXEC_END[];
12810 +#endif
12811 +#include <asm/boot.h>
12812 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
12813 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
12814 +#else
12815 +#define ktla_ktva(addr) (addr)
12816 +#define ktva_ktla(addr) (addr)
12817 +#endif
12818 +
12819 #define MODULES_VADDR VMALLOC_START
12820 #define MODULES_END VMALLOC_END
12821 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
12822 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
12823 index 47356f9..deb94a2 100644
12824 --- a/arch/x86/include/asm/pgtable_64.h
12825 +++ b/arch/x86/include/asm/pgtable_64.h
12826 @@ -16,10 +16,14 @@
12827
12828 extern pud_t level3_kernel_pgt[512];
12829 extern pud_t level3_ident_pgt[512];
12830 +extern pud_t level3_vmalloc_start_pgt[512];
12831 +extern pud_t level3_vmalloc_end_pgt[512];
12832 +extern pud_t level3_vmemmap_pgt[512];
12833 +extern pud_t level2_vmemmap_pgt[512];
12834 extern pmd_t level2_kernel_pgt[512];
12835 extern pmd_t level2_fixmap_pgt[512];
12836 -extern pmd_t level2_ident_pgt[512];
12837 -extern pgd_t init_level4_pgt[];
12838 +extern pmd_t level2_ident_pgt[512*2];
12839 +extern pgd_t init_level4_pgt[512];
12840
12841 #define swapper_pg_dir init_level4_pgt
12842
12843 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12844
12845 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12846 {
12847 + pax_open_kernel();
12848 *pmdp = pmd;
12849 + pax_close_kernel();
12850 }
12851
12852 static inline void native_pmd_clear(pmd_t *pmd)
12853 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
12854
12855 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12856 {
12857 + pax_open_kernel();
12858 *pudp = pud;
12859 + pax_close_kernel();
12860 }
12861
12862 static inline void native_pud_clear(pud_t *pud)
12863 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
12864
12865 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
12866 {
12867 + pax_open_kernel();
12868 + *pgdp = pgd;
12869 + pax_close_kernel();
12870 +}
12871 +
12872 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12873 +{
12874 *pgdp = pgd;
12875 }
12876
12877 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
12878 index 766ea16..5b96cb3 100644
12879 --- a/arch/x86/include/asm/pgtable_64_types.h
12880 +++ b/arch/x86/include/asm/pgtable_64_types.h
12881 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
12882 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
12883 #define MODULES_END _AC(0xffffffffff000000, UL)
12884 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
12885 +#define MODULES_EXEC_VADDR MODULES_VADDR
12886 +#define MODULES_EXEC_END MODULES_END
12887 +
12888 +#define ktla_ktva(addr) (addr)
12889 +#define ktva_ktla(addr) (addr)
12890
12891 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
12892 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
12893 index ec8a1fc..7ccb593 100644
12894 --- a/arch/x86/include/asm/pgtable_types.h
12895 +++ b/arch/x86/include/asm/pgtable_types.h
12896 @@ -16,13 +16,12 @@
12897 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
12898 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
12899 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
12900 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
12901 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
12902 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
12903 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
12904 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
12905 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
12906 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
12907 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
12908 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
12909 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
12910 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
12911
12912 /* If _PAGE_BIT_PRESENT is clear, we use these: */
12913 @@ -40,7 +39,6 @@
12914 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
12915 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
12916 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
12917 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
12918 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
12919 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
12920 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
12921 @@ -57,8 +55,10 @@
12922
12923 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
12924 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
12925 -#else
12926 +#elif defined(CONFIG_KMEMCHECK)
12927 #define _PAGE_NX (_AT(pteval_t, 0))
12928 +#else
12929 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
12930 #endif
12931
12932 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
12933 @@ -96,6 +96,9 @@
12934 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
12935 _PAGE_ACCESSED)
12936
12937 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
12938 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
12939 +
12940 #define __PAGE_KERNEL_EXEC \
12941 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
12942 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
12943 @@ -106,7 +109,7 @@
12944 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
12945 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
12946 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
12947 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
12948 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
12949 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
12950 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
12951 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
12952 @@ -168,8 +171,8 @@
12953 * bits are combined, this will alow user to access the high address mapped
12954 * VDSO in the presence of CONFIG_COMPAT_VDSO
12955 */
12956 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
12957 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
12958 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
12959 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
12960 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
12961 #endif
12962
12963 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
12964 {
12965 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
12966 }
12967 +#endif
12968
12969 +#if PAGETABLE_LEVELS == 3
12970 +#include <asm-generic/pgtable-nopud.h>
12971 +#endif
12972 +
12973 +#if PAGETABLE_LEVELS == 2
12974 +#include <asm-generic/pgtable-nopmd.h>
12975 +#endif
12976 +
12977 +#ifndef __ASSEMBLY__
12978 #if PAGETABLE_LEVELS > 3
12979 typedef struct { pudval_t pud; } pud_t;
12980
12981 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
12982 return pud.pud;
12983 }
12984 #else
12985 -#include <asm-generic/pgtable-nopud.h>
12986 -
12987 static inline pudval_t native_pud_val(pud_t pud)
12988 {
12989 return native_pgd_val(pud.pgd);
12990 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
12991 return pmd.pmd;
12992 }
12993 #else
12994 -#include <asm-generic/pgtable-nopmd.h>
12995 -
12996 static inline pmdval_t native_pmd_val(pmd_t pmd)
12997 {
12998 return native_pgd_val(pmd.pud.pgd);
12999 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
13000
13001 extern pteval_t __supported_pte_mask;
13002 extern void set_nx(void);
13003 -extern int nx_enabled;
13004
13005 #define pgprot_writecombine pgprot_writecombine
13006 extern pgprot_t pgprot_writecombine(pgprot_t prot);
13007 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
13008 index ad1fc85..0b15fe1 100644
13009 --- a/arch/x86/include/asm/processor.h
13010 +++ b/arch/x86/include/asm/processor.h
13011 @@ -289,7 +289,7 @@ struct tss_struct {
13012
13013 } ____cacheline_aligned;
13014
13015 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
13016 +extern struct tss_struct init_tss[NR_CPUS];
13017
13018 /*
13019 * Save the original ist values for checking stack pointers during debugging
13020 @@ -818,11 +818,18 @@ static inline void spin_lock_prefetch(const void *x)
13021 */
13022 #define TASK_SIZE PAGE_OFFSET
13023 #define TASK_SIZE_MAX TASK_SIZE
13024 +
13025 +#ifdef CONFIG_PAX_SEGMEXEC
13026 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
13027 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
13028 +#else
13029 #define STACK_TOP TASK_SIZE
13030 -#define STACK_TOP_MAX STACK_TOP
13031 +#endif
13032 +
13033 +#define STACK_TOP_MAX TASK_SIZE
13034
13035 #define INIT_THREAD { \
13036 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
13037 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
13038 .vm86_info = NULL, \
13039 .sysenter_cs = __KERNEL_CS, \
13040 .io_bitmap_ptr = NULL, \
13041 @@ -836,7 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
13042 */
13043 #define INIT_TSS { \
13044 .x86_tss = { \
13045 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
13046 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
13047 .ss0 = __KERNEL_DS, \
13048 .ss1 = __KERNEL_CS, \
13049 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
13050 @@ -847,11 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
13051 extern unsigned long thread_saved_pc(struct task_struct *tsk);
13052
13053 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
13054 -#define KSTK_TOP(info) \
13055 -({ \
13056 - unsigned long *__ptr = (unsigned long *)(info); \
13057 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
13058 -})
13059 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
13060
13061 /*
13062 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
13063 @@ -866,7 +869,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13064 #define task_pt_regs(task) \
13065 ({ \
13066 struct pt_regs *__regs__; \
13067 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
13068 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
13069 __regs__ - 1; \
13070 })
13071
13072 @@ -876,13 +879,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13073 /*
13074 * User space process size. 47bits minus one guard page.
13075 */
13076 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
13077 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
13078
13079 /* This decides where the kernel will search for a free chunk of vm
13080 * space during mmap's.
13081 */
13082 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
13083 - 0xc0000000 : 0xFFFFe000)
13084 + 0xc0000000 : 0xFFFFf000)
13085
13086 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
13087 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
13088 @@ -893,11 +896,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13089 #define STACK_TOP_MAX TASK_SIZE_MAX
13090
13091 #define INIT_THREAD { \
13092 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
13093 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
13094 }
13095
13096 #define INIT_TSS { \
13097 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
13098 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
13099 }
13100
13101 /*
13102 @@ -925,6 +928,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
13103 */
13104 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
13105
13106 +#ifdef CONFIG_PAX_SEGMEXEC
13107 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
13108 +#endif
13109 +
13110 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
13111
13112 /* Get/set a process' ability to use the timestamp counter instruction */
13113 @@ -985,12 +992,12 @@ extern bool cpu_has_amd_erratum(const int *);
13114 #define cpu_has_amd_erratum(x) (false)
13115 #endif /* CONFIG_CPU_SUP_AMD */
13116
13117 -extern unsigned long arch_align_stack(unsigned long sp);
13118 +#define arch_align_stack(x) ((x) & ~0xfUL)
13119 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
13120
13121 void default_idle(void);
13122 bool set_pm_idle_to_default(void);
13123
13124 -void stop_this_cpu(void *dummy);
13125 +void stop_this_cpu(void *dummy) __noreturn;
13126
13127 #endif /* _ASM_X86_PROCESSOR_H */
13128 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
13129 index 19f16eb..b50624b 100644
13130 --- a/arch/x86/include/asm/ptrace.h
13131 +++ b/arch/x86/include/asm/ptrace.h
13132 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
13133 }
13134
13135 /*
13136 - * user_mode_vm(regs) determines whether a register set came from user mode.
13137 + * user_mode(regs) determines whether a register set came from user mode.
13138 * This is true if V8086 mode was enabled OR if the register set was from
13139 * protected mode with RPL-3 CS value. This tricky test checks that with
13140 * one comparison. Many places in the kernel can bypass this full check
13141 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
13142 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
13143 + * be used.
13144 */
13145 -static inline int user_mode(struct pt_regs *regs)
13146 +static inline int user_mode_novm(struct pt_regs *regs)
13147 {
13148 #ifdef CONFIG_X86_32
13149 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
13150 #else
13151 - return !!(regs->cs & 3);
13152 + return !!(regs->cs & SEGMENT_RPL_MASK);
13153 #endif
13154 }
13155
13156 -static inline int user_mode_vm(struct pt_regs *regs)
13157 +static inline int user_mode(struct pt_regs *regs)
13158 {
13159 #ifdef CONFIG_X86_32
13160 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
13161 USER_RPL;
13162 #else
13163 - return user_mode(regs);
13164 + return user_mode_novm(regs);
13165 #endif
13166 }
13167
13168 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
13169 #ifdef CONFIG_X86_64
13170 static inline bool user_64bit_mode(struct pt_regs *regs)
13171 {
13172 + unsigned long cs = regs->cs & 0xffff;
13173 #ifndef CONFIG_PARAVIRT
13174 /*
13175 * On non-paravirt systems, this is the only long mode CPL 3
13176 * selector. We do not allow long mode selectors in the LDT.
13177 */
13178 - return regs->cs == __USER_CS;
13179 + return cs == __USER_CS;
13180 #else
13181 /* Headers are too twisted for this to go in paravirt.h. */
13182 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
13183 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
13184 #endif
13185 }
13186 #endif
13187 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
13188 index fe1ec5b..dc5c3fe 100644
13189 --- a/arch/x86/include/asm/realmode.h
13190 +++ b/arch/x86/include/asm/realmode.h
13191 @@ -22,16 +22,14 @@ struct real_mode_header {
13192 #endif
13193 /* APM/BIOS reboot */
13194 u32 machine_real_restart_asm;
13195 -#ifdef CONFIG_X86_64
13196 u32 machine_real_restart_seg;
13197 -#endif
13198 };
13199
13200 /* This must match data at trampoline_32/64.S */
13201 struct trampoline_header {
13202 #ifdef CONFIG_X86_32
13203 u32 start;
13204 - u16 gdt_pad;
13205 + u16 boot_cs;
13206 u16 gdt_limit;
13207 u32 gdt_base;
13208 #else
13209 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
13210 index a82c4f1..f9c9696 100644
13211 --- a/arch/x86/include/asm/reboot.h
13212 +++ b/arch/x86/include/asm/reboot.h
13213 @@ -6,12 +6,12 @@
13214 struct pt_regs;
13215
13216 struct machine_ops {
13217 - void (*restart)(char *cmd);
13218 - void (*halt)(void);
13219 - void (*power_off)(void);
13220 + void (* __noreturn restart)(char *cmd);
13221 + void (* __noreturn halt)(void);
13222 + void (* __noreturn power_off)(void);
13223 void (*shutdown)(void);
13224 void (*crash_shutdown)(struct pt_regs *);
13225 - void (*emergency_restart)(void);
13226 + void (* __noreturn emergency_restart)(void);
13227 };
13228
13229 extern struct machine_ops machine_ops;
13230 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
13231 index 2dbe4a7..ce1db00 100644
13232 --- a/arch/x86/include/asm/rwsem.h
13233 +++ b/arch/x86/include/asm/rwsem.h
13234 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
13235 {
13236 asm volatile("# beginning down_read\n\t"
13237 LOCK_PREFIX _ASM_INC "(%1)\n\t"
13238 +
13239 +#ifdef CONFIG_PAX_REFCOUNT
13240 + "jno 0f\n"
13241 + LOCK_PREFIX _ASM_DEC "(%1)\n"
13242 + "int $4\n0:\n"
13243 + _ASM_EXTABLE(0b, 0b)
13244 +#endif
13245 +
13246 /* adds 0x00000001 */
13247 " jns 1f\n"
13248 " call call_rwsem_down_read_failed\n"
13249 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
13250 "1:\n\t"
13251 " mov %1,%2\n\t"
13252 " add %3,%2\n\t"
13253 +
13254 +#ifdef CONFIG_PAX_REFCOUNT
13255 + "jno 0f\n"
13256 + "sub %3,%2\n"
13257 + "int $4\n0:\n"
13258 + _ASM_EXTABLE(0b, 0b)
13259 +#endif
13260 +
13261 " jle 2f\n\t"
13262 LOCK_PREFIX " cmpxchg %2,%0\n\t"
13263 " jnz 1b\n\t"
13264 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
13265 long tmp;
13266 asm volatile("# beginning down_write\n\t"
13267 LOCK_PREFIX " xadd %1,(%2)\n\t"
13268 +
13269 +#ifdef CONFIG_PAX_REFCOUNT
13270 + "jno 0f\n"
13271 + "mov %1,(%2)\n"
13272 + "int $4\n0:\n"
13273 + _ASM_EXTABLE(0b, 0b)
13274 +#endif
13275 +
13276 /* adds 0xffff0001, returns the old value */
13277 " test %1,%1\n\t"
13278 /* was the count 0 before? */
13279 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
13280 long tmp;
13281 asm volatile("# beginning __up_read\n\t"
13282 LOCK_PREFIX " xadd %1,(%2)\n\t"
13283 +
13284 +#ifdef CONFIG_PAX_REFCOUNT
13285 + "jno 0f\n"
13286 + "mov %1,(%2)\n"
13287 + "int $4\n0:\n"
13288 + _ASM_EXTABLE(0b, 0b)
13289 +#endif
13290 +
13291 /* subtracts 1, returns the old value */
13292 " jns 1f\n\t"
13293 " call call_rwsem_wake\n" /* expects old value in %edx */
13294 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
13295 long tmp;
13296 asm volatile("# beginning __up_write\n\t"
13297 LOCK_PREFIX " xadd %1,(%2)\n\t"
13298 +
13299 +#ifdef CONFIG_PAX_REFCOUNT
13300 + "jno 0f\n"
13301 + "mov %1,(%2)\n"
13302 + "int $4\n0:\n"
13303 + _ASM_EXTABLE(0b, 0b)
13304 +#endif
13305 +
13306 /* subtracts 0xffff0001, returns the old value */
13307 " jns 1f\n\t"
13308 " call call_rwsem_wake\n" /* expects old value in %edx */
13309 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13310 {
13311 asm volatile("# beginning __downgrade_write\n\t"
13312 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
13313 +
13314 +#ifdef CONFIG_PAX_REFCOUNT
13315 + "jno 0f\n"
13316 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
13317 + "int $4\n0:\n"
13318 + _ASM_EXTABLE(0b, 0b)
13319 +#endif
13320 +
13321 /*
13322 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
13323 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
13324 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13325 */
13326 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13327 {
13328 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
13329 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
13330 +
13331 +#ifdef CONFIG_PAX_REFCOUNT
13332 + "jno 0f\n"
13333 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
13334 + "int $4\n0:\n"
13335 + _ASM_EXTABLE(0b, 0b)
13336 +#endif
13337 +
13338 : "+m" (sem->count)
13339 : "er" (delta));
13340 }
13341 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13342 */
13343 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
13344 {
13345 - return delta + xadd(&sem->count, delta);
13346 + return delta + xadd_check_overflow(&sem->count, delta);
13347 }
13348
13349 #endif /* __KERNEL__ */
13350 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
13351 index c48a950..c6d7468 100644
13352 --- a/arch/x86/include/asm/segment.h
13353 +++ b/arch/x86/include/asm/segment.h
13354 @@ -64,10 +64,15 @@
13355 * 26 - ESPFIX small SS
13356 * 27 - per-cpu [ offset to per-cpu data area ]
13357 * 28 - stack_canary-20 [ for stack protector ]
13358 - * 29 - unused
13359 - * 30 - unused
13360 + * 29 - PCI BIOS CS
13361 + * 30 - PCI BIOS DS
13362 * 31 - TSS for double fault handler
13363 */
13364 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
13365 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
13366 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
13367 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
13368 +
13369 #define GDT_ENTRY_TLS_MIN 6
13370 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
13371
13372 @@ -79,6 +84,8 @@
13373
13374 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
13375
13376 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
13377 +
13378 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
13379
13380 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
13381 @@ -104,6 +111,12 @@
13382 #define __KERNEL_STACK_CANARY 0
13383 #endif
13384
13385 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
13386 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
13387 +
13388 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
13389 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
13390 +
13391 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
13392
13393 /*
13394 @@ -141,7 +154,7 @@
13395 */
13396
13397 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
13398 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
13399 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
13400
13401
13402 #else
13403 @@ -165,6 +178,8 @@
13404 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
13405 #define __USER32_DS __USER_DS
13406
13407 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
13408 +
13409 #define GDT_ENTRY_TSS 8 /* needs two entries */
13410 #define GDT_ENTRY_LDT 10 /* needs two entries */
13411 #define GDT_ENTRY_TLS_MIN 12
13412 @@ -185,6 +200,7 @@
13413 #endif
13414
13415 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
13416 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
13417 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
13418 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
13419 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
13420 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
13421 {
13422 unsigned long __limit;
13423 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
13424 - return __limit + 1;
13425 + return __limit;
13426 }
13427
13428 #endif /* !__ASSEMBLY__ */
13429 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
13430 index 4f19a15..e04d86f 100644
13431 --- a/arch/x86/include/asm/smp.h
13432 +++ b/arch/x86/include/asm/smp.h
13433 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
13434 /* cpus sharing the last level cache: */
13435 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
13436 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
13437 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
13438 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
13439
13440 static inline struct cpumask *cpu_sibling_mask(int cpu)
13441 {
13442 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
13443 extern int safe_smp_processor_id(void);
13444
13445 #elif defined(CONFIG_X86_64_SMP)
13446 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13447 -
13448 -#define stack_smp_processor_id() \
13449 -({ \
13450 - struct thread_info *ti; \
13451 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
13452 - ti->cpu; \
13453 -})
13454 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13455 +#define stack_smp_processor_id() raw_smp_processor_id()
13456 #define safe_smp_processor_id() smp_processor_id()
13457
13458 #endif
13459 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
13460 index 33692ea..350a534 100644
13461 --- a/arch/x86/include/asm/spinlock.h
13462 +++ b/arch/x86/include/asm/spinlock.h
13463 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
13464 static inline void arch_read_lock(arch_rwlock_t *rw)
13465 {
13466 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
13467 +
13468 +#ifdef CONFIG_PAX_REFCOUNT
13469 + "jno 0f\n"
13470 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
13471 + "int $4\n0:\n"
13472 + _ASM_EXTABLE(0b, 0b)
13473 +#endif
13474 +
13475 "jns 1f\n"
13476 "call __read_lock_failed\n\t"
13477 "1:\n"
13478 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
13479 static inline void arch_write_lock(arch_rwlock_t *rw)
13480 {
13481 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
13482 +
13483 +#ifdef CONFIG_PAX_REFCOUNT
13484 + "jno 0f\n"
13485 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
13486 + "int $4\n0:\n"
13487 + _ASM_EXTABLE(0b, 0b)
13488 +#endif
13489 +
13490 "jz 1f\n"
13491 "call __write_lock_failed\n\t"
13492 "1:\n"
13493 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
13494
13495 static inline void arch_read_unlock(arch_rwlock_t *rw)
13496 {
13497 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
13498 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
13499 +
13500 +#ifdef CONFIG_PAX_REFCOUNT
13501 + "jno 0f\n"
13502 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
13503 + "int $4\n0:\n"
13504 + _ASM_EXTABLE(0b, 0b)
13505 +#endif
13506 +
13507 :"+m" (rw->lock) : : "memory");
13508 }
13509
13510 static inline void arch_write_unlock(arch_rwlock_t *rw)
13511 {
13512 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
13513 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
13514 +
13515 +#ifdef CONFIG_PAX_REFCOUNT
13516 + "jno 0f\n"
13517 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
13518 + "int $4\n0:\n"
13519 + _ASM_EXTABLE(0b, 0b)
13520 +#endif
13521 +
13522 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
13523 }
13524
13525 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
13526 index 6a99859..03cb807 100644
13527 --- a/arch/x86/include/asm/stackprotector.h
13528 +++ b/arch/x86/include/asm/stackprotector.h
13529 @@ -47,7 +47,7 @@
13530 * head_32 for boot CPU and setup_per_cpu_areas() for others.
13531 */
13532 #define GDT_STACK_CANARY_INIT \
13533 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
13534 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
13535
13536 /*
13537 * Initialize the stackprotector canary value.
13538 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
13539
13540 static inline void load_stack_canary_segment(void)
13541 {
13542 -#ifdef CONFIG_X86_32
13543 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
13544 asm volatile ("mov %0, %%gs" : : "r" (0));
13545 #endif
13546 }
13547 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
13548 index 70bbe39..4ae2bd4 100644
13549 --- a/arch/x86/include/asm/stacktrace.h
13550 +++ b/arch/x86/include/asm/stacktrace.h
13551 @@ -11,28 +11,20 @@
13552
13553 extern int kstack_depth_to_print;
13554
13555 -struct thread_info;
13556 +struct task_struct;
13557 struct stacktrace_ops;
13558
13559 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
13560 - unsigned long *stack,
13561 - unsigned long bp,
13562 - const struct stacktrace_ops *ops,
13563 - void *data,
13564 - unsigned long *end,
13565 - int *graph);
13566 +typedef unsigned long walk_stack_t(struct task_struct *task,
13567 + void *stack_start,
13568 + unsigned long *stack,
13569 + unsigned long bp,
13570 + const struct stacktrace_ops *ops,
13571 + void *data,
13572 + unsigned long *end,
13573 + int *graph);
13574
13575 -extern unsigned long
13576 -print_context_stack(struct thread_info *tinfo,
13577 - unsigned long *stack, unsigned long bp,
13578 - const struct stacktrace_ops *ops, void *data,
13579 - unsigned long *end, int *graph);
13580 -
13581 -extern unsigned long
13582 -print_context_stack_bp(struct thread_info *tinfo,
13583 - unsigned long *stack, unsigned long bp,
13584 - const struct stacktrace_ops *ops, void *data,
13585 - unsigned long *end, int *graph);
13586 +extern walk_stack_t print_context_stack;
13587 +extern walk_stack_t print_context_stack_bp;
13588
13589 /* Generic stack tracer with callbacks */
13590
13591 @@ -40,7 +32,7 @@ struct stacktrace_ops {
13592 void (*address)(void *data, unsigned long address, int reliable);
13593 /* On negative return stop dumping */
13594 int (*stack)(void *data, char *name);
13595 - walk_stack_t walk_stack;
13596 + walk_stack_t *walk_stack;
13597 };
13598
13599 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
13600 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
13601 index 4ec45b3..a4f0a8a 100644
13602 --- a/arch/x86/include/asm/switch_to.h
13603 +++ b/arch/x86/include/asm/switch_to.h
13604 @@ -108,7 +108,7 @@ do { \
13605 "call __switch_to\n\t" \
13606 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
13607 __switch_canary \
13608 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
13609 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
13610 "movq %%rax,%%rdi\n\t" \
13611 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
13612 "jnz ret_from_fork\n\t" \
13613 @@ -119,7 +119,7 @@ do { \
13614 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
13615 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
13616 [_tif_fork] "i" (_TIF_FORK), \
13617 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
13618 + [thread_info] "m" (current_tinfo), \
13619 [current_task] "m" (current_task) \
13620 __switch_canary_iparam \
13621 : "memory", "cc" __EXTRA_CLOBBER)
13622 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
13623 index 2d946e6..e453ec4 100644
13624 --- a/arch/x86/include/asm/thread_info.h
13625 +++ b/arch/x86/include/asm/thread_info.h
13626 @@ -10,6 +10,7 @@
13627 #include <linux/compiler.h>
13628 #include <asm/page.h>
13629 #include <asm/types.h>
13630 +#include <asm/percpu.h>
13631
13632 /*
13633 * low level task data that entry.S needs immediate access to
13634 @@ -24,7 +25,6 @@ struct exec_domain;
13635 #include <linux/atomic.h>
13636
13637 struct thread_info {
13638 - struct task_struct *task; /* main task structure */
13639 struct exec_domain *exec_domain; /* execution domain */
13640 __u32 flags; /* low level flags */
13641 __u32 status; /* thread synchronous flags */
13642 @@ -34,19 +34,13 @@ struct thread_info {
13643 mm_segment_t addr_limit;
13644 struct restart_block restart_block;
13645 void __user *sysenter_return;
13646 -#ifdef CONFIG_X86_32
13647 - unsigned long previous_esp; /* ESP of the previous stack in
13648 - case of nested (IRQ) stacks
13649 - */
13650 - __u8 supervisor_stack[0];
13651 -#endif
13652 + unsigned long lowest_stack;
13653 unsigned int sig_on_uaccess_error:1;
13654 unsigned int uaccess_err:1; /* uaccess failed */
13655 };
13656
13657 -#define INIT_THREAD_INFO(tsk) \
13658 +#define INIT_THREAD_INFO \
13659 { \
13660 - .task = &tsk, \
13661 .exec_domain = &default_exec_domain, \
13662 .flags = 0, \
13663 .cpu = 0, \
13664 @@ -57,7 +51,7 @@ struct thread_info {
13665 }, \
13666 }
13667
13668 -#define init_thread_info (init_thread_union.thread_info)
13669 +#define init_thread_info (init_thread_union.stack)
13670 #define init_stack (init_thread_union.stack)
13671
13672 #else /* !__ASSEMBLY__ */
13673 @@ -98,6 +92,7 @@ struct thread_info {
13674 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
13675 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
13676 #define TIF_X32 30 /* 32-bit native x86-64 binary */
13677 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
13678
13679 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
13680 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
13681 @@ -122,17 +117,18 @@ struct thread_info {
13682 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
13683 #define _TIF_ADDR32 (1 << TIF_ADDR32)
13684 #define _TIF_X32 (1 << TIF_X32)
13685 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
13686
13687 /* work to do in syscall_trace_enter() */
13688 #define _TIF_WORK_SYSCALL_ENTRY \
13689 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
13690 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
13691 - _TIF_NOHZ)
13692 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
13693
13694 /* work to do in syscall_trace_leave() */
13695 #define _TIF_WORK_SYSCALL_EXIT \
13696 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
13697 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
13698 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
13699
13700 /* work to do on interrupt/exception return */
13701 #define _TIF_WORK_MASK \
13702 @@ -143,7 +139,7 @@ struct thread_info {
13703 /* work to do on any return to user space */
13704 #define _TIF_ALLWORK_MASK \
13705 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
13706 - _TIF_NOHZ)
13707 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
13708
13709 /* Only used for 64 bit */
13710 #define _TIF_DO_NOTIFY_MASK \
13711 @@ -159,45 +155,40 @@ struct thread_info {
13712
13713 #define PREEMPT_ACTIVE 0x10000000
13714
13715 -#ifdef CONFIG_X86_32
13716 -
13717 -#define STACK_WARN (THREAD_SIZE/8)
13718 -/*
13719 - * macros/functions for gaining access to the thread information structure
13720 - *
13721 - * preempt_count needs to be 1 initially, until the scheduler is functional.
13722 - */
13723 -#ifndef __ASSEMBLY__
13724 -
13725 -
13726 -/* how to get the current stack pointer from C */
13727 -register unsigned long current_stack_pointer asm("esp") __used;
13728 -
13729 -/* how to get the thread information struct from C */
13730 -static inline struct thread_info *current_thread_info(void)
13731 -{
13732 - return (struct thread_info *)
13733 - (current_stack_pointer & ~(THREAD_SIZE - 1));
13734 -}
13735 -
13736 -#else /* !__ASSEMBLY__ */
13737 -
13738 +#ifdef __ASSEMBLY__
13739 /* how to get the thread information struct from ASM */
13740 #define GET_THREAD_INFO(reg) \
13741 - movl $-THREAD_SIZE, reg; \
13742 - andl %esp, reg
13743 + mov PER_CPU_VAR(current_tinfo), reg
13744
13745 /* use this one if reg already contains %esp */
13746 -#define GET_THREAD_INFO_WITH_ESP(reg) \
13747 - andl $-THREAD_SIZE, reg
13748 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
13749 +#else
13750 +/* how to get the thread information struct from C */
13751 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
13752 +
13753 +static __always_inline struct thread_info *current_thread_info(void)
13754 +{
13755 + return this_cpu_read_stable(current_tinfo);
13756 +}
13757 +#endif
13758 +
13759 +#ifdef CONFIG_X86_32
13760 +
13761 +#define STACK_WARN (THREAD_SIZE/8)
13762 +/*
13763 + * macros/functions for gaining access to the thread information structure
13764 + *
13765 + * preempt_count needs to be 1 initially, until the scheduler is functional.
13766 + */
13767 +#ifndef __ASSEMBLY__
13768 +
13769 +/* how to get the current stack pointer from C */
13770 +register unsigned long current_stack_pointer asm("esp") __used;
13771
13772 #endif
13773
13774 #else /* X86_32 */
13775
13776 -#include <asm/percpu.h>
13777 -#define KERNEL_STACK_OFFSET (5*8)
13778 -
13779 /*
13780 * macros/functions for gaining access to the thread information structure
13781 * preempt_count needs to be 1 initially, until the scheduler is functional.
13782 @@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
13783 #ifndef __ASSEMBLY__
13784 DECLARE_PER_CPU(unsigned long, kernel_stack);
13785
13786 -static inline struct thread_info *current_thread_info(void)
13787 -{
13788 - struct thread_info *ti;
13789 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
13790 - KERNEL_STACK_OFFSET - THREAD_SIZE);
13791 - return ti;
13792 -}
13793 -
13794 -#else /* !__ASSEMBLY__ */
13795 -
13796 -/* how to get the thread information struct from ASM */
13797 -#define GET_THREAD_INFO(reg) \
13798 - movq PER_CPU_VAR(kernel_stack),reg ; \
13799 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
13800 -
13801 -/*
13802 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
13803 - * a certain register (to be used in assembler memory operands).
13804 - */
13805 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
13806 -
13807 +/* how to get the current stack pointer from C */
13808 +register unsigned long current_stack_pointer asm("rsp") __used;
13809 #endif
13810
13811 #endif /* !X86_32 */
13812 @@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
13813 extern void arch_task_cache_init(void);
13814 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
13815 extern void arch_release_task_struct(struct task_struct *tsk);
13816 +
13817 +#define __HAVE_THREAD_FUNCTIONS
13818 +#define task_thread_info(task) (&(task)->tinfo)
13819 +#define task_stack_page(task) ((task)->stack)
13820 +#define setup_thread_stack(p, org) do {} while (0)
13821 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
13822 +
13823 #endif
13824 #endif /* _ASM_X86_THREAD_INFO_H */
13825 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
13826 index 7ccf8d1..7cdca12 100644
13827 --- a/arch/x86/include/asm/uaccess.h
13828 +++ b/arch/x86/include/asm/uaccess.h
13829 @@ -7,6 +7,7 @@
13830 #include <linux/compiler.h>
13831 #include <linux/thread_info.h>
13832 #include <linux/string.h>
13833 +#include <linux/sched.h>
13834 #include <asm/asm.h>
13835 #include <asm/page.h>
13836 #include <asm/smap.h>
13837 @@ -14,6 +15,8 @@
13838 #define VERIFY_READ 0
13839 #define VERIFY_WRITE 1
13840
13841 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
13842 +
13843 /*
13844 * The fs value determines whether argument validity checking should be
13845 * performed or not. If get_fs() == USER_DS, checking is performed, with
13846 @@ -29,7 +32,12 @@
13847
13848 #define get_ds() (KERNEL_DS)
13849 #define get_fs() (current_thread_info()->addr_limit)
13850 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13851 +void __set_fs(mm_segment_t x);
13852 +void set_fs(mm_segment_t x);
13853 +#else
13854 #define set_fs(x) (current_thread_info()->addr_limit = (x))
13855 +#endif
13856
13857 #define segment_eq(a, b) ((a).seg == (b).seg)
13858
13859 @@ -77,8 +85,33 @@
13860 * checks that the pointer is in the user space range - after calling
13861 * this function, memory access functions may still return -EFAULT.
13862 */
13863 -#define access_ok(type, addr, size) \
13864 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13865 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13866 +#define access_ok(type, addr, size) \
13867 +({ \
13868 + long __size = size; \
13869 + unsigned long __addr = (unsigned long)addr; \
13870 + unsigned long __addr_ao = __addr & PAGE_MASK; \
13871 + unsigned long __end_ao = __addr + __size - 1; \
13872 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
13873 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
13874 + while(__addr_ao <= __end_ao) { \
13875 + char __c_ao; \
13876 + __addr_ao += PAGE_SIZE; \
13877 + if (__size > PAGE_SIZE) \
13878 + cond_resched(); \
13879 + if (__get_user(__c_ao, (char __user *)__addr)) \
13880 + break; \
13881 + if (type != VERIFY_WRITE) { \
13882 + __addr = __addr_ao; \
13883 + continue; \
13884 + } \
13885 + if (__put_user(__c_ao, (char __user *)__addr)) \
13886 + break; \
13887 + __addr = __addr_ao; \
13888 + } \
13889 + } \
13890 + __ret_ao; \
13891 +})
13892
13893 /*
13894 * The exception table consists of pairs of addresses relative to the
13895 @@ -189,13 +222,21 @@ extern int __get_user_bad(void);
13896 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
13897 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
13898
13899 -
13900 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13901 +#define __copyuser_seg "gs;"
13902 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
13903 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
13904 +#else
13905 +#define __copyuser_seg
13906 +#define __COPYUSER_SET_ES
13907 +#define __COPYUSER_RESTORE_ES
13908 +#endif
13909
13910 #ifdef CONFIG_X86_32
13911 #define __put_user_asm_u64(x, addr, err, errret) \
13912 asm volatile(ASM_STAC "\n" \
13913 - "1: movl %%eax,0(%2)\n" \
13914 - "2: movl %%edx,4(%2)\n" \
13915 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
13916 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
13917 "3: " ASM_CLAC "\n" \
13918 ".section .fixup,\"ax\"\n" \
13919 "4: movl %3,%0\n" \
13920 @@ -208,8 +249,8 @@ extern int __get_user_bad(void);
13921
13922 #define __put_user_asm_ex_u64(x, addr) \
13923 asm volatile(ASM_STAC "\n" \
13924 - "1: movl %%eax,0(%1)\n" \
13925 - "2: movl %%edx,4(%1)\n" \
13926 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
13927 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
13928 "3: " ASM_CLAC "\n" \
13929 _ASM_EXTABLE_EX(1b, 2b) \
13930 _ASM_EXTABLE_EX(2b, 3b) \
13931 @@ -261,7 +302,7 @@ extern void __put_user_8(void);
13932 __typeof__(*(ptr)) __pu_val; \
13933 __chk_user_ptr(ptr); \
13934 might_fault(); \
13935 - __pu_val = x; \
13936 + __pu_val = (x); \
13937 switch (sizeof(*(ptr))) { \
13938 case 1: \
13939 __put_user_x(1, __pu_val, ptr, __ret_pu); \
13940 @@ -383,7 +424,7 @@ do { \
13941
13942 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
13943 asm volatile(ASM_STAC "\n" \
13944 - "1: mov"itype" %2,%"rtype"1\n" \
13945 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
13946 "2: " ASM_CLAC "\n" \
13947 ".section .fixup,\"ax\"\n" \
13948 "3: mov %3,%0\n" \
13949 @@ -391,7 +432,7 @@ do { \
13950 " jmp 2b\n" \
13951 ".previous\n" \
13952 _ASM_EXTABLE(1b, 3b) \
13953 - : "=r" (err), ltype(x) \
13954 + : "=r" (err), ltype (x) \
13955 : "m" (__m(addr)), "i" (errret), "0" (err))
13956
13957 #define __get_user_size_ex(x, ptr, size) \
13958 @@ -416,7 +457,7 @@ do { \
13959 } while (0)
13960
13961 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
13962 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
13963 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
13964 "2:\n" \
13965 _ASM_EXTABLE_EX(1b, 2b) \
13966 : ltype(x) : "m" (__m(addr)))
13967 @@ -433,13 +474,24 @@ do { \
13968 int __gu_err; \
13969 unsigned long __gu_val; \
13970 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
13971 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
13972 + (x) = (__typeof__(*(ptr)))__gu_val; \
13973 __gu_err; \
13974 })
13975
13976 /* FIXME: this hack is definitely wrong -AK */
13977 struct __large_struct { unsigned long buf[100]; };
13978 -#define __m(x) (*(struct __large_struct __user *)(x))
13979 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13980 +#define ____m(x) \
13981 +({ \
13982 + unsigned long ____x = (unsigned long)(x); \
13983 + if (____x < PAX_USER_SHADOW_BASE) \
13984 + ____x += PAX_USER_SHADOW_BASE; \
13985 + (void __user *)____x; \
13986 +})
13987 +#else
13988 +#define ____m(x) (x)
13989 +#endif
13990 +#define __m(x) (*(struct __large_struct __user *)____m(x))
13991
13992 /*
13993 * Tell gcc we read from memory instead of writing: this is because
13994 @@ -448,7 +500,7 @@ struct __large_struct { unsigned long buf[100]; };
13995 */
13996 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
13997 asm volatile(ASM_STAC "\n" \
13998 - "1: mov"itype" %"rtype"1,%2\n" \
13999 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
14000 "2: " ASM_CLAC "\n" \
14001 ".section .fixup,\"ax\"\n" \
14002 "3: mov %3,%0\n" \
14003 @@ -456,10 +508,10 @@ struct __large_struct { unsigned long buf[100]; };
14004 ".previous\n" \
14005 _ASM_EXTABLE(1b, 3b) \
14006 : "=r"(err) \
14007 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
14008 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
14009
14010 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
14011 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
14012 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
14013 "2:\n" \
14014 _ASM_EXTABLE_EX(1b, 2b) \
14015 : : ltype(x), "m" (__m(addr)))
14016 @@ -498,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
14017 * On error, the variable @x is set to zero.
14018 */
14019
14020 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14021 +#define __get_user(x, ptr) get_user((x), (ptr))
14022 +#else
14023 #define __get_user(x, ptr) \
14024 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
14025 +#endif
14026
14027 /**
14028 * __put_user: - Write a simple value into user space, with less checking.
14029 @@ -521,8 +577,12 @@ struct __large_struct { unsigned long buf[100]; };
14030 * Returns zero on success, or -EFAULT on error.
14031 */
14032
14033 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14034 +#define __put_user(x, ptr) put_user((x), (ptr))
14035 +#else
14036 #define __put_user(x, ptr) \
14037 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
14038 +#endif
14039
14040 #define __get_user_unaligned __get_user
14041 #define __put_user_unaligned __put_user
14042 @@ -540,7 +600,7 @@ struct __large_struct { unsigned long buf[100]; };
14043 #define get_user_ex(x, ptr) do { \
14044 unsigned long __gue_val; \
14045 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
14046 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
14047 + (x) = (__typeof__(*(ptr)))__gue_val; \
14048 } while (0)
14049
14050 #ifdef CONFIG_X86_WP_WORKS_OK
14051 @@ -574,8 +634,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
14052 extern __must_check long strlen_user(const char __user *str);
14053 extern __must_check long strnlen_user(const char __user *str, long n);
14054
14055 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
14056 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
14057 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
14058 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
14059
14060 /*
14061 * movsl can be slow when source and dest are not both 8-byte aligned
14062 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
14063 index 7f760a9..00f93c0 100644
14064 --- a/arch/x86/include/asm/uaccess_32.h
14065 +++ b/arch/x86/include/asm/uaccess_32.h
14066 @@ -11,15 +11,15 @@
14067 #include <asm/page.h>
14068
14069 unsigned long __must_check __copy_to_user_ll
14070 - (void __user *to, const void *from, unsigned long n);
14071 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
14072 unsigned long __must_check __copy_from_user_ll
14073 - (void *to, const void __user *from, unsigned long n);
14074 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14075 unsigned long __must_check __copy_from_user_ll_nozero
14076 - (void *to, const void __user *from, unsigned long n);
14077 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14078 unsigned long __must_check __copy_from_user_ll_nocache
14079 - (void *to, const void __user *from, unsigned long n);
14080 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14081 unsigned long __must_check __copy_from_user_ll_nocache_nozero
14082 - (void *to, const void __user *from, unsigned long n);
14083 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14084
14085 /**
14086 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
14087 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
14088 static __always_inline unsigned long __must_check
14089 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
14090 {
14091 + if ((long)n < 0)
14092 + return n;
14093 +
14094 if (__builtin_constant_p(n)) {
14095 unsigned long ret;
14096
14097 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
14098 return ret;
14099 }
14100 }
14101 + if (!__builtin_constant_p(n))
14102 + check_object_size(from, n, true);
14103 return __copy_to_user_ll(to, from, n);
14104 }
14105
14106 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
14107 __copy_to_user(void __user *to, const void *from, unsigned long n)
14108 {
14109 might_fault();
14110 +
14111 return __copy_to_user_inatomic(to, from, n);
14112 }
14113
14114 static __always_inline unsigned long
14115 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
14116 {
14117 + if ((long)n < 0)
14118 + return n;
14119 +
14120 /* Avoid zeroing the tail if the copy fails..
14121 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
14122 * but as the zeroing behaviour is only significant when n is not
14123 @@ -137,6 +146,10 @@ static __always_inline unsigned long
14124 __copy_from_user(void *to, const void __user *from, unsigned long n)
14125 {
14126 might_fault();
14127 +
14128 + if ((long)n < 0)
14129 + return n;
14130 +
14131 if (__builtin_constant_p(n)) {
14132 unsigned long ret;
14133
14134 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
14135 return ret;
14136 }
14137 }
14138 + if (!__builtin_constant_p(n))
14139 + check_object_size(to, n, false);
14140 return __copy_from_user_ll(to, from, n);
14141 }
14142
14143 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
14144 const void __user *from, unsigned long n)
14145 {
14146 might_fault();
14147 +
14148 + if ((long)n < 0)
14149 + return n;
14150 +
14151 if (__builtin_constant_p(n)) {
14152 unsigned long ret;
14153
14154 @@ -181,15 +200,19 @@ static __always_inline unsigned long
14155 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
14156 unsigned long n)
14157 {
14158 - return __copy_from_user_ll_nocache_nozero(to, from, n);
14159 + if ((long)n < 0)
14160 + return n;
14161 +
14162 + return __copy_from_user_ll_nocache_nozero(to, from, n);
14163 }
14164
14165 -unsigned long __must_check copy_to_user(void __user *to,
14166 - const void *from, unsigned long n);
14167 -unsigned long __must_check _copy_from_user(void *to,
14168 - const void __user *from,
14169 - unsigned long n);
14170 -
14171 +extern void copy_to_user_overflow(void)
14172 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14173 + __compiletime_error("copy_to_user() buffer size is not provably correct")
14174 +#else
14175 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
14176 +#endif
14177 +;
14178
14179 extern void copy_from_user_overflow(void)
14180 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14181 @@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
14182 #endif
14183 ;
14184
14185 -static inline unsigned long __must_check copy_from_user(void *to,
14186 - const void __user *from,
14187 - unsigned long n)
14188 +/**
14189 + * copy_to_user: - Copy a block of data into user space.
14190 + * @to: Destination address, in user space.
14191 + * @from: Source address, in kernel space.
14192 + * @n: Number of bytes to copy.
14193 + *
14194 + * Context: User context only. This function may sleep.
14195 + *
14196 + * Copy data from kernel space to user space.
14197 + *
14198 + * Returns number of bytes that could not be copied.
14199 + * On success, this will be zero.
14200 + */
14201 +static inline unsigned long __must_check
14202 +copy_to_user(void __user *to, const void *from, unsigned long n)
14203 {
14204 - int sz = __compiletime_object_size(to);
14205 + size_t sz = __compiletime_object_size(from);
14206
14207 - if (likely(sz == -1 || sz >= n))
14208 - n = _copy_from_user(to, from, n);
14209 - else
14210 + if (unlikely(sz != (size_t)-1 && sz < n))
14211 + copy_to_user_overflow();
14212 + else if (access_ok(VERIFY_WRITE, to, n))
14213 + n = __copy_to_user(to, from, n);
14214 + return n;
14215 +}
14216 +
14217 +/**
14218 + * copy_from_user: - Copy a block of data from user space.
14219 + * @to: Destination address, in kernel space.
14220 + * @from: Source address, in user space.
14221 + * @n: Number of bytes to copy.
14222 + *
14223 + * Context: User context only. This function may sleep.
14224 + *
14225 + * Copy data from user space to kernel space.
14226 + *
14227 + * Returns number of bytes that could not be copied.
14228 + * On success, this will be zero.
14229 + *
14230 + * If some data could not be copied, this function will pad the copied
14231 + * data to the requested size using zero bytes.
14232 + */
14233 +static inline unsigned long __must_check
14234 +copy_from_user(void *to, const void __user *from, unsigned long n)
14235 +{
14236 + size_t sz = __compiletime_object_size(to);
14237 +
14238 + if (unlikely(sz != (size_t)-1 && sz < n))
14239 copy_from_user_overflow();
14240 -
14241 + else if (access_ok(VERIFY_READ, from, n))
14242 + n = __copy_from_user(to, from, n);
14243 + else if ((long)n > 0) {
14244 + if (!__builtin_constant_p(n))
14245 + check_object_size(to, n, false);
14246 + memset(to, 0, n);
14247 + }
14248 return n;
14249 }
14250
14251 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
14252 index 142810c..4389299 100644
14253 --- a/arch/x86/include/asm/uaccess_64.h
14254 +++ b/arch/x86/include/asm/uaccess_64.h
14255 @@ -10,6 +10,9 @@
14256 #include <asm/alternative.h>
14257 #include <asm/cpufeature.h>
14258 #include <asm/page.h>
14259 +#include <asm/pgtable.h>
14260 +
14261 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
14262
14263 /*
14264 * Copy To/From Userspace
14265 @@ -17,13 +20,13 @@
14266
14267 /* Handles exceptions in both to and from, but doesn't do access_ok */
14268 __must_check unsigned long
14269 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
14270 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
14271 __must_check unsigned long
14272 -copy_user_generic_string(void *to, const void *from, unsigned len);
14273 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
14274 __must_check unsigned long
14275 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
14276 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
14277
14278 -static __always_inline __must_check unsigned long
14279 +static __always_inline __must_check __size_overflow(3) unsigned long
14280 copy_user_generic(void *to, const void *from, unsigned len)
14281 {
14282 unsigned ret;
14283 @@ -41,142 +44,205 @@ copy_user_generic(void *to, const void *from, unsigned len)
14284 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
14285 "=d" (len)),
14286 "1" (to), "2" (from), "3" (len)
14287 - : "memory", "rcx", "r8", "r9", "r10", "r11");
14288 + : "memory", "rcx", "r8", "r9", "r11");
14289 return ret;
14290 }
14291
14292 +static __always_inline __must_check unsigned long
14293 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
14294 +static __always_inline __must_check unsigned long
14295 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
14296 __must_check unsigned long
14297 -_copy_to_user(void __user *to, const void *from, unsigned len);
14298 -__must_check unsigned long
14299 -_copy_from_user(void *to, const void __user *from, unsigned len);
14300 -__must_check unsigned long
14301 -copy_in_user(void __user *to, const void __user *from, unsigned len);
14302 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
14303 +
14304 +extern void copy_to_user_overflow(void)
14305 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14306 + __compiletime_error("copy_to_user() buffer size is not provably correct")
14307 +#else
14308 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
14309 +#endif
14310 +;
14311 +
14312 +extern void copy_from_user_overflow(void)
14313 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14314 + __compiletime_error("copy_from_user() buffer size is not provably correct")
14315 +#else
14316 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
14317 +#endif
14318 +;
14319
14320 static inline unsigned long __must_check copy_from_user(void *to,
14321 const void __user *from,
14322 unsigned long n)
14323 {
14324 - int sz = __compiletime_object_size(to);
14325 -
14326 might_fault();
14327 - if (likely(sz == -1 || sz >= n))
14328 - n = _copy_from_user(to, from, n);
14329 -#ifdef CONFIG_DEBUG_VM
14330 - else
14331 - WARN(1, "Buffer overflow detected!\n");
14332 -#endif
14333 +
14334 + if (access_ok(VERIFY_READ, from, n))
14335 + n = __copy_from_user(to, from, n);
14336 + else if (n < INT_MAX) {
14337 + if (!__builtin_constant_p(n))
14338 + check_object_size(to, n, false);
14339 + memset(to, 0, n);
14340 + }
14341 return n;
14342 }
14343
14344 static __always_inline __must_check
14345 -int copy_to_user(void __user *dst, const void *src, unsigned size)
14346 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
14347 {
14348 might_fault();
14349
14350 - return _copy_to_user(dst, src, size);
14351 + if (access_ok(VERIFY_WRITE, dst, size))
14352 + size = __copy_to_user(dst, src, size);
14353 + return size;
14354 }
14355
14356 static __always_inline __must_check
14357 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
14358 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
14359 {
14360 - int ret = 0;
14361 + size_t sz = __compiletime_object_size(dst);
14362 + unsigned ret = 0;
14363
14364 might_fault();
14365 - if (!__builtin_constant_p(size))
14366 - return copy_user_generic(dst, (__force void *)src, size);
14367 +
14368 + if (size > INT_MAX)
14369 + return size;
14370 +
14371 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14372 + if (!__access_ok(VERIFY_READ, src, size))
14373 + return size;
14374 +#endif
14375 +
14376 + if (unlikely(sz != (size_t)-1 && sz < size)) {
14377 + copy_from_user_overflow();
14378 + return size;
14379 + }
14380 +
14381 + if (!__builtin_constant_p(size)) {
14382 + check_object_size(dst, size, false);
14383 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14384 + }
14385 switch (size) {
14386 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
14387 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
14388 ret, "b", "b", "=q", 1);
14389 return ret;
14390 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
14391 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
14392 ret, "w", "w", "=r", 2);
14393 return ret;
14394 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
14395 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
14396 ret, "l", "k", "=r", 4);
14397 return ret;
14398 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
14399 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14400 ret, "q", "", "=r", 8);
14401 return ret;
14402 case 10:
14403 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14404 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14405 ret, "q", "", "=r", 10);
14406 if (unlikely(ret))
14407 return ret;
14408 __get_user_asm(*(u16 *)(8 + (char *)dst),
14409 - (u16 __user *)(8 + (char __user *)src),
14410 + (const u16 __user *)(8 + (const char __user *)src),
14411 ret, "w", "w", "=r", 2);
14412 return ret;
14413 case 16:
14414 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14415 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14416 ret, "q", "", "=r", 16);
14417 if (unlikely(ret))
14418 return ret;
14419 __get_user_asm(*(u64 *)(8 + (char *)dst),
14420 - (u64 __user *)(8 + (char __user *)src),
14421 + (const u64 __user *)(8 + (const char __user *)src),
14422 ret, "q", "", "=r", 8);
14423 return ret;
14424 default:
14425 - return copy_user_generic(dst, (__force void *)src, size);
14426 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14427 }
14428 }
14429
14430 static __always_inline __must_check
14431 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
14432 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
14433 {
14434 - int ret = 0;
14435 + size_t sz = __compiletime_object_size(src);
14436 + unsigned ret = 0;
14437
14438 might_fault();
14439 - if (!__builtin_constant_p(size))
14440 - return copy_user_generic((__force void *)dst, src, size);
14441 +
14442 + if (size > INT_MAX)
14443 + return size;
14444 +
14445 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14446 + if (!__access_ok(VERIFY_WRITE, dst, size))
14447 + return size;
14448 +#endif
14449 +
14450 + if (unlikely(sz != (size_t)-1 && sz < size)) {
14451 + copy_to_user_overflow();
14452 + return size;
14453 + }
14454 +
14455 + if (!__builtin_constant_p(size)) {
14456 + check_object_size(src, size, true);
14457 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14458 + }
14459 switch (size) {
14460 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
14461 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
14462 ret, "b", "b", "iq", 1);
14463 return ret;
14464 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
14465 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
14466 ret, "w", "w", "ir", 2);
14467 return ret;
14468 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
14469 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
14470 ret, "l", "k", "ir", 4);
14471 return ret;
14472 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
14473 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14474 ret, "q", "", "er", 8);
14475 return ret;
14476 case 10:
14477 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14478 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14479 ret, "q", "", "er", 10);
14480 if (unlikely(ret))
14481 return ret;
14482 asm("":::"memory");
14483 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
14484 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
14485 ret, "w", "w", "ir", 2);
14486 return ret;
14487 case 16:
14488 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14489 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14490 ret, "q", "", "er", 16);
14491 if (unlikely(ret))
14492 return ret;
14493 asm("":::"memory");
14494 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
14495 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
14496 ret, "q", "", "er", 8);
14497 return ret;
14498 default:
14499 - return copy_user_generic((__force void *)dst, src, size);
14500 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14501 }
14502 }
14503
14504 static __always_inline __must_check
14505 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14506 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
14507 {
14508 - int ret = 0;
14509 + unsigned ret = 0;
14510
14511 might_fault();
14512 +
14513 + if (size > INT_MAX)
14514 + return size;
14515 +
14516 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14517 + if (!__access_ok(VERIFY_READ, src, size))
14518 + return size;
14519 + if (!__access_ok(VERIFY_WRITE, dst, size))
14520 + return size;
14521 +#endif
14522 +
14523 if (!__builtin_constant_p(size))
14524 - return copy_user_generic((__force void *)dst,
14525 - (__force void *)src, size);
14526 + return copy_user_generic((__force_kernel void *)____m(dst),
14527 + (__force_kernel const void *)____m(src), size);
14528 switch (size) {
14529 case 1: {
14530 u8 tmp;
14531 - __get_user_asm(tmp, (u8 __user *)src,
14532 + __get_user_asm(tmp, (const u8 __user *)src,
14533 ret, "b", "b", "=q", 1);
14534 if (likely(!ret))
14535 __put_user_asm(tmp, (u8 __user *)dst,
14536 @@ -185,7 +251,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14537 }
14538 case 2: {
14539 u16 tmp;
14540 - __get_user_asm(tmp, (u16 __user *)src,
14541 + __get_user_asm(tmp, (const u16 __user *)src,
14542 ret, "w", "w", "=r", 2);
14543 if (likely(!ret))
14544 __put_user_asm(tmp, (u16 __user *)dst,
14545 @@ -195,7 +261,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14546
14547 case 4: {
14548 u32 tmp;
14549 - __get_user_asm(tmp, (u32 __user *)src,
14550 + __get_user_asm(tmp, (const u32 __user *)src,
14551 ret, "l", "k", "=r", 4);
14552 if (likely(!ret))
14553 __put_user_asm(tmp, (u32 __user *)dst,
14554 @@ -204,7 +270,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14555 }
14556 case 8: {
14557 u64 tmp;
14558 - __get_user_asm(tmp, (u64 __user *)src,
14559 + __get_user_asm(tmp, (const u64 __user *)src,
14560 ret, "q", "", "=r", 8);
14561 if (likely(!ret))
14562 __put_user_asm(tmp, (u64 __user *)dst,
14563 @@ -212,41 +278,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14564 return ret;
14565 }
14566 default:
14567 - return copy_user_generic((__force void *)dst,
14568 - (__force void *)src, size);
14569 + return copy_user_generic((__force_kernel void *)____m(dst),
14570 + (__force_kernel const void *)____m(src), size);
14571 }
14572 }
14573
14574 static __must_check __always_inline int
14575 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
14576 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
14577 {
14578 - return copy_user_generic(dst, (__force const void *)src, size);
14579 + if (size > INT_MAX)
14580 + return size;
14581 +
14582 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14583 + if (!__access_ok(VERIFY_READ, src, size))
14584 + return size;
14585 +#endif
14586 +
14587 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14588 }
14589
14590 -static __must_check __always_inline int
14591 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
14592 +static __must_check __always_inline unsigned long
14593 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
14594 {
14595 - return copy_user_generic((__force void *)dst, src, size);
14596 + if (size > INT_MAX)
14597 + return size;
14598 +
14599 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14600 + if (!__access_ok(VERIFY_WRITE, dst, size))
14601 + return size;
14602 +#endif
14603 +
14604 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14605 }
14606
14607 -extern long __copy_user_nocache(void *dst, const void __user *src,
14608 - unsigned size, int zerorest);
14609 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
14610 + unsigned long size, int zerorest) __size_overflow(3);
14611
14612 -static inline int
14613 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
14614 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
14615 {
14616 might_sleep();
14617 +
14618 + if (size > INT_MAX)
14619 + return size;
14620 +
14621 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14622 + if (!__access_ok(VERIFY_READ, src, size))
14623 + return size;
14624 +#endif
14625 +
14626 return __copy_user_nocache(dst, src, size, 1);
14627 }
14628
14629 -static inline int
14630 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14631 - unsigned size)
14632 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14633 + unsigned long size)
14634 {
14635 + if (size > INT_MAX)
14636 + return size;
14637 +
14638 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14639 + if (!__access_ok(VERIFY_READ, src, size))
14640 + return size;
14641 +#endif
14642 +
14643 return __copy_user_nocache(dst, src, size, 0);
14644 }
14645
14646 -unsigned long
14647 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
14648 +extern unsigned long
14649 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
14650
14651 #endif /* _ASM_X86_UACCESS_64_H */
14652 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
14653 index 5b238981..77fdd78 100644
14654 --- a/arch/x86/include/asm/word-at-a-time.h
14655 +++ b/arch/x86/include/asm/word-at-a-time.h
14656 @@ -11,7 +11,7 @@
14657 * and shift, for example.
14658 */
14659 struct word_at_a_time {
14660 - const unsigned long one_bits, high_bits;
14661 + unsigned long one_bits, high_bits;
14662 };
14663
14664 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
14665 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
14666 index 0415cda..b43d877 100644
14667 --- a/arch/x86/include/asm/xsave.h
14668 +++ b/arch/x86/include/asm/xsave.h
14669 @@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14670 return -EFAULT;
14671
14672 __asm__ __volatile__(ASM_STAC "\n"
14673 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
14674 + "1:"
14675 + __copyuser_seg
14676 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
14677 "2: " ASM_CLAC "\n"
14678 ".section .fixup,\"ax\"\n"
14679 "3: movl $-1,%[err]\n"
14680 @@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14681 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
14682 {
14683 int err;
14684 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
14685 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
14686 u32 lmask = mask;
14687 u32 hmask = mask >> 32;
14688
14689 __asm__ __volatile__(ASM_STAC "\n"
14690 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14691 + "1:"
14692 + __copyuser_seg
14693 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14694 "2: " ASM_CLAC "\n"
14695 ".section .fixup,\"ax\"\n"
14696 "3: movl $-1,%[err]\n"
14697 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
14698 index 91ce48f..a48ea05 100644
14699 --- a/arch/x86/kernel/Makefile
14700 +++ b/arch/x86/kernel/Makefile
14701 @@ -23,7 +23,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
14702 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
14703 obj-$(CONFIG_IRQ_WORK) += irq_work.o
14704 obj-y += probe_roms.o
14705 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
14706 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
14707 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
14708 obj-y += syscall_$(BITS).o
14709 obj-$(CONFIG_X86_64) += vsyscall_64.o
14710 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
14711 index e651f7a..c995dc4 100644
14712 --- a/arch/x86/kernel/acpi/boot.c
14713 +++ b/arch/x86/kernel/acpi/boot.c
14714 @@ -1576,7 +1576,7 @@ int __init acpi_boot_init(void)
14715 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
14716
14717 if (!acpi_noirq)
14718 - x86_init.pci.init = pci_acpi_init;
14719 + *(void **)&x86_init.pci.init = pci_acpi_init;
14720
14721 return 0;
14722 }
14723 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
14724 index 11676cf..a8cf3ec 100644
14725 --- a/arch/x86/kernel/acpi/sleep.c
14726 +++ b/arch/x86/kernel/acpi/sleep.c
14727 @@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
14728 #else /* CONFIG_64BIT */
14729 #ifdef CONFIG_SMP
14730 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
14731 +
14732 + pax_open_kernel();
14733 early_gdt_descr.address =
14734 (unsigned long)get_cpu_gdt_table(smp_processor_id());
14735 + pax_close_kernel();
14736 +
14737 initial_gs = per_cpu_offset(smp_processor_id());
14738 #endif
14739 initial_code = (unsigned long)wakeup_long64;
14740 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
14741 index 13ab720..95d5442 100644
14742 --- a/arch/x86/kernel/acpi/wakeup_32.S
14743 +++ b/arch/x86/kernel/acpi/wakeup_32.S
14744 @@ -30,13 +30,11 @@ wakeup_pmode_return:
14745 # and restore the stack ... but you need gdt for this to work
14746 movl saved_context_esp, %esp
14747
14748 - movl %cs:saved_magic, %eax
14749 - cmpl $0x12345678, %eax
14750 + cmpl $0x12345678, saved_magic
14751 jne bogus_magic
14752
14753 # jump to place where we left off
14754 - movl saved_eip, %eax
14755 - jmp *%eax
14756 + jmp *(saved_eip)
14757
14758 bogus_magic:
14759 jmp bogus_magic
14760 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
14761 index ef5ccca..bd83949 100644
14762 --- a/arch/x86/kernel/alternative.c
14763 +++ b/arch/x86/kernel/alternative.c
14764 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
14765 */
14766 for (a = start; a < end; a++) {
14767 instr = (u8 *)&a->instr_offset + a->instr_offset;
14768 +
14769 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14770 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14771 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
14772 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14773 +#endif
14774 +
14775 replacement = (u8 *)&a->repl_offset + a->repl_offset;
14776 BUG_ON(a->replacementlen > a->instrlen);
14777 BUG_ON(a->instrlen > sizeof(insnbuf));
14778 @@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
14779 for (poff = start; poff < end; poff++) {
14780 u8 *ptr = (u8 *)poff + *poff;
14781
14782 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14783 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14784 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14785 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14786 +#endif
14787 +
14788 if (!*poff || ptr < text || ptr >= text_end)
14789 continue;
14790 /* turn DS segment override prefix into lock prefix */
14791 - if (*ptr == 0x3e)
14792 + if (*ktla_ktva(ptr) == 0x3e)
14793 text_poke(ptr, ((unsigned char []){0xf0}), 1);
14794 }
14795 mutex_unlock(&text_mutex);
14796 @@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
14797 for (poff = start; poff < end; poff++) {
14798 u8 *ptr = (u8 *)poff + *poff;
14799
14800 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14801 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14802 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14803 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14804 +#endif
14805 +
14806 if (!*poff || ptr < text || ptr >= text_end)
14807 continue;
14808 /* turn lock prefix into DS segment override prefix */
14809 - if (*ptr == 0xf0)
14810 + if (*ktla_ktva(ptr) == 0xf0)
14811 text_poke(ptr, ((unsigned char []){0x3E}), 1);
14812 }
14813 mutex_unlock(&text_mutex);
14814 @@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
14815
14816 BUG_ON(p->len > MAX_PATCH_LEN);
14817 /* prep the buffer with the original instructions */
14818 - memcpy(insnbuf, p->instr, p->len);
14819 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
14820 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
14821 (unsigned long)p->instr, p->len);
14822
14823 @@ -515,7 +534,7 @@ void __init alternative_instructions(void)
14824 if (!uniproc_patched || num_possible_cpus() == 1)
14825 free_init_pages("SMP alternatives",
14826 (unsigned long)__smp_locks,
14827 - (unsigned long)__smp_locks_end);
14828 + PAGE_ALIGN((unsigned long)__smp_locks_end));
14829 #endif
14830
14831 apply_paravirt(__parainstructions, __parainstructions_end);
14832 @@ -535,13 +554,17 @@ void __init alternative_instructions(void)
14833 * instructions. And on the local CPU you need to be protected again NMI or MCE
14834 * handlers seeing an inconsistent instruction while you patch.
14835 */
14836 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
14837 +void *__kprobes text_poke_early(void *addr, const void *opcode,
14838 size_t len)
14839 {
14840 unsigned long flags;
14841 local_irq_save(flags);
14842 - memcpy(addr, opcode, len);
14843 +
14844 + pax_open_kernel();
14845 + memcpy(ktla_ktva(addr), opcode, len);
14846 sync_core();
14847 + pax_close_kernel();
14848 +
14849 local_irq_restore(flags);
14850 /* Could also do a CLFLUSH here to speed up CPU recovery; but
14851 that causes hangs on some VIA CPUs. */
14852 @@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
14853 */
14854 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
14855 {
14856 - unsigned long flags;
14857 - char *vaddr;
14858 + unsigned char *vaddr = ktla_ktva(addr);
14859 struct page *pages[2];
14860 - int i;
14861 + size_t i;
14862
14863 if (!core_kernel_text((unsigned long)addr)) {
14864 - pages[0] = vmalloc_to_page(addr);
14865 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
14866 + pages[0] = vmalloc_to_page(vaddr);
14867 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
14868 } else {
14869 - pages[0] = virt_to_page(addr);
14870 + pages[0] = virt_to_page(vaddr);
14871 WARN_ON(!PageReserved(pages[0]));
14872 - pages[1] = virt_to_page(addr + PAGE_SIZE);
14873 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
14874 }
14875 BUG_ON(!pages[0]);
14876 - local_irq_save(flags);
14877 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
14878 - if (pages[1])
14879 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
14880 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
14881 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
14882 - clear_fixmap(FIX_TEXT_POKE0);
14883 - if (pages[1])
14884 - clear_fixmap(FIX_TEXT_POKE1);
14885 - local_flush_tlb();
14886 - sync_core();
14887 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
14888 - that causes hangs on some VIA CPUs. */
14889 + text_poke_early(addr, opcode, len);
14890 for (i = 0; i < len; i++)
14891 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
14892 - local_irq_restore(flags);
14893 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
14894 return addr;
14895 }
14896
14897 diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
14898 index e663112..21938a3 100644
14899 --- a/arch/x86/kernel/amd_gart_64.c
14900 +++ b/arch/x86/kernel/amd_gart_64.c
14901 @@ -851,7 +851,7 @@ int __init gart_iommu_init(void)
14902
14903 flush_gart();
14904 dma_ops = &gart_dma_ops;
14905 - x86_platform.iommu_shutdown = gart_iommu_shutdown;
14906 + *(void **)&x86_platform.iommu_shutdown = gart_iommu_shutdown;
14907 swiotlb = 0;
14908
14909 return 0;
14910 diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
14911 index d5fd66f..6119b16 100644
14912 --- a/arch/x86/kernel/aperture_64.c
14913 +++ b/arch/x86/kernel/aperture_64.c
14914 @@ -390,7 +390,7 @@ int __init gart_iommu_hole_init(void)
14915
14916 iommu_detected = 1;
14917 gart_iommu_aperture = 1;
14918 - x86_init.iommu.iommu_init = gart_iommu_init;
14919 + *(void **)&x86_init.iommu.iommu_init = gart_iommu_init;
14920
14921 ctl = read_pci_config(bus, slot, 3,
14922 AMD64_GARTAPERTURECTL);
14923 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
14924 index b17416e..be6e5dc 100644
14925 --- a/arch/x86/kernel/apic/apic.c
14926 +++ b/arch/x86/kernel/apic/apic.c
14927 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
14928 /*
14929 * Debug level, exported for io_apic.c
14930 */
14931 -unsigned int apic_verbosity;
14932 +int apic_verbosity;
14933
14934 int pic_mode;
14935
14936 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
14937 apic_write(APIC_ESR, 0);
14938 v1 = apic_read(APIC_ESR);
14939 ack_APIC_irq();
14940 - atomic_inc(&irq_err_count);
14941 + atomic_inc_unchecked(&irq_err_count);
14942
14943 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
14944 smp_processor_id(), v0 , v1);
14945 @@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
14946 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
14947 /* Should happen once for each apic */
14948 WARN_ON((*drv)->eoi_write == eoi_write);
14949 - (*drv)->eoi_write = eoi_write;
14950 + pax_open_kernel();
14951 + *(void **)&(*drv)->eoi_write = eoi_write;
14952 + pax_close_kernel();
14953 }
14954 }
14955
14956 diff --git a/arch/x86/kernel/apic/apic_numachip.c b/arch/x86/kernel/apic/apic_numachip.c
14957 index a65829a..6ddc249 100644
14958 --- a/arch/x86/kernel/apic/apic_numachip.c
14959 +++ b/arch/x86/kernel/apic/apic_numachip.c
14960 @@ -178,7 +178,7 @@ static int __init numachip_system_init(void)
14961 if (!numachip_system)
14962 return 0;
14963
14964 - x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
14965 + *(void **)&x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
14966
14967 map_csrs();
14968
14969 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
14970 index 1817fa9..7bff097 100644
14971 --- a/arch/x86/kernel/apic/io_apic.c
14972 +++ b/arch/x86/kernel/apic/io_apic.c
14973 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
14974 }
14975 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
14976
14977 -void lock_vector_lock(void)
14978 +void lock_vector_lock(void) __acquires(vector_lock)
14979 {
14980 /* Used to the online set of cpus does not change
14981 * during assign_irq_vector.
14982 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
14983 raw_spin_lock(&vector_lock);
14984 }
14985
14986 -void unlock_vector_lock(void)
14987 +void unlock_vector_lock(void) __releases(vector_lock)
14988 {
14989 raw_spin_unlock(&vector_lock);
14990 }
14991 @@ -2411,7 +2411,7 @@ static void ack_apic_edge(struct irq_data *data)
14992 ack_APIC_irq();
14993 }
14994
14995 -atomic_t irq_mis_count;
14996 +atomic_unchecked_t irq_mis_count;
14997
14998 #ifdef CONFIG_GENERIC_PENDING_IRQ
14999 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
15000 @@ -2552,7 +2552,7 @@ static void ack_apic_level(struct irq_data *data)
15001 * at the cpu.
15002 */
15003 if (!(v & (1 << (i & 0x1f)))) {
15004 - atomic_inc(&irq_mis_count);
15005 + atomic_inc_unchecked(&irq_mis_count);
15006
15007 eoi_ioapic_irq(irq, cfg);
15008 }
15009 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
15010 index d661ee9..512c0a1 100644
15011 --- a/arch/x86/kernel/apic/numaq_32.c
15012 +++ b/arch/x86/kernel/apic/numaq_32.c
15013 @@ -257,14 +257,14 @@ static __init void early_check_numaq(void)
15014 early_get_smp_config();
15015
15016 if (found_numaq) {
15017 - x86_init.mpparse.mpc_record = numaq_mpc_record;
15018 - x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
15019 - x86_init.mpparse.mpc_apic_id = mpc_apic_id;
15020 - x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
15021 - x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
15022 - x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
15023 - x86_init.timers.tsc_pre_init = numaq_tsc_init;
15024 - x86_init.pci.init = pci_numaq_init;
15025 + *(void **)&x86_init.mpparse.mpc_record = numaq_mpc_record;
15026 + *(void **)&x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
15027 + *(void **)&x86_init.mpparse.mpc_apic_id = mpc_apic_id;
15028 + *(void **)&x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
15029 + *(void **)&x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
15030 + *(void **)&x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
15031 + *(void **)&x86_init.timers.tsc_pre_init = numaq_tsc_init;
15032 + *(void **)&x86_init.pci.init = pci_numaq_init;
15033 }
15034 }
15035
15036 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
15037 index 8cfade9..8ea7b51 100644
15038 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
15039 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
15040 @@ -139,8 +139,8 @@ static int __init uv_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
15041 is_uv1 ? UV1_HUB_REVISION_BASE : UV2_HUB_REVISION_BASE;
15042 pnodeid = early_get_pnodeid();
15043 early_get_apic_pnode_shift();
15044 - x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
15045 - x86_platform.nmi_init = uv_nmi_init;
15046 + *(void **)&x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
15047 + *(void **)&x86_platform.nmi_init = uv_nmi_init;
15048 if (!strcmp(oem_table_id, "UVL"))
15049 uv_system_type = UV_LEGACY_APIC;
15050 else if (!strcmp(oem_table_id, "UVX"))
15051 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
15052 index d65464e..1035d31 100644
15053 --- a/arch/x86/kernel/apm_32.c
15054 +++ b/arch/x86/kernel/apm_32.c
15055 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
15056 * This is for buggy BIOS's that refer to (real mode) segment 0x40
15057 * even though they are called in protected mode.
15058 */
15059 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
15060 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
15061 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
15062
15063 static const char driver_version[] = "1.16ac"; /* no spaces */
15064 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
15065 BUG_ON(cpu != 0);
15066 gdt = get_cpu_gdt_table(cpu);
15067 save_desc_40 = gdt[0x40 / 8];
15068 +
15069 + pax_open_kernel();
15070 gdt[0x40 / 8] = bad_bios_desc;
15071 + pax_close_kernel();
15072
15073 apm_irq_save(flags);
15074 APM_DO_SAVE_SEGS;
15075 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
15076 &call->esi);
15077 APM_DO_RESTORE_SEGS;
15078 apm_irq_restore(flags);
15079 +
15080 + pax_open_kernel();
15081 gdt[0x40 / 8] = save_desc_40;
15082 + pax_close_kernel();
15083 +
15084 put_cpu();
15085
15086 return call->eax & 0xff;
15087 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
15088 BUG_ON(cpu != 0);
15089 gdt = get_cpu_gdt_table(cpu);
15090 save_desc_40 = gdt[0x40 / 8];
15091 +
15092 + pax_open_kernel();
15093 gdt[0x40 / 8] = bad_bios_desc;
15094 + pax_close_kernel();
15095
15096 apm_irq_save(flags);
15097 APM_DO_SAVE_SEGS;
15098 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
15099 &call->eax);
15100 APM_DO_RESTORE_SEGS;
15101 apm_irq_restore(flags);
15102 +
15103 + pax_open_kernel();
15104 gdt[0x40 / 8] = save_desc_40;
15105 + pax_close_kernel();
15106 +
15107 put_cpu();
15108 return error;
15109 }
15110 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
15111 * code to that CPU.
15112 */
15113 gdt = get_cpu_gdt_table(0);
15114 +
15115 + pax_open_kernel();
15116 set_desc_base(&gdt[APM_CS >> 3],
15117 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
15118 set_desc_base(&gdt[APM_CS_16 >> 3],
15119 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
15120 set_desc_base(&gdt[APM_DS >> 3],
15121 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
15122 + pax_close_kernel();
15123
15124 proc_create("apm", 0, NULL, &apm_file_ops);
15125
15126 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
15127 index 2861082..6d4718e 100644
15128 --- a/arch/x86/kernel/asm-offsets.c
15129 +++ b/arch/x86/kernel/asm-offsets.c
15130 @@ -33,6 +33,8 @@ void common(void) {
15131 OFFSET(TI_status, thread_info, status);
15132 OFFSET(TI_addr_limit, thread_info, addr_limit);
15133 OFFSET(TI_preempt_count, thread_info, preempt_count);
15134 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
15135 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
15136
15137 BLANK();
15138 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
15139 @@ -53,8 +55,26 @@ void common(void) {
15140 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
15141 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
15142 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
15143 +
15144 +#ifdef CONFIG_PAX_KERNEXEC
15145 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
15146 #endif
15147
15148 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15149 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
15150 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
15151 +#ifdef CONFIG_X86_64
15152 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
15153 +#endif
15154 +#endif
15155 +
15156 +#endif
15157 +
15158 + BLANK();
15159 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
15160 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
15161 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
15162 +
15163 #ifdef CONFIG_XEN
15164 BLANK();
15165 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
15166 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
15167 index 1b4754f..fbb4227 100644
15168 --- a/arch/x86/kernel/asm-offsets_64.c
15169 +++ b/arch/x86/kernel/asm-offsets_64.c
15170 @@ -76,6 +76,7 @@ int main(void)
15171 BLANK();
15172 #undef ENTRY
15173
15174 + DEFINE(TSS_size, sizeof(struct tss_struct));
15175 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
15176 BLANK();
15177
15178 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
15179 index a0e067d..9c7db16 100644
15180 --- a/arch/x86/kernel/cpu/Makefile
15181 +++ b/arch/x86/kernel/cpu/Makefile
15182 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
15183 CFLAGS_REMOVE_perf_event.o = -pg
15184 endif
15185
15186 -# Make sure load_percpu_segment has no stackprotector
15187 -nostackp := $(call cc-option, -fno-stack-protector)
15188 -CFLAGS_common.o := $(nostackp)
15189 -
15190 obj-y := intel_cacheinfo.o scattered.o topology.o
15191 obj-y += proc.o capflags.o powerflags.o common.o
15192 obj-y += vmware.o hypervisor.o mshyperv.o
15193 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
15194 index 1b7d165..b9e2627 100644
15195 --- a/arch/x86/kernel/cpu/amd.c
15196 +++ b/arch/x86/kernel/cpu/amd.c
15197 @@ -738,7 +738,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
15198 unsigned int size)
15199 {
15200 /* AMD errata T13 (order #21922) */
15201 - if ((c->x86 == 6)) {
15202 + if (c->x86 == 6) {
15203 /* Duron Rev A0 */
15204 if (c->x86_model == 3 && c->x86_mask == 0)
15205 size = 64;
15206 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
15207 index 7505f7b..d59dac0 100644
15208 --- a/arch/x86/kernel/cpu/common.c
15209 +++ b/arch/x86/kernel/cpu/common.c
15210 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
15211
15212 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
15213
15214 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
15215 -#ifdef CONFIG_X86_64
15216 - /*
15217 - * We need valid kernel segments for data and code in long mode too
15218 - * IRET will check the segment types kkeil 2000/10/28
15219 - * Also sysret mandates a special GDT layout
15220 - *
15221 - * TLS descriptors are currently at a different place compared to i386.
15222 - * Hopefully nobody expects them at a fixed place (Wine?)
15223 - */
15224 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
15225 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
15226 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
15227 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
15228 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
15229 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
15230 -#else
15231 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
15232 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15233 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
15234 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
15235 - /*
15236 - * Segments used for calling PnP BIOS have byte granularity.
15237 - * They code segments and data segments have fixed 64k limits,
15238 - * the transfer segment sizes are set at run time.
15239 - */
15240 - /* 32-bit code */
15241 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15242 - /* 16-bit code */
15243 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15244 - /* 16-bit data */
15245 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
15246 - /* 16-bit data */
15247 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
15248 - /* 16-bit data */
15249 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
15250 - /*
15251 - * The APM segments have byte granularity and their bases
15252 - * are set at run time. All have 64k limits.
15253 - */
15254 - /* 32-bit code */
15255 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15256 - /* 16-bit code */
15257 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15258 - /* data */
15259 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
15260 -
15261 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15262 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15263 - GDT_STACK_CANARY_INIT
15264 -#endif
15265 -} };
15266 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
15267 -
15268 static int __init x86_xsave_setup(char *s)
15269 {
15270 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
15271 @@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
15272 {
15273 struct desc_ptr gdt_descr;
15274
15275 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
15276 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
15277 gdt_descr.size = GDT_SIZE - 1;
15278 load_gdt(&gdt_descr);
15279 /* Reload the per-cpu base */
15280 @@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
15281 /* Filter out anything that depends on CPUID levels we don't have */
15282 filter_cpuid_features(c, true);
15283
15284 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
15285 + setup_clear_cpu_cap(X86_FEATURE_SEP);
15286 +#endif
15287 +
15288 /* If the model name is still unset, do table lookup. */
15289 if (!c->x86_model_id[0]) {
15290 const char *p;
15291 @@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
15292 }
15293 __setup("clearcpuid=", setup_disablecpuid);
15294
15295 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
15296 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
15297 +
15298 #ifdef CONFIG_X86_64
15299 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
15300 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
15301 - (unsigned long) nmi_idt_table };
15302 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
15303
15304 DEFINE_PER_CPU_FIRST(union irq_stack_union,
15305 irq_stack_union) __aligned(PAGE_SIZE);
15306 @@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
15307 EXPORT_PER_CPU_SYMBOL(current_task);
15308
15309 DEFINE_PER_CPU(unsigned long, kernel_stack) =
15310 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
15311 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
15312 EXPORT_PER_CPU_SYMBOL(kernel_stack);
15313
15314 DEFINE_PER_CPU(char *, irq_stack_ptr) =
15315 @@ -1178,7 +1130,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
15316 {
15317 memset(regs, 0, sizeof(struct pt_regs));
15318 regs->fs = __KERNEL_PERCPU;
15319 - regs->gs = __KERNEL_STACK_CANARY;
15320 + savesegment(gs, regs->gs);
15321
15322 return regs;
15323 }
15324 @@ -1233,7 +1185,7 @@ void __cpuinit cpu_init(void)
15325 int i;
15326
15327 cpu = stack_smp_processor_id();
15328 - t = &per_cpu(init_tss, cpu);
15329 + t = init_tss + cpu;
15330 oist = &per_cpu(orig_ist, cpu);
15331
15332 #ifdef CONFIG_NUMA
15333 @@ -1259,7 +1211,7 @@ void __cpuinit cpu_init(void)
15334 switch_to_new_gdt(cpu);
15335 loadsegment(fs, 0);
15336
15337 - load_idt((const struct desc_ptr *)&idt_descr);
15338 + load_idt(&idt_descr);
15339
15340 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
15341 syscall_init();
15342 @@ -1268,7 +1220,6 @@ void __cpuinit cpu_init(void)
15343 wrmsrl(MSR_KERNEL_GS_BASE, 0);
15344 barrier();
15345
15346 - x86_configure_nx();
15347 if (cpu != 0)
15348 enable_x2apic();
15349
15350 @@ -1321,7 +1272,7 @@ void __cpuinit cpu_init(void)
15351 {
15352 int cpu = smp_processor_id();
15353 struct task_struct *curr = current;
15354 - struct tss_struct *t = &per_cpu(init_tss, cpu);
15355 + struct tss_struct *t = init_tss + cpu;
15356 struct thread_struct *thread = &curr->thread;
15357
15358 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
15359 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
15360 index 198e019..867575e 100644
15361 --- a/arch/x86/kernel/cpu/intel.c
15362 +++ b/arch/x86/kernel/cpu/intel.c
15363 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
15364 * Update the IDT descriptor and reload the IDT so that
15365 * it uses the read-only mapped virtual address.
15366 */
15367 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
15368 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
15369 load_idt(&idt_descr);
15370 }
15371 #endif
15372 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
15373 index 93c5451..3887433 100644
15374 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
15375 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
15376 @@ -983,6 +983,22 @@ static struct attribute *default_attrs[] = {
15377 };
15378
15379 #ifdef CONFIG_AMD_NB
15380 +static struct attribute *default_attrs_amd_nb[] = {
15381 + &type.attr,
15382 + &level.attr,
15383 + &coherency_line_size.attr,
15384 + &physical_line_partition.attr,
15385 + &ways_of_associativity.attr,
15386 + &number_of_sets.attr,
15387 + &size.attr,
15388 + &shared_cpu_map.attr,
15389 + &shared_cpu_list.attr,
15390 + NULL,
15391 + NULL,
15392 + NULL,
15393 + NULL
15394 +};
15395 +
15396 static struct attribute ** __cpuinit amd_l3_attrs(void)
15397 {
15398 static struct attribute **attrs;
15399 @@ -993,18 +1009,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
15400
15401 n = ARRAY_SIZE(default_attrs);
15402
15403 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
15404 - n += 2;
15405 -
15406 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
15407 - n += 1;
15408 -
15409 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
15410 - if (attrs == NULL)
15411 - return attrs = default_attrs;
15412 -
15413 - for (n = 0; default_attrs[n]; n++)
15414 - attrs[n] = default_attrs[n];
15415 + attrs = default_attrs_amd_nb;
15416
15417 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
15418 attrs[n++] = &cache_disable_0.attr;
15419 @@ -1055,6 +1060,13 @@ static struct kobj_type ktype_cache = {
15420 .default_attrs = default_attrs,
15421 };
15422
15423 +#ifdef CONFIG_AMD_NB
15424 +static struct kobj_type ktype_cache_amd_nb = {
15425 + .sysfs_ops = &sysfs_ops,
15426 + .default_attrs = default_attrs_amd_nb,
15427 +};
15428 +#endif
15429 +
15430 static struct kobj_type ktype_percpu_entry = {
15431 .sysfs_ops = &sysfs_ops,
15432 };
15433 @@ -1120,20 +1132,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
15434 return retval;
15435 }
15436
15437 +#ifdef CONFIG_AMD_NB
15438 + amd_l3_attrs();
15439 +#endif
15440 +
15441 for (i = 0; i < num_cache_leaves; i++) {
15442 + struct kobj_type *ktype;
15443 +
15444 this_object = INDEX_KOBJECT_PTR(cpu, i);
15445 this_object->cpu = cpu;
15446 this_object->index = i;
15447
15448 this_leaf = CPUID4_INFO_IDX(cpu, i);
15449
15450 - ktype_cache.default_attrs = default_attrs;
15451 + ktype = &ktype_cache;
15452 #ifdef CONFIG_AMD_NB
15453 if (this_leaf->base.nb)
15454 - ktype_cache.default_attrs = amd_l3_attrs();
15455 + ktype = &ktype_cache_amd_nb;
15456 #endif
15457 retval = kobject_init_and_add(&(this_object->kobj),
15458 - &ktype_cache,
15459 + ktype,
15460 per_cpu(ici_cache_kobject, cpu),
15461 "index%1lu", i);
15462 if (unlikely(retval)) {
15463 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
15464 index 46cbf86..55c7292 100644
15465 --- a/arch/x86/kernel/cpu/mcheck/mce.c
15466 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
15467 @@ -45,6 +45,7 @@
15468 #include <asm/processor.h>
15469 #include <asm/mce.h>
15470 #include <asm/msr.h>
15471 +#include <asm/local.h>
15472
15473 #include "mce-internal.h"
15474
15475 @@ -254,7 +255,7 @@ static void print_mce(struct mce *m)
15476 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
15477 m->cs, m->ip);
15478
15479 - if (m->cs == __KERNEL_CS)
15480 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
15481 print_symbol("{%s}", m->ip);
15482 pr_cont("\n");
15483 }
15484 @@ -287,10 +288,10 @@ static void print_mce(struct mce *m)
15485
15486 #define PANIC_TIMEOUT 5 /* 5 seconds */
15487
15488 -static atomic_t mce_paniced;
15489 +static atomic_unchecked_t mce_paniced;
15490
15491 static int fake_panic;
15492 -static atomic_t mce_fake_paniced;
15493 +static atomic_unchecked_t mce_fake_paniced;
15494
15495 /* Panic in progress. Enable interrupts and wait for final IPI */
15496 static void wait_for_panic(void)
15497 @@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15498 /*
15499 * Make sure only one CPU runs in machine check panic
15500 */
15501 - if (atomic_inc_return(&mce_paniced) > 1)
15502 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
15503 wait_for_panic();
15504 barrier();
15505
15506 @@ -322,7 +323,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15507 console_verbose();
15508 } else {
15509 /* Don't log too much for fake panic */
15510 - if (atomic_inc_return(&mce_fake_paniced) > 1)
15511 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
15512 return;
15513 }
15514 /* First print corrected ones that are still unlogged */
15515 @@ -694,7 +695,7 @@ static int mce_timed_out(u64 *t)
15516 * might have been modified by someone else.
15517 */
15518 rmb();
15519 - if (atomic_read(&mce_paniced))
15520 + if (atomic_read_unchecked(&mce_paniced))
15521 wait_for_panic();
15522 if (!monarch_timeout)
15523 goto out;
15524 @@ -1659,7 +1660,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
15525 }
15526
15527 /* Call the installed machine check handler for this CPU setup. */
15528 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
15529 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
15530 unexpected_machine_check;
15531
15532 /*
15533 @@ -1682,7 +1683,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15534 return;
15535 }
15536
15537 + pax_open_kernel();
15538 machine_check_vector = do_machine_check;
15539 + pax_close_kernel();
15540
15541 __mcheck_cpu_init_generic();
15542 __mcheck_cpu_init_vendor(c);
15543 @@ -1696,7 +1699,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15544 */
15545
15546 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
15547 -static int mce_chrdev_open_count; /* #times opened */
15548 +static local_t mce_chrdev_open_count; /* #times opened */
15549 static int mce_chrdev_open_exclu; /* already open exclusive? */
15550
15551 static int mce_chrdev_open(struct inode *inode, struct file *file)
15552 @@ -1704,7 +1707,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15553 spin_lock(&mce_chrdev_state_lock);
15554
15555 if (mce_chrdev_open_exclu ||
15556 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
15557 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
15558 spin_unlock(&mce_chrdev_state_lock);
15559
15560 return -EBUSY;
15561 @@ -1712,7 +1715,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15562
15563 if (file->f_flags & O_EXCL)
15564 mce_chrdev_open_exclu = 1;
15565 - mce_chrdev_open_count++;
15566 + local_inc(&mce_chrdev_open_count);
15567
15568 spin_unlock(&mce_chrdev_state_lock);
15569
15570 @@ -1723,7 +1726,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
15571 {
15572 spin_lock(&mce_chrdev_state_lock);
15573
15574 - mce_chrdev_open_count--;
15575 + local_dec(&mce_chrdev_open_count);
15576 mce_chrdev_open_exclu = 0;
15577
15578 spin_unlock(&mce_chrdev_state_lock);
15579 @@ -2367,7 +2370,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
15580 return NOTIFY_OK;
15581 }
15582
15583 -static struct notifier_block mce_cpu_notifier __cpuinitdata = {
15584 +static struct notifier_block mce_cpu_notifier __cpuinitconst = {
15585 .notifier_call = mce_cpu_callback,
15586 };
15587
15588 @@ -2445,7 +2448,7 @@ struct dentry *mce_get_debugfs_dir(void)
15589 static void mce_reset(void)
15590 {
15591 cpu_missing = 0;
15592 - atomic_set(&mce_fake_paniced, 0);
15593 + atomic_set_unchecked(&mce_fake_paniced, 0);
15594 atomic_set(&mce_executing, 0);
15595 atomic_set(&mce_callin, 0);
15596 atomic_set(&global_nwo, 0);
15597 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
15598 index 2d5454c..51987eb 100644
15599 --- a/arch/x86/kernel/cpu/mcheck/p5.c
15600 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
15601 @@ -11,6 +11,7 @@
15602 #include <asm/processor.h>
15603 #include <asm/mce.h>
15604 #include <asm/msr.h>
15605 +#include <asm/pgtable.h>
15606
15607 /* By default disabled */
15608 int mce_p5_enabled __read_mostly;
15609 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
15610 if (!cpu_has(c, X86_FEATURE_MCE))
15611 return;
15612
15613 + pax_open_kernel();
15614 machine_check_vector = pentium_machine_check;
15615 + pax_close_kernel();
15616 /* Make sure the vector pointer is visible before we enable MCEs: */
15617 wmb();
15618
15619 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
15620 index 2d7998f..17c9de1 100644
15621 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
15622 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
15623 @@ -10,6 +10,7 @@
15624 #include <asm/processor.h>
15625 #include <asm/mce.h>
15626 #include <asm/msr.h>
15627 +#include <asm/pgtable.h>
15628
15629 /* Machine check handler for WinChip C6: */
15630 static void winchip_machine_check(struct pt_regs *regs, long error_code)
15631 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
15632 {
15633 u32 lo, hi;
15634
15635 + pax_open_kernel();
15636 machine_check_vector = winchip_machine_check;
15637 + pax_close_kernel();
15638 /* Make sure the vector pointer is visible before we enable MCEs: */
15639 wmb();
15640
15641 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
15642 index 6b96110..0da73eb 100644
15643 --- a/arch/x86/kernel/cpu/mtrr/main.c
15644 +++ b/arch/x86/kernel/cpu/mtrr/main.c
15645 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
15646 u64 size_or_mask, size_and_mask;
15647 static bool mtrr_aps_delayed_init;
15648
15649 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
15650 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
15651
15652 const struct mtrr_ops *mtrr_if;
15653
15654 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
15655 index df5e41f..816c719 100644
15656 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
15657 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
15658 @@ -25,7 +25,7 @@ struct mtrr_ops {
15659 int (*validate_add_page)(unsigned long base, unsigned long size,
15660 unsigned int type);
15661 int (*have_wrcomb)(void);
15662 -};
15663 +} __do_const;
15664
15665 extern int generic_get_free_region(unsigned long base, unsigned long size,
15666 int replace_reg);
15667 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
15668 index d18b2b8..d3b834c 100644
15669 --- a/arch/x86/kernel/cpu/perf_event.c
15670 +++ b/arch/x86/kernel/cpu/perf_event.c
15671 @@ -1759,7 +1759,7 @@ static unsigned long get_segment_base(unsigned int segment)
15672 if (idx > GDT_ENTRIES)
15673 return 0;
15674
15675 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
15676 + desc = get_cpu_gdt_table(smp_processor_id());
15677 }
15678
15679 return get_desc_base(desc + idx);
15680 @@ -1849,7 +1849,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
15681 break;
15682
15683 perf_callchain_store(entry, frame.return_address);
15684 - fp = frame.next_frame;
15685 + fp = (const void __force_user *)frame.next_frame;
15686 }
15687 }
15688
15689 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
15690 index 324bb52..1a93d85 100644
15691 --- a/arch/x86/kernel/cpu/perf_event_intel.c
15692 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
15693 @@ -1949,10 +1949,10 @@ __init int intel_pmu_init(void)
15694 * v2 and above have a perf capabilities MSR
15695 */
15696 if (version > 1) {
15697 - u64 capabilities;
15698 + u64 capabilities = x86_pmu.intel_cap.capabilities;
15699
15700 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
15701 - x86_pmu.intel_cap.capabilities = capabilities;
15702 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
15703 + x86_pmu.intel_cap.capabilities = capabilities;
15704 }
15705
15706 intel_ds_init();
15707 diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
15708 index d22d0c4..088eb6f 100644
15709 --- a/arch/x86/kernel/cpu/vmware.c
15710 +++ b/arch/x86/kernel/cpu/vmware.c
15711 @@ -79,7 +79,7 @@ static void __init vmware_platform_setup(void)
15712 VMWARE_PORT(GETHZ, eax, ebx, ecx, edx);
15713
15714 if (ebx != UINT_MAX)
15715 - x86_platform.calibrate_tsc = vmware_get_tsc_khz;
15716 + *(void **)&x86_platform.calibrate_tsc = vmware_get_tsc_khz;
15717 else
15718 printk(KERN_WARNING
15719 "Failed to get TSC freq from the hypervisor\n");
15720 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
15721 index 13ad899..f642b9a 100644
15722 --- a/arch/x86/kernel/crash.c
15723 +++ b/arch/x86/kernel/crash.c
15724 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
15725 {
15726 #ifdef CONFIG_X86_32
15727 struct pt_regs fixed_regs;
15728 -#endif
15729
15730 -#ifdef CONFIG_X86_32
15731 - if (!user_mode_vm(regs)) {
15732 + if (!user_mode(regs)) {
15733 crash_fixup_ss_esp(&fixed_regs, regs);
15734 regs = &fixed_regs;
15735 }
15736 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
15737 index 37250fe..bf2ec74 100644
15738 --- a/arch/x86/kernel/doublefault_32.c
15739 +++ b/arch/x86/kernel/doublefault_32.c
15740 @@ -11,7 +11,7 @@
15741
15742 #define DOUBLEFAULT_STACKSIZE (1024)
15743 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
15744 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
15745 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
15746
15747 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
15748
15749 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
15750 unsigned long gdt, tss;
15751
15752 store_gdt(&gdt_desc);
15753 - gdt = gdt_desc.address;
15754 + gdt = (unsigned long)gdt_desc.address;
15755
15756 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
15757
15758 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
15759 /* 0x2 bit is always set */
15760 .flags = X86_EFLAGS_SF | 0x2,
15761 .sp = STACK_START,
15762 - .es = __USER_DS,
15763 + .es = __KERNEL_DS,
15764 .cs = __KERNEL_CS,
15765 .ss = __KERNEL_DS,
15766 - .ds = __USER_DS,
15767 + .ds = __KERNEL_DS,
15768 .fs = __KERNEL_PERCPU,
15769
15770 .__cr3 = __pa_nodebug(swapper_pg_dir),
15771 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
15772 index ae42418b..787c16b 100644
15773 --- a/arch/x86/kernel/dumpstack.c
15774 +++ b/arch/x86/kernel/dumpstack.c
15775 @@ -2,6 +2,9 @@
15776 * Copyright (C) 1991, 1992 Linus Torvalds
15777 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
15778 */
15779 +#ifdef CONFIG_GRKERNSEC_HIDESYM
15780 +#define __INCLUDED_BY_HIDESYM 1
15781 +#endif
15782 #include <linux/kallsyms.h>
15783 #include <linux/kprobes.h>
15784 #include <linux/uaccess.h>
15785 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
15786 static void
15787 print_ftrace_graph_addr(unsigned long addr, void *data,
15788 const struct stacktrace_ops *ops,
15789 - struct thread_info *tinfo, int *graph)
15790 + struct task_struct *task, int *graph)
15791 {
15792 - struct task_struct *task;
15793 unsigned long ret_addr;
15794 int index;
15795
15796 if (addr != (unsigned long)return_to_handler)
15797 return;
15798
15799 - task = tinfo->task;
15800 index = task->curr_ret_stack;
15801
15802 if (!task->ret_stack || index < *graph)
15803 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15804 static inline void
15805 print_ftrace_graph_addr(unsigned long addr, void *data,
15806 const struct stacktrace_ops *ops,
15807 - struct thread_info *tinfo, int *graph)
15808 + struct task_struct *task, int *graph)
15809 { }
15810 #endif
15811
15812 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15813 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
15814 */
15815
15816 -static inline int valid_stack_ptr(struct thread_info *tinfo,
15817 - void *p, unsigned int size, void *end)
15818 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
15819 {
15820 - void *t = tinfo;
15821 if (end) {
15822 if (p < end && p >= (end-THREAD_SIZE))
15823 return 1;
15824 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
15825 }
15826
15827 unsigned long
15828 -print_context_stack(struct thread_info *tinfo,
15829 +print_context_stack(struct task_struct *task, void *stack_start,
15830 unsigned long *stack, unsigned long bp,
15831 const struct stacktrace_ops *ops, void *data,
15832 unsigned long *end, int *graph)
15833 {
15834 struct stack_frame *frame = (struct stack_frame *)bp;
15835
15836 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
15837 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
15838 unsigned long addr;
15839
15840 addr = *stack;
15841 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
15842 } else {
15843 ops->address(data, addr, 0);
15844 }
15845 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15846 + print_ftrace_graph_addr(addr, data, ops, task, graph);
15847 }
15848 stack++;
15849 }
15850 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
15851 EXPORT_SYMBOL_GPL(print_context_stack);
15852
15853 unsigned long
15854 -print_context_stack_bp(struct thread_info *tinfo,
15855 +print_context_stack_bp(struct task_struct *task, void *stack_start,
15856 unsigned long *stack, unsigned long bp,
15857 const struct stacktrace_ops *ops, void *data,
15858 unsigned long *end, int *graph)
15859 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
15860 struct stack_frame *frame = (struct stack_frame *)bp;
15861 unsigned long *ret_addr = &frame->return_address;
15862
15863 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
15864 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
15865 unsigned long addr = *ret_addr;
15866
15867 if (!__kernel_text_address(addr))
15868 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
15869 ops->address(data, addr, 1);
15870 frame = frame->next_frame;
15871 ret_addr = &frame->return_address;
15872 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15873 + print_ftrace_graph_addr(addr, data, ops, task, graph);
15874 }
15875
15876 return (unsigned long)frame;
15877 @@ -189,7 +188,7 @@ void dump_stack(void)
15878
15879 bp = stack_frame(current, NULL);
15880 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
15881 - current->pid, current->comm, print_tainted(),
15882 + task_pid_nr(current), current->comm, print_tainted(),
15883 init_utsname()->release,
15884 (int)strcspn(init_utsname()->version, " "),
15885 init_utsname()->version);
15886 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
15887 }
15888 EXPORT_SYMBOL_GPL(oops_begin);
15889
15890 +extern void gr_handle_kernel_exploit(void);
15891 +
15892 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
15893 {
15894 if (regs && kexec_should_crash(current))
15895 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
15896 panic("Fatal exception in interrupt");
15897 if (panic_on_oops)
15898 panic("Fatal exception");
15899 - do_exit(signr);
15900 +
15901 + gr_handle_kernel_exploit();
15902 +
15903 + do_group_exit(signr);
15904 }
15905
15906 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
15907 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
15908 print_modules();
15909 show_regs(regs);
15910 #ifdef CONFIG_X86_32
15911 - if (user_mode_vm(regs)) {
15912 + if (user_mode(regs)) {
15913 sp = regs->sp;
15914 ss = regs->ss & 0xffff;
15915 } else {
15916 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
15917 unsigned long flags = oops_begin();
15918 int sig = SIGSEGV;
15919
15920 - if (!user_mode_vm(regs))
15921 + if (!user_mode(regs))
15922 report_bug(regs->ip, regs);
15923
15924 if (__die(str, regs, err))
15925 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
15926 index 1038a41..db2c12b 100644
15927 --- a/arch/x86/kernel/dumpstack_32.c
15928 +++ b/arch/x86/kernel/dumpstack_32.c
15929 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15930 bp = stack_frame(task, regs);
15931
15932 for (;;) {
15933 - struct thread_info *context;
15934 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
15935
15936 - context = (struct thread_info *)
15937 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
15938 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
15939 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
15940
15941 - stack = (unsigned long *)context->previous_esp;
15942 - if (!stack)
15943 + if (stack_start == task_stack_page(task))
15944 break;
15945 + stack = *(unsigned long **)stack_start;
15946 if (ops->stack(data, "IRQ") < 0)
15947 break;
15948 touch_nmi_watchdog();
15949 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
15950 {
15951 int i;
15952
15953 - __show_regs(regs, !user_mode_vm(regs));
15954 + __show_regs(regs, !user_mode(regs));
15955
15956 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
15957 TASK_COMM_LEN, current->comm, task_pid_nr(current),
15958 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
15959 * When in-kernel, we also print out the stack and code at the
15960 * time of the fault..
15961 */
15962 - if (!user_mode_vm(regs)) {
15963 + if (!user_mode(regs)) {
15964 unsigned int code_prologue = code_bytes * 43 / 64;
15965 unsigned int code_len = code_bytes;
15966 unsigned char c;
15967 u8 *ip;
15968 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
15969
15970 pr_emerg("Stack:\n");
15971 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
15972
15973 pr_emerg("Code:");
15974
15975 - ip = (u8 *)regs->ip - code_prologue;
15976 + ip = (u8 *)regs->ip - code_prologue + cs_base;
15977 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
15978 /* try starting at IP */
15979 - ip = (u8 *)regs->ip;
15980 + ip = (u8 *)regs->ip + cs_base;
15981 code_len = code_len - code_prologue + 1;
15982 }
15983 for (i = 0; i < code_len; i++, ip++) {
15984 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
15985 pr_cont(" Bad EIP value.");
15986 break;
15987 }
15988 - if (ip == (u8 *)regs->ip)
15989 + if (ip == (u8 *)regs->ip + cs_base)
15990 pr_cont(" <%02x>", c);
15991 else
15992 pr_cont(" %02x", c);
15993 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
15994 {
15995 unsigned short ud2;
15996
15997 + ip = ktla_ktva(ip);
15998 if (ip < PAGE_OFFSET)
15999 return 0;
16000 if (probe_kernel_address((unsigned short *)ip, ud2))
16001 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
16002
16003 return ud2 == 0x0b0f;
16004 }
16005 +
16006 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16007 +void pax_check_alloca(unsigned long size)
16008 +{
16009 + unsigned long sp = (unsigned long)&sp, stack_left;
16010 +
16011 + /* all kernel stacks are of the same size */
16012 + stack_left = sp & (THREAD_SIZE - 1);
16013 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16014 +}
16015 +EXPORT_SYMBOL(pax_check_alloca);
16016 +#endif
16017 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
16018 index b653675..51cc8c0 100644
16019 --- a/arch/x86/kernel/dumpstack_64.c
16020 +++ b/arch/x86/kernel/dumpstack_64.c
16021 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16022 unsigned long *irq_stack_end =
16023 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
16024 unsigned used = 0;
16025 - struct thread_info *tinfo;
16026 int graph = 0;
16027 unsigned long dummy;
16028 + void *stack_start;
16029
16030 if (!task)
16031 task = current;
16032 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16033 * current stack address. If the stacks consist of nested
16034 * exceptions
16035 */
16036 - tinfo = task_thread_info(task);
16037 for (;;) {
16038 char *id;
16039 unsigned long *estack_end;
16040 +
16041 estack_end = in_exception_stack(cpu, (unsigned long)stack,
16042 &used, &id);
16043
16044 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16045 if (ops->stack(data, id) < 0)
16046 break;
16047
16048 - bp = ops->walk_stack(tinfo, stack, bp, ops,
16049 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
16050 data, estack_end, &graph);
16051 ops->stack(data, "<EOE>");
16052 /*
16053 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16054 * second-to-last pointer (index -2 to end) in the
16055 * exception stack:
16056 */
16057 + if ((u16)estack_end[-1] != __KERNEL_DS)
16058 + goto out;
16059 stack = (unsigned long *) estack_end[-2];
16060 continue;
16061 }
16062 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16063 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
16064 if (ops->stack(data, "IRQ") < 0)
16065 break;
16066 - bp = ops->walk_stack(tinfo, stack, bp,
16067 + bp = ops->walk_stack(task, irq_stack, stack, bp,
16068 ops, data, irq_stack_end, &graph);
16069 /*
16070 * We link to the next stack (which would be
16071 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16072 /*
16073 * This handles the process stack:
16074 */
16075 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
16076 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
16077 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
16078 +out:
16079 put_cpu();
16080 }
16081 EXPORT_SYMBOL(dump_trace);
16082 @@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
16083 {
16084 int i;
16085 unsigned long sp;
16086 - const int cpu = smp_processor_id();
16087 + const int cpu = raw_smp_processor_id();
16088 struct task_struct *cur = current;
16089
16090 sp = regs->sp;
16091 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
16092
16093 return ud2 == 0x0b0f;
16094 }
16095 +
16096 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16097 +void pax_check_alloca(unsigned long size)
16098 +{
16099 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
16100 + unsigned cpu, used;
16101 + char *id;
16102 +
16103 + /* check the process stack first */
16104 + stack_start = (unsigned long)task_stack_page(current);
16105 + stack_end = stack_start + THREAD_SIZE;
16106 + if (likely(stack_start <= sp && sp < stack_end)) {
16107 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
16108 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16109 + return;
16110 + }
16111 +
16112 + cpu = get_cpu();
16113 +
16114 + /* check the irq stacks */
16115 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
16116 + stack_start = stack_end - IRQ_STACK_SIZE;
16117 + if (stack_start <= sp && sp < stack_end) {
16118 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
16119 + put_cpu();
16120 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16121 + return;
16122 + }
16123 +
16124 + /* check the exception stacks */
16125 + used = 0;
16126 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
16127 + stack_start = stack_end - EXCEPTION_STKSZ;
16128 + if (stack_end && stack_start <= sp && sp < stack_end) {
16129 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
16130 + put_cpu();
16131 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16132 + return;
16133 + }
16134 +
16135 + put_cpu();
16136 +
16137 + /* unknown stack */
16138 + BUG();
16139 +}
16140 +EXPORT_SYMBOL(pax_check_alloca);
16141 +#endif
16142 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
16143 index 9b9f18b..9fcaa04 100644
16144 --- a/arch/x86/kernel/early_printk.c
16145 +++ b/arch/x86/kernel/early_printk.c
16146 @@ -7,6 +7,7 @@
16147 #include <linux/pci_regs.h>
16148 #include <linux/pci_ids.h>
16149 #include <linux/errno.h>
16150 +#include <linux/sched.h>
16151 #include <asm/io.h>
16152 #include <asm/processor.h>
16153 #include <asm/fcntl.h>
16154 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
16155 index cf8639b..98fcee6 100644
16156 --- a/arch/x86/kernel/entry_32.S
16157 +++ b/arch/x86/kernel/entry_32.S
16158 @@ -177,13 +177,153 @@
16159 /*CFI_REL_OFFSET gs, PT_GS*/
16160 .endm
16161 .macro SET_KERNEL_GS reg
16162 +
16163 +#ifdef CONFIG_CC_STACKPROTECTOR
16164 movl $(__KERNEL_STACK_CANARY), \reg
16165 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16166 + movl $(__USER_DS), \reg
16167 +#else
16168 + xorl \reg, \reg
16169 +#endif
16170 +
16171 movl \reg, %gs
16172 .endm
16173
16174 #endif /* CONFIG_X86_32_LAZY_GS */
16175
16176 -.macro SAVE_ALL
16177 +.macro pax_enter_kernel
16178 +#ifdef CONFIG_PAX_KERNEXEC
16179 + call pax_enter_kernel
16180 +#endif
16181 +.endm
16182 +
16183 +.macro pax_exit_kernel
16184 +#ifdef CONFIG_PAX_KERNEXEC
16185 + call pax_exit_kernel
16186 +#endif
16187 +.endm
16188 +
16189 +#ifdef CONFIG_PAX_KERNEXEC
16190 +ENTRY(pax_enter_kernel)
16191 +#ifdef CONFIG_PARAVIRT
16192 + pushl %eax
16193 + pushl %ecx
16194 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
16195 + mov %eax, %esi
16196 +#else
16197 + mov %cr0, %esi
16198 +#endif
16199 + bts $16, %esi
16200 + jnc 1f
16201 + mov %cs, %esi
16202 + cmp $__KERNEL_CS, %esi
16203 + jz 3f
16204 + ljmp $__KERNEL_CS, $3f
16205 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
16206 +2:
16207 +#ifdef CONFIG_PARAVIRT
16208 + mov %esi, %eax
16209 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16210 +#else
16211 + mov %esi, %cr0
16212 +#endif
16213 +3:
16214 +#ifdef CONFIG_PARAVIRT
16215 + popl %ecx
16216 + popl %eax
16217 +#endif
16218 + ret
16219 +ENDPROC(pax_enter_kernel)
16220 +
16221 +ENTRY(pax_exit_kernel)
16222 +#ifdef CONFIG_PARAVIRT
16223 + pushl %eax
16224 + pushl %ecx
16225 +#endif
16226 + mov %cs, %esi
16227 + cmp $__KERNEXEC_KERNEL_CS, %esi
16228 + jnz 2f
16229 +#ifdef CONFIG_PARAVIRT
16230 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
16231 + mov %eax, %esi
16232 +#else
16233 + mov %cr0, %esi
16234 +#endif
16235 + btr $16, %esi
16236 + ljmp $__KERNEL_CS, $1f
16237 +1:
16238 +#ifdef CONFIG_PARAVIRT
16239 + mov %esi, %eax
16240 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
16241 +#else
16242 + mov %esi, %cr0
16243 +#endif
16244 +2:
16245 +#ifdef CONFIG_PARAVIRT
16246 + popl %ecx
16247 + popl %eax
16248 +#endif
16249 + ret
16250 +ENDPROC(pax_exit_kernel)
16251 +#endif
16252 +
16253 +.macro pax_erase_kstack
16254 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16255 + call pax_erase_kstack
16256 +#endif
16257 +.endm
16258 +
16259 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16260 +/*
16261 + * ebp: thread_info
16262 + */
16263 +ENTRY(pax_erase_kstack)
16264 + pushl %edi
16265 + pushl %ecx
16266 + pushl %eax
16267 +
16268 + mov TI_lowest_stack(%ebp), %edi
16269 + mov $-0xBEEF, %eax
16270 + std
16271 +
16272 +1: mov %edi, %ecx
16273 + and $THREAD_SIZE_asm - 1, %ecx
16274 + shr $2, %ecx
16275 + repne scasl
16276 + jecxz 2f
16277 +
16278 + cmp $2*16, %ecx
16279 + jc 2f
16280 +
16281 + mov $2*16, %ecx
16282 + repe scasl
16283 + jecxz 2f
16284 + jne 1b
16285 +
16286 +2: cld
16287 + mov %esp, %ecx
16288 + sub %edi, %ecx
16289 +
16290 + cmp $THREAD_SIZE_asm, %ecx
16291 + jb 3f
16292 + ud2
16293 +3:
16294 +
16295 + shr $2, %ecx
16296 + rep stosl
16297 +
16298 + mov TI_task_thread_sp0(%ebp), %edi
16299 + sub $128, %edi
16300 + mov %edi, TI_lowest_stack(%ebp)
16301 +
16302 + popl %eax
16303 + popl %ecx
16304 + popl %edi
16305 + ret
16306 +ENDPROC(pax_erase_kstack)
16307 +#endif
16308 +
16309 +.macro __SAVE_ALL _DS
16310 cld
16311 PUSH_GS
16312 pushl_cfi %fs
16313 @@ -206,7 +346,7 @@
16314 CFI_REL_OFFSET ecx, 0
16315 pushl_cfi %ebx
16316 CFI_REL_OFFSET ebx, 0
16317 - movl $(__USER_DS), %edx
16318 + movl $\_DS, %edx
16319 movl %edx, %ds
16320 movl %edx, %es
16321 movl $(__KERNEL_PERCPU), %edx
16322 @@ -214,6 +354,15 @@
16323 SET_KERNEL_GS %edx
16324 .endm
16325
16326 +.macro SAVE_ALL
16327 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
16328 + __SAVE_ALL __KERNEL_DS
16329 + pax_enter_kernel
16330 +#else
16331 + __SAVE_ALL __USER_DS
16332 +#endif
16333 +.endm
16334 +
16335 .macro RESTORE_INT_REGS
16336 popl_cfi %ebx
16337 CFI_RESTORE ebx
16338 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
16339 popfl_cfi
16340 jmp syscall_exit
16341 CFI_ENDPROC
16342 -END(ret_from_fork)
16343 +ENDPROC(ret_from_fork)
16344
16345 ENTRY(ret_from_kernel_thread)
16346 CFI_STARTPROC
16347 @@ -344,7 +493,15 @@ ret_from_intr:
16348 andl $SEGMENT_RPL_MASK, %eax
16349 #endif
16350 cmpl $USER_RPL, %eax
16351 +
16352 +#ifdef CONFIG_PAX_KERNEXEC
16353 + jae resume_userspace
16354 +
16355 + pax_exit_kernel
16356 + jmp resume_kernel
16357 +#else
16358 jb resume_kernel # not returning to v8086 or userspace
16359 +#endif
16360
16361 ENTRY(resume_userspace)
16362 LOCKDEP_SYS_EXIT
16363 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
16364 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
16365 # int/exception return?
16366 jne work_pending
16367 - jmp restore_all
16368 -END(ret_from_exception)
16369 + jmp restore_all_pax
16370 +ENDPROC(ret_from_exception)
16371
16372 #ifdef CONFIG_PREEMPT
16373 ENTRY(resume_kernel)
16374 @@ -372,7 +529,7 @@ need_resched:
16375 jz restore_all
16376 call preempt_schedule_irq
16377 jmp need_resched
16378 -END(resume_kernel)
16379 +ENDPROC(resume_kernel)
16380 #endif
16381 CFI_ENDPROC
16382 /*
16383 @@ -406,30 +563,45 @@ sysenter_past_esp:
16384 /*CFI_REL_OFFSET cs, 0*/
16385 /*
16386 * Push current_thread_info()->sysenter_return to the stack.
16387 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
16388 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
16389 */
16390 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
16391 + pushl_cfi $0
16392 CFI_REL_OFFSET eip, 0
16393
16394 pushl_cfi %eax
16395 SAVE_ALL
16396 + GET_THREAD_INFO(%ebp)
16397 + movl TI_sysenter_return(%ebp),%ebp
16398 + movl %ebp,PT_EIP(%esp)
16399 ENABLE_INTERRUPTS(CLBR_NONE)
16400
16401 /*
16402 * Load the potential sixth argument from user stack.
16403 * Careful about security.
16404 */
16405 + movl PT_OLDESP(%esp),%ebp
16406 +
16407 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16408 + mov PT_OLDSS(%esp),%ds
16409 +1: movl %ds:(%ebp),%ebp
16410 + push %ss
16411 + pop %ds
16412 +#else
16413 cmpl $__PAGE_OFFSET-3,%ebp
16414 jae syscall_fault
16415 ASM_STAC
16416 1: movl (%ebp),%ebp
16417 ASM_CLAC
16418 +#endif
16419 +
16420 movl %ebp,PT_EBP(%esp)
16421 _ASM_EXTABLE(1b,syscall_fault)
16422
16423 GET_THREAD_INFO(%ebp)
16424
16425 +#ifdef CONFIG_PAX_RANDKSTACK
16426 + pax_erase_kstack
16427 +#endif
16428 +
16429 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16430 jnz sysenter_audit
16431 sysenter_do_call:
16432 @@ -444,12 +616,24 @@ sysenter_do_call:
16433 testl $_TIF_ALLWORK_MASK, %ecx
16434 jne sysexit_audit
16435 sysenter_exit:
16436 +
16437 +#ifdef CONFIG_PAX_RANDKSTACK
16438 + pushl_cfi %eax
16439 + movl %esp, %eax
16440 + call pax_randomize_kstack
16441 + popl_cfi %eax
16442 +#endif
16443 +
16444 + pax_erase_kstack
16445 +
16446 /* if something modifies registers it must also disable sysexit */
16447 movl PT_EIP(%esp), %edx
16448 movl PT_OLDESP(%esp), %ecx
16449 xorl %ebp,%ebp
16450 TRACE_IRQS_ON
16451 1: mov PT_FS(%esp), %fs
16452 +2: mov PT_DS(%esp), %ds
16453 +3: mov PT_ES(%esp), %es
16454 PTGS_TO_GS
16455 ENABLE_INTERRUPTS_SYSEXIT
16456
16457 @@ -466,6 +650,9 @@ sysenter_audit:
16458 movl %eax,%edx /* 2nd arg: syscall number */
16459 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
16460 call __audit_syscall_entry
16461 +
16462 + pax_erase_kstack
16463 +
16464 pushl_cfi %ebx
16465 movl PT_EAX(%esp),%eax /* reload syscall number */
16466 jmp sysenter_do_call
16467 @@ -491,10 +678,16 @@ sysexit_audit:
16468
16469 CFI_ENDPROC
16470 .pushsection .fixup,"ax"
16471 -2: movl $0,PT_FS(%esp)
16472 +4: movl $0,PT_FS(%esp)
16473 + jmp 1b
16474 +5: movl $0,PT_DS(%esp)
16475 + jmp 1b
16476 +6: movl $0,PT_ES(%esp)
16477 jmp 1b
16478 .popsection
16479 - _ASM_EXTABLE(1b,2b)
16480 + _ASM_EXTABLE(1b,4b)
16481 + _ASM_EXTABLE(2b,5b)
16482 + _ASM_EXTABLE(3b,6b)
16483 PTGS_TO_GS_EX
16484 ENDPROC(ia32_sysenter_target)
16485
16486 @@ -509,6 +702,11 @@ ENTRY(system_call)
16487 pushl_cfi %eax # save orig_eax
16488 SAVE_ALL
16489 GET_THREAD_INFO(%ebp)
16490 +
16491 +#ifdef CONFIG_PAX_RANDKSTACK
16492 + pax_erase_kstack
16493 +#endif
16494 +
16495 # system call tracing in operation / emulation
16496 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16497 jnz syscall_trace_entry
16498 @@ -527,6 +725,15 @@ syscall_exit:
16499 testl $_TIF_ALLWORK_MASK, %ecx # current->work
16500 jne syscall_exit_work
16501
16502 +restore_all_pax:
16503 +
16504 +#ifdef CONFIG_PAX_RANDKSTACK
16505 + movl %esp, %eax
16506 + call pax_randomize_kstack
16507 +#endif
16508 +
16509 + pax_erase_kstack
16510 +
16511 restore_all:
16512 TRACE_IRQS_IRET
16513 restore_all_notrace:
16514 @@ -583,14 +790,34 @@ ldt_ss:
16515 * compensating for the offset by changing to the ESPFIX segment with
16516 * a base address that matches for the difference.
16517 */
16518 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
16519 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
16520 mov %esp, %edx /* load kernel esp */
16521 mov PT_OLDESP(%esp), %eax /* load userspace esp */
16522 mov %dx, %ax /* eax: new kernel esp */
16523 sub %eax, %edx /* offset (low word is 0) */
16524 +#ifdef CONFIG_SMP
16525 + movl PER_CPU_VAR(cpu_number), %ebx
16526 + shll $PAGE_SHIFT_asm, %ebx
16527 + addl $cpu_gdt_table, %ebx
16528 +#else
16529 + movl $cpu_gdt_table, %ebx
16530 +#endif
16531 shr $16, %edx
16532 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
16533 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
16534 +
16535 +#ifdef CONFIG_PAX_KERNEXEC
16536 + mov %cr0, %esi
16537 + btr $16, %esi
16538 + mov %esi, %cr0
16539 +#endif
16540 +
16541 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
16542 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
16543 +
16544 +#ifdef CONFIG_PAX_KERNEXEC
16545 + bts $16, %esi
16546 + mov %esi, %cr0
16547 +#endif
16548 +
16549 pushl_cfi $__ESPFIX_SS
16550 pushl_cfi %eax /* new kernel esp */
16551 /* Disable interrupts, but do not irqtrace this section: we
16552 @@ -619,20 +846,18 @@ work_resched:
16553 movl TI_flags(%ebp), %ecx
16554 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
16555 # than syscall tracing?
16556 - jz restore_all
16557 + jz restore_all_pax
16558 testb $_TIF_NEED_RESCHED, %cl
16559 jnz work_resched
16560
16561 work_notifysig: # deal with pending signals and
16562 # notify-resume requests
16563 + movl %esp, %eax
16564 #ifdef CONFIG_VM86
16565 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
16566 - movl %esp, %eax
16567 jne work_notifysig_v86 # returning to kernel-space or
16568 # vm86-space
16569 1:
16570 -#else
16571 - movl %esp, %eax
16572 #endif
16573 TRACE_IRQS_ON
16574 ENABLE_INTERRUPTS(CLBR_NONE)
16575 @@ -653,7 +878,7 @@ work_notifysig_v86:
16576 movl %eax, %esp
16577 jmp 1b
16578 #endif
16579 -END(work_pending)
16580 +ENDPROC(work_pending)
16581
16582 # perform syscall exit tracing
16583 ALIGN
16584 @@ -661,11 +886,14 @@ syscall_trace_entry:
16585 movl $-ENOSYS,PT_EAX(%esp)
16586 movl %esp, %eax
16587 call syscall_trace_enter
16588 +
16589 + pax_erase_kstack
16590 +
16591 /* What it returned is what we'll actually use. */
16592 cmpl $(NR_syscalls), %eax
16593 jnae syscall_call
16594 jmp syscall_exit
16595 -END(syscall_trace_entry)
16596 +ENDPROC(syscall_trace_entry)
16597
16598 # perform syscall exit tracing
16599 ALIGN
16600 @@ -678,21 +906,25 @@ syscall_exit_work:
16601 movl %esp, %eax
16602 call syscall_trace_leave
16603 jmp resume_userspace
16604 -END(syscall_exit_work)
16605 +ENDPROC(syscall_exit_work)
16606 CFI_ENDPROC
16607
16608 RING0_INT_FRAME # can't unwind into user space anyway
16609 syscall_fault:
16610 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16611 + push %ss
16612 + pop %ds
16613 +#endif
16614 ASM_CLAC
16615 GET_THREAD_INFO(%ebp)
16616 movl $-EFAULT,PT_EAX(%esp)
16617 jmp resume_userspace
16618 -END(syscall_fault)
16619 +ENDPROC(syscall_fault)
16620
16621 syscall_badsys:
16622 movl $-ENOSYS,PT_EAX(%esp)
16623 jmp resume_userspace
16624 -END(syscall_badsys)
16625 +ENDPROC(syscall_badsys)
16626 CFI_ENDPROC
16627 /*
16628 * End of kprobes section
16629 @@ -763,6 +995,36 @@ ENTRY(ptregs_clone)
16630 CFI_ENDPROC
16631 ENDPROC(ptregs_clone)
16632
16633 + ALIGN;
16634 +ENTRY(kernel_execve)
16635 + CFI_STARTPROC
16636 + pushl_cfi %ebp
16637 + sub $PT_OLDSS+4,%esp
16638 + pushl_cfi %edi
16639 + pushl_cfi %ecx
16640 + pushl_cfi %eax
16641 + lea 3*4(%esp),%edi
16642 + mov $PT_OLDSS/4+1,%ecx
16643 + xorl %eax,%eax
16644 + rep stosl
16645 + popl_cfi %eax
16646 + popl_cfi %ecx
16647 + popl_cfi %edi
16648 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
16649 + pushl_cfi %esp
16650 + call sys_execve
16651 + add $4,%esp
16652 + CFI_ADJUST_CFA_OFFSET -4
16653 + GET_THREAD_INFO(%ebp)
16654 + test %eax,%eax
16655 + jz syscall_exit
16656 + add $PT_OLDSS+4,%esp
16657 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
16658 + popl_cfi %ebp
16659 + ret
16660 + CFI_ENDPROC
16661 +ENDPROC(kernel_execve)
16662 +
16663 .macro FIXUP_ESPFIX_STACK
16664 /*
16665 * Switch back for ESPFIX stack to the normal zerobased stack
16666 @@ -772,8 +1034,15 @@ ENDPROC(ptregs_clone)
16667 * normal stack and adjusts ESP with the matching offset.
16668 */
16669 /* fixup the stack */
16670 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
16671 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
16672 +#ifdef CONFIG_SMP
16673 + movl PER_CPU_VAR(cpu_number), %ebx
16674 + shll $PAGE_SHIFT_asm, %ebx
16675 + addl $cpu_gdt_table, %ebx
16676 +#else
16677 + movl $cpu_gdt_table, %ebx
16678 +#endif
16679 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
16680 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
16681 shl $16, %eax
16682 addl %esp, %eax /* the adjusted stack pointer */
16683 pushl_cfi $__KERNEL_DS
16684 @@ -826,7 +1095,7 @@ vector=vector+1
16685 .endr
16686 2: jmp common_interrupt
16687 .endr
16688 -END(irq_entries_start)
16689 +ENDPROC(irq_entries_start)
16690
16691 .previous
16692 END(interrupt)
16693 @@ -877,7 +1146,7 @@ ENTRY(coprocessor_error)
16694 pushl_cfi $do_coprocessor_error
16695 jmp error_code
16696 CFI_ENDPROC
16697 -END(coprocessor_error)
16698 +ENDPROC(coprocessor_error)
16699
16700 ENTRY(simd_coprocessor_error)
16701 RING0_INT_FRAME
16702 @@ -899,7 +1168,7 @@ ENTRY(simd_coprocessor_error)
16703 #endif
16704 jmp error_code
16705 CFI_ENDPROC
16706 -END(simd_coprocessor_error)
16707 +ENDPROC(simd_coprocessor_error)
16708
16709 ENTRY(device_not_available)
16710 RING0_INT_FRAME
16711 @@ -908,18 +1177,18 @@ ENTRY(device_not_available)
16712 pushl_cfi $do_device_not_available
16713 jmp error_code
16714 CFI_ENDPROC
16715 -END(device_not_available)
16716 +ENDPROC(device_not_available)
16717
16718 #ifdef CONFIG_PARAVIRT
16719 ENTRY(native_iret)
16720 iret
16721 _ASM_EXTABLE(native_iret, iret_exc)
16722 -END(native_iret)
16723 +ENDPROC(native_iret)
16724
16725 ENTRY(native_irq_enable_sysexit)
16726 sti
16727 sysexit
16728 -END(native_irq_enable_sysexit)
16729 +ENDPROC(native_irq_enable_sysexit)
16730 #endif
16731
16732 ENTRY(overflow)
16733 @@ -929,7 +1198,7 @@ ENTRY(overflow)
16734 pushl_cfi $do_overflow
16735 jmp error_code
16736 CFI_ENDPROC
16737 -END(overflow)
16738 +ENDPROC(overflow)
16739
16740 ENTRY(bounds)
16741 RING0_INT_FRAME
16742 @@ -938,7 +1207,7 @@ ENTRY(bounds)
16743 pushl_cfi $do_bounds
16744 jmp error_code
16745 CFI_ENDPROC
16746 -END(bounds)
16747 +ENDPROC(bounds)
16748
16749 ENTRY(invalid_op)
16750 RING0_INT_FRAME
16751 @@ -947,7 +1216,7 @@ ENTRY(invalid_op)
16752 pushl_cfi $do_invalid_op
16753 jmp error_code
16754 CFI_ENDPROC
16755 -END(invalid_op)
16756 +ENDPROC(invalid_op)
16757
16758 ENTRY(coprocessor_segment_overrun)
16759 RING0_INT_FRAME
16760 @@ -956,7 +1225,7 @@ ENTRY(coprocessor_segment_overrun)
16761 pushl_cfi $do_coprocessor_segment_overrun
16762 jmp error_code
16763 CFI_ENDPROC
16764 -END(coprocessor_segment_overrun)
16765 +ENDPROC(coprocessor_segment_overrun)
16766
16767 ENTRY(invalid_TSS)
16768 RING0_EC_FRAME
16769 @@ -964,7 +1233,7 @@ ENTRY(invalid_TSS)
16770 pushl_cfi $do_invalid_TSS
16771 jmp error_code
16772 CFI_ENDPROC
16773 -END(invalid_TSS)
16774 +ENDPROC(invalid_TSS)
16775
16776 ENTRY(segment_not_present)
16777 RING0_EC_FRAME
16778 @@ -972,7 +1241,7 @@ ENTRY(segment_not_present)
16779 pushl_cfi $do_segment_not_present
16780 jmp error_code
16781 CFI_ENDPROC
16782 -END(segment_not_present)
16783 +ENDPROC(segment_not_present)
16784
16785 ENTRY(stack_segment)
16786 RING0_EC_FRAME
16787 @@ -980,7 +1249,7 @@ ENTRY(stack_segment)
16788 pushl_cfi $do_stack_segment
16789 jmp error_code
16790 CFI_ENDPROC
16791 -END(stack_segment)
16792 +ENDPROC(stack_segment)
16793
16794 ENTRY(alignment_check)
16795 RING0_EC_FRAME
16796 @@ -988,7 +1257,7 @@ ENTRY(alignment_check)
16797 pushl_cfi $do_alignment_check
16798 jmp error_code
16799 CFI_ENDPROC
16800 -END(alignment_check)
16801 +ENDPROC(alignment_check)
16802
16803 ENTRY(divide_error)
16804 RING0_INT_FRAME
16805 @@ -997,7 +1266,7 @@ ENTRY(divide_error)
16806 pushl_cfi $do_divide_error
16807 jmp error_code
16808 CFI_ENDPROC
16809 -END(divide_error)
16810 +ENDPROC(divide_error)
16811
16812 #ifdef CONFIG_X86_MCE
16813 ENTRY(machine_check)
16814 @@ -1007,7 +1276,7 @@ ENTRY(machine_check)
16815 pushl_cfi machine_check_vector
16816 jmp error_code
16817 CFI_ENDPROC
16818 -END(machine_check)
16819 +ENDPROC(machine_check)
16820 #endif
16821
16822 ENTRY(spurious_interrupt_bug)
16823 @@ -1017,7 +1286,7 @@ ENTRY(spurious_interrupt_bug)
16824 pushl_cfi $do_spurious_interrupt_bug
16825 jmp error_code
16826 CFI_ENDPROC
16827 -END(spurious_interrupt_bug)
16828 +ENDPROC(spurious_interrupt_bug)
16829 /*
16830 * End of kprobes section
16831 */
16832 @@ -1120,7 +1389,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
16833
16834 ENTRY(mcount)
16835 ret
16836 -END(mcount)
16837 +ENDPROC(mcount)
16838
16839 ENTRY(ftrace_caller)
16840 cmpl $0, function_trace_stop
16841 @@ -1153,7 +1422,7 @@ ftrace_graph_call:
16842 .globl ftrace_stub
16843 ftrace_stub:
16844 ret
16845 -END(ftrace_caller)
16846 +ENDPROC(ftrace_caller)
16847
16848 ENTRY(ftrace_regs_caller)
16849 pushf /* push flags before compare (in cs location) */
16850 @@ -1254,7 +1523,7 @@ trace:
16851 popl %ecx
16852 popl %eax
16853 jmp ftrace_stub
16854 -END(mcount)
16855 +ENDPROC(mcount)
16856 #endif /* CONFIG_DYNAMIC_FTRACE */
16857 #endif /* CONFIG_FUNCTION_TRACER */
16858
16859 @@ -1272,7 +1541,7 @@ ENTRY(ftrace_graph_caller)
16860 popl %ecx
16861 popl %eax
16862 ret
16863 -END(ftrace_graph_caller)
16864 +ENDPROC(ftrace_graph_caller)
16865
16866 .globl return_to_handler
16867 return_to_handler:
16868 @@ -1328,15 +1597,18 @@ error_code:
16869 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
16870 REG_TO_PTGS %ecx
16871 SET_KERNEL_GS %ecx
16872 - movl $(__USER_DS), %ecx
16873 + movl $(__KERNEL_DS), %ecx
16874 movl %ecx, %ds
16875 movl %ecx, %es
16876 +
16877 + pax_enter_kernel
16878 +
16879 TRACE_IRQS_OFF
16880 movl %esp,%eax # pt_regs pointer
16881 call *%edi
16882 jmp ret_from_exception
16883 CFI_ENDPROC
16884 -END(page_fault)
16885 +ENDPROC(page_fault)
16886
16887 /*
16888 * Debug traps and NMI can happen at the one SYSENTER instruction
16889 @@ -1379,7 +1651,7 @@ debug_stack_correct:
16890 call do_debug
16891 jmp ret_from_exception
16892 CFI_ENDPROC
16893 -END(debug)
16894 +ENDPROC(debug)
16895
16896 /*
16897 * NMI is doubly nasty. It can happen _while_ we're handling
16898 @@ -1417,6 +1689,9 @@ nmi_stack_correct:
16899 xorl %edx,%edx # zero error code
16900 movl %esp,%eax # pt_regs pointer
16901 call do_nmi
16902 +
16903 + pax_exit_kernel
16904 +
16905 jmp restore_all_notrace
16906 CFI_ENDPROC
16907
16908 @@ -1453,12 +1728,15 @@ nmi_espfix_stack:
16909 FIXUP_ESPFIX_STACK # %eax == %esp
16910 xorl %edx,%edx # zero error code
16911 call do_nmi
16912 +
16913 + pax_exit_kernel
16914 +
16915 RESTORE_REGS
16916 lss 12+4(%esp), %esp # back to espfix stack
16917 CFI_ADJUST_CFA_OFFSET -24
16918 jmp irq_return
16919 CFI_ENDPROC
16920 -END(nmi)
16921 +ENDPROC(nmi)
16922
16923 ENTRY(int3)
16924 RING0_INT_FRAME
16925 @@ -1471,14 +1749,14 @@ ENTRY(int3)
16926 call do_int3
16927 jmp ret_from_exception
16928 CFI_ENDPROC
16929 -END(int3)
16930 +ENDPROC(int3)
16931
16932 ENTRY(general_protection)
16933 RING0_EC_FRAME
16934 pushl_cfi $do_general_protection
16935 jmp error_code
16936 CFI_ENDPROC
16937 -END(general_protection)
16938 +ENDPROC(general_protection)
16939
16940 #ifdef CONFIG_KVM_GUEST
16941 ENTRY(async_page_fault)
16942 @@ -1487,7 +1765,7 @@ ENTRY(async_page_fault)
16943 pushl_cfi $do_async_page_fault
16944 jmp error_code
16945 CFI_ENDPROC
16946 -END(async_page_fault)
16947 +ENDPROC(async_page_fault)
16948 #endif
16949
16950 /*
16951 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
16952 index 1328fe4..cb03298 100644
16953 --- a/arch/x86/kernel/entry_64.S
16954 +++ b/arch/x86/kernel/entry_64.S
16955 @@ -59,6 +59,8 @@
16956 #include <asm/rcu.h>
16957 #include <asm/smap.h>
16958 #include <linux/err.h>
16959 +#include <asm/pgtable.h>
16960 +#include <asm/alternative-asm.h>
16961
16962 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
16963 #include <linux/elf-em.h>
16964 @@ -80,8 +82,9 @@
16965 #ifdef CONFIG_DYNAMIC_FTRACE
16966
16967 ENTRY(function_hook)
16968 + pax_force_retaddr
16969 retq
16970 -END(function_hook)
16971 +ENDPROC(function_hook)
16972
16973 /* skip is set if stack has been adjusted */
16974 .macro ftrace_caller_setup skip=0
16975 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
16976 #endif
16977
16978 GLOBAL(ftrace_stub)
16979 + pax_force_retaddr
16980 retq
16981 -END(ftrace_caller)
16982 +ENDPROC(ftrace_caller)
16983
16984 ENTRY(ftrace_regs_caller)
16985 /* Save the current flags before compare (in SS location)*/
16986 @@ -191,7 +195,7 @@ ftrace_restore_flags:
16987 popfq
16988 jmp ftrace_stub
16989
16990 -END(ftrace_regs_caller)
16991 +ENDPROC(ftrace_regs_caller)
16992
16993
16994 #else /* ! CONFIG_DYNAMIC_FTRACE */
16995 @@ -212,6 +216,7 @@ ENTRY(function_hook)
16996 #endif
16997
16998 GLOBAL(ftrace_stub)
16999 + pax_force_retaddr
17000 retq
17001
17002 trace:
17003 @@ -225,12 +230,13 @@ trace:
17004 #endif
17005 subq $MCOUNT_INSN_SIZE, %rdi
17006
17007 + pax_force_fptr ftrace_trace_function
17008 call *ftrace_trace_function
17009
17010 MCOUNT_RESTORE_FRAME
17011
17012 jmp ftrace_stub
17013 -END(function_hook)
17014 +ENDPROC(function_hook)
17015 #endif /* CONFIG_DYNAMIC_FTRACE */
17016 #endif /* CONFIG_FUNCTION_TRACER */
17017
17018 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
17019
17020 MCOUNT_RESTORE_FRAME
17021
17022 + pax_force_retaddr
17023 retq
17024 -END(ftrace_graph_caller)
17025 +ENDPROC(ftrace_graph_caller)
17026
17027 GLOBAL(return_to_handler)
17028 subq $24, %rsp
17029 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
17030 movq 8(%rsp), %rdx
17031 movq (%rsp), %rax
17032 addq $24, %rsp
17033 + pax_force_fptr %rdi
17034 jmp *%rdi
17035 +ENDPROC(return_to_handler)
17036 #endif
17037
17038
17039 @@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
17040 ENDPROC(native_usergs_sysret64)
17041 #endif /* CONFIG_PARAVIRT */
17042
17043 + .macro ljmpq sel, off
17044 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
17045 + .byte 0x48; ljmp *1234f(%rip)
17046 + .pushsection .rodata
17047 + .align 16
17048 + 1234: .quad \off; .word \sel
17049 + .popsection
17050 +#else
17051 + pushq $\sel
17052 + pushq $\off
17053 + lretq
17054 +#endif
17055 + .endm
17056 +
17057 + .macro pax_enter_kernel
17058 + pax_set_fptr_mask
17059 +#ifdef CONFIG_PAX_KERNEXEC
17060 + call pax_enter_kernel
17061 +#endif
17062 + .endm
17063 +
17064 + .macro pax_exit_kernel
17065 +#ifdef CONFIG_PAX_KERNEXEC
17066 + call pax_exit_kernel
17067 +#endif
17068 + .endm
17069 +
17070 +#ifdef CONFIG_PAX_KERNEXEC
17071 +ENTRY(pax_enter_kernel)
17072 + pushq %rdi
17073 +
17074 +#ifdef CONFIG_PARAVIRT
17075 + PV_SAVE_REGS(CLBR_RDI)
17076 +#endif
17077 +
17078 + GET_CR0_INTO_RDI
17079 + bts $16,%rdi
17080 + jnc 3f
17081 + mov %cs,%edi
17082 + cmp $__KERNEL_CS,%edi
17083 + jnz 2f
17084 +1:
17085 +
17086 +#ifdef CONFIG_PARAVIRT
17087 + PV_RESTORE_REGS(CLBR_RDI)
17088 +#endif
17089 +
17090 + popq %rdi
17091 + pax_force_retaddr
17092 + retq
17093 +
17094 +2: ljmpq __KERNEL_CS,1f
17095 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
17096 +4: SET_RDI_INTO_CR0
17097 + jmp 1b
17098 +ENDPROC(pax_enter_kernel)
17099 +
17100 +ENTRY(pax_exit_kernel)
17101 + pushq %rdi
17102 +
17103 +#ifdef CONFIG_PARAVIRT
17104 + PV_SAVE_REGS(CLBR_RDI)
17105 +#endif
17106 +
17107 + mov %cs,%rdi
17108 + cmp $__KERNEXEC_KERNEL_CS,%edi
17109 + jz 2f
17110 +1:
17111 +
17112 +#ifdef CONFIG_PARAVIRT
17113 + PV_RESTORE_REGS(CLBR_RDI);
17114 +#endif
17115 +
17116 + popq %rdi
17117 + pax_force_retaddr
17118 + retq
17119 +
17120 +2: GET_CR0_INTO_RDI
17121 + btr $16,%rdi
17122 + ljmpq __KERNEL_CS,3f
17123 +3: SET_RDI_INTO_CR0
17124 + jmp 1b
17125 +ENDPROC(pax_exit_kernel)
17126 +#endif
17127 +
17128 + .macro pax_enter_kernel_user
17129 + pax_set_fptr_mask
17130 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17131 + call pax_enter_kernel_user
17132 +#endif
17133 + .endm
17134 +
17135 + .macro pax_exit_kernel_user
17136 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17137 + call pax_exit_kernel_user
17138 +#endif
17139 +#ifdef CONFIG_PAX_RANDKSTACK
17140 + pushq %rax
17141 + call pax_randomize_kstack
17142 + popq %rax
17143 +#endif
17144 + .endm
17145 +
17146 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17147 +ENTRY(pax_enter_kernel_user)
17148 + pushq %rdi
17149 + pushq %rbx
17150 +
17151 +#ifdef CONFIG_PARAVIRT
17152 + PV_SAVE_REGS(CLBR_RDI)
17153 +#endif
17154 +
17155 + GET_CR3_INTO_RDI
17156 + mov %rdi,%rbx
17157 + add $__START_KERNEL_map,%rbx
17158 + sub phys_base(%rip),%rbx
17159 +
17160 +#ifdef CONFIG_PARAVIRT
17161 + pushq %rdi
17162 + cmpl $0, pv_info+PARAVIRT_enabled
17163 + jz 1f
17164 + i = 0
17165 + .rept USER_PGD_PTRS
17166 + mov i*8(%rbx),%rsi
17167 + mov $0,%sil
17168 + lea i*8(%rbx),%rdi
17169 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17170 + i = i + 1
17171 + .endr
17172 + jmp 2f
17173 +1:
17174 +#endif
17175 +
17176 + i = 0
17177 + .rept USER_PGD_PTRS
17178 + movb $0,i*8(%rbx)
17179 + i = i + 1
17180 + .endr
17181 +
17182 +#ifdef CONFIG_PARAVIRT
17183 +2: popq %rdi
17184 +#endif
17185 + SET_RDI_INTO_CR3
17186 +
17187 +#ifdef CONFIG_PAX_KERNEXEC
17188 + GET_CR0_INTO_RDI
17189 + bts $16,%rdi
17190 + SET_RDI_INTO_CR0
17191 +#endif
17192 +
17193 +#ifdef CONFIG_PARAVIRT
17194 + PV_RESTORE_REGS(CLBR_RDI)
17195 +#endif
17196 +
17197 + popq %rbx
17198 + popq %rdi
17199 + pax_force_retaddr
17200 + retq
17201 +ENDPROC(pax_enter_kernel_user)
17202 +
17203 +ENTRY(pax_exit_kernel_user)
17204 + push %rdi
17205 +
17206 +#ifdef CONFIG_PARAVIRT
17207 + pushq %rbx
17208 + PV_SAVE_REGS(CLBR_RDI)
17209 +#endif
17210 +
17211 +#ifdef CONFIG_PAX_KERNEXEC
17212 + GET_CR0_INTO_RDI
17213 + btr $16,%rdi
17214 + SET_RDI_INTO_CR0
17215 +#endif
17216 +
17217 + GET_CR3_INTO_RDI
17218 + add $__START_KERNEL_map,%rdi
17219 + sub phys_base(%rip),%rdi
17220 +
17221 +#ifdef CONFIG_PARAVIRT
17222 + cmpl $0, pv_info+PARAVIRT_enabled
17223 + jz 1f
17224 + mov %rdi,%rbx
17225 + i = 0
17226 + .rept USER_PGD_PTRS
17227 + mov i*8(%rbx),%rsi
17228 + mov $0x67,%sil
17229 + lea i*8(%rbx),%rdi
17230 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17231 + i = i + 1
17232 + .endr
17233 + jmp 2f
17234 +1:
17235 +#endif
17236 +
17237 + i = 0
17238 + .rept USER_PGD_PTRS
17239 + movb $0x67,i*8(%rdi)
17240 + i = i + 1
17241 + .endr
17242 +
17243 +#ifdef CONFIG_PARAVIRT
17244 +2: PV_RESTORE_REGS(CLBR_RDI)
17245 + popq %rbx
17246 +#endif
17247 +
17248 + popq %rdi
17249 + pax_force_retaddr
17250 + retq
17251 +ENDPROC(pax_exit_kernel_user)
17252 +#endif
17253 +
17254 +.macro pax_erase_kstack
17255 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17256 + call pax_erase_kstack
17257 +#endif
17258 +.endm
17259 +
17260 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17261 +ENTRY(pax_erase_kstack)
17262 + pushq %rdi
17263 + pushq %rcx
17264 + pushq %rax
17265 + pushq %r11
17266 +
17267 + GET_THREAD_INFO(%r11)
17268 + mov TI_lowest_stack(%r11), %rdi
17269 + mov $-0xBEEF, %rax
17270 + std
17271 +
17272 +1: mov %edi, %ecx
17273 + and $THREAD_SIZE_asm - 1, %ecx
17274 + shr $3, %ecx
17275 + repne scasq
17276 + jecxz 2f
17277 +
17278 + cmp $2*8, %ecx
17279 + jc 2f
17280 +
17281 + mov $2*8, %ecx
17282 + repe scasq
17283 + jecxz 2f
17284 + jne 1b
17285 +
17286 +2: cld
17287 + mov %esp, %ecx
17288 + sub %edi, %ecx
17289 +
17290 + cmp $THREAD_SIZE_asm, %rcx
17291 + jb 3f
17292 + ud2
17293 +3:
17294 +
17295 + shr $3, %ecx
17296 + rep stosq
17297 +
17298 + mov TI_task_thread_sp0(%r11), %rdi
17299 + sub $256, %rdi
17300 + mov %rdi, TI_lowest_stack(%r11)
17301 +
17302 + popq %r11
17303 + popq %rax
17304 + popq %rcx
17305 + popq %rdi
17306 + pax_force_retaddr
17307 + ret
17308 +ENDPROC(pax_erase_kstack)
17309 +#endif
17310
17311 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
17312 #ifdef CONFIG_TRACE_IRQFLAGS
17313 @@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
17314 .endm
17315
17316 .macro UNFAKE_STACK_FRAME
17317 - addq $8*6, %rsp
17318 - CFI_ADJUST_CFA_OFFSET -(6*8)
17319 + addq $8*6 + ARG_SKIP, %rsp
17320 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
17321 .endm
17322
17323 /*
17324 @@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
17325 movq %rsp, %rsi
17326
17327 leaq -RBP(%rsp),%rdi /* arg1 for handler */
17328 - testl $3, CS-RBP(%rsi)
17329 + testb $3, CS-RBP(%rsi)
17330 je 1f
17331 SWAPGS
17332 /*
17333 @@ -498,9 +774,10 @@ ENTRY(save_rest)
17334 movq_cfi r15, R15+16
17335 movq %r11, 8(%rsp) /* return address */
17336 FIXUP_TOP_OF_STACK %r11, 16
17337 + pax_force_retaddr
17338 ret
17339 CFI_ENDPROC
17340 -END(save_rest)
17341 +ENDPROC(save_rest)
17342
17343 /* save complete stack frame */
17344 .pushsection .kprobes.text, "ax"
17345 @@ -529,9 +806,10 @@ ENTRY(save_paranoid)
17346 js 1f /* negative -> in kernel */
17347 SWAPGS
17348 xorl %ebx,%ebx
17349 -1: ret
17350 +1: pax_force_retaddr_bts
17351 + ret
17352 CFI_ENDPROC
17353 -END(save_paranoid)
17354 +ENDPROC(save_paranoid)
17355 .popsection
17356
17357 /*
17358 @@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
17359
17360 RESTORE_REST
17361
17362 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17363 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17364 jz 1f
17365
17366 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
17367 @@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
17368 RESTORE_REST
17369 jmp int_ret_from_sys_call
17370 CFI_ENDPROC
17371 -END(ret_from_fork)
17372 +ENDPROC(ret_from_fork)
17373
17374 /*
17375 * System call entry. Up to 6 arguments in registers are supported.
17376 @@ -608,7 +886,7 @@ END(ret_from_fork)
17377 ENTRY(system_call)
17378 CFI_STARTPROC simple
17379 CFI_SIGNAL_FRAME
17380 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
17381 + CFI_DEF_CFA rsp,0
17382 CFI_REGISTER rip,rcx
17383 /*CFI_REGISTER rflags,r11*/
17384 SWAPGS_UNSAFE_STACK
17385 @@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
17386
17387 movq %rsp,PER_CPU_VAR(old_rsp)
17388 movq PER_CPU_VAR(kernel_stack),%rsp
17389 + SAVE_ARGS 8*6,0
17390 + pax_enter_kernel_user
17391 +
17392 +#ifdef CONFIG_PAX_RANDKSTACK
17393 + pax_erase_kstack
17394 +#endif
17395 +
17396 /*
17397 * No need to follow this irqs off/on section - it's straight
17398 * and short:
17399 */
17400 ENABLE_INTERRUPTS(CLBR_NONE)
17401 - SAVE_ARGS 8,0
17402 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
17403 movq %rcx,RIP-ARGOFFSET(%rsp)
17404 CFI_REL_OFFSET rip,RIP-ARGOFFSET
17405 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17406 + GET_THREAD_INFO(%rcx)
17407 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
17408 jnz tracesys
17409 system_call_fastpath:
17410 #if __SYSCALL_MASK == ~0
17411 @@ -640,7 +925,7 @@ system_call_fastpath:
17412 cmpl $__NR_syscall_max,%eax
17413 #endif
17414 ja badsys
17415 - movq %r10,%rcx
17416 + movq R10-ARGOFFSET(%rsp),%rcx
17417 call *sys_call_table(,%rax,8) # XXX: rip relative
17418 movq %rax,RAX-ARGOFFSET(%rsp)
17419 /*
17420 @@ -654,10 +939,13 @@ sysret_check:
17421 LOCKDEP_SYS_EXIT
17422 DISABLE_INTERRUPTS(CLBR_NONE)
17423 TRACE_IRQS_OFF
17424 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
17425 + GET_THREAD_INFO(%rcx)
17426 + movl TI_flags(%rcx),%edx
17427 andl %edi,%edx
17428 jnz sysret_careful
17429 CFI_REMEMBER_STATE
17430 + pax_exit_kernel_user
17431 + pax_erase_kstack
17432 /*
17433 * sysretq will re-enable interrupts:
17434 */
17435 @@ -709,14 +997,18 @@ badsys:
17436 * jump back to the normal fast path.
17437 */
17438 auditsys:
17439 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
17440 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
17441 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
17442 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
17443 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
17444 movq %rax,%rsi /* 2nd arg: syscall number */
17445 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
17446 call __audit_syscall_entry
17447 +
17448 + pax_erase_kstack
17449 +
17450 LOAD_ARGS 0 /* reload call-clobbered registers */
17451 + pax_set_fptr_mask
17452 jmp system_call_fastpath
17453
17454 /*
17455 @@ -737,7 +1029,7 @@ sysret_audit:
17456 /* Do syscall tracing */
17457 tracesys:
17458 #ifdef CONFIG_AUDITSYSCALL
17459 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17460 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
17461 jz auditsys
17462 #endif
17463 SAVE_REST
17464 @@ -745,12 +1037,16 @@ tracesys:
17465 FIXUP_TOP_OF_STACK %rdi
17466 movq %rsp,%rdi
17467 call syscall_trace_enter
17468 +
17469 + pax_erase_kstack
17470 +
17471 /*
17472 * Reload arg registers from stack in case ptrace changed them.
17473 * We don't reload %rax because syscall_trace_enter() returned
17474 * the value it wants us to use in the table lookup.
17475 */
17476 LOAD_ARGS ARGOFFSET, 1
17477 + pax_set_fptr_mask
17478 RESTORE_REST
17479 #if __SYSCALL_MASK == ~0
17480 cmpq $__NR_syscall_max,%rax
17481 @@ -759,7 +1055,7 @@ tracesys:
17482 cmpl $__NR_syscall_max,%eax
17483 #endif
17484 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
17485 - movq %r10,%rcx /* fixup for C */
17486 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
17487 call *sys_call_table(,%rax,8)
17488 movq %rax,RAX-ARGOFFSET(%rsp)
17489 /* Use IRET because user could have changed frame */
17490 @@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
17491 andl %edi,%edx
17492 jnz int_careful
17493 andl $~TS_COMPAT,TI_status(%rcx)
17494 - jmp retint_swapgs
17495 + pax_exit_kernel_user
17496 + pax_erase_kstack
17497 + jmp retint_swapgs_pax
17498
17499 /* Either reschedule or signal or syscall exit tracking needed. */
17500 /* First do a reschedule test. */
17501 @@ -826,7 +1124,7 @@ int_restore_rest:
17502 TRACE_IRQS_OFF
17503 jmp int_with_check
17504 CFI_ENDPROC
17505 -END(system_call)
17506 +ENDPROC(system_call)
17507
17508 /*
17509 * Certain special system calls that need to save a complete full stack frame.
17510 @@ -842,7 +1140,7 @@ ENTRY(\label)
17511 call \func
17512 jmp ptregscall_common
17513 CFI_ENDPROC
17514 -END(\label)
17515 +ENDPROC(\label)
17516 .endm
17517
17518 PTREGSCALL stub_clone, sys_clone, %r8
17519 @@ -860,9 +1158,10 @@ ENTRY(ptregscall_common)
17520 movq_cfi_restore R12+8, r12
17521 movq_cfi_restore RBP+8, rbp
17522 movq_cfi_restore RBX+8, rbx
17523 + pax_force_retaddr
17524 ret $REST_SKIP /* pop extended registers */
17525 CFI_ENDPROC
17526 -END(ptregscall_common)
17527 +ENDPROC(ptregscall_common)
17528
17529 ENTRY(stub_execve)
17530 CFI_STARTPROC
17531 @@ -876,7 +1175,7 @@ ENTRY(stub_execve)
17532 RESTORE_REST
17533 jmp int_ret_from_sys_call
17534 CFI_ENDPROC
17535 -END(stub_execve)
17536 +ENDPROC(stub_execve)
17537
17538 /*
17539 * sigreturn is special because it needs to restore all registers on return.
17540 @@ -894,7 +1193,7 @@ ENTRY(stub_rt_sigreturn)
17541 RESTORE_REST
17542 jmp int_ret_from_sys_call
17543 CFI_ENDPROC
17544 -END(stub_rt_sigreturn)
17545 +ENDPROC(stub_rt_sigreturn)
17546
17547 #ifdef CONFIG_X86_X32_ABI
17548 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
17549 @@ -962,7 +1261,7 @@ vector=vector+1
17550 2: jmp common_interrupt
17551 .endr
17552 CFI_ENDPROC
17553 -END(irq_entries_start)
17554 +ENDPROC(irq_entries_start)
17555
17556 .previous
17557 END(interrupt)
17558 @@ -982,6 +1281,16 @@ END(interrupt)
17559 subq $ORIG_RAX-RBP, %rsp
17560 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
17561 SAVE_ARGS_IRQ
17562 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17563 + testb $3, CS(%rdi)
17564 + jnz 1f
17565 + pax_enter_kernel
17566 + jmp 2f
17567 +1: pax_enter_kernel_user
17568 +2:
17569 +#else
17570 + pax_enter_kernel
17571 +#endif
17572 call \func
17573 .endm
17574
17575 @@ -1014,7 +1323,7 @@ ret_from_intr:
17576
17577 exit_intr:
17578 GET_THREAD_INFO(%rcx)
17579 - testl $3,CS-ARGOFFSET(%rsp)
17580 + testb $3,CS-ARGOFFSET(%rsp)
17581 je retint_kernel
17582
17583 /* Interrupt came from user space */
17584 @@ -1036,12 +1345,16 @@ retint_swapgs: /* return to user-space */
17585 * The iretq could re-enable interrupts:
17586 */
17587 DISABLE_INTERRUPTS(CLBR_ANY)
17588 + pax_exit_kernel_user
17589 +retint_swapgs_pax:
17590 TRACE_IRQS_IRETQ
17591 SWAPGS
17592 jmp restore_args
17593
17594 retint_restore_args: /* return to kernel space */
17595 DISABLE_INTERRUPTS(CLBR_ANY)
17596 + pax_exit_kernel
17597 + pax_force_retaddr (RIP-ARGOFFSET)
17598 /*
17599 * The iretq could re-enable interrupts:
17600 */
17601 @@ -1124,7 +1437,7 @@ ENTRY(retint_kernel)
17602 #endif
17603
17604 CFI_ENDPROC
17605 -END(common_interrupt)
17606 +ENDPROC(common_interrupt)
17607 /*
17608 * End of kprobes section
17609 */
17610 @@ -1142,7 +1455,7 @@ ENTRY(\sym)
17611 interrupt \do_sym
17612 jmp ret_from_intr
17613 CFI_ENDPROC
17614 -END(\sym)
17615 +ENDPROC(\sym)
17616 .endm
17617
17618 #ifdef CONFIG_SMP
17619 @@ -1198,12 +1511,22 @@ ENTRY(\sym)
17620 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17621 call error_entry
17622 DEFAULT_FRAME 0
17623 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17624 + testb $3, CS(%rsp)
17625 + jnz 1f
17626 + pax_enter_kernel
17627 + jmp 2f
17628 +1: pax_enter_kernel_user
17629 +2:
17630 +#else
17631 + pax_enter_kernel
17632 +#endif
17633 movq %rsp,%rdi /* pt_regs pointer */
17634 xorl %esi,%esi /* no error code */
17635 call \do_sym
17636 jmp error_exit /* %ebx: no swapgs flag */
17637 CFI_ENDPROC
17638 -END(\sym)
17639 +ENDPROC(\sym)
17640 .endm
17641
17642 .macro paranoidzeroentry sym do_sym
17643 @@ -1216,15 +1539,25 @@ ENTRY(\sym)
17644 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17645 call save_paranoid
17646 TRACE_IRQS_OFF
17647 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17648 + testb $3, CS(%rsp)
17649 + jnz 1f
17650 + pax_enter_kernel
17651 + jmp 2f
17652 +1: pax_enter_kernel_user
17653 +2:
17654 +#else
17655 + pax_enter_kernel
17656 +#endif
17657 movq %rsp,%rdi /* pt_regs pointer */
17658 xorl %esi,%esi /* no error code */
17659 call \do_sym
17660 jmp paranoid_exit /* %ebx: no swapgs flag */
17661 CFI_ENDPROC
17662 -END(\sym)
17663 +ENDPROC(\sym)
17664 .endm
17665
17666 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
17667 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
17668 .macro paranoidzeroentry_ist sym do_sym ist
17669 ENTRY(\sym)
17670 INTR_FRAME
17671 @@ -1235,14 +1568,30 @@ ENTRY(\sym)
17672 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17673 call save_paranoid
17674 TRACE_IRQS_OFF_DEBUG
17675 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17676 + testb $3, CS(%rsp)
17677 + jnz 1f
17678 + pax_enter_kernel
17679 + jmp 2f
17680 +1: pax_enter_kernel_user
17681 +2:
17682 +#else
17683 + pax_enter_kernel
17684 +#endif
17685 movq %rsp,%rdi /* pt_regs pointer */
17686 xorl %esi,%esi /* no error code */
17687 +#ifdef CONFIG_SMP
17688 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
17689 + lea init_tss(%r12), %r12
17690 +#else
17691 + lea init_tss(%rip), %r12
17692 +#endif
17693 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17694 call \do_sym
17695 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17696 jmp paranoid_exit /* %ebx: no swapgs flag */
17697 CFI_ENDPROC
17698 -END(\sym)
17699 +ENDPROC(\sym)
17700 .endm
17701
17702 .macro errorentry sym do_sym
17703 @@ -1254,13 +1603,23 @@ ENTRY(\sym)
17704 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17705 call error_entry
17706 DEFAULT_FRAME 0
17707 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17708 + testb $3, CS(%rsp)
17709 + jnz 1f
17710 + pax_enter_kernel
17711 + jmp 2f
17712 +1: pax_enter_kernel_user
17713 +2:
17714 +#else
17715 + pax_enter_kernel
17716 +#endif
17717 movq %rsp,%rdi /* pt_regs pointer */
17718 movq ORIG_RAX(%rsp),%rsi /* get error code */
17719 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17720 call \do_sym
17721 jmp error_exit /* %ebx: no swapgs flag */
17722 CFI_ENDPROC
17723 -END(\sym)
17724 +ENDPROC(\sym)
17725 .endm
17726
17727 /* error code is on the stack already */
17728 @@ -1274,13 +1633,23 @@ ENTRY(\sym)
17729 call save_paranoid
17730 DEFAULT_FRAME 0
17731 TRACE_IRQS_OFF
17732 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17733 + testb $3, CS(%rsp)
17734 + jnz 1f
17735 + pax_enter_kernel
17736 + jmp 2f
17737 +1: pax_enter_kernel_user
17738 +2:
17739 +#else
17740 + pax_enter_kernel
17741 +#endif
17742 movq %rsp,%rdi /* pt_regs pointer */
17743 movq ORIG_RAX(%rsp),%rsi /* get error code */
17744 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17745 call \do_sym
17746 jmp paranoid_exit /* %ebx: no swapgs flag */
17747 CFI_ENDPROC
17748 -END(\sym)
17749 +ENDPROC(\sym)
17750 .endm
17751
17752 zeroentry divide_error do_divide_error
17753 @@ -1310,9 +1679,10 @@ gs_change:
17754 2: mfence /* workaround */
17755 SWAPGS
17756 popfq_cfi
17757 + pax_force_retaddr
17758 ret
17759 CFI_ENDPROC
17760 -END(native_load_gs_index)
17761 +ENDPROC(native_load_gs_index)
17762
17763 _ASM_EXTABLE(gs_change,bad_gs)
17764 .section .fixup,"ax"
17765 @@ -1340,9 +1710,10 @@ ENTRY(call_softirq)
17766 CFI_DEF_CFA_REGISTER rsp
17767 CFI_ADJUST_CFA_OFFSET -8
17768 decl PER_CPU_VAR(irq_count)
17769 + pax_force_retaddr
17770 ret
17771 CFI_ENDPROC
17772 -END(call_softirq)
17773 +ENDPROC(call_softirq)
17774
17775 #ifdef CONFIG_XEN
17776 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
17777 @@ -1380,7 +1751,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
17778 decl PER_CPU_VAR(irq_count)
17779 jmp error_exit
17780 CFI_ENDPROC
17781 -END(xen_do_hypervisor_callback)
17782 +ENDPROC(xen_do_hypervisor_callback)
17783
17784 /*
17785 * Hypervisor uses this for application faults while it executes.
17786 @@ -1439,7 +1810,7 @@ ENTRY(xen_failsafe_callback)
17787 SAVE_ALL
17788 jmp error_exit
17789 CFI_ENDPROC
17790 -END(xen_failsafe_callback)
17791 +ENDPROC(xen_failsafe_callback)
17792
17793 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
17794 xen_hvm_callback_vector xen_evtchn_do_upcall
17795 @@ -1488,16 +1859,31 @@ ENTRY(paranoid_exit)
17796 TRACE_IRQS_OFF_DEBUG
17797 testl %ebx,%ebx /* swapgs needed? */
17798 jnz paranoid_restore
17799 - testl $3,CS(%rsp)
17800 + testb $3,CS(%rsp)
17801 jnz paranoid_userspace
17802 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17803 + pax_exit_kernel
17804 + TRACE_IRQS_IRETQ 0
17805 + SWAPGS_UNSAFE_STACK
17806 + RESTORE_ALL 8
17807 + pax_force_retaddr_bts
17808 + jmp irq_return
17809 +#endif
17810 paranoid_swapgs:
17811 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17812 + pax_exit_kernel_user
17813 +#else
17814 + pax_exit_kernel
17815 +#endif
17816 TRACE_IRQS_IRETQ 0
17817 SWAPGS_UNSAFE_STACK
17818 RESTORE_ALL 8
17819 jmp irq_return
17820 paranoid_restore:
17821 + pax_exit_kernel
17822 TRACE_IRQS_IRETQ_DEBUG 0
17823 RESTORE_ALL 8
17824 + pax_force_retaddr_bts
17825 jmp irq_return
17826 paranoid_userspace:
17827 GET_THREAD_INFO(%rcx)
17828 @@ -1526,7 +1912,7 @@ paranoid_schedule:
17829 TRACE_IRQS_OFF
17830 jmp paranoid_userspace
17831 CFI_ENDPROC
17832 -END(paranoid_exit)
17833 +ENDPROC(paranoid_exit)
17834
17835 /*
17836 * Exception entry point. This expects an error code/orig_rax on the stack.
17837 @@ -1553,12 +1939,13 @@ ENTRY(error_entry)
17838 movq_cfi r14, R14+8
17839 movq_cfi r15, R15+8
17840 xorl %ebx,%ebx
17841 - testl $3,CS+8(%rsp)
17842 + testb $3,CS+8(%rsp)
17843 je error_kernelspace
17844 error_swapgs:
17845 SWAPGS
17846 error_sti:
17847 TRACE_IRQS_OFF
17848 + pax_force_retaddr_bts
17849 ret
17850
17851 /*
17852 @@ -1585,7 +1972,7 @@ bstep_iret:
17853 movq %rcx,RIP+8(%rsp)
17854 jmp error_swapgs
17855 CFI_ENDPROC
17856 -END(error_entry)
17857 +ENDPROC(error_entry)
17858
17859
17860 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
17861 @@ -1605,7 +1992,7 @@ ENTRY(error_exit)
17862 jnz retint_careful
17863 jmp retint_swapgs
17864 CFI_ENDPROC
17865 -END(error_exit)
17866 +ENDPROC(error_exit)
17867
17868 /*
17869 * Test if a given stack is an NMI stack or not.
17870 @@ -1663,9 +2050,11 @@ ENTRY(nmi)
17871 * If %cs was not the kernel segment, then the NMI triggered in user
17872 * space, which means it is definitely not nested.
17873 */
17874 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
17875 + je 1f
17876 cmpl $__KERNEL_CS, 16(%rsp)
17877 jne first_nmi
17878 -
17879 +1:
17880 /*
17881 * Check the special variable on the stack to see if NMIs are
17882 * executing.
17883 @@ -1824,6 +2213,17 @@ end_repeat_nmi:
17884 */
17885 movq %cr2, %r12
17886
17887 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17888 + testb $3, CS(%rsp)
17889 + jnz 1f
17890 + pax_enter_kernel
17891 + jmp 2f
17892 +1: pax_enter_kernel_user
17893 +2:
17894 +#else
17895 + pax_enter_kernel
17896 +#endif
17897 +
17898 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
17899 movq %rsp,%rdi
17900 movq $-1,%rsi
17901 @@ -1839,21 +2239,32 @@ end_repeat_nmi:
17902 testl %ebx,%ebx /* swapgs needed? */
17903 jnz nmi_restore
17904 nmi_swapgs:
17905 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17906 + pax_exit_kernel_user
17907 +#else
17908 + pax_exit_kernel
17909 +#endif
17910 SWAPGS_UNSAFE_STACK
17911 + RESTORE_ALL 8
17912 + /* Clear the NMI executing stack variable */
17913 + movq $0, 10*8(%rsp)
17914 + jmp irq_return
17915 nmi_restore:
17916 + pax_exit_kernel
17917 RESTORE_ALL 8
17918 + pax_force_retaddr_bts
17919 /* Clear the NMI executing stack variable */
17920 movq $0, 10*8(%rsp)
17921 jmp irq_return
17922 CFI_ENDPROC
17923 -END(nmi)
17924 +ENDPROC(nmi)
17925
17926 ENTRY(ignore_sysret)
17927 CFI_STARTPROC
17928 mov $-ENOSYS,%eax
17929 sysret
17930 CFI_ENDPROC
17931 -END(ignore_sysret)
17932 +ENDPROC(ignore_sysret)
17933
17934 /*
17935 * End of kprobes section
17936 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
17937 index 1d41402..af9a46a 100644
17938 --- a/arch/x86/kernel/ftrace.c
17939 +++ b/arch/x86/kernel/ftrace.c
17940 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
17941 {
17942 unsigned char replaced[MCOUNT_INSN_SIZE];
17943
17944 + ip = ktla_ktva(ip);
17945 +
17946 /*
17947 * Note: Due to modules and __init, code can
17948 * disappear and change, we need to protect against faulting
17949 @@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
17950 unsigned char old[MCOUNT_INSN_SIZE], *new;
17951 int ret;
17952
17953 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
17954 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
17955 new = ftrace_call_replace(ip, (unsigned long)func);
17956
17957 /* See comment above by declaration of modifying_ftrace_code */
17958 @@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
17959 /* Also update the regs callback function */
17960 if (!ret) {
17961 ip = (unsigned long)(&ftrace_regs_call);
17962 - memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
17963 + memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
17964 new = ftrace_call_replace(ip, (unsigned long)func);
17965 ret = ftrace_modify_code(ip, old, new);
17966 }
17967 @@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
17968 * kernel identity mapping to modify code.
17969 */
17970 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
17971 - ip = (unsigned long)__va(__pa(ip));
17972 + ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
17973
17974 return probe_kernel_write((void *)ip, val, size);
17975 }
17976 @@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
17977 unsigned char replaced[MCOUNT_INSN_SIZE];
17978 unsigned char brk = BREAKPOINT_INSTRUCTION;
17979
17980 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
17981 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
17982 return -EFAULT;
17983
17984 /* Make sure it is what we expect it to be */
17985 @@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
17986 return ret;
17987
17988 fail_update:
17989 - probe_kernel_write((void *)ip, &old_code[0], 1);
17990 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
17991 goto out;
17992 }
17993
17994 @@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
17995 {
17996 unsigned char code[MCOUNT_INSN_SIZE];
17997
17998 + ip = ktla_ktva(ip);
17999 +
18000 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
18001 return -EFAULT;
18002
18003 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
18004 index c18f59d..69ddbc4 100644
18005 --- a/arch/x86/kernel/head32.c
18006 +++ b/arch/x86/kernel/head32.c
18007 @@ -18,20 +18,20 @@
18008 #include <asm/io_apic.h>
18009 #include <asm/bios_ebda.h>
18010 #include <asm/tlbflush.h>
18011 +#include <asm/boot.h>
18012
18013 static void __init i386_default_early_setup(void)
18014 {
18015 /* Initialize 32bit specific setup functions */
18016 - x86_init.resources.reserve_resources = i386_reserve_resources;
18017 - x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
18018 + *(void **)&x86_init.resources.reserve_resources = i386_reserve_resources;
18019 + *(void **)&x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
18020
18021 reserve_ebda_region();
18022 }
18023
18024 void __init i386_start_kernel(void)
18025 {
18026 - memblock_reserve(__pa_symbol(&_text),
18027 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
18028 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
18029
18030 #ifdef CONFIG_BLK_DEV_INITRD
18031 /* Reserve INITRD */
18032 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
18033 index 4dac2f6..bc6a335 100644
18034 --- a/arch/x86/kernel/head_32.S
18035 +++ b/arch/x86/kernel/head_32.S
18036 @@ -26,6 +26,12 @@
18037 /* Physical address */
18038 #define pa(X) ((X) - __PAGE_OFFSET)
18039
18040 +#ifdef CONFIG_PAX_KERNEXEC
18041 +#define ta(X) (X)
18042 +#else
18043 +#define ta(X) ((X) - __PAGE_OFFSET)
18044 +#endif
18045 +
18046 /*
18047 * References to members of the new_cpu_data structure.
18048 */
18049 @@ -55,11 +61,7 @@
18050 * and small than max_low_pfn, otherwise will waste some page table entries
18051 */
18052
18053 -#if PTRS_PER_PMD > 1
18054 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
18055 -#else
18056 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
18057 -#endif
18058 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
18059
18060 /* Number of possible pages in the lowmem region */
18061 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
18062 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
18063 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
18064
18065 /*
18066 + * Real beginning of normal "text" segment
18067 + */
18068 +ENTRY(stext)
18069 +ENTRY(_stext)
18070 +
18071 +/*
18072 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
18073 * %esi points to the real-mode code as a 32-bit pointer.
18074 * CS and DS must be 4 GB flat segments, but we don't depend on
18075 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
18076 * can.
18077 */
18078 __HEAD
18079 +
18080 +#ifdef CONFIG_PAX_KERNEXEC
18081 + jmp startup_32
18082 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
18083 +.fill PAGE_SIZE-5,1,0xcc
18084 +#endif
18085 +
18086 ENTRY(startup_32)
18087 movl pa(stack_start),%ecx
18088
18089 @@ -106,6 +121,59 @@ ENTRY(startup_32)
18090 2:
18091 leal -__PAGE_OFFSET(%ecx),%esp
18092
18093 +#ifdef CONFIG_SMP
18094 + movl $pa(cpu_gdt_table),%edi
18095 + movl $__per_cpu_load,%eax
18096 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
18097 + rorl $16,%eax
18098 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
18099 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
18100 + movl $__per_cpu_end - 1,%eax
18101 + subl $__per_cpu_start,%eax
18102 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
18103 +#endif
18104 +
18105 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18106 + movl $NR_CPUS,%ecx
18107 + movl $pa(cpu_gdt_table),%edi
18108 +1:
18109 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
18110 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
18111 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
18112 + addl $PAGE_SIZE_asm,%edi
18113 + loop 1b
18114 +#endif
18115 +
18116 +#ifdef CONFIG_PAX_KERNEXEC
18117 + movl $pa(boot_gdt),%edi
18118 + movl $__LOAD_PHYSICAL_ADDR,%eax
18119 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
18120 + rorl $16,%eax
18121 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
18122 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
18123 + rorl $16,%eax
18124 +
18125 + ljmp $(__BOOT_CS),$1f
18126 +1:
18127 +
18128 + movl $NR_CPUS,%ecx
18129 + movl $pa(cpu_gdt_table),%edi
18130 + addl $__PAGE_OFFSET,%eax
18131 +1:
18132 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
18133 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
18134 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
18135 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
18136 + rorl $16,%eax
18137 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
18138 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
18139 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
18140 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
18141 + rorl $16,%eax
18142 + addl $PAGE_SIZE_asm,%edi
18143 + loop 1b
18144 +#endif
18145 +
18146 /*
18147 * Clear BSS first so that there are no surprises...
18148 */
18149 @@ -196,8 +264,11 @@ ENTRY(startup_32)
18150 movl %eax, pa(max_pfn_mapped)
18151
18152 /* Do early initialization of the fixmap area */
18153 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
18154 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
18155 +#ifdef CONFIG_COMPAT_VDSO
18156 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
18157 +#else
18158 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
18159 +#endif
18160 #else /* Not PAE */
18161
18162 page_pde_offset = (__PAGE_OFFSET >> 20);
18163 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
18164 movl %eax, pa(max_pfn_mapped)
18165
18166 /* Do early initialization of the fixmap area */
18167 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
18168 - movl %eax,pa(initial_page_table+0xffc)
18169 +#ifdef CONFIG_COMPAT_VDSO
18170 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
18171 +#else
18172 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
18173 +#endif
18174 #endif
18175
18176 #ifdef CONFIG_PARAVIRT
18177 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
18178 cmpl $num_subarch_entries, %eax
18179 jae bad_subarch
18180
18181 - movl pa(subarch_entries)(,%eax,4), %eax
18182 - subl $__PAGE_OFFSET, %eax
18183 - jmp *%eax
18184 + jmp *pa(subarch_entries)(,%eax,4)
18185
18186 bad_subarch:
18187 WEAK(lguest_entry)
18188 @@ -256,10 +328,10 @@ WEAK(xen_entry)
18189 __INITDATA
18190
18191 subarch_entries:
18192 - .long default_entry /* normal x86/PC */
18193 - .long lguest_entry /* lguest hypervisor */
18194 - .long xen_entry /* Xen hypervisor */
18195 - .long default_entry /* Moorestown MID */
18196 + .long ta(default_entry) /* normal x86/PC */
18197 + .long ta(lguest_entry) /* lguest hypervisor */
18198 + .long ta(xen_entry) /* Xen hypervisor */
18199 + .long ta(default_entry) /* Moorestown MID */
18200 num_subarch_entries = (. - subarch_entries) / 4
18201 .previous
18202 #else
18203 @@ -316,6 +388,7 @@ default_entry:
18204 movl pa(mmu_cr4_features),%eax
18205 movl %eax,%cr4
18206
18207 +#ifdef CONFIG_X86_PAE
18208 testb $X86_CR4_PAE, %al # check if PAE is enabled
18209 jz 6f
18210
18211 @@ -344,6 +417,9 @@ default_entry:
18212 /* Make changes effective */
18213 wrmsr
18214
18215 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
18216 +#endif
18217 +
18218 6:
18219
18220 /*
18221 @@ -442,14 +518,20 @@ is386: movl $2,%ecx # set MP
18222 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
18223 movl %eax,%ss # after changing gdt.
18224
18225 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
18226 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
18227 movl %eax,%ds
18228 movl %eax,%es
18229
18230 movl $(__KERNEL_PERCPU), %eax
18231 movl %eax,%fs # set this cpu's percpu
18232
18233 +#ifdef CONFIG_CC_STACKPROTECTOR
18234 movl $(__KERNEL_STACK_CANARY),%eax
18235 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18236 + movl $(__USER_DS),%eax
18237 +#else
18238 + xorl %eax,%eax
18239 +#endif
18240 movl %eax,%gs
18241
18242 xorl %eax,%eax # Clear LDT
18243 @@ -526,8 +608,11 @@ setup_once:
18244 * relocation. Manually set base address in stack canary
18245 * segment descriptor.
18246 */
18247 - movl $gdt_page,%eax
18248 + movl $cpu_gdt_table,%eax
18249 movl $stack_canary,%ecx
18250 +#ifdef CONFIG_SMP
18251 + addl $__per_cpu_load,%ecx
18252 +#endif
18253 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
18254 shrl $16, %ecx
18255 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
18256 @@ -558,7 +643,7 @@ ENDPROC(early_idt_handlers)
18257 /* This is global to keep gas from relaxing the jumps */
18258 ENTRY(early_idt_handler)
18259 cld
18260 - cmpl $2,%ss:early_recursion_flag
18261 + cmpl $1,%ss:early_recursion_flag
18262 je hlt_loop
18263 incl %ss:early_recursion_flag
18264
18265 @@ -596,8 +681,8 @@ ENTRY(early_idt_handler)
18266 pushl (20+6*4)(%esp) /* trapno */
18267 pushl $fault_msg
18268 call printk
18269 -#endif
18270 call dump_stack
18271 +#endif
18272 hlt_loop:
18273 hlt
18274 jmp hlt_loop
18275 @@ -616,8 +701,11 @@ ENDPROC(early_idt_handler)
18276 /* This is the default interrupt "handler" :-) */
18277 ALIGN
18278 ignore_int:
18279 - cld
18280 #ifdef CONFIG_PRINTK
18281 + cmpl $2,%ss:early_recursion_flag
18282 + je hlt_loop
18283 + incl %ss:early_recursion_flag
18284 + cld
18285 pushl %eax
18286 pushl %ecx
18287 pushl %edx
18288 @@ -626,9 +714,6 @@ ignore_int:
18289 movl $(__KERNEL_DS),%eax
18290 movl %eax,%ds
18291 movl %eax,%es
18292 - cmpl $2,early_recursion_flag
18293 - je hlt_loop
18294 - incl early_recursion_flag
18295 pushl 16(%esp)
18296 pushl 24(%esp)
18297 pushl 32(%esp)
18298 @@ -662,29 +747,43 @@ ENTRY(setup_once_ref)
18299 /*
18300 * BSS section
18301 */
18302 -__PAGE_ALIGNED_BSS
18303 - .align PAGE_SIZE
18304 #ifdef CONFIG_X86_PAE
18305 +.section .initial_pg_pmd,"a",@progbits
18306 initial_pg_pmd:
18307 .fill 1024*KPMDS,4,0
18308 #else
18309 +.section .initial_page_table,"a",@progbits
18310 ENTRY(initial_page_table)
18311 .fill 1024,4,0
18312 #endif
18313 +.section .initial_pg_fixmap,"a",@progbits
18314 initial_pg_fixmap:
18315 .fill 1024,4,0
18316 +.section .empty_zero_page,"a",@progbits
18317 ENTRY(empty_zero_page)
18318 .fill 4096,1,0
18319 +.section .swapper_pg_dir,"a",@progbits
18320 ENTRY(swapper_pg_dir)
18321 +#ifdef CONFIG_X86_PAE
18322 + .fill 4,8,0
18323 +#else
18324 .fill 1024,4,0
18325 +#endif
18326 +
18327 +/*
18328 + * The IDT has to be page-aligned to simplify the Pentium
18329 + * F0 0F bug workaround.. We have a special link segment
18330 + * for this.
18331 + */
18332 +.section .idt,"a",@progbits
18333 +ENTRY(idt_table)
18334 + .fill 256,8,0
18335
18336 /*
18337 * This starts the data section.
18338 */
18339 #ifdef CONFIG_X86_PAE
18340 -__PAGE_ALIGNED_DATA
18341 - /* Page-aligned for the benefit of paravirt? */
18342 - .align PAGE_SIZE
18343 +.section .initial_page_table,"a",@progbits
18344 ENTRY(initial_page_table)
18345 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
18346 # if KPMDS == 3
18347 @@ -703,12 +802,20 @@ ENTRY(initial_page_table)
18348 # error "Kernel PMDs should be 1, 2 or 3"
18349 # endif
18350 .align PAGE_SIZE /* needs to be page-sized too */
18351 +
18352 +#ifdef CONFIG_PAX_PER_CPU_PGD
18353 +ENTRY(cpu_pgd)
18354 + .rept NR_CPUS
18355 + .fill 4,8,0
18356 + .endr
18357 +#endif
18358 +
18359 #endif
18360
18361 .data
18362 .balign 4
18363 ENTRY(stack_start)
18364 - .long init_thread_union+THREAD_SIZE
18365 + .long init_thread_union+THREAD_SIZE-8
18366
18367 __INITRODATA
18368 int_msg:
18369 @@ -736,7 +843,7 @@ fault_msg:
18370 * segment size, and 32-bit linear address value:
18371 */
18372
18373 - .data
18374 +.section .rodata,"a",@progbits
18375 .globl boot_gdt_descr
18376 .globl idt_descr
18377
18378 @@ -745,7 +852,7 @@ fault_msg:
18379 .word 0 # 32 bit align gdt_desc.address
18380 boot_gdt_descr:
18381 .word __BOOT_DS+7
18382 - .long boot_gdt - __PAGE_OFFSET
18383 + .long pa(boot_gdt)
18384
18385 .word 0 # 32-bit align idt_desc.address
18386 idt_descr:
18387 @@ -756,7 +863,7 @@ idt_descr:
18388 .word 0 # 32 bit align gdt_desc.address
18389 ENTRY(early_gdt_descr)
18390 .word GDT_ENTRIES*8-1
18391 - .long gdt_page /* Overwritten for secondary CPUs */
18392 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
18393
18394 /*
18395 * The boot_gdt must mirror the equivalent in setup.S and is
18396 @@ -765,5 +872,65 @@ ENTRY(early_gdt_descr)
18397 .align L1_CACHE_BYTES
18398 ENTRY(boot_gdt)
18399 .fill GDT_ENTRY_BOOT_CS,8,0
18400 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
18401 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
18402 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
18403 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
18404 +
18405 + .align PAGE_SIZE_asm
18406 +ENTRY(cpu_gdt_table)
18407 + .rept NR_CPUS
18408 + .quad 0x0000000000000000 /* NULL descriptor */
18409 + .quad 0x0000000000000000 /* 0x0b reserved */
18410 + .quad 0x0000000000000000 /* 0x13 reserved */
18411 + .quad 0x0000000000000000 /* 0x1b reserved */
18412 +
18413 +#ifdef CONFIG_PAX_KERNEXEC
18414 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
18415 +#else
18416 + .quad 0x0000000000000000 /* 0x20 unused */
18417 +#endif
18418 +
18419 + .quad 0x0000000000000000 /* 0x28 unused */
18420 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
18421 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
18422 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
18423 + .quad 0x0000000000000000 /* 0x4b reserved */
18424 + .quad 0x0000000000000000 /* 0x53 reserved */
18425 + .quad 0x0000000000000000 /* 0x5b reserved */
18426 +
18427 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
18428 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
18429 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
18430 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
18431 +
18432 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
18433 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
18434 +
18435 + /*
18436 + * Segments used for calling PnP BIOS have byte granularity.
18437 + * The code segments and data segments have fixed 64k limits,
18438 + * the transfer segment sizes are set at run time.
18439 + */
18440 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
18441 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
18442 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
18443 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
18444 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
18445 +
18446 + /*
18447 + * The APM segments have byte granularity and their bases
18448 + * are set at run time. All have 64k limits.
18449 + */
18450 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
18451 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
18452 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
18453 +
18454 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
18455 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
18456 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
18457 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
18458 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
18459 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
18460 +
18461 + /* Be sure this is zeroed to avoid false validations in Xen */
18462 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
18463 + .endr
18464 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
18465 index 94bf9cc..400455a 100644
18466 --- a/arch/x86/kernel/head_64.S
18467 +++ b/arch/x86/kernel/head_64.S
18468 @@ -20,6 +20,8 @@
18469 #include <asm/processor-flags.h>
18470 #include <asm/percpu.h>
18471 #include <asm/nops.h>
18472 +#include <asm/cpufeature.h>
18473 +#include <asm/alternative-asm.h>
18474
18475 #ifdef CONFIG_PARAVIRT
18476 #include <asm/asm-offsets.h>
18477 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
18478 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
18479 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
18480 L3_START_KERNEL = pud_index(__START_KERNEL_map)
18481 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
18482 +L3_VMALLOC_START = pud_index(VMALLOC_START)
18483 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
18484 +L3_VMALLOC_END = pud_index(VMALLOC_END)
18485 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
18486 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
18487
18488 .text
18489 __HEAD
18490 @@ -88,35 +96,23 @@ startup_64:
18491 */
18492 addq %rbp, init_level4_pgt + 0(%rip)
18493 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
18494 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
18495 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
18496 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
18497 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
18498
18499 addq %rbp, level3_ident_pgt + 0(%rip)
18500 +#ifndef CONFIG_XEN
18501 + addq %rbp, level3_ident_pgt + 8(%rip)
18502 +#endif
18503
18504 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
18505 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
18506 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
18507 +
18508 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
18509 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
18510
18511 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
18512 -
18513 - /* Add an Identity mapping if I am above 1G */
18514 - leaq _text(%rip), %rdi
18515 - andq $PMD_PAGE_MASK, %rdi
18516 -
18517 - movq %rdi, %rax
18518 - shrq $PUD_SHIFT, %rax
18519 - andq $(PTRS_PER_PUD - 1), %rax
18520 - jz ident_complete
18521 -
18522 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
18523 - leaq level3_ident_pgt(%rip), %rbx
18524 - movq %rdx, 0(%rbx, %rax, 8)
18525 -
18526 - movq %rdi, %rax
18527 - shrq $PMD_SHIFT, %rax
18528 - andq $(PTRS_PER_PMD - 1), %rax
18529 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
18530 - leaq level2_spare_pgt(%rip), %rbx
18531 - movq %rdx, 0(%rbx, %rax, 8)
18532 -ident_complete:
18533 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
18534
18535 /*
18536 * Fixup the kernel text+data virtual addresses. Note that
18537 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
18538 * after the boot processor executes this code.
18539 */
18540
18541 - /* Enable PAE mode and PGE */
18542 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
18543 + /* Enable PAE mode and PSE/PGE */
18544 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
18545 movq %rax, %cr4
18546
18547 /* Setup early boot stage 4 level pagetables. */
18548 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
18549 movl $MSR_EFER, %ecx
18550 rdmsr
18551 btsl $_EFER_SCE, %eax /* Enable System Call */
18552 - btl $20,%edi /* No Execute supported? */
18553 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
18554 jnc 1f
18555 btsl $_EFER_NX, %eax
18556 + leaq init_level4_pgt(%rip), %rdi
18557 +#ifndef CONFIG_EFI
18558 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
18559 +#endif
18560 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
18561 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
18562 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
18563 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
18564 1: wrmsr /* Make changes effective */
18565
18566 /* Setup cr0 */
18567 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
18568 * jump. In addition we need to ensure %cs is set so we make this
18569 * a far return.
18570 */
18571 + pax_set_fptr_mask
18572 movq initial_code(%rip),%rax
18573 pushq $0 # fake return address to stop unwinder
18574 pushq $__KERNEL_CS # set correct cs
18575 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
18576 bad_address:
18577 jmp bad_address
18578
18579 - .section ".init.text","ax"
18580 + __INIT
18581 .globl early_idt_handlers
18582 early_idt_handlers:
18583 # 104(%rsp) %rflags
18584 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
18585 addq $16,%rsp # drop vector number and error code
18586 decl early_recursion_flag(%rip)
18587 INTERRUPT_RETURN
18588 + .previous
18589
18590 + __INITDATA
18591 .balign 4
18592 early_recursion_flag:
18593 .long 0
18594 + .previous
18595
18596 + .section .rodata,"a",@progbits
18597 #ifdef CONFIG_EARLY_PRINTK
18598 early_idt_msg:
18599 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
18600 @@ -360,6 +369,7 @@ early_idt_ripmsg:
18601 #endif /* CONFIG_EARLY_PRINTK */
18602 .previous
18603
18604 + .section .rodata,"a",@progbits
18605 #define NEXT_PAGE(name) \
18606 .balign PAGE_SIZE; \
18607 ENTRY(name)
18608 @@ -372,7 +382,6 @@ ENTRY(name)
18609 i = i + 1 ; \
18610 .endr
18611
18612 - .data
18613 /*
18614 * This default setting generates an ident mapping at address 0x100000
18615 * and a mapping for the kernel that precisely maps virtual address
18616 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
18617 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18618 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
18619 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18620 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
18621 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
18622 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
18623 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
18624 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
18625 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18626 .org init_level4_pgt + L4_START_KERNEL*8, 0
18627 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
18628 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
18629
18630 +#ifdef CONFIG_PAX_PER_CPU_PGD
18631 +NEXT_PAGE(cpu_pgd)
18632 + .rept NR_CPUS
18633 + .fill 512,8,0
18634 + .endr
18635 +#endif
18636 +
18637 NEXT_PAGE(level3_ident_pgt)
18638 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18639 +#ifdef CONFIG_XEN
18640 .fill 511,8,0
18641 +#else
18642 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
18643 + .fill 510,8,0
18644 +#endif
18645 +
18646 +NEXT_PAGE(level3_vmalloc_start_pgt)
18647 + .fill 512,8,0
18648 +
18649 +NEXT_PAGE(level3_vmalloc_end_pgt)
18650 + .fill 512,8,0
18651 +
18652 +NEXT_PAGE(level3_vmemmap_pgt)
18653 + .fill L3_VMEMMAP_START,8,0
18654 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18655
18656 NEXT_PAGE(level3_kernel_pgt)
18657 .fill L3_START_KERNEL,8,0
18658 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
18659 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
18660 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18661
18662 +NEXT_PAGE(level2_vmemmap_pgt)
18663 + .fill 512,8,0
18664 +
18665 NEXT_PAGE(level2_fixmap_pgt)
18666 - .fill 506,8,0
18667 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18668 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
18669 - .fill 5,8,0
18670 + .fill 507,8,0
18671 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
18672 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
18673 + .fill 4,8,0
18674
18675 -NEXT_PAGE(level1_fixmap_pgt)
18676 +NEXT_PAGE(level1_vsyscall_pgt)
18677 .fill 512,8,0
18678
18679 -NEXT_PAGE(level2_ident_pgt)
18680 - /* Since I easily can, map the first 1G.
18681 + /* Since I easily can, map the first 2G.
18682 * Don't set NX because code runs from these pages.
18683 */
18684 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
18685 +NEXT_PAGE(level2_ident_pgt)
18686 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
18687
18688 NEXT_PAGE(level2_kernel_pgt)
18689 /*
18690 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
18691 * If you want to increase this then increase MODULES_VADDR
18692 * too.)
18693 */
18694 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
18695 - KERNEL_IMAGE_SIZE/PMD_SIZE)
18696 -
18697 -NEXT_PAGE(level2_spare_pgt)
18698 - .fill 512, 8, 0
18699 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
18700
18701 #undef PMDS
18702 #undef NEXT_PAGE
18703
18704 - .data
18705 + .align PAGE_SIZE
18706 +ENTRY(cpu_gdt_table)
18707 + .rept NR_CPUS
18708 + .quad 0x0000000000000000 /* NULL descriptor */
18709 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
18710 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
18711 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
18712 + .quad 0x00cffb000000ffff /* __USER32_CS */
18713 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
18714 + .quad 0x00affb000000ffff /* __USER_CS */
18715 +
18716 +#ifdef CONFIG_PAX_KERNEXEC
18717 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
18718 +#else
18719 + .quad 0x0 /* unused */
18720 +#endif
18721 +
18722 + .quad 0,0 /* TSS */
18723 + .quad 0,0 /* LDT */
18724 + .quad 0,0,0 /* three TLS descriptors */
18725 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
18726 + /* asm/segment.h:GDT_ENTRIES must match this */
18727 +
18728 + /* zero the remaining page */
18729 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
18730 + .endr
18731 +
18732 .align 16
18733 .globl early_gdt_descr
18734 early_gdt_descr:
18735 .word GDT_ENTRIES*8-1
18736 early_gdt_descr_base:
18737 - .quad INIT_PER_CPU_VAR(gdt_page)
18738 + .quad cpu_gdt_table
18739
18740 ENTRY(phys_base)
18741 /* This must match the first entry in level2_kernel_pgt */
18742 .quad 0x0000000000000000
18743
18744 #include "../../x86/xen/xen-head.S"
18745 -
18746 - .section .bss, "aw", @nobits
18747 +
18748 + .section .rodata,"a",@progbits
18749 .align L1_CACHE_BYTES
18750 ENTRY(idt_table)
18751 - .skip IDT_ENTRIES * 16
18752 + .fill 512,8,0
18753
18754 .align L1_CACHE_BYTES
18755 ENTRY(nmi_idt_table)
18756 - .skip IDT_ENTRIES * 16
18757 + .fill 512,8,0
18758
18759 __PAGE_ALIGNED_BSS
18760 .align PAGE_SIZE
18761 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
18762 index 9c3bd4a..e1d9b35 100644
18763 --- a/arch/x86/kernel/i386_ksyms_32.c
18764 +++ b/arch/x86/kernel/i386_ksyms_32.c
18765 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
18766 EXPORT_SYMBOL(cmpxchg8b_emu);
18767 #endif
18768
18769 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
18770 +
18771 /* Networking helper routines. */
18772 EXPORT_SYMBOL(csum_partial_copy_generic);
18773 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
18774 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
18775
18776 EXPORT_SYMBOL(__get_user_1);
18777 EXPORT_SYMBOL(__get_user_2);
18778 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
18779
18780 EXPORT_SYMBOL(csum_partial);
18781 EXPORT_SYMBOL(empty_zero_page);
18782 +
18783 +#ifdef CONFIG_PAX_KERNEXEC
18784 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
18785 +#endif
18786 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
18787 index 675a050..95febfd 100644
18788 --- a/arch/x86/kernel/i387.c
18789 +++ b/arch/x86/kernel/i387.c
18790 @@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
18791 static inline bool interrupted_user_mode(void)
18792 {
18793 struct pt_regs *regs = get_irq_regs();
18794 - return regs && user_mode_vm(regs);
18795 + return regs && user_mode(regs);
18796 }
18797
18798 /*
18799 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
18800 index 9a5c460..dc4374d 100644
18801 --- a/arch/x86/kernel/i8259.c
18802 +++ b/arch/x86/kernel/i8259.c
18803 @@ -209,7 +209,7 @@ spurious_8259A_irq:
18804 "spurious 8259A interrupt: IRQ%d.\n", irq);
18805 spurious_irq_mask |= irqmask;
18806 }
18807 - atomic_inc(&irq_err_count);
18808 + atomic_inc_unchecked(&irq_err_count);
18809 /*
18810 * Theoretically we do not have to handle this IRQ,
18811 * but in Linux this does not cause problems and is
18812 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
18813 index 8c96897..be66bfa 100644
18814 --- a/arch/x86/kernel/ioport.c
18815 +++ b/arch/x86/kernel/ioport.c
18816 @@ -6,6 +6,7 @@
18817 #include <linux/sched.h>
18818 #include <linux/kernel.h>
18819 #include <linux/capability.h>
18820 +#include <linux/security.h>
18821 #include <linux/errno.h>
18822 #include <linux/types.h>
18823 #include <linux/ioport.h>
18824 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18825
18826 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
18827 return -EINVAL;
18828 +#ifdef CONFIG_GRKERNSEC_IO
18829 + if (turn_on && grsec_disable_privio) {
18830 + gr_handle_ioperm();
18831 + return -EPERM;
18832 + }
18833 +#endif
18834 if (turn_on && !capable(CAP_SYS_RAWIO))
18835 return -EPERM;
18836
18837 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18838 * because the ->io_bitmap_max value must match the bitmap
18839 * contents:
18840 */
18841 - tss = &per_cpu(init_tss, get_cpu());
18842 + tss = init_tss + get_cpu();
18843
18844 if (turn_on)
18845 bitmap_clear(t->io_bitmap_ptr, from, num);
18846 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
18847 return -EINVAL;
18848 /* Trying to gain more privileges? */
18849 if (level > old) {
18850 +#ifdef CONFIG_GRKERNSEC_IO
18851 + if (grsec_disable_privio) {
18852 + gr_handle_iopl();
18853 + return -EPERM;
18854 + }
18855 +#endif
18856 if (!capable(CAP_SYS_RAWIO))
18857 return -EPERM;
18858 }
18859 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
18860 index e4595f1..ee3bfb8 100644
18861 --- a/arch/x86/kernel/irq.c
18862 +++ b/arch/x86/kernel/irq.c
18863 @@ -18,7 +18,7 @@
18864 #include <asm/mce.h>
18865 #include <asm/hw_irq.h>
18866
18867 -atomic_t irq_err_count;
18868 +atomic_unchecked_t irq_err_count;
18869
18870 /* Function pointer for generic interrupt vector handling */
18871 void (*x86_platform_ipi_callback)(void) = NULL;
18872 @@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
18873 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
18874 seq_printf(p, " Machine check polls\n");
18875 #endif
18876 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
18877 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
18878 #if defined(CONFIG_X86_IO_APIC)
18879 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
18880 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
18881 #endif
18882 return 0;
18883 }
18884 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
18885
18886 u64 arch_irq_stat(void)
18887 {
18888 - u64 sum = atomic_read(&irq_err_count);
18889 + u64 sum = atomic_read_unchecked(&irq_err_count);
18890
18891 #ifdef CONFIG_X86_IO_APIC
18892 - sum += atomic_read(&irq_mis_count);
18893 + sum += atomic_read_unchecked(&irq_mis_count);
18894 #endif
18895 return sum;
18896 }
18897 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
18898 index 344faf8..355f60d 100644
18899 --- a/arch/x86/kernel/irq_32.c
18900 +++ b/arch/x86/kernel/irq_32.c
18901 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
18902 __asm__ __volatile__("andl %%esp,%0" :
18903 "=r" (sp) : "0" (THREAD_SIZE - 1));
18904
18905 - return sp < (sizeof(struct thread_info) + STACK_WARN);
18906 + return sp < STACK_WARN;
18907 }
18908
18909 static void print_stack_overflow(void)
18910 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
18911 * per-CPU IRQ handling contexts (thread information and stack)
18912 */
18913 union irq_ctx {
18914 - struct thread_info tinfo;
18915 - u32 stack[THREAD_SIZE/sizeof(u32)];
18916 + unsigned long previous_esp;
18917 + u32 stack[THREAD_SIZE/sizeof(u32)];
18918 } __attribute__((aligned(THREAD_SIZE)));
18919
18920 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
18921 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
18922 static inline int
18923 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18924 {
18925 - union irq_ctx *curctx, *irqctx;
18926 + union irq_ctx *irqctx;
18927 u32 *isp, arg1, arg2;
18928
18929 - curctx = (union irq_ctx *) current_thread_info();
18930 irqctx = __this_cpu_read(hardirq_ctx);
18931
18932 /*
18933 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18934 * handler) we can't do that and just have to keep using the
18935 * current stack (which is the irq stack already after all)
18936 */
18937 - if (unlikely(curctx == irqctx))
18938 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
18939 return 0;
18940
18941 /* build the stack frame on the IRQ stack */
18942 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
18943 - irqctx->tinfo.task = curctx->tinfo.task;
18944 - irqctx->tinfo.previous_esp = current_stack_pointer;
18945 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
18946 + irqctx->previous_esp = current_stack_pointer;
18947
18948 - /* Copy the preempt_count so that the [soft]irq checks work. */
18949 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
18950 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18951 + __set_fs(MAKE_MM_SEG(0));
18952 +#endif
18953
18954 if (unlikely(overflow))
18955 call_on_stack(print_stack_overflow, isp);
18956 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18957 : "0" (irq), "1" (desc), "2" (isp),
18958 "D" (desc->handle_irq)
18959 : "memory", "cc", "ecx");
18960 +
18961 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18962 + __set_fs(current_thread_info()->addr_limit);
18963 +#endif
18964 +
18965 return 1;
18966 }
18967
18968 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18969 */
18970 void __cpuinit irq_ctx_init(int cpu)
18971 {
18972 - union irq_ctx *irqctx;
18973 -
18974 if (per_cpu(hardirq_ctx, cpu))
18975 return;
18976
18977 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
18978 - THREADINFO_GFP,
18979 - THREAD_SIZE_ORDER));
18980 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
18981 - irqctx->tinfo.cpu = cpu;
18982 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
18983 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
18984 -
18985 - per_cpu(hardirq_ctx, cpu) = irqctx;
18986 -
18987 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
18988 - THREADINFO_GFP,
18989 - THREAD_SIZE_ORDER));
18990 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
18991 - irqctx->tinfo.cpu = cpu;
18992 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
18993 -
18994 - per_cpu(softirq_ctx, cpu) = irqctx;
18995 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
18996 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
18997 +
18998 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
18999 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
19000
19001 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
19002 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
19003 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
19004 asmlinkage void do_softirq(void)
19005 {
19006 unsigned long flags;
19007 - struct thread_info *curctx;
19008 union irq_ctx *irqctx;
19009 u32 *isp;
19010
19011 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
19012 local_irq_save(flags);
19013
19014 if (local_softirq_pending()) {
19015 - curctx = current_thread_info();
19016 irqctx = __this_cpu_read(softirq_ctx);
19017 - irqctx->tinfo.task = curctx->task;
19018 - irqctx->tinfo.previous_esp = current_stack_pointer;
19019 + irqctx->previous_esp = current_stack_pointer;
19020
19021 /* build the stack frame on the softirq stack */
19022 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
19023 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
19024 +
19025 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19026 + __set_fs(MAKE_MM_SEG(0));
19027 +#endif
19028
19029 call_on_stack(__do_softirq, isp);
19030 +
19031 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19032 + __set_fs(current_thread_info()->addr_limit);
19033 +#endif
19034 +
19035 /*
19036 * Shouldn't happen, we returned above if in_interrupt():
19037 */
19038 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
19039 if (unlikely(!desc))
19040 return false;
19041
19042 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
19043 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
19044 if (unlikely(overflow))
19045 print_stack_overflow();
19046 desc->handle_irq(irq, desc);
19047 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
19048 index d04d3ec..ea4b374 100644
19049 --- a/arch/x86/kernel/irq_64.c
19050 +++ b/arch/x86/kernel/irq_64.c
19051 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
19052 u64 estack_top, estack_bottom;
19053 u64 curbase = (u64)task_stack_page(current);
19054
19055 - if (user_mode_vm(regs))
19056 + if (user_mode(regs))
19057 return;
19058
19059 if (regs->sp >= curbase + sizeof(struct thread_info) +
19060 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
19061 index dc1404b..bbc43e7 100644
19062 --- a/arch/x86/kernel/kdebugfs.c
19063 +++ b/arch/x86/kernel/kdebugfs.c
19064 @@ -27,7 +27,7 @@ struct setup_data_node {
19065 u32 len;
19066 };
19067
19068 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
19069 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
19070 size_t count, loff_t *ppos)
19071 {
19072 struct setup_data_node *node = file->private_data;
19073 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
19074 index 836f832..a8bda67 100644
19075 --- a/arch/x86/kernel/kgdb.c
19076 +++ b/arch/x86/kernel/kgdb.c
19077 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
19078 #ifdef CONFIG_X86_32
19079 switch (regno) {
19080 case GDB_SS:
19081 - if (!user_mode_vm(regs))
19082 + if (!user_mode(regs))
19083 *(unsigned long *)mem = __KERNEL_DS;
19084 break;
19085 case GDB_SP:
19086 - if (!user_mode_vm(regs))
19087 + if (!user_mode(regs))
19088 *(unsigned long *)mem = kernel_stack_pointer(regs);
19089 break;
19090 case GDB_GS:
19091 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
19092 bp->attr.bp_addr = breakinfo[breakno].addr;
19093 bp->attr.bp_len = breakinfo[breakno].len;
19094 bp->attr.bp_type = breakinfo[breakno].type;
19095 - info->address = breakinfo[breakno].addr;
19096 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
19097 + info->address = ktla_ktva(breakinfo[breakno].addr);
19098 + else
19099 + info->address = breakinfo[breakno].addr;
19100 info->len = breakinfo[breakno].len;
19101 info->type = breakinfo[breakno].type;
19102 val = arch_install_hw_breakpoint(bp);
19103 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
19104 case 'k':
19105 /* clear the trace bit */
19106 linux_regs->flags &= ~X86_EFLAGS_TF;
19107 - atomic_set(&kgdb_cpu_doing_single_step, -1);
19108 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
19109
19110 /* set the trace bit if we're stepping */
19111 if (remcomInBuffer[0] == 's') {
19112 linux_regs->flags |= X86_EFLAGS_TF;
19113 - atomic_set(&kgdb_cpu_doing_single_step,
19114 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
19115 raw_smp_processor_id());
19116 }
19117
19118 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
19119
19120 switch (cmd) {
19121 case DIE_DEBUG:
19122 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
19123 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
19124 if (user_mode(regs))
19125 return single_step_cont(regs, args);
19126 break;
19127 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
19128 #endif /* CONFIG_DEBUG_RODATA */
19129
19130 bpt->type = BP_BREAKPOINT;
19131 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
19132 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
19133 BREAK_INSTR_SIZE);
19134 if (err)
19135 return err;
19136 - err = probe_kernel_write((char *)bpt->bpt_addr,
19137 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
19138 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
19139 #ifdef CONFIG_DEBUG_RODATA
19140 if (!err)
19141 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
19142 return -EBUSY;
19143 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
19144 BREAK_INSTR_SIZE);
19145 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
19146 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
19147 if (err)
19148 return err;
19149 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
19150 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
19151 if (mutex_is_locked(&text_mutex))
19152 goto knl_write;
19153 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
19154 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
19155 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
19156 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
19157 goto knl_write;
19158 return err;
19159 knl_write:
19160 #endif /* CONFIG_DEBUG_RODATA */
19161 - return probe_kernel_write((char *)bpt->bpt_addr,
19162 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
19163 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
19164 }
19165
19166 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
19167 index c5e410e..ed5a7f0 100644
19168 --- a/arch/x86/kernel/kprobes-opt.c
19169 +++ b/arch/x86/kernel/kprobes-opt.c
19170 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
19171 * Verify if the address gap is in 2GB range, because this uses
19172 * a relative jump.
19173 */
19174 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
19175 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
19176 if (abs(rel) > 0x7fffffff)
19177 return -ERANGE;
19178
19179 @@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
19180 op->optinsn.size = ret;
19181
19182 /* Copy arch-dep-instance from template */
19183 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
19184 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
19185
19186 /* Set probe information */
19187 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
19188
19189 /* Set probe function call */
19190 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
19191 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
19192
19193 /* Set returning jmp instruction at the tail of out-of-line buffer */
19194 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
19195 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
19196 (u8 *)op->kp.addr + op->optinsn.size);
19197
19198 flush_icache_range((unsigned long) buf,
19199 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
19200 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
19201
19202 /* Backup instructions which will be replaced by jump address */
19203 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
19204 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
19205 RELATIVE_ADDR_SIZE);
19206
19207 insn_buf[0] = RELATIVEJUMP_OPCODE;
19208 @@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
19209 /* This kprobe is really able to run optimized path. */
19210 op = container_of(p, struct optimized_kprobe, kp);
19211 /* Detour through copied instructions */
19212 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
19213 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
19214 if (!reenter)
19215 reset_current_kprobe();
19216 preempt_enable_no_resched();
19217 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
19218 index 57916c0..9e0b9d0 100644
19219 --- a/arch/x86/kernel/kprobes.c
19220 +++ b/arch/x86/kernel/kprobes.c
19221 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
19222 s32 raddr;
19223 } __attribute__((packed)) *insn;
19224
19225 - insn = (struct __arch_relative_insn *)from;
19226 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
19227 +
19228 + pax_open_kernel();
19229 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
19230 insn->op = op;
19231 + pax_close_kernel();
19232 }
19233
19234 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
19235 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
19236 kprobe_opcode_t opcode;
19237 kprobe_opcode_t *orig_opcodes = opcodes;
19238
19239 - if (search_exception_tables((unsigned long)opcodes))
19240 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
19241 return 0; /* Page fault may occur on this address. */
19242
19243 retry:
19244 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
19245 * for the first byte, we can recover the original instruction
19246 * from it and kp->opcode.
19247 */
19248 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19249 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19250 buf[0] = kp->opcode;
19251 - return (unsigned long)buf;
19252 + return ktva_ktla((unsigned long)buf);
19253 }
19254
19255 /*
19256 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19257 /* Another subsystem puts a breakpoint, failed to recover */
19258 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
19259 return 0;
19260 + pax_open_kernel();
19261 memcpy(dest, insn.kaddr, insn.length);
19262 + pax_close_kernel();
19263
19264 #ifdef CONFIG_X86_64
19265 if (insn_rip_relative(&insn)) {
19266 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19267 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
19268 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
19269 disp = (u8 *) dest + insn_offset_displacement(&insn);
19270 + pax_open_kernel();
19271 *(s32 *) disp = (s32) newdisp;
19272 + pax_close_kernel();
19273 }
19274 #endif
19275 return insn.length;
19276 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19277 * nor set current_kprobe, because it doesn't use single
19278 * stepping.
19279 */
19280 - regs->ip = (unsigned long)p->ainsn.insn;
19281 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19282 preempt_enable_no_resched();
19283 return;
19284 }
19285 @@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19286 regs->flags &= ~X86_EFLAGS_IF;
19287 /* single step inline if the instruction is an int3 */
19288 if (p->opcode == BREAKPOINT_INSTRUCTION)
19289 - regs->ip = (unsigned long)p->addr;
19290 + regs->ip = ktla_ktva((unsigned long)p->addr);
19291 else
19292 - regs->ip = (unsigned long)p->ainsn.insn;
19293 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19294 }
19295
19296 /*
19297 @@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
19298 setup_singlestep(p, regs, kcb, 0);
19299 return 1;
19300 }
19301 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
19302 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
19303 /*
19304 * The breakpoint instruction was removed right
19305 * after we hit it. Another cpu has removed
19306 @@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
19307 " movq %rax, 152(%rsp)\n"
19308 RESTORE_REGS_STRING
19309 " popfq\n"
19310 +#ifdef KERNEXEC_PLUGIN
19311 + " btsq $63,(%rsp)\n"
19312 +#endif
19313 #else
19314 " pushf\n"
19315 SAVE_REGS_STRING
19316 @@ -788,7 +798,7 @@ static void __kprobes
19317 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
19318 {
19319 unsigned long *tos = stack_addr(regs);
19320 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
19321 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
19322 unsigned long orig_ip = (unsigned long)p->addr;
19323 kprobe_opcode_t *insn = p->ainsn.insn;
19324
19325 @@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
19326 struct die_args *args = data;
19327 int ret = NOTIFY_DONE;
19328
19329 - if (args->regs && user_mode_vm(args->regs))
19330 + if (args->regs && user_mode(args->regs))
19331 return ret;
19332
19333 switch (val) {
19334 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
19335 index 4180a87..4678e4f 100644
19336 --- a/arch/x86/kernel/kvm.c
19337 +++ b/arch/x86/kernel/kvm.c
19338 @@ -267,7 +267,7 @@ static void __init paravirt_ops_setup(void)
19339 pv_info.paravirt_enabled = 1;
19340
19341 if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY))
19342 - pv_cpu_ops.io_delay = kvm_io_delay;
19343 + *(void **)&pv_cpu_ops.io_delay = kvm_io_delay;
19344
19345 #ifdef CONFIG_X86_IO_APIC
19346 no_timer_check = 1;
19347 @@ -461,18 +461,18 @@ void __init kvm_guest_init(void)
19348 for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++)
19349 spin_lock_init(&async_pf_sleepers[i].lock);
19350 if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF))
19351 - x86_init.irqs.trap_init = kvm_apf_trap_init;
19352 + *(void **)&x86_init.irqs.trap_init = kvm_apf_trap_init;
19353
19354 if (kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) {
19355 has_steal_clock = 1;
19356 - pv_time_ops.steal_clock = kvm_steal_clock;
19357 + *(void **)&pv_time_ops.steal_clock = kvm_steal_clock;
19358 }
19359
19360 if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
19361 apic_set_eoi_write(kvm_guest_apic_eoi_write);
19362
19363 #ifdef CONFIG_SMP
19364 - smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
19365 + *(void **)&smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
19366 register_cpu_notifier(&kvm_cpu_notifier);
19367 #else
19368 kvm_guest_cpu_init();
19369 diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
19370 index f1b42b3..27ac4e7 100644
19371 --- a/arch/x86/kernel/kvmclock.c
19372 +++ b/arch/x86/kernel/kvmclock.c
19373 @@ -211,19 +211,19 @@ void __init kvmclock_init(void)
19374
19375 if (kvm_register_clock("boot clock"))
19376 return;
19377 - pv_time_ops.sched_clock = kvm_clock_read;
19378 - x86_platform.calibrate_tsc = kvm_get_tsc_khz;
19379 - x86_platform.get_wallclock = kvm_get_wallclock;
19380 - x86_platform.set_wallclock = kvm_set_wallclock;
19381 + *(void **)&pv_time_ops.sched_clock = kvm_clock_read;
19382 + *(void **)&x86_platform.calibrate_tsc = kvm_get_tsc_khz;
19383 + *(void **)&x86_platform.get_wallclock = kvm_get_wallclock;
19384 + *(void **)&x86_platform.set_wallclock = kvm_set_wallclock;
19385 #ifdef CONFIG_X86_LOCAL_APIC
19386 - x86_cpuinit.early_percpu_clock_init =
19387 + *(void **)&x86_cpuinit.early_percpu_clock_init =
19388 kvm_setup_secondary_clock;
19389 #endif
19390 - x86_platform.save_sched_clock_state = kvm_save_sched_clock_state;
19391 - x86_platform.restore_sched_clock_state = kvm_restore_sched_clock_state;
19392 - machine_ops.shutdown = kvm_shutdown;
19393 + *(void **)&x86_platform.save_sched_clock_state = kvm_save_sched_clock_state;
19394 + *(void **)&x86_platform.restore_sched_clock_state = kvm_restore_sched_clock_state;
19395 + *(void **)&machine_ops.shutdown = kvm_shutdown;
19396 #ifdef CONFIG_KEXEC
19397 - machine_ops.crash_shutdown = kvm_crash_shutdown;
19398 + *(void **)&machine_ops.crash_shutdown = kvm_crash_shutdown;
19399 #endif
19400 kvm_get_preset_lpj();
19401 clocksource_register_hz(&kvm_clock, NSEC_PER_SEC);
19402 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
19403 index ebc9873..1b9724b 100644
19404 --- a/arch/x86/kernel/ldt.c
19405 +++ b/arch/x86/kernel/ldt.c
19406 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
19407 if (reload) {
19408 #ifdef CONFIG_SMP
19409 preempt_disable();
19410 - load_LDT(pc);
19411 + load_LDT_nolock(pc);
19412 if (!cpumask_equal(mm_cpumask(current->mm),
19413 cpumask_of(smp_processor_id())))
19414 smp_call_function(flush_ldt, current->mm, 1);
19415 preempt_enable();
19416 #else
19417 - load_LDT(pc);
19418 + load_LDT_nolock(pc);
19419 #endif
19420 }
19421 if (oldsize) {
19422 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
19423 return err;
19424
19425 for (i = 0; i < old->size; i++)
19426 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
19427 + write_ldt_entry(new->ldt, i, old->ldt + i);
19428 return 0;
19429 }
19430
19431 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
19432 retval = copy_ldt(&mm->context, &old_mm->context);
19433 mutex_unlock(&old_mm->context.lock);
19434 }
19435 +
19436 + if (tsk == current) {
19437 + mm->context.vdso = 0;
19438 +
19439 +#ifdef CONFIG_X86_32
19440 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
19441 + mm->context.user_cs_base = 0UL;
19442 + mm->context.user_cs_limit = ~0UL;
19443 +
19444 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
19445 + cpus_clear(mm->context.cpu_user_cs_mask);
19446 +#endif
19447 +
19448 +#endif
19449 +#endif
19450 +
19451 + }
19452 +
19453 return retval;
19454 }
19455
19456 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
19457 }
19458 }
19459
19460 +#ifdef CONFIG_PAX_SEGMEXEC
19461 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
19462 + error = -EINVAL;
19463 + goto out_unlock;
19464 + }
19465 +#endif
19466 +
19467 fill_ldt(&ldt, &ldt_info);
19468 if (oldmode)
19469 ldt.avl = 0;
19470 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
19471 index 5b19e4d..6476a76 100644
19472 --- a/arch/x86/kernel/machine_kexec_32.c
19473 +++ b/arch/x86/kernel/machine_kexec_32.c
19474 @@ -26,7 +26,7 @@
19475 #include <asm/cacheflush.h>
19476 #include <asm/debugreg.h>
19477
19478 -static void set_idt(void *newidt, __u16 limit)
19479 +static void set_idt(struct desc_struct *newidt, __u16 limit)
19480 {
19481 struct desc_ptr curidt;
19482
19483 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
19484 }
19485
19486
19487 -static void set_gdt(void *newgdt, __u16 limit)
19488 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
19489 {
19490 struct desc_ptr curgdt;
19491
19492 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
19493 }
19494
19495 control_page = page_address(image->control_code_page);
19496 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
19497 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
19498
19499 relocate_kernel_ptr = control_page;
19500 page_list[PA_CONTROL_PAGE] = __pa(control_page);
19501 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
19502 index 3544aed..01ddc1c 100644
19503 --- a/arch/x86/kernel/microcode_intel.c
19504 +++ b/arch/x86/kernel/microcode_intel.c
19505 @@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
19506
19507 static int get_ucode_user(void *to, const void *from, size_t n)
19508 {
19509 - return copy_from_user(to, from, n);
19510 + return copy_from_user(to, (const void __force_user *)from, n);
19511 }
19512
19513 static enum ucode_state
19514 request_microcode_user(int cpu, const void __user *buf, size_t size)
19515 {
19516 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
19517 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
19518 }
19519
19520 static void microcode_fini_cpu(int cpu)
19521 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
19522 index 216a4d7..b328f09 100644
19523 --- a/arch/x86/kernel/module.c
19524 +++ b/arch/x86/kernel/module.c
19525 @@ -43,15 +43,60 @@ do { \
19526 } while (0)
19527 #endif
19528
19529 -void *module_alloc(unsigned long size)
19530 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
19531 {
19532 - if (PAGE_ALIGN(size) > MODULES_LEN)
19533 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
19534 return NULL;
19535 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
19536 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
19537 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
19538 -1, __builtin_return_address(0));
19539 }
19540
19541 +void *module_alloc(unsigned long size)
19542 +{
19543 +
19544 +#ifdef CONFIG_PAX_KERNEXEC
19545 + return __module_alloc(size, PAGE_KERNEL);
19546 +#else
19547 + return __module_alloc(size, PAGE_KERNEL_EXEC);
19548 +#endif
19549 +
19550 +}
19551 +
19552 +#ifdef CONFIG_PAX_KERNEXEC
19553 +#ifdef CONFIG_X86_32
19554 +void *module_alloc_exec(unsigned long size)
19555 +{
19556 + struct vm_struct *area;
19557 +
19558 + if (size == 0)
19559 + return NULL;
19560 +
19561 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
19562 + return area ? area->addr : NULL;
19563 +}
19564 +EXPORT_SYMBOL(module_alloc_exec);
19565 +
19566 +void module_free_exec(struct module *mod, void *module_region)
19567 +{
19568 + vunmap(module_region);
19569 +}
19570 +EXPORT_SYMBOL(module_free_exec);
19571 +#else
19572 +void module_free_exec(struct module *mod, void *module_region)
19573 +{
19574 + module_free(mod, module_region);
19575 +}
19576 +EXPORT_SYMBOL(module_free_exec);
19577 +
19578 +void *module_alloc_exec(unsigned long size)
19579 +{
19580 + return __module_alloc(size, PAGE_KERNEL_RX);
19581 +}
19582 +EXPORT_SYMBOL(module_alloc_exec);
19583 +#endif
19584 +#endif
19585 +
19586 #ifdef CONFIG_X86_32
19587 int apply_relocate(Elf32_Shdr *sechdrs,
19588 const char *strtab,
19589 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19590 unsigned int i;
19591 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
19592 Elf32_Sym *sym;
19593 - uint32_t *location;
19594 + uint32_t *plocation, location;
19595
19596 DEBUGP("Applying relocate section %u to %u\n",
19597 relsec, sechdrs[relsec].sh_info);
19598 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
19599 /* This is where to make the change */
19600 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
19601 - + rel[i].r_offset;
19602 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
19603 + location = (uint32_t)plocation;
19604 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
19605 + plocation = ktla_ktva((void *)plocation);
19606 /* This is the symbol it is referring to. Note that all
19607 undefined symbols have been resolved. */
19608 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
19609 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19610 switch (ELF32_R_TYPE(rel[i].r_info)) {
19611 case R_386_32:
19612 /* We add the value into the location given */
19613 - *location += sym->st_value;
19614 + pax_open_kernel();
19615 + *plocation += sym->st_value;
19616 + pax_close_kernel();
19617 break;
19618 case R_386_PC32:
19619 /* Add the value, subtract its position */
19620 - *location += sym->st_value - (uint32_t)location;
19621 + pax_open_kernel();
19622 + *plocation += sym->st_value - location;
19623 + pax_close_kernel();
19624 break;
19625 default:
19626 pr_err("%s: Unknown relocation: %u\n",
19627 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
19628 case R_X86_64_NONE:
19629 break;
19630 case R_X86_64_64:
19631 + pax_open_kernel();
19632 *(u64 *)loc = val;
19633 + pax_close_kernel();
19634 break;
19635 case R_X86_64_32:
19636 + pax_open_kernel();
19637 *(u32 *)loc = val;
19638 + pax_close_kernel();
19639 if (val != *(u32 *)loc)
19640 goto overflow;
19641 break;
19642 case R_X86_64_32S:
19643 + pax_open_kernel();
19644 *(s32 *)loc = val;
19645 + pax_close_kernel();
19646 if ((s64)val != *(s32 *)loc)
19647 goto overflow;
19648 break;
19649 case R_X86_64_PC32:
19650 val -= (u64)loc;
19651 + pax_open_kernel();
19652 *(u32 *)loc = val;
19653 + pax_close_kernel();
19654 +
19655 #if 0
19656 if ((s64)val != *(s32 *)loc)
19657 goto overflow;
19658 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
19659 index f84f5c5..e27e54b 100644
19660 --- a/arch/x86/kernel/nmi.c
19661 +++ b/arch/x86/kernel/nmi.c
19662 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
19663 dotraplinkage notrace __kprobes void
19664 do_nmi(struct pt_regs *regs, long error_code)
19665 {
19666 +
19667 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19668 + if (!user_mode(regs)) {
19669 + unsigned long cs = regs->cs & 0xFFFF;
19670 + unsigned long ip = ktva_ktla(regs->ip);
19671 +
19672 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
19673 + regs->ip = ip;
19674 + }
19675 +#endif
19676 +
19677 nmi_nesting_preprocess(regs);
19678
19679 nmi_enter();
19680 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
19681 index 676b8c7..870ba04 100644
19682 --- a/arch/x86/kernel/paravirt-spinlocks.c
19683 +++ b/arch/x86/kernel/paravirt-spinlocks.c
19684 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
19685 arch_spin_lock(lock);
19686 }
19687
19688 -struct pv_lock_ops pv_lock_ops = {
19689 +struct pv_lock_ops pv_lock_ops __read_only = {
19690 #ifdef CONFIG_SMP
19691 .spin_is_locked = __ticket_spin_is_locked,
19692 .spin_is_contended = __ticket_spin_is_contended,
19693 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
19694 index 17fff18..0f5f957 100644
19695 --- a/arch/x86/kernel/paravirt.c
19696 +++ b/arch/x86/kernel/paravirt.c
19697 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
19698 {
19699 return x;
19700 }
19701 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19702 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
19703 +#endif
19704
19705 void __init default_banner(void)
19706 {
19707 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
19708 if (opfunc == NULL)
19709 /* If there's no function, patch it with a ud2a (BUG) */
19710 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
19711 - else if (opfunc == _paravirt_nop)
19712 + else if (opfunc == (void *)_paravirt_nop)
19713 /* If the operation is a nop, then nop the callsite */
19714 ret = paravirt_patch_nop();
19715
19716 /* identity functions just return their single argument */
19717 - else if (opfunc == _paravirt_ident_32)
19718 + else if (opfunc == (void *)_paravirt_ident_32)
19719 ret = paravirt_patch_ident_32(insnbuf, len);
19720 - else if (opfunc == _paravirt_ident_64)
19721 + else if (opfunc == (void *)_paravirt_ident_64)
19722 ret = paravirt_patch_ident_64(insnbuf, len);
19723 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19724 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
19725 + ret = paravirt_patch_ident_64(insnbuf, len);
19726 +#endif
19727
19728 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
19729 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
19730 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
19731 if (insn_len > len || start == NULL)
19732 insn_len = len;
19733 else
19734 - memcpy(insnbuf, start, insn_len);
19735 + memcpy(insnbuf, ktla_ktva(start), insn_len);
19736
19737 return insn_len;
19738 }
19739 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
19740 preempt_enable();
19741 }
19742
19743 -struct pv_info pv_info = {
19744 +struct pv_info pv_info __read_only = {
19745 .name = "bare hardware",
19746 .paravirt_enabled = 0,
19747 .kernel_rpl = 0,
19748 @@ -324,7 +331,7 @@ struct pv_time_ops pv_time_ops = {
19749 .steal_clock = native_steal_clock,
19750 };
19751
19752 -struct pv_irq_ops pv_irq_ops = {
19753 +struct pv_irq_ops pv_irq_ops __read_only = {
19754 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
19755 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
19756 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
19757 @@ -401,15 +408,20 @@ struct pv_apic_ops pv_apic_ops = {
19758 #endif
19759 };
19760
19761 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
19762 +#ifdef CONFIG_X86_32
19763 +#ifdef CONFIG_X86_PAE
19764 +/* 64-bit pagetable entries */
19765 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
19766 +#else
19767 /* 32-bit pagetable entries */
19768 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
19769 +#endif
19770 #else
19771 /* 64-bit pagetable entries */
19772 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
19773 #endif
19774
19775 -struct pv_mmu_ops pv_mmu_ops = {
19776 +struct pv_mmu_ops pv_mmu_ops __read_only = {
19777
19778 .read_cr2 = native_read_cr2,
19779 .write_cr2 = native_write_cr2,
19780 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
19781 .make_pud = PTE_IDENT,
19782
19783 .set_pgd = native_set_pgd,
19784 + .set_pgd_batched = native_set_pgd_batched,
19785 #endif
19786 #endif /* PAGETABLE_LEVELS >= 3 */
19787
19788 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
19789 },
19790
19791 .set_fixmap = native_set_fixmap,
19792 +
19793 +#ifdef CONFIG_PAX_KERNEXEC
19794 + .pax_open_kernel = native_pax_open_kernel,
19795 + .pax_close_kernel = native_pax_close_kernel,
19796 +#endif
19797 +
19798 };
19799
19800 EXPORT_SYMBOL_GPL(pv_time_ops);
19801 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
19802 index 299d493..79c13dd 100644
19803 --- a/arch/x86/kernel/pci-calgary_64.c
19804 +++ b/arch/x86/kernel/pci-calgary_64.c
19805 @@ -1461,7 +1461,7 @@ int __init detect_calgary(void)
19806 printk(KERN_INFO "PCI-DMA: Calgary TCE table spec is %d\n",
19807 specified_table_size);
19808
19809 - x86_init.iommu.iommu_init = calgary_iommu_init;
19810 + *(void **)&x86_init.iommu.iommu_init = calgary_iommu_init;
19811 }
19812 return calgary_found;
19813
19814 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
19815 index 35ccf75..7a15747 100644
19816 --- a/arch/x86/kernel/pci-iommu_table.c
19817 +++ b/arch/x86/kernel/pci-iommu_table.c
19818 @@ -2,7 +2,7 @@
19819 #include <asm/iommu_table.h>
19820 #include <linux/string.h>
19821 #include <linux/kallsyms.h>
19822 -
19823 +#include <linux/sched.h>
19824
19825 #define DEBUG 1
19826
19827 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
19828 index b644e1c..4a6d379 100644
19829 --- a/arch/x86/kernel/process.c
19830 +++ b/arch/x86/kernel/process.c
19831 @@ -36,7 +36,8 @@
19832 * section. Since TSS's are completely CPU-local, we want them
19833 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
19834 */
19835 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
19836 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
19837 +EXPORT_SYMBOL(init_tss);
19838
19839 #ifdef CONFIG_X86_64
19840 static DEFINE_PER_CPU(unsigned char, is_idle);
19841 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
19842 task_xstate_cachep =
19843 kmem_cache_create("task_xstate", xstate_size,
19844 __alignof__(union thread_xstate),
19845 - SLAB_PANIC | SLAB_NOTRACK, NULL);
19846 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
19847 }
19848
19849 /*
19850 @@ -105,7 +106,7 @@ void exit_thread(void)
19851 unsigned long *bp = t->io_bitmap_ptr;
19852
19853 if (bp) {
19854 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
19855 + struct tss_struct *tss = init_tss + get_cpu();
19856
19857 t->io_bitmap_ptr = NULL;
19858 clear_thread_flag(TIF_IO_BITMAP);
19859 @@ -136,7 +137,7 @@ void show_regs_common(void)
19860 board = dmi_get_system_info(DMI_BOARD_NAME);
19861
19862 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
19863 - current->pid, current->comm, print_tainted(),
19864 + task_pid_nr(current), current->comm, print_tainted(),
19865 init_utsname()->release,
19866 (int)strcspn(init_utsname()->version, " "),
19867 init_utsname()->version,
19868 @@ -149,6 +150,9 @@ void flush_thread(void)
19869 {
19870 struct task_struct *tsk = current;
19871
19872 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19873 + loadsegment(gs, 0);
19874 +#endif
19875 flush_ptrace_hw_breakpoint(tsk);
19876 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
19877 drop_init_fpu(tsk);
19878 @@ -336,7 +340,7 @@ static void __exit_idle(void)
19879 void exit_idle(void)
19880 {
19881 /* idle loop has pid 0 */
19882 - if (current->pid)
19883 + if (task_pid_nr(current))
19884 return;
19885 __exit_idle();
19886 }
19887 @@ -445,7 +449,7 @@ bool set_pm_idle_to_default(void)
19888
19889 return ret;
19890 }
19891 -void stop_this_cpu(void *dummy)
19892 +__noreturn void stop_this_cpu(void *dummy)
19893 {
19894 local_irq_disable();
19895 /*
19896 @@ -673,16 +677,37 @@ static int __init idle_setup(char *str)
19897 }
19898 early_param("idle", idle_setup);
19899
19900 -unsigned long arch_align_stack(unsigned long sp)
19901 +#ifdef CONFIG_PAX_RANDKSTACK
19902 +void pax_randomize_kstack(struct pt_regs *regs)
19903 {
19904 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
19905 - sp -= get_random_int() % 8192;
19906 - return sp & ~0xf;
19907 -}
19908 + struct thread_struct *thread = &current->thread;
19909 + unsigned long time;
19910
19911 -unsigned long arch_randomize_brk(struct mm_struct *mm)
19912 -{
19913 - unsigned long range_end = mm->brk + 0x02000000;
19914 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
19915 -}
19916 + if (!randomize_va_space)
19917 + return;
19918 +
19919 + if (v8086_mode(regs))
19920 + return;
19921
19922 + rdtscl(time);
19923 +
19924 + /* P4 seems to return a 0 LSB, ignore it */
19925 +#ifdef CONFIG_MPENTIUM4
19926 + time &= 0x3EUL;
19927 + time <<= 2;
19928 +#elif defined(CONFIG_X86_64)
19929 + time &= 0xFUL;
19930 + time <<= 4;
19931 +#else
19932 + time &= 0x1FUL;
19933 + time <<= 3;
19934 +#endif
19935 +
19936 + thread->sp0 ^= time;
19937 + load_sp0(init_tss + smp_processor_id(), thread);
19938 +
19939 +#ifdef CONFIG_X86_64
19940 + this_cpu_write(kernel_stack, thread->sp0);
19941 +#endif
19942 +}
19943 +#endif
19944 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
19945 index 44e0bff..5ceb99c 100644
19946 --- a/arch/x86/kernel/process_32.c
19947 +++ b/arch/x86/kernel/process_32.c
19948 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
19949 unsigned long thread_saved_pc(struct task_struct *tsk)
19950 {
19951 return ((unsigned long *)tsk->thread.sp)[3];
19952 +//XXX return tsk->thread.eip;
19953 }
19954
19955 void __show_regs(struct pt_regs *regs, int all)
19956 @@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
19957 unsigned long sp;
19958 unsigned short ss, gs;
19959
19960 - if (user_mode_vm(regs)) {
19961 + if (user_mode(regs)) {
19962 sp = regs->sp;
19963 ss = regs->ss & 0xffff;
19964 - gs = get_user_gs(regs);
19965 } else {
19966 sp = kernel_stack_pointer(regs);
19967 savesegment(ss, ss);
19968 - savesegment(gs, gs);
19969 }
19970 + gs = get_user_gs(regs);
19971
19972 show_regs_common();
19973
19974 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
19975 (u16)regs->cs, regs->ip, regs->flags,
19976 - smp_processor_id());
19977 + raw_smp_processor_id());
19978 print_symbol("EIP is at %s\n", regs->ip);
19979
19980 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
19981 @@ -131,20 +131,21 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
19982 unsigned long arg,
19983 struct task_struct *p, struct pt_regs *regs)
19984 {
19985 - struct pt_regs *childregs = task_pt_regs(p);
19986 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
19987 struct task_struct *tsk;
19988 int err;
19989
19990 p->thread.sp = (unsigned long) childregs;
19991 p->thread.sp0 = (unsigned long) (childregs+1);
19992 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
19993
19994 if (unlikely(!regs)) {
19995 /* kernel thread */
19996 memset(childregs, 0, sizeof(struct pt_regs));
19997 p->thread.ip = (unsigned long) ret_from_kernel_thread;
19998 - task_user_gs(p) = __KERNEL_STACK_CANARY;
19999 - childregs->ds = __USER_DS;
20000 - childregs->es = __USER_DS;
20001 + savesegment(gs, childregs->gs);
20002 + childregs->ds = __KERNEL_DS;
20003 + childregs->es = __KERNEL_DS;
20004 childregs->fs = __KERNEL_PERCPU;
20005 childregs->bx = sp; /* function */
20006 childregs->bp = arg;
20007 @@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20008 struct thread_struct *prev = &prev_p->thread,
20009 *next = &next_p->thread;
20010 int cpu = smp_processor_id();
20011 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
20012 + struct tss_struct *tss = init_tss + cpu;
20013 fpu_switch_t fpu;
20014
20015 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
20016 @@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20017 */
20018 lazy_save_gs(prev->gs);
20019
20020 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20021 + __set_fs(task_thread_info(next_p)->addr_limit);
20022 +#endif
20023 +
20024 /*
20025 * Load the per-thread Thread-Local Storage descriptor.
20026 */
20027 @@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20028 */
20029 arch_end_context_switch(next_p);
20030
20031 + this_cpu_write(current_task, next_p);
20032 + this_cpu_write(current_tinfo, &next_p->tinfo);
20033 +
20034 /*
20035 * Restore %gs if needed (which is common)
20036 */
20037 @@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20038
20039 switch_fpu_finish(next_p, fpu);
20040
20041 - this_cpu_write(current_task, next_p);
20042 -
20043 return prev_p;
20044 }
20045
20046 @@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
20047 } while (count++ < 16);
20048 return 0;
20049 }
20050 -
20051 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
20052 index 16c6365..5d32218 100644
20053 --- a/arch/x86/kernel/process_64.c
20054 +++ b/arch/x86/kernel/process_64.c
20055 @@ -153,10 +153,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
20056 struct pt_regs *childregs;
20057 struct task_struct *me = current;
20058
20059 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
20060 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
20061 childregs = task_pt_regs(p);
20062 p->thread.sp = (unsigned long) childregs;
20063 p->thread.usersp = me->thread.usersp;
20064 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
20065 set_tsk_thread_flag(p, TIF_FORK);
20066 p->fpu_counter = 0;
20067 p->thread.io_bitmap_ptr = NULL;
20068 @@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20069 struct thread_struct *prev = &prev_p->thread;
20070 struct thread_struct *next = &next_p->thread;
20071 int cpu = smp_processor_id();
20072 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
20073 + struct tss_struct *tss = init_tss + cpu;
20074 unsigned fsindex, gsindex;
20075 fpu_switch_t fpu;
20076
20077 @@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20078 prev->usersp = this_cpu_read(old_rsp);
20079 this_cpu_write(old_rsp, next->usersp);
20080 this_cpu_write(current_task, next_p);
20081 + this_cpu_write(current_tinfo, &next_p->tinfo);
20082
20083 - this_cpu_write(kernel_stack,
20084 - (unsigned long)task_stack_page(next_p) +
20085 - THREAD_SIZE - KERNEL_STACK_OFFSET);
20086 + this_cpu_write(kernel_stack, next->sp0);
20087
20088 /*
20089 * Now maybe reload the debug registers and handle I/O bitmaps
20090 @@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
20091 if (!p || p == current || p->state == TASK_RUNNING)
20092 return 0;
20093 stack = (unsigned long)task_stack_page(p);
20094 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
20095 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
20096 return 0;
20097 fp = *(u64 *)(p->thread.sp);
20098 do {
20099 - if (fp < (unsigned long)stack ||
20100 - fp >= (unsigned long)stack+THREAD_SIZE)
20101 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
20102 return 0;
20103 ip = *(u64 *)(fp+8);
20104 if (!in_sched_functions(ip))
20105 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
20106 index 974b67e..12cb2b5 100644
20107 --- a/arch/x86/kernel/ptrace.c
20108 +++ b/arch/x86/kernel/ptrace.c
20109 @@ -183,14 +183,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
20110 {
20111 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
20112 unsigned long sp = (unsigned long)&regs->sp;
20113 - struct thread_info *tinfo;
20114
20115 - if (context == (sp & ~(THREAD_SIZE - 1)))
20116 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
20117 return sp;
20118
20119 - tinfo = (struct thread_info *)context;
20120 - if (tinfo->previous_esp)
20121 - return tinfo->previous_esp;
20122 + sp = *(unsigned long *)context;
20123 + if (sp)
20124 + return sp;
20125
20126 return (unsigned long)regs;
20127 }
20128 @@ -587,7 +586,7 @@ static void ptrace_triggered(struct perf_event *bp,
20129 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
20130 {
20131 int i;
20132 - int dr7 = 0;
20133 + unsigned long dr7 = 0;
20134 struct arch_hw_breakpoint *info;
20135
20136 for (i = 0; i < HBP_NUM; i++) {
20137 @@ -855,7 +854,7 @@ long arch_ptrace(struct task_struct *child, long request,
20138 unsigned long addr, unsigned long data)
20139 {
20140 int ret;
20141 - unsigned long __user *datap = (unsigned long __user *)data;
20142 + unsigned long __user *datap = (__force unsigned long __user *)data;
20143
20144 switch (request) {
20145 /* read the word at location addr in the USER area. */
20146 @@ -940,14 +939,14 @@ long arch_ptrace(struct task_struct *child, long request,
20147 if ((int) addr < 0)
20148 return -EIO;
20149 ret = do_get_thread_area(child, addr,
20150 - (struct user_desc __user *)data);
20151 + (__force struct user_desc __user *) data);
20152 break;
20153
20154 case PTRACE_SET_THREAD_AREA:
20155 if ((int) addr < 0)
20156 return -EIO;
20157 ret = do_set_thread_area(child, addr,
20158 - (struct user_desc __user *)data, 0);
20159 + (__force struct user_desc __user *) data, 0);
20160 break;
20161 #endif
20162
20163 @@ -1325,7 +1324,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
20164
20165 #ifdef CONFIG_X86_64
20166
20167 -static struct user_regset x86_64_regsets[] __read_mostly = {
20168 +static struct user_regset x86_64_regsets[] = {
20169 [REGSET_GENERAL] = {
20170 .core_note_type = NT_PRSTATUS,
20171 .n = sizeof(struct user_regs_struct) / sizeof(long),
20172 @@ -1366,7 +1365,7 @@ static const struct user_regset_view user_x86_64_view = {
20173 #endif /* CONFIG_X86_64 */
20174
20175 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
20176 -static struct user_regset x86_32_regsets[] __read_mostly = {
20177 +static struct user_regset x86_32_regsets[] = {
20178 [REGSET_GENERAL] = {
20179 .core_note_type = NT_PRSTATUS,
20180 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
20181 @@ -1419,13 +1418,13 @@ static const struct user_regset_view user_x86_32_view = {
20182 */
20183 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
20184
20185 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
20186 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
20187 {
20188 #ifdef CONFIG_X86_64
20189 - x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20190 + *(unsigned int *)&x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20191 #endif
20192 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
20193 - x86_32_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20194 + *(unsigned int *)&x86_32_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20195 #endif
20196 xstate_fx_sw_bytes[USER_XSTATE_XCR0_WORD] = xstate_mask;
20197 }
20198 @@ -1454,7 +1453,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
20199 memset(info, 0, sizeof(*info));
20200 info->si_signo = SIGTRAP;
20201 info->si_code = si_code;
20202 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
20203 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
20204 }
20205
20206 void user_single_step_siginfo(struct task_struct *tsk,
20207 @@ -1483,6 +1482,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
20208 # define IS_IA32 0
20209 #endif
20210
20211 +#ifdef CONFIG_GRKERNSEC_SETXID
20212 +extern void gr_delayed_cred_worker(void);
20213 +#endif
20214 +
20215 /*
20216 * We must return the syscall number to actually look up in the table.
20217 * This can be -1L to skip running any syscall at all.
20218 @@ -1493,6 +1496,11 @@ long syscall_trace_enter(struct pt_regs *regs)
20219
20220 rcu_user_exit();
20221
20222 +#ifdef CONFIG_GRKERNSEC_SETXID
20223 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
20224 + gr_delayed_cred_worker();
20225 +#endif
20226 +
20227 /*
20228 * If we stepped into a sysenter/syscall insn, it trapped in
20229 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
20230 @@ -1548,6 +1556,11 @@ void syscall_trace_leave(struct pt_regs *regs)
20231 */
20232 rcu_user_exit();
20233
20234 +#ifdef CONFIG_GRKERNSEC_SETXID
20235 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
20236 + gr_delayed_cred_worker();
20237 +#endif
20238 +
20239 audit_syscall_exit(regs);
20240
20241 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
20242 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
20243 index 42eb330..139955c 100644
20244 --- a/arch/x86/kernel/pvclock.c
20245 +++ b/arch/x86/kernel/pvclock.c
20246 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
20247 return pv_tsc_khz;
20248 }
20249
20250 -static atomic64_t last_value = ATOMIC64_INIT(0);
20251 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
20252
20253 void pvclock_resume(void)
20254 {
20255 - atomic64_set(&last_value, 0);
20256 + atomic64_set_unchecked(&last_value, 0);
20257 }
20258
20259 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
20260 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
20261 * updating at the same time, and one of them could be slightly behind,
20262 * making the assumption that last_value always go forward fail to hold.
20263 */
20264 - last = atomic64_read(&last_value);
20265 + last = atomic64_read_unchecked(&last_value);
20266 do {
20267 if (ret < last)
20268 return last;
20269 - last = atomic64_cmpxchg(&last_value, last, ret);
20270 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
20271 } while (unlikely(last != ret));
20272
20273 return ret;
20274 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
20275 index 76fa1e9..a93c759 100644
20276 --- a/arch/x86/kernel/reboot.c
20277 +++ b/arch/x86/kernel/reboot.c
20278 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
20279 EXPORT_SYMBOL(pm_power_off);
20280
20281 static const struct desc_ptr no_idt = {};
20282 -static int reboot_mode;
20283 +static unsigned short reboot_mode;
20284 enum reboot_type reboot_type = BOOT_ACPI;
20285 int reboot_force;
20286
20287 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
20288
20289 void __noreturn machine_real_restart(unsigned int type)
20290 {
20291 +
20292 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20293 + struct desc_struct *gdt;
20294 +#endif
20295 +
20296 local_irq_disable();
20297
20298 /*
20299 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
20300
20301 /* Jump to the identity-mapped low memory code */
20302 #ifdef CONFIG_X86_32
20303 - asm volatile("jmpl *%0" : :
20304 +
20305 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20306 + gdt = get_cpu_gdt_table(smp_processor_id());
20307 + pax_open_kernel();
20308 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20309 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
20310 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
20311 + loadsegment(ds, __KERNEL_DS);
20312 + loadsegment(es, __KERNEL_DS);
20313 + loadsegment(ss, __KERNEL_DS);
20314 +#endif
20315 +#ifdef CONFIG_PAX_KERNEXEC
20316 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
20317 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
20318 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
20319 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
20320 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
20321 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
20322 +#endif
20323 + pax_close_kernel();
20324 +#endif
20325 +
20326 + asm volatile("ljmpl *%0" : :
20327 "rm" (real_mode_header->machine_real_restart_asm),
20328 "a" (type));
20329 #else
20330 @@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
20331 * try to force a triple fault and then cycle between hitting the keyboard
20332 * controller and doing that
20333 */
20334 -static void native_machine_emergency_restart(void)
20335 +static void __noreturn native_machine_emergency_restart(void)
20336 {
20337 int i;
20338 int attempt = 0;
20339 @@ -654,13 +681,13 @@ void native_machine_shutdown(void)
20340 #endif
20341 }
20342
20343 -static void __machine_emergency_restart(int emergency)
20344 +static void __noreturn __machine_emergency_restart(int emergency)
20345 {
20346 reboot_emergency = emergency;
20347 machine_ops.emergency_restart();
20348 }
20349
20350 -static void native_machine_restart(char *__unused)
20351 +static void __noreturn native_machine_restart(char *__unused)
20352 {
20353 pr_notice("machine restart\n");
20354
20355 @@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
20356 __machine_emergency_restart(0);
20357 }
20358
20359 -static void native_machine_halt(void)
20360 +static void __noreturn native_machine_halt(void)
20361 {
20362 /* Stop other cpus and apics */
20363 machine_shutdown();
20364 @@ -679,7 +706,7 @@ static void native_machine_halt(void)
20365 stop_this_cpu(NULL);
20366 }
20367
20368 -static void native_machine_power_off(void)
20369 +static void __noreturn native_machine_power_off(void)
20370 {
20371 if (pm_power_off) {
20372 if (!reboot_force)
20373 @@ -688,6 +715,7 @@ static void native_machine_power_off(void)
20374 }
20375 /* A fallback in case there is no PM info available */
20376 tboot_shutdown(TB_SHUTDOWN_HALT);
20377 + unreachable();
20378 }
20379
20380 struct machine_ops machine_ops = {
20381 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
20382 index 7a6f3b3..bed145d7 100644
20383 --- a/arch/x86/kernel/relocate_kernel_64.S
20384 +++ b/arch/x86/kernel/relocate_kernel_64.S
20385 @@ -11,6 +11,7 @@
20386 #include <asm/kexec.h>
20387 #include <asm/processor-flags.h>
20388 #include <asm/pgtable_types.h>
20389 +#include <asm/alternative-asm.h>
20390
20391 /*
20392 * Must be relocatable PIC code callable as a C function
20393 @@ -160,13 +161,14 @@ identity_mapped:
20394 xorq %rbp, %rbp
20395 xorq %r8, %r8
20396 xorq %r9, %r9
20397 - xorq %r10, %r9
20398 + xorq %r10, %r10
20399 xorq %r11, %r11
20400 xorq %r12, %r12
20401 xorq %r13, %r13
20402 xorq %r14, %r14
20403 xorq %r15, %r15
20404
20405 + pax_force_retaddr 0, 1
20406 ret
20407
20408 1:
20409 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
20410 index aeacb0e..f9d4c02 100644
20411 --- a/arch/x86/kernel/setup.c
20412 +++ b/arch/x86/kernel/setup.c
20413 @@ -441,7 +441,7 @@ static void __init parse_setup_data(void)
20414
20415 switch (data->type) {
20416 case SETUP_E820_EXT:
20417 - parse_e820_ext(data);
20418 + parse_e820_ext((struct setup_data __force_kernel *)data);
20419 break;
20420 case SETUP_DTB:
20421 add_dtb(pa_data);
20422 @@ -710,7 +710,7 @@ static void __init trim_bios_range(void)
20423 * area (640->1Mb) as ram even though it is not.
20424 * take them out.
20425 */
20426 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
20427 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
20428
20429 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
20430 }
20431 @@ -834,14 +834,14 @@ void __init setup_arch(char **cmdline_p)
20432
20433 if (!boot_params.hdr.root_flags)
20434 root_mountflags &= ~MS_RDONLY;
20435 - init_mm.start_code = (unsigned long) _text;
20436 - init_mm.end_code = (unsigned long) _etext;
20437 + init_mm.start_code = ktla_ktva((unsigned long) _text);
20438 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
20439 init_mm.end_data = (unsigned long) _edata;
20440 init_mm.brk = _brk_end;
20441
20442 - code_resource.start = virt_to_phys(_text);
20443 - code_resource.end = virt_to_phys(_etext)-1;
20444 - data_resource.start = virt_to_phys(_etext);
20445 + code_resource.start = virt_to_phys(ktla_ktva(_text));
20446 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
20447 + data_resource.start = virt_to_phys(_sdata);
20448 data_resource.end = virt_to_phys(_edata)-1;
20449 bss_resource.start = virt_to_phys(&__bss_start);
20450 bss_resource.end = virt_to_phys(&__bss_stop)-1;
20451 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
20452 index 5cdff03..5810740 100644
20453 --- a/arch/x86/kernel/setup_percpu.c
20454 +++ b/arch/x86/kernel/setup_percpu.c
20455 @@ -21,19 +21,17 @@
20456 #include <asm/cpu.h>
20457 #include <asm/stackprotector.h>
20458
20459 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
20460 +#ifdef CONFIG_SMP
20461 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
20462 EXPORT_PER_CPU_SYMBOL(cpu_number);
20463 +#endif
20464
20465 -#ifdef CONFIG_X86_64
20466 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
20467 -#else
20468 -#define BOOT_PERCPU_OFFSET 0
20469 -#endif
20470
20471 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
20472 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
20473
20474 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
20475 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
20476 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
20477 };
20478 EXPORT_SYMBOL(__per_cpu_offset);
20479 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
20480 {
20481 #ifdef CONFIG_X86_32
20482 struct desc_struct gdt;
20483 + unsigned long base = per_cpu_offset(cpu);
20484
20485 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
20486 - 0x2 | DESCTYPE_S, 0x8);
20487 - gdt.s = 1;
20488 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
20489 + 0x83 | DESCTYPE_S, 0xC);
20490 write_gdt_entry(get_cpu_gdt_table(cpu),
20491 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
20492 #endif
20493 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
20494 /* alrighty, percpu areas up and running */
20495 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
20496 for_each_possible_cpu(cpu) {
20497 +#ifdef CONFIG_CC_STACKPROTECTOR
20498 +#ifdef CONFIG_X86_32
20499 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
20500 +#endif
20501 +#endif
20502 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
20503 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
20504 per_cpu(cpu_number, cpu) = cpu;
20505 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
20506 */
20507 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
20508 #endif
20509 +#ifdef CONFIG_CC_STACKPROTECTOR
20510 +#ifdef CONFIG_X86_32
20511 + if (!cpu)
20512 + per_cpu(stack_canary.canary, cpu) = canary;
20513 +#endif
20514 +#endif
20515 /*
20516 * Up to this point, the boot CPU has been using .init.data
20517 * area. Reload any changed state for the boot CPU.
20518 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
20519 index 70b27ee..fcf827f 100644
20520 --- a/arch/x86/kernel/signal.c
20521 +++ b/arch/x86/kernel/signal.c
20522 @@ -195,7 +195,7 @@ static unsigned long align_sigframe(unsigned long sp)
20523 * Align the stack pointer according to the i386 ABI,
20524 * i.e. so that on function entry ((sp + 4) & 15) == 0.
20525 */
20526 - sp = ((sp + 4) & -16ul) - 4;
20527 + sp = ((sp - 12) & -16ul) - 4;
20528 #else /* !CONFIG_X86_32 */
20529 sp = round_down(sp, 16) - 8;
20530 #endif
20531 @@ -303,9 +303,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20532 }
20533
20534 if (current->mm->context.vdso)
20535 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20536 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20537 else
20538 - restorer = &frame->retcode;
20539 + restorer = (void __user *)&frame->retcode;
20540 if (ka->sa.sa_flags & SA_RESTORER)
20541 restorer = ka->sa.sa_restorer;
20542
20543 @@ -319,7 +319,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20544 * reasons and because gdb uses it as a signature to notice
20545 * signal handler stack frames.
20546 */
20547 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
20548 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
20549
20550 if (err)
20551 return -EFAULT;
20552 @@ -369,7 +369,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20553 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
20554
20555 /* Set up to return from userspace. */
20556 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20557 + if (current->mm->context.vdso)
20558 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20559 + else
20560 + restorer = (void __user *)&frame->retcode;
20561 if (ka->sa.sa_flags & SA_RESTORER)
20562 restorer = ka->sa.sa_restorer;
20563 put_user_ex(restorer, &frame->pretcode);
20564 @@ -381,7 +384,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20565 * reasons and because gdb uses it as a signature to notice
20566 * signal handler stack frames.
20567 */
20568 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
20569 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
20570 } put_user_catch(err);
20571
20572 err |= copy_siginfo_to_user(&frame->info, info);
20573 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
20574 index f3e2ec8..ad5287a 100644
20575 --- a/arch/x86/kernel/smpboot.c
20576 +++ b/arch/x86/kernel/smpboot.c
20577 @@ -673,6 +673,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20578 idle->thread.sp = (unsigned long) (((struct pt_regs *)
20579 (THREAD_SIZE + task_stack_page(idle))) - 1);
20580 per_cpu(current_task, cpu) = idle;
20581 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
20582
20583 #ifdef CONFIG_X86_32
20584 /* Stack for startup_32 can be just as for start_secondary onwards */
20585 @@ -680,11 +681,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20586 #else
20587 clear_tsk_thread_flag(idle, TIF_FORK);
20588 initial_gs = per_cpu_offset(cpu);
20589 - per_cpu(kernel_stack, cpu) =
20590 - (unsigned long)task_stack_page(idle) -
20591 - KERNEL_STACK_OFFSET + THREAD_SIZE;
20592 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
20593 #endif
20594 +
20595 + pax_open_kernel();
20596 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20597 + pax_close_kernel();
20598 +
20599 initial_code = (unsigned long)start_secondary;
20600 stack_start = idle->thread.sp;
20601
20602 @@ -823,6 +826,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
20603 /* the FPU context is blank, nobody can own it */
20604 __cpu_disable_lazy_restore(cpu);
20605
20606 +#ifdef CONFIG_PAX_PER_CPU_PGD
20607 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
20608 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
20609 + KERNEL_PGD_PTRS);
20610 +#endif
20611 +
20612 + /* the FPU context is blank, nobody can own it */
20613 + __cpu_disable_lazy_restore(cpu);
20614 +
20615 err = do_boot_cpu(apicid, cpu, tidle);
20616 if (err) {
20617 pr_debug("do_boot_cpu failed %d\n", err);
20618 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
20619 index 9b4d51d..5d28b58 100644
20620 --- a/arch/x86/kernel/step.c
20621 +++ b/arch/x86/kernel/step.c
20622 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20623 struct desc_struct *desc;
20624 unsigned long base;
20625
20626 - seg &= ~7UL;
20627 + seg >>= 3;
20628
20629 mutex_lock(&child->mm->context.lock);
20630 - if (unlikely((seg >> 3) >= child->mm->context.size))
20631 + if (unlikely(seg >= child->mm->context.size))
20632 addr = -1L; /* bogus selector, access would fault */
20633 else {
20634 desc = child->mm->context.ldt + seg;
20635 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20636 addr += base;
20637 }
20638 mutex_unlock(&child->mm->context.lock);
20639 - }
20640 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
20641 + addr = ktla_ktva(addr);
20642
20643 return addr;
20644 }
20645 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
20646 unsigned char opcode[15];
20647 unsigned long addr = convert_ip_to_linear(child, regs);
20648
20649 + if (addr == -EINVAL)
20650 + return 0;
20651 +
20652 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
20653 for (i = 0; i < copied; i++) {
20654 switch (opcode[i]) {
20655 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
20656 new file mode 100644
20657 index 0000000..26bb1af
20658 --- /dev/null
20659 +++ b/arch/x86/kernel/sys_i386_32.c
20660 @@ -0,0 +1,249 @@
20661 +/*
20662 + * This file contains various random system calls that
20663 + * have a non-standard calling sequence on the Linux/i386
20664 + * platform.
20665 + */
20666 +
20667 +#include <linux/errno.h>
20668 +#include <linux/sched.h>
20669 +#include <linux/mm.h>
20670 +#include <linux/fs.h>
20671 +#include <linux/smp.h>
20672 +#include <linux/sem.h>
20673 +#include <linux/msg.h>
20674 +#include <linux/shm.h>
20675 +#include <linux/stat.h>
20676 +#include <linux/syscalls.h>
20677 +#include <linux/mman.h>
20678 +#include <linux/file.h>
20679 +#include <linux/utsname.h>
20680 +#include <linux/ipc.h>
20681 +
20682 +#include <linux/uaccess.h>
20683 +#include <linux/unistd.h>
20684 +
20685 +#include <asm/syscalls.h>
20686 +
20687 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
20688 +{
20689 + unsigned long pax_task_size = TASK_SIZE;
20690 +
20691 +#ifdef CONFIG_PAX_SEGMEXEC
20692 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
20693 + pax_task_size = SEGMEXEC_TASK_SIZE;
20694 +#endif
20695 +
20696 + if (len > pax_task_size || addr > pax_task_size - len)
20697 + return -EINVAL;
20698 +
20699 + return 0;
20700 +}
20701 +
20702 +unsigned long
20703 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
20704 + unsigned long len, unsigned long pgoff, unsigned long flags)
20705 +{
20706 + struct mm_struct *mm = current->mm;
20707 + struct vm_area_struct *vma;
20708 + unsigned long start_addr, pax_task_size = TASK_SIZE;
20709 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20710 +
20711 +#ifdef CONFIG_PAX_SEGMEXEC
20712 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20713 + pax_task_size = SEGMEXEC_TASK_SIZE;
20714 +#endif
20715 +
20716 + pax_task_size -= PAGE_SIZE;
20717 +
20718 + if (len > pax_task_size)
20719 + return -ENOMEM;
20720 +
20721 + if (flags & MAP_FIXED)
20722 + return addr;
20723 +
20724 +#ifdef CONFIG_PAX_RANDMMAP
20725 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20726 +#endif
20727 +
20728 + if (addr) {
20729 + addr = PAGE_ALIGN(addr);
20730 + if (pax_task_size - len >= addr) {
20731 + vma = find_vma(mm, addr);
20732 + if (check_heap_stack_gap(vma, addr, len, offset))
20733 + return addr;
20734 + }
20735 + }
20736 + if (len > mm->cached_hole_size) {
20737 + start_addr = addr = mm->free_area_cache;
20738 + } else {
20739 + start_addr = addr = mm->mmap_base;
20740 + mm->cached_hole_size = 0;
20741 + }
20742 +
20743 +#ifdef CONFIG_PAX_PAGEEXEC
20744 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
20745 + start_addr = 0x00110000UL;
20746 +
20747 +#ifdef CONFIG_PAX_RANDMMAP
20748 + if (mm->pax_flags & MF_PAX_RANDMMAP)
20749 + start_addr += mm->delta_mmap & 0x03FFF000UL;
20750 +#endif
20751 +
20752 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
20753 + start_addr = addr = mm->mmap_base;
20754 + else
20755 + addr = start_addr;
20756 + }
20757 +#endif
20758 +
20759 +full_search:
20760 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
20761 + /* At this point: (!vma || addr < vma->vm_end). */
20762 + if (pax_task_size - len < addr) {
20763 + /*
20764 + * Start a new search - just in case we missed
20765 + * some holes.
20766 + */
20767 + if (start_addr != mm->mmap_base) {
20768 + start_addr = addr = mm->mmap_base;
20769 + mm->cached_hole_size = 0;
20770 + goto full_search;
20771 + }
20772 + return -ENOMEM;
20773 + }
20774 + if (check_heap_stack_gap(vma, addr, len, offset))
20775 + break;
20776 + if (addr + mm->cached_hole_size < vma->vm_start)
20777 + mm->cached_hole_size = vma->vm_start - addr;
20778 + addr = vma->vm_end;
20779 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
20780 + start_addr = addr = mm->mmap_base;
20781 + mm->cached_hole_size = 0;
20782 + goto full_search;
20783 + }
20784 + }
20785 +
20786 + /*
20787 + * Remember the place where we stopped the search:
20788 + */
20789 + mm->free_area_cache = addr + len;
20790 + return addr;
20791 +}
20792 +
20793 +unsigned long
20794 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20795 + const unsigned long len, const unsigned long pgoff,
20796 + const unsigned long flags)
20797 +{
20798 + struct vm_area_struct *vma;
20799 + struct mm_struct *mm = current->mm;
20800 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
20801 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20802 +
20803 +#ifdef CONFIG_PAX_SEGMEXEC
20804 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20805 + pax_task_size = SEGMEXEC_TASK_SIZE;
20806 +#endif
20807 +
20808 + pax_task_size -= PAGE_SIZE;
20809 +
20810 + /* requested length too big for entire address space */
20811 + if (len > pax_task_size)
20812 + return -ENOMEM;
20813 +
20814 + if (flags & MAP_FIXED)
20815 + return addr;
20816 +
20817 +#ifdef CONFIG_PAX_PAGEEXEC
20818 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
20819 + goto bottomup;
20820 +#endif
20821 +
20822 +#ifdef CONFIG_PAX_RANDMMAP
20823 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20824 +#endif
20825 +
20826 + /* requesting a specific address */
20827 + if (addr) {
20828 + addr = PAGE_ALIGN(addr);
20829 + if (pax_task_size - len >= addr) {
20830 + vma = find_vma(mm, addr);
20831 + if (check_heap_stack_gap(vma, addr, len, offset))
20832 + return addr;
20833 + }
20834 + }
20835 +
20836 + /* check if free_area_cache is useful for us */
20837 + if (len <= mm->cached_hole_size) {
20838 + mm->cached_hole_size = 0;
20839 + mm->free_area_cache = mm->mmap_base;
20840 + }
20841 +
20842 + /* either no address requested or can't fit in requested address hole */
20843 + addr = mm->free_area_cache;
20844 +
20845 + /* make sure it can fit in the remaining address space */
20846 + if (addr > len) {
20847 + vma = find_vma(mm, addr-len);
20848 + if (check_heap_stack_gap(vma, addr - len, len, offset))
20849 + /* remember the address as a hint for next time */
20850 + return (mm->free_area_cache = addr-len);
20851 + }
20852 +
20853 + if (mm->mmap_base < len)
20854 + goto bottomup;
20855 +
20856 + addr = mm->mmap_base-len;
20857 +
20858 + do {
20859 + /*
20860 + * Lookup failure means no vma is above this address,
20861 + * else if new region fits below vma->vm_start,
20862 + * return with success:
20863 + */
20864 + vma = find_vma(mm, addr);
20865 + if (check_heap_stack_gap(vma, addr, len, offset))
20866 + /* remember the address as a hint for next time */
20867 + return (mm->free_area_cache = addr);
20868 +
20869 + /* remember the largest hole we saw so far */
20870 + if (addr + mm->cached_hole_size < vma->vm_start)
20871 + mm->cached_hole_size = vma->vm_start - addr;
20872 +
20873 + /* try just below the current vma->vm_start */
20874 + addr = skip_heap_stack_gap(vma, len, offset);
20875 + } while (!IS_ERR_VALUE(addr));
20876 +
20877 +bottomup:
20878 + /*
20879 + * A failed mmap() very likely causes application failure,
20880 + * so fall back to the bottom-up function here. This scenario
20881 + * can happen with large stack limits and large mmap()
20882 + * allocations.
20883 + */
20884 +
20885 +#ifdef CONFIG_PAX_SEGMEXEC
20886 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20887 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
20888 + else
20889 +#endif
20890 +
20891 + mm->mmap_base = TASK_UNMAPPED_BASE;
20892 +
20893 +#ifdef CONFIG_PAX_RANDMMAP
20894 + if (mm->pax_flags & MF_PAX_RANDMMAP)
20895 + mm->mmap_base += mm->delta_mmap;
20896 +#endif
20897 +
20898 + mm->free_area_cache = mm->mmap_base;
20899 + mm->cached_hole_size = ~0UL;
20900 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
20901 + /*
20902 + * Restore the topdown base:
20903 + */
20904 + mm->mmap_base = base;
20905 + mm->free_area_cache = base;
20906 + mm->cached_hole_size = ~0UL;
20907 +
20908 + return addr;
20909 +}
20910 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
20911 index b4d3c39..d699d77 100644
20912 --- a/arch/x86/kernel/sys_x86_64.c
20913 +++ b/arch/x86/kernel/sys_x86_64.c
20914 @@ -95,8 +95,8 @@ out:
20915 return error;
20916 }
20917
20918 -static void find_start_end(unsigned long flags, unsigned long *begin,
20919 - unsigned long *end)
20920 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
20921 + unsigned long *begin, unsigned long *end)
20922 {
20923 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
20924 unsigned long new_begin;
20925 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
20926 *begin = new_begin;
20927 }
20928 } else {
20929 - *begin = TASK_UNMAPPED_BASE;
20930 + *begin = mm->mmap_base;
20931 *end = TASK_SIZE;
20932 }
20933 }
20934 @@ -128,20 +128,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
20935 struct vm_area_struct *vma;
20936 unsigned long start_addr;
20937 unsigned long begin, end;
20938 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20939
20940 if (flags & MAP_FIXED)
20941 return addr;
20942
20943 - find_start_end(flags, &begin, &end);
20944 + find_start_end(mm, flags, &begin, &end);
20945
20946 if (len > end)
20947 return -ENOMEM;
20948
20949 +#ifdef CONFIG_PAX_RANDMMAP
20950 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20951 +#endif
20952 +
20953 if (addr) {
20954 addr = PAGE_ALIGN(addr);
20955 vma = find_vma(mm, addr);
20956 - if (end - len >= addr &&
20957 - (!vma || addr + len <= vma->vm_start))
20958 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
20959 return addr;
20960 }
20961 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
20962 @@ -172,7 +176,7 @@ full_search:
20963 }
20964 return -ENOMEM;
20965 }
20966 - if (!vma || addr + len <= vma->vm_start) {
20967 + if (check_heap_stack_gap(vma, addr, len, offset)) {
20968 /*
20969 * Remember the place where we stopped the search:
20970 */
20971 @@ -195,7 +199,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20972 {
20973 struct vm_area_struct *vma;
20974 struct mm_struct *mm = current->mm;
20975 - unsigned long addr = addr0, start_addr;
20976 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
20977 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20978
20979 /* requested length too big for entire address space */
20980 if (len > TASK_SIZE)
20981 @@ -208,13 +213,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20982 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
20983 goto bottomup;
20984
20985 +#ifdef CONFIG_PAX_RANDMMAP
20986 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20987 +#endif
20988 +
20989 /* requesting a specific address */
20990 if (addr) {
20991 addr = PAGE_ALIGN(addr);
20992 - vma = find_vma(mm, addr);
20993 - if (TASK_SIZE - len >= addr &&
20994 - (!vma || addr + len <= vma->vm_start))
20995 - return addr;
20996 + if (TASK_SIZE - len >= addr) {
20997 + vma = find_vma(mm, addr);
20998 + if (check_heap_stack_gap(vma, addr, len, offset))
20999 + return addr;
21000 + }
21001 }
21002
21003 /* check if free_area_cache is useful for us */
21004 @@ -240,7 +250,7 @@ try_again:
21005 * return with success:
21006 */
21007 vma = find_vma(mm, addr);
21008 - if (!vma || addr+len <= vma->vm_start)
21009 + if (check_heap_stack_gap(vma, addr, len, offset))
21010 /* remember the address as a hint for next time */
21011 return mm->free_area_cache = addr;
21012
21013 @@ -249,8 +259,8 @@ try_again:
21014 mm->cached_hole_size = vma->vm_start - addr;
21015
21016 /* try just below the current vma->vm_start */
21017 - addr = vma->vm_start-len;
21018 - } while (len < vma->vm_start);
21019 + addr = skip_heap_stack_gap(vma, len, offset);
21020 + } while (!IS_ERR_VALUE(addr));
21021
21022 fail:
21023 /*
21024 @@ -270,13 +280,21 @@ bottomup:
21025 * can happen with large stack limits and large mmap()
21026 * allocations.
21027 */
21028 + mm->mmap_base = TASK_UNMAPPED_BASE;
21029 +
21030 +#ifdef CONFIG_PAX_RANDMMAP
21031 + if (mm->pax_flags & MF_PAX_RANDMMAP)
21032 + mm->mmap_base += mm->delta_mmap;
21033 +#endif
21034 +
21035 + mm->free_area_cache = mm->mmap_base;
21036 mm->cached_hole_size = ~0UL;
21037 - mm->free_area_cache = TASK_UNMAPPED_BASE;
21038 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
21039 /*
21040 * Restore the topdown base:
21041 */
21042 - mm->free_area_cache = mm->mmap_base;
21043 + mm->mmap_base = base;
21044 + mm->free_area_cache = base;
21045 mm->cached_hole_size = ~0UL;
21046
21047 return addr;
21048 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
21049 index f84fe00..93fe08f 100644
21050 --- a/arch/x86/kernel/tboot.c
21051 +++ b/arch/x86/kernel/tboot.c
21052 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
21053
21054 void tboot_shutdown(u32 shutdown_type)
21055 {
21056 - void (*shutdown)(void);
21057 + void (* __noreturn shutdown)(void);
21058
21059 if (!tboot_enabled())
21060 return;
21061 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
21062
21063 switch_to_tboot_pt();
21064
21065 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
21066 + shutdown = (void *)tboot->shutdown_entry;
21067 shutdown();
21068
21069 /* should not reach here */
21070 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
21071 return 0;
21072 }
21073
21074 -static atomic_t ap_wfs_count;
21075 +static atomic_unchecked_t ap_wfs_count;
21076
21077 static int tboot_wait_for_aps(int num_aps)
21078 {
21079 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
21080 {
21081 switch (action) {
21082 case CPU_DYING:
21083 - atomic_inc(&ap_wfs_count);
21084 + atomic_inc_unchecked(&ap_wfs_count);
21085 if (num_online_cpus() == 1)
21086 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
21087 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
21088 return NOTIFY_BAD;
21089 break;
21090 }
21091 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
21092
21093 tboot_create_trampoline();
21094
21095 - atomic_set(&ap_wfs_count, 0);
21096 + atomic_set_unchecked(&ap_wfs_count, 0);
21097 register_hotcpu_notifier(&tboot_cpu_notifier);
21098
21099 acpi_os_set_prepare_sleep(&tboot_sleep);
21100 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
21101 index 24d3c91..d06b473 100644
21102 --- a/arch/x86/kernel/time.c
21103 +++ b/arch/x86/kernel/time.c
21104 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
21105 {
21106 unsigned long pc = instruction_pointer(regs);
21107
21108 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
21109 + if (!user_mode(regs) && in_lock_functions(pc)) {
21110 #ifdef CONFIG_FRAME_POINTER
21111 - return *(unsigned long *)(regs->bp + sizeof(long));
21112 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
21113 #else
21114 unsigned long *sp =
21115 (unsigned long *)kernel_stack_pointer(regs);
21116 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
21117 * or above a saved flags. Eflags has bits 22-31 zero,
21118 * kernel addresses don't.
21119 */
21120 +
21121 +#ifdef CONFIG_PAX_KERNEXEC
21122 + return ktla_ktva(sp[0]);
21123 +#else
21124 if (sp[0] >> 22)
21125 return sp[0];
21126 if (sp[1] >> 22)
21127 return sp[1];
21128 #endif
21129 +
21130 +#endif
21131 }
21132 return pc;
21133 }
21134 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
21135 index 9d9d2f9..cad418a 100644
21136 --- a/arch/x86/kernel/tls.c
21137 +++ b/arch/x86/kernel/tls.c
21138 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
21139 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
21140 return -EINVAL;
21141
21142 +#ifdef CONFIG_PAX_SEGMEXEC
21143 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
21144 + return -EINVAL;
21145 +#endif
21146 +
21147 set_tls_desc(p, idx, &info, 1);
21148
21149 return 0;
21150 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
21151
21152 if (kbuf)
21153 info = kbuf;
21154 - else if (__copy_from_user(infobuf, ubuf, count))
21155 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
21156 return -EFAULT;
21157 else
21158 info = infobuf;
21159 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
21160 index 8276dc6..4ca48a2 100644
21161 --- a/arch/x86/kernel/traps.c
21162 +++ b/arch/x86/kernel/traps.c
21163 @@ -71,12 +71,6 @@ asmlinkage int system_call(void);
21164
21165 /* Do we ignore FPU interrupts ? */
21166 char ignore_fpu_irq;
21167 -
21168 -/*
21169 - * The IDT has to be page-aligned to simplify the Pentium
21170 - * F0 0F bug workaround.
21171 - */
21172 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
21173 #endif
21174
21175 DECLARE_BITMAP(used_vectors, NR_VECTORS);
21176 @@ -109,11 +103,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
21177 }
21178
21179 static int __kprobes
21180 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21181 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
21182 struct pt_regs *regs, long error_code)
21183 {
21184 #ifdef CONFIG_X86_32
21185 - if (regs->flags & X86_VM_MASK) {
21186 + if (v8086_mode(regs)) {
21187 /*
21188 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
21189 * On nmi (interrupt 2), do_trap should not be called.
21190 @@ -126,12 +120,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21191 return -1;
21192 }
21193 #endif
21194 - if (!user_mode(regs)) {
21195 + if (!user_mode_novm(regs)) {
21196 if (!fixup_exception(regs)) {
21197 tsk->thread.error_code = error_code;
21198 tsk->thread.trap_nr = trapnr;
21199 +
21200 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21201 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
21202 + str = "PAX: suspicious stack segment fault";
21203 +#endif
21204 +
21205 die(str, regs, error_code);
21206 }
21207 +
21208 +#ifdef CONFIG_PAX_REFCOUNT
21209 + if (trapnr == 4)
21210 + pax_report_refcount_overflow(regs);
21211 +#endif
21212 +
21213 return 0;
21214 }
21215
21216 @@ -139,7 +145,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21217 }
21218
21219 static void __kprobes
21220 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
21221 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
21222 long error_code, siginfo_t *info)
21223 {
21224 struct task_struct *tsk = current;
21225 @@ -163,7 +169,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
21226 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
21227 printk_ratelimit()) {
21228 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
21229 - tsk->comm, tsk->pid, str,
21230 + tsk->comm, task_pid_nr(tsk), str,
21231 regs->ip, regs->sp, error_code);
21232 print_vma_addr(" in ", regs->ip);
21233 pr_cont("\n");
21234 @@ -269,7 +275,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
21235 conditional_sti(regs);
21236
21237 #ifdef CONFIG_X86_32
21238 - if (regs->flags & X86_VM_MASK) {
21239 + if (v8086_mode(regs)) {
21240 local_irq_enable();
21241 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
21242 goto exit;
21243 @@ -277,18 +283,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
21244 #endif
21245
21246 tsk = current;
21247 - if (!user_mode(regs)) {
21248 + if (!user_mode_novm(regs)) {
21249 if (fixup_exception(regs))
21250 goto exit;
21251
21252 tsk->thread.error_code = error_code;
21253 tsk->thread.trap_nr = X86_TRAP_GP;
21254 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
21255 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
21256 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
21257 +
21258 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21259 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
21260 + die("PAX: suspicious general protection fault", regs, error_code);
21261 + else
21262 +#endif
21263 +
21264 die("general protection fault", regs, error_code);
21265 + }
21266 goto exit;
21267 }
21268
21269 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21270 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
21271 + struct mm_struct *mm = tsk->mm;
21272 + unsigned long limit;
21273 +
21274 + down_write(&mm->mmap_sem);
21275 + limit = mm->context.user_cs_limit;
21276 + if (limit < TASK_SIZE) {
21277 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
21278 + up_write(&mm->mmap_sem);
21279 + return;
21280 + }
21281 + up_write(&mm->mmap_sem);
21282 + }
21283 +#endif
21284 +
21285 tsk->thread.error_code = error_code;
21286 tsk->thread.trap_nr = X86_TRAP_GP;
21287
21288 @@ -443,7 +473,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21289 /* It's safe to allow irq's after DR6 has been saved */
21290 preempt_conditional_sti(regs);
21291
21292 - if (regs->flags & X86_VM_MASK) {
21293 + if (v8086_mode(regs)) {
21294 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
21295 X86_TRAP_DB);
21296 preempt_conditional_cli(regs);
21297 @@ -458,7 +488,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21298 * We already checked v86 mode above, so we can check for kernel mode
21299 * by just checking the CPL of CS.
21300 */
21301 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
21302 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
21303 tsk->thread.debugreg6 &= ~DR_STEP;
21304 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
21305 regs->flags &= ~X86_EFLAGS_TF;
21306 @@ -490,7 +520,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
21307 return;
21308 conditional_sti(regs);
21309
21310 - if (!user_mode_vm(regs))
21311 + if (!user_mode(regs))
21312 {
21313 if (!fixup_exception(regs)) {
21314 task->thread.error_code = error_code;
21315 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
21316 index aafa555..a04691a 100644
21317 --- a/arch/x86/kernel/uprobes.c
21318 +++ b/arch/x86/kernel/uprobes.c
21319 @@ -614,7 +614,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
21320 int ret = NOTIFY_DONE;
21321
21322 /* We are only interested in userspace traps */
21323 - if (regs && !user_mode_vm(regs))
21324 + if (regs && !user_mode(regs))
21325 return NOTIFY_DONE;
21326
21327 switch (val) {
21328 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
21329 index b9242ba..50c5edd 100644
21330 --- a/arch/x86/kernel/verify_cpu.S
21331 +++ b/arch/x86/kernel/verify_cpu.S
21332 @@ -20,6 +20,7 @@
21333 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
21334 * arch/x86/kernel/trampoline_64.S: secondary processor verification
21335 * arch/x86/kernel/head_32.S: processor startup
21336 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
21337 *
21338 * verify_cpu, returns the status of longmode and SSE in register %eax.
21339 * 0: Success 1: Failure
21340 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
21341 index 5c9687b..5f857d3 100644
21342 --- a/arch/x86/kernel/vm86_32.c
21343 +++ b/arch/x86/kernel/vm86_32.c
21344 @@ -43,6 +43,7 @@
21345 #include <linux/ptrace.h>
21346 #include <linux/audit.h>
21347 #include <linux/stddef.h>
21348 +#include <linux/grsecurity.h>
21349
21350 #include <asm/uaccess.h>
21351 #include <asm/io.h>
21352 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
21353 do_exit(SIGSEGV);
21354 }
21355
21356 - tss = &per_cpu(init_tss, get_cpu());
21357 + tss = init_tss + get_cpu();
21358 current->thread.sp0 = current->thread.saved_sp0;
21359 current->thread.sysenter_cs = __KERNEL_CS;
21360 load_sp0(tss, &current->thread);
21361 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
21362 struct task_struct *tsk;
21363 int tmp, ret = -EPERM;
21364
21365 +#ifdef CONFIG_GRKERNSEC_VM86
21366 + if (!capable(CAP_SYS_RAWIO)) {
21367 + gr_handle_vm86();
21368 + goto out;
21369 + }
21370 +#endif
21371 +
21372 tsk = current;
21373 if (tsk->thread.saved_sp0)
21374 goto out;
21375 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
21376 int tmp, ret;
21377 struct vm86plus_struct __user *v86;
21378
21379 +#ifdef CONFIG_GRKERNSEC_VM86
21380 + if (!capable(CAP_SYS_RAWIO)) {
21381 + gr_handle_vm86();
21382 + ret = -EPERM;
21383 + goto out;
21384 + }
21385 +#endif
21386 +
21387 tsk = current;
21388 switch (cmd) {
21389 case VM86_REQUEST_IRQ:
21390 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
21391 tsk->thread.saved_fs = info->regs32->fs;
21392 tsk->thread.saved_gs = get_user_gs(info->regs32);
21393
21394 - tss = &per_cpu(init_tss, get_cpu());
21395 + tss = init_tss + get_cpu();
21396 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
21397 if (cpu_has_sep)
21398 tsk->thread.sysenter_cs = 0;
21399 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
21400 goto cannot_handle;
21401 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
21402 goto cannot_handle;
21403 - intr_ptr = (unsigned long __user *) (i << 2);
21404 + intr_ptr = (__force unsigned long __user *) (i << 2);
21405 if (get_user(segoffs, intr_ptr))
21406 goto cannot_handle;
21407 if ((segoffs >> 16) == BIOSSEG)
21408 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
21409 index 22a1530..8fbaaad 100644
21410 --- a/arch/x86/kernel/vmlinux.lds.S
21411 +++ b/arch/x86/kernel/vmlinux.lds.S
21412 @@ -26,6 +26,13 @@
21413 #include <asm/page_types.h>
21414 #include <asm/cache.h>
21415 #include <asm/boot.h>
21416 +#include <asm/segment.h>
21417 +
21418 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21419 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
21420 +#else
21421 +#define __KERNEL_TEXT_OFFSET 0
21422 +#endif
21423
21424 #undef i386 /* in case the preprocessor is a 32bit one */
21425
21426 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
21427
21428 PHDRS {
21429 text PT_LOAD FLAGS(5); /* R_E */
21430 +#ifdef CONFIG_X86_32
21431 + module PT_LOAD FLAGS(5); /* R_E */
21432 +#endif
21433 +#ifdef CONFIG_XEN
21434 + rodata PT_LOAD FLAGS(5); /* R_E */
21435 +#else
21436 + rodata PT_LOAD FLAGS(4); /* R__ */
21437 +#endif
21438 data PT_LOAD FLAGS(6); /* RW_ */
21439 -#ifdef CONFIG_X86_64
21440 + init.begin PT_LOAD FLAGS(6); /* RW_ */
21441 #ifdef CONFIG_SMP
21442 percpu PT_LOAD FLAGS(6); /* RW_ */
21443 #endif
21444 + text.init PT_LOAD FLAGS(5); /* R_E */
21445 + text.exit PT_LOAD FLAGS(5); /* R_E */
21446 init PT_LOAD FLAGS(7); /* RWE */
21447 -#endif
21448 note PT_NOTE FLAGS(0); /* ___ */
21449 }
21450
21451 SECTIONS
21452 {
21453 #ifdef CONFIG_X86_32
21454 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
21455 - phys_startup_32 = startup_32 - LOAD_OFFSET;
21456 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
21457 #else
21458 - . = __START_KERNEL;
21459 - phys_startup_64 = startup_64 - LOAD_OFFSET;
21460 + . = __START_KERNEL;
21461 #endif
21462
21463 /* Text and read-only data */
21464 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
21465 - _text = .;
21466 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21467 /* bootstrapping code */
21468 +#ifdef CONFIG_X86_32
21469 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21470 +#else
21471 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21472 +#endif
21473 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21474 + _text = .;
21475 HEAD_TEXT
21476 #ifdef CONFIG_X86_32
21477 . = ALIGN(PAGE_SIZE);
21478 @@ -108,13 +128,48 @@ SECTIONS
21479 IRQENTRY_TEXT
21480 *(.fixup)
21481 *(.gnu.warning)
21482 - /* End of text section */
21483 - _etext = .;
21484 } :text = 0x9090
21485
21486 - NOTES :text :note
21487 + . += __KERNEL_TEXT_OFFSET;
21488
21489 - EXCEPTION_TABLE(16) :text = 0x9090
21490 +#ifdef CONFIG_X86_32
21491 + . = ALIGN(PAGE_SIZE);
21492 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
21493 +
21494 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
21495 + MODULES_EXEC_VADDR = .;
21496 + BYTE(0)
21497 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
21498 + . = ALIGN(HPAGE_SIZE) - 1;
21499 + MODULES_EXEC_END = .;
21500 +#endif
21501 +
21502 + } :module
21503 +#endif
21504 +
21505 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
21506 + /* End of text section */
21507 + BYTE(0)
21508 + _etext = . - __KERNEL_TEXT_OFFSET;
21509 + }
21510 +
21511 +#ifdef CONFIG_X86_32
21512 + . = ALIGN(PAGE_SIZE);
21513 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
21514 + *(.idt)
21515 + . = ALIGN(PAGE_SIZE);
21516 + *(.empty_zero_page)
21517 + *(.initial_pg_fixmap)
21518 + *(.initial_pg_pmd)
21519 + *(.initial_page_table)
21520 + *(.swapper_pg_dir)
21521 + } :rodata
21522 +#endif
21523 +
21524 + . = ALIGN(PAGE_SIZE);
21525 + NOTES :rodata :note
21526 +
21527 + EXCEPTION_TABLE(16) :rodata
21528
21529 #if defined(CONFIG_DEBUG_RODATA)
21530 /* .text should occupy whole number of pages */
21531 @@ -126,16 +181,20 @@ SECTIONS
21532
21533 /* Data */
21534 .data : AT(ADDR(.data) - LOAD_OFFSET) {
21535 +
21536 +#ifdef CONFIG_PAX_KERNEXEC
21537 + . = ALIGN(HPAGE_SIZE);
21538 +#else
21539 + . = ALIGN(PAGE_SIZE);
21540 +#endif
21541 +
21542 /* Start of data section */
21543 _sdata = .;
21544
21545 /* init_task */
21546 INIT_TASK_DATA(THREAD_SIZE)
21547
21548 -#ifdef CONFIG_X86_32
21549 - /* 32 bit has nosave before _edata */
21550 NOSAVE_DATA
21551 -#endif
21552
21553 PAGE_ALIGNED_DATA(PAGE_SIZE)
21554
21555 @@ -176,12 +235,19 @@ SECTIONS
21556 #endif /* CONFIG_X86_64 */
21557
21558 /* Init code and data - will be freed after init */
21559 - . = ALIGN(PAGE_SIZE);
21560 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
21561 + BYTE(0)
21562 +
21563 +#ifdef CONFIG_PAX_KERNEXEC
21564 + . = ALIGN(HPAGE_SIZE);
21565 +#else
21566 + . = ALIGN(PAGE_SIZE);
21567 +#endif
21568 +
21569 __init_begin = .; /* paired with __init_end */
21570 - }
21571 + } :init.begin
21572
21573 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
21574 +#ifdef CONFIG_SMP
21575 /*
21576 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
21577 * output PHDR, so the next output section - .init.text - should
21578 @@ -190,12 +256,27 @@ SECTIONS
21579 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
21580 #endif
21581
21582 - INIT_TEXT_SECTION(PAGE_SIZE)
21583 -#ifdef CONFIG_X86_64
21584 - :init
21585 -#endif
21586 + . = ALIGN(PAGE_SIZE);
21587 + init_begin = .;
21588 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
21589 + VMLINUX_SYMBOL(_sinittext) = .;
21590 + INIT_TEXT
21591 + VMLINUX_SYMBOL(_einittext) = .;
21592 + . = ALIGN(PAGE_SIZE);
21593 + } :text.init
21594
21595 - INIT_DATA_SECTION(16)
21596 + /*
21597 + * .exit.text is discard at runtime, not link time, to deal with
21598 + * references from .altinstructions and .eh_frame
21599 + */
21600 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21601 + EXIT_TEXT
21602 + . = ALIGN(16);
21603 + } :text.exit
21604 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
21605 +
21606 + . = ALIGN(PAGE_SIZE);
21607 + INIT_DATA_SECTION(16) :init
21608
21609 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
21610 __x86_cpu_dev_start = .;
21611 @@ -257,19 +338,12 @@ SECTIONS
21612 }
21613
21614 . = ALIGN(8);
21615 - /*
21616 - * .exit.text is discard at runtime, not link time, to deal with
21617 - * references from .altinstructions and .eh_frame
21618 - */
21619 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
21620 - EXIT_TEXT
21621 - }
21622
21623 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
21624 EXIT_DATA
21625 }
21626
21627 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
21628 +#ifndef CONFIG_SMP
21629 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
21630 #endif
21631
21632 @@ -288,16 +362,10 @@ SECTIONS
21633 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
21634 __smp_locks = .;
21635 *(.smp_locks)
21636 - . = ALIGN(PAGE_SIZE);
21637 __smp_locks_end = .;
21638 + . = ALIGN(PAGE_SIZE);
21639 }
21640
21641 -#ifdef CONFIG_X86_64
21642 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
21643 - NOSAVE_DATA
21644 - }
21645 -#endif
21646 -
21647 /* BSS */
21648 . = ALIGN(PAGE_SIZE);
21649 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
21650 @@ -313,6 +381,7 @@ SECTIONS
21651 __brk_base = .;
21652 . += 64 * 1024; /* 64k alignment slop space */
21653 *(.brk_reservation) /* areas brk users have reserved */
21654 + . = ALIGN(HPAGE_SIZE);
21655 __brk_limit = .;
21656 }
21657
21658 @@ -339,13 +408,12 @@ SECTIONS
21659 * for the boot processor.
21660 */
21661 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
21662 -INIT_PER_CPU(gdt_page);
21663 INIT_PER_CPU(irq_stack_union);
21664
21665 /*
21666 * Build-time check on the image size:
21667 */
21668 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
21669 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
21670 "kernel image bigger than KERNEL_IMAGE_SIZE");
21671
21672 #ifdef CONFIG_SMP
21673 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
21674 index 992f890..0ab1aae 100644
21675 --- a/arch/x86/kernel/vsmp_64.c
21676 +++ b/arch/x86/kernel/vsmp_64.c
21677 @@ -114,7 +114,7 @@ static void __init set_vsmp_pv_ops(void)
21678 pv_irq_ops.irq_enable = PV_CALLEE_SAVE(vsmp_irq_enable);
21679 pv_irq_ops.save_fl = PV_CALLEE_SAVE(vsmp_save_fl);
21680 pv_irq_ops.restore_fl = PV_CALLEE_SAVE(vsmp_restore_fl);
21681 - pv_init_ops.patch = vsmp_patch;
21682 + *(void **)&pv_init_ops.patch = vsmp_patch;
21683 ctl &= ~(1 << 4);
21684 }
21685 writel(ctl, address + 4);
21686 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
21687 static void vsmp_apic_post_init(void)
21688 {
21689 /* need to update phys_pkg_id */
21690 - apic->phys_pkg_id = apicid_phys_pkg_id;
21691 - apic->vector_allocation_domain = fill_vector_allocation_domain;
21692 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
21693 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
21694 }
21695
21696 void __init vsmp_init(void)
21697 @@ -227,7 +227,7 @@ void __init vsmp_init(void)
21698 if (!is_vsmp_box())
21699 return;
21700
21701 - x86_platform.apic_post_init = vsmp_apic_post_init;
21702 + *(void **)&x86_platform.apic_post_init = vsmp_apic_post_init;
21703
21704 vsmp_cap_cpus();
21705
21706 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
21707 index 3a3e8c9..1af9465 100644
21708 --- a/arch/x86/kernel/vsyscall_64.c
21709 +++ b/arch/x86/kernel/vsyscall_64.c
21710 @@ -56,15 +56,13 @@
21711 DEFINE_VVAR(int, vgetcpu_mode);
21712 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
21713
21714 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
21715 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
21716
21717 static int __init vsyscall_setup(char *str)
21718 {
21719 if (str) {
21720 if (!strcmp("emulate", str))
21721 vsyscall_mode = EMULATE;
21722 - else if (!strcmp("native", str))
21723 - vsyscall_mode = NATIVE;
21724 else if (!strcmp("none", str))
21725 vsyscall_mode = NONE;
21726 else
21727 @@ -315,8 +313,7 @@ done:
21728 return true;
21729
21730 sigsegv:
21731 - force_sig(SIGSEGV, current);
21732 - return true;
21733 + do_group_exit(SIGKILL);
21734 }
21735
21736 /*
21737 @@ -369,10 +366,7 @@ void __init map_vsyscall(void)
21738 extern char __vvar_page;
21739 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
21740
21741 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
21742 - vsyscall_mode == NATIVE
21743 - ? PAGE_KERNEL_VSYSCALL
21744 - : PAGE_KERNEL_VVAR);
21745 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
21746 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
21747 (unsigned long)VSYSCALL_START);
21748
21749 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
21750 index 1330dd1..d220b99 100644
21751 --- a/arch/x86/kernel/x8664_ksyms_64.c
21752 +++ b/arch/x86/kernel/x8664_ksyms_64.c
21753 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
21754 EXPORT_SYMBOL(copy_user_generic_unrolled);
21755 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
21756 EXPORT_SYMBOL(__copy_user_nocache);
21757 -EXPORT_SYMBOL(_copy_from_user);
21758 -EXPORT_SYMBOL(_copy_to_user);
21759
21760 EXPORT_SYMBOL(copy_page);
21761 EXPORT_SYMBOL(clear_page);
21762 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
21763 index ada87a3..afea76d 100644
21764 --- a/arch/x86/kernel/xsave.c
21765 +++ b/arch/x86/kernel/xsave.c
21766 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
21767 {
21768 int err;
21769
21770 + buf = (struct xsave_struct __user *)____m(buf);
21771 if (use_xsave())
21772 err = xsave_user(buf);
21773 else if (use_fxsr())
21774 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
21775 */
21776 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
21777 {
21778 + buf = (void __user *)____m(buf);
21779 if (use_xsave()) {
21780 if ((unsigned long)buf % 64 || fx_only) {
21781 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
21782 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
21783 index ec79e77..420f5cc 100644
21784 --- a/arch/x86/kvm/cpuid.c
21785 +++ b/arch/x86/kvm/cpuid.c
21786 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
21787 struct kvm_cpuid2 *cpuid,
21788 struct kvm_cpuid_entry2 __user *entries)
21789 {
21790 - int r;
21791 + int r, i;
21792
21793 r = -E2BIG;
21794 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
21795 goto out;
21796 r = -EFAULT;
21797 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
21798 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21799 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21800 goto out;
21801 + for (i = 0; i < cpuid->nent; ++i) {
21802 + struct kvm_cpuid_entry2 cpuid_entry;
21803 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
21804 + goto out;
21805 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
21806 + }
21807 vcpu->arch.cpuid_nent = cpuid->nent;
21808 kvm_apic_set_version(vcpu);
21809 kvm_x86_ops->cpuid_update(vcpu);
21810 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
21811 struct kvm_cpuid2 *cpuid,
21812 struct kvm_cpuid_entry2 __user *entries)
21813 {
21814 - int r;
21815 + int r, i;
21816
21817 r = -E2BIG;
21818 if (cpuid->nent < vcpu->arch.cpuid_nent)
21819 goto out;
21820 r = -EFAULT;
21821 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
21822 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21823 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21824 goto out;
21825 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
21826 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
21827 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
21828 + goto out;
21829 + }
21830 return 0;
21831
21832 out:
21833 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
21834 index bba39bf..296540a 100644
21835 --- a/arch/x86/kvm/emulate.c
21836 +++ b/arch/x86/kvm/emulate.c
21837 @@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21838
21839 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
21840 do { \
21841 + unsigned long _tmp; \
21842 __asm__ __volatile__ ( \
21843 _PRE_EFLAGS("0", "4", "2") \
21844 _op _suffix " %"_x"3,%1; " \
21845 @@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21846 /* Raw emulation: instruction has two explicit operands. */
21847 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
21848 do { \
21849 - unsigned long _tmp; \
21850 - \
21851 switch ((ctxt)->dst.bytes) { \
21852 case 2: \
21853 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
21854 @@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21855
21856 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
21857 do { \
21858 - unsigned long _tmp; \
21859 switch ((ctxt)->dst.bytes) { \
21860 case 1: \
21861 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
21862 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
21863 index 43e9fad..3b7c059 100644
21864 --- a/arch/x86/kvm/lapic.c
21865 +++ b/arch/x86/kvm/lapic.c
21866 @@ -55,7 +55,7 @@
21867 #define APIC_BUS_CYCLE_NS 1
21868
21869 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
21870 -#define apic_debug(fmt, arg...)
21871 +#define apic_debug(fmt, arg...) do {} while (0)
21872
21873 #define APIC_LVT_NUM 6
21874 /* 14 is the version for Xeon and Pentium 8.4.8*/
21875 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
21876 index 714e2c0..3f7a086 100644
21877 --- a/arch/x86/kvm/paging_tmpl.h
21878 +++ b/arch/x86/kvm/paging_tmpl.h
21879 @@ -208,7 +208,7 @@ retry_walk:
21880 if (unlikely(kvm_is_error_hva(host_addr)))
21881 goto error;
21882
21883 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
21884 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
21885 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
21886 goto error;
21887 walker->ptep_user[walker->level - 1] = ptep_user;
21888 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
21889 index d017df3..61ae42e 100644
21890 --- a/arch/x86/kvm/svm.c
21891 +++ b/arch/x86/kvm/svm.c
21892 @@ -3500,7 +3500,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
21893 int cpu = raw_smp_processor_id();
21894
21895 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
21896 +
21897 + pax_open_kernel();
21898 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
21899 + pax_close_kernel();
21900 +
21901 load_TR_desc();
21902 }
21903
21904 @@ -3874,6 +3878,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
21905 #endif
21906 #endif
21907
21908 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21909 + __set_fs(current_thread_info()->addr_limit);
21910 +#endif
21911 +
21912 reload_tss(vcpu);
21913
21914 local_irq_disable();
21915 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
21916 index f858159..4ab7dba 100644
21917 --- a/arch/x86/kvm/vmx.c
21918 +++ b/arch/x86/kvm/vmx.c
21919 @@ -1332,7 +1332,11 @@ static void reload_tss(void)
21920 struct desc_struct *descs;
21921
21922 descs = (void *)gdt->address;
21923 +
21924 + pax_open_kernel();
21925 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
21926 + pax_close_kernel();
21927 +
21928 load_TR_desc();
21929 }
21930
21931 @@ -1546,6 +1550,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
21932 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
21933 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
21934
21935 +#ifdef CONFIG_PAX_PER_CPU_PGD
21936 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
21937 +#endif
21938 +
21939 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
21940 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
21941 vmx->loaded_vmcs->cpu = cpu;
21942 @@ -2669,8 +2677,11 @@ static __init int hardware_setup(void)
21943 if (!cpu_has_vmx_flexpriority())
21944 flexpriority_enabled = 0;
21945
21946 - if (!cpu_has_vmx_tpr_shadow())
21947 - kvm_x86_ops->update_cr8_intercept = NULL;
21948 + if (!cpu_has_vmx_tpr_shadow()) {
21949 + pax_open_kernel();
21950 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
21951 + pax_close_kernel();
21952 + }
21953
21954 if (enable_ept && !cpu_has_vmx_ept_2m_page())
21955 kvm_disable_largepages();
21956 @@ -3712,7 +3723,10 @@ static void vmx_set_constant_host_state(void)
21957
21958 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
21959 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
21960 +
21961 +#ifndef CONFIG_PAX_PER_CPU_PGD
21962 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
21963 +#endif
21964
21965 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
21966 #ifdef CONFIG_X86_64
21967 @@ -3733,7 +3747,7 @@ static void vmx_set_constant_host_state(void)
21968 native_store_idt(&dt);
21969 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
21970
21971 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
21972 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
21973
21974 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
21975 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
21976 @@ -6279,6 +6293,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21977 "jmp 2f \n\t"
21978 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
21979 "2: "
21980 +
21981 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21982 + "ljmp %[cs],$3f\n\t"
21983 + "3: "
21984 +#endif
21985 +
21986 /* Save guest registers, load host registers, keep flags */
21987 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
21988 "pop %0 \n\t"
21989 @@ -6331,6 +6351,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21990 #endif
21991 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
21992 [wordsize]"i"(sizeof(ulong))
21993 +
21994 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21995 + ,[cs]"i"(__KERNEL_CS)
21996 +#endif
21997 +
21998 : "cc", "memory"
21999 #ifdef CONFIG_X86_64
22000 , "rax", "rbx", "rdi", "rsi"
22001 @@ -6344,7 +6369,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22002 if (debugctlmsr)
22003 update_debugctlmsr(debugctlmsr);
22004
22005 -#ifndef CONFIG_X86_64
22006 +#ifdef CONFIG_X86_32
22007 /*
22008 * The sysexit path does not restore ds/es, so we must set them to
22009 * a reasonable value ourselves.
22010 @@ -6353,8 +6378,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22011 * may be executed in interrupt context, which saves and restore segments
22012 * around it, nullifying its effect.
22013 */
22014 - loadsegment(ds, __USER_DS);
22015 - loadsegment(es, __USER_DS);
22016 + loadsegment(ds, __KERNEL_DS);
22017 + loadsegment(es, __KERNEL_DS);
22018 + loadsegment(ss, __KERNEL_DS);
22019 +
22020 +#ifdef CONFIG_PAX_KERNEXEC
22021 + loadsegment(fs, __KERNEL_PERCPU);
22022 +#endif
22023 +
22024 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22025 + __set_fs(current_thread_info()->addr_limit);
22026 +#endif
22027 +
22028 #endif
22029
22030 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
22031 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
22032 index 4f76417..93429b5 100644
22033 --- a/arch/x86/kvm/x86.c
22034 +++ b/arch/x86/kvm/x86.c
22035 @@ -1390,8 +1390,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
22036 {
22037 struct kvm *kvm = vcpu->kvm;
22038 int lm = is_long_mode(vcpu);
22039 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
22040 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
22041 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
22042 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
22043 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
22044 : kvm->arch.xen_hvm_config.blob_size_32;
22045 u32 page_num = data & ~PAGE_MASK;
22046 @@ -2255,6 +2255,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
22047 if (n < msr_list.nmsrs)
22048 goto out;
22049 r = -EFAULT;
22050 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
22051 + goto out;
22052 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
22053 num_msrs_to_save * sizeof(u32)))
22054 goto out;
22055 @@ -2379,7 +2381,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
22056 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
22057 struct kvm_interrupt *irq)
22058 {
22059 - if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
22060 + if (irq->irq >= KVM_NR_INTERRUPTS)
22061 return -EINVAL;
22062 if (irqchip_in_kernel(vcpu->kvm))
22063 return -ENXIO;
22064 @@ -4881,7 +4883,7 @@ static void kvm_set_mmio_spte_mask(void)
22065 kvm_mmu_set_mmio_spte_mask(mask);
22066 }
22067
22068 -int kvm_arch_init(void *opaque)
22069 +int kvm_arch_init(const void *opaque)
22070 {
22071 int r;
22072 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
22073 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
22074 index 642d880..5dd034e 100644
22075 --- a/arch/x86/lguest/boot.c
22076 +++ b/arch/x86/lguest/boot.c
22077 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
22078
22079 static void set_lguest_basic_apic_ops(void)
22080 {
22081 - apic->read = lguest_apic_read;
22082 - apic->write = lguest_apic_write;
22083 - apic->icr_read = lguest_apic_icr_read;
22084 - apic->icr_write = lguest_apic_icr_write;
22085 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
22086 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
22087 + *(void **)&apic->read = lguest_apic_read;
22088 + *(void **)&apic->write = lguest_apic_write;
22089 + *(void **)&apic->icr_read = lguest_apic_icr_read;
22090 + *(void **)&apic->icr_write = lguest_apic_icr_write;
22091 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
22092 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
22093 };
22094 #endif
22095
22096 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
22097 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
22098 * Launcher to reboot us.
22099 */
22100 -static void lguest_restart(char *reason)
22101 +static __noreturn void lguest_restart(char *reason)
22102 {
22103 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
22104 + BUG();
22105 }
22106
22107 /*G:050
22108 @@ -1292,28 +1293,28 @@ __init void lguest_init(void)
22109 pv_irq_ops.safe_halt = lguest_safe_halt;
22110
22111 /* Setup operations */
22112 - pv_init_ops.patch = lguest_patch;
22113 + *(void **)&pv_init_ops.patch = lguest_patch;
22114
22115 /* Intercepts of various CPU instructions */
22116 - pv_cpu_ops.load_gdt = lguest_load_gdt;
22117 - pv_cpu_ops.cpuid = lguest_cpuid;
22118 - pv_cpu_ops.load_idt = lguest_load_idt;
22119 - pv_cpu_ops.iret = lguest_iret;
22120 - pv_cpu_ops.load_sp0 = lguest_load_sp0;
22121 - pv_cpu_ops.load_tr_desc = lguest_load_tr_desc;
22122 - pv_cpu_ops.set_ldt = lguest_set_ldt;
22123 - pv_cpu_ops.load_tls = lguest_load_tls;
22124 - pv_cpu_ops.set_debugreg = lguest_set_debugreg;
22125 - pv_cpu_ops.clts = lguest_clts;
22126 - pv_cpu_ops.read_cr0 = lguest_read_cr0;
22127 - pv_cpu_ops.write_cr0 = lguest_write_cr0;
22128 - pv_cpu_ops.read_cr4 = lguest_read_cr4;
22129 - pv_cpu_ops.write_cr4 = lguest_write_cr4;
22130 - pv_cpu_ops.write_gdt_entry = lguest_write_gdt_entry;
22131 - pv_cpu_ops.write_idt_entry = lguest_write_idt_entry;
22132 - pv_cpu_ops.wbinvd = lguest_wbinvd;
22133 - pv_cpu_ops.start_context_switch = paravirt_start_context_switch;
22134 - pv_cpu_ops.end_context_switch = lguest_end_context_switch;
22135 + *(void **)&pv_cpu_ops.load_gdt = lguest_load_gdt;
22136 + *(void **)&pv_cpu_ops.cpuid = lguest_cpuid;
22137 + *(void **)&pv_cpu_ops.load_idt = lguest_load_idt;
22138 + *(void **)&pv_cpu_ops.iret = lguest_iret;
22139 + *(void **)&pv_cpu_ops.load_sp0 = lguest_load_sp0;
22140 + *(void **)&pv_cpu_ops.load_tr_desc = lguest_load_tr_desc;
22141 + *(void **)&pv_cpu_ops.set_ldt = lguest_set_ldt;
22142 + *(void **)&pv_cpu_ops.load_tls = lguest_load_tls;
22143 + *(void **)&pv_cpu_ops.set_debugreg = lguest_set_debugreg;
22144 + *(void **)&pv_cpu_ops.clts = lguest_clts;
22145 + *(void **)&pv_cpu_ops.read_cr0 = lguest_read_cr0;
22146 + *(void **)&pv_cpu_ops.write_cr0 = lguest_write_cr0;
22147 + *(void **)&pv_cpu_ops.read_cr4 = lguest_read_cr4;
22148 + *(void **)&pv_cpu_ops.write_cr4 = lguest_write_cr4;
22149 + *(void **)&pv_cpu_ops.write_gdt_entry = lguest_write_gdt_entry;
22150 + *(void **)&pv_cpu_ops.write_idt_entry = lguest_write_idt_entry;
22151 + *(void **)&pv_cpu_ops.wbinvd = lguest_wbinvd;
22152 + *(void **)&pv_cpu_ops.start_context_switch = paravirt_start_context_switch;
22153 + *(void **)&pv_cpu_ops.end_context_switch = lguest_end_context_switch;
22154
22155 /* Pagetable management */
22156 pv_mmu_ops.write_cr3 = lguest_write_cr3;
22157 @@ -1341,11 +1342,11 @@ __init void lguest_init(void)
22158 set_lguest_basic_apic_ops();
22159 #endif
22160
22161 - x86_init.resources.memory_setup = lguest_memory_setup;
22162 - x86_init.irqs.intr_init = lguest_init_IRQ;
22163 - x86_init.timers.timer_init = lguest_time_init;
22164 - x86_platform.calibrate_tsc = lguest_tsc_khz;
22165 - x86_platform.get_wallclock = lguest_get_wallclock;
22166 + *(void **)&x86_init.resources.memory_setup = lguest_memory_setup;
22167 + *(void **)&x86_init.irqs.intr_init = lguest_init_IRQ;
22168 + *(void **)&x86_init.timers.timer_init = lguest_time_init;
22169 + *(void **)&x86_platform.calibrate_tsc = lguest_tsc_khz;
22170 + *(void **)&x86_platform.get_wallclock = lguest_get_wallclock;
22171
22172 /*
22173 * Now is a good time to look at the implementations of these functions
22174 @@ -1434,7 +1435,7 @@ __init void lguest_init(void)
22175 * routine.
22176 */
22177 pm_power_off = lguest_power_off;
22178 - machine_ops.restart = lguest_restart;
22179 + *(void **)&machine_ops.restart = lguest_restart;
22180
22181 /*
22182 * Now we're set up, call i386_start_kernel() in head32.c and we proceed
22183 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
22184 index 00933d5..3a64af9 100644
22185 --- a/arch/x86/lib/atomic64_386_32.S
22186 +++ b/arch/x86/lib/atomic64_386_32.S
22187 @@ -48,6 +48,10 @@ BEGIN(read)
22188 movl (v), %eax
22189 movl 4(v), %edx
22190 RET_ENDP
22191 +BEGIN(read_unchecked)
22192 + movl (v), %eax
22193 + movl 4(v), %edx
22194 +RET_ENDP
22195 #undef v
22196
22197 #define v %esi
22198 @@ -55,6 +59,10 @@ BEGIN(set)
22199 movl %ebx, (v)
22200 movl %ecx, 4(v)
22201 RET_ENDP
22202 +BEGIN(set_unchecked)
22203 + movl %ebx, (v)
22204 + movl %ecx, 4(v)
22205 +RET_ENDP
22206 #undef v
22207
22208 #define v %esi
22209 @@ -70,6 +78,20 @@ RET_ENDP
22210 BEGIN(add)
22211 addl %eax, (v)
22212 adcl %edx, 4(v)
22213 +
22214 +#ifdef CONFIG_PAX_REFCOUNT
22215 + jno 0f
22216 + subl %eax, (v)
22217 + sbbl %edx, 4(v)
22218 + int $4
22219 +0:
22220 + _ASM_EXTABLE(0b, 0b)
22221 +#endif
22222 +
22223 +RET_ENDP
22224 +BEGIN(add_unchecked)
22225 + addl %eax, (v)
22226 + adcl %edx, 4(v)
22227 RET_ENDP
22228 #undef v
22229
22230 @@ -77,6 +99,24 @@ RET_ENDP
22231 BEGIN(add_return)
22232 addl (v), %eax
22233 adcl 4(v), %edx
22234 +
22235 +#ifdef CONFIG_PAX_REFCOUNT
22236 + into
22237 +1234:
22238 + _ASM_EXTABLE(1234b, 2f)
22239 +#endif
22240 +
22241 + movl %eax, (v)
22242 + movl %edx, 4(v)
22243 +
22244 +#ifdef CONFIG_PAX_REFCOUNT
22245 +2:
22246 +#endif
22247 +
22248 +RET_ENDP
22249 +BEGIN(add_return_unchecked)
22250 + addl (v), %eax
22251 + adcl 4(v), %edx
22252 movl %eax, (v)
22253 movl %edx, 4(v)
22254 RET_ENDP
22255 @@ -86,6 +126,20 @@ RET_ENDP
22256 BEGIN(sub)
22257 subl %eax, (v)
22258 sbbl %edx, 4(v)
22259 +
22260 +#ifdef CONFIG_PAX_REFCOUNT
22261 + jno 0f
22262 + addl %eax, (v)
22263 + adcl %edx, 4(v)
22264 + int $4
22265 +0:
22266 + _ASM_EXTABLE(0b, 0b)
22267 +#endif
22268 +
22269 +RET_ENDP
22270 +BEGIN(sub_unchecked)
22271 + subl %eax, (v)
22272 + sbbl %edx, 4(v)
22273 RET_ENDP
22274 #undef v
22275
22276 @@ -96,6 +150,27 @@ BEGIN(sub_return)
22277 sbbl $0, %edx
22278 addl (v), %eax
22279 adcl 4(v), %edx
22280 +
22281 +#ifdef CONFIG_PAX_REFCOUNT
22282 + into
22283 +1234:
22284 + _ASM_EXTABLE(1234b, 2f)
22285 +#endif
22286 +
22287 + movl %eax, (v)
22288 + movl %edx, 4(v)
22289 +
22290 +#ifdef CONFIG_PAX_REFCOUNT
22291 +2:
22292 +#endif
22293 +
22294 +RET_ENDP
22295 +BEGIN(sub_return_unchecked)
22296 + negl %edx
22297 + negl %eax
22298 + sbbl $0, %edx
22299 + addl (v), %eax
22300 + adcl 4(v), %edx
22301 movl %eax, (v)
22302 movl %edx, 4(v)
22303 RET_ENDP
22304 @@ -105,6 +180,20 @@ RET_ENDP
22305 BEGIN(inc)
22306 addl $1, (v)
22307 adcl $0, 4(v)
22308 +
22309 +#ifdef CONFIG_PAX_REFCOUNT
22310 + jno 0f
22311 + subl $1, (v)
22312 + sbbl $0, 4(v)
22313 + int $4
22314 +0:
22315 + _ASM_EXTABLE(0b, 0b)
22316 +#endif
22317 +
22318 +RET_ENDP
22319 +BEGIN(inc_unchecked)
22320 + addl $1, (v)
22321 + adcl $0, 4(v)
22322 RET_ENDP
22323 #undef v
22324
22325 @@ -114,6 +203,26 @@ BEGIN(inc_return)
22326 movl 4(v), %edx
22327 addl $1, %eax
22328 adcl $0, %edx
22329 +
22330 +#ifdef CONFIG_PAX_REFCOUNT
22331 + into
22332 +1234:
22333 + _ASM_EXTABLE(1234b, 2f)
22334 +#endif
22335 +
22336 + movl %eax, (v)
22337 + movl %edx, 4(v)
22338 +
22339 +#ifdef CONFIG_PAX_REFCOUNT
22340 +2:
22341 +#endif
22342 +
22343 +RET_ENDP
22344 +BEGIN(inc_return_unchecked)
22345 + movl (v), %eax
22346 + movl 4(v), %edx
22347 + addl $1, %eax
22348 + adcl $0, %edx
22349 movl %eax, (v)
22350 movl %edx, 4(v)
22351 RET_ENDP
22352 @@ -123,6 +232,20 @@ RET_ENDP
22353 BEGIN(dec)
22354 subl $1, (v)
22355 sbbl $0, 4(v)
22356 +
22357 +#ifdef CONFIG_PAX_REFCOUNT
22358 + jno 0f
22359 + addl $1, (v)
22360 + adcl $0, 4(v)
22361 + int $4
22362 +0:
22363 + _ASM_EXTABLE(0b, 0b)
22364 +#endif
22365 +
22366 +RET_ENDP
22367 +BEGIN(dec_unchecked)
22368 + subl $1, (v)
22369 + sbbl $0, 4(v)
22370 RET_ENDP
22371 #undef v
22372
22373 @@ -132,6 +255,26 @@ BEGIN(dec_return)
22374 movl 4(v), %edx
22375 subl $1, %eax
22376 sbbl $0, %edx
22377 +
22378 +#ifdef CONFIG_PAX_REFCOUNT
22379 + into
22380 +1234:
22381 + _ASM_EXTABLE(1234b, 2f)
22382 +#endif
22383 +
22384 + movl %eax, (v)
22385 + movl %edx, 4(v)
22386 +
22387 +#ifdef CONFIG_PAX_REFCOUNT
22388 +2:
22389 +#endif
22390 +
22391 +RET_ENDP
22392 +BEGIN(dec_return_unchecked)
22393 + movl (v), %eax
22394 + movl 4(v), %edx
22395 + subl $1, %eax
22396 + sbbl $0, %edx
22397 movl %eax, (v)
22398 movl %edx, 4(v)
22399 RET_ENDP
22400 @@ -143,6 +286,13 @@ BEGIN(add_unless)
22401 adcl %edx, %edi
22402 addl (v), %eax
22403 adcl 4(v), %edx
22404 +
22405 +#ifdef CONFIG_PAX_REFCOUNT
22406 + into
22407 +1234:
22408 + _ASM_EXTABLE(1234b, 2f)
22409 +#endif
22410 +
22411 cmpl %eax, %ecx
22412 je 3f
22413 1:
22414 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
22415 1:
22416 addl $1, %eax
22417 adcl $0, %edx
22418 +
22419 +#ifdef CONFIG_PAX_REFCOUNT
22420 + into
22421 +1234:
22422 + _ASM_EXTABLE(1234b, 2f)
22423 +#endif
22424 +
22425 movl %eax, (v)
22426 movl %edx, 4(v)
22427 movl $1, %eax
22428 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
22429 movl 4(v), %edx
22430 subl $1, %eax
22431 sbbl $0, %edx
22432 +
22433 +#ifdef CONFIG_PAX_REFCOUNT
22434 + into
22435 +1234:
22436 + _ASM_EXTABLE(1234b, 1f)
22437 +#endif
22438 +
22439 js 1f
22440 movl %eax, (v)
22441 movl %edx, 4(v)
22442 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
22443 index f5cc9eb..51fa319 100644
22444 --- a/arch/x86/lib/atomic64_cx8_32.S
22445 +++ b/arch/x86/lib/atomic64_cx8_32.S
22446 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
22447 CFI_STARTPROC
22448
22449 read64 %ecx
22450 + pax_force_retaddr
22451 ret
22452 CFI_ENDPROC
22453 ENDPROC(atomic64_read_cx8)
22454
22455 +ENTRY(atomic64_read_unchecked_cx8)
22456 + CFI_STARTPROC
22457 +
22458 + read64 %ecx
22459 + pax_force_retaddr
22460 + ret
22461 + CFI_ENDPROC
22462 +ENDPROC(atomic64_read_unchecked_cx8)
22463 +
22464 ENTRY(atomic64_set_cx8)
22465 CFI_STARTPROC
22466
22467 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
22468 cmpxchg8b (%esi)
22469 jne 1b
22470
22471 + pax_force_retaddr
22472 ret
22473 CFI_ENDPROC
22474 ENDPROC(atomic64_set_cx8)
22475
22476 +ENTRY(atomic64_set_unchecked_cx8)
22477 + CFI_STARTPROC
22478 +
22479 +1:
22480 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
22481 + * are atomic on 586 and newer */
22482 + cmpxchg8b (%esi)
22483 + jne 1b
22484 +
22485 + pax_force_retaddr
22486 + ret
22487 + CFI_ENDPROC
22488 +ENDPROC(atomic64_set_unchecked_cx8)
22489 +
22490 ENTRY(atomic64_xchg_cx8)
22491 CFI_STARTPROC
22492
22493 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
22494 cmpxchg8b (%esi)
22495 jne 1b
22496
22497 + pax_force_retaddr
22498 ret
22499 CFI_ENDPROC
22500 ENDPROC(atomic64_xchg_cx8)
22501
22502 -.macro addsub_return func ins insc
22503 -ENTRY(atomic64_\func\()_return_cx8)
22504 +.macro addsub_return func ins insc unchecked=""
22505 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22506 CFI_STARTPROC
22507 SAVE ebp
22508 SAVE ebx
22509 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
22510 movl %edx, %ecx
22511 \ins\()l %esi, %ebx
22512 \insc\()l %edi, %ecx
22513 +
22514 +.ifb \unchecked
22515 +#ifdef CONFIG_PAX_REFCOUNT
22516 + into
22517 +2:
22518 + _ASM_EXTABLE(2b, 3f)
22519 +#endif
22520 +.endif
22521 +
22522 LOCK_PREFIX
22523 cmpxchg8b (%ebp)
22524 jne 1b
22525 -
22526 -10:
22527 movl %ebx, %eax
22528 movl %ecx, %edx
22529 +
22530 +.ifb \unchecked
22531 +#ifdef CONFIG_PAX_REFCOUNT
22532 +3:
22533 +#endif
22534 +.endif
22535 +
22536 RESTORE edi
22537 RESTORE esi
22538 RESTORE ebx
22539 RESTORE ebp
22540 + pax_force_retaddr
22541 ret
22542 CFI_ENDPROC
22543 -ENDPROC(atomic64_\func\()_return_cx8)
22544 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22545 .endm
22546
22547 addsub_return add add adc
22548 addsub_return sub sub sbb
22549 +addsub_return add add adc _unchecked
22550 +addsub_return sub sub sbb _unchecked
22551
22552 -.macro incdec_return func ins insc
22553 -ENTRY(atomic64_\func\()_return_cx8)
22554 +.macro incdec_return func ins insc unchecked=""
22555 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22556 CFI_STARTPROC
22557 SAVE ebx
22558
22559 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
22560 movl %edx, %ecx
22561 \ins\()l $1, %ebx
22562 \insc\()l $0, %ecx
22563 +
22564 +.ifb \unchecked
22565 +#ifdef CONFIG_PAX_REFCOUNT
22566 + into
22567 +2:
22568 + _ASM_EXTABLE(2b, 3f)
22569 +#endif
22570 +.endif
22571 +
22572 LOCK_PREFIX
22573 cmpxchg8b (%esi)
22574 jne 1b
22575
22576 -10:
22577 movl %ebx, %eax
22578 movl %ecx, %edx
22579 +
22580 +.ifb \unchecked
22581 +#ifdef CONFIG_PAX_REFCOUNT
22582 +3:
22583 +#endif
22584 +.endif
22585 +
22586 RESTORE ebx
22587 + pax_force_retaddr
22588 ret
22589 CFI_ENDPROC
22590 -ENDPROC(atomic64_\func\()_return_cx8)
22591 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22592 .endm
22593
22594 incdec_return inc add adc
22595 incdec_return dec sub sbb
22596 +incdec_return inc add adc _unchecked
22597 +incdec_return dec sub sbb _unchecked
22598
22599 ENTRY(atomic64_dec_if_positive_cx8)
22600 CFI_STARTPROC
22601 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
22602 movl %edx, %ecx
22603 subl $1, %ebx
22604 sbb $0, %ecx
22605 +
22606 +#ifdef CONFIG_PAX_REFCOUNT
22607 + into
22608 +1234:
22609 + _ASM_EXTABLE(1234b, 2f)
22610 +#endif
22611 +
22612 js 2f
22613 LOCK_PREFIX
22614 cmpxchg8b (%esi)
22615 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
22616 movl %ebx, %eax
22617 movl %ecx, %edx
22618 RESTORE ebx
22619 + pax_force_retaddr
22620 ret
22621 CFI_ENDPROC
22622 ENDPROC(atomic64_dec_if_positive_cx8)
22623 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
22624 movl %edx, %ecx
22625 addl %ebp, %ebx
22626 adcl %edi, %ecx
22627 +
22628 +#ifdef CONFIG_PAX_REFCOUNT
22629 + into
22630 +1234:
22631 + _ASM_EXTABLE(1234b, 3f)
22632 +#endif
22633 +
22634 LOCK_PREFIX
22635 cmpxchg8b (%esi)
22636 jne 1b
22637 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
22638 CFI_ADJUST_CFA_OFFSET -8
22639 RESTORE ebx
22640 RESTORE ebp
22641 + pax_force_retaddr
22642 ret
22643 4:
22644 cmpl %edx, 4(%esp)
22645 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
22646 xorl %ecx, %ecx
22647 addl $1, %ebx
22648 adcl %edx, %ecx
22649 +
22650 +#ifdef CONFIG_PAX_REFCOUNT
22651 + into
22652 +1234:
22653 + _ASM_EXTABLE(1234b, 3f)
22654 +#endif
22655 +
22656 LOCK_PREFIX
22657 cmpxchg8b (%esi)
22658 jne 1b
22659 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
22660 movl $1, %eax
22661 3:
22662 RESTORE ebx
22663 + pax_force_retaddr
22664 ret
22665 CFI_ENDPROC
22666 ENDPROC(atomic64_inc_not_zero_cx8)
22667 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
22668 index 2af5df3..62b1a5a 100644
22669 --- a/arch/x86/lib/checksum_32.S
22670 +++ b/arch/x86/lib/checksum_32.S
22671 @@ -29,7 +29,8 @@
22672 #include <asm/dwarf2.h>
22673 #include <asm/errno.h>
22674 #include <asm/asm.h>
22675 -
22676 +#include <asm/segment.h>
22677 +
22678 /*
22679 * computes a partial checksum, e.g. for TCP/UDP fragments
22680 */
22681 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
22682
22683 #define ARGBASE 16
22684 #define FP 12
22685 -
22686 -ENTRY(csum_partial_copy_generic)
22687 +
22688 +ENTRY(csum_partial_copy_generic_to_user)
22689 CFI_STARTPROC
22690 +
22691 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22692 + pushl_cfi %gs
22693 + popl_cfi %es
22694 + jmp csum_partial_copy_generic
22695 +#endif
22696 +
22697 +ENTRY(csum_partial_copy_generic_from_user)
22698 +
22699 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22700 + pushl_cfi %gs
22701 + popl_cfi %ds
22702 +#endif
22703 +
22704 +ENTRY(csum_partial_copy_generic)
22705 subl $4,%esp
22706 CFI_ADJUST_CFA_OFFSET 4
22707 pushl_cfi %edi
22708 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
22709 jmp 4f
22710 SRC(1: movw (%esi), %bx )
22711 addl $2, %esi
22712 -DST( movw %bx, (%edi) )
22713 +DST( movw %bx, %es:(%edi) )
22714 addl $2, %edi
22715 addw %bx, %ax
22716 adcl $0, %eax
22717 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
22718 SRC(1: movl (%esi), %ebx )
22719 SRC( movl 4(%esi), %edx )
22720 adcl %ebx, %eax
22721 -DST( movl %ebx, (%edi) )
22722 +DST( movl %ebx, %es:(%edi) )
22723 adcl %edx, %eax
22724 -DST( movl %edx, 4(%edi) )
22725 +DST( movl %edx, %es:4(%edi) )
22726
22727 SRC( movl 8(%esi), %ebx )
22728 SRC( movl 12(%esi), %edx )
22729 adcl %ebx, %eax
22730 -DST( movl %ebx, 8(%edi) )
22731 +DST( movl %ebx, %es:8(%edi) )
22732 adcl %edx, %eax
22733 -DST( movl %edx, 12(%edi) )
22734 +DST( movl %edx, %es:12(%edi) )
22735
22736 SRC( movl 16(%esi), %ebx )
22737 SRC( movl 20(%esi), %edx )
22738 adcl %ebx, %eax
22739 -DST( movl %ebx, 16(%edi) )
22740 +DST( movl %ebx, %es:16(%edi) )
22741 adcl %edx, %eax
22742 -DST( movl %edx, 20(%edi) )
22743 +DST( movl %edx, %es:20(%edi) )
22744
22745 SRC( movl 24(%esi), %ebx )
22746 SRC( movl 28(%esi), %edx )
22747 adcl %ebx, %eax
22748 -DST( movl %ebx, 24(%edi) )
22749 +DST( movl %ebx, %es:24(%edi) )
22750 adcl %edx, %eax
22751 -DST( movl %edx, 28(%edi) )
22752 +DST( movl %edx, %es:28(%edi) )
22753
22754 lea 32(%esi), %esi
22755 lea 32(%edi), %edi
22756 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
22757 shrl $2, %edx # This clears CF
22758 SRC(3: movl (%esi), %ebx )
22759 adcl %ebx, %eax
22760 -DST( movl %ebx, (%edi) )
22761 +DST( movl %ebx, %es:(%edi) )
22762 lea 4(%esi), %esi
22763 lea 4(%edi), %edi
22764 dec %edx
22765 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
22766 jb 5f
22767 SRC( movw (%esi), %cx )
22768 leal 2(%esi), %esi
22769 -DST( movw %cx, (%edi) )
22770 +DST( movw %cx, %es:(%edi) )
22771 leal 2(%edi), %edi
22772 je 6f
22773 shll $16,%ecx
22774 SRC(5: movb (%esi), %cl )
22775 -DST( movb %cl, (%edi) )
22776 +DST( movb %cl, %es:(%edi) )
22777 6: addl %ecx, %eax
22778 adcl $0, %eax
22779 7:
22780 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
22781
22782 6001:
22783 movl ARGBASE+20(%esp), %ebx # src_err_ptr
22784 - movl $-EFAULT, (%ebx)
22785 + movl $-EFAULT, %ss:(%ebx)
22786
22787 # zero the complete destination - computing the rest
22788 # is too much work
22789 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
22790
22791 6002:
22792 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22793 - movl $-EFAULT,(%ebx)
22794 + movl $-EFAULT,%ss:(%ebx)
22795 jmp 5000b
22796
22797 .previous
22798
22799 + pushl_cfi %ss
22800 + popl_cfi %ds
22801 + pushl_cfi %ss
22802 + popl_cfi %es
22803 popl_cfi %ebx
22804 CFI_RESTORE ebx
22805 popl_cfi %esi
22806 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
22807 popl_cfi %ecx # equivalent to addl $4,%esp
22808 ret
22809 CFI_ENDPROC
22810 -ENDPROC(csum_partial_copy_generic)
22811 +ENDPROC(csum_partial_copy_generic_to_user)
22812
22813 #else
22814
22815 /* Version for PentiumII/PPro */
22816
22817 #define ROUND1(x) \
22818 + nop; nop; nop; \
22819 SRC(movl x(%esi), %ebx ) ; \
22820 addl %ebx, %eax ; \
22821 - DST(movl %ebx, x(%edi) ) ;
22822 + DST(movl %ebx, %es:x(%edi)) ;
22823
22824 #define ROUND(x) \
22825 + nop; nop; nop; \
22826 SRC(movl x(%esi), %ebx ) ; \
22827 adcl %ebx, %eax ; \
22828 - DST(movl %ebx, x(%edi) ) ;
22829 + DST(movl %ebx, %es:x(%edi)) ;
22830
22831 #define ARGBASE 12
22832 -
22833 -ENTRY(csum_partial_copy_generic)
22834 +
22835 +ENTRY(csum_partial_copy_generic_to_user)
22836 CFI_STARTPROC
22837 +
22838 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22839 + pushl_cfi %gs
22840 + popl_cfi %es
22841 + jmp csum_partial_copy_generic
22842 +#endif
22843 +
22844 +ENTRY(csum_partial_copy_generic_from_user)
22845 +
22846 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22847 + pushl_cfi %gs
22848 + popl_cfi %ds
22849 +#endif
22850 +
22851 +ENTRY(csum_partial_copy_generic)
22852 pushl_cfi %ebx
22853 CFI_REL_OFFSET ebx, 0
22854 pushl_cfi %edi
22855 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
22856 subl %ebx, %edi
22857 lea -1(%esi),%edx
22858 andl $-32,%edx
22859 - lea 3f(%ebx,%ebx), %ebx
22860 + lea 3f(%ebx,%ebx,2), %ebx
22861 testl %esi, %esi
22862 jmp *%ebx
22863 1: addl $64,%esi
22864 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
22865 jb 5f
22866 SRC( movw (%esi), %dx )
22867 leal 2(%esi), %esi
22868 -DST( movw %dx, (%edi) )
22869 +DST( movw %dx, %es:(%edi) )
22870 leal 2(%edi), %edi
22871 je 6f
22872 shll $16,%edx
22873 5:
22874 SRC( movb (%esi), %dl )
22875 -DST( movb %dl, (%edi) )
22876 +DST( movb %dl, %es:(%edi) )
22877 6: addl %edx, %eax
22878 adcl $0, %eax
22879 7:
22880 .section .fixup, "ax"
22881 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
22882 - movl $-EFAULT, (%ebx)
22883 + movl $-EFAULT, %ss:(%ebx)
22884 # zero the complete destination (computing the rest is too much work)
22885 movl ARGBASE+8(%esp),%edi # dst
22886 movl ARGBASE+12(%esp),%ecx # len
22887 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
22888 rep; stosb
22889 jmp 7b
22890 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22891 - movl $-EFAULT, (%ebx)
22892 + movl $-EFAULT, %ss:(%ebx)
22893 jmp 7b
22894 .previous
22895
22896 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22897 + pushl_cfi %ss
22898 + popl_cfi %ds
22899 + pushl_cfi %ss
22900 + popl_cfi %es
22901 +#endif
22902 +
22903 popl_cfi %esi
22904 CFI_RESTORE esi
22905 popl_cfi %edi
22906 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
22907 CFI_RESTORE ebx
22908 ret
22909 CFI_ENDPROC
22910 -ENDPROC(csum_partial_copy_generic)
22911 +ENDPROC(csum_partial_copy_generic_to_user)
22912
22913 #undef ROUND
22914 #undef ROUND1
22915 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
22916 index f2145cf..cea889d 100644
22917 --- a/arch/x86/lib/clear_page_64.S
22918 +++ b/arch/x86/lib/clear_page_64.S
22919 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
22920 movl $4096/8,%ecx
22921 xorl %eax,%eax
22922 rep stosq
22923 + pax_force_retaddr
22924 ret
22925 CFI_ENDPROC
22926 ENDPROC(clear_page_c)
22927 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
22928 movl $4096,%ecx
22929 xorl %eax,%eax
22930 rep stosb
22931 + pax_force_retaddr
22932 ret
22933 CFI_ENDPROC
22934 ENDPROC(clear_page_c_e)
22935 @@ -43,6 +45,7 @@ ENTRY(clear_page)
22936 leaq 64(%rdi),%rdi
22937 jnz .Lloop
22938 nop
22939 + pax_force_retaddr
22940 ret
22941 CFI_ENDPROC
22942 .Lclear_page_end:
22943 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
22944
22945 #include <asm/cpufeature.h>
22946
22947 - .section .altinstr_replacement,"ax"
22948 + .section .altinstr_replacement,"a"
22949 1: .byte 0xeb /* jmp <disp8> */
22950 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
22951 2: .byte 0xeb /* jmp <disp8> */
22952 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
22953 index 1e572c5..2a162cd 100644
22954 --- a/arch/x86/lib/cmpxchg16b_emu.S
22955 +++ b/arch/x86/lib/cmpxchg16b_emu.S
22956 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
22957
22958 popf
22959 mov $1, %al
22960 + pax_force_retaddr
22961 ret
22962
22963 not_same:
22964 popf
22965 xor %al,%al
22966 + pax_force_retaddr
22967 ret
22968
22969 CFI_ENDPROC
22970 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
22971 index 6b34d04..dccb07f 100644
22972 --- a/arch/x86/lib/copy_page_64.S
22973 +++ b/arch/x86/lib/copy_page_64.S
22974 @@ -9,6 +9,7 @@ copy_page_c:
22975 CFI_STARTPROC
22976 movl $4096/8,%ecx
22977 rep movsq
22978 + pax_force_retaddr
22979 ret
22980 CFI_ENDPROC
22981 ENDPROC(copy_page_c)
22982 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
22983
22984 ENTRY(copy_page)
22985 CFI_STARTPROC
22986 - subq $2*8,%rsp
22987 - CFI_ADJUST_CFA_OFFSET 2*8
22988 + subq $3*8,%rsp
22989 + CFI_ADJUST_CFA_OFFSET 3*8
22990 movq %rbx,(%rsp)
22991 CFI_REL_OFFSET rbx, 0
22992 movq %r12,1*8(%rsp)
22993 CFI_REL_OFFSET r12, 1*8
22994 + movq %r13,2*8(%rsp)
22995 + CFI_REL_OFFSET r13, 2*8
22996
22997 movl $(4096/64)-5,%ecx
22998 .p2align 4
22999 @@ -37,7 +40,7 @@ ENTRY(copy_page)
23000 movq 16 (%rsi), %rdx
23001 movq 24 (%rsi), %r8
23002 movq 32 (%rsi), %r9
23003 - movq 40 (%rsi), %r10
23004 + movq 40 (%rsi), %r13
23005 movq 48 (%rsi), %r11
23006 movq 56 (%rsi), %r12
23007
23008 @@ -48,7 +51,7 @@ ENTRY(copy_page)
23009 movq %rdx, 16 (%rdi)
23010 movq %r8, 24 (%rdi)
23011 movq %r9, 32 (%rdi)
23012 - movq %r10, 40 (%rdi)
23013 + movq %r13, 40 (%rdi)
23014 movq %r11, 48 (%rdi)
23015 movq %r12, 56 (%rdi)
23016
23017 @@ -67,7 +70,7 @@ ENTRY(copy_page)
23018 movq 16 (%rsi), %rdx
23019 movq 24 (%rsi), %r8
23020 movq 32 (%rsi), %r9
23021 - movq 40 (%rsi), %r10
23022 + movq 40 (%rsi), %r13
23023 movq 48 (%rsi), %r11
23024 movq 56 (%rsi), %r12
23025
23026 @@ -76,7 +79,7 @@ ENTRY(copy_page)
23027 movq %rdx, 16 (%rdi)
23028 movq %r8, 24 (%rdi)
23029 movq %r9, 32 (%rdi)
23030 - movq %r10, 40 (%rdi)
23031 + movq %r13, 40 (%rdi)
23032 movq %r11, 48 (%rdi)
23033 movq %r12, 56 (%rdi)
23034
23035 @@ -89,8 +92,11 @@ ENTRY(copy_page)
23036 CFI_RESTORE rbx
23037 movq 1*8(%rsp),%r12
23038 CFI_RESTORE r12
23039 - addq $2*8,%rsp
23040 - CFI_ADJUST_CFA_OFFSET -2*8
23041 + movq 2*8(%rsp),%r13
23042 + CFI_RESTORE r13
23043 + addq $3*8,%rsp
23044 + CFI_ADJUST_CFA_OFFSET -3*8
23045 + pax_force_retaddr
23046 ret
23047 .Lcopy_page_end:
23048 CFI_ENDPROC
23049 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
23050
23051 #include <asm/cpufeature.h>
23052
23053 - .section .altinstr_replacement,"ax"
23054 + .section .altinstr_replacement,"a"
23055 1: .byte 0xeb /* jmp <disp8> */
23056 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
23057 2:
23058 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
23059 index a30ca15..d25fab6 100644
23060 --- a/arch/x86/lib/copy_user_64.S
23061 +++ b/arch/x86/lib/copy_user_64.S
23062 @@ -18,6 +18,7 @@
23063 #include <asm/alternative-asm.h>
23064 #include <asm/asm.h>
23065 #include <asm/smap.h>
23066 +#include <asm/pgtable.h>
23067
23068 /*
23069 * By placing feature2 after feature1 in altinstructions section, we logically
23070 @@ -31,7 +32,7 @@
23071 .byte 0xe9 /* 32bit jump */
23072 .long \orig-1f /* by default jump to orig */
23073 1:
23074 - .section .altinstr_replacement,"ax"
23075 + .section .altinstr_replacement,"a"
23076 2: .byte 0xe9 /* near jump with 32bit immediate */
23077 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
23078 3: .byte 0xe9 /* near jump with 32bit immediate */
23079 @@ -70,47 +71,20 @@
23080 #endif
23081 .endm
23082
23083 -/* Standard copy_to_user with segment limit checking */
23084 -ENTRY(_copy_to_user)
23085 - CFI_STARTPROC
23086 - GET_THREAD_INFO(%rax)
23087 - movq %rdi,%rcx
23088 - addq %rdx,%rcx
23089 - jc bad_to_user
23090 - cmpq TI_addr_limit(%rax),%rcx
23091 - ja bad_to_user
23092 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
23093 - copy_user_generic_unrolled,copy_user_generic_string, \
23094 - copy_user_enhanced_fast_string
23095 - CFI_ENDPROC
23096 -ENDPROC(_copy_to_user)
23097 -
23098 -/* Standard copy_from_user with segment limit checking */
23099 -ENTRY(_copy_from_user)
23100 - CFI_STARTPROC
23101 - GET_THREAD_INFO(%rax)
23102 - movq %rsi,%rcx
23103 - addq %rdx,%rcx
23104 - jc bad_from_user
23105 - cmpq TI_addr_limit(%rax),%rcx
23106 - ja bad_from_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_from_user)
23112 -
23113 .section .fixup,"ax"
23114 /* must zero dest */
23115 ENTRY(bad_from_user)
23116 bad_from_user:
23117 CFI_STARTPROC
23118 + testl %edx,%edx
23119 + js bad_to_user
23120 movl %edx,%ecx
23121 xorl %eax,%eax
23122 rep
23123 stosb
23124 bad_to_user:
23125 movl %edx,%eax
23126 + pax_force_retaddr
23127 ret
23128 CFI_ENDPROC
23129 ENDPROC(bad_from_user)
23130 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
23131 jz 17f
23132 1: movq (%rsi),%r8
23133 2: movq 1*8(%rsi),%r9
23134 -3: movq 2*8(%rsi),%r10
23135 +3: movq 2*8(%rsi),%rax
23136 4: movq 3*8(%rsi),%r11
23137 5: movq %r8,(%rdi)
23138 6: movq %r9,1*8(%rdi)
23139 -7: movq %r10,2*8(%rdi)
23140 +7: movq %rax,2*8(%rdi)
23141 8: movq %r11,3*8(%rdi)
23142 9: movq 4*8(%rsi),%r8
23143 10: movq 5*8(%rsi),%r9
23144 -11: movq 6*8(%rsi),%r10
23145 +11: movq 6*8(%rsi),%rax
23146 12: movq 7*8(%rsi),%r11
23147 13: movq %r8,4*8(%rdi)
23148 14: movq %r9,5*8(%rdi)
23149 -15: movq %r10,6*8(%rdi)
23150 +15: movq %rax,6*8(%rdi)
23151 16: movq %r11,7*8(%rdi)
23152 leaq 64(%rsi),%rsi
23153 leaq 64(%rdi),%rdi
23154 @@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
23155 jnz 21b
23156 23: xor %eax,%eax
23157 ASM_CLAC
23158 + pax_force_retaddr
23159 ret
23160
23161 .section .fixup,"ax"
23162 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
23163 movsb
23164 4: xorl %eax,%eax
23165 ASM_CLAC
23166 + pax_force_retaddr
23167 ret
23168
23169 .section .fixup,"ax"
23170 @@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
23171 movsb
23172 2: xorl %eax,%eax
23173 ASM_CLAC
23174 + pax_force_retaddr
23175 ret
23176
23177 .section .fixup,"ax"
23178 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
23179 index 6a4f43c..f5f9e26 100644
23180 --- a/arch/x86/lib/copy_user_nocache_64.S
23181 +++ b/arch/x86/lib/copy_user_nocache_64.S
23182 @@ -8,6 +8,7 @@
23183
23184 #include <linux/linkage.h>
23185 #include <asm/dwarf2.h>
23186 +#include <asm/alternative-asm.h>
23187
23188 #define FIX_ALIGNMENT 1
23189
23190 @@ -16,6 +17,7 @@
23191 #include <asm/thread_info.h>
23192 #include <asm/asm.h>
23193 #include <asm/smap.h>
23194 +#include <asm/pgtable.h>
23195
23196 .macro ALIGN_DESTINATION
23197 #ifdef FIX_ALIGNMENT
23198 @@ -49,6 +51,15 @@
23199 */
23200 ENTRY(__copy_user_nocache)
23201 CFI_STARTPROC
23202 +
23203 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23204 + mov $PAX_USER_SHADOW_BASE,%rcx
23205 + cmp %rcx,%rsi
23206 + jae 1f
23207 + add %rcx,%rsi
23208 +1:
23209 +#endif
23210 +
23211 ASM_STAC
23212 cmpl $8,%edx
23213 jb 20f /* less then 8 bytes, go to byte copy loop */
23214 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
23215 jz 17f
23216 1: movq (%rsi),%r8
23217 2: movq 1*8(%rsi),%r9
23218 -3: movq 2*8(%rsi),%r10
23219 +3: movq 2*8(%rsi),%rax
23220 4: movq 3*8(%rsi),%r11
23221 5: movnti %r8,(%rdi)
23222 6: movnti %r9,1*8(%rdi)
23223 -7: movnti %r10,2*8(%rdi)
23224 +7: movnti %rax,2*8(%rdi)
23225 8: movnti %r11,3*8(%rdi)
23226 9: movq 4*8(%rsi),%r8
23227 10: movq 5*8(%rsi),%r9
23228 -11: movq 6*8(%rsi),%r10
23229 +11: movq 6*8(%rsi),%rax
23230 12: movq 7*8(%rsi),%r11
23231 13: movnti %r8,4*8(%rdi)
23232 14: movnti %r9,5*8(%rdi)
23233 -15: movnti %r10,6*8(%rdi)
23234 +15: movnti %rax,6*8(%rdi)
23235 16: movnti %r11,7*8(%rdi)
23236 leaq 64(%rsi),%rsi
23237 leaq 64(%rdi),%rdi
23238 @@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
23239 23: xorl %eax,%eax
23240 ASM_CLAC
23241 sfence
23242 + pax_force_retaddr
23243 ret
23244
23245 .section .fixup,"ax"
23246 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
23247 index 2419d5f..953ee51 100644
23248 --- a/arch/x86/lib/csum-copy_64.S
23249 +++ b/arch/x86/lib/csum-copy_64.S
23250 @@ -9,6 +9,7 @@
23251 #include <asm/dwarf2.h>
23252 #include <asm/errno.h>
23253 #include <asm/asm.h>
23254 +#include <asm/alternative-asm.h>
23255
23256 /*
23257 * Checksum copy with exception handling.
23258 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
23259 CFI_RESTORE rbp
23260 addq $7*8, %rsp
23261 CFI_ADJUST_CFA_OFFSET -7*8
23262 + pax_force_retaddr 0, 1
23263 ret
23264 CFI_RESTORE_STATE
23265
23266 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
23267 index 25b7ae8..169fafc 100644
23268 --- a/arch/x86/lib/csum-wrappers_64.c
23269 +++ b/arch/x86/lib/csum-wrappers_64.c
23270 @@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
23271 len -= 2;
23272 }
23273 }
23274 - isum = csum_partial_copy_generic((__force const void *)src,
23275 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
23276 dst, len, isum, errp, NULL);
23277 if (unlikely(*errp))
23278 goto out_err;
23279 @@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
23280 }
23281
23282 *errp = 0;
23283 - return csum_partial_copy_generic(src, (void __force *)dst,
23284 + return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
23285 len, isum, NULL, errp);
23286 }
23287 EXPORT_SYMBOL(csum_partial_copy_to_user);
23288 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
23289 index 156b9c8..b144132 100644
23290 --- a/arch/x86/lib/getuser.S
23291 +++ b/arch/x86/lib/getuser.S
23292 @@ -34,17 +34,40 @@
23293 #include <asm/thread_info.h>
23294 #include <asm/asm.h>
23295 #include <asm/smap.h>
23296 +#include <asm/segment.h>
23297 +#include <asm/pgtable.h>
23298 +#include <asm/alternative-asm.h>
23299 +
23300 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23301 +#define __copyuser_seg gs;
23302 +#else
23303 +#define __copyuser_seg
23304 +#endif
23305
23306 .text
23307 ENTRY(__get_user_1)
23308 CFI_STARTPROC
23309 +
23310 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23311 GET_THREAD_INFO(%_ASM_DX)
23312 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23313 jae bad_get_user
23314 ASM_STAC
23315 -1: movzb (%_ASM_AX),%edx
23316 +
23317 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23318 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23319 + cmp %_ASM_DX,%_ASM_AX
23320 + jae 1234f
23321 + add %_ASM_DX,%_ASM_AX
23322 +1234:
23323 +#endif
23324 +
23325 +#endif
23326 +
23327 +1: __copyuser_seg movzb (%_ASM_AX),%edx
23328 xor %eax,%eax
23329 ASM_CLAC
23330 + pax_force_retaddr
23331 ret
23332 CFI_ENDPROC
23333 ENDPROC(__get_user_1)
23334 @@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
23335 ENTRY(__get_user_2)
23336 CFI_STARTPROC
23337 add $1,%_ASM_AX
23338 +
23339 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23340 jc bad_get_user
23341 GET_THREAD_INFO(%_ASM_DX)
23342 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23343 jae bad_get_user
23344 ASM_STAC
23345 -2: movzwl -1(%_ASM_AX),%edx
23346 +
23347 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23348 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23349 + cmp %_ASM_DX,%_ASM_AX
23350 + jae 1234f
23351 + add %_ASM_DX,%_ASM_AX
23352 +1234:
23353 +#endif
23354 +
23355 +#endif
23356 +
23357 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
23358 xor %eax,%eax
23359 ASM_CLAC
23360 + pax_force_retaddr
23361 ret
23362 CFI_ENDPROC
23363 ENDPROC(__get_user_2)
23364 @@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
23365 ENTRY(__get_user_4)
23366 CFI_STARTPROC
23367 add $3,%_ASM_AX
23368 +
23369 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23370 jc bad_get_user
23371 GET_THREAD_INFO(%_ASM_DX)
23372 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23373 jae bad_get_user
23374 ASM_STAC
23375 -3: mov -3(%_ASM_AX),%edx
23376 +
23377 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23378 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23379 + cmp %_ASM_DX,%_ASM_AX
23380 + jae 1234f
23381 + add %_ASM_DX,%_ASM_AX
23382 +1234:
23383 +#endif
23384 +
23385 +#endif
23386 +
23387 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
23388 xor %eax,%eax
23389 ASM_CLAC
23390 + pax_force_retaddr
23391 ret
23392 CFI_ENDPROC
23393 ENDPROC(__get_user_4)
23394 @@ -87,10 +138,20 @@ ENTRY(__get_user_8)
23395 GET_THREAD_INFO(%_ASM_DX)
23396 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23397 jae bad_get_user
23398 +
23399 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23400 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23401 + cmp %_ASM_DX,%_ASM_AX
23402 + jae 1234f
23403 + add %_ASM_DX,%_ASM_AX
23404 +1234:
23405 +#endif
23406 +
23407 ASM_STAC
23408 4: movq -7(%_ASM_AX),%_ASM_DX
23409 xor %eax,%eax
23410 ASM_CLAC
23411 + pax_force_retaddr
23412 ret
23413 CFI_ENDPROC
23414 ENDPROC(__get_user_8)
23415 @@ -101,6 +162,7 @@ bad_get_user:
23416 xor %edx,%edx
23417 mov $(-EFAULT),%_ASM_AX
23418 ASM_CLAC
23419 + pax_force_retaddr
23420 ret
23421 CFI_ENDPROC
23422 END(bad_get_user)
23423 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
23424 index 54fcffe..7be149e 100644
23425 --- a/arch/x86/lib/insn.c
23426 +++ b/arch/x86/lib/insn.c
23427 @@ -20,8 +20,10 @@
23428
23429 #ifdef __KERNEL__
23430 #include <linux/string.h>
23431 +#include <asm/pgtable_types.h>
23432 #else
23433 #include <string.h>
23434 +#define ktla_ktva(addr) addr
23435 #endif
23436 #include <asm/inat.h>
23437 #include <asm/insn.h>
23438 @@ -53,8 +55,8 @@
23439 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
23440 {
23441 memset(insn, 0, sizeof(*insn));
23442 - insn->kaddr = kaddr;
23443 - insn->next_byte = kaddr;
23444 + insn->kaddr = ktla_ktva(kaddr);
23445 + insn->next_byte = ktla_ktva(kaddr);
23446 insn->x86_64 = x86_64 ? 1 : 0;
23447 insn->opnd_bytes = 4;
23448 if (x86_64)
23449 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
23450 index 05a95e7..326f2fa 100644
23451 --- a/arch/x86/lib/iomap_copy_64.S
23452 +++ b/arch/x86/lib/iomap_copy_64.S
23453 @@ -17,6 +17,7 @@
23454
23455 #include <linux/linkage.h>
23456 #include <asm/dwarf2.h>
23457 +#include <asm/alternative-asm.h>
23458
23459 /*
23460 * override generic version in lib/iomap_copy.c
23461 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
23462 CFI_STARTPROC
23463 movl %edx,%ecx
23464 rep movsd
23465 + pax_force_retaddr
23466 ret
23467 CFI_ENDPROC
23468 ENDPROC(__iowrite32_copy)
23469 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
23470 index 1c273be..da9cc0e 100644
23471 --- a/arch/x86/lib/memcpy_64.S
23472 +++ b/arch/x86/lib/memcpy_64.S
23473 @@ -33,6 +33,7 @@
23474 rep movsq
23475 movl %edx, %ecx
23476 rep movsb
23477 + pax_force_retaddr
23478 ret
23479 .Lmemcpy_e:
23480 .previous
23481 @@ -49,6 +50,7 @@
23482 movq %rdi, %rax
23483 movq %rdx, %rcx
23484 rep movsb
23485 + pax_force_retaddr
23486 ret
23487 .Lmemcpy_e_e:
23488 .previous
23489 @@ -76,13 +78,13 @@ ENTRY(memcpy)
23490 */
23491 movq 0*8(%rsi), %r8
23492 movq 1*8(%rsi), %r9
23493 - movq 2*8(%rsi), %r10
23494 + movq 2*8(%rsi), %rcx
23495 movq 3*8(%rsi), %r11
23496 leaq 4*8(%rsi), %rsi
23497
23498 movq %r8, 0*8(%rdi)
23499 movq %r9, 1*8(%rdi)
23500 - movq %r10, 2*8(%rdi)
23501 + movq %rcx, 2*8(%rdi)
23502 movq %r11, 3*8(%rdi)
23503 leaq 4*8(%rdi), %rdi
23504 jae .Lcopy_forward_loop
23505 @@ -105,12 +107,12 @@ ENTRY(memcpy)
23506 subq $0x20, %rdx
23507 movq -1*8(%rsi), %r8
23508 movq -2*8(%rsi), %r9
23509 - movq -3*8(%rsi), %r10
23510 + movq -3*8(%rsi), %rcx
23511 movq -4*8(%rsi), %r11
23512 leaq -4*8(%rsi), %rsi
23513 movq %r8, -1*8(%rdi)
23514 movq %r9, -2*8(%rdi)
23515 - movq %r10, -3*8(%rdi)
23516 + movq %rcx, -3*8(%rdi)
23517 movq %r11, -4*8(%rdi)
23518 leaq -4*8(%rdi), %rdi
23519 jae .Lcopy_backward_loop
23520 @@ -130,12 +132,13 @@ ENTRY(memcpy)
23521 */
23522 movq 0*8(%rsi), %r8
23523 movq 1*8(%rsi), %r9
23524 - movq -2*8(%rsi, %rdx), %r10
23525 + movq -2*8(%rsi, %rdx), %rcx
23526 movq -1*8(%rsi, %rdx), %r11
23527 movq %r8, 0*8(%rdi)
23528 movq %r9, 1*8(%rdi)
23529 - movq %r10, -2*8(%rdi, %rdx)
23530 + movq %rcx, -2*8(%rdi, %rdx)
23531 movq %r11, -1*8(%rdi, %rdx)
23532 + pax_force_retaddr
23533 retq
23534 .p2align 4
23535 .Lless_16bytes:
23536 @@ -148,6 +151,7 @@ ENTRY(memcpy)
23537 movq -1*8(%rsi, %rdx), %r9
23538 movq %r8, 0*8(%rdi)
23539 movq %r9, -1*8(%rdi, %rdx)
23540 + pax_force_retaddr
23541 retq
23542 .p2align 4
23543 .Lless_8bytes:
23544 @@ -161,6 +165,7 @@ ENTRY(memcpy)
23545 movl -4(%rsi, %rdx), %r8d
23546 movl %ecx, (%rdi)
23547 movl %r8d, -4(%rdi, %rdx)
23548 + pax_force_retaddr
23549 retq
23550 .p2align 4
23551 .Lless_3bytes:
23552 @@ -179,6 +184,7 @@ ENTRY(memcpy)
23553 movb %cl, (%rdi)
23554
23555 .Lend:
23556 + pax_force_retaddr
23557 retq
23558 CFI_ENDPROC
23559 ENDPROC(memcpy)
23560 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
23561 index ee16461..c39c199 100644
23562 --- a/arch/x86/lib/memmove_64.S
23563 +++ b/arch/x86/lib/memmove_64.S
23564 @@ -61,13 +61,13 @@ ENTRY(memmove)
23565 5:
23566 sub $0x20, %rdx
23567 movq 0*8(%rsi), %r11
23568 - movq 1*8(%rsi), %r10
23569 + movq 1*8(%rsi), %rcx
23570 movq 2*8(%rsi), %r9
23571 movq 3*8(%rsi), %r8
23572 leaq 4*8(%rsi), %rsi
23573
23574 movq %r11, 0*8(%rdi)
23575 - movq %r10, 1*8(%rdi)
23576 + movq %rcx, 1*8(%rdi)
23577 movq %r9, 2*8(%rdi)
23578 movq %r8, 3*8(%rdi)
23579 leaq 4*8(%rdi), %rdi
23580 @@ -81,10 +81,10 @@ ENTRY(memmove)
23581 4:
23582 movq %rdx, %rcx
23583 movq -8(%rsi, %rdx), %r11
23584 - lea -8(%rdi, %rdx), %r10
23585 + lea -8(%rdi, %rdx), %r9
23586 shrq $3, %rcx
23587 rep movsq
23588 - movq %r11, (%r10)
23589 + movq %r11, (%r9)
23590 jmp 13f
23591 .Lmemmove_end_forward:
23592
23593 @@ -95,14 +95,14 @@ ENTRY(memmove)
23594 7:
23595 movq %rdx, %rcx
23596 movq (%rsi), %r11
23597 - movq %rdi, %r10
23598 + movq %rdi, %r9
23599 leaq -8(%rsi, %rdx), %rsi
23600 leaq -8(%rdi, %rdx), %rdi
23601 shrq $3, %rcx
23602 std
23603 rep movsq
23604 cld
23605 - movq %r11, (%r10)
23606 + movq %r11, (%r9)
23607 jmp 13f
23608
23609 /*
23610 @@ -127,13 +127,13 @@ ENTRY(memmove)
23611 8:
23612 subq $0x20, %rdx
23613 movq -1*8(%rsi), %r11
23614 - movq -2*8(%rsi), %r10
23615 + movq -2*8(%rsi), %rcx
23616 movq -3*8(%rsi), %r9
23617 movq -4*8(%rsi), %r8
23618 leaq -4*8(%rsi), %rsi
23619
23620 movq %r11, -1*8(%rdi)
23621 - movq %r10, -2*8(%rdi)
23622 + movq %rcx, -2*8(%rdi)
23623 movq %r9, -3*8(%rdi)
23624 movq %r8, -4*8(%rdi)
23625 leaq -4*8(%rdi), %rdi
23626 @@ -151,11 +151,11 @@ ENTRY(memmove)
23627 * Move data from 16 bytes to 31 bytes.
23628 */
23629 movq 0*8(%rsi), %r11
23630 - movq 1*8(%rsi), %r10
23631 + movq 1*8(%rsi), %rcx
23632 movq -2*8(%rsi, %rdx), %r9
23633 movq -1*8(%rsi, %rdx), %r8
23634 movq %r11, 0*8(%rdi)
23635 - movq %r10, 1*8(%rdi)
23636 + movq %rcx, 1*8(%rdi)
23637 movq %r9, -2*8(%rdi, %rdx)
23638 movq %r8, -1*8(%rdi, %rdx)
23639 jmp 13f
23640 @@ -167,9 +167,9 @@ ENTRY(memmove)
23641 * Move data from 8 bytes to 15 bytes.
23642 */
23643 movq 0*8(%rsi), %r11
23644 - movq -1*8(%rsi, %rdx), %r10
23645 + movq -1*8(%rsi, %rdx), %r9
23646 movq %r11, 0*8(%rdi)
23647 - movq %r10, -1*8(%rdi, %rdx)
23648 + movq %r9, -1*8(%rdi, %rdx)
23649 jmp 13f
23650 10:
23651 cmpq $4, %rdx
23652 @@ -178,9 +178,9 @@ ENTRY(memmove)
23653 * Move data from 4 bytes to 7 bytes.
23654 */
23655 movl (%rsi), %r11d
23656 - movl -4(%rsi, %rdx), %r10d
23657 + movl -4(%rsi, %rdx), %r9d
23658 movl %r11d, (%rdi)
23659 - movl %r10d, -4(%rdi, %rdx)
23660 + movl %r9d, -4(%rdi, %rdx)
23661 jmp 13f
23662 11:
23663 cmp $2, %rdx
23664 @@ -189,9 +189,9 @@ ENTRY(memmove)
23665 * Move data from 2 bytes to 3 bytes.
23666 */
23667 movw (%rsi), %r11w
23668 - movw -2(%rsi, %rdx), %r10w
23669 + movw -2(%rsi, %rdx), %r9w
23670 movw %r11w, (%rdi)
23671 - movw %r10w, -2(%rdi, %rdx)
23672 + movw %r9w, -2(%rdi, %rdx)
23673 jmp 13f
23674 12:
23675 cmp $1, %rdx
23676 @@ -202,6 +202,7 @@ ENTRY(memmove)
23677 movb (%rsi), %r11b
23678 movb %r11b, (%rdi)
23679 13:
23680 + pax_force_retaddr
23681 retq
23682 CFI_ENDPROC
23683
23684 @@ -210,6 +211,7 @@ ENTRY(memmove)
23685 /* Forward moving data. */
23686 movq %rdx, %rcx
23687 rep movsb
23688 + pax_force_retaddr
23689 retq
23690 .Lmemmove_end_forward_efs:
23691 .previous
23692 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
23693 index 2dcb380..963660a 100644
23694 --- a/arch/x86/lib/memset_64.S
23695 +++ b/arch/x86/lib/memset_64.S
23696 @@ -30,6 +30,7 @@
23697 movl %edx,%ecx
23698 rep stosb
23699 movq %r9,%rax
23700 + pax_force_retaddr
23701 ret
23702 .Lmemset_e:
23703 .previous
23704 @@ -52,6 +53,7 @@
23705 movq %rdx,%rcx
23706 rep stosb
23707 movq %r9,%rax
23708 + pax_force_retaddr
23709 ret
23710 .Lmemset_e_e:
23711 .previous
23712 @@ -59,7 +61,7 @@
23713 ENTRY(memset)
23714 ENTRY(__memset)
23715 CFI_STARTPROC
23716 - movq %rdi,%r10
23717 + movq %rdi,%r11
23718
23719 /* expand byte value */
23720 movzbl %sil,%ecx
23721 @@ -117,7 +119,8 @@ ENTRY(__memset)
23722 jnz .Lloop_1
23723
23724 .Lende:
23725 - movq %r10,%rax
23726 + movq %r11,%rax
23727 + pax_force_retaddr
23728 ret
23729
23730 CFI_RESTORE_STATE
23731 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
23732 index c9f2d9b..e7fd2c0 100644
23733 --- a/arch/x86/lib/mmx_32.c
23734 +++ b/arch/x86/lib/mmx_32.c
23735 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23736 {
23737 void *p;
23738 int i;
23739 + unsigned long cr0;
23740
23741 if (unlikely(in_interrupt()))
23742 return __memcpy(to, from, len);
23743 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23744 kernel_fpu_begin();
23745
23746 __asm__ __volatile__ (
23747 - "1: prefetch (%0)\n" /* This set is 28 bytes */
23748 - " prefetch 64(%0)\n"
23749 - " prefetch 128(%0)\n"
23750 - " prefetch 192(%0)\n"
23751 - " prefetch 256(%0)\n"
23752 + "1: prefetch (%1)\n" /* This set is 28 bytes */
23753 + " prefetch 64(%1)\n"
23754 + " prefetch 128(%1)\n"
23755 + " prefetch 192(%1)\n"
23756 + " prefetch 256(%1)\n"
23757 "2: \n"
23758 ".section .fixup, \"ax\"\n"
23759 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23760 + "3: \n"
23761 +
23762 +#ifdef CONFIG_PAX_KERNEXEC
23763 + " movl %%cr0, %0\n"
23764 + " movl %0, %%eax\n"
23765 + " andl $0xFFFEFFFF, %%eax\n"
23766 + " movl %%eax, %%cr0\n"
23767 +#endif
23768 +
23769 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23770 +
23771 +#ifdef CONFIG_PAX_KERNEXEC
23772 + " movl %0, %%cr0\n"
23773 +#endif
23774 +
23775 " jmp 2b\n"
23776 ".previous\n"
23777 _ASM_EXTABLE(1b, 3b)
23778 - : : "r" (from));
23779 + : "=&r" (cr0) : "r" (from) : "ax");
23780
23781 for ( ; i > 5; i--) {
23782 __asm__ __volatile__ (
23783 - "1: prefetch 320(%0)\n"
23784 - "2: movq (%0), %%mm0\n"
23785 - " movq 8(%0), %%mm1\n"
23786 - " movq 16(%0), %%mm2\n"
23787 - " movq 24(%0), %%mm3\n"
23788 - " movq %%mm0, (%1)\n"
23789 - " movq %%mm1, 8(%1)\n"
23790 - " movq %%mm2, 16(%1)\n"
23791 - " movq %%mm3, 24(%1)\n"
23792 - " movq 32(%0), %%mm0\n"
23793 - " movq 40(%0), %%mm1\n"
23794 - " movq 48(%0), %%mm2\n"
23795 - " movq 56(%0), %%mm3\n"
23796 - " movq %%mm0, 32(%1)\n"
23797 - " movq %%mm1, 40(%1)\n"
23798 - " movq %%mm2, 48(%1)\n"
23799 - " movq %%mm3, 56(%1)\n"
23800 + "1: prefetch 320(%1)\n"
23801 + "2: movq (%1), %%mm0\n"
23802 + " movq 8(%1), %%mm1\n"
23803 + " movq 16(%1), %%mm2\n"
23804 + " movq 24(%1), %%mm3\n"
23805 + " movq %%mm0, (%2)\n"
23806 + " movq %%mm1, 8(%2)\n"
23807 + " movq %%mm2, 16(%2)\n"
23808 + " movq %%mm3, 24(%2)\n"
23809 + " movq 32(%1), %%mm0\n"
23810 + " movq 40(%1), %%mm1\n"
23811 + " movq 48(%1), %%mm2\n"
23812 + " movq 56(%1), %%mm3\n"
23813 + " movq %%mm0, 32(%2)\n"
23814 + " movq %%mm1, 40(%2)\n"
23815 + " movq %%mm2, 48(%2)\n"
23816 + " movq %%mm3, 56(%2)\n"
23817 ".section .fixup, \"ax\"\n"
23818 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23819 + "3:\n"
23820 +
23821 +#ifdef CONFIG_PAX_KERNEXEC
23822 + " movl %%cr0, %0\n"
23823 + " movl %0, %%eax\n"
23824 + " andl $0xFFFEFFFF, %%eax\n"
23825 + " movl %%eax, %%cr0\n"
23826 +#endif
23827 +
23828 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23829 +
23830 +#ifdef CONFIG_PAX_KERNEXEC
23831 + " movl %0, %%cr0\n"
23832 +#endif
23833 +
23834 " jmp 2b\n"
23835 ".previous\n"
23836 _ASM_EXTABLE(1b, 3b)
23837 - : : "r" (from), "r" (to) : "memory");
23838 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23839
23840 from += 64;
23841 to += 64;
23842 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
23843 static void fast_copy_page(void *to, void *from)
23844 {
23845 int i;
23846 + unsigned long cr0;
23847
23848 kernel_fpu_begin();
23849
23850 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
23851 * but that is for later. -AV
23852 */
23853 __asm__ __volatile__(
23854 - "1: prefetch (%0)\n"
23855 - " prefetch 64(%0)\n"
23856 - " prefetch 128(%0)\n"
23857 - " prefetch 192(%0)\n"
23858 - " prefetch 256(%0)\n"
23859 + "1: prefetch (%1)\n"
23860 + " prefetch 64(%1)\n"
23861 + " prefetch 128(%1)\n"
23862 + " prefetch 192(%1)\n"
23863 + " prefetch 256(%1)\n"
23864 "2: \n"
23865 ".section .fixup, \"ax\"\n"
23866 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23867 + "3: \n"
23868 +
23869 +#ifdef CONFIG_PAX_KERNEXEC
23870 + " movl %%cr0, %0\n"
23871 + " movl %0, %%eax\n"
23872 + " andl $0xFFFEFFFF, %%eax\n"
23873 + " movl %%eax, %%cr0\n"
23874 +#endif
23875 +
23876 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23877 +
23878 +#ifdef CONFIG_PAX_KERNEXEC
23879 + " movl %0, %%cr0\n"
23880 +#endif
23881 +
23882 " jmp 2b\n"
23883 ".previous\n"
23884 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
23885 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
23886
23887 for (i = 0; i < (4096-320)/64; i++) {
23888 __asm__ __volatile__ (
23889 - "1: prefetch 320(%0)\n"
23890 - "2: movq (%0), %%mm0\n"
23891 - " movntq %%mm0, (%1)\n"
23892 - " movq 8(%0), %%mm1\n"
23893 - " movntq %%mm1, 8(%1)\n"
23894 - " movq 16(%0), %%mm2\n"
23895 - " movntq %%mm2, 16(%1)\n"
23896 - " movq 24(%0), %%mm3\n"
23897 - " movntq %%mm3, 24(%1)\n"
23898 - " movq 32(%0), %%mm4\n"
23899 - " movntq %%mm4, 32(%1)\n"
23900 - " movq 40(%0), %%mm5\n"
23901 - " movntq %%mm5, 40(%1)\n"
23902 - " movq 48(%0), %%mm6\n"
23903 - " movntq %%mm6, 48(%1)\n"
23904 - " movq 56(%0), %%mm7\n"
23905 - " movntq %%mm7, 56(%1)\n"
23906 + "1: prefetch 320(%1)\n"
23907 + "2: movq (%1), %%mm0\n"
23908 + " movntq %%mm0, (%2)\n"
23909 + " movq 8(%1), %%mm1\n"
23910 + " movntq %%mm1, 8(%2)\n"
23911 + " movq 16(%1), %%mm2\n"
23912 + " movntq %%mm2, 16(%2)\n"
23913 + " movq 24(%1), %%mm3\n"
23914 + " movntq %%mm3, 24(%2)\n"
23915 + " movq 32(%1), %%mm4\n"
23916 + " movntq %%mm4, 32(%2)\n"
23917 + " movq 40(%1), %%mm5\n"
23918 + " movntq %%mm5, 40(%2)\n"
23919 + " movq 48(%1), %%mm6\n"
23920 + " movntq %%mm6, 48(%2)\n"
23921 + " movq 56(%1), %%mm7\n"
23922 + " movntq %%mm7, 56(%2)\n"
23923 ".section .fixup, \"ax\"\n"
23924 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23925 + "3:\n"
23926 +
23927 +#ifdef CONFIG_PAX_KERNEXEC
23928 + " movl %%cr0, %0\n"
23929 + " movl %0, %%eax\n"
23930 + " andl $0xFFFEFFFF, %%eax\n"
23931 + " movl %%eax, %%cr0\n"
23932 +#endif
23933 +
23934 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23935 +
23936 +#ifdef CONFIG_PAX_KERNEXEC
23937 + " movl %0, %%cr0\n"
23938 +#endif
23939 +
23940 " jmp 2b\n"
23941 ".previous\n"
23942 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
23943 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23944
23945 from += 64;
23946 to += 64;
23947 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
23948 static void fast_copy_page(void *to, void *from)
23949 {
23950 int i;
23951 + unsigned long cr0;
23952
23953 kernel_fpu_begin();
23954
23955 __asm__ __volatile__ (
23956 - "1: prefetch (%0)\n"
23957 - " prefetch 64(%0)\n"
23958 - " prefetch 128(%0)\n"
23959 - " prefetch 192(%0)\n"
23960 - " prefetch 256(%0)\n"
23961 + "1: prefetch (%1)\n"
23962 + " prefetch 64(%1)\n"
23963 + " prefetch 128(%1)\n"
23964 + " prefetch 192(%1)\n"
23965 + " prefetch 256(%1)\n"
23966 "2: \n"
23967 ".section .fixup, \"ax\"\n"
23968 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23969 + "3: \n"
23970 +
23971 +#ifdef CONFIG_PAX_KERNEXEC
23972 + " movl %%cr0, %0\n"
23973 + " movl %0, %%eax\n"
23974 + " andl $0xFFFEFFFF, %%eax\n"
23975 + " movl %%eax, %%cr0\n"
23976 +#endif
23977 +
23978 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23979 +
23980 +#ifdef CONFIG_PAX_KERNEXEC
23981 + " movl %0, %%cr0\n"
23982 +#endif
23983 +
23984 " jmp 2b\n"
23985 ".previous\n"
23986 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
23987 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
23988
23989 for (i = 0; i < 4096/64; i++) {
23990 __asm__ __volatile__ (
23991 - "1: prefetch 320(%0)\n"
23992 - "2: movq (%0), %%mm0\n"
23993 - " movq 8(%0), %%mm1\n"
23994 - " movq 16(%0), %%mm2\n"
23995 - " movq 24(%0), %%mm3\n"
23996 - " movq %%mm0, (%1)\n"
23997 - " movq %%mm1, 8(%1)\n"
23998 - " movq %%mm2, 16(%1)\n"
23999 - " movq %%mm3, 24(%1)\n"
24000 - " movq 32(%0), %%mm0\n"
24001 - " movq 40(%0), %%mm1\n"
24002 - " movq 48(%0), %%mm2\n"
24003 - " movq 56(%0), %%mm3\n"
24004 - " movq %%mm0, 32(%1)\n"
24005 - " movq %%mm1, 40(%1)\n"
24006 - " movq %%mm2, 48(%1)\n"
24007 - " movq %%mm3, 56(%1)\n"
24008 + "1: prefetch 320(%1)\n"
24009 + "2: movq (%1), %%mm0\n"
24010 + " movq 8(%1), %%mm1\n"
24011 + " movq 16(%1), %%mm2\n"
24012 + " movq 24(%1), %%mm3\n"
24013 + " movq %%mm0, (%2)\n"
24014 + " movq %%mm1, 8(%2)\n"
24015 + " movq %%mm2, 16(%2)\n"
24016 + " movq %%mm3, 24(%2)\n"
24017 + " movq 32(%1), %%mm0\n"
24018 + " movq 40(%1), %%mm1\n"
24019 + " movq 48(%1), %%mm2\n"
24020 + " movq 56(%1), %%mm3\n"
24021 + " movq %%mm0, 32(%2)\n"
24022 + " movq %%mm1, 40(%2)\n"
24023 + " movq %%mm2, 48(%2)\n"
24024 + " movq %%mm3, 56(%2)\n"
24025 ".section .fixup, \"ax\"\n"
24026 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
24027 + "3:\n"
24028 +
24029 +#ifdef CONFIG_PAX_KERNEXEC
24030 + " movl %%cr0, %0\n"
24031 + " movl %0, %%eax\n"
24032 + " andl $0xFFFEFFFF, %%eax\n"
24033 + " movl %%eax, %%cr0\n"
24034 +#endif
24035 +
24036 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
24037 +
24038 +#ifdef CONFIG_PAX_KERNEXEC
24039 + " movl %0, %%cr0\n"
24040 +#endif
24041 +
24042 " jmp 2b\n"
24043 ".previous\n"
24044 _ASM_EXTABLE(1b, 3b)
24045 - : : "r" (from), "r" (to) : "memory");
24046 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
24047
24048 from += 64;
24049 to += 64;
24050 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
24051 index f6d13ee..aca5f0b 100644
24052 --- a/arch/x86/lib/msr-reg.S
24053 +++ b/arch/x86/lib/msr-reg.S
24054 @@ -3,6 +3,7 @@
24055 #include <asm/dwarf2.h>
24056 #include <asm/asm.h>
24057 #include <asm/msr.h>
24058 +#include <asm/alternative-asm.h>
24059
24060 #ifdef CONFIG_X86_64
24061 /*
24062 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
24063 CFI_STARTPROC
24064 pushq_cfi %rbx
24065 pushq_cfi %rbp
24066 - movq %rdi, %r10 /* Save pointer */
24067 + movq %rdi, %r9 /* Save pointer */
24068 xorl %r11d, %r11d /* Return value */
24069 movl (%rdi), %eax
24070 movl 4(%rdi), %ecx
24071 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
24072 movl 28(%rdi), %edi
24073 CFI_REMEMBER_STATE
24074 1: \op
24075 -2: movl %eax, (%r10)
24076 +2: movl %eax, (%r9)
24077 movl %r11d, %eax /* Return value */
24078 - movl %ecx, 4(%r10)
24079 - movl %edx, 8(%r10)
24080 - movl %ebx, 12(%r10)
24081 - movl %ebp, 20(%r10)
24082 - movl %esi, 24(%r10)
24083 - movl %edi, 28(%r10)
24084 + movl %ecx, 4(%r9)
24085 + movl %edx, 8(%r9)
24086 + movl %ebx, 12(%r9)
24087 + movl %ebp, 20(%r9)
24088 + movl %esi, 24(%r9)
24089 + movl %edi, 28(%r9)
24090 popq_cfi %rbp
24091 popq_cfi %rbx
24092 + pax_force_retaddr
24093 ret
24094 3:
24095 CFI_RESTORE_STATE
24096 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
24097 index fc6ba17..04471c5 100644
24098 --- a/arch/x86/lib/putuser.S
24099 +++ b/arch/x86/lib/putuser.S
24100 @@ -16,7 +16,9 @@
24101 #include <asm/errno.h>
24102 #include <asm/asm.h>
24103 #include <asm/smap.h>
24104 -
24105 +#include <asm/segment.h>
24106 +#include <asm/pgtable.h>
24107 +#include <asm/alternative-asm.h>
24108
24109 /*
24110 * __put_user_X
24111 @@ -30,57 +32,125 @@
24112 * as they get called from within inline assembly.
24113 */
24114
24115 -#define ENTER CFI_STARTPROC ; \
24116 - GET_THREAD_INFO(%_ASM_BX)
24117 -#define EXIT ASM_CLAC ; \
24118 - ret ; \
24119 +#define ENTER CFI_STARTPROC
24120 +#define EXIT ASM_CLAC ; \
24121 + pax_force_retaddr ; \
24122 + ret ; \
24123 CFI_ENDPROC
24124
24125 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24126 +#define _DEST %_ASM_CX,%_ASM_BX
24127 +#else
24128 +#define _DEST %_ASM_CX
24129 +#endif
24130 +
24131 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24132 +#define __copyuser_seg gs;
24133 +#else
24134 +#define __copyuser_seg
24135 +#endif
24136 +
24137 .text
24138 ENTRY(__put_user_1)
24139 ENTER
24140 +
24141 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24142 + GET_THREAD_INFO(%_ASM_BX)
24143 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
24144 jae bad_put_user
24145 ASM_STAC
24146 -1: movb %al,(%_ASM_CX)
24147 +
24148 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24149 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24150 + cmp %_ASM_BX,%_ASM_CX
24151 + jb 1234f
24152 + xor %ebx,%ebx
24153 +1234:
24154 +#endif
24155 +
24156 +#endif
24157 +
24158 +1: __copyuser_seg movb %al,(_DEST)
24159 xor %eax,%eax
24160 EXIT
24161 ENDPROC(__put_user_1)
24162
24163 ENTRY(__put_user_2)
24164 ENTER
24165 +
24166 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24167 + GET_THREAD_INFO(%_ASM_BX)
24168 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24169 sub $1,%_ASM_BX
24170 cmp %_ASM_BX,%_ASM_CX
24171 jae bad_put_user
24172 ASM_STAC
24173 -2: movw %ax,(%_ASM_CX)
24174 +
24175 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24176 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24177 + cmp %_ASM_BX,%_ASM_CX
24178 + jb 1234f
24179 + xor %ebx,%ebx
24180 +1234:
24181 +#endif
24182 +
24183 +#endif
24184 +
24185 +2: __copyuser_seg movw %ax,(_DEST)
24186 xor %eax,%eax
24187 EXIT
24188 ENDPROC(__put_user_2)
24189
24190 ENTRY(__put_user_4)
24191 ENTER
24192 +
24193 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24194 + GET_THREAD_INFO(%_ASM_BX)
24195 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24196 sub $3,%_ASM_BX
24197 cmp %_ASM_BX,%_ASM_CX
24198 jae bad_put_user
24199 ASM_STAC
24200 -3: movl %eax,(%_ASM_CX)
24201 +
24202 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24203 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24204 + cmp %_ASM_BX,%_ASM_CX
24205 + jb 1234f
24206 + xor %ebx,%ebx
24207 +1234:
24208 +#endif
24209 +
24210 +#endif
24211 +
24212 +3: __copyuser_seg movl %eax,(_DEST)
24213 xor %eax,%eax
24214 EXIT
24215 ENDPROC(__put_user_4)
24216
24217 ENTRY(__put_user_8)
24218 ENTER
24219 +
24220 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24221 + GET_THREAD_INFO(%_ASM_BX)
24222 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24223 sub $7,%_ASM_BX
24224 cmp %_ASM_BX,%_ASM_CX
24225 jae bad_put_user
24226 ASM_STAC
24227 -4: mov %_ASM_AX,(%_ASM_CX)
24228 +
24229 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24230 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24231 + cmp %_ASM_BX,%_ASM_CX
24232 + jb 1234f
24233 + xor %ebx,%ebx
24234 +1234:
24235 +#endif
24236 +
24237 +#endif
24238 +
24239 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
24240 #ifdef CONFIG_X86_32
24241 -5: movl %edx,4(%_ASM_CX)
24242 +5: __copyuser_seg movl %edx,4(_DEST)
24243 #endif
24244 xor %eax,%eax
24245 EXIT
24246 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
24247 index 1cad221..de671ee 100644
24248 --- a/arch/x86/lib/rwlock.S
24249 +++ b/arch/x86/lib/rwlock.S
24250 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
24251 FRAME
24252 0: LOCK_PREFIX
24253 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
24254 +
24255 +#ifdef CONFIG_PAX_REFCOUNT
24256 + jno 1234f
24257 + LOCK_PREFIX
24258 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
24259 + int $4
24260 +1234:
24261 + _ASM_EXTABLE(1234b, 1234b)
24262 +#endif
24263 +
24264 1: rep; nop
24265 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
24266 jne 1b
24267 LOCK_PREFIX
24268 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
24269 +
24270 +#ifdef CONFIG_PAX_REFCOUNT
24271 + jno 1234f
24272 + LOCK_PREFIX
24273 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
24274 + int $4
24275 +1234:
24276 + _ASM_EXTABLE(1234b, 1234b)
24277 +#endif
24278 +
24279 jnz 0b
24280 ENDFRAME
24281 + pax_force_retaddr
24282 ret
24283 CFI_ENDPROC
24284 END(__write_lock_failed)
24285 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
24286 FRAME
24287 0: LOCK_PREFIX
24288 READ_LOCK_SIZE(inc) (%__lock_ptr)
24289 +
24290 +#ifdef CONFIG_PAX_REFCOUNT
24291 + jno 1234f
24292 + LOCK_PREFIX
24293 + READ_LOCK_SIZE(dec) (%__lock_ptr)
24294 + int $4
24295 +1234:
24296 + _ASM_EXTABLE(1234b, 1234b)
24297 +#endif
24298 +
24299 1: rep; nop
24300 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
24301 js 1b
24302 LOCK_PREFIX
24303 READ_LOCK_SIZE(dec) (%__lock_ptr)
24304 +
24305 +#ifdef CONFIG_PAX_REFCOUNT
24306 + jno 1234f
24307 + LOCK_PREFIX
24308 + READ_LOCK_SIZE(inc) (%__lock_ptr)
24309 + int $4
24310 +1234:
24311 + _ASM_EXTABLE(1234b, 1234b)
24312 +#endif
24313 +
24314 js 0b
24315 ENDFRAME
24316 + pax_force_retaddr
24317 ret
24318 CFI_ENDPROC
24319 END(__read_lock_failed)
24320 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
24321 index 5dff5f0..cadebf4 100644
24322 --- a/arch/x86/lib/rwsem.S
24323 +++ b/arch/x86/lib/rwsem.S
24324 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
24325 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24326 CFI_RESTORE __ASM_REG(dx)
24327 restore_common_regs
24328 + pax_force_retaddr
24329 ret
24330 CFI_ENDPROC
24331 ENDPROC(call_rwsem_down_read_failed)
24332 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
24333 movq %rax,%rdi
24334 call rwsem_down_write_failed
24335 restore_common_regs
24336 + pax_force_retaddr
24337 ret
24338 CFI_ENDPROC
24339 ENDPROC(call_rwsem_down_write_failed)
24340 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
24341 movq %rax,%rdi
24342 call rwsem_wake
24343 restore_common_regs
24344 -1: ret
24345 +1: pax_force_retaddr
24346 + ret
24347 CFI_ENDPROC
24348 ENDPROC(call_rwsem_wake)
24349
24350 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
24351 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24352 CFI_RESTORE __ASM_REG(dx)
24353 restore_common_regs
24354 + pax_force_retaddr
24355 ret
24356 CFI_ENDPROC
24357 ENDPROC(call_rwsem_downgrade_wake)
24358 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
24359 index a63efd6..ccecad8 100644
24360 --- a/arch/x86/lib/thunk_64.S
24361 +++ b/arch/x86/lib/thunk_64.S
24362 @@ -8,6 +8,7 @@
24363 #include <linux/linkage.h>
24364 #include <asm/dwarf2.h>
24365 #include <asm/calling.h>
24366 +#include <asm/alternative-asm.h>
24367
24368 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
24369 .macro THUNK name, func, put_ret_addr_in_rdi=0
24370 @@ -41,5 +42,6 @@
24371 SAVE_ARGS
24372 restore:
24373 RESTORE_ARGS
24374 + pax_force_retaddr
24375 ret
24376 CFI_ENDPROC
24377 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
24378 index 98f6d6b6..d27f045 100644
24379 --- a/arch/x86/lib/usercopy_32.c
24380 +++ b/arch/x86/lib/usercopy_32.c
24381 @@ -42,11 +42,13 @@ do { \
24382 int __d0; \
24383 might_fault(); \
24384 __asm__ __volatile__( \
24385 + __COPYUSER_SET_ES \
24386 ASM_STAC "\n" \
24387 "0: rep; stosl\n" \
24388 " movl %2,%0\n" \
24389 "1: rep; stosb\n" \
24390 "2: " ASM_CLAC "\n" \
24391 + __COPYUSER_RESTORE_ES \
24392 ".section .fixup,\"ax\"\n" \
24393 "3: lea 0(%2,%0,4),%0\n" \
24394 " jmp 2b\n" \
24395 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
24396
24397 #ifdef CONFIG_X86_INTEL_USERCOPY
24398 static unsigned long
24399 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
24400 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
24401 {
24402 int d0, d1;
24403 __asm__ __volatile__(
24404 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24405 " .align 2,0x90\n"
24406 "3: movl 0(%4), %%eax\n"
24407 "4: movl 4(%4), %%edx\n"
24408 - "5: movl %%eax, 0(%3)\n"
24409 - "6: movl %%edx, 4(%3)\n"
24410 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
24411 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
24412 "7: movl 8(%4), %%eax\n"
24413 "8: movl 12(%4),%%edx\n"
24414 - "9: movl %%eax, 8(%3)\n"
24415 - "10: movl %%edx, 12(%3)\n"
24416 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
24417 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
24418 "11: movl 16(%4), %%eax\n"
24419 "12: movl 20(%4), %%edx\n"
24420 - "13: movl %%eax, 16(%3)\n"
24421 - "14: movl %%edx, 20(%3)\n"
24422 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
24423 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
24424 "15: movl 24(%4), %%eax\n"
24425 "16: movl 28(%4), %%edx\n"
24426 - "17: movl %%eax, 24(%3)\n"
24427 - "18: movl %%edx, 28(%3)\n"
24428 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
24429 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
24430 "19: movl 32(%4), %%eax\n"
24431 "20: movl 36(%4), %%edx\n"
24432 - "21: movl %%eax, 32(%3)\n"
24433 - "22: movl %%edx, 36(%3)\n"
24434 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
24435 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
24436 "23: movl 40(%4), %%eax\n"
24437 "24: movl 44(%4), %%edx\n"
24438 - "25: movl %%eax, 40(%3)\n"
24439 - "26: movl %%edx, 44(%3)\n"
24440 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
24441 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
24442 "27: movl 48(%4), %%eax\n"
24443 "28: movl 52(%4), %%edx\n"
24444 - "29: movl %%eax, 48(%3)\n"
24445 - "30: movl %%edx, 52(%3)\n"
24446 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
24447 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
24448 "31: movl 56(%4), %%eax\n"
24449 "32: movl 60(%4), %%edx\n"
24450 - "33: movl %%eax, 56(%3)\n"
24451 - "34: movl %%edx, 60(%3)\n"
24452 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
24453 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
24454 " addl $-64, %0\n"
24455 " addl $64, %4\n"
24456 " addl $64, %3\n"
24457 @@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24458 " shrl $2, %0\n"
24459 " andl $3, %%eax\n"
24460 " cld\n"
24461 + __COPYUSER_SET_ES
24462 "99: rep; movsl\n"
24463 "36: movl %%eax, %0\n"
24464 "37: rep; movsb\n"
24465 "100:\n"
24466 + __COPYUSER_RESTORE_ES
24467 ".section .fixup,\"ax\"\n"
24468 "101: lea 0(%%eax,%0,4),%0\n"
24469 " jmp 100b\n"
24470 @@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24471 }
24472
24473 static unsigned long
24474 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
24475 +{
24476 + int d0, d1;
24477 + __asm__ __volatile__(
24478 + " .align 2,0x90\n"
24479 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
24480 + " cmpl $67, %0\n"
24481 + " jbe 3f\n"
24482 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
24483 + " .align 2,0x90\n"
24484 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
24485 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
24486 + "5: movl %%eax, 0(%3)\n"
24487 + "6: movl %%edx, 4(%3)\n"
24488 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
24489 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
24490 + "9: movl %%eax, 8(%3)\n"
24491 + "10: movl %%edx, 12(%3)\n"
24492 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
24493 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
24494 + "13: movl %%eax, 16(%3)\n"
24495 + "14: movl %%edx, 20(%3)\n"
24496 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
24497 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
24498 + "17: movl %%eax, 24(%3)\n"
24499 + "18: movl %%edx, 28(%3)\n"
24500 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
24501 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
24502 + "21: movl %%eax, 32(%3)\n"
24503 + "22: movl %%edx, 36(%3)\n"
24504 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
24505 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
24506 + "25: movl %%eax, 40(%3)\n"
24507 + "26: movl %%edx, 44(%3)\n"
24508 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
24509 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
24510 + "29: movl %%eax, 48(%3)\n"
24511 + "30: movl %%edx, 52(%3)\n"
24512 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
24513 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
24514 + "33: movl %%eax, 56(%3)\n"
24515 + "34: movl %%edx, 60(%3)\n"
24516 + " addl $-64, %0\n"
24517 + " addl $64, %4\n"
24518 + " addl $64, %3\n"
24519 + " cmpl $63, %0\n"
24520 + " ja 1b\n"
24521 + "35: movl %0, %%eax\n"
24522 + " shrl $2, %0\n"
24523 + " andl $3, %%eax\n"
24524 + " cld\n"
24525 + "99: rep; "__copyuser_seg" movsl\n"
24526 + "36: movl %%eax, %0\n"
24527 + "37: rep; "__copyuser_seg" movsb\n"
24528 + "100:\n"
24529 + ".section .fixup,\"ax\"\n"
24530 + "101: lea 0(%%eax,%0,4),%0\n"
24531 + " jmp 100b\n"
24532 + ".previous\n"
24533 + _ASM_EXTABLE(1b,100b)
24534 + _ASM_EXTABLE(2b,100b)
24535 + _ASM_EXTABLE(3b,100b)
24536 + _ASM_EXTABLE(4b,100b)
24537 + _ASM_EXTABLE(5b,100b)
24538 + _ASM_EXTABLE(6b,100b)
24539 + _ASM_EXTABLE(7b,100b)
24540 + _ASM_EXTABLE(8b,100b)
24541 + _ASM_EXTABLE(9b,100b)
24542 + _ASM_EXTABLE(10b,100b)
24543 + _ASM_EXTABLE(11b,100b)
24544 + _ASM_EXTABLE(12b,100b)
24545 + _ASM_EXTABLE(13b,100b)
24546 + _ASM_EXTABLE(14b,100b)
24547 + _ASM_EXTABLE(15b,100b)
24548 + _ASM_EXTABLE(16b,100b)
24549 + _ASM_EXTABLE(17b,100b)
24550 + _ASM_EXTABLE(18b,100b)
24551 + _ASM_EXTABLE(19b,100b)
24552 + _ASM_EXTABLE(20b,100b)
24553 + _ASM_EXTABLE(21b,100b)
24554 + _ASM_EXTABLE(22b,100b)
24555 + _ASM_EXTABLE(23b,100b)
24556 + _ASM_EXTABLE(24b,100b)
24557 + _ASM_EXTABLE(25b,100b)
24558 + _ASM_EXTABLE(26b,100b)
24559 + _ASM_EXTABLE(27b,100b)
24560 + _ASM_EXTABLE(28b,100b)
24561 + _ASM_EXTABLE(29b,100b)
24562 + _ASM_EXTABLE(30b,100b)
24563 + _ASM_EXTABLE(31b,100b)
24564 + _ASM_EXTABLE(32b,100b)
24565 + _ASM_EXTABLE(33b,100b)
24566 + _ASM_EXTABLE(34b,100b)
24567 + _ASM_EXTABLE(35b,100b)
24568 + _ASM_EXTABLE(36b,100b)
24569 + _ASM_EXTABLE(37b,100b)
24570 + _ASM_EXTABLE(99b,101b)
24571 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
24572 + : "1"(to), "2"(from), "0"(size)
24573 + : "eax", "edx", "memory");
24574 + return size;
24575 +}
24576 +
24577 +static unsigned long __size_overflow(3)
24578 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24579 {
24580 int d0, d1;
24581 __asm__ __volatile__(
24582 " .align 2,0x90\n"
24583 - "0: movl 32(%4), %%eax\n"
24584 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24585 " cmpl $67, %0\n"
24586 " jbe 2f\n"
24587 - "1: movl 64(%4), %%eax\n"
24588 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24589 " .align 2,0x90\n"
24590 - "2: movl 0(%4), %%eax\n"
24591 - "21: movl 4(%4), %%edx\n"
24592 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24593 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24594 " movl %%eax, 0(%3)\n"
24595 " movl %%edx, 4(%3)\n"
24596 - "3: movl 8(%4), %%eax\n"
24597 - "31: movl 12(%4),%%edx\n"
24598 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24599 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24600 " movl %%eax, 8(%3)\n"
24601 " movl %%edx, 12(%3)\n"
24602 - "4: movl 16(%4), %%eax\n"
24603 - "41: movl 20(%4), %%edx\n"
24604 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24605 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24606 " movl %%eax, 16(%3)\n"
24607 " movl %%edx, 20(%3)\n"
24608 - "10: movl 24(%4), %%eax\n"
24609 - "51: movl 28(%4), %%edx\n"
24610 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24611 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24612 " movl %%eax, 24(%3)\n"
24613 " movl %%edx, 28(%3)\n"
24614 - "11: movl 32(%4), %%eax\n"
24615 - "61: movl 36(%4), %%edx\n"
24616 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24617 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24618 " movl %%eax, 32(%3)\n"
24619 " movl %%edx, 36(%3)\n"
24620 - "12: movl 40(%4), %%eax\n"
24621 - "71: movl 44(%4), %%edx\n"
24622 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24623 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24624 " movl %%eax, 40(%3)\n"
24625 " movl %%edx, 44(%3)\n"
24626 - "13: movl 48(%4), %%eax\n"
24627 - "81: movl 52(%4), %%edx\n"
24628 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24629 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24630 " movl %%eax, 48(%3)\n"
24631 " movl %%edx, 52(%3)\n"
24632 - "14: movl 56(%4), %%eax\n"
24633 - "91: movl 60(%4), %%edx\n"
24634 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24635 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24636 " movl %%eax, 56(%3)\n"
24637 " movl %%edx, 60(%3)\n"
24638 " addl $-64, %0\n"
24639 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24640 " shrl $2, %0\n"
24641 " andl $3, %%eax\n"
24642 " cld\n"
24643 - "6: rep; movsl\n"
24644 + "6: rep; "__copyuser_seg" movsl\n"
24645 " movl %%eax,%0\n"
24646 - "7: rep; movsb\n"
24647 + "7: rep; "__copyuser_seg" movsb\n"
24648 "8:\n"
24649 ".section .fixup,\"ax\"\n"
24650 "9: lea 0(%%eax,%0,4),%0\n"
24651 @@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24652 * hyoshiok@miraclelinux.com
24653 */
24654
24655 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24656 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
24657 const void __user *from, unsigned long size)
24658 {
24659 int d0, d1;
24660
24661 __asm__ __volatile__(
24662 " .align 2,0x90\n"
24663 - "0: movl 32(%4), %%eax\n"
24664 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24665 " cmpl $67, %0\n"
24666 " jbe 2f\n"
24667 - "1: movl 64(%4), %%eax\n"
24668 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24669 " .align 2,0x90\n"
24670 - "2: movl 0(%4), %%eax\n"
24671 - "21: movl 4(%4), %%edx\n"
24672 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24673 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24674 " movnti %%eax, 0(%3)\n"
24675 " movnti %%edx, 4(%3)\n"
24676 - "3: movl 8(%4), %%eax\n"
24677 - "31: movl 12(%4),%%edx\n"
24678 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24679 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24680 " movnti %%eax, 8(%3)\n"
24681 " movnti %%edx, 12(%3)\n"
24682 - "4: movl 16(%4), %%eax\n"
24683 - "41: movl 20(%4), %%edx\n"
24684 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24685 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24686 " movnti %%eax, 16(%3)\n"
24687 " movnti %%edx, 20(%3)\n"
24688 - "10: movl 24(%4), %%eax\n"
24689 - "51: movl 28(%4), %%edx\n"
24690 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24691 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24692 " movnti %%eax, 24(%3)\n"
24693 " movnti %%edx, 28(%3)\n"
24694 - "11: movl 32(%4), %%eax\n"
24695 - "61: movl 36(%4), %%edx\n"
24696 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24697 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24698 " movnti %%eax, 32(%3)\n"
24699 " movnti %%edx, 36(%3)\n"
24700 - "12: movl 40(%4), %%eax\n"
24701 - "71: movl 44(%4), %%edx\n"
24702 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24703 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24704 " movnti %%eax, 40(%3)\n"
24705 " movnti %%edx, 44(%3)\n"
24706 - "13: movl 48(%4), %%eax\n"
24707 - "81: movl 52(%4), %%edx\n"
24708 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24709 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24710 " movnti %%eax, 48(%3)\n"
24711 " movnti %%edx, 52(%3)\n"
24712 - "14: movl 56(%4), %%eax\n"
24713 - "91: movl 60(%4), %%edx\n"
24714 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24715 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24716 " movnti %%eax, 56(%3)\n"
24717 " movnti %%edx, 60(%3)\n"
24718 " addl $-64, %0\n"
24719 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24720 " shrl $2, %0\n"
24721 " andl $3, %%eax\n"
24722 " cld\n"
24723 - "6: rep; movsl\n"
24724 + "6: rep; "__copyuser_seg" movsl\n"
24725 " movl %%eax,%0\n"
24726 - "7: rep; movsb\n"
24727 + "7: rep; "__copyuser_seg" movsb\n"
24728 "8:\n"
24729 ".section .fixup,\"ax\"\n"
24730 "9: lea 0(%%eax,%0,4),%0\n"
24731 @@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24732 return size;
24733 }
24734
24735 -static unsigned long __copy_user_intel_nocache(void *to,
24736 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
24737 const void __user *from, unsigned long size)
24738 {
24739 int d0, d1;
24740
24741 __asm__ __volatile__(
24742 " .align 2,0x90\n"
24743 - "0: movl 32(%4), %%eax\n"
24744 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24745 " cmpl $67, %0\n"
24746 " jbe 2f\n"
24747 - "1: movl 64(%4), %%eax\n"
24748 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24749 " .align 2,0x90\n"
24750 - "2: movl 0(%4), %%eax\n"
24751 - "21: movl 4(%4), %%edx\n"
24752 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24753 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24754 " movnti %%eax, 0(%3)\n"
24755 " movnti %%edx, 4(%3)\n"
24756 - "3: movl 8(%4), %%eax\n"
24757 - "31: movl 12(%4),%%edx\n"
24758 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24759 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24760 " movnti %%eax, 8(%3)\n"
24761 " movnti %%edx, 12(%3)\n"
24762 - "4: movl 16(%4), %%eax\n"
24763 - "41: movl 20(%4), %%edx\n"
24764 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24765 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24766 " movnti %%eax, 16(%3)\n"
24767 " movnti %%edx, 20(%3)\n"
24768 - "10: movl 24(%4), %%eax\n"
24769 - "51: movl 28(%4), %%edx\n"
24770 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24771 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24772 " movnti %%eax, 24(%3)\n"
24773 " movnti %%edx, 28(%3)\n"
24774 - "11: movl 32(%4), %%eax\n"
24775 - "61: movl 36(%4), %%edx\n"
24776 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24777 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24778 " movnti %%eax, 32(%3)\n"
24779 " movnti %%edx, 36(%3)\n"
24780 - "12: movl 40(%4), %%eax\n"
24781 - "71: movl 44(%4), %%edx\n"
24782 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24783 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24784 " movnti %%eax, 40(%3)\n"
24785 " movnti %%edx, 44(%3)\n"
24786 - "13: movl 48(%4), %%eax\n"
24787 - "81: movl 52(%4), %%edx\n"
24788 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24789 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24790 " movnti %%eax, 48(%3)\n"
24791 " movnti %%edx, 52(%3)\n"
24792 - "14: movl 56(%4), %%eax\n"
24793 - "91: movl 60(%4), %%edx\n"
24794 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24795 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24796 " movnti %%eax, 56(%3)\n"
24797 " movnti %%edx, 60(%3)\n"
24798 " addl $-64, %0\n"
24799 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
24800 " shrl $2, %0\n"
24801 " andl $3, %%eax\n"
24802 " cld\n"
24803 - "6: rep; movsl\n"
24804 + "6: rep; "__copyuser_seg" movsl\n"
24805 " movl %%eax,%0\n"
24806 - "7: rep; movsb\n"
24807 + "7: rep; "__copyuser_seg" movsb\n"
24808 "8:\n"
24809 ".section .fixup,\"ax\"\n"
24810 "9: lea 0(%%eax,%0,4),%0\n"
24811 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
24812 */
24813 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
24814 unsigned long size);
24815 -unsigned long __copy_user_intel(void __user *to, const void *from,
24816 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
24817 + unsigned long size);
24818 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
24819 unsigned long size);
24820 unsigned long __copy_user_zeroing_intel_nocache(void *to,
24821 const void __user *from, unsigned long size);
24822 #endif /* CONFIG_X86_INTEL_USERCOPY */
24823
24824 /* Generic arbitrary sized copy. */
24825 -#define __copy_user(to, from, size) \
24826 +#define __copy_user(to, from, size, prefix, set, restore) \
24827 do { \
24828 int __d0, __d1, __d2; \
24829 __asm__ __volatile__( \
24830 + set \
24831 " cmp $7,%0\n" \
24832 " jbe 1f\n" \
24833 " movl %1,%0\n" \
24834 " negl %0\n" \
24835 " andl $7,%0\n" \
24836 " subl %0,%3\n" \
24837 - "4: rep; movsb\n" \
24838 + "4: rep; "prefix"movsb\n" \
24839 " movl %3,%0\n" \
24840 " shrl $2,%0\n" \
24841 " andl $3,%3\n" \
24842 " .align 2,0x90\n" \
24843 - "0: rep; movsl\n" \
24844 + "0: rep; "prefix"movsl\n" \
24845 " movl %3,%0\n" \
24846 - "1: rep; movsb\n" \
24847 + "1: rep; "prefix"movsb\n" \
24848 "2:\n" \
24849 + restore \
24850 ".section .fixup,\"ax\"\n" \
24851 "5: addl %3,%0\n" \
24852 " jmp 2b\n" \
24853 @@ -538,14 +650,14 @@ do { \
24854 " negl %0\n" \
24855 " andl $7,%0\n" \
24856 " subl %0,%3\n" \
24857 - "4: rep; movsb\n" \
24858 + "4: rep; "__copyuser_seg"movsb\n" \
24859 " movl %3,%0\n" \
24860 " shrl $2,%0\n" \
24861 " andl $3,%3\n" \
24862 " .align 2,0x90\n" \
24863 - "0: rep; movsl\n" \
24864 + "0: rep; "__copyuser_seg"movsl\n" \
24865 " movl %3,%0\n" \
24866 - "1: rep; movsb\n" \
24867 + "1: rep; "__copyuser_seg"movsb\n" \
24868 "2:\n" \
24869 ".section .fixup,\"ax\"\n" \
24870 "5: addl %3,%0\n" \
24871 @@ -629,9 +741,9 @@ survive:
24872 #endif
24873 stac();
24874 if (movsl_is_ok(to, from, n))
24875 - __copy_user(to, from, n);
24876 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
24877 else
24878 - n = __copy_user_intel(to, from, n);
24879 + n = __generic_copy_to_user_intel(to, from, n);
24880 clac();
24881 return n;
24882 }
24883 @@ -655,10 +767,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
24884 {
24885 stac();
24886 if (movsl_is_ok(to, from, n))
24887 - __copy_user(to, from, n);
24888 + __copy_user(to, from, n, __copyuser_seg, "", "");
24889 else
24890 - n = __copy_user_intel((void __user *)to,
24891 - (const void *)from, n);
24892 + n = __generic_copy_from_user_intel(to, from, n);
24893 clac();
24894 return n;
24895 }
24896 @@ -689,66 +800,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
24897 if (n > 64 && cpu_has_xmm2)
24898 n = __copy_user_intel_nocache(to, from, n);
24899 else
24900 - __copy_user(to, from, n);
24901 + __copy_user(to, from, n, __copyuser_seg, "", "");
24902 #else
24903 - __copy_user(to, from, n);
24904 + __copy_user(to, from, n, __copyuser_seg, "", "");
24905 #endif
24906 clac();
24907 return n;
24908 }
24909 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
24910
24911 -/**
24912 - * copy_to_user: - Copy a block of data into user space.
24913 - * @to: Destination address, in user space.
24914 - * @from: Source address, in kernel space.
24915 - * @n: Number of bytes to copy.
24916 - *
24917 - * Context: User context only. This function may sleep.
24918 - *
24919 - * Copy data from kernel space to user space.
24920 - *
24921 - * Returns number of bytes that could not be copied.
24922 - * On success, this will be zero.
24923 - */
24924 -unsigned long
24925 -copy_to_user(void __user *to, const void *from, unsigned long n)
24926 -{
24927 - if (access_ok(VERIFY_WRITE, to, n))
24928 - n = __copy_to_user(to, from, n);
24929 - return n;
24930 -}
24931 -EXPORT_SYMBOL(copy_to_user);
24932 -
24933 -/**
24934 - * copy_from_user: - Copy a block of data from user space.
24935 - * @to: Destination address, in kernel space.
24936 - * @from: Source address, in user space.
24937 - * @n: Number of bytes to copy.
24938 - *
24939 - * Context: User context only. This function may sleep.
24940 - *
24941 - * Copy data from user space to kernel space.
24942 - *
24943 - * Returns number of bytes that could not be copied.
24944 - * On success, this will be zero.
24945 - *
24946 - * If some data could not be copied, this function will pad the copied
24947 - * data to the requested size using zero bytes.
24948 - */
24949 -unsigned long
24950 -_copy_from_user(void *to, const void __user *from, unsigned long n)
24951 -{
24952 - if (access_ok(VERIFY_READ, from, n))
24953 - n = __copy_from_user(to, from, n);
24954 - else
24955 - memset(to, 0, n);
24956 - return n;
24957 -}
24958 -EXPORT_SYMBOL(_copy_from_user);
24959 -
24960 void copy_from_user_overflow(void)
24961 {
24962 WARN(1, "Buffer overflow detected!\n");
24963 }
24964 EXPORT_SYMBOL(copy_from_user_overflow);
24965 +
24966 +void copy_to_user_overflow(void)
24967 +{
24968 + WARN(1, "Buffer overflow detected!\n");
24969 +}
24970 +EXPORT_SYMBOL(copy_to_user_overflow);
24971 +
24972 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24973 +void __set_fs(mm_segment_t x)
24974 +{
24975 + switch (x.seg) {
24976 + case 0:
24977 + loadsegment(gs, 0);
24978 + break;
24979 + case TASK_SIZE_MAX:
24980 + loadsegment(gs, __USER_DS);
24981 + break;
24982 + case -1UL:
24983 + loadsegment(gs, __KERNEL_DS);
24984 + break;
24985 + default:
24986 + BUG();
24987 + }
24988 + return;
24989 +}
24990 +EXPORT_SYMBOL(__set_fs);
24991 +
24992 +void set_fs(mm_segment_t x)
24993 +{
24994 + current_thread_info()->addr_limit = x;
24995 + __set_fs(x);
24996 +}
24997 +EXPORT_SYMBOL(set_fs);
24998 +#endif
24999 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
25000 index 05928aa..b33dea1 100644
25001 --- a/arch/x86/lib/usercopy_64.c
25002 +++ b/arch/x86/lib/usercopy_64.c
25003 @@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
25004 _ASM_EXTABLE(0b,3b)
25005 _ASM_EXTABLE(1b,2b)
25006 : [size8] "=&c"(size), [dst] "=&D" (__d0)
25007 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
25008 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
25009 [zero] "r" (0UL), [eight] "r" (8UL));
25010 clac();
25011 return size;
25012 @@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
25013 }
25014 EXPORT_SYMBOL(clear_user);
25015
25016 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
25017 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
25018 {
25019 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
25020 - return copy_user_generic((__force void *)to, (__force void *)from, len);
25021 - }
25022 - return len;
25023 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
25024 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
25025 + return len;
25026 }
25027 EXPORT_SYMBOL(copy_in_user);
25028
25029 @@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
25030 * it is not necessary to optimize tail handling.
25031 */
25032 unsigned long
25033 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
25034 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
25035 {
25036 char c;
25037 unsigned zero_len;
25038 @@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
25039 clac();
25040 return len;
25041 }
25042 +
25043 +void copy_from_user_overflow(void)
25044 +{
25045 + WARN(1, "Buffer overflow detected!\n");
25046 +}
25047 +EXPORT_SYMBOL(copy_from_user_overflow);
25048 +
25049 +void copy_to_user_overflow(void)
25050 +{
25051 + WARN(1, "Buffer overflow detected!\n");
25052 +}
25053 +EXPORT_SYMBOL(copy_to_user_overflow);
25054 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
25055 index 903ec1e..c4166b2 100644
25056 --- a/arch/x86/mm/extable.c
25057 +++ b/arch/x86/mm/extable.c
25058 @@ -6,12 +6,24 @@
25059 static inline unsigned long
25060 ex_insn_addr(const struct exception_table_entry *x)
25061 {
25062 - return (unsigned long)&x->insn + x->insn;
25063 + unsigned long reloc = 0;
25064 +
25065 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25066 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25067 +#endif
25068 +
25069 + return (unsigned long)&x->insn + x->insn + reloc;
25070 }
25071 static inline unsigned long
25072 ex_fixup_addr(const struct exception_table_entry *x)
25073 {
25074 - return (unsigned long)&x->fixup + x->fixup;
25075 + unsigned long reloc = 0;
25076 +
25077 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25078 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25079 +#endif
25080 +
25081 + return (unsigned long)&x->fixup + x->fixup + reloc;
25082 }
25083
25084 int fixup_exception(struct pt_regs *regs)
25085 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
25086 unsigned long new_ip;
25087
25088 #ifdef CONFIG_PNPBIOS
25089 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
25090 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
25091 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
25092 extern u32 pnp_bios_is_utter_crap;
25093 pnp_bios_is_utter_crap = 1;
25094 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
25095 i += 4;
25096 p->fixup -= i;
25097 i += 4;
25098 +
25099 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25100 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
25101 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25102 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25103 +#endif
25104 +
25105 }
25106 }
25107
25108 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
25109 index 8e13ecb..2722f3a 100644
25110 --- a/arch/x86/mm/fault.c
25111 +++ b/arch/x86/mm/fault.c
25112 @@ -13,12 +13,19 @@
25113 #include <linux/perf_event.h> /* perf_sw_event */
25114 #include <linux/hugetlb.h> /* hstate_index_to_shift */
25115 #include <linux/prefetch.h> /* prefetchw */
25116 +#include <linux/unistd.h>
25117 +#include <linux/compiler.h>
25118
25119 #include <asm/traps.h> /* dotraplinkage, ... */
25120 #include <asm/pgalloc.h> /* pgd_*(), ... */
25121 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
25122 #include <asm/fixmap.h> /* VSYSCALL_START */
25123 #include <asm/rcu.h> /* exception_enter(), ... */
25124 +#include <asm/tlbflush.h>
25125 +
25126 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25127 +#include <asm/stacktrace.h>
25128 +#endif
25129
25130 /*
25131 * Page fault error code bits:
25132 @@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
25133 int ret = 0;
25134
25135 /* kprobe_running() needs smp_processor_id() */
25136 - if (kprobes_built_in() && !user_mode_vm(regs)) {
25137 + if (kprobes_built_in() && !user_mode(regs)) {
25138 preempt_disable();
25139 if (kprobe_running() && kprobe_fault_handler(regs, 14))
25140 ret = 1;
25141 @@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
25142 return !instr_lo || (instr_lo>>1) == 1;
25143 case 0x00:
25144 /* Prefetch instruction is 0x0F0D or 0x0F18 */
25145 - if (probe_kernel_address(instr, opcode))
25146 + if (user_mode(regs)) {
25147 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
25148 + return 0;
25149 + } else if (probe_kernel_address(instr, opcode))
25150 return 0;
25151
25152 *prefetch = (instr_lo == 0xF) &&
25153 @@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
25154 while (instr < max_instr) {
25155 unsigned char opcode;
25156
25157 - if (probe_kernel_address(instr, opcode))
25158 + if (user_mode(regs)) {
25159 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
25160 + break;
25161 + } else if (probe_kernel_address(instr, opcode))
25162 break;
25163
25164 instr++;
25165 @@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
25166 force_sig_info(si_signo, &info, tsk);
25167 }
25168
25169 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25170 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
25171 +#endif
25172 +
25173 +#ifdef CONFIG_PAX_EMUTRAMP
25174 +static int pax_handle_fetch_fault(struct pt_regs *regs);
25175 +#endif
25176 +
25177 +#ifdef CONFIG_PAX_PAGEEXEC
25178 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
25179 +{
25180 + pgd_t *pgd;
25181 + pud_t *pud;
25182 + pmd_t *pmd;
25183 +
25184 + pgd = pgd_offset(mm, address);
25185 + if (!pgd_present(*pgd))
25186 + return NULL;
25187 + pud = pud_offset(pgd, address);
25188 + if (!pud_present(*pud))
25189 + return NULL;
25190 + pmd = pmd_offset(pud, address);
25191 + if (!pmd_present(*pmd))
25192 + return NULL;
25193 + return pmd;
25194 +}
25195 +#endif
25196 +
25197 DEFINE_SPINLOCK(pgd_lock);
25198 LIST_HEAD(pgd_list);
25199
25200 @@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
25201 for (address = VMALLOC_START & PMD_MASK;
25202 address >= TASK_SIZE && address < FIXADDR_TOP;
25203 address += PMD_SIZE) {
25204 +
25205 +#ifdef CONFIG_PAX_PER_CPU_PGD
25206 + unsigned long cpu;
25207 +#else
25208 struct page *page;
25209 +#endif
25210
25211 spin_lock(&pgd_lock);
25212 +
25213 +#ifdef CONFIG_PAX_PER_CPU_PGD
25214 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25215 + pgd_t *pgd = get_cpu_pgd(cpu);
25216 + pmd_t *ret;
25217 +#else
25218 list_for_each_entry(page, &pgd_list, lru) {
25219 + pgd_t *pgd = page_address(page);
25220 spinlock_t *pgt_lock;
25221 pmd_t *ret;
25222
25223 @@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
25224 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25225
25226 spin_lock(pgt_lock);
25227 - ret = vmalloc_sync_one(page_address(page), address);
25228 +#endif
25229 +
25230 + ret = vmalloc_sync_one(pgd, address);
25231 +
25232 +#ifndef CONFIG_PAX_PER_CPU_PGD
25233 spin_unlock(pgt_lock);
25234 +#endif
25235
25236 if (!ret)
25237 break;
25238 @@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
25239 * an interrupt in the middle of a task switch..
25240 */
25241 pgd_paddr = read_cr3();
25242 +
25243 +#ifdef CONFIG_PAX_PER_CPU_PGD
25244 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
25245 +#endif
25246 +
25247 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
25248 if (!pmd_k)
25249 return -1;
25250 @@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
25251 * happen within a race in page table update. In the later
25252 * case just flush:
25253 */
25254 +
25255 +#ifdef CONFIG_PAX_PER_CPU_PGD
25256 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
25257 + pgd = pgd_offset_cpu(smp_processor_id(), address);
25258 +#else
25259 pgd = pgd_offset(current->active_mm, address);
25260 +#endif
25261 +
25262 pgd_ref = pgd_offset_k(address);
25263 if (pgd_none(*pgd_ref))
25264 return -1;
25265 @@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
25266 static int is_errata100(struct pt_regs *regs, unsigned long address)
25267 {
25268 #ifdef CONFIG_X86_64
25269 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
25270 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
25271 return 1;
25272 #endif
25273 return 0;
25274 @@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
25275 }
25276
25277 static const char nx_warning[] = KERN_CRIT
25278 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
25279 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
25280
25281 static void
25282 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
25283 @@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
25284 if (!oops_may_print())
25285 return;
25286
25287 - if (error_code & PF_INSTR) {
25288 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
25289 unsigned int level;
25290
25291 pte_t *pte = lookup_address(address, &level);
25292
25293 if (pte && pte_present(*pte) && !pte_exec(*pte))
25294 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
25295 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
25296 }
25297
25298 +#ifdef CONFIG_PAX_KERNEXEC
25299 + if (init_mm.start_code <= address && address < init_mm.end_code) {
25300 + if (current->signal->curr_ip)
25301 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
25302 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
25303 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
25304 + else
25305 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
25306 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
25307 + }
25308 +#endif
25309 +
25310 printk(KERN_ALERT "BUG: unable to handle kernel ");
25311 if (address < PAGE_SIZE)
25312 printk(KERN_CONT "NULL pointer dereference");
25313 @@ -749,12 +831,29 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
25314 }
25315 #endif
25316
25317 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25318 + if (pax_is_fetch_fault(regs, error_code, address)) {
25319 +
25320 +#ifdef CONFIG_PAX_EMUTRAMP
25321 + switch (pax_handle_fetch_fault(regs)) {
25322 + case 2:
25323 + return;
25324 + }
25325 +#endif
25326 +
25327 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25328 + do_group_exit(SIGKILL);
25329 + }
25330 +#endif
25331 +
25332 + /* Kernel addresses are always protection faults: */
25333 + error_code |= (address >= TASK_SIZE);
25334 +
25335 if (unlikely(show_unhandled_signals))
25336 show_signal_msg(regs, error_code, address, tsk);
25337
25338 - /* Kernel addresses are always protection faults: */
25339 tsk->thread.cr2 = address;
25340 - tsk->thread.error_code = error_code | (address >= TASK_SIZE);
25341 + tsk->thread.error_code = error_code;
25342 tsk->thread.trap_nr = X86_TRAP_PF;
25343
25344 force_sig_info_fault(SIGSEGV, si_code, address, tsk, 0);
25345 @@ -845,7 +944,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
25346 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
25347 printk(KERN_ERR
25348 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
25349 - tsk->comm, tsk->pid, address);
25350 + tsk->comm, task_pid_nr(tsk), address);
25351 code = BUS_MCEERR_AR;
25352 }
25353 #endif
25354 @@ -901,6 +1000,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
25355 return 1;
25356 }
25357
25358 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25359 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
25360 +{
25361 + pte_t *pte;
25362 + pmd_t *pmd;
25363 + spinlock_t *ptl;
25364 + unsigned char pte_mask;
25365 +
25366 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
25367 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
25368 + return 0;
25369 +
25370 + /* PaX: it's our fault, let's handle it if we can */
25371 +
25372 + /* PaX: take a look at read faults before acquiring any locks */
25373 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
25374 + /* instruction fetch attempt from a protected page in user mode */
25375 + up_read(&mm->mmap_sem);
25376 +
25377 +#ifdef CONFIG_PAX_EMUTRAMP
25378 + switch (pax_handle_fetch_fault(regs)) {
25379 + case 2:
25380 + return 1;
25381 + }
25382 +#endif
25383 +
25384 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25385 + do_group_exit(SIGKILL);
25386 + }
25387 +
25388 + pmd = pax_get_pmd(mm, address);
25389 + if (unlikely(!pmd))
25390 + return 0;
25391 +
25392 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
25393 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
25394 + pte_unmap_unlock(pte, ptl);
25395 + return 0;
25396 + }
25397 +
25398 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
25399 + /* write attempt to a protected page in user mode */
25400 + pte_unmap_unlock(pte, ptl);
25401 + return 0;
25402 + }
25403 +
25404 +#ifdef CONFIG_SMP
25405 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
25406 +#else
25407 + if (likely(address > get_limit(regs->cs)))
25408 +#endif
25409 + {
25410 + set_pte(pte, pte_mkread(*pte));
25411 + __flush_tlb_one(address);
25412 + pte_unmap_unlock(pte, ptl);
25413 + up_read(&mm->mmap_sem);
25414 + return 1;
25415 + }
25416 +
25417 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
25418 +
25419 + /*
25420 + * PaX: fill DTLB with user rights and retry
25421 + */
25422 + __asm__ __volatile__ (
25423 + "orb %2,(%1)\n"
25424 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
25425 +/*
25426 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
25427 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
25428 + * page fault when examined during a TLB load attempt. this is true not only
25429 + * for PTEs holding a non-present entry but also present entries that will
25430 + * raise a page fault (such as those set up by PaX, or the copy-on-write
25431 + * mechanism). in effect it means that we do *not* need to flush the TLBs
25432 + * for our target pages since their PTEs are simply not in the TLBs at all.
25433 +
25434 + * the best thing in omitting it is that we gain around 15-20% speed in the
25435 + * fast path of the page fault handler and can get rid of tracing since we
25436 + * can no longer flush unintended entries.
25437 + */
25438 + "invlpg (%0)\n"
25439 +#endif
25440 + __copyuser_seg"testb $0,(%0)\n"
25441 + "xorb %3,(%1)\n"
25442 + :
25443 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
25444 + : "memory", "cc");
25445 + pte_unmap_unlock(pte, ptl);
25446 + up_read(&mm->mmap_sem);
25447 + return 1;
25448 +}
25449 +#endif
25450 +
25451 /*
25452 * Handle a spurious fault caused by a stale TLB entry.
25453 *
25454 @@ -973,6 +1165,9 @@ int show_unhandled_signals = 1;
25455 static inline int
25456 access_error(unsigned long error_code, struct vm_area_struct *vma)
25457 {
25458 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
25459 + return 1;
25460 +
25461 if (error_code & PF_WRITE) {
25462 /* write, present and write, not present: */
25463 if (unlikely(!(vma->vm_flags & VM_WRITE)))
25464 @@ -1001,7 +1196,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
25465 if (error_code & PF_USER)
25466 return false;
25467
25468 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
25469 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
25470 return false;
25471
25472 return true;
25473 @@ -1017,18 +1212,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25474 {
25475 struct vm_area_struct *vma;
25476 struct task_struct *tsk;
25477 - unsigned long address;
25478 struct mm_struct *mm;
25479 int fault;
25480 int write = error_code & PF_WRITE;
25481 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
25482 (write ? FAULT_FLAG_WRITE : 0);
25483
25484 - tsk = current;
25485 - mm = tsk->mm;
25486 -
25487 /* Get the faulting address: */
25488 - address = read_cr2();
25489 + unsigned long address = read_cr2();
25490 +
25491 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25492 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
25493 + if (!search_exception_tables(regs->ip)) {
25494 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25495 + bad_area_nosemaphore(regs, error_code, address);
25496 + return;
25497 + }
25498 + if (address < PAX_USER_SHADOW_BASE) {
25499 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25500 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
25501 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
25502 + } else
25503 + address -= PAX_USER_SHADOW_BASE;
25504 + }
25505 +#endif
25506 +
25507 + tsk = current;
25508 + mm = tsk->mm;
25509
25510 /*
25511 * Detect and handle instructions that would cause a page fault for
25512 @@ -1089,7 +1299,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25513 * User-mode registers count as a user access even for any
25514 * potential system fault or CPU buglet:
25515 */
25516 - if (user_mode_vm(regs)) {
25517 + if (user_mode(regs)) {
25518 local_irq_enable();
25519 error_code |= PF_USER;
25520 } else {
25521 @@ -1151,6 +1361,11 @@ retry:
25522 might_sleep();
25523 }
25524
25525 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25526 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
25527 + return;
25528 +#endif
25529 +
25530 vma = find_vma(mm, address);
25531 if (unlikely(!vma)) {
25532 bad_area(regs, error_code, address);
25533 @@ -1162,18 +1377,24 @@ retry:
25534 bad_area(regs, error_code, address);
25535 return;
25536 }
25537 - if (error_code & PF_USER) {
25538 - /*
25539 - * Accessing the stack below %sp is always a bug.
25540 - * The large cushion allows instructions like enter
25541 - * and pusha to work. ("enter $65535, $31" pushes
25542 - * 32 pointers and then decrements %sp by 65535.)
25543 - */
25544 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
25545 - bad_area(regs, error_code, address);
25546 - return;
25547 - }
25548 + /*
25549 + * Accessing the stack below %sp is always a bug.
25550 + * The large cushion allows instructions like enter
25551 + * and pusha to work. ("enter $65535, $31" pushes
25552 + * 32 pointers and then decrements %sp by 65535.)
25553 + */
25554 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
25555 + bad_area(regs, error_code, address);
25556 + return;
25557 }
25558 +
25559 +#ifdef CONFIG_PAX_SEGMEXEC
25560 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
25561 + bad_area(regs, error_code, address);
25562 + return;
25563 + }
25564 +#endif
25565 +
25566 if (unlikely(expand_stack(vma, address))) {
25567 bad_area(regs, error_code, address);
25568 return;
25569 @@ -1237,3 +1458,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
25570 __do_page_fault(regs, error_code);
25571 exception_exit(regs);
25572 }
25573 +
25574 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25575 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
25576 +{
25577 + struct mm_struct *mm = current->mm;
25578 + unsigned long ip = regs->ip;
25579 +
25580 + if (v8086_mode(regs))
25581 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
25582 +
25583 +#ifdef CONFIG_PAX_PAGEEXEC
25584 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
25585 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
25586 + return true;
25587 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
25588 + return true;
25589 + return false;
25590 + }
25591 +#endif
25592 +
25593 +#ifdef CONFIG_PAX_SEGMEXEC
25594 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
25595 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
25596 + return true;
25597 + return false;
25598 + }
25599 +#endif
25600 +
25601 + return false;
25602 +}
25603 +#endif
25604 +
25605 +#ifdef CONFIG_PAX_EMUTRAMP
25606 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
25607 +{
25608 + int err;
25609 +
25610 + do { /* PaX: libffi trampoline emulation */
25611 + unsigned char mov, jmp;
25612 + unsigned int addr1, addr2;
25613 +
25614 +#ifdef CONFIG_X86_64
25615 + if ((regs->ip + 9) >> 32)
25616 + break;
25617 +#endif
25618 +
25619 + err = get_user(mov, (unsigned char __user *)regs->ip);
25620 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25621 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25622 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25623 +
25624 + if (err)
25625 + break;
25626 +
25627 + if (mov == 0xB8 && jmp == 0xE9) {
25628 + regs->ax = addr1;
25629 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25630 + return 2;
25631 + }
25632 + } while (0);
25633 +
25634 + do { /* PaX: gcc trampoline emulation #1 */
25635 + unsigned char mov1, mov2;
25636 + unsigned short jmp;
25637 + unsigned int addr1, addr2;
25638 +
25639 +#ifdef CONFIG_X86_64
25640 + if ((regs->ip + 11) >> 32)
25641 + break;
25642 +#endif
25643 +
25644 + err = get_user(mov1, (unsigned char __user *)regs->ip);
25645 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25646 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
25647 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25648 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
25649 +
25650 + if (err)
25651 + break;
25652 +
25653 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
25654 + regs->cx = addr1;
25655 + regs->ax = addr2;
25656 + regs->ip = addr2;
25657 + return 2;
25658 + }
25659 + } while (0);
25660 +
25661 + do { /* PaX: gcc trampoline emulation #2 */
25662 + unsigned char mov, jmp;
25663 + unsigned int addr1, addr2;
25664 +
25665 +#ifdef CONFIG_X86_64
25666 + if ((regs->ip + 9) >> 32)
25667 + break;
25668 +#endif
25669 +
25670 + err = get_user(mov, (unsigned char __user *)regs->ip);
25671 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25672 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25673 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25674 +
25675 + if (err)
25676 + break;
25677 +
25678 + if (mov == 0xB9 && jmp == 0xE9) {
25679 + regs->cx = addr1;
25680 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25681 + return 2;
25682 + }
25683 + } while (0);
25684 +
25685 + return 1; /* PaX in action */
25686 +}
25687 +
25688 +#ifdef CONFIG_X86_64
25689 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
25690 +{
25691 + int err;
25692 +
25693 + do { /* PaX: libffi trampoline emulation */
25694 + unsigned short mov1, mov2, jmp1;
25695 + unsigned char stcclc, jmp2;
25696 + unsigned long addr1, addr2;
25697 +
25698 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25699 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25700 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25701 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25702 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
25703 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
25704 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
25705 +
25706 + if (err)
25707 + break;
25708 +
25709 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25710 + regs->r11 = addr1;
25711 + regs->r10 = addr2;
25712 + if (stcclc == 0xF8)
25713 + regs->flags &= ~X86_EFLAGS_CF;
25714 + else
25715 + regs->flags |= X86_EFLAGS_CF;
25716 + regs->ip = addr1;
25717 + return 2;
25718 + }
25719 + } while (0);
25720 +
25721 + do { /* PaX: gcc trampoline emulation #1 */
25722 + unsigned short mov1, mov2, jmp1;
25723 + unsigned char jmp2;
25724 + unsigned int addr1;
25725 + unsigned long addr2;
25726 +
25727 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25728 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
25729 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
25730 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
25731 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
25732 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
25733 +
25734 + if (err)
25735 + break;
25736 +
25737 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25738 + regs->r11 = addr1;
25739 + regs->r10 = addr2;
25740 + regs->ip = addr1;
25741 + return 2;
25742 + }
25743 + } while (0);
25744 +
25745 + do { /* PaX: gcc trampoline emulation #2 */
25746 + unsigned short mov1, mov2, jmp1;
25747 + unsigned char jmp2;
25748 + unsigned long addr1, addr2;
25749 +
25750 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25751 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25752 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25753 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25754 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
25755 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
25756 +
25757 + if (err)
25758 + break;
25759 +
25760 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25761 + regs->r11 = addr1;
25762 + regs->r10 = addr2;
25763 + regs->ip = addr1;
25764 + return 2;
25765 + }
25766 + } while (0);
25767 +
25768 + return 1; /* PaX in action */
25769 +}
25770 +#endif
25771 +
25772 +/*
25773 + * PaX: decide what to do with offenders (regs->ip = fault address)
25774 + *
25775 + * returns 1 when task should be killed
25776 + * 2 when gcc trampoline was detected
25777 + */
25778 +static int pax_handle_fetch_fault(struct pt_regs *regs)
25779 +{
25780 + if (v8086_mode(regs))
25781 + return 1;
25782 +
25783 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
25784 + return 1;
25785 +
25786 +#ifdef CONFIG_X86_32
25787 + return pax_handle_fetch_fault_32(regs);
25788 +#else
25789 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
25790 + return pax_handle_fetch_fault_32(regs);
25791 + else
25792 + return pax_handle_fetch_fault_64(regs);
25793 +#endif
25794 +}
25795 +#endif
25796 +
25797 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25798 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
25799 +{
25800 + long i;
25801 +
25802 + printk(KERN_ERR "PAX: bytes at PC: ");
25803 + for (i = 0; i < 20; i++) {
25804 + unsigned char c;
25805 + if (get_user(c, (unsigned char __force_user *)pc+i))
25806 + printk(KERN_CONT "?? ");
25807 + else
25808 + printk(KERN_CONT "%02x ", c);
25809 + }
25810 + printk("\n");
25811 +
25812 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
25813 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
25814 + unsigned long c;
25815 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
25816 +#ifdef CONFIG_X86_32
25817 + printk(KERN_CONT "???????? ");
25818 +#else
25819 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
25820 + printk(KERN_CONT "???????? ???????? ");
25821 + else
25822 + printk(KERN_CONT "???????????????? ");
25823 +#endif
25824 + } else {
25825 +#ifdef CONFIG_X86_64
25826 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
25827 + printk(KERN_CONT "%08x ", (unsigned int)c);
25828 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
25829 + } else
25830 +#endif
25831 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
25832 + }
25833 + }
25834 + printk("\n");
25835 +}
25836 +#endif
25837 +
25838 +/**
25839 + * probe_kernel_write(): safely attempt to write to a location
25840 + * @dst: address to write to
25841 + * @src: pointer to the data that shall be written
25842 + * @size: size of the data chunk
25843 + *
25844 + * Safely write to address @dst from the buffer at @src. If a kernel fault
25845 + * happens, handle that and return -EFAULT.
25846 + */
25847 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
25848 +{
25849 + long ret;
25850 + mm_segment_t old_fs = get_fs();
25851 +
25852 + set_fs(KERNEL_DS);
25853 + pagefault_disable();
25854 + pax_open_kernel();
25855 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
25856 + pax_close_kernel();
25857 + pagefault_enable();
25858 + set_fs(old_fs);
25859 +
25860 + return ret ? -EFAULT : 0;
25861 +}
25862 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
25863 index dd74e46..7d26398 100644
25864 --- a/arch/x86/mm/gup.c
25865 +++ b/arch/x86/mm/gup.c
25866 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
25867 addr = start;
25868 len = (unsigned long) nr_pages << PAGE_SHIFT;
25869 end = start + len;
25870 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25871 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25872 (void __user *)start, len)))
25873 return 0;
25874
25875 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
25876 index 6f31ee5..8ee4164 100644
25877 --- a/arch/x86/mm/highmem_32.c
25878 +++ b/arch/x86/mm/highmem_32.c
25879 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
25880 idx = type + KM_TYPE_NR*smp_processor_id();
25881 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25882 BUG_ON(!pte_none(*(kmap_pte-idx)));
25883 +
25884 + pax_open_kernel();
25885 set_pte(kmap_pte-idx, mk_pte(page, prot));
25886 + pax_close_kernel();
25887 +
25888 arch_flush_lazy_mmu_mode();
25889
25890 return (void *)vaddr;
25891 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
25892 index 937bff5..a354c44 100644
25893 --- a/arch/x86/mm/hugetlbpage.c
25894 +++ b/arch/x86/mm/hugetlbpage.c
25895 @@ -276,13 +276,21 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
25896 struct hstate *h = hstate_file(file);
25897 struct mm_struct *mm = current->mm;
25898 struct vm_area_struct *vma;
25899 - unsigned long start_addr;
25900 + unsigned long start_addr, pax_task_size = TASK_SIZE;
25901 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25902 +
25903 +#ifdef CONFIG_PAX_SEGMEXEC
25904 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25905 + pax_task_size = SEGMEXEC_TASK_SIZE;
25906 +#endif
25907 +
25908 + pax_task_size -= PAGE_SIZE;
25909
25910 if (len > mm->cached_hole_size) {
25911 - start_addr = mm->free_area_cache;
25912 + start_addr = mm->free_area_cache;
25913 } else {
25914 - start_addr = TASK_UNMAPPED_BASE;
25915 - mm->cached_hole_size = 0;
25916 + start_addr = mm->mmap_base;
25917 + mm->cached_hole_size = 0;
25918 }
25919
25920 full_search:
25921 @@ -290,26 +298,27 @@ full_search:
25922
25923 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
25924 /* At this point: (!vma || addr < vma->vm_end). */
25925 - if (TASK_SIZE - len < addr) {
25926 + if (pax_task_size - len < addr) {
25927 /*
25928 * Start a new search - just in case we missed
25929 * some holes.
25930 */
25931 - if (start_addr != TASK_UNMAPPED_BASE) {
25932 - start_addr = TASK_UNMAPPED_BASE;
25933 + if (start_addr != mm->mmap_base) {
25934 + start_addr = mm->mmap_base;
25935 mm->cached_hole_size = 0;
25936 goto full_search;
25937 }
25938 return -ENOMEM;
25939 }
25940 - if (!vma || addr + len <= vma->vm_start) {
25941 - mm->free_area_cache = addr + len;
25942 - return addr;
25943 - }
25944 + if (check_heap_stack_gap(vma, addr, len, offset))
25945 + break;
25946 if (addr + mm->cached_hole_size < vma->vm_start)
25947 mm->cached_hole_size = vma->vm_start - addr;
25948 addr = ALIGN(vma->vm_end, huge_page_size(h));
25949 }
25950 +
25951 + mm->free_area_cache = addr + len;
25952 + return addr;
25953 }
25954
25955 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25956 @@ -320,9 +329,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25957 struct mm_struct *mm = current->mm;
25958 struct vm_area_struct *vma;
25959 unsigned long base = mm->mmap_base;
25960 - unsigned long addr = addr0;
25961 + unsigned long addr;
25962 unsigned long largest_hole = mm->cached_hole_size;
25963 - unsigned long start_addr;
25964 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25965
25966 /* don't allow allocations above current base */
25967 if (mm->free_area_cache > base)
25968 @@ -332,16 +341,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25969 largest_hole = 0;
25970 mm->free_area_cache = base;
25971 }
25972 -try_again:
25973 - start_addr = mm->free_area_cache;
25974
25975 /* make sure it can fit in the remaining address space */
25976 if (mm->free_area_cache < len)
25977 goto fail;
25978
25979 /* either no address requested or can't fit in requested address hole */
25980 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
25981 + addr = mm->free_area_cache - len;
25982 do {
25983 + addr &= huge_page_mask(h);
25984 /*
25985 * Lookup failure means no vma is above this address,
25986 * i.e. return with success:
25987 @@ -350,10 +358,10 @@ try_again:
25988 if (!vma)
25989 return addr;
25990
25991 - if (addr + len <= vma->vm_start) {
25992 + if (check_heap_stack_gap(vma, addr, len, offset)) {
25993 /* remember the address as a hint for next time */
25994 - mm->cached_hole_size = largest_hole;
25995 - return (mm->free_area_cache = addr);
25996 + mm->cached_hole_size = largest_hole;
25997 + return (mm->free_area_cache = addr);
25998 } else if (mm->free_area_cache == vma->vm_end) {
25999 /* pull free_area_cache down to the first hole */
26000 mm->free_area_cache = vma->vm_start;
26001 @@ -362,29 +370,34 @@ try_again:
26002
26003 /* remember the largest hole we saw so far */
26004 if (addr + largest_hole < vma->vm_start)
26005 - largest_hole = vma->vm_start - addr;
26006 + largest_hole = vma->vm_start - addr;
26007
26008 /* try just below the current vma->vm_start */
26009 - addr = (vma->vm_start - len) & huge_page_mask(h);
26010 - } while (len <= vma->vm_start);
26011 + addr = skip_heap_stack_gap(vma, len, offset);
26012 + } while (!IS_ERR_VALUE(addr));
26013
26014 fail:
26015 /*
26016 - * if hint left us with no space for the requested
26017 - * mapping then try again:
26018 - */
26019 - if (start_addr != base) {
26020 - mm->free_area_cache = base;
26021 - largest_hole = 0;
26022 - goto try_again;
26023 - }
26024 - /*
26025 * A failed mmap() very likely causes application failure,
26026 * so fall back to the bottom-up function here. This scenario
26027 * can happen with large stack limits and large mmap()
26028 * allocations.
26029 */
26030 - mm->free_area_cache = TASK_UNMAPPED_BASE;
26031 +
26032 +#ifdef CONFIG_PAX_SEGMEXEC
26033 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26034 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
26035 + else
26036 +#endif
26037 +
26038 + mm->mmap_base = TASK_UNMAPPED_BASE;
26039 +
26040 +#ifdef CONFIG_PAX_RANDMMAP
26041 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26042 + mm->mmap_base += mm->delta_mmap;
26043 +#endif
26044 +
26045 + mm->free_area_cache = mm->mmap_base;
26046 mm->cached_hole_size = ~0UL;
26047 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
26048 len, pgoff, flags);
26049 @@ -392,6 +405,7 @@ fail:
26050 /*
26051 * Restore the topdown base:
26052 */
26053 + mm->mmap_base = base;
26054 mm->free_area_cache = base;
26055 mm->cached_hole_size = ~0UL;
26056
26057 @@ -405,10 +419,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
26058 struct hstate *h = hstate_file(file);
26059 struct mm_struct *mm = current->mm;
26060 struct vm_area_struct *vma;
26061 + unsigned long pax_task_size = TASK_SIZE;
26062 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
26063
26064 if (len & ~huge_page_mask(h))
26065 return -EINVAL;
26066 - if (len > TASK_SIZE)
26067 +
26068 +#ifdef CONFIG_PAX_SEGMEXEC
26069 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26070 + pax_task_size = SEGMEXEC_TASK_SIZE;
26071 +#endif
26072 +
26073 + pax_task_size -= PAGE_SIZE;
26074 +
26075 + if (len > pax_task_size)
26076 return -ENOMEM;
26077
26078 if (flags & MAP_FIXED) {
26079 @@ -420,8 +444,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
26080 if (addr) {
26081 addr = ALIGN(addr, huge_page_size(h));
26082 vma = find_vma(mm, addr);
26083 - if (TASK_SIZE - len >= addr &&
26084 - (!vma || addr + len <= vma->vm_start))
26085 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26086 return addr;
26087 }
26088 if (mm->get_unmapped_area == arch_get_unmapped_area)
26089 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
26090 index d7aea41..0fc945b 100644
26091 --- a/arch/x86/mm/init.c
26092 +++ b/arch/x86/mm/init.c
26093 @@ -4,6 +4,7 @@
26094 #include <linux/swap.h>
26095 #include <linux/memblock.h>
26096 #include <linux/bootmem.h> /* for max_low_pfn */
26097 +#include <linux/tboot.h>
26098
26099 #include <asm/cacheflush.h>
26100 #include <asm/e820.h>
26101 @@ -16,6 +17,8 @@
26102 #include <asm/tlb.h>
26103 #include <asm/proto.h>
26104 #include <asm/dma.h> /* for MAX_DMA_PFN */
26105 +#include <asm/desc.h>
26106 +#include <asm/bios_ebda.h>
26107
26108 unsigned long __initdata pgt_buf_start;
26109 unsigned long __meminitdata pgt_buf_end;
26110 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
26111 {
26112 int i;
26113 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
26114 - unsigned long start = 0, good_end;
26115 + unsigned long start = 0x100000, good_end;
26116 phys_addr_t base;
26117
26118 for (i = 0; i < nr_range; i++) {
26119 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
26120 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
26121 * mmio resources as well as potential bios/acpi data regions.
26122 */
26123 +
26124 +#ifdef CONFIG_GRKERNSEC_KMEM
26125 +static unsigned int ebda_start __read_only;
26126 +static unsigned int ebda_end __read_only;
26127 +#endif
26128 +
26129 int devmem_is_allowed(unsigned long pagenr)
26130 {
26131 - if (pagenr < 256)
26132 +#ifdef CONFIG_GRKERNSEC_KMEM
26133 + /* allow BDA */
26134 + if (!pagenr)
26135 return 1;
26136 + /* allow EBDA */
26137 + if (pagenr >= ebda_start && pagenr < ebda_end)
26138 + return 1;
26139 + /* if tboot is in use, allow access to its hardcoded serial log range */
26140 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
26141 + return 1;
26142 +#else
26143 + if (!pagenr)
26144 + return 1;
26145 +#ifdef CONFIG_VM86
26146 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
26147 + return 1;
26148 +#endif
26149 +#endif
26150 +
26151 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
26152 + return 1;
26153 +#ifdef CONFIG_GRKERNSEC_KMEM
26154 + /* throw out everything else below 1MB */
26155 + if (pagenr <= 256)
26156 + return 0;
26157 +#endif
26158 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
26159 return 0;
26160 if (!page_is_ram(pagenr))
26161 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
26162 #endif
26163 }
26164
26165 +#ifdef CONFIG_GRKERNSEC_KMEM
26166 +static inline void gr_init_ebda(void)
26167 +{
26168 + unsigned int ebda_addr;
26169 + unsigned int ebda_size = 0;
26170 +
26171 + ebda_addr = get_bios_ebda();
26172 + if (ebda_addr) {
26173 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
26174 + ebda_size <<= 10;
26175 + }
26176 + if (ebda_addr && ebda_size) {
26177 + ebda_start = ebda_addr >> PAGE_SHIFT;
26178 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
26179 + } else {
26180 + ebda_start = 0x9f000 >> PAGE_SHIFT;
26181 + ebda_end = 0xa0000 >> PAGE_SHIFT;
26182 + }
26183 +}
26184 +#else
26185 +static inline void gr_init_ebda(void) { }
26186 +#endif
26187 +
26188 void free_initmem(void)
26189 {
26190 +#ifdef CONFIG_PAX_KERNEXEC
26191 +#ifdef CONFIG_X86_32
26192 + /* PaX: limit KERNEL_CS to actual size */
26193 + unsigned long addr, limit;
26194 + struct desc_struct d;
26195 + int cpu;
26196 +#else
26197 + pgd_t *pgd;
26198 + pud_t *pud;
26199 + pmd_t *pmd;
26200 + unsigned long addr, end;
26201 +#endif
26202 +#endif
26203 +
26204 + gr_init_ebda();
26205 +
26206 +#ifdef CONFIG_PAX_KERNEXEC
26207 +#ifdef CONFIG_X86_32
26208 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
26209 + limit = (limit - 1UL) >> PAGE_SHIFT;
26210 +
26211 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
26212 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26213 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
26214 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
26215 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
26216 + }
26217 +
26218 + /* PaX: make KERNEL_CS read-only */
26219 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
26220 + if (!paravirt_enabled())
26221 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
26222 +/*
26223 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
26224 + pgd = pgd_offset_k(addr);
26225 + pud = pud_offset(pgd, addr);
26226 + pmd = pmd_offset(pud, addr);
26227 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26228 + }
26229 +*/
26230 +#ifdef CONFIG_X86_PAE
26231 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
26232 +/*
26233 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
26234 + pgd = pgd_offset_k(addr);
26235 + pud = pud_offset(pgd, addr);
26236 + pmd = pmd_offset(pud, addr);
26237 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
26238 + }
26239 +*/
26240 +#endif
26241 +
26242 +#ifdef CONFIG_MODULES
26243 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
26244 +#endif
26245 +
26246 +#else
26247 + /* PaX: make kernel code/rodata read-only, rest non-executable */
26248 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
26249 + pgd = pgd_offset_k(addr);
26250 + pud = pud_offset(pgd, addr);
26251 + pmd = pmd_offset(pud, addr);
26252 + if (!pmd_present(*pmd))
26253 + continue;
26254 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
26255 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26256 + else
26257 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
26258 + }
26259 +
26260 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
26261 + end = addr + KERNEL_IMAGE_SIZE;
26262 + for (; addr < end; addr += PMD_SIZE) {
26263 + pgd = pgd_offset_k(addr);
26264 + pud = pud_offset(pgd, addr);
26265 + pmd = pmd_offset(pud, addr);
26266 + if (!pmd_present(*pmd))
26267 + continue;
26268 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
26269 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26270 + }
26271 +#endif
26272 +
26273 + flush_tlb_all();
26274 +#endif
26275 +
26276 free_init_pages("unused kernel memory",
26277 (unsigned long)(&__init_begin),
26278 (unsigned long)(&__init_end));
26279 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
26280 index 11a5800..4bd9977 100644
26281 --- a/arch/x86/mm/init_32.c
26282 +++ b/arch/x86/mm/init_32.c
26283 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
26284 }
26285
26286 /*
26287 - * Creates a middle page table and puts a pointer to it in the
26288 - * given global directory entry. This only returns the gd entry
26289 - * in non-PAE compilation mode, since the middle layer is folded.
26290 - */
26291 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
26292 -{
26293 - pud_t *pud;
26294 - pmd_t *pmd_table;
26295 -
26296 -#ifdef CONFIG_X86_PAE
26297 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
26298 - if (after_bootmem)
26299 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
26300 - else
26301 - pmd_table = (pmd_t *)alloc_low_page();
26302 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
26303 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
26304 - pud = pud_offset(pgd, 0);
26305 - BUG_ON(pmd_table != pmd_offset(pud, 0));
26306 -
26307 - return pmd_table;
26308 - }
26309 -#endif
26310 - pud = pud_offset(pgd, 0);
26311 - pmd_table = pmd_offset(pud, 0);
26312 -
26313 - return pmd_table;
26314 -}
26315 -
26316 -/*
26317 * Create a page table and place a pointer to it in a middle page
26318 * directory entry:
26319 */
26320 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
26321 page_table = (pte_t *)alloc_low_page();
26322
26323 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
26324 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26325 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
26326 +#else
26327 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
26328 +#endif
26329 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
26330 }
26331
26332 return pte_offset_kernel(pmd, 0);
26333 }
26334
26335 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
26336 +{
26337 + pud_t *pud;
26338 + pmd_t *pmd_table;
26339 +
26340 + pud = pud_offset(pgd, 0);
26341 + pmd_table = pmd_offset(pud, 0);
26342 +
26343 + return pmd_table;
26344 +}
26345 +
26346 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
26347 {
26348 int pgd_idx = pgd_index(vaddr);
26349 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26350 int pgd_idx, pmd_idx;
26351 unsigned long vaddr;
26352 pgd_t *pgd;
26353 + pud_t *pud;
26354 pmd_t *pmd;
26355 pte_t *pte = NULL;
26356
26357 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26358 pgd = pgd_base + pgd_idx;
26359
26360 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
26361 - pmd = one_md_table_init(pgd);
26362 - pmd = pmd + pmd_index(vaddr);
26363 + pud = pud_offset(pgd, vaddr);
26364 + pmd = pmd_offset(pud, vaddr);
26365 +
26366 +#ifdef CONFIG_X86_PAE
26367 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26368 +#endif
26369 +
26370 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
26371 pmd++, pmd_idx++) {
26372 pte = page_table_kmap_check(one_page_table_init(pmd),
26373 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26374 }
26375 }
26376
26377 -static inline int is_kernel_text(unsigned long addr)
26378 +static inline int is_kernel_text(unsigned long start, unsigned long end)
26379 {
26380 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
26381 - return 1;
26382 - return 0;
26383 + if ((start > ktla_ktva((unsigned long)_etext) ||
26384 + end <= ktla_ktva((unsigned long)_stext)) &&
26385 + (start > ktla_ktva((unsigned long)_einittext) ||
26386 + end <= ktla_ktva((unsigned long)_sinittext)) &&
26387 +
26388 +#ifdef CONFIG_ACPI_SLEEP
26389 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
26390 +#endif
26391 +
26392 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
26393 + return 0;
26394 + return 1;
26395 }
26396
26397 /*
26398 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
26399 unsigned long last_map_addr = end;
26400 unsigned long start_pfn, end_pfn;
26401 pgd_t *pgd_base = swapper_pg_dir;
26402 - int pgd_idx, pmd_idx, pte_ofs;
26403 + unsigned int pgd_idx, pmd_idx, pte_ofs;
26404 unsigned long pfn;
26405 pgd_t *pgd;
26406 + pud_t *pud;
26407 pmd_t *pmd;
26408 pte_t *pte;
26409 unsigned pages_2m, pages_4k;
26410 @@ -280,8 +281,13 @@ repeat:
26411 pfn = start_pfn;
26412 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26413 pgd = pgd_base + pgd_idx;
26414 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
26415 - pmd = one_md_table_init(pgd);
26416 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
26417 + pud = pud_offset(pgd, 0);
26418 + pmd = pmd_offset(pud, 0);
26419 +
26420 +#ifdef CONFIG_X86_PAE
26421 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26422 +#endif
26423
26424 if (pfn >= end_pfn)
26425 continue;
26426 @@ -293,14 +299,13 @@ repeat:
26427 #endif
26428 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
26429 pmd++, pmd_idx++) {
26430 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
26431 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
26432
26433 /*
26434 * Map with big pages if possible, otherwise
26435 * create normal page tables:
26436 */
26437 if (use_pse) {
26438 - unsigned int addr2;
26439 pgprot_t prot = PAGE_KERNEL_LARGE;
26440 /*
26441 * first pass will use the same initial
26442 @@ -310,11 +315,7 @@ repeat:
26443 __pgprot(PTE_IDENT_ATTR |
26444 _PAGE_PSE);
26445
26446 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
26447 - PAGE_OFFSET + PAGE_SIZE-1;
26448 -
26449 - if (is_kernel_text(addr) ||
26450 - is_kernel_text(addr2))
26451 + if (is_kernel_text(address, address + PMD_SIZE))
26452 prot = PAGE_KERNEL_LARGE_EXEC;
26453
26454 pages_2m++;
26455 @@ -331,7 +332,7 @@ repeat:
26456 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26457 pte += pte_ofs;
26458 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
26459 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
26460 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
26461 pgprot_t prot = PAGE_KERNEL;
26462 /*
26463 * first pass will use the same initial
26464 @@ -339,7 +340,7 @@ repeat:
26465 */
26466 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
26467
26468 - if (is_kernel_text(addr))
26469 + if (is_kernel_text(address, address + PAGE_SIZE))
26470 prot = PAGE_KERNEL_EXEC;
26471
26472 pages_4k++;
26473 @@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
26474
26475 pud = pud_offset(pgd, va);
26476 pmd = pmd_offset(pud, va);
26477 - if (!pmd_present(*pmd))
26478 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
26479 break;
26480
26481 pte = pte_offset_kernel(pmd, va);
26482 @@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
26483
26484 static void __init pagetable_init(void)
26485 {
26486 - pgd_t *pgd_base = swapper_pg_dir;
26487 -
26488 - permanent_kmaps_init(pgd_base);
26489 + permanent_kmaps_init(swapper_pg_dir);
26490 }
26491
26492 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26493 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26494 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26495
26496 /* user-defined highmem size */
26497 @@ -731,6 +730,12 @@ void __init mem_init(void)
26498
26499 pci_iommu_alloc();
26500
26501 +#ifdef CONFIG_PAX_PER_CPU_PGD
26502 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26503 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26504 + KERNEL_PGD_PTRS);
26505 +#endif
26506 +
26507 #ifdef CONFIG_FLATMEM
26508 BUG_ON(!mem_map);
26509 #endif
26510 @@ -757,7 +762,7 @@ void __init mem_init(void)
26511 reservedpages++;
26512
26513 codesize = (unsigned long) &_etext - (unsigned long) &_text;
26514 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
26515 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
26516 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
26517
26518 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
26519 @@ -798,10 +803,10 @@ void __init mem_init(void)
26520 ((unsigned long)&__init_end -
26521 (unsigned long)&__init_begin) >> 10,
26522
26523 - (unsigned long)&_etext, (unsigned long)&_edata,
26524 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
26525 + (unsigned long)&_sdata, (unsigned long)&_edata,
26526 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
26527
26528 - (unsigned long)&_text, (unsigned long)&_etext,
26529 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
26530 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
26531
26532 /*
26533 @@ -879,6 +884,7 @@ void set_kernel_text_rw(void)
26534 if (!kernel_set_to_readonly)
26535 return;
26536
26537 + start = ktla_ktva(start);
26538 pr_debug("Set kernel text: %lx - %lx for read write\n",
26539 start, start+size);
26540
26541 @@ -893,6 +899,7 @@ void set_kernel_text_ro(void)
26542 if (!kernel_set_to_readonly)
26543 return;
26544
26545 + start = ktla_ktva(start);
26546 pr_debug("Set kernel text: %lx - %lx for read only\n",
26547 start, start+size);
26548
26549 @@ -921,6 +928,7 @@ void mark_rodata_ro(void)
26550 unsigned long start = PFN_ALIGN(_text);
26551 unsigned long size = PFN_ALIGN(_etext) - start;
26552
26553 + start = ktla_ktva(start);
26554 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
26555 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
26556 size >> 10);
26557 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
26558 index 3baff25..8b37564 100644
26559 --- a/arch/x86/mm/init_64.c
26560 +++ b/arch/x86/mm/init_64.c
26561 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
26562 * around without checking the pgd every time.
26563 */
26564
26565 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
26566 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
26567 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26568
26569 int force_personality32;
26570 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26571
26572 for (address = start; address <= end; address += PGDIR_SIZE) {
26573 const pgd_t *pgd_ref = pgd_offset_k(address);
26574 +
26575 +#ifdef CONFIG_PAX_PER_CPU_PGD
26576 + unsigned long cpu;
26577 +#else
26578 struct page *page;
26579 +#endif
26580
26581 if (pgd_none(*pgd_ref))
26582 continue;
26583
26584 spin_lock(&pgd_lock);
26585 +
26586 +#ifdef CONFIG_PAX_PER_CPU_PGD
26587 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26588 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
26589 +#else
26590 list_for_each_entry(page, &pgd_list, lru) {
26591 pgd_t *pgd;
26592 spinlock_t *pgt_lock;
26593 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26594 /* the pgt_lock only for Xen */
26595 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26596 spin_lock(pgt_lock);
26597 +#endif
26598
26599 if (pgd_none(*pgd))
26600 set_pgd(pgd, *pgd_ref);
26601 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26602 BUG_ON(pgd_page_vaddr(*pgd)
26603 != pgd_page_vaddr(*pgd_ref));
26604
26605 +#ifndef CONFIG_PAX_PER_CPU_PGD
26606 spin_unlock(pgt_lock);
26607 +#endif
26608 +
26609 }
26610 spin_unlock(&pgd_lock);
26611 }
26612 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
26613 {
26614 if (pgd_none(*pgd)) {
26615 pud_t *pud = (pud_t *)spp_getpage();
26616 - pgd_populate(&init_mm, pgd, pud);
26617 + pgd_populate_kernel(&init_mm, pgd, pud);
26618 if (pud != pud_offset(pgd, 0))
26619 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
26620 pud, pud_offset(pgd, 0));
26621 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
26622 {
26623 if (pud_none(*pud)) {
26624 pmd_t *pmd = (pmd_t *) spp_getpage();
26625 - pud_populate(&init_mm, pud, pmd);
26626 + pud_populate_kernel(&init_mm, pud, pmd);
26627 if (pmd != pmd_offset(pud, 0))
26628 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
26629 pmd, pmd_offset(pud, 0));
26630 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
26631 pmd = fill_pmd(pud, vaddr);
26632 pte = fill_pte(pmd, vaddr);
26633
26634 + pax_open_kernel();
26635 set_pte(pte, new_pte);
26636 + pax_close_kernel();
26637
26638 /*
26639 * It's enough to flush this one mapping.
26640 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
26641 pgd = pgd_offset_k((unsigned long)__va(phys));
26642 if (pgd_none(*pgd)) {
26643 pud = (pud_t *) spp_getpage();
26644 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
26645 - _PAGE_USER));
26646 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
26647 }
26648 pud = pud_offset(pgd, (unsigned long)__va(phys));
26649 if (pud_none(*pud)) {
26650 pmd = (pmd_t *) spp_getpage();
26651 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
26652 - _PAGE_USER));
26653 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
26654 }
26655 pmd = pmd_offset(pud, phys);
26656 BUG_ON(!pmd_none(*pmd));
26657 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
26658 if (pfn >= pgt_buf_top)
26659 panic("alloc_low_page: ran out of memory");
26660
26661 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26662 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26663 clear_page(adr);
26664 *phys = pfn * PAGE_SIZE;
26665 return adr;
26666 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
26667
26668 phys = __pa(virt);
26669 left = phys & (PAGE_SIZE - 1);
26670 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26671 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26672 adr = (void *)(((unsigned long)adr) | left);
26673
26674 return adr;
26675 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
26676 unmap_low_page(pmd);
26677
26678 spin_lock(&init_mm.page_table_lock);
26679 - pud_populate(&init_mm, pud, __va(pmd_phys));
26680 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
26681 spin_unlock(&init_mm.page_table_lock);
26682 }
26683 __flush_tlb_all();
26684 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
26685 unmap_low_page(pud);
26686
26687 spin_lock(&init_mm.page_table_lock);
26688 - pgd_populate(&init_mm, pgd, __va(pud_phys));
26689 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
26690 spin_unlock(&init_mm.page_table_lock);
26691 pgd_changed = true;
26692 }
26693 @@ -691,6 +705,12 @@ void __init mem_init(void)
26694
26695 pci_iommu_alloc();
26696
26697 +#ifdef CONFIG_PAX_PER_CPU_PGD
26698 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26699 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26700 + KERNEL_PGD_PTRS);
26701 +#endif
26702 +
26703 /* clear_bss() already clear the empty_zero_page */
26704
26705 reservedpages = 0;
26706 @@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
26707 static struct vm_area_struct gate_vma = {
26708 .vm_start = VSYSCALL_START,
26709 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
26710 - .vm_page_prot = PAGE_READONLY_EXEC,
26711 - .vm_flags = VM_READ | VM_EXEC
26712 + .vm_page_prot = PAGE_READONLY,
26713 + .vm_flags = VM_READ
26714 };
26715
26716 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26717 @@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
26718
26719 const char *arch_vma_name(struct vm_area_struct *vma)
26720 {
26721 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26722 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26723 return "[vdso]";
26724 if (vma == &gate_vma)
26725 return "[vsyscall]";
26726 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
26727 index 7b179b4..6bd1777 100644
26728 --- a/arch/x86/mm/iomap_32.c
26729 +++ b/arch/x86/mm/iomap_32.c
26730 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
26731 type = kmap_atomic_idx_push();
26732 idx = type + KM_TYPE_NR * smp_processor_id();
26733 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
26734 +
26735 + pax_open_kernel();
26736 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
26737 + pax_close_kernel();
26738 +
26739 arch_flush_lazy_mmu_mode();
26740
26741 return (void *)vaddr;
26742 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
26743 index 78fe3f1..2f9433c 100644
26744 --- a/arch/x86/mm/ioremap.c
26745 +++ b/arch/x86/mm/ioremap.c
26746 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
26747 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
26748 int is_ram = page_is_ram(pfn);
26749
26750 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
26751 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
26752 return NULL;
26753 WARN_ON_ONCE(is_ram);
26754 }
26755 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
26756 *
26757 * Caller must ensure there is only one unmapping for the same pointer.
26758 */
26759 -void iounmap(volatile void __iomem *addr)
26760 +void iounmap(const volatile void __iomem *addr)
26761 {
26762 struct vm_struct *p, *o;
26763
26764 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
26765
26766 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
26767 if (page_is_ram(start >> PAGE_SHIFT))
26768 +#ifdef CONFIG_HIGHMEM
26769 + if ((start >> PAGE_SHIFT) < max_low_pfn)
26770 +#endif
26771 return __va(phys);
26772
26773 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
26774 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
26775 early_param("early_ioremap_debug", early_ioremap_debug_setup);
26776
26777 static __initdata int after_paging_init;
26778 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
26779 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
26780
26781 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
26782 {
26783 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
26784 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
26785
26786 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
26787 - memset(bm_pte, 0, sizeof(bm_pte));
26788 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
26789 + pmd_populate_user(&init_mm, pmd, bm_pte);
26790
26791 /*
26792 * The boot-ioremap range spans multiple pmds, for which
26793 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
26794 index d87dd6d..bf3fa66 100644
26795 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
26796 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
26797 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
26798 * memory (e.g. tracked pages)? For now, we need this to avoid
26799 * invoking kmemcheck for PnP BIOS calls.
26800 */
26801 - if (regs->flags & X86_VM_MASK)
26802 + if (v8086_mode(regs))
26803 return false;
26804 - if (regs->cs != __KERNEL_CS)
26805 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
26806 return false;
26807
26808 pte = kmemcheck_pte_lookup(address);
26809 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
26810 index 845df68..1d8d29f 100644
26811 --- a/arch/x86/mm/mmap.c
26812 +++ b/arch/x86/mm/mmap.c
26813 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
26814 * Leave an at least ~128 MB hole with possible stack randomization.
26815 */
26816 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
26817 -#define MAX_GAP (TASK_SIZE/6*5)
26818 +#define MAX_GAP (pax_task_size/6*5)
26819
26820 static int mmap_is_legacy(void)
26821 {
26822 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
26823 return rnd << PAGE_SHIFT;
26824 }
26825
26826 -static unsigned long mmap_base(void)
26827 +static unsigned long mmap_base(struct mm_struct *mm)
26828 {
26829 unsigned long gap = rlimit(RLIMIT_STACK);
26830 + unsigned long pax_task_size = TASK_SIZE;
26831 +
26832 +#ifdef CONFIG_PAX_SEGMEXEC
26833 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26834 + pax_task_size = SEGMEXEC_TASK_SIZE;
26835 +#endif
26836
26837 if (gap < MIN_GAP)
26838 gap = MIN_GAP;
26839 else if (gap > MAX_GAP)
26840 gap = MAX_GAP;
26841
26842 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
26843 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
26844 }
26845
26846 /*
26847 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
26848 * does, but not when emulating X86_32
26849 */
26850 -static unsigned long mmap_legacy_base(void)
26851 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
26852 {
26853 - if (mmap_is_ia32())
26854 + if (mmap_is_ia32()) {
26855 +
26856 +#ifdef CONFIG_PAX_SEGMEXEC
26857 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26858 + return SEGMEXEC_TASK_UNMAPPED_BASE;
26859 + else
26860 +#endif
26861 +
26862 return TASK_UNMAPPED_BASE;
26863 - else
26864 + } else
26865 return TASK_UNMAPPED_BASE + mmap_rnd();
26866 }
26867
26868 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
26869 void arch_pick_mmap_layout(struct mm_struct *mm)
26870 {
26871 if (mmap_is_legacy()) {
26872 - mm->mmap_base = mmap_legacy_base();
26873 + mm->mmap_base = mmap_legacy_base(mm);
26874 +
26875 +#ifdef CONFIG_PAX_RANDMMAP
26876 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26877 + mm->mmap_base += mm->delta_mmap;
26878 +#endif
26879 +
26880 mm->get_unmapped_area = arch_get_unmapped_area;
26881 mm->unmap_area = arch_unmap_area;
26882 } else {
26883 - mm->mmap_base = mmap_base();
26884 + mm->mmap_base = mmap_base(mm);
26885 +
26886 +#ifdef CONFIG_PAX_RANDMMAP
26887 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26888 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
26889 +#endif
26890 +
26891 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
26892 mm->unmap_area = arch_unmap_area_topdown;
26893 }
26894 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
26895 index dc0b727..f612039 100644
26896 --- a/arch/x86/mm/mmio-mod.c
26897 +++ b/arch/x86/mm/mmio-mod.c
26898 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
26899 break;
26900 default:
26901 {
26902 - unsigned char *ip = (unsigned char *)instptr;
26903 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
26904 my_trace->opcode = MMIO_UNKNOWN_OP;
26905 my_trace->width = 0;
26906 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
26907 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
26908 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26909 void __iomem *addr)
26910 {
26911 - static atomic_t next_id;
26912 + static atomic_unchecked_t next_id;
26913 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
26914 /* These are page-unaligned. */
26915 struct mmiotrace_map map = {
26916 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26917 .private = trace
26918 },
26919 .phys = offset,
26920 - .id = atomic_inc_return(&next_id)
26921 + .id = atomic_inc_return_unchecked(&next_id)
26922 };
26923 map.map_id = trace->id;
26924
26925 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
26926 ioremap_trace_core(offset, size, addr);
26927 }
26928
26929 -static void iounmap_trace_core(volatile void __iomem *addr)
26930 +static void iounmap_trace_core(const volatile void __iomem *addr)
26931 {
26932 struct mmiotrace_map map = {
26933 .phys = 0,
26934 @@ -328,7 +328,7 @@ not_enabled:
26935 }
26936 }
26937
26938 -void mmiotrace_iounmap(volatile void __iomem *addr)
26939 +void mmiotrace_iounmap(const volatile void __iomem *addr)
26940 {
26941 might_sleep();
26942 if (is_enabled()) /* recheck and proper locking in *_core() */
26943 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
26944 index b008656..773eac2 100644
26945 --- a/arch/x86/mm/pageattr-test.c
26946 +++ b/arch/x86/mm/pageattr-test.c
26947 @@ -36,7 +36,7 @@ enum {
26948
26949 static int pte_testbit(pte_t pte)
26950 {
26951 - return pte_flags(pte) & _PAGE_UNUSED1;
26952 + return pte_flags(pte) & _PAGE_CPA_TEST;
26953 }
26954
26955 struct split_state {
26956 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
26957 index a718e0d..77419bc 100644
26958 --- a/arch/x86/mm/pageattr.c
26959 +++ b/arch/x86/mm/pageattr.c
26960 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26961 */
26962 #ifdef CONFIG_PCI_BIOS
26963 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
26964 - pgprot_val(forbidden) |= _PAGE_NX;
26965 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26966 #endif
26967
26968 /*
26969 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26970 * Does not cover __inittext since that is gone later on. On
26971 * 64bit we do not enforce !NX on the low mapping
26972 */
26973 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
26974 - pgprot_val(forbidden) |= _PAGE_NX;
26975 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
26976 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26977
26978 +#ifdef CONFIG_DEBUG_RODATA
26979 /*
26980 * The .rodata section needs to be read-only. Using the pfn
26981 * catches all aliases.
26982 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26983 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
26984 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
26985 pgprot_val(forbidden) |= _PAGE_RW;
26986 +#endif
26987
26988 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
26989 /*
26990 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26991 }
26992 #endif
26993
26994 +#ifdef CONFIG_PAX_KERNEXEC
26995 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
26996 + pgprot_val(forbidden) |= _PAGE_RW;
26997 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26998 + }
26999 +#endif
27000 +
27001 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
27002
27003 return prot;
27004 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
27005 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
27006 {
27007 /* change init_mm */
27008 + pax_open_kernel();
27009 set_pte_atomic(kpte, pte);
27010 +
27011 #ifdef CONFIG_X86_32
27012 if (!SHARED_KERNEL_PMD) {
27013 +
27014 +#ifdef CONFIG_PAX_PER_CPU_PGD
27015 + unsigned long cpu;
27016 +#else
27017 struct page *page;
27018 +#endif
27019
27020 +#ifdef CONFIG_PAX_PER_CPU_PGD
27021 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27022 + pgd_t *pgd = get_cpu_pgd(cpu);
27023 +#else
27024 list_for_each_entry(page, &pgd_list, lru) {
27025 - pgd_t *pgd;
27026 + pgd_t *pgd = (pgd_t *)page_address(page);
27027 +#endif
27028 +
27029 pud_t *pud;
27030 pmd_t *pmd;
27031
27032 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
27033 + pgd += pgd_index(address);
27034 pud = pud_offset(pgd, address);
27035 pmd = pmd_offset(pud, address);
27036 set_pte_atomic((pte_t *)pmd, pte);
27037 }
27038 }
27039 #endif
27040 + pax_close_kernel();
27041 }
27042
27043 static int
27044 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
27045 index 0eb572e..92f5c1e 100644
27046 --- a/arch/x86/mm/pat.c
27047 +++ b/arch/x86/mm/pat.c
27048 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
27049
27050 if (!entry) {
27051 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
27052 - current->comm, current->pid, start, end - 1);
27053 + current->comm, task_pid_nr(current), start, end - 1);
27054 return -EINVAL;
27055 }
27056
27057 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27058
27059 while (cursor < to) {
27060 if (!devmem_is_allowed(pfn)) {
27061 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
27062 - current->comm, from, to - 1);
27063 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
27064 + current->comm, from, to - 1, cursor);
27065 return 0;
27066 }
27067 cursor += PAGE_SIZE;
27068 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
27069 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
27070 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
27071 "for [mem %#010Lx-%#010Lx]\n",
27072 - current->comm, current->pid,
27073 + current->comm, task_pid_nr(current),
27074 cattr_name(flags),
27075 base, (unsigned long long)(base + size-1));
27076 return -EINVAL;
27077 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
27078 flags = lookup_memtype(paddr);
27079 if (want_flags != flags) {
27080 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
27081 - current->comm, current->pid,
27082 + current->comm, task_pid_nr(current),
27083 cattr_name(want_flags),
27084 (unsigned long long)paddr,
27085 (unsigned long long)(paddr + size - 1),
27086 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
27087 free_memtype(paddr, paddr + size);
27088 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
27089 " for [mem %#010Lx-%#010Lx], got %s\n",
27090 - current->comm, current->pid,
27091 + current->comm, task_pid_nr(current),
27092 cattr_name(want_flags),
27093 (unsigned long long)paddr,
27094 (unsigned long long)(paddr + size - 1),
27095 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
27096 index 9f0614d..92ae64a 100644
27097 --- a/arch/x86/mm/pf_in.c
27098 +++ b/arch/x86/mm/pf_in.c
27099 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
27100 int i;
27101 enum reason_type rv = OTHERS;
27102
27103 - p = (unsigned char *)ins_addr;
27104 + p = (unsigned char *)ktla_ktva(ins_addr);
27105 p += skip_prefix(p, &prf);
27106 p += get_opcode(p, &opcode);
27107
27108 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
27109 struct prefix_bits prf;
27110 int i;
27111
27112 - p = (unsigned char *)ins_addr;
27113 + p = (unsigned char *)ktla_ktva(ins_addr);
27114 p += skip_prefix(p, &prf);
27115 p += get_opcode(p, &opcode);
27116
27117 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
27118 struct prefix_bits prf;
27119 int i;
27120
27121 - p = (unsigned char *)ins_addr;
27122 + p = (unsigned char *)ktla_ktva(ins_addr);
27123 p += skip_prefix(p, &prf);
27124 p += get_opcode(p, &opcode);
27125
27126 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
27127 struct prefix_bits prf;
27128 int i;
27129
27130 - p = (unsigned char *)ins_addr;
27131 + p = (unsigned char *)ktla_ktva(ins_addr);
27132 p += skip_prefix(p, &prf);
27133 p += get_opcode(p, &opcode);
27134 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
27135 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
27136 struct prefix_bits prf;
27137 int i;
27138
27139 - p = (unsigned char *)ins_addr;
27140 + p = (unsigned char *)ktla_ktva(ins_addr);
27141 p += skip_prefix(p, &prf);
27142 p += get_opcode(p, &opcode);
27143 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
27144 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
27145 index 8573b83..4f3ed7e 100644
27146 --- a/arch/x86/mm/pgtable.c
27147 +++ b/arch/x86/mm/pgtable.c
27148 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
27149 list_del(&page->lru);
27150 }
27151
27152 -#define UNSHARED_PTRS_PER_PGD \
27153 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
27154 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27155 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
27156
27157 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
27158 +{
27159 + unsigned int count = USER_PGD_PTRS;
27160
27161 + while (count--)
27162 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
27163 +}
27164 +#endif
27165 +
27166 +#ifdef CONFIG_PAX_PER_CPU_PGD
27167 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
27168 +{
27169 + unsigned int count = USER_PGD_PTRS;
27170 +
27171 + while (count--) {
27172 + pgd_t pgd;
27173 +
27174 +#ifdef CONFIG_X86_64
27175 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
27176 +#else
27177 + pgd = *src++;
27178 +#endif
27179 +
27180 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27181 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
27182 +#endif
27183 +
27184 + *dst++ = pgd;
27185 + }
27186 +
27187 +}
27188 +#endif
27189 +
27190 +#ifdef CONFIG_X86_64
27191 +#define pxd_t pud_t
27192 +#define pyd_t pgd_t
27193 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
27194 +#define pxd_free(mm, pud) pud_free((mm), (pud))
27195 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
27196 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
27197 +#define PYD_SIZE PGDIR_SIZE
27198 +#else
27199 +#define pxd_t pmd_t
27200 +#define pyd_t pud_t
27201 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
27202 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
27203 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
27204 +#define pyd_offset(mm, address) pud_offset((mm), (address))
27205 +#define PYD_SIZE PUD_SIZE
27206 +#endif
27207 +
27208 +#ifdef CONFIG_PAX_PER_CPU_PGD
27209 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
27210 +static inline void pgd_dtor(pgd_t *pgd) {}
27211 +#else
27212 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
27213 {
27214 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
27215 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
27216 pgd_list_del(pgd);
27217 spin_unlock(&pgd_lock);
27218 }
27219 +#endif
27220
27221 /*
27222 * List of all pgd's needed for non-PAE so it can invalidate entries
27223 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
27224 * -- wli
27225 */
27226
27227 -#ifdef CONFIG_X86_PAE
27228 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
27229 /*
27230 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
27231 * updating the top-level pagetable entries to guarantee the
27232 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
27233 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
27234 * and initialize the kernel pmds here.
27235 */
27236 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
27237 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
27238
27239 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
27240 {
27241 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
27242 */
27243 flush_tlb_mm(mm);
27244 }
27245 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
27246 +#define PREALLOCATED_PXDS USER_PGD_PTRS
27247 #else /* !CONFIG_X86_PAE */
27248
27249 /* No need to prepopulate any pagetable entries in non-PAE modes. */
27250 -#define PREALLOCATED_PMDS 0
27251 +#define PREALLOCATED_PXDS 0
27252
27253 #endif /* CONFIG_X86_PAE */
27254
27255 -static void free_pmds(pmd_t *pmds[])
27256 +static void free_pxds(pxd_t *pxds[])
27257 {
27258 int i;
27259
27260 - for(i = 0; i < PREALLOCATED_PMDS; i++)
27261 - if (pmds[i])
27262 - free_page((unsigned long)pmds[i]);
27263 + for(i = 0; i < PREALLOCATED_PXDS; i++)
27264 + if (pxds[i])
27265 + free_page((unsigned long)pxds[i]);
27266 }
27267
27268 -static int preallocate_pmds(pmd_t *pmds[])
27269 +static int preallocate_pxds(pxd_t *pxds[])
27270 {
27271 int i;
27272 bool failed = false;
27273
27274 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
27275 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
27276 - if (pmd == NULL)
27277 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
27278 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
27279 + if (pxd == NULL)
27280 failed = true;
27281 - pmds[i] = pmd;
27282 + pxds[i] = pxd;
27283 }
27284
27285 if (failed) {
27286 - free_pmds(pmds);
27287 + free_pxds(pxds);
27288 return -ENOMEM;
27289 }
27290
27291 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
27292 * preallocate which never got a corresponding vma will need to be
27293 * freed manually.
27294 */
27295 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
27296 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
27297 {
27298 int i;
27299
27300 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
27301 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
27302 pgd_t pgd = pgdp[i];
27303
27304 if (pgd_val(pgd) != 0) {
27305 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
27306 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
27307
27308 - pgdp[i] = native_make_pgd(0);
27309 + set_pgd(pgdp + i, native_make_pgd(0));
27310
27311 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
27312 - pmd_free(mm, pmd);
27313 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
27314 + pxd_free(mm, pxd);
27315 }
27316 }
27317 }
27318
27319 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
27320 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
27321 {
27322 - pud_t *pud;
27323 + pyd_t *pyd;
27324 unsigned long addr;
27325 int i;
27326
27327 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
27328 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
27329 return;
27330
27331 - pud = pud_offset(pgd, 0);
27332 +#ifdef CONFIG_X86_64
27333 + pyd = pyd_offset(mm, 0L);
27334 +#else
27335 + pyd = pyd_offset(pgd, 0L);
27336 +#endif
27337
27338 - for (addr = i = 0; i < PREALLOCATED_PMDS;
27339 - i++, pud++, addr += PUD_SIZE) {
27340 - pmd_t *pmd = pmds[i];
27341 + for (addr = i = 0; i < PREALLOCATED_PXDS;
27342 + i++, pyd++, addr += PYD_SIZE) {
27343 + pxd_t *pxd = pxds[i];
27344
27345 if (i >= KERNEL_PGD_BOUNDARY)
27346 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27347 - sizeof(pmd_t) * PTRS_PER_PMD);
27348 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27349 + sizeof(pxd_t) * PTRS_PER_PMD);
27350
27351 - pud_populate(mm, pud, pmd);
27352 + pyd_populate(mm, pyd, pxd);
27353 }
27354 }
27355
27356 pgd_t *pgd_alloc(struct mm_struct *mm)
27357 {
27358 pgd_t *pgd;
27359 - pmd_t *pmds[PREALLOCATED_PMDS];
27360 + pxd_t *pxds[PREALLOCATED_PXDS];
27361
27362 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
27363
27364 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27365
27366 mm->pgd = pgd;
27367
27368 - if (preallocate_pmds(pmds) != 0)
27369 + if (preallocate_pxds(pxds) != 0)
27370 goto out_free_pgd;
27371
27372 if (paravirt_pgd_alloc(mm) != 0)
27373 - goto out_free_pmds;
27374 + goto out_free_pxds;
27375
27376 /*
27377 * Make sure that pre-populating the pmds is atomic with
27378 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27379 spin_lock(&pgd_lock);
27380
27381 pgd_ctor(mm, pgd);
27382 - pgd_prepopulate_pmd(mm, pgd, pmds);
27383 + pgd_prepopulate_pxd(mm, pgd, pxds);
27384
27385 spin_unlock(&pgd_lock);
27386
27387 return pgd;
27388
27389 -out_free_pmds:
27390 - free_pmds(pmds);
27391 +out_free_pxds:
27392 + free_pxds(pxds);
27393 out_free_pgd:
27394 free_page((unsigned long)pgd);
27395 out:
27396 @@ -295,7 +356,7 @@ out:
27397
27398 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
27399 {
27400 - pgd_mop_up_pmds(mm, pgd);
27401 + pgd_mop_up_pxds(mm, pgd);
27402 pgd_dtor(pgd);
27403 paravirt_pgd_free(mm, pgd);
27404 free_page((unsigned long)pgd);
27405 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
27406 index a69bcb8..19068ab 100644
27407 --- a/arch/x86/mm/pgtable_32.c
27408 +++ b/arch/x86/mm/pgtable_32.c
27409 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
27410 return;
27411 }
27412 pte = pte_offset_kernel(pmd, vaddr);
27413 +
27414 + pax_open_kernel();
27415 if (pte_val(pteval))
27416 set_pte_at(&init_mm, vaddr, pte, pteval);
27417 else
27418 pte_clear(&init_mm, vaddr, pte);
27419 + pax_close_kernel();
27420
27421 /*
27422 * It's enough to flush this one mapping.
27423 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
27424 index 410531d..0f16030 100644
27425 --- a/arch/x86/mm/setup_nx.c
27426 +++ b/arch/x86/mm/setup_nx.c
27427 @@ -5,8 +5,10 @@
27428 #include <asm/pgtable.h>
27429 #include <asm/proto.h>
27430
27431 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27432 static int disable_nx __cpuinitdata;
27433
27434 +#ifndef CONFIG_PAX_PAGEEXEC
27435 /*
27436 * noexec = on|off
27437 *
27438 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
27439 return 0;
27440 }
27441 early_param("noexec", noexec_setup);
27442 +#endif
27443 +
27444 +#endif
27445
27446 void __cpuinit x86_configure_nx(void)
27447 {
27448 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27449 if (cpu_has_nx && !disable_nx)
27450 __supported_pte_mask |= _PAGE_NX;
27451 else
27452 +#endif
27453 __supported_pte_mask &= ~_PAGE_NX;
27454 }
27455
27456 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
27457 index 60f926c..a710970 100644
27458 --- a/arch/x86/mm/tlb.c
27459 +++ b/arch/x86/mm/tlb.c
27460 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
27461 BUG();
27462 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
27463 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
27464 +
27465 +#ifndef CONFIG_PAX_PER_CPU_PGD
27466 load_cr3(swapper_pg_dir);
27467 +#endif
27468 +
27469 }
27470 }
27471 EXPORT_SYMBOL_GPL(leave_mm);
27472 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
27473 index 877b9a1..a8ecf42 100644
27474 --- a/arch/x86/net/bpf_jit.S
27475 +++ b/arch/x86/net/bpf_jit.S
27476 @@ -9,6 +9,7 @@
27477 */
27478 #include <linux/linkage.h>
27479 #include <asm/dwarf2.h>
27480 +#include <asm/alternative-asm.h>
27481
27482 /*
27483 * Calling convention :
27484 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
27485 jle bpf_slow_path_word
27486 mov (SKBDATA,%rsi),%eax
27487 bswap %eax /* ntohl() */
27488 + pax_force_retaddr
27489 ret
27490
27491 sk_load_half:
27492 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
27493 jle bpf_slow_path_half
27494 movzwl (SKBDATA,%rsi),%eax
27495 rol $8,%ax # ntohs()
27496 + pax_force_retaddr
27497 ret
27498
27499 sk_load_byte:
27500 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
27501 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
27502 jle bpf_slow_path_byte
27503 movzbl (SKBDATA,%rsi),%eax
27504 + pax_force_retaddr
27505 ret
27506
27507 /**
27508 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
27509 movzbl (SKBDATA,%rsi),%ebx
27510 and $15,%bl
27511 shl $2,%bl
27512 + pax_force_retaddr
27513 ret
27514
27515 /* rsi contains offset and can be scratched */
27516 @@ -109,6 +114,7 @@ bpf_slow_path_word:
27517 js bpf_error
27518 mov -12(%rbp),%eax
27519 bswap %eax
27520 + pax_force_retaddr
27521 ret
27522
27523 bpf_slow_path_half:
27524 @@ -117,12 +123,14 @@ bpf_slow_path_half:
27525 mov -12(%rbp),%ax
27526 rol $8,%ax
27527 movzwl %ax,%eax
27528 + pax_force_retaddr
27529 ret
27530
27531 bpf_slow_path_byte:
27532 bpf_slow_path_common(1)
27533 js bpf_error
27534 movzbl -12(%rbp),%eax
27535 + pax_force_retaddr
27536 ret
27537
27538 bpf_slow_path_byte_msh:
27539 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
27540 and $15,%al
27541 shl $2,%al
27542 xchg %eax,%ebx
27543 + pax_force_retaddr
27544 ret
27545
27546 #define sk_negative_common(SIZE) \
27547 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
27548 sk_negative_common(4)
27549 mov (%rax), %eax
27550 bswap %eax
27551 + pax_force_retaddr
27552 ret
27553
27554 bpf_slow_path_half_neg:
27555 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
27556 mov (%rax),%ax
27557 rol $8,%ax
27558 movzwl %ax,%eax
27559 + pax_force_retaddr
27560 ret
27561
27562 bpf_slow_path_byte_neg:
27563 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
27564 .globl sk_load_byte_negative_offset
27565 sk_negative_common(1)
27566 movzbl (%rax), %eax
27567 + pax_force_retaddr
27568 ret
27569
27570 bpf_slow_path_byte_msh_neg:
27571 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
27572 and $15,%al
27573 shl $2,%al
27574 xchg %eax,%ebx
27575 + pax_force_retaddr
27576 ret
27577
27578 bpf_error:
27579 @@ -197,4 +210,5 @@ bpf_error:
27580 xor %eax,%eax
27581 mov -8(%rbp),%rbx
27582 leaveq
27583 + pax_force_retaddr
27584 ret
27585 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
27586 index 520d2bd..b895ef4 100644
27587 --- a/arch/x86/net/bpf_jit_comp.c
27588 +++ b/arch/x86/net/bpf_jit_comp.c
27589 @@ -11,6 +11,7 @@
27590 #include <asm/cacheflush.h>
27591 #include <linux/netdevice.h>
27592 #include <linux/filter.h>
27593 +#include <linux/random.h>
27594
27595 /*
27596 * Conventions :
27597 @@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
27598 return ptr + len;
27599 }
27600
27601 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27602 +#define MAX_INSTR_CODE_SIZE 96
27603 +#else
27604 +#define MAX_INSTR_CODE_SIZE 64
27605 +#endif
27606 +
27607 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
27608
27609 #define EMIT1(b1) EMIT(b1, 1)
27610 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
27611 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
27612 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
27613 +
27614 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27615 +/* original constant will appear in ecx */
27616 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
27617 +do { \
27618 + /* mov ecx, randkey */ \
27619 + EMIT1(0xb9); \
27620 + EMIT(_key, 4); \
27621 + /* xor ecx, randkey ^ off */ \
27622 + EMIT2(0x81, 0xf1); \
27623 + EMIT((_key) ^ (_off), 4); \
27624 +} while (0)
27625 +
27626 +#define EMIT1_off32(b1, _off) \
27627 +do { \
27628 + switch (b1) { \
27629 + case 0x05: /* add eax, imm32 */ \
27630 + case 0x2d: /* sub eax, imm32 */ \
27631 + case 0x25: /* and eax, imm32 */ \
27632 + case 0x0d: /* or eax, imm32 */ \
27633 + case 0xb8: /* mov eax, imm32 */ \
27634 + case 0x3d: /* cmp eax, imm32 */ \
27635 + case 0xa9: /* test eax, imm32 */ \
27636 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27637 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
27638 + break; \
27639 + case 0xbb: /* mov ebx, imm32 */ \
27640 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27641 + /* mov ebx, ecx */ \
27642 + EMIT2(0x89, 0xcb); \
27643 + break; \
27644 + case 0xbe: /* mov esi, imm32 */ \
27645 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27646 + /* mov esi, ecx */ \
27647 + EMIT2(0x89, 0xce); \
27648 + break; \
27649 + case 0xe9: /* jmp rel imm32 */ \
27650 + EMIT1(b1); \
27651 + EMIT(_off, 4); \
27652 + /* prevent fall-through, we're not called if off = 0 */ \
27653 + EMIT(0xcccccccc, 4); \
27654 + EMIT(0xcccccccc, 4); \
27655 + break; \
27656 + default: \
27657 + EMIT1(b1); \
27658 + EMIT(_off, 4); \
27659 + } \
27660 +} while (0)
27661 +
27662 +#define EMIT2_off32(b1, b2, _off) \
27663 +do { \
27664 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
27665 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
27666 + EMIT(randkey, 4); \
27667 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
27668 + EMIT((_off) - randkey, 4); \
27669 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
27670 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27671 + /* imul eax, ecx */ \
27672 + EMIT3(0x0f, 0xaf, 0xc1); \
27673 + } else { \
27674 + EMIT2(b1, b2); \
27675 + EMIT(_off, 4); \
27676 + } \
27677 +} while (0)
27678 +#else
27679 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
27680 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
27681 +#endif
27682
27683 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
27684 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
27685 @@ -89,6 +164,24 @@ do { \
27686 #define X86_JBE 0x76
27687 #define X86_JA 0x77
27688
27689 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27690 +#define APPEND_FLOW_VERIFY() \
27691 +do { \
27692 + /* mov ecx, randkey */ \
27693 + EMIT1(0xb9); \
27694 + EMIT(randkey, 4); \
27695 + /* cmp ecx, randkey */ \
27696 + EMIT2(0x81, 0xf9); \
27697 + EMIT(randkey, 4); \
27698 + /* jz after 8 int 3s */ \
27699 + EMIT2(0x74, 0x08); \
27700 + EMIT(0xcccccccc, 4); \
27701 + EMIT(0xcccccccc, 4); \
27702 +} while (0)
27703 +#else
27704 +#define APPEND_FLOW_VERIFY() do { } while (0)
27705 +#endif
27706 +
27707 #define EMIT_COND_JMP(op, offset) \
27708 do { \
27709 if (is_near(offset)) \
27710 @@ -96,6 +189,7 @@ do { \
27711 else { \
27712 EMIT2(0x0f, op + 0x10); \
27713 EMIT(offset, 4); /* jxx .+off32 */ \
27714 + APPEND_FLOW_VERIFY(); \
27715 } \
27716 } while (0)
27717
27718 @@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
27719 set_fs(old_fs);
27720 }
27721
27722 +struct bpf_jit_work {
27723 + struct work_struct work;
27724 + void *image;
27725 +};
27726 +
27727 #define CHOOSE_LOAD_FUNC(K, func) \
27728 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
27729
27730 void bpf_jit_compile(struct sk_filter *fp)
27731 {
27732 - u8 temp[64];
27733 + u8 temp[MAX_INSTR_CODE_SIZE];
27734 u8 *prog;
27735 unsigned int proglen, oldproglen = 0;
27736 int ilen, i;
27737 @@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
27738 unsigned int *addrs;
27739 const struct sock_filter *filter = fp->insns;
27740 int flen = fp->len;
27741 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27742 + unsigned int randkey;
27743 +#endif
27744
27745 if (!bpf_jit_enable)
27746 return;
27747 @@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
27748 if (addrs == NULL)
27749 return;
27750
27751 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
27752 + if (!fp->work)
27753 + goto out;
27754 +
27755 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27756 + randkey = get_random_int();
27757 +#endif
27758 +
27759 /* Before first pass, make a rough estimation of addrs[]
27760 - * each bpf instruction is translated to less than 64 bytes
27761 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
27762 */
27763 for (proglen = 0, i = 0; i < flen; i++) {
27764 - proglen += 64;
27765 + proglen += MAX_INSTR_CODE_SIZE;
27766 addrs[i] = proglen;
27767 }
27768 cleanup_addr = proglen; /* epilogue address */
27769 @@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
27770 case BPF_S_ALU_MUL_K: /* A *= K */
27771 if (is_imm8(K))
27772 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
27773 - else {
27774 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
27775 - EMIT(K, 4);
27776 - }
27777 + else
27778 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
27779 break;
27780 case BPF_S_ALU_DIV_X: /* A /= X; */
27781 seen |= SEEN_XREG;
27782 @@ -301,13 +409,23 @@ void bpf_jit_compile(struct sk_filter *fp)
27783 break;
27784 case BPF_S_ALU_MOD_K: /* A %= K; */
27785 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
27786 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27787 + DILUTE_CONST_SEQUENCE(K, randkey);
27788 +#else
27789 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
27790 +#endif
27791 EMIT2(0xf7, 0xf1); /* div %ecx */
27792 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
27793 break;
27794 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
27795 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27796 + DILUTE_CONST_SEQUENCE(K, randkey);
27797 + // imul rax, rcx
27798 + EMIT4(0x48, 0x0f, 0xaf, 0xc1);
27799 +#else
27800 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
27801 EMIT(K, 4);
27802 +#endif
27803 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
27804 break;
27805 case BPF_S_ALU_AND_X:
27806 @@ -543,8 +661,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
27807 if (is_imm8(K)) {
27808 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
27809 } else {
27810 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
27811 - EMIT(K, 4);
27812 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
27813 }
27814 } else {
27815 EMIT2(0x89,0xde); /* mov %ebx,%esi */
27816 @@ -627,17 +744,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27817 break;
27818 default:
27819 /* hmm, too complex filter, give up with jit compiler */
27820 - goto out;
27821 + goto error;
27822 }
27823 ilen = prog - temp;
27824 if (image) {
27825 if (unlikely(proglen + ilen > oldproglen)) {
27826 pr_err("bpb_jit_compile fatal error\n");
27827 - kfree(addrs);
27828 - module_free(NULL, image);
27829 - return;
27830 + module_free_exec(NULL, image);
27831 + goto error;
27832 }
27833 + pax_open_kernel();
27834 memcpy(image + proglen, temp, ilen);
27835 + pax_close_kernel();
27836 }
27837 proglen += ilen;
27838 addrs[i] = proglen;
27839 @@ -658,11 +776,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27840 break;
27841 }
27842 if (proglen == oldproglen) {
27843 - image = module_alloc(max_t(unsigned int,
27844 - proglen,
27845 - sizeof(struct work_struct)));
27846 + image = module_alloc_exec(proglen);
27847 if (!image)
27848 - goto out;
27849 + goto error;
27850 }
27851 oldproglen = proglen;
27852 }
27853 @@ -678,7 +794,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27854 bpf_flush_icache(image, image + proglen);
27855
27856 fp->bpf_func = (void *)image;
27857 - }
27858 + } else
27859 +error:
27860 + kfree(fp->work);
27861 +
27862 out:
27863 kfree(addrs);
27864 return;
27865 @@ -686,18 +805,20 @@ out:
27866
27867 static void jit_free_defer(struct work_struct *arg)
27868 {
27869 - module_free(NULL, arg);
27870 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
27871 + kfree(arg);
27872 }
27873
27874 /* run from softirq, we must use a work_struct to call
27875 - * module_free() from process context
27876 + * module_free_exec() from process context
27877 */
27878 void bpf_jit_free(struct sk_filter *fp)
27879 {
27880 if (fp->bpf_func != sk_run_filter) {
27881 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
27882 + struct work_struct *work = &fp->work->work;
27883
27884 INIT_WORK(work, jit_free_defer);
27885 + fp->work->image = fp->bpf_func;
27886 schedule_work(work);
27887 }
27888 }
27889 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
27890 index d6aa6e8..266395a 100644
27891 --- a/arch/x86/oprofile/backtrace.c
27892 +++ b/arch/x86/oprofile/backtrace.c
27893 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
27894 struct stack_frame_ia32 *fp;
27895 unsigned long bytes;
27896
27897 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27898 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27899 if (bytes != sizeof(bufhead))
27900 return NULL;
27901
27902 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
27903 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
27904
27905 oprofile_add_trace(bufhead[0].return_address);
27906
27907 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
27908 struct stack_frame bufhead[2];
27909 unsigned long bytes;
27910
27911 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27912 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27913 if (bytes != sizeof(bufhead))
27914 return NULL;
27915
27916 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
27917 {
27918 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
27919
27920 - if (!user_mode_vm(regs)) {
27921 + if (!user_mode(regs)) {
27922 unsigned long stack = kernel_stack_pointer(regs);
27923 if (depth)
27924 dump_trace(NULL, regs, (unsigned long *)stack, 0,
27925 diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
27926 index 192397c..5ba6f9e 100644
27927 --- a/arch/x86/pci/acpi.c
27928 +++ b/arch/x86/pci/acpi.c
27929 @@ -568,7 +568,7 @@ int __init pci_acpi_init(void)
27930 acpi_irq_penalty_init();
27931 pcibios_enable_irq = acpi_pci_irq_enable;
27932 pcibios_disable_irq = acpi_pci_irq_disable;
27933 - x86_init.pci.init_irq = x86_init_noop;
27934 + *(void **)&x86_init.pci.init_irq = x86_init_noop;
27935
27936 if (pci_routeirq) {
27937 /*
27938 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
27939 index e14a2ff..3fd6b58 100644
27940 --- a/arch/x86/pci/mrst.c
27941 +++ b/arch/x86/pci/mrst.c
27942 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
27943 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
27944 pci_mmcfg_late_init();
27945 pcibios_enable_irq = mrst_pci_irq_enable;
27946 - pci_root_ops = pci_mrst_ops;
27947 + pax_open_kernel();
27948 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
27949 + pax_close_kernel();
27950 pci_soc_mode = 1;
27951 /* Continue with standard init */
27952 return 1;
27953 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
27954 index da8fe05..7ee6704 100644
27955 --- a/arch/x86/pci/pcbios.c
27956 +++ b/arch/x86/pci/pcbios.c
27957 @@ -79,50 +79,93 @@ union bios32 {
27958 static struct {
27959 unsigned long address;
27960 unsigned short segment;
27961 -} bios32_indirect = { 0, __KERNEL_CS };
27962 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
27963
27964 /*
27965 * Returns the entry point for the given service, NULL on error
27966 */
27967
27968 -static unsigned long bios32_service(unsigned long service)
27969 +static unsigned long __devinit bios32_service(unsigned long service)
27970 {
27971 unsigned char return_code; /* %al */
27972 unsigned long address; /* %ebx */
27973 unsigned long length; /* %ecx */
27974 unsigned long entry; /* %edx */
27975 unsigned long flags;
27976 + struct desc_struct d, *gdt;
27977
27978 local_irq_save(flags);
27979 - __asm__("lcall *(%%edi); cld"
27980 +
27981 + gdt = get_cpu_gdt_table(smp_processor_id());
27982 +
27983 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
27984 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
27985 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
27986 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
27987 +
27988 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
27989 : "=a" (return_code),
27990 "=b" (address),
27991 "=c" (length),
27992 "=d" (entry)
27993 : "0" (service),
27994 "1" (0),
27995 - "D" (&bios32_indirect));
27996 + "D" (&bios32_indirect),
27997 + "r"(__PCIBIOS_DS)
27998 + : "memory");
27999 +
28000 + pax_open_kernel();
28001 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
28002 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
28003 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
28004 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
28005 + pax_close_kernel();
28006 +
28007 local_irq_restore(flags);
28008
28009 switch (return_code) {
28010 - case 0:
28011 - return address + entry;
28012 - case 0x80: /* Not present */
28013 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
28014 - return 0;
28015 - default: /* Shouldn't happen */
28016 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
28017 - service, return_code);
28018 + case 0: {
28019 + int cpu;
28020 + unsigned char flags;
28021 +
28022 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
28023 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
28024 + printk(KERN_WARNING "bios32_service: not valid\n");
28025 return 0;
28026 + }
28027 + address = address + PAGE_OFFSET;
28028 + length += 16UL; /* some BIOSs underreport this... */
28029 + flags = 4;
28030 + if (length >= 64*1024*1024) {
28031 + length >>= PAGE_SHIFT;
28032 + flags |= 8;
28033 + }
28034 +
28035 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28036 + gdt = get_cpu_gdt_table(cpu);
28037 + pack_descriptor(&d, address, length, 0x9b, flags);
28038 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
28039 + pack_descriptor(&d, address, length, 0x93, flags);
28040 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
28041 + }
28042 + return entry;
28043 + }
28044 + case 0x80: /* Not present */
28045 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
28046 + return 0;
28047 + default: /* Shouldn't happen */
28048 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
28049 + service, return_code);
28050 + return 0;
28051 }
28052 }
28053
28054 static struct {
28055 unsigned long address;
28056 unsigned short segment;
28057 -} pci_indirect = { 0, __KERNEL_CS };
28058 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
28059
28060 -static int pci_bios_present;
28061 +static int pci_bios_present __read_only;
28062
28063 static int __devinit check_pcibios(void)
28064 {
28065 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
28066 unsigned long flags, pcibios_entry;
28067
28068 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
28069 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
28070 + pci_indirect.address = pcibios_entry;
28071
28072 local_irq_save(flags);
28073 - __asm__(
28074 - "lcall *(%%edi); cld\n\t"
28075 + __asm__("movw %w6, %%ds\n\t"
28076 + "lcall *%%ss:(%%edi); cld\n\t"
28077 + "push %%ss\n\t"
28078 + "pop %%ds\n\t"
28079 "jc 1f\n\t"
28080 "xor %%ah, %%ah\n"
28081 "1:"
28082 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
28083 "=b" (ebx),
28084 "=c" (ecx)
28085 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
28086 - "D" (&pci_indirect)
28087 + "D" (&pci_indirect),
28088 + "r" (__PCIBIOS_DS)
28089 : "memory");
28090 local_irq_restore(flags);
28091
28092 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28093
28094 switch (len) {
28095 case 1:
28096 - __asm__("lcall *(%%esi); cld\n\t"
28097 + __asm__("movw %w6, %%ds\n\t"
28098 + "lcall *%%ss:(%%esi); cld\n\t"
28099 + "push %%ss\n\t"
28100 + "pop %%ds\n\t"
28101 "jc 1f\n\t"
28102 "xor %%ah, %%ah\n"
28103 "1:"
28104 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28105 : "1" (PCIBIOS_READ_CONFIG_BYTE),
28106 "b" (bx),
28107 "D" ((long)reg),
28108 - "S" (&pci_indirect));
28109 + "S" (&pci_indirect),
28110 + "r" (__PCIBIOS_DS));
28111 /*
28112 * Zero-extend the result beyond 8 bits, do not trust the
28113 * BIOS having done it:
28114 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28115 *value &= 0xff;
28116 break;
28117 case 2:
28118 - __asm__("lcall *(%%esi); cld\n\t"
28119 + __asm__("movw %w6, %%ds\n\t"
28120 + "lcall *%%ss:(%%esi); cld\n\t"
28121 + "push %%ss\n\t"
28122 + "pop %%ds\n\t"
28123 "jc 1f\n\t"
28124 "xor %%ah, %%ah\n"
28125 "1:"
28126 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28127 : "1" (PCIBIOS_READ_CONFIG_WORD),
28128 "b" (bx),
28129 "D" ((long)reg),
28130 - "S" (&pci_indirect));
28131 + "S" (&pci_indirect),
28132 + "r" (__PCIBIOS_DS));
28133 /*
28134 * Zero-extend the result beyond 16 bits, do not trust the
28135 * BIOS having done it:
28136 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28137 *value &= 0xffff;
28138 break;
28139 case 4:
28140 - __asm__("lcall *(%%esi); cld\n\t"
28141 + __asm__("movw %w6, %%ds\n\t"
28142 + "lcall *%%ss:(%%esi); cld\n\t"
28143 + "push %%ss\n\t"
28144 + "pop %%ds\n\t"
28145 "jc 1f\n\t"
28146 "xor %%ah, %%ah\n"
28147 "1:"
28148 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28149 : "1" (PCIBIOS_READ_CONFIG_DWORD),
28150 "b" (bx),
28151 "D" ((long)reg),
28152 - "S" (&pci_indirect));
28153 + "S" (&pci_indirect),
28154 + "r" (__PCIBIOS_DS));
28155 break;
28156 }
28157
28158 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28159
28160 switch (len) {
28161 case 1:
28162 - __asm__("lcall *(%%esi); cld\n\t"
28163 + __asm__("movw %w6, %%ds\n\t"
28164 + "lcall *%%ss:(%%esi); cld\n\t"
28165 + "push %%ss\n\t"
28166 + "pop %%ds\n\t"
28167 "jc 1f\n\t"
28168 "xor %%ah, %%ah\n"
28169 "1:"
28170 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28171 "c" (value),
28172 "b" (bx),
28173 "D" ((long)reg),
28174 - "S" (&pci_indirect));
28175 + "S" (&pci_indirect),
28176 + "r" (__PCIBIOS_DS));
28177 break;
28178 case 2:
28179 - __asm__("lcall *(%%esi); cld\n\t"
28180 + __asm__("movw %w6, %%ds\n\t"
28181 + "lcall *%%ss:(%%esi); cld\n\t"
28182 + "push %%ss\n\t"
28183 + "pop %%ds\n\t"
28184 "jc 1f\n\t"
28185 "xor %%ah, %%ah\n"
28186 "1:"
28187 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28188 "c" (value),
28189 "b" (bx),
28190 "D" ((long)reg),
28191 - "S" (&pci_indirect));
28192 + "S" (&pci_indirect),
28193 + "r" (__PCIBIOS_DS));
28194 break;
28195 case 4:
28196 - __asm__("lcall *(%%esi); cld\n\t"
28197 + __asm__("movw %w6, %%ds\n\t"
28198 + "lcall *%%ss:(%%esi); cld\n\t"
28199 + "push %%ss\n\t"
28200 + "pop %%ds\n\t"
28201 "jc 1f\n\t"
28202 "xor %%ah, %%ah\n"
28203 "1:"
28204 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28205 "c" (value),
28206 "b" (bx),
28207 "D" ((long)reg),
28208 - "S" (&pci_indirect));
28209 + "S" (&pci_indirect),
28210 + "r" (__PCIBIOS_DS));
28211 break;
28212 }
28213
28214 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
28215
28216 DBG("PCI: Fetching IRQ routing table... ");
28217 __asm__("push %%es\n\t"
28218 + "movw %w8, %%ds\n\t"
28219 "push %%ds\n\t"
28220 "pop %%es\n\t"
28221 - "lcall *(%%esi); cld\n\t"
28222 + "lcall *%%ss:(%%esi); cld\n\t"
28223 "pop %%es\n\t"
28224 + "push %%ss\n\t"
28225 + "pop %%ds\n"
28226 "jc 1f\n\t"
28227 "xor %%ah, %%ah\n"
28228 "1:"
28229 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
28230 "1" (0),
28231 "D" ((long) &opt),
28232 "S" (&pci_indirect),
28233 - "m" (opt)
28234 + "m" (opt),
28235 + "r" (__PCIBIOS_DS)
28236 : "memory");
28237 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
28238 if (ret & 0xff00)
28239 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
28240 {
28241 int ret;
28242
28243 - __asm__("lcall *(%%esi); cld\n\t"
28244 + __asm__("movw %w5, %%ds\n\t"
28245 + "lcall *%%ss:(%%esi); cld\n\t"
28246 + "push %%ss\n\t"
28247 + "pop %%ds\n"
28248 "jc 1f\n\t"
28249 "xor %%ah, %%ah\n"
28250 "1:"
28251 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
28252 : "0" (PCIBIOS_SET_PCI_HW_INT),
28253 "b" ((dev->bus->number << 8) | dev->devfn),
28254 "c" ((irq << 8) | (pin + 10)),
28255 - "S" (&pci_indirect));
28256 + "S" (&pci_indirect),
28257 + "r" (__PCIBIOS_DS));
28258 return !(ret & 0xff00);
28259 }
28260 EXPORT_SYMBOL(pcibios_set_irq_routing);
28261 diff --git a/arch/x86/pci/xen.c b/arch/x86/pci/xen.c
28262 index 56ab749..3cb792a 100644
28263 --- a/arch/x86/pci/xen.c
28264 +++ b/arch/x86/pci/xen.c
28265 @@ -395,9 +395,9 @@ int __init pci_xen_init(void)
28266 #endif
28267
28268 #ifdef CONFIG_PCI_MSI
28269 - x86_msi.setup_msi_irqs = xen_setup_msi_irqs;
28270 - x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28271 - x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
28272 + *(void **)&x86_msi.setup_msi_irqs = xen_setup_msi_irqs;
28273 + *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28274 + *(void **)&x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
28275 #endif
28276 return 0;
28277 }
28278 @@ -416,8 +416,8 @@ int __init pci_xen_hvm_init(void)
28279 #endif
28280
28281 #ifdef CONFIG_PCI_MSI
28282 - x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs;
28283 - x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28284 + *(void **)&x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs;
28285 + *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28286 #endif
28287 return 0;
28288 }
28289 @@ -474,9 +474,9 @@ int __init pci_xen_initial_domain(void)
28290 int irq;
28291
28292 #ifdef CONFIG_PCI_MSI
28293 - x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs;
28294 - x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28295 - x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs;
28296 + *(void **)&x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs;
28297 + *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28298 + *(void **)&x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs;
28299 #endif
28300 xen_setup_acpi_sci();
28301 __acpi_register_gsi = acpi_register_gsi_xen;
28302 diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
28303 index 77cf009..7fe44c8 100644
28304 --- a/arch/x86/platform/efi/efi.c
28305 +++ b/arch/x86/platform/efi/efi.c
28306 @@ -746,8 +746,8 @@ void __init efi_init(void)
28307
28308 #ifdef CONFIG_X86_32
28309 if (efi_is_native()) {
28310 - x86_platform.get_wallclock = efi_get_time;
28311 - x86_platform.set_wallclock = efi_set_rtc_mmss;
28312 + *(void **)&x86_platform.get_wallclock = efi_get_time;
28313 + *(void **)&x86_platform.set_wallclock = efi_set_rtc_mmss;
28314 }
28315 #endif
28316
28317 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
28318 index 40e4469..1ab536e 100644
28319 --- a/arch/x86/platform/efi/efi_32.c
28320 +++ b/arch/x86/platform/efi/efi_32.c
28321 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
28322 {
28323 struct desc_ptr gdt_descr;
28324
28325 +#ifdef CONFIG_PAX_KERNEXEC
28326 + struct desc_struct d;
28327 +#endif
28328 +
28329 local_irq_save(efi_rt_eflags);
28330
28331 load_cr3(initial_page_table);
28332 __flush_tlb_all();
28333
28334 +#ifdef CONFIG_PAX_KERNEXEC
28335 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
28336 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28337 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
28338 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28339 +#endif
28340 +
28341 gdt_descr.address = __pa(get_cpu_gdt_table(0));
28342 gdt_descr.size = GDT_SIZE - 1;
28343 load_gdt(&gdt_descr);
28344 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
28345 {
28346 struct desc_ptr gdt_descr;
28347
28348 +#ifdef CONFIG_PAX_KERNEXEC
28349 + struct desc_struct d;
28350 +
28351 + memset(&d, 0, sizeof d);
28352 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28353 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28354 +#endif
28355 +
28356 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
28357 gdt_descr.size = GDT_SIZE - 1;
28358 load_gdt(&gdt_descr);
28359 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
28360 index fbe66e6..eae5e38 100644
28361 --- a/arch/x86/platform/efi/efi_stub_32.S
28362 +++ b/arch/x86/platform/efi/efi_stub_32.S
28363 @@ -6,7 +6,9 @@
28364 */
28365
28366 #include <linux/linkage.h>
28367 +#include <linux/init.h>
28368 #include <asm/page_types.h>
28369 +#include <asm/segment.h>
28370
28371 /*
28372 * efi_call_phys(void *, ...) is a function with variable parameters.
28373 @@ -20,7 +22,7 @@
28374 * service functions will comply with gcc calling convention, too.
28375 */
28376
28377 -.text
28378 +__INIT
28379 ENTRY(efi_call_phys)
28380 /*
28381 * 0. The function can only be called in Linux kernel. So CS has been
28382 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
28383 * The mapping of lower virtual memory has been created in prelog and
28384 * epilog.
28385 */
28386 - movl $1f, %edx
28387 - subl $__PAGE_OFFSET, %edx
28388 - jmp *%edx
28389 +#ifdef CONFIG_PAX_KERNEXEC
28390 + movl $(__KERNEXEC_EFI_DS), %edx
28391 + mov %edx, %ds
28392 + mov %edx, %es
28393 + mov %edx, %ss
28394 + addl $2f,(1f)
28395 + ljmp *(1f)
28396 +
28397 +__INITDATA
28398 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
28399 +.previous
28400 +
28401 +2:
28402 + subl $2b,(1b)
28403 +#else
28404 + jmp 1f-__PAGE_OFFSET
28405 1:
28406 +#endif
28407
28408 /*
28409 * 2. Now on the top of stack is the return
28410 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
28411 * parameter 2, ..., param n. To make things easy, we save the return
28412 * address of efi_call_phys in a global variable.
28413 */
28414 - popl %edx
28415 - movl %edx, saved_return_addr
28416 - /* get the function pointer into ECX*/
28417 - popl %ecx
28418 - movl %ecx, efi_rt_function_ptr
28419 - movl $2f, %edx
28420 - subl $__PAGE_OFFSET, %edx
28421 - pushl %edx
28422 + popl (saved_return_addr)
28423 + popl (efi_rt_function_ptr)
28424
28425 /*
28426 * 3. Clear PG bit in %CR0.
28427 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
28428 /*
28429 * 5. Call the physical function.
28430 */
28431 - jmp *%ecx
28432 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
28433
28434 -2:
28435 /*
28436 * 6. After EFI runtime service returns, control will return to
28437 * following instruction. We'd better readjust stack pointer first.
28438 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
28439 movl %cr0, %edx
28440 orl $0x80000000, %edx
28441 movl %edx, %cr0
28442 - jmp 1f
28443 -1:
28444 +
28445 /*
28446 * 8. Now restore the virtual mode from flat mode by
28447 * adding EIP with PAGE_OFFSET.
28448 */
28449 - movl $1f, %edx
28450 - jmp *%edx
28451 +#ifdef CONFIG_PAX_KERNEXEC
28452 + movl $(__KERNEL_DS), %edx
28453 + mov %edx, %ds
28454 + mov %edx, %es
28455 + mov %edx, %ss
28456 + ljmp $(__KERNEL_CS),$1f
28457 +#else
28458 + jmp 1f+__PAGE_OFFSET
28459 +#endif
28460 1:
28461
28462 /*
28463 * 9. Balance the stack. And because EAX contain the return value,
28464 * we'd better not clobber it.
28465 */
28466 - leal efi_rt_function_ptr, %edx
28467 - movl (%edx), %ecx
28468 - pushl %ecx
28469 + pushl (efi_rt_function_ptr)
28470
28471 /*
28472 - * 10. Push the saved return address onto the stack and return.
28473 + * 10. Return to the saved return address.
28474 */
28475 - leal saved_return_addr, %edx
28476 - movl (%edx), %ecx
28477 - pushl %ecx
28478 - ret
28479 + jmpl *(saved_return_addr)
28480 ENDPROC(efi_call_phys)
28481 .previous
28482
28483 -.data
28484 +__INITDATA
28485 saved_return_addr:
28486 .long 0
28487 efi_rt_function_ptr:
28488 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
28489 index 4c07cca..2c8427d 100644
28490 --- a/arch/x86/platform/efi/efi_stub_64.S
28491 +++ b/arch/x86/platform/efi/efi_stub_64.S
28492 @@ -7,6 +7,7 @@
28493 */
28494
28495 #include <linux/linkage.h>
28496 +#include <asm/alternative-asm.h>
28497
28498 #define SAVE_XMM \
28499 mov %rsp, %rax; \
28500 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
28501 call *%rdi
28502 addq $32, %rsp
28503 RESTORE_XMM
28504 + pax_force_retaddr 0, 1
28505 ret
28506 ENDPROC(efi_call0)
28507
28508 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
28509 call *%rdi
28510 addq $32, %rsp
28511 RESTORE_XMM
28512 + pax_force_retaddr 0, 1
28513 ret
28514 ENDPROC(efi_call1)
28515
28516 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
28517 call *%rdi
28518 addq $32, %rsp
28519 RESTORE_XMM
28520 + pax_force_retaddr 0, 1
28521 ret
28522 ENDPROC(efi_call2)
28523
28524 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
28525 call *%rdi
28526 addq $32, %rsp
28527 RESTORE_XMM
28528 + pax_force_retaddr 0, 1
28529 ret
28530 ENDPROC(efi_call3)
28531
28532 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
28533 call *%rdi
28534 addq $32, %rsp
28535 RESTORE_XMM
28536 + pax_force_retaddr 0, 1
28537 ret
28538 ENDPROC(efi_call4)
28539
28540 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
28541 call *%rdi
28542 addq $48, %rsp
28543 RESTORE_XMM
28544 + pax_force_retaddr 0, 1
28545 ret
28546 ENDPROC(efi_call5)
28547
28548 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
28549 call *%rdi
28550 addq $48, %rsp
28551 RESTORE_XMM
28552 + pax_force_retaddr 0, 1
28553 ret
28554 ENDPROC(efi_call6)
28555 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
28556 index fd41a92..bc8091d 100644
28557 --- a/arch/x86/platform/mrst/mrst.c
28558 +++ b/arch/x86/platform/mrst/mrst.c
28559 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
28560 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
28561 int sfi_mrtc_num;
28562
28563 -static void mrst_power_off(void)
28564 +static __noreturn void mrst_power_off(void)
28565 {
28566 + BUG();
28567 }
28568
28569 -static void mrst_reboot(void)
28570 +static __noreturn void mrst_reboot(void)
28571 {
28572 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
28573 + BUG();
28574 }
28575
28576 /* parse all the mtimer info to a static mtimer array */
28577 @@ -233,14 +235,14 @@ static void __init mrst_time_init(void)
28578 case MRST_TIMER_APBT_ONLY:
28579 break;
28580 case MRST_TIMER_LAPIC_APBT:
28581 - x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28582 - x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28583 + *(void **)&x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28584 + *(void **)&x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28585 break;
28586 default:
28587 if (!boot_cpu_has(X86_FEATURE_ARAT))
28588 break;
28589 - x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28590 - x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28591 + *(void **)&x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28592 + *(void **)&x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28593 return;
28594 }
28595 /* we need at least one APB timer */
28596 @@ -282,35 +284,35 @@ static unsigned char mrst_get_nmi_reason(void)
28597 */
28598 void __init x86_mrst_early_setup(void)
28599 {
28600 - x86_init.resources.probe_roms = x86_init_noop;
28601 - x86_init.resources.reserve_resources = x86_init_noop;
28602 + *(void **)&x86_init.resources.probe_roms = x86_init_noop;
28603 + *(void **)&x86_init.resources.reserve_resources = x86_init_noop;
28604
28605 - x86_init.timers.timer_init = mrst_time_init;
28606 - x86_init.timers.setup_percpu_clockev = x86_init_noop;
28607 + *(void **)&x86_init.timers.timer_init = mrst_time_init;
28608 + *(void **)&x86_init.timers.setup_percpu_clockev = x86_init_noop;
28609
28610 - x86_init.irqs.pre_vector_init = x86_init_noop;
28611 + *(void **)&x86_init.irqs.pre_vector_init = x86_init_noop;
28612
28613 - x86_init.oem.arch_setup = mrst_arch_setup;
28614 + *(void **)&x86_init.oem.arch_setup = mrst_arch_setup;
28615
28616 - x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
28617 + *(void **)&x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
28618
28619 - x86_platform.calibrate_tsc = mrst_calibrate_tsc;
28620 - x86_platform.i8042_detect = mrst_i8042_detect;
28621 - x86_init.timers.wallclock_init = mrst_rtc_init;
28622 - x86_platform.get_nmi_reason = mrst_get_nmi_reason;
28623 + *(void **)&x86_platform.calibrate_tsc = mrst_calibrate_tsc;
28624 + *(void **)&x86_platform.i8042_detect = mrst_i8042_detect;
28625 + *(void **)&x86_init.timers.wallclock_init = mrst_rtc_init;
28626 + *(void **)&x86_platform.get_nmi_reason = mrst_get_nmi_reason;
28627
28628 - x86_init.pci.init = pci_mrst_init;
28629 - x86_init.pci.fixup_irqs = x86_init_noop;
28630 + *(void **)&x86_init.pci.init = pci_mrst_init;
28631 + *(void **)&x86_init.pci.fixup_irqs = x86_init_noop;
28632
28633 legacy_pic = &null_legacy_pic;
28634
28635 /* Moorestown specific power_off/restart method */
28636 pm_power_off = mrst_power_off;
28637 - machine_ops.emergency_restart = mrst_reboot;
28638 + *(void **)&machine_ops.emergency_restart = mrst_reboot;
28639
28640 /* Avoid searching for BIOS MP tables */
28641 - x86_init.mpparse.find_smp_config = x86_init_noop;
28642 - x86_init.mpparse.get_smp_config = x86_init_uint_noop;
28643 + *(void **)&x86_init.mpparse.find_smp_config = x86_init_noop;
28644 + *(void **)&x86_init.mpparse.get_smp_config = x86_init_uint_noop;
28645 set_bit(MP_BUS_ISA, mp_bus_not_pci);
28646 }
28647
28648 diff --git a/arch/x86/platform/mrst/vrtc.c b/arch/x86/platform/mrst/vrtc.c
28649 index 225bd0f..22e8086 100644
28650 --- a/arch/x86/platform/mrst/vrtc.c
28651 +++ b/arch/x86/platform/mrst/vrtc.c
28652 @@ -120,8 +120,8 @@ void __init mrst_rtc_init(void)
28653
28654 vrtc_virt_base = (void __iomem *)set_fixmap_offset_nocache(FIX_LNW_VRTC,
28655 vrtc_paddr);
28656 - x86_platform.get_wallclock = vrtc_get_time;
28657 - x86_platform.set_wallclock = vrtc_set_mmss;
28658 + *(void **)&x86_platform.get_wallclock = vrtc_get_time;
28659 + *(void **)&x86_platform.set_wallclock = vrtc_set_mmss;
28660 }
28661
28662 /*
28663 diff --git a/arch/x86/platform/olpc/olpc.c b/arch/x86/platform/olpc/olpc.c
28664 index 2737608..0d62cc2 100644
28665 --- a/arch/x86/platform/olpc/olpc.c
28666 +++ b/arch/x86/platform/olpc/olpc.c
28667 @@ -395,7 +395,7 @@ static int __init olpc_init(void)
28668 * XO-1 only. */
28669 if (olpc_platform_info.boardrev < olpc_board_pre(0xd0) &&
28670 !cs5535_has_vsa2())
28671 - x86_init.pci.arch_init = pci_olpc_init;
28672 + *(void **)&x86_init.pci.arch_init = pci_olpc_init;
28673 #endif
28674
28675 if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) { /* XO-1 */
28676 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
28677 index d6ee929..3637cb5 100644
28678 --- a/arch/x86/platform/olpc/olpc_dt.c
28679 +++ b/arch/x86/platform/olpc/olpc_dt.c
28680 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
28681 return res;
28682 }
28683
28684 -static struct of_pdt_ops prom_olpc_ops __initdata = {
28685 +static struct of_pdt_ops prom_olpc_ops __initconst = {
28686 .nextprop = olpc_dt_nextprop,
28687 .getproplen = olpc_dt_getproplen,
28688 .getproperty = olpc_dt_getproperty,
28689 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
28690 index 218cdb1..c1178eb 100644
28691 --- a/arch/x86/power/cpu.c
28692 +++ b/arch/x86/power/cpu.c
28693 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
28694 static void fix_processor_context(void)
28695 {
28696 int cpu = smp_processor_id();
28697 - struct tss_struct *t = &per_cpu(init_tss, cpu);
28698 + struct tss_struct *t = init_tss + cpu;
28699
28700 set_tss_desc(cpu, t); /*
28701 * This just modifies memory; should not be
28702 @@ -142,8 +142,6 @@ static void fix_processor_context(void)
28703 */
28704
28705 #ifdef CONFIG_X86_64
28706 - get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
28707 -
28708 syscall_init(); /* This sets MSR_*STAR and related */
28709 #endif
28710 load_TR_desc(); /* This does ltr */
28711 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
28712 index cbca565..bae7133 100644
28713 --- a/arch/x86/realmode/init.c
28714 +++ b/arch/x86/realmode/init.c
28715 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
28716 __va(real_mode_header->trampoline_header);
28717
28718 #ifdef CONFIG_X86_32
28719 - trampoline_header->start = __pa(startup_32_smp);
28720 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
28721 +
28722 +#ifdef CONFIG_PAX_KERNEXEC
28723 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
28724 +#endif
28725 +
28726 + trampoline_header->boot_cs = __BOOT_CS;
28727 trampoline_header->gdt_limit = __BOOT_DS + 7;
28728 trampoline_header->gdt_base = __pa(boot_gdt);
28729 #else
28730 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
28731 index 8869287..d577672 100644
28732 --- a/arch/x86/realmode/rm/Makefile
28733 +++ b/arch/x86/realmode/rm/Makefile
28734 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
28735 $(call cc-option, -fno-unit-at-a-time)) \
28736 $(call cc-option, -fno-stack-protector) \
28737 $(call cc-option, -mpreferred-stack-boundary=2)
28738 +ifdef CONSTIFY_PLUGIN
28739 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
28740 +endif
28741 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
28742 GCOV_PROFILE := n
28743 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
28744 index a28221d..93c40f1 100644
28745 --- a/arch/x86/realmode/rm/header.S
28746 +++ b/arch/x86/realmode/rm/header.S
28747 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
28748 #endif
28749 /* APM/BIOS reboot */
28750 .long pa_machine_real_restart_asm
28751 -#ifdef CONFIG_X86_64
28752 +#ifdef CONFIG_X86_32
28753 + .long __KERNEL_CS
28754 +#else
28755 .long __KERNEL32_CS
28756 #endif
28757 END(real_mode_header)
28758 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
28759 index c1b2791..f9e31c7 100644
28760 --- a/arch/x86/realmode/rm/trampoline_32.S
28761 +++ b/arch/x86/realmode/rm/trampoline_32.S
28762 @@ -25,6 +25,12 @@
28763 #include <asm/page_types.h>
28764 #include "realmode.h"
28765
28766 +#ifdef CONFIG_PAX_KERNEXEC
28767 +#define ta(X) (X)
28768 +#else
28769 +#define ta(X) (pa_ ## X)
28770 +#endif
28771 +
28772 .text
28773 .code16
28774
28775 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
28776
28777 cli # We should be safe anyway
28778
28779 - movl tr_start, %eax # where we need to go
28780 -
28781 movl $0xA5A5A5A5, trampoline_status
28782 # write marker for master knows we're running
28783
28784 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
28785 movw $1, %dx # protected mode (PE) bit
28786 lmsw %dx # into protected mode
28787
28788 - ljmpl $__BOOT_CS, $pa_startup_32
28789 + ljmpl *(trampoline_header)
28790
28791 .section ".text32","ax"
28792 .code32
28793 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
28794 .balign 8
28795 GLOBAL(trampoline_header)
28796 tr_start: .space 4
28797 - tr_gdt_pad: .space 2
28798 + tr_boot_cs: .space 2
28799 tr_gdt: .space 6
28800 END(trampoline_header)
28801
28802 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
28803 index bb360dc..3e5945f 100644
28804 --- a/arch/x86/realmode/rm/trampoline_64.S
28805 +++ b/arch/x86/realmode/rm/trampoline_64.S
28806 @@ -107,7 +107,7 @@ ENTRY(startup_32)
28807 wrmsr
28808
28809 # Enable paging and in turn activate Long Mode
28810 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
28811 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
28812 movl %eax, %cr0
28813
28814 /*
28815 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
28816 index 5a1847d..deccb30 100644
28817 --- a/arch/x86/tools/relocs.c
28818 +++ b/arch/x86/tools/relocs.c
28819 @@ -12,10 +12,13 @@
28820 #include <regex.h>
28821 #include <tools/le_byteshift.h>
28822
28823 +#include "../../../include/generated/autoconf.h"
28824 +
28825 static void die(char *fmt, ...);
28826
28827 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
28828 static Elf32_Ehdr ehdr;
28829 +static Elf32_Phdr *phdr;
28830 static unsigned long reloc_count, reloc_idx;
28831 static unsigned long *relocs;
28832 static unsigned long reloc16_count, reloc16_idx;
28833 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
28834 }
28835 }
28836
28837 +static void read_phdrs(FILE *fp)
28838 +{
28839 + unsigned int i;
28840 +
28841 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
28842 + if (!phdr) {
28843 + die("Unable to allocate %d program headers\n",
28844 + ehdr.e_phnum);
28845 + }
28846 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
28847 + die("Seek to %d failed: %s\n",
28848 + ehdr.e_phoff, strerror(errno));
28849 + }
28850 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
28851 + die("Cannot read ELF program headers: %s\n",
28852 + strerror(errno));
28853 + }
28854 + for(i = 0; i < ehdr.e_phnum; i++) {
28855 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
28856 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
28857 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
28858 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
28859 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
28860 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
28861 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
28862 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
28863 + }
28864 +
28865 +}
28866 +
28867 static void read_shdrs(FILE *fp)
28868 {
28869 - int i;
28870 + unsigned int i;
28871 Elf32_Shdr shdr;
28872
28873 secs = calloc(ehdr.e_shnum, sizeof(struct section));
28874 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
28875
28876 static void read_strtabs(FILE *fp)
28877 {
28878 - int i;
28879 + unsigned int i;
28880 for (i = 0; i < ehdr.e_shnum; i++) {
28881 struct section *sec = &secs[i];
28882 if (sec->shdr.sh_type != SHT_STRTAB) {
28883 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
28884
28885 static void read_symtabs(FILE *fp)
28886 {
28887 - int i,j;
28888 + unsigned int i,j;
28889 for (i = 0; i < ehdr.e_shnum; i++) {
28890 struct section *sec = &secs[i];
28891 if (sec->shdr.sh_type != SHT_SYMTAB) {
28892 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
28893 }
28894
28895
28896 -static void read_relocs(FILE *fp)
28897 +static void read_relocs(FILE *fp, int use_real_mode)
28898 {
28899 - int i,j;
28900 + unsigned int i,j;
28901 + uint32_t base;
28902 +
28903 for (i = 0; i < ehdr.e_shnum; i++) {
28904 struct section *sec = &secs[i];
28905 if (sec->shdr.sh_type != SHT_REL) {
28906 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
28907 die("Cannot read symbol table: %s\n",
28908 strerror(errno));
28909 }
28910 + base = 0;
28911 +
28912 +#ifdef CONFIG_X86_32
28913 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
28914 + if (phdr[j].p_type != PT_LOAD )
28915 + continue;
28916 + 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)
28917 + continue;
28918 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
28919 + break;
28920 + }
28921 +#endif
28922 +
28923 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
28924 Elf32_Rel *rel = &sec->reltab[j];
28925 - rel->r_offset = elf32_to_cpu(rel->r_offset);
28926 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
28927 rel->r_info = elf32_to_cpu(rel->r_info);
28928 }
28929 }
28930 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
28931
28932 static void print_absolute_symbols(void)
28933 {
28934 - int i;
28935 + unsigned int i;
28936 printf("Absolute symbols\n");
28937 printf(" Num: Value Size Type Bind Visibility Name\n");
28938 for (i = 0; i < ehdr.e_shnum; i++) {
28939 struct section *sec = &secs[i];
28940 char *sym_strtab;
28941 - int j;
28942 + unsigned int j;
28943
28944 if (sec->shdr.sh_type != SHT_SYMTAB) {
28945 continue;
28946 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
28947
28948 static void print_absolute_relocs(void)
28949 {
28950 - int i, printed = 0;
28951 + unsigned int i, printed = 0;
28952
28953 for (i = 0; i < ehdr.e_shnum; i++) {
28954 struct section *sec = &secs[i];
28955 struct section *sec_applies, *sec_symtab;
28956 char *sym_strtab;
28957 Elf32_Sym *sh_symtab;
28958 - int j;
28959 + unsigned int j;
28960 if (sec->shdr.sh_type != SHT_REL) {
28961 continue;
28962 }
28963 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
28964 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
28965 int use_real_mode)
28966 {
28967 - int i;
28968 + unsigned int i;
28969 /* Walk through the relocations */
28970 for (i = 0; i < ehdr.e_shnum; i++) {
28971 char *sym_strtab;
28972 Elf32_Sym *sh_symtab;
28973 struct section *sec_applies, *sec_symtab;
28974 - int j;
28975 + unsigned int j;
28976 struct section *sec = &secs[i];
28977
28978 if (sec->shdr.sh_type != SHT_REL) {
28979 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
28980 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
28981 r_type = ELF32_R_TYPE(rel->r_info);
28982
28983 + if (!use_real_mode) {
28984 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
28985 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
28986 + continue;
28987 +
28988 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
28989 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
28990 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
28991 + continue;
28992 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
28993 + continue;
28994 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
28995 + continue;
28996 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
28997 + continue;
28998 +#endif
28999 + }
29000 +
29001 shn_abs = sym->st_shndx == SHN_ABS;
29002
29003 switch (r_type) {
29004 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
29005
29006 static void emit_relocs(int as_text, int use_real_mode)
29007 {
29008 - int i;
29009 + unsigned int i;
29010 /* Count how many relocations I have and allocate space for them. */
29011 reloc_count = 0;
29012 walk_relocs(count_reloc, use_real_mode);
29013 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
29014 fname, strerror(errno));
29015 }
29016 read_ehdr(fp);
29017 + read_phdrs(fp);
29018 read_shdrs(fp);
29019 read_strtabs(fp);
29020 read_symtabs(fp);
29021 - read_relocs(fp);
29022 + read_relocs(fp, use_real_mode);
29023 if (show_absolute_syms) {
29024 print_absolute_symbols();
29025 return 0;
29026 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
29027 index fd14be1..e3c79c0 100644
29028 --- a/arch/x86/vdso/Makefile
29029 +++ b/arch/x86/vdso/Makefile
29030 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
29031 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
29032 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
29033
29034 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
29035 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
29036 GCOV_PROFILE := n
29037
29038 #
29039 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
29040 index 0faad64..39ef157 100644
29041 --- a/arch/x86/vdso/vdso32-setup.c
29042 +++ b/arch/x86/vdso/vdso32-setup.c
29043 @@ -25,6 +25,7 @@
29044 #include <asm/tlbflush.h>
29045 #include <asm/vdso.h>
29046 #include <asm/proto.h>
29047 +#include <asm/mman.h>
29048
29049 enum {
29050 VDSO_DISABLED = 0,
29051 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
29052 void enable_sep_cpu(void)
29053 {
29054 int cpu = get_cpu();
29055 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
29056 + struct tss_struct *tss = init_tss + cpu;
29057
29058 if (!boot_cpu_has(X86_FEATURE_SEP)) {
29059 put_cpu();
29060 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
29061 gate_vma.vm_start = FIXADDR_USER_START;
29062 gate_vma.vm_end = FIXADDR_USER_END;
29063 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
29064 - gate_vma.vm_page_prot = __P101;
29065 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
29066
29067 return 0;
29068 }
29069 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29070 if (compat)
29071 addr = VDSO_HIGH_BASE;
29072 else {
29073 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
29074 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
29075 if (IS_ERR_VALUE(addr)) {
29076 ret = addr;
29077 goto up_fail;
29078 }
29079 }
29080
29081 - current->mm->context.vdso = (void *)addr;
29082 + current->mm->context.vdso = addr;
29083
29084 if (compat_uses_vma || !compat) {
29085 /*
29086 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29087 }
29088
29089 current_thread_info()->sysenter_return =
29090 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
29091 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
29092
29093 up_fail:
29094 if (ret)
29095 - current->mm->context.vdso = NULL;
29096 + current->mm->context.vdso = 0;
29097
29098 up_write(&mm->mmap_sem);
29099
29100 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
29101
29102 const char *arch_vma_name(struct vm_area_struct *vma)
29103 {
29104 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
29105 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
29106 return "[vdso]";
29107 +
29108 +#ifdef CONFIG_PAX_SEGMEXEC
29109 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
29110 + return "[vdso]";
29111 +#endif
29112 +
29113 return NULL;
29114 }
29115
29116 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
29117 * Check to see if the corresponding task was created in compat vdso
29118 * mode.
29119 */
29120 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
29121 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
29122 return &gate_vma;
29123 return NULL;
29124 }
29125 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
29126 index 00aaf04..4a26505 100644
29127 --- a/arch/x86/vdso/vma.c
29128 +++ b/arch/x86/vdso/vma.c
29129 @@ -16,8 +16,6 @@
29130 #include <asm/vdso.h>
29131 #include <asm/page.h>
29132
29133 -unsigned int __read_mostly vdso_enabled = 1;
29134 -
29135 extern char vdso_start[], vdso_end[];
29136 extern unsigned short vdso_sync_cpuid;
29137
29138 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
29139 * unaligned here as a result of stack start randomization.
29140 */
29141 addr = PAGE_ALIGN(addr);
29142 - addr = align_addr(addr, NULL, ALIGN_VDSO);
29143
29144 return addr;
29145 }
29146 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
29147 unsigned size)
29148 {
29149 struct mm_struct *mm = current->mm;
29150 - unsigned long addr;
29151 + unsigned long addr = 0;
29152 int ret;
29153
29154 - if (!vdso_enabled)
29155 - return 0;
29156 -
29157 down_write(&mm->mmap_sem);
29158 +
29159 +#ifdef CONFIG_PAX_RANDMMAP
29160 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
29161 +#endif
29162 +
29163 addr = vdso_addr(mm->start_stack, size);
29164 + addr = align_addr(addr, NULL, ALIGN_VDSO);
29165 addr = get_unmapped_area(NULL, addr, size, 0, 0);
29166 if (IS_ERR_VALUE(addr)) {
29167 ret = addr;
29168 goto up_fail;
29169 }
29170
29171 - current->mm->context.vdso = (void *)addr;
29172 + mm->context.vdso = addr;
29173
29174 ret = install_special_mapping(mm, addr, size,
29175 VM_READ|VM_EXEC|
29176 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
29177 pages);
29178 - if (ret) {
29179 - current->mm->context.vdso = NULL;
29180 - goto up_fail;
29181 - }
29182 + if (ret)
29183 + mm->context.vdso = 0;
29184
29185 up_fail:
29186 up_write(&mm->mmap_sem);
29187 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29188 vdsox32_size);
29189 }
29190 #endif
29191 -
29192 -static __init int vdso_setup(char *s)
29193 -{
29194 - vdso_enabled = simple_strtoul(s, NULL, 0);
29195 - return 0;
29196 -}
29197 -__setup("vdso=", vdso_setup);
29198 diff --git a/arch/x86/xen/apic.c b/arch/x86/xen/apic.c
29199 index 7005ced..530d6eb 100644
29200 --- a/arch/x86/xen/apic.c
29201 +++ b/arch/x86/xen/apic.c
29202 @@ -30,5 +30,5 @@ static unsigned int xen_io_apic_read(unsigned apic, unsigned reg)
29203
29204 void __init xen_init_apic(void)
29205 {
29206 - x86_io_apic_ops.read = xen_io_apic_read;
29207 + *(void **)&x86_io_apic_ops.read = xen_io_apic_read;
29208 }
29209 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
29210 index 586d838..9181904 100644
29211 --- a/arch/x86/xen/enlighten.c
29212 +++ b/arch/x86/xen/enlighten.c
29213 @@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
29214
29215 struct shared_info xen_dummy_shared_info;
29216
29217 -void *xen_initial_gdt;
29218 -
29219 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
29220 __read_mostly int xen_have_vector_callback;
29221 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
29222 @@ -473,8 +471,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
29223 {
29224 unsigned long va = dtr->address;
29225 unsigned int size = dtr->size + 1;
29226 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
29227 - unsigned long frames[pages];
29228 + unsigned long frames[65536 / PAGE_SIZE];
29229 int f;
29230
29231 /*
29232 @@ -522,8 +519,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
29233 {
29234 unsigned long va = dtr->address;
29235 unsigned int size = dtr->size + 1;
29236 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
29237 - unsigned long frames[pages];
29238 + unsigned long frames[65536 / PAGE_SIZE];
29239 int f;
29240
29241 /*
29242 @@ -918,21 +914,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
29243
29244 static void set_xen_basic_apic_ops(void)
29245 {
29246 - apic->read = xen_apic_read;
29247 - apic->write = xen_apic_write;
29248 - apic->icr_read = xen_apic_icr_read;
29249 - apic->icr_write = xen_apic_icr_write;
29250 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
29251 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
29252 - apic->set_apic_id = xen_set_apic_id;
29253 - apic->get_apic_id = xen_get_apic_id;
29254 + *(void **)&apic->read = xen_apic_read;
29255 + *(void **)&apic->write = xen_apic_write;
29256 + *(void **)&apic->icr_read = xen_apic_icr_read;
29257 + *(void **)&apic->icr_write = xen_apic_icr_write;
29258 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
29259 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
29260 + *(void **)&apic->set_apic_id = xen_set_apic_id;
29261 + *(void **)&apic->get_apic_id = xen_get_apic_id;
29262
29263 #ifdef CONFIG_SMP
29264 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
29265 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
29266 - apic->send_IPI_mask = xen_send_IPI_mask;
29267 - apic->send_IPI_all = xen_send_IPI_all;
29268 - apic->send_IPI_self = xen_send_IPI_self;
29269 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
29270 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
29271 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
29272 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
29273 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
29274 #endif
29275 }
29276
29277 @@ -1222,30 +1218,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
29278 #endif
29279 };
29280
29281 -static void xen_reboot(int reason)
29282 +static __noreturn void xen_reboot(int reason)
29283 {
29284 struct sched_shutdown r = { .reason = reason };
29285
29286 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
29287 - BUG();
29288 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
29289 + BUG();
29290 }
29291
29292 -static void xen_restart(char *msg)
29293 +static __noreturn void xen_restart(char *msg)
29294 {
29295 xen_reboot(SHUTDOWN_reboot);
29296 }
29297
29298 -static void xen_emergency_restart(void)
29299 +static __noreturn void xen_emergency_restart(void)
29300 {
29301 xen_reboot(SHUTDOWN_reboot);
29302 }
29303
29304 -static void xen_machine_halt(void)
29305 +static __noreturn void xen_machine_halt(void)
29306 {
29307 xen_reboot(SHUTDOWN_poweroff);
29308 }
29309
29310 -static void xen_machine_power_off(void)
29311 +static __noreturn void xen_machine_power_off(void)
29312 {
29313 if (pm_power_off)
29314 pm_power_off();
29315 @@ -1290,14 +1286,14 @@ static const struct machine_ops xen_machine_ops __initconst = {
29316 */
29317 static void __init xen_setup_stackprotector(void)
29318 {
29319 - pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
29320 - pv_cpu_ops.load_gdt = xen_load_gdt_boot;
29321 + *(void **)&pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
29322 + *(void **)&pv_cpu_ops.load_gdt = xen_load_gdt_boot;
29323
29324 setup_stack_canary_segment(0);
29325 switch_to_new_gdt(0);
29326
29327 - pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
29328 - pv_cpu_ops.load_gdt = xen_load_gdt;
29329 + *(void **)&pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
29330 + *(void **)&pv_cpu_ops.load_gdt = xen_load_gdt;
29331 }
29332
29333 /* First C function to be called on Xen boot */
29334 @@ -1315,13 +1311,13 @@ asmlinkage void __init xen_start_kernel(void)
29335
29336 /* Install Xen paravirt ops */
29337 pv_info = xen_info;
29338 - pv_init_ops = xen_init_ops;
29339 - pv_cpu_ops = xen_cpu_ops;
29340 - pv_apic_ops = xen_apic_ops;
29341 + memcpy((void *)&pv_init_ops, &xen_init_ops, sizeof pv_init_ops);
29342 + memcpy((void *)&pv_cpu_ops, &xen_cpu_ops, sizeof pv_cpu_ops);
29343 + memcpy((void *)&pv_apic_ops, &xen_apic_ops, sizeof pv_apic_ops);
29344
29345 - x86_init.resources.memory_setup = xen_memory_setup;
29346 - x86_init.oem.arch_setup = xen_arch_setup;
29347 - x86_init.oem.banner = xen_banner;
29348 + *(void **)&x86_init.resources.memory_setup = xen_memory_setup;
29349 + *(void **)&x86_init.oem.arch_setup = xen_arch_setup;
29350 + *(void **)&x86_init.oem.banner = xen_banner;
29351
29352 xen_init_time_ops();
29353
29354 @@ -1347,7 +1343,17 @@ asmlinkage void __init xen_start_kernel(void)
29355 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
29356
29357 /* Work out if we support NX */
29358 - x86_configure_nx();
29359 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29360 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
29361 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
29362 + unsigned l, h;
29363 +
29364 + __supported_pte_mask |= _PAGE_NX;
29365 + rdmsr(MSR_EFER, l, h);
29366 + l |= EFER_NX;
29367 + wrmsr(MSR_EFER, l, h);
29368 + }
29369 +#endif
29370
29371 xen_setup_features();
29372
29373 @@ -1376,14 +1382,7 @@ asmlinkage void __init xen_start_kernel(void)
29374 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
29375 }
29376
29377 - machine_ops = xen_machine_ops;
29378 -
29379 - /*
29380 - * The only reliable way to retain the initial address of the
29381 - * percpu gdt_page is to remember it here, so we can go and
29382 - * mark it RW later, when the initial percpu area is freed.
29383 - */
29384 - xen_initial_gdt = &per_cpu(gdt_page, 0);
29385 + memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
29386
29387 xen_smp_init();
29388
29389 @@ -1450,7 +1449,7 @@ asmlinkage void __init xen_start_kernel(void)
29390 add_preferred_console("tty", 0, NULL);
29391 add_preferred_console("hvc", 0, NULL);
29392 if (pci_xen)
29393 - x86_init.pci.arch_init = pci_xen_init;
29394 + *(void **)&x86_init.pci.arch_init = pci_xen_init;
29395 } else {
29396 const struct dom0_vga_console_info *info =
29397 (void *)((char *)xen_start_info +
29398 @@ -1476,8 +1475,8 @@ asmlinkage void __init xen_start_kernel(void)
29399 xen_acpi_sleep_register();
29400
29401 /* Avoid searching for BIOS MP tables */
29402 - x86_init.mpparse.find_smp_config = x86_init_noop;
29403 - x86_init.mpparse.get_smp_config = x86_init_uint_noop;
29404 + *(void **)&x86_init.mpparse.find_smp_config = x86_init_noop;
29405 + *(void **)&x86_init.mpparse.get_smp_config = x86_init_uint_noop;
29406 }
29407 #ifdef CONFIG_PCI
29408 /* PCI BIOS service won't work from a PV guest. */
29409 @@ -1583,7 +1582,7 @@ static void __init xen_hvm_guest_init(void)
29410 xen_hvm_smp_init();
29411 register_cpu_notifier(&xen_hvm_cpu_notifier);
29412 xen_unplug_emulated_devices();
29413 - x86_init.irqs.intr_init = xen_init_IRQ;
29414 + *(void **)&x86_init.irqs.intr_init = xen_init_IRQ;
29415 xen_hvm_init_time_ops();
29416 xen_hvm_init_mmu_ops();
29417 }
29418 diff --git a/arch/x86/xen/irq.c b/arch/x86/xen/irq.c
29419 index 01a4dc0..3ca0cc9 100644
29420 --- a/arch/x86/xen/irq.c
29421 +++ b/arch/x86/xen/irq.c
29422 @@ -130,5 +130,5 @@ static const struct pv_irq_ops xen_irq_ops __initconst = {
29423 void __init xen_init_irq_ops(void)
29424 {
29425 pv_irq_ops = xen_irq_ops;
29426 - x86_init.irqs.intr_init = xen_init_IRQ;
29427 + *(void **)&x86_init.irqs.intr_init = xen_init_IRQ;
29428 }
29429 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
29430 index dcf5f2d..5f72fe7 100644
29431 --- a/arch/x86/xen/mmu.c
29432 +++ b/arch/x86/xen/mmu.c
29433 @@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29434 /* L3_k[510] -> level2_kernel_pgt
29435 * L3_i[511] -> level2_fixmap_pgt */
29436 convert_pfn_mfn(level3_kernel_pgt);
29437 + convert_pfn_mfn(level3_vmalloc_start_pgt);
29438 + convert_pfn_mfn(level3_vmalloc_end_pgt);
29439 + convert_pfn_mfn(level3_vmemmap_pgt);
29440
29441 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
29442 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
29443 @@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29444 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
29445 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
29446 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
29447 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
29448 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
29449 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
29450 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
29451 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
29452 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
29453 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
29454 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
29455
29456 @@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
29457 pv_mmu_ops.set_pud = xen_set_pud;
29458 #if PAGETABLE_LEVELS == 4
29459 pv_mmu_ops.set_pgd = xen_set_pgd;
29460 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
29461 #endif
29462
29463 /* This will work as long as patching hasn't happened yet
29464 @@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
29465 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
29466 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
29467 .set_pgd = xen_set_pgd_hyper,
29468 + .set_pgd_batched = xen_set_pgd_hyper,
29469
29470 .alloc_pud = xen_alloc_pmd_init,
29471 .release_pud = xen_release_pmd_init,
29472 @@ -2197,8 +2206,8 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
29473
29474 void __init xen_init_mmu_ops(void)
29475 {
29476 - x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve;
29477 - x86_init.paging.pagetable_init = xen_pagetable_init;
29478 + *(void **)&x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve;
29479 + *(void **)&x86_init.paging.pagetable_init = xen_pagetable_init;
29480 pv_mmu_ops = xen_mmu_ops;
29481
29482 memset(dummy_mapping, 0xff, PAGE_SIZE);
29483 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
29484 index 353c50f..a0b9b0d 100644
29485 --- a/arch/x86/xen/smp.c
29486 +++ b/arch/x86/xen/smp.c
29487 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
29488 {
29489 BUG_ON(smp_processor_id() != 0);
29490 native_smp_prepare_boot_cpu();
29491 -
29492 - /* We've switched to the "real" per-cpu gdt, so make sure the
29493 - old memory can be recycled */
29494 - make_lowmem_page_readwrite(xen_initial_gdt);
29495 -
29496 xen_filter_cpu_maps();
29497 xen_setup_vcpu_info_placement();
29498 }
29499 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
29500 gdt = get_cpu_gdt_table(cpu);
29501
29502 ctxt->flags = VGCF_IN_KERNEL;
29503 - ctxt->user_regs.ds = __USER_DS;
29504 - ctxt->user_regs.es = __USER_DS;
29505 + ctxt->user_regs.ds = __KERNEL_DS;
29506 + ctxt->user_regs.es = __KERNEL_DS;
29507 ctxt->user_regs.ss = __KERNEL_DS;
29508 #ifdef CONFIG_X86_32
29509 ctxt->user_regs.fs = __KERNEL_PERCPU;
29510 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
29511 + savesegment(gs, ctxt->user_regs.gs);
29512 #else
29513 ctxt->gs_base_kernel = per_cpu_offset(cpu);
29514 #endif
29515 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
29516 int rc;
29517
29518 per_cpu(current_task, cpu) = idle;
29519 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
29520 #ifdef CONFIG_X86_32
29521 irq_ctx_init(cpu);
29522 #else
29523 clear_tsk_thread_flag(idle, TIF_FORK);
29524 - per_cpu(kernel_stack, cpu) =
29525 - (unsigned long)task_stack_page(idle) -
29526 - KERNEL_STACK_OFFSET + THREAD_SIZE;
29527 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
29528 #endif
29529 xen_setup_runstate_info(cpu);
29530 xen_setup_timer(cpu);
29531 @@ -637,7 +631,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
29532
29533 void __init xen_smp_init(void)
29534 {
29535 - smp_ops = xen_smp_ops;
29536 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
29537 xen_fill_possible_map();
29538 xen_init_spinlocks();
29539 }
29540 @@ -672,10 +666,10 @@ void __init xen_hvm_smp_init(void)
29541 {
29542 if (!xen_have_vector_callback)
29543 return;
29544 - smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
29545 - smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
29546 - smp_ops.cpu_up = xen_hvm_cpu_up;
29547 - smp_ops.cpu_die = xen_hvm_cpu_die;
29548 - smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
29549 - smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
29550 + *(void **)&smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
29551 + *(void **)&smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
29552 + *(void **)&smp_ops.cpu_up = xen_hvm_cpu_up;
29553 + *(void **)&smp_ops.cpu_die = xen_hvm_cpu_die;
29554 + *(void **)&smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
29555 + *(void **)&smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
29556 }
29557 diff --git a/arch/x86/xen/spinlock.c b/arch/x86/xen/spinlock.c
29558 index 83e866d..ef60385 100644
29559 --- a/arch/x86/xen/spinlock.c
29560 +++ b/arch/x86/xen/spinlock.c
29561 @@ -390,12 +390,12 @@ void __init xen_init_spinlocks(void)
29562 {
29563 BUILD_BUG_ON(sizeof(struct xen_spinlock) > sizeof(arch_spinlock_t));
29564
29565 - pv_lock_ops.spin_is_locked = xen_spin_is_locked;
29566 - pv_lock_ops.spin_is_contended = xen_spin_is_contended;
29567 - pv_lock_ops.spin_lock = xen_spin_lock;
29568 - pv_lock_ops.spin_lock_flags = xen_spin_lock_flags;
29569 - pv_lock_ops.spin_trylock = xen_spin_trylock;
29570 - pv_lock_ops.spin_unlock = xen_spin_unlock;
29571 + *(void **)&pv_lock_ops.spin_is_locked = xen_spin_is_locked;
29572 + *(void **)&pv_lock_ops.spin_is_contended = xen_spin_is_contended;
29573 + *(void **)&pv_lock_ops.spin_lock = xen_spin_lock;
29574 + *(void **)&pv_lock_ops.spin_lock_flags = xen_spin_lock_flags;
29575 + *(void **)&pv_lock_ops.spin_trylock = xen_spin_trylock;
29576 + *(void **)&pv_lock_ops.spin_unlock = xen_spin_unlock;
29577 }
29578
29579 #ifdef CONFIG_XEN_DEBUG_FS
29580 diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
29581 index 0296a95..3c51a2d 100644
29582 --- a/arch/x86/xen/time.c
29583 +++ b/arch/x86/xen/time.c
29584 @@ -481,15 +481,15 @@ static void __init xen_time_init(void)
29585
29586 void __init xen_init_time_ops(void)
29587 {
29588 - pv_time_ops = xen_time_ops;
29589 + memcpy((void *)&pv_time_ops, &xen_time_ops, sizeof pv_time_ops);
29590
29591 - x86_init.timers.timer_init = xen_time_init;
29592 - x86_init.timers.setup_percpu_clockev = x86_init_noop;
29593 - x86_cpuinit.setup_percpu_clockev = x86_init_noop;
29594 + *(void **)&x86_init.timers.timer_init = xen_time_init;
29595 + *(void **)&x86_init.timers.setup_percpu_clockev = x86_init_noop;
29596 + *(void **)&x86_cpuinit.setup_percpu_clockev = x86_init_noop;
29597
29598 - x86_platform.calibrate_tsc = xen_tsc_khz;
29599 - x86_platform.get_wallclock = xen_get_wallclock;
29600 - x86_platform.set_wallclock = xen_set_wallclock;
29601 + *(void **)&x86_platform.calibrate_tsc = xen_tsc_khz;
29602 + *(void **)&x86_platform.get_wallclock = xen_get_wallclock;
29603 + *(void **)&x86_platform.set_wallclock = xen_set_wallclock;
29604 }
29605
29606 #ifdef CONFIG_XEN_PVHVM
29607 @@ -514,12 +514,12 @@ void __init xen_hvm_init_time_ops(void)
29608 return;
29609 }
29610
29611 - pv_time_ops = xen_time_ops;
29612 - x86_init.timers.setup_percpu_clockev = xen_time_init;
29613 - x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;
29614 + memcpy((void *)&pv_time_ops, &xen_time_ops, sizeof pv_time_ops);
29615 + *(void **)&x86_init.timers.setup_percpu_clockev = xen_time_init;
29616 + *(void **)&x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;
29617
29618 - x86_platform.calibrate_tsc = xen_tsc_khz;
29619 - x86_platform.get_wallclock = xen_get_wallclock;
29620 - x86_platform.set_wallclock = xen_set_wallclock;
29621 + *(void **)&x86_platform.calibrate_tsc = xen_tsc_khz;
29622 + *(void **)&x86_platform.get_wallclock = xen_get_wallclock;
29623 + *(void **)&x86_platform.set_wallclock = xen_set_wallclock;
29624 }
29625 #endif
29626 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
29627 index f9643fc..602e8af 100644
29628 --- a/arch/x86/xen/xen-asm_32.S
29629 +++ b/arch/x86/xen/xen-asm_32.S
29630 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
29631 ESP_OFFSET=4 # bytes pushed onto stack
29632
29633 /*
29634 - * Store vcpu_info pointer for easy access. Do it this way to
29635 - * avoid having to reload %fs
29636 + * Store vcpu_info pointer for easy access.
29637 */
29638 #ifdef CONFIG_SMP
29639 - GET_THREAD_INFO(%eax)
29640 - movl TI_cpu(%eax), %eax
29641 - movl __per_cpu_offset(,%eax,4), %eax
29642 - mov xen_vcpu(%eax), %eax
29643 + push %fs
29644 + mov $(__KERNEL_PERCPU), %eax
29645 + mov %eax, %fs
29646 + mov PER_CPU_VAR(xen_vcpu), %eax
29647 + pop %fs
29648 #else
29649 movl xen_vcpu, %eax
29650 #endif
29651 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
29652 index 7faed58..ba4427c 100644
29653 --- a/arch/x86/xen/xen-head.S
29654 +++ b/arch/x86/xen/xen-head.S
29655 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
29656 #ifdef CONFIG_X86_32
29657 mov %esi,xen_start_info
29658 mov $init_thread_union+THREAD_SIZE,%esp
29659 +#ifdef CONFIG_SMP
29660 + movl $cpu_gdt_table,%edi
29661 + movl $__per_cpu_load,%eax
29662 + movw %ax,__KERNEL_PERCPU + 2(%edi)
29663 + rorl $16,%eax
29664 + movb %al,__KERNEL_PERCPU + 4(%edi)
29665 + movb %ah,__KERNEL_PERCPU + 7(%edi)
29666 + movl $__per_cpu_end - 1,%eax
29667 + subl $__per_cpu_start,%eax
29668 + movw %ax,__KERNEL_PERCPU + 0(%edi)
29669 +#endif
29670 #else
29671 mov %rsi,xen_start_info
29672 mov $init_thread_union+THREAD_SIZE,%rsp
29673 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
29674 index a95b417..b6dbd0b 100644
29675 --- a/arch/x86/xen/xen-ops.h
29676 +++ b/arch/x86/xen/xen-ops.h
29677 @@ -10,8 +10,6 @@
29678 extern const char xen_hypervisor_callback[];
29679 extern const char xen_failsafe_callback[];
29680
29681 -extern void *xen_initial_gdt;
29682 -
29683 struct trap_info;
29684 void xen_copy_trap_info(struct trap_info *traps);
29685
29686 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
29687 index 525bd3d..ef888b1 100644
29688 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
29689 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
29690 @@ -119,9 +119,9 @@
29691 ----------------------------------------------------------------------*/
29692
29693 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
29694 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
29695 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
29696 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
29697 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29698
29699 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
29700 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
29701 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
29702 index 2f33760..835e50a 100644
29703 --- a/arch/xtensa/variants/fsf/include/variant/core.h
29704 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
29705 @@ -11,6 +11,7 @@
29706 #ifndef _XTENSA_CORE_H
29707 #define _XTENSA_CORE_H
29708
29709 +#include <linux/const.h>
29710
29711 /****************************************************************************
29712 Parameters Useful for Any Code, USER or PRIVILEGED
29713 @@ -112,9 +113,9 @@
29714 ----------------------------------------------------------------------*/
29715
29716 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29717 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29718 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29719 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29720 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29721
29722 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
29723 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
29724 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
29725 index af00795..2bb8105 100644
29726 --- a/arch/xtensa/variants/s6000/include/variant/core.h
29727 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
29728 @@ -11,6 +11,7 @@
29729 #ifndef _XTENSA_CORE_CONFIGURATION_H
29730 #define _XTENSA_CORE_CONFIGURATION_H
29731
29732 +#include <linux/const.h>
29733
29734 /****************************************************************************
29735 Parameters Useful for Any Code, USER or PRIVILEGED
29736 @@ -118,9 +119,9 @@
29737 ----------------------------------------------------------------------*/
29738
29739 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29740 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29741 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29742 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29743 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29744
29745 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
29746 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
29747 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
29748 index 58916af..9cb880b 100644
29749 --- a/block/blk-iopoll.c
29750 +++ b/block/blk-iopoll.c
29751 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
29752 }
29753 EXPORT_SYMBOL(blk_iopoll_complete);
29754
29755 -static void blk_iopoll_softirq(struct softirq_action *h)
29756 +static void blk_iopoll_softirq(void)
29757 {
29758 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
29759 int rearm = 0, budget = blk_iopoll_budget;
29760 diff --git a/block/blk-map.c b/block/blk-map.c
29761 index 623e1cd..ca1e109 100644
29762 --- a/block/blk-map.c
29763 +++ b/block/blk-map.c
29764 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
29765 if (!len || !kbuf)
29766 return -EINVAL;
29767
29768 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
29769 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
29770 if (do_copy)
29771 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
29772 else
29773 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
29774 index 467c8de..4bddc6d 100644
29775 --- a/block/blk-softirq.c
29776 +++ b/block/blk-softirq.c
29777 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
29778 * Softirq action handler - move entries to local list and loop over them
29779 * while passing them to the queue registered handler.
29780 */
29781 -static void blk_done_softirq(struct softirq_action *h)
29782 +static void blk_done_softirq(void)
29783 {
29784 struct list_head *cpu_list, local_list;
29785
29786 diff --git a/block/bsg.c b/block/bsg.c
29787 index ff64ae3..593560c 100644
29788 --- a/block/bsg.c
29789 +++ b/block/bsg.c
29790 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
29791 struct sg_io_v4 *hdr, struct bsg_device *bd,
29792 fmode_t has_write_perm)
29793 {
29794 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29795 + unsigned char *cmdptr;
29796 +
29797 if (hdr->request_len > BLK_MAX_CDB) {
29798 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
29799 if (!rq->cmd)
29800 return -ENOMEM;
29801 - }
29802 + cmdptr = rq->cmd;
29803 + } else
29804 + cmdptr = tmpcmd;
29805
29806 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
29807 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
29808 hdr->request_len))
29809 return -EFAULT;
29810
29811 + if (cmdptr != rq->cmd)
29812 + memcpy(rq->cmd, cmdptr, hdr->request_len);
29813 +
29814 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
29815 if (blk_verify_command(rq->cmd, has_write_perm))
29816 return -EPERM;
29817 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
29818 index 7c668c8..db3521c 100644
29819 --- a/block/compat_ioctl.c
29820 +++ b/block/compat_ioctl.c
29821 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
29822 err |= __get_user(f->spec1, &uf->spec1);
29823 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
29824 err |= __get_user(name, &uf->name);
29825 - f->name = compat_ptr(name);
29826 + f->name = (void __force_kernel *)compat_ptr(name);
29827 if (err) {
29828 err = -EFAULT;
29829 goto out;
29830 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
29831 index 6296b40..417c00f 100644
29832 --- a/block/partitions/efi.c
29833 +++ b/block/partitions/efi.c
29834 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
29835 if (!gpt)
29836 return NULL;
29837
29838 + if (!le32_to_cpu(gpt->num_partition_entries))
29839 + return NULL;
29840 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
29841 + if (!pte)
29842 + return NULL;
29843 +
29844 count = le32_to_cpu(gpt->num_partition_entries) *
29845 le32_to_cpu(gpt->sizeof_partition_entry);
29846 - if (!count)
29847 - return NULL;
29848 - pte = kzalloc(count, GFP_KERNEL);
29849 - if (!pte)
29850 - return NULL;
29851 -
29852 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
29853 (u8 *) pte,
29854 count) < count) {
29855 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
29856 index 9a87daa..fb17486 100644
29857 --- a/block/scsi_ioctl.c
29858 +++ b/block/scsi_ioctl.c
29859 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
29860 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
29861 struct sg_io_hdr *hdr, fmode_t mode)
29862 {
29863 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
29864 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29865 + unsigned char *cmdptr;
29866 +
29867 + if (rq->cmd != rq->__cmd)
29868 + cmdptr = rq->cmd;
29869 + else
29870 + cmdptr = tmpcmd;
29871 +
29872 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
29873 return -EFAULT;
29874 +
29875 + if (cmdptr != rq->cmd)
29876 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
29877 +
29878 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
29879 return -EPERM;
29880
29881 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29882 int err;
29883 unsigned int in_len, out_len, bytes, opcode, cmdlen;
29884 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
29885 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29886 + unsigned char *cmdptr;
29887
29888 if (!sic)
29889 return -EINVAL;
29890 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29891 */
29892 err = -EFAULT;
29893 rq->cmd_len = cmdlen;
29894 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
29895 +
29896 + if (rq->cmd != rq->__cmd)
29897 + cmdptr = rq->cmd;
29898 + else
29899 + cmdptr = tmpcmd;
29900 +
29901 + if (copy_from_user(cmdptr, sic->data, cmdlen))
29902 goto error;
29903
29904 + if (rq->cmd != cmdptr)
29905 + memcpy(rq->cmd, cmdptr, cmdlen);
29906 +
29907 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
29908 goto error;
29909
29910 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
29911 index 7bdd61b..afec999 100644
29912 --- a/crypto/cryptd.c
29913 +++ b/crypto/cryptd.c
29914 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
29915
29916 struct cryptd_blkcipher_request_ctx {
29917 crypto_completion_t complete;
29918 -};
29919 +} __no_const;
29920
29921 struct cryptd_hash_ctx {
29922 struct crypto_shash *child;
29923 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
29924
29925 struct cryptd_aead_request_ctx {
29926 crypto_completion_t complete;
29927 -};
29928 +} __no_const;
29929
29930 static void cryptd_queue_worker(struct work_struct *work);
29931
29932 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
29933 index e6defd8..c26a225 100644
29934 --- a/drivers/acpi/apei/cper.c
29935 +++ b/drivers/acpi/apei/cper.c
29936 @@ -38,12 +38,12 @@
29937 */
29938 u64 cper_next_record_id(void)
29939 {
29940 - static atomic64_t seq;
29941 + static atomic64_unchecked_t seq;
29942
29943 - if (!atomic64_read(&seq))
29944 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
29945 + if (!atomic64_read_unchecked(&seq))
29946 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
29947
29948 - return atomic64_inc_return(&seq);
29949 + return atomic64_inc_return_unchecked(&seq);
29950 }
29951 EXPORT_SYMBOL_GPL(cper_next_record_id);
29952
29953 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
29954 index 7586544..636a2f0 100644
29955 --- a/drivers/acpi/ec_sys.c
29956 +++ b/drivers/acpi/ec_sys.c
29957 @@ -12,6 +12,7 @@
29958 #include <linux/acpi.h>
29959 #include <linux/debugfs.h>
29960 #include <linux/module.h>
29961 +#include <linux/uaccess.h>
29962 #include "internal.h"
29963
29964 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
29965 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29966 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
29967 */
29968 unsigned int size = EC_SPACE_SIZE;
29969 - u8 *data = (u8 *) buf;
29970 + u8 data;
29971 loff_t init_off = *off;
29972 int err = 0;
29973
29974 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29975 size = count;
29976
29977 while (size) {
29978 - err = ec_read(*off, &data[*off - init_off]);
29979 + err = ec_read(*off, &data);
29980 if (err)
29981 return err;
29982 + if (put_user(data, &buf[*off - init_off]))
29983 + return -EFAULT;
29984 *off += 1;
29985 size--;
29986 }
29987 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
29988
29989 unsigned int size = count;
29990 loff_t init_off = *off;
29991 - u8 *data = (u8 *) buf;
29992 int err = 0;
29993
29994 if (*off >= EC_SPACE_SIZE)
29995 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
29996 }
29997
29998 while (size) {
29999 - u8 byte_write = data[*off - init_off];
30000 + u8 byte_write;
30001 + if (get_user(byte_write, &buf[*off - init_off]))
30002 + return -EFAULT;
30003 err = ec_write(*off, byte_write);
30004 if (err)
30005 return err;
30006 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
30007 index 27adb09..1ed412d 100644
30008 --- a/drivers/acpi/proc.c
30009 +++ b/drivers/acpi/proc.c
30010 @@ -360,19 +360,13 @@ acpi_system_write_wakeup_device(struct file *file,
30011 size_t count, loff_t * ppos)
30012 {
30013 struct list_head *node, *next;
30014 - char strbuf[5];
30015 - char str[5] = "";
30016 - unsigned int len = count;
30017 + char strbuf[5] = {0};
30018
30019 - if (len > 4)
30020 - len = 4;
30021 - if (len < 0)
30022 + if (count > 4)
30023 + count = 4;
30024 + if (copy_from_user(strbuf, buffer, count))
30025 return -EFAULT;
30026 -
30027 - if (copy_from_user(strbuf, buffer, len))
30028 - return -EFAULT;
30029 - strbuf[len] = '\0';
30030 - sscanf(strbuf, "%s", str);
30031 + strbuf[count] = '\0';
30032
30033 mutex_lock(&acpi_device_lock);
30034 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
30035 @@ -381,7 +375,7 @@ acpi_system_write_wakeup_device(struct file *file,
30036 if (!dev->wakeup.flags.valid)
30037 continue;
30038
30039 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
30040 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
30041 if (device_can_wakeup(&dev->dev)) {
30042 bool enable = !device_may_wakeup(&dev->dev);
30043 device_set_wakeup_enable(&dev->dev, enable);
30044 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
30045 index bd4e5dc..0497b66 100644
30046 --- a/drivers/acpi/processor_driver.c
30047 +++ b/drivers/acpi/processor_driver.c
30048 @@ -552,7 +552,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
30049 return 0;
30050 #endif
30051
30052 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
30053 + BUG_ON(pr->id >= nr_cpu_ids);
30054
30055 /*
30056 * Buggy BIOS check
30057 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
30058 index c8ac4fe..631818e 100644
30059 --- a/drivers/ata/libata-core.c
30060 +++ b/drivers/ata/libata-core.c
30061 @@ -4779,7 +4779,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
30062 struct ata_port *ap;
30063 unsigned int tag;
30064
30065 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30066 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30067 ap = qc->ap;
30068
30069 qc->flags = 0;
30070 @@ -4795,7 +4795,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
30071 struct ata_port *ap;
30072 struct ata_link *link;
30073
30074 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30075 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30076 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
30077 ap = qc->ap;
30078 link = qc->dev->link;
30079 @@ -5891,6 +5891,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
30080 return;
30081
30082 spin_lock(&lock);
30083 + pax_open_kernel();
30084
30085 for (cur = ops->inherits; cur; cur = cur->inherits) {
30086 void **inherit = (void **)cur;
30087 @@ -5904,8 +5905,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
30088 if (IS_ERR(*pp))
30089 *pp = NULL;
30090
30091 - ops->inherits = NULL;
30092 + *(struct ata_port_operations **)&ops->inherits = NULL;
30093
30094 + pax_close_kernel();
30095 spin_unlock(&lock);
30096 }
30097
30098 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
30099 index 371fd2c..0836c78 100644
30100 --- a/drivers/ata/pata_arasan_cf.c
30101 +++ b/drivers/ata/pata_arasan_cf.c
30102 @@ -861,7 +861,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
30103 /* Handle platform specific quirks */
30104 if (pdata->quirk) {
30105 if (pdata->quirk & CF_BROKEN_PIO) {
30106 - ap->ops->set_piomode = NULL;
30107 + pax_open_kernel();
30108 + *(void **)&ap->ops->set_piomode = NULL;
30109 + pax_close_kernel();
30110 ap->pio_mask = 0;
30111 }
30112 if (pdata->quirk & CF_BROKEN_MWDMA)
30113 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
30114 index f9b983a..887b9d8 100644
30115 --- a/drivers/atm/adummy.c
30116 +++ b/drivers/atm/adummy.c
30117 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
30118 vcc->pop(vcc, skb);
30119 else
30120 dev_kfree_skb_any(skb);
30121 - atomic_inc(&vcc->stats->tx);
30122 + atomic_inc_unchecked(&vcc->stats->tx);
30123
30124 return 0;
30125 }
30126 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
30127 index ff7bb8a..568fc0b 100644
30128 --- a/drivers/atm/ambassador.c
30129 +++ b/drivers/atm/ambassador.c
30130 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
30131 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
30132
30133 // VC layer stats
30134 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30135 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30136
30137 // free the descriptor
30138 kfree (tx_descr);
30139 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
30140 dump_skb ("<<<", vc, skb);
30141
30142 // VC layer stats
30143 - atomic_inc(&atm_vcc->stats->rx);
30144 + atomic_inc_unchecked(&atm_vcc->stats->rx);
30145 __net_timestamp(skb);
30146 // end of our responsibility
30147 atm_vcc->push (atm_vcc, skb);
30148 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
30149 } else {
30150 PRINTK (KERN_INFO, "dropped over-size frame");
30151 // should we count this?
30152 - atomic_inc(&atm_vcc->stats->rx_drop);
30153 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30154 }
30155
30156 } else {
30157 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
30158 }
30159
30160 if (check_area (skb->data, skb->len)) {
30161 - atomic_inc(&atm_vcc->stats->tx_err);
30162 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
30163 return -ENOMEM; // ?
30164 }
30165
30166 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
30167 index b22d71c..d6e1049 100644
30168 --- a/drivers/atm/atmtcp.c
30169 +++ b/drivers/atm/atmtcp.c
30170 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30171 if (vcc->pop) vcc->pop(vcc,skb);
30172 else dev_kfree_skb(skb);
30173 if (dev_data) return 0;
30174 - atomic_inc(&vcc->stats->tx_err);
30175 + atomic_inc_unchecked(&vcc->stats->tx_err);
30176 return -ENOLINK;
30177 }
30178 size = skb->len+sizeof(struct atmtcp_hdr);
30179 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30180 if (!new_skb) {
30181 if (vcc->pop) vcc->pop(vcc,skb);
30182 else dev_kfree_skb(skb);
30183 - atomic_inc(&vcc->stats->tx_err);
30184 + atomic_inc_unchecked(&vcc->stats->tx_err);
30185 return -ENOBUFS;
30186 }
30187 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
30188 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30189 if (vcc->pop) vcc->pop(vcc,skb);
30190 else dev_kfree_skb(skb);
30191 out_vcc->push(out_vcc,new_skb);
30192 - atomic_inc(&vcc->stats->tx);
30193 - atomic_inc(&out_vcc->stats->rx);
30194 + atomic_inc_unchecked(&vcc->stats->tx);
30195 + atomic_inc_unchecked(&out_vcc->stats->rx);
30196 return 0;
30197 }
30198
30199 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
30200 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
30201 read_unlock(&vcc_sklist_lock);
30202 if (!out_vcc) {
30203 - atomic_inc(&vcc->stats->tx_err);
30204 + atomic_inc_unchecked(&vcc->stats->tx_err);
30205 goto done;
30206 }
30207 skb_pull(skb,sizeof(struct atmtcp_hdr));
30208 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
30209 __net_timestamp(new_skb);
30210 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
30211 out_vcc->push(out_vcc,new_skb);
30212 - atomic_inc(&vcc->stats->tx);
30213 - atomic_inc(&out_vcc->stats->rx);
30214 + atomic_inc_unchecked(&vcc->stats->tx);
30215 + atomic_inc_unchecked(&out_vcc->stats->rx);
30216 done:
30217 if (vcc->pop) vcc->pop(vcc,skb);
30218 else dev_kfree_skb(skb);
30219 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
30220 index 81e44f7..498ea36 100644
30221 --- a/drivers/atm/eni.c
30222 +++ b/drivers/atm/eni.c
30223 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
30224 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
30225 vcc->dev->number);
30226 length = 0;
30227 - atomic_inc(&vcc->stats->rx_err);
30228 + atomic_inc_unchecked(&vcc->stats->rx_err);
30229 }
30230 else {
30231 length = ATM_CELL_SIZE-1; /* no HEC */
30232 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
30233 size);
30234 }
30235 eff = length = 0;
30236 - atomic_inc(&vcc->stats->rx_err);
30237 + atomic_inc_unchecked(&vcc->stats->rx_err);
30238 }
30239 else {
30240 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
30241 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
30242 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
30243 vcc->dev->number,vcc->vci,length,size << 2,descr);
30244 length = eff = 0;
30245 - atomic_inc(&vcc->stats->rx_err);
30246 + atomic_inc_unchecked(&vcc->stats->rx_err);
30247 }
30248 }
30249 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
30250 @@ -767,7 +767,7 @@ rx_dequeued++;
30251 vcc->push(vcc,skb);
30252 pushed++;
30253 }
30254 - atomic_inc(&vcc->stats->rx);
30255 + atomic_inc_unchecked(&vcc->stats->rx);
30256 }
30257 wake_up(&eni_dev->rx_wait);
30258 }
30259 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
30260 PCI_DMA_TODEVICE);
30261 if (vcc->pop) vcc->pop(vcc,skb);
30262 else dev_kfree_skb_irq(skb);
30263 - atomic_inc(&vcc->stats->tx);
30264 + atomic_inc_unchecked(&vcc->stats->tx);
30265 wake_up(&eni_dev->tx_wait);
30266 dma_complete++;
30267 }
30268 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
30269 index 86fed1b..6dc4721 100644
30270 --- a/drivers/atm/firestream.c
30271 +++ b/drivers/atm/firestream.c
30272 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
30273 }
30274 }
30275
30276 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30277 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30278
30279 fs_dprintk (FS_DEBUG_TXMEM, "i");
30280 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
30281 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
30282 #endif
30283 skb_put (skb, qe->p1 & 0xffff);
30284 ATM_SKB(skb)->vcc = atm_vcc;
30285 - atomic_inc(&atm_vcc->stats->rx);
30286 + atomic_inc_unchecked(&atm_vcc->stats->rx);
30287 __net_timestamp(skb);
30288 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
30289 atm_vcc->push (atm_vcc, skb);
30290 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
30291 kfree (pe);
30292 }
30293 if (atm_vcc)
30294 - atomic_inc(&atm_vcc->stats->rx_drop);
30295 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30296 break;
30297 case 0x1f: /* Reassembly abort: no buffers. */
30298 /* Silently increment error counter. */
30299 if (atm_vcc)
30300 - atomic_inc(&atm_vcc->stats->rx_drop);
30301 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30302 break;
30303 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
30304 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
30305 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
30306 index 361f5ae..7fc552d 100644
30307 --- a/drivers/atm/fore200e.c
30308 +++ b/drivers/atm/fore200e.c
30309 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
30310 #endif
30311 /* check error condition */
30312 if (*entry->status & STATUS_ERROR)
30313 - atomic_inc(&vcc->stats->tx_err);
30314 + atomic_inc_unchecked(&vcc->stats->tx_err);
30315 else
30316 - atomic_inc(&vcc->stats->tx);
30317 + atomic_inc_unchecked(&vcc->stats->tx);
30318 }
30319 }
30320
30321 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
30322 if (skb == NULL) {
30323 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
30324
30325 - atomic_inc(&vcc->stats->rx_drop);
30326 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30327 return -ENOMEM;
30328 }
30329
30330 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
30331
30332 dev_kfree_skb_any(skb);
30333
30334 - atomic_inc(&vcc->stats->rx_drop);
30335 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30336 return -ENOMEM;
30337 }
30338
30339 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
30340
30341 vcc->push(vcc, skb);
30342 - atomic_inc(&vcc->stats->rx);
30343 + atomic_inc_unchecked(&vcc->stats->rx);
30344
30345 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
30346
30347 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
30348 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
30349 fore200e->atm_dev->number,
30350 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
30351 - atomic_inc(&vcc->stats->rx_err);
30352 + atomic_inc_unchecked(&vcc->stats->rx_err);
30353 }
30354 }
30355
30356 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
30357 goto retry_here;
30358 }
30359
30360 - atomic_inc(&vcc->stats->tx_err);
30361 + atomic_inc_unchecked(&vcc->stats->tx_err);
30362
30363 fore200e->tx_sat++;
30364 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
30365 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
30366 index b182c2f..1c6fa8a 100644
30367 --- a/drivers/atm/he.c
30368 +++ b/drivers/atm/he.c
30369 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30370
30371 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
30372 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
30373 - atomic_inc(&vcc->stats->rx_drop);
30374 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30375 goto return_host_buffers;
30376 }
30377
30378 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30379 RBRQ_LEN_ERR(he_dev->rbrq_head)
30380 ? "LEN_ERR" : "",
30381 vcc->vpi, vcc->vci);
30382 - atomic_inc(&vcc->stats->rx_err);
30383 + atomic_inc_unchecked(&vcc->stats->rx_err);
30384 goto return_host_buffers;
30385 }
30386
30387 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30388 vcc->push(vcc, skb);
30389 spin_lock(&he_dev->global_lock);
30390
30391 - atomic_inc(&vcc->stats->rx);
30392 + atomic_inc_unchecked(&vcc->stats->rx);
30393
30394 return_host_buffers:
30395 ++pdus_assembled;
30396 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
30397 tpd->vcc->pop(tpd->vcc, tpd->skb);
30398 else
30399 dev_kfree_skb_any(tpd->skb);
30400 - atomic_inc(&tpd->vcc->stats->tx_err);
30401 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
30402 }
30403 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
30404 return;
30405 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30406 vcc->pop(vcc, skb);
30407 else
30408 dev_kfree_skb_any(skb);
30409 - atomic_inc(&vcc->stats->tx_err);
30410 + atomic_inc_unchecked(&vcc->stats->tx_err);
30411 return -EINVAL;
30412 }
30413
30414 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30415 vcc->pop(vcc, skb);
30416 else
30417 dev_kfree_skb_any(skb);
30418 - atomic_inc(&vcc->stats->tx_err);
30419 + atomic_inc_unchecked(&vcc->stats->tx_err);
30420 return -EINVAL;
30421 }
30422 #endif
30423 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30424 vcc->pop(vcc, skb);
30425 else
30426 dev_kfree_skb_any(skb);
30427 - atomic_inc(&vcc->stats->tx_err);
30428 + atomic_inc_unchecked(&vcc->stats->tx_err);
30429 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30430 return -ENOMEM;
30431 }
30432 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30433 vcc->pop(vcc, skb);
30434 else
30435 dev_kfree_skb_any(skb);
30436 - atomic_inc(&vcc->stats->tx_err);
30437 + atomic_inc_unchecked(&vcc->stats->tx_err);
30438 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30439 return -ENOMEM;
30440 }
30441 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30442 __enqueue_tpd(he_dev, tpd, cid);
30443 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30444
30445 - atomic_inc(&vcc->stats->tx);
30446 + atomic_inc_unchecked(&vcc->stats->tx);
30447
30448 return 0;
30449 }
30450 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
30451 index 7d01c2a..4e3ac01 100644
30452 --- a/drivers/atm/horizon.c
30453 +++ b/drivers/atm/horizon.c
30454 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
30455 {
30456 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
30457 // VC layer stats
30458 - atomic_inc(&vcc->stats->rx);
30459 + atomic_inc_unchecked(&vcc->stats->rx);
30460 __net_timestamp(skb);
30461 // end of our responsibility
30462 vcc->push (vcc, skb);
30463 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
30464 dev->tx_iovec = NULL;
30465
30466 // VC layer stats
30467 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30468 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30469
30470 // free the skb
30471 hrz_kfree_skb (skb);
30472 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
30473 index 8974bd2..b856f85 100644
30474 --- a/drivers/atm/idt77252.c
30475 +++ b/drivers/atm/idt77252.c
30476 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
30477 else
30478 dev_kfree_skb(skb);
30479
30480 - atomic_inc(&vcc->stats->tx);
30481 + atomic_inc_unchecked(&vcc->stats->tx);
30482 }
30483
30484 atomic_dec(&scq->used);
30485 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30486 if ((sb = dev_alloc_skb(64)) == NULL) {
30487 printk("%s: Can't allocate buffers for aal0.\n",
30488 card->name);
30489 - atomic_add(i, &vcc->stats->rx_drop);
30490 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
30491 break;
30492 }
30493 if (!atm_charge(vcc, sb->truesize)) {
30494 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
30495 card->name);
30496 - atomic_add(i - 1, &vcc->stats->rx_drop);
30497 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
30498 dev_kfree_skb(sb);
30499 break;
30500 }
30501 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30502 ATM_SKB(sb)->vcc = vcc;
30503 __net_timestamp(sb);
30504 vcc->push(vcc, sb);
30505 - atomic_inc(&vcc->stats->rx);
30506 + atomic_inc_unchecked(&vcc->stats->rx);
30507
30508 cell += ATM_CELL_PAYLOAD;
30509 }
30510 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30511 "(CDC: %08x)\n",
30512 card->name, len, rpp->len, readl(SAR_REG_CDC));
30513 recycle_rx_pool_skb(card, rpp);
30514 - atomic_inc(&vcc->stats->rx_err);
30515 + atomic_inc_unchecked(&vcc->stats->rx_err);
30516 return;
30517 }
30518 if (stat & SAR_RSQE_CRC) {
30519 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
30520 recycle_rx_pool_skb(card, rpp);
30521 - atomic_inc(&vcc->stats->rx_err);
30522 + atomic_inc_unchecked(&vcc->stats->rx_err);
30523 return;
30524 }
30525 if (skb_queue_len(&rpp->queue) > 1) {
30526 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30527 RXPRINTK("%s: Can't alloc RX skb.\n",
30528 card->name);
30529 recycle_rx_pool_skb(card, rpp);
30530 - atomic_inc(&vcc->stats->rx_err);
30531 + atomic_inc_unchecked(&vcc->stats->rx_err);
30532 return;
30533 }
30534 if (!atm_charge(vcc, skb->truesize)) {
30535 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30536 __net_timestamp(skb);
30537
30538 vcc->push(vcc, skb);
30539 - atomic_inc(&vcc->stats->rx);
30540 + atomic_inc_unchecked(&vcc->stats->rx);
30541
30542 return;
30543 }
30544 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30545 __net_timestamp(skb);
30546
30547 vcc->push(vcc, skb);
30548 - atomic_inc(&vcc->stats->rx);
30549 + atomic_inc_unchecked(&vcc->stats->rx);
30550
30551 if (skb->truesize > SAR_FB_SIZE_3)
30552 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
30553 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
30554 if (vcc->qos.aal != ATM_AAL0) {
30555 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
30556 card->name, vpi, vci);
30557 - atomic_inc(&vcc->stats->rx_drop);
30558 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30559 goto drop;
30560 }
30561
30562 if ((sb = dev_alloc_skb(64)) == NULL) {
30563 printk("%s: Can't allocate buffers for AAL0.\n",
30564 card->name);
30565 - atomic_inc(&vcc->stats->rx_err);
30566 + atomic_inc_unchecked(&vcc->stats->rx_err);
30567 goto drop;
30568 }
30569
30570 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
30571 ATM_SKB(sb)->vcc = vcc;
30572 __net_timestamp(sb);
30573 vcc->push(vcc, sb);
30574 - atomic_inc(&vcc->stats->rx);
30575 + atomic_inc_unchecked(&vcc->stats->rx);
30576
30577 drop:
30578 skb_pull(queue, 64);
30579 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30580
30581 if (vc == NULL) {
30582 printk("%s: NULL connection in send().\n", card->name);
30583 - atomic_inc(&vcc->stats->tx_err);
30584 + atomic_inc_unchecked(&vcc->stats->tx_err);
30585 dev_kfree_skb(skb);
30586 return -EINVAL;
30587 }
30588 if (!test_bit(VCF_TX, &vc->flags)) {
30589 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
30590 - atomic_inc(&vcc->stats->tx_err);
30591 + atomic_inc_unchecked(&vcc->stats->tx_err);
30592 dev_kfree_skb(skb);
30593 return -EINVAL;
30594 }
30595 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30596 break;
30597 default:
30598 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
30599 - atomic_inc(&vcc->stats->tx_err);
30600 + atomic_inc_unchecked(&vcc->stats->tx_err);
30601 dev_kfree_skb(skb);
30602 return -EINVAL;
30603 }
30604
30605 if (skb_shinfo(skb)->nr_frags != 0) {
30606 printk("%s: No scatter-gather yet.\n", card->name);
30607 - atomic_inc(&vcc->stats->tx_err);
30608 + atomic_inc_unchecked(&vcc->stats->tx_err);
30609 dev_kfree_skb(skb);
30610 return -EINVAL;
30611 }
30612 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30613
30614 err = queue_skb(card, vc, skb, oam);
30615 if (err) {
30616 - atomic_inc(&vcc->stats->tx_err);
30617 + atomic_inc_unchecked(&vcc->stats->tx_err);
30618 dev_kfree_skb(skb);
30619 return err;
30620 }
30621 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
30622 skb = dev_alloc_skb(64);
30623 if (!skb) {
30624 printk("%s: Out of memory in send_oam().\n", card->name);
30625 - atomic_inc(&vcc->stats->tx_err);
30626 + atomic_inc_unchecked(&vcc->stats->tx_err);
30627 return -ENOMEM;
30628 }
30629 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
30630 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
30631 index 96cce6d..62c3ec5 100644
30632 --- a/drivers/atm/iphase.c
30633 +++ b/drivers/atm/iphase.c
30634 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
30635 status = (u_short) (buf_desc_ptr->desc_mode);
30636 if (status & (RX_CER | RX_PTE | RX_OFL))
30637 {
30638 - atomic_inc(&vcc->stats->rx_err);
30639 + atomic_inc_unchecked(&vcc->stats->rx_err);
30640 IF_ERR(printk("IA: bad packet, dropping it");)
30641 if (status & RX_CER) {
30642 IF_ERR(printk(" cause: packet CRC error\n");)
30643 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
30644 len = dma_addr - buf_addr;
30645 if (len > iadev->rx_buf_sz) {
30646 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
30647 - atomic_inc(&vcc->stats->rx_err);
30648 + atomic_inc_unchecked(&vcc->stats->rx_err);
30649 goto out_free_desc;
30650 }
30651
30652 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30653 ia_vcc = INPH_IA_VCC(vcc);
30654 if (ia_vcc == NULL)
30655 {
30656 - atomic_inc(&vcc->stats->rx_err);
30657 + atomic_inc_unchecked(&vcc->stats->rx_err);
30658 atm_return(vcc, skb->truesize);
30659 dev_kfree_skb_any(skb);
30660 goto INCR_DLE;
30661 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30662 if ((length > iadev->rx_buf_sz) || (length >
30663 (skb->len - sizeof(struct cpcs_trailer))))
30664 {
30665 - atomic_inc(&vcc->stats->rx_err);
30666 + atomic_inc_unchecked(&vcc->stats->rx_err);
30667 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
30668 length, skb->len);)
30669 atm_return(vcc, skb->truesize);
30670 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30671
30672 IF_RX(printk("rx_dle_intr: skb push");)
30673 vcc->push(vcc,skb);
30674 - atomic_inc(&vcc->stats->rx);
30675 + atomic_inc_unchecked(&vcc->stats->rx);
30676 iadev->rx_pkt_cnt++;
30677 }
30678 INCR_DLE:
30679 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
30680 {
30681 struct k_sonet_stats *stats;
30682 stats = &PRIV(_ia_dev[board])->sonet_stats;
30683 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
30684 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
30685 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
30686 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
30687 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
30688 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
30689 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
30690 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
30691 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
30692 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
30693 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
30694 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
30695 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
30696 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
30697 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
30698 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
30699 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
30700 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
30701 }
30702 ia_cmds.status = 0;
30703 break;
30704 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30705 if ((desc == 0) || (desc > iadev->num_tx_desc))
30706 {
30707 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
30708 - atomic_inc(&vcc->stats->tx);
30709 + atomic_inc_unchecked(&vcc->stats->tx);
30710 if (vcc->pop)
30711 vcc->pop(vcc, skb);
30712 else
30713 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30714 ATM_DESC(skb) = vcc->vci;
30715 skb_queue_tail(&iadev->tx_dma_q, skb);
30716
30717 - atomic_inc(&vcc->stats->tx);
30718 + atomic_inc_unchecked(&vcc->stats->tx);
30719 iadev->tx_pkt_cnt++;
30720 /* Increment transaction counter */
30721 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
30722
30723 #if 0
30724 /* add flow control logic */
30725 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
30726 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
30727 if (iavcc->vc_desc_cnt > 10) {
30728 vcc->tx_quota = vcc->tx_quota * 3 / 4;
30729 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
30730 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
30731 index 68c7588..7036683 100644
30732 --- a/drivers/atm/lanai.c
30733 +++ b/drivers/atm/lanai.c
30734 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
30735 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
30736 lanai_endtx(lanai, lvcc);
30737 lanai_free_skb(lvcc->tx.atmvcc, skb);
30738 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
30739 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
30740 }
30741
30742 /* Try to fill the buffer - don't call unless there is backlog */
30743 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
30744 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
30745 __net_timestamp(skb);
30746 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
30747 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
30748 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
30749 out:
30750 lvcc->rx.buf.ptr = end;
30751 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
30752 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30753 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
30754 "vcc %d\n", lanai->number, (unsigned int) s, vci);
30755 lanai->stats.service_rxnotaal5++;
30756 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30757 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30758 return 0;
30759 }
30760 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
30761 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30762 int bytes;
30763 read_unlock(&vcc_sklist_lock);
30764 DPRINTK("got trashed rx pdu on vci %d\n", vci);
30765 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30766 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30767 lvcc->stats.x.aal5.service_trash++;
30768 bytes = (SERVICE_GET_END(s) * 16) -
30769 (((unsigned long) lvcc->rx.buf.ptr) -
30770 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30771 }
30772 if (s & SERVICE_STREAM) {
30773 read_unlock(&vcc_sklist_lock);
30774 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30775 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30776 lvcc->stats.x.aal5.service_stream++;
30777 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
30778 "PDU on VCI %d!\n", lanai->number, vci);
30779 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30780 return 0;
30781 }
30782 DPRINTK("got rx crc error on vci %d\n", vci);
30783 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30784 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30785 lvcc->stats.x.aal5.service_rxcrc++;
30786 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
30787 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
30788 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
30789 index 1c70c45..300718d 100644
30790 --- a/drivers/atm/nicstar.c
30791 +++ b/drivers/atm/nicstar.c
30792 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30793 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
30794 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
30795 card->index);
30796 - atomic_inc(&vcc->stats->tx_err);
30797 + atomic_inc_unchecked(&vcc->stats->tx_err);
30798 dev_kfree_skb_any(skb);
30799 return -EINVAL;
30800 }
30801 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30802 if (!vc->tx) {
30803 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
30804 card->index);
30805 - atomic_inc(&vcc->stats->tx_err);
30806 + atomic_inc_unchecked(&vcc->stats->tx_err);
30807 dev_kfree_skb_any(skb);
30808 return -EINVAL;
30809 }
30810 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30811 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
30812 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
30813 card->index);
30814 - atomic_inc(&vcc->stats->tx_err);
30815 + atomic_inc_unchecked(&vcc->stats->tx_err);
30816 dev_kfree_skb_any(skb);
30817 return -EINVAL;
30818 }
30819
30820 if (skb_shinfo(skb)->nr_frags != 0) {
30821 printk("nicstar%d: No scatter-gather yet.\n", card->index);
30822 - atomic_inc(&vcc->stats->tx_err);
30823 + atomic_inc_unchecked(&vcc->stats->tx_err);
30824 dev_kfree_skb_any(skb);
30825 return -EINVAL;
30826 }
30827 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30828 }
30829
30830 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
30831 - atomic_inc(&vcc->stats->tx_err);
30832 + atomic_inc_unchecked(&vcc->stats->tx_err);
30833 dev_kfree_skb_any(skb);
30834 return -EIO;
30835 }
30836 - atomic_inc(&vcc->stats->tx);
30837 + atomic_inc_unchecked(&vcc->stats->tx);
30838
30839 return 0;
30840 }
30841 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30842 printk
30843 ("nicstar%d: Can't allocate buffers for aal0.\n",
30844 card->index);
30845 - atomic_add(i, &vcc->stats->rx_drop);
30846 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
30847 break;
30848 }
30849 if (!atm_charge(vcc, sb->truesize)) {
30850 RXPRINTK
30851 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
30852 card->index);
30853 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30854 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30855 dev_kfree_skb_any(sb);
30856 break;
30857 }
30858 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30859 ATM_SKB(sb)->vcc = vcc;
30860 __net_timestamp(sb);
30861 vcc->push(vcc, sb);
30862 - atomic_inc(&vcc->stats->rx);
30863 + atomic_inc_unchecked(&vcc->stats->rx);
30864 cell += ATM_CELL_PAYLOAD;
30865 }
30866
30867 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30868 if (iovb == NULL) {
30869 printk("nicstar%d: Out of iovec buffers.\n",
30870 card->index);
30871 - atomic_inc(&vcc->stats->rx_drop);
30872 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30873 recycle_rx_buf(card, skb);
30874 return;
30875 }
30876 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30877 small or large buffer itself. */
30878 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
30879 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
30880 - atomic_inc(&vcc->stats->rx_err);
30881 + atomic_inc_unchecked(&vcc->stats->rx_err);
30882 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30883 NS_MAX_IOVECS);
30884 NS_PRV_IOVCNT(iovb) = 0;
30885 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30886 ("nicstar%d: Expected a small buffer, and this is not one.\n",
30887 card->index);
30888 which_list(card, skb);
30889 - atomic_inc(&vcc->stats->rx_err);
30890 + atomic_inc_unchecked(&vcc->stats->rx_err);
30891 recycle_rx_buf(card, skb);
30892 vc->rx_iov = NULL;
30893 recycle_iov_buf(card, iovb);
30894 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30895 ("nicstar%d: Expected a large buffer, and this is not one.\n",
30896 card->index);
30897 which_list(card, skb);
30898 - atomic_inc(&vcc->stats->rx_err);
30899 + atomic_inc_unchecked(&vcc->stats->rx_err);
30900 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30901 NS_PRV_IOVCNT(iovb));
30902 vc->rx_iov = NULL;
30903 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30904 printk(" - PDU size mismatch.\n");
30905 else
30906 printk(".\n");
30907 - atomic_inc(&vcc->stats->rx_err);
30908 + atomic_inc_unchecked(&vcc->stats->rx_err);
30909 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30910 NS_PRV_IOVCNT(iovb));
30911 vc->rx_iov = NULL;
30912 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30913 /* skb points to a small buffer */
30914 if (!atm_charge(vcc, skb->truesize)) {
30915 push_rxbufs(card, skb);
30916 - atomic_inc(&vcc->stats->rx_drop);
30917 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30918 } else {
30919 skb_put(skb, len);
30920 dequeue_sm_buf(card, skb);
30921 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30922 ATM_SKB(skb)->vcc = vcc;
30923 __net_timestamp(skb);
30924 vcc->push(vcc, skb);
30925 - atomic_inc(&vcc->stats->rx);
30926 + atomic_inc_unchecked(&vcc->stats->rx);
30927 }
30928 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
30929 struct sk_buff *sb;
30930 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30931 if (len <= NS_SMBUFSIZE) {
30932 if (!atm_charge(vcc, sb->truesize)) {
30933 push_rxbufs(card, sb);
30934 - atomic_inc(&vcc->stats->rx_drop);
30935 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30936 } else {
30937 skb_put(sb, len);
30938 dequeue_sm_buf(card, sb);
30939 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30940 ATM_SKB(sb)->vcc = vcc;
30941 __net_timestamp(sb);
30942 vcc->push(vcc, sb);
30943 - atomic_inc(&vcc->stats->rx);
30944 + atomic_inc_unchecked(&vcc->stats->rx);
30945 }
30946
30947 push_rxbufs(card, skb);
30948 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30949
30950 if (!atm_charge(vcc, skb->truesize)) {
30951 push_rxbufs(card, skb);
30952 - atomic_inc(&vcc->stats->rx_drop);
30953 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30954 } else {
30955 dequeue_lg_buf(card, skb);
30956 #ifdef NS_USE_DESTRUCTORS
30957 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30958 ATM_SKB(skb)->vcc = vcc;
30959 __net_timestamp(skb);
30960 vcc->push(vcc, skb);
30961 - atomic_inc(&vcc->stats->rx);
30962 + atomic_inc_unchecked(&vcc->stats->rx);
30963 }
30964
30965 push_rxbufs(card, sb);
30966 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30967 printk
30968 ("nicstar%d: Out of huge buffers.\n",
30969 card->index);
30970 - atomic_inc(&vcc->stats->rx_drop);
30971 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30972 recycle_iovec_rx_bufs(card,
30973 (struct iovec *)
30974 iovb->data,
30975 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30976 card->hbpool.count++;
30977 } else
30978 dev_kfree_skb_any(hb);
30979 - atomic_inc(&vcc->stats->rx_drop);
30980 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30981 } else {
30982 /* Copy the small buffer to the huge buffer */
30983 sb = (struct sk_buff *)iov->iov_base;
30984 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30985 #endif /* NS_USE_DESTRUCTORS */
30986 __net_timestamp(hb);
30987 vcc->push(vcc, hb);
30988 - atomic_inc(&vcc->stats->rx);
30989 + atomic_inc_unchecked(&vcc->stats->rx);
30990 }
30991 }
30992
30993 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
30994 index 1853a45..cf2426d 100644
30995 --- a/drivers/atm/solos-pci.c
30996 +++ b/drivers/atm/solos-pci.c
30997 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
30998 }
30999 atm_charge(vcc, skb->truesize);
31000 vcc->push(vcc, skb);
31001 - atomic_inc(&vcc->stats->rx);
31002 + atomic_inc_unchecked(&vcc->stats->rx);
31003 break;
31004
31005 case PKT_STATUS:
31006 @@ -1010,7 +1010,7 @@ static uint32_t fpga_tx(struct solos_card *card)
31007 vcc = SKB_CB(oldskb)->vcc;
31008
31009 if (vcc) {
31010 - atomic_inc(&vcc->stats->tx);
31011 + atomic_inc_unchecked(&vcc->stats->tx);
31012 solos_pop(vcc, oldskb);
31013 } else
31014 dev_kfree_skb_irq(oldskb);
31015 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
31016 index 0215934..ce9f5b1 100644
31017 --- a/drivers/atm/suni.c
31018 +++ b/drivers/atm/suni.c
31019 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
31020
31021
31022 #define ADD_LIMITED(s,v) \
31023 - atomic_add((v),&stats->s); \
31024 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
31025 + atomic_add_unchecked((v),&stats->s); \
31026 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
31027
31028
31029 static void suni_hz(unsigned long from_timer)
31030 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
31031 index 5120a96..e2572bd 100644
31032 --- a/drivers/atm/uPD98402.c
31033 +++ b/drivers/atm/uPD98402.c
31034 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
31035 struct sonet_stats tmp;
31036 int error = 0;
31037
31038 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
31039 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
31040 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
31041 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
31042 if (zero && !error) {
31043 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
31044
31045
31046 #define ADD_LIMITED(s,v) \
31047 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
31048 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
31049 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31050 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
31051 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
31052 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31053
31054
31055 static void stat_event(struct atm_dev *dev)
31056 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
31057 if (reason & uPD98402_INT_PFM) stat_event(dev);
31058 if (reason & uPD98402_INT_PCO) {
31059 (void) GET(PCOCR); /* clear interrupt cause */
31060 - atomic_add(GET(HECCT),
31061 + atomic_add_unchecked(GET(HECCT),
31062 &PRIV(dev)->sonet_stats.uncorr_hcs);
31063 }
31064 if ((reason & uPD98402_INT_RFO) &&
31065 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
31066 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
31067 uPD98402_INT_LOS),PIMR); /* enable them */
31068 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
31069 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31070 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
31071 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
31072 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31073 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
31074 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
31075 return 0;
31076 }
31077
31078 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
31079 index abe4e20..83c4727 100644
31080 --- a/drivers/atm/zatm.c
31081 +++ b/drivers/atm/zatm.c
31082 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
31083 }
31084 if (!size) {
31085 dev_kfree_skb_irq(skb);
31086 - if (vcc) atomic_inc(&vcc->stats->rx_err);
31087 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
31088 continue;
31089 }
31090 if (!atm_charge(vcc,skb->truesize)) {
31091 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
31092 skb->len = size;
31093 ATM_SKB(skb)->vcc = vcc;
31094 vcc->push(vcc,skb);
31095 - atomic_inc(&vcc->stats->rx);
31096 + atomic_inc_unchecked(&vcc->stats->rx);
31097 }
31098 zout(pos & 0xffff,MTA(mbx));
31099 #if 0 /* probably a stupid idea */
31100 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
31101 skb_queue_head(&zatm_vcc->backlog,skb);
31102 break;
31103 }
31104 - atomic_inc(&vcc->stats->tx);
31105 + atomic_inc_unchecked(&vcc->stats->tx);
31106 wake_up(&zatm_vcc->tx_wait);
31107 }
31108
31109 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
31110 index 147d1a4..d0fd4b0 100644
31111 --- a/drivers/base/devtmpfs.c
31112 +++ b/drivers/base/devtmpfs.c
31113 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
31114 if (!thread)
31115 return 0;
31116
31117 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
31118 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
31119 if (err)
31120 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
31121 else
31122 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
31123 index e6ee5e8..98ad7fc 100644
31124 --- a/drivers/base/power/wakeup.c
31125 +++ b/drivers/base/power/wakeup.c
31126 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
31127 * They need to be modified together atomically, so it's better to use one
31128 * atomic variable to hold them both.
31129 */
31130 -static atomic_t combined_event_count = ATOMIC_INIT(0);
31131 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
31132
31133 #define IN_PROGRESS_BITS (sizeof(int) * 4)
31134 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
31135
31136 static void split_counters(unsigned int *cnt, unsigned int *inpr)
31137 {
31138 - unsigned int comb = atomic_read(&combined_event_count);
31139 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
31140
31141 *cnt = (comb >> IN_PROGRESS_BITS);
31142 *inpr = comb & MAX_IN_PROGRESS;
31143 @@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
31144 ws->start_prevent_time = ws->last_time;
31145
31146 /* Increment the counter of events in progress. */
31147 - cec = atomic_inc_return(&combined_event_count);
31148 + cec = atomic_inc_return_unchecked(&combined_event_count);
31149
31150 trace_wakeup_source_activate(ws->name, cec);
31151 }
31152 @@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
31153 * Increment the counter of registered wakeup events and decrement the
31154 * couter of wakeup events in progress simultaneously.
31155 */
31156 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
31157 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
31158 trace_wakeup_source_deactivate(ws->name, cec);
31159
31160 split_counters(&cnt, &inpr);
31161 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
31162 index ca83f96..69d4ea9 100644
31163 --- a/drivers/block/cciss.c
31164 +++ b/drivers/block/cciss.c
31165 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
31166 int err;
31167 u32 cp;
31168
31169 + memset(&arg64, 0, sizeof(arg64));
31170 +
31171 err = 0;
31172 err |=
31173 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
31174 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
31175 while (!list_empty(&h->reqQ)) {
31176 c = list_entry(h->reqQ.next, CommandList_struct, list);
31177 /* can't do anything if fifo is full */
31178 - if ((h->access.fifo_full(h))) {
31179 + if ((h->access->fifo_full(h))) {
31180 dev_warn(&h->pdev->dev, "fifo full\n");
31181 break;
31182 }
31183 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
31184 h->Qdepth--;
31185
31186 /* Tell the controller execute command */
31187 - h->access.submit_command(h, c);
31188 + h->access->submit_command(h, c);
31189
31190 /* Put job onto the completed Q */
31191 addQ(&h->cmpQ, c);
31192 @@ -3443,17 +3445,17 @@ startio:
31193
31194 static inline unsigned long get_next_completion(ctlr_info_t *h)
31195 {
31196 - return h->access.command_completed(h);
31197 + return h->access->command_completed(h);
31198 }
31199
31200 static inline int interrupt_pending(ctlr_info_t *h)
31201 {
31202 - return h->access.intr_pending(h);
31203 + return h->access->intr_pending(h);
31204 }
31205
31206 static inline long interrupt_not_for_us(ctlr_info_t *h)
31207 {
31208 - return ((h->access.intr_pending(h) == 0) ||
31209 + return ((h->access->intr_pending(h) == 0) ||
31210 (h->interrupts_enabled == 0));
31211 }
31212
31213 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
31214 u32 a;
31215
31216 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
31217 - return h->access.command_completed(h);
31218 + return h->access->command_completed(h);
31219
31220 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
31221 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
31222 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
31223 trans_support & CFGTBL_Trans_use_short_tags);
31224
31225 /* Change the access methods to the performant access methods */
31226 - h->access = SA5_performant_access;
31227 + h->access = &SA5_performant_access;
31228 h->transMethod = CFGTBL_Trans_Performant;
31229
31230 return;
31231 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
31232 if (prod_index < 0)
31233 return -ENODEV;
31234 h->product_name = products[prod_index].product_name;
31235 - h->access = *(products[prod_index].access);
31236 + h->access = products[prod_index].access;
31237
31238 if (cciss_board_disabled(h)) {
31239 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
31240 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
31241 }
31242
31243 /* make sure the board interrupts are off */
31244 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31245 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31246 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
31247 if (rc)
31248 goto clean2;
31249 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
31250 * fake ones to scoop up any residual completions.
31251 */
31252 spin_lock_irqsave(&h->lock, flags);
31253 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31254 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31255 spin_unlock_irqrestore(&h->lock, flags);
31256 free_irq(h->intr[h->intr_mode], h);
31257 rc = cciss_request_irq(h, cciss_msix_discard_completions,
31258 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
31259 dev_info(&h->pdev->dev, "Board READY.\n");
31260 dev_info(&h->pdev->dev,
31261 "Waiting for stale completions to drain.\n");
31262 - h->access.set_intr_mask(h, CCISS_INTR_ON);
31263 + h->access->set_intr_mask(h, CCISS_INTR_ON);
31264 msleep(10000);
31265 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31266 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31267
31268 rc = controller_reset_failed(h->cfgtable);
31269 if (rc)
31270 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
31271 cciss_scsi_setup(h);
31272
31273 /* Turn the interrupts on so we can service requests */
31274 - h->access.set_intr_mask(h, CCISS_INTR_ON);
31275 + h->access->set_intr_mask(h, CCISS_INTR_ON);
31276
31277 /* Get the firmware version */
31278 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
31279 @@ -5210,7 +5212,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
31280 kfree(flush_buf);
31281 if (return_code != IO_OK)
31282 dev_warn(&h->pdev->dev, "Error flushing cache\n");
31283 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31284 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31285 free_irq(h->intr[h->intr_mode], h);
31286 }
31287
31288 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
31289 index 7fda30e..eb5dfe0 100644
31290 --- a/drivers/block/cciss.h
31291 +++ b/drivers/block/cciss.h
31292 @@ -101,7 +101,7 @@ struct ctlr_info
31293 /* information about each logical volume */
31294 drive_info_struct *drv[CISS_MAX_LUN];
31295
31296 - struct access_method access;
31297 + struct access_method *access;
31298
31299 /* queue and queue Info */
31300 struct list_head reqQ;
31301 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
31302 index 9125bbe..eede5c8 100644
31303 --- a/drivers/block/cpqarray.c
31304 +++ b/drivers/block/cpqarray.c
31305 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
31306 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
31307 goto Enomem4;
31308 }
31309 - hba[i]->access.set_intr_mask(hba[i], 0);
31310 + hba[i]->access->set_intr_mask(hba[i], 0);
31311 if (request_irq(hba[i]->intr, do_ida_intr,
31312 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
31313 {
31314 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
31315 add_timer(&hba[i]->timer);
31316
31317 /* Enable IRQ now that spinlock and rate limit timer are set up */
31318 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
31319 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
31320
31321 for(j=0; j<NWD; j++) {
31322 struct gendisk *disk = ida_gendisk[i][j];
31323 @@ -694,7 +694,7 @@ DBGINFO(
31324 for(i=0; i<NR_PRODUCTS; i++) {
31325 if (board_id == products[i].board_id) {
31326 c->product_name = products[i].product_name;
31327 - c->access = *(products[i].access);
31328 + c->access = products[i].access;
31329 break;
31330 }
31331 }
31332 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
31333 hba[ctlr]->intr = intr;
31334 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
31335 hba[ctlr]->product_name = products[j].product_name;
31336 - hba[ctlr]->access = *(products[j].access);
31337 + hba[ctlr]->access = products[j].access;
31338 hba[ctlr]->ctlr = ctlr;
31339 hba[ctlr]->board_id = board_id;
31340 hba[ctlr]->pci_dev = NULL; /* not PCI */
31341 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
31342
31343 while((c = h->reqQ) != NULL) {
31344 /* Can't do anything if we're busy */
31345 - if (h->access.fifo_full(h) == 0)
31346 + if (h->access->fifo_full(h) == 0)
31347 return;
31348
31349 /* Get the first entry from the request Q */
31350 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
31351 h->Qdepth--;
31352
31353 /* Tell the controller to do our bidding */
31354 - h->access.submit_command(h, c);
31355 + h->access->submit_command(h, c);
31356
31357 /* Get onto the completion Q */
31358 addQ(&h->cmpQ, c);
31359 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
31360 unsigned long flags;
31361 __u32 a,a1;
31362
31363 - istat = h->access.intr_pending(h);
31364 + istat = h->access->intr_pending(h);
31365 /* Is this interrupt for us? */
31366 if (istat == 0)
31367 return IRQ_NONE;
31368 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
31369 */
31370 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
31371 if (istat & FIFO_NOT_EMPTY) {
31372 - while((a = h->access.command_completed(h))) {
31373 + while((a = h->access->command_completed(h))) {
31374 a1 = a; a &= ~3;
31375 if ((c = h->cmpQ) == NULL)
31376 {
31377 @@ -1449,11 +1449,11 @@ static int sendcmd(
31378 /*
31379 * Disable interrupt
31380 */
31381 - info_p->access.set_intr_mask(info_p, 0);
31382 + info_p->access->set_intr_mask(info_p, 0);
31383 /* Make sure there is room in the command FIFO */
31384 /* Actually it should be completely empty at this time. */
31385 for (i = 200000; i > 0; i--) {
31386 - temp = info_p->access.fifo_full(info_p);
31387 + temp = info_p->access->fifo_full(info_p);
31388 if (temp != 0) {
31389 break;
31390 }
31391 @@ -1466,7 +1466,7 @@ DBG(
31392 /*
31393 * Send the cmd
31394 */
31395 - info_p->access.submit_command(info_p, c);
31396 + info_p->access->submit_command(info_p, c);
31397 complete = pollcomplete(ctlr);
31398
31399 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
31400 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
31401 * we check the new geometry. Then turn interrupts back on when
31402 * we're done.
31403 */
31404 - host->access.set_intr_mask(host, 0);
31405 + host->access->set_intr_mask(host, 0);
31406 getgeometry(ctlr);
31407 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
31408 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
31409
31410 for(i=0; i<NWD; i++) {
31411 struct gendisk *disk = ida_gendisk[ctlr][i];
31412 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
31413 /* Wait (up to 2 seconds) for a command to complete */
31414
31415 for (i = 200000; i > 0; i--) {
31416 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
31417 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
31418 if (done == 0) {
31419 udelay(10); /* a short fixed delay */
31420 } else
31421 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
31422 index be73e9d..7fbf140 100644
31423 --- a/drivers/block/cpqarray.h
31424 +++ b/drivers/block/cpqarray.h
31425 @@ -99,7 +99,7 @@ struct ctlr_info {
31426 drv_info_t drv[NWD];
31427 struct proc_dir_entry *proc;
31428
31429 - struct access_method access;
31430 + struct access_method *access;
31431
31432 cmdlist_t *reqQ;
31433 cmdlist_t *cmpQ;
31434 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
31435 index b953cc7..e3dc580 100644
31436 --- a/drivers/block/drbd/drbd_int.h
31437 +++ b/drivers/block/drbd/drbd_int.h
31438 @@ -735,7 +735,7 @@ struct drbd_request;
31439 struct drbd_epoch {
31440 struct list_head list;
31441 unsigned int barrier_nr;
31442 - atomic_t epoch_size; /* increased on every request added. */
31443 + atomic_unchecked_t epoch_size; /* increased on every request added. */
31444 atomic_t active; /* increased on every req. added, and dec on every finished. */
31445 unsigned long flags;
31446 };
31447 @@ -1116,7 +1116,7 @@ struct drbd_conf {
31448 void *int_dig_in;
31449 void *int_dig_vv;
31450 wait_queue_head_t seq_wait;
31451 - atomic_t packet_seq;
31452 + atomic_unchecked_t packet_seq;
31453 unsigned int peer_seq;
31454 spinlock_t peer_seq_lock;
31455 unsigned int minor;
31456 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
31457
31458 static inline void drbd_tcp_cork(struct socket *sock)
31459 {
31460 - int __user val = 1;
31461 + int val = 1;
31462 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31463 - (char __user *)&val, sizeof(val));
31464 + (char __force_user *)&val, sizeof(val));
31465 }
31466
31467 static inline void drbd_tcp_uncork(struct socket *sock)
31468 {
31469 - int __user val = 0;
31470 + int val = 0;
31471 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31472 - (char __user *)&val, sizeof(val));
31473 + (char __force_user *)&val, sizeof(val));
31474 }
31475
31476 static inline void drbd_tcp_nodelay(struct socket *sock)
31477 {
31478 - int __user val = 1;
31479 + int val = 1;
31480 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
31481 - (char __user *)&val, sizeof(val));
31482 + (char __force_user *)&val, sizeof(val));
31483 }
31484
31485 static inline void drbd_tcp_quickack(struct socket *sock)
31486 {
31487 - int __user val = 2;
31488 + int val = 2;
31489 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
31490 - (char __user *)&val, sizeof(val));
31491 + (char __force_user *)&val, sizeof(val));
31492 }
31493
31494 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
31495 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
31496 index f55683a..2101b96 100644
31497 --- a/drivers/block/drbd/drbd_main.c
31498 +++ b/drivers/block/drbd/drbd_main.c
31499 @@ -2556,7 +2556,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
31500 p.sector = sector;
31501 p.block_id = block_id;
31502 p.blksize = blksize;
31503 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31504 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31505
31506 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
31507 return false;
31508 @@ -2854,7 +2854,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
31509
31510 p.sector = cpu_to_be64(req->sector);
31511 p.block_id = (unsigned long)req;
31512 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31513 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31514
31515 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
31516
31517 @@ -3139,7 +3139,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
31518 atomic_set(&mdev->unacked_cnt, 0);
31519 atomic_set(&mdev->local_cnt, 0);
31520 atomic_set(&mdev->net_cnt, 0);
31521 - atomic_set(&mdev->packet_seq, 0);
31522 + atomic_set_unchecked(&mdev->packet_seq, 0);
31523 atomic_set(&mdev->pp_in_use, 0);
31524 atomic_set(&mdev->pp_in_use_by_net, 0);
31525 atomic_set(&mdev->rs_sect_in, 0);
31526 @@ -3221,8 +3221,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
31527 mdev->receiver.t_state);
31528
31529 /* no need to lock it, I'm the only thread alive */
31530 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
31531 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
31532 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
31533 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
31534 mdev->al_writ_cnt =
31535 mdev->bm_writ_cnt =
31536 mdev->read_cnt =
31537 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
31538 index edb490a..ecd69da 100644
31539 --- a/drivers/block/drbd/drbd_nl.c
31540 +++ b/drivers/block/drbd/drbd_nl.c
31541 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
31542 module_put(THIS_MODULE);
31543 }
31544
31545 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31546 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31547
31548 static unsigned short *
31549 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
31550 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
31551 cn_reply->id.idx = CN_IDX_DRBD;
31552 cn_reply->id.val = CN_VAL_DRBD;
31553
31554 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31555 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31556 cn_reply->ack = 0; /* not used here. */
31557 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31558 (int)((char *)tl - (char *)reply->tag_list);
31559 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
31560 cn_reply->id.idx = CN_IDX_DRBD;
31561 cn_reply->id.val = CN_VAL_DRBD;
31562
31563 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31564 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31565 cn_reply->ack = 0; /* not used here. */
31566 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31567 (int)((char *)tl - (char *)reply->tag_list);
31568 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
31569 cn_reply->id.idx = CN_IDX_DRBD;
31570 cn_reply->id.val = CN_VAL_DRBD;
31571
31572 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
31573 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
31574 cn_reply->ack = 0; // not used here.
31575 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31576 (int)((char*)tl - (char*)reply->tag_list);
31577 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
31578 cn_reply->id.idx = CN_IDX_DRBD;
31579 cn_reply->id.val = CN_VAL_DRBD;
31580
31581 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31582 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31583 cn_reply->ack = 0; /* not used here. */
31584 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31585 (int)((char *)tl - (char *)reply->tag_list);
31586 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
31587 index c74ca2d..860c819 100644
31588 --- a/drivers/block/drbd/drbd_receiver.c
31589 +++ b/drivers/block/drbd/drbd_receiver.c
31590 @@ -898,7 +898,7 @@ retry:
31591 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
31592 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
31593
31594 - atomic_set(&mdev->packet_seq, 0);
31595 + atomic_set_unchecked(&mdev->packet_seq, 0);
31596 mdev->peer_seq = 0;
31597
31598 if (drbd_send_protocol(mdev) == -1)
31599 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31600 do {
31601 next_epoch = NULL;
31602
31603 - epoch_size = atomic_read(&epoch->epoch_size);
31604 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
31605
31606 switch (ev & ~EV_CLEANUP) {
31607 case EV_PUT:
31608 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31609 rv = FE_DESTROYED;
31610 } else {
31611 epoch->flags = 0;
31612 - atomic_set(&epoch->epoch_size, 0);
31613 + atomic_set_unchecked(&epoch->epoch_size, 0);
31614 /* atomic_set(&epoch->active, 0); is already zero */
31615 if (rv == FE_STILL_LIVE)
31616 rv = FE_RECYCLED;
31617 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31618 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
31619 drbd_flush(mdev);
31620
31621 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
31622 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31623 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
31624 if (epoch)
31625 break;
31626 }
31627
31628 epoch = mdev->current_epoch;
31629 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
31630 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
31631
31632 D_ASSERT(atomic_read(&epoch->active) == 0);
31633 D_ASSERT(epoch->flags == 0);
31634 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31635 }
31636
31637 epoch->flags = 0;
31638 - atomic_set(&epoch->epoch_size, 0);
31639 + atomic_set_unchecked(&epoch->epoch_size, 0);
31640 atomic_set(&epoch->active, 0);
31641
31642 spin_lock(&mdev->epoch_lock);
31643 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
31644 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31645 list_add(&epoch->list, &mdev->current_epoch->list);
31646 mdev->current_epoch = epoch;
31647 mdev->epochs++;
31648 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31649 spin_unlock(&mdev->peer_seq_lock);
31650
31651 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
31652 - atomic_inc(&mdev->current_epoch->epoch_size);
31653 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
31654 return drbd_drain_block(mdev, data_size);
31655 }
31656
31657 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31658
31659 spin_lock(&mdev->epoch_lock);
31660 e->epoch = mdev->current_epoch;
31661 - atomic_inc(&e->epoch->epoch_size);
31662 + atomic_inc_unchecked(&e->epoch->epoch_size);
31663 atomic_inc(&e->epoch->active);
31664 spin_unlock(&mdev->epoch_lock);
31665
31666 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
31667 D_ASSERT(list_empty(&mdev->done_ee));
31668
31669 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
31670 - atomic_set(&mdev->current_epoch->epoch_size, 0);
31671 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
31672 D_ASSERT(list_empty(&mdev->current_epoch->list));
31673 }
31674
31675 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
31676 index 54046e5..7759c55 100644
31677 --- a/drivers/block/loop.c
31678 +++ b/drivers/block/loop.c
31679 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
31680 mm_segment_t old_fs = get_fs();
31681
31682 set_fs(get_ds());
31683 - bw = file->f_op->write(file, buf, len, &pos);
31684 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
31685 set_fs(old_fs);
31686 if (likely(bw == len))
31687 return 0;
31688 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
31689 index d620b44..587561e 100644
31690 --- a/drivers/cdrom/cdrom.c
31691 +++ b/drivers/cdrom/cdrom.c
31692 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
31693 ENSURE(reset, CDC_RESET);
31694 ENSURE(generic_packet, CDC_GENERIC_PACKET);
31695 cdi->mc_flags = 0;
31696 - cdo->n_minors = 0;
31697 cdi->options = CDO_USE_FFLAGS;
31698
31699 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
31700 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
31701 else
31702 cdi->cdda_method = CDDA_OLD;
31703
31704 - if (!cdo->generic_packet)
31705 - cdo->generic_packet = cdrom_dummy_generic_packet;
31706 + if (!cdo->generic_packet) {
31707 + pax_open_kernel();
31708 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
31709 + pax_close_kernel();
31710 + }
31711
31712 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
31713 mutex_lock(&cdrom_mutex);
31714 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
31715 if (cdi->exit)
31716 cdi->exit(cdi);
31717
31718 - cdi->ops->n_minors--;
31719 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
31720 }
31721
31722 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
31723 index 75d485a..2809958 100644
31724 --- a/drivers/cdrom/gdrom.c
31725 +++ b/drivers/cdrom/gdrom.c
31726 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
31727 .audio_ioctl = gdrom_audio_ioctl,
31728 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
31729 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
31730 - .n_minors = 1,
31731 };
31732
31733 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
31734 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
31735 index 72bedad..8181ce1 100644
31736 --- a/drivers/char/Kconfig
31737 +++ b/drivers/char/Kconfig
31738 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
31739
31740 config DEVKMEM
31741 bool "/dev/kmem virtual device support"
31742 - default y
31743 + default n
31744 + depends on !GRKERNSEC_KMEM
31745 help
31746 Say Y here if you want to support the /dev/kmem device. The
31747 /dev/kmem device is rarely used, but can be used for certain
31748 @@ -581,6 +582,7 @@ config DEVPORT
31749 bool
31750 depends on !M68K
31751 depends on ISA || PCI
31752 + depends on !GRKERNSEC_KMEM
31753 default y
31754
31755 source "drivers/s390/char/Kconfig"
31756 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
31757 index 2e04433..22afc64 100644
31758 --- a/drivers/char/agp/frontend.c
31759 +++ b/drivers/char/agp/frontend.c
31760 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
31761 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
31762 return -EFAULT;
31763
31764 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
31765 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
31766 return -EFAULT;
31767
31768 client = agp_find_client_by_pid(reserve.pid);
31769 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
31770 index 21cb980..f15107c 100644
31771 --- a/drivers/char/genrtc.c
31772 +++ b/drivers/char/genrtc.c
31773 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
31774 switch (cmd) {
31775
31776 case RTC_PLL_GET:
31777 + memset(&pll, 0, sizeof(pll));
31778 if (get_rtc_pll(&pll))
31779 return -EINVAL;
31780 else
31781 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
31782 index dfd7876..c0b0885 100644
31783 --- a/drivers/char/hpet.c
31784 +++ b/drivers/char/hpet.c
31785 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
31786 }
31787
31788 static int
31789 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
31790 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
31791 struct hpet_info *info)
31792 {
31793 struct hpet_timer __iomem *timer;
31794 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
31795 index a0c84bb..9edcf60 100644
31796 --- a/drivers/char/ipmi/ipmi_msghandler.c
31797 +++ b/drivers/char/ipmi/ipmi_msghandler.c
31798 @@ -420,7 +420,7 @@ struct ipmi_smi {
31799 struct proc_dir_entry *proc_dir;
31800 char proc_dir_name[10];
31801
31802 - atomic_t stats[IPMI_NUM_STATS];
31803 + atomic_unchecked_t stats[IPMI_NUM_STATS];
31804
31805 /*
31806 * run_to_completion duplicate of smb_info, smi_info
31807 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
31808
31809
31810 #define ipmi_inc_stat(intf, stat) \
31811 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
31812 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
31813 #define ipmi_get_stat(intf, stat) \
31814 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
31815 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
31816
31817 static int is_lan_addr(struct ipmi_addr *addr)
31818 {
31819 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
31820 INIT_LIST_HEAD(&intf->cmd_rcvrs);
31821 init_waitqueue_head(&intf->waitq);
31822 for (i = 0; i < IPMI_NUM_STATS; i++)
31823 - atomic_set(&intf->stats[i], 0);
31824 + atomic_set_unchecked(&intf->stats[i], 0);
31825
31826 intf->proc_dir = NULL;
31827
31828 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
31829 index 32a6c7e..f6966a9 100644
31830 --- a/drivers/char/ipmi/ipmi_si_intf.c
31831 +++ b/drivers/char/ipmi/ipmi_si_intf.c
31832 @@ -275,7 +275,7 @@ struct smi_info {
31833 unsigned char slave_addr;
31834
31835 /* Counters and things for the proc filesystem. */
31836 - atomic_t stats[SI_NUM_STATS];
31837 + atomic_unchecked_t stats[SI_NUM_STATS];
31838
31839 struct task_struct *thread;
31840
31841 @@ -284,9 +284,9 @@ struct smi_info {
31842 };
31843
31844 #define smi_inc_stat(smi, stat) \
31845 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
31846 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
31847 #define smi_get_stat(smi, stat) \
31848 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
31849 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
31850
31851 #define SI_MAX_PARMS 4
31852
31853 @@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
31854 atomic_set(&new_smi->req_events, 0);
31855 new_smi->run_to_completion = 0;
31856 for (i = 0; i < SI_NUM_STATS; i++)
31857 - atomic_set(&new_smi->stats[i], 0);
31858 + atomic_set_unchecked(&new_smi->stats[i], 0);
31859
31860 new_smi->interrupt_disabled = 1;
31861 atomic_set(&new_smi->stop_operation, 0);
31862 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
31863 index 0537903..121c699 100644
31864 --- a/drivers/char/mem.c
31865 +++ b/drivers/char/mem.c
31866 @@ -18,6 +18,7 @@
31867 #include <linux/raw.h>
31868 #include <linux/tty.h>
31869 #include <linux/capability.h>
31870 +#include <linux/security.h>
31871 #include <linux/ptrace.h>
31872 #include <linux/device.h>
31873 #include <linux/highmem.h>
31874 @@ -37,6 +38,10 @@
31875
31876 #define DEVPORT_MINOR 4
31877
31878 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31879 +extern const struct file_operations grsec_fops;
31880 +#endif
31881 +
31882 static inline unsigned long size_inside_page(unsigned long start,
31883 unsigned long size)
31884 {
31885 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31886
31887 while (cursor < to) {
31888 if (!devmem_is_allowed(pfn)) {
31889 +#ifdef CONFIG_GRKERNSEC_KMEM
31890 + gr_handle_mem_readwrite(from, to);
31891 +#else
31892 printk(KERN_INFO
31893 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
31894 current->comm, from, to);
31895 +#endif
31896 return 0;
31897 }
31898 cursor += PAGE_SIZE;
31899 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31900 }
31901 return 1;
31902 }
31903 +#elif defined(CONFIG_GRKERNSEC_KMEM)
31904 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31905 +{
31906 + return 0;
31907 +}
31908 #else
31909 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31910 {
31911 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31912
31913 while (count > 0) {
31914 unsigned long remaining;
31915 + char *temp;
31916
31917 sz = size_inside_page(p, count);
31918
31919 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31920 if (!ptr)
31921 return -EFAULT;
31922
31923 - remaining = copy_to_user(buf, ptr, sz);
31924 +#ifdef CONFIG_PAX_USERCOPY
31925 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31926 + if (!temp) {
31927 + unxlate_dev_mem_ptr(p, ptr);
31928 + return -ENOMEM;
31929 + }
31930 + memcpy(temp, ptr, sz);
31931 +#else
31932 + temp = ptr;
31933 +#endif
31934 +
31935 + remaining = copy_to_user(buf, temp, sz);
31936 +
31937 +#ifdef CONFIG_PAX_USERCOPY
31938 + kfree(temp);
31939 +#endif
31940 +
31941 unxlate_dev_mem_ptr(p, ptr);
31942 if (remaining)
31943 return -EFAULT;
31944 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31945 size_t count, loff_t *ppos)
31946 {
31947 unsigned long p = *ppos;
31948 - ssize_t low_count, read, sz;
31949 + ssize_t low_count, read, sz, err = 0;
31950 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
31951 - int err = 0;
31952
31953 read = 0;
31954 if (p < (unsigned long) high_memory) {
31955 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31956 }
31957 #endif
31958 while (low_count > 0) {
31959 + char *temp;
31960 +
31961 sz = size_inside_page(p, low_count);
31962
31963 /*
31964 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31965 */
31966 kbuf = xlate_dev_kmem_ptr((char *)p);
31967
31968 - if (copy_to_user(buf, kbuf, sz))
31969 +#ifdef CONFIG_PAX_USERCOPY
31970 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31971 + if (!temp)
31972 + return -ENOMEM;
31973 + memcpy(temp, kbuf, sz);
31974 +#else
31975 + temp = kbuf;
31976 +#endif
31977 +
31978 + err = copy_to_user(buf, temp, sz);
31979 +
31980 +#ifdef CONFIG_PAX_USERCOPY
31981 + kfree(temp);
31982 +#endif
31983 +
31984 + if (err)
31985 return -EFAULT;
31986 buf += sz;
31987 p += sz;
31988 @@ -833,6 +880,9 @@ static const struct memdev {
31989 #ifdef CONFIG_CRASH_DUMP
31990 [12] = { "oldmem", 0, &oldmem_fops, NULL },
31991 #endif
31992 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31993 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
31994 +#endif
31995 };
31996
31997 static int memory_open(struct inode *inode, struct file *filp)
31998 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
31999 index 9df78e2..01ba9ae 100644
32000 --- a/drivers/char/nvram.c
32001 +++ b/drivers/char/nvram.c
32002 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
32003
32004 spin_unlock_irq(&rtc_lock);
32005
32006 - if (copy_to_user(buf, contents, tmp - contents))
32007 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
32008 return -EFAULT;
32009
32010 *ppos = i;
32011 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
32012 index 21721d2..4e98777 100644
32013 --- a/drivers/char/pcmcia/synclink_cs.c
32014 +++ b/drivers/char/pcmcia/synclink_cs.c
32015 @@ -2346,9 +2346,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32016
32017 if (debug_level >= DEBUG_LEVEL_INFO)
32018 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
32019 - __FILE__,__LINE__, info->device_name, port->count);
32020 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
32021
32022 - WARN_ON(!port->count);
32023 + WARN_ON(!atomic_read(&port->count));
32024
32025 if (tty_port_close_start(port, tty, filp) == 0)
32026 goto cleanup;
32027 @@ -2366,7 +2366,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32028 cleanup:
32029 if (debug_level >= DEBUG_LEVEL_INFO)
32030 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
32031 - tty->driver->name, port->count);
32032 + tty->driver->name, atomic_read(&port->count));
32033 }
32034
32035 /* Wait until the transmitter is empty.
32036 @@ -2508,7 +2508,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32037
32038 if (debug_level >= DEBUG_LEVEL_INFO)
32039 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
32040 - __FILE__,__LINE__,tty->driver->name, port->count);
32041 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
32042
32043 /* If port is closing, signal caller to try again */
32044 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
32045 @@ -2528,11 +2528,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32046 goto cleanup;
32047 }
32048 spin_lock(&port->lock);
32049 - port->count++;
32050 + atomic_inc(&port->count);
32051 spin_unlock(&port->lock);
32052 spin_unlock_irqrestore(&info->netlock, flags);
32053
32054 - if (port->count == 1) {
32055 + if (atomic_read(&port->count) == 1) {
32056 /* 1st open on this device, init hardware */
32057 retval = startup(info, tty);
32058 if (retval < 0)
32059 @@ -3886,7 +3886,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
32060 unsigned short new_crctype;
32061
32062 /* return error if TTY interface open */
32063 - if (info->port.count)
32064 + if (atomic_read(&info->port.count))
32065 return -EBUSY;
32066
32067 switch (encoding)
32068 @@ -3989,7 +3989,7 @@ static int hdlcdev_open(struct net_device *dev)
32069
32070 /* arbitrate between network and tty opens */
32071 spin_lock_irqsave(&info->netlock, flags);
32072 - if (info->port.count != 0 || info->netcount != 0) {
32073 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
32074 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
32075 spin_unlock_irqrestore(&info->netlock, flags);
32076 return -EBUSY;
32077 @@ -4078,7 +4078,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
32078 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
32079
32080 /* return error if TTY interface open */
32081 - if (info->port.count)
32082 + if (atomic_read(&info->port.count))
32083 return -EBUSY;
32084
32085 if (cmd != SIOCWANDEV)
32086 diff --git a/drivers/char/random.c b/drivers/char/random.c
32087 index b86eae9..b9c2ed7 100644
32088 --- a/drivers/char/random.c
32089 +++ b/drivers/char/random.c
32090 @@ -272,8 +272,13 @@
32091 /*
32092 * Configuration information
32093 */
32094 +#ifdef CONFIG_GRKERNSEC_RANDNET
32095 +#define INPUT_POOL_WORDS 512
32096 +#define OUTPUT_POOL_WORDS 128
32097 +#else
32098 #define INPUT_POOL_WORDS 128
32099 #define OUTPUT_POOL_WORDS 32
32100 +#endif
32101 #define SEC_XFER_SIZE 512
32102 #define EXTRACT_SIZE 10
32103
32104 @@ -313,10 +318,17 @@ static struct poolinfo {
32105 int poolwords;
32106 int tap1, tap2, tap3, tap4, tap5;
32107 } poolinfo_table[] = {
32108 +#ifdef CONFIG_GRKERNSEC_RANDNET
32109 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
32110 + { 512, 411, 308, 208, 104, 1 },
32111 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
32112 + { 128, 103, 76, 51, 25, 1 },
32113 +#else
32114 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
32115 { 128, 103, 76, 51, 25, 1 },
32116 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
32117 { 32, 26, 20, 14, 7, 1 },
32118 +#endif
32119 #if 0
32120 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
32121 { 2048, 1638, 1231, 819, 411, 1 },
32122 @@ -437,6 +449,7 @@ struct entropy_store {
32123 int entropy_count;
32124 int entropy_total;
32125 unsigned int initialized:1;
32126 + bool last_data_init;
32127 __u8 last_data[EXTRACT_SIZE];
32128 };
32129
32130 @@ -527,8 +540,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
32131 input_rotate += i ? 7 : 14;
32132 }
32133
32134 - ACCESS_ONCE(r->input_rotate) = input_rotate;
32135 - ACCESS_ONCE(r->add_ptr) = i;
32136 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
32137 + ACCESS_ONCE_RW(r->add_ptr) = i;
32138 smp_wmb();
32139
32140 if (out)
32141 @@ -957,6 +970,10 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
32142 ssize_t ret = 0, i;
32143 __u8 tmp[EXTRACT_SIZE];
32144
32145 + /* if last_data isn't primed, we need EXTRACT_SIZE extra bytes */
32146 + if (fips_enabled && !r->last_data_init)
32147 + nbytes += EXTRACT_SIZE;
32148 +
32149 trace_extract_entropy(r->name, nbytes, r->entropy_count, _RET_IP_);
32150 xfer_secondary_pool(r, nbytes);
32151 nbytes = account(r, nbytes, min, reserved);
32152 @@ -967,6 +984,17 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
32153 if (fips_enabled) {
32154 unsigned long flags;
32155
32156 +
32157 + /* prime last_data value if need be, per fips 140-2 */
32158 + if (!r->last_data_init) {
32159 + spin_lock_irqsave(&r->lock, flags);
32160 + memcpy(r->last_data, tmp, EXTRACT_SIZE);
32161 + r->last_data_init = true;
32162 + nbytes -= EXTRACT_SIZE;
32163 + spin_unlock_irqrestore(&r->lock, flags);
32164 + extract_buf(r, tmp);
32165 + }
32166 +
32167 spin_lock_irqsave(&r->lock, flags);
32168 if (!memcmp(tmp, r->last_data, EXTRACT_SIZE))
32169 panic("Hardware RNG duplicated output!\n");
32170 @@ -1008,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
32171
32172 extract_buf(r, tmp);
32173 i = min_t(int, nbytes, EXTRACT_SIZE);
32174 - if (copy_to_user(buf, tmp, i)) {
32175 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
32176 ret = -EFAULT;
32177 break;
32178 }
32179 @@ -1086,6 +1114,7 @@ static void init_std_data(struct entropy_store *r)
32180
32181 r->entropy_count = 0;
32182 r->entropy_total = 0;
32183 + r->last_data_init = false;
32184 mix_pool_bytes(r, &now, sizeof(now), NULL);
32185 for (i = r->poolinfo->POOLBYTES; i > 0; i -= sizeof(rv)) {
32186 if (!arch_get_random_long(&rv))
32187 @@ -1342,7 +1371,7 @@ EXPORT_SYMBOL(generate_random_uuid);
32188 #include <linux/sysctl.h>
32189
32190 static int min_read_thresh = 8, min_write_thresh;
32191 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
32192 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
32193 static int max_write_thresh = INPUT_POOL_WORDS * 32;
32194 static char sysctl_bootid[16];
32195
32196 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
32197 index 9b4f011..b7e0a1a 100644
32198 --- a/drivers/char/sonypi.c
32199 +++ b/drivers/char/sonypi.c
32200 @@ -54,6 +54,7 @@
32201
32202 #include <asm/uaccess.h>
32203 #include <asm/io.h>
32204 +#include <asm/local.h>
32205
32206 #include <linux/sonypi.h>
32207
32208 @@ -490,7 +491,7 @@ static struct sonypi_device {
32209 spinlock_t fifo_lock;
32210 wait_queue_head_t fifo_proc_list;
32211 struct fasync_struct *fifo_async;
32212 - int open_count;
32213 + local_t open_count;
32214 int model;
32215 struct input_dev *input_jog_dev;
32216 struct input_dev *input_key_dev;
32217 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
32218 static int sonypi_misc_release(struct inode *inode, struct file *file)
32219 {
32220 mutex_lock(&sonypi_device.lock);
32221 - sonypi_device.open_count--;
32222 + local_dec(&sonypi_device.open_count);
32223 mutex_unlock(&sonypi_device.lock);
32224 return 0;
32225 }
32226 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
32227 {
32228 mutex_lock(&sonypi_device.lock);
32229 /* Flush input queue on first open */
32230 - if (!sonypi_device.open_count)
32231 + if (!local_read(&sonypi_device.open_count))
32232 kfifo_reset(&sonypi_device.fifo);
32233 - sonypi_device.open_count++;
32234 + local_inc(&sonypi_device.open_count);
32235 mutex_unlock(&sonypi_device.lock);
32236
32237 return 0;
32238 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
32239 index 93211df..c7805f7 100644
32240 --- a/drivers/char/tpm/tpm.c
32241 +++ b/drivers/char/tpm/tpm.c
32242 @@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
32243 chip->vendor.req_complete_val)
32244 goto out_recv;
32245
32246 - if ((status == chip->vendor.req_canceled)) {
32247 + if (status == chip->vendor.req_canceled) {
32248 dev_err(chip->dev, "Operation Canceled\n");
32249 rc = -ECANCELED;
32250 goto out;
32251 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
32252 index 56051d0..11cf3b7 100644
32253 --- a/drivers/char/tpm/tpm_acpi.c
32254 +++ b/drivers/char/tpm/tpm_acpi.c
32255 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
32256 virt = acpi_os_map_memory(start, len);
32257 if (!virt) {
32258 kfree(log->bios_event_log);
32259 + log->bios_event_log = NULL;
32260 printk("%s: ERROR - Unable to map memory\n", __func__);
32261 return -EIO;
32262 }
32263
32264 - memcpy_fromio(log->bios_event_log, virt, len);
32265 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
32266
32267 acpi_os_unmap_memory(virt, len);
32268 return 0;
32269 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
32270 index 84ddc55..1d32f1e 100644
32271 --- a/drivers/char/tpm/tpm_eventlog.c
32272 +++ b/drivers/char/tpm/tpm_eventlog.c
32273 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
32274 event = addr;
32275
32276 if ((event->event_type == 0 && event->event_size == 0) ||
32277 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
32278 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
32279 return NULL;
32280
32281 return addr;
32282 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
32283 return NULL;
32284
32285 if ((event->event_type == 0 && event->event_size == 0) ||
32286 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
32287 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
32288 return NULL;
32289
32290 (*pos)++;
32291 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
32292 int i;
32293
32294 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
32295 - seq_putc(m, data[i]);
32296 + if (!seq_putc(m, data[i]))
32297 + return -EFAULT;
32298
32299 return 0;
32300 }
32301 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
32302 index 8ab9c3d..c3e65d3 100644
32303 --- a/drivers/char/virtio_console.c
32304 +++ b/drivers/char/virtio_console.c
32305 @@ -622,7 +622,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
32306 if (to_user) {
32307 ssize_t ret;
32308
32309 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
32310 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
32311 if (ret)
32312 return -EFAULT;
32313 } else {
32314 @@ -721,7 +721,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
32315 if (!port_has_data(port) && !port->host_connected)
32316 return 0;
32317
32318 - return fill_readbuf(port, ubuf, count, true);
32319 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
32320 }
32321
32322 static int wait_port_writable(struct port *port, bool nonblock)
32323 diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
32324 index 75c0a1a..96ba8f6 100644
32325 --- a/drivers/edac/edac_mc.c
32326 +++ b/drivers/edac/edac_mc.c
32327 @@ -340,7 +340,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
32328 /*
32329 * Alocate and fill the csrow/channels structs
32330 */
32331 - mci->csrows = kcalloc(sizeof(*mci->csrows), tot_csrows, GFP_KERNEL);
32332 + mci->csrows = kcalloc(tot_csrows, sizeof(*mci->csrows), GFP_KERNEL);
32333 if (!mci->csrows)
32334 goto error;
32335 for (row = 0; row < tot_csrows; row++) {
32336 @@ -351,7 +351,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
32337 csr->csrow_idx = row;
32338 csr->mci = mci;
32339 csr->nr_channels = tot_channels;
32340 - csr->channels = kcalloc(sizeof(*csr->channels), tot_channels,
32341 + csr->channels = kcalloc(tot_channels, sizeof(*csr->channels),
32342 GFP_KERNEL);
32343 if (!csr->channels)
32344 goto error;
32345 @@ -369,7 +369,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
32346 /*
32347 * Allocate and fill the dimm structs
32348 */
32349 - mci->dimms = kcalloc(sizeof(*mci->dimms), tot_dimms, GFP_KERNEL);
32350 + mci->dimms = kcalloc(tot_dimms, sizeof(*mci->dimms), GFP_KERNEL);
32351 if (!mci->dimms)
32352 goto error;
32353
32354 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
32355 index 1bfb207..0d059c2 100644
32356 --- a/drivers/edac/edac_pci_sysfs.c
32357 +++ b/drivers/edac/edac_pci_sysfs.c
32358 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
32359 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
32360 static int edac_pci_poll_msec = 1000; /* one second workq period */
32361
32362 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
32363 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
32364 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
32365 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
32366
32367 static struct kobject *edac_pci_top_main_kobj;
32368 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
32369 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32370 edac_printk(KERN_CRIT, EDAC_PCI,
32371 "Signaled System Error on %s\n",
32372 pci_name(dev));
32373 - atomic_inc(&pci_nonparity_count);
32374 + atomic_inc_unchecked(&pci_nonparity_count);
32375 }
32376
32377 if (status & (PCI_STATUS_PARITY)) {
32378 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32379 "Master Data Parity Error on %s\n",
32380 pci_name(dev));
32381
32382 - atomic_inc(&pci_parity_count);
32383 + atomic_inc_unchecked(&pci_parity_count);
32384 }
32385
32386 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32387 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32388 "Detected Parity Error on %s\n",
32389 pci_name(dev));
32390
32391 - atomic_inc(&pci_parity_count);
32392 + atomic_inc_unchecked(&pci_parity_count);
32393 }
32394 }
32395
32396 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32397 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
32398 "Signaled System Error on %s\n",
32399 pci_name(dev));
32400 - atomic_inc(&pci_nonparity_count);
32401 + atomic_inc_unchecked(&pci_nonparity_count);
32402 }
32403
32404 if (status & (PCI_STATUS_PARITY)) {
32405 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32406 "Master Data Parity Error on "
32407 "%s\n", pci_name(dev));
32408
32409 - atomic_inc(&pci_parity_count);
32410 + atomic_inc_unchecked(&pci_parity_count);
32411 }
32412
32413 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32414 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32415 "Detected Parity Error on %s\n",
32416 pci_name(dev));
32417
32418 - atomic_inc(&pci_parity_count);
32419 + atomic_inc_unchecked(&pci_parity_count);
32420 }
32421 }
32422 }
32423 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
32424 if (!check_pci_errors)
32425 return;
32426
32427 - before_count = atomic_read(&pci_parity_count);
32428 + before_count = atomic_read_unchecked(&pci_parity_count);
32429
32430 /* scan all PCI devices looking for a Parity Error on devices and
32431 * bridges.
32432 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
32433 /* Only if operator has selected panic on PCI Error */
32434 if (edac_pci_get_panic_on_pe()) {
32435 /* If the count is different 'after' from 'before' */
32436 - if (before_count != atomic_read(&pci_parity_count))
32437 + if (before_count != atomic_read_unchecked(&pci_parity_count))
32438 panic("EDAC: PCI Parity Error");
32439 }
32440 }
32441 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
32442 index 8c87a5e..a19cbd7 100644
32443 --- a/drivers/edac/mce_amd.h
32444 +++ b/drivers/edac/mce_amd.h
32445 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
32446 struct amd_decoder_ops {
32447 bool (*dc_mce)(u16, u8);
32448 bool (*ic_mce)(u16, u8);
32449 -};
32450 +} __no_const;
32451
32452 void amd_report_gart_errors(bool);
32453 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
32454 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
32455 index 57ea7f4..789e3c3 100644
32456 --- a/drivers/firewire/core-card.c
32457 +++ b/drivers/firewire/core-card.c
32458 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
32459
32460 void fw_core_remove_card(struct fw_card *card)
32461 {
32462 - struct fw_card_driver dummy_driver = dummy_driver_template;
32463 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
32464
32465 card->driver->update_phy_reg(card, 4,
32466 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
32467 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
32468 index f8d2287..5aaf4db 100644
32469 --- a/drivers/firewire/core-cdev.c
32470 +++ b/drivers/firewire/core-cdev.c
32471 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
32472 int ret;
32473
32474 if ((request->channels == 0 && request->bandwidth == 0) ||
32475 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
32476 - request->bandwidth < 0)
32477 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
32478 return -EINVAL;
32479
32480 r = kmalloc(sizeof(*r), GFP_KERNEL);
32481 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
32482 index 28a94c7..58da63a 100644
32483 --- a/drivers/firewire/core-transaction.c
32484 +++ b/drivers/firewire/core-transaction.c
32485 @@ -38,6 +38,7 @@
32486 #include <linux/timer.h>
32487 #include <linux/types.h>
32488 #include <linux/workqueue.h>
32489 +#include <linux/sched.h>
32490
32491 #include <asm/byteorder.h>
32492
32493 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
32494 index 515a42c..5ecf3ba 100644
32495 --- a/drivers/firewire/core.h
32496 +++ b/drivers/firewire/core.h
32497 @@ -111,6 +111,7 @@ struct fw_card_driver {
32498
32499 int (*stop_iso)(struct fw_iso_context *ctx);
32500 };
32501 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
32502
32503 void fw_card_initialize(struct fw_card *card,
32504 const struct fw_card_driver *driver, struct device *device);
32505 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
32506 index 982f1f5..d21e5da 100644
32507 --- a/drivers/firmware/dmi_scan.c
32508 +++ b/drivers/firmware/dmi_scan.c
32509 @@ -491,11 +491,6 @@ void __init dmi_scan_machine(void)
32510 }
32511 }
32512 else {
32513 - /*
32514 - * no iounmap() for that ioremap(); it would be a no-op, but
32515 - * it's so early in setup that sucker gets confused into doing
32516 - * what it shouldn't if we actually call it.
32517 - */
32518 p = dmi_ioremap(0xF0000, 0x10000);
32519 if (p == NULL)
32520 goto error;
32521 @@ -770,7 +765,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
32522 if (buf == NULL)
32523 return -1;
32524
32525 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
32526 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
32527
32528 iounmap(buf);
32529 return 0;
32530 diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
32531 index bfd8f43..133189c 100644
32532 --- a/drivers/firmware/efivars.c
32533 +++ b/drivers/firmware/efivars.c
32534 @@ -1234,9 +1234,9 @@ efivars_init(void)
32535 return -ENOMEM;
32536 }
32537
32538 - ops.get_variable = efi.get_variable;
32539 - ops.set_variable = efi.set_variable;
32540 - ops.get_next_variable = efi.get_next_variable;
32541 + *(void **)&ops.get_variable = efi.get_variable;
32542 + *(void **)&ops.set_variable = efi.set_variable;
32543 + *(void **)&ops.get_next_variable = efi.get_next_variable;
32544 error = register_efivars(&__efivars, &ops, efi_kobj);
32545 if (error)
32546 goto err_put;
32547 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
32548 index 82d5c20..44a7177 100644
32549 --- a/drivers/gpio/gpio-vr41xx.c
32550 +++ b/drivers/gpio/gpio-vr41xx.c
32551 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
32552 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
32553 maskl, pendl, maskh, pendh);
32554
32555 - atomic_inc(&irq_err_count);
32556 + atomic_inc_unchecked(&irq_err_count);
32557
32558 return -EINVAL;
32559 }
32560 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
32561 index 1227adf..f2301c2 100644
32562 --- a/drivers/gpu/drm/drm_crtc_helper.c
32563 +++ b/drivers/gpu/drm/drm_crtc_helper.c
32564 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
32565 struct drm_crtc *tmp;
32566 int crtc_mask = 1;
32567
32568 - WARN(!crtc, "checking null crtc?\n");
32569 + BUG_ON(!crtc);
32570
32571 dev = crtc->dev;
32572
32573 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
32574 index be174ca..0bcbb71 100644
32575 --- a/drivers/gpu/drm/drm_drv.c
32576 +++ b/drivers/gpu/drm/drm_drv.c
32577 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
32578 /**
32579 * Copy and IOCTL return string to user space
32580 */
32581 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
32582 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
32583 {
32584 int len;
32585
32586 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
32587 return -ENODEV;
32588
32589 atomic_inc(&dev->ioctl_count);
32590 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
32591 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
32592 ++file_priv->ioctl_count;
32593
32594 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
32595 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
32596 index 133b413..fd68225 100644
32597 --- a/drivers/gpu/drm/drm_fops.c
32598 +++ b/drivers/gpu/drm/drm_fops.c
32599 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
32600 }
32601
32602 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
32603 - atomic_set(&dev->counts[i], 0);
32604 + atomic_set_unchecked(&dev->counts[i], 0);
32605
32606 dev->sigdata.lock = NULL;
32607
32608 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
32609 if (drm_device_is_unplugged(dev))
32610 return -ENODEV;
32611
32612 - if (!dev->open_count++)
32613 + if (local_inc_return(&dev->open_count) == 1)
32614 need_setup = 1;
32615 mutex_lock(&dev->struct_mutex);
32616 old_mapping = dev->dev_mapping;
32617 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
32618 retcode = drm_open_helper(inode, filp, dev);
32619 if (retcode)
32620 goto err_undo;
32621 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
32622 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
32623 if (need_setup) {
32624 retcode = drm_setup(dev);
32625 if (retcode)
32626 @@ -164,7 +164,7 @@ err_undo:
32627 iput(container_of(dev->dev_mapping, struct inode, i_data));
32628 dev->dev_mapping = old_mapping;
32629 mutex_unlock(&dev->struct_mutex);
32630 - dev->open_count--;
32631 + local_dec(&dev->open_count);
32632 return retcode;
32633 }
32634 EXPORT_SYMBOL(drm_open);
32635 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
32636
32637 mutex_lock(&drm_global_mutex);
32638
32639 - DRM_DEBUG("open_count = %d\n", dev->open_count);
32640 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
32641
32642 if (dev->driver->preclose)
32643 dev->driver->preclose(dev, file_priv);
32644 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
32645 * Begin inline drm_release
32646 */
32647
32648 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
32649 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
32650 task_pid_nr(current),
32651 (long)old_encode_dev(file_priv->minor->device),
32652 - dev->open_count);
32653 + local_read(&dev->open_count));
32654
32655 /* Release any auth tokens that might point to this file_priv,
32656 (do that under the drm_global_mutex) */
32657 @@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
32658 * End inline drm_release
32659 */
32660
32661 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
32662 - if (!--dev->open_count) {
32663 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
32664 + if (local_dec_and_test(&dev->open_count)) {
32665 if (atomic_read(&dev->ioctl_count)) {
32666 DRM_ERROR("Device busy: %d\n",
32667 atomic_read(&dev->ioctl_count));
32668 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
32669 index f731116..629842c 100644
32670 --- a/drivers/gpu/drm/drm_global.c
32671 +++ b/drivers/gpu/drm/drm_global.c
32672 @@ -36,7 +36,7 @@
32673 struct drm_global_item {
32674 struct mutex mutex;
32675 void *object;
32676 - int refcount;
32677 + atomic_t refcount;
32678 };
32679
32680 static struct drm_global_item glob[DRM_GLOBAL_NUM];
32681 @@ -49,7 +49,7 @@ void drm_global_init(void)
32682 struct drm_global_item *item = &glob[i];
32683 mutex_init(&item->mutex);
32684 item->object = NULL;
32685 - item->refcount = 0;
32686 + atomic_set(&item->refcount, 0);
32687 }
32688 }
32689
32690 @@ -59,7 +59,7 @@ void drm_global_release(void)
32691 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
32692 struct drm_global_item *item = &glob[i];
32693 BUG_ON(item->object != NULL);
32694 - BUG_ON(item->refcount != 0);
32695 + BUG_ON(atomic_read(&item->refcount) != 0);
32696 }
32697 }
32698
32699 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32700 void *object;
32701
32702 mutex_lock(&item->mutex);
32703 - if (item->refcount == 0) {
32704 + if (atomic_read(&item->refcount) == 0) {
32705 item->object = kzalloc(ref->size, GFP_KERNEL);
32706 if (unlikely(item->object == NULL)) {
32707 ret = -ENOMEM;
32708 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32709 goto out_err;
32710
32711 }
32712 - ++item->refcount;
32713 + atomic_inc(&item->refcount);
32714 ref->object = item->object;
32715 object = item->object;
32716 mutex_unlock(&item->mutex);
32717 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
32718 struct drm_global_item *item = &glob[ref->global_type];
32719
32720 mutex_lock(&item->mutex);
32721 - BUG_ON(item->refcount == 0);
32722 + BUG_ON(atomic_read(&item->refcount) == 0);
32723 BUG_ON(ref->object != item->object);
32724 - if (--item->refcount == 0) {
32725 + if (atomic_dec_and_test(&item->refcount)) {
32726 ref->release(ref);
32727 item->object = NULL;
32728 }
32729 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
32730 index d4b20ce..77a8d41 100644
32731 --- a/drivers/gpu/drm/drm_info.c
32732 +++ b/drivers/gpu/drm/drm_info.c
32733 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
32734 struct drm_local_map *map;
32735 struct drm_map_list *r_list;
32736
32737 - /* Hardcoded from _DRM_FRAME_BUFFER,
32738 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
32739 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
32740 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
32741 + static const char * const types[] = {
32742 + [_DRM_FRAME_BUFFER] = "FB",
32743 + [_DRM_REGISTERS] = "REG",
32744 + [_DRM_SHM] = "SHM",
32745 + [_DRM_AGP] = "AGP",
32746 + [_DRM_SCATTER_GATHER] = "SG",
32747 + [_DRM_CONSISTENT] = "PCI",
32748 + [_DRM_GEM] = "GEM" };
32749 const char *type;
32750 int i;
32751
32752 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
32753 map = r_list->map;
32754 if (!map)
32755 continue;
32756 - if (map->type < 0 || map->type > 5)
32757 + if (map->type >= ARRAY_SIZE(types))
32758 type = "??";
32759 else
32760 type = types[map->type];
32761 @@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
32762 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
32763 vma->vm_flags & VM_LOCKED ? 'l' : '-',
32764 vma->vm_flags & VM_IO ? 'i' : '-',
32765 +#ifdef CONFIG_GRKERNSEC_HIDESYM
32766 + 0);
32767 +#else
32768 vma->vm_pgoff);
32769 +#endif
32770
32771 #if defined(__i386__)
32772 pgprot = pgprot_val(vma->vm_page_prot);
32773 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
32774 index 2f4c434..764794b 100644
32775 --- a/drivers/gpu/drm/drm_ioc32.c
32776 +++ b/drivers/gpu/drm/drm_ioc32.c
32777 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
32778 request = compat_alloc_user_space(nbytes);
32779 if (!access_ok(VERIFY_WRITE, request, nbytes))
32780 return -EFAULT;
32781 - list = (struct drm_buf_desc *) (request + 1);
32782 + list = (struct drm_buf_desc __user *) (request + 1);
32783
32784 if (__put_user(count, &request->count)
32785 || __put_user(list, &request->list))
32786 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
32787 request = compat_alloc_user_space(nbytes);
32788 if (!access_ok(VERIFY_WRITE, request, nbytes))
32789 return -EFAULT;
32790 - list = (struct drm_buf_pub *) (request + 1);
32791 + list = (struct drm_buf_pub __user *) (request + 1);
32792
32793 if (__put_user(count, &request->count)
32794 || __put_user(list, &request->list))
32795 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
32796 index 23dd975..63e9801 100644
32797 --- a/drivers/gpu/drm/drm_ioctl.c
32798 +++ b/drivers/gpu/drm/drm_ioctl.c
32799 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
32800 stats->data[i].value =
32801 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
32802 else
32803 - stats->data[i].value = atomic_read(&dev->counts[i]);
32804 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
32805 stats->data[i].type = dev->types[i];
32806 }
32807
32808 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
32809 index d752c96..fe08455 100644
32810 --- a/drivers/gpu/drm/drm_lock.c
32811 +++ b/drivers/gpu/drm/drm_lock.c
32812 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32813 if (drm_lock_take(&master->lock, lock->context)) {
32814 master->lock.file_priv = file_priv;
32815 master->lock.lock_time = jiffies;
32816 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
32817 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
32818 break; /* Got lock */
32819 }
32820
32821 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32822 return -EINVAL;
32823 }
32824
32825 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
32826 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
32827
32828 if (drm_lock_free(&master->lock, lock->context)) {
32829 /* FIXME: Should really bail out here. */
32830 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
32831 index c236fd2..6b5f2e7 100644
32832 --- a/drivers/gpu/drm/drm_stub.c
32833 +++ b/drivers/gpu/drm/drm_stub.c
32834 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
32835
32836 drm_device_set_unplugged(dev);
32837
32838 - if (dev->open_count == 0) {
32839 + if (local_read(&dev->open_count) == 0) {
32840 drm_put_dev(dev);
32841 }
32842 mutex_unlock(&drm_global_mutex);
32843 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
32844 index 004ecdf..db1f6e0 100644
32845 --- a/drivers/gpu/drm/i810/i810_dma.c
32846 +++ b/drivers/gpu/drm/i810/i810_dma.c
32847 @@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
32848 dma->buflist[vertex->idx],
32849 vertex->discard, vertex->used);
32850
32851 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32852 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32853 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32854 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32855 sarea_priv->last_enqueue = dev_priv->counter - 1;
32856 sarea_priv->last_dispatch = (int)hw_status[5];
32857
32858 @@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
32859 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
32860 mc->last_render);
32861
32862 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32863 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32864 + atomic_add_unchecked(mc->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 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
32870 index 6e0acad..93c8289 100644
32871 --- a/drivers/gpu/drm/i810/i810_drv.h
32872 +++ b/drivers/gpu/drm/i810/i810_drv.h
32873 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
32874 int page_flipping;
32875
32876 wait_queue_head_t irq_queue;
32877 - atomic_t irq_received;
32878 - atomic_t irq_emitted;
32879 + atomic_unchecked_t irq_received;
32880 + atomic_unchecked_t irq_emitted;
32881
32882 int front_offset;
32883 } drm_i810_private_t;
32884 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
32885 index 3a1a495..995c093 100644
32886 --- a/drivers/gpu/drm/i915/i915_debugfs.c
32887 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
32888 @@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
32889 I915_READ(GTIMR));
32890 }
32891 seq_printf(m, "Interrupts received: %d\n",
32892 - atomic_read(&dev_priv->irq_received));
32893 + atomic_read_unchecked(&dev_priv->irq_received));
32894 for_each_ring(ring, dev_priv, i) {
32895 if (IS_GEN6(dev) || IS_GEN7(dev)) {
32896 seq_printf(m,
32897 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
32898 index 61ae104..f8a4bc1 100644
32899 --- a/drivers/gpu/drm/i915/i915_dma.c
32900 +++ b/drivers/gpu/drm/i915/i915_dma.c
32901 @@ -1274,7 +1274,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
32902 bool can_switch;
32903
32904 spin_lock(&dev->count_lock);
32905 - can_switch = (dev->open_count == 0);
32906 + can_switch = (local_read(&dev->open_count) == 0);
32907 spin_unlock(&dev->count_lock);
32908 return can_switch;
32909 }
32910 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
32911 index 92f1750..3beba74 100644
32912 --- a/drivers/gpu/drm/i915/i915_drv.h
32913 +++ b/drivers/gpu/drm/i915/i915_drv.h
32914 @@ -430,7 +430,7 @@ typedef struct drm_i915_private {
32915
32916 struct resource mch_res;
32917
32918 - atomic_t irq_received;
32919 + atomic_unchecked_t irq_received;
32920
32921 /* protects the irq masks */
32922 spinlock_t irq_lock;
32923 @@ -1055,7 +1055,7 @@ struct drm_i915_gem_object {
32924 * will be page flipped away on the next vblank. When it
32925 * reaches 0, dev_priv->pending_flip_queue will be woken up.
32926 */
32927 - atomic_t pending_flip;
32928 + atomic_unchecked_t pending_flip;
32929 };
32930
32931 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
32932 @@ -1558,7 +1558,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
32933 struct drm_i915_private *dev_priv, unsigned port);
32934 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
32935 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
32936 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32937 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32938 {
32939 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
32940 }
32941 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32942 index 67036e9..b9f1357 100644
32943 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32944 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32945 @@ -681,7 +681,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
32946 i915_gem_clflush_object(obj);
32947
32948 if (obj->base.pending_write_domain)
32949 - flips |= atomic_read(&obj->pending_flip);
32950 + flips |= atomic_read_unchecked(&obj->pending_flip);
32951
32952 flush_domains |= obj->base.write_domain;
32953 }
32954 @@ -712,9 +712,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
32955
32956 static int
32957 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
32958 - int count)
32959 + unsigned int count)
32960 {
32961 - int i;
32962 + unsigned int i;
32963
32964 for (i = 0; i < count; i++) {
32965 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
32966 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
32967 index dc29ace..137d83a 100644
32968 --- a/drivers/gpu/drm/i915/i915_irq.c
32969 +++ b/drivers/gpu/drm/i915/i915_irq.c
32970 @@ -531,7 +531,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
32971 u32 pipe_stats[I915_MAX_PIPES];
32972 bool blc_event;
32973
32974 - atomic_inc(&dev_priv->irq_received);
32975 + atomic_inc_unchecked(&dev_priv->irq_received);
32976
32977 while (true) {
32978 iir = I915_READ(VLV_IIR);
32979 @@ -678,7 +678,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
32980 irqreturn_t ret = IRQ_NONE;
32981 int i;
32982
32983 - atomic_inc(&dev_priv->irq_received);
32984 + atomic_inc_unchecked(&dev_priv->irq_received);
32985
32986 /* disable master interrupt before clearing iir */
32987 de_ier = I915_READ(DEIER);
32988 @@ -753,7 +753,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
32989 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
32990 u32 hotplug_mask;
32991
32992 - atomic_inc(&dev_priv->irq_received);
32993 + atomic_inc_unchecked(&dev_priv->irq_received);
32994
32995 /* disable master interrupt before clearing iir */
32996 de_ier = I915_READ(DEIER);
32997 @@ -1762,7 +1762,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
32998 {
32999 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33000
33001 - atomic_set(&dev_priv->irq_received, 0);
33002 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33003
33004 I915_WRITE(HWSTAM, 0xeffe);
33005
33006 @@ -1788,7 +1788,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
33007 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33008 int pipe;
33009
33010 - atomic_set(&dev_priv->irq_received, 0);
33011 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33012
33013 /* VLV magic */
33014 I915_WRITE(VLV_IMR, 0);
33015 @@ -2093,7 +2093,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
33016 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33017 int pipe;
33018
33019 - atomic_set(&dev_priv->irq_received, 0);
33020 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33021
33022 for_each_pipe(pipe)
33023 I915_WRITE(PIPESTAT(pipe), 0);
33024 @@ -2144,7 +2144,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
33025 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
33026 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
33027
33028 - atomic_inc(&dev_priv->irq_received);
33029 + atomic_inc_unchecked(&dev_priv->irq_received);
33030
33031 iir = I915_READ16(IIR);
33032 if (iir == 0)
33033 @@ -2229,7 +2229,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
33034 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33035 int pipe;
33036
33037 - atomic_set(&dev_priv->irq_received, 0);
33038 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33039
33040 if (I915_HAS_HOTPLUG(dev)) {
33041 I915_WRITE(PORT_HOTPLUG_EN, 0);
33042 @@ -2324,7 +2324,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
33043 };
33044 int pipe, ret = IRQ_NONE;
33045
33046 - atomic_inc(&dev_priv->irq_received);
33047 + atomic_inc_unchecked(&dev_priv->irq_received);
33048
33049 iir = I915_READ(IIR);
33050 do {
33051 @@ -2450,7 +2450,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
33052 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33053 int pipe;
33054
33055 - atomic_set(&dev_priv->irq_received, 0);
33056 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33057
33058 I915_WRITE(PORT_HOTPLUG_EN, 0);
33059 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
33060 @@ -2557,7 +2557,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
33061 int irq_received;
33062 int ret = IRQ_NONE, pipe;
33063
33064 - atomic_inc(&dev_priv->irq_received);
33065 + atomic_inc_unchecked(&dev_priv->irq_received);
33066
33067 iir = I915_READ(IIR);
33068
33069 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
33070 index 4d3c7c6..eaac87b 100644
33071 --- a/drivers/gpu/drm/i915/intel_display.c
33072 +++ b/drivers/gpu/drm/i915/intel_display.c
33073 @@ -2131,7 +2131,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
33074
33075 wait_event(dev_priv->pending_flip_queue,
33076 atomic_read(&dev_priv->mm.wedged) ||
33077 - atomic_read(&obj->pending_flip) == 0);
33078 + atomic_read_unchecked(&obj->pending_flip) == 0);
33079
33080 /* Big Hammer, we also need to ensure that any pending
33081 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
33082 @@ -6221,8 +6221,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
33083
33084 obj = work->old_fb_obj;
33085
33086 - atomic_clear_mask(1 << intel_crtc->plane,
33087 - &obj->pending_flip.counter);
33088 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
33089 wake_up(&dev_priv->pending_flip_queue);
33090
33091 queue_work(dev_priv->wq, &work->work);
33092 @@ -6589,7 +6588,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33093 /* Block clients from rendering to the new back buffer until
33094 * the flip occurs and the object is no longer visible.
33095 */
33096 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33097 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33098 atomic_inc(&intel_crtc->unpin_work_count);
33099
33100 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
33101 @@ -6606,7 +6605,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33102
33103 cleanup_pending:
33104 atomic_dec(&intel_crtc->unpin_work_count);
33105 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33106 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33107 drm_gem_object_unreference(&work->old_fb_obj->base);
33108 drm_gem_object_unreference(&obj->base);
33109 mutex_unlock(&dev->struct_mutex);
33110 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
33111 index 54558a0..2d97005 100644
33112 --- a/drivers/gpu/drm/mga/mga_drv.h
33113 +++ b/drivers/gpu/drm/mga/mga_drv.h
33114 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
33115 u32 clear_cmd;
33116 u32 maccess;
33117
33118 - atomic_t vbl_received; /**< Number of vblanks received. */
33119 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
33120 wait_queue_head_t fence_queue;
33121 - atomic_t last_fence_retired;
33122 + atomic_unchecked_t last_fence_retired;
33123 u32 next_fence_to_post;
33124
33125 unsigned int fb_cpp;
33126 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
33127 index 598c281..60d590e 100644
33128 --- a/drivers/gpu/drm/mga/mga_irq.c
33129 +++ b/drivers/gpu/drm/mga/mga_irq.c
33130 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
33131 if (crtc != 0)
33132 return 0;
33133
33134 - return atomic_read(&dev_priv->vbl_received);
33135 + return atomic_read_unchecked(&dev_priv->vbl_received);
33136 }
33137
33138
33139 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33140 /* VBLANK interrupt */
33141 if (status & MGA_VLINEPEN) {
33142 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
33143 - atomic_inc(&dev_priv->vbl_received);
33144 + atomic_inc_unchecked(&dev_priv->vbl_received);
33145 drm_handle_vblank(dev, 0);
33146 handled = 1;
33147 }
33148 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33149 if ((prim_start & ~0x03) != (prim_end & ~0x03))
33150 MGA_WRITE(MGA_PRIMEND, prim_end);
33151
33152 - atomic_inc(&dev_priv->last_fence_retired);
33153 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
33154 DRM_WAKEUP(&dev_priv->fence_queue);
33155 handled = 1;
33156 }
33157 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
33158 * using fences.
33159 */
33160 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
33161 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
33162 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
33163 - *sequence) <= (1 << 23)));
33164
33165 *sequence = cur_fence;
33166 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
33167 index 09fdef2..57f5c3b 100644
33168 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
33169 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
33170 @@ -1240,7 +1240,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
33171 struct bit_table {
33172 const char id;
33173 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
33174 -};
33175 +} __no_const;
33176
33177 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
33178
33179 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
33180 index a101699..a163f0a 100644
33181 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
33182 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
33183 @@ -80,7 +80,7 @@ struct nouveau_drm {
33184 struct drm_global_reference mem_global_ref;
33185 struct ttm_bo_global_ref bo_global_ref;
33186 struct ttm_bo_device bdev;
33187 - atomic_t validate_sequence;
33188 + atomic_unchecked_t validate_sequence;
33189 int (*move)(struct nouveau_channel *,
33190 struct ttm_buffer_object *,
33191 struct ttm_mem_reg *, struct ttm_mem_reg *);
33192 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
33193 index cdb83ac..27f0a16 100644
33194 --- a/drivers/gpu/drm/nouveau/nouveau_fence.h
33195 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
33196 @@ -43,7 +43,7 @@ struct nouveau_fence_priv {
33197 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
33198 struct nouveau_channel *);
33199 u32 (*read)(struct nouveau_channel *);
33200 -};
33201 +} __no_const;
33202
33203 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
33204
33205 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
33206 index 5e2f521..0d21436 100644
33207 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
33208 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
33209 @@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
33210 int trycnt = 0;
33211 int ret, i;
33212
33213 - sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
33214 + sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
33215 retry:
33216 if (++trycnt > 100000) {
33217 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
33218 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
33219 index 6f0ac64..9c2dfb4 100644
33220 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
33221 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
33222 @@ -63,7 +63,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
33223 bool can_switch;
33224
33225 spin_lock(&dev->count_lock);
33226 - can_switch = (dev->open_count == 0);
33227 + can_switch = (local_read(&dev->open_count) == 0);
33228 spin_unlock(&dev->count_lock);
33229 return can_switch;
33230 }
33231 diff --git a/drivers/gpu/drm/nouveau/nv50_evo.c b/drivers/gpu/drm/nouveau/nv50_evo.c
33232 index 9f6f55c..30e3a29 100644
33233 --- a/drivers/gpu/drm/nouveau/nv50_evo.c
33234 +++ b/drivers/gpu/drm/nouveau/nv50_evo.c
33235 @@ -152,9 +152,9 @@ nv50_evo_channel_new(struct drm_device *dev, int chid,
33236 kzalloc(sizeof(*evo->object->oclass), GFP_KERNEL);
33237 evo->object->oclass->ofuncs =
33238 kzalloc(sizeof(*evo->object->oclass->ofuncs), GFP_KERNEL);
33239 - evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
33240 - evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
33241 - evo->object->oclass->ofuncs->rd08 =
33242 + *(void**)&evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
33243 + *(void**)&evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
33244 + *(void**)&evo->object->oclass->ofuncs->rd08 =
33245 ioremap(pci_resource_start(dev->pdev, 0) +
33246 NV50_PDISPLAY_USER(evo->handle), PAGE_SIZE);
33247 return 0;
33248 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
33249 index b562b59..9d725a8 100644
33250 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
33251 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
33252 @@ -317,7 +317,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
33253 }
33254
33255 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
33256 - struct dp_train_func func = {
33257 + static struct dp_train_func func = {
33258 .link_set = nv50_sor_dp_link_set,
33259 .train_set = nv50_sor_dp_train_set,
33260 .train_adj = nv50_sor_dp_train_adj
33261 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
33262 index c402fca..f1d694b 100644
33263 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
33264 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
33265 @@ -1389,7 +1389,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
33266 nv_wait(device, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
33267
33268 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
33269 - struct dp_train_func func = {
33270 + static struct dp_train_func func = {
33271 .link_set = nvd0_sor_dp_link_set,
33272 .train_set = nvd0_sor_dp_train_set,
33273 .train_adj = nvd0_sor_dp_train_adj
33274 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
33275 index d4660cf..70dbe65 100644
33276 --- a/drivers/gpu/drm/r128/r128_cce.c
33277 +++ b/drivers/gpu/drm/r128/r128_cce.c
33278 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
33279
33280 /* GH: Simple idle check.
33281 */
33282 - atomic_set(&dev_priv->idle_count, 0);
33283 + atomic_set_unchecked(&dev_priv->idle_count, 0);
33284
33285 /* We don't support anything other than bus-mastering ring mode,
33286 * but the ring can be in either AGP or PCI space for the ring
33287 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
33288 index 930c71b..499aded 100644
33289 --- a/drivers/gpu/drm/r128/r128_drv.h
33290 +++ b/drivers/gpu/drm/r128/r128_drv.h
33291 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
33292 int is_pci;
33293 unsigned long cce_buffers_offset;
33294
33295 - atomic_t idle_count;
33296 + atomic_unchecked_t idle_count;
33297
33298 int page_flipping;
33299 int current_page;
33300 u32 crtc_offset;
33301 u32 crtc_offset_cntl;
33302
33303 - atomic_t vbl_received;
33304 + atomic_unchecked_t vbl_received;
33305
33306 u32 color_fmt;
33307 unsigned int front_offset;
33308 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
33309 index 2ea4f09..d391371 100644
33310 --- a/drivers/gpu/drm/r128/r128_irq.c
33311 +++ b/drivers/gpu/drm/r128/r128_irq.c
33312 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
33313 if (crtc != 0)
33314 return 0;
33315
33316 - return atomic_read(&dev_priv->vbl_received);
33317 + return atomic_read_unchecked(&dev_priv->vbl_received);
33318 }
33319
33320 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33321 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33322 /* VBLANK interrupt */
33323 if (status & R128_CRTC_VBLANK_INT) {
33324 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
33325 - atomic_inc(&dev_priv->vbl_received);
33326 + atomic_inc_unchecked(&dev_priv->vbl_received);
33327 drm_handle_vblank(dev, 0);
33328 return IRQ_HANDLED;
33329 }
33330 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
33331 index 19bb7e6..de7e2a2 100644
33332 --- a/drivers/gpu/drm/r128/r128_state.c
33333 +++ b/drivers/gpu/drm/r128/r128_state.c
33334 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
33335
33336 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
33337 {
33338 - if (atomic_read(&dev_priv->idle_count) == 0)
33339 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
33340 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
33341 else
33342 - atomic_set(&dev_priv->idle_count, 0);
33343 + atomic_set_unchecked(&dev_priv->idle_count, 0);
33344 }
33345
33346 #endif
33347 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
33348 index 5a82b6b..9e69c73 100644
33349 --- a/drivers/gpu/drm/radeon/mkregtable.c
33350 +++ b/drivers/gpu/drm/radeon/mkregtable.c
33351 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
33352 regex_t mask_rex;
33353 regmatch_t match[4];
33354 char buf[1024];
33355 - size_t end;
33356 + long end;
33357 int len;
33358 int done = 0;
33359 int r;
33360 unsigned o;
33361 struct offset *offset;
33362 char last_reg_s[10];
33363 - int last_reg;
33364 + unsigned long last_reg;
33365
33366 if (regcomp
33367 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
33368 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
33369 index 008d645..de03849 100644
33370 --- a/drivers/gpu/drm/radeon/radeon_device.c
33371 +++ b/drivers/gpu/drm/radeon/radeon_device.c
33372 @@ -941,7 +941,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
33373 bool can_switch;
33374
33375 spin_lock(&dev->count_lock);
33376 - can_switch = (dev->open_count == 0);
33377 + can_switch = (local_read(&dev->open_count) == 0);
33378 spin_unlock(&dev->count_lock);
33379 return can_switch;
33380 }
33381 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
33382 index a1b59ca..86f2d44 100644
33383 --- a/drivers/gpu/drm/radeon/radeon_drv.h
33384 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
33385 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
33386
33387 /* SW interrupt */
33388 wait_queue_head_t swi_queue;
33389 - atomic_t swi_emitted;
33390 + atomic_unchecked_t swi_emitted;
33391 int vblank_crtc;
33392 uint32_t irq_enable_reg;
33393 uint32_t r500_disp_irq_reg;
33394 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
33395 index c180df8..cd80dd2d 100644
33396 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
33397 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
33398 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
33399 request = compat_alloc_user_space(sizeof(*request));
33400 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
33401 || __put_user(req32.param, &request->param)
33402 - || __put_user((void __user *)(unsigned long)req32.value,
33403 + || __put_user((unsigned long)req32.value,
33404 &request->value))
33405 return -EFAULT;
33406
33407 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
33408 index e771033..a0bc6b3 100644
33409 --- a/drivers/gpu/drm/radeon/radeon_irq.c
33410 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
33411 @@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
33412 unsigned int ret;
33413 RING_LOCALS;
33414
33415 - atomic_inc(&dev_priv->swi_emitted);
33416 - ret = atomic_read(&dev_priv->swi_emitted);
33417 + atomic_inc_unchecked(&dev_priv->swi_emitted);
33418 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
33419
33420 BEGIN_RING(4);
33421 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
33422 @@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
33423 drm_radeon_private_t *dev_priv =
33424 (drm_radeon_private_t *) dev->dev_private;
33425
33426 - atomic_set(&dev_priv->swi_emitted, 0);
33427 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
33428 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
33429
33430 dev->max_vblank_count = 0x001fffff;
33431 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
33432 index 8e9057b..af6dacb 100644
33433 --- a/drivers/gpu/drm/radeon/radeon_state.c
33434 +++ b/drivers/gpu/drm/radeon/radeon_state.c
33435 @@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
33436 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
33437 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
33438
33439 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33440 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33441 sarea_priv->nbox * sizeof(depth_boxes[0])))
33442 return -EFAULT;
33443
33444 @@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
33445 {
33446 drm_radeon_private_t *dev_priv = dev->dev_private;
33447 drm_radeon_getparam_t *param = data;
33448 - int value;
33449 + int value = 0;
33450
33451 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
33452
33453 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
33454 index 5ebe1b3..1ed9426 100644
33455 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
33456 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
33457 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33458 }
33459 if (unlikely(ttm_vm_ops == NULL)) {
33460 ttm_vm_ops = vma->vm_ops;
33461 - radeon_ttm_vm_ops = *ttm_vm_ops;
33462 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33463 + pax_open_kernel();
33464 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
33465 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33466 + pax_close_kernel();
33467 }
33468 vma->vm_ops = &radeon_ttm_vm_ops;
33469 return 0;
33470 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
33471 index 5706d2a..17aedaa 100644
33472 --- a/drivers/gpu/drm/radeon/rs690.c
33473 +++ b/drivers/gpu/drm/radeon/rs690.c
33474 @@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
33475 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
33476 rdev->pm.sideport_bandwidth.full)
33477 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
33478 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
33479 + read_delay_latency.full = dfixed_const(800 * 1000);
33480 read_delay_latency.full = dfixed_div(read_delay_latency,
33481 rdev->pm.igp_sideport_mclk);
33482 + a.full = dfixed_const(370);
33483 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
33484 } else {
33485 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
33486 rdev->pm.k8_bandwidth.full)
33487 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33488 index bd2a3b4..122d9ad 100644
33489 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
33490 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33491 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
33492 static int ttm_pool_mm_shrink(struct shrinker *shrink,
33493 struct shrink_control *sc)
33494 {
33495 - static atomic_t start_pool = ATOMIC_INIT(0);
33496 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
33497 unsigned i;
33498 - unsigned pool_offset = atomic_add_return(1, &start_pool);
33499 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
33500 struct ttm_page_pool *pool;
33501 int shrink_pages = sc->nr_to_scan;
33502
33503 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
33504 index 893a650..6190d3b 100644
33505 --- a/drivers/gpu/drm/via/via_drv.h
33506 +++ b/drivers/gpu/drm/via/via_drv.h
33507 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
33508 typedef uint32_t maskarray_t[5];
33509
33510 typedef struct drm_via_irq {
33511 - atomic_t irq_received;
33512 + atomic_unchecked_t irq_received;
33513 uint32_t pending_mask;
33514 uint32_t enable_mask;
33515 wait_queue_head_t irq_queue;
33516 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
33517 struct timeval last_vblank;
33518 int last_vblank_valid;
33519 unsigned usec_per_vblank;
33520 - atomic_t vbl_received;
33521 + atomic_unchecked_t vbl_received;
33522 drm_via_state_t hc_state;
33523 char pci_buf[VIA_PCI_BUF_SIZE];
33524 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
33525 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
33526 index ac98964..5dbf512 100644
33527 --- a/drivers/gpu/drm/via/via_irq.c
33528 +++ b/drivers/gpu/drm/via/via_irq.c
33529 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
33530 if (crtc != 0)
33531 return 0;
33532
33533 - return atomic_read(&dev_priv->vbl_received);
33534 + return atomic_read_unchecked(&dev_priv->vbl_received);
33535 }
33536
33537 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33538 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33539
33540 status = VIA_READ(VIA_REG_INTERRUPT);
33541 if (status & VIA_IRQ_VBLANK_PENDING) {
33542 - atomic_inc(&dev_priv->vbl_received);
33543 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
33544 + atomic_inc_unchecked(&dev_priv->vbl_received);
33545 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
33546 do_gettimeofday(&cur_vblank);
33547 if (dev_priv->last_vblank_valid) {
33548 dev_priv->usec_per_vblank =
33549 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33550 dev_priv->last_vblank = cur_vblank;
33551 dev_priv->last_vblank_valid = 1;
33552 }
33553 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
33554 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
33555 DRM_DEBUG("US per vblank is: %u\n",
33556 dev_priv->usec_per_vblank);
33557 }
33558 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33559
33560 for (i = 0; i < dev_priv->num_irqs; ++i) {
33561 if (status & cur_irq->pending_mask) {
33562 - atomic_inc(&cur_irq->irq_received);
33563 + atomic_inc_unchecked(&cur_irq->irq_received);
33564 DRM_WAKEUP(&cur_irq->irq_queue);
33565 handled = 1;
33566 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
33567 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
33568 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33569 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
33570 masks[irq][4]));
33571 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
33572 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
33573 } else {
33574 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33575 (((cur_irq_sequence =
33576 - atomic_read(&cur_irq->irq_received)) -
33577 + atomic_read_unchecked(&cur_irq->irq_received)) -
33578 *sequence) <= (1 << 23)));
33579 }
33580 *sequence = cur_irq_sequence;
33581 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
33582 }
33583
33584 for (i = 0; i < dev_priv->num_irqs; ++i) {
33585 - atomic_set(&cur_irq->irq_received, 0);
33586 + atomic_set_unchecked(&cur_irq->irq_received, 0);
33587 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
33588 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
33589 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
33590 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
33591 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
33592 case VIA_IRQ_RELATIVE:
33593 irqwait->request.sequence +=
33594 - atomic_read(&cur_irq->irq_received);
33595 + atomic_read_unchecked(&cur_irq->irq_received);
33596 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
33597 case VIA_IRQ_ABSOLUTE:
33598 break;
33599 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33600 index 88a179e..57fe50481c 100644
33601 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33602 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33603 @@ -263,7 +263,7 @@ struct vmw_private {
33604 * Fencing and IRQs.
33605 */
33606
33607 - atomic_t marker_seq;
33608 + atomic_unchecked_t marker_seq;
33609 wait_queue_head_t fence_queue;
33610 wait_queue_head_t fifo_queue;
33611 int fence_queue_waiters; /* Protected by hw_mutex */
33612 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33613 index 3eb1486..0a47ee9 100644
33614 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33615 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33616 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
33617 (unsigned int) min,
33618 (unsigned int) fifo->capabilities);
33619
33620 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33621 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33622 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
33623 vmw_marker_queue_init(&fifo->marker_queue);
33624 return vmw_fifo_send_fence(dev_priv, &dummy);
33625 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
33626 if (reserveable)
33627 iowrite32(bytes, fifo_mem +
33628 SVGA_FIFO_RESERVED);
33629 - return fifo_mem + (next_cmd >> 2);
33630 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
33631 } else {
33632 need_bounce = true;
33633 }
33634 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33635
33636 fm = vmw_fifo_reserve(dev_priv, bytes);
33637 if (unlikely(fm == NULL)) {
33638 - *seqno = atomic_read(&dev_priv->marker_seq);
33639 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33640 ret = -ENOMEM;
33641 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
33642 false, 3*HZ);
33643 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33644 }
33645
33646 do {
33647 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
33648 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
33649 } while (*seqno == 0);
33650
33651 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
33652 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33653 index 4640adb..e1384ed 100644
33654 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33655 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33656 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
33657 * emitted. Then the fence is stale and signaled.
33658 */
33659
33660 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
33661 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
33662 > VMW_FENCE_WRAP);
33663
33664 return ret;
33665 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
33666
33667 if (fifo_idle)
33668 down_read(&fifo_state->rwsem);
33669 - signal_seq = atomic_read(&dev_priv->marker_seq);
33670 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
33671 ret = 0;
33672
33673 for (;;) {
33674 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33675 index 8a8725c..afed796 100644
33676 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33677 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33678 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
33679 while (!vmw_lag_lt(queue, us)) {
33680 spin_lock(&queue->lock);
33681 if (list_empty(&queue->head))
33682 - seqno = atomic_read(&dev_priv->marker_seq);
33683 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33684 else {
33685 marker = list_first_entry(&queue->head,
33686 struct vmw_marker, head);
33687 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
33688 index 52146db..ae33762 100644
33689 --- a/drivers/hid/hid-core.c
33690 +++ b/drivers/hid/hid-core.c
33691 @@ -2201,7 +2201,7 @@ static bool hid_ignore(struct hid_device *hdev)
33692
33693 int hid_add_device(struct hid_device *hdev)
33694 {
33695 - static atomic_t id = ATOMIC_INIT(0);
33696 + static atomic_unchecked_t id = ATOMIC_INIT(0);
33697 int ret;
33698
33699 if (WARN_ON(hdev->status & HID_STAT_ADDED))
33700 @@ -2236,7 +2236,7 @@ int hid_add_device(struct hid_device *hdev)
33701 /* XXX hack, any other cleaner solution after the driver core
33702 * is converted to allow more than 20 bytes as the device name? */
33703 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
33704 - hdev->vendor, hdev->product, atomic_inc_return(&id));
33705 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
33706
33707 hid_debug_register(hdev, dev_name(&hdev->dev));
33708 ret = device_add(&hdev->dev);
33709 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
33710 index eec3291..8ed706b 100644
33711 --- a/drivers/hid/hid-wiimote-debug.c
33712 +++ b/drivers/hid/hid-wiimote-debug.c
33713 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
33714 else if (size == 0)
33715 return -EIO;
33716
33717 - if (copy_to_user(u, buf, size))
33718 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
33719 return -EFAULT;
33720
33721 *off += size;
33722 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
33723 index 14599e2..711c965 100644
33724 --- a/drivers/hid/usbhid/hiddev.c
33725 +++ b/drivers/hid/usbhid/hiddev.c
33726 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
33727 break;
33728
33729 case HIDIOCAPPLICATION:
33730 - if (arg < 0 || arg >= hid->maxapplication)
33731 + if (arg >= hid->maxapplication)
33732 break;
33733
33734 for (i = 0; i < hid->maxcollection; i++)
33735 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
33736 index f4c3d28..82f45a9 100644
33737 --- a/drivers/hv/channel.c
33738 +++ b/drivers/hv/channel.c
33739 @@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
33740 int ret = 0;
33741 int t;
33742
33743 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
33744 - atomic_inc(&vmbus_connection.next_gpadl_handle);
33745 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
33746 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
33747
33748 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
33749 if (ret)
33750 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
33751 index 3648f8f..30ef30d 100644
33752 --- a/drivers/hv/hv.c
33753 +++ b/drivers/hv/hv.c
33754 @@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
33755 u64 output_address = (output) ? virt_to_phys(output) : 0;
33756 u32 output_address_hi = output_address >> 32;
33757 u32 output_address_lo = output_address & 0xFFFFFFFF;
33758 - void *hypercall_page = hv_context.hypercall_page;
33759 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
33760
33761 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
33762 "=a"(hv_status_lo) : "d" (control_hi),
33763 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
33764 index d8d1fad..b91caf7 100644
33765 --- a/drivers/hv/hyperv_vmbus.h
33766 +++ b/drivers/hv/hyperv_vmbus.h
33767 @@ -594,7 +594,7 @@ enum vmbus_connect_state {
33768 struct vmbus_connection {
33769 enum vmbus_connect_state conn_state;
33770
33771 - atomic_t next_gpadl_handle;
33772 + atomic_unchecked_t next_gpadl_handle;
33773
33774 /*
33775 * Represents channel interrupts. Each bit position represents a
33776 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
33777 index 8e1a9ec..4687821 100644
33778 --- a/drivers/hv/vmbus_drv.c
33779 +++ b/drivers/hv/vmbus_drv.c
33780 @@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
33781 {
33782 int ret = 0;
33783
33784 - static atomic_t device_num = ATOMIC_INIT(0);
33785 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
33786
33787 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
33788 - atomic_inc_return(&device_num));
33789 + atomic_inc_return_unchecked(&device_num));
33790
33791 child_device_obj->device.bus = &hv_bus;
33792 child_device_obj->device.parent = &hv_acpi_dev->dev;
33793 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
33794 index 07a0c1a..0cac334 100644
33795 --- a/drivers/hwmon/sht15.c
33796 +++ b/drivers/hwmon/sht15.c
33797 @@ -169,7 +169,7 @@ struct sht15_data {
33798 int supply_uV;
33799 bool supply_uV_valid;
33800 struct work_struct update_supply_work;
33801 - atomic_t interrupt_handled;
33802 + atomic_unchecked_t interrupt_handled;
33803 };
33804
33805 /**
33806 @@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
33807 return ret;
33808
33809 gpio_direction_input(data->pdata->gpio_data);
33810 - atomic_set(&data->interrupt_handled, 0);
33811 + atomic_set_unchecked(&data->interrupt_handled, 0);
33812
33813 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33814 if (gpio_get_value(data->pdata->gpio_data) == 0) {
33815 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
33816 /* Only relevant if the interrupt hasn't occurred. */
33817 - if (!atomic_read(&data->interrupt_handled))
33818 + if (!atomic_read_unchecked(&data->interrupt_handled))
33819 schedule_work(&data->read_work);
33820 }
33821 ret = wait_event_timeout(data->wait_queue,
33822 @@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
33823
33824 /* First disable the interrupt */
33825 disable_irq_nosync(irq);
33826 - atomic_inc(&data->interrupt_handled);
33827 + atomic_inc_unchecked(&data->interrupt_handled);
33828 /* Then schedule a reading work struct */
33829 if (data->state != SHT15_READING_NOTHING)
33830 schedule_work(&data->read_work);
33831 @@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
33832 * If not, then start the interrupt again - care here as could
33833 * have gone low in meantime so verify it hasn't!
33834 */
33835 - atomic_set(&data->interrupt_handled, 0);
33836 + atomic_set_unchecked(&data->interrupt_handled, 0);
33837 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33838 /* If still not occurred or another handler was scheduled */
33839 if (gpio_get_value(data->pdata->gpio_data)
33840 - || atomic_read(&data->interrupt_handled))
33841 + || atomic_read_unchecked(&data->interrupt_handled))
33842 return;
33843 }
33844
33845 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
33846 index 378fcb5..5e91fa8 100644
33847 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
33848 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
33849 @@ -43,7 +43,7 @@
33850 extern struct i2c_adapter amd756_smbus;
33851
33852 static struct i2c_adapter *s4882_adapter;
33853 -static struct i2c_algorithm *s4882_algo;
33854 +static i2c_algorithm_no_const *s4882_algo;
33855
33856 /* Wrapper access functions for multiplexed SMBus */
33857 static DEFINE_MUTEX(amd756_lock);
33858 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
33859 index 29015eb..af2d8e9 100644
33860 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
33861 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
33862 @@ -41,7 +41,7 @@
33863 extern struct i2c_adapter *nforce2_smbus;
33864
33865 static struct i2c_adapter *s4985_adapter;
33866 -static struct i2c_algorithm *s4985_algo;
33867 +static i2c_algorithm_no_const *s4985_algo;
33868
33869 /* Wrapper access functions for multiplexed SMBus */
33870 static DEFINE_MUTEX(nforce2_lock);
33871 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
33872 index 8126824..55a2798 100644
33873 --- a/drivers/ide/ide-cd.c
33874 +++ b/drivers/ide/ide-cd.c
33875 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
33876 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
33877 if ((unsigned long)buf & alignment
33878 || blk_rq_bytes(rq) & q->dma_pad_mask
33879 - || object_is_on_stack(buf))
33880 + || object_starts_on_stack(buf))
33881 drive->dma = 0;
33882 }
33883 }
33884 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
33885 index 394fea2..c833880 100644
33886 --- a/drivers/infiniband/core/cm.c
33887 +++ b/drivers/infiniband/core/cm.c
33888 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
33889
33890 struct cm_counter_group {
33891 struct kobject obj;
33892 - atomic_long_t counter[CM_ATTR_COUNT];
33893 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
33894 };
33895
33896 struct cm_counter_attribute {
33897 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
33898 struct ib_mad_send_buf *msg = NULL;
33899 int ret;
33900
33901 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33902 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33903 counter[CM_REQ_COUNTER]);
33904
33905 /* Quick state check to discard duplicate REQs. */
33906 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
33907 if (!cm_id_priv)
33908 return;
33909
33910 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33911 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33912 counter[CM_REP_COUNTER]);
33913 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
33914 if (ret)
33915 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
33916 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
33917 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
33918 spin_unlock_irq(&cm_id_priv->lock);
33919 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33920 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33921 counter[CM_RTU_COUNTER]);
33922 goto out;
33923 }
33924 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
33925 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
33926 dreq_msg->local_comm_id);
33927 if (!cm_id_priv) {
33928 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33929 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33930 counter[CM_DREQ_COUNTER]);
33931 cm_issue_drep(work->port, work->mad_recv_wc);
33932 return -EINVAL;
33933 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
33934 case IB_CM_MRA_REP_RCVD:
33935 break;
33936 case IB_CM_TIMEWAIT:
33937 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33938 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33939 counter[CM_DREQ_COUNTER]);
33940 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33941 goto unlock;
33942 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
33943 cm_free_msg(msg);
33944 goto deref;
33945 case IB_CM_DREQ_RCVD:
33946 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33947 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33948 counter[CM_DREQ_COUNTER]);
33949 goto unlock;
33950 default:
33951 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
33952 ib_modify_mad(cm_id_priv->av.port->mad_agent,
33953 cm_id_priv->msg, timeout)) {
33954 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
33955 - atomic_long_inc(&work->port->
33956 + atomic_long_inc_unchecked(&work->port->
33957 counter_group[CM_RECV_DUPLICATES].
33958 counter[CM_MRA_COUNTER]);
33959 goto out;
33960 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
33961 break;
33962 case IB_CM_MRA_REQ_RCVD:
33963 case IB_CM_MRA_REP_RCVD:
33964 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33965 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33966 counter[CM_MRA_COUNTER]);
33967 /* fall through */
33968 default:
33969 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
33970 case IB_CM_LAP_IDLE:
33971 break;
33972 case IB_CM_MRA_LAP_SENT:
33973 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33974 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33975 counter[CM_LAP_COUNTER]);
33976 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33977 goto unlock;
33978 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
33979 cm_free_msg(msg);
33980 goto deref;
33981 case IB_CM_LAP_RCVD:
33982 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33983 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33984 counter[CM_LAP_COUNTER]);
33985 goto unlock;
33986 default:
33987 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
33988 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
33989 if (cur_cm_id_priv) {
33990 spin_unlock_irq(&cm.lock);
33991 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33992 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33993 counter[CM_SIDR_REQ_COUNTER]);
33994 goto out; /* Duplicate message. */
33995 }
33996 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
33997 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
33998 msg->retries = 1;
33999
34000 - atomic_long_add(1 + msg->retries,
34001 + atomic_long_add_unchecked(1 + msg->retries,
34002 &port->counter_group[CM_XMIT].counter[attr_index]);
34003 if (msg->retries)
34004 - atomic_long_add(msg->retries,
34005 + atomic_long_add_unchecked(msg->retries,
34006 &port->counter_group[CM_XMIT_RETRIES].
34007 counter[attr_index]);
34008
34009 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
34010 }
34011
34012 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
34013 - atomic_long_inc(&port->counter_group[CM_RECV].
34014 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
34015 counter[attr_id - CM_ATTR_ID_OFFSET]);
34016
34017 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
34018 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
34019 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
34020
34021 return sprintf(buf, "%ld\n",
34022 - atomic_long_read(&group->counter[cm_attr->index]));
34023 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
34024 }
34025
34026 static const struct sysfs_ops cm_counter_ops = {
34027 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
34028 index 176c8f9..2627b62 100644
34029 --- a/drivers/infiniband/core/fmr_pool.c
34030 +++ b/drivers/infiniband/core/fmr_pool.c
34031 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
34032
34033 struct task_struct *thread;
34034
34035 - atomic_t req_ser;
34036 - atomic_t flush_ser;
34037 + atomic_unchecked_t req_ser;
34038 + atomic_unchecked_t flush_ser;
34039
34040 wait_queue_head_t force_wait;
34041 };
34042 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34043 struct ib_fmr_pool *pool = pool_ptr;
34044
34045 do {
34046 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
34047 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
34048 ib_fmr_batch_release(pool);
34049
34050 - atomic_inc(&pool->flush_ser);
34051 + atomic_inc_unchecked(&pool->flush_ser);
34052 wake_up_interruptible(&pool->force_wait);
34053
34054 if (pool->flush_function)
34055 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34056 }
34057
34058 set_current_state(TASK_INTERRUPTIBLE);
34059 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
34060 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
34061 !kthread_should_stop())
34062 schedule();
34063 __set_current_state(TASK_RUNNING);
34064 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
34065 pool->dirty_watermark = params->dirty_watermark;
34066 pool->dirty_len = 0;
34067 spin_lock_init(&pool->pool_lock);
34068 - atomic_set(&pool->req_ser, 0);
34069 - atomic_set(&pool->flush_ser, 0);
34070 + atomic_set_unchecked(&pool->req_ser, 0);
34071 + atomic_set_unchecked(&pool->flush_ser, 0);
34072 init_waitqueue_head(&pool->force_wait);
34073
34074 pool->thread = kthread_run(ib_fmr_cleanup_thread,
34075 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
34076 }
34077 spin_unlock_irq(&pool->pool_lock);
34078
34079 - serial = atomic_inc_return(&pool->req_ser);
34080 + serial = atomic_inc_return_unchecked(&pool->req_ser);
34081 wake_up_process(pool->thread);
34082
34083 if (wait_event_interruptible(pool->force_wait,
34084 - atomic_read(&pool->flush_ser) - serial >= 0))
34085 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
34086 return -EINTR;
34087
34088 return 0;
34089 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
34090 } else {
34091 list_add_tail(&fmr->list, &pool->dirty_list);
34092 if (++pool->dirty_len >= pool->dirty_watermark) {
34093 - atomic_inc(&pool->req_ser);
34094 + atomic_inc_unchecked(&pool->req_ser);
34095 wake_up_process(pool->thread);
34096 }
34097 }
34098 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
34099 index afd8179..598063f 100644
34100 --- a/drivers/infiniband/hw/cxgb4/mem.c
34101 +++ b/drivers/infiniband/hw/cxgb4/mem.c
34102 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34103 int err;
34104 struct fw_ri_tpte tpt;
34105 u32 stag_idx;
34106 - static atomic_t key;
34107 + static atomic_unchecked_t key;
34108
34109 if (c4iw_fatal_error(rdev))
34110 return -EIO;
34111 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34112 if (rdev->stats.stag.cur > rdev->stats.stag.max)
34113 rdev->stats.stag.max = rdev->stats.stag.cur;
34114 mutex_unlock(&rdev->stats.lock);
34115 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
34116 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
34117 }
34118 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
34119 __func__, stag_state, type, pdid, stag_idx);
34120 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
34121 index 79b3dbc..96e5fcc 100644
34122 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
34123 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
34124 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34125 struct ib_atomic_eth *ateth;
34126 struct ipath_ack_entry *e;
34127 u64 vaddr;
34128 - atomic64_t *maddr;
34129 + atomic64_unchecked_t *maddr;
34130 u64 sdata;
34131 u32 rkey;
34132 u8 next;
34133 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34134 IB_ACCESS_REMOTE_ATOMIC)))
34135 goto nack_acc_unlck;
34136 /* Perform atomic OP and save result. */
34137 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34138 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34139 sdata = be64_to_cpu(ateth->swap_data);
34140 e = &qp->s_ack_queue[qp->r_head_ack_queue];
34141 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
34142 - (u64) atomic64_add_return(sdata, maddr) - sdata :
34143 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34144 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34145 be64_to_cpu(ateth->compare_data),
34146 sdata);
34147 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
34148 index 1f95bba..9530f87 100644
34149 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
34150 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
34151 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
34152 unsigned long flags;
34153 struct ib_wc wc;
34154 u64 sdata;
34155 - atomic64_t *maddr;
34156 + atomic64_unchecked_t *maddr;
34157 enum ib_wc_status send_status;
34158
34159 /*
34160 @@ -382,11 +382,11 @@ again:
34161 IB_ACCESS_REMOTE_ATOMIC)))
34162 goto acc_err;
34163 /* Perform atomic OP and save result. */
34164 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34165 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34166 sdata = wqe->wr.wr.atomic.compare_add;
34167 *(u64 *) sqp->s_sge.sge.vaddr =
34168 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
34169 - (u64) atomic64_add_return(sdata, maddr) - sdata :
34170 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34171 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34172 sdata, wqe->wr.wr.atomic.swap);
34173 goto send_comp;
34174 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
34175 index 748db2d..5f75cc3 100644
34176 --- a/drivers/infiniband/hw/nes/nes.c
34177 +++ b/drivers/infiniband/hw/nes/nes.c
34178 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
34179 LIST_HEAD(nes_adapter_list);
34180 static LIST_HEAD(nes_dev_list);
34181
34182 -atomic_t qps_destroyed;
34183 +atomic_unchecked_t qps_destroyed;
34184
34185 static unsigned int ee_flsh_adapter;
34186 static unsigned int sysfs_nonidx_addr;
34187 @@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
34188 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
34189 struct nes_adapter *nesadapter = nesdev->nesadapter;
34190
34191 - atomic_inc(&qps_destroyed);
34192 + atomic_inc_unchecked(&qps_destroyed);
34193
34194 /* Free the control structures */
34195
34196 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
34197 index 33cc589..3bd6538 100644
34198 --- a/drivers/infiniband/hw/nes/nes.h
34199 +++ b/drivers/infiniband/hw/nes/nes.h
34200 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
34201 extern unsigned int wqm_quanta;
34202 extern struct list_head nes_adapter_list;
34203
34204 -extern atomic_t cm_connects;
34205 -extern atomic_t cm_accepts;
34206 -extern atomic_t cm_disconnects;
34207 -extern atomic_t cm_closes;
34208 -extern atomic_t cm_connecteds;
34209 -extern atomic_t cm_connect_reqs;
34210 -extern atomic_t cm_rejects;
34211 -extern atomic_t mod_qp_timouts;
34212 -extern atomic_t qps_created;
34213 -extern atomic_t qps_destroyed;
34214 -extern atomic_t sw_qps_destroyed;
34215 +extern atomic_unchecked_t cm_connects;
34216 +extern atomic_unchecked_t cm_accepts;
34217 +extern atomic_unchecked_t cm_disconnects;
34218 +extern atomic_unchecked_t cm_closes;
34219 +extern atomic_unchecked_t cm_connecteds;
34220 +extern atomic_unchecked_t cm_connect_reqs;
34221 +extern atomic_unchecked_t cm_rejects;
34222 +extern atomic_unchecked_t mod_qp_timouts;
34223 +extern atomic_unchecked_t qps_created;
34224 +extern atomic_unchecked_t qps_destroyed;
34225 +extern atomic_unchecked_t sw_qps_destroyed;
34226 extern u32 mh_detected;
34227 extern u32 mh_pauses_sent;
34228 extern u32 cm_packets_sent;
34229 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
34230 extern u32 cm_packets_received;
34231 extern u32 cm_packets_dropped;
34232 extern u32 cm_packets_retrans;
34233 -extern atomic_t cm_listens_created;
34234 -extern atomic_t cm_listens_destroyed;
34235 +extern atomic_unchecked_t cm_listens_created;
34236 +extern atomic_unchecked_t cm_listens_destroyed;
34237 extern u32 cm_backlog_drops;
34238 -extern atomic_t cm_loopbacks;
34239 -extern atomic_t cm_nodes_created;
34240 -extern atomic_t cm_nodes_destroyed;
34241 -extern atomic_t cm_accel_dropped_pkts;
34242 -extern atomic_t cm_resets_recvd;
34243 -extern atomic_t pau_qps_created;
34244 -extern atomic_t pau_qps_destroyed;
34245 +extern atomic_unchecked_t cm_loopbacks;
34246 +extern atomic_unchecked_t cm_nodes_created;
34247 +extern atomic_unchecked_t cm_nodes_destroyed;
34248 +extern atomic_unchecked_t cm_accel_dropped_pkts;
34249 +extern atomic_unchecked_t cm_resets_recvd;
34250 +extern atomic_unchecked_t pau_qps_created;
34251 +extern atomic_unchecked_t pau_qps_destroyed;
34252
34253 extern u32 int_mod_timer_init;
34254 extern u32 int_mod_cq_depth_256;
34255 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
34256 index cfaacaf..fa0722e 100644
34257 --- a/drivers/infiniband/hw/nes/nes_cm.c
34258 +++ b/drivers/infiniband/hw/nes/nes_cm.c
34259 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
34260 u32 cm_packets_retrans;
34261 u32 cm_packets_created;
34262 u32 cm_packets_received;
34263 -atomic_t cm_listens_created;
34264 -atomic_t cm_listens_destroyed;
34265 +atomic_unchecked_t cm_listens_created;
34266 +atomic_unchecked_t cm_listens_destroyed;
34267 u32 cm_backlog_drops;
34268 -atomic_t cm_loopbacks;
34269 -atomic_t cm_nodes_created;
34270 -atomic_t cm_nodes_destroyed;
34271 -atomic_t cm_accel_dropped_pkts;
34272 -atomic_t cm_resets_recvd;
34273 +atomic_unchecked_t cm_loopbacks;
34274 +atomic_unchecked_t cm_nodes_created;
34275 +atomic_unchecked_t cm_nodes_destroyed;
34276 +atomic_unchecked_t cm_accel_dropped_pkts;
34277 +atomic_unchecked_t cm_resets_recvd;
34278
34279 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
34280 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
34281 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
34282
34283 static struct nes_cm_core *g_cm_core;
34284
34285 -atomic_t cm_connects;
34286 -atomic_t cm_accepts;
34287 -atomic_t cm_disconnects;
34288 -atomic_t cm_closes;
34289 -atomic_t cm_connecteds;
34290 -atomic_t cm_connect_reqs;
34291 -atomic_t cm_rejects;
34292 +atomic_unchecked_t cm_connects;
34293 +atomic_unchecked_t cm_accepts;
34294 +atomic_unchecked_t cm_disconnects;
34295 +atomic_unchecked_t cm_closes;
34296 +atomic_unchecked_t cm_connecteds;
34297 +atomic_unchecked_t cm_connect_reqs;
34298 +atomic_unchecked_t cm_rejects;
34299
34300 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
34301 {
34302 @@ -1281,7 +1281,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
34303 kfree(listener);
34304 listener = NULL;
34305 ret = 0;
34306 - atomic_inc(&cm_listens_destroyed);
34307 + atomic_inc_unchecked(&cm_listens_destroyed);
34308 } else {
34309 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
34310 }
34311 @@ -1480,7 +1480,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
34312 cm_node->rem_mac);
34313
34314 add_hte_node(cm_core, cm_node);
34315 - atomic_inc(&cm_nodes_created);
34316 + atomic_inc_unchecked(&cm_nodes_created);
34317
34318 return cm_node;
34319 }
34320 @@ -1538,7 +1538,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
34321 }
34322
34323 atomic_dec(&cm_core->node_cnt);
34324 - atomic_inc(&cm_nodes_destroyed);
34325 + atomic_inc_unchecked(&cm_nodes_destroyed);
34326 nesqp = cm_node->nesqp;
34327 if (nesqp) {
34328 nesqp->cm_node = NULL;
34329 @@ -1602,7 +1602,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
34330
34331 static void drop_packet(struct sk_buff *skb)
34332 {
34333 - atomic_inc(&cm_accel_dropped_pkts);
34334 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
34335 dev_kfree_skb_any(skb);
34336 }
34337
34338 @@ -1665,7 +1665,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
34339 {
34340
34341 int reset = 0; /* whether to send reset in case of err.. */
34342 - atomic_inc(&cm_resets_recvd);
34343 + atomic_inc_unchecked(&cm_resets_recvd);
34344 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
34345 " refcnt=%d\n", cm_node, cm_node->state,
34346 atomic_read(&cm_node->ref_count));
34347 @@ -2306,7 +2306,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
34348 rem_ref_cm_node(cm_node->cm_core, cm_node);
34349 return NULL;
34350 }
34351 - atomic_inc(&cm_loopbacks);
34352 + atomic_inc_unchecked(&cm_loopbacks);
34353 loopbackremotenode->loopbackpartner = cm_node;
34354 loopbackremotenode->tcp_cntxt.rcv_wscale =
34355 NES_CM_DEFAULT_RCV_WND_SCALE;
34356 @@ -2581,7 +2581,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
34357 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
34358 else {
34359 rem_ref_cm_node(cm_core, cm_node);
34360 - atomic_inc(&cm_accel_dropped_pkts);
34361 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
34362 dev_kfree_skb_any(skb);
34363 }
34364 break;
34365 @@ -2889,7 +2889,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
34366
34367 if ((cm_id) && (cm_id->event_handler)) {
34368 if (issue_disconn) {
34369 - atomic_inc(&cm_disconnects);
34370 + atomic_inc_unchecked(&cm_disconnects);
34371 cm_event.event = IW_CM_EVENT_DISCONNECT;
34372 cm_event.status = disconn_status;
34373 cm_event.local_addr = cm_id->local_addr;
34374 @@ -2911,7 +2911,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
34375 }
34376
34377 if (issue_close) {
34378 - atomic_inc(&cm_closes);
34379 + atomic_inc_unchecked(&cm_closes);
34380 nes_disconnect(nesqp, 1);
34381
34382 cm_id->provider_data = nesqp;
34383 @@ -3047,7 +3047,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34384
34385 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
34386 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
34387 - atomic_inc(&cm_accepts);
34388 + atomic_inc_unchecked(&cm_accepts);
34389
34390 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
34391 netdev_refcnt_read(nesvnic->netdev));
34392 @@ -3242,7 +3242,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
34393 struct nes_cm_core *cm_core;
34394 u8 *start_buff;
34395
34396 - atomic_inc(&cm_rejects);
34397 + atomic_inc_unchecked(&cm_rejects);
34398 cm_node = (struct nes_cm_node *)cm_id->provider_data;
34399 loopback = cm_node->loopbackpartner;
34400 cm_core = cm_node->cm_core;
34401 @@ -3302,7 +3302,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34402 ntohl(cm_id->local_addr.sin_addr.s_addr),
34403 ntohs(cm_id->local_addr.sin_port));
34404
34405 - atomic_inc(&cm_connects);
34406 + atomic_inc_unchecked(&cm_connects);
34407 nesqp->active_conn = 1;
34408
34409 /* cache the cm_id in the qp */
34410 @@ -3412,7 +3412,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
34411 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
34412 return err;
34413 }
34414 - atomic_inc(&cm_listens_created);
34415 + atomic_inc_unchecked(&cm_listens_created);
34416 }
34417
34418 cm_id->add_ref(cm_id);
34419 @@ -3513,7 +3513,7 @@ static void cm_event_connected(struct nes_cm_event *event)
34420
34421 if (nesqp->destroyed)
34422 return;
34423 - atomic_inc(&cm_connecteds);
34424 + atomic_inc_unchecked(&cm_connecteds);
34425 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
34426 " local port 0x%04X. jiffies = %lu.\n",
34427 nesqp->hwqp.qp_id,
34428 @@ -3693,7 +3693,7 @@ static void cm_event_reset(struct nes_cm_event *event)
34429
34430 cm_id->add_ref(cm_id);
34431 ret = cm_id->event_handler(cm_id, &cm_event);
34432 - atomic_inc(&cm_closes);
34433 + atomic_inc_unchecked(&cm_closes);
34434 cm_event.event = IW_CM_EVENT_CLOSE;
34435 cm_event.status = 0;
34436 cm_event.provider_data = cm_id->provider_data;
34437 @@ -3729,7 +3729,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
34438 return;
34439 cm_id = cm_node->cm_id;
34440
34441 - atomic_inc(&cm_connect_reqs);
34442 + atomic_inc_unchecked(&cm_connect_reqs);
34443 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34444 cm_node, cm_id, jiffies);
34445
34446 @@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
34447 return;
34448 cm_id = cm_node->cm_id;
34449
34450 - atomic_inc(&cm_connect_reqs);
34451 + atomic_inc_unchecked(&cm_connect_reqs);
34452 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34453 cm_node, cm_id, jiffies);
34454
34455 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
34456 index 3ba7be3..c81f6ff 100644
34457 --- a/drivers/infiniband/hw/nes/nes_mgt.c
34458 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
34459 @@ -40,8 +40,8 @@
34460 #include "nes.h"
34461 #include "nes_mgt.h"
34462
34463 -atomic_t pau_qps_created;
34464 -atomic_t pau_qps_destroyed;
34465 +atomic_unchecked_t pau_qps_created;
34466 +atomic_unchecked_t pau_qps_destroyed;
34467
34468 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
34469 {
34470 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
34471 {
34472 struct sk_buff *skb;
34473 unsigned long flags;
34474 - atomic_inc(&pau_qps_destroyed);
34475 + atomic_inc_unchecked(&pau_qps_destroyed);
34476
34477 /* Free packets that have not yet been forwarded */
34478 /* Lock is acquired by skb_dequeue when removing the skb */
34479 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
34480 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
34481 skb_queue_head_init(&nesqp->pau_list);
34482 spin_lock_init(&nesqp->pau_lock);
34483 - atomic_inc(&pau_qps_created);
34484 + atomic_inc_unchecked(&pau_qps_created);
34485 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
34486 }
34487
34488 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
34489 index 0564be7..f68b0f1 100644
34490 --- a/drivers/infiniband/hw/nes/nes_nic.c
34491 +++ b/drivers/infiniband/hw/nes/nes_nic.c
34492 @@ -1272,39 +1272,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
34493 target_stat_values[++index] = mh_detected;
34494 target_stat_values[++index] = mh_pauses_sent;
34495 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
34496 - target_stat_values[++index] = atomic_read(&cm_connects);
34497 - target_stat_values[++index] = atomic_read(&cm_accepts);
34498 - target_stat_values[++index] = atomic_read(&cm_disconnects);
34499 - target_stat_values[++index] = atomic_read(&cm_connecteds);
34500 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
34501 - target_stat_values[++index] = atomic_read(&cm_rejects);
34502 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
34503 - target_stat_values[++index] = atomic_read(&qps_created);
34504 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
34505 - target_stat_values[++index] = atomic_read(&qps_destroyed);
34506 - target_stat_values[++index] = atomic_read(&cm_closes);
34507 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
34508 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
34509 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
34510 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
34511 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
34512 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
34513 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
34514 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
34515 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
34516 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
34517 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
34518 target_stat_values[++index] = cm_packets_sent;
34519 target_stat_values[++index] = cm_packets_bounced;
34520 target_stat_values[++index] = cm_packets_created;
34521 target_stat_values[++index] = cm_packets_received;
34522 target_stat_values[++index] = cm_packets_dropped;
34523 target_stat_values[++index] = cm_packets_retrans;
34524 - target_stat_values[++index] = atomic_read(&cm_listens_created);
34525 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
34526 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
34527 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
34528 target_stat_values[++index] = cm_backlog_drops;
34529 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
34530 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
34531 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
34532 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
34533 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
34534 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
34535 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
34536 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
34537 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
34538 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
34539 target_stat_values[++index] = nesadapter->free_4kpbl;
34540 target_stat_values[++index] = nesadapter->free_256pbl;
34541 target_stat_values[++index] = int_mod_timer_init;
34542 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
34543 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
34544 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
34545 - target_stat_values[++index] = atomic_read(&pau_qps_created);
34546 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
34547 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
34548 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
34549 }
34550
34551 /**
34552 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
34553 index 07e4fba..685f041 100644
34554 --- a/drivers/infiniband/hw/nes/nes_verbs.c
34555 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
34556 @@ -46,9 +46,9 @@
34557
34558 #include <rdma/ib_umem.h>
34559
34560 -atomic_t mod_qp_timouts;
34561 -atomic_t qps_created;
34562 -atomic_t sw_qps_destroyed;
34563 +atomic_unchecked_t mod_qp_timouts;
34564 +atomic_unchecked_t qps_created;
34565 +atomic_unchecked_t sw_qps_destroyed;
34566
34567 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
34568
34569 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
34570 if (init_attr->create_flags)
34571 return ERR_PTR(-EINVAL);
34572
34573 - atomic_inc(&qps_created);
34574 + atomic_inc_unchecked(&qps_created);
34575 switch (init_attr->qp_type) {
34576 case IB_QPT_RC:
34577 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
34578 @@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
34579 struct iw_cm_event cm_event;
34580 int ret = 0;
34581
34582 - atomic_inc(&sw_qps_destroyed);
34583 + atomic_inc_unchecked(&sw_qps_destroyed);
34584 nesqp->destroyed = 1;
34585
34586 /* Blow away the connection if it exists. */
34587 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
34588 index 4d11575..3e890e5 100644
34589 --- a/drivers/infiniband/hw/qib/qib.h
34590 +++ b/drivers/infiniband/hw/qib/qib.h
34591 @@ -51,6 +51,7 @@
34592 #include <linux/completion.h>
34593 #include <linux/kref.h>
34594 #include <linux/sched.h>
34595 +#include <linux/slab.h>
34596
34597 #include "qib_common.h"
34598 #include "qib_verbs.h"
34599 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
34600 index da739d9..da1c7f4 100644
34601 --- a/drivers/input/gameport/gameport.c
34602 +++ b/drivers/input/gameport/gameport.c
34603 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
34604 */
34605 static void gameport_init_port(struct gameport *gameport)
34606 {
34607 - static atomic_t gameport_no = ATOMIC_INIT(0);
34608 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
34609
34610 __module_get(THIS_MODULE);
34611
34612 mutex_init(&gameport->drv_mutex);
34613 device_initialize(&gameport->dev);
34614 dev_set_name(&gameport->dev, "gameport%lu",
34615 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
34616 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
34617 gameport->dev.bus = &gameport_bus;
34618 gameport->dev.release = gameport_release_port;
34619 if (gameport->parent)
34620 diff --git a/drivers/input/input.c b/drivers/input/input.c
34621 index 53a0dde..abffda7 100644
34622 --- a/drivers/input/input.c
34623 +++ b/drivers/input/input.c
34624 @@ -1902,7 +1902,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
34625 */
34626 int input_register_device(struct input_dev *dev)
34627 {
34628 - static atomic_t input_no = ATOMIC_INIT(0);
34629 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
34630 struct input_handler *handler;
34631 unsigned int packet_size;
34632 const char *path;
34633 @@ -1945,7 +1945,7 @@ int input_register_device(struct input_dev *dev)
34634 dev->setkeycode = input_default_setkeycode;
34635
34636 dev_set_name(&dev->dev, "input%ld",
34637 - (unsigned long) atomic_inc_return(&input_no) - 1);
34638 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
34639
34640 error = device_add(&dev->dev);
34641 if (error)
34642 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
34643 index 04c69af..5f92d00 100644
34644 --- a/drivers/input/joystick/sidewinder.c
34645 +++ b/drivers/input/joystick/sidewinder.c
34646 @@ -30,6 +30,7 @@
34647 #include <linux/kernel.h>
34648 #include <linux/module.h>
34649 #include <linux/slab.h>
34650 +#include <linux/sched.h>
34651 #include <linux/init.h>
34652 #include <linux/input.h>
34653 #include <linux/gameport.h>
34654 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
34655 index 83811e4..0822b90 100644
34656 --- a/drivers/input/joystick/xpad.c
34657 +++ b/drivers/input/joystick/xpad.c
34658 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
34659
34660 static int xpad_led_probe(struct usb_xpad *xpad)
34661 {
34662 - static atomic_t led_seq = ATOMIC_INIT(0);
34663 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
34664 long led_no;
34665 struct xpad_led *led;
34666 struct led_classdev *led_cdev;
34667 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
34668 if (!led)
34669 return -ENOMEM;
34670
34671 - led_no = (long)atomic_inc_return(&led_seq) - 1;
34672 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
34673
34674 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
34675 led->xpad = xpad;
34676 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
34677 index 4c842c3..590b0bf 100644
34678 --- a/drivers/input/mousedev.c
34679 +++ b/drivers/input/mousedev.c
34680 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
34681
34682 spin_unlock_irq(&client->packet_lock);
34683
34684 - if (copy_to_user(buffer, data, count))
34685 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
34686 return -EFAULT;
34687
34688 return count;
34689 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
34690 index d0f7533..fb8215b 100644
34691 --- a/drivers/input/serio/serio.c
34692 +++ b/drivers/input/serio/serio.c
34693 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
34694 */
34695 static void serio_init_port(struct serio *serio)
34696 {
34697 - static atomic_t serio_no = ATOMIC_INIT(0);
34698 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
34699
34700 __module_get(THIS_MODULE);
34701
34702 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
34703 mutex_init(&serio->drv_mutex);
34704 device_initialize(&serio->dev);
34705 dev_set_name(&serio->dev, "serio%ld",
34706 - (long)atomic_inc_return(&serio_no) - 1);
34707 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
34708 serio->dev.bus = &serio_bus;
34709 serio->dev.release = serio_release_port;
34710 serio->dev.groups = serio_device_attr_groups;
34711 diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
34712 index faf10ba..7cfaba9 100644
34713 --- a/drivers/iommu/amd_iommu_init.c
34714 +++ b/drivers/iommu/amd_iommu_init.c
34715 @@ -1922,7 +1922,7 @@ static int __init state_next(void)
34716 case IOMMU_ACPI_FINISHED:
34717 early_enable_iommus();
34718 register_syscore_ops(&amd_iommu_syscore_ops);
34719 - x86_platform.iommu_shutdown = disable_iommus;
34720 + *(void **)&x86_platform.iommu_shutdown = disable_iommus;
34721 init_state = IOMMU_ENABLED;
34722 break;
34723 case IOMMU_ENABLED:
34724 @@ -2064,7 +2064,7 @@ int __init amd_iommu_detect(void)
34725
34726 amd_iommu_detected = true;
34727 iommu_detected = 1;
34728 - x86_init.iommu.iommu_init = amd_iommu_init;
34729 + *(void **)&x86_init.iommu.iommu_init = amd_iommu_init;
34730
34731 return 0;
34732 }
34733 diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
34734 index 86e2f4a..d1cec5d 100644
34735 --- a/drivers/iommu/dmar.c
34736 +++ b/drivers/iommu/dmar.c
34737 @@ -555,7 +555,7 @@ int __init detect_intel_iommu(void)
34738
34739 #ifdef CONFIG_X86
34740 if (ret)
34741 - x86_init.iommu.iommu_init = intel_iommu_init;
34742 + *(void **)&x86_init.iommu.iommu_init = intel_iommu_init;
34743 #endif
34744 }
34745 early_acpi_os_unmap_memory(dmar_tbl, dmar_tbl_size);
34746 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
34747 index c679867..6e2e34d 100644
34748 --- a/drivers/isdn/capi/capi.c
34749 +++ b/drivers/isdn/capi/capi.c
34750 @@ -83,8 +83,8 @@ struct capiminor {
34751
34752 struct capi20_appl *ap;
34753 u32 ncci;
34754 - atomic_t datahandle;
34755 - atomic_t msgid;
34756 + atomic_unchecked_t datahandle;
34757 + atomic_unchecked_t msgid;
34758
34759 struct tty_port port;
34760 int ttyinstop;
34761 @@ -393,7 +393,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
34762 capimsg_setu16(s, 2, mp->ap->applid);
34763 capimsg_setu8 (s, 4, CAPI_DATA_B3);
34764 capimsg_setu8 (s, 5, CAPI_RESP);
34765 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
34766 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
34767 capimsg_setu32(s, 8, mp->ncci);
34768 capimsg_setu16(s, 12, datahandle);
34769 }
34770 @@ -514,14 +514,14 @@ static void handle_minor_send(struct capiminor *mp)
34771 mp->outbytes -= len;
34772 spin_unlock_bh(&mp->outlock);
34773
34774 - datahandle = atomic_inc_return(&mp->datahandle);
34775 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
34776 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
34777 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34778 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34779 capimsg_setu16(skb->data, 2, mp->ap->applid);
34780 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
34781 capimsg_setu8 (skb->data, 5, CAPI_REQ);
34782 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
34783 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
34784 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
34785 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
34786 capimsg_setu16(skb->data, 16, len); /* Data length */
34787 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
34788 index 67abf3f..076b3a6 100644
34789 --- a/drivers/isdn/gigaset/interface.c
34790 +++ b/drivers/isdn/gigaset/interface.c
34791 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
34792 }
34793 tty->driver_data = cs;
34794
34795 - ++cs->port.count;
34796 + atomic_inc(&cs->port.count);
34797
34798 - if (cs->port.count == 1) {
34799 + if (atomic_read(&cs->port.count) == 1) {
34800 tty_port_tty_set(&cs->port, tty);
34801 tty->low_latency = 1;
34802 }
34803 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
34804
34805 if (!cs->connected)
34806 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
34807 - else if (!cs->port.count)
34808 + else if (!atomic_read(&cs->port.count))
34809 dev_warn(cs->dev, "%s: device not opened\n", __func__);
34810 - else if (!--cs->port.count)
34811 + else if (!atomic_dec_return(&cs->port.count))
34812 tty_port_tty_set(&cs->port, NULL);
34813
34814 mutex_unlock(&cs->mutex);
34815 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
34816 index 821f7ac..28d4030 100644
34817 --- a/drivers/isdn/hardware/avm/b1.c
34818 +++ b/drivers/isdn/hardware/avm/b1.c
34819 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
34820 }
34821 if (left) {
34822 if (t4file->user) {
34823 - if (copy_from_user(buf, dp, left))
34824 + if (left > sizeof buf || copy_from_user(buf, dp, left))
34825 return -EFAULT;
34826 } else {
34827 memcpy(buf, dp, left);
34828 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
34829 }
34830 if (left) {
34831 if (config->user) {
34832 - if (copy_from_user(buf, dp, left))
34833 + if (left > sizeof buf || copy_from_user(buf, dp, left))
34834 return -EFAULT;
34835 } else {
34836 memcpy(buf, dp, left);
34837 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
34838 index b817809..409caff 100644
34839 --- a/drivers/isdn/i4l/isdn_tty.c
34840 +++ b/drivers/isdn/i4l/isdn_tty.c
34841 @@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
34842
34843 #ifdef ISDN_DEBUG_MODEM_OPEN
34844 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
34845 - port->count);
34846 + atomic_read(&port->count));
34847 #endif
34848 - port->count++;
34849 + atomic_inc(&port->count);
34850 port->tty = tty;
34851 /*
34852 * Start up serial port
34853 @@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34854 #endif
34855 return;
34856 }
34857 - if ((tty->count == 1) && (port->count != 1)) {
34858 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
34859 /*
34860 * Uh, oh. tty->count is 1, which means that the tty
34861 * structure will be freed. Info->count should always
34862 @@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34863 * serial port won't be shutdown.
34864 */
34865 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
34866 - "info->count is %d\n", port->count);
34867 - port->count = 1;
34868 + "info->count is %d\n", atomic_read(&port->count));
34869 + atomic_set(&port->count, 1);
34870 }
34871 - if (--port->count < 0) {
34872 + if (atomic_dec_return(&port->count) < 0) {
34873 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
34874 - info->line, port->count);
34875 - port->count = 0;
34876 + info->line, atomic_read(&port->count));
34877 + atomic_set(&port->count, 0);
34878 }
34879 - if (port->count) {
34880 + if (atomic_read(&port->count)) {
34881 #ifdef ISDN_DEBUG_MODEM_OPEN
34882 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
34883 #endif
34884 @@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
34885 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
34886 return;
34887 isdn_tty_shutdown(info);
34888 - port->count = 0;
34889 + atomic_set(&port->count, 0);
34890 port->flags &= ~ASYNC_NORMAL_ACTIVE;
34891 port->tty = NULL;
34892 wake_up_interruptible(&port->open_wait);
34893 @@ -1971,7 +1971,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
34894 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
34895 modem_info *info = &dev->mdm.info[i];
34896
34897 - if (info->port.count == 0)
34898 + if (atomic_read(&info->port.count) == 0)
34899 continue;
34900 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
34901 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
34902 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
34903 index e74df7c..03a03ba 100644
34904 --- a/drivers/isdn/icn/icn.c
34905 +++ b/drivers/isdn/icn/icn.c
34906 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
34907 if (count > len)
34908 count = len;
34909 if (user) {
34910 - if (copy_from_user(msg, buf, count))
34911 + if (count > sizeof msg || copy_from_user(msg, buf, count))
34912 return -EFAULT;
34913 } else
34914 memcpy(msg, buf, count);
34915 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
34916 index b5fdcb7..5b6c59f 100644
34917 --- a/drivers/lguest/core.c
34918 +++ b/drivers/lguest/core.c
34919 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
34920 * it's worked so far. The end address needs +1 because __get_vm_area
34921 * allocates an extra guard page, so we need space for that.
34922 */
34923 +
34924 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
34925 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34926 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
34927 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34928 +#else
34929 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34930 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
34931 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34932 +#endif
34933 +
34934 if (!switcher_vma) {
34935 err = -ENOMEM;
34936 printk("lguest: could not map switcher pages high\n");
34937 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
34938 * Now the Switcher is mapped at the right address, we can't fail!
34939 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
34940 */
34941 - memcpy(switcher_vma->addr, start_switcher_text,
34942 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
34943 end_switcher_text - start_switcher_text);
34944
34945 printk(KERN_INFO "lguest: mapped switcher at %p\n",
34946 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
34947 index 4af12e1..0e89afe 100644
34948 --- a/drivers/lguest/x86/core.c
34949 +++ b/drivers/lguest/x86/core.c
34950 @@ -59,7 +59,7 @@ static struct {
34951 /* Offset from where switcher.S was compiled to where we've copied it */
34952 static unsigned long switcher_offset(void)
34953 {
34954 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
34955 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
34956 }
34957
34958 /* This cpu's struct lguest_pages. */
34959 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
34960 * These copies are pretty cheap, so we do them unconditionally: */
34961 /* Save the current Host top-level page directory.
34962 */
34963 +
34964 +#ifdef CONFIG_PAX_PER_CPU_PGD
34965 + pages->state.host_cr3 = read_cr3();
34966 +#else
34967 pages->state.host_cr3 = __pa(current->mm->pgd);
34968 +#endif
34969 +
34970 /*
34971 * Set up the Guest's page tables to see this CPU's pages (and no
34972 * other CPU's pages).
34973 @@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
34974 * compiled-in switcher code and the high-mapped copy we just made.
34975 */
34976 for (i = 0; i < IDT_ENTRIES; i++)
34977 - default_idt_entries[i] += switcher_offset();
34978 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
34979
34980 /*
34981 * Set up the Switcher's per-cpu areas.
34982 @@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
34983 * it will be undisturbed when we switch. To change %cs and jump we
34984 * need this structure to feed to Intel's "lcall" instruction.
34985 */
34986 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
34987 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
34988 lguest_entry.segment = LGUEST_CS;
34989
34990 /*
34991 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
34992 index 40634b0..4f5855e 100644
34993 --- a/drivers/lguest/x86/switcher_32.S
34994 +++ b/drivers/lguest/x86/switcher_32.S
34995 @@ -87,6 +87,7 @@
34996 #include <asm/page.h>
34997 #include <asm/segment.h>
34998 #include <asm/lguest.h>
34999 +#include <asm/processor-flags.h>
35000
35001 // We mark the start of the code to copy
35002 // It's placed in .text tho it's never run here
35003 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
35004 // Changes type when we load it: damn Intel!
35005 // For after we switch over our page tables
35006 // That entry will be read-only: we'd crash.
35007 +
35008 +#ifdef CONFIG_PAX_KERNEXEC
35009 + mov %cr0, %edx
35010 + xor $X86_CR0_WP, %edx
35011 + mov %edx, %cr0
35012 +#endif
35013 +
35014 movl $(GDT_ENTRY_TSS*8), %edx
35015 ltr %dx
35016
35017 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
35018 // Let's clear it again for our return.
35019 // The GDT descriptor of the Host
35020 // Points to the table after two "size" bytes
35021 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
35022 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
35023 // Clear "used" from type field (byte 5, bit 2)
35024 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
35025 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
35026 +
35027 +#ifdef CONFIG_PAX_KERNEXEC
35028 + mov %cr0, %eax
35029 + xor $X86_CR0_WP, %eax
35030 + mov %eax, %cr0
35031 +#endif
35032
35033 // Once our page table's switched, the Guest is live!
35034 // The Host fades as we run this final step.
35035 @@ -295,13 +309,12 @@ deliver_to_host:
35036 // I consulted gcc, and it gave
35037 // These instructions, which I gladly credit:
35038 leal (%edx,%ebx,8), %eax
35039 - movzwl (%eax),%edx
35040 - movl 4(%eax), %eax
35041 - xorw %ax, %ax
35042 - orl %eax, %edx
35043 + movl 4(%eax), %edx
35044 + movw (%eax), %dx
35045 // Now the address of the handler's in %edx
35046 // We call it now: its "iret" drops us home.
35047 - jmp *%edx
35048 + ljmp $__KERNEL_CS, $1f
35049 +1: jmp *%edx
35050
35051 // Every interrupt can come to us here
35052 // But we must truly tell each apart.
35053 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
35054 index 7155945..4bcc562 100644
35055 --- a/drivers/md/bitmap.c
35056 +++ b/drivers/md/bitmap.c
35057 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
35058 chunk_kb ? "KB" : "B");
35059 if (bitmap->storage.file) {
35060 seq_printf(seq, ", file: ");
35061 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
35062 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
35063 }
35064
35065 seq_printf(seq, "\n");
35066 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
35067 index a651d52..82f8a95 100644
35068 --- a/drivers/md/dm-ioctl.c
35069 +++ b/drivers/md/dm-ioctl.c
35070 @@ -1601,7 +1601,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
35071 cmd == DM_LIST_VERSIONS_CMD)
35072 return 0;
35073
35074 - if ((cmd == DM_DEV_CREATE_CMD)) {
35075 + if (cmd == DM_DEV_CREATE_CMD) {
35076 if (!*param->name) {
35077 DMWARN("name not supplied when creating device");
35078 return -EINVAL;
35079 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
35080 index fd61f98..8050783 100644
35081 --- a/drivers/md/dm-raid1.c
35082 +++ b/drivers/md/dm-raid1.c
35083 @@ -40,7 +40,7 @@ enum dm_raid1_error {
35084
35085 struct mirror {
35086 struct mirror_set *ms;
35087 - atomic_t error_count;
35088 + atomic_unchecked_t error_count;
35089 unsigned long error_type;
35090 struct dm_dev *dev;
35091 sector_t offset;
35092 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
35093 struct mirror *m;
35094
35095 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
35096 - if (!atomic_read(&m->error_count))
35097 + if (!atomic_read_unchecked(&m->error_count))
35098 return m;
35099
35100 return NULL;
35101 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35102 * simple way to tell if a device has encountered
35103 * errors.
35104 */
35105 - atomic_inc(&m->error_count);
35106 + atomic_inc_unchecked(&m->error_count);
35107
35108 if (test_and_set_bit(error_type, &m->error_type))
35109 return;
35110 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
35111 struct mirror *m = get_default_mirror(ms);
35112
35113 do {
35114 - if (likely(!atomic_read(&m->error_count)))
35115 + if (likely(!atomic_read_unchecked(&m->error_count)))
35116 return m;
35117
35118 if (m-- == ms->mirror)
35119 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
35120 {
35121 struct mirror *default_mirror = get_default_mirror(m->ms);
35122
35123 - return !atomic_read(&default_mirror->error_count);
35124 + return !atomic_read_unchecked(&default_mirror->error_count);
35125 }
35126
35127 static int mirror_available(struct mirror_set *ms, struct bio *bio)
35128 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
35129 */
35130 if (likely(region_in_sync(ms, region, 1)))
35131 m = choose_mirror(ms, bio->bi_sector);
35132 - else if (m && atomic_read(&m->error_count))
35133 + else if (m && atomic_read_unchecked(&m->error_count))
35134 m = NULL;
35135
35136 if (likely(m))
35137 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
35138 }
35139
35140 ms->mirror[mirror].ms = ms;
35141 - atomic_set(&(ms->mirror[mirror].error_count), 0);
35142 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
35143 ms->mirror[mirror].error_type = 0;
35144 ms->mirror[mirror].offset = offset;
35145
35146 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
35147 */
35148 static char device_status_char(struct mirror *m)
35149 {
35150 - if (!atomic_read(&(m->error_count)))
35151 + if (!atomic_read_unchecked(&(m->error_count)))
35152 return 'A';
35153
35154 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
35155 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
35156 index e2f87653..f279abe 100644
35157 --- a/drivers/md/dm-stripe.c
35158 +++ b/drivers/md/dm-stripe.c
35159 @@ -20,7 +20,7 @@ struct stripe {
35160 struct dm_dev *dev;
35161 sector_t physical_start;
35162
35163 - atomic_t error_count;
35164 + atomic_unchecked_t error_count;
35165 };
35166
35167 struct stripe_c {
35168 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
35169 kfree(sc);
35170 return r;
35171 }
35172 - atomic_set(&(sc->stripe[i].error_count), 0);
35173 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
35174 }
35175
35176 ti->private = sc;
35177 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
35178 DMEMIT("%d ", sc->stripes);
35179 for (i = 0; i < sc->stripes; i++) {
35180 DMEMIT("%s ", sc->stripe[i].dev->name);
35181 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
35182 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
35183 'D' : 'A';
35184 }
35185 buffer[i] = '\0';
35186 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
35187 */
35188 for (i = 0; i < sc->stripes; i++)
35189 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
35190 - atomic_inc(&(sc->stripe[i].error_count));
35191 - if (atomic_read(&(sc->stripe[i].error_count)) <
35192 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
35193 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
35194 DM_IO_ERROR_THRESHOLD)
35195 schedule_work(&sc->trigger_event);
35196 }
35197 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
35198 index fa29557..d24a5b7 100644
35199 --- a/drivers/md/dm-table.c
35200 +++ b/drivers/md/dm-table.c
35201 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
35202 if (!dev_size)
35203 return 0;
35204
35205 - if ((start >= dev_size) || (start + len > dev_size)) {
35206 + if ((start >= dev_size) || (len > dev_size - start)) {
35207 DMWARN("%s: %s too small for target: "
35208 "start=%llu, len=%llu, dev_size=%llu",
35209 dm_device_name(ti->table->md), bdevname(bdev, b),
35210 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
35211 index 693e149..b7e0fde 100644
35212 --- a/drivers/md/dm-thin-metadata.c
35213 +++ b/drivers/md/dm-thin-metadata.c
35214 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35215 {
35216 pmd->info.tm = pmd->tm;
35217 pmd->info.levels = 2;
35218 - pmd->info.value_type.context = pmd->data_sm;
35219 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35220 pmd->info.value_type.size = sizeof(__le64);
35221 pmd->info.value_type.inc = data_block_inc;
35222 pmd->info.value_type.dec = data_block_dec;
35223 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35224
35225 pmd->bl_info.tm = pmd->tm;
35226 pmd->bl_info.levels = 1;
35227 - pmd->bl_info.value_type.context = pmd->data_sm;
35228 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35229 pmd->bl_info.value_type.size = sizeof(__le64);
35230 pmd->bl_info.value_type.inc = data_block_inc;
35231 pmd->bl_info.value_type.dec = data_block_dec;
35232 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
35233 index 77e6eff..913d695 100644
35234 --- a/drivers/md/dm.c
35235 +++ b/drivers/md/dm.c
35236 @@ -182,9 +182,9 @@ struct mapped_device {
35237 /*
35238 * Event handling.
35239 */
35240 - atomic_t event_nr;
35241 + atomic_unchecked_t event_nr;
35242 wait_queue_head_t eventq;
35243 - atomic_t uevent_seq;
35244 + atomic_unchecked_t uevent_seq;
35245 struct list_head uevent_list;
35246 spinlock_t uevent_lock; /* Protect access to uevent_list */
35247
35248 @@ -1847,8 +1847,8 @@ static struct mapped_device *alloc_dev(int minor)
35249 rwlock_init(&md->map_lock);
35250 atomic_set(&md->holders, 1);
35251 atomic_set(&md->open_count, 0);
35252 - atomic_set(&md->event_nr, 0);
35253 - atomic_set(&md->uevent_seq, 0);
35254 + atomic_set_unchecked(&md->event_nr, 0);
35255 + atomic_set_unchecked(&md->uevent_seq, 0);
35256 INIT_LIST_HEAD(&md->uevent_list);
35257 spin_lock_init(&md->uevent_lock);
35258
35259 @@ -1982,7 +1982,7 @@ static void event_callback(void *context)
35260
35261 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
35262
35263 - atomic_inc(&md->event_nr);
35264 + atomic_inc_unchecked(&md->event_nr);
35265 wake_up(&md->eventq);
35266 }
35267
35268 @@ -2637,18 +2637,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
35269
35270 uint32_t dm_next_uevent_seq(struct mapped_device *md)
35271 {
35272 - return atomic_add_return(1, &md->uevent_seq);
35273 + return atomic_add_return_unchecked(1, &md->uevent_seq);
35274 }
35275
35276 uint32_t dm_get_event_nr(struct mapped_device *md)
35277 {
35278 - return atomic_read(&md->event_nr);
35279 + return atomic_read_unchecked(&md->event_nr);
35280 }
35281
35282 int dm_wait_event(struct mapped_device *md, int event_nr)
35283 {
35284 return wait_event_interruptible(md->eventq,
35285 - (event_nr != atomic_read(&md->event_nr)));
35286 + (event_nr != atomic_read_unchecked(&md->event_nr)));
35287 }
35288
35289 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
35290 diff --git a/drivers/md/md.c b/drivers/md/md.c
35291 index 6120071..31d9be2 100644
35292 --- a/drivers/md/md.c
35293 +++ b/drivers/md/md.c
35294 @@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
35295 * start build, activate spare
35296 */
35297 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
35298 -static atomic_t md_event_count;
35299 +static atomic_unchecked_t md_event_count;
35300 void md_new_event(struct mddev *mddev)
35301 {
35302 - atomic_inc(&md_event_count);
35303 + atomic_inc_unchecked(&md_event_count);
35304 wake_up(&md_event_waiters);
35305 }
35306 EXPORT_SYMBOL_GPL(md_new_event);
35307 @@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
35308 */
35309 static void md_new_event_inintr(struct mddev *mddev)
35310 {
35311 - atomic_inc(&md_event_count);
35312 + atomic_inc_unchecked(&md_event_count);
35313 wake_up(&md_event_waiters);
35314 }
35315
35316 @@ -1504,7 +1504,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
35317 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
35318 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
35319 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
35320 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
35321 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
35322
35323 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
35324 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
35325 @@ -1748,7 +1748,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
35326 else
35327 sb->resync_offset = cpu_to_le64(0);
35328
35329 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
35330 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
35331
35332 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
35333 sb->size = cpu_to_le64(mddev->dev_sectors);
35334 @@ -2748,7 +2748,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
35335 static ssize_t
35336 errors_show(struct md_rdev *rdev, char *page)
35337 {
35338 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
35339 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
35340 }
35341
35342 static ssize_t
35343 @@ -2757,7 +2757,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
35344 char *e;
35345 unsigned long n = simple_strtoul(buf, &e, 10);
35346 if (*buf && (*e == 0 || *e == '\n')) {
35347 - atomic_set(&rdev->corrected_errors, n);
35348 + atomic_set_unchecked(&rdev->corrected_errors, n);
35349 return len;
35350 }
35351 return -EINVAL;
35352 @@ -3204,8 +3204,8 @@ int md_rdev_init(struct md_rdev *rdev)
35353 rdev->sb_loaded = 0;
35354 rdev->bb_page = NULL;
35355 atomic_set(&rdev->nr_pending, 0);
35356 - atomic_set(&rdev->read_errors, 0);
35357 - atomic_set(&rdev->corrected_errors, 0);
35358 + atomic_set_unchecked(&rdev->read_errors, 0);
35359 + atomic_set_unchecked(&rdev->corrected_errors, 0);
35360
35361 INIT_LIST_HEAD(&rdev->same_set);
35362 init_waitqueue_head(&rdev->blocked_wait);
35363 @@ -6984,7 +6984,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
35364
35365 spin_unlock(&pers_lock);
35366 seq_printf(seq, "\n");
35367 - seq->poll_event = atomic_read(&md_event_count);
35368 + seq->poll_event = atomic_read_unchecked(&md_event_count);
35369 return 0;
35370 }
35371 if (v == (void*)2) {
35372 @@ -7087,7 +7087,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
35373 return error;
35374
35375 seq = file->private_data;
35376 - seq->poll_event = atomic_read(&md_event_count);
35377 + seq->poll_event = atomic_read_unchecked(&md_event_count);
35378 return error;
35379 }
35380
35381 @@ -7101,7 +7101,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
35382 /* always allow read */
35383 mask = POLLIN | POLLRDNORM;
35384
35385 - if (seq->poll_event != atomic_read(&md_event_count))
35386 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
35387 mask |= POLLERR | POLLPRI;
35388 return mask;
35389 }
35390 @@ -7145,7 +7145,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
35391 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
35392 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
35393 (int)part_stat_read(&disk->part0, sectors[1]) -
35394 - atomic_read(&disk->sync_io);
35395 + atomic_read_unchecked(&disk->sync_io);
35396 /* sync IO will cause sync_io to increase before the disk_stats
35397 * as sync_io is counted when a request starts, and
35398 * disk_stats is counted when it completes.
35399 diff --git a/drivers/md/md.h b/drivers/md/md.h
35400 index af443ab..0f93be3 100644
35401 --- a/drivers/md/md.h
35402 +++ b/drivers/md/md.h
35403 @@ -94,13 +94,13 @@ struct md_rdev {
35404 * only maintained for arrays that
35405 * support hot removal
35406 */
35407 - atomic_t read_errors; /* number of consecutive read errors that
35408 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
35409 * we have tried to ignore.
35410 */
35411 struct timespec last_read_error; /* monotonic time since our
35412 * last read error
35413 */
35414 - atomic_t corrected_errors; /* number of corrected read errors,
35415 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
35416 * for reporting to userspace and storing
35417 * in superblock.
35418 */
35419 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
35420
35421 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
35422 {
35423 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
35424 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
35425 }
35426
35427 struct md_personality
35428 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
35429 index 1cbfc6b..56e1dbb 100644
35430 --- a/drivers/md/persistent-data/dm-space-map.h
35431 +++ b/drivers/md/persistent-data/dm-space-map.h
35432 @@ -60,6 +60,7 @@ struct dm_space_map {
35433 int (*root_size)(struct dm_space_map *sm, size_t *result);
35434 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
35435 };
35436 +typedef struct dm_space_map __no_const dm_space_map_no_const;
35437
35438 /*----------------------------------------------------------------*/
35439
35440 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
35441 index a0f7309..5599dbc 100644
35442 --- a/drivers/md/raid1.c
35443 +++ b/drivers/md/raid1.c
35444 @@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
35445 if (r1_sync_page_io(rdev, sect, s,
35446 bio->bi_io_vec[idx].bv_page,
35447 READ) != 0)
35448 - atomic_add(s, &rdev->corrected_errors);
35449 + atomic_add_unchecked(s, &rdev->corrected_errors);
35450 }
35451 sectors -= s;
35452 sect += s;
35453 @@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
35454 test_bit(In_sync, &rdev->flags)) {
35455 if (r1_sync_page_io(rdev, sect, s,
35456 conf->tmppage, READ)) {
35457 - atomic_add(s, &rdev->corrected_errors);
35458 + atomic_add_unchecked(s, &rdev->corrected_errors);
35459 printk(KERN_INFO
35460 "md/raid1:%s: read error corrected "
35461 "(%d sectors at %llu on %s)\n",
35462 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
35463 index c9acbd7..386cd3e 100644
35464 --- a/drivers/md/raid10.c
35465 +++ b/drivers/md/raid10.c
35466 @@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
35467 /* The write handler will notice the lack of
35468 * R10BIO_Uptodate and record any errors etc
35469 */
35470 - atomic_add(r10_bio->sectors,
35471 + atomic_add_unchecked(r10_bio->sectors,
35472 &conf->mirrors[d].rdev->corrected_errors);
35473
35474 /* for reconstruct, we always reschedule after a read.
35475 @@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35476 {
35477 struct timespec cur_time_mon;
35478 unsigned long hours_since_last;
35479 - unsigned int read_errors = atomic_read(&rdev->read_errors);
35480 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
35481
35482 ktime_get_ts(&cur_time_mon);
35483
35484 @@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35485 * overflowing the shift of read_errors by hours_since_last.
35486 */
35487 if (hours_since_last >= 8 * sizeof(read_errors))
35488 - atomic_set(&rdev->read_errors, 0);
35489 + atomic_set_unchecked(&rdev->read_errors, 0);
35490 else
35491 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
35492 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
35493 }
35494
35495 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
35496 @@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35497 return;
35498
35499 check_decay_read_errors(mddev, rdev);
35500 - atomic_inc(&rdev->read_errors);
35501 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
35502 + atomic_inc_unchecked(&rdev->read_errors);
35503 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
35504 char b[BDEVNAME_SIZE];
35505 bdevname(rdev->bdev, b);
35506
35507 @@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35508 "md/raid10:%s: %s: Raid device exceeded "
35509 "read_error threshold [cur %d:max %d]\n",
35510 mdname(mddev), b,
35511 - atomic_read(&rdev->read_errors), max_read_errors);
35512 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
35513 printk(KERN_NOTICE
35514 "md/raid10:%s: %s: Failing raid device\n",
35515 mdname(mddev), b);
35516 @@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35517 sect +
35518 choose_data_offset(r10_bio, rdev)),
35519 bdevname(rdev->bdev, b));
35520 - atomic_add(s, &rdev->corrected_errors);
35521 + atomic_add_unchecked(s, &rdev->corrected_errors);
35522 }
35523
35524 rdev_dec_pending(rdev, mddev);
35525 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
35526 index a450268..c4168a9 100644
35527 --- a/drivers/md/raid5.c
35528 +++ b/drivers/md/raid5.c
35529 @@ -1789,21 +1789,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
35530 mdname(conf->mddev), STRIPE_SECTORS,
35531 (unsigned long long)s,
35532 bdevname(rdev->bdev, b));
35533 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
35534 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
35535 clear_bit(R5_ReadError, &sh->dev[i].flags);
35536 clear_bit(R5_ReWrite, &sh->dev[i].flags);
35537 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
35538 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
35539
35540 - if (atomic_read(&rdev->read_errors))
35541 - atomic_set(&rdev->read_errors, 0);
35542 + if (atomic_read_unchecked(&rdev->read_errors))
35543 + atomic_set_unchecked(&rdev->read_errors, 0);
35544 } else {
35545 const char *bdn = bdevname(rdev->bdev, b);
35546 int retry = 0;
35547 int set_bad = 0;
35548
35549 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
35550 - atomic_inc(&rdev->read_errors);
35551 + atomic_inc_unchecked(&rdev->read_errors);
35552 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
35553 printk_ratelimited(
35554 KERN_WARNING
35555 @@ -1831,7 +1831,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
35556 mdname(conf->mddev),
35557 (unsigned long long)s,
35558 bdn);
35559 - } else if (atomic_read(&rdev->read_errors)
35560 + } else if (atomic_read_unchecked(&rdev->read_errors)
35561 > conf->max_nr_stripes)
35562 printk(KERN_WARNING
35563 "md/raid:%s: Too many read errors, failing device %s.\n",
35564 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
35565 index d33101a..6b13069 100644
35566 --- a/drivers/media/dvb-core/dvbdev.c
35567 +++ b/drivers/media/dvb-core/dvbdev.c
35568 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
35569 const struct dvb_device *template, void *priv, int type)
35570 {
35571 struct dvb_device *dvbdev;
35572 - struct file_operations *dvbdevfops;
35573 + file_operations_no_const *dvbdevfops;
35574 struct device *clsdev;
35575 int minor;
35576 int id;
35577 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
35578 index 404f63a..4796533 100644
35579 --- a/drivers/media/dvb-frontends/dib3000.h
35580 +++ b/drivers/media/dvb-frontends/dib3000.h
35581 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
35582 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
35583 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
35584 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
35585 -};
35586 +} __no_const;
35587
35588 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
35589 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
35590 diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c
35591 index 3aa6856..435ad25 100644
35592 --- a/drivers/media/pci/cx88/cx88-alsa.c
35593 +++ b/drivers/media/pci/cx88/cx88-alsa.c
35594 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
35595 * Only boards with eeprom and byte 1 at eeprom=1 have it
35596 */
35597
35598 -static const struct pci_device_id cx88_audio_pci_tbl[] __devinitdata = {
35599 +static const struct pci_device_id cx88_audio_pci_tbl[] __devinitconst = {
35600 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35601 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35602 {0, }
35603 diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
35604 index feff57e..66a2c67 100644
35605 --- a/drivers/media/pci/ddbridge/ddbridge-core.c
35606 +++ b/drivers/media/pci/ddbridge/ddbridge-core.c
35607 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
35608 .subvendor = _subvend, .subdevice = _subdev, \
35609 .driver_data = (unsigned long)&_driverdata }
35610
35611 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
35612 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
35613 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
35614 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
35615 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
35616 diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c
35617 index 96a13ed..6df45b4 100644
35618 --- a/drivers/media/pci/ngene/ngene-cards.c
35619 +++ b/drivers/media/pci/ngene/ngene-cards.c
35620 @@ -741,7 +741,7 @@ static struct ngene_info ngene_info_terratec = {
35621
35622 /****************************************************************************/
35623
35624 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
35625 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
35626 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
35627 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
35628 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
35629 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
35630 index a3b1a34..71ce0e3 100644
35631 --- a/drivers/media/platform/omap/omap_vout.c
35632 +++ b/drivers/media/platform/omap/omap_vout.c
35633 @@ -65,7 +65,6 @@ enum omap_vout_channels {
35634 OMAP_VIDEO2,
35635 };
35636
35637 -static struct videobuf_queue_ops video_vbq_ops;
35638 /* Variables configurable through module params*/
35639 static u32 video1_numbuffers = 3;
35640 static u32 video2_numbuffers = 3;
35641 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
35642 {
35643 struct videobuf_queue *q;
35644 struct omap_vout_device *vout = NULL;
35645 + static struct videobuf_queue_ops video_vbq_ops = {
35646 + .buf_setup = omap_vout_buffer_setup,
35647 + .buf_prepare = omap_vout_buffer_prepare,
35648 + .buf_release = omap_vout_buffer_release,
35649 + .buf_queue = omap_vout_buffer_queue,
35650 + };
35651
35652 vout = video_drvdata(file);
35653 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
35654 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
35655 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
35656
35657 q = &vout->vbq;
35658 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
35659 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
35660 - video_vbq_ops.buf_release = omap_vout_buffer_release;
35661 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
35662 spin_lock_init(&vout->vbq_lock);
35663
35664 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
35665 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
35666 index ddb422e..8cf008e 100644
35667 --- a/drivers/media/platform/s5p-tv/mixer.h
35668 +++ b/drivers/media/platform/s5p-tv/mixer.h
35669 @@ -155,7 +155,7 @@ struct mxr_layer {
35670 /** layer index (unique identifier) */
35671 int idx;
35672 /** callbacks for layer methods */
35673 - struct mxr_layer_ops ops;
35674 + struct mxr_layer_ops *ops;
35675 /** format array */
35676 const struct mxr_format **fmt_array;
35677 /** size of format array */
35678 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35679 index b93a21f..2535195 100644
35680 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35681 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35682 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
35683 {
35684 struct mxr_layer *layer;
35685 int ret;
35686 - struct mxr_layer_ops ops = {
35687 + static struct mxr_layer_ops ops = {
35688 .release = mxr_graph_layer_release,
35689 .buffer_set = mxr_graph_buffer_set,
35690 .stream_set = mxr_graph_stream_set,
35691 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
35692 index 3b1670a..595c939 100644
35693 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
35694 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
35695 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
35696 layer->update_buf = next;
35697 }
35698
35699 - layer->ops.buffer_set(layer, layer->update_buf);
35700 + layer->ops->buffer_set(layer, layer->update_buf);
35701
35702 if (done && done != layer->shadow_buf)
35703 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
35704 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
35705 index 0c1cd89..6574647 100644
35706 --- a/drivers/media/platform/s5p-tv/mixer_video.c
35707 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
35708 @@ -209,7 +209,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
35709 layer->geo.src.height = layer->geo.src.full_height;
35710
35711 mxr_geometry_dump(mdev, &layer->geo);
35712 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35713 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35714 mxr_geometry_dump(mdev, &layer->geo);
35715 }
35716
35717 @@ -227,7 +227,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
35718 layer->geo.dst.full_width = mbus_fmt.width;
35719 layer->geo.dst.full_height = mbus_fmt.height;
35720 layer->geo.dst.field = mbus_fmt.field;
35721 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35722 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35723
35724 mxr_geometry_dump(mdev, &layer->geo);
35725 }
35726 @@ -333,7 +333,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
35727 /* set source size to highest accepted value */
35728 geo->src.full_width = max(geo->dst.full_width, pix->width);
35729 geo->src.full_height = max(geo->dst.full_height, pix->height);
35730 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35731 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35732 mxr_geometry_dump(mdev, &layer->geo);
35733 /* set cropping to total visible screen */
35734 geo->src.width = pix->width;
35735 @@ -341,12 +341,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
35736 geo->src.x_offset = 0;
35737 geo->src.y_offset = 0;
35738 /* assure consistency of geometry */
35739 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
35740 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
35741 mxr_geometry_dump(mdev, &layer->geo);
35742 /* set full size to lowest possible value */
35743 geo->src.full_width = 0;
35744 geo->src.full_height = 0;
35745 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35746 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35747 mxr_geometry_dump(mdev, &layer->geo);
35748
35749 /* returning results */
35750 @@ -473,7 +473,7 @@ static int mxr_s_selection(struct file *file, void *fh,
35751 target->width = s->r.width;
35752 target->height = s->r.height;
35753
35754 - layer->ops.fix_geometry(layer, stage, s->flags);
35755 + layer->ops->fix_geometry(layer, stage, s->flags);
35756
35757 /* retrieve update selection rectangle */
35758 res.left = target->x_offset;
35759 @@ -928,13 +928,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
35760 mxr_output_get(mdev);
35761
35762 mxr_layer_update_output(layer);
35763 - layer->ops.format_set(layer);
35764 + layer->ops->format_set(layer);
35765 /* enabling layer in hardware */
35766 spin_lock_irqsave(&layer->enq_slock, flags);
35767 layer->state = MXR_LAYER_STREAMING;
35768 spin_unlock_irqrestore(&layer->enq_slock, flags);
35769
35770 - layer->ops.stream_set(layer, MXR_ENABLE);
35771 + layer->ops->stream_set(layer, MXR_ENABLE);
35772 mxr_streamer_get(mdev);
35773
35774 return 0;
35775 @@ -1004,7 +1004,7 @@ static int stop_streaming(struct vb2_queue *vq)
35776 spin_unlock_irqrestore(&layer->enq_slock, flags);
35777
35778 /* disabling layer in hardware */
35779 - layer->ops.stream_set(layer, MXR_DISABLE);
35780 + layer->ops->stream_set(layer, MXR_DISABLE);
35781 /* remove one streamer */
35782 mxr_streamer_put(mdev);
35783 /* allow changes in output configuration */
35784 @@ -1043,8 +1043,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
35785
35786 void mxr_layer_release(struct mxr_layer *layer)
35787 {
35788 - if (layer->ops.release)
35789 - layer->ops.release(layer);
35790 + if (layer->ops->release)
35791 + layer->ops->release(layer);
35792 }
35793
35794 void mxr_base_layer_release(struct mxr_layer *layer)
35795 @@ -1070,7 +1070,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
35796
35797 layer->mdev = mdev;
35798 layer->idx = idx;
35799 - layer->ops = *ops;
35800 + layer->ops = ops;
35801
35802 spin_lock_init(&layer->enq_slock);
35803 INIT_LIST_HEAD(&layer->enq_list);
35804 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35805 index 3d13a63..da31bf1 100644
35806 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35807 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35808 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
35809 {
35810 struct mxr_layer *layer;
35811 int ret;
35812 - struct mxr_layer_ops ops = {
35813 + static struct mxr_layer_ops ops = {
35814 .release = mxr_vp_layer_release,
35815 .buffer_set = mxr_vp_buffer_set,
35816 .stream_set = mxr_vp_stream_set,
35817 diff --git a/drivers/media/platform/timblogiw.c b/drivers/media/platform/timblogiw.c
35818 index 02194c0..36d69c1 100644
35819 --- a/drivers/media/platform/timblogiw.c
35820 +++ b/drivers/media/platform/timblogiw.c
35821 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
35822
35823 /* Platform device functions */
35824
35825 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35826 +static struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35827 .vidioc_querycap = timblogiw_querycap,
35828 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
35829 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
35830 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35831 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
35832 };
35833
35834 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
35835 +static struct v4l2_file_operations timblogiw_fops = {
35836 .owner = THIS_MODULE,
35837 .open = timblogiw_open,
35838 .release = timblogiw_close,
35839 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
35840 index 697a421..16c5a5f 100644
35841 --- a/drivers/media/radio/radio-cadet.c
35842 +++ b/drivers/media/radio/radio-cadet.c
35843 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35844 unsigned char readbuf[RDS_BUFFER];
35845 int i = 0;
35846
35847 + if (count > RDS_BUFFER)
35848 + return -EFAULT;
35849 mutex_lock(&dev->lock);
35850 if (dev->rdsstat == 0)
35851 cadet_start_rds(dev);
35852 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35853 while (i < count && dev->rdsin != dev->rdsout)
35854 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
35855
35856 - if (i && copy_to_user(data, readbuf, i))
35857 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
35858 i = -EFAULT;
35859 unlock:
35860 mutex_unlock(&dev->lock);
35861 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
35862 index 3940bb0..fb3952a 100644
35863 --- a/drivers/media/usb/dvb-usb/cxusb.c
35864 +++ b/drivers/media/usb/dvb-usb/cxusb.c
35865 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
35866
35867 struct dib0700_adapter_state {
35868 int (*set_param_save) (struct dvb_frontend *);
35869 -};
35870 +} __no_const;
35871
35872 static int dib7070_set_param_override(struct dvb_frontend *fe)
35873 {
35874 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
35875 index 9382895..ac8093c 100644
35876 --- a/drivers/media/usb/dvb-usb/dw2102.c
35877 +++ b/drivers/media/usb/dvb-usb/dw2102.c
35878 @@ -95,7 +95,7 @@ struct su3000_state {
35879
35880 struct s6x0_state {
35881 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
35882 -};
35883 +} __no_const;
35884
35885 /* debug */
35886 static int dvb_usb_dw2102_debug;
35887 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
35888 index fb69baa..cf7ad22 100644
35889 --- a/drivers/message/fusion/mptbase.c
35890 +++ b/drivers/message/fusion/mptbase.c
35891 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
35892 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
35893 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
35894
35895 +#ifdef CONFIG_GRKERNSEC_HIDESYM
35896 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
35897 +#else
35898 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
35899 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
35900 +#endif
35901 +
35902 /*
35903 * Rounding UP to nearest 4-kB boundary here...
35904 */
35905 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
35906 index 551262e..7551198 100644
35907 --- a/drivers/message/fusion/mptsas.c
35908 +++ b/drivers/message/fusion/mptsas.c
35909 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
35910 return 0;
35911 }
35912
35913 +static inline void
35914 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35915 +{
35916 + if (phy_info->port_details) {
35917 + phy_info->port_details->rphy = rphy;
35918 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35919 + ioc->name, rphy));
35920 + }
35921 +
35922 + if (rphy) {
35923 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35924 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35925 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35926 + ioc->name, rphy, rphy->dev.release));
35927 + }
35928 +}
35929 +
35930 /* no mutex */
35931 static void
35932 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
35933 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
35934 return NULL;
35935 }
35936
35937 -static inline void
35938 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35939 -{
35940 - if (phy_info->port_details) {
35941 - phy_info->port_details->rphy = rphy;
35942 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35943 - ioc->name, rphy));
35944 - }
35945 -
35946 - if (rphy) {
35947 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35948 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35949 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35950 - ioc->name, rphy, rphy->dev.release));
35951 - }
35952 -}
35953 -
35954 static inline struct sas_port *
35955 mptsas_get_port(struct mptsas_phyinfo *phy_info)
35956 {
35957 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
35958 index 0c3ced7..1fe34ec 100644
35959 --- a/drivers/message/fusion/mptscsih.c
35960 +++ b/drivers/message/fusion/mptscsih.c
35961 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
35962
35963 h = shost_priv(SChost);
35964
35965 - if (h) {
35966 - if (h->info_kbuf == NULL)
35967 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35968 - return h->info_kbuf;
35969 - h->info_kbuf[0] = '\0';
35970 + if (!h)
35971 + return NULL;
35972
35973 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35974 - h->info_kbuf[size-1] = '\0';
35975 - }
35976 + if (h->info_kbuf == NULL)
35977 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35978 + return h->info_kbuf;
35979 + h->info_kbuf[0] = '\0';
35980 +
35981 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35982 + h->info_kbuf[size-1] = '\0';
35983
35984 return h->info_kbuf;
35985 }
35986 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
35987 index 8001aa6..b137580 100644
35988 --- a/drivers/message/i2o/i2o_proc.c
35989 +++ b/drivers/message/i2o/i2o_proc.c
35990 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
35991 "Array Controller Device"
35992 };
35993
35994 -static char *chtostr(char *tmp, u8 *chars, int n)
35995 -{
35996 - tmp[0] = 0;
35997 - return strncat(tmp, (char *)chars, n);
35998 -}
35999 -
36000 static int i2o_report_query_status(struct seq_file *seq, int block_status,
36001 char *group)
36002 {
36003 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36004 } *result;
36005
36006 i2o_exec_execute_ddm_table ddm_table;
36007 - char tmp[28 + 1];
36008
36009 result = kmalloc(sizeof(*result), GFP_KERNEL);
36010 if (!result)
36011 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36012
36013 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
36014 seq_printf(seq, "%-#8x", ddm_table.module_id);
36015 - seq_printf(seq, "%-29s",
36016 - chtostr(tmp, ddm_table.module_name_version, 28));
36017 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
36018 seq_printf(seq, "%9d ", ddm_table.data_size);
36019 seq_printf(seq, "%8d", ddm_table.code_size);
36020
36021 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36022
36023 i2o_driver_result_table *result;
36024 i2o_driver_store_table *dst;
36025 - char tmp[28 + 1];
36026
36027 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
36028 if (result == NULL)
36029 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36030
36031 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
36032 seq_printf(seq, "%-#8x", dst->module_id);
36033 - seq_printf(seq, "%-29s",
36034 - chtostr(tmp, dst->module_name_version, 28));
36035 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
36036 + seq_printf(seq, "%-.28s", dst->module_name_version);
36037 + seq_printf(seq, "%-.8s", dst->date);
36038 seq_printf(seq, "%8d ", dst->module_size);
36039 seq_printf(seq, "%8d ", dst->mpb_size);
36040 seq_printf(seq, "0x%04x", dst->module_flags);
36041 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36042 // == (allow) 512d bytes (max)
36043 static u16 *work16 = (u16 *) work32;
36044 int token;
36045 - char tmp[16 + 1];
36046
36047 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
36048
36049 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36050 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
36051 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
36052 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
36053 - seq_printf(seq, "Vendor info : %s\n",
36054 - chtostr(tmp, (u8 *) (work32 + 2), 16));
36055 - seq_printf(seq, "Product info : %s\n",
36056 - chtostr(tmp, (u8 *) (work32 + 6), 16));
36057 - seq_printf(seq, "Description : %s\n",
36058 - chtostr(tmp, (u8 *) (work32 + 10), 16));
36059 - seq_printf(seq, "Product rev. : %s\n",
36060 - chtostr(tmp, (u8 *) (work32 + 14), 8));
36061 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
36062 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
36063 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
36064 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
36065
36066 seq_printf(seq, "Serial number : ");
36067 print_serial_number(seq, (u8 *) (work32 + 16),
36068 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36069 u8 pad[256]; // allow up to 256 byte (max) serial number
36070 } result;
36071
36072 - char tmp[24 + 1];
36073 -
36074 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
36075
36076 if (token < 0) {
36077 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36078 }
36079
36080 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
36081 - seq_printf(seq, "Module name : %s\n",
36082 - chtostr(tmp, result.module_name, 24));
36083 - seq_printf(seq, "Module revision : %s\n",
36084 - chtostr(tmp, result.module_rev, 8));
36085 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
36086 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
36087
36088 seq_printf(seq, "Serial number : ");
36089 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
36090 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36091 u8 instance_number[4];
36092 } result;
36093
36094 - char tmp[64 + 1];
36095 -
36096 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
36097
36098 if (token < 0) {
36099 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36100 return 0;
36101 }
36102
36103 - seq_printf(seq, "Device name : %s\n",
36104 - chtostr(tmp, result.device_name, 64));
36105 - seq_printf(seq, "Service name : %s\n",
36106 - chtostr(tmp, result.service_name, 64));
36107 - seq_printf(seq, "Physical name : %s\n",
36108 - chtostr(tmp, result.physical_location, 64));
36109 - seq_printf(seq, "Instance number : %s\n",
36110 - chtostr(tmp, result.instance_number, 4));
36111 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
36112 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
36113 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
36114 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
36115
36116 return 0;
36117 }
36118 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
36119 index a8c08f3..155fe3d 100644
36120 --- a/drivers/message/i2o/iop.c
36121 +++ b/drivers/message/i2o/iop.c
36122 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
36123
36124 spin_lock_irqsave(&c->context_list_lock, flags);
36125
36126 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
36127 - atomic_inc(&c->context_list_counter);
36128 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
36129 + atomic_inc_unchecked(&c->context_list_counter);
36130
36131 - entry->context = atomic_read(&c->context_list_counter);
36132 + entry->context = atomic_read_unchecked(&c->context_list_counter);
36133
36134 list_add(&entry->list, &c->context_list);
36135
36136 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
36137
36138 #if BITS_PER_LONG == 64
36139 spin_lock_init(&c->context_list_lock);
36140 - atomic_set(&c->context_list_counter, 0);
36141 + atomic_set_unchecked(&c->context_list_counter, 0);
36142 INIT_LIST_HEAD(&c->context_list);
36143 #endif
36144
36145 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
36146 index 965c480..71f2db9 100644
36147 --- a/drivers/mfd/janz-cmodio.c
36148 +++ b/drivers/mfd/janz-cmodio.c
36149 @@ -13,6 +13,7 @@
36150
36151 #include <linux/kernel.h>
36152 #include <linux/module.h>
36153 +#include <linux/slab.h>
36154 #include <linux/init.h>
36155 #include <linux/pci.h>
36156 #include <linux/interrupt.h>
36157 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
36158 index 3aa9a96..59cf685 100644
36159 --- a/drivers/misc/kgdbts.c
36160 +++ b/drivers/misc/kgdbts.c
36161 @@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
36162 char before[BREAK_INSTR_SIZE];
36163 char after[BREAK_INSTR_SIZE];
36164
36165 - probe_kernel_read(before, (char *)kgdbts_break_test,
36166 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
36167 BREAK_INSTR_SIZE);
36168 init_simple_test();
36169 ts.tst = plant_and_detach_test;
36170 @@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
36171 /* Activate test with initial breakpoint */
36172 if (!is_early)
36173 kgdb_breakpoint();
36174 - probe_kernel_read(after, (char *)kgdbts_break_test,
36175 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
36176 BREAK_INSTR_SIZE);
36177 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
36178 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
36179 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
36180 index 4a87e5c..76bdf5c 100644
36181 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
36182 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
36183 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
36184 * the lid is closed. This leads to interrupts as soon as a little move
36185 * is done.
36186 */
36187 - atomic_inc(&lis3->count);
36188 + atomic_inc_unchecked(&lis3->count);
36189
36190 wake_up_interruptible(&lis3->misc_wait);
36191 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
36192 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
36193 if (lis3->pm_dev)
36194 pm_runtime_get_sync(lis3->pm_dev);
36195
36196 - atomic_set(&lis3->count, 0);
36197 + atomic_set_unchecked(&lis3->count, 0);
36198 return 0;
36199 }
36200
36201 @@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
36202 add_wait_queue(&lis3->misc_wait, &wait);
36203 while (true) {
36204 set_current_state(TASK_INTERRUPTIBLE);
36205 - data = atomic_xchg(&lis3->count, 0);
36206 + data = atomic_xchg_unchecked(&lis3->count, 0);
36207 if (data)
36208 break;
36209
36210 @@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
36211 struct lis3lv02d, miscdev);
36212
36213 poll_wait(file, &lis3->misc_wait, wait);
36214 - if (atomic_read(&lis3->count))
36215 + if (atomic_read_unchecked(&lis3->count))
36216 return POLLIN | POLLRDNORM;
36217 return 0;
36218 }
36219 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
36220 index c439c82..1f20f57 100644
36221 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
36222 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
36223 @@ -297,7 +297,7 @@ struct lis3lv02d {
36224 struct input_polled_dev *idev; /* input device */
36225 struct platform_device *pdev; /* platform device */
36226 struct regulator_bulk_data regulators[2];
36227 - atomic_t count; /* interrupt count after last read */
36228 + atomic_unchecked_t count; /* interrupt count after last read */
36229 union axis_conversion ac; /* hw -> logical axis */
36230 int mapped_btns[3];
36231
36232 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
36233 index 2f30bad..c4c13d0 100644
36234 --- a/drivers/misc/sgi-gru/gruhandles.c
36235 +++ b/drivers/misc/sgi-gru/gruhandles.c
36236 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
36237 unsigned long nsec;
36238
36239 nsec = CLKS2NSEC(clks);
36240 - atomic_long_inc(&mcs_op_statistics[op].count);
36241 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
36242 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
36243 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
36244 if (mcs_op_statistics[op].max < nsec)
36245 mcs_op_statistics[op].max = nsec;
36246 }
36247 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
36248 index 950dbe9..eeef0f8 100644
36249 --- a/drivers/misc/sgi-gru/gruprocfs.c
36250 +++ b/drivers/misc/sgi-gru/gruprocfs.c
36251 @@ -32,9 +32,9 @@
36252
36253 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
36254
36255 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
36256 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
36257 {
36258 - unsigned long val = atomic_long_read(v);
36259 + unsigned long val = atomic_long_read_unchecked(v);
36260
36261 seq_printf(s, "%16lu %s\n", val, id);
36262 }
36263 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
36264
36265 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
36266 for (op = 0; op < mcsop_last; op++) {
36267 - count = atomic_long_read(&mcs_op_statistics[op].count);
36268 - total = atomic_long_read(&mcs_op_statistics[op].total);
36269 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
36270 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
36271 max = mcs_op_statistics[op].max;
36272 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
36273 count ? total / count : 0, max);
36274 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
36275 index 5c3ce24..4915ccb 100644
36276 --- a/drivers/misc/sgi-gru/grutables.h
36277 +++ b/drivers/misc/sgi-gru/grutables.h
36278 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
36279 * GRU statistics.
36280 */
36281 struct gru_stats_s {
36282 - atomic_long_t vdata_alloc;
36283 - atomic_long_t vdata_free;
36284 - atomic_long_t gts_alloc;
36285 - atomic_long_t gts_free;
36286 - atomic_long_t gms_alloc;
36287 - atomic_long_t gms_free;
36288 - atomic_long_t gts_double_allocate;
36289 - atomic_long_t assign_context;
36290 - atomic_long_t assign_context_failed;
36291 - atomic_long_t free_context;
36292 - atomic_long_t load_user_context;
36293 - atomic_long_t load_kernel_context;
36294 - atomic_long_t lock_kernel_context;
36295 - atomic_long_t unlock_kernel_context;
36296 - atomic_long_t steal_user_context;
36297 - atomic_long_t steal_kernel_context;
36298 - atomic_long_t steal_context_failed;
36299 - atomic_long_t nopfn;
36300 - atomic_long_t asid_new;
36301 - atomic_long_t asid_next;
36302 - atomic_long_t asid_wrap;
36303 - atomic_long_t asid_reuse;
36304 - atomic_long_t intr;
36305 - atomic_long_t intr_cbr;
36306 - atomic_long_t intr_tfh;
36307 - atomic_long_t intr_spurious;
36308 - atomic_long_t intr_mm_lock_failed;
36309 - atomic_long_t call_os;
36310 - atomic_long_t call_os_wait_queue;
36311 - atomic_long_t user_flush_tlb;
36312 - atomic_long_t user_unload_context;
36313 - atomic_long_t user_exception;
36314 - atomic_long_t set_context_option;
36315 - atomic_long_t check_context_retarget_intr;
36316 - atomic_long_t check_context_unload;
36317 - atomic_long_t tlb_dropin;
36318 - atomic_long_t tlb_preload_page;
36319 - atomic_long_t tlb_dropin_fail_no_asid;
36320 - atomic_long_t tlb_dropin_fail_upm;
36321 - atomic_long_t tlb_dropin_fail_invalid;
36322 - atomic_long_t tlb_dropin_fail_range_active;
36323 - atomic_long_t tlb_dropin_fail_idle;
36324 - atomic_long_t tlb_dropin_fail_fmm;
36325 - atomic_long_t tlb_dropin_fail_no_exception;
36326 - atomic_long_t tfh_stale_on_fault;
36327 - atomic_long_t mmu_invalidate_range;
36328 - atomic_long_t mmu_invalidate_page;
36329 - atomic_long_t flush_tlb;
36330 - atomic_long_t flush_tlb_gru;
36331 - atomic_long_t flush_tlb_gru_tgh;
36332 - atomic_long_t flush_tlb_gru_zero_asid;
36333 + atomic_long_unchecked_t vdata_alloc;
36334 + atomic_long_unchecked_t vdata_free;
36335 + atomic_long_unchecked_t gts_alloc;
36336 + atomic_long_unchecked_t gts_free;
36337 + atomic_long_unchecked_t gms_alloc;
36338 + atomic_long_unchecked_t gms_free;
36339 + atomic_long_unchecked_t gts_double_allocate;
36340 + atomic_long_unchecked_t assign_context;
36341 + atomic_long_unchecked_t assign_context_failed;
36342 + atomic_long_unchecked_t free_context;
36343 + atomic_long_unchecked_t load_user_context;
36344 + atomic_long_unchecked_t load_kernel_context;
36345 + atomic_long_unchecked_t lock_kernel_context;
36346 + atomic_long_unchecked_t unlock_kernel_context;
36347 + atomic_long_unchecked_t steal_user_context;
36348 + atomic_long_unchecked_t steal_kernel_context;
36349 + atomic_long_unchecked_t steal_context_failed;
36350 + atomic_long_unchecked_t nopfn;
36351 + atomic_long_unchecked_t asid_new;
36352 + atomic_long_unchecked_t asid_next;
36353 + atomic_long_unchecked_t asid_wrap;
36354 + atomic_long_unchecked_t asid_reuse;
36355 + atomic_long_unchecked_t intr;
36356 + atomic_long_unchecked_t intr_cbr;
36357 + atomic_long_unchecked_t intr_tfh;
36358 + atomic_long_unchecked_t intr_spurious;
36359 + atomic_long_unchecked_t intr_mm_lock_failed;
36360 + atomic_long_unchecked_t call_os;
36361 + atomic_long_unchecked_t call_os_wait_queue;
36362 + atomic_long_unchecked_t user_flush_tlb;
36363 + atomic_long_unchecked_t user_unload_context;
36364 + atomic_long_unchecked_t user_exception;
36365 + atomic_long_unchecked_t set_context_option;
36366 + atomic_long_unchecked_t check_context_retarget_intr;
36367 + atomic_long_unchecked_t check_context_unload;
36368 + atomic_long_unchecked_t tlb_dropin;
36369 + atomic_long_unchecked_t tlb_preload_page;
36370 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
36371 + atomic_long_unchecked_t tlb_dropin_fail_upm;
36372 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
36373 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
36374 + atomic_long_unchecked_t tlb_dropin_fail_idle;
36375 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
36376 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
36377 + atomic_long_unchecked_t tfh_stale_on_fault;
36378 + atomic_long_unchecked_t mmu_invalidate_range;
36379 + atomic_long_unchecked_t mmu_invalidate_page;
36380 + atomic_long_unchecked_t flush_tlb;
36381 + atomic_long_unchecked_t flush_tlb_gru;
36382 + atomic_long_unchecked_t flush_tlb_gru_tgh;
36383 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
36384
36385 - atomic_long_t copy_gpa;
36386 - atomic_long_t read_gpa;
36387 + atomic_long_unchecked_t copy_gpa;
36388 + atomic_long_unchecked_t read_gpa;
36389
36390 - atomic_long_t mesq_receive;
36391 - atomic_long_t mesq_receive_none;
36392 - atomic_long_t mesq_send;
36393 - atomic_long_t mesq_send_failed;
36394 - atomic_long_t mesq_noop;
36395 - atomic_long_t mesq_send_unexpected_error;
36396 - atomic_long_t mesq_send_lb_overflow;
36397 - atomic_long_t mesq_send_qlimit_reached;
36398 - atomic_long_t mesq_send_amo_nacked;
36399 - atomic_long_t mesq_send_put_nacked;
36400 - atomic_long_t mesq_page_overflow;
36401 - atomic_long_t mesq_qf_locked;
36402 - atomic_long_t mesq_qf_noop_not_full;
36403 - atomic_long_t mesq_qf_switch_head_failed;
36404 - atomic_long_t mesq_qf_unexpected_error;
36405 - atomic_long_t mesq_noop_unexpected_error;
36406 - atomic_long_t mesq_noop_lb_overflow;
36407 - atomic_long_t mesq_noop_qlimit_reached;
36408 - atomic_long_t mesq_noop_amo_nacked;
36409 - atomic_long_t mesq_noop_put_nacked;
36410 - atomic_long_t mesq_noop_page_overflow;
36411 + atomic_long_unchecked_t mesq_receive;
36412 + atomic_long_unchecked_t mesq_receive_none;
36413 + atomic_long_unchecked_t mesq_send;
36414 + atomic_long_unchecked_t mesq_send_failed;
36415 + atomic_long_unchecked_t mesq_noop;
36416 + atomic_long_unchecked_t mesq_send_unexpected_error;
36417 + atomic_long_unchecked_t mesq_send_lb_overflow;
36418 + atomic_long_unchecked_t mesq_send_qlimit_reached;
36419 + atomic_long_unchecked_t mesq_send_amo_nacked;
36420 + atomic_long_unchecked_t mesq_send_put_nacked;
36421 + atomic_long_unchecked_t mesq_page_overflow;
36422 + atomic_long_unchecked_t mesq_qf_locked;
36423 + atomic_long_unchecked_t mesq_qf_noop_not_full;
36424 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
36425 + atomic_long_unchecked_t mesq_qf_unexpected_error;
36426 + atomic_long_unchecked_t mesq_noop_unexpected_error;
36427 + atomic_long_unchecked_t mesq_noop_lb_overflow;
36428 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
36429 + atomic_long_unchecked_t mesq_noop_amo_nacked;
36430 + atomic_long_unchecked_t mesq_noop_put_nacked;
36431 + atomic_long_unchecked_t mesq_noop_page_overflow;
36432
36433 };
36434
36435 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
36436 tghop_invalidate, mcsop_last};
36437
36438 struct mcs_op_statistic {
36439 - atomic_long_t count;
36440 - atomic_long_t total;
36441 + atomic_long_unchecked_t count;
36442 + atomic_long_unchecked_t total;
36443 unsigned long max;
36444 };
36445
36446 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
36447
36448 #define STAT(id) do { \
36449 if (gru_options & OPT_STATS) \
36450 - atomic_long_inc(&gru_stats.id); \
36451 + atomic_long_inc_unchecked(&gru_stats.id); \
36452 } while (0)
36453
36454 #ifdef CONFIG_SGI_GRU_DEBUG
36455 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
36456 index c862cd4..0d176fe 100644
36457 --- a/drivers/misc/sgi-xp/xp.h
36458 +++ b/drivers/misc/sgi-xp/xp.h
36459 @@ -288,7 +288,7 @@ struct xpc_interface {
36460 xpc_notify_func, void *);
36461 void (*received) (short, int, void *);
36462 enum xp_retval (*partid_to_nasids) (short, void *);
36463 -};
36464 +} __no_const;
36465
36466 extern struct xpc_interface xpc_interface;
36467
36468 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
36469 index b94d5f7..7f494c5 100644
36470 --- a/drivers/misc/sgi-xp/xpc.h
36471 +++ b/drivers/misc/sgi-xp/xpc.h
36472 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
36473 void (*received_payload) (struct xpc_channel *, void *);
36474 void (*notify_senders_of_disconnect) (struct xpc_channel *);
36475 };
36476 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
36477
36478 /* struct xpc_partition act_state values (for XPC HB) */
36479
36480 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
36481 /* found in xpc_main.c */
36482 extern struct device *xpc_part;
36483 extern struct device *xpc_chan;
36484 -extern struct xpc_arch_operations xpc_arch_ops;
36485 +extern xpc_arch_operations_no_const xpc_arch_ops;
36486 extern int xpc_disengage_timelimit;
36487 extern int xpc_disengage_timedout;
36488 extern int xpc_activate_IRQ_rcvd;
36489 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
36490 index d971817..33bdca5 100644
36491 --- a/drivers/misc/sgi-xp/xpc_main.c
36492 +++ b/drivers/misc/sgi-xp/xpc_main.c
36493 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
36494 .notifier_call = xpc_system_die,
36495 };
36496
36497 -struct xpc_arch_operations xpc_arch_ops;
36498 +xpc_arch_operations_no_const xpc_arch_ops;
36499
36500 /*
36501 * Timer function to enforce the timelimit on the partition disengage.
36502 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
36503
36504 if (((die_args->trapnr == X86_TRAP_MF) ||
36505 (die_args->trapnr == X86_TRAP_XF)) &&
36506 - !user_mode_vm(die_args->regs))
36507 + !user_mode(die_args->regs))
36508 xpc_die_deactivate();
36509
36510 break;
36511 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
36512 index a0e1720..ee63d0b 100644
36513 --- a/drivers/mmc/core/mmc_ops.c
36514 +++ b/drivers/mmc/core/mmc_ops.c
36515 @@ -245,7 +245,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
36516 void *data_buf;
36517 int is_on_stack;
36518
36519 - is_on_stack = object_is_on_stack(buf);
36520 + is_on_stack = object_starts_on_stack(buf);
36521 if (is_on_stack) {
36522 /*
36523 * dma onto stack is unsafe/nonportable, but callers to this
36524 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
36525 index 53b8fd9..615b462 100644
36526 --- a/drivers/mmc/host/dw_mmc.h
36527 +++ b/drivers/mmc/host/dw_mmc.h
36528 @@ -205,5 +205,5 @@ struct dw_mci_drv_data {
36529 int (*parse_dt)(struct dw_mci *host);
36530 int (*setup_bus)(struct dw_mci *host,
36531 struct device_node *slot_np, u8 bus_width);
36532 -};
36533 +} __do_const;
36534 #endif /* _DW_MMC_H_ */
36535 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
36536 index c9ec725..178e79a 100644
36537 --- a/drivers/mmc/host/sdhci-s3c.c
36538 +++ b/drivers/mmc/host/sdhci-s3c.c
36539 @@ -719,9 +719,11 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
36540 * we can use overriding functions instead of default.
36541 */
36542 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
36543 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
36544 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
36545 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
36546 + pax_open_kernel();
36547 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
36548 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
36549 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
36550 + pax_close_kernel();
36551 }
36552
36553 /* It supports additional host capabilities if needed */
36554 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
36555 index a4eb8b5..8c0628f 100644
36556 --- a/drivers/mtd/devices/doc2000.c
36557 +++ b/drivers/mtd/devices/doc2000.c
36558 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
36559
36560 /* The ECC will not be calculated correctly if less than 512 is written */
36561 /* DBB-
36562 - if (len != 0x200 && eccbuf)
36563 + if (len != 0x200)
36564 printk(KERN_WARNING
36565 "ECC needs a full sector write (adr: %lx size %lx)\n",
36566 (long) to, (long) len);
36567 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
36568 index e706a23..b3d262f 100644
36569 --- a/drivers/mtd/nand/denali.c
36570 +++ b/drivers/mtd/nand/denali.c
36571 @@ -26,6 +26,7 @@
36572 #include <linux/pci.h>
36573 #include <linux/mtd/mtd.h>
36574 #include <linux/module.h>
36575 +#include <linux/slab.h>
36576
36577 #include "denali.h"
36578
36579 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
36580 index 51b9d6a..52af9a7 100644
36581 --- a/drivers/mtd/nftlmount.c
36582 +++ b/drivers/mtd/nftlmount.c
36583 @@ -24,6 +24,7 @@
36584 #include <asm/errno.h>
36585 #include <linux/delay.h>
36586 #include <linux/slab.h>
36587 +#include <linux/sched.h>
36588 #include <linux/mtd/mtd.h>
36589 #include <linux/mtd/nand.h>
36590 #include <linux/mtd/nftl.h>
36591 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
36592 index 203ff9d..0968ca8 100644
36593 --- a/drivers/net/ethernet/8390/ax88796.c
36594 +++ b/drivers/net/ethernet/8390/ax88796.c
36595 @@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
36596 if (ax->plat->reg_offsets)
36597 ei_local->reg_offset = ax->plat->reg_offsets;
36598 else {
36599 + resource_size_t _mem_size = mem_size;
36600 + do_div(_mem_size, 0x18);
36601 ei_local->reg_offset = ax->reg_offsets;
36602 for (ret = 0; ret < 0x18; ret++)
36603 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
36604 + ax->reg_offsets[ret] = _mem_size * ret;
36605 }
36606
36607 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
36608 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36609 index 9c5ea6c..eaad276 100644
36610 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36611 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36612 @@ -1046,7 +1046,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
36613 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
36614 {
36615 /* RX_MODE controlling object */
36616 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
36617 + bnx2x_init_rx_mode_obj(bp);
36618
36619 /* multicast configuration controlling object */
36620 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
36621 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36622 index 614981c..11216c7 100644
36623 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36624 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36625 @@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
36626 return rc;
36627 }
36628
36629 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36630 - struct bnx2x_rx_mode_obj *o)
36631 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
36632 {
36633 if (CHIP_IS_E1x(bp)) {
36634 - o->wait_comp = bnx2x_empty_rx_mode_wait;
36635 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
36636 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
36637 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
36638 } else {
36639 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
36640 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
36641 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
36642 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
36643 }
36644 }
36645
36646 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36647 index acf2fe4..efb96df 100644
36648 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36649 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36650 @@ -1281,8 +1281,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
36651
36652 /********************* RX MODE ****************/
36653
36654 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36655 - struct bnx2x_rx_mode_obj *o);
36656 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
36657
36658 /**
36659 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
36660 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
36661 index d9308c32..d87b824 100644
36662 --- a/drivers/net/ethernet/broadcom/tg3.h
36663 +++ b/drivers/net/ethernet/broadcom/tg3.h
36664 @@ -140,6 +140,7 @@
36665 #define CHIPREV_ID_5750_A0 0x4000
36666 #define CHIPREV_ID_5750_A1 0x4001
36667 #define CHIPREV_ID_5750_A3 0x4003
36668 +#define CHIPREV_ID_5750_C1 0x4201
36669 #define CHIPREV_ID_5750_C2 0x4202
36670 #define CHIPREV_ID_5752_A0_HW 0x5000
36671 #define CHIPREV_ID_5752_A0 0x6000
36672 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36673 index 8cffcdf..aadf043 100644
36674 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36675 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36676 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
36677 */
36678 struct l2t_skb_cb {
36679 arp_failure_handler_func arp_failure_handler;
36680 -};
36681 +} __no_const;
36682
36683 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
36684
36685 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
36686 index f879e92..726f20f 100644
36687 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
36688 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
36689 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36690 for (i=0; i<ETH_ALEN; i++) {
36691 tmp.addr[i] = dev->dev_addr[i];
36692 }
36693 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36694 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36695 break;
36696
36697 case DE4X5_SET_HWADDR: /* Set the hardware address */
36698 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36699 spin_lock_irqsave(&lp->lock, flags);
36700 memcpy(&statbuf, &lp->pktStats, ioc->len);
36701 spin_unlock_irqrestore(&lp->lock, flags);
36702 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
36703 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
36704 return -EFAULT;
36705 break;
36706 }
36707 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
36708 index d1b6cc5..cde0d97 100644
36709 --- a/drivers/net/ethernet/emulex/benet/be_main.c
36710 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
36711 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
36712
36713 if (wrapped)
36714 newacc += 65536;
36715 - ACCESS_ONCE(*acc) = newacc;
36716 + ACCESS_ONCE_RW(*acc) = newacc;
36717 }
36718
36719 void be_parse_stats(struct be_adapter *adapter)
36720 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
36721 index 74d749e..eefb1bd 100644
36722 --- a/drivers/net/ethernet/faraday/ftgmac100.c
36723 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
36724 @@ -31,6 +31,8 @@
36725 #include <linux/netdevice.h>
36726 #include <linux/phy.h>
36727 #include <linux/platform_device.h>
36728 +#include <linux/interrupt.h>
36729 +#include <linux/irqreturn.h>
36730 #include <net/ip.h>
36731
36732 #include "ftgmac100.h"
36733 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
36734 index b901a01..1ff32ee 100644
36735 --- a/drivers/net/ethernet/faraday/ftmac100.c
36736 +++ b/drivers/net/ethernet/faraday/ftmac100.c
36737 @@ -31,6 +31,8 @@
36738 #include <linux/module.h>
36739 #include <linux/netdevice.h>
36740 #include <linux/platform_device.h>
36741 +#include <linux/interrupt.h>
36742 +#include <linux/irqreturn.h>
36743
36744 #include "ftmac100.h"
36745
36746 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36747 index d929131..aed108f 100644
36748 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36749 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36750 @@ -865,7 +865,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
36751 /* store the new cycle speed */
36752 adapter->cycle_speed = cycle_speed;
36753
36754 - ACCESS_ONCE(adapter->base_incval) = incval;
36755 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
36756 smp_mb();
36757
36758 /* grab the ptp lock */
36759 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36760 index c2e420a..26a75e0 100644
36761 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
36762 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36763 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36764 struct __vxge_hw_fifo *fifo;
36765 struct vxge_hw_fifo_config *config;
36766 u32 txdl_size, txdl_per_memblock;
36767 - struct vxge_hw_mempool_cbs fifo_mp_callback;
36768 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
36769 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
36770 + };
36771 +
36772 struct __vxge_hw_virtualpath *vpath;
36773
36774 if ((vp == NULL) || (attr == NULL)) {
36775 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36776 goto exit;
36777 }
36778
36779 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
36780 -
36781 fifo->mempool =
36782 __vxge_hw_mempool_create(vpath->hldev,
36783 fifo->config->memblock_size,
36784 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
36785 index 927aa33..a6c2518 100644
36786 --- a/drivers/net/ethernet/realtek/r8169.c
36787 +++ b/drivers/net/ethernet/realtek/r8169.c
36788 @@ -747,22 +747,22 @@ struct rtl8169_private {
36789 struct mdio_ops {
36790 void (*write)(struct rtl8169_private *, int, int);
36791 int (*read)(struct rtl8169_private *, int);
36792 - } mdio_ops;
36793 + } __no_const mdio_ops;
36794
36795 struct pll_power_ops {
36796 void (*down)(struct rtl8169_private *);
36797 void (*up)(struct rtl8169_private *);
36798 - } pll_power_ops;
36799 + } __no_const pll_power_ops;
36800
36801 struct jumbo_ops {
36802 void (*enable)(struct rtl8169_private *);
36803 void (*disable)(struct rtl8169_private *);
36804 - } jumbo_ops;
36805 + } __no_const jumbo_ops;
36806
36807 struct csi_ops {
36808 void (*write)(struct rtl8169_private *, int, int);
36809 u32 (*read)(struct rtl8169_private *, int);
36810 - } csi_ops;
36811 + } __no_const csi_ops;
36812
36813 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
36814 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
36815 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
36816 index 0767043f..08c2553 100644
36817 --- a/drivers/net/ethernet/sfc/ptp.c
36818 +++ b/drivers/net/ethernet/sfc/ptp.c
36819 @@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
36820 (u32)((u64)ptp->start.dma_addr >> 32));
36821
36822 /* Clear flag that signals MC ready */
36823 - ACCESS_ONCE(*start) = 0;
36824 + ACCESS_ONCE_RW(*start) = 0;
36825 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
36826 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
36827
36828 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36829 index 0c74a70..3bc6f68 100644
36830 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36831 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36832 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
36833
36834 writel(value, ioaddr + MMC_CNTRL);
36835
36836 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36837 - MMC_CNTRL, value);
36838 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36839 +// MMC_CNTRL, value);
36840 }
36841
36842 /* To mask all all interrupts.*/
36843 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
36844 index 5fd6f46..ee1f265 100644
36845 --- a/drivers/net/hyperv/hyperv_net.h
36846 +++ b/drivers/net/hyperv/hyperv_net.h
36847 @@ -101,7 +101,7 @@ struct rndis_device {
36848
36849 enum rndis_device_state state;
36850 bool link_state;
36851 - atomic_t new_req_id;
36852 + atomic_unchecked_t new_req_id;
36853
36854 spinlock_t request_lock;
36855 struct list_head req_list;
36856 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
36857 index 928148c..d83298e 100644
36858 --- a/drivers/net/hyperv/rndis_filter.c
36859 +++ b/drivers/net/hyperv/rndis_filter.c
36860 @@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
36861 * template
36862 */
36863 set = &rndis_msg->msg.set_req;
36864 - set->req_id = atomic_inc_return(&dev->new_req_id);
36865 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36866
36867 /* Add to the request list */
36868 spin_lock_irqsave(&dev->request_lock, flags);
36869 @@ -760,7 +760,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
36870
36871 /* Setup the rndis set */
36872 halt = &request->request_msg.msg.halt_req;
36873 - halt->req_id = atomic_inc_return(&dev->new_req_id);
36874 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36875
36876 /* Ignore return since this msg is optional. */
36877 rndis_filter_send_request(dev, request);
36878 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
36879 index 7d39add..037e1da 100644
36880 --- a/drivers/net/ieee802154/fakehard.c
36881 +++ b/drivers/net/ieee802154/fakehard.c
36882 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
36883 phy->transmit_power = 0xbf;
36884
36885 dev->netdev_ops = &fake_ops;
36886 - dev->ml_priv = &fake_mlme;
36887 + dev->ml_priv = (void *)&fake_mlme;
36888
36889 priv = netdev_priv(dev);
36890 priv->phy = phy;
36891 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
36892 index 0f0f9ce..0ca5819 100644
36893 --- a/drivers/net/macvtap.c
36894 +++ b/drivers/net/macvtap.c
36895 @@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
36896 return NOTIFY_DONE;
36897 }
36898
36899 -static struct notifier_block macvtap_notifier_block __read_mostly = {
36900 +static struct notifier_block macvtap_notifier_block = {
36901 .notifier_call = macvtap_device_event,
36902 };
36903
36904 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
36905 index daec9b0..6428fcb 100644
36906 --- a/drivers/net/phy/mdio-bitbang.c
36907 +++ b/drivers/net/phy/mdio-bitbang.c
36908 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
36909 struct mdiobb_ctrl *ctrl = bus->priv;
36910
36911 module_put(ctrl->ops->owner);
36912 + mdiobus_unregister(bus);
36913 mdiobus_free(bus);
36914 }
36915 EXPORT_SYMBOL(free_mdio_bitbang);
36916 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
36917 index eb3f5ce..d773730 100644
36918 --- a/drivers/net/ppp/ppp_generic.c
36919 +++ b/drivers/net/ppp/ppp_generic.c
36920 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36921 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
36922 struct ppp_stats stats;
36923 struct ppp_comp_stats cstats;
36924 - char *vers;
36925
36926 switch (cmd) {
36927 case SIOCGPPPSTATS:
36928 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36929 break;
36930
36931 case SIOCGPPPVER:
36932 - vers = PPP_VERSION;
36933 - if (copy_to_user(addr, vers, strlen(vers) + 1))
36934 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
36935 break;
36936 err = 0;
36937 break;
36938 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
36939 index ad86660..9fd0884 100644
36940 --- a/drivers/net/team/team.c
36941 +++ b/drivers/net/team/team.c
36942 @@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
36943 return NOTIFY_DONE;
36944 }
36945
36946 -static struct notifier_block team_notifier_block __read_mostly = {
36947 +static struct notifier_block team_notifier_block = {
36948 .notifier_call = team_device_event,
36949 };
36950
36951 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
36952 index 0873cdc..ddb178e 100644
36953 --- a/drivers/net/tun.c
36954 +++ b/drivers/net/tun.c
36955 @@ -1374,7 +1374,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
36956 }
36957
36958 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36959 - unsigned long arg, int ifreq_len)
36960 + unsigned long arg, size_t ifreq_len)
36961 {
36962 struct tun_file *tfile = file->private_data;
36963 struct tun_struct *tun;
36964 @@ -1387,6 +1387,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36965 int vnet_hdr_sz;
36966 int ret;
36967
36968 + if (ifreq_len > sizeof ifr)
36969 + return -EFAULT;
36970 +
36971 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
36972 if (copy_from_user(&ifr, argp, ifreq_len))
36973 return -EFAULT;
36974 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
36975 index 605a4ba..a883dd1 100644
36976 --- a/drivers/net/usb/hso.c
36977 +++ b/drivers/net/usb/hso.c
36978 @@ -71,7 +71,7 @@
36979 #include <asm/byteorder.h>
36980 #include <linux/serial_core.h>
36981 #include <linux/serial.h>
36982 -
36983 +#include <asm/local.h>
36984
36985 #define MOD_AUTHOR "Option Wireless"
36986 #define MOD_DESCRIPTION "USB High Speed Option driver"
36987 @@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
36988 struct urb *urb;
36989
36990 urb = serial->rx_urb[0];
36991 - if (serial->port.count > 0) {
36992 + if (atomic_read(&serial->port.count) > 0) {
36993 count = put_rxbuf_data(urb, serial);
36994 if (count == -1)
36995 return;
36996 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
36997 DUMP1(urb->transfer_buffer, urb->actual_length);
36998
36999 /* Anyone listening? */
37000 - if (serial->port.count == 0)
37001 + if (atomic_read(&serial->port.count) == 0)
37002 return;
37003
37004 if (status == 0) {
37005 @@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37006 tty_port_tty_set(&serial->port, tty);
37007
37008 /* check for port already opened, if not set the termios */
37009 - serial->port.count++;
37010 - if (serial->port.count == 1) {
37011 + if (atomic_inc_return(&serial->port.count) == 1) {
37012 serial->rx_state = RX_IDLE;
37013 /* Force default termio settings */
37014 _hso_serial_set_termios(tty, NULL);
37015 @@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37016 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
37017 if (result) {
37018 hso_stop_serial_device(serial->parent);
37019 - serial->port.count--;
37020 + atomic_dec(&serial->port.count);
37021 kref_put(&serial->parent->ref, hso_serial_ref_free);
37022 }
37023 } else {
37024 @@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
37025
37026 /* reset the rts and dtr */
37027 /* do the actual close */
37028 - serial->port.count--;
37029 + atomic_dec(&serial->port.count);
37030
37031 - if (serial->port.count <= 0) {
37032 - serial->port.count = 0;
37033 + if (atomic_read(&serial->port.count) <= 0) {
37034 + atomic_set(&serial->port.count, 0);
37035 tty_port_tty_set(&serial->port, NULL);
37036 if (!usb_gone)
37037 hso_stop_serial_device(serial->parent);
37038 @@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
37039
37040 /* the actual setup */
37041 spin_lock_irqsave(&serial->serial_lock, flags);
37042 - if (serial->port.count)
37043 + if (atomic_read(&serial->port.count))
37044 _hso_serial_set_termios(tty, old);
37045 else
37046 tty->termios = *old;
37047 @@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
37048 D1("Pending read interrupt on port %d\n", i);
37049 spin_lock(&serial->serial_lock);
37050 if (serial->rx_state == RX_IDLE &&
37051 - serial->port.count > 0) {
37052 + atomic_read(&serial->port.count) > 0) {
37053 /* Setup and send a ctrl req read on
37054 * port i */
37055 if (!serial->rx_urb_filled[0]) {
37056 @@ -3078,7 +3077,7 @@ static int hso_resume(struct usb_interface *iface)
37057 /* Start all serial ports */
37058 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
37059 if (serial_table[i] && (serial_table[i]->interface == iface)) {
37060 - if (dev2ser(serial_table[i])->port.count) {
37061 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
37062 result =
37063 hso_start_serial_device(serial_table[i], GFP_NOIO);
37064 hso_kick_transmit(dev2ser(serial_table[i]));
37065 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37066 index 8d78253..bebbb68 100644
37067 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37068 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37069 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37070 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
37071 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
37072
37073 - ACCESS_ONCE(ads->ds_link) = i->link;
37074 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
37075 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
37076 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
37077
37078 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
37079 ctl6 = SM(i->keytype, AR_EncrType);
37080 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37081
37082 if ((i->is_first || i->is_last) &&
37083 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
37084 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
37085 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
37086 | set11nTries(i->rates, 1)
37087 | set11nTries(i->rates, 2)
37088 | set11nTries(i->rates, 3)
37089 | (i->dur_update ? AR_DurUpdateEna : 0)
37090 | SM(0, AR_BurstDur);
37091
37092 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
37093 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
37094 | set11nRate(i->rates, 1)
37095 | set11nRate(i->rates, 2)
37096 | set11nRate(i->rates, 3);
37097 } else {
37098 - ACCESS_ONCE(ads->ds_ctl2) = 0;
37099 - ACCESS_ONCE(ads->ds_ctl3) = 0;
37100 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
37101 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
37102 }
37103
37104 if (!i->is_first) {
37105 - ACCESS_ONCE(ads->ds_ctl0) = 0;
37106 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37107 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37108 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
37109 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37110 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37111 return;
37112 }
37113
37114 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37115 break;
37116 }
37117
37118 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37119 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37120 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37121 | SM(i->txpower, AR_XmitPower)
37122 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37123 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37124 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
37125 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
37126
37127 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37128 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37129 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37130 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37131
37132 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
37133 return;
37134
37135 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37136 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37137 | set11nPktDurRTSCTS(i->rates, 1);
37138
37139 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37140 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37141 | set11nPktDurRTSCTS(i->rates, 3);
37142
37143 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37144 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37145 | set11nRateFlags(i->rates, 1)
37146 | set11nRateFlags(i->rates, 2)
37147 | set11nRateFlags(i->rates, 3)
37148 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37149 index 301bf72..3f5654f 100644
37150 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37151 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37152 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37153 (i->qcu << AR_TxQcuNum_S) | desc_len;
37154
37155 checksum += val;
37156 - ACCESS_ONCE(ads->info) = val;
37157 + ACCESS_ONCE_RW(ads->info) = val;
37158
37159 checksum += i->link;
37160 - ACCESS_ONCE(ads->link) = i->link;
37161 + ACCESS_ONCE_RW(ads->link) = i->link;
37162
37163 checksum += i->buf_addr[0];
37164 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
37165 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
37166 checksum += i->buf_addr[1];
37167 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
37168 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
37169 checksum += i->buf_addr[2];
37170 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
37171 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
37172 checksum += i->buf_addr[3];
37173 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
37174 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
37175
37176 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
37177 - ACCESS_ONCE(ads->ctl3) = val;
37178 + ACCESS_ONCE_RW(ads->ctl3) = val;
37179 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
37180 - ACCESS_ONCE(ads->ctl5) = val;
37181 + ACCESS_ONCE_RW(ads->ctl5) = val;
37182 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
37183 - ACCESS_ONCE(ads->ctl7) = val;
37184 + ACCESS_ONCE_RW(ads->ctl7) = val;
37185 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
37186 - ACCESS_ONCE(ads->ctl9) = val;
37187 + ACCESS_ONCE_RW(ads->ctl9) = val;
37188
37189 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
37190 - ACCESS_ONCE(ads->ctl10) = checksum;
37191 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
37192
37193 if (i->is_first || i->is_last) {
37194 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
37195 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
37196 | set11nTries(i->rates, 1)
37197 | set11nTries(i->rates, 2)
37198 | set11nTries(i->rates, 3)
37199 | (i->dur_update ? AR_DurUpdateEna : 0)
37200 | SM(0, AR_BurstDur);
37201
37202 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
37203 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
37204 | set11nRate(i->rates, 1)
37205 | set11nRate(i->rates, 2)
37206 | set11nRate(i->rates, 3);
37207 } else {
37208 - ACCESS_ONCE(ads->ctl13) = 0;
37209 - ACCESS_ONCE(ads->ctl14) = 0;
37210 + ACCESS_ONCE_RW(ads->ctl13) = 0;
37211 + ACCESS_ONCE_RW(ads->ctl14) = 0;
37212 }
37213
37214 ads->ctl20 = 0;
37215 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37216
37217 ctl17 = SM(i->keytype, AR_EncrType);
37218 if (!i->is_first) {
37219 - ACCESS_ONCE(ads->ctl11) = 0;
37220 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37221 - ACCESS_ONCE(ads->ctl15) = 0;
37222 - ACCESS_ONCE(ads->ctl16) = 0;
37223 - ACCESS_ONCE(ads->ctl17) = ctl17;
37224 - ACCESS_ONCE(ads->ctl18) = 0;
37225 - ACCESS_ONCE(ads->ctl19) = 0;
37226 + ACCESS_ONCE_RW(ads->ctl11) = 0;
37227 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37228 + ACCESS_ONCE_RW(ads->ctl15) = 0;
37229 + ACCESS_ONCE_RW(ads->ctl16) = 0;
37230 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37231 + ACCESS_ONCE_RW(ads->ctl18) = 0;
37232 + ACCESS_ONCE_RW(ads->ctl19) = 0;
37233 return;
37234 }
37235
37236 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37237 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37238 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37239 | SM(i->txpower, AR_XmitPower)
37240 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37241 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37242 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
37243 ctl12 |= SM(val, AR_PAPRDChainMask);
37244
37245 - ACCESS_ONCE(ads->ctl12) = ctl12;
37246 - ACCESS_ONCE(ads->ctl17) = ctl17;
37247 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
37248 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37249
37250 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37251 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37252 | set11nPktDurRTSCTS(i->rates, 1);
37253
37254 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37255 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37256 | set11nPktDurRTSCTS(i->rates, 3);
37257
37258 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
37259 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
37260 | set11nRateFlags(i->rates, 1)
37261 | set11nRateFlags(i->rates, 2)
37262 | set11nRateFlags(i->rates, 3)
37263 | SM(i->rtscts_rate, AR_RTSCTSRate);
37264
37265 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
37266 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
37267 }
37268
37269 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
37270 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
37271 index dbc1b7a..67e2ca2 100644
37272 --- a/drivers/net/wireless/ath/ath9k/hw.h
37273 +++ b/drivers/net/wireless/ath/ath9k/hw.h
37274 @@ -657,7 +657,7 @@ struct ath_hw_private_ops {
37275
37276 /* ANI */
37277 void (*ani_cache_ini_regs)(struct ath_hw *ah);
37278 -};
37279 +} __no_const;
37280
37281 /**
37282 * struct ath_hw_ops - callbacks used by hardware code and driver code
37283 @@ -687,7 +687,7 @@ struct ath_hw_ops {
37284 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
37285 struct ath_hw_antcomb_conf *antconf);
37286 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
37287 -};
37288 +} __no_const;
37289
37290 struct ath_nf_limits {
37291 s16 max;
37292 diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37293 index 71ced17..cd82b12 100644
37294 --- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37295 +++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37296 @@ -184,7 +184,7 @@ struct brcmf_cfg80211_event_loop {
37297 struct net_device *ndev,
37298 const struct brcmf_event_msg *e,
37299 void *data);
37300 -};
37301 +} __no_const;
37302
37303 /* basic structure of scan request */
37304 struct brcmf_cfg80211_scan_req {
37305 @@ -239,7 +239,7 @@ struct brcmf_cfg80211_profile {
37306 struct brcmf_cfg80211_iscan_eloop {
37307 s32 (*handler[WL_SCAN_ERSULTS_LAST])
37308 (struct brcmf_cfg80211_info *cfg);
37309 -};
37310 +} __no_const;
37311
37312 /* dongle iscan controller */
37313 struct brcmf_cfg80211_iscan_ctrl {
37314 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
37315 index e252acb..6ad1e65 100644
37316 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
37317 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
37318 @@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
37319 */
37320 if (il3945_mod_params.disable_hw_scan) {
37321 D_INFO("Disabling hw_scan\n");
37322 - il3945_mac_ops.hw_scan = NULL;
37323 + pax_open_kernel();
37324 + *(void **)&il3945_mac_ops.hw_scan = NULL;
37325 + pax_close_kernel();
37326 }
37327
37328 D_INFO("*** LOAD DRIVER ***\n");
37329 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37330 index 1a98fa3..51e6661 100644
37331 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37332 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37333 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
37334 {
37335 struct iwl_priv *priv = file->private_data;
37336 char buf[64];
37337 - int buf_size;
37338 + size_t buf_size;
37339 u32 offset, len;
37340
37341 memset(buf, 0, sizeof(buf));
37342 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
37343 struct iwl_priv *priv = file->private_data;
37344
37345 char buf[8];
37346 - int buf_size;
37347 + size_t buf_size;
37348 u32 reset_flag;
37349
37350 memset(buf, 0, sizeof(buf));
37351 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
37352 {
37353 struct iwl_priv *priv = file->private_data;
37354 char buf[8];
37355 - int buf_size;
37356 + size_t buf_size;
37357 int ht40;
37358
37359 memset(buf, 0, sizeof(buf));
37360 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
37361 {
37362 struct iwl_priv *priv = file->private_data;
37363 char buf[8];
37364 - int buf_size;
37365 + size_t buf_size;
37366 int value;
37367
37368 memset(buf, 0, sizeof(buf));
37369 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
37370 {
37371 struct iwl_priv *priv = file->private_data;
37372 char buf[8];
37373 - int buf_size;
37374 + size_t buf_size;
37375 int clear;
37376
37377 memset(buf, 0, sizeof(buf));
37378 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
37379 {
37380 struct iwl_priv *priv = file->private_data;
37381 char buf[8];
37382 - int buf_size;
37383 + size_t buf_size;
37384 int trace;
37385
37386 memset(buf, 0, sizeof(buf));
37387 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
37388 {
37389 struct iwl_priv *priv = file->private_data;
37390 char buf[8];
37391 - int buf_size;
37392 + size_t buf_size;
37393 int missed;
37394
37395 memset(buf, 0, sizeof(buf));
37396 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
37397
37398 struct iwl_priv *priv = file->private_data;
37399 char buf[8];
37400 - int buf_size;
37401 + size_t buf_size;
37402 int plcp;
37403
37404 memset(buf, 0, sizeof(buf));
37405 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
37406
37407 struct iwl_priv *priv = file->private_data;
37408 char buf[8];
37409 - int buf_size;
37410 + size_t buf_size;
37411 int flush;
37412
37413 memset(buf, 0, sizeof(buf));
37414 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
37415
37416 struct iwl_priv *priv = file->private_data;
37417 char buf[8];
37418 - int buf_size;
37419 + size_t buf_size;
37420 int rts;
37421
37422 if (!priv->cfg->ht_params)
37423 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
37424 {
37425 struct iwl_priv *priv = file->private_data;
37426 char buf[8];
37427 - int buf_size;
37428 + size_t buf_size;
37429
37430 memset(buf, 0, sizeof(buf));
37431 buf_size = min(count, sizeof(buf) - 1);
37432 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
37433 struct iwl_priv *priv = file->private_data;
37434 u32 event_log_flag;
37435 char buf[8];
37436 - int buf_size;
37437 + size_t buf_size;
37438
37439 /* check that the interface is up */
37440 if (!iwl_is_ready(priv))
37441 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
37442 struct iwl_priv *priv = file->private_data;
37443 char buf[8];
37444 u32 calib_disabled;
37445 - int buf_size;
37446 + size_t buf_size;
37447
37448 memset(buf, 0, sizeof(buf));
37449 buf_size = min(count, sizeof(buf) - 1);
37450 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
37451 index fe0fffd..b4c5724 100644
37452 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
37453 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
37454 @@ -1967,7 +1967,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
37455 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
37456
37457 char buf[8];
37458 - int buf_size;
37459 + size_t buf_size;
37460 u32 reset_flag;
37461
37462 memset(buf, 0, sizeof(buf));
37463 @@ -1988,7 +1988,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
37464 {
37465 struct iwl_trans *trans = file->private_data;
37466 char buf[8];
37467 - int buf_size;
37468 + size_t buf_size;
37469 int csr;
37470
37471 memset(buf, 0, sizeof(buf));
37472 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
37473 index 429ca32..f86236b 100644
37474 --- a/drivers/net/wireless/mac80211_hwsim.c
37475 +++ b/drivers/net/wireless/mac80211_hwsim.c
37476 @@ -1751,9 +1751,11 @@ static int __init init_mac80211_hwsim(void)
37477 return -EINVAL;
37478
37479 if (fake_hw_scan) {
37480 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
37481 - mac80211_hwsim_ops.sw_scan_start = NULL;
37482 - mac80211_hwsim_ops.sw_scan_complete = NULL;
37483 + pax_open_kernel();
37484 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
37485 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
37486 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
37487 + pax_close_kernel();
37488 }
37489
37490 spin_lock_init(&hwsim_radio_lock);
37491 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
37492 index bd1f0cb..db85ab0 100644
37493 --- a/drivers/net/wireless/rndis_wlan.c
37494 +++ b/drivers/net/wireless/rndis_wlan.c
37495 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
37496
37497 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
37498
37499 - if (rts_threshold < 0 || rts_threshold > 2347)
37500 + if (rts_threshold > 2347)
37501 rts_threshold = 2347;
37502
37503 tmp = cpu_to_le32(rts_threshold);
37504 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
37505 index 0751b35..246ba3e 100644
37506 --- a/drivers/net/wireless/rt2x00/rt2x00.h
37507 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
37508 @@ -398,7 +398,7 @@ struct rt2x00_intf {
37509 * for hardware which doesn't support hardware
37510 * sequence counting.
37511 */
37512 - atomic_t seqno;
37513 + atomic_unchecked_t seqno;
37514 };
37515
37516 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
37517 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
37518 index e488b94..14b6a0c 100644
37519 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
37520 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
37521 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
37522 * sequence counter given by mac80211.
37523 */
37524 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
37525 - seqno = atomic_add_return(0x10, &intf->seqno);
37526 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
37527 else
37528 - seqno = atomic_read(&intf->seqno);
37529 + seqno = atomic_read_unchecked(&intf->seqno);
37530
37531 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
37532 hdr->seq_ctrl |= cpu_to_le16(seqno);
37533 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
37534 index e2750a1..797e179 100644
37535 --- a/drivers/net/wireless/ti/wl1251/sdio.c
37536 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
37537 @@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
37538
37539 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
37540
37541 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37542 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37543 + pax_open_kernel();
37544 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37545 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37546 + pax_close_kernel();
37547
37548 wl1251_info("using dedicated interrupt line");
37549 } else {
37550 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37551 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37552 + pax_open_kernel();
37553 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37554 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37555 + pax_close_kernel();
37556
37557 wl1251_info("using SDIO interrupt");
37558 }
37559 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
37560 index dadf1db..d9db7a7 100644
37561 --- a/drivers/net/wireless/ti/wl12xx/main.c
37562 +++ b/drivers/net/wireless/ti/wl12xx/main.c
37563 @@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37564 sizeof(wl->conf.mem));
37565
37566 /* read data preparation is only needed by wl127x */
37567 - wl->ops->prepare_read = wl127x_prepare_read;
37568 + pax_open_kernel();
37569 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37570 + pax_close_kernel();
37571
37572 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37573 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37574 @@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37575 sizeof(wl->conf.mem));
37576
37577 /* read data preparation is only needed by wl127x */
37578 - wl->ops->prepare_read = wl127x_prepare_read;
37579 + pax_open_kernel();
37580 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37581 + pax_close_kernel();
37582
37583 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37584 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37585 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
37586 index a39682a..1e8220c 100644
37587 --- a/drivers/net/wireless/ti/wl18xx/main.c
37588 +++ b/drivers/net/wireless/ti/wl18xx/main.c
37589 @@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
37590 }
37591
37592 if (!checksum_param) {
37593 - wl18xx_ops.set_rx_csum = NULL;
37594 - wl18xx_ops.init_vif = NULL;
37595 + pax_open_kernel();
37596 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
37597 + *(void **)&wl18xx_ops.init_vif = NULL;
37598 + pax_close_kernel();
37599 }
37600
37601 /* Enable 11a Band only if we have 5G antennas */
37602 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
37603 index d93b2b6..ae50401 100644
37604 --- a/drivers/oprofile/buffer_sync.c
37605 +++ b/drivers/oprofile/buffer_sync.c
37606 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
37607 if (cookie == NO_COOKIE)
37608 offset = pc;
37609 if (cookie == INVALID_COOKIE) {
37610 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37611 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37612 offset = pc;
37613 }
37614 if (cookie != last_cookie) {
37615 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
37616 /* add userspace sample */
37617
37618 if (!mm) {
37619 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
37620 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
37621 return 0;
37622 }
37623
37624 cookie = lookup_dcookie(mm, s->eip, &offset);
37625
37626 if (cookie == INVALID_COOKIE) {
37627 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37628 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37629 return 0;
37630 }
37631
37632 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
37633 /* ignore backtraces if failed to add a sample */
37634 if (state == sb_bt_start) {
37635 state = sb_bt_ignore;
37636 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
37637 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
37638 }
37639 }
37640 release_mm(mm);
37641 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
37642 index c0cc4e7..44d4e54 100644
37643 --- a/drivers/oprofile/event_buffer.c
37644 +++ b/drivers/oprofile/event_buffer.c
37645 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
37646 }
37647
37648 if (buffer_pos == buffer_size) {
37649 - atomic_inc(&oprofile_stats.event_lost_overflow);
37650 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
37651 return;
37652 }
37653
37654 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
37655 index ed2c3ec..deda85a 100644
37656 --- a/drivers/oprofile/oprof.c
37657 +++ b/drivers/oprofile/oprof.c
37658 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
37659 if (oprofile_ops.switch_events())
37660 return;
37661
37662 - atomic_inc(&oprofile_stats.multiplex_counter);
37663 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
37664 start_switch_worker();
37665 }
37666
37667 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
37668 index 917d28e..d62d981 100644
37669 --- a/drivers/oprofile/oprofile_stats.c
37670 +++ b/drivers/oprofile/oprofile_stats.c
37671 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
37672 cpu_buf->sample_invalid_eip = 0;
37673 }
37674
37675 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
37676 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
37677 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
37678 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
37679 - atomic_set(&oprofile_stats.multiplex_counter, 0);
37680 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
37681 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
37682 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
37683 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
37684 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
37685 }
37686
37687
37688 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
37689 index 38b6fc0..b5cbfce 100644
37690 --- a/drivers/oprofile/oprofile_stats.h
37691 +++ b/drivers/oprofile/oprofile_stats.h
37692 @@ -13,11 +13,11 @@
37693 #include <linux/atomic.h>
37694
37695 struct oprofile_stat_struct {
37696 - atomic_t sample_lost_no_mm;
37697 - atomic_t sample_lost_no_mapping;
37698 - atomic_t bt_lost_no_mapping;
37699 - atomic_t event_lost_overflow;
37700 - atomic_t multiplex_counter;
37701 + atomic_unchecked_t sample_lost_no_mm;
37702 + atomic_unchecked_t sample_lost_no_mapping;
37703 + atomic_unchecked_t bt_lost_no_mapping;
37704 + atomic_unchecked_t event_lost_overflow;
37705 + atomic_unchecked_t multiplex_counter;
37706 };
37707
37708 extern struct oprofile_stat_struct oprofile_stats;
37709 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
37710 index 849357c..b83c1e0 100644
37711 --- a/drivers/oprofile/oprofilefs.c
37712 +++ b/drivers/oprofile/oprofilefs.c
37713 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
37714
37715
37716 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
37717 - char const *name, atomic_t *val)
37718 + char const *name, atomic_unchecked_t *val)
37719 {
37720 return __oprofilefs_create_file(sb, root, name,
37721 &atomic_ro_fops, 0444, val);
37722 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
37723 index 3f56bc0..707d642 100644
37724 --- a/drivers/parport/procfs.c
37725 +++ b/drivers/parport/procfs.c
37726 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
37727
37728 *ppos += len;
37729
37730 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
37731 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
37732 }
37733
37734 #ifdef CONFIG_PARPORT_1284
37735 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
37736
37737 *ppos += len;
37738
37739 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
37740 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
37741 }
37742 #endif /* IEEE1284.3 support. */
37743
37744 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
37745 index a6a71c4..c91097b 100644
37746 --- a/drivers/pci/hotplug/cpcihp_generic.c
37747 +++ b/drivers/pci/hotplug/cpcihp_generic.c
37748 @@ -73,7 +73,6 @@ static u16 port;
37749 static unsigned int enum_bit;
37750 static u8 enum_mask;
37751
37752 -static struct cpci_hp_controller_ops generic_hpc_ops;
37753 static struct cpci_hp_controller generic_hpc;
37754
37755 static int __init validate_parameters(void)
37756 @@ -139,6 +138,10 @@ static int query_enum(void)
37757 return ((value & enum_mask) == enum_mask);
37758 }
37759
37760 +static struct cpci_hp_controller_ops generic_hpc_ops = {
37761 + .query_enum = query_enum,
37762 +};
37763 +
37764 static int __init cpcihp_generic_init(void)
37765 {
37766 int status;
37767 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
37768 pci_dev_put(dev);
37769
37770 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
37771 - generic_hpc_ops.query_enum = query_enum;
37772 generic_hpc.ops = &generic_hpc_ops;
37773
37774 status = cpci_hp_register_controller(&generic_hpc);
37775 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
37776 index 6bf8d2a..9711ce0 100644
37777 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
37778 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
37779 @@ -59,7 +59,6 @@
37780 /* local variables */
37781 static bool debug;
37782 static bool poll;
37783 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
37784 static struct cpci_hp_controller zt5550_hpc;
37785
37786 /* Primary cPCI bus bridge device */
37787 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
37788 return 0;
37789 }
37790
37791 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
37792 + .query_enum = zt5550_hc_query_enum,
37793 +};
37794 +
37795 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
37796 {
37797 int status;
37798 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
37799 dbg("returned from zt5550_hc_config");
37800
37801 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
37802 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
37803 zt5550_hpc.ops = &zt5550_hpc_ops;
37804 if(!poll) {
37805 zt5550_hpc.irq = hc_dev->irq;
37806 zt5550_hpc.irq_flags = IRQF_SHARED;
37807 zt5550_hpc.dev_id = hc_dev;
37808
37809 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37810 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37811 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37812 + pax_open_kernel();
37813 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37814 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37815 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37816 + pax_open_kernel();
37817 } else {
37818 info("using ENUM# polling mode");
37819 }
37820 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
37821 index 76ba8a1..20ca857 100644
37822 --- a/drivers/pci/hotplug/cpqphp_nvram.c
37823 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
37824 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
37825
37826 void compaq_nvram_init (void __iomem *rom_start)
37827 {
37828 +
37829 +#ifndef CONFIG_PAX_KERNEXEC
37830 if (rom_start) {
37831 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
37832 }
37833 +#endif
37834 +
37835 dbg("int15 entry = %p\n", compaq_int15_entry_point);
37836
37837 /* initialize our int15 lock */
37838 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
37839 index 449f257..0731e96 100644
37840 --- a/drivers/pci/pcie/aspm.c
37841 +++ b/drivers/pci/pcie/aspm.c
37842 @@ -27,9 +27,9 @@
37843 #define MODULE_PARAM_PREFIX "pcie_aspm."
37844
37845 /* Note: those are not register definitions */
37846 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
37847 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
37848 -#define ASPM_STATE_L1 (4) /* L1 state */
37849 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
37850 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
37851 +#define ASPM_STATE_L1 (4U) /* L1 state */
37852 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
37853 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
37854
37855 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
37856 index ec909af..e7517f3 100644
37857 --- a/drivers/pci/probe.c
37858 +++ b/drivers/pci/probe.c
37859 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
37860 struct pci_bus_region region;
37861 bool bar_too_big = false, bar_disabled = false;
37862
37863 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
37864 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
37865
37866 /* No printks while decoding is disabled! */
37867 if (!dev->mmio_always_on) {
37868 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
37869 index 9b8505c..f00870a 100644
37870 --- a/drivers/pci/proc.c
37871 +++ b/drivers/pci/proc.c
37872 @@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
37873 static int __init pci_proc_init(void)
37874 {
37875 struct pci_dev *dev = NULL;
37876 +
37877 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
37878 +#ifdef CONFIG_GRKERNSEC_PROC_USER
37879 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
37880 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
37881 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
37882 +#endif
37883 +#else
37884 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
37885 +#endif
37886 proc_create("devices", 0, proc_bus_pci_dir,
37887 &proc_bus_pci_dev_operations);
37888 proc_initialized = 1;
37889 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
37890 index 75dd651..2af4c9a 100644
37891 --- a/drivers/platform/x86/thinkpad_acpi.c
37892 +++ b/drivers/platform/x86/thinkpad_acpi.c
37893 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
37894 return 0;
37895 }
37896
37897 -void static hotkey_mask_warn_incomplete_mask(void)
37898 +static void hotkey_mask_warn_incomplete_mask(void)
37899 {
37900 /* log only what the user can fix... */
37901 const u32 wantedmask = hotkey_driver_mask &
37902 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
37903 }
37904 }
37905
37906 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37907 - struct tp_nvram_state *newn,
37908 - const u32 event_mask)
37909 -{
37910 -
37911 #define TPACPI_COMPARE_KEY(__scancode, __member) \
37912 do { \
37913 if ((event_mask & (1 << __scancode)) && \
37914 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37915 tpacpi_hotkey_send_key(__scancode); \
37916 } while (0)
37917
37918 - void issue_volchange(const unsigned int oldvol,
37919 - const unsigned int newvol)
37920 - {
37921 - unsigned int i = oldvol;
37922 +static void issue_volchange(const unsigned int oldvol,
37923 + const unsigned int newvol,
37924 + const u32 event_mask)
37925 +{
37926 + unsigned int i = oldvol;
37927
37928 - while (i > newvol) {
37929 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37930 - i--;
37931 - }
37932 - while (i < newvol) {
37933 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37934 - i++;
37935 - }
37936 + while (i > newvol) {
37937 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37938 + i--;
37939 }
37940 + while (i < newvol) {
37941 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37942 + i++;
37943 + }
37944 +}
37945
37946 - void issue_brightnesschange(const unsigned int oldbrt,
37947 - const unsigned int newbrt)
37948 - {
37949 - unsigned int i = oldbrt;
37950 +static void issue_brightnesschange(const unsigned int oldbrt,
37951 + const unsigned int newbrt,
37952 + const u32 event_mask)
37953 +{
37954 + unsigned int i = oldbrt;
37955
37956 - while (i > newbrt) {
37957 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37958 - i--;
37959 - }
37960 - while (i < newbrt) {
37961 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37962 - i++;
37963 - }
37964 + while (i > newbrt) {
37965 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37966 + i--;
37967 + }
37968 + while (i < newbrt) {
37969 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37970 + i++;
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 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
37979 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
37980 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
37981 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37982 oldn->volume_level != newn->volume_level) {
37983 /* recently muted, or repeated mute keypress, or
37984 * multiple presses ending in mute */
37985 - issue_volchange(oldn->volume_level, newn->volume_level);
37986 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
37987 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
37988 }
37989 } else {
37990 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37991 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37992 }
37993 if (oldn->volume_level != newn->volume_level) {
37994 - issue_volchange(oldn->volume_level, newn->volume_level);
37995 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
37996 } else if (oldn->volume_toggle != newn->volume_toggle) {
37997 /* repeated vol up/down keypress at end of scale ? */
37998 if (newn->volume_level == 0)
37999 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38000 /* handle brightness */
38001 if (oldn->brightness_level != newn->brightness_level) {
38002 issue_brightnesschange(oldn->brightness_level,
38003 - newn->brightness_level);
38004 + newn->brightness_level,
38005 + event_mask);
38006 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
38007 /* repeated key presses that didn't change state */
38008 if (newn->brightness_level == 0)
38009 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38010 && !tp_features.bright_unkfw)
38011 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38012 }
38013 +}
38014
38015 #undef TPACPI_COMPARE_KEY
38016 #undef TPACPI_MAY_SEND_KEY
38017 -}
38018
38019 /*
38020 * Polling driver
38021 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
38022 index 769d265..a3a05ca 100644
38023 --- a/drivers/pnp/pnpbios/bioscalls.c
38024 +++ b/drivers/pnp/pnpbios/bioscalls.c
38025 @@ -58,7 +58,7 @@ do { \
38026 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
38027 } while(0)
38028
38029 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
38030 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
38031 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
38032
38033 /*
38034 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38035
38036 cpu = get_cpu();
38037 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
38038 +
38039 + pax_open_kernel();
38040 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
38041 + pax_close_kernel();
38042
38043 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
38044 spin_lock_irqsave(&pnp_bios_lock, flags);
38045 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38046 :"memory");
38047 spin_unlock_irqrestore(&pnp_bios_lock, flags);
38048
38049 + pax_open_kernel();
38050 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
38051 + pax_close_kernel();
38052 +
38053 put_cpu();
38054
38055 /* If we get here and this is set then the PnP BIOS faulted on us. */
38056 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
38057 return status;
38058 }
38059
38060 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
38061 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
38062 {
38063 int i;
38064
38065 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38066 pnp_bios_callpoint.offset = header->fields.pm16offset;
38067 pnp_bios_callpoint.segment = PNP_CS16;
38068
38069 + pax_open_kernel();
38070 +
38071 for_each_possible_cpu(i) {
38072 struct desc_struct *gdt = get_cpu_gdt_table(i);
38073 if (!gdt)
38074 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38075 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
38076 (unsigned long)__va(header->fields.pm16dseg));
38077 }
38078 +
38079 + pax_close_kernel();
38080 }
38081 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
38082 index b0ecacb..7c9da2e 100644
38083 --- a/drivers/pnp/resource.c
38084 +++ b/drivers/pnp/resource.c
38085 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
38086 return 1;
38087
38088 /* check if the resource is valid */
38089 - if (*irq < 0 || *irq > 15)
38090 + if (*irq > 15)
38091 return 0;
38092
38093 /* check if the resource is reserved */
38094 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
38095 return 1;
38096
38097 /* check if the resource is valid */
38098 - if (*dma < 0 || *dma == 4 || *dma > 7)
38099 + if (*dma == 4 || *dma > 7)
38100 return 0;
38101
38102 /* check if the resource is reserved */
38103 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
38104 index 7df7c5f..bd48c47 100644
38105 --- a/drivers/power/pda_power.c
38106 +++ b/drivers/power/pda_power.c
38107 @@ -37,7 +37,11 @@ static int polling;
38108
38109 #ifdef CONFIG_USB_OTG_UTILS
38110 static struct usb_phy *transceiver;
38111 -static struct notifier_block otg_nb;
38112 +static int otg_handle_notification(struct notifier_block *nb,
38113 + unsigned long event, void *unused);
38114 +static struct notifier_block otg_nb = {
38115 + .notifier_call = otg_handle_notification
38116 +};
38117 #endif
38118
38119 static struct regulator *ac_draw;
38120 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
38121
38122 #ifdef CONFIG_USB_OTG_UTILS
38123 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
38124 - otg_nb.notifier_call = otg_handle_notification;
38125 ret = usb_register_notifier(transceiver, &otg_nb);
38126 if (ret) {
38127 dev_err(dev, "failure to register otg notifier\n");
38128 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
38129 index 8d53174..04c65de 100644
38130 --- a/drivers/regulator/max8660.c
38131 +++ b/drivers/regulator/max8660.c
38132 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
38133 max8660->shadow_regs[MAX8660_OVER1] = 5;
38134 } else {
38135 /* Otherwise devices can be toggled via software */
38136 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
38137 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
38138 + pax_open_kernel();
38139 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
38140 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
38141 + pax_close_kernel();
38142 }
38143
38144 /*
38145 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
38146 index 1fa6381..f58834e 100644
38147 --- a/drivers/regulator/mc13892-regulator.c
38148 +++ b/drivers/regulator/mc13892-regulator.c
38149 @@ -540,10 +540,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
38150 }
38151 mc13xxx_unlock(mc13892);
38152
38153 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38154 + pax_open_kernel();
38155 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38156 = mc13892_vcam_set_mode;
38157 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38158 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38159 = mc13892_vcam_get_mode;
38160 + pax_close_kernel();
38161
38162 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
38163 ARRAY_SIZE(mc13892_regulators));
38164 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
38165 index cace6d3..f623fda 100644
38166 --- a/drivers/rtc/rtc-dev.c
38167 +++ b/drivers/rtc/rtc-dev.c
38168 @@ -14,6 +14,7 @@
38169 #include <linux/module.h>
38170 #include <linux/rtc.h>
38171 #include <linux/sched.h>
38172 +#include <linux/grsecurity.h>
38173 #include "rtc-core.h"
38174
38175 static dev_t rtc_devt;
38176 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
38177 if (copy_from_user(&tm, uarg, sizeof(tm)))
38178 return -EFAULT;
38179
38180 + gr_log_timechange();
38181 +
38182 return rtc_set_time(rtc, &tm);
38183
38184 case RTC_PIE_ON:
38185 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
38186 index 4ad7e36..d004679 100644
38187 --- a/drivers/scsi/bfa/bfa.h
38188 +++ b/drivers/scsi/bfa/bfa.h
38189 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
38190 u32 *end);
38191 int cpe_vec_q0;
38192 int rme_vec_q0;
38193 -};
38194 +} __no_const;
38195 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
38196
38197 struct bfa_faa_cbfn_s {
38198 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
38199 index e693af6..2e525b6 100644
38200 --- a/drivers/scsi/bfa/bfa_fcpim.h
38201 +++ b/drivers/scsi/bfa/bfa_fcpim.h
38202 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
38203
38204 struct bfa_itn_s {
38205 bfa_isr_func_t isr;
38206 -};
38207 +} __no_const;
38208
38209 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
38210 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
38211 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
38212 index 23a90e7..9cf04ee 100644
38213 --- a/drivers/scsi/bfa/bfa_ioc.h
38214 +++ b/drivers/scsi/bfa/bfa_ioc.h
38215 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
38216 bfa_ioc_disable_cbfn_t disable_cbfn;
38217 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
38218 bfa_ioc_reset_cbfn_t reset_cbfn;
38219 -};
38220 +} __no_const;
38221
38222 /*
38223 * IOC event notification mechanism.
38224 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
38225 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
38226 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
38227 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
38228 -};
38229 +} __no_const;
38230
38231 /*
38232 * Queue element to wait for room in request queue. FIFO order is
38233 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
38234 index 593085a..47aa999 100644
38235 --- a/drivers/scsi/hosts.c
38236 +++ b/drivers/scsi/hosts.c
38237 @@ -42,7 +42,7 @@
38238 #include "scsi_logging.h"
38239
38240
38241 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38242 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38243
38244
38245 static void scsi_host_cls_release(struct device *dev)
38246 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
38247 * subtract one because we increment first then return, but we need to
38248 * know what the next host number was before increment
38249 */
38250 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
38251 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
38252 shost->dma_channel = 0xff;
38253
38254 /* These three are default values which can be overridden */
38255 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
38256 index 4217e49..9c77e3e 100644
38257 --- a/drivers/scsi/hpsa.c
38258 +++ b/drivers/scsi/hpsa.c
38259 @@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
38260 unsigned long flags;
38261
38262 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38263 - return h->access.command_completed(h, q);
38264 + return h->access->command_completed(h, q);
38265
38266 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
38267 a = rq->head[rq->current_entry];
38268 @@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
38269 while (!list_empty(&h->reqQ)) {
38270 c = list_entry(h->reqQ.next, struct CommandList, list);
38271 /* can't do anything if fifo is full */
38272 - if ((h->access.fifo_full(h))) {
38273 + if ((h->access->fifo_full(h))) {
38274 dev_warn(&h->pdev->dev, "fifo full\n");
38275 break;
38276 }
38277 @@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
38278
38279 /* Tell the controller execute command */
38280 spin_unlock_irqrestore(&h->lock, flags);
38281 - h->access.submit_command(h, c);
38282 + h->access->submit_command(h, c);
38283 spin_lock_irqsave(&h->lock, flags);
38284 }
38285 spin_unlock_irqrestore(&h->lock, flags);
38286 @@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
38287
38288 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
38289 {
38290 - return h->access.command_completed(h, q);
38291 + return h->access->command_completed(h, q);
38292 }
38293
38294 static inline bool interrupt_pending(struct ctlr_info *h)
38295 {
38296 - return h->access.intr_pending(h);
38297 + return h->access->intr_pending(h);
38298 }
38299
38300 static inline long interrupt_not_for_us(struct ctlr_info *h)
38301 {
38302 - return (h->access.intr_pending(h) == 0) ||
38303 + return (h->access->intr_pending(h) == 0) ||
38304 (h->interrupts_enabled == 0);
38305 }
38306
38307 @@ -4318,7 +4318,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
38308 if (prod_index < 0)
38309 return -ENODEV;
38310 h->product_name = products[prod_index].product_name;
38311 - h->access = *(products[prod_index].access);
38312 + h->access = products[prod_index].access;
38313
38314 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
38315 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
38316 @@ -4600,7 +4600,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
38317
38318 assert_spin_locked(&lockup_detector_lock);
38319 remove_ctlr_from_lockup_detector_list(h);
38320 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38321 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38322 spin_lock_irqsave(&h->lock, flags);
38323 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
38324 spin_unlock_irqrestore(&h->lock, flags);
38325 @@ -4778,7 +4778,7 @@ reinit_after_soft_reset:
38326 }
38327
38328 /* make sure the board interrupts are off */
38329 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38330 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38331
38332 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
38333 goto clean2;
38334 @@ -4812,7 +4812,7 @@ reinit_after_soft_reset:
38335 * fake ones to scoop up any residual completions.
38336 */
38337 spin_lock_irqsave(&h->lock, flags);
38338 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38339 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38340 spin_unlock_irqrestore(&h->lock, flags);
38341 free_irqs(h);
38342 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
38343 @@ -4831,9 +4831,9 @@ reinit_after_soft_reset:
38344 dev_info(&h->pdev->dev, "Board READY.\n");
38345 dev_info(&h->pdev->dev,
38346 "Waiting for stale completions to drain.\n");
38347 - h->access.set_intr_mask(h, HPSA_INTR_ON);
38348 + h->access->set_intr_mask(h, HPSA_INTR_ON);
38349 msleep(10000);
38350 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38351 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38352
38353 rc = controller_reset_failed(h->cfgtable);
38354 if (rc)
38355 @@ -4854,7 +4854,7 @@ reinit_after_soft_reset:
38356 }
38357
38358 /* Turn the interrupts on so we can service requests */
38359 - h->access.set_intr_mask(h, HPSA_INTR_ON);
38360 + h->access->set_intr_mask(h, HPSA_INTR_ON);
38361
38362 hpsa_hba_inquiry(h);
38363 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
38364 @@ -4906,7 +4906,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
38365 * To write all data in the battery backed cache to disks
38366 */
38367 hpsa_flush_cache(h);
38368 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38369 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38370 hpsa_free_irqs_and_disable_msix(h);
38371 }
38372
38373 @@ -5075,7 +5075,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
38374 return;
38375 }
38376 /* Change the access methods to the performant access methods */
38377 - h->access = SA5_performant_access;
38378 + h->access = &SA5_performant_access;
38379 h->transMethod = CFGTBL_Trans_Performant;
38380 }
38381
38382 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
38383 index 9816479..c5d4e97 100644
38384 --- a/drivers/scsi/hpsa.h
38385 +++ b/drivers/scsi/hpsa.h
38386 @@ -79,7 +79,7 @@ struct ctlr_info {
38387 unsigned int msix_vector;
38388 unsigned int msi_vector;
38389 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
38390 - struct access_method access;
38391 + struct access_method *access;
38392
38393 /* queue and queue Info */
38394 struct list_head reqQ;
38395 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
38396 index c772d8d..35c362c 100644
38397 --- a/drivers/scsi/libfc/fc_exch.c
38398 +++ b/drivers/scsi/libfc/fc_exch.c
38399 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
38400 u16 pool_max_index;
38401
38402 struct {
38403 - atomic_t no_free_exch;
38404 - atomic_t no_free_exch_xid;
38405 - atomic_t xid_not_found;
38406 - atomic_t xid_busy;
38407 - atomic_t seq_not_found;
38408 - atomic_t non_bls_resp;
38409 + atomic_unchecked_t no_free_exch;
38410 + atomic_unchecked_t no_free_exch_xid;
38411 + atomic_unchecked_t xid_not_found;
38412 + atomic_unchecked_t xid_busy;
38413 + atomic_unchecked_t seq_not_found;
38414 + atomic_unchecked_t non_bls_resp;
38415 } stats;
38416 };
38417
38418 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
38419 /* allocate memory for exchange */
38420 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
38421 if (!ep) {
38422 - atomic_inc(&mp->stats.no_free_exch);
38423 + atomic_inc_unchecked(&mp->stats.no_free_exch);
38424 goto out;
38425 }
38426 memset(ep, 0, sizeof(*ep));
38427 @@ -786,7 +786,7 @@ out:
38428 return ep;
38429 err:
38430 spin_unlock_bh(&pool->lock);
38431 - atomic_inc(&mp->stats.no_free_exch_xid);
38432 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
38433 mempool_free(ep, mp->ep_pool);
38434 return NULL;
38435 }
38436 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38437 xid = ntohs(fh->fh_ox_id); /* we originated exch */
38438 ep = fc_exch_find(mp, xid);
38439 if (!ep) {
38440 - atomic_inc(&mp->stats.xid_not_found);
38441 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38442 reject = FC_RJT_OX_ID;
38443 goto out;
38444 }
38445 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38446 ep = fc_exch_find(mp, xid);
38447 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
38448 if (ep) {
38449 - atomic_inc(&mp->stats.xid_busy);
38450 + atomic_inc_unchecked(&mp->stats.xid_busy);
38451 reject = FC_RJT_RX_ID;
38452 goto rel;
38453 }
38454 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38455 }
38456 xid = ep->xid; /* get our XID */
38457 } else if (!ep) {
38458 - atomic_inc(&mp->stats.xid_not_found);
38459 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38460 reject = FC_RJT_RX_ID; /* XID not found */
38461 goto out;
38462 }
38463 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38464 } else {
38465 sp = &ep->seq;
38466 if (sp->id != fh->fh_seq_id) {
38467 - atomic_inc(&mp->stats.seq_not_found);
38468 + atomic_inc_unchecked(&mp->stats.seq_not_found);
38469 if (f_ctl & FC_FC_END_SEQ) {
38470 /*
38471 * Update sequence_id based on incoming last
38472 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38473
38474 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
38475 if (!ep) {
38476 - atomic_inc(&mp->stats.xid_not_found);
38477 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38478 goto out;
38479 }
38480 if (ep->esb_stat & ESB_ST_COMPLETE) {
38481 - atomic_inc(&mp->stats.xid_not_found);
38482 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38483 goto rel;
38484 }
38485 if (ep->rxid == FC_XID_UNKNOWN)
38486 ep->rxid = ntohs(fh->fh_rx_id);
38487 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
38488 - atomic_inc(&mp->stats.xid_not_found);
38489 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38490 goto rel;
38491 }
38492 if (ep->did != ntoh24(fh->fh_s_id) &&
38493 ep->did != FC_FID_FLOGI) {
38494 - atomic_inc(&mp->stats.xid_not_found);
38495 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38496 goto rel;
38497 }
38498 sof = fr_sof(fp);
38499 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38500 sp->ssb_stat |= SSB_ST_RESP;
38501 sp->id = fh->fh_seq_id;
38502 } else if (sp->id != fh->fh_seq_id) {
38503 - atomic_inc(&mp->stats.seq_not_found);
38504 + atomic_inc_unchecked(&mp->stats.seq_not_found);
38505 goto rel;
38506 }
38507
38508 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38509 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
38510
38511 if (!sp)
38512 - atomic_inc(&mp->stats.xid_not_found);
38513 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38514 else
38515 - atomic_inc(&mp->stats.non_bls_resp);
38516 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
38517
38518 fc_frame_free(fp);
38519 }
38520 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
38521
38522 list_for_each_entry(ema, &lport->ema_list, ema_list) {
38523 mp = ema->mp;
38524 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
38525 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
38526 st->fc_no_free_exch_xid +=
38527 - atomic_read(&mp->stats.no_free_exch_xid);
38528 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
38529 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
38530 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
38531 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
38532 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
38533 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
38534 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
38535 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
38536 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
38537 }
38538 }
38539 EXPORT_SYMBOL(fc_exch_update_stats);
38540 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
38541 index bdb81cd..d3c7c2c 100644
38542 --- a/drivers/scsi/libsas/sas_ata.c
38543 +++ b/drivers/scsi/libsas/sas_ata.c
38544 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
38545 .postreset = ata_std_postreset,
38546 .error_handler = ata_std_error_handler,
38547 .post_internal_cmd = sas_ata_post_internal,
38548 - .qc_defer = ata_std_qc_defer,
38549 + .qc_defer = ata_std_qc_defer,
38550 .qc_prep = ata_noop_qc_prep,
38551 .qc_issue = sas_ata_qc_issue,
38552 .qc_fill_rtf = sas_ata_qc_fill_rtf,
38553 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
38554 index 69b5993..1ac9dce 100644
38555 --- a/drivers/scsi/lpfc/lpfc.h
38556 +++ b/drivers/scsi/lpfc/lpfc.h
38557 @@ -424,7 +424,7 @@ struct lpfc_vport {
38558 struct dentry *debug_nodelist;
38559 struct dentry *vport_debugfs_root;
38560 struct lpfc_debugfs_trc *disc_trc;
38561 - atomic_t disc_trc_cnt;
38562 + atomic_unchecked_t disc_trc_cnt;
38563 #endif
38564 uint8_t stat_data_enabled;
38565 uint8_t stat_data_blocked;
38566 @@ -840,8 +840,8 @@ struct lpfc_hba {
38567 struct timer_list fabric_block_timer;
38568 unsigned long bit_flags;
38569 #define FABRIC_COMANDS_BLOCKED 0
38570 - atomic_t num_rsrc_err;
38571 - atomic_t num_cmd_success;
38572 + atomic_unchecked_t num_rsrc_err;
38573 + atomic_unchecked_t num_cmd_success;
38574 unsigned long last_rsrc_error_time;
38575 unsigned long last_ramp_down_time;
38576 unsigned long last_ramp_up_time;
38577 @@ -877,7 +877,7 @@ struct lpfc_hba {
38578
38579 struct dentry *debug_slow_ring_trc;
38580 struct lpfc_debugfs_trc *slow_ring_trc;
38581 - atomic_t slow_ring_trc_cnt;
38582 + atomic_unchecked_t slow_ring_trc_cnt;
38583 /* iDiag debugfs sub-directory */
38584 struct dentry *idiag_root;
38585 struct dentry *idiag_pci_cfg;
38586 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
38587 index f63f5ff..de29189 100644
38588 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
38589 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
38590 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
38591
38592 #include <linux/debugfs.h>
38593
38594 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38595 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38596 static unsigned long lpfc_debugfs_start_time = 0L;
38597
38598 /* iDiag */
38599 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
38600 lpfc_debugfs_enable = 0;
38601
38602 len = 0;
38603 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
38604 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
38605 (lpfc_debugfs_max_disc_trc - 1);
38606 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
38607 dtp = vport->disc_trc + i;
38608 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
38609 lpfc_debugfs_enable = 0;
38610
38611 len = 0;
38612 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
38613 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
38614 (lpfc_debugfs_max_slow_ring_trc - 1);
38615 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
38616 dtp = phba->slow_ring_trc + i;
38617 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
38618 !vport || !vport->disc_trc)
38619 return;
38620
38621 - index = atomic_inc_return(&vport->disc_trc_cnt) &
38622 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
38623 (lpfc_debugfs_max_disc_trc - 1);
38624 dtp = vport->disc_trc + index;
38625 dtp->fmt = fmt;
38626 dtp->data1 = data1;
38627 dtp->data2 = data2;
38628 dtp->data3 = data3;
38629 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38630 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38631 dtp->jif = jiffies;
38632 #endif
38633 return;
38634 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
38635 !phba || !phba->slow_ring_trc)
38636 return;
38637
38638 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
38639 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
38640 (lpfc_debugfs_max_slow_ring_trc - 1);
38641 dtp = phba->slow_ring_trc + index;
38642 dtp->fmt = fmt;
38643 dtp->data1 = data1;
38644 dtp->data2 = data2;
38645 dtp->data3 = data3;
38646 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38647 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38648 dtp->jif = jiffies;
38649 #endif
38650 return;
38651 @@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38652 "slow_ring buffer\n");
38653 goto debug_failed;
38654 }
38655 - atomic_set(&phba->slow_ring_trc_cnt, 0);
38656 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
38657 memset(phba->slow_ring_trc, 0,
38658 (sizeof(struct lpfc_debugfs_trc) *
38659 lpfc_debugfs_max_slow_ring_trc));
38660 @@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38661 "buffer\n");
38662 goto debug_failed;
38663 }
38664 - atomic_set(&vport->disc_trc_cnt, 0);
38665 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
38666
38667 snprintf(name, sizeof(name), "discovery_trace");
38668 vport->debug_disc_trc =
38669 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
38670 index 7dc4218..3436f08 100644
38671 --- a/drivers/scsi/lpfc/lpfc_init.c
38672 +++ b/drivers/scsi/lpfc/lpfc_init.c
38673 @@ -10589,8 +10589,10 @@ lpfc_init(void)
38674 "misc_register returned with status %d", error);
38675
38676 if (lpfc_enable_npiv) {
38677 - lpfc_transport_functions.vport_create = lpfc_vport_create;
38678 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38679 + pax_open_kernel();
38680 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
38681 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38682 + pax_close_kernel();
38683 }
38684 lpfc_transport_template =
38685 fc_attach_transport(&lpfc_transport_functions);
38686 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
38687 index 7f45ac9..cf62eda 100644
38688 --- a/drivers/scsi/lpfc/lpfc_scsi.c
38689 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
38690 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
38691 uint32_t evt_posted;
38692
38693 spin_lock_irqsave(&phba->hbalock, flags);
38694 - atomic_inc(&phba->num_rsrc_err);
38695 + atomic_inc_unchecked(&phba->num_rsrc_err);
38696 phba->last_rsrc_error_time = jiffies;
38697
38698 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
38699 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
38700 unsigned long flags;
38701 struct lpfc_hba *phba = vport->phba;
38702 uint32_t evt_posted;
38703 - atomic_inc(&phba->num_cmd_success);
38704 + atomic_inc_unchecked(&phba->num_cmd_success);
38705
38706 if (vport->cfg_lun_queue_depth <= queue_depth)
38707 return;
38708 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38709 unsigned long num_rsrc_err, num_cmd_success;
38710 int i;
38711
38712 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
38713 - num_cmd_success = atomic_read(&phba->num_cmd_success);
38714 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
38715 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
38716
38717 /*
38718 * The error and success command counters are global per
38719 @@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38720 }
38721 }
38722 lpfc_destroy_vport_work_array(phba, vports);
38723 - atomic_set(&phba->num_rsrc_err, 0);
38724 - atomic_set(&phba->num_cmd_success, 0);
38725 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38726 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38727 }
38728
38729 /**
38730 @@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
38731 }
38732 }
38733 lpfc_destroy_vport_work_array(phba, vports);
38734 - atomic_set(&phba->num_rsrc_err, 0);
38735 - atomic_set(&phba->num_cmd_success, 0);
38736 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38737 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38738 }
38739
38740 /**
38741 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
38742 index af763ea..41904f7 100644
38743 --- a/drivers/scsi/pmcraid.c
38744 +++ b/drivers/scsi/pmcraid.c
38745 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
38746 res->scsi_dev = scsi_dev;
38747 scsi_dev->hostdata = res;
38748 res->change_detected = 0;
38749 - atomic_set(&res->read_failures, 0);
38750 - atomic_set(&res->write_failures, 0);
38751 + atomic_set_unchecked(&res->read_failures, 0);
38752 + atomic_set_unchecked(&res->write_failures, 0);
38753 rc = 0;
38754 }
38755 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
38756 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
38757
38758 /* If this was a SCSI read/write command keep count of errors */
38759 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
38760 - atomic_inc(&res->read_failures);
38761 + atomic_inc_unchecked(&res->read_failures);
38762 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
38763 - atomic_inc(&res->write_failures);
38764 + atomic_inc_unchecked(&res->write_failures);
38765
38766 if (!RES_IS_GSCSI(res->cfg_entry) &&
38767 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
38768 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
38769 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38770 * hrrq_id assigned here in queuecommand
38771 */
38772 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38773 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38774 pinstance->num_hrrq;
38775 cmd->cmd_done = pmcraid_io_done;
38776
38777 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
38778 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38779 * hrrq_id assigned here in queuecommand
38780 */
38781 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38782 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38783 pinstance->num_hrrq;
38784
38785 if (request_size) {
38786 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
38787
38788 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
38789 /* add resources only after host is added into system */
38790 - if (!atomic_read(&pinstance->expose_resources))
38791 + if (!atomic_read_unchecked(&pinstance->expose_resources))
38792 return;
38793
38794 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
38795 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
38796 init_waitqueue_head(&pinstance->reset_wait_q);
38797
38798 atomic_set(&pinstance->outstanding_cmds, 0);
38799 - atomic_set(&pinstance->last_message_id, 0);
38800 - atomic_set(&pinstance->expose_resources, 0);
38801 + atomic_set_unchecked(&pinstance->last_message_id, 0);
38802 + atomic_set_unchecked(&pinstance->expose_resources, 0);
38803
38804 INIT_LIST_HEAD(&pinstance->free_res_q);
38805 INIT_LIST_HEAD(&pinstance->used_res_q);
38806 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
38807 /* Schedule worker thread to handle CCN and take care of adding and
38808 * removing devices to OS
38809 */
38810 - atomic_set(&pinstance->expose_resources, 1);
38811 + atomic_set_unchecked(&pinstance->expose_resources, 1);
38812 schedule_work(&pinstance->worker_q);
38813 return rc;
38814
38815 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
38816 index e1d150f..6c6df44 100644
38817 --- a/drivers/scsi/pmcraid.h
38818 +++ b/drivers/scsi/pmcraid.h
38819 @@ -748,7 +748,7 @@ struct pmcraid_instance {
38820 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
38821
38822 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
38823 - atomic_t last_message_id;
38824 + atomic_unchecked_t last_message_id;
38825
38826 /* configuration table */
38827 struct pmcraid_config_table *cfg_table;
38828 @@ -777,7 +777,7 @@ struct pmcraid_instance {
38829 atomic_t outstanding_cmds;
38830
38831 /* should add/delete resources to mid-layer now ?*/
38832 - atomic_t expose_resources;
38833 + atomic_unchecked_t expose_resources;
38834
38835
38836
38837 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
38838 struct pmcraid_config_table_entry_ext cfg_entry_ext;
38839 };
38840 struct scsi_device *scsi_dev; /* Link scsi_device structure */
38841 - atomic_t read_failures; /* count of failed READ commands */
38842 - atomic_t write_failures; /* count of failed WRITE commands */
38843 + atomic_unchecked_t read_failures; /* count of failed READ commands */
38844 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
38845
38846 /* To indicate add/delete/modify during CCN */
38847 u8 change_detected;
38848 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
38849 index 83d7984..a27d947 100644
38850 --- a/drivers/scsi/qla2xxx/qla_attr.c
38851 +++ b/drivers/scsi/qla2xxx/qla_attr.c
38852 @@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
38853 return 0;
38854 }
38855
38856 -struct fc_function_template qla2xxx_transport_functions = {
38857 +fc_function_template_no_const qla2xxx_transport_functions = {
38858
38859 .show_host_node_name = 1,
38860 .show_host_port_name = 1,
38861 @@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
38862 .bsg_timeout = qla24xx_bsg_timeout,
38863 };
38864
38865 -struct fc_function_template qla2xxx_transport_vport_functions = {
38866 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
38867
38868 .show_host_node_name = 1,
38869 .show_host_port_name = 1,
38870 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
38871 index 6acb397..d86e3e0 100644
38872 --- a/drivers/scsi/qla2xxx/qla_gbl.h
38873 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
38874 @@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
38875 struct device_attribute;
38876 extern struct device_attribute *qla2x00_host_attrs[];
38877 struct fc_function_template;
38878 -extern struct fc_function_template qla2xxx_transport_functions;
38879 -extern struct fc_function_template qla2xxx_transport_vport_functions;
38880 +extern fc_function_template_no_const qla2xxx_transport_functions;
38881 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
38882 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
38883 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
38884 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
38885 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
38886 index f4b1fc8..a1ce4dd 100644
38887 --- a/drivers/scsi/qla2xxx/qla_os.c
38888 +++ b/drivers/scsi/qla2xxx/qla_os.c
38889 @@ -1462,8 +1462,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
38890 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
38891 /* Ok, a 64bit DMA mask is applicable. */
38892 ha->flags.enable_64bit_addressing = 1;
38893 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38894 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38895 + pax_open_kernel();
38896 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38897 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38898 + pax_close_kernel();
38899 return;
38900 }
38901 }
38902 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
38903 index 329d553..f20d31d 100644
38904 --- a/drivers/scsi/qla4xxx/ql4_def.h
38905 +++ b/drivers/scsi/qla4xxx/ql4_def.h
38906 @@ -273,7 +273,7 @@ struct ddb_entry {
38907 * (4000 only) */
38908 atomic_t relogin_timer; /* Max Time to wait for
38909 * relogin to complete */
38910 - atomic_t relogin_retry_count; /* Num of times relogin has been
38911 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
38912 * retried */
38913 uint32_t default_time2wait; /* Default Min time between
38914 * relogins (+aens) */
38915 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
38916 index fbc546e..c7d1b48 100644
38917 --- a/drivers/scsi/qla4xxx/ql4_os.c
38918 +++ b/drivers/scsi/qla4xxx/ql4_os.c
38919 @@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
38920 */
38921 if (!iscsi_is_session_online(cls_sess)) {
38922 /* Reset retry relogin timer */
38923 - atomic_inc(&ddb_entry->relogin_retry_count);
38924 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
38925 DEBUG2(ql4_printk(KERN_INFO, ha,
38926 "%s: index[%d] relogin timed out-retrying"
38927 " relogin (%d), retry (%d)\n", __func__,
38928 ddb_entry->fw_ddb_index,
38929 - atomic_read(&ddb_entry->relogin_retry_count),
38930 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
38931 ddb_entry->default_time2wait + 4));
38932 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
38933 atomic_set(&ddb_entry->retry_relogin_timer,
38934 @@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
38935
38936 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
38937 atomic_set(&ddb_entry->relogin_timer, 0);
38938 - atomic_set(&ddb_entry->relogin_retry_count, 0);
38939 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38940 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
38941 ddb_entry->default_relogin_timeout =
38942 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
38943 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
38944 index 2c0d0ec..4e8681a 100644
38945 --- a/drivers/scsi/scsi.c
38946 +++ b/drivers/scsi/scsi.c
38947 @@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
38948 unsigned long timeout;
38949 int rtn = 0;
38950
38951 - atomic_inc(&cmd->device->iorequest_cnt);
38952 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38953
38954 /* check if the device is still usable */
38955 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
38956 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
38957 index 9032e91..7a805d0 100644
38958 --- a/drivers/scsi/scsi_lib.c
38959 +++ b/drivers/scsi/scsi_lib.c
38960 @@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
38961 shost = sdev->host;
38962 scsi_init_cmd_errh(cmd);
38963 cmd->result = DID_NO_CONNECT << 16;
38964 - atomic_inc(&cmd->device->iorequest_cnt);
38965 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38966
38967 /*
38968 * SCSI request completion path will do scsi_device_unbusy(),
38969 @@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
38970
38971 INIT_LIST_HEAD(&cmd->eh_entry);
38972
38973 - atomic_inc(&cmd->device->iodone_cnt);
38974 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
38975 if (cmd->result)
38976 - atomic_inc(&cmd->device->ioerr_cnt);
38977 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
38978
38979 disposition = scsi_decide_disposition(cmd);
38980 if (disposition != SUCCESS &&
38981 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
38982 index 931a7d9..0c2a754 100644
38983 --- a/drivers/scsi/scsi_sysfs.c
38984 +++ b/drivers/scsi/scsi_sysfs.c
38985 @@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
38986 char *buf) \
38987 { \
38988 struct scsi_device *sdev = to_scsi_device(dev); \
38989 - unsigned long long count = atomic_read(&sdev->field); \
38990 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
38991 return snprintf(buf, 20, "0x%llx\n", count); \
38992 } \
38993 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
38994 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
38995 index 84a1fdf..693b0d6 100644
38996 --- a/drivers/scsi/scsi_tgt_lib.c
38997 +++ b/drivers/scsi/scsi_tgt_lib.c
38998 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
38999 int err;
39000
39001 dprintk("%lx %u\n", uaddr, len);
39002 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
39003 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
39004 if (err) {
39005 /*
39006 * TODO: need to fixup sg_tablesize, max_segment_size,
39007 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
39008 index e894ca7..de9d7660 100644
39009 --- a/drivers/scsi/scsi_transport_fc.c
39010 +++ b/drivers/scsi/scsi_transport_fc.c
39011 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
39012 * Netlink Infrastructure
39013 */
39014
39015 -static atomic_t fc_event_seq;
39016 +static atomic_unchecked_t fc_event_seq;
39017
39018 /**
39019 * fc_get_event_number - Obtain the next sequential FC event number
39020 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
39021 u32
39022 fc_get_event_number(void)
39023 {
39024 - return atomic_add_return(1, &fc_event_seq);
39025 + return atomic_add_return_unchecked(1, &fc_event_seq);
39026 }
39027 EXPORT_SYMBOL(fc_get_event_number);
39028
39029 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
39030 {
39031 int error;
39032
39033 - atomic_set(&fc_event_seq, 0);
39034 + atomic_set_unchecked(&fc_event_seq, 0);
39035
39036 error = transport_class_register(&fc_host_class);
39037 if (error)
39038 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
39039 char *cp;
39040
39041 *val = simple_strtoul(buf, &cp, 0);
39042 - if ((*cp && (*cp != '\n')) || (*val < 0))
39043 + if (*cp && (*cp != '\n'))
39044 return -EINVAL;
39045 /*
39046 * Check for overflow; dev_loss_tmo is u32
39047 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
39048 index 31969f2..2b348f0 100644
39049 --- a/drivers/scsi/scsi_transport_iscsi.c
39050 +++ b/drivers/scsi/scsi_transport_iscsi.c
39051 @@ -79,7 +79,7 @@ struct iscsi_internal {
39052 struct transport_container session_cont;
39053 };
39054
39055 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
39056 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
39057 static struct workqueue_struct *iscsi_eh_timer_workq;
39058
39059 static DEFINE_IDA(iscsi_sess_ida);
39060 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
39061 int err;
39062
39063 ihost = shost->shost_data;
39064 - session->sid = atomic_add_return(1, &iscsi_session_nr);
39065 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
39066
39067 if (target_id == ISCSI_MAX_TARGET) {
39068 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
39069 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
39070 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
39071 ISCSI_TRANSPORT_VERSION);
39072
39073 - atomic_set(&iscsi_session_nr, 0);
39074 + atomic_set_unchecked(&iscsi_session_nr, 0);
39075
39076 err = class_register(&iscsi_transport_class);
39077 if (err)
39078 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
39079 index 21a045e..ec89e03 100644
39080 --- a/drivers/scsi/scsi_transport_srp.c
39081 +++ b/drivers/scsi/scsi_transport_srp.c
39082 @@ -33,7 +33,7 @@
39083 #include "scsi_transport_srp_internal.h"
39084
39085 struct srp_host_attrs {
39086 - atomic_t next_port_id;
39087 + atomic_unchecked_t next_port_id;
39088 };
39089 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
39090
39091 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
39092 struct Scsi_Host *shost = dev_to_shost(dev);
39093 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
39094
39095 - atomic_set(&srp_host->next_port_id, 0);
39096 + atomic_set_unchecked(&srp_host->next_port_id, 0);
39097 return 0;
39098 }
39099
39100 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
39101 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
39102 rport->roles = ids->roles;
39103
39104 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
39105 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
39106 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
39107
39108 transport_setup_device(&rport->dev);
39109 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
39110 index a45e12a..d9120cb 100644
39111 --- a/drivers/scsi/sd.c
39112 +++ b/drivers/scsi/sd.c
39113 @@ -2899,7 +2899,7 @@ static int sd_probe(struct device *dev)
39114 sdkp->disk = gd;
39115 sdkp->index = index;
39116 atomic_set(&sdkp->openers, 0);
39117 - atomic_set(&sdkp->device->ioerr_cnt, 0);
39118 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
39119
39120 if (!sdp->request_queue->rq_timeout) {
39121 if (sdp->type != TYPE_MOD)
39122 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
39123 index be2c9a6..275525c 100644
39124 --- a/drivers/scsi/sg.c
39125 +++ b/drivers/scsi/sg.c
39126 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
39127 sdp->disk->disk_name,
39128 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
39129 NULL,
39130 - (char *)arg);
39131 + (char __user *)arg);
39132 case BLKTRACESTART:
39133 return blk_trace_startstop(sdp->device->request_queue, 1);
39134 case BLKTRACESTOP:
39135 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
39136 index 84c2861..ece0a31 100644
39137 --- a/drivers/spi/spi.c
39138 +++ b/drivers/spi/spi.c
39139 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
39140 EXPORT_SYMBOL_GPL(spi_bus_unlock);
39141
39142 /* portable code must never pass more than 32 bytes */
39143 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
39144 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
39145
39146 static u8 *buf;
39147
39148 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
39149 index 34afc16..ffe44dd 100644
39150 --- a/drivers/staging/octeon/ethernet-rx.c
39151 +++ b/drivers/staging/octeon/ethernet-rx.c
39152 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39153 /* Increment RX stats for virtual ports */
39154 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
39155 #ifdef CONFIG_64BIT
39156 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
39157 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
39158 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
39159 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
39160 #else
39161 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
39162 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
39163 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
39164 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
39165 #endif
39166 }
39167 netif_receive_skb(skb);
39168 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39169 dev->name);
39170 */
39171 #ifdef CONFIG_64BIT
39172 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
39173 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39174 #else
39175 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
39176 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
39177 #endif
39178 dev_kfree_skb_irq(skb);
39179 }
39180 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
39181 index 683bedc..86dba9a 100644
39182 --- a/drivers/staging/octeon/ethernet.c
39183 +++ b/drivers/staging/octeon/ethernet.c
39184 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
39185 * since the RX tasklet also increments it.
39186 */
39187 #ifdef CONFIG_64BIT
39188 - atomic64_add(rx_status.dropped_packets,
39189 - (atomic64_t *)&priv->stats.rx_dropped);
39190 + atomic64_add_unchecked(rx_status.dropped_packets,
39191 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39192 #else
39193 - atomic_add(rx_status.dropped_packets,
39194 - (atomic_t *)&priv->stats.rx_dropped);
39195 + atomic_add_unchecked(rx_status.dropped_packets,
39196 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
39197 #endif
39198 }
39199
39200 diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
39201 index a2b7e03..aaf3630 100644
39202 --- a/drivers/staging/ramster/tmem.c
39203 +++ b/drivers/staging/ramster/tmem.c
39204 @@ -50,25 +50,25 @@
39205 * A tmem host implementation must use this function to register callbacks
39206 * for memory allocation.
39207 */
39208 -static struct tmem_hostops tmem_hostops;
39209 +static struct tmem_hostops *tmem_hostops;
39210
39211 static void tmem_objnode_tree_init(void);
39212
39213 void tmem_register_hostops(struct tmem_hostops *m)
39214 {
39215 tmem_objnode_tree_init();
39216 - tmem_hostops = *m;
39217 + tmem_hostops = m;
39218 }
39219
39220 /*
39221 * A tmem host implementation must use this function to register
39222 * callbacks for a page-accessible memory (PAM) implementation.
39223 */
39224 -static struct tmem_pamops tmem_pamops;
39225 +static struct tmem_pamops *tmem_pamops;
39226
39227 void tmem_register_pamops(struct tmem_pamops *m)
39228 {
39229 - tmem_pamops = *m;
39230 + tmem_pamops = m;
39231 }
39232
39233 /*
39234 @@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
39235 obj->pampd_count = 0;
39236 #ifdef CONFIG_RAMSTER
39237 if (tmem_pamops.new_obj != NULL)
39238 - (*tmem_pamops.new_obj)(obj);
39239 + (tmem_pamops->new_obj)(obj);
39240 #endif
39241 SET_SENTINEL(obj, OBJ);
39242
39243 @@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
39244 rbnode = rb_next(rbnode);
39245 tmem_pampd_destroy_all_in_obj(obj, true);
39246 tmem_obj_free(obj, hb);
39247 - (*tmem_hostops.obj_free)(obj, pool);
39248 + (tmem_hostops->obj_free)(obj, pool);
39249 }
39250 spin_unlock(&hb->lock);
39251 }
39252 @@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
39253 ASSERT_SENTINEL(obj, OBJ);
39254 BUG_ON(obj->pool == NULL);
39255 ASSERT_SENTINEL(obj->pool, POOL);
39256 - objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
39257 + objnode = (tmem_hostops->objnode_alloc)(obj->pool);
39258 if (unlikely(objnode == NULL))
39259 goto out;
39260 objnode->obj = obj;
39261 @@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
39262 ASSERT_SENTINEL(pool, POOL);
39263 objnode->obj->objnode_count--;
39264 objnode->obj = NULL;
39265 - (*tmem_hostops.objnode_free)(objnode, pool);
39266 + (tmem_hostops->objnode_free)(objnode, pool);
39267 }
39268
39269 /*
39270 @@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
39271 void *old_pampd = *(void **)slot;
39272 *(void **)slot = new_pampd;
39273 if (!no_free)
39274 - (*tmem_pamops.free)(old_pampd, obj->pool,
39275 + (tmem_pamops->free)(old_pampd, obj->pool,
39276 NULL, 0, false);
39277 ret = new_pampd;
39278 }
39279 @@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
39280 if (objnode->slots[i]) {
39281 if (ht == 1) {
39282 obj->pampd_count--;
39283 - (*tmem_pamops.free)(objnode->slots[i],
39284 + (tmem_pamops->free)(objnode->slots[i],
39285 obj->pool, NULL, 0, true);
39286 objnode->slots[i] = NULL;
39287 continue;
39288 @@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
39289 return;
39290 if (obj->objnode_tree_height == 0) {
39291 obj->pampd_count--;
39292 - (*tmem_pamops.free)(obj->objnode_tree_root,
39293 + (tmem_pamops->free)(obj->objnode_tree_root,
39294 obj->pool, NULL, 0, true);
39295 } else {
39296 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
39297 @@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
39298 obj->objnode_tree_root = NULL;
39299 #ifdef CONFIG_RAMSTER
39300 if (tmem_pamops.free_obj != NULL)
39301 - (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
39302 + (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
39303 #endif
39304 }
39305
39306 @@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39307 /* if found, is a dup put, flush the old one */
39308 pampd_del = tmem_pampd_delete_from_obj(obj, index);
39309 BUG_ON(pampd_del != pampd);
39310 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
39311 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
39312 if (obj->pampd_count == 0) {
39313 objnew = obj;
39314 objfound = NULL;
39315 @@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39316 pampd = NULL;
39317 }
39318 } else {
39319 - obj = objnew = (*tmem_hostops.obj_alloc)(pool);
39320 + obj = objnew = (tmem_hostops->obj_alloc)(pool);
39321 if (unlikely(obj == NULL)) {
39322 ret = -ENOMEM;
39323 goto out;
39324 @@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39325 if (unlikely(ret == -ENOMEM))
39326 /* may have partially built objnode tree ("stump") */
39327 goto delete_and_free;
39328 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
39329 + (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
39330 goto out;
39331
39332 delete_and_free:
39333 (void)tmem_pampd_delete_from_obj(obj, index);
39334 if (pampd)
39335 - (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
39336 + (tmem_pamops->free)(pampd, pool, NULL, 0, true);
39337 if (objnew) {
39338 tmem_obj_free(objnew, hb);
39339 - (*tmem_hostops.obj_free)(objnew, pool);
39340 + (tmem_hostops->obj_free)(objnew, pool);
39341 }
39342 out:
39343 spin_unlock(&hb->lock);
39344 @@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
39345 if (pampd != NULL) {
39346 BUG_ON(obj == NULL);
39347 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
39348 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
39349 + (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
39350 } else if (delete) {
39351 BUG_ON(obj == NULL);
39352 (void)tmem_pampd_delete_from_obj(obj, index);
39353 @@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
39354 int ret = 0;
39355
39356 if (!is_ephemeral(pool))
39357 - new_pampd = (*tmem_pamops.repatriate_preload)(
39358 + new_pampd = (tmem_pamops->repatriate_preload)(
39359 old_pampd, pool, oidp, index, &intransit);
39360 if (intransit)
39361 ret = -EAGAIN;
39362 @@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
39363 /* must release the hb->lock else repatriate can't sleep */
39364 spin_unlock(&hb->lock);
39365 if (!intransit)
39366 - ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
39367 + ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
39368 oidp, index, free, data);
39369 if (ret == -EAGAIN) {
39370 /* rare I think, but should cond_resched()??? */
39371 @@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
39372 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
39373 /* if we bug here, pamops wasn't properly set up for ramster */
39374 BUG_ON(tmem_pamops.replace_in_obj == NULL);
39375 - ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
39376 + ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
39377 out:
39378 spin_unlock(&hb->lock);
39379 return ret;
39380 @@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39381 if (free) {
39382 if (obj->pampd_count == 0) {
39383 tmem_obj_free(obj, hb);
39384 - (*tmem_hostops.obj_free)(obj, pool);
39385 + (tmem_hostops->obj_free)(obj, pool);
39386 obj = NULL;
39387 }
39388 }
39389 if (free)
39390 - ret = (*tmem_pamops.get_data_and_free)(
39391 + ret = (tmem_pamops->get_data_and_free)(
39392 data, sizep, raw, pampd, pool, oidp, index);
39393 else
39394 - ret = (*tmem_pamops.get_data)(
39395 + ret = (tmem_pamops->get_data)(
39396 data, sizep, raw, pampd, pool, oidp, index);
39397 if (ret < 0)
39398 goto out;
39399 @@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
39400 pampd = tmem_pampd_delete_from_obj(obj, index);
39401 if (pampd == NULL)
39402 goto out;
39403 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
39404 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
39405 if (obj->pampd_count == 0) {
39406 tmem_obj_free(obj, hb);
39407 - (*tmem_hostops.obj_free)(obj, pool);
39408 + (tmem_hostops->obj_free)(obj, pool);
39409 }
39410 ret = 0;
39411
39412 @@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
39413 goto out;
39414 tmem_pampd_destroy_all_in_obj(obj, false);
39415 tmem_obj_free(obj, hb);
39416 - (*tmem_hostops.obj_free)(obj, pool);
39417 + (tmem_hostops->obj_free)(obj, pool);
39418 ret = 0;
39419
39420 out:
39421 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
39422 index dc23395..cf7e9b1 100644
39423 --- a/drivers/staging/rtl8712/rtl871x_io.h
39424 +++ b/drivers/staging/rtl8712/rtl871x_io.h
39425 @@ -108,7 +108,7 @@ struct _io_ops {
39426 u8 *pmem);
39427 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
39428 u8 *pmem);
39429 -};
39430 +} __no_const;
39431
39432 struct io_req {
39433 struct list_head list;
39434 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
39435 index 180c963..1f18377 100644
39436 --- a/drivers/staging/sbe-2t3e3/netdev.c
39437 +++ b/drivers/staging/sbe-2t3e3/netdev.c
39438 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39439 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
39440
39441 if (rlen)
39442 - if (copy_to_user(data, &resp, rlen))
39443 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
39444 return -EFAULT;
39445
39446 return 0;
39447 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
39448 index c66b8b3..a4a035b 100644
39449 --- a/drivers/staging/usbip/vhci.h
39450 +++ b/drivers/staging/usbip/vhci.h
39451 @@ -83,7 +83,7 @@ struct vhci_hcd {
39452 unsigned resuming:1;
39453 unsigned long re_timeout;
39454
39455 - atomic_t seqnum;
39456 + atomic_unchecked_t seqnum;
39457
39458 /*
39459 * NOTE:
39460 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
39461 index 620d1be..1cd6711 100644
39462 --- a/drivers/staging/usbip/vhci_hcd.c
39463 +++ b/drivers/staging/usbip/vhci_hcd.c
39464 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
39465 return;
39466 }
39467
39468 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
39469 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39470 if (priv->seqnum == 0xffff)
39471 dev_info(&urb->dev->dev, "seqnum max\n");
39472
39473 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
39474 return -ENOMEM;
39475 }
39476
39477 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
39478 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39479 if (unlink->seqnum == 0xffff)
39480 pr_info("seqnum max\n");
39481
39482 @@ -924,7 +924,7 @@ static int vhci_start(struct usb_hcd *hcd)
39483 vdev->rhport = rhport;
39484 }
39485
39486 - atomic_set(&vhci->seqnum, 0);
39487 + atomic_set_unchecked(&vhci->seqnum, 0);
39488 spin_lock_init(&vhci->lock);
39489
39490 hcd->power_budget = 0; /* no limit */
39491 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
39492 index f0eaf04..5a82e06 100644
39493 --- a/drivers/staging/usbip/vhci_rx.c
39494 +++ b/drivers/staging/usbip/vhci_rx.c
39495 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
39496 if (!urb) {
39497 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
39498 pr_info("max seqnum %d\n",
39499 - atomic_read(&the_controller->seqnum));
39500 + atomic_read_unchecked(&the_controller->seqnum));
39501 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
39502 return;
39503 }
39504 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
39505 index 67b1b88..6392fe9 100644
39506 --- a/drivers/staging/vt6655/hostap.c
39507 +++ b/drivers/staging/vt6655/hostap.c
39508 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
39509 *
39510 */
39511
39512 +static net_device_ops_no_const apdev_netdev_ops;
39513 +
39514 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39515 {
39516 PSDevice apdev_priv;
39517 struct net_device *dev = pDevice->dev;
39518 int ret;
39519 - const struct net_device_ops apdev_netdev_ops = {
39520 - .ndo_start_xmit = pDevice->tx_80211,
39521 - };
39522
39523 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39524
39525 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39526 *apdev_priv = *pDevice;
39527 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39528
39529 + /* only half broken now */
39530 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39531 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39532
39533 pDevice->apdev->type = ARPHRD_IEEE80211;
39534 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
39535 index 0a73d40..6fda560 100644
39536 --- a/drivers/staging/vt6656/hostap.c
39537 +++ b/drivers/staging/vt6656/hostap.c
39538 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
39539 *
39540 */
39541
39542 +static net_device_ops_no_const apdev_netdev_ops;
39543 +
39544 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39545 {
39546 PSDevice apdev_priv;
39547 struct net_device *dev = pDevice->dev;
39548 int ret;
39549 - const struct net_device_ops apdev_netdev_ops = {
39550 - .ndo_start_xmit = pDevice->tx_80211,
39551 - };
39552
39553 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39554
39555 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39556 *apdev_priv = *pDevice;
39557 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39558
39559 + /* only half broken now */
39560 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39561 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39562
39563 pDevice->apdev->type = ARPHRD_IEEE80211;
39564 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
39565 index 56c8e60..1920c63 100644
39566 --- a/drivers/staging/zcache/tmem.c
39567 +++ b/drivers/staging/zcache/tmem.c
39568 @@ -39,7 +39,7 @@
39569 * A tmem host implementation must use this function to register callbacks
39570 * for memory allocation.
39571 */
39572 -static struct tmem_hostops tmem_hostops;
39573 +static tmem_hostops_no_const tmem_hostops;
39574
39575 static void tmem_objnode_tree_init(void);
39576
39577 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
39578 * A tmem host implementation must use this function to register
39579 * callbacks for a page-accessible memory (PAM) implementation
39580 */
39581 -static struct tmem_pamops tmem_pamops;
39582 +static tmem_pamops_no_const tmem_pamops;
39583
39584 void tmem_register_pamops(struct tmem_pamops *m)
39585 {
39586 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
39587 index 0d4aa82..f7832d4 100644
39588 --- a/drivers/staging/zcache/tmem.h
39589 +++ b/drivers/staging/zcache/tmem.h
39590 @@ -180,6 +180,7 @@ struct tmem_pamops {
39591 void (*new_obj)(struct tmem_obj *);
39592 int (*replace_in_obj)(void *, struct tmem_obj *);
39593 };
39594 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
39595 extern void tmem_register_pamops(struct tmem_pamops *m);
39596
39597 /* memory allocation methods provided by the host implementation */
39598 @@ -189,6 +190,7 @@ struct tmem_hostops {
39599 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
39600 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
39601 };
39602 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
39603 extern void tmem_register_hostops(struct tmem_hostops *m);
39604
39605 /* core tmem accessor functions */
39606 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
39607 index 13fe16c..cbdc39a 100644
39608 --- a/drivers/target/target_core_transport.c
39609 +++ b/drivers/target/target_core_transport.c
39610 @@ -1085,7 +1085,7 @@ struct se_device *transport_add_device_to_core_hba(
39611 spin_lock_init(&dev->se_port_lock);
39612 spin_lock_init(&dev->se_tmr_lock);
39613 spin_lock_init(&dev->qf_cmd_lock);
39614 - atomic_set(&dev->dev_ordered_id, 0);
39615 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
39616
39617 se_dev_set_default_attribs(dev, dev_limits);
39618
39619 @@ -1275,7 +1275,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
39620 * Used to determine when ORDERED commands should go from
39621 * Dormant to Active status.
39622 */
39623 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
39624 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
39625 smp_mb__after_atomic_inc();
39626 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
39627 cmd->se_ordered_id, cmd->sam_task_attr,
39628 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
39629 index 0a6a0bc..5501b06 100644
39630 --- a/drivers/tty/cyclades.c
39631 +++ b/drivers/tty/cyclades.c
39632 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
39633 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
39634 info->port.count);
39635 #endif
39636 - info->port.count++;
39637 + atomic_inc(&info->port.count);
39638 #ifdef CY_DEBUG_COUNT
39639 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
39640 - current->pid, info->port.count);
39641 + current->pid, atomic_read(&info->port.count));
39642 #endif
39643
39644 /*
39645 @@ -3989,7 +3989,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
39646 for (j = 0; j < cy_card[i].nports; j++) {
39647 info = &cy_card[i].ports[j];
39648
39649 - if (info->port.count) {
39650 + if (atomic_read(&info->port.count)) {
39651 /* XXX is the ldisc num worth this? */
39652 struct tty_struct *tty;
39653 struct tty_ldisc *ld;
39654 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
39655 index 13ee53b..418d164 100644
39656 --- a/drivers/tty/hvc/hvc_console.c
39657 +++ b/drivers/tty/hvc/hvc_console.c
39658 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
39659
39660 spin_lock_irqsave(&hp->port.lock, flags);
39661 /* Check and then increment for fast path open. */
39662 - if (hp->port.count++ > 0) {
39663 + if (atomic_inc_return(&hp->port.count) > 1) {
39664 spin_unlock_irqrestore(&hp->port.lock, flags);
39665 hvc_kick();
39666 return 0;
39667 @@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39668
39669 spin_lock_irqsave(&hp->port.lock, flags);
39670
39671 - if (--hp->port.count == 0) {
39672 + if (atomic_dec_return(&hp->port.count) == 0) {
39673 spin_unlock_irqrestore(&hp->port.lock, flags);
39674 /* We are done with the tty pointer now. */
39675 tty_port_tty_set(&hp->port, NULL);
39676 @@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39677 */
39678 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
39679 } else {
39680 - if (hp->port.count < 0)
39681 + if (atomic_read(&hp->port.count) < 0)
39682 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
39683 - hp->vtermno, hp->port.count);
39684 + hp->vtermno, atomic_read(&hp->port.count));
39685 spin_unlock_irqrestore(&hp->port.lock, flags);
39686 }
39687 }
39688 @@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
39689 * open->hangup case this can be called after the final close so prevent
39690 * that from happening for now.
39691 */
39692 - if (hp->port.count <= 0) {
39693 + if (atomic_read(&hp->port.count) <= 0) {
39694 spin_unlock_irqrestore(&hp->port.lock, flags);
39695 return;
39696 }
39697
39698 - hp->port.count = 0;
39699 + atomic_set(&hp->port.count, 0);
39700 spin_unlock_irqrestore(&hp->port.lock, flags);
39701 tty_port_tty_set(&hp->port, NULL);
39702
39703 @@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
39704 return -EPIPE;
39705
39706 /* FIXME what's this (unprotected) check for? */
39707 - if (hp->port.count <= 0)
39708 + if (atomic_read(&hp->port.count) <= 0)
39709 return -EIO;
39710
39711 spin_lock_irqsave(&hp->lock, flags);
39712 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
39713 index cab5c7a..4cc66ea 100644
39714 --- a/drivers/tty/hvc/hvcs.c
39715 +++ b/drivers/tty/hvc/hvcs.c
39716 @@ -83,6 +83,7 @@
39717 #include <asm/hvcserver.h>
39718 #include <asm/uaccess.h>
39719 #include <asm/vio.h>
39720 +#include <asm/local.h>
39721
39722 /*
39723 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
39724 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
39725
39726 spin_lock_irqsave(&hvcsd->lock, flags);
39727
39728 - if (hvcsd->port.count > 0) {
39729 + if (atomic_read(&hvcsd->port.count) > 0) {
39730 spin_unlock_irqrestore(&hvcsd->lock, flags);
39731 printk(KERN_INFO "HVCS: vterm state unchanged. "
39732 "The hvcs device node is still in use.\n");
39733 @@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
39734 }
39735 }
39736
39737 - hvcsd->port.count = 0;
39738 + atomic_set(&hvcsd->port.count, 0);
39739 hvcsd->port.tty = tty;
39740 tty->driver_data = hvcsd;
39741
39742 @@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
39743 unsigned long flags;
39744
39745 spin_lock_irqsave(&hvcsd->lock, flags);
39746 - hvcsd->port.count++;
39747 + atomic_inc(&hvcsd->port.count);
39748 hvcsd->todo_mask |= HVCS_SCHED_READ;
39749 spin_unlock_irqrestore(&hvcsd->lock, flags);
39750
39751 @@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39752 hvcsd = tty->driver_data;
39753
39754 spin_lock_irqsave(&hvcsd->lock, flags);
39755 - if (--hvcsd->port.count == 0) {
39756 + if (atomic_dec_and_test(&hvcsd->port.count)) {
39757
39758 vio_disable_interrupts(hvcsd->vdev);
39759
39760 @@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39761
39762 free_irq(irq, hvcsd);
39763 return;
39764 - } else if (hvcsd->port.count < 0) {
39765 + } else if (atomic_read(&hvcsd->port.count) < 0) {
39766 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
39767 " is missmanaged.\n",
39768 - hvcsd->vdev->unit_address, hvcsd->port.count);
39769 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
39770 }
39771
39772 spin_unlock_irqrestore(&hvcsd->lock, flags);
39773 @@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39774
39775 spin_lock_irqsave(&hvcsd->lock, flags);
39776 /* Preserve this so that we know how many kref refs to put */
39777 - temp_open_count = hvcsd->port.count;
39778 + temp_open_count = atomic_read(&hvcsd->port.count);
39779
39780 /*
39781 * Don't kref put inside the spinlock because the destruction
39782 @@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39783 tty->driver_data = NULL;
39784 hvcsd->port.tty = NULL;
39785
39786 - hvcsd->port.count = 0;
39787 + atomic_set(&hvcsd->port.count, 0);
39788
39789 /* This will drop any buffered data on the floor which is OK in a hangup
39790 * scenario. */
39791 @@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
39792 * the middle of a write operation? This is a crummy place to do this
39793 * but we want to keep it all in the spinlock.
39794 */
39795 - if (hvcsd->port.count <= 0) {
39796 + if (atomic_read(&hvcsd->port.count) <= 0) {
39797 spin_unlock_irqrestore(&hvcsd->lock, flags);
39798 return -ENODEV;
39799 }
39800 @@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
39801 {
39802 struct hvcs_struct *hvcsd = tty->driver_data;
39803
39804 - if (!hvcsd || hvcsd->port.count <= 0)
39805 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
39806 return 0;
39807
39808 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
39809 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
39810 index 160f0ad..588b853 100644
39811 --- a/drivers/tty/ipwireless/tty.c
39812 +++ b/drivers/tty/ipwireless/tty.c
39813 @@ -29,6 +29,7 @@
39814 #include <linux/tty_driver.h>
39815 #include <linux/tty_flip.h>
39816 #include <linux/uaccess.h>
39817 +#include <asm/local.h>
39818
39819 #include "tty.h"
39820 #include "network.h"
39821 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39822 mutex_unlock(&tty->ipw_tty_mutex);
39823 return -ENODEV;
39824 }
39825 - if (tty->port.count == 0)
39826 + if (atomic_read(&tty->port.count) == 0)
39827 tty->tx_bytes_queued = 0;
39828
39829 - tty->port.count++;
39830 + atomic_inc(&tty->port.count);
39831
39832 tty->port.tty = linux_tty;
39833 linux_tty->driver_data = tty;
39834 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39835
39836 static void do_ipw_close(struct ipw_tty *tty)
39837 {
39838 - tty->port.count--;
39839 -
39840 - if (tty->port.count == 0) {
39841 + if (atomic_dec_return(&tty->port.count) == 0) {
39842 struct tty_struct *linux_tty = tty->port.tty;
39843
39844 if (linux_tty != NULL) {
39845 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
39846 return;
39847
39848 mutex_lock(&tty->ipw_tty_mutex);
39849 - if (tty->port.count == 0) {
39850 + if (atomic_read(&tty->port.count) == 0) {
39851 mutex_unlock(&tty->ipw_tty_mutex);
39852 return;
39853 }
39854 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
39855 return;
39856 }
39857
39858 - if (!tty->port.count) {
39859 + if (!atomic_read(&tty->port.count)) {
39860 mutex_unlock(&tty->ipw_tty_mutex);
39861 return;
39862 }
39863 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
39864 return -ENODEV;
39865
39866 mutex_lock(&tty->ipw_tty_mutex);
39867 - if (!tty->port.count) {
39868 + if (!atomic_read(&tty->port.count)) {
39869 mutex_unlock(&tty->ipw_tty_mutex);
39870 return -EINVAL;
39871 }
39872 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
39873 if (!tty)
39874 return -ENODEV;
39875
39876 - if (!tty->port.count)
39877 + if (!atomic_read(&tty->port.count))
39878 return -EINVAL;
39879
39880 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
39881 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
39882 if (!tty)
39883 return 0;
39884
39885 - if (!tty->port.count)
39886 + if (!atomic_read(&tty->port.count))
39887 return 0;
39888
39889 return tty->tx_bytes_queued;
39890 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
39891 if (!tty)
39892 return -ENODEV;
39893
39894 - if (!tty->port.count)
39895 + if (!atomic_read(&tty->port.count))
39896 return -EINVAL;
39897
39898 return get_control_lines(tty);
39899 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
39900 if (!tty)
39901 return -ENODEV;
39902
39903 - if (!tty->port.count)
39904 + if (!atomic_read(&tty->port.count))
39905 return -EINVAL;
39906
39907 return set_control_lines(tty, set, clear);
39908 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
39909 if (!tty)
39910 return -ENODEV;
39911
39912 - if (!tty->port.count)
39913 + if (!atomic_read(&tty->port.count))
39914 return -EINVAL;
39915
39916 /* FIXME: Exactly how is the tty object locked here .. */
39917 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
39918 * are gone */
39919 mutex_lock(&ttyj->ipw_tty_mutex);
39920 }
39921 - while (ttyj->port.count)
39922 + while (atomic_read(&ttyj->port.count))
39923 do_ipw_close(ttyj);
39924 ipwireless_disassociate_network_ttys(network,
39925 ttyj->channel_idx);
39926 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
39927 index 56e616b..9d9f10a 100644
39928 --- a/drivers/tty/moxa.c
39929 +++ b/drivers/tty/moxa.c
39930 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
39931 }
39932
39933 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
39934 - ch->port.count++;
39935 + atomic_inc(&ch->port.count);
39936 tty->driver_data = ch;
39937 tty_port_tty_set(&ch->port, tty);
39938 mutex_lock(&ch->port.mutex);
39939 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
39940 index 1e8e8ce..a9efc93 100644
39941 --- a/drivers/tty/n_gsm.c
39942 +++ b/drivers/tty/n_gsm.c
39943 @@ -1638,7 +1638,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
39944 kref_init(&dlci->ref);
39945 mutex_init(&dlci->mutex);
39946 dlci->fifo = &dlci->_fifo;
39947 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
39948 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
39949 kfree(dlci);
39950 return NULL;
39951 }
39952 @@ -2925,7 +2925,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
39953 struct gsm_dlci *dlci = tty->driver_data;
39954 struct tty_port *port = &dlci->port;
39955
39956 - port->count++;
39957 + atomic_inc(&port->count);
39958 dlci_get(dlci);
39959 dlci_get(dlci->gsm->dlci[0]);
39960 mux_get(dlci->gsm);
39961 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
39962 index 8c0b7b4..e88f052 100644
39963 --- a/drivers/tty/n_tty.c
39964 +++ b/drivers/tty/n_tty.c
39965 @@ -2142,6 +2142,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
39966 {
39967 *ops = tty_ldisc_N_TTY;
39968 ops->owner = NULL;
39969 - ops->refcount = ops->flags = 0;
39970 + atomic_set(&ops->refcount, 0);
39971 + ops->flags = 0;
39972 }
39973 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
39974 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
39975 index 8cf8d0a..4ef9ed0 100644
39976 --- a/drivers/tty/pty.c
39977 +++ b/drivers/tty/pty.c
39978 @@ -730,8 +730,10 @@ static void __init unix98_pty_init(void)
39979 panic("Couldn't register Unix98 pts driver");
39980
39981 /* Now create the /dev/ptmx special device */
39982 + pax_open_kernel();
39983 tty_default_fops(&ptmx_fops);
39984 - ptmx_fops.open = ptmx_open;
39985 + *(void **)&ptmx_fops.open = ptmx_open;
39986 + pax_close_kernel();
39987
39988 cdev_init(&ptmx_cdev, &ptmx_fops);
39989 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
39990 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
39991 index 9700d34..df7520c 100644
39992 --- a/drivers/tty/rocket.c
39993 +++ b/drivers/tty/rocket.c
39994 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
39995 tty->driver_data = info;
39996 tty_port_tty_set(port, tty);
39997
39998 - if (port->count++ == 0) {
39999 + if (atomic_inc_return(&port->count) == 1) {
40000 atomic_inc(&rp_num_ports_open);
40001
40002 #ifdef ROCKET_DEBUG_OPEN
40003 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40004 #endif
40005 }
40006 #ifdef ROCKET_DEBUG_OPEN
40007 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
40008 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
40009 #endif
40010
40011 /*
40012 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
40013 spin_unlock_irqrestore(&info->port.lock, flags);
40014 return;
40015 }
40016 - if (info->port.count)
40017 + if (atomic_read(&info->port.count))
40018 atomic_dec(&rp_num_ports_open);
40019 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
40020 spin_unlock_irqrestore(&info->port.lock, flags);
40021 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
40022 index 1002054..dd644a8 100644
40023 --- a/drivers/tty/serial/kgdboc.c
40024 +++ b/drivers/tty/serial/kgdboc.c
40025 @@ -24,8 +24,9 @@
40026 #define MAX_CONFIG_LEN 40
40027
40028 static struct kgdb_io kgdboc_io_ops;
40029 +static struct kgdb_io kgdboc_io_ops_console;
40030
40031 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
40032 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
40033 static int configured = -1;
40034
40035 static char config[MAX_CONFIG_LEN];
40036 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
40037 kgdboc_unregister_kbd();
40038 if (configured == 1)
40039 kgdb_unregister_io_module(&kgdboc_io_ops);
40040 + else if (configured == 2)
40041 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
40042 }
40043
40044 static int configure_kgdboc(void)
40045 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
40046 int err;
40047 char *cptr = config;
40048 struct console *cons;
40049 + int is_console = 0;
40050
40051 err = kgdboc_option_setup(config);
40052 if (err || !strlen(config) || isspace(config[0]))
40053 goto noconfig;
40054
40055 err = -ENODEV;
40056 - kgdboc_io_ops.is_console = 0;
40057 kgdb_tty_driver = NULL;
40058
40059 kgdboc_use_kms = 0;
40060 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
40061 int idx;
40062 if (cons->device && cons->device(cons, &idx) == p &&
40063 idx == tty_line) {
40064 - kgdboc_io_ops.is_console = 1;
40065 + is_console = 1;
40066 break;
40067 }
40068 cons = cons->next;
40069 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
40070 kgdb_tty_line = tty_line;
40071
40072 do_register:
40073 - err = kgdb_register_io_module(&kgdboc_io_ops);
40074 + if (is_console) {
40075 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
40076 + configured = 2;
40077 + } else {
40078 + err = kgdb_register_io_module(&kgdboc_io_ops);
40079 + configured = 1;
40080 + }
40081 if (err)
40082 goto noconfig;
40083
40084 @@ -205,8 +214,6 @@ do_register:
40085 if (err)
40086 goto nmi_con_failed;
40087
40088 - configured = 1;
40089 -
40090 return 0;
40091
40092 nmi_con_failed:
40093 @@ -223,7 +230,7 @@ noconfig:
40094 static int __init init_kgdboc(void)
40095 {
40096 /* Already configured? */
40097 - if (configured == 1)
40098 + if (configured >= 1)
40099 return 0;
40100
40101 return configure_kgdboc();
40102 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
40103 if (config[len - 1] == '\n')
40104 config[len - 1] = '\0';
40105
40106 - if (configured == 1)
40107 + if (configured >= 1)
40108 cleanup_kgdboc();
40109
40110 /* Go and configure with the new params. */
40111 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
40112 .post_exception = kgdboc_post_exp_handler,
40113 };
40114
40115 +static struct kgdb_io kgdboc_io_ops_console = {
40116 + .name = "kgdboc",
40117 + .read_char = kgdboc_get_char,
40118 + .write_char = kgdboc_put_char,
40119 + .pre_exception = kgdboc_pre_exp_handler,
40120 + .post_exception = kgdboc_post_exp_handler,
40121 + .is_console = 1
40122 +};
40123 +
40124 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
40125 /* This is only available if kgdboc is a built in for early debugging */
40126 static int __init kgdboc_early_init(char *opt)
40127 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
40128 index 7f04717..0f3794f 100644
40129 --- a/drivers/tty/serial/samsung.c
40130 +++ b/drivers/tty/serial/samsung.c
40131 @@ -445,11 +445,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
40132 }
40133 }
40134
40135 +static int s3c64xx_serial_startup(struct uart_port *port);
40136 static int s3c24xx_serial_startup(struct uart_port *port)
40137 {
40138 struct s3c24xx_uart_port *ourport = to_ourport(port);
40139 int ret;
40140
40141 + /* Startup sequence is different for s3c64xx and higher SoC's */
40142 + if (s3c24xx_serial_has_interrupt_mask(port))
40143 + return s3c64xx_serial_startup(port);
40144 +
40145 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
40146 port->mapbase, port->membase);
40147
40148 @@ -1115,10 +1120,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
40149 /* setup info for port */
40150 port->dev = &platdev->dev;
40151
40152 - /* Startup sequence is different for s3c64xx and higher SoC's */
40153 - if (s3c24xx_serial_has_interrupt_mask(port))
40154 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
40155 -
40156 port->uartclk = 1;
40157
40158 if (cfg->uart_flags & UPF_CONS_FLOW) {
40159 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
40160 index 0fcfd98..8244fce 100644
40161 --- a/drivers/tty/serial/serial_core.c
40162 +++ b/drivers/tty/serial/serial_core.c
40163 @@ -1408,7 +1408,7 @@ static void uart_hangup(struct tty_struct *tty)
40164 uart_flush_buffer(tty);
40165 uart_shutdown(tty, state);
40166 spin_lock_irqsave(&port->lock, flags);
40167 - port->count = 0;
40168 + atomic_set(&port->count, 0);
40169 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
40170 spin_unlock_irqrestore(&port->lock, flags);
40171 tty_port_tty_set(port, NULL);
40172 @@ -1504,7 +1504,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40173 goto end;
40174 }
40175
40176 - port->count++;
40177 + atomic_inc(&port->count);
40178 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
40179 retval = -ENXIO;
40180 goto err_dec_count;
40181 @@ -1531,7 +1531,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40182 /*
40183 * Make sure the device is in D0 state.
40184 */
40185 - if (port->count == 1)
40186 + if (atomic_read(&port->count) == 1)
40187 uart_change_pm(state, 0);
40188
40189 /*
40190 @@ -1549,7 +1549,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40191 end:
40192 return retval;
40193 err_dec_count:
40194 - port->count--;
40195 + atomic_inc(&port->count);
40196 mutex_unlock(&port->mutex);
40197 goto end;
40198 }
40199 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
40200 index 70e3a52..5742052 100644
40201 --- a/drivers/tty/synclink.c
40202 +++ b/drivers/tty/synclink.c
40203 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40204
40205 if (debug_level >= DEBUG_LEVEL_INFO)
40206 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
40207 - __FILE__,__LINE__, info->device_name, info->port.count);
40208 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40209
40210 if (tty_port_close_start(&info->port, tty, filp) == 0)
40211 goto cleanup;
40212 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40213 cleanup:
40214 if (debug_level >= DEBUG_LEVEL_INFO)
40215 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
40216 - tty->driver->name, info->port.count);
40217 + tty->driver->name, atomic_read(&info->port.count));
40218
40219 } /* end of mgsl_close() */
40220
40221 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
40222
40223 mgsl_flush_buffer(tty);
40224 shutdown(info);
40225 -
40226 - info->port.count = 0;
40227 +
40228 + atomic_set(&info->port.count, 0);
40229 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40230 info->port.tty = NULL;
40231
40232 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40233
40234 if (debug_level >= DEBUG_LEVEL_INFO)
40235 printk("%s(%d):block_til_ready before block on %s count=%d\n",
40236 - __FILE__,__LINE__, tty->driver->name, port->count );
40237 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40238
40239 spin_lock_irqsave(&info->irq_spinlock, flags);
40240 if (!tty_hung_up_p(filp)) {
40241 extra_count = true;
40242 - port->count--;
40243 + atomic_dec(&port->count);
40244 }
40245 spin_unlock_irqrestore(&info->irq_spinlock, flags);
40246 port->blocked_open++;
40247 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40248
40249 if (debug_level >= DEBUG_LEVEL_INFO)
40250 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
40251 - __FILE__,__LINE__, tty->driver->name, port->count );
40252 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40253
40254 tty_unlock(tty);
40255 schedule();
40256 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40257
40258 /* FIXME: Racy on hangup during close wait */
40259 if (extra_count)
40260 - port->count++;
40261 + atomic_inc(&port->count);
40262 port->blocked_open--;
40263
40264 if (debug_level >= DEBUG_LEVEL_INFO)
40265 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
40266 - __FILE__,__LINE__, tty->driver->name, port->count );
40267 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40268
40269 if (!retval)
40270 port->flags |= ASYNC_NORMAL_ACTIVE;
40271 @@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
40272
40273 if (debug_level >= DEBUG_LEVEL_INFO)
40274 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
40275 - __FILE__,__LINE__,tty->driver->name, info->port.count);
40276 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
40277
40278 /* If port is closing, signal caller to try again */
40279 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40280 @@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
40281 spin_unlock_irqrestore(&info->netlock, flags);
40282 goto cleanup;
40283 }
40284 - info->port.count++;
40285 + atomic_inc(&info->port.count);
40286 spin_unlock_irqrestore(&info->netlock, flags);
40287
40288 - if (info->port.count == 1) {
40289 + if (atomic_read(&info->port.count) == 1) {
40290 /* 1st open on this device, init hardware */
40291 retval = startup(info);
40292 if (retval < 0)
40293 @@ -3451,8 +3451,8 @@ cleanup:
40294 if (retval) {
40295 if (tty->count == 1)
40296 info->port.tty = NULL; /* tty layer will release tty struct */
40297 - if(info->port.count)
40298 - info->port.count--;
40299 + if (atomic_read(&info->port.count))
40300 + atomic_dec(&info->port.count);
40301 }
40302
40303 return retval;
40304 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40305 unsigned short new_crctype;
40306
40307 /* return error if TTY interface open */
40308 - if (info->port.count)
40309 + if (atomic_read(&info->port.count))
40310 return -EBUSY;
40311
40312 switch (encoding)
40313 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
40314
40315 /* arbitrate between network and tty opens */
40316 spin_lock_irqsave(&info->netlock, flags);
40317 - if (info->port.count != 0 || info->netcount != 0) {
40318 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40319 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40320 spin_unlock_irqrestore(&info->netlock, flags);
40321 return -EBUSY;
40322 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40323 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
40324
40325 /* return error if TTY interface open */
40326 - if (info->port.count)
40327 + if (atomic_read(&info->port.count))
40328 return -EBUSY;
40329
40330 if (cmd != SIOCWANDEV)
40331 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
40332 index b38e954..ce45b38 100644
40333 --- a/drivers/tty/synclink_gt.c
40334 +++ b/drivers/tty/synclink_gt.c
40335 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
40336 tty->driver_data = info;
40337 info->port.tty = tty;
40338
40339 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
40340 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
40341
40342 /* If port is closing, signal caller to try again */
40343 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40344 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
40345 mutex_unlock(&info->port.mutex);
40346 goto cleanup;
40347 }
40348 - info->port.count++;
40349 + atomic_inc(&info->port.count);
40350 spin_unlock_irqrestore(&info->netlock, flags);
40351
40352 - if (info->port.count == 1) {
40353 + if (atomic_read(&info->port.count) == 1) {
40354 /* 1st open on this device, init hardware */
40355 retval = startup(info);
40356 if (retval < 0) {
40357 @@ -716,8 +716,8 @@ cleanup:
40358 if (retval) {
40359 if (tty->count == 1)
40360 info->port.tty = NULL; /* tty layer will release tty struct */
40361 - if(info->port.count)
40362 - info->port.count--;
40363 + if(atomic_read(&info->port.count))
40364 + atomic_dec(&info->port.count);
40365 }
40366
40367 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
40368 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40369
40370 if (sanity_check(info, tty->name, "close"))
40371 return;
40372 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
40373 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
40374
40375 if (tty_port_close_start(&info->port, tty, filp) == 0)
40376 goto cleanup;
40377 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40378 tty_port_close_end(&info->port, tty);
40379 info->port.tty = NULL;
40380 cleanup:
40381 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
40382 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
40383 }
40384
40385 static void hangup(struct tty_struct *tty)
40386 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
40387 shutdown(info);
40388
40389 spin_lock_irqsave(&info->port.lock, flags);
40390 - info->port.count = 0;
40391 + atomic_set(&info->port.count, 0);
40392 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40393 info->port.tty = NULL;
40394 spin_unlock_irqrestore(&info->port.lock, flags);
40395 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40396 unsigned short new_crctype;
40397
40398 /* return error if TTY interface open */
40399 - if (info->port.count)
40400 + if (atomic_read(&info->port.count))
40401 return -EBUSY;
40402
40403 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
40404 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
40405
40406 /* arbitrate between network and tty opens */
40407 spin_lock_irqsave(&info->netlock, flags);
40408 - if (info->port.count != 0 || info->netcount != 0) {
40409 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40410 DBGINFO(("%s hdlc_open busy\n", dev->name));
40411 spin_unlock_irqrestore(&info->netlock, flags);
40412 return -EBUSY;
40413 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40414 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
40415
40416 /* return error if TTY interface open */
40417 - if (info->port.count)
40418 + if (atomic_read(&info->port.count))
40419 return -EBUSY;
40420
40421 if (cmd != SIOCWANDEV)
40422 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
40423 if (port == NULL)
40424 continue;
40425 spin_lock(&port->lock);
40426 - if ((port->port.count || port->netcount) &&
40427 + if ((atomic_read(&port->port.count) || port->netcount) &&
40428 port->pending_bh && !port->bh_running &&
40429 !port->bh_requested) {
40430 DBGISR(("%s bh queued\n", port->device_name));
40431 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40432 spin_lock_irqsave(&info->lock, flags);
40433 if (!tty_hung_up_p(filp)) {
40434 extra_count = true;
40435 - port->count--;
40436 + atomic_dec(&port->count);
40437 }
40438 spin_unlock_irqrestore(&info->lock, flags);
40439 port->blocked_open++;
40440 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40441 remove_wait_queue(&port->open_wait, &wait);
40442
40443 if (extra_count)
40444 - port->count++;
40445 + atomic_inc(&port->count);
40446 port->blocked_open--;
40447
40448 if (!retval)
40449 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
40450 index f17d9f3..27a041b 100644
40451 --- a/drivers/tty/synclinkmp.c
40452 +++ b/drivers/tty/synclinkmp.c
40453 @@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
40454
40455 if (debug_level >= DEBUG_LEVEL_INFO)
40456 printk("%s(%d):%s open(), old ref count = %d\n",
40457 - __FILE__,__LINE__,tty->driver->name, info->port.count);
40458 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
40459
40460 /* If port is closing, signal caller to try again */
40461 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40462 @@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
40463 spin_unlock_irqrestore(&info->netlock, flags);
40464 goto cleanup;
40465 }
40466 - info->port.count++;
40467 + atomic_inc(&info->port.count);
40468 spin_unlock_irqrestore(&info->netlock, flags);
40469
40470 - if (info->port.count == 1) {
40471 + if (atomic_read(&info->port.count) == 1) {
40472 /* 1st open on this device, init hardware */
40473 retval = startup(info);
40474 if (retval < 0)
40475 @@ -797,8 +797,8 @@ cleanup:
40476 if (retval) {
40477 if (tty->count == 1)
40478 info->port.tty = NULL; /* tty layer will release tty struct */
40479 - if(info->port.count)
40480 - info->port.count--;
40481 + if(atomic_read(&info->port.count))
40482 + atomic_dec(&info->port.count);
40483 }
40484
40485 return retval;
40486 @@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40487
40488 if (debug_level >= DEBUG_LEVEL_INFO)
40489 printk("%s(%d):%s close() entry, count=%d\n",
40490 - __FILE__,__LINE__, info->device_name, info->port.count);
40491 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40492
40493 if (tty_port_close_start(&info->port, tty, filp) == 0)
40494 goto cleanup;
40495 @@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40496 cleanup:
40497 if (debug_level >= DEBUG_LEVEL_INFO)
40498 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
40499 - tty->driver->name, info->port.count);
40500 + tty->driver->name, atomic_read(&info->port.count));
40501 }
40502
40503 /* Called by tty_hangup() when a hangup is signaled.
40504 @@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
40505 shutdown(info);
40506
40507 spin_lock_irqsave(&info->port.lock, flags);
40508 - info->port.count = 0;
40509 + atomic_set(&info->port.count, 0);
40510 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40511 info->port.tty = NULL;
40512 spin_unlock_irqrestore(&info->port.lock, flags);
40513 @@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40514 unsigned short new_crctype;
40515
40516 /* return error if TTY interface open */
40517 - if (info->port.count)
40518 + if (atomic_read(&info->port.count))
40519 return -EBUSY;
40520
40521 switch (encoding)
40522 @@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
40523
40524 /* arbitrate between network and tty opens */
40525 spin_lock_irqsave(&info->netlock, flags);
40526 - if (info->port.count != 0 || info->netcount != 0) {
40527 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40528 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40529 spin_unlock_irqrestore(&info->netlock, flags);
40530 return -EBUSY;
40531 @@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40532 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
40533
40534 /* return error if TTY interface open */
40535 - if (info->port.count)
40536 + if (atomic_read(&info->port.count))
40537 return -EBUSY;
40538
40539 if (cmd != SIOCWANDEV)
40540 @@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
40541 * do not request bottom half processing if the
40542 * device is not open in a normal mode.
40543 */
40544 - if ( port && (port->port.count || port->netcount) &&
40545 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
40546 port->pending_bh && !port->bh_running &&
40547 !port->bh_requested ) {
40548 if ( debug_level >= DEBUG_LEVEL_ISR )
40549 @@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40550
40551 if (debug_level >= DEBUG_LEVEL_INFO)
40552 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
40553 - __FILE__,__LINE__, tty->driver->name, port->count );
40554 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40555
40556 spin_lock_irqsave(&info->lock, flags);
40557 if (!tty_hung_up_p(filp)) {
40558 extra_count = true;
40559 - port->count--;
40560 + atomic_dec(&port->count);
40561 }
40562 spin_unlock_irqrestore(&info->lock, flags);
40563 port->blocked_open++;
40564 @@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40565
40566 if (debug_level >= DEBUG_LEVEL_INFO)
40567 printk("%s(%d):%s block_til_ready() count=%d\n",
40568 - __FILE__,__LINE__, tty->driver->name, port->count );
40569 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40570
40571 tty_unlock(tty);
40572 schedule();
40573 @@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40574 remove_wait_queue(&port->open_wait, &wait);
40575
40576 if (extra_count)
40577 - port->count++;
40578 + atomic_inc(&port->count);
40579 port->blocked_open--;
40580
40581 if (debug_level >= DEBUG_LEVEL_INFO)
40582 printk("%s(%d):%s block_til_ready() after, count=%d\n",
40583 - __FILE__,__LINE__, tty->driver->name, port->count );
40584 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40585
40586 if (!retval)
40587 port->flags |= ASYNC_NORMAL_ACTIVE;
40588 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
40589 index 16ee6ce..bfcac57 100644
40590 --- a/drivers/tty/sysrq.c
40591 +++ b/drivers/tty/sysrq.c
40592 @@ -866,7 +866,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
40593 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
40594 size_t count, loff_t *ppos)
40595 {
40596 - if (count) {
40597 + if (count && capable(CAP_SYS_ADMIN)) {
40598 char c;
40599
40600 if (get_user(c, buf))
40601 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
40602 index 2ea176b..2877bc8 100644
40603 --- a/drivers/tty/tty_io.c
40604 +++ b/drivers/tty/tty_io.c
40605 @@ -3395,7 +3395,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
40606
40607 void tty_default_fops(struct file_operations *fops)
40608 {
40609 - *fops = tty_fops;
40610 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
40611 }
40612
40613 /*
40614 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
40615 index 0f2a2c5..471e228 100644
40616 --- a/drivers/tty/tty_ldisc.c
40617 +++ b/drivers/tty/tty_ldisc.c
40618 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
40619 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
40620 struct tty_ldisc_ops *ldo = ld->ops;
40621
40622 - ldo->refcount--;
40623 + atomic_dec(&ldo->refcount);
40624 module_put(ldo->owner);
40625 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40626
40627 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
40628 spin_lock_irqsave(&tty_ldisc_lock, flags);
40629 tty_ldiscs[disc] = new_ldisc;
40630 new_ldisc->num = disc;
40631 - new_ldisc->refcount = 0;
40632 + atomic_set(&new_ldisc->refcount, 0);
40633 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40634
40635 return ret;
40636 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
40637 return -EINVAL;
40638
40639 spin_lock_irqsave(&tty_ldisc_lock, flags);
40640 - if (tty_ldiscs[disc]->refcount)
40641 + if (atomic_read(&tty_ldiscs[disc]->refcount))
40642 ret = -EBUSY;
40643 else
40644 tty_ldiscs[disc] = NULL;
40645 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
40646 if (ldops) {
40647 ret = ERR_PTR(-EAGAIN);
40648 if (try_module_get(ldops->owner)) {
40649 - ldops->refcount++;
40650 + atomic_inc(&ldops->refcount);
40651 ret = ldops;
40652 }
40653 }
40654 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
40655 unsigned long flags;
40656
40657 spin_lock_irqsave(&tty_ldisc_lock, flags);
40658 - ldops->refcount--;
40659 + atomic_dec(&ldops->refcount);
40660 module_put(ldops->owner);
40661 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40662 }
40663 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
40664 index d7bdd8d..feaef30 100644
40665 --- a/drivers/tty/tty_port.c
40666 +++ b/drivers/tty/tty_port.c
40667 @@ -202,7 +202,7 @@ void tty_port_hangup(struct tty_port *port)
40668 unsigned long flags;
40669
40670 spin_lock_irqsave(&port->lock, flags);
40671 - port->count = 0;
40672 + atomic_set(&port->count, 0);
40673 port->flags &= ~ASYNC_NORMAL_ACTIVE;
40674 if (port->tty) {
40675 set_bit(TTY_IO_ERROR, &port->tty->flags);
40676 @@ -328,7 +328,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40677 /* The port lock protects the port counts */
40678 spin_lock_irqsave(&port->lock, flags);
40679 if (!tty_hung_up_p(filp))
40680 - port->count--;
40681 + atomic_dec(&port->count);
40682 port->blocked_open++;
40683 spin_unlock_irqrestore(&port->lock, flags);
40684
40685 @@ -370,7 +370,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40686 we must not mess that up further */
40687 spin_lock_irqsave(&port->lock, flags);
40688 if (!tty_hung_up_p(filp))
40689 - port->count++;
40690 + atomic_inc(&port->count);
40691 port->blocked_open--;
40692 if (retval == 0)
40693 port->flags |= ASYNC_NORMAL_ACTIVE;
40694 @@ -390,19 +390,19 @@ int tty_port_close_start(struct tty_port *port,
40695 return 0;
40696 }
40697
40698 - if (tty->count == 1 && port->count != 1) {
40699 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
40700 printk(KERN_WARNING
40701 "tty_port_close_start: tty->count = 1 port count = %d.\n",
40702 - port->count);
40703 - port->count = 1;
40704 + atomic_read(&port->count));
40705 + atomic_set(&port->count, 1);
40706 }
40707 - if (--port->count < 0) {
40708 + if (atomic_dec_return(&port->count) < 0) {
40709 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
40710 - port->count);
40711 - port->count = 0;
40712 + atomic_read(&port->count));
40713 + atomic_set(&port->count, 0);
40714 }
40715
40716 - if (port->count) {
40717 + if (atomic_read(&port->count)) {
40718 spin_unlock_irqrestore(&port->lock, flags);
40719 if (port->ops->drop)
40720 port->ops->drop(port);
40721 @@ -500,7 +500,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
40722 {
40723 spin_lock_irq(&port->lock);
40724 if (!tty_hung_up_p(filp))
40725 - ++port->count;
40726 + atomic_inc(&port->count);
40727 spin_unlock_irq(&port->lock);
40728 tty_port_tty_set(port, tty);
40729
40730 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
40731 index 681765b..d3ccdf2 100644
40732 --- a/drivers/tty/vt/keyboard.c
40733 +++ b/drivers/tty/vt/keyboard.c
40734 @@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
40735 kbd->kbdmode == VC_OFF) &&
40736 value != KVAL(K_SAK))
40737 return; /* SAK is allowed even in raw mode */
40738 +
40739 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
40740 + {
40741 + void *func = fn_handler[value];
40742 + if (func == fn_show_state || func == fn_show_ptregs ||
40743 + func == fn_show_mem)
40744 + return;
40745 + }
40746 +#endif
40747 +
40748 fn_handler[value](vc);
40749 }
40750
40751 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40752 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
40753 return -EFAULT;
40754
40755 - if (!capable(CAP_SYS_TTY_CONFIG))
40756 - perm = 0;
40757 -
40758 switch (cmd) {
40759 case KDGKBENT:
40760 /* Ensure another thread doesn't free it under us */
40761 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40762 spin_unlock_irqrestore(&kbd_event_lock, flags);
40763 return put_user(val, &user_kbe->kb_value);
40764 case KDSKBENT:
40765 + if (!capable(CAP_SYS_TTY_CONFIG))
40766 + perm = 0;
40767 +
40768 if (!perm)
40769 return -EPERM;
40770 if (!i && v == K_NOSUCHMAP) {
40771 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40772 int i, j, k;
40773 int ret;
40774
40775 - if (!capable(CAP_SYS_TTY_CONFIG))
40776 - perm = 0;
40777 -
40778 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
40779 if (!kbs) {
40780 ret = -ENOMEM;
40781 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40782 kfree(kbs);
40783 return ((p && *p) ? -EOVERFLOW : 0);
40784 case KDSKBSENT:
40785 + if (!capable(CAP_SYS_TTY_CONFIG))
40786 + perm = 0;
40787 +
40788 if (!perm) {
40789 ret = -EPERM;
40790 goto reterr;
40791 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
40792 index 5110f36..8dc0a74 100644
40793 --- a/drivers/uio/uio.c
40794 +++ b/drivers/uio/uio.c
40795 @@ -25,6 +25,7 @@
40796 #include <linux/kobject.h>
40797 #include <linux/cdev.h>
40798 #include <linux/uio_driver.h>
40799 +#include <asm/local.h>
40800
40801 #define UIO_MAX_DEVICES (1U << MINORBITS)
40802
40803 @@ -32,10 +33,10 @@ struct uio_device {
40804 struct module *owner;
40805 struct device *dev;
40806 int minor;
40807 - atomic_t event;
40808 + atomic_unchecked_t event;
40809 struct fasync_struct *async_queue;
40810 wait_queue_head_t wait;
40811 - int vma_count;
40812 + local_t vma_count;
40813 struct uio_info *info;
40814 struct kobject *map_dir;
40815 struct kobject *portio_dir;
40816 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
40817 struct device_attribute *attr, char *buf)
40818 {
40819 struct uio_device *idev = dev_get_drvdata(dev);
40820 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
40821 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
40822 }
40823
40824 static struct device_attribute uio_class_attributes[] = {
40825 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
40826 {
40827 struct uio_device *idev = info->uio_dev;
40828
40829 - atomic_inc(&idev->event);
40830 + atomic_inc_unchecked(&idev->event);
40831 wake_up_interruptible(&idev->wait);
40832 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
40833 }
40834 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
40835 }
40836
40837 listener->dev = idev;
40838 - listener->event_count = atomic_read(&idev->event);
40839 + listener->event_count = atomic_read_unchecked(&idev->event);
40840 filep->private_data = listener;
40841
40842 if (idev->info->open) {
40843 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
40844 return -EIO;
40845
40846 poll_wait(filep, &idev->wait, wait);
40847 - if (listener->event_count != atomic_read(&idev->event))
40848 + if (listener->event_count != atomic_read_unchecked(&idev->event))
40849 return POLLIN | POLLRDNORM;
40850 return 0;
40851 }
40852 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
40853 do {
40854 set_current_state(TASK_INTERRUPTIBLE);
40855
40856 - event_count = atomic_read(&idev->event);
40857 + event_count = atomic_read_unchecked(&idev->event);
40858 if (event_count != listener->event_count) {
40859 if (copy_to_user(buf, &event_count, count))
40860 retval = -EFAULT;
40861 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
40862 static void uio_vma_open(struct vm_area_struct *vma)
40863 {
40864 struct uio_device *idev = vma->vm_private_data;
40865 - idev->vma_count++;
40866 + local_inc(&idev->vma_count);
40867 }
40868
40869 static void uio_vma_close(struct vm_area_struct *vma)
40870 {
40871 struct uio_device *idev = vma->vm_private_data;
40872 - idev->vma_count--;
40873 + local_dec(&idev->vma_count);
40874 }
40875
40876 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40877 @@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
40878 idev->owner = owner;
40879 idev->info = info;
40880 init_waitqueue_head(&idev->wait);
40881 - atomic_set(&idev->event, 0);
40882 + atomic_set_unchecked(&idev->event, 0);
40883
40884 ret = uio_get_minor(idev);
40885 if (ret)
40886 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
40887 index b7eb86a..36d28af 100644
40888 --- a/drivers/usb/atm/cxacru.c
40889 +++ b/drivers/usb/atm/cxacru.c
40890 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
40891 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
40892 if (ret < 2)
40893 return -EINVAL;
40894 - if (index < 0 || index > 0x7f)
40895 + if (index > 0x7f)
40896 return -EINVAL;
40897 pos += tmp;
40898
40899 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
40900 index 35f10bf..6a38a0b 100644
40901 --- a/drivers/usb/atm/usbatm.c
40902 +++ b/drivers/usb/atm/usbatm.c
40903 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40904 if (printk_ratelimit())
40905 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
40906 __func__, vpi, vci);
40907 - atomic_inc(&vcc->stats->rx_err);
40908 + atomic_inc_unchecked(&vcc->stats->rx_err);
40909 return;
40910 }
40911
40912 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40913 if (length > ATM_MAX_AAL5_PDU) {
40914 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
40915 __func__, length, vcc);
40916 - atomic_inc(&vcc->stats->rx_err);
40917 + atomic_inc_unchecked(&vcc->stats->rx_err);
40918 goto out;
40919 }
40920
40921 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40922 if (sarb->len < pdu_length) {
40923 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
40924 __func__, pdu_length, sarb->len, vcc);
40925 - atomic_inc(&vcc->stats->rx_err);
40926 + atomic_inc_unchecked(&vcc->stats->rx_err);
40927 goto out;
40928 }
40929
40930 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
40931 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
40932 __func__, vcc);
40933 - atomic_inc(&vcc->stats->rx_err);
40934 + atomic_inc_unchecked(&vcc->stats->rx_err);
40935 goto out;
40936 }
40937
40938 @@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40939 if (printk_ratelimit())
40940 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
40941 __func__, length);
40942 - atomic_inc(&vcc->stats->rx_drop);
40943 + atomic_inc_unchecked(&vcc->stats->rx_drop);
40944 goto out;
40945 }
40946
40947 @@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40948
40949 vcc->push(vcc, skb);
40950
40951 - atomic_inc(&vcc->stats->rx);
40952 + atomic_inc_unchecked(&vcc->stats->rx);
40953 out:
40954 skb_trim(sarb, 0);
40955 }
40956 @@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
40957 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
40958
40959 usbatm_pop(vcc, skb);
40960 - atomic_inc(&vcc->stats->tx);
40961 + atomic_inc_unchecked(&vcc->stats->tx);
40962
40963 skb = skb_dequeue(&instance->sndqueue);
40964 }
40965 @@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
40966 if (!left--)
40967 return sprintf(page,
40968 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
40969 - atomic_read(&atm_dev->stats.aal5.tx),
40970 - atomic_read(&atm_dev->stats.aal5.tx_err),
40971 - atomic_read(&atm_dev->stats.aal5.rx),
40972 - atomic_read(&atm_dev->stats.aal5.rx_err),
40973 - atomic_read(&atm_dev->stats.aal5.rx_drop));
40974 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
40975 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
40976 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
40977 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
40978 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
40979
40980 if (!left--) {
40981 if (instance->disconnected)
40982 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
40983 index f460de3..95ba1f6 100644
40984 --- a/drivers/usb/core/devices.c
40985 +++ b/drivers/usb/core/devices.c
40986 @@ -126,7 +126,7 @@ static const char format_endpt[] =
40987 * time it gets called.
40988 */
40989 static struct device_connect_event {
40990 - atomic_t count;
40991 + atomic_unchecked_t count;
40992 wait_queue_head_t wait;
40993 } device_event = {
40994 .count = ATOMIC_INIT(1),
40995 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
40996
40997 void usbfs_conn_disc_event(void)
40998 {
40999 - atomic_add(2, &device_event.count);
41000 + atomic_add_unchecked(2, &device_event.count);
41001 wake_up(&device_event.wait);
41002 }
41003
41004 @@ -647,7 +647,7 @@ static unsigned int usb_device_poll(struct file *file,
41005
41006 poll_wait(file, &device_event.wait, wait);
41007
41008 - event_count = atomic_read(&device_event.count);
41009 + event_count = atomic_read_unchecked(&device_event.count);
41010 if (file->f_version != event_count) {
41011 file->f_version = event_count;
41012 return POLLIN | POLLRDNORM;
41013 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
41014 index f034716..aed0368 100644
41015 --- a/drivers/usb/core/hcd.c
41016 +++ b/drivers/usb/core/hcd.c
41017 @@ -1478,7 +1478,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41018 */
41019 usb_get_urb(urb);
41020 atomic_inc(&urb->use_count);
41021 - atomic_inc(&urb->dev->urbnum);
41022 + atomic_inc_unchecked(&urb->dev->urbnum);
41023 usbmon_urb_submit(&hcd->self, urb);
41024
41025 /* NOTE requirements on root-hub callers (usbfs and the hub
41026 @@ -1505,7 +1505,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41027 urb->hcpriv = NULL;
41028 INIT_LIST_HEAD(&urb->urb_list);
41029 atomic_dec(&urb->use_count);
41030 - atomic_dec(&urb->dev->urbnum);
41031 + atomic_dec_unchecked(&urb->dev->urbnum);
41032 if (atomic_read(&urb->reject))
41033 wake_up(&usb_kill_urb_queue);
41034 usb_put_urb(urb);
41035 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
41036 index 818e4a0..0fc9589 100644
41037 --- a/drivers/usb/core/sysfs.c
41038 +++ b/drivers/usb/core/sysfs.c
41039 @@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
41040 struct usb_device *udev;
41041
41042 udev = to_usb_device(dev);
41043 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
41044 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
41045 }
41046 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
41047
41048 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
41049 index cd8fb44..17fbe0c 100644
41050 --- a/drivers/usb/core/usb.c
41051 +++ b/drivers/usb/core/usb.c
41052 @@ -397,7 +397,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
41053 set_dev_node(&dev->dev, dev_to_node(bus->controller));
41054 dev->state = USB_STATE_ATTACHED;
41055 dev->lpm_disable_count = 1;
41056 - atomic_set(&dev->urbnum, 0);
41057 + atomic_set_unchecked(&dev->urbnum, 0);
41058
41059 INIT_LIST_HEAD(&dev->ep0.urb_list);
41060 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
41061 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
41062 index 4bfa78a..902bfbd 100644
41063 --- a/drivers/usb/early/ehci-dbgp.c
41064 +++ b/drivers/usb/early/ehci-dbgp.c
41065 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
41066
41067 #ifdef CONFIG_KGDB
41068 static struct kgdb_io kgdbdbgp_io_ops;
41069 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
41070 +static struct kgdb_io kgdbdbgp_io_ops_console;
41071 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
41072 #else
41073 #define dbgp_kgdb_mode (0)
41074 #endif
41075 @@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
41076 .write_char = kgdbdbgp_write_char,
41077 };
41078
41079 +static struct kgdb_io kgdbdbgp_io_ops_console = {
41080 + .name = "kgdbdbgp",
41081 + .read_char = kgdbdbgp_read_char,
41082 + .write_char = kgdbdbgp_write_char,
41083 + .is_console = 1
41084 +};
41085 +
41086 static int kgdbdbgp_wait_time;
41087
41088 static int __init kgdbdbgp_parse_config(char *str)
41089 @@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
41090 ptr++;
41091 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
41092 }
41093 - kgdb_register_io_module(&kgdbdbgp_io_ops);
41094 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
41095 + if (early_dbgp_console.index != -1)
41096 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
41097 + else
41098 + kgdb_register_io_module(&kgdbdbgp_io_ops);
41099
41100 return 0;
41101 }
41102 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
41103 index f173952..83d6ec0 100644
41104 --- a/drivers/usb/gadget/u_serial.c
41105 +++ b/drivers/usb/gadget/u_serial.c
41106 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41107 spin_lock_irq(&port->port_lock);
41108
41109 /* already open? Great. */
41110 - if (port->port.count) {
41111 + if (atomic_read(&port->port.count)) {
41112 status = 0;
41113 - port->port.count++;
41114 + atomic_inc(&port->port.count);
41115
41116 /* currently opening/closing? wait ... */
41117 } else if (port->openclose) {
41118 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41119 tty->driver_data = port;
41120 port->port.tty = tty;
41121
41122 - port->port.count = 1;
41123 + atomic_set(&port->port.count, 1);
41124 port->openclose = false;
41125
41126 /* if connected, start the I/O stream */
41127 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41128
41129 spin_lock_irq(&port->port_lock);
41130
41131 - if (port->port.count != 1) {
41132 - if (port->port.count == 0)
41133 + if (atomic_read(&port->port.count) != 1) {
41134 + if (atomic_read(&port->port.count) == 0)
41135 WARN_ON(1);
41136 else
41137 - --port->port.count;
41138 + atomic_dec(&port->port.count);
41139 goto exit;
41140 }
41141
41142 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41143 * and sleep if necessary
41144 */
41145 port->openclose = true;
41146 - port->port.count = 0;
41147 + atomic_set(&port->port.count, 0);
41148
41149 gser = port->port_usb;
41150 if (gser && gser->disconnect)
41151 @@ -1157,7 +1157,7 @@ static int gs_closed(struct gs_port *port)
41152 int cond;
41153
41154 spin_lock_irq(&port->port_lock);
41155 - cond = (port->port.count == 0) && !port->openclose;
41156 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
41157 spin_unlock_irq(&port->port_lock);
41158 return cond;
41159 }
41160 @@ -1270,7 +1270,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
41161 /* if it's already open, start I/O ... and notify the serial
41162 * protocol about open/close status (connect/disconnect).
41163 */
41164 - if (port->port.count) {
41165 + if (atomic_read(&port->port.count)) {
41166 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
41167 gs_start_io(port);
41168 if (gser->connect)
41169 @@ -1317,7 +1317,7 @@ void gserial_disconnect(struct gserial *gser)
41170
41171 port->port_usb = NULL;
41172 gser->ioport = NULL;
41173 - if (port->port.count > 0 || port->openclose) {
41174 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
41175 wake_up_interruptible(&port->drain_wait);
41176 if (port->port.tty)
41177 tty_hangup(port->port.tty);
41178 @@ -1333,7 +1333,7 @@ void gserial_disconnect(struct gserial *gser)
41179
41180 /* finally, free any unused/unusable I/O buffers */
41181 spin_lock_irqsave(&port->port_lock, flags);
41182 - if (port->port.count == 0 && !port->openclose)
41183 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
41184 gs_buf_free(&port->port_write_buf);
41185 gs_free_requests(gser->out, &port->read_pool, NULL);
41186 gs_free_requests(gser->out, &port->read_queue, NULL);
41187 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
41188 index 5f3bcd3..bfca43f 100644
41189 --- a/drivers/usb/serial/console.c
41190 +++ b/drivers/usb/serial/console.c
41191 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
41192
41193 info->port = port;
41194
41195 - ++port->port.count;
41196 + atomic_inc(&port->port.count);
41197 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
41198 if (serial->type->set_termios) {
41199 /*
41200 @@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
41201 }
41202 /* Now that any required fake tty operations are completed restore
41203 * the tty port count */
41204 - --port->port.count;
41205 + atomic_dec(&port->port.count);
41206 /* The console is special in terms of closing the device so
41207 * indicate this port is now acting as a system console. */
41208 port->port.console = 1;
41209 @@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
41210 free_tty:
41211 kfree(tty);
41212 reset_open_count:
41213 - port->port.count = 0;
41214 + atomic_set(&port->port.count, 0);
41215 usb_autopm_put_interface(serial->interface);
41216 error_get_interface:
41217 usb_serial_put(serial);
41218 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
41219 index d6bea3e..60b250e 100644
41220 --- a/drivers/usb/wusbcore/wa-hc.h
41221 +++ b/drivers/usb/wusbcore/wa-hc.h
41222 @@ -192,7 +192,7 @@ struct wahc {
41223 struct list_head xfer_delayed_list;
41224 spinlock_t xfer_list_lock;
41225 struct work_struct xfer_work;
41226 - atomic_t xfer_id_count;
41227 + atomic_unchecked_t xfer_id_count;
41228 };
41229
41230
41231 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
41232 INIT_LIST_HEAD(&wa->xfer_delayed_list);
41233 spin_lock_init(&wa->xfer_list_lock);
41234 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
41235 - atomic_set(&wa->xfer_id_count, 1);
41236 + atomic_set_unchecked(&wa->xfer_id_count, 1);
41237 }
41238
41239 /**
41240 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
41241 index 57c01ab..8a05959 100644
41242 --- a/drivers/usb/wusbcore/wa-xfer.c
41243 +++ b/drivers/usb/wusbcore/wa-xfer.c
41244 @@ -296,7 +296,7 @@ out:
41245 */
41246 static void wa_xfer_id_init(struct wa_xfer *xfer)
41247 {
41248 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
41249 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
41250 }
41251
41252 /*
41253 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
41254 index dedaf81..b0f11ab 100644
41255 --- a/drivers/vhost/vhost.c
41256 +++ b/drivers/vhost/vhost.c
41257 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
41258 return 0;
41259 }
41260
41261 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
41262 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
41263 {
41264 struct file *eventfp, *filep = NULL;
41265 bool pollstart = false, pollstop = false;
41266 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
41267 index 0fefa84..7a9d581 100644
41268 --- a/drivers/video/aty/aty128fb.c
41269 +++ b/drivers/video/aty/aty128fb.c
41270 @@ -149,7 +149,7 @@ enum {
41271 };
41272
41273 /* Must match above enum */
41274 -static char * const r128_family[] __devinitconst = {
41275 +static const char * const r128_family[] __devinitconst = {
41276 "AGP",
41277 "PCI",
41278 "PRO AGP",
41279 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
41280 index 5c3960d..15cf8fc 100644
41281 --- a/drivers/video/fbcmap.c
41282 +++ b/drivers/video/fbcmap.c
41283 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
41284 rc = -ENODEV;
41285 goto out;
41286 }
41287 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
41288 - !info->fbops->fb_setcmap)) {
41289 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
41290 rc = -EINVAL;
41291 goto out1;
41292 }
41293 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
41294 index 3ff0105..7589d98 100644
41295 --- a/drivers/video/fbmem.c
41296 +++ b/drivers/video/fbmem.c
41297 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
41298 image->dx += image->width + 8;
41299 }
41300 } else if (rotate == FB_ROTATE_UD) {
41301 - for (x = 0; x < num && image->dx >= 0; x++) {
41302 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
41303 info->fbops->fb_imageblit(info, image);
41304 image->dx -= image->width + 8;
41305 }
41306 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
41307 image->dy += image->height + 8;
41308 }
41309 } else if (rotate == FB_ROTATE_CCW) {
41310 - for (x = 0; x < num && image->dy >= 0; x++) {
41311 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
41312 info->fbops->fb_imageblit(info, image);
41313 image->dy -= image->height + 8;
41314 }
41315 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
41316 return -EFAULT;
41317 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
41318 return -EINVAL;
41319 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
41320 + if (con2fb.framebuffer >= FB_MAX)
41321 return -EINVAL;
41322 if (!registered_fb[con2fb.framebuffer])
41323 request_module("fb%d", con2fb.framebuffer);
41324 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
41325 index 7672d2e..b56437f 100644
41326 --- a/drivers/video/i810/i810_accel.c
41327 +++ b/drivers/video/i810/i810_accel.c
41328 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
41329 }
41330 }
41331 printk("ringbuffer lockup!!!\n");
41332 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
41333 i810_report_error(mmio);
41334 par->dev_flags |= LOCKUP;
41335 info->pixmap.scan_align = 1;
41336 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
41337 index 3c14e43..eafa544 100644
41338 --- a/drivers/video/logo/logo_linux_clut224.ppm
41339 +++ b/drivers/video/logo/logo_linux_clut224.ppm
41340 @@ -1,1604 +1,1123 @@
41341 P3
41342 -# Standard 224-color Linux logo
41343 80 80
41344 255
41345 - 0 0 0 0 0 0 0 0 0 0 0 0
41346 - 0 0 0 0 0 0 0 0 0 0 0 0
41347 - 0 0 0 0 0 0 0 0 0 0 0 0
41348 - 0 0 0 0 0 0 0 0 0 0 0 0
41349 - 0 0 0 0 0 0 0 0 0 0 0 0
41350 - 0 0 0 0 0 0 0 0 0 0 0 0
41351 - 0 0 0 0 0 0 0 0 0 0 0 0
41352 - 0 0 0 0 0 0 0 0 0 0 0 0
41353 - 0 0 0 0 0 0 0 0 0 0 0 0
41354 - 6 6 6 6 6 6 10 10 10 10 10 10
41355 - 10 10 10 6 6 6 6 6 6 6 6 6
41356 - 0 0 0 0 0 0 0 0 0 0 0 0
41357 - 0 0 0 0 0 0 0 0 0 0 0 0
41358 - 0 0 0 0 0 0 0 0 0 0 0 0
41359 - 0 0 0 0 0 0 0 0 0 0 0 0
41360 - 0 0 0 0 0 0 0 0 0 0 0 0
41361 - 0 0 0 0 0 0 0 0 0 0 0 0
41362 - 0 0 0 0 0 0 0 0 0 0 0 0
41363 - 0 0 0 0 0 0 0 0 0 0 0 0
41364 - 0 0 0 0 0 0 0 0 0 0 0 0
41365 - 0 0 0 0 0 0 0 0 0 0 0 0
41366 - 0 0 0 0 0 0 0 0 0 0 0 0
41367 - 0 0 0 0 0 0 0 0 0 0 0 0
41368 - 0 0 0 0 0 0 0 0 0 0 0 0
41369 - 0 0 0 0 0 0 0 0 0 0 0 0
41370 - 0 0 0 0 0 0 0 0 0 0 0 0
41371 - 0 0 0 0 0 0 0 0 0 0 0 0
41372 - 0 0 0 0 0 0 0 0 0 0 0 0
41373 - 0 0 0 6 6 6 10 10 10 14 14 14
41374 - 22 22 22 26 26 26 30 30 30 34 34 34
41375 - 30 30 30 30 30 30 26 26 26 18 18 18
41376 - 14 14 14 10 10 10 6 6 6 0 0 0
41377 - 0 0 0 0 0 0 0 0 0 0 0 0
41378 - 0 0 0 0 0 0 0 0 0 0 0 0
41379 - 0 0 0 0 0 0 0 0 0 0 0 0
41380 - 0 0 0 0 0 0 0 0 0 0 0 0
41381 - 0 0 0 0 0 0 0 0 0 0 0 0
41382 - 0 0 0 0 0 0 0 0 0 0 0 0
41383 - 0 0 0 0 0 0 0 0 0 0 0 0
41384 - 0 0 0 0 0 0 0 0 0 0 0 0
41385 - 0 0 0 0 0 0 0 0 0 0 0 0
41386 - 0 0 0 0 0 1 0 0 1 0 0 0
41387 - 0 0 0 0 0 0 0 0 0 0 0 0
41388 - 0 0 0 0 0 0 0 0 0 0 0 0
41389 - 0 0 0 0 0 0 0 0 0 0 0 0
41390 - 0 0 0 0 0 0 0 0 0 0 0 0
41391 - 0 0 0 0 0 0 0 0 0 0 0 0
41392 - 0 0 0 0 0 0 0 0 0 0 0 0
41393 - 6 6 6 14 14 14 26 26 26 42 42 42
41394 - 54 54 54 66 66 66 78 78 78 78 78 78
41395 - 78 78 78 74 74 74 66 66 66 54 54 54
41396 - 42 42 42 26 26 26 18 18 18 10 10 10
41397 - 6 6 6 0 0 0 0 0 0 0 0 0
41398 - 0 0 0 0 0 0 0 0 0 0 0 0
41399 - 0 0 0 0 0 0 0 0 0 0 0 0
41400 - 0 0 0 0 0 0 0 0 0 0 0 0
41401 - 0 0 0 0 0 0 0 0 0 0 0 0
41402 - 0 0 0 0 0 0 0 0 0 0 0 0
41403 - 0 0 0 0 0 0 0 0 0 0 0 0
41404 - 0 0 0 0 0 0 0 0 0 0 0 0
41405 - 0 0 0 0 0 0 0 0 0 0 0 0
41406 - 0 0 1 0 0 0 0 0 0 0 0 0
41407 - 0 0 0 0 0 0 0 0 0 0 0 0
41408 - 0 0 0 0 0 0 0 0 0 0 0 0
41409 - 0 0 0 0 0 0 0 0 0 0 0 0
41410 - 0 0 0 0 0 0 0 0 0 0 0 0
41411 - 0 0 0 0 0 0 0 0 0 0 0 0
41412 - 0 0 0 0 0 0 0 0 0 10 10 10
41413 - 22 22 22 42 42 42 66 66 66 86 86 86
41414 - 66 66 66 38 38 38 38 38 38 22 22 22
41415 - 26 26 26 34 34 34 54 54 54 66 66 66
41416 - 86 86 86 70 70 70 46 46 46 26 26 26
41417 - 14 14 14 6 6 6 0 0 0 0 0 0
41418 - 0 0 0 0 0 0 0 0 0 0 0 0
41419 - 0 0 0 0 0 0 0 0 0 0 0 0
41420 - 0 0 0 0 0 0 0 0 0 0 0 0
41421 - 0 0 0 0 0 0 0 0 0 0 0 0
41422 - 0 0 0 0 0 0 0 0 0 0 0 0
41423 - 0 0 0 0 0 0 0 0 0 0 0 0
41424 - 0 0 0 0 0 0 0 0 0 0 0 0
41425 - 0 0 0 0 0 0 0 0 0 0 0 0
41426 - 0 0 1 0 0 1 0 0 1 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 10 10 10 26 26 26
41433 - 50 50 50 82 82 82 58 58 58 6 6 6
41434 - 2 2 6 2 2 6 2 2 6 2 2 6
41435 - 2 2 6 2 2 6 2 2 6 2 2 6
41436 - 6 6 6 54 54 54 86 86 86 66 66 66
41437 - 38 38 38 18 18 18 6 6 6 0 0 0
41438 - 0 0 0 0 0 0 0 0 0 0 0 0
41439 - 0 0 0 0 0 0 0 0 0 0 0 0
41440 - 0 0 0 0 0 0 0 0 0 0 0 0
41441 - 0 0 0 0 0 0 0 0 0 0 0 0
41442 - 0 0 0 0 0 0 0 0 0 0 0 0
41443 - 0 0 0 0 0 0 0 0 0 0 0 0
41444 - 0 0 0 0 0 0 0 0 0 0 0 0
41445 - 0 0 0 0 0 0 0 0 0 0 0 0
41446 - 0 0 0 0 0 0 0 0 0 0 0 0
41447 - 0 0 0 0 0 0 0 0 0 0 0 0
41448 - 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
41453 - 78 78 78 34 34 34 2 2 6 2 2 6
41454 - 2 2 6 2 2 6 2 2 6 2 2 6
41455 - 2 2 6 2 2 6 2 2 6 2 2 6
41456 - 2 2 6 2 2 6 6 6 6 70 70 70
41457 - 78 78 78 46 46 46 22 22 22 6 6 6
41458 - 0 0 0 0 0 0 0 0 0 0 0 0
41459 - 0 0 0 0 0 0 0 0 0 0 0 0
41460 - 0 0 0 0 0 0 0 0 0 0 0 0
41461 - 0 0 0 0 0 0 0 0 0 0 0 0
41462 - 0 0 0 0 0 0 0 0 0 0 0 0
41463 - 0 0 0 0 0 0 0 0 0 0 0 0
41464 - 0 0 0 0 0 0 0 0 0 0 0 0
41465 - 0 0 0 0 0 0 0 0 0 0 0 0
41466 - 0 0 1 0 0 1 0 0 1 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 - 6 6 6 18 18 18 42 42 42 82 82 82
41473 - 26 26 26 2 2 6 2 2 6 2 2 6
41474 - 2 2 6 2 2 6 2 2 6 2 2 6
41475 - 2 2 6 2 2 6 2 2 6 14 14 14
41476 - 46 46 46 34 34 34 6 6 6 2 2 6
41477 - 42 42 42 78 78 78 42 42 42 18 18 18
41478 - 6 6 6 0 0 0 0 0 0 0 0 0
41479 - 0 0 0 0 0 0 0 0 0 0 0 0
41480 - 0 0 0 0 0 0 0 0 0 0 0 0
41481 - 0 0 0 0 0 0 0 0 0 0 0 0
41482 - 0 0 0 0 0 0 0 0 0 0 0 0
41483 - 0 0 0 0 0 0 0 0 0 0 0 0
41484 - 0 0 0 0 0 0 0 0 0 0 0 0
41485 - 0 0 0 0 0 0 0 0 0 0 0 0
41486 - 0 0 1 0 0 0 0 0 1 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 - 10 10 10 30 30 30 66 66 66 58 58 58
41493 - 2 2 6 2 2 6 2 2 6 2 2 6
41494 - 2 2 6 2 2 6 2 2 6 2 2 6
41495 - 2 2 6 2 2 6 2 2 6 26 26 26
41496 - 86 86 86 101 101 101 46 46 46 10 10 10
41497 - 2 2 6 58 58 58 70 70 70 34 34 34
41498 - 10 10 10 0 0 0 0 0 0 0 0 0
41499 - 0 0 0 0 0 0 0 0 0 0 0 0
41500 - 0 0 0 0 0 0 0 0 0 0 0 0
41501 - 0 0 0 0 0 0 0 0 0 0 0 0
41502 - 0 0 0 0 0 0 0 0 0 0 0 0
41503 - 0 0 0 0 0 0 0 0 0 0 0 0
41504 - 0 0 0 0 0 0 0 0 0 0 0 0
41505 - 0 0 0 0 0 0 0 0 0 0 0 0
41506 - 0 0 1 0 0 1 0 0 1 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 - 14 14 14 42 42 42 86 86 86 10 10 10
41513 - 2 2 6 2 2 6 2 2 6 2 2 6
41514 - 2 2 6 2 2 6 2 2 6 2 2 6
41515 - 2 2 6 2 2 6 2 2 6 30 30 30
41516 - 94 94 94 94 94 94 58 58 58 26 26 26
41517 - 2 2 6 6 6 6 78 78 78 54 54 54
41518 - 22 22 22 6 6 6 0 0 0 0 0 0
41519 - 0 0 0 0 0 0 0 0 0 0 0 0
41520 - 0 0 0 0 0 0 0 0 0 0 0 0
41521 - 0 0 0 0 0 0 0 0 0 0 0 0
41522 - 0 0 0 0 0 0 0 0 0 0 0 0
41523 - 0 0 0 0 0 0 0 0 0 0 0 0
41524 - 0 0 0 0 0 0 0 0 0 0 0 0
41525 - 0 0 0 0 0 0 0 0 0 0 0 0
41526 - 0 0 0 0 0 0 0 0 0 0 0 0
41527 - 0 0 0 0 0 0 0 0 0 0 0 0
41528 - 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 6 6 6
41532 - 22 22 22 62 62 62 62 62 62 2 2 6
41533 - 2 2 6 2 2 6 2 2 6 2 2 6
41534 - 2 2 6 2 2 6 2 2 6 2 2 6
41535 - 2 2 6 2 2 6 2 2 6 26 26 26
41536 - 54 54 54 38 38 38 18 18 18 10 10 10
41537 - 2 2 6 2 2 6 34 34 34 82 82 82
41538 - 38 38 38 14 14 14 0 0 0 0 0 0
41539 - 0 0 0 0 0 0 0 0 0 0 0 0
41540 - 0 0 0 0 0 0 0 0 0 0 0 0
41541 - 0 0 0 0 0 0 0 0 0 0 0 0
41542 - 0 0 0 0 0 0 0 0 0 0 0 0
41543 - 0 0 0 0 0 0 0 0 0 0 0 0
41544 - 0 0 0 0 0 0 0 0 0 0 0 0
41545 - 0 0 0 0 0 0 0 0 0 0 0 0
41546 - 0 0 0 0 0 1 0 0 1 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 6 6 6
41552 - 30 30 30 78 78 78 30 30 30 2 2 6
41553 - 2 2 6 2 2 6 2 2 6 2 2 6
41554 - 2 2 6 2 2 6 2 2 6 2 2 6
41555 - 2 2 6 2 2 6 2 2 6 10 10 10
41556 - 10 10 10 2 2 6 2 2 6 2 2 6
41557 - 2 2 6 2 2 6 2 2 6 78 78 78
41558 - 50 50 50 18 18 18 6 6 6 0 0 0
41559 - 0 0 0 0 0 0 0 0 0 0 0 0
41560 - 0 0 0 0 0 0 0 0 0 0 0 0
41561 - 0 0 0 0 0 0 0 0 0 0 0 0
41562 - 0 0 0 0 0 0 0 0 0 0 0 0
41563 - 0 0 0 0 0 0 0 0 0 0 0 0
41564 - 0 0 0 0 0 0 0 0 0 0 0 0
41565 - 0 0 0 0 0 0 0 0 0 0 0 0
41566 - 0 0 1 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 10 10 10
41572 - 38 38 38 86 86 86 14 14 14 2 2 6
41573 - 2 2 6 2 2 6 2 2 6 2 2 6
41574 - 2 2 6 2 2 6 2 2 6 2 2 6
41575 - 2 2 6 2 2 6 2 2 6 2 2 6
41576 - 2 2 6 2 2 6 2 2 6 2 2 6
41577 - 2 2 6 2 2 6 2 2 6 54 54 54
41578 - 66 66 66 26 26 26 6 6 6 0 0 0
41579 - 0 0 0 0 0 0 0 0 0 0 0 0
41580 - 0 0 0 0 0 0 0 0 0 0 0 0
41581 - 0 0 0 0 0 0 0 0 0 0 0 0
41582 - 0 0 0 0 0 0 0 0 0 0 0 0
41583 - 0 0 0 0 0 0 0 0 0 0 0 0
41584 - 0 0 0 0 0 0 0 0 0 0 0 0
41585 - 0 0 0 0 0 0 0 0 0 0 0 0
41586 - 0 0 0 0 0 1 0 0 1 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 14 14 14
41592 - 42 42 42 82 82 82 2 2 6 2 2 6
41593 - 2 2 6 6 6 6 10 10 10 2 2 6
41594 - 2 2 6 2 2 6 2 2 6 2 2 6
41595 - 2 2 6 2 2 6 2 2 6 6 6 6
41596 - 14 14 14 10 10 10 2 2 6 2 2 6
41597 - 2 2 6 2 2 6 2 2 6 18 18 18
41598 - 82 82 82 34 34 34 10 10 10 0 0 0
41599 - 0 0 0 0 0 0 0 0 0 0 0 0
41600 - 0 0 0 0 0 0 0 0 0 0 0 0
41601 - 0 0 0 0 0 0 0 0 0 0 0 0
41602 - 0 0 0 0 0 0 0 0 0 0 0 0
41603 - 0 0 0 0 0 0 0 0 0 0 0 0
41604 - 0 0 0 0 0 0 0 0 0 0 0 0
41605 - 0 0 0 0 0 0 0 0 0 0 0 0
41606 - 0 0 1 0 0 0 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 14 14 14
41612 - 46 46 46 86 86 86 2 2 6 2 2 6
41613 - 6 6 6 6 6 6 22 22 22 34 34 34
41614 - 6 6 6 2 2 6 2 2 6 2 2 6
41615 - 2 2 6 2 2 6 18 18 18 34 34 34
41616 - 10 10 10 50 50 50 22 22 22 2 2 6
41617 - 2 2 6 2 2 6 2 2 6 10 10 10
41618 - 86 86 86 42 42 42 14 14 14 0 0 0
41619 - 0 0 0 0 0 0 0 0 0 0 0 0
41620 - 0 0 0 0 0 0 0 0 0 0 0 0
41621 - 0 0 0 0 0 0 0 0 0 0 0 0
41622 - 0 0 0 0 0 0 0 0 0 0 0 0
41623 - 0 0 0 0 0 0 0 0 0 0 0 0
41624 - 0 0 0 0 0 0 0 0 0 0 0 0
41625 - 0 0 0 0 0 0 0 0 0 0 0 0
41626 - 0 0 1 0 0 1 0 0 1 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 14 14 14
41632 - 46 46 46 86 86 86 2 2 6 2 2 6
41633 - 38 38 38 116 116 116 94 94 94 22 22 22
41634 - 22 22 22 2 2 6 2 2 6 2 2 6
41635 - 14 14 14 86 86 86 138 138 138 162 162 162
41636 -154 154 154 38 38 38 26 26 26 6 6 6
41637 - 2 2 6 2 2 6 2 2 6 2 2 6
41638 - 86 86 86 46 46 46 14 14 14 0 0 0
41639 - 0 0 0 0 0 0 0 0 0 0 0 0
41640 - 0 0 0 0 0 0 0 0 0 0 0 0
41641 - 0 0 0 0 0 0 0 0 0 0 0 0
41642 - 0 0 0 0 0 0 0 0 0 0 0 0
41643 - 0 0 0 0 0 0 0 0 0 0 0 0
41644 - 0 0 0 0 0 0 0 0 0 0 0 0
41645 - 0 0 0 0 0 0 0 0 0 0 0 0
41646 - 0 0 0 0 0 0 0 0 0 0 0 0
41647 - 0 0 0 0 0 0 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 14 14 14
41652 - 46 46 46 86 86 86 2 2 6 14 14 14
41653 -134 134 134 198 198 198 195 195 195 116 116 116
41654 - 10 10 10 2 2 6 2 2 6 6 6 6
41655 -101 98 89 187 187 187 210 210 210 218 218 218
41656 -214 214 214 134 134 134 14 14 14 6 6 6
41657 - 2 2 6 2 2 6 2 2 6 2 2 6
41658 - 86 86 86 50 50 50 18 18 18 6 6 6
41659 - 0 0 0 0 0 0 0 0 0 0 0 0
41660 - 0 0 0 0 0 0 0 0 0 0 0 0
41661 - 0 0 0 0 0 0 0 0 0 0 0 0
41662 - 0 0 0 0 0 0 0 0 0 0 0 0
41663 - 0 0 0 0 0 0 0 0 0 0 0 0
41664 - 0 0 0 0 0 0 0 0 0 0 0 0
41665 - 0 0 0 0 0 0 0 0 1 0 0 0
41666 - 0 0 1 0 0 1 0 0 1 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 14 14 14
41672 - 46 46 46 86 86 86 2 2 6 54 54 54
41673 -218 218 218 195 195 195 226 226 226 246 246 246
41674 - 58 58 58 2 2 6 2 2 6 30 30 30
41675 -210 210 210 253 253 253 174 174 174 123 123 123
41676 -221 221 221 234 234 234 74 74 74 2 2 6
41677 - 2 2 6 2 2 6 2 2 6 2 2 6
41678 - 70 70 70 58 58 58 22 22 22 6 6 6
41679 - 0 0 0 0 0 0 0 0 0 0 0 0
41680 - 0 0 0 0 0 0 0 0 0 0 0 0
41681 - 0 0 0 0 0 0 0 0 0 0 0 0
41682 - 0 0 0 0 0 0 0 0 0 0 0 0
41683 - 0 0 0 0 0 0 0 0 0 0 0 0
41684 - 0 0 0 0 0 0 0 0 0 0 0 0
41685 - 0 0 0 0 0 0 0 0 0 0 0 0
41686 - 0 0 0 0 0 0 0 0 0 0 0 0
41687 - 0 0 0 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 14 14 14
41692 - 46 46 46 82 82 82 2 2 6 106 106 106
41693 -170 170 170 26 26 26 86 86 86 226 226 226
41694 -123 123 123 10 10 10 14 14 14 46 46 46
41695 -231 231 231 190 190 190 6 6 6 70 70 70
41696 - 90 90 90 238 238 238 158 158 158 2 2 6
41697 - 2 2 6 2 2 6 2 2 6 2 2 6
41698 - 70 70 70 58 58 58 22 22 22 6 6 6
41699 - 0 0 0 0 0 0 0 0 0 0 0 0
41700 - 0 0 0 0 0 0 0 0 0 0 0 0
41701 - 0 0 0 0 0 0 0 0 0 0 0 0
41702 - 0 0 0 0 0 0 0 0 0 0 0 0
41703 - 0 0 0 0 0 0 0 0 0 0 0 0
41704 - 0 0 0 0 0 0 0 0 0 0 0 0
41705 - 0 0 0 0 0 0 0 0 1 0 0 0
41706 - 0 0 1 0 0 1 0 0 1 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 14 14 14
41712 - 42 42 42 86 86 86 6 6 6 116 116 116
41713 -106 106 106 6 6 6 70 70 70 149 149 149
41714 -128 128 128 18 18 18 38 38 38 54 54 54
41715 -221 221 221 106 106 106 2 2 6 14 14 14
41716 - 46 46 46 190 190 190 198 198 198 2 2 6
41717 - 2 2 6 2 2 6 2 2 6 2 2 6
41718 - 74 74 74 62 62 62 22 22 22 6 6 6
41719 - 0 0 0 0 0 0 0 0 0 0 0 0
41720 - 0 0 0 0 0 0 0 0 0 0 0 0
41721 - 0 0 0 0 0 0 0 0 0 0 0 0
41722 - 0 0 0 0 0 0 0 0 0 0 0 0
41723 - 0 0 0 0 0 0 0 0 0 0 0 0
41724 - 0 0 0 0 0 0 0 0 0 0 0 0
41725 - 0 0 0 0 0 0 0 0 1 0 0 0
41726 - 0 0 1 0 0 0 0 0 1 0 0 0
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 14 14 14
41732 - 42 42 42 94 94 94 14 14 14 101 101 101
41733 -128 128 128 2 2 6 18 18 18 116 116 116
41734 -118 98 46 121 92 8 121 92 8 98 78 10
41735 -162 162 162 106 106 106 2 2 6 2 2 6
41736 - 2 2 6 195 195 195 195 195 195 6 6 6
41737 - 2 2 6 2 2 6 2 2 6 2 2 6
41738 - 74 74 74 62 62 62 22 22 22 6 6 6
41739 - 0 0 0 0 0 0 0 0 0 0 0 0
41740 - 0 0 0 0 0 0 0 0 0 0 0 0
41741 - 0 0 0 0 0 0 0 0 0 0 0 0
41742 - 0 0 0 0 0 0 0 0 0 0 0 0
41743 - 0 0 0 0 0 0 0 0 0 0 0 0
41744 - 0 0 0 0 0 0 0 0 0 0 0 0
41745 - 0 0 0 0 0 0 0 0 1 0 0 1
41746 - 0 0 1 0 0 0 0 0 1 0 0 0
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 10 10 10
41752 - 38 38 38 90 90 90 14 14 14 58 58 58
41753 -210 210 210 26 26 26 54 38 6 154 114 10
41754 -226 170 11 236 186 11 225 175 15 184 144 12
41755 -215 174 15 175 146 61 37 26 9 2 2 6
41756 - 70 70 70 246 246 246 138 138 138 2 2 6
41757 - 2 2 6 2 2 6 2 2 6 2 2 6
41758 - 70 70 70 66 66 66 26 26 26 6 6 6
41759 - 0 0 0 0 0 0 0 0 0 0 0 0
41760 - 0 0 0 0 0 0 0 0 0 0 0 0
41761 - 0 0 0 0 0 0 0 0 0 0 0 0
41762 - 0 0 0 0 0 0 0 0 0 0 0 0
41763 - 0 0 0 0 0 0 0 0 0 0 0 0
41764 - 0 0 0 0 0 0 0 0 0 0 0 0
41765 - 0 0 0 0 0 0 0 0 0 0 0 0
41766 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
41772 - 38 38 38 86 86 86 14 14 14 10 10 10
41773 -195 195 195 188 164 115 192 133 9 225 175 15
41774 -239 182 13 234 190 10 232 195 16 232 200 30
41775 -245 207 45 241 208 19 232 195 16 184 144 12
41776 -218 194 134 211 206 186 42 42 42 2 2 6
41777 - 2 2 6 2 2 6 2 2 6 2 2 6
41778 - 50 50 50 74 74 74 30 30 30 6 6 6
41779 - 0 0 0 0 0 0 0 0 0 0 0 0
41780 - 0 0 0 0 0 0 0 0 0 0 0 0
41781 - 0 0 0 0 0 0 0 0 0 0 0 0
41782 - 0 0 0 0 0 0 0 0 0 0 0 0
41783 - 0 0 0 0 0 0 0 0 0 0 0 0
41784 - 0 0 0 0 0 0 0 0 0 0 0 0
41785 - 0 0 0 0 0 0 0 0 0 0 0 0
41786 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
41792 - 34 34 34 86 86 86 14 14 14 2 2 6
41793 -121 87 25 192 133 9 219 162 10 239 182 13
41794 -236 186 11 232 195 16 241 208 19 244 214 54
41795 -246 218 60 246 218 38 246 215 20 241 208 19
41796 -241 208 19 226 184 13 121 87 25 2 2 6
41797 - 2 2 6 2 2 6 2 2 6 2 2 6
41798 - 50 50 50 82 82 82 34 34 34 10 10 10
41799 - 0 0 0 0 0 0 0 0 0 0 0 0
41800 - 0 0 0 0 0 0 0 0 0 0 0 0
41801 - 0 0 0 0 0 0 0 0 0 0 0 0
41802 - 0 0 0 0 0 0 0 0 0 0 0 0
41803 - 0 0 0 0 0 0 0 0 0 0 0 0
41804 - 0 0 0 0 0 0 0 0 0 0 0 0
41805 - 0 0 0 0 0 0 0 0 0 0 0 0
41806 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
41812 - 34 34 34 82 82 82 30 30 30 61 42 6
41813 -180 123 7 206 145 10 230 174 11 239 182 13
41814 -234 190 10 238 202 15 241 208 19 246 218 74
41815 -246 218 38 246 215 20 246 215 20 246 215 20
41816 -226 184 13 215 174 15 184 144 12 6 6 6
41817 - 2 2 6 2 2 6 2 2 6 2 2 6
41818 - 26 26 26 94 94 94 42 42 42 14 14 14
41819 - 0 0 0 0 0 0 0 0 0 0 0 0
41820 - 0 0 0 0 0 0 0 0 0 0 0 0
41821 - 0 0 0 0 0 0 0 0 0 0 0 0
41822 - 0 0 0 0 0 0 0 0 0 0 0 0
41823 - 0 0 0 0 0 0 0 0 0 0 0 0
41824 - 0 0 0 0 0 0 0 0 0 0 0 0
41825 - 0 0 0 0 0 0 0 0 0 0 0 0
41826 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
41832 - 30 30 30 78 78 78 50 50 50 104 69 6
41833 -192 133 9 216 158 10 236 178 12 236 186 11
41834 -232 195 16 241 208 19 244 214 54 245 215 43
41835 -246 215 20 246 215 20 241 208 19 198 155 10
41836 -200 144 11 216 158 10 156 118 10 2 2 6
41837 - 2 2 6 2 2 6 2 2 6 2 2 6
41838 - 6 6 6 90 90 90 54 54 54 18 18 18
41839 - 6 6 6 0 0 0 0 0 0 0 0 0
41840 - 0 0 0 0 0 0 0 0 0 0 0 0
41841 - 0 0 0 0 0 0 0 0 0 0 0 0
41842 - 0 0 0 0 0 0 0 0 0 0 0 0
41843 - 0 0 0 0 0 0 0 0 0 0 0 0
41844 - 0 0 0 0 0 0 0 0 0 0 0 0
41845 - 0 0 0 0 0 0 0 0 0 0 0 0
41846 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
41852 - 30 30 30 78 78 78 46 46 46 22 22 22
41853 -137 92 6 210 162 10 239 182 13 238 190 10
41854 -238 202 15 241 208 19 246 215 20 246 215 20
41855 -241 208 19 203 166 17 185 133 11 210 150 10
41856 -216 158 10 210 150 10 102 78 10 2 2 6
41857 - 6 6 6 54 54 54 14 14 14 2 2 6
41858 - 2 2 6 62 62 62 74 74 74 30 30 30
41859 - 10 10 10 0 0 0 0 0 0 0 0 0
41860 - 0 0 0 0 0 0 0 0 0 0 0 0
41861 - 0 0 0 0 0 0 0 0 0 0 0 0
41862 - 0 0 0 0 0 0 0 0 0 0 0 0
41863 - 0 0 0 0 0 0 0 0 0 0 0 0
41864 - 0 0 0 0 0 0 0 0 0 0 0 0
41865 - 0 0 0 0 0 0 0 0 0 0 0 0
41866 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
41872 - 34 34 34 78 78 78 50 50 50 6 6 6
41873 - 94 70 30 139 102 15 190 146 13 226 184 13
41874 -232 200 30 232 195 16 215 174 15 190 146 13
41875 -168 122 10 192 133 9 210 150 10 213 154 11
41876 -202 150 34 182 157 106 101 98 89 2 2 6
41877 - 2 2 6 78 78 78 116 116 116 58 58 58
41878 - 2 2 6 22 22 22 90 90 90 46 46 46
41879 - 18 18 18 6 6 6 0 0 0 0 0 0
41880 - 0 0 0 0 0 0 0 0 0 0 0 0
41881 - 0 0 0 0 0 0 0 0 0 0 0 0
41882 - 0 0 0 0 0 0 0 0 0 0 0 0
41883 - 0 0 0 0 0 0 0 0 0 0 0 0
41884 - 0 0 0 0 0 0 0 0 0 0 0 0
41885 - 0 0 0 0 0 0 0 0 0 0 0 0
41886 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
41892 - 38 38 38 86 86 86 50 50 50 6 6 6
41893 -128 128 128 174 154 114 156 107 11 168 122 10
41894 -198 155 10 184 144 12 197 138 11 200 144 11
41895 -206 145 10 206 145 10 197 138 11 188 164 115
41896 -195 195 195 198 198 198 174 174 174 14 14 14
41897 - 2 2 6 22 22 22 116 116 116 116 116 116
41898 - 22 22 22 2 2 6 74 74 74 70 70 70
41899 - 30 30 30 10 10 10 0 0 0 0 0 0
41900 - 0 0 0 0 0 0 0 0 0 0 0 0
41901 - 0 0 0 0 0 0 0 0 0 0 0 0
41902 - 0 0 0 0 0 0 0 0 0 0 0 0
41903 - 0 0 0 0 0 0 0 0 0 0 0 0
41904 - 0 0 0 0 0 0 0 0 0 0 0 0
41905 - 0 0 0 0 0 0 0 0 0 0 0 0
41906 - 0 0 0 0 0 0 0 0 0 0 0 0
41907 - 0 0 0 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 6 6 6 18 18 18
41912 - 50 50 50 101 101 101 26 26 26 10 10 10
41913 -138 138 138 190 190 190 174 154 114 156 107 11
41914 -197 138 11 200 144 11 197 138 11 192 133 9
41915 -180 123 7 190 142 34 190 178 144 187 187 187
41916 -202 202 202 221 221 221 214 214 214 66 66 66
41917 - 2 2 6 2 2 6 50 50 50 62 62 62
41918 - 6 6 6 2 2 6 10 10 10 90 90 90
41919 - 50 50 50 18 18 18 6 6 6 0 0 0
41920 - 0 0 0 0 0 0 0 0 0 0 0 0
41921 - 0 0 0 0 0 0 0 0 0 0 0 0
41922 - 0 0 0 0 0 0 0 0 0 0 0 0
41923 - 0 0 0 0 0 0 0 0 0 0 0 0
41924 - 0 0 0 0 0 0 0 0 0 0 0 0
41925 - 0 0 0 0 0 0 0 0 0 0 0 0
41926 - 0 0 0 0 0 0 0 0 0 0 0 0
41927 - 0 0 0 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 10 10 10 34 34 34
41932 - 74 74 74 74 74 74 2 2 6 6 6 6
41933 -144 144 144 198 198 198 190 190 190 178 166 146
41934 -154 121 60 156 107 11 156 107 11 168 124 44
41935 -174 154 114 187 187 187 190 190 190 210 210 210
41936 -246 246 246 253 253 253 253 253 253 182 182 182
41937 - 6 6 6 2 2 6 2 2 6 2 2 6
41938 - 2 2 6 2 2 6 2 2 6 62 62 62
41939 - 74 74 74 34 34 34 14 14 14 0 0 0
41940 - 0 0 0 0 0 0 0 0 0 0 0 0
41941 - 0 0 0 0 0 0 0 0 0 0 0 0
41942 - 0 0 0 0 0 0 0 0 0 0 0 0
41943 - 0 0 0 0 0 0 0 0 0 0 0 0
41944 - 0 0 0 0 0 0 0 0 0 0 0 0
41945 - 0 0 0 0 0 0 0 0 0 0 0 0
41946 - 0 0 0 0 0 0 0 0 0 0 0 0
41947 - 0 0 0 0 0 0 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 10 10 10 22 22 22 54 54 54
41952 - 94 94 94 18 18 18 2 2 6 46 46 46
41953 -234 234 234 221 221 221 190 190 190 190 190 190
41954 -190 190 190 187 187 187 187 187 187 190 190 190
41955 -190 190 190 195 195 195 214 214 214 242 242 242
41956 -253 253 253 253 253 253 253 253 253 253 253 253
41957 - 82 82 82 2 2 6 2 2 6 2 2 6
41958 - 2 2 6 2 2 6 2 2 6 14 14 14
41959 - 86 86 86 54 54 54 22 22 22 6 6 6
41960 - 0 0 0 0 0 0 0 0 0 0 0 0
41961 - 0 0 0 0 0 0 0 0 0 0 0 0
41962 - 0 0 0 0 0 0 0 0 0 0 0 0
41963 - 0 0 0 0 0 0 0 0 0 0 0 0
41964 - 0 0 0 0 0 0 0 0 0 0 0 0
41965 - 0 0 0 0 0 0 0 0 0 0 0 0
41966 - 0 0 0 0 0 0 0 0 0 0 0 0
41967 - 0 0 0 0 0 0 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 - 6 6 6 18 18 18 46 46 46 90 90 90
41972 - 46 46 46 18 18 18 6 6 6 182 182 182
41973 -253 253 253 246 246 246 206 206 206 190 190 190
41974 -190 190 190 190 190 190 190 190 190 190 190 190
41975 -206 206 206 231 231 231 250 250 250 253 253 253
41976 -253 253 253 253 253 253 253 253 253 253 253 253
41977 -202 202 202 14 14 14 2 2 6 2 2 6
41978 - 2 2 6 2 2 6 2 2 6 2 2 6
41979 - 42 42 42 86 86 86 42 42 42 18 18 18
41980 - 6 6 6 0 0 0 0 0 0 0 0 0
41981 - 0 0 0 0 0 0 0 0 0 0 0 0
41982 - 0 0 0 0 0 0 0 0 0 0 0 0
41983 - 0 0 0 0 0 0 0 0 0 0 0 0
41984 - 0 0 0 0 0 0 0 0 0 0 0 0
41985 - 0 0 0 0 0 0 0 0 0 0 0 0
41986 - 0 0 0 0 0 0 0 0 0 0 0 0
41987 - 0 0 0 0 0 0 0 0 0 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 6 6 6
41991 - 14 14 14 38 38 38 74 74 74 66 66 66
41992 - 2 2 6 6 6 6 90 90 90 250 250 250
41993 -253 253 253 253 253 253 238 238 238 198 198 198
41994 -190 190 190 190 190 190 195 195 195 221 221 221
41995 -246 246 246 253 253 253 253 253 253 253 253 253
41996 -253 253 253 253 253 253 253 253 253 253 253 253
41997 -253 253 253 82 82 82 2 2 6 2 2 6
41998 - 2 2 6 2 2 6 2 2 6 2 2 6
41999 - 2 2 6 78 78 78 70 70 70 34 34 34
42000 - 14 14 14 6 6 6 0 0 0 0 0 0
42001 - 0 0 0 0 0 0 0 0 0 0 0 0
42002 - 0 0 0 0 0 0 0 0 0 0 0 0
42003 - 0 0 0 0 0 0 0 0 0 0 0 0
42004 - 0 0 0 0 0 0 0 0 0 0 0 0
42005 - 0 0 0 0 0 0 0 0 0 0 0 0
42006 - 0 0 0 0 0 0 0 0 0 0 0 0
42007 - 0 0 0 0 0 0 0 0 0 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 14 14 14
42011 - 34 34 34 66 66 66 78 78 78 6 6 6
42012 - 2 2 6 18 18 18 218 218 218 253 253 253
42013 -253 253 253 253 253 253 253 253 253 246 246 246
42014 -226 226 226 231 231 231 246 246 246 253 253 253
42015 -253 253 253 253 253 253 253 253 253 253 253 253
42016 -253 253 253 253 253 253 253 253 253 253 253 253
42017 -253 253 253 178 178 178 2 2 6 2 2 6
42018 - 2 2 6 2 2 6 2 2 6 2 2 6
42019 - 2 2 6 18 18 18 90 90 90 62 62 62
42020 - 30 30 30 10 10 10 0 0 0 0 0 0
42021 - 0 0 0 0 0 0 0 0 0 0 0 0
42022 - 0 0 0 0 0 0 0 0 0 0 0 0
42023 - 0 0 0 0 0 0 0 0 0 0 0 0
42024 - 0 0 0 0 0 0 0 0 0 0 0 0
42025 - 0 0 0 0 0 0 0 0 0 0 0 0
42026 - 0 0 0 0 0 0 0 0 0 0 0 0
42027 - 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 26 26 26
42031 - 58 58 58 90 90 90 18 18 18 2 2 6
42032 - 2 2 6 110 110 110 253 253 253 253 253 253
42033 -253 253 253 253 253 253 253 253 253 253 253 253
42034 -250 250 250 253 253 253 253 253 253 253 253 253
42035 -253 253 253 253 253 253 253 253 253 253 253 253
42036 -253 253 253 253 253 253 253 253 253 253 253 253
42037 -253 253 253 231 231 231 18 18 18 2 2 6
42038 - 2 2 6 2 2 6 2 2 6 2 2 6
42039 - 2 2 6 2 2 6 18 18 18 94 94 94
42040 - 54 54 54 26 26 26 10 10 10 0 0 0
42041 - 0 0 0 0 0 0 0 0 0 0 0 0
42042 - 0 0 0 0 0 0 0 0 0 0 0 0
42043 - 0 0 0 0 0 0 0 0 0 0 0 0
42044 - 0 0 0 0 0 0 0 0 0 0 0 0
42045 - 0 0 0 0 0 0 0 0 0 0 0 0
42046 - 0 0 0 0 0 0 0 0 0 0 0 0
42047 - 0 0 0 0 0 0 0 0 0 0 0 0
42048 - 0 0 0 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 6 6 6 22 22 22 50 50 50
42051 - 90 90 90 26 26 26 2 2 6 2 2 6
42052 - 14 14 14 195 195 195 250 250 250 253 253 253
42053 -253 253 253 253 253 253 253 253 253 253 253 253
42054 -253 253 253 253 253 253 253 253 253 253 253 253
42055 -253 253 253 253 253 253 253 253 253 253 253 253
42056 -253 253 253 253 253 253 253 253 253 253 253 253
42057 -250 250 250 242 242 242 54 54 54 2 2 6
42058 - 2 2 6 2 2 6 2 2 6 2 2 6
42059 - 2 2 6 2 2 6 2 2 6 38 38 38
42060 - 86 86 86 50 50 50 22 22 22 6 6 6
42061 - 0 0 0 0 0 0 0 0 0 0 0 0
42062 - 0 0 0 0 0 0 0 0 0 0 0 0
42063 - 0 0 0 0 0 0 0 0 0 0 0 0
42064 - 0 0 0 0 0 0 0 0 0 0 0 0
42065 - 0 0 0 0 0 0 0 0 0 0 0 0
42066 - 0 0 0 0 0 0 0 0 0 0 0 0
42067 - 0 0 0 0 0 0 0 0 0 0 0 0
42068 - 0 0 0 0 0 0 0 0 0 0 0 0
42069 - 0 0 0 0 0 0 0 0 0 0 0 0
42070 - 6 6 6 14 14 14 38 38 38 82 82 82
42071 - 34 34 34 2 2 6 2 2 6 2 2 6
42072 - 42 42 42 195 195 195 246 246 246 253 253 253
42073 -253 253 253 253 253 253 253 253 253 250 250 250
42074 -242 242 242 242 242 242 250 250 250 253 253 253
42075 -253 253 253 253 253 253 253 253 253 253 253 253
42076 -253 253 253 250 250 250 246 246 246 238 238 238
42077 -226 226 226 231 231 231 101 101 101 6 6 6
42078 - 2 2 6 2 2 6 2 2 6 2 2 6
42079 - 2 2 6 2 2 6 2 2 6 2 2 6
42080 - 38 38 38 82 82 82 42 42 42 14 14 14
42081 - 6 6 6 0 0 0 0 0 0 0 0 0
42082 - 0 0 0 0 0 0 0 0 0 0 0 0
42083 - 0 0 0 0 0 0 0 0 0 0 0 0
42084 - 0 0 0 0 0 0 0 0 0 0 0 0
42085 - 0 0 0 0 0 0 0 0 0 0 0 0
42086 - 0 0 0 0 0 0 0 0 0 0 0 0
42087 - 0 0 0 0 0 0 0 0 0 0 0 0
42088 - 0 0 0 0 0 0 0 0 0 0 0 0
42089 - 0 0 0 0 0 0 0 0 0 0 0 0
42090 - 10 10 10 26 26 26 62 62 62 66 66 66
42091 - 2 2 6 2 2 6 2 2 6 6 6 6
42092 - 70 70 70 170 170 170 206 206 206 234 234 234
42093 -246 246 246 250 250 250 250 250 250 238 238 238
42094 -226 226 226 231 231 231 238 238 238 250 250 250
42095 -250 250 250 250 250 250 246 246 246 231 231 231
42096 -214 214 214 206 206 206 202 202 202 202 202 202
42097 -198 198 198 202 202 202 182 182 182 18 18 18
42098 - 2 2 6 2 2 6 2 2 6 2 2 6
42099 - 2 2 6 2 2 6 2 2 6 2 2 6
42100 - 2 2 6 62 62 62 66 66 66 30 30 30
42101 - 10 10 10 0 0 0 0 0 0 0 0 0
42102 - 0 0 0 0 0 0 0 0 0 0 0 0
42103 - 0 0 0 0 0 0 0 0 0 0 0 0
42104 - 0 0 0 0 0 0 0 0 0 0 0 0
42105 - 0 0 0 0 0 0 0 0 0 0 0 0
42106 - 0 0 0 0 0 0 0 0 0 0 0 0
42107 - 0 0 0 0 0 0 0 0 0 0 0 0
42108 - 0 0 0 0 0 0 0 0 0 0 0 0
42109 - 0 0 0 0 0 0 0 0 0 0 0 0
42110 - 14 14 14 42 42 42 82 82 82 18 18 18
42111 - 2 2 6 2 2 6 2 2 6 10 10 10
42112 - 94 94 94 182 182 182 218 218 218 242 242 242
42113 -250 250 250 253 253 253 253 253 253 250 250 250
42114 -234 234 234 253 253 253 253 253 253 253 253 253
42115 -253 253 253 253 253 253 253 253 253 246 246 246
42116 -238 238 238 226 226 226 210 210 210 202 202 202
42117 -195 195 195 195 195 195 210 210 210 158 158 158
42118 - 6 6 6 14 14 14 50 50 50 14 14 14
42119 - 2 2 6 2 2 6 2 2 6 2 2 6
42120 - 2 2 6 6 6 6 86 86 86 46 46 46
42121 - 18 18 18 6 6 6 0 0 0 0 0 0
42122 - 0 0 0 0 0 0 0 0 0 0 0 0
42123 - 0 0 0 0 0 0 0 0 0 0 0 0
42124 - 0 0 0 0 0 0 0 0 0 0 0 0
42125 - 0 0 0 0 0 0 0 0 0 0 0 0
42126 - 0 0 0 0 0 0 0 0 0 0 0 0
42127 - 0 0 0 0 0 0 0 0 0 0 0 0
42128 - 0 0 0 0 0 0 0 0 0 0 0 0
42129 - 0 0 0 0 0 0 0 0 0 6 6 6
42130 - 22 22 22 54 54 54 70 70 70 2 2 6
42131 - 2 2 6 10 10 10 2 2 6 22 22 22
42132 -166 166 166 231 231 231 250 250 250 253 253 253
42133 -253 253 253 253 253 253 253 253 253 250 250 250
42134 -242 242 242 253 253 253 253 253 253 253 253 253
42135 -253 253 253 253 253 253 253 253 253 253 253 253
42136 -253 253 253 253 253 253 253 253 253 246 246 246
42137 -231 231 231 206 206 206 198 198 198 226 226 226
42138 - 94 94 94 2 2 6 6 6 6 38 38 38
42139 - 30 30 30 2 2 6 2 2 6 2 2 6
42140 - 2 2 6 2 2 6 62 62 62 66 66 66
42141 - 26 26 26 10 10 10 0 0 0 0 0 0
42142 - 0 0 0 0 0 0 0 0 0 0 0 0
42143 - 0 0 0 0 0 0 0 0 0 0 0 0
42144 - 0 0 0 0 0 0 0 0 0 0 0 0
42145 - 0 0 0 0 0 0 0 0 0 0 0 0
42146 - 0 0 0 0 0 0 0 0 0 0 0 0
42147 - 0 0 0 0 0 0 0 0 0 0 0 0
42148 - 0 0 0 0 0 0 0 0 0 0 0 0
42149 - 0 0 0 0 0 0 0 0 0 10 10 10
42150 - 30 30 30 74 74 74 50 50 50 2 2 6
42151 - 26 26 26 26 26 26 2 2 6 106 106 106
42152 -238 238 238 253 253 253 253 253 253 253 253 253
42153 -253 253 253 253 253 253 253 253 253 253 253 253
42154 -253 253 253 253 253 253 253 253 253 253 253 253
42155 -253 253 253 253 253 253 253 253 253 253 253 253
42156 -253 253 253 253 253 253 253 253 253 253 253 253
42157 -253 253 253 246 246 246 218 218 218 202 202 202
42158 -210 210 210 14 14 14 2 2 6 2 2 6
42159 - 30 30 30 22 22 22 2 2 6 2 2 6
42160 - 2 2 6 2 2 6 18 18 18 86 86 86
42161 - 42 42 42 14 14 14 0 0 0 0 0 0
42162 - 0 0 0 0 0 0 0 0 0 0 0 0
42163 - 0 0 0 0 0 0 0 0 0 0 0 0
42164 - 0 0 0 0 0 0 0 0 0 0 0 0
42165 - 0 0 0 0 0 0 0 0 0 0 0 0
42166 - 0 0 0 0 0 0 0 0 0 0 0 0
42167 - 0 0 0 0 0 0 0 0 0 0 0 0
42168 - 0 0 0 0 0 0 0 0 0 0 0 0
42169 - 0 0 0 0 0 0 0 0 0 14 14 14
42170 - 42 42 42 90 90 90 22 22 22 2 2 6
42171 - 42 42 42 2 2 6 18 18 18 218 218 218
42172 -253 253 253 253 253 253 253 253 253 253 253 253
42173 -253 253 253 253 253 253 253 253 253 253 253 253
42174 -253 253 253 253 253 253 253 253 253 253 253 253
42175 -253 253 253 253 253 253 253 253 253 253 253 253
42176 -253 253 253 253 253 253 253 253 253 253 253 253
42177 -253 253 253 253 253 253 250 250 250 221 221 221
42178 -218 218 218 101 101 101 2 2 6 14 14 14
42179 - 18 18 18 38 38 38 10 10 10 2 2 6
42180 - 2 2 6 2 2 6 2 2 6 78 78 78
42181 - 58 58 58 22 22 22 6 6 6 0 0 0
42182 - 0 0 0 0 0 0 0 0 0 0 0 0
42183 - 0 0 0 0 0 0 0 0 0 0 0 0
42184 - 0 0 0 0 0 0 0 0 0 0 0 0
42185 - 0 0 0 0 0 0 0 0 0 0 0 0
42186 - 0 0 0 0 0 0 0 0 0 0 0 0
42187 - 0 0 0 0 0 0 0 0 0 0 0 0
42188 - 0 0 0 0 0 0 0 0 0 0 0 0
42189 - 0 0 0 0 0 0 6 6 6 18 18 18
42190 - 54 54 54 82 82 82 2 2 6 26 26 26
42191 - 22 22 22 2 2 6 123 123 123 253 253 253
42192 -253 253 253 253 253 253 253 253 253 253 253 253
42193 -253 253 253 253 253 253 253 253 253 253 253 253
42194 -253 253 253 253 253 253 253 253 253 253 253 253
42195 -253 253 253 253 253 253 253 253 253 253 253 253
42196 -253 253 253 253 253 253 253 253 253 253 253 253
42197 -253 253 253 253 253 253 253 253 253 250 250 250
42198 -238 238 238 198 198 198 6 6 6 38 38 38
42199 - 58 58 58 26 26 26 38 38 38 2 2 6
42200 - 2 2 6 2 2 6 2 2 6 46 46 46
42201 - 78 78 78 30 30 30 10 10 10 0 0 0
42202 - 0 0 0 0 0 0 0 0 0 0 0 0
42203 - 0 0 0 0 0 0 0 0 0 0 0 0
42204 - 0 0 0 0 0 0 0 0 0 0 0 0
42205 - 0 0 0 0 0 0 0 0 0 0 0 0
42206 - 0 0 0 0 0 0 0 0 0 0 0 0
42207 - 0 0 0 0 0 0 0 0 0 0 0 0
42208 - 0 0 0 0 0 0 0 0 0 0 0 0
42209 - 0 0 0 0 0 0 10 10 10 30 30 30
42210 - 74 74 74 58 58 58 2 2 6 42 42 42
42211 - 2 2 6 22 22 22 231 231 231 253 253 253
42212 -253 253 253 253 253 253 253 253 253 253 253 253
42213 -253 253 253 253 253 253 253 253 253 250 250 250
42214 -253 253 253 253 253 253 253 253 253 253 253 253
42215 -253 253 253 253 253 253 253 253 253 253 253 253
42216 -253 253 253 253 253 253 253 253 253 253 253 253
42217 -253 253 253 253 253 253 253 253 253 253 253 253
42218 -253 253 253 246 246 246 46 46 46 38 38 38
42219 - 42 42 42 14 14 14 38 38 38 14 14 14
42220 - 2 2 6 2 2 6 2 2 6 6 6 6
42221 - 86 86 86 46 46 46 14 14 14 0 0 0
42222 - 0 0 0 0 0 0 0 0 0 0 0 0
42223 - 0 0 0 0 0 0 0 0 0 0 0 0
42224 - 0 0 0 0 0 0 0 0 0 0 0 0
42225 - 0 0 0 0 0 0 0 0 0 0 0 0
42226 - 0 0 0 0 0 0 0 0 0 0 0 0
42227 - 0 0 0 0 0 0 0 0 0 0 0 0
42228 - 0 0 0 0 0 0 0 0 0 0 0 0
42229 - 0 0 0 6 6 6 14 14 14 42 42 42
42230 - 90 90 90 18 18 18 18 18 18 26 26 26
42231 - 2 2 6 116 116 116 253 253 253 253 253 253
42232 -253 253 253 253 253 253 253 253 253 253 253 253
42233 -253 253 253 253 253 253 250 250 250 238 238 238
42234 -253 253 253 253 253 253 253 253 253 253 253 253
42235 -253 253 253 253 253 253 253 253 253 253 253 253
42236 -253 253 253 253 253 253 253 253 253 253 253 253
42237 -253 253 253 253 253 253 253 253 253 253 253 253
42238 -253 253 253 253 253 253 94 94 94 6 6 6
42239 - 2 2 6 2 2 6 10 10 10 34 34 34
42240 - 2 2 6 2 2 6 2 2 6 2 2 6
42241 - 74 74 74 58 58 58 22 22 22 6 6 6
42242 - 0 0 0 0 0 0 0 0 0 0 0 0
42243 - 0 0 0 0 0 0 0 0 0 0 0 0
42244 - 0 0 0 0 0 0 0 0 0 0 0 0
42245 - 0 0 0 0 0 0 0 0 0 0 0 0
42246 - 0 0 0 0 0 0 0 0 0 0 0 0
42247 - 0 0 0 0 0 0 0 0 0 0 0 0
42248 - 0 0 0 0 0 0 0 0 0 0 0 0
42249 - 0 0 0 10 10 10 26 26 26 66 66 66
42250 - 82 82 82 2 2 6 38 38 38 6 6 6
42251 - 14 14 14 210 210 210 253 253 253 253 253 253
42252 -253 253 253 253 253 253 253 253 253 253 253 253
42253 -253 253 253 253 253 253 246 246 246 242 242 242
42254 -253 253 253 253 253 253 253 253 253 253 253 253
42255 -253 253 253 253 253 253 253 253 253 253 253 253
42256 -253 253 253 253 253 253 253 253 253 253 253 253
42257 -253 253 253 253 253 253 253 253 253 253 253 253
42258 -253 253 253 253 253 253 144 144 144 2 2 6
42259 - 2 2 6 2 2 6 2 2 6 46 46 46
42260 - 2 2 6 2 2 6 2 2 6 2 2 6
42261 - 42 42 42 74 74 74 30 30 30 10 10 10
42262 - 0 0 0 0 0 0 0 0 0 0 0 0
42263 - 0 0 0 0 0 0 0 0 0 0 0 0
42264 - 0 0 0 0 0 0 0 0 0 0 0 0
42265 - 0 0 0 0 0 0 0 0 0 0 0 0
42266 - 0 0 0 0 0 0 0 0 0 0 0 0
42267 - 0 0 0 0 0 0 0 0 0 0 0 0
42268 - 0 0 0 0 0 0 0 0 0 0 0 0
42269 - 6 6 6 14 14 14 42 42 42 90 90 90
42270 - 26 26 26 6 6 6 42 42 42 2 2 6
42271 - 74 74 74 250 250 250 253 253 253 253 253 253
42272 -253 253 253 253 253 253 253 253 253 253 253 253
42273 -253 253 253 253 253 253 242 242 242 242 242 242
42274 -253 253 253 253 253 253 253 253 253 253 253 253
42275 -253 253 253 253 253 253 253 253 253 253 253 253
42276 -253 253 253 253 253 253 253 253 253 253 253 253
42277 -253 253 253 253 253 253 253 253 253 253 253 253
42278 -253 253 253 253 253 253 182 182 182 2 2 6
42279 - 2 2 6 2 2 6 2 2 6 46 46 46
42280 - 2 2 6 2 2 6 2 2 6 2 2 6
42281 - 10 10 10 86 86 86 38 38 38 10 10 10
42282 - 0 0 0 0 0 0 0 0 0 0 0 0
42283 - 0 0 0 0 0 0 0 0 0 0 0 0
42284 - 0 0 0 0 0 0 0 0 0 0 0 0
42285 - 0 0 0 0 0 0 0 0 0 0 0 0
42286 - 0 0 0 0 0 0 0 0 0 0 0 0
42287 - 0 0 0 0 0 0 0 0 0 0 0 0
42288 - 0 0 0 0 0 0 0 0 0 0 0 0
42289 - 10 10 10 26 26 26 66 66 66 82 82 82
42290 - 2 2 6 22 22 22 18 18 18 2 2 6
42291 -149 149 149 253 253 253 253 253 253 253 253 253
42292 -253 253 253 253 253 253 253 253 253 253 253 253
42293 -253 253 253 253 253 253 234 234 234 242 242 242
42294 -253 253 253 253 253 253 253 253 253 253 253 253
42295 -253 253 253 253 253 253 253 253 253 253 253 253
42296 -253 253 253 253 253 253 253 253 253 253 253 253
42297 -253 253 253 253 253 253 253 253 253 253 253 253
42298 -253 253 253 253 253 253 206 206 206 2 2 6
42299 - 2 2 6 2 2 6 2 2 6 38 38 38
42300 - 2 2 6 2 2 6 2 2 6 2 2 6
42301 - 6 6 6 86 86 86 46 46 46 14 14 14
42302 - 0 0 0 0 0 0 0 0 0 0 0 0
42303 - 0 0 0 0 0 0 0 0 0 0 0 0
42304 - 0 0 0 0 0 0 0 0 0 0 0 0
42305 - 0 0 0 0 0 0 0 0 0 0 0 0
42306 - 0 0 0 0 0 0 0 0 0 0 0 0
42307 - 0 0 0 0 0 0 0 0 0 0 0 0
42308 - 0 0 0 0 0 0 0 0 0 6 6 6
42309 - 18 18 18 46 46 46 86 86 86 18 18 18
42310 - 2 2 6 34 34 34 10 10 10 6 6 6
42311 -210 210 210 253 253 253 253 253 253 253 253 253
42312 -253 253 253 253 253 253 253 253 253 253 253 253
42313 -253 253 253 253 253 253 234 234 234 242 242 242
42314 -253 253 253 253 253 253 253 253 253 253 253 253
42315 -253 253 253 253 253 253 253 253 253 253 253 253
42316 -253 253 253 253 253 253 253 253 253 253 253 253
42317 -253 253 253 253 253 253 253 253 253 253 253 253
42318 -253 253 253 253 253 253 221 221 221 6 6 6
42319 - 2 2 6 2 2 6 6 6 6 30 30 30
42320 - 2 2 6 2 2 6 2 2 6 2 2 6
42321 - 2 2 6 82 82 82 54 54 54 18 18 18
42322 - 6 6 6 0 0 0 0 0 0 0 0 0
42323 - 0 0 0 0 0 0 0 0 0 0 0 0
42324 - 0 0 0 0 0 0 0 0 0 0 0 0
42325 - 0 0 0 0 0 0 0 0 0 0 0 0
42326 - 0 0 0 0 0 0 0 0 0 0 0 0
42327 - 0 0 0 0 0 0 0 0 0 0 0 0
42328 - 0 0 0 0 0 0 0 0 0 10 10 10
42329 - 26 26 26 66 66 66 62 62 62 2 2 6
42330 - 2 2 6 38 38 38 10 10 10 26 26 26
42331 -238 238 238 253 253 253 253 253 253 253 253 253
42332 -253 253 253 253 253 253 253 253 253 253 253 253
42333 -253 253 253 253 253 253 231 231 231 238 238 238
42334 -253 253 253 253 253 253 253 253 253 253 253 253
42335 -253 253 253 253 253 253 253 253 253 253 253 253
42336 -253 253 253 253 253 253 253 253 253 253 253 253
42337 -253 253 253 253 253 253 253 253 253 253 253 253
42338 -253 253 253 253 253 253 231 231 231 6 6 6
42339 - 2 2 6 2 2 6 10 10 10 30 30 30
42340 - 2 2 6 2 2 6 2 2 6 2 2 6
42341 - 2 2 6 66 66 66 58 58 58 22 22 22
42342 - 6 6 6 0 0 0 0 0 0 0 0 0
42343 - 0 0 0 0 0 0 0 0 0 0 0 0
42344 - 0 0 0 0 0 0 0 0 0 0 0 0
42345 - 0 0 0 0 0 0 0 0 0 0 0 0
42346 - 0 0 0 0 0 0 0 0 0 0 0 0
42347 - 0 0 0 0 0 0 0 0 0 0 0 0
42348 - 0 0 0 0 0 0 0 0 0 10 10 10
42349 - 38 38 38 78 78 78 6 6 6 2 2 6
42350 - 2 2 6 46 46 46 14 14 14 42 42 42
42351 -246 246 246 253 253 253 253 253 253 253 253 253
42352 -253 253 253 253 253 253 253 253 253 253 253 253
42353 -253 253 253 253 253 253 231 231 231 242 242 242
42354 -253 253 253 253 253 253 253 253 253 253 253 253
42355 -253 253 253 253 253 253 253 253 253 253 253 253
42356 -253 253 253 253 253 253 253 253 253 253 253 253
42357 -253 253 253 253 253 253 253 253 253 253 253 253
42358 -253 253 253 253 253 253 234 234 234 10 10 10
42359 - 2 2 6 2 2 6 22 22 22 14 14 14
42360 - 2 2 6 2 2 6 2 2 6 2 2 6
42361 - 2 2 6 66 66 66 62 62 62 22 22 22
42362 - 6 6 6 0 0 0 0 0 0 0 0 0
42363 - 0 0 0 0 0 0 0 0 0 0 0 0
42364 - 0 0 0 0 0 0 0 0 0 0 0 0
42365 - 0 0 0 0 0 0 0 0 0 0 0 0
42366 - 0 0 0 0 0 0 0 0 0 0 0 0
42367 - 0 0 0 0 0 0 0 0 0 0 0 0
42368 - 0 0 0 0 0 0 6 6 6 18 18 18
42369 - 50 50 50 74 74 74 2 2 6 2 2 6
42370 - 14 14 14 70 70 70 34 34 34 62 62 62
42371 -250 250 250 253 253 253 253 253 253 253 253 253
42372 -253 253 253 253 253 253 253 253 253 253 253 253
42373 -253 253 253 253 253 253 231 231 231 246 246 246
42374 -253 253 253 253 253 253 253 253 253 253 253 253
42375 -253 253 253 253 253 253 253 253 253 253 253 253
42376 -253 253 253 253 253 253 253 253 253 253 253 253
42377 -253 253 253 253 253 253 253 253 253 253 253 253
42378 -253 253 253 253 253 253 234 234 234 14 14 14
42379 - 2 2 6 2 2 6 30 30 30 2 2 6
42380 - 2 2 6 2 2 6 2 2 6 2 2 6
42381 - 2 2 6 66 66 66 62 62 62 22 22 22
42382 - 6 6 6 0 0 0 0 0 0 0 0 0
42383 - 0 0 0 0 0 0 0 0 0 0 0 0
42384 - 0 0 0 0 0 0 0 0 0 0 0 0
42385 - 0 0 0 0 0 0 0 0 0 0 0 0
42386 - 0 0 0 0 0 0 0 0 0 0 0 0
42387 - 0 0 0 0 0 0 0 0 0 0 0 0
42388 - 0 0 0 0 0 0 6 6 6 18 18 18
42389 - 54 54 54 62 62 62 2 2 6 2 2 6
42390 - 2 2 6 30 30 30 46 46 46 70 70 70
42391 -250 250 250 253 253 253 253 253 253 253 253 253
42392 -253 253 253 253 253 253 253 253 253 253 253 253
42393 -253 253 253 253 253 253 231 231 231 246 246 246
42394 -253 253 253 253 253 253 253 253 253 253 253 253
42395 -253 253 253 253 253 253 253 253 253 253 253 253
42396 -253 253 253 253 253 253 253 253 253 253 253 253
42397 -253 253 253 253 253 253 253 253 253 253 253 253
42398 -253 253 253 253 253 253 226 226 226 10 10 10
42399 - 2 2 6 6 6 6 30 30 30 2 2 6
42400 - 2 2 6 2 2 6 2 2 6 2 2 6
42401 - 2 2 6 66 66 66 58 58 58 22 22 22
42402 - 6 6 6 0 0 0 0 0 0 0 0 0
42403 - 0 0 0 0 0 0 0 0 0 0 0 0
42404 - 0 0 0 0 0 0 0 0 0 0 0 0
42405 - 0 0 0 0 0 0 0 0 0 0 0 0
42406 - 0 0 0 0 0 0 0 0 0 0 0 0
42407 - 0 0 0 0 0 0 0 0 0 0 0 0
42408 - 0 0 0 0 0 0 6 6 6 22 22 22
42409 - 58 58 58 62 62 62 2 2 6 2 2 6
42410 - 2 2 6 2 2 6 30 30 30 78 78 78
42411 -250 250 250 253 253 253 253 253 253 253 253 253
42412 -253 253 253 253 253 253 253 253 253 253 253 253
42413 -253 253 253 253 253 253 231 231 231 246 246 246
42414 -253 253 253 253 253 253 253 253 253 253 253 253
42415 -253 253 253 253 253 253 253 253 253 253 253 253
42416 -253 253 253 253 253 253 253 253 253 253 253 253
42417 -253 253 253 253 253 253 253 253 253 253 253 253
42418 -253 253 253 253 253 253 206 206 206 2 2 6
42419 - 22 22 22 34 34 34 18 14 6 22 22 22
42420 - 26 26 26 18 18 18 6 6 6 2 2 6
42421 - 2 2 6 82 82 82 54 54 54 18 18 18
42422 - 6 6 6 0 0 0 0 0 0 0 0 0
42423 - 0 0 0 0 0 0 0 0 0 0 0 0
42424 - 0 0 0 0 0 0 0 0 0 0 0 0
42425 - 0 0 0 0 0 0 0 0 0 0 0 0
42426 - 0 0 0 0 0 0 0 0 0 0 0 0
42427 - 0 0 0 0 0 0 0 0 0 0 0 0
42428 - 0 0 0 0 0 0 6 6 6 26 26 26
42429 - 62 62 62 106 106 106 74 54 14 185 133 11
42430 -210 162 10 121 92 8 6 6 6 62 62 62
42431 -238 238 238 253 253 253 253 253 253 253 253 253
42432 -253 253 253 253 253 253 253 253 253 253 253 253
42433 -253 253 253 253 253 253 231 231 231 246 246 246
42434 -253 253 253 253 253 253 253 253 253 253 253 253
42435 -253 253 253 253 253 253 253 253 253 253 253 253
42436 -253 253 253 253 253 253 253 253 253 253 253 253
42437 -253 253 253 253 253 253 253 253 253 253 253 253
42438 -253 253 253 253 253 253 158 158 158 18 18 18
42439 - 14 14 14 2 2 6 2 2 6 2 2 6
42440 - 6 6 6 18 18 18 66 66 66 38 38 38
42441 - 6 6 6 94 94 94 50 50 50 18 18 18
42442 - 6 6 6 0 0 0 0 0 0 0 0 0
42443 - 0 0 0 0 0 0 0 0 0 0 0 0
42444 - 0 0 0 0 0 0 0 0 0 0 0 0
42445 - 0 0 0 0 0 0 0 0 0 0 0 0
42446 - 0 0 0 0 0 0 0 0 0 0 0 0
42447 - 0 0 0 0 0 0 0 0 0 6 6 6
42448 - 10 10 10 10 10 10 18 18 18 38 38 38
42449 - 78 78 78 142 134 106 216 158 10 242 186 14
42450 -246 190 14 246 190 14 156 118 10 10 10 10
42451 - 90 90 90 238 238 238 253 253 253 253 253 253
42452 -253 253 253 253 253 253 253 253 253 253 253 253
42453 -253 253 253 253 253 253 231 231 231 250 250 250
42454 -253 253 253 253 253 253 253 253 253 253 253 253
42455 -253 253 253 253 253 253 253 253 253 253 253 253
42456 -253 253 253 253 253 253 253 253 253 253 253 253
42457 -253 253 253 253 253 253 253 253 253 246 230 190
42458 -238 204 91 238 204 91 181 142 44 37 26 9
42459 - 2 2 6 2 2 6 2 2 6 2 2 6
42460 - 2 2 6 2 2 6 38 38 38 46 46 46
42461 - 26 26 26 106 106 106 54 54 54 18 18 18
42462 - 6 6 6 0 0 0 0 0 0 0 0 0
42463 - 0 0 0 0 0 0 0 0 0 0 0 0
42464 - 0 0 0 0 0 0 0 0 0 0 0 0
42465 - 0 0 0 0 0 0 0 0 0 0 0 0
42466 - 0 0 0 0 0 0 0 0 0 0 0 0
42467 - 0 0 0 6 6 6 14 14 14 22 22 22
42468 - 30 30 30 38 38 38 50 50 50 70 70 70
42469 -106 106 106 190 142 34 226 170 11 242 186 14
42470 -246 190 14 246 190 14 246 190 14 154 114 10
42471 - 6 6 6 74 74 74 226 226 226 253 253 253
42472 -253 253 253 253 253 253 253 253 253 253 253 253
42473 -253 253 253 253 253 253 231 231 231 250 250 250
42474 -253 253 253 253 253 253 253 253 253 253 253 253
42475 -253 253 253 253 253 253 253 253 253 253 253 253
42476 -253 253 253 253 253 253 253 253 253 253 253 253
42477 -253 253 253 253 253 253 253 253 253 228 184 62
42478 -241 196 14 241 208 19 232 195 16 38 30 10
42479 - 2 2 6 2 2 6 2 2 6 2 2 6
42480 - 2 2 6 6 6 6 30 30 30 26 26 26
42481 -203 166 17 154 142 90 66 66 66 26 26 26
42482 - 6 6 6 0 0 0 0 0 0 0 0 0
42483 - 0 0 0 0 0 0 0 0 0 0 0 0
42484 - 0 0 0 0 0 0 0 0 0 0 0 0
42485 - 0 0 0 0 0 0 0 0 0 0 0 0
42486 - 0 0 0 0 0 0 0 0 0 0 0 0
42487 - 6 6 6 18 18 18 38 38 38 58 58 58
42488 - 78 78 78 86 86 86 101 101 101 123 123 123
42489 -175 146 61 210 150 10 234 174 13 246 186 14
42490 -246 190 14 246 190 14 246 190 14 238 190 10
42491 -102 78 10 2 2 6 46 46 46 198 198 198
42492 -253 253 253 253 253 253 253 253 253 253 253 253
42493 -253 253 253 253 253 253 234 234 234 242 242 242
42494 -253 253 253 253 253 253 253 253 253 253 253 253
42495 -253 253 253 253 253 253 253 253 253 253 253 253
42496 -253 253 253 253 253 253 253 253 253 253 253 253
42497 -253 253 253 253 253 253 253 253 253 224 178 62
42498 -242 186 14 241 196 14 210 166 10 22 18 6
42499 - 2 2 6 2 2 6 2 2 6 2 2 6
42500 - 2 2 6 2 2 6 6 6 6 121 92 8
42501 -238 202 15 232 195 16 82 82 82 34 34 34
42502 - 10 10 10 0 0 0 0 0 0 0 0 0
42503 - 0 0 0 0 0 0 0 0 0 0 0 0
42504 - 0 0 0 0 0 0 0 0 0 0 0 0
42505 - 0 0 0 0 0 0 0 0 0 0 0 0
42506 - 0 0 0 0 0 0 0 0 0 0 0 0
42507 - 14 14 14 38 38 38 70 70 70 154 122 46
42508 -190 142 34 200 144 11 197 138 11 197 138 11
42509 -213 154 11 226 170 11 242 186 14 246 190 14
42510 -246 190 14 246 190 14 246 190 14 246 190 14
42511 -225 175 15 46 32 6 2 2 6 22 22 22
42512 -158 158 158 250 250 250 253 253 253 253 253 253
42513 -253 253 253 253 253 253 253 253 253 253 253 253
42514 -253 253 253 253 253 253 253 253 253 253 253 253
42515 -253 253 253 253 253 253 253 253 253 253 253 253
42516 -253 253 253 253 253 253 253 253 253 253 253 253
42517 -253 253 253 250 250 250 242 242 242 224 178 62
42518 -239 182 13 236 186 11 213 154 11 46 32 6
42519 - 2 2 6 2 2 6 2 2 6 2 2 6
42520 - 2 2 6 2 2 6 61 42 6 225 175 15
42521 -238 190 10 236 186 11 112 100 78 42 42 42
42522 - 14 14 14 0 0 0 0 0 0 0 0 0
42523 - 0 0 0 0 0 0 0 0 0 0 0 0
42524 - 0 0 0 0 0 0 0 0 0 0 0 0
42525 - 0 0 0 0 0 0 0 0 0 0 0 0
42526 - 0 0 0 0 0 0 0 0 0 6 6 6
42527 - 22 22 22 54 54 54 154 122 46 213 154 11
42528 -226 170 11 230 174 11 226 170 11 226 170 11
42529 -236 178 12 242 186 14 246 190 14 246 190 14
42530 -246 190 14 246 190 14 246 190 14 246 190 14
42531 -241 196 14 184 144 12 10 10 10 2 2 6
42532 - 6 6 6 116 116 116 242 242 242 253 253 253
42533 -253 253 253 253 253 253 253 253 253 253 253 253
42534 -253 253 253 253 253 253 253 253 253 253 253 253
42535 -253 253 253 253 253 253 253 253 253 253 253 253
42536 -253 253 253 253 253 253 253 253 253 253 253 253
42537 -253 253 253 231 231 231 198 198 198 214 170 54
42538 -236 178 12 236 178 12 210 150 10 137 92 6
42539 - 18 14 6 2 2 6 2 2 6 2 2 6
42540 - 6 6 6 70 47 6 200 144 11 236 178 12
42541 -239 182 13 239 182 13 124 112 88 58 58 58
42542 - 22 22 22 6 6 6 0 0 0 0 0 0
42543 - 0 0 0 0 0 0 0 0 0 0 0 0
42544 - 0 0 0 0 0 0 0 0 0 0 0 0
42545 - 0 0 0 0 0 0 0 0 0 0 0 0
42546 - 0 0 0 0 0 0 0 0 0 10 10 10
42547 - 30 30 30 70 70 70 180 133 36 226 170 11
42548 -239 182 13 242 186 14 242 186 14 246 186 14
42549 -246 190 14 246 190 14 246 190 14 246 190 14
42550 -246 190 14 246 190 14 246 190 14 246 190 14
42551 -246 190 14 232 195 16 98 70 6 2 2 6
42552 - 2 2 6 2 2 6 66 66 66 221 221 221
42553 -253 253 253 253 253 253 253 253 253 253 253 253
42554 -253 253 253 253 253 253 253 253 253 253 253 253
42555 -253 253 253 253 253 253 253 253 253 253 253 253
42556 -253 253 253 253 253 253 253 253 253 253 253 253
42557 -253 253 253 206 206 206 198 198 198 214 166 58
42558 -230 174 11 230 174 11 216 158 10 192 133 9
42559 -163 110 8 116 81 8 102 78 10 116 81 8
42560 -167 114 7 197 138 11 226 170 11 239 182 13
42561 -242 186 14 242 186 14 162 146 94 78 78 78
42562 - 34 34 34 14 14 14 6 6 6 0 0 0
42563 - 0 0 0 0 0 0 0 0 0 0 0 0
42564 - 0 0 0 0 0 0 0 0 0 0 0 0
42565 - 0 0 0 0 0 0 0 0 0 0 0 0
42566 - 0 0 0 0 0 0 0 0 0 6 6 6
42567 - 30 30 30 78 78 78 190 142 34 226 170 11
42568 -239 182 13 246 190 14 246 190 14 246 190 14
42569 -246 190 14 246 190 14 246 190 14 246 190 14
42570 -246 190 14 246 190 14 246 190 14 246 190 14
42571 -246 190 14 241 196 14 203 166 17 22 18 6
42572 - 2 2 6 2 2 6 2 2 6 38 38 38
42573 -218 218 218 253 253 253 253 253 253 253 253 253
42574 -253 253 253 253 253 253 253 253 253 253 253 253
42575 -253 253 253 253 253 253 253 253 253 253 253 253
42576 -253 253 253 253 253 253 253 253 253 253 253 253
42577 -250 250 250 206 206 206 198 198 198 202 162 69
42578 -226 170 11 236 178 12 224 166 10 210 150 10
42579 -200 144 11 197 138 11 192 133 9 197 138 11
42580 -210 150 10 226 170 11 242 186 14 246 190 14
42581 -246 190 14 246 186 14 225 175 15 124 112 88
42582 - 62 62 62 30 30 30 14 14 14 6 6 6
42583 - 0 0 0 0 0 0 0 0 0 0 0 0
42584 - 0 0 0 0 0 0 0 0 0 0 0 0
42585 - 0 0 0 0 0 0 0 0 0 0 0 0
42586 - 0 0 0 0 0 0 0 0 0 10 10 10
42587 - 30 30 30 78 78 78 174 135 50 224 166 10
42588 -239 182 13 246 190 14 246 190 14 246 190 14
42589 -246 190 14 246 190 14 246 190 14 246 190 14
42590 -246 190 14 246 190 14 246 190 14 246 190 14
42591 -246 190 14 246 190 14 241 196 14 139 102 15
42592 - 2 2 6 2 2 6 2 2 6 2 2 6
42593 - 78 78 78 250 250 250 253 253 253 253 253 253
42594 -253 253 253 253 253 253 253 253 253 253 253 253
42595 -253 253 253 253 253 253 253 253 253 253 253 253
42596 -253 253 253 253 253 253 253 253 253 253 253 253
42597 -250 250 250 214 214 214 198 198 198 190 150 46
42598 -219 162 10 236 178 12 234 174 13 224 166 10
42599 -216 158 10 213 154 11 213 154 11 216 158 10
42600 -226 170 11 239 182 13 246 190 14 246 190 14
42601 -246 190 14 246 190 14 242 186 14 206 162 42
42602 -101 101 101 58 58 58 30 30 30 14 14 14
42603 - 6 6 6 0 0 0 0 0 0 0 0 0
42604 - 0 0 0 0 0 0 0 0 0 0 0 0
42605 - 0 0 0 0 0 0 0 0 0 0 0 0
42606 - 0 0 0 0 0 0 0 0 0 10 10 10
42607 - 30 30 30 74 74 74 174 135 50 216 158 10
42608 -236 178 12 246 190 14 246 190 14 246 190 14
42609 -246 190 14 246 190 14 246 190 14 246 190 14
42610 -246 190 14 246 190 14 246 190 14 246 190 14
42611 -246 190 14 246 190 14 241 196 14 226 184 13
42612 - 61 42 6 2 2 6 2 2 6 2 2 6
42613 - 22 22 22 238 238 238 253 253 253 253 253 253
42614 -253 253 253 253 253 253 253 253 253 253 253 253
42615 -253 253 253 253 253 253 253 253 253 253 253 253
42616 -253 253 253 253 253 253 253 253 253 253 253 253
42617 -253 253 253 226 226 226 187 187 187 180 133 36
42618 -216 158 10 236 178 12 239 182 13 236 178 12
42619 -230 174 11 226 170 11 226 170 11 230 174 11
42620 -236 178 12 242 186 14 246 190 14 246 190 14
42621 -246 190 14 246 190 14 246 186 14 239 182 13
42622 -206 162 42 106 106 106 66 66 66 34 34 34
42623 - 14 14 14 6 6 6 0 0 0 0 0 0
42624 - 0 0 0 0 0 0 0 0 0 0 0 0
42625 - 0 0 0 0 0 0 0 0 0 0 0 0
42626 - 0 0 0 0 0 0 0 0 0 6 6 6
42627 - 26 26 26 70 70 70 163 133 67 213 154 11
42628 -236 178 12 246 190 14 246 190 14 246 190 14
42629 -246 190 14 246 190 14 246 190 14 246 190 14
42630 -246 190 14 246 190 14 246 190 14 246 190 14
42631 -246 190 14 246 190 14 246 190 14 241 196 14
42632 -190 146 13 18 14 6 2 2 6 2 2 6
42633 - 46 46 46 246 246 246 253 253 253 253 253 253
42634 -253 253 253 253 253 253 253 253 253 253 253 253
42635 -253 253 253 253 253 253 253 253 253 253 253 253
42636 -253 253 253 253 253 253 253 253 253 253 253 253
42637 -253 253 253 221 221 221 86 86 86 156 107 11
42638 -216 158 10 236 178 12 242 186 14 246 186 14
42639 -242 186 14 239 182 13 239 182 13 242 186 14
42640 -242 186 14 246 186 14 246 190 14 246 190 14
42641 -246 190 14 246 190 14 246 190 14 246 190 14
42642 -242 186 14 225 175 15 142 122 72 66 66 66
42643 - 30 30 30 10 10 10 0 0 0 0 0 0
42644 - 0 0 0 0 0 0 0 0 0 0 0 0
42645 - 0 0 0 0 0 0 0 0 0 0 0 0
42646 - 0 0 0 0 0 0 0 0 0 6 6 6
42647 - 26 26 26 70 70 70 163 133 67 210 150 10
42648 -236 178 12 246 190 14 246 190 14 246 190 14
42649 -246 190 14 246 190 14 246 190 14 246 190 14
42650 -246 190 14 246 190 14 246 190 14 246 190 14
42651 -246 190 14 246 190 14 246 190 14 246 190 14
42652 -232 195 16 121 92 8 34 34 34 106 106 106
42653 -221 221 221 253 253 253 253 253 253 253 253 253
42654 -253 253 253 253 253 253 253 253 253 253 253 253
42655 -253 253 253 253 253 253 253 253 253 253 253 253
42656 -253 253 253 253 253 253 253 253 253 253 253 253
42657 -242 242 242 82 82 82 18 14 6 163 110 8
42658 -216 158 10 236 178 12 242 186 14 246 190 14
42659 -246 190 14 246 190 14 246 190 14 246 190 14
42660 -246 190 14 246 190 14 246 190 14 246 190 14
42661 -246 190 14 246 190 14 246 190 14 246 190 14
42662 -246 190 14 246 190 14 242 186 14 163 133 67
42663 - 46 46 46 18 18 18 6 6 6 0 0 0
42664 - 0 0 0 0 0 0 0 0 0 0 0 0
42665 - 0 0 0 0 0 0 0 0 0 0 0 0
42666 - 0 0 0 0 0 0 0 0 0 10 10 10
42667 - 30 30 30 78 78 78 163 133 67 210 150 10
42668 -236 178 12 246 186 14 246 190 14 246 190 14
42669 -246 190 14 246 190 14 246 190 14 246 190 14
42670 -246 190 14 246 190 14 246 190 14 246 190 14
42671 -246 190 14 246 190 14 246 190 14 246 190 14
42672 -241 196 14 215 174 15 190 178 144 253 253 253
42673 -253 253 253 253 253 253 253 253 253 253 253 253
42674 -253 253 253 253 253 253 253 253 253 253 253 253
42675 -253 253 253 253 253 253 253 253 253 253 253 253
42676 -253 253 253 253 253 253 253 253 253 218 218 218
42677 - 58 58 58 2 2 6 22 18 6 167 114 7
42678 -216 158 10 236 178 12 246 186 14 246 190 14
42679 -246 190 14 246 190 14 246 190 14 246 190 14
42680 -246 190 14 246 190 14 246 190 14 246 190 14
42681 -246 190 14 246 190 14 246 190 14 246 190 14
42682 -246 190 14 246 186 14 242 186 14 190 150 46
42683 - 54 54 54 22 22 22 6 6 6 0 0 0
42684 - 0 0 0 0 0 0 0 0 0 0 0 0
42685 - 0 0 0 0 0 0 0 0 0 0 0 0
42686 - 0 0 0 0 0 0 0 0 0 14 14 14
42687 - 38 38 38 86 86 86 180 133 36 213 154 11
42688 -236 178 12 246 186 14 246 190 14 246 190 14
42689 -246 190 14 246 190 14 246 190 14 246 190 14
42690 -246 190 14 246 190 14 246 190 14 246 190 14
42691 -246 190 14 246 190 14 246 190 14 246 190 14
42692 -246 190 14 232 195 16 190 146 13 214 214 214
42693 -253 253 253 253 253 253 253 253 253 253 253 253
42694 -253 253 253 253 253 253 253 253 253 253 253 253
42695 -253 253 253 253 253 253 253 253 253 253 253 253
42696 -253 253 253 250 250 250 170 170 170 26 26 26
42697 - 2 2 6 2 2 6 37 26 9 163 110 8
42698 -219 162 10 239 182 13 246 186 14 246 190 14
42699 -246 190 14 246 190 14 246 190 14 246 190 14
42700 -246 190 14 246 190 14 246 190 14 246 190 14
42701 -246 190 14 246 190 14 246 190 14 246 190 14
42702 -246 186 14 236 178 12 224 166 10 142 122 72
42703 - 46 46 46 18 18 18 6 6 6 0 0 0
42704 - 0 0 0 0 0 0 0 0 0 0 0 0
42705 - 0 0 0 0 0 0 0 0 0 0 0 0
42706 - 0 0 0 0 0 0 6 6 6 18 18 18
42707 - 50 50 50 109 106 95 192 133 9 224 166 10
42708 -242 186 14 246 190 14 246 190 14 246 190 14
42709 -246 190 14 246 190 14 246 190 14 246 190 14
42710 -246 190 14 246 190 14 246 190 14 246 190 14
42711 -246 190 14 246 190 14 246 190 14 246 190 14
42712 -242 186 14 226 184 13 210 162 10 142 110 46
42713 -226 226 226 253 253 253 253 253 253 253 253 253
42714 -253 253 253 253 253 253 253 253 253 253 253 253
42715 -253 253 253 253 253 253 253 253 253 253 253 253
42716 -198 198 198 66 66 66 2 2 6 2 2 6
42717 - 2 2 6 2 2 6 50 34 6 156 107 11
42718 -219 162 10 239 182 13 246 186 14 246 190 14
42719 -246 190 14 246 190 14 246 190 14 246 190 14
42720 -246 190 14 246 190 14 246 190 14 246 190 14
42721 -246 190 14 246 190 14 246 190 14 242 186 14
42722 -234 174 13 213 154 11 154 122 46 66 66 66
42723 - 30 30 30 10 10 10 0 0 0 0 0 0
42724 - 0 0 0 0 0 0 0 0 0 0 0 0
42725 - 0 0 0 0 0 0 0 0 0 0 0 0
42726 - 0 0 0 0 0 0 6 6 6 22 22 22
42727 - 58 58 58 154 121 60 206 145 10 234 174 13
42728 -242 186 14 246 186 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 246 190 14 246 190 14
42731 -246 190 14 246 190 14 246 190 14 246 190 14
42732 -246 186 14 236 178 12 210 162 10 163 110 8
42733 - 61 42 6 138 138 138 218 218 218 250 250 250
42734 -253 253 253 253 253 253 253 253 253 250 250 250
42735 -242 242 242 210 210 210 144 144 144 66 66 66
42736 - 6 6 6 2 2 6 2 2 6 2 2 6
42737 - 2 2 6 2 2 6 61 42 6 163 110 8
42738 -216 158 10 236 178 12 246 190 14 246 190 14
42739 -246 190 14 246 190 14 246 190 14 246 190 14
42740 -246 190 14 246 190 14 246 190 14 246 190 14
42741 -246 190 14 239 182 13 230 174 11 216 158 10
42742 -190 142 34 124 112 88 70 70 70 38 38 38
42743 - 18 18 18 6 6 6 0 0 0 0 0 0
42744 - 0 0 0 0 0 0 0 0 0 0 0 0
42745 - 0 0 0 0 0 0 0 0 0 0 0 0
42746 - 0 0 0 0 0 0 6 6 6 22 22 22
42747 - 62 62 62 168 124 44 206 145 10 224 166 10
42748 -236 178 12 239 182 13 242 186 14 242 186 14
42749 -246 186 14 246 190 14 246 190 14 246 190 14
42750 -246 190 14 246 190 14 246 190 14 246 190 14
42751 -246 190 14 246 190 14 246 190 14 246 190 14
42752 -246 190 14 236 178 12 216 158 10 175 118 6
42753 - 80 54 7 2 2 6 6 6 6 30 30 30
42754 - 54 54 54 62 62 62 50 50 50 38 38 38
42755 - 14 14 14 2 2 6 2 2 6 2 2 6
42756 - 2 2 6 2 2 6 2 2 6 2 2 6
42757 - 2 2 6 6 6 6 80 54 7 167 114 7
42758 -213 154 11 236 178 12 246 190 14 246 190 14
42759 -246 190 14 246 190 14 246 190 14 246 190 14
42760 -246 190 14 242 186 14 239 182 13 239 182 13
42761 -230 174 11 210 150 10 174 135 50 124 112 88
42762 - 82 82 82 54 54 54 34 34 34 18 18 18
42763 - 6 6 6 0 0 0 0 0 0 0 0 0
42764 - 0 0 0 0 0 0 0 0 0 0 0 0
42765 - 0 0 0 0 0 0 0 0 0 0 0 0
42766 - 0 0 0 0 0 0 6 6 6 18 18 18
42767 - 50 50 50 158 118 36 192 133 9 200 144 11
42768 -216 158 10 219 162 10 224 166 10 226 170 11
42769 -230 174 11 236 178 12 239 182 13 239 182 13
42770 -242 186 14 246 186 14 246 190 14 246 190 14
42771 -246 190 14 246 190 14 246 190 14 246 190 14
42772 -246 186 14 230 174 11 210 150 10 163 110 8
42773 -104 69 6 10 10 10 2 2 6 2 2 6
42774 - 2 2 6 2 2 6 2 2 6 2 2 6
42775 - 2 2 6 2 2 6 2 2 6 2 2 6
42776 - 2 2 6 2 2 6 2 2 6 2 2 6
42777 - 2 2 6 6 6 6 91 60 6 167 114 7
42778 -206 145 10 230 174 11 242 186 14 246 190 14
42779 -246 190 14 246 190 14 246 186 14 242 186 14
42780 -239 182 13 230 174 11 224 166 10 213 154 11
42781 -180 133 36 124 112 88 86 86 86 58 58 58
42782 - 38 38 38 22 22 22 10 10 10 6 6 6
42783 - 0 0 0 0 0 0 0 0 0 0 0 0
42784 - 0 0 0 0 0 0 0 0 0 0 0 0
42785 - 0 0 0 0 0 0 0 0 0 0 0 0
42786 - 0 0 0 0 0 0 0 0 0 14 14 14
42787 - 34 34 34 70 70 70 138 110 50 158 118 36
42788 -167 114 7 180 123 7 192 133 9 197 138 11
42789 -200 144 11 206 145 10 213 154 11 219 162 10
42790 -224 166 10 230 174 11 239 182 13 242 186 14
42791 -246 186 14 246 186 14 246 186 14 246 186 14
42792 -239 182 13 216 158 10 185 133 11 152 99 6
42793 -104 69 6 18 14 6 2 2 6 2 2 6
42794 - 2 2 6 2 2 6 2 2 6 2 2 6
42795 - 2 2 6 2 2 6 2 2 6 2 2 6
42796 - 2 2 6 2 2 6 2 2 6 2 2 6
42797 - 2 2 6 6 6 6 80 54 7 152 99 6
42798 -192 133 9 219 162 10 236 178 12 239 182 13
42799 -246 186 14 242 186 14 239 182 13 236 178 12
42800 -224 166 10 206 145 10 192 133 9 154 121 60
42801 - 94 94 94 62 62 62 42 42 42 22 22 22
42802 - 14 14 14 6 6 6 0 0 0 0 0 0
42803 - 0 0 0 0 0 0 0 0 0 0 0 0
42804 - 0 0 0 0 0 0 0 0 0 0 0 0
42805 - 0 0 0 0 0 0 0 0 0 0 0 0
42806 - 0 0 0 0 0 0 0 0 0 6 6 6
42807 - 18 18 18 34 34 34 58 58 58 78 78 78
42808 -101 98 89 124 112 88 142 110 46 156 107 11
42809 -163 110 8 167 114 7 175 118 6 180 123 7
42810 -185 133 11 197 138 11 210 150 10 219 162 10
42811 -226 170 11 236 178 12 236 178 12 234 174 13
42812 -219 162 10 197 138 11 163 110 8 130 83 6
42813 - 91 60 6 10 10 10 2 2 6 2 2 6
42814 - 18 18 18 38 38 38 38 38 38 38 38 38
42815 - 38 38 38 38 38 38 38 38 38 38 38 38
42816 - 38 38 38 38 38 38 26 26 26 2 2 6
42817 - 2 2 6 6 6 6 70 47 6 137 92 6
42818 -175 118 6 200 144 11 219 162 10 230 174 11
42819 -234 174 13 230 174 11 219 162 10 210 150 10
42820 -192 133 9 163 110 8 124 112 88 82 82 82
42821 - 50 50 50 30 30 30 14 14 14 6 6 6
42822 - 0 0 0 0 0 0 0 0 0 0 0 0
42823 - 0 0 0 0 0 0 0 0 0 0 0 0
42824 - 0 0 0 0 0 0 0 0 0 0 0 0
42825 - 0 0 0 0 0 0 0 0 0 0 0 0
42826 - 0 0 0 0 0 0 0 0 0 0 0 0
42827 - 6 6 6 14 14 14 22 22 22 34 34 34
42828 - 42 42 42 58 58 58 74 74 74 86 86 86
42829 -101 98 89 122 102 70 130 98 46 121 87 25
42830 -137 92 6 152 99 6 163 110 8 180 123 7
42831 -185 133 11 197 138 11 206 145 10 200 144 11
42832 -180 123 7 156 107 11 130 83 6 104 69 6
42833 - 50 34 6 54 54 54 110 110 110 101 98 89
42834 - 86 86 86 82 82 82 78 78 78 78 78 78
42835 - 78 78 78 78 78 78 78 78 78 78 78 78
42836 - 78 78 78 82 82 82 86 86 86 94 94 94
42837 -106 106 106 101 101 101 86 66 34 124 80 6
42838 -156 107 11 180 123 7 192 133 9 200 144 11
42839 -206 145 10 200 144 11 192 133 9 175 118 6
42840 -139 102 15 109 106 95 70 70 70 42 42 42
42841 - 22 22 22 10 10 10 0 0 0 0 0 0
42842 - 0 0 0 0 0 0 0 0 0 0 0 0
42843 - 0 0 0 0 0 0 0 0 0 0 0 0
42844 - 0 0 0 0 0 0 0 0 0 0 0 0
42845 - 0 0 0 0 0 0 0 0 0 0 0 0
42846 - 0 0 0 0 0 0 0 0 0 0 0 0
42847 - 0 0 0 0 0 0 6 6 6 10 10 10
42848 - 14 14 14 22 22 22 30 30 30 38 38 38
42849 - 50 50 50 62 62 62 74 74 74 90 90 90
42850 -101 98 89 112 100 78 121 87 25 124 80 6
42851 -137 92 6 152 99 6 152 99 6 152 99 6
42852 -138 86 6 124 80 6 98 70 6 86 66 30
42853 -101 98 89 82 82 82 58 58 58 46 46 46
42854 - 38 38 38 34 34 34 34 34 34 34 34 34
42855 - 34 34 34 34 34 34 34 34 34 34 34 34
42856 - 34 34 34 34 34 34 38 38 38 42 42 42
42857 - 54 54 54 82 82 82 94 86 76 91 60 6
42858 -134 86 6 156 107 11 167 114 7 175 118 6
42859 -175 118 6 167 114 7 152 99 6 121 87 25
42860 -101 98 89 62 62 62 34 34 34 18 18 18
42861 - 6 6 6 0 0 0 0 0 0 0 0 0
42862 - 0 0 0 0 0 0 0 0 0 0 0 0
42863 - 0 0 0 0 0 0 0 0 0 0 0 0
42864 - 0 0 0 0 0 0 0 0 0 0 0 0
42865 - 0 0 0 0 0 0 0 0 0 0 0 0
42866 - 0 0 0 0 0 0 0 0 0 0 0 0
42867 - 0 0 0 0 0 0 0 0 0 0 0 0
42868 - 0 0 0 6 6 6 6 6 6 10 10 10
42869 - 18 18 18 22 22 22 30 30 30 42 42 42
42870 - 50 50 50 66 66 66 86 86 86 101 98 89
42871 -106 86 58 98 70 6 104 69 6 104 69 6
42872 -104 69 6 91 60 6 82 62 34 90 90 90
42873 - 62 62 62 38 38 38 22 22 22 14 14 14
42874 - 10 10 10 10 10 10 10 10 10 10 10 10
42875 - 10 10 10 10 10 10 6 6 6 10 10 10
42876 - 10 10 10 10 10 10 10 10 10 14 14 14
42877 - 22 22 22 42 42 42 70 70 70 89 81 66
42878 - 80 54 7 104 69 6 124 80 6 137 92 6
42879 -134 86 6 116 81 8 100 82 52 86 86 86
42880 - 58 58 58 30 30 30 14 14 14 6 6 6
42881 - 0 0 0 0 0 0 0 0 0 0 0 0
42882 - 0 0 0 0 0 0 0 0 0 0 0 0
42883 - 0 0 0 0 0 0 0 0 0 0 0 0
42884 - 0 0 0 0 0 0 0 0 0 0 0 0
42885 - 0 0 0 0 0 0 0 0 0 0 0 0
42886 - 0 0 0 0 0 0 0 0 0 0 0 0
42887 - 0 0 0 0 0 0 0 0 0 0 0 0
42888 - 0 0 0 0 0 0 0 0 0 0 0 0
42889 - 0 0 0 6 6 6 10 10 10 14 14 14
42890 - 18 18 18 26 26 26 38 38 38 54 54 54
42891 - 70 70 70 86 86 86 94 86 76 89 81 66
42892 - 89 81 66 86 86 86 74 74 74 50 50 50
42893 - 30 30 30 14 14 14 6 6 6 0 0 0
42894 - 0 0 0 0 0 0 0 0 0 0 0 0
42895 - 0 0 0 0 0 0 0 0 0 0 0 0
42896 - 0 0 0 0 0 0 0 0 0 0 0 0
42897 - 6 6 6 18 18 18 34 34 34 58 58 58
42898 - 82 82 82 89 81 66 89 81 66 89 81 66
42899 - 94 86 66 94 86 76 74 74 74 50 50 50
42900 - 26 26 26 14 14 14 6 6 6 0 0 0
42901 - 0 0 0 0 0 0 0 0 0 0 0 0
42902 - 0 0 0 0 0 0 0 0 0 0 0 0
42903 - 0 0 0 0 0 0 0 0 0 0 0 0
42904 - 0 0 0 0 0 0 0 0 0 0 0 0
42905 - 0 0 0 0 0 0 0 0 0 0 0 0
42906 - 0 0 0 0 0 0 0 0 0 0 0 0
42907 - 0 0 0 0 0 0 0 0 0 0 0 0
42908 - 0 0 0 0 0 0 0 0 0 0 0 0
42909 - 0 0 0 0 0 0 0 0 0 0 0 0
42910 - 6 6 6 6 6 6 14 14 14 18 18 18
42911 - 30 30 30 38 38 38 46 46 46 54 54 54
42912 - 50 50 50 42 42 42 30 30 30 18 18 18
42913 - 10 10 10 0 0 0 0 0 0 0 0 0
42914 - 0 0 0 0 0 0 0 0 0 0 0 0
42915 - 0 0 0 0 0 0 0 0 0 0 0 0
42916 - 0 0 0 0 0 0 0 0 0 0 0 0
42917 - 0 0 0 6 6 6 14 14 14 26 26 26
42918 - 38 38 38 50 50 50 58 58 58 58 58 58
42919 - 54 54 54 42 42 42 30 30 30 18 18 18
42920 - 10 10 10 0 0 0 0 0 0 0 0 0
42921 - 0 0 0 0 0 0 0 0 0 0 0 0
42922 - 0 0 0 0 0 0 0 0 0 0 0 0
42923 - 0 0 0 0 0 0 0 0 0 0 0 0
42924 - 0 0 0 0 0 0 0 0 0 0 0 0
42925 - 0 0 0 0 0 0 0 0 0 0 0 0
42926 - 0 0 0 0 0 0 0 0 0 0 0 0
42927 - 0 0 0 0 0 0 0 0 0 0 0 0
42928 - 0 0 0 0 0 0 0 0 0 0 0 0
42929 - 0 0 0 0 0 0 0 0 0 0 0 0
42930 - 0 0 0 0 0 0 0 0 0 6 6 6
42931 - 6 6 6 10 10 10 14 14 14 18 18 18
42932 - 18 18 18 14 14 14 10 10 10 6 6 6
42933 - 0 0 0 0 0 0 0 0 0 0 0 0
42934 - 0 0 0 0 0 0 0 0 0 0 0 0
42935 - 0 0 0 0 0 0 0 0 0 0 0 0
42936 - 0 0 0 0 0 0 0 0 0 0 0 0
42937 - 0 0 0 0 0 0 0 0 0 6 6 6
42938 - 14 14 14 18 18 18 22 22 22 22 22 22
42939 - 18 18 18 14 14 14 10 10 10 6 6 6
42940 - 0 0 0 0 0 0 0 0 0 0 0 0
42941 - 0 0 0 0 0 0 0 0 0 0 0 0
42942 - 0 0 0 0 0 0 0 0 0 0 0 0
42943 - 0 0 0 0 0 0 0 0 0 0 0 0
42944 - 0 0 0 0 0 0 0 0 0 0 0 0
42945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42953 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42954 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42958 +4 4 4 4 4 4
42959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42967 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42972 +4 4 4 4 4 4
42973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42986 +4 4 4 4 4 4
42987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43000 +4 4 4 4 4 4
43001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43014 +4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
43027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43028 +4 4 4 4 4 4
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 3 3 3 0 0 0 0 0 0
43034 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 1 1 1 0 0 0
43039 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43040 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
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 2 2 2 0 0 0 3 4 3 26 28 28
43048 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
43049 +5 5 5 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 3 3 3 0 0 0 1 1 1 6 6 6
43053 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
43054 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
43055 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43056 +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 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
43062 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
43063 +0 0 0 3 3 3 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 0 0 0 4 4 4 41 54 63 125 124 125
43067 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
43068 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
43069 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
43070 +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 5 5 5 5 5 5 2 2 2 0 0 0
43075 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
43076 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
43077 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
43080 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
43081 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
43082 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
43083 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
43084 +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 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
43089 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
43090 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
43091 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
43092 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43093 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
43094 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
43095 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
43096 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
43097 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
43098 +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 4 4 4 4 4 4 5 5 5
43102 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
43103 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
43104 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
43105 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
43106 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
43107 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
43108 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
43109 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
43110 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
43111 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
43112 +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 4 4 4 4 4 4 5 5 5 3 3 3
43116 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
43117 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
43118 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
43119 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
43120 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
43121 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
43122 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
43123 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
43124 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
43125 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
43126 +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 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
43130 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
43131 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
43132 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
43133 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
43134 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
43135 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
43136 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
43137 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
43138 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
43139 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
43140 +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 4 4 4 4 4 4 4 4 4 4 4 4
43143 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
43144 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
43145 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
43146 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
43147 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
43148 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
43149 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
43150 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
43151 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
43152 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
43153 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43154 +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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43157 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
43158 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
43159 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
43160 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
43161 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
43162 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
43163 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
43164 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
43165 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
43166 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
43167 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
43168 +4 4 4 4 4 4
43169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43170 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
43171 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
43172 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
43173 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
43174 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
43175 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
43176 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
43177 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
43178 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
43179 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
43180 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
43181 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
43182 +4 4 4 4 4 4
43183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43184 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
43185 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
43186 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
43187 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43188 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
43189 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
43190 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
43191 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
43192 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
43193 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
43194 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
43195 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
43196 +0 0 0 4 4 4
43197 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43198 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
43199 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
43200 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
43201 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
43202 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
43203 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
43204 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
43205 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
43206 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
43207 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
43208 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
43209 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
43210 +2 0 0 0 0 0
43211 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
43212 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
43213 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
43214 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
43215 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
43216 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
43217 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
43218 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
43219 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
43220 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
43221 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
43222 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
43223 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
43224 +37 38 37 0 0 0
43225 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43226 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
43227 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
43228 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
43229 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
43230 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
43231 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
43232 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
43233 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
43234 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
43235 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
43236 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
43237 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
43238 +85 115 134 4 0 0
43239 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
43240 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
43241 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
43242 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
43243 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
43244 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
43245 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
43246 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
43247 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
43248 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
43249 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
43250 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
43251 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
43252 +60 73 81 4 0 0
43253 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
43254 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
43255 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
43256 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
43257 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
43258 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
43259 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
43260 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
43261 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
43262 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
43263 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
43264 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
43265 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
43266 +16 19 21 4 0 0
43267 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
43268 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
43269 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
43270 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
43271 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
43272 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
43273 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
43274 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
43275 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
43276 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
43277 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
43278 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
43279 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
43280 +4 0 0 4 3 3
43281 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
43282 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
43283 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
43284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
43285 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
43286 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
43287 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
43288 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
43289 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
43290 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
43291 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
43292 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
43293 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
43294 +3 2 2 4 4 4
43295 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
43296 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
43297 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
43298 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43299 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
43300 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
43301 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
43302 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
43303 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
43304 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
43305 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
43306 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
43307 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
43308 +4 4 4 4 4 4
43309 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
43310 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
43311 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
43312 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
43313 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
43314 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
43315 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
43316 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
43317 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
43318 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
43319 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
43320 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
43321 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
43322 +4 4 4 4 4 4
43323 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
43324 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
43325 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
43326 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
43327 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
43328 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
43329 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
43330 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
43331 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
43332 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
43333 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
43334 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
43335 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
43336 +5 5 5 5 5 5
43337 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
43338 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
43339 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
43340 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
43341 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
43342 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43343 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
43344 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
43345 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
43346 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
43347 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
43348 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
43349 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
43350 +5 5 5 4 4 4
43351 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
43352 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
43353 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
43354 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
43355 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43356 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
43357 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
43358 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
43359 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
43360 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
43361 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
43362 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
43363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43364 +4 4 4 4 4 4
43365 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
43366 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
43367 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
43368 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
43369 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
43370 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43371 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43372 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
43373 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
43374 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
43375 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
43376 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
43377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43378 +4 4 4 4 4 4
43379 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
43380 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
43381 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
43382 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
43383 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43384 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
43385 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
43386 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
43387 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
43388 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
43389 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
43390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43392 +4 4 4 4 4 4
43393 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
43394 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
43395 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
43396 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
43397 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43398 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43399 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43400 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
43401 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
43402 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
43403 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
43404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43406 +4 4 4 4 4 4
43407 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
43408 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
43409 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
43410 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
43411 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43412 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
43413 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
43414 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
43415 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
43416 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
43417 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43418 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43419 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43420 +4 4 4 4 4 4
43421 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
43422 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
43423 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
43424 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
43425 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43426 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
43427 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
43428 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
43429 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
43430 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
43431 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
43432 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43433 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43434 +4 4 4 4 4 4
43435 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
43436 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
43437 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
43438 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
43439 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43440 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
43441 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
43442 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
43443 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
43444 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
43445 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
43446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43447 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43448 +4 4 4 4 4 4
43449 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
43450 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
43451 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
43452 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43453 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
43454 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
43455 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
43456 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
43457 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
43458 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
43459 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43461 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43462 +4 4 4 4 4 4
43463 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
43464 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
43465 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
43466 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43467 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43468 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
43469 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
43470 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
43471 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
43472 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
43473 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43475 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43476 +4 4 4 4 4 4
43477 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
43478 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
43479 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43480 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43481 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43482 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
43483 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
43484 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
43485 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
43486 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
43487 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43489 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43490 +4 4 4 4 4 4
43491 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
43492 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
43493 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43494 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43495 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43496 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
43497 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
43498 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
43499 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43500 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43501 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43503 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43504 +4 4 4 4 4 4
43505 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43506 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
43507 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43508 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
43509 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
43510 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
43511 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
43512 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
43513 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43514 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43515 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43517 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43518 +4 4 4 4 4 4
43519 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43520 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
43521 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43522 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
43523 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43524 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
43525 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
43526 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
43527 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43528 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43529 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43531 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43532 +4 4 4 4 4 4
43533 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
43534 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
43535 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43536 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
43537 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
43538 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
43539 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
43540 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
43541 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43542 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43543 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43544 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43545 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43546 +4 4 4 4 4 4
43547 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
43548 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
43549 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43550 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
43551 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
43552 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
43553 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
43554 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
43555 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43556 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43557 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43559 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43560 +4 4 4 4 4 4
43561 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43562 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
43563 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43564 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
43565 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
43566 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
43567 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
43568 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
43569 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43570 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43571 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43573 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43574 +4 4 4 4 4 4
43575 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
43576 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
43577 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43578 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
43579 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
43580 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
43581 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
43582 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
43583 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
43584 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43585 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43587 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43588 +4 4 4 4 4 4
43589 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43590 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
43591 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
43592 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
43593 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
43594 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
43595 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
43596 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
43597 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43598 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43599 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43602 +4 4 4 4 4 4
43603 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43604 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
43605 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43606 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
43607 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
43608 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
43609 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
43610 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
43611 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43612 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43613 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43616 +4 4 4 4 4 4
43617 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43618 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
43619 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
43620 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
43621 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
43622 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
43623 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43624 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
43625 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43626 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43627 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43629 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43630 +4 4 4 4 4 4
43631 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43632 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
43633 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
43634 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43635 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
43636 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
43637 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43638 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
43639 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43640 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43641 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43643 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43644 +4 4 4 4 4 4
43645 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43646 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
43647 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
43648 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
43649 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
43650 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
43651 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
43652 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
43653 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
43654 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43655 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43658 +4 4 4 4 4 4
43659 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43660 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
43661 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
43662 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
43663 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
43664 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
43665 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
43666 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
43667 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
43668 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43669 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43672 +4 4 4 4 4 4
43673 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
43674 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
43675 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
43676 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
43677 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43678 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
43679 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
43680 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
43681 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
43682 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43683 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43686 +4 4 4 4 4 4
43687 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43688 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
43689 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
43690 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
43691 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
43692 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
43693 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
43694 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
43695 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
43696 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43697 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43700 +4 4 4 4 4 4
43701 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
43702 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
43703 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
43704 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
43705 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
43706 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
43707 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
43708 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
43709 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
43710 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
43711 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43714 +4 4 4 4 4 4
43715 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
43716 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43717 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
43718 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
43719 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
43720 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
43721 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
43722 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
43723 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
43724 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
43725 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43728 +4 4 4 4 4 4
43729 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
43730 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43731 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
43732 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
43733 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
43734 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
43735 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43736 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
43737 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
43738 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
43739 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43741 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43742 +4 4 4 4 4 4
43743 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
43744 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
43745 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
43746 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
43747 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
43748 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
43749 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
43750 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
43751 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
43752 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
43753 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43756 +4 4 4 4 4 4
43757 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
43758 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
43759 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43760 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
43761 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
43762 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
43763 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
43764 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
43765 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
43766 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
43769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43770 +4 4 4 4 4 4
43771 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43772 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
43773 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
43774 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
43775 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
43776 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
43777 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
43778 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
43779 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
43780 +13 16 17 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
43783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43784 +4 4 4 4 4 4
43785 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
43786 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
43787 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
43788 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
43789 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
43790 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
43791 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
43792 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
43793 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
43794 +4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
43797 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43798 +4 4 4 4 4 4
43799 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
43800 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
43801 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
43802 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
43803 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
43804 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
43805 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
43806 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
43807 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43808 +4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
43811 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43812 +4 4 4 4 4 4
43813 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
43814 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43815 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
43816 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43817 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
43818 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
43819 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
43820 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
43821 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4 4 4 4 4 4 4 4 4 4
43825 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43826 +4 4 4 4 4 4
43827 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
43828 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
43829 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
43830 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
43831 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
43832 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
43833 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
43834 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
43835 +4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
43839 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43840 +4 4 4 4 4 4
43841 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43842 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
43843 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
43844 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
43845 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
43846 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
43847 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
43848 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
43849 +4 0 0 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 4 4 4 4 4 4 4 4 4 4 4 4
43853 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43854 +4 4 4 4 4 4
43855 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
43856 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
43857 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43858 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
43859 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
43860 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
43861 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
43862 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4
43867 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43868 +4 4 4 4 4 4
43869 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
43870 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
43871 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
43872 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
43873 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
43874 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
43875 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
43876 +6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
43881 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43882 +4 4 4 4 4 4
43883 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43884 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
43885 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43886 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
43887 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
43888 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
43889 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
43890 +4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
43895 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43896 +4 4 4 4 4 4
43897 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43898 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
43899 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
43900 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
43901 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
43902 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
43903 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
43904 +6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
43909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43910 +4 4 4 4 4 4
43911 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43912 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
43913 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
43914 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43915 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
43916 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
43917 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
43918 +5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
43923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43924 +4 4 4 4 4 4
43925 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43926 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43927 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43928 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
43929 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
43930 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
43931 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
43932 +4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
43937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43938 +4 4 4 4 4 4
43939 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43940 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43941 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43942 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43943 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
43944 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
43945 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
43951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43952 +4 4 4 4 4 4
43953 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43954 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43956 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43957 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43958 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
43959 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
43965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43966 +4 4 4 4 4 4
43967 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43970 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43971 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43972 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43973 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
43979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43980 +4 4 4 4 4 4
43981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43984 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
43985 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
43986 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
43987 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
43993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43994 +4 4 4 4 4 4
43995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43999 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
44000 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44001 +6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44008 +4 4 4 4 4 4
44009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44013 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
44014 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
44015 +4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44022 +4 4 4 4 4 4
44023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44027 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
44028 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
44029 +5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44036 +4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4 4 4 4
44039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44041 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
44042 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
44049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44050 +4 4 4 4 4 4
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 4 4 4 4 4 4 4 4 4
44053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44055 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
44056 +5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
44063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44064 +4 4 4 4 4 4
44065 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
44066 index 86d449e..af6a7f7 100644
44067 --- a/drivers/video/udlfb.c
44068 +++ b/drivers/video/udlfb.c
44069 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
44070 dlfb_urb_completion(urb);
44071
44072 error:
44073 - atomic_add(bytes_sent, &dev->bytes_sent);
44074 - atomic_add(bytes_identical, &dev->bytes_identical);
44075 - atomic_add(width*height*2, &dev->bytes_rendered);
44076 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44077 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44078 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
44079 end_cycles = get_cycles();
44080 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
44081 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44082 >> 10)), /* Kcycles */
44083 &dev->cpu_kcycles_used);
44084
44085 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
44086 dlfb_urb_completion(urb);
44087
44088 error:
44089 - atomic_add(bytes_sent, &dev->bytes_sent);
44090 - atomic_add(bytes_identical, &dev->bytes_identical);
44091 - atomic_add(bytes_rendered, &dev->bytes_rendered);
44092 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44093 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44094 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
44095 end_cycles = get_cycles();
44096 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
44097 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44098 >> 10)), /* Kcycles */
44099 &dev->cpu_kcycles_used);
44100 }
44101 @@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
44102 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44103 struct dlfb_data *dev = fb_info->par;
44104 return snprintf(buf, PAGE_SIZE, "%u\n",
44105 - atomic_read(&dev->bytes_rendered));
44106 + atomic_read_unchecked(&dev->bytes_rendered));
44107 }
44108
44109 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44110 @@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44111 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44112 struct dlfb_data *dev = fb_info->par;
44113 return snprintf(buf, PAGE_SIZE, "%u\n",
44114 - atomic_read(&dev->bytes_identical));
44115 + atomic_read_unchecked(&dev->bytes_identical));
44116 }
44117
44118 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44119 @@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44120 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44121 struct dlfb_data *dev = fb_info->par;
44122 return snprintf(buf, PAGE_SIZE, "%u\n",
44123 - atomic_read(&dev->bytes_sent));
44124 + atomic_read_unchecked(&dev->bytes_sent));
44125 }
44126
44127 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44128 @@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44129 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44130 struct dlfb_data *dev = fb_info->par;
44131 return snprintf(buf, PAGE_SIZE, "%u\n",
44132 - atomic_read(&dev->cpu_kcycles_used));
44133 + atomic_read_unchecked(&dev->cpu_kcycles_used));
44134 }
44135
44136 static ssize_t edid_show(
44137 @@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
44138 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44139 struct dlfb_data *dev = fb_info->par;
44140
44141 - atomic_set(&dev->bytes_rendered, 0);
44142 - atomic_set(&dev->bytes_identical, 0);
44143 - atomic_set(&dev->bytes_sent, 0);
44144 - atomic_set(&dev->cpu_kcycles_used, 0);
44145 + atomic_set_unchecked(&dev->bytes_rendered, 0);
44146 + atomic_set_unchecked(&dev->bytes_identical, 0);
44147 + atomic_set_unchecked(&dev->bytes_sent, 0);
44148 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
44149
44150 return count;
44151 }
44152 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
44153 index 2f8f82d..191de37 100644
44154 --- a/drivers/video/uvesafb.c
44155 +++ b/drivers/video/uvesafb.c
44156 @@ -19,6 +19,7 @@
44157 #include <linux/io.h>
44158 #include <linux/mutex.h>
44159 #include <linux/slab.h>
44160 +#include <linux/moduleloader.h>
44161 #include <video/edid.h>
44162 #include <video/uvesafb.h>
44163 #ifdef CONFIG_X86
44164 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
44165 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
44166 par->pmi_setpal = par->ypan = 0;
44167 } else {
44168 +
44169 +#ifdef CONFIG_PAX_KERNEXEC
44170 +#ifdef CONFIG_MODULES
44171 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
44172 +#endif
44173 + if (!par->pmi_code) {
44174 + par->pmi_setpal = par->ypan = 0;
44175 + return 0;
44176 + }
44177 +#endif
44178 +
44179 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
44180 + task->t.regs.edi);
44181 +
44182 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44183 + pax_open_kernel();
44184 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
44185 + pax_close_kernel();
44186 +
44187 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
44188 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
44189 +#else
44190 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
44191 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
44192 +#endif
44193 +
44194 printk(KERN_INFO "uvesafb: protected mode interface info at "
44195 "%04x:%04x\n",
44196 (u16)task->t.regs.es, (u16)task->t.regs.edi);
44197 @@ -818,13 +841,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
44198 par->ypan = ypan;
44199
44200 if (par->pmi_setpal || par->ypan) {
44201 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
44202 if (__supported_pte_mask & _PAGE_NX) {
44203 par->pmi_setpal = par->ypan = 0;
44204 printk(KERN_WARNING "uvesafb: NX protection is actively."
44205 "We have better not to use the PMI.\n");
44206 - } else {
44207 + } else
44208 +#endif
44209 uvesafb_vbe_getpmi(task, par);
44210 - }
44211 }
44212 #else
44213 /* The protected mode interface is not available on non-x86. */
44214 @@ -1838,6 +1862,11 @@ out:
44215 if (par->vbe_modes)
44216 kfree(par->vbe_modes);
44217
44218 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44219 + if (par->pmi_code)
44220 + module_free_exec(NULL, par->pmi_code);
44221 +#endif
44222 +
44223 framebuffer_release(info);
44224 return err;
44225 }
44226 @@ -1864,6 +1893,12 @@ static int uvesafb_remove(struct platform_device *dev)
44227 kfree(par->vbe_state_orig);
44228 if (par->vbe_state_saved)
44229 kfree(par->vbe_state_saved);
44230 +
44231 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44232 + if (par->pmi_code)
44233 + module_free_exec(NULL, par->pmi_code);
44234 +#endif
44235 +
44236 }
44237
44238 framebuffer_release(info);
44239 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
44240 index 501b340..86bd4cf 100644
44241 --- a/drivers/video/vesafb.c
44242 +++ b/drivers/video/vesafb.c
44243 @@ -9,6 +9,7 @@
44244 */
44245
44246 #include <linux/module.h>
44247 +#include <linux/moduleloader.h>
44248 #include <linux/kernel.h>
44249 #include <linux/errno.h>
44250 #include <linux/string.h>
44251 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
44252 static int vram_total __initdata; /* Set total amount of memory */
44253 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
44254 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
44255 -static void (*pmi_start)(void) __read_mostly;
44256 -static void (*pmi_pal) (void) __read_mostly;
44257 +static void (*pmi_start)(void) __read_only;
44258 +static void (*pmi_pal) (void) __read_only;
44259 static int depth __read_mostly;
44260 static int vga_compat __read_mostly;
44261 /* --------------------------------------------------------------------- */
44262 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
44263 unsigned int size_vmode;
44264 unsigned int size_remap;
44265 unsigned int size_total;
44266 + void *pmi_code = NULL;
44267
44268 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
44269 return -ENODEV;
44270 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
44271 size_remap = size_total;
44272 vesafb_fix.smem_len = size_remap;
44273
44274 -#ifndef __i386__
44275 - screen_info.vesapm_seg = 0;
44276 -#endif
44277 -
44278 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
44279 printk(KERN_WARNING
44280 "vesafb: cannot reserve video memory at 0x%lx\n",
44281 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
44282 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
44283 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
44284
44285 +#ifdef __i386__
44286 +
44287 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44288 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
44289 + if (!pmi_code)
44290 +#elif !defined(CONFIG_PAX_KERNEXEC)
44291 + if (0)
44292 +#endif
44293 +
44294 +#endif
44295 + screen_info.vesapm_seg = 0;
44296 +
44297 if (screen_info.vesapm_seg) {
44298 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
44299 - screen_info.vesapm_seg,screen_info.vesapm_off);
44300 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
44301 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
44302 }
44303
44304 if (screen_info.vesapm_seg < 0xc000)
44305 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
44306
44307 if (ypan || pmi_setpal) {
44308 unsigned short *pmi_base;
44309 +
44310 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
44311 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
44312 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
44313 +
44314 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44315 + pax_open_kernel();
44316 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
44317 +#else
44318 + pmi_code = pmi_base;
44319 +#endif
44320 +
44321 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
44322 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
44323 +
44324 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44325 + pmi_start = ktva_ktla(pmi_start);
44326 + pmi_pal = ktva_ktla(pmi_pal);
44327 + pax_close_kernel();
44328 +#endif
44329 +
44330 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
44331 if (pmi_base[3]) {
44332 printk(KERN_INFO "vesafb: pmi: ports = ");
44333 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
44334 info->node, info->fix.id);
44335 return 0;
44336 err:
44337 +
44338 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44339 + module_free_exec(NULL, pmi_code);
44340 +#endif
44341 +
44342 if (info->screen_base)
44343 iounmap(info->screen_base);
44344 framebuffer_release(info);
44345 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
44346 index 88714ae..16c2e11 100644
44347 --- a/drivers/video/via/via_clock.h
44348 +++ b/drivers/video/via/via_clock.h
44349 @@ -56,7 +56,7 @@ struct via_clock {
44350
44351 void (*set_engine_pll_state)(u8 state);
44352 void (*set_engine_pll)(struct via_pll_config config);
44353 -};
44354 +} __no_const;
44355
44356
44357 static inline u32 get_pll_internal_frequency(u32 ref_freq,
44358 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
44359 index 6b1b7e1..b2fa4d5 100644
44360 --- a/drivers/virtio/virtio_mmio.c
44361 +++ b/drivers/virtio/virtio_mmio.c
44362 @@ -530,7 +530,7 @@ static int vm_cmdline_set(const char *device,
44363
44364 resources[0].end = memparse(device, &str) - 1;
44365
44366 - processed = sscanf(str, "@%lli:%u%n:%d%n",
44367 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
44368 &base, &resources[1].start, &consumed,
44369 &vm_cmdline_id, &consumed);
44370
44371 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
44372 index fef20db..d28b1ab 100644
44373 --- a/drivers/xen/xenfs/xenstored.c
44374 +++ b/drivers/xen/xenfs/xenstored.c
44375 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
44376 static int xsd_kva_open(struct inode *inode, struct file *file)
44377 {
44378 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
44379 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44380 + NULL);
44381 +#else
44382 xen_store_interface);
44383 +#endif
44384 +
44385 if (!file->private_data)
44386 return -ENOMEM;
44387 return 0;
44388 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
44389 index 890bed5..17ae73e 100644
44390 --- a/fs/9p/vfs_inode.c
44391 +++ b/fs/9p/vfs_inode.c
44392 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
44393 void
44394 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44395 {
44396 - char *s = nd_get_link(nd);
44397 + const char *s = nd_get_link(nd);
44398
44399 p9_debug(P9_DEBUG_VFS, " %s %s\n",
44400 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
44401 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
44402 index 0efd152..b5802ad 100644
44403 --- a/fs/Kconfig.binfmt
44404 +++ b/fs/Kconfig.binfmt
44405 @@ -89,7 +89,7 @@ config HAVE_AOUT
44406
44407 config BINFMT_AOUT
44408 tristate "Kernel support for a.out and ECOFF binaries"
44409 - depends on HAVE_AOUT
44410 + depends on HAVE_AOUT && BROKEN
44411 ---help---
44412 A.out (Assembler.OUTput) is a set of formats for libraries and
44413 executables used in the earliest versions of UNIX. Linux used
44414 diff --git a/fs/aio.c b/fs/aio.c
44415 index 71f613c..9d01f1f 100644
44416 --- a/fs/aio.c
44417 +++ b/fs/aio.c
44418 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
44419 size += sizeof(struct io_event) * nr_events;
44420 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
44421
44422 - if (nr_pages < 0)
44423 + if (nr_pages <= 0)
44424 return -EINVAL;
44425
44426 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
44427 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
44428 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44429 {
44430 ssize_t ret;
44431 + struct iovec iovstack;
44432
44433 #ifdef CONFIG_COMPAT
44434 if (compat)
44435 ret = compat_rw_copy_check_uvector(type,
44436 (struct compat_iovec __user *)kiocb->ki_buf,
44437 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44438 + kiocb->ki_nbytes, 1, &iovstack,
44439 &kiocb->ki_iovec);
44440 else
44441 #endif
44442 ret = rw_copy_check_uvector(type,
44443 (struct iovec __user *)kiocb->ki_buf,
44444 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44445 + kiocb->ki_nbytes, 1, &iovstack,
44446 &kiocb->ki_iovec);
44447 if (ret < 0)
44448 goto out;
44449 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44450 if (ret < 0)
44451 goto out;
44452
44453 + if (kiocb->ki_iovec == &iovstack) {
44454 + kiocb->ki_inline_vec = iovstack;
44455 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
44456 + }
44457 kiocb->ki_nr_segs = kiocb->ki_nbytes;
44458 kiocb->ki_cur_seg = 0;
44459 /* ki_nbytes/left now reflect bytes instead of segs */
44460 diff --git a/fs/attr.c b/fs/attr.c
44461 index cce7df5..eaa2731 100644
44462 --- a/fs/attr.c
44463 +++ b/fs/attr.c
44464 @@ -100,6 +100,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
44465 unsigned long limit;
44466
44467 limit = rlimit(RLIMIT_FSIZE);
44468 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
44469 if (limit != RLIM_INFINITY && offset > limit)
44470 goto out_sig;
44471 if (offset > inode->i_sb->s_maxbytes)
44472 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
44473 index dce436e..55e670d 100644
44474 --- a/fs/autofs4/waitq.c
44475 +++ b/fs/autofs4/waitq.c
44476 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
44477 {
44478 unsigned long sigpipe, flags;
44479 mm_segment_t fs;
44480 - const char *data = (const char *)addr;
44481 + const char __user *data = (const char __force_user *)addr;
44482 ssize_t wr = 0;
44483
44484 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
44485 @@ -347,6 +347,10 @@ static int validate_request(struct autofs_wait_queue **wait,
44486 return 1;
44487 }
44488
44489 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44490 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
44491 +#endif
44492 +
44493 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44494 enum autofs_notify notify)
44495 {
44496 @@ -380,7 +384,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44497
44498 /* If this is a direct mount request create a dummy name */
44499 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
44500 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44501 + /* this name does get written to userland via autofs4_write() */
44502 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
44503 +#else
44504 qstr.len = sprintf(name, "%p", dentry);
44505 +#endif
44506 else {
44507 qstr.len = autofs4_getpath(sbi, dentry, &name);
44508 if (!qstr.len) {
44509 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
44510 index 2b3bda8..6a2d4be 100644
44511 --- a/fs/befs/linuxvfs.c
44512 +++ b/fs/befs/linuxvfs.c
44513 @@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44514 {
44515 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
44516 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
44517 - char *link = nd_get_link(nd);
44518 + const char *link = nd_get_link(nd);
44519 if (!IS_ERR(link))
44520 kfree(link);
44521 }
44522 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
44523 index 0e7a6f8..332b1ca 100644
44524 --- a/fs/binfmt_aout.c
44525 +++ b/fs/binfmt_aout.c
44526 @@ -16,6 +16,7 @@
44527 #include <linux/string.h>
44528 #include <linux/fs.h>
44529 #include <linux/file.h>
44530 +#include <linux/security.h>
44531 #include <linux/stat.h>
44532 #include <linux/fcntl.h>
44533 #include <linux/ptrace.h>
44534 @@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
44535 #endif
44536 # define START_STACK(u) ((void __user *)u.start_stack)
44537
44538 + memset(&dump, 0, sizeof(dump));
44539 +
44540 fs = get_fs();
44541 set_fs(KERNEL_DS);
44542 has_dumped = 1;
44543 @@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
44544
44545 /* If the size of the dump file exceeds the rlimit, then see what would happen
44546 if we wrote the stack, but not the data area. */
44547 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
44548 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
44549 dump.u_dsize = 0;
44550
44551 /* Make sure we have enough room to write the stack and data areas. */
44552 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
44553 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
44554 dump.u_ssize = 0;
44555
44556 @@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44557 rlim = rlimit(RLIMIT_DATA);
44558 if (rlim >= RLIM_INFINITY)
44559 rlim = ~0;
44560 +
44561 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
44562 if (ex.a_data + ex.a_bss > rlim)
44563 return -ENOMEM;
44564
44565 @@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44566
44567 install_exec_creds(bprm);
44568
44569 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44570 + current->mm->pax_flags = 0UL;
44571 +#endif
44572 +
44573 +#ifdef CONFIG_PAX_PAGEEXEC
44574 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
44575 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
44576 +
44577 +#ifdef CONFIG_PAX_EMUTRAMP
44578 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
44579 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
44580 +#endif
44581 +
44582 +#ifdef CONFIG_PAX_MPROTECT
44583 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
44584 + current->mm->pax_flags |= MF_PAX_MPROTECT;
44585 +#endif
44586 +
44587 + }
44588 +#endif
44589 +
44590 if (N_MAGIC(ex) == OMAGIC) {
44591 unsigned long text_addr, map_size;
44592 loff_t pos;
44593 @@ -332,7 +360,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44594 }
44595
44596 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
44597 - PROT_READ | PROT_WRITE | PROT_EXEC,
44598 + PROT_READ | PROT_WRITE,
44599 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
44600 fd_offset + ex.a_text);
44601 if (error != N_DATADDR(ex)) {
44602 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
44603 index fbd9f60..0b845dd 100644
44604 --- a/fs/binfmt_elf.c
44605 +++ b/fs/binfmt_elf.c
44606 @@ -33,6 +33,7 @@
44607 #include <linux/elf.h>
44608 #include <linux/utsname.h>
44609 #include <linux/coredump.h>
44610 +#include <linux/xattr.h>
44611 #include <asm/uaccess.h>
44612 #include <asm/param.h>
44613 #include <asm/page.h>
44614 @@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
44615 #define elf_core_dump NULL
44616 #endif
44617
44618 +#ifdef CONFIG_PAX_MPROTECT
44619 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
44620 +#endif
44621 +
44622 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
44623 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
44624 #else
44625 @@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
44626 .load_binary = load_elf_binary,
44627 .load_shlib = load_elf_library,
44628 .core_dump = elf_core_dump,
44629 +
44630 +#ifdef CONFIG_PAX_MPROTECT
44631 + .handle_mprotect= elf_handle_mprotect,
44632 +#endif
44633 +
44634 .min_coredump = ELF_EXEC_PAGESIZE,
44635 };
44636
44637 @@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
44638
44639 static int set_brk(unsigned long start, unsigned long end)
44640 {
44641 + unsigned long e = end;
44642 +
44643 start = ELF_PAGEALIGN(start);
44644 end = ELF_PAGEALIGN(end);
44645 if (end > start) {
44646 @@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
44647 if (BAD_ADDR(addr))
44648 return addr;
44649 }
44650 - current->mm->start_brk = current->mm->brk = end;
44651 + current->mm->start_brk = current->mm->brk = e;
44652 return 0;
44653 }
44654
44655 @@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44656 elf_addr_t __user *u_rand_bytes;
44657 const char *k_platform = ELF_PLATFORM;
44658 const char *k_base_platform = ELF_BASE_PLATFORM;
44659 - unsigned char k_rand_bytes[16];
44660 + u32 k_rand_bytes[4];
44661 int items;
44662 elf_addr_t *elf_info;
44663 int ei_index = 0;
44664 const struct cred *cred = current_cred();
44665 struct vm_area_struct *vma;
44666 + unsigned long saved_auxv[AT_VECTOR_SIZE];
44667
44668 /*
44669 * In some cases (e.g. Hyper-Threading), we want to avoid L1
44670 @@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44671 * Generate 16 random bytes for userspace PRNG seeding.
44672 */
44673 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
44674 - u_rand_bytes = (elf_addr_t __user *)
44675 - STACK_ALLOC(p, sizeof(k_rand_bytes));
44676 + srandom32(k_rand_bytes[0] ^ random32());
44677 + srandom32(k_rand_bytes[1] ^ random32());
44678 + srandom32(k_rand_bytes[2] ^ random32());
44679 + srandom32(k_rand_bytes[3] ^ random32());
44680 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
44681 + u_rand_bytes = (elf_addr_t __user *) p;
44682 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
44683 return -EFAULT;
44684
44685 @@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44686 return -EFAULT;
44687 current->mm->env_end = p;
44688
44689 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
44690 +
44691 /* Put the elf_info on the stack in the right place. */
44692 sp = (elf_addr_t __user *)envp + 1;
44693 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
44694 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
44695 return -EFAULT;
44696 return 0;
44697 }
44698 @@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
44699 an ELF header */
44700
44701 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44702 - struct file *interpreter, unsigned long *interp_map_addr,
44703 - unsigned long no_base)
44704 + struct file *interpreter, unsigned long no_base)
44705 {
44706 struct elf_phdr *elf_phdata;
44707 struct elf_phdr *eppnt;
44708 - unsigned long load_addr = 0;
44709 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
44710 int load_addr_set = 0;
44711 unsigned long last_bss = 0, elf_bss = 0;
44712 - unsigned long error = ~0UL;
44713 + unsigned long error = -EINVAL;
44714 unsigned long total_size;
44715 int retval, i, size;
44716
44717 @@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44718 goto out_close;
44719 }
44720
44721 +#ifdef CONFIG_PAX_SEGMEXEC
44722 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
44723 + pax_task_size = SEGMEXEC_TASK_SIZE;
44724 +#endif
44725 +
44726 eppnt = elf_phdata;
44727 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
44728 if (eppnt->p_type == PT_LOAD) {
44729 @@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44730 map_addr = elf_map(interpreter, load_addr + vaddr,
44731 eppnt, elf_prot, elf_type, total_size);
44732 total_size = 0;
44733 - if (!*interp_map_addr)
44734 - *interp_map_addr = map_addr;
44735 error = map_addr;
44736 if (BAD_ADDR(map_addr))
44737 goto out_close;
44738 @@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44739 k = load_addr + eppnt->p_vaddr;
44740 if (BAD_ADDR(k) ||
44741 eppnt->p_filesz > eppnt->p_memsz ||
44742 - eppnt->p_memsz > TASK_SIZE ||
44743 - TASK_SIZE - eppnt->p_memsz < k) {
44744 + eppnt->p_memsz > pax_task_size ||
44745 + pax_task_size - eppnt->p_memsz < k) {
44746 error = -ENOMEM;
44747 goto out_close;
44748 }
44749 @@ -530,6 +551,315 @@ out:
44750 return error;
44751 }
44752
44753 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
44754 +#ifdef CONFIG_PAX_SOFTMODE
44755 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
44756 +{
44757 + unsigned long pax_flags = 0UL;
44758 +
44759 +#ifdef CONFIG_PAX_PAGEEXEC
44760 + if (elf_phdata->p_flags & PF_PAGEEXEC)
44761 + pax_flags |= MF_PAX_PAGEEXEC;
44762 +#endif
44763 +
44764 +#ifdef CONFIG_PAX_SEGMEXEC
44765 + if (elf_phdata->p_flags & PF_SEGMEXEC)
44766 + pax_flags |= MF_PAX_SEGMEXEC;
44767 +#endif
44768 +
44769 +#ifdef CONFIG_PAX_EMUTRAMP
44770 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
44771 + pax_flags |= MF_PAX_EMUTRAMP;
44772 +#endif
44773 +
44774 +#ifdef CONFIG_PAX_MPROTECT
44775 + if (elf_phdata->p_flags & PF_MPROTECT)
44776 + pax_flags |= MF_PAX_MPROTECT;
44777 +#endif
44778 +
44779 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44780 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
44781 + pax_flags |= MF_PAX_RANDMMAP;
44782 +#endif
44783 +
44784 + return pax_flags;
44785 +}
44786 +#endif
44787 +
44788 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
44789 +{
44790 + unsigned long pax_flags = 0UL;
44791 +
44792 +#ifdef CONFIG_PAX_PAGEEXEC
44793 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
44794 + pax_flags |= MF_PAX_PAGEEXEC;
44795 +#endif
44796 +
44797 +#ifdef CONFIG_PAX_SEGMEXEC
44798 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
44799 + pax_flags |= MF_PAX_SEGMEXEC;
44800 +#endif
44801 +
44802 +#ifdef CONFIG_PAX_EMUTRAMP
44803 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
44804 + pax_flags |= MF_PAX_EMUTRAMP;
44805 +#endif
44806 +
44807 +#ifdef CONFIG_PAX_MPROTECT
44808 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
44809 + pax_flags |= MF_PAX_MPROTECT;
44810 +#endif
44811 +
44812 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44813 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
44814 + pax_flags |= MF_PAX_RANDMMAP;
44815 +#endif
44816 +
44817 + return pax_flags;
44818 +}
44819 +#endif
44820 +
44821 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44822 +#ifdef CONFIG_PAX_SOFTMODE
44823 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
44824 +{
44825 + unsigned long pax_flags = 0UL;
44826 +
44827 +#ifdef CONFIG_PAX_PAGEEXEC
44828 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
44829 + pax_flags |= MF_PAX_PAGEEXEC;
44830 +#endif
44831 +
44832 +#ifdef CONFIG_PAX_SEGMEXEC
44833 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
44834 + pax_flags |= MF_PAX_SEGMEXEC;
44835 +#endif
44836 +
44837 +#ifdef CONFIG_PAX_EMUTRAMP
44838 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
44839 + pax_flags |= MF_PAX_EMUTRAMP;
44840 +#endif
44841 +
44842 +#ifdef CONFIG_PAX_MPROTECT
44843 + if (pax_flags_softmode & MF_PAX_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 && (pax_flags_softmode & MF_PAX_RANDMMAP))
44849 + pax_flags |= MF_PAX_RANDMMAP;
44850 +#endif
44851 +
44852 + return pax_flags;
44853 +}
44854 +#endif
44855 +
44856 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
44857 +{
44858 + unsigned long pax_flags = 0UL;
44859 +
44860 +#ifdef CONFIG_PAX_PAGEEXEC
44861 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
44862 + pax_flags |= MF_PAX_PAGEEXEC;
44863 +#endif
44864 +
44865 +#ifdef CONFIG_PAX_SEGMEXEC
44866 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
44867 + pax_flags |= MF_PAX_SEGMEXEC;
44868 +#endif
44869 +
44870 +#ifdef CONFIG_PAX_EMUTRAMP
44871 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
44872 + pax_flags |= MF_PAX_EMUTRAMP;
44873 +#endif
44874 +
44875 +#ifdef CONFIG_PAX_MPROTECT
44876 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
44877 + pax_flags |= MF_PAX_MPROTECT;
44878 +#endif
44879 +
44880 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44881 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
44882 + pax_flags |= MF_PAX_RANDMMAP;
44883 +#endif
44884 +
44885 + return pax_flags;
44886 +}
44887 +#endif
44888 +
44889 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44890 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
44891 +{
44892 + unsigned long pax_flags = 0UL;
44893 +
44894 +#ifdef CONFIG_PAX_EI_PAX
44895 +
44896 +#ifdef CONFIG_PAX_PAGEEXEC
44897 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
44898 + pax_flags |= MF_PAX_PAGEEXEC;
44899 +#endif
44900 +
44901 +#ifdef CONFIG_PAX_SEGMEXEC
44902 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
44903 + pax_flags |= MF_PAX_SEGMEXEC;
44904 +#endif
44905 +
44906 +#ifdef CONFIG_PAX_EMUTRAMP
44907 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
44908 + pax_flags |= MF_PAX_EMUTRAMP;
44909 +#endif
44910 +
44911 +#ifdef CONFIG_PAX_MPROTECT
44912 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
44913 + pax_flags |= MF_PAX_MPROTECT;
44914 +#endif
44915 +
44916 +#ifdef CONFIG_PAX_ASLR
44917 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
44918 + pax_flags |= MF_PAX_RANDMMAP;
44919 +#endif
44920 +
44921 +#else
44922 +
44923 +#ifdef CONFIG_PAX_PAGEEXEC
44924 + pax_flags |= MF_PAX_PAGEEXEC;
44925 +#endif
44926 +
44927 +#ifdef CONFIG_PAX_SEGMEXEC
44928 + pax_flags |= MF_PAX_SEGMEXEC;
44929 +#endif
44930 +
44931 +#ifdef CONFIG_PAX_MPROTECT
44932 + pax_flags |= MF_PAX_MPROTECT;
44933 +#endif
44934 +
44935 +#ifdef CONFIG_PAX_RANDMMAP
44936 + if (randomize_va_space)
44937 + pax_flags |= MF_PAX_RANDMMAP;
44938 +#endif
44939 +
44940 +#endif
44941 +
44942 + return pax_flags;
44943 +}
44944 +
44945 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
44946 +{
44947 +
44948 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
44949 + unsigned long i;
44950 +
44951 + for (i = 0UL; i < elf_ex->e_phnum; i++)
44952 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
44953 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
44954 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
44955 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
44956 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
44957 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
44958 + return ~0UL;
44959 +
44960 +#ifdef CONFIG_PAX_SOFTMODE
44961 + if (pax_softmode)
44962 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
44963 + else
44964 +#endif
44965 +
44966 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
44967 + break;
44968 + }
44969 +#endif
44970 +
44971 + return ~0UL;
44972 +}
44973 +
44974 +static unsigned long pax_parse_xattr_pax(struct file * const file)
44975 +{
44976 +
44977 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44978 + ssize_t xattr_size, i;
44979 + unsigned char xattr_value[5];
44980 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
44981 +
44982 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
44983 + if (xattr_size <= 0 || xattr_size > 5)
44984 + return ~0UL;
44985 +
44986 + for (i = 0; i < xattr_size; i++)
44987 + switch (xattr_value[i]) {
44988 + default:
44989 + return ~0UL;
44990 +
44991 +#define parse_flag(option1, option2, flag) \
44992 + case option1: \
44993 + if (pax_flags_hardmode & MF_PAX_##flag) \
44994 + return ~0UL; \
44995 + pax_flags_hardmode |= MF_PAX_##flag; \
44996 + break; \
44997 + case option2: \
44998 + if (pax_flags_softmode & MF_PAX_##flag) \
44999 + return ~0UL; \
45000 + pax_flags_softmode |= MF_PAX_##flag; \
45001 + break;
45002 +
45003 + parse_flag('p', 'P', PAGEEXEC);
45004 + parse_flag('e', 'E', EMUTRAMP);
45005 + parse_flag('m', 'M', MPROTECT);
45006 + parse_flag('r', 'R', RANDMMAP);
45007 + parse_flag('s', 'S', SEGMEXEC);
45008 +
45009 +#undef parse_flag
45010 + }
45011 +
45012 + if (pax_flags_hardmode & pax_flags_softmode)
45013 + return ~0UL;
45014 +
45015 +#ifdef CONFIG_PAX_SOFTMODE
45016 + if (pax_softmode)
45017 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
45018 + else
45019 +#endif
45020 +
45021 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
45022 +#else
45023 + return ~0UL;
45024 +#endif
45025 +
45026 +}
45027 +
45028 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
45029 +{
45030 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
45031 +
45032 + pax_flags = pax_parse_ei_pax(elf_ex);
45033 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
45034 + xattr_pax_flags = pax_parse_xattr_pax(file);
45035 +
45036 + if (pt_pax_flags == ~0UL)
45037 + pt_pax_flags = xattr_pax_flags;
45038 + else if (xattr_pax_flags == ~0UL)
45039 + xattr_pax_flags = pt_pax_flags;
45040 + if (pt_pax_flags != xattr_pax_flags)
45041 + return -EINVAL;
45042 + if (pt_pax_flags != ~0UL)
45043 + pax_flags = pt_pax_flags;
45044 +
45045 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
45046 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45047 + if ((__supported_pte_mask & _PAGE_NX))
45048 + pax_flags &= ~MF_PAX_SEGMEXEC;
45049 + else
45050 + pax_flags &= ~MF_PAX_PAGEEXEC;
45051 + }
45052 +#endif
45053 +
45054 + if (0 > pax_check_flags(&pax_flags))
45055 + return -EINVAL;
45056 +
45057 + current->mm->pax_flags = pax_flags;
45058 + return 0;
45059 +}
45060 +#endif
45061 +
45062 /*
45063 * These are the functions used to load ELF style executables and shared
45064 * libraries. There is no binary dependent code anywhere else.
45065 @@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
45066 {
45067 unsigned int random_variable = 0;
45068
45069 +#ifdef CONFIG_PAX_RANDUSTACK
45070 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
45071 + return stack_top - current->mm->delta_stack;
45072 +#endif
45073 +
45074 if ((current->flags & PF_RANDOMIZE) &&
45075 !(current->personality & ADDR_NO_RANDOMIZE)) {
45076 random_variable = get_random_int() & STACK_RND_MASK;
45077 @@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45078 unsigned long load_addr = 0, load_bias = 0;
45079 int load_addr_set = 0;
45080 char * elf_interpreter = NULL;
45081 - unsigned long error;
45082 + unsigned long error = 0;
45083 struct elf_phdr *elf_ppnt, *elf_phdata;
45084 unsigned long elf_bss, elf_brk;
45085 int retval, i;
45086 @@ -574,11 +909,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45087 unsigned long start_code, end_code, start_data, end_data;
45088 unsigned long reloc_func_desc __maybe_unused = 0;
45089 int executable_stack = EXSTACK_DEFAULT;
45090 - unsigned long def_flags = 0;
45091 struct {
45092 struct elfhdr elf_ex;
45093 struct elfhdr interp_elf_ex;
45094 } *loc;
45095 + unsigned long pax_task_size = TASK_SIZE;
45096
45097 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
45098 if (!loc) {
45099 @@ -714,11 +1049,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45100 goto out_free_dentry;
45101
45102 /* OK, This is the point of no return */
45103 - current->mm->def_flags = def_flags;
45104 +
45105 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45106 + current->mm->pax_flags = 0UL;
45107 +#endif
45108 +
45109 +#ifdef CONFIG_PAX_DLRESOLVE
45110 + current->mm->call_dl_resolve = 0UL;
45111 +#endif
45112 +
45113 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
45114 + current->mm->call_syscall = 0UL;
45115 +#endif
45116 +
45117 +#ifdef CONFIG_PAX_ASLR
45118 + current->mm->delta_mmap = 0UL;
45119 + current->mm->delta_stack = 0UL;
45120 +#endif
45121 +
45122 + current->mm->def_flags = 0;
45123 +
45124 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45125 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
45126 + send_sig(SIGKILL, current, 0);
45127 + goto out_free_dentry;
45128 + }
45129 +#endif
45130 +
45131 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45132 + pax_set_initial_flags(bprm);
45133 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
45134 + if (pax_set_initial_flags_func)
45135 + (pax_set_initial_flags_func)(bprm);
45136 +#endif
45137 +
45138 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
45139 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
45140 + current->mm->context.user_cs_limit = PAGE_SIZE;
45141 + current->mm->def_flags |= VM_PAGEEXEC;
45142 + }
45143 +#endif
45144 +
45145 +#ifdef CONFIG_PAX_SEGMEXEC
45146 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
45147 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
45148 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
45149 + pax_task_size = SEGMEXEC_TASK_SIZE;
45150 + current->mm->def_flags |= VM_NOHUGEPAGE;
45151 + }
45152 +#endif
45153 +
45154 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
45155 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45156 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
45157 + put_cpu();
45158 + }
45159 +#endif
45160
45161 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
45162 may depend on the personality. */
45163 SET_PERSONALITY(loc->elf_ex);
45164 +
45165 +#ifdef CONFIG_PAX_ASLR
45166 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45167 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
45168 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
45169 + }
45170 +#endif
45171 +
45172 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45173 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45174 + executable_stack = EXSTACK_DISABLE_X;
45175 + current->personality &= ~READ_IMPLIES_EXEC;
45176 + } else
45177 +#endif
45178 +
45179 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
45180 current->personality |= READ_IMPLIES_EXEC;
45181
45182 @@ -809,6 +1214,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45183 #else
45184 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
45185 #endif
45186 +
45187 +#ifdef CONFIG_PAX_RANDMMAP
45188 + /* PaX: randomize base address at the default exe base if requested */
45189 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
45190 +#ifdef CONFIG_SPARC64
45191 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
45192 +#else
45193 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
45194 +#endif
45195 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
45196 + elf_flags |= MAP_FIXED;
45197 + }
45198 +#endif
45199 +
45200 }
45201
45202 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
45203 @@ -841,9 +1260,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45204 * allowed task size. Note that p_filesz must always be
45205 * <= p_memsz so it is only necessary to check p_memsz.
45206 */
45207 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45208 - elf_ppnt->p_memsz > TASK_SIZE ||
45209 - TASK_SIZE - elf_ppnt->p_memsz < k) {
45210 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45211 + elf_ppnt->p_memsz > pax_task_size ||
45212 + pax_task_size - elf_ppnt->p_memsz < k) {
45213 /* set_brk can never work. Avoid overflows. */
45214 send_sig(SIGKILL, current, 0);
45215 retval = -EINVAL;
45216 @@ -882,17 +1301,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45217 goto out_free_dentry;
45218 }
45219 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
45220 - send_sig(SIGSEGV, current, 0);
45221 - retval = -EFAULT; /* Nobody gets to see this, but.. */
45222 - goto out_free_dentry;
45223 + /*
45224 + * This bss-zeroing can fail if the ELF
45225 + * file specifies odd protections. So
45226 + * we don't check the return value
45227 + */
45228 }
45229
45230 +#ifdef CONFIG_PAX_RANDMMAP
45231 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45232 + unsigned long start, size;
45233 +
45234 + start = ELF_PAGEALIGN(elf_brk);
45235 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
45236 + down_read(&current->mm->mmap_sem);
45237 + retval = -ENOMEM;
45238 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
45239 + unsigned long prot = PROT_NONE;
45240 +
45241 + up_read(&current->mm->mmap_sem);
45242 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
45243 +// if (current->personality & ADDR_NO_RANDOMIZE)
45244 +// prot = PROT_READ;
45245 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
45246 + retval = IS_ERR_VALUE(start) ? start : 0;
45247 + } else
45248 + up_read(&current->mm->mmap_sem);
45249 + if (retval == 0)
45250 + retval = set_brk(start + size, start + size + PAGE_SIZE);
45251 + if (retval < 0) {
45252 + send_sig(SIGKILL, current, 0);
45253 + goto out_free_dentry;
45254 + }
45255 + }
45256 +#endif
45257 +
45258 if (elf_interpreter) {
45259 - unsigned long interp_map_addr = 0;
45260 -
45261 elf_entry = load_elf_interp(&loc->interp_elf_ex,
45262 interpreter,
45263 - &interp_map_addr,
45264 load_bias);
45265 if (!IS_ERR((void *)elf_entry)) {
45266 /*
45267 @@ -1114,7 +1560,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
45268 * Decide what to dump of a segment, part, all or none.
45269 */
45270 static unsigned long vma_dump_size(struct vm_area_struct *vma,
45271 - unsigned long mm_flags)
45272 + unsigned long mm_flags, long signr)
45273 {
45274 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
45275
45276 @@ -1151,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
45277 if (vma->vm_file == NULL)
45278 return 0;
45279
45280 - if (FILTER(MAPPED_PRIVATE))
45281 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
45282 goto whole;
45283
45284 /*
45285 @@ -1373,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
45286 {
45287 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
45288 int i = 0;
45289 - do
45290 + do {
45291 i += 2;
45292 - while (auxv[i - 2] != AT_NULL);
45293 + } while (auxv[i - 2] != AT_NULL);
45294 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
45295 }
45296
45297 @@ -2003,14 +2449,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
45298 }
45299
45300 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
45301 - unsigned long mm_flags)
45302 + struct coredump_params *cprm)
45303 {
45304 struct vm_area_struct *vma;
45305 size_t size = 0;
45306
45307 for (vma = first_vma(current, gate_vma); vma != NULL;
45308 vma = next_vma(vma, gate_vma))
45309 - size += vma_dump_size(vma, mm_flags);
45310 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45311 return size;
45312 }
45313
45314 @@ -2104,7 +2550,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45315
45316 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
45317
45318 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
45319 + offset += elf_core_vma_data_size(gate_vma, cprm);
45320 offset += elf_core_extra_data_size();
45321 e_shoff = offset;
45322
45323 @@ -2118,10 +2564,12 @@ static int elf_core_dump(struct coredump_params *cprm)
45324 offset = dataoff;
45325
45326 size += sizeof(*elf);
45327 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45328 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
45329 goto end_coredump;
45330
45331 size += sizeof(*phdr4note);
45332 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45333 if (size > cprm->limit
45334 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
45335 goto end_coredump;
45336 @@ -2135,7 +2583,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45337 phdr.p_offset = offset;
45338 phdr.p_vaddr = vma->vm_start;
45339 phdr.p_paddr = 0;
45340 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
45341 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45342 phdr.p_memsz = vma->vm_end - vma->vm_start;
45343 offset += phdr.p_filesz;
45344 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
45345 @@ -2146,6 +2594,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45346 phdr.p_align = ELF_EXEC_PAGESIZE;
45347
45348 size += sizeof(phdr);
45349 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45350 if (size > cprm->limit
45351 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
45352 goto end_coredump;
45353 @@ -2170,7 +2619,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45354 unsigned long addr;
45355 unsigned long end;
45356
45357 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
45358 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45359
45360 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
45361 struct page *page;
45362 @@ -2179,6 +2628,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45363 page = get_dump_page(addr);
45364 if (page) {
45365 void *kaddr = kmap(page);
45366 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
45367 stop = ((size += PAGE_SIZE) > cprm->limit) ||
45368 !dump_write(cprm->file, kaddr,
45369 PAGE_SIZE);
45370 @@ -2196,6 +2646,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45371
45372 if (e_phnum == PN_XNUM) {
45373 size += sizeof(*shdr4extnum);
45374 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45375 if (size > cprm->limit
45376 || !dump_write(cprm->file, shdr4extnum,
45377 sizeof(*shdr4extnum)))
45378 @@ -2216,6 +2667,97 @@ out:
45379
45380 #endif /* CONFIG_ELF_CORE */
45381
45382 +#ifdef CONFIG_PAX_MPROTECT
45383 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
45384 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
45385 + * we'll remove VM_MAYWRITE for good on RELRO segments.
45386 + *
45387 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
45388 + * basis because we want to allow the common case and not the special ones.
45389 + */
45390 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
45391 +{
45392 + struct elfhdr elf_h;
45393 + struct elf_phdr elf_p;
45394 + unsigned long i;
45395 + unsigned long oldflags;
45396 + bool is_textrel_rw, is_textrel_rx, is_relro;
45397 +
45398 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
45399 + return;
45400 +
45401 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
45402 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
45403 +
45404 +#ifdef CONFIG_PAX_ELFRELOCS
45405 + /* possible TEXTREL */
45406 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
45407 + 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);
45408 +#else
45409 + is_textrel_rw = false;
45410 + is_textrel_rx = false;
45411 +#endif
45412 +
45413 + /* possible RELRO */
45414 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
45415 +
45416 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
45417 + return;
45418 +
45419 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
45420 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
45421 +
45422 +#ifdef CONFIG_PAX_ETEXECRELOCS
45423 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45424 +#else
45425 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
45426 +#endif
45427 +
45428 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45429 + !elf_check_arch(&elf_h) ||
45430 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
45431 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
45432 + return;
45433 +
45434 + for (i = 0UL; i < elf_h.e_phnum; i++) {
45435 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
45436 + return;
45437 + switch (elf_p.p_type) {
45438 + case PT_DYNAMIC:
45439 + if (!is_textrel_rw && !is_textrel_rx)
45440 + continue;
45441 + i = 0UL;
45442 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
45443 + elf_dyn dyn;
45444 +
45445 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
45446 + return;
45447 + if (dyn.d_tag == DT_NULL)
45448 + return;
45449 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
45450 + gr_log_textrel(vma);
45451 + if (is_textrel_rw)
45452 + vma->vm_flags |= VM_MAYWRITE;
45453 + else
45454 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
45455 + vma->vm_flags &= ~VM_MAYWRITE;
45456 + return;
45457 + }
45458 + i++;
45459 + }
45460 + return;
45461 +
45462 + case PT_GNU_RELRO:
45463 + if (!is_relro)
45464 + continue;
45465 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
45466 + vma->vm_flags &= ~VM_MAYWRITE;
45467 + return;
45468 + }
45469 + }
45470 +}
45471 +#endif
45472 +
45473 static int __init init_elf_binfmt(void)
45474 {
45475 register_binfmt(&elf_format);
45476 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
45477 index e280352..7b2f231 100644
45478 --- a/fs/binfmt_flat.c
45479 +++ b/fs/binfmt_flat.c
45480 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
45481 realdatastart = (unsigned long) -ENOMEM;
45482 printk("Unable to allocate RAM for process data, errno %d\n",
45483 (int)-realdatastart);
45484 + down_write(&current->mm->mmap_sem);
45485 vm_munmap(textpos, text_len);
45486 + up_write(&current->mm->mmap_sem);
45487 ret = realdatastart;
45488 goto err;
45489 }
45490 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45491 }
45492 if (IS_ERR_VALUE(result)) {
45493 printk("Unable to read data+bss, errno %d\n", (int)-result);
45494 + down_write(&current->mm->mmap_sem);
45495 vm_munmap(textpos, text_len);
45496 vm_munmap(realdatastart, len);
45497 + up_write(&current->mm->mmap_sem);
45498 ret = result;
45499 goto err;
45500 }
45501 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45502 }
45503 if (IS_ERR_VALUE(result)) {
45504 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
45505 + down_write(&current->mm->mmap_sem);
45506 vm_munmap(textpos, text_len + data_len + extra +
45507 MAX_SHARED_LIBS * sizeof(unsigned long));
45508 + up_write(&current->mm->mmap_sem);
45509 ret = result;
45510 goto err;
45511 }
45512 diff --git a/fs/bio.c b/fs/bio.c
45513 index b96fc6c..431d628 100644
45514 --- a/fs/bio.c
45515 +++ b/fs/bio.c
45516 @@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
45517 /*
45518 * Overflow, abort
45519 */
45520 - if (end < start)
45521 + if (end < start || end - start > INT_MAX - nr_pages)
45522 return ERR_PTR(-EINVAL);
45523
45524 nr_pages += end - start;
45525 @@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
45526 /*
45527 * Overflow, abort
45528 */
45529 - if (end < start)
45530 + if (end < start || end - start > INT_MAX - nr_pages)
45531 return ERR_PTR(-EINVAL);
45532
45533 nr_pages += end - start;
45534 @@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
45535 const int read = bio_data_dir(bio) == READ;
45536 struct bio_map_data *bmd = bio->bi_private;
45537 int i;
45538 - char *p = bmd->sgvecs[0].iov_base;
45539 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
45540
45541 __bio_for_each_segment(bvec, bio, i, 0) {
45542 char *addr = page_address(bvec->bv_page);
45543 diff --git a/fs/block_dev.c b/fs/block_dev.c
45544 index ab3a456..7da538b 100644
45545 --- a/fs/block_dev.c
45546 +++ b/fs/block_dev.c
45547 @@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
45548 else if (bdev->bd_contains == bdev)
45549 return true; /* is a whole device which isn't held */
45550
45551 - else if (whole->bd_holder == bd_may_claim)
45552 + else if (whole->bd_holder == (void *)bd_may_claim)
45553 return true; /* is a partition of a device that is being partitioned */
45554 else if (whole->bd_holder != NULL)
45555 return false; /* is a partition of a held device */
45556 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
45557 index cdfb4c4..da736d4 100644
45558 --- a/fs/btrfs/ctree.c
45559 +++ b/fs/btrfs/ctree.c
45560 @@ -1035,9 +1035,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
45561 free_extent_buffer(buf);
45562 add_root_to_dirty_list(root);
45563 } else {
45564 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
45565 - parent_start = parent->start;
45566 - else
45567 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
45568 + if (parent)
45569 + parent_start = parent->start;
45570 + else
45571 + parent_start = 0;
45572 + } else
45573 parent_start = 0;
45574
45575 WARN_ON(trans->transid != btrfs_header_generation(parent));
45576 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
45577 index 95542a1..95a8727 100644
45578 --- a/fs/btrfs/inode.c
45579 +++ b/fs/btrfs/inode.c
45580 @@ -7243,7 +7243,7 @@ fail:
45581 return -ENOMEM;
45582 }
45583
45584 -static int btrfs_getattr(struct vfsmount *mnt,
45585 +int btrfs_getattr(struct vfsmount *mnt,
45586 struct dentry *dentry, struct kstat *stat)
45587 {
45588 struct inode *inode = dentry->d_inode;
45589 @@ -7257,6 +7257,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
45590 return 0;
45591 }
45592
45593 +EXPORT_SYMBOL(btrfs_getattr);
45594 +
45595 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
45596 +{
45597 + return BTRFS_I(inode)->root->anon_dev;
45598 +}
45599 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
45600 +
45601 /*
45602 * If a file is moved, it will inherit the cow and compression flags of the new
45603 * directory.
45604 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
45605 index 8fcf9a5..a200000 100644
45606 --- a/fs/btrfs/ioctl.c
45607 +++ b/fs/btrfs/ioctl.c
45608 @@ -2965,9 +2965,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45609 for (i = 0; i < num_types; i++) {
45610 struct btrfs_space_info *tmp;
45611
45612 + /* Don't copy in more than we allocated */
45613 if (!slot_count)
45614 break;
45615
45616 + slot_count--;
45617 +
45618 info = NULL;
45619 rcu_read_lock();
45620 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
45621 @@ -2989,10 +2992,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45622 memcpy(dest, &space, sizeof(space));
45623 dest++;
45624 space_args.total_spaces++;
45625 - slot_count--;
45626 }
45627 - if (!slot_count)
45628 - break;
45629 }
45630 up_read(&info->groups_sem);
45631 }
45632 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
45633 index 776f0aa..3aad281 100644
45634 --- a/fs/btrfs/relocation.c
45635 +++ b/fs/btrfs/relocation.c
45636 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
45637 }
45638 spin_unlock(&rc->reloc_root_tree.lock);
45639
45640 - BUG_ON((struct btrfs_root *)node->data != root);
45641 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
45642
45643 if (!del) {
45644 spin_lock(&rc->reloc_root_tree.lock);
45645 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
45646 index 622f469..e8d2d55 100644
45647 --- a/fs/cachefiles/bind.c
45648 +++ b/fs/cachefiles/bind.c
45649 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
45650 args);
45651
45652 /* start by checking things over */
45653 - ASSERT(cache->fstop_percent >= 0 &&
45654 - cache->fstop_percent < cache->fcull_percent &&
45655 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
45656 cache->fcull_percent < cache->frun_percent &&
45657 cache->frun_percent < 100);
45658
45659 - ASSERT(cache->bstop_percent >= 0 &&
45660 - cache->bstop_percent < cache->bcull_percent &&
45661 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
45662 cache->bcull_percent < cache->brun_percent &&
45663 cache->brun_percent < 100);
45664
45665 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
45666 index 0a1467b..6a53245 100644
45667 --- a/fs/cachefiles/daemon.c
45668 +++ b/fs/cachefiles/daemon.c
45669 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
45670 if (n > buflen)
45671 return -EMSGSIZE;
45672
45673 - if (copy_to_user(_buffer, buffer, n) != 0)
45674 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
45675 return -EFAULT;
45676
45677 return n;
45678 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
45679 if (test_bit(CACHEFILES_DEAD, &cache->flags))
45680 return -EIO;
45681
45682 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
45683 + if (datalen > PAGE_SIZE - 1)
45684 return -EOPNOTSUPP;
45685
45686 /* drag the command string into the kernel so we can parse it */
45687 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
45688 if (args[0] != '%' || args[1] != '\0')
45689 return -EINVAL;
45690
45691 - if (fstop < 0 || fstop >= cache->fcull_percent)
45692 + if (fstop >= cache->fcull_percent)
45693 return cachefiles_daemon_range_error(cache, args);
45694
45695 cache->fstop_percent = fstop;
45696 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
45697 if (args[0] != '%' || args[1] != '\0')
45698 return -EINVAL;
45699
45700 - if (bstop < 0 || bstop >= cache->bcull_percent)
45701 + if (bstop >= cache->bcull_percent)
45702 return cachefiles_daemon_range_error(cache, args);
45703
45704 cache->bstop_percent = bstop;
45705 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
45706 index bd6bc1b..b627b53 100644
45707 --- a/fs/cachefiles/internal.h
45708 +++ b/fs/cachefiles/internal.h
45709 @@ -57,7 +57,7 @@ struct cachefiles_cache {
45710 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
45711 struct rb_root active_nodes; /* active nodes (can't be culled) */
45712 rwlock_t active_lock; /* lock for active_nodes */
45713 - atomic_t gravecounter; /* graveyard uniquifier */
45714 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
45715 unsigned frun_percent; /* when to stop culling (% files) */
45716 unsigned fcull_percent; /* when to start culling (% files) */
45717 unsigned fstop_percent; /* when to stop allocating (% files) */
45718 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
45719 * proc.c
45720 */
45721 #ifdef CONFIG_CACHEFILES_HISTOGRAM
45722 -extern atomic_t cachefiles_lookup_histogram[HZ];
45723 -extern atomic_t cachefiles_mkdir_histogram[HZ];
45724 -extern atomic_t cachefiles_create_histogram[HZ];
45725 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45726 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45727 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
45728
45729 extern int __init cachefiles_proc_init(void);
45730 extern void cachefiles_proc_cleanup(void);
45731 static inline
45732 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
45733 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
45734 {
45735 unsigned long jif = jiffies - start_jif;
45736 if (jif >= HZ)
45737 jif = HZ - 1;
45738 - atomic_inc(&histogram[jif]);
45739 + atomic_inc_unchecked(&histogram[jif]);
45740 }
45741
45742 #else
45743 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
45744 index b0b5f7c..039bb26 100644
45745 --- a/fs/cachefiles/namei.c
45746 +++ b/fs/cachefiles/namei.c
45747 @@ -318,7 +318,7 @@ try_again:
45748 /* first step is to make up a grave dentry in the graveyard */
45749 sprintf(nbuffer, "%08x%08x",
45750 (uint32_t) get_seconds(),
45751 - (uint32_t) atomic_inc_return(&cache->gravecounter));
45752 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
45753
45754 /* do the multiway lock magic */
45755 trap = lock_rename(cache->graveyard, dir);
45756 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
45757 index eccd339..4c1d995 100644
45758 --- a/fs/cachefiles/proc.c
45759 +++ b/fs/cachefiles/proc.c
45760 @@ -14,9 +14,9 @@
45761 #include <linux/seq_file.h>
45762 #include "internal.h"
45763
45764 -atomic_t cachefiles_lookup_histogram[HZ];
45765 -atomic_t cachefiles_mkdir_histogram[HZ];
45766 -atomic_t cachefiles_create_histogram[HZ];
45767 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45768 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45769 +atomic_unchecked_t cachefiles_create_histogram[HZ];
45770
45771 /*
45772 * display the latency histogram
45773 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
45774 return 0;
45775 default:
45776 index = (unsigned long) v - 3;
45777 - x = atomic_read(&cachefiles_lookup_histogram[index]);
45778 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
45779 - z = atomic_read(&cachefiles_create_histogram[index]);
45780 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
45781 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
45782 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
45783 if (x == 0 && y == 0 && z == 0)
45784 return 0;
45785
45786 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
45787 index c994691..2a1537f 100644
45788 --- a/fs/cachefiles/rdwr.c
45789 +++ b/fs/cachefiles/rdwr.c
45790 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
45791 old_fs = get_fs();
45792 set_fs(KERNEL_DS);
45793 ret = file->f_op->write(
45794 - file, (const void __user *) data, len, &pos);
45795 + file, (const void __force_user *) data, len, &pos);
45796 set_fs(old_fs);
45797 kunmap(page);
45798 if (ret != len)
45799 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
45800 index e5b7731..b9c59fb 100644
45801 --- a/fs/ceph/dir.c
45802 +++ b/fs/ceph/dir.c
45803 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
45804 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
45805 struct ceph_mds_client *mdsc = fsc->mdsc;
45806 unsigned frag = fpos_frag(filp->f_pos);
45807 - int off = fpos_off(filp->f_pos);
45808 + unsigned int off = fpos_off(filp->f_pos);
45809 int err;
45810 u32 ftype;
45811 struct ceph_mds_reply_info_parsed *rinfo;
45812 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
45813 index d9ea6ed..1e6c8ac 100644
45814 --- a/fs/cifs/cifs_debug.c
45815 +++ b/fs/cifs/cifs_debug.c
45816 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45817
45818 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
45819 #ifdef CONFIG_CIFS_STATS2
45820 - atomic_set(&totBufAllocCount, 0);
45821 - atomic_set(&totSmBufAllocCount, 0);
45822 + atomic_set_unchecked(&totBufAllocCount, 0);
45823 + atomic_set_unchecked(&totSmBufAllocCount, 0);
45824 #endif /* CONFIG_CIFS_STATS2 */
45825 spin_lock(&cifs_tcp_ses_lock);
45826 list_for_each(tmp1, &cifs_tcp_ses_list) {
45827 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45828 tcon = list_entry(tmp3,
45829 struct cifs_tcon,
45830 tcon_list);
45831 - atomic_set(&tcon->num_smbs_sent, 0);
45832 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
45833 if (server->ops->clear_stats)
45834 server->ops->clear_stats(tcon);
45835 }
45836 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45837 smBufAllocCount.counter, cifs_min_small);
45838 #ifdef CONFIG_CIFS_STATS2
45839 seq_printf(m, "Total Large %d Small %d Allocations\n",
45840 - atomic_read(&totBufAllocCount),
45841 - atomic_read(&totSmBufAllocCount));
45842 + atomic_read_unchecked(&totBufAllocCount),
45843 + atomic_read_unchecked(&totSmBufAllocCount));
45844 #endif /* CONFIG_CIFS_STATS2 */
45845
45846 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
45847 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45848 if (tcon->need_reconnect)
45849 seq_puts(m, "\tDISCONNECTED ");
45850 seq_printf(m, "\nSMBs: %d",
45851 - atomic_read(&tcon->num_smbs_sent));
45852 + atomic_read_unchecked(&tcon->num_smbs_sent));
45853 if (server->ops->print_stats)
45854 server->ops->print_stats(m, tcon);
45855 }
45856 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
45857 index e7931cc..76a1ab9 100644
45858 --- a/fs/cifs/cifsfs.c
45859 +++ b/fs/cifs/cifsfs.c
45860 @@ -999,7 +999,7 @@ cifs_init_request_bufs(void)
45861 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
45862 cifs_req_cachep = kmem_cache_create("cifs_request",
45863 CIFSMaxBufSize + max_hdr_size, 0,
45864 - SLAB_HWCACHE_ALIGN, NULL);
45865 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
45866 if (cifs_req_cachep == NULL)
45867 return -ENOMEM;
45868
45869 @@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
45870 efficient to alloc 1 per page off the slab compared to 17K (5page)
45871 alloc of large cifs buffers even when page debugging is on */
45872 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
45873 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
45874 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
45875 NULL);
45876 if (cifs_sm_req_cachep == NULL) {
45877 mempool_destroy(cifs_req_poolp);
45878 @@ -1111,8 +1111,8 @@ init_cifs(void)
45879 atomic_set(&bufAllocCount, 0);
45880 atomic_set(&smBufAllocCount, 0);
45881 #ifdef CONFIG_CIFS_STATS2
45882 - atomic_set(&totBufAllocCount, 0);
45883 - atomic_set(&totSmBufAllocCount, 0);
45884 + atomic_set_unchecked(&totBufAllocCount, 0);
45885 + atomic_set_unchecked(&totSmBufAllocCount, 0);
45886 #endif /* CONFIG_CIFS_STATS2 */
45887
45888 atomic_set(&midCount, 0);
45889 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
45890 index f5af252..489b5f2 100644
45891 --- a/fs/cifs/cifsglob.h
45892 +++ b/fs/cifs/cifsglob.h
45893 @@ -751,35 +751,35 @@ struct cifs_tcon {
45894 __u16 Flags; /* optional support bits */
45895 enum statusEnum tidStatus;
45896 #ifdef CONFIG_CIFS_STATS
45897 - atomic_t num_smbs_sent;
45898 + atomic_unchecked_t num_smbs_sent;
45899 union {
45900 struct {
45901 - atomic_t num_writes;
45902 - atomic_t num_reads;
45903 - atomic_t num_flushes;
45904 - atomic_t num_oplock_brks;
45905 - atomic_t num_opens;
45906 - atomic_t num_closes;
45907 - atomic_t num_deletes;
45908 - atomic_t num_mkdirs;
45909 - atomic_t num_posixopens;
45910 - atomic_t num_posixmkdirs;
45911 - atomic_t num_rmdirs;
45912 - atomic_t num_renames;
45913 - atomic_t num_t2renames;
45914 - atomic_t num_ffirst;
45915 - atomic_t num_fnext;
45916 - atomic_t num_fclose;
45917 - atomic_t num_hardlinks;
45918 - atomic_t num_symlinks;
45919 - atomic_t num_locks;
45920 - atomic_t num_acl_get;
45921 - atomic_t num_acl_set;
45922 + atomic_unchecked_t num_writes;
45923 + atomic_unchecked_t num_reads;
45924 + atomic_unchecked_t num_flushes;
45925 + atomic_unchecked_t num_oplock_brks;
45926 + atomic_unchecked_t num_opens;
45927 + atomic_unchecked_t num_closes;
45928 + atomic_unchecked_t num_deletes;
45929 + atomic_unchecked_t num_mkdirs;
45930 + atomic_unchecked_t num_posixopens;
45931 + atomic_unchecked_t num_posixmkdirs;
45932 + atomic_unchecked_t num_rmdirs;
45933 + atomic_unchecked_t num_renames;
45934 + atomic_unchecked_t num_t2renames;
45935 + atomic_unchecked_t num_ffirst;
45936 + atomic_unchecked_t num_fnext;
45937 + atomic_unchecked_t num_fclose;
45938 + atomic_unchecked_t num_hardlinks;
45939 + atomic_unchecked_t num_symlinks;
45940 + atomic_unchecked_t num_locks;
45941 + atomic_unchecked_t num_acl_get;
45942 + atomic_unchecked_t num_acl_set;
45943 } cifs_stats;
45944 #ifdef CONFIG_CIFS_SMB2
45945 struct {
45946 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
45947 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
45948 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
45949 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
45950 } smb2_stats;
45951 #endif /* CONFIG_CIFS_SMB2 */
45952 } stats;
45953 @@ -1094,7 +1094,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
45954 }
45955
45956 #ifdef CONFIG_CIFS_STATS
45957 -#define cifs_stats_inc atomic_inc
45958 +#define cifs_stats_inc atomic_inc_unchecked
45959
45960 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
45961 unsigned int bytes)
45962 @@ -1459,8 +1459,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
45963 /* Various Debug counters */
45964 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
45965 #ifdef CONFIG_CIFS_STATS2
45966 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
45967 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
45968 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
45969 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
45970 #endif
45971 GLOBAL_EXTERN atomic_t smBufAllocCount;
45972 GLOBAL_EXTERN atomic_t midCount;
45973 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
45974 index 51dc2fb..1e12a33 100644
45975 --- a/fs/cifs/link.c
45976 +++ b/fs/cifs/link.c
45977 @@ -616,7 +616,7 @@ symlink_exit:
45978
45979 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
45980 {
45981 - char *p = nd_get_link(nd);
45982 + const char *p = nd_get_link(nd);
45983 if (!IS_ERR(p))
45984 kfree(p);
45985 }
45986 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
45987 index 3a00c0d..42d901c 100644
45988 --- a/fs/cifs/misc.c
45989 +++ b/fs/cifs/misc.c
45990 @@ -169,7 +169,7 @@ cifs_buf_get(void)
45991 memset(ret_buf, 0, buf_size + 3);
45992 atomic_inc(&bufAllocCount);
45993 #ifdef CONFIG_CIFS_STATS2
45994 - atomic_inc(&totBufAllocCount);
45995 + atomic_inc_unchecked(&totBufAllocCount);
45996 #endif /* CONFIG_CIFS_STATS2 */
45997 }
45998
45999 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
46000 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
46001 atomic_inc(&smBufAllocCount);
46002 #ifdef CONFIG_CIFS_STATS2
46003 - atomic_inc(&totSmBufAllocCount);
46004 + atomic_inc_unchecked(&totSmBufAllocCount);
46005 #endif /* CONFIG_CIFS_STATS2 */
46006
46007 }
46008 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
46009 index 591bf19..690d600 100644
46010 --- a/fs/cifs/smb1ops.c
46011 +++ b/fs/cifs/smb1ops.c
46012 @@ -617,27 +617,27 @@ static void
46013 cifs_clear_stats(struct cifs_tcon *tcon)
46014 {
46015 #ifdef CONFIG_CIFS_STATS
46016 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
46017 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
46018 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
46019 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46020 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
46021 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
46022 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46023 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
46024 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
46025 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
46026 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
46027 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
46028 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
46029 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
46030 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
46031 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
46032 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
46033 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
46034 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
46035 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
46036 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
46037 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
46038 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
46039 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
46040 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46041 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
46042 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
46043 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46044 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
46045 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
46046 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
46047 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
46048 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
46049 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
46050 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
46051 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
46052 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
46053 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
46054 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
46055 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
46056 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
46057 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
46058 #endif
46059 }
46060
46061 @@ -646,36 +646,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46062 {
46063 #ifdef CONFIG_CIFS_STATS
46064 seq_printf(m, " Oplocks breaks: %d",
46065 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
46066 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
46067 seq_printf(m, "\nReads: %d Bytes: %llu",
46068 - atomic_read(&tcon->stats.cifs_stats.num_reads),
46069 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
46070 (long long)(tcon->bytes_read));
46071 seq_printf(m, "\nWrites: %d Bytes: %llu",
46072 - atomic_read(&tcon->stats.cifs_stats.num_writes),
46073 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
46074 (long long)(tcon->bytes_written));
46075 seq_printf(m, "\nFlushes: %d",
46076 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
46077 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
46078 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
46079 - atomic_read(&tcon->stats.cifs_stats.num_locks),
46080 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
46081 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
46082 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
46083 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
46084 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
46085 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
46086 - atomic_read(&tcon->stats.cifs_stats.num_opens),
46087 - atomic_read(&tcon->stats.cifs_stats.num_closes),
46088 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
46089 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
46090 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
46091 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
46092 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
46093 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
46094 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
46095 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
46096 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
46097 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
46098 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
46099 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
46100 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
46101 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
46102 seq_printf(m, "\nRenames: %d T2 Renames %d",
46103 - atomic_read(&tcon->stats.cifs_stats.num_renames),
46104 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
46105 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
46106 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
46107 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
46108 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
46109 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
46110 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
46111 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
46112 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
46113 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
46114 #endif
46115 }
46116
46117 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
46118 index 4d9dbe0..0af4601 100644
46119 --- a/fs/cifs/smb2ops.c
46120 +++ b/fs/cifs/smb2ops.c
46121 @@ -291,8 +291,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
46122 #ifdef CONFIG_CIFS_STATS
46123 int i;
46124 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
46125 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46126 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46127 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46128 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46129 }
46130 #endif
46131 }
46132 @@ -301,66 +301,66 @@ static void
46133 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46134 {
46135 #ifdef CONFIG_CIFS_STATS
46136 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46137 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46138 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46139 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46140 seq_printf(m, "\nNegotiates: %d sent %d failed",
46141 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
46142 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
46143 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
46144 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
46145 seq_printf(m, "\nSessionSetups: %d sent %d failed",
46146 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
46147 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
46148 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
46149 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
46150 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
46151 seq_printf(m, "\nLogoffs: %d sent %d failed",
46152 - atomic_read(&sent[SMB2_LOGOFF_HE]),
46153 - atomic_read(&failed[SMB2_LOGOFF_HE]));
46154 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
46155 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
46156 seq_printf(m, "\nTreeConnects: %d sent %d failed",
46157 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
46158 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
46159 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
46160 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
46161 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
46162 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
46163 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
46164 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
46165 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
46166 seq_printf(m, "\nCreates: %d sent %d failed",
46167 - atomic_read(&sent[SMB2_CREATE_HE]),
46168 - atomic_read(&failed[SMB2_CREATE_HE]));
46169 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
46170 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
46171 seq_printf(m, "\nCloses: %d sent %d failed",
46172 - atomic_read(&sent[SMB2_CLOSE_HE]),
46173 - atomic_read(&failed[SMB2_CLOSE_HE]));
46174 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
46175 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
46176 seq_printf(m, "\nFlushes: %d sent %d failed",
46177 - atomic_read(&sent[SMB2_FLUSH_HE]),
46178 - atomic_read(&failed[SMB2_FLUSH_HE]));
46179 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
46180 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
46181 seq_printf(m, "\nReads: %d sent %d failed",
46182 - atomic_read(&sent[SMB2_READ_HE]),
46183 - atomic_read(&failed[SMB2_READ_HE]));
46184 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
46185 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
46186 seq_printf(m, "\nWrites: %d sent %d failed",
46187 - atomic_read(&sent[SMB2_WRITE_HE]),
46188 - atomic_read(&failed[SMB2_WRITE_HE]));
46189 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
46190 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
46191 seq_printf(m, "\nLocks: %d sent %d failed",
46192 - atomic_read(&sent[SMB2_LOCK_HE]),
46193 - atomic_read(&failed[SMB2_LOCK_HE]));
46194 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
46195 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
46196 seq_printf(m, "\nIOCTLs: %d sent %d failed",
46197 - atomic_read(&sent[SMB2_IOCTL_HE]),
46198 - atomic_read(&failed[SMB2_IOCTL_HE]));
46199 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
46200 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
46201 seq_printf(m, "\nCancels: %d sent %d failed",
46202 - atomic_read(&sent[SMB2_CANCEL_HE]),
46203 - atomic_read(&failed[SMB2_CANCEL_HE]));
46204 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
46205 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
46206 seq_printf(m, "\nEchos: %d sent %d failed",
46207 - atomic_read(&sent[SMB2_ECHO_HE]),
46208 - atomic_read(&failed[SMB2_ECHO_HE]));
46209 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
46210 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
46211 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
46212 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
46213 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
46214 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
46215 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
46216 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
46217 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
46218 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
46219 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
46220 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
46221 seq_printf(m, "\nQueryInfos: %d sent %d failed",
46222 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
46223 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
46224 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
46225 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
46226 seq_printf(m, "\nSetInfos: %d sent %d failed",
46227 - atomic_read(&sent[SMB2_SET_INFO_HE]),
46228 - atomic_read(&failed[SMB2_SET_INFO_HE]));
46229 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
46230 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
46231 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
46232 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
46233 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
46234 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
46235 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
46236 #endif
46237 }
46238
46239 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
46240 index 958ae0e..505c9d0 100644
46241 --- a/fs/coda/cache.c
46242 +++ b/fs/coda/cache.c
46243 @@ -24,7 +24,7 @@
46244 #include "coda_linux.h"
46245 #include "coda_cache.h"
46246
46247 -static atomic_t permission_epoch = ATOMIC_INIT(0);
46248 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
46249
46250 /* replace or extend an acl cache hit */
46251 void coda_cache_enter(struct inode *inode, int mask)
46252 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
46253 struct coda_inode_info *cii = ITOC(inode);
46254
46255 spin_lock(&cii->c_lock);
46256 - cii->c_cached_epoch = atomic_read(&permission_epoch);
46257 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
46258 if (cii->c_uid != current_fsuid()) {
46259 cii->c_uid = current_fsuid();
46260 cii->c_cached_perm = mask;
46261 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
46262 {
46263 struct coda_inode_info *cii = ITOC(inode);
46264 spin_lock(&cii->c_lock);
46265 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
46266 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
46267 spin_unlock(&cii->c_lock);
46268 }
46269
46270 /* remove all acl caches */
46271 void coda_cache_clear_all(struct super_block *sb)
46272 {
46273 - atomic_inc(&permission_epoch);
46274 + atomic_inc_unchecked(&permission_epoch);
46275 }
46276
46277
46278 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
46279 spin_lock(&cii->c_lock);
46280 hit = (mask & cii->c_cached_perm) == mask &&
46281 cii->c_uid == current_fsuid() &&
46282 - cii->c_cached_epoch == atomic_read(&permission_epoch);
46283 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
46284 spin_unlock(&cii->c_lock);
46285
46286 return hit;
46287 diff --git a/fs/compat.c b/fs/compat.c
46288 index 015e1e1..5ce8e54 100644
46289 --- a/fs/compat.c
46290 +++ b/fs/compat.c
46291 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
46292
46293 set_fs(KERNEL_DS);
46294 /* The __user pointer cast is valid because of the set_fs() */
46295 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
46296 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
46297 set_fs(oldfs);
46298 /* truncating is ok because it's a user address */
46299 if (!ret)
46300 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
46301 goto out;
46302
46303 ret = -EINVAL;
46304 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
46305 + if (nr_segs > UIO_MAXIOV)
46306 goto out;
46307 if (nr_segs > fast_segs) {
46308 ret = -ENOMEM;
46309 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
46310
46311 struct compat_readdir_callback {
46312 struct compat_old_linux_dirent __user *dirent;
46313 + struct file * file;
46314 int result;
46315 };
46316
46317 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
46318 buf->result = -EOVERFLOW;
46319 return -EOVERFLOW;
46320 }
46321 +
46322 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46323 + return 0;
46324 +
46325 buf->result++;
46326 dirent = buf->dirent;
46327 if (!access_ok(VERIFY_WRITE, dirent,
46328 @@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
46329
46330 buf.result = 0;
46331 buf.dirent = dirent;
46332 + buf.file = f.file;
46333
46334 error = vfs_readdir(f.file, compat_fillonedir, &buf);
46335 if (buf.result)
46336 @@ -897,6 +903,7 @@ struct compat_linux_dirent {
46337 struct compat_getdents_callback {
46338 struct compat_linux_dirent __user *current_dir;
46339 struct compat_linux_dirent __user *previous;
46340 + struct file * file;
46341 int count;
46342 int error;
46343 };
46344 @@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
46345 buf->error = -EOVERFLOW;
46346 return -EOVERFLOW;
46347 }
46348 +
46349 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46350 + return 0;
46351 +
46352 dirent = buf->previous;
46353 if (dirent) {
46354 if (__put_user(offset, &dirent->d_off))
46355 @@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
46356 buf.previous = NULL;
46357 buf.count = count;
46358 buf.error = 0;
46359 + buf.file = f.file;
46360
46361 error = vfs_readdir(f.file, compat_filldir, &buf);
46362 if (error >= 0)
46363 @@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
46364 struct compat_getdents_callback64 {
46365 struct linux_dirent64 __user *current_dir;
46366 struct linux_dirent64 __user *previous;
46367 + struct file * file;
46368 int count;
46369 int error;
46370 };
46371 @@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
46372 buf->error = -EINVAL; /* only used if we fail.. */
46373 if (reclen > buf->count)
46374 return -EINVAL;
46375 +
46376 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46377 + return 0;
46378 +
46379 dirent = buf->previous;
46380
46381 if (dirent) {
46382 @@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
46383 buf.previous = NULL;
46384 buf.count = count;
46385 buf.error = 0;
46386 + buf.file = f.file;
46387
46388 error = vfs_readdir(f.file, compat_filldir64, &buf);
46389 if (error >= 0)
46390 error = buf.error;
46391 lastdirent = buf.previous;
46392 if (lastdirent) {
46393 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
46394 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
46395 if (__put_user_unaligned(d_off, &lastdirent->d_off))
46396 error = -EFAULT;
46397 else
46398 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
46399 index a81147e..20bf2b5 100644
46400 --- a/fs/compat_binfmt_elf.c
46401 +++ b/fs/compat_binfmt_elf.c
46402 @@ -30,11 +30,13 @@
46403 #undef elf_phdr
46404 #undef elf_shdr
46405 #undef elf_note
46406 +#undef elf_dyn
46407 #undef elf_addr_t
46408 #define elfhdr elf32_hdr
46409 #define elf_phdr elf32_phdr
46410 #define elf_shdr elf32_shdr
46411 #define elf_note elf32_note
46412 +#define elf_dyn Elf32_Dyn
46413 #define elf_addr_t Elf32_Addr
46414
46415 /*
46416 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
46417 index 4c6285f..b7a2411 100644
46418 --- a/fs/compat_ioctl.c
46419 +++ b/fs/compat_ioctl.c
46420 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
46421 return -EFAULT;
46422 if (__get_user(udata, &ss32->iomem_base))
46423 return -EFAULT;
46424 - ss.iomem_base = compat_ptr(udata);
46425 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
46426 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
46427 __get_user(ss.port_high, &ss32->port_high))
46428 return -EFAULT;
46429 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
46430 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
46431 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
46432 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
46433 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46434 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46435 return -EFAULT;
46436
46437 return ioctl_preallocate(file, p);
46438 @@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
46439 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
46440 {
46441 unsigned int a, b;
46442 - a = *(unsigned int *)p;
46443 - b = *(unsigned int *)q;
46444 + a = *(const unsigned int *)p;
46445 + b = *(const unsigned int *)q;
46446 if (a > b)
46447 return 1;
46448 if (a < b)
46449 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
46450 index 7414ae2..d98ad6d 100644
46451 --- a/fs/configfs/dir.c
46452 +++ b/fs/configfs/dir.c
46453 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46454 }
46455 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
46456 struct configfs_dirent *next;
46457 - const char * name;
46458 + const unsigned char * name;
46459 + char d_name[sizeof(next->s_dentry->d_iname)];
46460 int len;
46461 struct inode *inode = NULL;
46462
46463 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46464 continue;
46465
46466 name = configfs_get_name(next);
46467 - len = strlen(name);
46468 + if (next->s_dentry && name == next->s_dentry->d_iname) {
46469 + len = next->s_dentry->d_name.len;
46470 + memcpy(d_name, name, len);
46471 + name = d_name;
46472 + } else
46473 + len = strlen(name);
46474
46475 /*
46476 * We'll have a dentry and an inode for
46477 diff --git a/fs/coredump.c b/fs/coredump.c
46478 index ce47379..68c8e43 100644
46479 --- a/fs/coredump.c
46480 +++ b/fs/coredump.c
46481 @@ -52,7 +52,7 @@ struct core_name {
46482 char *corename;
46483 int used, size;
46484 };
46485 -static atomic_t call_count = ATOMIC_INIT(1);
46486 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
46487
46488 /* The maximal length of core_pattern is also specified in sysctl.c */
46489
46490 @@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
46491 {
46492 char *old_corename = cn->corename;
46493
46494 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
46495 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
46496 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
46497
46498 if (!cn->corename) {
46499 @@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
46500 int pid_in_pattern = 0;
46501 int err = 0;
46502
46503 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
46504 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
46505 cn->corename = kmalloc(cn->size, GFP_KERNEL);
46506 cn->used = 0;
46507
46508 @@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
46509 pipe = file->f_path.dentry->d_inode->i_pipe;
46510
46511 pipe_lock(pipe);
46512 - pipe->readers++;
46513 - pipe->writers--;
46514 + atomic_inc(&pipe->readers);
46515 + atomic_dec(&pipe->writers);
46516
46517 - while ((pipe->readers > 1) && (!signal_pending(current))) {
46518 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
46519 wake_up_interruptible_sync(&pipe->wait);
46520 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
46521 pipe_wait(pipe);
46522 }
46523
46524 - pipe->readers--;
46525 - pipe->writers++;
46526 + atomic_dec(&pipe->readers);
46527 + atomic_inc(&pipe->writers);
46528 pipe_unlock(pipe);
46529
46530 }
46531 @@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46532 int ispipe;
46533 struct files_struct *displaced;
46534 bool need_nonrelative = false;
46535 - static atomic_t core_dump_count = ATOMIC_INIT(0);
46536 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
46537 + long signr = siginfo->si_signo;
46538 struct coredump_params cprm = {
46539 .siginfo = siginfo,
46540 .regs = regs,
46541 @@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46542 .mm_flags = mm->flags,
46543 };
46544
46545 - audit_core_dumps(siginfo->si_signo);
46546 + audit_core_dumps(signr);
46547 +
46548 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
46549 + gr_handle_brute_attach(cprm.mm_flags);
46550
46551 binfmt = mm->binfmt;
46552 if (!binfmt || !binfmt->core_dump)
46553 @@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46554 need_nonrelative = true;
46555 }
46556
46557 - retval = coredump_wait(siginfo->si_signo, &core_state);
46558 + retval = coredump_wait(signr, &core_state);
46559 if (retval < 0)
46560 goto fail_creds;
46561
46562 @@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46563 }
46564 cprm.limit = RLIM_INFINITY;
46565
46566 - dump_count = atomic_inc_return(&core_dump_count);
46567 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
46568 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
46569 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
46570 task_tgid_vnr(current), current->comm);
46571 @@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46572 } else {
46573 struct inode *inode;
46574
46575 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
46576 +
46577 if (cprm.limit < binfmt->min_coredump)
46578 goto fail_unlock;
46579
46580 @@ -640,7 +646,7 @@ close_fail:
46581 filp_close(cprm.file, NULL);
46582 fail_dropcount:
46583 if (ispipe)
46584 - atomic_dec(&core_dump_count);
46585 + atomic_dec_unchecked(&core_dump_count);
46586 fail_unlock:
46587 kfree(cn.corename);
46588 fail_corename:
46589 @@ -659,7 +665,7 @@ fail:
46590 */
46591 int dump_write(struct file *file, const void *addr, int nr)
46592 {
46593 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
46594 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
46595 }
46596 EXPORT_SYMBOL(dump_write);
46597
46598 diff --git a/fs/dcache.c b/fs/dcache.c
46599 index 0d0adb6..f4646e9 100644
46600 --- a/fs/dcache.c
46601 +++ b/fs/dcache.c
46602 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
46603 mempages -= reserve;
46604
46605 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
46606 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
46607 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
46608
46609 dcache_init();
46610 inode_init();
46611 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
46612 index b607d92..41fda09 100644
46613 --- a/fs/debugfs/inode.c
46614 +++ b/fs/debugfs/inode.c
46615 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
46616 */
46617 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
46618 {
46619 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
46620 + return __create_file(name, S_IFDIR | S_IRWXU,
46621 +#else
46622 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
46623 +#endif
46624 parent, NULL, NULL);
46625 }
46626 EXPORT_SYMBOL_GPL(debugfs_create_dir);
46627 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
46628 index cc7709e..7e7211f 100644
46629 --- a/fs/ecryptfs/inode.c
46630 +++ b/fs/ecryptfs/inode.c
46631 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
46632 old_fs = get_fs();
46633 set_fs(get_ds());
46634 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
46635 - (char __user *)lower_buf,
46636 + (char __force_user *)lower_buf,
46637 PATH_MAX);
46638 set_fs(old_fs);
46639 if (rc < 0)
46640 @@ -706,7 +706,7 @@ out:
46641 static void
46642 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
46643 {
46644 - char *buf = nd_get_link(nd);
46645 + const char *buf = nd_get_link(nd);
46646 if (!IS_ERR(buf)) {
46647 /* Free the char* */
46648 kfree(buf);
46649 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
46650 index 412e6ed..4292d22 100644
46651 --- a/fs/ecryptfs/miscdev.c
46652 +++ b/fs/ecryptfs/miscdev.c
46653 @@ -315,7 +315,7 @@ check_list:
46654 goto out_unlock_msg_ctx;
46655 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
46656 if (msg_ctx->msg) {
46657 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
46658 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
46659 goto out_unlock_msg_ctx;
46660 i += packet_length_size;
46661 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
46662 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
46663 index b2a34a1..162fa69 100644
46664 --- a/fs/ecryptfs/read_write.c
46665 +++ b/fs/ecryptfs/read_write.c
46666 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
46667 return -EIO;
46668 fs_save = get_fs();
46669 set_fs(get_ds());
46670 - rc = vfs_write(lower_file, data, size, &offset);
46671 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
46672 set_fs(fs_save);
46673 mark_inode_dirty_sync(ecryptfs_inode);
46674 return rc;
46675 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
46676 return -EIO;
46677 fs_save = get_fs();
46678 set_fs(get_ds());
46679 - rc = vfs_read(lower_file, data, size, &offset);
46680 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
46681 set_fs(fs_save);
46682 return rc;
46683 }
46684 diff --git a/fs/exec.c b/fs/exec.c
46685 index c6e6de4..90a9d6e 100644
46686 --- a/fs/exec.c
46687 +++ b/fs/exec.c
46688 @@ -55,6 +55,17 @@
46689 #include <linux/pipe_fs_i.h>
46690 #include <linux/oom.h>
46691 #include <linux/compat.h>
46692 +#include <linux/random.h>
46693 +#include <linux/seq_file.h>
46694 +#include <linux/coredump.h>
46695 +#include <linux/mman.h>
46696 +
46697 +#ifdef CONFIG_PAX_REFCOUNT
46698 +#include <linux/kallsyms.h>
46699 +#include <linux/kdebug.h>
46700 +#endif
46701 +
46702 +#include <trace/events/fs.h>
46703
46704 #include <asm/uaccess.h>
46705 #include <asm/mmu_context.h>
46706 @@ -66,6 +77,18 @@
46707
46708 #include <trace/events/sched.h>
46709
46710 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
46711 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
46712 +{
46713 + 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");
46714 +}
46715 +#endif
46716 +
46717 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
46718 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
46719 +EXPORT_SYMBOL(pax_set_initial_flags_func);
46720 +#endif
46721 +
46722 int suid_dumpable = 0;
46723
46724 static LIST_HEAD(formats);
46725 @@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46726 int write)
46727 {
46728 struct page *page;
46729 - int ret;
46730
46731 -#ifdef CONFIG_STACK_GROWSUP
46732 - if (write) {
46733 - ret = expand_downwards(bprm->vma, pos);
46734 - if (ret < 0)
46735 - return NULL;
46736 - }
46737 -#endif
46738 - ret = get_user_pages(current, bprm->mm, pos,
46739 - 1, write, 1, &page, NULL);
46740 - if (ret <= 0)
46741 + if (0 > expand_downwards(bprm->vma, pos))
46742 + return NULL;
46743 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
46744 return NULL;
46745
46746 if (write) {
46747 @@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46748 if (size <= ARG_MAX)
46749 return page;
46750
46751 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46752 + // only allow 512KB for argv+env on suid/sgid binaries
46753 + // to prevent easy ASLR exhaustion
46754 + if (((bprm->cred->euid != current_euid()) ||
46755 + (bprm->cred->egid != current_egid())) &&
46756 + (size > (512 * 1024))) {
46757 + put_page(page);
46758 + return NULL;
46759 + }
46760 +#endif
46761 +
46762 /*
46763 * Limit to 1/4-th the stack size for the argv+env strings.
46764 * This ensures that:
46765 @@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46766 vma->vm_end = STACK_TOP_MAX;
46767 vma->vm_start = vma->vm_end - PAGE_SIZE;
46768 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
46769 +
46770 +#ifdef CONFIG_PAX_SEGMEXEC
46771 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
46772 +#endif
46773 +
46774 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
46775 INIT_LIST_HEAD(&vma->anon_vma_chain);
46776
46777 @@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46778 mm->stack_vm = mm->total_vm = 1;
46779 up_write(&mm->mmap_sem);
46780 bprm->p = vma->vm_end - sizeof(void *);
46781 +
46782 +#ifdef CONFIG_PAX_RANDUSTACK
46783 + if (randomize_va_space)
46784 + bprm->p ^= random32() & ~PAGE_MASK;
46785 +#endif
46786 +
46787 return 0;
46788 err:
46789 up_write(&mm->mmap_sem);
46790 @@ -384,19 +421,7 @@ err:
46791 return err;
46792 }
46793
46794 -struct user_arg_ptr {
46795 -#ifdef CONFIG_COMPAT
46796 - bool is_compat;
46797 -#endif
46798 - union {
46799 - const char __user *const __user *native;
46800 -#ifdef CONFIG_COMPAT
46801 - const compat_uptr_t __user *compat;
46802 -#endif
46803 - } ptr;
46804 -};
46805 -
46806 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46807 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46808 {
46809 const char __user *native;
46810
46811 @@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46812 compat_uptr_t compat;
46813
46814 if (get_user(compat, argv.ptr.compat + nr))
46815 - return ERR_PTR(-EFAULT);
46816 + return (const char __force_user *)ERR_PTR(-EFAULT);
46817
46818 return compat_ptr(compat);
46819 }
46820 #endif
46821
46822 if (get_user(native, argv.ptr.native + nr))
46823 - return ERR_PTR(-EFAULT);
46824 + return (const char __force_user *)ERR_PTR(-EFAULT);
46825
46826 return native;
46827 }
46828 @@ -431,11 +456,12 @@ static int count(struct user_arg_ptr argv, int max)
46829 if (!p)
46830 break;
46831
46832 - if (IS_ERR(p))
46833 + if (IS_ERR((const char __force_kernel *)p))
46834 return -EFAULT;
46835
46836 - if (i++ >= max)
46837 + if (i >= max)
46838 return -E2BIG;
46839 + ++i;
46840
46841 if (fatal_signal_pending(current))
46842 return -ERESTARTNOHAND;
46843 @@ -465,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
46844
46845 ret = -EFAULT;
46846 str = get_user_arg_ptr(argv, argc);
46847 - if (IS_ERR(str))
46848 + if (IS_ERR((const char __force_kernel *)str))
46849 goto out;
46850
46851 len = strnlen_user(str, MAX_ARG_STRLEN);
46852 @@ -547,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
46853 int r;
46854 mm_segment_t oldfs = get_fs();
46855 struct user_arg_ptr argv = {
46856 - .ptr.native = (const char __user *const __user *)__argv,
46857 + .ptr.native = (const char __force_user *const __force_user *)__argv,
46858 };
46859
46860 set_fs(KERNEL_DS);
46861 @@ -582,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46862 unsigned long new_end = old_end - shift;
46863 struct mmu_gather tlb;
46864
46865 - BUG_ON(new_start > new_end);
46866 + if (new_start >= new_end || new_start < mmap_min_addr)
46867 + return -ENOMEM;
46868
46869 /*
46870 * ensure there are no vmas between where we want to go
46871 @@ -591,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46872 if (vma != find_vma(mm, new_start))
46873 return -EFAULT;
46874
46875 +#ifdef CONFIG_PAX_SEGMEXEC
46876 + BUG_ON(pax_find_mirror_vma(vma));
46877 +#endif
46878 +
46879 /*
46880 * cover the whole range: [new_start, old_end)
46881 */
46882 @@ -671,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46883 stack_top = arch_align_stack(stack_top);
46884 stack_top = PAGE_ALIGN(stack_top);
46885
46886 - if (unlikely(stack_top < mmap_min_addr) ||
46887 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
46888 - return -ENOMEM;
46889 -
46890 stack_shift = vma->vm_end - stack_top;
46891
46892 bprm->p -= stack_shift;
46893 @@ -686,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
46894 bprm->exec -= stack_shift;
46895
46896 down_write(&mm->mmap_sem);
46897 +
46898 + /* Move stack pages down in memory. */
46899 + if (stack_shift) {
46900 + ret = shift_arg_pages(vma, stack_shift);
46901 + if (ret)
46902 + goto out_unlock;
46903 + }
46904 +
46905 vm_flags = VM_STACK_FLAGS;
46906
46907 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46908 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46909 + vm_flags &= ~VM_EXEC;
46910 +
46911 +#ifdef CONFIG_PAX_MPROTECT
46912 + if (mm->pax_flags & MF_PAX_MPROTECT)
46913 + vm_flags &= ~VM_MAYEXEC;
46914 +#endif
46915 +
46916 + }
46917 +#endif
46918 +
46919 /*
46920 * Adjust stack execute permissions; explicitly enable for
46921 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
46922 @@ -706,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46923 goto out_unlock;
46924 BUG_ON(prev != vma);
46925
46926 - /* Move stack pages down in memory. */
46927 - if (stack_shift) {
46928 - ret = shift_arg_pages(vma, stack_shift);
46929 - if (ret)
46930 - goto out_unlock;
46931 - }
46932 -
46933 /* mprotect_fixup is overkill to remove the temporary stack flags */
46934 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
46935
46936 @@ -736,6 +776,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
46937 #endif
46938 current->mm->start_stack = bprm->p;
46939 ret = expand_stack(vma, stack_base);
46940 +
46941 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
46942 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
46943 + unsigned long size, flags, vm_flags;
46944 +
46945 + size = STACK_TOP - vma->vm_end;
46946 + flags = MAP_FIXED | MAP_PRIVATE;
46947 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
46948 +
46949 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
46950 +
46951 +#ifdef CONFIG_X86
46952 + if (!ret) {
46953 + size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
46954 + ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
46955 + }
46956 +#endif
46957 +
46958 + }
46959 +#endif
46960 +
46961 if (ret)
46962 ret = -EFAULT;
46963
46964 @@ -771,6 +832,8 @@ struct file *open_exec(const char *name)
46965
46966 fsnotify_open(file);
46967
46968 + trace_open_exec(name);
46969 +
46970 err = deny_write_access(file);
46971 if (err)
46972 goto exit;
46973 @@ -794,7 +857,7 @@ int kernel_read(struct file *file, loff_t offset,
46974 old_fs = get_fs();
46975 set_fs(get_ds());
46976 /* The cast to a user pointer is valid due to the set_fs() */
46977 - result = vfs_read(file, (void __user *)addr, count, &pos);
46978 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
46979 set_fs(old_fs);
46980 return result;
46981 }
46982 @@ -1246,7 +1309,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
46983 }
46984 rcu_read_unlock();
46985
46986 - if (p->fs->users > n_fs) {
46987 + if (atomic_read(&p->fs->users) > n_fs) {
46988 bprm->unsafe |= LSM_UNSAFE_SHARE;
46989 } else {
46990 res = -EAGAIN;
46991 @@ -1449,6 +1512,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
46992
46993 EXPORT_SYMBOL(search_binary_handler);
46994
46995 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46996 +static DEFINE_PER_CPU(u64, exec_counter);
46997 +static int __init init_exec_counters(void)
46998 +{
46999 + unsigned int cpu;
47000 +
47001 + for_each_possible_cpu(cpu) {
47002 + per_cpu(exec_counter, cpu) = (u64)cpu;
47003 + }
47004 +
47005 + return 0;
47006 +}
47007 +early_initcall(init_exec_counters);
47008 +static inline void increment_exec_counter(void)
47009 +{
47010 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
47011 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
47012 +}
47013 +#else
47014 +static inline void increment_exec_counter(void) {}
47015 +#endif
47016 +
47017 /*
47018 * sys_execve() executes a new program.
47019 */
47020 @@ -1457,6 +1542,11 @@ static int do_execve_common(const char *filename,
47021 struct user_arg_ptr envp,
47022 struct pt_regs *regs)
47023 {
47024 +#ifdef CONFIG_GRKERNSEC
47025 + struct file *old_exec_file;
47026 + struct acl_subject_label *old_acl;
47027 + struct rlimit old_rlim[RLIM_NLIMITS];
47028 +#endif
47029 struct linux_binprm *bprm;
47030 struct file *file;
47031 struct files_struct *displaced;
47032 @@ -1464,6 +1554,8 @@ static int do_execve_common(const char *filename,
47033 int retval;
47034 const struct cred *cred = current_cred();
47035
47036 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
47037 +
47038 /*
47039 * We move the actual failure in case of RLIMIT_NPROC excess from
47040 * set*uid() to execve() because too many poorly written programs
47041 @@ -1504,12 +1596,27 @@ static int do_execve_common(const char *filename,
47042 if (IS_ERR(file))
47043 goto out_unmark;
47044
47045 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
47046 + retval = -EPERM;
47047 + goto out_file;
47048 + }
47049 +
47050 sched_exec();
47051
47052 bprm->file = file;
47053 bprm->filename = filename;
47054 bprm->interp = filename;
47055
47056 + if (gr_process_user_ban()) {
47057 + retval = -EPERM;
47058 + goto out_file;
47059 + }
47060 +
47061 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
47062 + retval = -EACCES;
47063 + goto out_file;
47064 + }
47065 +
47066 retval = bprm_mm_init(bprm);
47067 if (retval)
47068 goto out_file;
47069 @@ -1526,24 +1633,65 @@ static int do_execve_common(const char *filename,
47070 if (retval < 0)
47071 goto out;
47072
47073 +#ifdef CONFIG_GRKERNSEC
47074 + old_acl = current->acl;
47075 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
47076 + old_exec_file = current->exec_file;
47077 + get_file(file);
47078 + current->exec_file = file;
47079 +#endif
47080 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47081 + /* limit suid stack to 8MB
47082 + we saved the old limits above and will restore them if this exec fails
47083 + */
47084 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
47085 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
47086 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
47087 +#endif
47088 +
47089 + if (!gr_tpe_allow(file)) {
47090 + retval = -EACCES;
47091 + goto out_fail;
47092 + }
47093 +
47094 + if (gr_check_crash_exec(file)) {
47095 + retval = -EACCES;
47096 + goto out_fail;
47097 + }
47098 +
47099 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
47100 + bprm->unsafe);
47101 + if (retval < 0)
47102 + goto out_fail;
47103 +
47104 retval = copy_strings_kernel(1, &bprm->filename, bprm);
47105 if (retval < 0)
47106 - goto out;
47107 + goto out_fail;
47108
47109 bprm->exec = bprm->p;
47110 retval = copy_strings(bprm->envc, envp, bprm);
47111 if (retval < 0)
47112 - goto out;
47113 + goto out_fail;
47114
47115 retval = copy_strings(bprm->argc, argv, bprm);
47116 if (retval < 0)
47117 - goto out;
47118 + goto out_fail;
47119 +
47120 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
47121 +
47122 + gr_handle_exec_args(bprm, argv);
47123
47124 retval = search_binary_handler(bprm,regs);
47125 if (retval < 0)
47126 - goto out;
47127 + goto out_fail;
47128 +#ifdef CONFIG_GRKERNSEC
47129 + if (old_exec_file)
47130 + fput(old_exec_file);
47131 +#endif
47132
47133 /* execve succeeded */
47134 +
47135 + increment_exec_counter();
47136 current->fs->in_exec = 0;
47137 current->in_execve = 0;
47138 acct_update_integrals(current);
47139 @@ -1552,6 +1700,14 @@ static int do_execve_common(const char *filename,
47140 put_files_struct(displaced);
47141 return retval;
47142
47143 +out_fail:
47144 +#ifdef CONFIG_GRKERNSEC
47145 + current->acl = old_acl;
47146 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
47147 + fput(current->exec_file);
47148 + current->exec_file = old_exec_file;
47149 +#endif
47150 +
47151 out:
47152 if (bprm->mm) {
47153 acct_arg_size(bprm, 0);
47154 @@ -1727,3 +1883,253 @@ int kernel_execve(const char *filename,
47155 ret_from_kernel_execve(p);
47156 }
47157 #endif
47158 +
47159 +int pax_check_flags(unsigned long *flags)
47160 +{
47161 + int retval = 0;
47162 +
47163 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
47164 + if (*flags & MF_PAX_SEGMEXEC)
47165 + {
47166 + *flags &= ~MF_PAX_SEGMEXEC;
47167 + retval = -EINVAL;
47168 + }
47169 +#endif
47170 +
47171 + if ((*flags & MF_PAX_PAGEEXEC)
47172 +
47173 +#ifdef CONFIG_PAX_PAGEEXEC
47174 + && (*flags & MF_PAX_SEGMEXEC)
47175 +#endif
47176 +
47177 + )
47178 + {
47179 + *flags &= ~MF_PAX_PAGEEXEC;
47180 + retval = -EINVAL;
47181 + }
47182 +
47183 + if ((*flags & MF_PAX_MPROTECT)
47184 +
47185 +#ifdef CONFIG_PAX_MPROTECT
47186 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47187 +#endif
47188 +
47189 + )
47190 + {
47191 + *flags &= ~MF_PAX_MPROTECT;
47192 + retval = -EINVAL;
47193 + }
47194 +
47195 + if ((*flags & MF_PAX_EMUTRAMP)
47196 +
47197 +#ifdef CONFIG_PAX_EMUTRAMP
47198 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47199 +#endif
47200 +
47201 + )
47202 + {
47203 + *flags &= ~MF_PAX_EMUTRAMP;
47204 + retval = -EINVAL;
47205 + }
47206 +
47207 + return retval;
47208 +}
47209 +
47210 +EXPORT_SYMBOL(pax_check_flags);
47211 +
47212 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47213 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
47214 +{
47215 + struct task_struct *tsk = current;
47216 + struct mm_struct *mm = current->mm;
47217 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
47218 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
47219 + char *path_exec = NULL;
47220 + char *path_fault = NULL;
47221 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
47222 + siginfo_t info = { };
47223 +
47224 + if (buffer_exec && buffer_fault) {
47225 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
47226 +
47227 + down_read(&mm->mmap_sem);
47228 + vma = mm->mmap;
47229 + while (vma && (!vma_exec || !vma_fault)) {
47230 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
47231 + vma_exec = vma;
47232 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
47233 + vma_fault = vma;
47234 + vma = vma->vm_next;
47235 + }
47236 + if (vma_exec) {
47237 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
47238 + if (IS_ERR(path_exec))
47239 + path_exec = "<path too long>";
47240 + else {
47241 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
47242 + if (path_exec) {
47243 + *path_exec = 0;
47244 + path_exec = buffer_exec;
47245 + } else
47246 + path_exec = "<path too long>";
47247 + }
47248 + }
47249 + if (vma_fault) {
47250 + start = vma_fault->vm_start;
47251 + end = vma_fault->vm_end;
47252 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
47253 + if (vma_fault->vm_file) {
47254 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
47255 + if (IS_ERR(path_fault))
47256 + path_fault = "<path too long>";
47257 + else {
47258 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
47259 + if (path_fault) {
47260 + *path_fault = 0;
47261 + path_fault = buffer_fault;
47262 + } else
47263 + path_fault = "<path too long>";
47264 + }
47265 + } else
47266 + path_fault = "<anonymous mapping>";
47267 + }
47268 + up_read(&mm->mmap_sem);
47269 + }
47270 + if (tsk->signal->curr_ip)
47271 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
47272 + else
47273 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
47274 + 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),
47275 + from_kuid(&init_user_ns, task_uid(tsk)), from_kuid(&init_user_ns, task_euid(tsk)), pc, sp);
47276 + free_page((unsigned long)buffer_exec);
47277 + free_page((unsigned long)buffer_fault);
47278 + pax_report_insns(regs, pc, sp);
47279 + info.si_signo = SIGKILL;
47280 + info.si_errno = 0;
47281 + info.si_code = SI_KERNEL;
47282 + info.si_pid = 0;
47283 + info.si_uid = 0;
47284 + do_coredump(&info, regs);
47285 +}
47286 +#endif
47287 +
47288 +#ifdef CONFIG_PAX_REFCOUNT
47289 +void pax_report_refcount_overflow(struct pt_regs *regs)
47290 +{
47291 + if (current->signal->curr_ip)
47292 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
47293 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
47294 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
47295 + else
47296 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
47297 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
47298 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
47299 + show_regs(regs);
47300 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
47301 +}
47302 +#endif
47303 +
47304 +#ifdef CONFIG_PAX_USERCOPY
47305 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
47306 +static noinline int check_stack_object(const void *obj, unsigned long len)
47307 +{
47308 + const void * const stack = task_stack_page(current);
47309 + const void * const stackend = stack + THREAD_SIZE;
47310 +
47311 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
47312 + const void *frame = NULL;
47313 + const void *oldframe;
47314 +#endif
47315 +
47316 + if (obj + len < obj)
47317 + return -1;
47318 +
47319 + if (obj + len <= stack || stackend <= obj)
47320 + return 0;
47321 +
47322 + if (obj < stack || stackend < obj + len)
47323 + return -1;
47324 +
47325 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
47326 + oldframe = __builtin_frame_address(1);
47327 + if (oldframe)
47328 + frame = __builtin_frame_address(2);
47329 + /*
47330 + low ----------------------------------------------> high
47331 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
47332 + ^----------------^
47333 + allow copies only within here
47334 + */
47335 + while (stack <= frame && frame < stackend) {
47336 + /* if obj + len extends past the last frame, this
47337 + check won't pass and the next frame will be 0,
47338 + causing us to bail out and correctly report
47339 + the copy as invalid
47340 + */
47341 + if (obj + len <= frame)
47342 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
47343 + oldframe = frame;
47344 + frame = *(const void * const *)frame;
47345 + }
47346 + return -1;
47347 +#else
47348 + return 1;
47349 +#endif
47350 +}
47351 +
47352 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
47353 +{
47354 + if (current->signal->curr_ip)
47355 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
47356 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
47357 + else
47358 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
47359 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
47360 + dump_stack();
47361 + gr_handle_kernel_exploit();
47362 + do_group_exit(SIGKILL);
47363 +}
47364 +#endif
47365 +
47366 +void check_object_size(const void *ptr, unsigned long n, bool to)
47367 +{
47368 +
47369 +#ifdef CONFIG_PAX_USERCOPY
47370 + const char *type;
47371 +
47372 + if (!n)
47373 + return;
47374 +
47375 + type = check_heap_object(ptr, n);
47376 + if (!type) {
47377 + if (check_stack_object(ptr, n) != -1)
47378 + return;
47379 + type = "<process stack>";
47380 + }
47381 +
47382 + pax_report_usercopy(ptr, n, to, type);
47383 +#endif
47384 +
47385 +}
47386 +EXPORT_SYMBOL(check_object_size);
47387 +
47388 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
47389 +void pax_track_stack(void)
47390 +{
47391 + unsigned long sp = (unsigned long)&sp;
47392 + if (sp < current_thread_info()->lowest_stack &&
47393 + sp > (unsigned long)task_stack_page(current))
47394 + current_thread_info()->lowest_stack = sp;
47395 +}
47396 +EXPORT_SYMBOL(pax_track_stack);
47397 +#endif
47398 +
47399 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
47400 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
47401 +{
47402 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
47403 + dump_stack();
47404 + do_group_exit(SIGKILL);
47405 +}
47406 +EXPORT_SYMBOL(report_size_overflow);
47407 +#endif
47408 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
47409 index 2616d0e..2ffdec9 100644
47410 --- a/fs/ext2/balloc.c
47411 +++ b/fs/ext2/balloc.c
47412 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
47413
47414 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47415 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47416 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47417 + if (free_blocks < root_blocks + 1 &&
47418 !uid_eq(sbi->s_resuid, current_fsuid()) &&
47419 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47420 - !in_group_p (sbi->s_resgid))) {
47421 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47422 return 0;
47423 }
47424 return 1;
47425 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
47426 index 22548f5..41521d8 100644
47427 --- a/fs/ext3/balloc.c
47428 +++ b/fs/ext3/balloc.c
47429 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
47430
47431 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47432 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47433 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47434 + if (free_blocks < root_blocks + 1 &&
47435 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
47436 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47437 - !in_group_p (sbi->s_resgid))) {
47438 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47439 return 0;
47440 }
47441 return 1;
47442 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
47443 index cf18217..8f6b9c3 100644
47444 --- a/fs/ext4/balloc.c
47445 +++ b/fs/ext4/balloc.c
47446 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
47447 /* Hm, nope. Are (enough) root reserved clusters available? */
47448 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
47449 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
47450 - capable(CAP_SYS_RESOURCE) ||
47451 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
47452 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
47453 + capable_nolog(CAP_SYS_RESOURCE)) {
47454
47455 if (free_clusters >= (nclusters + dirty_clusters))
47456 return 1;
47457 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
47458 index 3c20de1..6ff2460 100644
47459 --- a/fs/ext4/ext4.h
47460 +++ b/fs/ext4/ext4.h
47461 @@ -1247,19 +1247,19 @@ struct ext4_sb_info {
47462 unsigned long s_mb_last_start;
47463
47464 /* stats for buddy allocator */
47465 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
47466 - atomic_t s_bal_success; /* we found long enough chunks */
47467 - atomic_t s_bal_allocated; /* in blocks */
47468 - atomic_t s_bal_ex_scanned; /* total extents scanned */
47469 - atomic_t s_bal_goals; /* goal hits */
47470 - atomic_t s_bal_breaks; /* too long searches */
47471 - atomic_t s_bal_2orders; /* 2^order hits */
47472 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
47473 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
47474 + atomic_unchecked_t s_bal_allocated; /* in blocks */
47475 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
47476 + atomic_unchecked_t s_bal_goals; /* goal hits */
47477 + atomic_unchecked_t s_bal_breaks; /* too long searches */
47478 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
47479 spinlock_t s_bal_lock;
47480 unsigned long s_mb_buddies_generated;
47481 unsigned long long s_mb_generation_time;
47482 - atomic_t s_mb_lost_chunks;
47483 - atomic_t s_mb_preallocated;
47484 - atomic_t s_mb_discarded;
47485 + atomic_unchecked_t s_mb_lost_chunks;
47486 + atomic_unchecked_t s_mb_preallocated;
47487 + atomic_unchecked_t s_mb_discarded;
47488 atomic_t s_lock_busy;
47489
47490 /* locality groups */
47491 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
47492 index 526e553..3f2de85 100644
47493 --- a/fs/ext4/mballoc.c
47494 +++ b/fs/ext4/mballoc.c
47495 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
47496 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
47497
47498 if (EXT4_SB(sb)->s_mb_stats)
47499 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
47500 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
47501
47502 break;
47503 }
47504 @@ -2044,7 +2044,7 @@ repeat:
47505 ac->ac_status = AC_STATUS_CONTINUE;
47506 ac->ac_flags |= EXT4_MB_HINT_FIRST;
47507 cr = 3;
47508 - atomic_inc(&sbi->s_mb_lost_chunks);
47509 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
47510 goto repeat;
47511 }
47512 }
47513 @@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
47514 if (sbi->s_mb_stats) {
47515 ext4_msg(sb, KERN_INFO,
47516 "mballoc: %u blocks %u reqs (%u success)",
47517 - atomic_read(&sbi->s_bal_allocated),
47518 - atomic_read(&sbi->s_bal_reqs),
47519 - atomic_read(&sbi->s_bal_success));
47520 + atomic_read_unchecked(&sbi->s_bal_allocated),
47521 + atomic_read_unchecked(&sbi->s_bal_reqs),
47522 + atomic_read_unchecked(&sbi->s_bal_success));
47523 ext4_msg(sb, KERN_INFO,
47524 "mballoc: %u extents scanned, %u goal hits, "
47525 "%u 2^N hits, %u breaks, %u lost",
47526 - atomic_read(&sbi->s_bal_ex_scanned),
47527 - atomic_read(&sbi->s_bal_goals),
47528 - atomic_read(&sbi->s_bal_2orders),
47529 - atomic_read(&sbi->s_bal_breaks),
47530 - atomic_read(&sbi->s_mb_lost_chunks));
47531 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
47532 + atomic_read_unchecked(&sbi->s_bal_goals),
47533 + atomic_read_unchecked(&sbi->s_bal_2orders),
47534 + atomic_read_unchecked(&sbi->s_bal_breaks),
47535 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
47536 ext4_msg(sb, KERN_INFO,
47537 "mballoc: %lu generated and it took %Lu",
47538 sbi->s_mb_buddies_generated,
47539 sbi->s_mb_generation_time);
47540 ext4_msg(sb, KERN_INFO,
47541 "mballoc: %u preallocated, %u discarded",
47542 - atomic_read(&sbi->s_mb_preallocated),
47543 - atomic_read(&sbi->s_mb_discarded));
47544 + atomic_read_unchecked(&sbi->s_mb_preallocated),
47545 + atomic_read_unchecked(&sbi->s_mb_discarded));
47546 }
47547
47548 free_percpu(sbi->s_locality_groups);
47549 @@ -3052,16 +3052,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
47550 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
47551
47552 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
47553 - atomic_inc(&sbi->s_bal_reqs);
47554 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47555 + atomic_inc_unchecked(&sbi->s_bal_reqs);
47556 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47557 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
47558 - atomic_inc(&sbi->s_bal_success);
47559 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
47560 + atomic_inc_unchecked(&sbi->s_bal_success);
47561 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
47562 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
47563 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
47564 - atomic_inc(&sbi->s_bal_goals);
47565 + atomic_inc_unchecked(&sbi->s_bal_goals);
47566 if (ac->ac_found > sbi->s_mb_max_to_scan)
47567 - atomic_inc(&sbi->s_bal_breaks);
47568 + atomic_inc_unchecked(&sbi->s_bal_breaks);
47569 }
47570
47571 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
47572 @@ -3461,7 +3461,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
47573 trace_ext4_mb_new_inode_pa(ac, pa);
47574
47575 ext4_mb_use_inode_pa(ac, pa);
47576 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
47577 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
47578
47579 ei = EXT4_I(ac->ac_inode);
47580 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47581 @@ -3521,7 +3521,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
47582 trace_ext4_mb_new_group_pa(ac, pa);
47583
47584 ext4_mb_use_group_pa(ac, pa);
47585 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47586 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47587
47588 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47589 lg = ac->ac_lg;
47590 @@ -3610,7 +3610,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
47591 * from the bitmap and continue.
47592 */
47593 }
47594 - atomic_add(free, &sbi->s_mb_discarded);
47595 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
47596
47597 return err;
47598 }
47599 @@ -3628,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
47600 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
47601 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
47602 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
47603 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47604 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47605 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
47606
47607 return 0;
47608 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
47609 index d59b351..775f8c8 100644
47610 --- a/fs/ext4/super.c
47611 +++ b/fs/ext4/super.c
47612 @@ -3212,7 +3212,6 @@ int ext4_calculate_overhead(struct super_block *sb)
47613 ext4_fsblk_t overhead = 0;
47614 char *buf = (char *) get_zeroed_page(GFP_KERNEL);
47615
47616 - memset(buf, 0, PAGE_SIZE);
47617 if (!buf)
47618 return -ENOMEM;
47619
47620 diff --git a/fs/fcntl.c b/fs/fcntl.c
47621 index 71a600a..20d87b1 100644
47622 --- a/fs/fcntl.c
47623 +++ b/fs/fcntl.c
47624 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
47625 if (err)
47626 return err;
47627
47628 + if (gr_handle_chroot_fowner(pid, type))
47629 + return -ENOENT;
47630 + if (gr_check_protected_task_fowner(pid, type))
47631 + return -EACCES;
47632 +
47633 f_modown(filp, pid, type, force);
47634 return 0;
47635 }
47636 diff --git a/fs/fhandle.c b/fs/fhandle.c
47637 index f775bfd..629bd4c 100644
47638 --- a/fs/fhandle.c
47639 +++ b/fs/fhandle.c
47640 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
47641 } else
47642 retval = 0;
47643 /* copy the mount id */
47644 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
47645 - sizeof(*mnt_id)) ||
47646 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
47647 copy_to_user(ufh, handle,
47648 sizeof(struct file_handle) + handle_bytes))
47649 retval = -EFAULT;
47650 diff --git a/fs/fifo.c b/fs/fifo.c
47651 index cf6f434..3d7942c 100644
47652 --- a/fs/fifo.c
47653 +++ b/fs/fifo.c
47654 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
47655 */
47656 filp->f_op = &read_pipefifo_fops;
47657 pipe->r_counter++;
47658 - if (pipe->readers++ == 0)
47659 + if (atomic_inc_return(&pipe->readers) == 1)
47660 wake_up_partner(inode);
47661
47662 - if (!pipe->writers) {
47663 + if (!atomic_read(&pipe->writers)) {
47664 if ((filp->f_flags & O_NONBLOCK)) {
47665 /* suppress POLLHUP until we have
47666 * seen a writer */
47667 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
47668 * errno=ENXIO when there is no process reading the FIFO.
47669 */
47670 ret = -ENXIO;
47671 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
47672 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
47673 goto err;
47674
47675 filp->f_op = &write_pipefifo_fops;
47676 pipe->w_counter++;
47677 - if (!pipe->writers++)
47678 + if (atomic_inc_return(&pipe->writers) == 1)
47679 wake_up_partner(inode);
47680
47681 - if (!pipe->readers) {
47682 + if (!atomic_read(&pipe->readers)) {
47683 if (wait_for_partner(inode, &pipe->r_counter))
47684 goto err_wr;
47685 }
47686 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
47687 */
47688 filp->f_op = &rdwr_pipefifo_fops;
47689
47690 - pipe->readers++;
47691 - pipe->writers++;
47692 + atomic_inc(&pipe->readers);
47693 + atomic_inc(&pipe->writers);
47694 pipe->r_counter++;
47695 pipe->w_counter++;
47696 - if (pipe->readers == 1 || pipe->writers == 1)
47697 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
47698 wake_up_partner(inode);
47699 break;
47700
47701 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
47702 return 0;
47703
47704 err_rd:
47705 - if (!--pipe->readers)
47706 + if (atomic_dec_and_test(&pipe->readers))
47707 wake_up_interruptible(&pipe->wait);
47708 ret = -ERESTARTSYS;
47709 goto err;
47710
47711 err_wr:
47712 - if (!--pipe->writers)
47713 + if (atomic_dec_and_test(&pipe->writers))
47714 wake_up_interruptible(&pipe->wait);
47715 ret = -ERESTARTSYS;
47716 goto err;
47717
47718 err:
47719 - if (!pipe->readers && !pipe->writers)
47720 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
47721 free_pipe_info(inode);
47722
47723 err_nocleanup:
47724 diff --git a/fs/file.c b/fs/file.c
47725 index eff2316..8c8930c 100644
47726 --- a/fs/file.c
47727 +++ b/fs/file.c
47728 @@ -16,6 +16,7 @@
47729 #include <linux/slab.h>
47730 #include <linux/vmalloc.h>
47731 #include <linux/file.h>
47732 +#include <linux/security.h>
47733 #include <linux/fdtable.h>
47734 #include <linux/bitops.h>
47735 #include <linux/interrupt.h>
47736 @@ -898,6 +899,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
47737 if (!file)
47738 return __close_fd(files, fd);
47739
47740 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
47741 if (fd >= rlimit(RLIMIT_NOFILE))
47742 return -EBADF;
47743
47744 @@ -924,6 +926,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
47745 if (unlikely(oldfd == newfd))
47746 return -EINVAL;
47747
47748 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
47749 if (newfd >= rlimit(RLIMIT_NOFILE))
47750 return -EBADF;
47751
47752 @@ -979,6 +982,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
47753 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
47754 {
47755 int err;
47756 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
47757 if (from >= rlimit(RLIMIT_NOFILE))
47758 return -EINVAL;
47759 err = alloc_fd(from, flags);
47760 diff --git a/fs/filesystems.c b/fs/filesystems.c
47761 index da165f6..3671bdb 100644
47762 --- a/fs/filesystems.c
47763 +++ b/fs/filesystems.c
47764 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
47765 int len = dot ? dot - name : strlen(name);
47766
47767 fs = __get_fs_type(name, len);
47768 +
47769 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
47770 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
47771 +#else
47772 if (!fs && (request_module("%.*s", len, name) == 0))
47773 +#endif
47774 fs = __get_fs_type(name, len);
47775
47776 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
47777 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
47778 index 5df4775..9d9336f 100644
47779 --- a/fs/fs_struct.c
47780 +++ b/fs/fs_struct.c
47781 @@ -4,6 +4,7 @@
47782 #include <linux/path.h>
47783 #include <linux/slab.h>
47784 #include <linux/fs_struct.h>
47785 +#include <linux/grsecurity.h>
47786 #include "internal.h"
47787
47788 /*
47789 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
47790 write_seqcount_begin(&fs->seq);
47791 old_root = fs->root;
47792 fs->root = *path;
47793 + gr_set_chroot_entries(current, path);
47794 write_seqcount_end(&fs->seq);
47795 spin_unlock(&fs->lock);
47796 if (old_root.dentry)
47797 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
47798 return 1;
47799 }
47800
47801 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
47802 +{
47803 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
47804 + return 0;
47805 + *p = *new;
47806 +
47807 + /* This function is only called from pivot_root(). Leave our
47808 + gr_chroot_dentry and is_chrooted flags as-is, so that a
47809 + pivoted root isn't treated as a chroot
47810 + */
47811 + //gr_set_chroot_entries(task, new);
47812 +
47813 + return 1;
47814 +}
47815 +
47816 void chroot_fs_refs(struct path *old_root, struct path *new_root)
47817 {
47818 struct task_struct *g, *p;
47819 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
47820 int hits = 0;
47821 spin_lock(&fs->lock);
47822 write_seqcount_begin(&fs->seq);
47823 - hits += replace_path(&fs->root, old_root, new_root);
47824 + hits += replace_root_path(p, &fs->root, old_root, new_root);
47825 hits += replace_path(&fs->pwd, old_root, new_root);
47826 write_seqcount_end(&fs->seq);
47827 while (hits--) {
47828 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
47829 task_lock(tsk);
47830 spin_lock(&fs->lock);
47831 tsk->fs = NULL;
47832 - kill = !--fs->users;
47833 + gr_clear_chroot_entries(tsk);
47834 + kill = !atomic_dec_return(&fs->users);
47835 spin_unlock(&fs->lock);
47836 task_unlock(tsk);
47837 if (kill)
47838 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47839 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
47840 /* We don't need to lock fs - think why ;-) */
47841 if (fs) {
47842 - fs->users = 1;
47843 + atomic_set(&fs->users, 1);
47844 fs->in_exec = 0;
47845 spin_lock_init(&fs->lock);
47846 seqcount_init(&fs->seq);
47847 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47848 spin_lock(&old->lock);
47849 fs->root = old->root;
47850 path_get(&fs->root);
47851 + /* instead of calling gr_set_chroot_entries here,
47852 + we call it from every caller of this function
47853 + */
47854 fs->pwd = old->pwd;
47855 path_get(&fs->pwd);
47856 spin_unlock(&old->lock);
47857 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
47858
47859 task_lock(current);
47860 spin_lock(&fs->lock);
47861 - kill = !--fs->users;
47862 + kill = !atomic_dec_return(&fs->users);
47863 current->fs = new_fs;
47864 + gr_set_chroot_entries(current, &new_fs->root);
47865 spin_unlock(&fs->lock);
47866 task_unlock(current);
47867
47868 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
47869
47870 int current_umask(void)
47871 {
47872 - return current->fs->umask;
47873 + return current->fs->umask | gr_acl_umask();
47874 }
47875 EXPORT_SYMBOL(current_umask);
47876
47877 /* to be mentioned only in INIT_TASK */
47878 struct fs_struct init_fs = {
47879 - .users = 1,
47880 + .users = ATOMIC_INIT(1),
47881 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
47882 .seq = SEQCNT_ZERO,
47883 .umask = 0022,
47884 @@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
47885 task_lock(current);
47886
47887 spin_lock(&init_fs.lock);
47888 - init_fs.users++;
47889 + atomic_inc(&init_fs.users);
47890 spin_unlock(&init_fs.lock);
47891
47892 spin_lock(&fs->lock);
47893 current->fs = &init_fs;
47894 - kill = !--fs->users;
47895 + gr_set_chroot_entries(current, &current->fs->root);
47896 + kill = !atomic_dec_return(&fs->users);
47897 spin_unlock(&fs->lock);
47898
47899 task_unlock(current);
47900 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
47901 index 9905350..02eaec4 100644
47902 --- a/fs/fscache/cookie.c
47903 +++ b/fs/fscache/cookie.c
47904 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
47905 parent ? (char *) parent->def->name : "<no-parent>",
47906 def->name, netfs_data);
47907
47908 - fscache_stat(&fscache_n_acquires);
47909 + fscache_stat_unchecked(&fscache_n_acquires);
47910
47911 /* if there's no parent cookie, then we don't create one here either */
47912 if (!parent) {
47913 - fscache_stat(&fscache_n_acquires_null);
47914 + fscache_stat_unchecked(&fscache_n_acquires_null);
47915 _leave(" [no parent]");
47916 return NULL;
47917 }
47918 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
47919 /* allocate and initialise a cookie */
47920 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
47921 if (!cookie) {
47922 - fscache_stat(&fscache_n_acquires_oom);
47923 + fscache_stat_unchecked(&fscache_n_acquires_oom);
47924 _leave(" [ENOMEM]");
47925 return NULL;
47926 }
47927 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47928
47929 switch (cookie->def->type) {
47930 case FSCACHE_COOKIE_TYPE_INDEX:
47931 - fscache_stat(&fscache_n_cookie_index);
47932 + fscache_stat_unchecked(&fscache_n_cookie_index);
47933 break;
47934 case FSCACHE_COOKIE_TYPE_DATAFILE:
47935 - fscache_stat(&fscache_n_cookie_data);
47936 + fscache_stat_unchecked(&fscache_n_cookie_data);
47937 break;
47938 default:
47939 - fscache_stat(&fscache_n_cookie_special);
47940 + fscache_stat_unchecked(&fscache_n_cookie_special);
47941 break;
47942 }
47943
47944 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47945 if (fscache_acquire_non_index_cookie(cookie) < 0) {
47946 atomic_dec(&parent->n_children);
47947 __fscache_cookie_put(cookie);
47948 - fscache_stat(&fscache_n_acquires_nobufs);
47949 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
47950 _leave(" = NULL");
47951 return NULL;
47952 }
47953 }
47954
47955 - fscache_stat(&fscache_n_acquires_ok);
47956 + fscache_stat_unchecked(&fscache_n_acquires_ok);
47957 _leave(" = %p", cookie);
47958 return cookie;
47959 }
47960 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
47961 cache = fscache_select_cache_for_object(cookie->parent);
47962 if (!cache) {
47963 up_read(&fscache_addremove_sem);
47964 - fscache_stat(&fscache_n_acquires_no_cache);
47965 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
47966 _leave(" = -ENOMEDIUM [no cache]");
47967 return -ENOMEDIUM;
47968 }
47969 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
47970 object = cache->ops->alloc_object(cache, cookie);
47971 fscache_stat_d(&fscache_n_cop_alloc_object);
47972 if (IS_ERR(object)) {
47973 - fscache_stat(&fscache_n_object_no_alloc);
47974 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
47975 ret = PTR_ERR(object);
47976 goto error;
47977 }
47978
47979 - fscache_stat(&fscache_n_object_alloc);
47980 + fscache_stat_unchecked(&fscache_n_object_alloc);
47981
47982 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
47983
47984 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
47985 struct fscache_object *object;
47986 struct hlist_node *_p;
47987
47988 - fscache_stat(&fscache_n_updates);
47989 + fscache_stat_unchecked(&fscache_n_updates);
47990
47991 if (!cookie) {
47992 - fscache_stat(&fscache_n_updates_null);
47993 + fscache_stat_unchecked(&fscache_n_updates_null);
47994 _leave(" [no cookie]");
47995 return;
47996 }
47997 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
47998 struct fscache_object *object;
47999 unsigned long event;
48000
48001 - fscache_stat(&fscache_n_relinquishes);
48002 + fscache_stat_unchecked(&fscache_n_relinquishes);
48003 if (retire)
48004 - fscache_stat(&fscache_n_relinquishes_retire);
48005 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
48006
48007 if (!cookie) {
48008 - fscache_stat(&fscache_n_relinquishes_null);
48009 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
48010 _leave(" [no cookie]");
48011 return;
48012 }
48013 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48014
48015 /* wait for the cookie to finish being instantiated (or to fail) */
48016 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
48017 - fscache_stat(&fscache_n_relinquishes_waitcrt);
48018 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
48019 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
48020 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
48021 }
48022 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
48023 index f6aad48..88dcf26 100644
48024 --- a/fs/fscache/internal.h
48025 +++ b/fs/fscache/internal.h
48026 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
48027 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
48028 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
48029
48030 -extern atomic_t fscache_n_op_pend;
48031 -extern atomic_t fscache_n_op_run;
48032 -extern atomic_t fscache_n_op_enqueue;
48033 -extern atomic_t fscache_n_op_deferred_release;
48034 -extern atomic_t fscache_n_op_release;
48035 -extern atomic_t fscache_n_op_gc;
48036 -extern atomic_t fscache_n_op_cancelled;
48037 -extern atomic_t fscache_n_op_rejected;
48038 +extern atomic_unchecked_t fscache_n_op_pend;
48039 +extern atomic_unchecked_t fscache_n_op_run;
48040 +extern atomic_unchecked_t fscache_n_op_enqueue;
48041 +extern atomic_unchecked_t fscache_n_op_deferred_release;
48042 +extern atomic_unchecked_t fscache_n_op_release;
48043 +extern atomic_unchecked_t fscache_n_op_gc;
48044 +extern atomic_unchecked_t fscache_n_op_cancelled;
48045 +extern atomic_unchecked_t fscache_n_op_rejected;
48046
48047 -extern atomic_t fscache_n_attr_changed;
48048 -extern atomic_t fscache_n_attr_changed_ok;
48049 -extern atomic_t fscache_n_attr_changed_nobufs;
48050 -extern atomic_t fscache_n_attr_changed_nomem;
48051 -extern atomic_t fscache_n_attr_changed_calls;
48052 +extern atomic_unchecked_t fscache_n_attr_changed;
48053 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
48054 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
48055 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
48056 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
48057
48058 -extern atomic_t fscache_n_allocs;
48059 -extern atomic_t fscache_n_allocs_ok;
48060 -extern atomic_t fscache_n_allocs_wait;
48061 -extern atomic_t fscache_n_allocs_nobufs;
48062 -extern atomic_t fscache_n_allocs_intr;
48063 -extern atomic_t fscache_n_allocs_object_dead;
48064 -extern atomic_t fscache_n_alloc_ops;
48065 -extern atomic_t fscache_n_alloc_op_waits;
48066 +extern atomic_unchecked_t fscache_n_allocs;
48067 +extern atomic_unchecked_t fscache_n_allocs_ok;
48068 +extern atomic_unchecked_t fscache_n_allocs_wait;
48069 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
48070 +extern atomic_unchecked_t fscache_n_allocs_intr;
48071 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
48072 +extern atomic_unchecked_t fscache_n_alloc_ops;
48073 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
48074
48075 -extern atomic_t fscache_n_retrievals;
48076 -extern atomic_t fscache_n_retrievals_ok;
48077 -extern atomic_t fscache_n_retrievals_wait;
48078 -extern atomic_t fscache_n_retrievals_nodata;
48079 -extern atomic_t fscache_n_retrievals_nobufs;
48080 -extern atomic_t fscache_n_retrievals_intr;
48081 -extern atomic_t fscache_n_retrievals_nomem;
48082 -extern atomic_t fscache_n_retrievals_object_dead;
48083 -extern atomic_t fscache_n_retrieval_ops;
48084 -extern atomic_t fscache_n_retrieval_op_waits;
48085 +extern atomic_unchecked_t fscache_n_retrievals;
48086 +extern atomic_unchecked_t fscache_n_retrievals_ok;
48087 +extern atomic_unchecked_t fscache_n_retrievals_wait;
48088 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
48089 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
48090 +extern atomic_unchecked_t fscache_n_retrievals_intr;
48091 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
48092 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
48093 +extern atomic_unchecked_t fscache_n_retrieval_ops;
48094 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
48095
48096 -extern atomic_t fscache_n_stores;
48097 -extern atomic_t fscache_n_stores_ok;
48098 -extern atomic_t fscache_n_stores_again;
48099 -extern atomic_t fscache_n_stores_nobufs;
48100 -extern atomic_t fscache_n_stores_oom;
48101 -extern atomic_t fscache_n_store_ops;
48102 -extern atomic_t fscache_n_store_calls;
48103 -extern atomic_t fscache_n_store_pages;
48104 -extern atomic_t fscache_n_store_radix_deletes;
48105 -extern atomic_t fscache_n_store_pages_over_limit;
48106 +extern atomic_unchecked_t fscache_n_stores;
48107 +extern atomic_unchecked_t fscache_n_stores_ok;
48108 +extern atomic_unchecked_t fscache_n_stores_again;
48109 +extern atomic_unchecked_t fscache_n_stores_nobufs;
48110 +extern atomic_unchecked_t fscache_n_stores_oom;
48111 +extern atomic_unchecked_t fscache_n_store_ops;
48112 +extern atomic_unchecked_t fscache_n_store_calls;
48113 +extern atomic_unchecked_t fscache_n_store_pages;
48114 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
48115 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
48116
48117 -extern atomic_t fscache_n_store_vmscan_not_storing;
48118 -extern atomic_t fscache_n_store_vmscan_gone;
48119 -extern atomic_t fscache_n_store_vmscan_busy;
48120 -extern atomic_t fscache_n_store_vmscan_cancelled;
48121 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48122 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
48123 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
48124 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48125
48126 -extern atomic_t fscache_n_marks;
48127 -extern atomic_t fscache_n_uncaches;
48128 +extern atomic_unchecked_t fscache_n_marks;
48129 +extern atomic_unchecked_t fscache_n_uncaches;
48130
48131 -extern atomic_t fscache_n_acquires;
48132 -extern atomic_t fscache_n_acquires_null;
48133 -extern atomic_t fscache_n_acquires_no_cache;
48134 -extern atomic_t fscache_n_acquires_ok;
48135 -extern atomic_t fscache_n_acquires_nobufs;
48136 -extern atomic_t fscache_n_acquires_oom;
48137 +extern atomic_unchecked_t fscache_n_acquires;
48138 +extern atomic_unchecked_t fscache_n_acquires_null;
48139 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
48140 +extern atomic_unchecked_t fscache_n_acquires_ok;
48141 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
48142 +extern atomic_unchecked_t fscache_n_acquires_oom;
48143
48144 -extern atomic_t fscache_n_updates;
48145 -extern atomic_t fscache_n_updates_null;
48146 -extern atomic_t fscache_n_updates_run;
48147 +extern atomic_unchecked_t fscache_n_updates;
48148 +extern atomic_unchecked_t fscache_n_updates_null;
48149 +extern atomic_unchecked_t fscache_n_updates_run;
48150
48151 -extern atomic_t fscache_n_relinquishes;
48152 -extern atomic_t fscache_n_relinquishes_null;
48153 -extern atomic_t fscache_n_relinquishes_waitcrt;
48154 -extern atomic_t fscache_n_relinquishes_retire;
48155 +extern atomic_unchecked_t fscache_n_relinquishes;
48156 +extern atomic_unchecked_t fscache_n_relinquishes_null;
48157 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48158 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
48159
48160 -extern atomic_t fscache_n_cookie_index;
48161 -extern atomic_t fscache_n_cookie_data;
48162 -extern atomic_t fscache_n_cookie_special;
48163 +extern atomic_unchecked_t fscache_n_cookie_index;
48164 +extern atomic_unchecked_t fscache_n_cookie_data;
48165 +extern atomic_unchecked_t fscache_n_cookie_special;
48166
48167 -extern atomic_t fscache_n_object_alloc;
48168 -extern atomic_t fscache_n_object_no_alloc;
48169 -extern atomic_t fscache_n_object_lookups;
48170 -extern atomic_t fscache_n_object_lookups_negative;
48171 -extern atomic_t fscache_n_object_lookups_positive;
48172 -extern atomic_t fscache_n_object_lookups_timed_out;
48173 -extern atomic_t fscache_n_object_created;
48174 -extern atomic_t fscache_n_object_avail;
48175 -extern atomic_t fscache_n_object_dead;
48176 +extern atomic_unchecked_t fscache_n_object_alloc;
48177 +extern atomic_unchecked_t fscache_n_object_no_alloc;
48178 +extern atomic_unchecked_t fscache_n_object_lookups;
48179 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
48180 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
48181 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
48182 +extern atomic_unchecked_t fscache_n_object_created;
48183 +extern atomic_unchecked_t fscache_n_object_avail;
48184 +extern atomic_unchecked_t fscache_n_object_dead;
48185
48186 -extern atomic_t fscache_n_checkaux_none;
48187 -extern atomic_t fscache_n_checkaux_okay;
48188 -extern atomic_t fscache_n_checkaux_update;
48189 -extern atomic_t fscache_n_checkaux_obsolete;
48190 +extern atomic_unchecked_t fscache_n_checkaux_none;
48191 +extern atomic_unchecked_t fscache_n_checkaux_okay;
48192 +extern atomic_unchecked_t fscache_n_checkaux_update;
48193 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
48194
48195 extern atomic_t fscache_n_cop_alloc_object;
48196 extern atomic_t fscache_n_cop_lookup_object;
48197 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
48198 atomic_inc(stat);
48199 }
48200
48201 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
48202 +{
48203 + atomic_inc_unchecked(stat);
48204 +}
48205 +
48206 static inline void fscache_stat_d(atomic_t *stat)
48207 {
48208 atomic_dec(stat);
48209 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
48210
48211 #define __fscache_stat(stat) (NULL)
48212 #define fscache_stat(stat) do {} while (0)
48213 +#define fscache_stat_unchecked(stat) do {} while (0)
48214 #define fscache_stat_d(stat) do {} while (0)
48215 #endif
48216
48217 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
48218 index b6b897c..0ffff9c 100644
48219 --- a/fs/fscache/object.c
48220 +++ b/fs/fscache/object.c
48221 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48222 /* update the object metadata on disk */
48223 case FSCACHE_OBJECT_UPDATING:
48224 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
48225 - fscache_stat(&fscache_n_updates_run);
48226 + fscache_stat_unchecked(&fscache_n_updates_run);
48227 fscache_stat(&fscache_n_cop_update_object);
48228 object->cache->ops->update_object(object);
48229 fscache_stat_d(&fscache_n_cop_update_object);
48230 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48231 spin_lock(&object->lock);
48232 object->state = FSCACHE_OBJECT_DEAD;
48233 spin_unlock(&object->lock);
48234 - fscache_stat(&fscache_n_object_dead);
48235 + fscache_stat_unchecked(&fscache_n_object_dead);
48236 goto terminal_transit;
48237
48238 /* handle the parent cache of this object being withdrawn from
48239 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48240 spin_lock(&object->lock);
48241 object->state = FSCACHE_OBJECT_DEAD;
48242 spin_unlock(&object->lock);
48243 - fscache_stat(&fscache_n_object_dead);
48244 + fscache_stat_unchecked(&fscache_n_object_dead);
48245 goto terminal_transit;
48246
48247 /* complain about the object being woken up once it is
48248 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48249 parent->cookie->def->name, cookie->def->name,
48250 object->cache->tag->name);
48251
48252 - fscache_stat(&fscache_n_object_lookups);
48253 + fscache_stat_unchecked(&fscache_n_object_lookups);
48254 fscache_stat(&fscache_n_cop_lookup_object);
48255 ret = object->cache->ops->lookup_object(object);
48256 fscache_stat_d(&fscache_n_cop_lookup_object);
48257 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48258 if (ret == -ETIMEDOUT) {
48259 /* probably stuck behind another object, so move this one to
48260 * the back of the queue */
48261 - fscache_stat(&fscache_n_object_lookups_timed_out);
48262 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
48263 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
48264 }
48265
48266 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
48267
48268 spin_lock(&object->lock);
48269 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
48270 - fscache_stat(&fscache_n_object_lookups_negative);
48271 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
48272
48273 /* transit here to allow write requests to begin stacking up
48274 * and read requests to begin returning ENODATA */
48275 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
48276 * result, in which case there may be data available */
48277 spin_lock(&object->lock);
48278 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
48279 - fscache_stat(&fscache_n_object_lookups_positive);
48280 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
48281
48282 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
48283
48284 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
48285 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
48286 } else {
48287 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
48288 - fscache_stat(&fscache_n_object_created);
48289 + fscache_stat_unchecked(&fscache_n_object_created);
48290
48291 object->state = FSCACHE_OBJECT_AVAILABLE;
48292 spin_unlock(&object->lock);
48293 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
48294 fscache_enqueue_dependents(object);
48295
48296 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
48297 - fscache_stat(&fscache_n_object_avail);
48298 + fscache_stat_unchecked(&fscache_n_object_avail);
48299
48300 _leave("");
48301 }
48302 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
48303 enum fscache_checkaux result;
48304
48305 if (!object->cookie->def->check_aux) {
48306 - fscache_stat(&fscache_n_checkaux_none);
48307 + fscache_stat_unchecked(&fscache_n_checkaux_none);
48308 return FSCACHE_CHECKAUX_OKAY;
48309 }
48310
48311 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
48312 switch (result) {
48313 /* entry okay as is */
48314 case FSCACHE_CHECKAUX_OKAY:
48315 - fscache_stat(&fscache_n_checkaux_okay);
48316 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
48317 break;
48318
48319 /* entry requires update */
48320 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
48321 - fscache_stat(&fscache_n_checkaux_update);
48322 + fscache_stat_unchecked(&fscache_n_checkaux_update);
48323 break;
48324
48325 /* entry requires deletion */
48326 case FSCACHE_CHECKAUX_OBSOLETE:
48327 - fscache_stat(&fscache_n_checkaux_obsolete);
48328 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
48329 break;
48330
48331 default:
48332 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
48333 index 30afdfa..2256596 100644
48334 --- a/fs/fscache/operation.c
48335 +++ b/fs/fscache/operation.c
48336 @@ -17,7 +17,7 @@
48337 #include <linux/slab.h>
48338 #include "internal.h"
48339
48340 -atomic_t fscache_op_debug_id;
48341 +atomic_unchecked_t fscache_op_debug_id;
48342 EXPORT_SYMBOL(fscache_op_debug_id);
48343
48344 /**
48345 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
48346 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
48347 ASSERTCMP(atomic_read(&op->usage), >, 0);
48348
48349 - fscache_stat(&fscache_n_op_enqueue);
48350 + fscache_stat_unchecked(&fscache_n_op_enqueue);
48351 switch (op->flags & FSCACHE_OP_TYPE) {
48352 case FSCACHE_OP_ASYNC:
48353 _debug("queue async");
48354 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
48355 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
48356 if (op->processor)
48357 fscache_enqueue_operation(op);
48358 - fscache_stat(&fscache_n_op_run);
48359 + fscache_stat_unchecked(&fscache_n_op_run);
48360 }
48361
48362 /*
48363 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48364 if (object->n_ops > 1) {
48365 atomic_inc(&op->usage);
48366 list_add_tail(&op->pend_link, &object->pending_ops);
48367 - fscache_stat(&fscache_n_op_pend);
48368 + fscache_stat_unchecked(&fscache_n_op_pend);
48369 } else if (!list_empty(&object->pending_ops)) {
48370 atomic_inc(&op->usage);
48371 list_add_tail(&op->pend_link, &object->pending_ops);
48372 - fscache_stat(&fscache_n_op_pend);
48373 + fscache_stat_unchecked(&fscache_n_op_pend);
48374 fscache_start_operations(object);
48375 } else {
48376 ASSERTCMP(object->n_in_progress, ==, 0);
48377 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48378 object->n_exclusive++; /* reads and writes must wait */
48379 atomic_inc(&op->usage);
48380 list_add_tail(&op->pend_link, &object->pending_ops);
48381 - fscache_stat(&fscache_n_op_pend);
48382 + fscache_stat_unchecked(&fscache_n_op_pend);
48383 ret = 0;
48384 } else {
48385 /* not allowed to submit ops in any other state */
48386 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
48387 if (object->n_exclusive > 0) {
48388 atomic_inc(&op->usage);
48389 list_add_tail(&op->pend_link, &object->pending_ops);
48390 - fscache_stat(&fscache_n_op_pend);
48391 + fscache_stat_unchecked(&fscache_n_op_pend);
48392 } else if (!list_empty(&object->pending_ops)) {
48393 atomic_inc(&op->usage);
48394 list_add_tail(&op->pend_link, &object->pending_ops);
48395 - fscache_stat(&fscache_n_op_pend);
48396 + fscache_stat_unchecked(&fscache_n_op_pend);
48397 fscache_start_operations(object);
48398 } else {
48399 ASSERTCMP(object->n_exclusive, ==, 0);
48400 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
48401 object->n_ops++;
48402 atomic_inc(&op->usage);
48403 list_add_tail(&op->pend_link, &object->pending_ops);
48404 - fscache_stat(&fscache_n_op_pend);
48405 + fscache_stat_unchecked(&fscache_n_op_pend);
48406 ret = 0;
48407 } else if (object->state == FSCACHE_OBJECT_DYING ||
48408 object->state == FSCACHE_OBJECT_LC_DYING ||
48409 object->state == FSCACHE_OBJECT_WITHDRAWING) {
48410 - fscache_stat(&fscache_n_op_rejected);
48411 + fscache_stat_unchecked(&fscache_n_op_rejected);
48412 ret = -ENOBUFS;
48413 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
48414 fscache_report_unexpected_submission(object, op, ostate);
48415 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
48416
48417 ret = -EBUSY;
48418 if (!list_empty(&op->pend_link)) {
48419 - fscache_stat(&fscache_n_op_cancelled);
48420 + fscache_stat_unchecked(&fscache_n_op_cancelled);
48421 list_del_init(&op->pend_link);
48422 object->n_ops--;
48423 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
48424 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
48425 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
48426 BUG();
48427
48428 - fscache_stat(&fscache_n_op_release);
48429 + fscache_stat_unchecked(&fscache_n_op_release);
48430
48431 if (op->release) {
48432 op->release(op);
48433 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
48434 * lock, and defer it otherwise */
48435 if (!spin_trylock(&object->lock)) {
48436 _debug("defer put");
48437 - fscache_stat(&fscache_n_op_deferred_release);
48438 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
48439
48440 cache = object->cache;
48441 spin_lock(&cache->op_gc_list_lock);
48442 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
48443
48444 _debug("GC DEFERRED REL OBJ%x OP%x",
48445 object->debug_id, op->debug_id);
48446 - fscache_stat(&fscache_n_op_gc);
48447 + fscache_stat_unchecked(&fscache_n_op_gc);
48448
48449 ASSERTCMP(atomic_read(&op->usage), ==, 0);
48450
48451 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
48452 index 3f7a59b..cf196cc 100644
48453 --- a/fs/fscache/page.c
48454 +++ b/fs/fscache/page.c
48455 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48456 val = radix_tree_lookup(&cookie->stores, page->index);
48457 if (!val) {
48458 rcu_read_unlock();
48459 - fscache_stat(&fscache_n_store_vmscan_not_storing);
48460 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
48461 __fscache_uncache_page(cookie, page);
48462 return true;
48463 }
48464 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48465 spin_unlock(&cookie->stores_lock);
48466
48467 if (xpage) {
48468 - fscache_stat(&fscache_n_store_vmscan_cancelled);
48469 - fscache_stat(&fscache_n_store_radix_deletes);
48470 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
48471 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48472 ASSERTCMP(xpage, ==, page);
48473 } else {
48474 - fscache_stat(&fscache_n_store_vmscan_gone);
48475 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
48476 }
48477
48478 wake_up_bit(&cookie->flags, 0);
48479 @@ -107,7 +107,7 @@ page_busy:
48480 /* we might want to wait here, but that could deadlock the allocator as
48481 * the work threads writing to the cache may all end up sleeping
48482 * on memory allocation */
48483 - fscache_stat(&fscache_n_store_vmscan_busy);
48484 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
48485 return false;
48486 }
48487 EXPORT_SYMBOL(__fscache_maybe_release_page);
48488 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
48489 FSCACHE_COOKIE_STORING_TAG);
48490 if (!radix_tree_tag_get(&cookie->stores, page->index,
48491 FSCACHE_COOKIE_PENDING_TAG)) {
48492 - fscache_stat(&fscache_n_store_radix_deletes);
48493 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48494 xpage = radix_tree_delete(&cookie->stores, page->index);
48495 }
48496 spin_unlock(&cookie->stores_lock);
48497 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
48498
48499 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
48500
48501 - fscache_stat(&fscache_n_attr_changed_calls);
48502 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
48503
48504 if (fscache_object_is_active(object)) {
48505 fscache_stat(&fscache_n_cop_attr_changed);
48506 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48507
48508 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48509
48510 - fscache_stat(&fscache_n_attr_changed);
48511 + fscache_stat_unchecked(&fscache_n_attr_changed);
48512
48513 op = kzalloc(sizeof(*op), GFP_KERNEL);
48514 if (!op) {
48515 - fscache_stat(&fscache_n_attr_changed_nomem);
48516 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
48517 _leave(" = -ENOMEM");
48518 return -ENOMEM;
48519 }
48520 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48521 if (fscache_submit_exclusive_op(object, op) < 0)
48522 goto nobufs;
48523 spin_unlock(&cookie->lock);
48524 - fscache_stat(&fscache_n_attr_changed_ok);
48525 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
48526 fscache_put_operation(op);
48527 _leave(" = 0");
48528 return 0;
48529 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48530 nobufs:
48531 spin_unlock(&cookie->lock);
48532 kfree(op);
48533 - fscache_stat(&fscache_n_attr_changed_nobufs);
48534 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
48535 _leave(" = %d", -ENOBUFS);
48536 return -ENOBUFS;
48537 }
48538 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
48539 /* allocate a retrieval operation and attempt to submit it */
48540 op = kzalloc(sizeof(*op), GFP_NOIO);
48541 if (!op) {
48542 - fscache_stat(&fscache_n_retrievals_nomem);
48543 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48544 return NULL;
48545 }
48546
48547 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48548 return 0;
48549 }
48550
48551 - fscache_stat(&fscache_n_retrievals_wait);
48552 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
48553
48554 jif = jiffies;
48555 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
48556 fscache_wait_bit_interruptible,
48557 TASK_INTERRUPTIBLE) != 0) {
48558 - fscache_stat(&fscache_n_retrievals_intr);
48559 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48560 _leave(" = -ERESTARTSYS");
48561 return -ERESTARTSYS;
48562 }
48563 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48564 */
48565 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48566 struct fscache_retrieval *op,
48567 - atomic_t *stat_op_waits,
48568 - atomic_t *stat_object_dead)
48569 + atomic_unchecked_t *stat_op_waits,
48570 + atomic_unchecked_t *stat_object_dead)
48571 {
48572 int ret;
48573
48574 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48575 goto check_if_dead;
48576
48577 _debug(">>> WT");
48578 - fscache_stat(stat_op_waits);
48579 + fscache_stat_unchecked(stat_op_waits);
48580 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
48581 fscache_wait_bit_interruptible,
48582 TASK_INTERRUPTIBLE) < 0) {
48583 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48584
48585 check_if_dead:
48586 if (unlikely(fscache_object_is_dead(object))) {
48587 - fscache_stat(stat_object_dead);
48588 + fscache_stat_unchecked(stat_object_dead);
48589 return -ENOBUFS;
48590 }
48591 return 0;
48592 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48593
48594 _enter("%p,%p,,,", cookie, page);
48595
48596 - fscache_stat(&fscache_n_retrievals);
48597 + fscache_stat_unchecked(&fscache_n_retrievals);
48598
48599 if (hlist_empty(&cookie->backing_objects))
48600 goto nobufs;
48601 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48602 goto nobufs_unlock;
48603 spin_unlock(&cookie->lock);
48604
48605 - fscache_stat(&fscache_n_retrieval_ops);
48606 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
48607
48608 /* pin the netfs read context in case we need to do the actual netfs
48609 * read because we've encountered a cache read failure */
48610 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48611
48612 error:
48613 if (ret == -ENOMEM)
48614 - fscache_stat(&fscache_n_retrievals_nomem);
48615 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48616 else if (ret == -ERESTARTSYS)
48617 - fscache_stat(&fscache_n_retrievals_intr);
48618 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48619 else if (ret == -ENODATA)
48620 - fscache_stat(&fscache_n_retrievals_nodata);
48621 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48622 else if (ret < 0)
48623 - fscache_stat(&fscache_n_retrievals_nobufs);
48624 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48625 else
48626 - fscache_stat(&fscache_n_retrievals_ok);
48627 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
48628
48629 fscache_put_retrieval(op);
48630 _leave(" = %d", ret);
48631 @@ -429,7 +429,7 @@ nobufs_unlock:
48632 spin_unlock(&cookie->lock);
48633 kfree(op);
48634 nobufs:
48635 - fscache_stat(&fscache_n_retrievals_nobufs);
48636 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48637 _leave(" = -ENOBUFS");
48638 return -ENOBUFS;
48639 }
48640 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48641
48642 _enter("%p,,%d,,,", cookie, *nr_pages);
48643
48644 - fscache_stat(&fscache_n_retrievals);
48645 + fscache_stat_unchecked(&fscache_n_retrievals);
48646
48647 if (hlist_empty(&cookie->backing_objects))
48648 goto nobufs;
48649 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48650 goto nobufs_unlock;
48651 spin_unlock(&cookie->lock);
48652
48653 - fscache_stat(&fscache_n_retrieval_ops);
48654 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
48655
48656 /* pin the netfs read context in case we need to do the actual netfs
48657 * read because we've encountered a cache read failure */
48658 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48659
48660 error:
48661 if (ret == -ENOMEM)
48662 - fscache_stat(&fscache_n_retrievals_nomem);
48663 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48664 else if (ret == -ERESTARTSYS)
48665 - fscache_stat(&fscache_n_retrievals_intr);
48666 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48667 else if (ret == -ENODATA)
48668 - fscache_stat(&fscache_n_retrievals_nodata);
48669 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48670 else if (ret < 0)
48671 - fscache_stat(&fscache_n_retrievals_nobufs);
48672 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48673 else
48674 - fscache_stat(&fscache_n_retrievals_ok);
48675 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
48676
48677 fscache_put_retrieval(op);
48678 _leave(" = %d", ret);
48679 @@ -545,7 +545,7 @@ nobufs_unlock:
48680 spin_unlock(&cookie->lock);
48681 kfree(op);
48682 nobufs:
48683 - fscache_stat(&fscache_n_retrievals_nobufs);
48684 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48685 _leave(" = -ENOBUFS");
48686 return -ENOBUFS;
48687 }
48688 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48689
48690 _enter("%p,%p,,,", cookie, page);
48691
48692 - fscache_stat(&fscache_n_allocs);
48693 + fscache_stat_unchecked(&fscache_n_allocs);
48694
48695 if (hlist_empty(&cookie->backing_objects))
48696 goto nobufs;
48697 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48698 goto nobufs_unlock;
48699 spin_unlock(&cookie->lock);
48700
48701 - fscache_stat(&fscache_n_alloc_ops);
48702 + fscache_stat_unchecked(&fscache_n_alloc_ops);
48703
48704 ret = fscache_wait_for_retrieval_activation(
48705 object, op,
48706 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48707
48708 error:
48709 if (ret == -ERESTARTSYS)
48710 - fscache_stat(&fscache_n_allocs_intr);
48711 + fscache_stat_unchecked(&fscache_n_allocs_intr);
48712 else if (ret < 0)
48713 - fscache_stat(&fscache_n_allocs_nobufs);
48714 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48715 else
48716 - fscache_stat(&fscache_n_allocs_ok);
48717 + fscache_stat_unchecked(&fscache_n_allocs_ok);
48718
48719 fscache_put_retrieval(op);
48720 _leave(" = %d", ret);
48721 @@ -625,7 +625,7 @@ nobufs_unlock:
48722 spin_unlock(&cookie->lock);
48723 kfree(op);
48724 nobufs:
48725 - fscache_stat(&fscache_n_allocs_nobufs);
48726 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48727 _leave(" = -ENOBUFS");
48728 return -ENOBUFS;
48729 }
48730 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48731
48732 spin_lock(&cookie->stores_lock);
48733
48734 - fscache_stat(&fscache_n_store_calls);
48735 + fscache_stat_unchecked(&fscache_n_store_calls);
48736
48737 /* find a page to store */
48738 page = NULL;
48739 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48740 page = results[0];
48741 _debug("gang %d [%lx]", n, page->index);
48742 if (page->index > op->store_limit) {
48743 - fscache_stat(&fscache_n_store_pages_over_limit);
48744 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
48745 goto superseded;
48746 }
48747
48748 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48749 spin_unlock(&cookie->stores_lock);
48750 spin_unlock(&object->lock);
48751
48752 - fscache_stat(&fscache_n_store_pages);
48753 + fscache_stat_unchecked(&fscache_n_store_pages);
48754 fscache_stat(&fscache_n_cop_write_page);
48755 ret = object->cache->ops->write_page(op, page);
48756 fscache_stat_d(&fscache_n_cop_write_page);
48757 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48758 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48759 ASSERT(PageFsCache(page));
48760
48761 - fscache_stat(&fscache_n_stores);
48762 + fscache_stat_unchecked(&fscache_n_stores);
48763
48764 op = kzalloc(sizeof(*op), GFP_NOIO);
48765 if (!op)
48766 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48767 spin_unlock(&cookie->stores_lock);
48768 spin_unlock(&object->lock);
48769
48770 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
48771 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
48772 op->store_limit = object->store_limit;
48773
48774 if (fscache_submit_op(object, &op->op) < 0)
48775 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48776
48777 spin_unlock(&cookie->lock);
48778 radix_tree_preload_end();
48779 - fscache_stat(&fscache_n_store_ops);
48780 - fscache_stat(&fscache_n_stores_ok);
48781 + fscache_stat_unchecked(&fscache_n_store_ops);
48782 + fscache_stat_unchecked(&fscache_n_stores_ok);
48783
48784 /* the work queue now carries its own ref on the object */
48785 fscache_put_operation(&op->op);
48786 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48787 return 0;
48788
48789 already_queued:
48790 - fscache_stat(&fscache_n_stores_again);
48791 + fscache_stat_unchecked(&fscache_n_stores_again);
48792 already_pending:
48793 spin_unlock(&cookie->stores_lock);
48794 spin_unlock(&object->lock);
48795 spin_unlock(&cookie->lock);
48796 radix_tree_preload_end();
48797 kfree(op);
48798 - fscache_stat(&fscache_n_stores_ok);
48799 + fscache_stat_unchecked(&fscache_n_stores_ok);
48800 _leave(" = 0");
48801 return 0;
48802
48803 @@ -851,14 +851,14 @@ nobufs:
48804 spin_unlock(&cookie->lock);
48805 radix_tree_preload_end();
48806 kfree(op);
48807 - fscache_stat(&fscache_n_stores_nobufs);
48808 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
48809 _leave(" = -ENOBUFS");
48810 return -ENOBUFS;
48811
48812 nomem_free:
48813 kfree(op);
48814 nomem:
48815 - fscache_stat(&fscache_n_stores_oom);
48816 + fscache_stat_unchecked(&fscache_n_stores_oom);
48817 _leave(" = -ENOMEM");
48818 return -ENOMEM;
48819 }
48820 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
48821 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48822 ASSERTCMP(page, !=, NULL);
48823
48824 - fscache_stat(&fscache_n_uncaches);
48825 + fscache_stat_unchecked(&fscache_n_uncaches);
48826
48827 /* cache withdrawal may beat us to it */
48828 if (!PageFsCache(page))
48829 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
48830 unsigned long loop;
48831
48832 #ifdef CONFIG_FSCACHE_STATS
48833 - atomic_add(pagevec->nr, &fscache_n_marks);
48834 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
48835 #endif
48836
48837 for (loop = 0; loop < pagevec->nr; loop++) {
48838 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
48839 index 4765190..2a067f2 100644
48840 --- a/fs/fscache/stats.c
48841 +++ b/fs/fscache/stats.c
48842 @@ -18,95 +18,95 @@
48843 /*
48844 * operation counters
48845 */
48846 -atomic_t fscache_n_op_pend;
48847 -atomic_t fscache_n_op_run;
48848 -atomic_t fscache_n_op_enqueue;
48849 -atomic_t fscache_n_op_requeue;
48850 -atomic_t fscache_n_op_deferred_release;
48851 -atomic_t fscache_n_op_release;
48852 -atomic_t fscache_n_op_gc;
48853 -atomic_t fscache_n_op_cancelled;
48854 -atomic_t fscache_n_op_rejected;
48855 +atomic_unchecked_t fscache_n_op_pend;
48856 +atomic_unchecked_t fscache_n_op_run;
48857 +atomic_unchecked_t fscache_n_op_enqueue;
48858 +atomic_unchecked_t fscache_n_op_requeue;
48859 +atomic_unchecked_t fscache_n_op_deferred_release;
48860 +atomic_unchecked_t fscache_n_op_release;
48861 +atomic_unchecked_t fscache_n_op_gc;
48862 +atomic_unchecked_t fscache_n_op_cancelled;
48863 +atomic_unchecked_t fscache_n_op_rejected;
48864
48865 -atomic_t fscache_n_attr_changed;
48866 -atomic_t fscache_n_attr_changed_ok;
48867 -atomic_t fscache_n_attr_changed_nobufs;
48868 -atomic_t fscache_n_attr_changed_nomem;
48869 -atomic_t fscache_n_attr_changed_calls;
48870 +atomic_unchecked_t fscache_n_attr_changed;
48871 +atomic_unchecked_t fscache_n_attr_changed_ok;
48872 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
48873 +atomic_unchecked_t fscache_n_attr_changed_nomem;
48874 +atomic_unchecked_t fscache_n_attr_changed_calls;
48875
48876 -atomic_t fscache_n_allocs;
48877 -atomic_t fscache_n_allocs_ok;
48878 -atomic_t fscache_n_allocs_wait;
48879 -atomic_t fscache_n_allocs_nobufs;
48880 -atomic_t fscache_n_allocs_intr;
48881 -atomic_t fscache_n_allocs_object_dead;
48882 -atomic_t fscache_n_alloc_ops;
48883 -atomic_t fscache_n_alloc_op_waits;
48884 +atomic_unchecked_t fscache_n_allocs;
48885 +atomic_unchecked_t fscache_n_allocs_ok;
48886 +atomic_unchecked_t fscache_n_allocs_wait;
48887 +atomic_unchecked_t fscache_n_allocs_nobufs;
48888 +atomic_unchecked_t fscache_n_allocs_intr;
48889 +atomic_unchecked_t fscache_n_allocs_object_dead;
48890 +atomic_unchecked_t fscache_n_alloc_ops;
48891 +atomic_unchecked_t fscache_n_alloc_op_waits;
48892
48893 -atomic_t fscache_n_retrievals;
48894 -atomic_t fscache_n_retrievals_ok;
48895 -atomic_t fscache_n_retrievals_wait;
48896 -atomic_t fscache_n_retrievals_nodata;
48897 -atomic_t fscache_n_retrievals_nobufs;
48898 -atomic_t fscache_n_retrievals_intr;
48899 -atomic_t fscache_n_retrievals_nomem;
48900 -atomic_t fscache_n_retrievals_object_dead;
48901 -atomic_t fscache_n_retrieval_ops;
48902 -atomic_t fscache_n_retrieval_op_waits;
48903 +atomic_unchecked_t fscache_n_retrievals;
48904 +atomic_unchecked_t fscache_n_retrievals_ok;
48905 +atomic_unchecked_t fscache_n_retrievals_wait;
48906 +atomic_unchecked_t fscache_n_retrievals_nodata;
48907 +atomic_unchecked_t fscache_n_retrievals_nobufs;
48908 +atomic_unchecked_t fscache_n_retrievals_intr;
48909 +atomic_unchecked_t fscache_n_retrievals_nomem;
48910 +atomic_unchecked_t fscache_n_retrievals_object_dead;
48911 +atomic_unchecked_t fscache_n_retrieval_ops;
48912 +atomic_unchecked_t fscache_n_retrieval_op_waits;
48913
48914 -atomic_t fscache_n_stores;
48915 -atomic_t fscache_n_stores_ok;
48916 -atomic_t fscache_n_stores_again;
48917 -atomic_t fscache_n_stores_nobufs;
48918 -atomic_t fscache_n_stores_oom;
48919 -atomic_t fscache_n_store_ops;
48920 -atomic_t fscache_n_store_calls;
48921 -atomic_t fscache_n_store_pages;
48922 -atomic_t fscache_n_store_radix_deletes;
48923 -atomic_t fscache_n_store_pages_over_limit;
48924 +atomic_unchecked_t fscache_n_stores;
48925 +atomic_unchecked_t fscache_n_stores_ok;
48926 +atomic_unchecked_t fscache_n_stores_again;
48927 +atomic_unchecked_t fscache_n_stores_nobufs;
48928 +atomic_unchecked_t fscache_n_stores_oom;
48929 +atomic_unchecked_t fscache_n_store_ops;
48930 +atomic_unchecked_t fscache_n_store_calls;
48931 +atomic_unchecked_t fscache_n_store_pages;
48932 +atomic_unchecked_t fscache_n_store_radix_deletes;
48933 +atomic_unchecked_t fscache_n_store_pages_over_limit;
48934
48935 -atomic_t fscache_n_store_vmscan_not_storing;
48936 -atomic_t fscache_n_store_vmscan_gone;
48937 -atomic_t fscache_n_store_vmscan_busy;
48938 -atomic_t fscache_n_store_vmscan_cancelled;
48939 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48940 +atomic_unchecked_t fscache_n_store_vmscan_gone;
48941 +atomic_unchecked_t fscache_n_store_vmscan_busy;
48942 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48943
48944 -atomic_t fscache_n_marks;
48945 -atomic_t fscache_n_uncaches;
48946 +atomic_unchecked_t fscache_n_marks;
48947 +atomic_unchecked_t fscache_n_uncaches;
48948
48949 -atomic_t fscache_n_acquires;
48950 -atomic_t fscache_n_acquires_null;
48951 -atomic_t fscache_n_acquires_no_cache;
48952 -atomic_t fscache_n_acquires_ok;
48953 -atomic_t fscache_n_acquires_nobufs;
48954 -atomic_t fscache_n_acquires_oom;
48955 +atomic_unchecked_t fscache_n_acquires;
48956 +atomic_unchecked_t fscache_n_acquires_null;
48957 +atomic_unchecked_t fscache_n_acquires_no_cache;
48958 +atomic_unchecked_t fscache_n_acquires_ok;
48959 +atomic_unchecked_t fscache_n_acquires_nobufs;
48960 +atomic_unchecked_t fscache_n_acquires_oom;
48961
48962 -atomic_t fscache_n_updates;
48963 -atomic_t fscache_n_updates_null;
48964 -atomic_t fscache_n_updates_run;
48965 +atomic_unchecked_t fscache_n_updates;
48966 +atomic_unchecked_t fscache_n_updates_null;
48967 +atomic_unchecked_t fscache_n_updates_run;
48968
48969 -atomic_t fscache_n_relinquishes;
48970 -atomic_t fscache_n_relinquishes_null;
48971 -atomic_t fscache_n_relinquishes_waitcrt;
48972 -atomic_t fscache_n_relinquishes_retire;
48973 +atomic_unchecked_t fscache_n_relinquishes;
48974 +atomic_unchecked_t fscache_n_relinquishes_null;
48975 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48976 +atomic_unchecked_t fscache_n_relinquishes_retire;
48977
48978 -atomic_t fscache_n_cookie_index;
48979 -atomic_t fscache_n_cookie_data;
48980 -atomic_t fscache_n_cookie_special;
48981 +atomic_unchecked_t fscache_n_cookie_index;
48982 +atomic_unchecked_t fscache_n_cookie_data;
48983 +atomic_unchecked_t fscache_n_cookie_special;
48984
48985 -atomic_t fscache_n_object_alloc;
48986 -atomic_t fscache_n_object_no_alloc;
48987 -atomic_t fscache_n_object_lookups;
48988 -atomic_t fscache_n_object_lookups_negative;
48989 -atomic_t fscache_n_object_lookups_positive;
48990 -atomic_t fscache_n_object_lookups_timed_out;
48991 -atomic_t fscache_n_object_created;
48992 -atomic_t fscache_n_object_avail;
48993 -atomic_t fscache_n_object_dead;
48994 +atomic_unchecked_t fscache_n_object_alloc;
48995 +atomic_unchecked_t fscache_n_object_no_alloc;
48996 +atomic_unchecked_t fscache_n_object_lookups;
48997 +atomic_unchecked_t fscache_n_object_lookups_negative;
48998 +atomic_unchecked_t fscache_n_object_lookups_positive;
48999 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
49000 +atomic_unchecked_t fscache_n_object_created;
49001 +atomic_unchecked_t fscache_n_object_avail;
49002 +atomic_unchecked_t fscache_n_object_dead;
49003
49004 -atomic_t fscache_n_checkaux_none;
49005 -atomic_t fscache_n_checkaux_okay;
49006 -atomic_t fscache_n_checkaux_update;
49007 -atomic_t fscache_n_checkaux_obsolete;
49008 +atomic_unchecked_t fscache_n_checkaux_none;
49009 +atomic_unchecked_t fscache_n_checkaux_okay;
49010 +atomic_unchecked_t fscache_n_checkaux_update;
49011 +atomic_unchecked_t fscache_n_checkaux_obsolete;
49012
49013 atomic_t fscache_n_cop_alloc_object;
49014 atomic_t fscache_n_cop_lookup_object;
49015 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
49016 seq_puts(m, "FS-Cache statistics\n");
49017
49018 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
49019 - atomic_read(&fscache_n_cookie_index),
49020 - atomic_read(&fscache_n_cookie_data),
49021 - atomic_read(&fscache_n_cookie_special));
49022 + atomic_read_unchecked(&fscache_n_cookie_index),
49023 + atomic_read_unchecked(&fscache_n_cookie_data),
49024 + atomic_read_unchecked(&fscache_n_cookie_special));
49025
49026 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
49027 - atomic_read(&fscache_n_object_alloc),
49028 - atomic_read(&fscache_n_object_no_alloc),
49029 - atomic_read(&fscache_n_object_avail),
49030 - atomic_read(&fscache_n_object_dead));
49031 + atomic_read_unchecked(&fscache_n_object_alloc),
49032 + atomic_read_unchecked(&fscache_n_object_no_alloc),
49033 + atomic_read_unchecked(&fscache_n_object_avail),
49034 + atomic_read_unchecked(&fscache_n_object_dead));
49035 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
49036 - atomic_read(&fscache_n_checkaux_none),
49037 - atomic_read(&fscache_n_checkaux_okay),
49038 - atomic_read(&fscache_n_checkaux_update),
49039 - atomic_read(&fscache_n_checkaux_obsolete));
49040 + atomic_read_unchecked(&fscache_n_checkaux_none),
49041 + atomic_read_unchecked(&fscache_n_checkaux_okay),
49042 + atomic_read_unchecked(&fscache_n_checkaux_update),
49043 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
49044
49045 seq_printf(m, "Pages : mrk=%u unc=%u\n",
49046 - atomic_read(&fscache_n_marks),
49047 - atomic_read(&fscache_n_uncaches));
49048 + atomic_read_unchecked(&fscache_n_marks),
49049 + atomic_read_unchecked(&fscache_n_uncaches));
49050
49051 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
49052 " oom=%u\n",
49053 - atomic_read(&fscache_n_acquires),
49054 - atomic_read(&fscache_n_acquires_null),
49055 - atomic_read(&fscache_n_acquires_no_cache),
49056 - atomic_read(&fscache_n_acquires_ok),
49057 - atomic_read(&fscache_n_acquires_nobufs),
49058 - atomic_read(&fscache_n_acquires_oom));
49059 + atomic_read_unchecked(&fscache_n_acquires),
49060 + atomic_read_unchecked(&fscache_n_acquires_null),
49061 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
49062 + atomic_read_unchecked(&fscache_n_acquires_ok),
49063 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
49064 + atomic_read_unchecked(&fscache_n_acquires_oom));
49065
49066 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
49067 - atomic_read(&fscache_n_object_lookups),
49068 - atomic_read(&fscache_n_object_lookups_negative),
49069 - atomic_read(&fscache_n_object_lookups_positive),
49070 - atomic_read(&fscache_n_object_created),
49071 - atomic_read(&fscache_n_object_lookups_timed_out));
49072 + atomic_read_unchecked(&fscache_n_object_lookups),
49073 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
49074 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
49075 + atomic_read_unchecked(&fscache_n_object_created),
49076 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
49077
49078 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
49079 - atomic_read(&fscache_n_updates),
49080 - atomic_read(&fscache_n_updates_null),
49081 - atomic_read(&fscache_n_updates_run));
49082 + atomic_read_unchecked(&fscache_n_updates),
49083 + atomic_read_unchecked(&fscache_n_updates_null),
49084 + atomic_read_unchecked(&fscache_n_updates_run));
49085
49086 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
49087 - atomic_read(&fscache_n_relinquishes),
49088 - atomic_read(&fscache_n_relinquishes_null),
49089 - atomic_read(&fscache_n_relinquishes_waitcrt),
49090 - atomic_read(&fscache_n_relinquishes_retire));
49091 + atomic_read_unchecked(&fscache_n_relinquishes),
49092 + atomic_read_unchecked(&fscache_n_relinquishes_null),
49093 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
49094 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
49095
49096 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
49097 - atomic_read(&fscache_n_attr_changed),
49098 - atomic_read(&fscache_n_attr_changed_ok),
49099 - atomic_read(&fscache_n_attr_changed_nobufs),
49100 - atomic_read(&fscache_n_attr_changed_nomem),
49101 - atomic_read(&fscache_n_attr_changed_calls));
49102 + atomic_read_unchecked(&fscache_n_attr_changed),
49103 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
49104 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
49105 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
49106 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
49107
49108 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
49109 - atomic_read(&fscache_n_allocs),
49110 - atomic_read(&fscache_n_allocs_ok),
49111 - atomic_read(&fscache_n_allocs_wait),
49112 - atomic_read(&fscache_n_allocs_nobufs),
49113 - atomic_read(&fscache_n_allocs_intr));
49114 + atomic_read_unchecked(&fscache_n_allocs),
49115 + atomic_read_unchecked(&fscache_n_allocs_ok),
49116 + atomic_read_unchecked(&fscache_n_allocs_wait),
49117 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
49118 + atomic_read_unchecked(&fscache_n_allocs_intr));
49119 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
49120 - atomic_read(&fscache_n_alloc_ops),
49121 - atomic_read(&fscache_n_alloc_op_waits),
49122 - atomic_read(&fscache_n_allocs_object_dead));
49123 + atomic_read_unchecked(&fscache_n_alloc_ops),
49124 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
49125 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
49126
49127 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
49128 " int=%u oom=%u\n",
49129 - atomic_read(&fscache_n_retrievals),
49130 - atomic_read(&fscache_n_retrievals_ok),
49131 - atomic_read(&fscache_n_retrievals_wait),
49132 - atomic_read(&fscache_n_retrievals_nodata),
49133 - atomic_read(&fscache_n_retrievals_nobufs),
49134 - atomic_read(&fscache_n_retrievals_intr),
49135 - atomic_read(&fscache_n_retrievals_nomem));
49136 + atomic_read_unchecked(&fscache_n_retrievals),
49137 + atomic_read_unchecked(&fscache_n_retrievals_ok),
49138 + atomic_read_unchecked(&fscache_n_retrievals_wait),
49139 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
49140 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
49141 + atomic_read_unchecked(&fscache_n_retrievals_intr),
49142 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
49143 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
49144 - atomic_read(&fscache_n_retrieval_ops),
49145 - atomic_read(&fscache_n_retrieval_op_waits),
49146 - atomic_read(&fscache_n_retrievals_object_dead));
49147 + atomic_read_unchecked(&fscache_n_retrieval_ops),
49148 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
49149 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
49150
49151 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
49152 - atomic_read(&fscache_n_stores),
49153 - atomic_read(&fscache_n_stores_ok),
49154 - atomic_read(&fscache_n_stores_again),
49155 - atomic_read(&fscache_n_stores_nobufs),
49156 - atomic_read(&fscache_n_stores_oom));
49157 + atomic_read_unchecked(&fscache_n_stores),
49158 + atomic_read_unchecked(&fscache_n_stores_ok),
49159 + atomic_read_unchecked(&fscache_n_stores_again),
49160 + atomic_read_unchecked(&fscache_n_stores_nobufs),
49161 + atomic_read_unchecked(&fscache_n_stores_oom));
49162 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
49163 - atomic_read(&fscache_n_store_ops),
49164 - atomic_read(&fscache_n_store_calls),
49165 - atomic_read(&fscache_n_store_pages),
49166 - atomic_read(&fscache_n_store_radix_deletes),
49167 - atomic_read(&fscache_n_store_pages_over_limit));
49168 + atomic_read_unchecked(&fscache_n_store_ops),
49169 + atomic_read_unchecked(&fscache_n_store_calls),
49170 + atomic_read_unchecked(&fscache_n_store_pages),
49171 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
49172 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
49173
49174 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
49175 - atomic_read(&fscache_n_store_vmscan_not_storing),
49176 - atomic_read(&fscache_n_store_vmscan_gone),
49177 - atomic_read(&fscache_n_store_vmscan_busy),
49178 - atomic_read(&fscache_n_store_vmscan_cancelled));
49179 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
49180 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
49181 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
49182 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
49183
49184 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
49185 - atomic_read(&fscache_n_op_pend),
49186 - atomic_read(&fscache_n_op_run),
49187 - atomic_read(&fscache_n_op_enqueue),
49188 - atomic_read(&fscache_n_op_cancelled),
49189 - atomic_read(&fscache_n_op_rejected));
49190 + atomic_read_unchecked(&fscache_n_op_pend),
49191 + atomic_read_unchecked(&fscache_n_op_run),
49192 + atomic_read_unchecked(&fscache_n_op_enqueue),
49193 + atomic_read_unchecked(&fscache_n_op_cancelled),
49194 + atomic_read_unchecked(&fscache_n_op_rejected));
49195 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
49196 - atomic_read(&fscache_n_op_deferred_release),
49197 - atomic_read(&fscache_n_op_release),
49198 - atomic_read(&fscache_n_op_gc));
49199 + atomic_read_unchecked(&fscache_n_op_deferred_release),
49200 + atomic_read_unchecked(&fscache_n_op_release),
49201 + atomic_read_unchecked(&fscache_n_op_gc));
49202
49203 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
49204 atomic_read(&fscache_n_cop_alloc_object),
49205 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
49206 index ee8d550..7189d8c 100644
49207 --- a/fs/fuse/cuse.c
49208 +++ b/fs/fuse/cuse.c
49209 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
49210 INIT_LIST_HEAD(&cuse_conntbl[i]);
49211
49212 /* inherit and extend fuse_dev_operations */
49213 - cuse_channel_fops = fuse_dev_operations;
49214 - cuse_channel_fops.owner = THIS_MODULE;
49215 - cuse_channel_fops.open = cuse_channel_open;
49216 - cuse_channel_fops.release = cuse_channel_release;
49217 + pax_open_kernel();
49218 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
49219 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
49220 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
49221 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
49222 + pax_close_kernel();
49223
49224 cuse_class = class_create(THIS_MODULE, "cuse");
49225 if (IS_ERR(cuse_class))
49226 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
49227 index 8c23fa7..0e3aac7 100644
49228 --- a/fs/fuse/dev.c
49229 +++ b/fs/fuse/dev.c
49230 @@ -1241,7 +1241,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
49231 ret = 0;
49232 pipe_lock(pipe);
49233
49234 - if (!pipe->readers) {
49235 + if (!atomic_read(&pipe->readers)) {
49236 send_sig(SIGPIPE, current, 0);
49237 if (!ret)
49238 ret = -EPIPE;
49239 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
49240 index 324bc08..4fdd56e 100644
49241 --- a/fs/fuse/dir.c
49242 +++ b/fs/fuse/dir.c
49243 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
49244 return link;
49245 }
49246
49247 -static void free_link(char *link)
49248 +static void free_link(const char *link)
49249 {
49250 if (!IS_ERR(link))
49251 free_page((unsigned long) link);
49252 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
49253 index 381893c..3793318 100644
49254 --- a/fs/gfs2/inode.c
49255 +++ b/fs/gfs2/inode.c
49256 @@ -1490,7 +1490,7 @@ out:
49257
49258 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
49259 {
49260 - char *s = nd_get_link(nd);
49261 + const char *s = nd_get_link(nd);
49262 if (!IS_ERR(s))
49263 kfree(s);
49264 }
49265 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
49266 index c5bc355..5a513bb 100644
49267 --- a/fs/hugetlbfs/inode.c
49268 +++ b/fs/hugetlbfs/inode.c
49269 @@ -923,7 +923,7 @@ static struct file_system_type hugetlbfs_fs_type = {
49270 .kill_sb = kill_litter_super,
49271 };
49272
49273 -static struct vfsmount *hugetlbfs_vfsmount;
49274 +struct vfsmount *hugetlbfs_vfsmount;
49275
49276 static int can_do_hugetlb_shm(void)
49277 {
49278 diff --git a/fs/inode.c b/fs/inode.c
49279 index 64999f1..8fad608 100644
49280 --- a/fs/inode.c
49281 +++ b/fs/inode.c
49282 @@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
49283
49284 #ifdef CONFIG_SMP
49285 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
49286 - static atomic_t shared_last_ino;
49287 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
49288 + static atomic_unchecked_t shared_last_ino;
49289 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
49290
49291 res = next - LAST_INO_BATCH;
49292 }
49293 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
49294 index 4a6cf28..d3a29d3 100644
49295 --- a/fs/jffs2/erase.c
49296 +++ b/fs/jffs2/erase.c
49297 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
49298 struct jffs2_unknown_node marker = {
49299 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
49300 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
49301 - .totlen = cpu_to_je32(c->cleanmarker_size)
49302 + .totlen = cpu_to_je32(c->cleanmarker_size),
49303 + .hdr_crc = cpu_to_je32(0)
49304 };
49305
49306 jffs2_prealloc_raw_node_refs(c, jeb, 1);
49307 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
49308 index a6597d6..41b30ec 100644
49309 --- a/fs/jffs2/wbuf.c
49310 +++ b/fs/jffs2/wbuf.c
49311 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
49312 {
49313 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
49314 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
49315 - .totlen = constant_cpu_to_je32(8)
49316 + .totlen = constant_cpu_to_je32(8),
49317 + .hdr_crc = constant_cpu_to_je32(0)
49318 };
49319
49320 /*
49321 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
49322 index 1a543be..d803c40 100644
49323 --- a/fs/jfs/super.c
49324 +++ b/fs/jfs/super.c
49325 @@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
49326
49327 jfs_inode_cachep =
49328 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
49329 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
49330 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
49331 init_once);
49332 if (jfs_inode_cachep == NULL)
49333 return -ENOMEM;
49334 diff --git a/fs/libfs.c b/fs/libfs.c
49335 index 7cc37ca..b3e3eec 100644
49336 --- a/fs/libfs.c
49337 +++ b/fs/libfs.c
49338 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49339
49340 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
49341 struct dentry *next;
49342 + char d_name[sizeof(next->d_iname)];
49343 + const unsigned char *name;
49344 +
49345 next = list_entry(p, struct dentry, d_u.d_child);
49346 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
49347 if (!simple_positive(next)) {
49348 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49349
49350 spin_unlock(&next->d_lock);
49351 spin_unlock(&dentry->d_lock);
49352 - if (filldir(dirent, next->d_name.name,
49353 + name = next->d_name.name;
49354 + if (name == next->d_iname) {
49355 + memcpy(d_name, name, next->d_name.len);
49356 + name = d_name;
49357 + }
49358 + if (filldir(dirent, name,
49359 next->d_name.len, filp->f_pos,
49360 next->d_inode->i_ino,
49361 dt_type(next->d_inode)) < 0)
49362 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
49363 index 05d2912..760abfa 100644
49364 --- a/fs/lockd/clntproc.c
49365 +++ b/fs/lockd/clntproc.c
49366 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
49367 /*
49368 * Cookie counter for NLM requests
49369 */
49370 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
49371 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
49372
49373 void nlmclnt_next_cookie(struct nlm_cookie *c)
49374 {
49375 - u32 cookie = atomic_inc_return(&nlm_cookie);
49376 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
49377
49378 memcpy(c->data, &cookie, 4);
49379 c->len=4;
49380 diff --git a/fs/locks.c b/fs/locks.c
49381 index a94e331..060bce3 100644
49382 --- a/fs/locks.c
49383 +++ b/fs/locks.c
49384 @@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
49385 return;
49386
49387 if (filp->f_op && filp->f_op->flock) {
49388 - struct file_lock fl = {
49389 + struct file_lock flock = {
49390 .fl_pid = current->tgid,
49391 .fl_file = filp,
49392 .fl_flags = FL_FLOCK,
49393 .fl_type = F_UNLCK,
49394 .fl_end = OFFSET_MAX,
49395 };
49396 - filp->f_op->flock(filp, F_SETLKW, &fl);
49397 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
49398 - fl.fl_ops->fl_release_private(&fl);
49399 + filp->f_op->flock(filp, F_SETLKW, &flock);
49400 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
49401 + flock.fl_ops->fl_release_private(&flock);
49402 }
49403
49404 lock_flocks();
49405 diff --git a/fs/namei.c b/fs/namei.c
49406 index 5f4cdf3..959a013 100644
49407 --- a/fs/namei.c
49408 +++ b/fs/namei.c
49409 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
49410 if (ret != -EACCES)
49411 return ret;
49412
49413 +#ifdef CONFIG_GRKERNSEC
49414 + /* we'll block if we have to log due to a denied capability use */
49415 + if (mask & MAY_NOT_BLOCK)
49416 + return -ECHILD;
49417 +#endif
49418 +
49419 if (S_ISDIR(inode->i_mode)) {
49420 /* DACs are overridable for directories */
49421 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
49422 - return 0;
49423 if (!(mask & MAY_WRITE))
49424 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49425 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49426 + inode_capable(inode, CAP_DAC_READ_SEARCH))
49427 return 0;
49428 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
49429 + return 0;
49430 return -EACCES;
49431 }
49432 /*
49433 + * Searching includes executable on directories, else just read.
49434 + */
49435 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49436 + if (mask == MAY_READ)
49437 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49438 + inode_capable(inode, CAP_DAC_READ_SEARCH))
49439 + return 0;
49440 +
49441 + /*
49442 * Read/write DACs are always overridable.
49443 * Executable DACs are overridable when there is
49444 * at least one exec bit set.
49445 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
49446 if (inode_capable(inode, CAP_DAC_OVERRIDE))
49447 return 0;
49448
49449 - /*
49450 - * Searching includes executable on directories, else just read.
49451 - */
49452 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49453 - if (mask == MAY_READ)
49454 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49455 - return 0;
49456 -
49457 return -EACCES;
49458 }
49459
49460 @@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49461 {
49462 struct dentry *dentry = link->dentry;
49463 int error;
49464 - char *s;
49465 + const char *s;
49466
49467 BUG_ON(nd->flags & LOOKUP_RCU);
49468
49469 @@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49470 if (error)
49471 goto out_put_nd_path;
49472
49473 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
49474 + dentry->d_inode, dentry, nd->path.mnt)) {
49475 + error = -EACCES;
49476 + goto out_put_nd_path;
49477 + }
49478 +
49479 nd->last_type = LAST_BIND;
49480 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
49481 error = PTR_ERR(*p);
49482 @@ -1605,6 +1619,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
49483 break;
49484 res = walk_component(nd, path, &nd->last,
49485 nd->last_type, LOOKUP_FOLLOW);
49486 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
49487 + res = -EACCES;
49488 put_link(nd, &link, cookie);
49489 } while (res > 0);
49490
49491 @@ -1703,7 +1719,7 @@ EXPORT_SYMBOL(full_name_hash);
49492 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
49493 {
49494 unsigned long a, b, adata, bdata, mask, hash, len;
49495 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49496 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49497
49498 hash = a = 0;
49499 len = -sizeof(unsigned long);
49500 @@ -1993,6 +2009,8 @@ static int path_lookupat(int dfd, const char *name,
49501 if (err)
49502 break;
49503 err = lookup_last(nd, &path);
49504 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
49505 + err = -EACCES;
49506 put_link(nd, &link, cookie);
49507 }
49508 }
49509 @@ -2000,6 +2018,21 @@ static int path_lookupat(int dfd, const char *name,
49510 if (!err)
49511 err = complete_walk(nd);
49512
49513 + if (!(nd->flags & LOOKUP_PARENT)) {
49514 +#ifdef CONFIG_GRKERNSEC
49515 + if (flags & LOOKUP_RCU) {
49516 + if (!err)
49517 + path_put(&nd->path);
49518 + err = -ECHILD;
49519 + } else
49520 +#endif
49521 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49522 + if (!err)
49523 + path_put(&nd->path);
49524 + err = -ENOENT;
49525 + }
49526 + }
49527 +
49528 if (!err && nd->flags & LOOKUP_DIRECTORY) {
49529 if (!nd->inode->i_op->lookup) {
49530 path_put(&nd->path);
49531 @@ -2027,8 +2060,17 @@ static int filename_lookup(int dfd, struct filename *name,
49532 retval = path_lookupat(dfd, name->name,
49533 flags | LOOKUP_REVAL, nd);
49534
49535 - if (likely(!retval))
49536 + if (likely(!retval)) {
49537 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
49538 +#ifdef CONFIG_GRKERNSEC
49539 + if (flags & LOOKUP_RCU)
49540 + return -ECHILD;
49541 +#endif
49542 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
49543 + return -ENOENT;
49544 + }
49545 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
49546 + }
49547 return retval;
49548 }
49549
49550 @@ -2402,6 +2444,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
49551 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
49552 return -EPERM;
49553
49554 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
49555 + return -EPERM;
49556 + if (gr_handle_rawio(inode))
49557 + return -EPERM;
49558 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
49559 + return -EACCES;
49560 +
49561 return 0;
49562 }
49563
49564 @@ -2623,7 +2672,7 @@ looked_up:
49565 * cleared otherwise prior to returning.
49566 */
49567 static int lookup_open(struct nameidata *nd, struct path *path,
49568 - struct file *file,
49569 + struct path *link, struct file *file,
49570 const struct open_flags *op,
49571 bool got_write, int *opened)
49572 {
49573 @@ -2658,6 +2707,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49574 /* Negative dentry, just create the file */
49575 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
49576 umode_t mode = op->mode;
49577 +
49578 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
49579 + error = -EACCES;
49580 + goto out_dput;
49581 + }
49582 +
49583 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
49584 + error = -EACCES;
49585 + goto out_dput;
49586 + }
49587 +
49588 if (!IS_POSIXACL(dir->d_inode))
49589 mode &= ~current_umask();
49590 /*
49591 @@ -2679,6 +2739,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49592 nd->flags & LOOKUP_EXCL);
49593 if (error)
49594 goto out_dput;
49595 + else
49596 + gr_handle_create(dentry, nd->path.mnt);
49597 }
49598 out_no_open:
49599 path->dentry = dentry;
49600 @@ -2693,7 +2755,7 @@ out_dput:
49601 /*
49602 * Handle the last step of open()
49603 */
49604 -static int do_last(struct nameidata *nd, struct path *path,
49605 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
49606 struct file *file, const struct open_flags *op,
49607 int *opened, struct filename *name)
49608 {
49609 @@ -2722,16 +2784,44 @@ static int do_last(struct nameidata *nd, struct path *path,
49610 error = complete_walk(nd);
49611 if (error)
49612 return error;
49613 +#ifdef CONFIG_GRKERNSEC
49614 + if (nd->flags & LOOKUP_RCU) {
49615 + error = -ECHILD;
49616 + goto out;
49617 + }
49618 +#endif
49619 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49620 + error = -ENOENT;
49621 + goto out;
49622 + }
49623 audit_inode(name, nd->path.dentry, 0);
49624 if (open_flag & O_CREAT) {
49625 error = -EISDIR;
49626 goto out;
49627 }
49628 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49629 + error = -EACCES;
49630 + goto out;
49631 + }
49632 goto finish_open;
49633 case LAST_BIND:
49634 error = complete_walk(nd);
49635 if (error)
49636 return error;
49637 +#ifdef CONFIG_GRKERNSEC
49638 + if (nd->flags & LOOKUP_RCU) {
49639 + error = -ECHILD;
49640 + goto out;
49641 + }
49642 +#endif
49643 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
49644 + error = -ENOENT;
49645 + goto out;
49646 + }
49647 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49648 + error = -EACCES;
49649 + goto out;
49650 + }
49651 audit_inode(name, dir, 0);
49652 goto finish_open;
49653 }
49654 @@ -2780,7 +2870,7 @@ retry_lookup:
49655 */
49656 }
49657 mutex_lock(&dir->d_inode->i_mutex);
49658 - error = lookup_open(nd, path, file, op, got_write, opened);
49659 + error = lookup_open(nd, path, link, file, op, got_write, opened);
49660 mutex_unlock(&dir->d_inode->i_mutex);
49661
49662 if (error <= 0) {
49663 @@ -2804,11 +2894,28 @@ retry_lookup:
49664 goto finish_open_created;
49665 }
49666
49667 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
49668 + error = -ENOENT;
49669 + goto exit_dput;
49670 + }
49671 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
49672 + error = -EACCES;
49673 + goto exit_dput;
49674 + }
49675 +
49676 /*
49677 * create/update audit record if it already exists.
49678 */
49679 - if (path->dentry->d_inode)
49680 + if (path->dentry->d_inode) {
49681 + /* only check if O_CREAT is specified, all other checks need to go
49682 + into may_open */
49683 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
49684 + error = -EACCES;
49685 + goto exit_dput;
49686 + }
49687 +
49688 audit_inode(name, path->dentry, 0);
49689 + }
49690
49691 /*
49692 * If atomic_open() acquired write access it is dropped now due to
49693 @@ -2849,6 +2956,11 @@ finish_lookup:
49694 }
49695 }
49696 BUG_ON(inode != path->dentry->d_inode);
49697 + /* if we're resolving a symlink to another symlink */
49698 + if (link && gr_handle_symlink_owner(link, inode)) {
49699 + error = -EACCES;
49700 + goto out;
49701 + }
49702 return 1;
49703 }
49704
49705 @@ -2858,7 +2970,6 @@ finish_lookup:
49706 save_parent.dentry = nd->path.dentry;
49707 save_parent.mnt = mntget(path->mnt);
49708 nd->path.dentry = path->dentry;
49709 -
49710 }
49711 nd->inode = inode;
49712 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
49713 @@ -2867,6 +2978,22 @@ finish_lookup:
49714 path_put(&save_parent);
49715 return error;
49716 }
49717 +
49718 +#ifdef CONFIG_GRKERNSEC
49719 + if (nd->flags & LOOKUP_RCU) {
49720 + error = -ECHILD;
49721 + goto out;
49722 + }
49723 +#endif
49724 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49725 + error = -ENOENT;
49726 + goto out;
49727 + }
49728 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49729 + error = -EACCES;
49730 + goto out;
49731 + }
49732 +
49733 error = -EISDIR;
49734 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
49735 goto out;
49736 @@ -2965,7 +3092,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49737 if (unlikely(error))
49738 goto out;
49739
49740 - error = do_last(nd, &path, file, op, &opened, pathname);
49741 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
49742 while (unlikely(error > 0)) { /* trailing symlink */
49743 struct path link = path;
49744 void *cookie;
49745 @@ -2983,7 +3110,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49746 error = follow_link(&link, nd, &cookie);
49747 if (unlikely(error))
49748 break;
49749 - error = do_last(nd, &path, file, op, &opened, pathname);
49750 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
49751 put_link(nd, &link, cookie);
49752 }
49753 out:
49754 @@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
49755 goto unlock;
49756
49757 error = -EEXIST;
49758 - if (dentry->d_inode)
49759 + if (dentry->d_inode) {
49760 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
49761 + error = -ENOENT;
49762 + }
49763 goto fail;
49764 + }
49765 /*
49766 * Special case - lookup gave negative, but... we had foo/bar/
49767 * From the vfs_mknod() POV we just have a negative dentry -
49768 @@ -3125,6 +3256,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
49769 }
49770 EXPORT_SYMBOL(user_path_create);
49771
49772 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, int is_dir)
49773 +{
49774 + struct filename *tmp = getname(pathname);
49775 + struct dentry *res;
49776 + if (IS_ERR(tmp))
49777 + return ERR_CAST(tmp);
49778 + res = kern_path_create(dfd, tmp->name, path, is_dir);
49779 + if (IS_ERR(res))
49780 + putname(tmp);
49781 + else
49782 + *to = tmp;
49783 + return res;
49784 +}
49785 +
49786 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
49787 {
49788 int error = may_create(dir, dentry);
49789 @@ -3186,6 +3331,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49790
49791 if (!IS_POSIXACL(path.dentry->d_inode))
49792 mode &= ~current_umask();
49793 +
49794 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
49795 + error = -EPERM;
49796 + goto out;
49797 + }
49798 +
49799 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
49800 + error = -EACCES;
49801 + goto out;
49802 + }
49803 +
49804 error = security_path_mknod(&path, dentry, mode, dev);
49805 if (error)
49806 goto out;
49807 @@ -3202,6 +3358,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49808 break;
49809 }
49810 out:
49811 + if (!error)
49812 + gr_handle_create(dentry, path.mnt);
49813 done_path_create(&path, dentry);
49814 return error;
49815 }
49816 @@ -3248,9 +3406,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
49817
49818 if (!IS_POSIXACL(path.dentry->d_inode))
49819 mode &= ~current_umask();
49820 +
49821 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
49822 + error = -EACCES;
49823 + goto out;
49824 + }
49825 +
49826 error = security_path_mkdir(&path, dentry, mode);
49827 if (!error)
49828 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
49829 + if (!error)
49830 + gr_handle_create(dentry, path.mnt);
49831 +out:
49832 done_path_create(&path, dentry);
49833 return error;
49834 }
49835 @@ -3327,6 +3494,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
49836 struct filename *name;
49837 struct dentry *dentry;
49838 struct nameidata nd;
49839 + ino_t saved_ino = 0;
49840 + dev_t saved_dev = 0;
49841
49842 name = user_path_parent(dfd, pathname, &nd);
49843 if (IS_ERR(name))
49844 @@ -3358,10 +3527,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
49845 error = -ENOENT;
49846 goto exit3;
49847 }
49848 +
49849 + saved_ino = dentry->d_inode->i_ino;
49850 + saved_dev = gr_get_dev_from_dentry(dentry);
49851 +
49852 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
49853 + error = -EACCES;
49854 + goto exit3;
49855 + }
49856 +
49857 error = security_path_rmdir(&nd.path, dentry);
49858 if (error)
49859 goto exit3;
49860 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
49861 + if (!error && (saved_dev || saved_ino))
49862 + gr_handle_delete(saved_ino, saved_dev);
49863 exit3:
49864 dput(dentry);
49865 exit2:
49866 @@ -3423,6 +3603,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49867 struct dentry *dentry;
49868 struct nameidata nd;
49869 struct inode *inode = NULL;
49870 + ino_t saved_ino = 0;
49871 + dev_t saved_dev = 0;
49872
49873 name = user_path_parent(dfd, pathname, &nd);
49874 if (IS_ERR(name))
49875 @@ -3448,10 +3630,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49876 if (!inode)
49877 goto slashes;
49878 ihold(inode);
49879 +
49880 + if (inode->i_nlink <= 1) {
49881 + saved_ino = inode->i_ino;
49882 + saved_dev = gr_get_dev_from_dentry(dentry);
49883 + }
49884 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
49885 + error = -EACCES;
49886 + goto exit2;
49887 + }
49888 +
49889 error = security_path_unlink(&nd.path, dentry);
49890 if (error)
49891 goto exit2;
49892 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
49893 + if (!error && (saved_ino || saved_dev))
49894 + gr_handle_delete(saved_ino, saved_dev);
49895 exit2:
49896 dput(dentry);
49897 }
49898 @@ -3523,9 +3717,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
49899 if (IS_ERR(dentry))
49900 goto out_putname;
49901
49902 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
49903 + error = -EACCES;
49904 + goto out;
49905 + }
49906 +
49907 error = security_path_symlink(&path, dentry, from->name);
49908 if (!error)
49909 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
49910 + if (!error)
49911 + gr_handle_create(dentry, path.mnt);
49912 +out:
49913 done_path_create(&path, dentry);
49914 out_putname:
49915 putname(from);
49916 @@ -3595,6 +3797,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49917 {
49918 struct dentry *new_dentry;
49919 struct path old_path, new_path;
49920 + struct filename *to = NULL;
49921 int how = 0;
49922 int error;
49923
49924 @@ -3618,7 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49925 if (error)
49926 return error;
49927
49928 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
49929 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
49930 error = PTR_ERR(new_dentry);
49931 if (IS_ERR(new_dentry))
49932 goto out;
49933 @@ -3629,11 +3832,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49934 error = may_linkat(&old_path);
49935 if (unlikely(error))
49936 goto out_dput;
49937 +
49938 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
49939 + old_path.dentry->d_inode,
49940 + old_path.dentry->d_inode->i_mode, to)) {
49941 + error = -EACCES;
49942 + goto out_dput;
49943 + }
49944 +
49945 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
49946 + old_path.dentry, old_path.mnt, to)) {
49947 + error = -EACCES;
49948 + goto out_dput;
49949 + }
49950 +
49951 error = security_path_link(old_path.dentry, &new_path, new_dentry);
49952 if (error)
49953 goto out_dput;
49954 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
49955 + if (!error)
49956 + gr_handle_create(new_dentry, new_path.mnt);
49957 out_dput:
49958 + putname(to);
49959 done_path_create(&new_path, new_dentry);
49960 out:
49961 path_put(&old_path);
49962 @@ -3873,12 +4093,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
49963 if (new_dentry == trap)
49964 goto exit5;
49965
49966 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
49967 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
49968 + to);
49969 + if (error)
49970 + goto exit5;
49971 +
49972 error = security_path_rename(&oldnd.path, old_dentry,
49973 &newnd.path, new_dentry);
49974 if (error)
49975 goto exit5;
49976 error = vfs_rename(old_dir->d_inode, old_dentry,
49977 new_dir->d_inode, new_dentry);
49978 + if (!error)
49979 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
49980 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
49981 exit5:
49982 dput(new_dentry);
49983 exit4:
49984 @@ -3903,6 +4132,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
49985
49986 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
49987 {
49988 + char tmpbuf[64];
49989 + const char *newlink;
49990 int len;
49991
49992 len = PTR_ERR(link);
49993 @@ -3912,7 +4143,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
49994 len = strlen(link);
49995 if (len > (unsigned) buflen)
49996 len = buflen;
49997 - if (copy_to_user(buffer, link, len))
49998 +
49999 + if (len < sizeof(tmpbuf)) {
50000 + memcpy(tmpbuf, link, len);
50001 + newlink = tmpbuf;
50002 + } else
50003 + newlink = link;
50004 +
50005 + if (copy_to_user(buffer, newlink, len))
50006 len = -EFAULT;
50007 out:
50008 return len;
50009 diff --git a/fs/namespace.c b/fs/namespace.c
50010 index 2496062..e26f6d6 100644
50011 --- a/fs/namespace.c
50012 +++ b/fs/namespace.c
50013 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
50014 if (!(sb->s_flags & MS_RDONLY))
50015 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
50016 up_write(&sb->s_umount);
50017 +
50018 + gr_log_remount(mnt->mnt_devname, retval);
50019 +
50020 return retval;
50021 }
50022
50023 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
50024 br_write_unlock(&vfsmount_lock);
50025 up_write(&namespace_sem);
50026 release_mounts(&umount_list);
50027 +
50028 + gr_log_unmount(mnt->mnt_devname, retval);
50029 +
50030 return retval;
50031 }
50032
50033 @@ -2244,6 +2250,16 @@ long do_mount(const char *dev_name, const char *dir_name,
50034 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
50035 MS_STRICTATIME);
50036
50037 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
50038 + retval = -EPERM;
50039 + goto dput_out;
50040 + }
50041 +
50042 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
50043 + retval = -EPERM;
50044 + goto dput_out;
50045 + }
50046 +
50047 if (flags & MS_REMOUNT)
50048 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
50049 data_page);
50050 @@ -2258,6 +2274,9 @@ long do_mount(const char *dev_name, const char *dir_name,
50051 dev_name, data_page);
50052 dput_out:
50053 path_put(&path);
50054 +
50055 + gr_log_mount(dev_name, dir_name, retval);
50056 +
50057 return retval;
50058 }
50059
50060 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
50061 if (error)
50062 goto out2;
50063
50064 + if (gr_handle_chroot_pivot()) {
50065 + error = -EPERM;
50066 + goto out2;
50067 + }
50068 +
50069 get_fs_root(current->fs, &root);
50070 error = lock_mount(&old);
50071 if (error)
50072 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
50073 index 6fa01ae..2790820 100644
50074 --- a/fs/nfs/inode.c
50075 +++ b/fs/nfs/inode.c
50076 @@ -1029,16 +1029,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
50077 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
50078 }
50079
50080 -static atomic_long_t nfs_attr_generation_counter;
50081 +static atomic_long_unchecked_t nfs_attr_generation_counter;
50082
50083 static unsigned long nfs_read_attr_generation_counter(void)
50084 {
50085 - return atomic_long_read(&nfs_attr_generation_counter);
50086 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
50087 }
50088
50089 unsigned long nfs_inc_attr_generation_counter(void)
50090 {
50091 - return atomic_long_inc_return(&nfs_attr_generation_counter);
50092 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
50093 }
50094
50095 void nfs_fattr_init(struct nfs_fattr *fattr)
50096 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
50097 index f59169e..fd7d359 100644
50098 --- a/fs/nfsd/vfs.c
50099 +++ b/fs/nfsd/vfs.c
50100 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
50101 } else {
50102 oldfs = get_fs();
50103 set_fs(KERNEL_DS);
50104 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
50105 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
50106 set_fs(oldfs);
50107 }
50108
50109 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
50110
50111 /* Write the data. */
50112 oldfs = get_fs(); set_fs(KERNEL_DS);
50113 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
50114 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
50115 set_fs(oldfs);
50116 if (host_err < 0)
50117 goto out_nfserr;
50118 @@ -1587,7 +1587,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
50119 */
50120
50121 oldfs = get_fs(); set_fs(KERNEL_DS);
50122 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
50123 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
50124 set_fs(oldfs);
50125
50126 if (host_err < 0)
50127 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
50128 index 6fcaeb8..9d16d04 100644
50129 --- a/fs/notify/fanotify/fanotify_user.c
50130 +++ b/fs/notify/fanotify/fanotify_user.c
50131 @@ -250,8 +250,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
50132
50133 fd = fanotify_event_metadata.fd;
50134 ret = -EFAULT;
50135 - if (copy_to_user(buf, &fanotify_event_metadata,
50136 - fanotify_event_metadata.event_len))
50137 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
50138 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
50139 goto out_close_fd;
50140
50141 ret = prepare_for_access_response(group, event, fd);
50142 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
50143 index c887b13..0fdf472 100644
50144 --- a/fs/notify/notification.c
50145 +++ b/fs/notify/notification.c
50146 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
50147 * get set to 0 so it will never get 'freed'
50148 */
50149 static struct fsnotify_event *q_overflow_event;
50150 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50151 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50152
50153 /**
50154 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
50155 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50156 */
50157 u32 fsnotify_get_cookie(void)
50158 {
50159 - return atomic_inc_return(&fsnotify_sync_cookie);
50160 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
50161 }
50162 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
50163
50164 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
50165 index 99e3610..02c1068 100644
50166 --- a/fs/ntfs/dir.c
50167 +++ b/fs/ntfs/dir.c
50168 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
50169 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
50170 ~(s64)(ndir->itype.index.block_size - 1)));
50171 /* Bounds checks. */
50172 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
50173 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
50174 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
50175 "inode 0x%lx or driver bug.", vdir->i_ino);
50176 goto err_out;
50177 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
50178 index 1ecf464..e1ff8bf 100644
50179 --- a/fs/ntfs/file.c
50180 +++ b/fs/ntfs/file.c
50181 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
50182 #endif /* NTFS_RW */
50183 };
50184
50185 -const struct file_operations ntfs_empty_file_ops = {};
50186 +const struct file_operations ntfs_empty_file_ops __read_only;
50187
50188 -const struct inode_operations ntfs_empty_inode_ops = {};
50189 +const struct inode_operations ntfs_empty_inode_ops __read_only;
50190 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
50191 index a9f78c7..ed8a381 100644
50192 --- a/fs/ocfs2/localalloc.c
50193 +++ b/fs/ocfs2/localalloc.c
50194 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
50195 goto bail;
50196 }
50197
50198 - atomic_inc(&osb->alloc_stats.moves);
50199 + atomic_inc_unchecked(&osb->alloc_stats.moves);
50200
50201 bail:
50202 if (handle)
50203 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
50204 index d355e6e..578d905 100644
50205 --- a/fs/ocfs2/ocfs2.h
50206 +++ b/fs/ocfs2/ocfs2.h
50207 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
50208
50209 struct ocfs2_alloc_stats
50210 {
50211 - atomic_t moves;
50212 - atomic_t local_data;
50213 - atomic_t bitmap_data;
50214 - atomic_t bg_allocs;
50215 - atomic_t bg_extends;
50216 + atomic_unchecked_t moves;
50217 + atomic_unchecked_t local_data;
50218 + atomic_unchecked_t bitmap_data;
50219 + atomic_unchecked_t bg_allocs;
50220 + atomic_unchecked_t bg_extends;
50221 };
50222
50223 enum ocfs2_local_alloc_state
50224 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
50225 index f169da4..9112253 100644
50226 --- a/fs/ocfs2/suballoc.c
50227 +++ b/fs/ocfs2/suballoc.c
50228 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
50229 mlog_errno(status);
50230 goto bail;
50231 }
50232 - atomic_inc(&osb->alloc_stats.bg_extends);
50233 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
50234
50235 /* You should never ask for this much metadata */
50236 BUG_ON(bits_wanted >
50237 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
50238 mlog_errno(status);
50239 goto bail;
50240 }
50241 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50242 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50243
50244 *suballoc_loc = res.sr_bg_blkno;
50245 *suballoc_bit_start = res.sr_bit_offset;
50246 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
50247 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
50248 res->sr_bits);
50249
50250 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50251 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50252
50253 BUG_ON(res->sr_bits != 1);
50254
50255 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
50256 mlog_errno(status);
50257 goto bail;
50258 }
50259 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50260 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50261
50262 BUG_ON(res.sr_bits != 1);
50263
50264 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
50265 cluster_start,
50266 num_clusters);
50267 if (!status)
50268 - atomic_inc(&osb->alloc_stats.local_data);
50269 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
50270 } else {
50271 if (min_clusters > (osb->bitmap_cpg - 1)) {
50272 /* The only paths asking for contiguousness
50273 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
50274 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
50275 res.sr_bg_blkno,
50276 res.sr_bit_offset);
50277 - atomic_inc(&osb->alloc_stats.bitmap_data);
50278 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
50279 *num_clusters = res.sr_bits;
50280 }
50281 }
50282 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
50283 index 0e91ec2..f4b3fc6 100644
50284 --- a/fs/ocfs2/super.c
50285 +++ b/fs/ocfs2/super.c
50286 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
50287 "%10s => GlobalAllocs: %d LocalAllocs: %d "
50288 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
50289 "Stats",
50290 - atomic_read(&osb->alloc_stats.bitmap_data),
50291 - atomic_read(&osb->alloc_stats.local_data),
50292 - atomic_read(&osb->alloc_stats.bg_allocs),
50293 - atomic_read(&osb->alloc_stats.moves),
50294 - atomic_read(&osb->alloc_stats.bg_extends));
50295 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
50296 + atomic_read_unchecked(&osb->alloc_stats.local_data),
50297 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
50298 + atomic_read_unchecked(&osb->alloc_stats.moves),
50299 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
50300
50301 out += snprintf(buf + out, len - out,
50302 "%10s => State: %u Descriptor: %llu Size: %u bits "
50303 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
50304 spin_lock_init(&osb->osb_xattr_lock);
50305 ocfs2_init_steal_slots(osb);
50306
50307 - atomic_set(&osb->alloc_stats.moves, 0);
50308 - atomic_set(&osb->alloc_stats.local_data, 0);
50309 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
50310 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
50311 - atomic_set(&osb->alloc_stats.bg_extends, 0);
50312 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
50313 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
50314 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
50315 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
50316 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
50317
50318 /* Copy the blockcheck stats from the superblock probe */
50319 osb->osb_ecc_stats = *stats;
50320 diff --git a/fs/open.c b/fs/open.c
50321 index 59071f5..c6229a0 100644
50322 --- a/fs/open.c
50323 +++ b/fs/open.c
50324 @@ -31,6 +31,8 @@
50325 #include <linux/ima.h>
50326 #include <linux/dnotify.h>
50327
50328 +#define CREATE_TRACE_POINTS
50329 +#include <trace/events/fs.h>
50330 #include "internal.h"
50331
50332 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
50333 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
50334 error = locks_verify_truncate(inode, NULL, length);
50335 if (!error)
50336 error = security_path_truncate(&path);
50337 +
50338 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
50339 + error = -EACCES;
50340 +
50341 if (!error)
50342 error = do_truncate(path.dentry, length, 0, NULL);
50343
50344 @@ -362,6 +368,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
50345 if (__mnt_is_readonly(path.mnt))
50346 res = -EROFS;
50347
50348 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
50349 + res = -EACCES;
50350 +
50351 out_path_release:
50352 path_put(&path);
50353 out:
50354 @@ -388,6 +397,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
50355 if (error)
50356 goto dput_and_out;
50357
50358 + gr_log_chdir(path.dentry, path.mnt);
50359 +
50360 set_fs_pwd(current->fs, &path);
50361
50362 dput_and_out:
50363 @@ -413,6 +424,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
50364 goto out_putf;
50365
50366 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
50367 +
50368 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
50369 + error = -EPERM;
50370 +
50371 + if (!error)
50372 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
50373 +
50374 if (!error)
50375 set_fs_pwd(current->fs, &f.file->f_path);
50376 out_putf:
50377 @@ -441,7 +459,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
50378 if (error)
50379 goto dput_and_out;
50380
50381 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
50382 + goto dput_and_out;
50383 +
50384 set_fs_root(current->fs, &path);
50385 +
50386 + gr_handle_chroot_chdir(&path);
50387 +
50388 error = 0;
50389 dput_and_out:
50390 path_put(&path);
50391 @@ -459,6 +483,16 @@ static int chmod_common(struct path *path, umode_t mode)
50392 if (error)
50393 return error;
50394 mutex_lock(&inode->i_mutex);
50395 +
50396 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
50397 + error = -EACCES;
50398 + goto out_unlock;
50399 + }
50400 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
50401 + error = -EACCES;
50402 + goto out_unlock;
50403 + }
50404 +
50405 error = security_path_chmod(path, mode);
50406 if (error)
50407 goto out_unlock;
50408 @@ -514,6 +548,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
50409 uid = make_kuid(current_user_ns(), user);
50410 gid = make_kgid(current_user_ns(), group);
50411
50412 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
50413 + return -EACCES;
50414 +
50415 newattrs.ia_valid = ATTR_CTIME;
50416 if (user != (uid_t) -1) {
50417 if (!uid_valid(uid))
50418 @@ -925,6 +962,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
50419 } else {
50420 fsnotify_open(f);
50421 fd_install(fd, f);
50422 + trace_do_sys_open(tmp->name, flags, mode);
50423 }
50424 }
50425 putname(tmp);
50426 diff --git a/fs/pipe.c b/fs/pipe.c
50427 index bd3479d..fb92c4d 100644
50428 --- a/fs/pipe.c
50429 +++ b/fs/pipe.c
50430 @@ -438,9 +438,9 @@ redo:
50431 }
50432 if (bufs) /* More to do? */
50433 continue;
50434 - if (!pipe->writers)
50435 + if (!atomic_read(&pipe->writers))
50436 break;
50437 - if (!pipe->waiting_writers) {
50438 + if (!atomic_read(&pipe->waiting_writers)) {
50439 /* syscall merging: Usually we must not sleep
50440 * if O_NONBLOCK is set, or if we got some data.
50441 * But if a writer sleeps in kernel space, then
50442 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
50443 mutex_lock(&inode->i_mutex);
50444 pipe = inode->i_pipe;
50445
50446 - if (!pipe->readers) {
50447 + if (!atomic_read(&pipe->readers)) {
50448 send_sig(SIGPIPE, current, 0);
50449 ret = -EPIPE;
50450 goto out;
50451 @@ -553,7 +553,7 @@ redo1:
50452 for (;;) {
50453 int bufs;
50454
50455 - if (!pipe->readers) {
50456 + if (!atomic_read(&pipe->readers)) {
50457 send_sig(SIGPIPE, current, 0);
50458 if (!ret)
50459 ret = -EPIPE;
50460 @@ -644,9 +644,9 @@ redo2:
50461 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50462 do_wakeup = 0;
50463 }
50464 - pipe->waiting_writers++;
50465 + atomic_inc(&pipe->waiting_writers);
50466 pipe_wait(pipe);
50467 - pipe->waiting_writers--;
50468 + atomic_dec(&pipe->waiting_writers);
50469 }
50470 out:
50471 mutex_unlock(&inode->i_mutex);
50472 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50473 mask = 0;
50474 if (filp->f_mode & FMODE_READ) {
50475 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
50476 - if (!pipe->writers && filp->f_version != pipe->w_counter)
50477 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
50478 mask |= POLLHUP;
50479 }
50480
50481 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50482 * Most Unices do not set POLLERR for FIFOs but on Linux they
50483 * behave exactly like pipes for poll().
50484 */
50485 - if (!pipe->readers)
50486 + if (!atomic_read(&pipe->readers))
50487 mask |= POLLERR;
50488 }
50489
50490 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
50491
50492 mutex_lock(&inode->i_mutex);
50493 pipe = inode->i_pipe;
50494 - pipe->readers -= decr;
50495 - pipe->writers -= decw;
50496 + atomic_sub(decr, &pipe->readers);
50497 + atomic_sub(decw, &pipe->writers);
50498
50499 - if (!pipe->readers && !pipe->writers) {
50500 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
50501 free_pipe_info(inode);
50502 } else {
50503 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
50504 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
50505
50506 if (inode->i_pipe) {
50507 ret = 0;
50508 - inode->i_pipe->readers++;
50509 + atomic_inc(&inode->i_pipe->readers);
50510 }
50511
50512 mutex_unlock(&inode->i_mutex);
50513 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
50514
50515 if (inode->i_pipe) {
50516 ret = 0;
50517 - inode->i_pipe->writers++;
50518 + atomic_inc(&inode->i_pipe->writers);
50519 }
50520
50521 mutex_unlock(&inode->i_mutex);
50522 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
50523 if (inode->i_pipe) {
50524 ret = 0;
50525 if (filp->f_mode & FMODE_READ)
50526 - inode->i_pipe->readers++;
50527 + atomic_inc(&inode->i_pipe->readers);
50528 if (filp->f_mode & FMODE_WRITE)
50529 - inode->i_pipe->writers++;
50530 + atomic_inc(&inode->i_pipe->writers);
50531 }
50532
50533 mutex_unlock(&inode->i_mutex);
50534 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
50535 inode->i_pipe = NULL;
50536 }
50537
50538 -static struct vfsmount *pipe_mnt __read_mostly;
50539 +struct vfsmount *pipe_mnt __read_mostly;
50540
50541 /*
50542 * pipefs_dname() is called from d_path().
50543 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
50544 goto fail_iput;
50545 inode->i_pipe = pipe;
50546
50547 - pipe->readers = pipe->writers = 1;
50548 + atomic_set(&pipe->readers, 1);
50549 + atomic_set(&pipe->writers, 1);
50550 inode->i_fop = &rdwr_pipefifo_fops;
50551
50552 /*
50553 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
50554 index 15af622..0e9f4467 100644
50555 --- a/fs/proc/Kconfig
50556 +++ b/fs/proc/Kconfig
50557 @@ -30,12 +30,12 @@ config PROC_FS
50558
50559 config PROC_KCORE
50560 bool "/proc/kcore support" if !ARM
50561 - depends on PROC_FS && MMU
50562 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
50563
50564 config PROC_VMCORE
50565 bool "/proc/vmcore support"
50566 - depends on PROC_FS && CRASH_DUMP
50567 - default y
50568 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
50569 + default n
50570 help
50571 Exports the dump image of crashed kernel in ELF format.
50572
50573 @@ -59,8 +59,8 @@ config PROC_SYSCTL
50574 limited in memory.
50575
50576 config PROC_PAGE_MONITOR
50577 - default y
50578 - depends on PROC_FS && MMU
50579 + default n
50580 + depends on PROC_FS && MMU && !GRKERNSEC
50581 bool "Enable /proc page monitoring" if EXPERT
50582 help
50583 Various /proc files exist to monitor process memory utilization:
50584 diff --git a/fs/proc/array.c b/fs/proc/array.c
50585 index bd31e02..15cae71 100644
50586 --- a/fs/proc/array.c
50587 +++ b/fs/proc/array.c
50588 @@ -60,6 +60,7 @@
50589 #include <linux/tty.h>
50590 #include <linux/string.h>
50591 #include <linux/mman.h>
50592 +#include <linux/grsecurity.h>
50593 #include <linux/proc_fs.h>
50594 #include <linux/ioport.h>
50595 #include <linux/uaccess.h>
50596 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
50597 seq_putc(m, '\n');
50598 }
50599
50600 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50601 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
50602 +{
50603 + if (p->mm)
50604 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
50605 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
50606 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
50607 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
50608 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
50609 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
50610 + else
50611 + seq_printf(m, "PaX:\t-----\n");
50612 +}
50613 +#endif
50614 +
50615 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50616 struct pid *pid, struct task_struct *task)
50617 {
50618 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50619 task_cpus_allowed(m, task);
50620 cpuset_task_status_allowed(m, task);
50621 task_context_switch_counts(m, task);
50622 +
50623 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50624 + task_pax(m, task);
50625 +#endif
50626 +
50627 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
50628 + task_grsec_rbac(m, task);
50629 +#endif
50630 +
50631 return 0;
50632 }
50633
50634 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50635 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50636 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50637 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50638 +#endif
50639 +
50640 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50641 struct pid *pid, struct task_struct *task, int whole)
50642 {
50643 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50644 char tcomm[sizeof(task->comm)];
50645 unsigned long flags;
50646
50647 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50648 + if (current->exec_id != m->exec_id) {
50649 + gr_log_badprocpid("stat");
50650 + return 0;
50651 + }
50652 +#endif
50653 +
50654 state = *get_task_state(task);
50655 vsize = eip = esp = 0;
50656 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50657 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50658 gtime = task->gtime;
50659 }
50660
50661 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50662 + if (PAX_RAND_FLAGS(mm)) {
50663 + eip = 0;
50664 + esp = 0;
50665 + wchan = 0;
50666 + }
50667 +#endif
50668 +#ifdef CONFIG_GRKERNSEC_HIDESYM
50669 + wchan = 0;
50670 + eip =0;
50671 + esp =0;
50672 +#endif
50673 +
50674 /* scale priority and nice values from timeslices to -20..20 */
50675 /* to make it look like a "normal" Unix priority/nice value */
50676 priority = task_prio(task);
50677 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50678 seq_put_decimal_ull(m, ' ', vsize);
50679 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
50680 seq_put_decimal_ull(m, ' ', rsslim);
50681 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50682 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
50683 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
50684 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
50685 +#else
50686 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
50687 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
50688 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
50689 +#endif
50690 seq_put_decimal_ull(m, ' ', esp);
50691 seq_put_decimal_ull(m, ' ', eip);
50692 /* The signal information here is obsolete.
50693 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50694 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
50695 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
50696
50697 - if (mm && permitted) {
50698 + if (mm && permitted
50699 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50700 + && !PAX_RAND_FLAGS(mm)
50701 +#endif
50702 + ) {
50703 seq_put_decimal_ull(m, ' ', mm->start_data);
50704 seq_put_decimal_ull(m, ' ', mm->end_data);
50705 seq_put_decimal_ull(m, ' ', mm->start_brk);
50706 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50707 struct pid *pid, struct task_struct *task)
50708 {
50709 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
50710 - struct mm_struct *mm = get_task_mm(task);
50711 + struct mm_struct *mm;
50712
50713 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50714 + if (current->exec_id != m->exec_id) {
50715 + gr_log_badprocpid("statm");
50716 + return 0;
50717 + }
50718 +#endif
50719 + mm = get_task_mm(task);
50720 if (mm) {
50721 size = task_statm(mm, &shared, &text, &data, &resident);
50722 mmput(mm);
50723 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50724 return 0;
50725 }
50726
50727 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50728 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
50729 +{
50730 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
50731 +}
50732 +#endif
50733 +
50734 #ifdef CONFIG_CHECKPOINT_RESTORE
50735 static struct pid *
50736 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
50737 diff --git a/fs/proc/base.c b/fs/proc/base.c
50738 index 9e28356..c485b3c 100644
50739 --- a/fs/proc/base.c
50740 +++ b/fs/proc/base.c
50741 @@ -111,6 +111,14 @@ struct pid_entry {
50742 union proc_op op;
50743 };
50744
50745 +struct getdents_callback {
50746 + struct linux_dirent __user * current_dir;
50747 + struct linux_dirent __user * previous;
50748 + struct file * file;
50749 + int count;
50750 + int error;
50751 +};
50752 +
50753 #define NOD(NAME, MODE, IOP, FOP, OP) { \
50754 .name = (NAME), \
50755 .len = sizeof(NAME) - 1, \
50756 @@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
50757 if (!mm->arg_end)
50758 goto out_mm; /* Shh! No looking before we're done */
50759
50760 + if (gr_acl_handle_procpidmem(task))
50761 + goto out_mm;
50762 +
50763 len = mm->arg_end - mm->arg_start;
50764
50765 if (len > PAGE_SIZE)
50766 @@ -235,12 +246,28 @@ out:
50767 return res;
50768 }
50769
50770 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50771 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50772 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50773 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50774 +#endif
50775 +
50776 static int proc_pid_auxv(struct task_struct *task, char *buffer)
50777 {
50778 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
50779 int res = PTR_ERR(mm);
50780 if (mm && !IS_ERR(mm)) {
50781 unsigned int nwords = 0;
50782 +
50783 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50784 + /* allow if we're currently ptracing this task */
50785 + if (PAX_RAND_FLAGS(mm) &&
50786 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
50787 + mmput(mm);
50788 + return 0;
50789 + }
50790 +#endif
50791 +
50792 do {
50793 nwords += 2;
50794 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
50795 @@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
50796 }
50797
50798
50799 -#ifdef CONFIG_KALLSYMS
50800 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50801 /*
50802 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
50803 * Returns the resolved symbol. If that fails, simply return the address.
50804 @@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
50805 mutex_unlock(&task->signal->cred_guard_mutex);
50806 }
50807
50808 -#ifdef CONFIG_STACKTRACE
50809 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50810
50811 #define MAX_STACK_TRACE_DEPTH 64
50812
50813 @@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
50814 return count;
50815 }
50816
50817 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50818 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50819 static int proc_pid_syscall(struct task_struct *task, char *buffer)
50820 {
50821 long nr;
50822 @@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
50823 /************************************************************************/
50824
50825 /* permission checks */
50826 -static int proc_fd_access_allowed(struct inode *inode)
50827 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
50828 {
50829 struct task_struct *task;
50830 int allowed = 0;
50831 @@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
50832 */
50833 task = get_proc_task(inode);
50834 if (task) {
50835 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50836 + if (log)
50837 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50838 + else
50839 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50840 put_task_struct(task);
50841 }
50842 return allowed;
50843 @@ -562,10 +592,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
50844 struct task_struct *task,
50845 int hide_pid_min)
50846 {
50847 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50848 + return false;
50849 +
50850 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50851 + rcu_read_lock();
50852 + {
50853 + const struct cred *tmpcred = current_cred();
50854 + const struct cred *cred = __task_cred(task);
50855 +
50856 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
50857 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50858 + || in_group_p(grsec_proc_gid)
50859 +#endif
50860 + ) {
50861 + rcu_read_unlock();
50862 + return true;
50863 + }
50864 + }
50865 + rcu_read_unlock();
50866 +
50867 + if (!pid->hide_pid)
50868 + return false;
50869 +#endif
50870 +
50871 if (pid->hide_pid < hide_pid_min)
50872 return true;
50873 if (in_group_p(pid->pid_gid))
50874 return true;
50875 +
50876 return ptrace_may_access(task, PTRACE_MODE_READ);
50877 }
50878
50879 @@ -583,7 +638,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
50880 put_task_struct(task);
50881
50882 if (!has_perms) {
50883 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50884 + {
50885 +#else
50886 if (pid->hide_pid == 2) {
50887 +#endif
50888 /*
50889 * Let's make getdents(), stat(), and open()
50890 * consistent with each other. If a process
50891 @@ -681,6 +740,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
50892 if (!task)
50893 return -ESRCH;
50894
50895 + if (gr_acl_handle_procpidmem(task)) {
50896 + put_task_struct(task);
50897 + return -EPERM;
50898 + }
50899 +
50900 mm = mm_access(task, mode);
50901 put_task_struct(task);
50902
50903 @@ -696,6 +760,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
50904
50905 file->private_data = mm;
50906
50907 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50908 + file->f_version = current->exec_id;
50909 +#endif
50910 +
50911 return 0;
50912 }
50913
50914 @@ -717,6 +785,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
50915 ssize_t copied;
50916 char *page;
50917
50918 +#ifdef CONFIG_GRKERNSEC
50919 + if (write)
50920 + return -EPERM;
50921 +#endif
50922 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50923 + if (file->f_version != current->exec_id) {
50924 + gr_log_badprocpid("mem");
50925 + return 0;
50926 + }
50927 +#endif
50928 +
50929 if (!mm)
50930 return 0;
50931
50932 @@ -821,6 +900,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
50933 if (!mm)
50934 return 0;
50935
50936 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50937 + if (file->f_version != current->exec_id) {
50938 + gr_log_badprocpid("environ");
50939 + return 0;
50940 + }
50941 +#endif
50942 +
50943 page = (char *)__get_free_page(GFP_TEMPORARY);
50944 if (!page)
50945 return -ENOMEM;
50946 @@ -1436,7 +1522,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
50947 int error = -EACCES;
50948
50949 /* Are we allowed to snoop on the tasks file descriptors? */
50950 - if (!proc_fd_access_allowed(inode))
50951 + if (!proc_fd_access_allowed(inode, 0))
50952 goto out;
50953
50954 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
50955 @@ -1480,8 +1566,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
50956 struct path path;
50957
50958 /* Are we allowed to snoop on the tasks file descriptors? */
50959 - if (!proc_fd_access_allowed(inode))
50960 - goto out;
50961 + /* logging this is needed for learning on chromium to work properly,
50962 + but we don't want to flood the logs from 'ps' which does a readlink
50963 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
50964 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
50965 + */
50966 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
50967 + if (!proc_fd_access_allowed(inode,0))
50968 + goto out;
50969 + } else {
50970 + if (!proc_fd_access_allowed(inode,1))
50971 + goto out;
50972 + }
50973
50974 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
50975 if (error)
50976 @@ -1531,7 +1627,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
50977 rcu_read_lock();
50978 cred = __task_cred(task);
50979 inode->i_uid = cred->euid;
50980 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50981 + inode->i_gid = grsec_proc_gid;
50982 +#else
50983 inode->i_gid = cred->egid;
50984 +#endif
50985 rcu_read_unlock();
50986 }
50987 security_task_to_inode(task, inode);
50988 @@ -1567,10 +1667,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
50989 return -ENOENT;
50990 }
50991 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
50992 +#ifdef CONFIG_GRKERNSEC_PROC_USER
50993 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
50994 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50995 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
50996 +#endif
50997 task_dumpable(task)) {
50998 cred = __task_cred(task);
50999 stat->uid = cred->euid;
51000 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51001 + stat->gid = grsec_proc_gid;
51002 +#else
51003 stat->gid = cred->egid;
51004 +#endif
51005 }
51006 }
51007 rcu_read_unlock();
51008 @@ -1608,11 +1717,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
51009
51010 if (task) {
51011 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51012 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51013 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51014 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51015 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51016 +#endif
51017 task_dumpable(task)) {
51018 rcu_read_lock();
51019 cred = __task_cred(task);
51020 inode->i_uid = cred->euid;
51021 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51022 + inode->i_gid = grsec_proc_gid;
51023 +#else
51024 inode->i_gid = cred->egid;
51025 +#endif
51026 rcu_read_unlock();
51027 } else {
51028 inode->i_uid = GLOBAL_ROOT_UID;
51029 @@ -2065,6 +2183,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
51030 if (!task)
51031 goto out_no_task;
51032
51033 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51034 + goto out;
51035 +
51036 /*
51037 * Yes, it does not scale. And it should not. Don't add
51038 * new entries into /proc/<tgid>/ without very good reasons.
51039 @@ -2109,6 +2230,9 @@ static int proc_pident_readdir(struct file *filp,
51040 if (!task)
51041 goto out_no_task;
51042
51043 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51044 + goto out;
51045 +
51046 ret = 0;
51047 i = filp->f_pos;
51048 switch (i) {
51049 @@ -2380,7 +2504,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
51050 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
51051 void *cookie)
51052 {
51053 - char *s = nd_get_link(nd);
51054 + const char *s = nd_get_link(nd);
51055 if (!IS_ERR(s))
51056 kfree(s);
51057 }
51058 @@ -2662,7 +2786,7 @@ static const struct pid_entry tgid_base_stuff[] = {
51059 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
51060 #endif
51061 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51062 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51063 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51064 INF("syscall", S_IRUGO, proc_pid_syscall),
51065 #endif
51066 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51067 @@ -2687,10 +2811,10 @@ static const struct pid_entry tgid_base_stuff[] = {
51068 #ifdef CONFIG_SECURITY
51069 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51070 #endif
51071 -#ifdef CONFIG_KALLSYMS
51072 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51073 INF("wchan", S_IRUGO, proc_pid_wchan),
51074 #endif
51075 -#ifdef CONFIG_STACKTRACE
51076 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51077 ONE("stack", S_IRUGO, proc_pid_stack),
51078 #endif
51079 #ifdef CONFIG_SCHEDSTATS
51080 @@ -2724,6 +2848,9 @@ static const struct pid_entry tgid_base_stuff[] = {
51081 #ifdef CONFIG_HARDWALL
51082 INF("hardwall", S_IRUGO, proc_pid_hardwall),
51083 #endif
51084 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51085 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
51086 +#endif
51087 #ifdef CONFIG_USER_NS
51088 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
51089 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
51090 @@ -2856,7 +2983,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
51091 if (!inode)
51092 goto out;
51093
51094 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51095 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
51096 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51097 + inode->i_gid = grsec_proc_gid;
51098 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
51099 +#else
51100 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
51101 +#endif
51102 inode->i_op = &proc_tgid_base_inode_operations;
51103 inode->i_fop = &proc_tgid_base_operations;
51104 inode->i_flags|=S_IMMUTABLE;
51105 @@ -2898,7 +3032,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
51106 if (!task)
51107 goto out;
51108
51109 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51110 + goto out_put_task;
51111 +
51112 result = proc_pid_instantiate(dir, dentry, task, NULL);
51113 +out_put_task:
51114 put_task_struct(task);
51115 out:
51116 return result;
51117 @@ -2961,6 +3099,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
51118 static int fake_filldir(void *buf, const char *name, int namelen,
51119 loff_t offset, u64 ino, unsigned d_type)
51120 {
51121 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
51122 + __buf->error = -EINVAL;
51123 return 0;
51124 }
51125
51126 @@ -3027,7 +3167,7 @@ static const struct pid_entry tid_base_stuff[] = {
51127 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
51128 #endif
51129 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51130 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51131 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51132 INF("syscall", S_IRUGO, proc_pid_syscall),
51133 #endif
51134 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51135 @@ -3054,10 +3194,10 @@ static const struct pid_entry tid_base_stuff[] = {
51136 #ifdef CONFIG_SECURITY
51137 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51138 #endif
51139 -#ifdef CONFIG_KALLSYMS
51140 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51141 INF("wchan", S_IRUGO, proc_pid_wchan),
51142 #endif
51143 -#ifdef CONFIG_STACKTRACE
51144 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51145 ONE("stack", S_IRUGO, proc_pid_stack),
51146 #endif
51147 #ifdef CONFIG_SCHEDSTATS
51148 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
51149 index 82676e3..5f8518a 100644
51150 --- a/fs/proc/cmdline.c
51151 +++ b/fs/proc/cmdline.c
51152 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
51153
51154 static int __init proc_cmdline_init(void)
51155 {
51156 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51157 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
51158 +#else
51159 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
51160 +#endif
51161 return 0;
51162 }
51163 module_init(proc_cmdline_init);
51164 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
51165 index b143471..bb105e5 100644
51166 --- a/fs/proc/devices.c
51167 +++ b/fs/proc/devices.c
51168 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
51169
51170 static int __init proc_devices_init(void)
51171 {
51172 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51173 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
51174 +#else
51175 proc_create("devices", 0, NULL, &proc_devinfo_operations);
51176 +#endif
51177 return 0;
51178 }
51179 module_init(proc_devices_init);
51180 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
51181 index f28a875..c467953 100644
51182 --- a/fs/proc/fd.c
51183 +++ b/fs/proc/fd.c
51184 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
51185 if (!task)
51186 return -ENOENT;
51187
51188 - files = get_files_struct(task);
51189 + if (!gr_acl_handle_procpidmem(task))
51190 + files = get_files_struct(task);
51191 put_task_struct(task);
51192
51193 if (files) {
51194 @@ -300,11 +301,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
51195 */
51196 int proc_fd_permission(struct inode *inode, int mask)
51197 {
51198 + struct task_struct *task;
51199 int rv = generic_permission(inode, mask);
51200 - if (rv == 0)
51201 - return 0;
51202 +
51203 if (task_pid(current) == proc_pid(inode))
51204 rv = 0;
51205 +
51206 + task = get_proc_task(inode);
51207 + if (task == NULL)
51208 + return rv;
51209 +
51210 + if (gr_acl_handle_procpidmem(task))
51211 + rv = -EACCES;
51212 +
51213 + put_task_struct(task);
51214 +
51215 return rv;
51216 }
51217
51218 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
51219 index 3b22bbd..895b58c 100644
51220 --- a/fs/proc/inode.c
51221 +++ b/fs/proc/inode.c
51222 @@ -21,11 +21,17 @@
51223 #include <linux/seq_file.h>
51224 #include <linux/slab.h>
51225 #include <linux/mount.h>
51226 +#include <linux/grsecurity.h>
51227
51228 #include <asm/uaccess.h>
51229
51230 #include "internal.h"
51231
51232 +#ifdef CONFIG_PROC_SYSCTL
51233 +extern const struct inode_operations proc_sys_inode_operations;
51234 +extern const struct inode_operations proc_sys_dir_operations;
51235 +#endif
51236 +
51237 static void proc_evict_inode(struct inode *inode)
51238 {
51239 struct proc_dir_entry *de;
51240 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
51241 ns_ops = PROC_I(inode)->ns_ops;
51242 if (ns_ops && ns_ops->put)
51243 ns_ops->put(PROC_I(inode)->ns);
51244 +
51245 +#ifdef CONFIG_PROC_SYSCTL
51246 + if (inode->i_op == &proc_sys_inode_operations ||
51247 + inode->i_op == &proc_sys_dir_operations)
51248 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
51249 +#endif
51250 +
51251 }
51252
51253 static struct kmem_cache * proc_inode_cachep;
51254 @@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
51255 if (de->mode) {
51256 inode->i_mode = de->mode;
51257 inode->i_uid = de->uid;
51258 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51259 + inode->i_gid = grsec_proc_gid;
51260 +#else
51261 inode->i_gid = de->gid;
51262 +#endif
51263 }
51264 if (de->size)
51265 inode->i_size = de->size;
51266 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
51267 index 43973b0..a20e704 100644
51268 --- a/fs/proc/internal.h
51269 +++ b/fs/proc/internal.h
51270 @@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51271 struct pid *pid, struct task_struct *task);
51272 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51273 struct pid *pid, struct task_struct *task);
51274 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51275 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
51276 +#endif
51277 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
51278
51279 extern const struct file_operations proc_tid_children_operations;
51280 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
51281 index 86c67ee..cdca321 100644
51282 --- a/fs/proc/kcore.c
51283 +++ b/fs/proc/kcore.c
51284 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51285 * the addresses in the elf_phdr on our list.
51286 */
51287 start = kc_offset_to_vaddr(*fpos - elf_buflen);
51288 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
51289 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
51290 + if (tsz > buflen)
51291 tsz = buflen;
51292 -
51293 +
51294 while (buflen) {
51295 struct kcore_list *m;
51296
51297 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51298 kfree(elf_buf);
51299 } else {
51300 if (kern_addr_valid(start)) {
51301 - unsigned long n;
51302 + char *elf_buf;
51303 + mm_segment_t oldfs;
51304
51305 - n = copy_to_user(buffer, (char *)start, tsz);
51306 - /*
51307 - * We cannot distinguish between fault on source
51308 - * and fault on destination. When this happens
51309 - * we clear too and hope it will trigger the
51310 - * EFAULT again.
51311 - */
51312 - if (n) {
51313 - if (clear_user(buffer + tsz - n,
51314 - n))
51315 + elf_buf = kmalloc(tsz, GFP_KERNEL);
51316 + if (!elf_buf)
51317 + return -ENOMEM;
51318 + oldfs = get_fs();
51319 + set_fs(KERNEL_DS);
51320 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
51321 + set_fs(oldfs);
51322 + if (copy_to_user(buffer, elf_buf, tsz)) {
51323 + kfree(elf_buf);
51324 return -EFAULT;
51325 + }
51326 }
51327 + set_fs(oldfs);
51328 + kfree(elf_buf);
51329 } else {
51330 if (clear_user(buffer, tsz))
51331 return -EFAULT;
51332 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51333
51334 static int open_kcore(struct inode *inode, struct file *filp)
51335 {
51336 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
51337 + return -EPERM;
51338 +#endif
51339 if (!capable(CAP_SYS_RAWIO))
51340 return -EPERM;
51341 if (kcore_need_update)
51342 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
51343 index 80e4645..53e5fcf 100644
51344 --- a/fs/proc/meminfo.c
51345 +++ b/fs/proc/meminfo.c
51346 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
51347 vmi.used >> 10,
51348 vmi.largest_chunk >> 10
51349 #ifdef CONFIG_MEMORY_FAILURE
51350 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
51351 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
51352 #endif
51353 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
51354 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
51355 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
51356 index b1822dd..df622cb 100644
51357 --- a/fs/proc/nommu.c
51358 +++ b/fs/proc/nommu.c
51359 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
51360 if (len < 1)
51361 len = 1;
51362 seq_printf(m, "%*c", len, ' ');
51363 - seq_path(m, &file->f_path, "");
51364 + seq_path(m, &file->f_path, "\n\\");
51365 }
51366
51367 seq_putc(m, '\n');
51368 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
51369 index fe72cd0..cb9b67d 100644
51370 --- a/fs/proc/proc_net.c
51371 +++ b/fs/proc/proc_net.c
51372 @@ -23,6 +23,7 @@
51373 #include <linux/nsproxy.h>
51374 #include <net/net_namespace.h>
51375 #include <linux/seq_file.h>
51376 +#include <linux/grsecurity.h>
51377
51378 #include "internal.h"
51379
51380 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
51381 struct task_struct *task;
51382 struct nsproxy *ns;
51383 struct net *net = NULL;
51384 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51385 + const struct cred *cred = current_cred();
51386 +#endif
51387 +
51388 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51389 + if (cred->fsuid)
51390 + return net;
51391 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51392 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
51393 + return net;
51394 +#endif
51395
51396 rcu_read_lock();
51397 task = pid_task(proc_pid(dir), PIDTYPE_PID);
51398 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
51399 index a781bdf..6665284 100644
51400 --- a/fs/proc/proc_sysctl.c
51401 +++ b/fs/proc/proc_sysctl.c
51402 @@ -12,11 +12,15 @@
51403 #include <linux/module.h>
51404 #include "internal.h"
51405
51406 +extern int gr_handle_chroot_sysctl(const int op);
51407 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
51408 + const int op);
51409 +
51410 static const struct dentry_operations proc_sys_dentry_operations;
51411 static const struct file_operations proc_sys_file_operations;
51412 -static const struct inode_operations proc_sys_inode_operations;
51413 +const struct inode_operations proc_sys_inode_operations;
51414 static const struct file_operations proc_sys_dir_file_operations;
51415 -static const struct inode_operations proc_sys_dir_operations;
51416 +const struct inode_operations proc_sys_dir_operations;
51417
51418 void proc_sys_poll_notify(struct ctl_table_poll *poll)
51419 {
51420 @@ -465,6 +469,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
51421
51422 err = NULL;
51423 d_set_d_op(dentry, &proc_sys_dentry_operations);
51424 +
51425 + gr_handle_proc_create(dentry, inode);
51426 +
51427 d_add(dentry, inode);
51428
51429 out:
51430 @@ -480,18 +487,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51431 struct inode *inode = filp->f_path.dentry->d_inode;
51432 struct ctl_table_header *head = grab_header(inode);
51433 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
51434 + int op = write ? MAY_WRITE : MAY_READ;
51435 ssize_t error;
51436 size_t res;
51437
51438 if (IS_ERR(head))
51439 return PTR_ERR(head);
51440
51441 +
51442 /*
51443 * At this point we know that the sysctl was not unregistered
51444 * and won't be until we finish.
51445 */
51446 error = -EPERM;
51447 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
51448 + if (sysctl_perm(head->root, table, op))
51449 goto out;
51450
51451 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
51452 @@ -499,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51453 if (!table->proc_handler)
51454 goto out;
51455
51456 +#ifdef CONFIG_GRKERNSEC
51457 + error = -EPERM;
51458 + if (gr_handle_chroot_sysctl(op))
51459 + goto out;
51460 + dget(filp->f_path.dentry);
51461 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
51462 + dput(filp->f_path.dentry);
51463 + goto out;
51464 + }
51465 + dput(filp->f_path.dentry);
51466 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
51467 + goto out;
51468 + if (write && !capable(CAP_SYS_ADMIN))
51469 + goto out;
51470 +#endif
51471 +
51472 /* careful: calling conventions are nasty here */
51473 res = count;
51474 error = table->proc_handler(table, write, buf, &res, ppos);
51475 @@ -596,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
51476 return -ENOMEM;
51477 } else {
51478 d_set_d_op(child, &proc_sys_dentry_operations);
51479 +
51480 + gr_handle_proc_create(child, inode);
51481 +
51482 d_add(child, inode);
51483 }
51484 } else {
51485 @@ -639,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
51486 if ((*pos)++ < file->f_pos)
51487 return 0;
51488
51489 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
51490 + return 0;
51491 +
51492 if (unlikely(S_ISLNK(table->mode)))
51493 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
51494 else
51495 @@ -756,6 +787,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
51496 if (IS_ERR(head))
51497 return PTR_ERR(head);
51498
51499 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
51500 + return -ENOENT;
51501 +
51502 generic_fillattr(inode, stat);
51503 if (table)
51504 stat->mode = (stat->mode & S_IFMT) | table->mode;
51505 @@ -778,13 +812,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
51506 .llseek = generic_file_llseek,
51507 };
51508
51509 -static const struct inode_operations proc_sys_inode_operations = {
51510 +const struct inode_operations proc_sys_inode_operations = {
51511 .permission = proc_sys_permission,
51512 .setattr = proc_sys_setattr,
51513 .getattr = proc_sys_getattr,
51514 };
51515
51516 -static const struct inode_operations proc_sys_dir_operations = {
51517 +const struct inode_operations proc_sys_dir_operations = {
51518 .lookup = proc_sys_lookup,
51519 .permission = proc_sys_permission,
51520 .setattr = proc_sys_setattr,
51521 diff --git a/fs/proc/root.c b/fs/proc/root.c
51522 index 9889a92..2613b48 100644
51523 --- a/fs/proc/root.c
51524 +++ b/fs/proc/root.c
51525 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
51526 #ifdef CONFIG_PROC_DEVICETREE
51527 proc_device_tree_init();
51528 #endif
51529 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51530 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51531 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
51532 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51533 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
51534 +#endif
51535 +#else
51536 proc_mkdir("bus", NULL);
51537 +#endif
51538 proc_sys_init();
51539 }
51540
51541 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
51542 index 90c63f9..e662cfc 100644
51543 --- a/fs/proc/task_mmu.c
51544 +++ b/fs/proc/task_mmu.c
51545 @@ -11,12 +11,19 @@
51546 #include <linux/rmap.h>
51547 #include <linux/swap.h>
51548 #include <linux/swapops.h>
51549 +#include <linux/grsecurity.h>
51550
51551 #include <asm/elf.h>
51552 #include <asm/uaccess.h>
51553 #include <asm/tlbflush.h>
51554 #include "internal.h"
51555
51556 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51557 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51558 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
51559 + _mm->pax_flags & MF_PAX_SEGMEXEC))
51560 +#endif
51561 +
51562 void task_mem(struct seq_file *m, struct mm_struct *mm)
51563 {
51564 unsigned long data, text, lib, swap;
51565 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51566 "VmExe:\t%8lu kB\n"
51567 "VmLib:\t%8lu kB\n"
51568 "VmPTE:\t%8lu kB\n"
51569 - "VmSwap:\t%8lu kB\n",
51570 - hiwater_vm << (PAGE_SHIFT-10),
51571 + "VmSwap:\t%8lu kB\n"
51572 +
51573 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51574 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
51575 +#endif
51576 +
51577 + ,hiwater_vm << (PAGE_SHIFT-10),
51578 total_vm << (PAGE_SHIFT-10),
51579 mm->locked_vm << (PAGE_SHIFT-10),
51580 mm->pinned_vm << (PAGE_SHIFT-10),
51581 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51582 data << (PAGE_SHIFT-10),
51583 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
51584 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
51585 - swap << (PAGE_SHIFT-10));
51586 + swap << (PAGE_SHIFT-10)
51587 +
51588 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51589 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51590 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
51591 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
51592 +#else
51593 + , mm->context.user_cs_base
51594 + , mm->context.user_cs_limit
51595 +#endif
51596 +#endif
51597 +
51598 + );
51599 }
51600
51601 unsigned long task_vsize(struct mm_struct *mm)
51602 @@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51603 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
51604 }
51605
51606 - /* We don't show the stack guard page in /proc/maps */
51607 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51608 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
51609 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
51610 +#else
51611 start = vma->vm_start;
51612 - if (stack_guard_page_start(vma, start))
51613 - start += PAGE_SIZE;
51614 end = vma->vm_end;
51615 - if (stack_guard_page_end(vma, end))
51616 - end -= PAGE_SIZE;
51617 +#endif
51618
51619 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
51620 start,
51621 @@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51622 flags & VM_WRITE ? 'w' : '-',
51623 flags & VM_EXEC ? 'x' : '-',
51624 flags & VM_MAYSHARE ? 's' : 'p',
51625 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51626 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
51627 +#else
51628 pgoff,
51629 +#endif
51630 MAJOR(dev), MINOR(dev), ino, &len);
51631
51632 /*
51633 @@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51634 */
51635 if (file) {
51636 pad_len_spaces(m, len);
51637 - seq_path(m, &file->f_path, "\n");
51638 + seq_path(m, &file->f_path, "\n\\");
51639 goto done;
51640 }
51641
51642 @@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51643 * Thread stack in /proc/PID/task/TID/maps or
51644 * the main process stack.
51645 */
51646 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
51647 - vma->vm_end >= mm->start_stack)) {
51648 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
51649 + (vma->vm_start <= mm->start_stack &&
51650 + vma->vm_end >= mm->start_stack)) {
51651 name = "[stack]";
51652 } else {
51653 /* Thread stack in /proc/PID/maps */
51654 @@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
51655 struct proc_maps_private *priv = m->private;
51656 struct task_struct *task = priv->task;
51657
51658 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51659 + if (current->exec_id != m->exec_id) {
51660 + gr_log_badprocpid("maps");
51661 + return 0;
51662 + }
51663 +#endif
51664 +
51665 show_map_vma(m, vma, is_pid);
51666
51667 if (m->count < m->size) /* vma is copied successfully */
51668 @@ -538,12 +574,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51669 .private = &mss,
51670 };
51671
51672 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51673 + if (current->exec_id != m->exec_id) {
51674 + gr_log_badprocpid("smaps");
51675 + return 0;
51676 + }
51677 +#endif
51678 memset(&mss, 0, sizeof mss);
51679 - mss.vma = vma;
51680 - /* mmap_sem is held in m_start */
51681 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51682 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51683 -
51684 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51685 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
51686 +#endif
51687 + mss.vma = vma;
51688 + /* mmap_sem is held in m_start */
51689 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51690 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51691 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51692 + }
51693 +#endif
51694 show_map_vma(m, vma, is_pid);
51695
51696 seq_printf(m,
51697 @@ -561,7 +608,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51698 "KernelPageSize: %8lu kB\n"
51699 "MMUPageSize: %8lu kB\n"
51700 "Locked: %8lu kB\n",
51701 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51702 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
51703 +#else
51704 (vma->vm_end - vma->vm_start) >> 10,
51705 +#endif
51706 mss.resident >> 10,
51707 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
51708 mss.shared_clean >> 10,
51709 @@ -1211,6 +1262,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51710 int n;
51711 char buffer[50];
51712
51713 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51714 + if (current->exec_id != m->exec_id) {
51715 + gr_log_badprocpid("numa_maps");
51716 + return 0;
51717 + }
51718 +#endif
51719 +
51720 if (!mm)
51721 return 0;
51722
51723 @@ -1228,11 +1286,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51724 mpol_to_str(buffer, sizeof(buffer), pol, 0);
51725 mpol_cond_put(pol);
51726
51727 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51728 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
51729 +#else
51730 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
51731 +#endif
51732
51733 if (file) {
51734 seq_printf(m, " file=");
51735 - seq_path(m, &file->f_path, "\n\t= ");
51736 + seq_path(m, &file->f_path, "\n\t\\= ");
51737 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
51738 seq_printf(m, " heap");
51739 } else {
51740 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
51741 index 1ccfa53..0848f95 100644
51742 --- a/fs/proc/task_nommu.c
51743 +++ b/fs/proc/task_nommu.c
51744 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51745 else
51746 bytes += kobjsize(mm);
51747
51748 - if (current->fs && current->fs->users > 1)
51749 + if (current->fs && atomic_read(&current->fs->users) > 1)
51750 sbytes += kobjsize(current->fs);
51751 else
51752 bytes += kobjsize(current->fs);
51753 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
51754
51755 if (file) {
51756 pad_len_spaces(m, len);
51757 - seq_path(m, &file->f_path, "");
51758 + seq_path(m, &file->f_path, "\n\\");
51759 } else if (mm) {
51760 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
51761
51762 diff --git a/fs/pstore/ftrace.c b/fs/pstore/ftrace.c
51763 index 2d57e1a..43b1280 100644
51764 --- a/fs/pstore/ftrace.c
51765 +++ b/fs/pstore/ftrace.c
51766 @@ -28,7 +28,9 @@
51767 #include "internal.h"
51768
51769 static void notrace pstore_ftrace_call(unsigned long ip,
51770 - unsigned long parent_ip)
51771 + unsigned long parent_ip,
51772 + struct ftrace_ops *op,
51773 + struct pt_regs *regs)
51774 {
51775 unsigned long flags;
51776 struct pstore_ftrace_record rec = {};
51777 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
51778 index 16e8abb..2dcf914 100644
51779 --- a/fs/quota/netlink.c
51780 +++ b/fs/quota/netlink.c
51781 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
51782 void quota_send_warning(struct kqid qid, dev_t dev,
51783 const char warntype)
51784 {
51785 - static atomic_t seq;
51786 + static atomic_unchecked_t seq;
51787 struct sk_buff *skb;
51788 void *msg_head;
51789 int ret;
51790 @@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
51791 "VFS: Not enough memory to send quota warning.\n");
51792 return;
51793 }
51794 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
51795 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
51796 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
51797 if (!msg_head) {
51798 printk(KERN_ERR
51799 diff --git a/fs/read_write.c b/fs/read_write.c
51800 index d065348..8e2b43d 100644
51801 --- a/fs/read_write.c
51802 +++ b/fs/read_write.c
51803 @@ -935,6 +935,8 @@ ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, size_t count,
51804 if (retval > 0) {
51805 add_rchar(current, retval);
51806 add_wchar(current, retval);
51807 + fsnotify_access(in.file);
51808 + fsnotify_modify(out.file);
51809 }
51810
51811 inc_syscr(current);
51812 diff --git a/fs/readdir.c b/fs/readdir.c
51813 index 5e69ef5..e5d9099 100644
51814 --- a/fs/readdir.c
51815 +++ b/fs/readdir.c
51816 @@ -17,6 +17,7 @@
51817 #include <linux/security.h>
51818 #include <linux/syscalls.h>
51819 #include <linux/unistd.h>
51820 +#include <linux/namei.h>
51821
51822 #include <asm/uaccess.h>
51823
51824 @@ -67,6 +68,7 @@ struct old_linux_dirent {
51825
51826 struct readdir_callback {
51827 struct old_linux_dirent __user * dirent;
51828 + struct file * file;
51829 int result;
51830 };
51831
51832 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
51833 buf->result = -EOVERFLOW;
51834 return -EOVERFLOW;
51835 }
51836 +
51837 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51838 + return 0;
51839 +
51840 buf->result++;
51841 dirent = buf->dirent;
51842 if (!access_ok(VERIFY_WRITE, dirent,
51843 @@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
51844
51845 buf.result = 0;
51846 buf.dirent = dirent;
51847 + buf.file = f.file;
51848
51849 error = vfs_readdir(f.file, fillonedir, &buf);
51850 if (buf.result)
51851 @@ -139,6 +146,7 @@ struct linux_dirent {
51852 struct getdents_callback {
51853 struct linux_dirent __user * current_dir;
51854 struct linux_dirent __user * previous;
51855 + struct file * file;
51856 int count;
51857 int error;
51858 };
51859 @@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
51860 buf->error = -EOVERFLOW;
51861 return -EOVERFLOW;
51862 }
51863 +
51864 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51865 + return 0;
51866 +
51867 dirent = buf->previous;
51868 if (dirent) {
51869 if (__put_user(offset, &dirent->d_off))
51870 @@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51871 buf.previous = NULL;
51872 buf.count = count;
51873 buf.error = 0;
51874 + buf.file = f.file;
51875
51876 error = vfs_readdir(f.file, filldir, &buf);
51877 if (error >= 0)
51878 @@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51879 struct getdents_callback64 {
51880 struct linux_dirent64 __user * current_dir;
51881 struct linux_dirent64 __user * previous;
51882 + struct file *file;
51883 int count;
51884 int error;
51885 };
51886 @@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
51887 buf->error = -EINVAL; /* only used if we fail.. */
51888 if (reclen > buf->count)
51889 return -EINVAL;
51890 +
51891 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51892 + return 0;
51893 +
51894 dirent = buf->previous;
51895 if (dirent) {
51896 if (__put_user(offset, &dirent->d_off))
51897 @@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
51898
51899 buf.current_dir = dirent;
51900 buf.previous = NULL;
51901 + buf.file = f.file;
51902 buf.count = count;
51903 buf.error = 0;
51904
51905 @@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
51906 error = buf.error;
51907 lastdirent = buf.previous;
51908 if (lastdirent) {
51909 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
51910 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
51911 if (__put_user(d_off, &lastdirent->d_off))
51912 error = -EFAULT;
51913 else
51914 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
51915 index 2b7882b..1c5ef48 100644
51916 --- a/fs/reiserfs/do_balan.c
51917 +++ b/fs/reiserfs/do_balan.c
51918 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
51919 return;
51920 }
51921
51922 - atomic_inc(&(fs_generation(tb->tb_sb)));
51923 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
51924 do_balance_starts(tb);
51925
51926 /* balance leaf returns 0 except if combining L R and S into
51927 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
51928 index e60e870..f40ac16 100644
51929 --- a/fs/reiserfs/procfs.c
51930 +++ b/fs/reiserfs/procfs.c
51931 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
51932 "SMALL_TAILS " : "NO_TAILS ",
51933 replay_only(sb) ? "REPLAY_ONLY " : "",
51934 convert_reiserfs(sb) ? "CONV " : "",
51935 - atomic_read(&r->s_generation_counter),
51936 + atomic_read_unchecked(&r->s_generation_counter),
51937 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
51938 SF(s_do_balance), SF(s_unneeded_left_neighbor),
51939 SF(s_good_search_by_key_reada), SF(s_bmaps),
51940 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
51941 index 33215f5..c5d427a 100644
51942 --- a/fs/reiserfs/reiserfs.h
51943 +++ b/fs/reiserfs/reiserfs.h
51944 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
51945 /* Comment? -Hans */
51946 wait_queue_head_t s_wait;
51947 /* To be obsoleted soon by per buffer seals.. -Hans */
51948 - atomic_t s_generation_counter; // increased by one every time the
51949 + atomic_unchecked_t s_generation_counter; // increased by one every time the
51950 // tree gets re-balanced
51951 unsigned long s_properties; /* File system properties. Currently holds
51952 on-disk FS format */
51953 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
51954 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
51955
51956 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
51957 -#define get_generation(s) atomic_read (&fs_generation(s))
51958 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
51959 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
51960 #define __fs_changed(gen,s) (gen != get_generation (s))
51961 #define fs_changed(gen,s) \
51962 diff --git a/fs/select.c b/fs/select.c
51963 index 2ef72d9..f213b17 100644
51964 --- a/fs/select.c
51965 +++ b/fs/select.c
51966 @@ -20,6 +20,7 @@
51967 #include <linux/export.h>
51968 #include <linux/slab.h>
51969 #include <linux/poll.h>
51970 +#include <linux/security.h>
51971 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
51972 #include <linux/file.h>
51973 #include <linux/fdtable.h>
51974 @@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
51975 struct poll_list *walk = head;
51976 unsigned long todo = nfds;
51977
51978 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
51979 if (nfds > rlimit(RLIMIT_NOFILE))
51980 return -EINVAL;
51981
51982 diff --git a/fs/seq_file.c b/fs/seq_file.c
51983 index 99dffab..e4fcb71 100644
51984 --- a/fs/seq_file.c
51985 +++ b/fs/seq_file.c
51986 @@ -10,6 +10,7 @@
51987 #include <linux/seq_file.h>
51988 #include <linux/slab.h>
51989 #include <linux/cred.h>
51990 +#include <linux/sched.h>
51991
51992 #include <asm/uaccess.h>
51993 #include <asm/page.h>
51994 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
51995 #ifdef CONFIG_USER_NS
51996 p->user_ns = file->f_cred->user_ns;
51997 #endif
51998 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51999 + p->exec_id = current->exec_id;
52000 +#endif
52001
52002 /*
52003 * Wrappers around seq_open(e.g. swaps_open) need to be
52004 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52005 return 0;
52006 }
52007 if (!m->buf) {
52008 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52009 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52010 if (!m->buf)
52011 return -ENOMEM;
52012 }
52013 @@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52014 Eoverflow:
52015 m->op->stop(m, p);
52016 kfree(m->buf);
52017 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52018 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52019 return !m->buf ? -ENOMEM : -EAGAIN;
52020 }
52021
52022 @@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52023
52024 /* grab buffer if we didn't have one */
52025 if (!m->buf) {
52026 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52027 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52028 if (!m->buf)
52029 goto Enomem;
52030 }
52031 @@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52032 goto Fill;
52033 m->op->stop(m, p);
52034 kfree(m->buf);
52035 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52036 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52037 if (!m->buf)
52038 goto Enomem;
52039 m->count = 0;
52040 @@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
52041 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
52042 void *data)
52043 {
52044 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
52045 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
52046 int res = -ENOMEM;
52047
52048 if (op) {
52049 diff --git a/fs/splice.c b/fs/splice.c
52050 index 48c7bd1..d0740e4 100644
52051 --- a/fs/splice.c
52052 +++ b/fs/splice.c
52053 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52054 pipe_lock(pipe);
52055
52056 for (;;) {
52057 - if (!pipe->readers) {
52058 + if (!atomic_read(&pipe->readers)) {
52059 send_sig(SIGPIPE, current, 0);
52060 if (!ret)
52061 ret = -EPIPE;
52062 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52063 do_wakeup = 0;
52064 }
52065
52066 - pipe->waiting_writers++;
52067 + atomic_inc(&pipe->waiting_writers);
52068 pipe_wait(pipe);
52069 - pipe->waiting_writers--;
52070 + atomic_dec(&pipe->waiting_writers);
52071 }
52072
52073 pipe_unlock(pipe);
52074 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
52075 old_fs = get_fs();
52076 set_fs(get_ds());
52077 /* The cast to a user pointer is valid due to the set_fs() */
52078 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
52079 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
52080 set_fs(old_fs);
52081
52082 return res;
52083 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
52084 old_fs = get_fs();
52085 set_fs(get_ds());
52086 /* The cast to a user pointer is valid due to the set_fs() */
52087 - res = vfs_write(file, (const char __user *)buf, count, &pos);
52088 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
52089 set_fs(old_fs);
52090
52091 return res;
52092 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
52093 goto err;
52094
52095 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
52096 - vec[i].iov_base = (void __user *) page_address(page);
52097 + vec[i].iov_base = (void __force_user *) page_address(page);
52098 vec[i].iov_len = this_len;
52099 spd.pages[i] = page;
52100 spd.nr_pages++;
52101 @@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
52102 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
52103 {
52104 while (!pipe->nrbufs) {
52105 - if (!pipe->writers)
52106 + if (!atomic_read(&pipe->writers))
52107 return 0;
52108
52109 - if (!pipe->waiting_writers && sd->num_spliced)
52110 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
52111 return 0;
52112
52113 if (sd->flags & SPLICE_F_NONBLOCK)
52114 @@ -1192,7 +1192,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
52115 * out of the pipe right after the splice_to_pipe(). So set
52116 * PIPE_READERS appropriately.
52117 */
52118 - pipe->readers = 1;
52119 + atomic_set(&pipe->readers, 1);
52120
52121 current->splice_pipe = pipe;
52122 }
52123 @@ -1741,9 +1741,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52124 ret = -ERESTARTSYS;
52125 break;
52126 }
52127 - if (!pipe->writers)
52128 + if (!atomic_read(&pipe->writers))
52129 break;
52130 - if (!pipe->waiting_writers) {
52131 + if (!atomic_read(&pipe->waiting_writers)) {
52132 if (flags & SPLICE_F_NONBLOCK) {
52133 ret = -EAGAIN;
52134 break;
52135 @@ -1775,7 +1775,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52136 pipe_lock(pipe);
52137
52138 while (pipe->nrbufs >= pipe->buffers) {
52139 - if (!pipe->readers) {
52140 + if (!atomic_read(&pipe->readers)) {
52141 send_sig(SIGPIPE, current, 0);
52142 ret = -EPIPE;
52143 break;
52144 @@ -1788,9 +1788,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52145 ret = -ERESTARTSYS;
52146 break;
52147 }
52148 - pipe->waiting_writers++;
52149 + atomic_inc(&pipe->waiting_writers);
52150 pipe_wait(pipe);
52151 - pipe->waiting_writers--;
52152 + atomic_dec(&pipe->waiting_writers);
52153 }
52154
52155 pipe_unlock(pipe);
52156 @@ -1826,14 +1826,14 @@ retry:
52157 pipe_double_lock(ipipe, opipe);
52158
52159 do {
52160 - if (!opipe->readers) {
52161 + if (!atomic_read(&opipe->readers)) {
52162 send_sig(SIGPIPE, current, 0);
52163 if (!ret)
52164 ret = -EPIPE;
52165 break;
52166 }
52167
52168 - if (!ipipe->nrbufs && !ipipe->writers)
52169 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
52170 break;
52171
52172 /*
52173 @@ -1930,7 +1930,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
52174 pipe_double_lock(ipipe, opipe);
52175
52176 do {
52177 - if (!opipe->readers) {
52178 + if (!atomic_read(&opipe->readers)) {
52179 send_sig(SIGPIPE, current, 0);
52180 if (!ret)
52181 ret = -EPIPE;
52182 @@ -1975,7 +1975,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
52183 * return EAGAIN if we have the potential of some data in the
52184 * future, otherwise just return 0
52185 */
52186 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
52187 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
52188 ret = -EAGAIN;
52189
52190 pipe_unlock(ipipe);
52191 diff --git a/fs/stat.c b/fs/stat.c
52192 index eae4946..6198f55 100644
52193 --- a/fs/stat.c
52194 +++ b/fs/stat.c
52195 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
52196 stat->gid = inode->i_gid;
52197 stat->rdev = inode->i_rdev;
52198 stat->size = i_size_read(inode);
52199 - stat->atime = inode->i_atime;
52200 - stat->mtime = inode->i_mtime;
52201 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
52202 + stat->atime = inode->i_ctime;
52203 + stat->mtime = inode->i_ctime;
52204 + } else {
52205 + stat->atime = inode->i_atime;
52206 + stat->mtime = inode->i_mtime;
52207 + }
52208 stat->ctime = inode->i_ctime;
52209 stat->blksize = (1 << inode->i_blkbits);
52210 stat->blocks = inode->i_blocks;
52211 @@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
52212 if (retval)
52213 return retval;
52214
52215 - if (inode->i_op->getattr)
52216 - return inode->i_op->getattr(mnt, dentry, stat);
52217 + if (inode->i_op->getattr) {
52218 + retval = inode->i_op->getattr(mnt, dentry, stat);
52219 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
52220 + stat->atime = stat->ctime;
52221 + stat->mtime = stat->ctime;
52222 + }
52223 + return retval;
52224 + }
52225
52226 generic_fillattr(inode, stat);
52227 return 0;
52228 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
52229 index 2fbdff6..5530a61 100644
52230 --- a/fs/sysfs/dir.c
52231 +++ b/fs/sysfs/dir.c
52232 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
52233 struct sysfs_dirent *sd;
52234 int rc;
52235
52236 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
52237 + const char *parent_name = parent_sd->s_name;
52238 +
52239 + mode = S_IFDIR | S_IRWXU;
52240 +
52241 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
52242 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
52243 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
52244 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
52245 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
52246 +#endif
52247 +
52248 /* allocate */
52249 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
52250 if (!sd)
52251 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
52252 index 00012e3..8392349 100644
52253 --- a/fs/sysfs/file.c
52254 +++ b/fs/sysfs/file.c
52255 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
52256
52257 struct sysfs_open_dirent {
52258 atomic_t refcnt;
52259 - atomic_t event;
52260 + atomic_unchecked_t event;
52261 wait_queue_head_t poll;
52262 struct list_head buffers; /* goes through sysfs_buffer.list */
52263 };
52264 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
52265 if (!sysfs_get_active(attr_sd))
52266 return -ENODEV;
52267
52268 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
52269 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
52270 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
52271
52272 sysfs_put_active(attr_sd);
52273 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
52274 return -ENOMEM;
52275
52276 atomic_set(&new_od->refcnt, 0);
52277 - atomic_set(&new_od->event, 1);
52278 + atomic_set_unchecked(&new_od->event, 1);
52279 init_waitqueue_head(&new_od->poll);
52280 INIT_LIST_HEAD(&new_od->buffers);
52281 goto retry;
52282 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
52283
52284 sysfs_put_active(attr_sd);
52285
52286 - if (buffer->event != atomic_read(&od->event))
52287 + if (buffer->event != atomic_read_unchecked(&od->event))
52288 goto trigger;
52289
52290 return DEFAULT_POLLMASK;
52291 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
52292
52293 od = sd->s_attr.open;
52294 if (od) {
52295 - atomic_inc(&od->event);
52296 + atomic_inc_unchecked(&od->event);
52297 wake_up_interruptible(&od->poll);
52298 }
52299
52300 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
52301 index 3c9eb56..9dea5be 100644
52302 --- a/fs/sysfs/symlink.c
52303 +++ b/fs/sysfs/symlink.c
52304 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
52305
52306 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
52307 {
52308 - char *page = nd_get_link(nd);
52309 + const char *page = nd_get_link(nd);
52310 if (!IS_ERR(page))
52311 free_page((unsigned long)page);
52312 }
52313 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
52314 index c175b4d..8f36a16 100644
52315 --- a/fs/udf/misc.c
52316 +++ b/fs/udf/misc.c
52317 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
52318
52319 u8 udf_tag_checksum(const struct tag *t)
52320 {
52321 - u8 *data = (u8 *)t;
52322 + const u8 *data = (const u8 *)t;
52323 u8 checksum = 0;
52324 int i;
52325 for (i = 0; i < sizeof(struct tag); ++i)
52326 diff --git a/fs/utimes.c b/fs/utimes.c
52327 index bb0696a..552054b 100644
52328 --- a/fs/utimes.c
52329 +++ b/fs/utimes.c
52330 @@ -1,6 +1,7 @@
52331 #include <linux/compiler.h>
52332 #include <linux/file.h>
52333 #include <linux/fs.h>
52334 +#include <linux/security.h>
52335 #include <linux/linkage.h>
52336 #include <linux/mount.h>
52337 #include <linux/namei.h>
52338 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
52339 goto mnt_drop_write_and_out;
52340 }
52341 }
52342 +
52343 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
52344 + error = -EACCES;
52345 + goto mnt_drop_write_and_out;
52346 + }
52347 +
52348 mutex_lock(&inode->i_mutex);
52349 error = notify_change(path->dentry, &newattrs);
52350 mutex_unlock(&inode->i_mutex);
52351 diff --git a/fs/xattr.c b/fs/xattr.c
52352 index e21c119..21dfc7c 100644
52353 --- a/fs/xattr.c
52354 +++ b/fs/xattr.c
52355 @@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
52356 * Extended attribute SET operations
52357 */
52358 static long
52359 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
52360 +setxattr(struct path *path, const char __user *name, const void __user *value,
52361 size_t size, int flags)
52362 {
52363 int error;
52364 @@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
52365 posix_acl_fix_xattr_from_user(kvalue, size);
52366 }
52367
52368 - error = vfs_setxattr(d, kname, kvalue, size, flags);
52369 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
52370 + error = -EACCES;
52371 + goto out;
52372 + }
52373 +
52374 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
52375 out:
52376 if (vvalue)
52377 vfree(vvalue);
52378 @@ -376,7 +381,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
52379 return error;
52380 error = mnt_want_write(path.mnt);
52381 if (!error) {
52382 - error = setxattr(path.dentry, name, value, size, flags);
52383 + error = setxattr(&path, name, value, size, flags);
52384 mnt_drop_write(path.mnt);
52385 }
52386 path_put(&path);
52387 @@ -395,7 +400,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
52388 return error;
52389 error = mnt_want_write(path.mnt);
52390 if (!error) {
52391 - error = setxattr(path.dentry, name, value, size, flags);
52392 + error = setxattr(&path, name, value, size, flags);
52393 mnt_drop_write(path.mnt);
52394 }
52395 path_put(&path);
52396 @@ -406,16 +411,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
52397 const void __user *,value, size_t, size, int, flags)
52398 {
52399 struct fd f = fdget(fd);
52400 - struct dentry *dentry;
52401 int error = -EBADF;
52402
52403 if (!f.file)
52404 return error;
52405 - dentry = f.file->f_path.dentry;
52406 - audit_inode(NULL, dentry, 0);
52407 + audit_inode(NULL, f.file->f_path.dentry, 0);
52408 error = mnt_want_write_file(f.file);
52409 if (!error) {
52410 - error = setxattr(dentry, name, value, size, flags);
52411 + error = setxattr(&f.file->f_path, name, value, size, flags);
52412 mnt_drop_write_file(f.file);
52413 }
52414 fdput(f);
52415 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
52416 index 9fbea87..6b19972 100644
52417 --- a/fs/xattr_acl.c
52418 +++ b/fs/xattr_acl.c
52419 @@ -76,8 +76,8 @@ struct posix_acl *
52420 posix_acl_from_xattr(struct user_namespace *user_ns,
52421 const void *value, size_t size)
52422 {
52423 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
52424 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
52425 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
52426 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
52427 int count;
52428 struct posix_acl *acl;
52429 struct posix_acl_entry *acl_e;
52430 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
52431 index 83d0cf3..2ef526b 100644
52432 --- a/fs/xfs/xfs_bmap.c
52433 +++ b/fs/xfs/xfs_bmap.c
52434 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
52435 int nmap,
52436 int ret_nmap);
52437 #else
52438 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
52439 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
52440 #endif /* DEBUG */
52441
52442 STATIC int
52443 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
52444 index 1b9fc3e..e1bdde0 100644
52445 --- a/fs/xfs/xfs_dir2_sf.c
52446 +++ b/fs/xfs/xfs_dir2_sf.c
52447 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
52448 }
52449
52450 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
52451 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52452 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
52453 + char name[sfep->namelen];
52454 + memcpy(name, sfep->name, sfep->namelen);
52455 + if (filldir(dirent, name, sfep->namelen,
52456 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
52457 + *offset = off & 0x7fffffff;
52458 + return 0;
52459 + }
52460 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52461 off & 0x7fffffff, ino, DT_UNKNOWN)) {
52462 *offset = off & 0x7fffffff;
52463 return 0;
52464 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
52465 index c1df3c6..f987db6 100644
52466 --- a/fs/xfs/xfs_ioctl.c
52467 +++ b/fs/xfs/xfs_ioctl.c
52468 @@ -126,7 +126,7 @@ xfs_find_handle(
52469 }
52470
52471 error = -EFAULT;
52472 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
52473 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
52474 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
52475 goto out_put;
52476
52477 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
52478 index 4e00cf0..3374374 100644
52479 --- a/fs/xfs/xfs_iops.c
52480 +++ b/fs/xfs/xfs_iops.c
52481 @@ -394,7 +394,7 @@ xfs_vn_put_link(
52482 struct nameidata *nd,
52483 void *p)
52484 {
52485 - char *s = nd_get_link(nd);
52486 + const char *s = nd_get_link(nd);
52487
52488 if (!IS_ERR(s))
52489 kfree(s);
52490 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
52491 new file mode 100644
52492 index 0000000..92247e4
52493 --- /dev/null
52494 +++ b/grsecurity/Kconfig
52495 @@ -0,0 +1,1021 @@
52496 +#
52497 +# grecurity configuration
52498 +#
52499 +menu "Memory Protections"
52500 +depends on GRKERNSEC
52501 +
52502 +config GRKERNSEC_KMEM
52503 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
52504 + default y if GRKERNSEC_CONFIG_AUTO
52505 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
52506 + help
52507 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
52508 + be written to or read from to modify or leak the contents of the running
52509 + kernel. /dev/port will also not be allowed to be opened and support
52510 + for /dev/cpu/*/msr will be removed. If you have module
52511 + support disabled, enabling this will close up five ways that are
52512 + currently used to insert malicious code into the running kernel.
52513 +
52514 + Even with all these features enabled, we still highly recommend that
52515 + you use the RBAC system, as it is still possible for an attacker to
52516 + modify the running kernel through privileged I/O granted by ioperm/iopl.
52517 +
52518 + If you are not using XFree86, you may be able to stop this additional
52519 + case by enabling the 'Disable privileged I/O' option. Though nothing
52520 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
52521 + but only to video memory, which is the only writing we allow in this
52522 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
52523 + not be allowed to mprotect it with PROT_WRITE later.
52524 + Enabling this feature will prevent the "cpupower" and "powertop" tools
52525 + from working.
52526 +
52527 + It is highly recommended that you say Y here if you meet all the
52528 + conditions above.
52529 +
52530 +config GRKERNSEC_VM86
52531 + bool "Restrict VM86 mode"
52532 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52533 + depends on X86_32
52534 +
52535 + help
52536 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
52537 + make use of a special execution mode on 32bit x86 processors called
52538 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
52539 + video cards and will still work with this option enabled. The purpose
52540 + of the option is to prevent exploitation of emulation errors in
52541 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
52542 + Nearly all users should be able to enable this option.
52543 +
52544 +config GRKERNSEC_IO
52545 + bool "Disable privileged I/O"
52546 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52547 + depends on X86
52548 + select RTC_CLASS
52549 + select RTC_INTF_DEV
52550 + select RTC_DRV_CMOS
52551 +
52552 + help
52553 + If you say Y here, all ioperm and iopl calls will return an error.
52554 + Ioperm and iopl can be used to modify the running kernel.
52555 + Unfortunately, some programs need this access to operate properly,
52556 + the most notable of which are XFree86 and hwclock. hwclock can be
52557 + remedied by having RTC support in the kernel, so real-time
52558 + clock support is enabled if this option is enabled, to ensure
52559 + that hwclock operates correctly. XFree86 still will not
52560 + operate correctly with this option enabled, so DO NOT CHOOSE Y
52561 + IF YOU USE XFree86. If you use XFree86 and you still want to
52562 + protect your kernel against modification, use the RBAC system.
52563 +
52564 +config GRKERNSEC_JIT_HARDEN
52565 + bool "Harden BPF JIT against spray attacks"
52566 + default y if GRKERNSEC_CONFIG_AUTO
52567 + depends on BPF_JIT
52568 + help
52569 + If you say Y here, the native code generated by the kernel's Berkeley
52570 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
52571 + attacks that attempt to fit attacker-beneficial instructions in
52572 + 32bit immediate fields of JIT-generated native instructions. The
52573 + attacker will generally aim to cause an unintended instruction sequence
52574 + of JIT-generated native code to execute by jumping into the middle of
52575 + a generated instruction. This feature effectively randomizes the 32bit
52576 + immediate constants present in the generated code to thwart such attacks.
52577 +
52578 + If you're using KERNEXEC, it's recommended that you enable this option
52579 + to supplement the hardening of the kernel.
52580 +
52581 +config GRKERNSEC_RAND_THREADSTACK
52582 + bool "Insert random gaps between thread stacks"
52583 + default y if GRKERNSEC_CONFIG_AUTO
52584 + depends on PAX_RANDMMAP && !PPC
52585 + help
52586 + If you say Y here, a random-sized gap will be enforced between allocated
52587 + thread stacks. Glibc's NPTL and other threading libraries that
52588 + pass MAP_STACK to the kernel for thread stack allocation are supported.
52589 + The implementation currently provides 8 bits of entropy for the gap.
52590 +
52591 + Many distributions do not compile threaded remote services with the
52592 + -fstack-check argument to GCC, causing the variable-sized stack-based
52593 + allocator, alloca(), to not probe the stack on allocation. This
52594 + permits an unbounded alloca() to skip over any guard page and potentially
52595 + modify another thread's stack reliably. An enforced random gap
52596 + reduces the reliability of such an attack and increases the chance
52597 + that such a read/write to another thread's stack instead lands in
52598 + an unmapped area, causing a crash and triggering grsecurity's
52599 + anti-bruteforcing logic.
52600 +
52601 +config GRKERNSEC_PROC_MEMMAP
52602 + bool "Harden ASLR against information leaks and entropy reduction"
52603 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
52604 + depends on PAX_NOEXEC || PAX_ASLR
52605 + help
52606 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
52607 + give no information about the addresses of its mappings if
52608 + PaX features that rely on random addresses are enabled on the task.
52609 + In addition to sanitizing this information and disabling other
52610 + dangerous sources of information, this option causes reads of sensitive
52611 + /proc/<pid> entries where the file descriptor was opened in a different
52612 + task than the one performing the read. Such attempts are logged.
52613 + This option also limits argv/env strings for suid/sgid binaries
52614 + to 512KB to prevent a complete exhaustion of the stack entropy provided
52615 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
52616 + binaries to prevent alternative mmap layouts from being abused.
52617 +
52618 + If you use PaX it is essential that you say Y here as it closes up
52619 + several holes that make full ASLR useless locally.
52620 +
52621 +config GRKERNSEC_BRUTE
52622 + bool "Deter exploit bruteforcing"
52623 + default y if GRKERNSEC_CONFIG_AUTO
52624 + help
52625 + If you say Y here, attempts to bruteforce exploits against forking
52626 + daemons such as apache or sshd, as well as against suid/sgid binaries
52627 + will be deterred. When a child of a forking daemon is killed by PaX
52628 + or crashes due to an illegal instruction or other suspicious signal,
52629 + the parent process will be delayed 30 seconds upon every subsequent
52630 + fork until the administrator is able to assess the situation and
52631 + restart the daemon.
52632 + In the suid/sgid case, the attempt is logged, the user has all their
52633 + processes terminated, and they are prevented from executing any further
52634 + processes for 15 minutes.
52635 + It is recommended that you also enable signal logging in the auditing
52636 + section so that logs are generated when a process triggers a suspicious
52637 + signal.
52638 + If the sysctl option is enabled, a sysctl option with name
52639 + "deter_bruteforce" is created.
52640 +
52641 +
52642 +config GRKERNSEC_MODHARDEN
52643 + bool "Harden module auto-loading"
52644 + default y if GRKERNSEC_CONFIG_AUTO
52645 + depends on MODULES
52646 + help
52647 + If you say Y here, module auto-loading in response to use of some
52648 + feature implemented by an unloaded module will be restricted to
52649 + root users. Enabling this option helps defend against attacks
52650 + by unprivileged users who abuse the auto-loading behavior to
52651 + cause a vulnerable module to load that is then exploited.
52652 +
52653 + If this option prevents a legitimate use of auto-loading for a
52654 + non-root user, the administrator can execute modprobe manually
52655 + with the exact name of the module mentioned in the alert log.
52656 + Alternatively, the administrator can add the module to the list
52657 + of modules loaded at boot by modifying init scripts.
52658 +
52659 + Modification of init scripts will most likely be needed on
52660 + Ubuntu servers with encrypted home directory support enabled,
52661 + as the first non-root user logging in will cause the ecb(aes),
52662 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
52663 +
52664 +config GRKERNSEC_HIDESYM
52665 + bool "Hide kernel symbols"
52666 + default y if GRKERNSEC_CONFIG_AUTO
52667 + select PAX_USERCOPY_SLABS
52668 + help
52669 + If you say Y here, getting information on loaded modules, and
52670 + displaying all kernel symbols through a syscall will be restricted
52671 + to users with CAP_SYS_MODULE. For software compatibility reasons,
52672 + /proc/kallsyms will be restricted to the root user. The RBAC
52673 + system can hide that entry even from root.
52674 +
52675 + This option also prevents leaking of kernel addresses through
52676 + several /proc entries.
52677 +
52678 + Note that this option is only effective provided the following
52679 + conditions are met:
52680 + 1) The kernel using grsecurity is not precompiled by some distribution
52681 + 2) You have also enabled GRKERNSEC_DMESG
52682 + 3) You are using the RBAC system and hiding other files such as your
52683 + kernel image and System.map. Alternatively, enabling this option
52684 + causes the permissions on /boot, /lib/modules, and the kernel
52685 + source directory to change at compile time to prevent
52686 + reading by non-root users.
52687 + If the above conditions are met, this option will aid in providing a
52688 + useful protection against local kernel exploitation of overflows
52689 + and arbitrary read/write vulnerabilities.
52690 +
52691 +config GRKERNSEC_KERN_LOCKOUT
52692 + bool "Active kernel exploit response"
52693 + default y if GRKERNSEC_CONFIG_AUTO
52694 + depends on X86 || ARM || PPC || SPARC
52695 + help
52696 + If you say Y here, when a PaX alert is triggered due to suspicious
52697 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
52698 + or an OOPS occurs due to bad memory accesses, instead of just
52699 + terminating the offending process (and potentially allowing
52700 + a subsequent exploit from the same user), we will take one of two
52701 + actions:
52702 + If the user was root, we will panic the system
52703 + If the user was non-root, we will log the attempt, terminate
52704 + all processes owned by the user, then prevent them from creating
52705 + any new processes until the system is restarted
52706 + This deters repeated kernel exploitation/bruteforcing attempts
52707 + and is useful for later forensics.
52708 +
52709 +endmenu
52710 +menu "Role Based Access Control Options"
52711 +depends on GRKERNSEC
52712 +
52713 +config GRKERNSEC_RBAC_DEBUG
52714 + bool
52715 +
52716 +config GRKERNSEC_NO_RBAC
52717 + bool "Disable RBAC system"
52718 + help
52719 + If you say Y here, the /dev/grsec device will be removed from the kernel,
52720 + preventing the RBAC system from being enabled. You should only say Y
52721 + here if you have no intention of using the RBAC system, so as to prevent
52722 + an attacker with root access from misusing the RBAC system to hide files
52723 + and processes when loadable module support and /dev/[k]mem have been
52724 + locked down.
52725 +
52726 +config GRKERNSEC_ACL_HIDEKERN
52727 + bool "Hide kernel processes"
52728 + help
52729 + If you say Y here, all kernel threads will be hidden to all
52730 + processes but those whose subject has the "view hidden processes"
52731 + flag.
52732 +
52733 +config GRKERNSEC_ACL_MAXTRIES
52734 + int "Maximum tries before password lockout"
52735 + default 3
52736 + help
52737 + This option enforces the maximum number of times a user can attempt
52738 + to authorize themselves with the grsecurity RBAC system before being
52739 + denied the ability to attempt authorization again for a specified time.
52740 + The lower the number, the harder it will be to brute-force a password.
52741 +
52742 +config GRKERNSEC_ACL_TIMEOUT
52743 + int "Time to wait after max password tries, in seconds"
52744 + default 30
52745 + help
52746 + This option specifies the time the user must wait after attempting to
52747 + authorize to the RBAC system with the maximum number of invalid
52748 + passwords. The higher the number, the harder it will be to brute-force
52749 + a password.
52750 +
52751 +endmenu
52752 +menu "Filesystem Protections"
52753 +depends on GRKERNSEC
52754 +
52755 +config GRKERNSEC_PROC
52756 + bool "Proc restrictions"
52757 + default y if GRKERNSEC_CONFIG_AUTO
52758 + help
52759 + If you say Y here, the permissions of the /proc filesystem
52760 + will be altered to enhance system security and privacy. You MUST
52761 + choose either a user only restriction or a user and group restriction.
52762 + Depending upon the option you choose, you can either restrict users to
52763 + see only the processes they themselves run, or choose a group that can
52764 + view all processes and files normally restricted to root if you choose
52765 + the "restrict to user only" option. NOTE: If you're running identd or
52766 + ntpd as a non-root user, you will have to run it as the group you
52767 + specify here.
52768 +
52769 +config GRKERNSEC_PROC_USER
52770 + bool "Restrict /proc to user only"
52771 + depends on GRKERNSEC_PROC
52772 + help
52773 + If you say Y here, non-root users will only be able to view their own
52774 + processes, and restricts them from viewing network-related information,
52775 + and viewing kernel symbol and module information.
52776 +
52777 +config GRKERNSEC_PROC_USERGROUP
52778 + bool "Allow special group"
52779 + default y if GRKERNSEC_CONFIG_AUTO
52780 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
52781 + help
52782 + If you say Y here, you will be able to select a group that will be
52783 + able to view all processes and network-related information. If you've
52784 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
52785 + remain hidden. This option is useful if you want to run identd as
52786 + a non-root user. The group you select may also be chosen at boot time
52787 + via "grsec_proc_gid=" on the kernel commandline.
52788 +
52789 +config GRKERNSEC_PROC_GID
52790 + int "GID for special group"
52791 + depends on GRKERNSEC_PROC_USERGROUP
52792 + default 1001
52793 +
52794 +config GRKERNSEC_PROC_ADD
52795 + bool "Additional restrictions"
52796 + default y if GRKERNSEC_CONFIG_AUTO
52797 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
52798 + help
52799 + If you say Y here, additional restrictions will be placed on
52800 + /proc that keep normal users from viewing device information and
52801 + slabinfo information that could be useful for exploits.
52802 +
52803 +config GRKERNSEC_LINK
52804 + bool "Linking restrictions"
52805 + default y if GRKERNSEC_CONFIG_AUTO
52806 + help
52807 + If you say Y here, /tmp race exploits will be prevented, since users
52808 + will no longer be able to follow symlinks owned by other users in
52809 + world-writable +t directories (e.g. /tmp), unless the owner of the
52810 + symlink is the owner of the directory. users will also not be
52811 + able to hardlink to files they do not own. If the sysctl option is
52812 + enabled, a sysctl option with name "linking_restrictions" is created.
52813 +
52814 +config GRKERNSEC_SYMLINKOWN
52815 + bool "Kernel-enforced SymlinksIfOwnerMatch"
52816 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
52817 + help
52818 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
52819 + that prevents it from being used as a security feature. As Apache
52820 + verifies the symlink by performing a stat() against the target of
52821 + the symlink before it is followed, an attacker can setup a symlink
52822 + to point to a same-owned file, then replace the symlink with one
52823 + that targets another user's file just after Apache "validates" the
52824 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
52825 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
52826 + will be in place for the group you specify. If the sysctl option
52827 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
52828 + created.
52829 +
52830 +config GRKERNSEC_SYMLINKOWN_GID
52831 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
52832 + depends on GRKERNSEC_SYMLINKOWN
52833 + default 1006
52834 + help
52835 + Setting this GID determines what group kernel-enforced
52836 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
52837 + is enabled, a sysctl option with name "symlinkown_gid" is created.
52838 +
52839 +config GRKERNSEC_FIFO
52840 + bool "FIFO restrictions"
52841 + default y if GRKERNSEC_CONFIG_AUTO
52842 + help
52843 + If you say Y here, users will not be able to write to FIFOs they don't
52844 + own in world-writable +t directories (e.g. /tmp), unless the owner of
52845 + the FIFO is the same owner of the directory it's held in. If the sysctl
52846 + option is enabled, a sysctl option with name "fifo_restrictions" is
52847 + created.
52848 +
52849 +config GRKERNSEC_SYSFS_RESTRICT
52850 + bool "Sysfs/debugfs restriction"
52851 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52852 + depends on SYSFS
52853 + help
52854 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
52855 + any filesystem normally mounted under it (e.g. debugfs) will be
52856 + mostly accessible only by root. These filesystems generally provide access
52857 + to hardware and debug information that isn't appropriate for unprivileged
52858 + users of the system. Sysfs and debugfs have also become a large source
52859 + of new vulnerabilities, ranging from infoleaks to local compromise.
52860 + There has been very little oversight with an eye toward security involved
52861 + in adding new exporters of information to these filesystems, so their
52862 + use is discouraged.
52863 + For reasons of compatibility, a few directories have been whitelisted
52864 + for access by non-root users:
52865 + /sys/fs/selinux
52866 + /sys/fs/fuse
52867 + /sys/devices/system/cpu
52868 +
52869 +config GRKERNSEC_ROFS
52870 + bool "Runtime read-only mount protection"
52871 + help
52872 + If you say Y here, a sysctl option with name "romount_protect" will
52873 + be created. By setting this option to 1 at runtime, filesystems
52874 + will be protected in the following ways:
52875 + * No new writable mounts will be allowed
52876 + * Existing read-only mounts won't be able to be remounted read/write
52877 + * Write operations will be denied on all block devices
52878 + This option acts independently of grsec_lock: once it is set to 1,
52879 + it cannot be turned off. Therefore, please be mindful of the resulting
52880 + behavior if this option is enabled in an init script on a read-only
52881 + filesystem. This feature is mainly intended for secure embedded systems.
52882 +
52883 +config GRKERNSEC_DEVICE_SIDECHANNEL
52884 + bool "Eliminate stat/notify-based device sidechannels"
52885 + default y if GRKERNSEC_CONFIG_AUTO
52886 + help
52887 + If you say Y here, timing analyses on block or character
52888 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
52889 + will be thwarted for unprivileged users. If a process without
52890 + CAP_MKNOD stats such a device, the last access and last modify times
52891 + will match the device's create time. No access or modify events
52892 + will be triggered through inotify/dnotify/fanotify for such devices.
52893 + This feature will prevent attacks that may at a minimum
52894 + allow an attacker to determine the administrator's password length.
52895 +
52896 +config GRKERNSEC_CHROOT
52897 + bool "Chroot jail restrictions"
52898 + default y if GRKERNSEC_CONFIG_AUTO
52899 + help
52900 + If you say Y here, you will be able to choose several options that will
52901 + make breaking out of a chrooted jail much more difficult. If you
52902 + encounter no software incompatibilities with the following options, it
52903 + is recommended that you enable each one.
52904 +
52905 +config GRKERNSEC_CHROOT_MOUNT
52906 + bool "Deny mounts"
52907 + default y if GRKERNSEC_CONFIG_AUTO
52908 + depends on GRKERNSEC_CHROOT
52909 + help
52910 + If you say Y here, processes inside a chroot will not be able to
52911 + mount or remount filesystems. If the sysctl option is enabled, a
52912 + sysctl option with name "chroot_deny_mount" is created.
52913 +
52914 +config GRKERNSEC_CHROOT_DOUBLE
52915 + bool "Deny double-chroots"
52916 + default y if GRKERNSEC_CONFIG_AUTO
52917 + depends on GRKERNSEC_CHROOT
52918 + help
52919 + If you say Y here, processes inside a chroot will not be able to chroot
52920 + again outside the chroot. This is a widely used method of breaking
52921 + out of a chroot jail and should not be allowed. If the sysctl
52922 + option is enabled, a sysctl option with name
52923 + "chroot_deny_chroot" is created.
52924 +
52925 +config GRKERNSEC_CHROOT_PIVOT
52926 + bool "Deny pivot_root in chroot"
52927 + default y if GRKERNSEC_CONFIG_AUTO
52928 + depends on GRKERNSEC_CHROOT
52929 + help
52930 + If you say Y here, processes inside a chroot will not be able to use
52931 + a function called pivot_root() that was introduced in Linux 2.3.41. It
52932 + works similar to chroot in that it changes the root filesystem. This
52933 + function could be misused in a chrooted process to attempt to break out
52934 + of the chroot, and therefore should not be allowed. If the sysctl
52935 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
52936 + created.
52937 +
52938 +config GRKERNSEC_CHROOT_CHDIR
52939 + bool "Enforce chdir(\"/\") on all chroots"
52940 + default y if GRKERNSEC_CONFIG_AUTO
52941 + depends on GRKERNSEC_CHROOT
52942 + help
52943 + If you say Y here, the current working directory of all newly-chrooted
52944 + applications will be set to the the root directory of the chroot.
52945 + The man page on chroot(2) states:
52946 + Note that this call does not change the current working
52947 + directory, so that `.' can be outside the tree rooted at
52948 + `/'. In particular, the super-user can escape from a
52949 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
52950 +
52951 + It is recommended that you say Y here, since it's not known to break
52952 + any software. If the sysctl option is enabled, a sysctl option with
52953 + name "chroot_enforce_chdir" is created.
52954 +
52955 +config GRKERNSEC_CHROOT_CHMOD
52956 + bool "Deny (f)chmod +s"
52957 + default y if GRKERNSEC_CONFIG_AUTO
52958 + depends on GRKERNSEC_CHROOT
52959 + help
52960 + If you say Y here, processes inside a chroot will not be able to chmod
52961 + or fchmod files to make them have suid or sgid bits. This protects
52962 + against another published method of breaking a chroot. If the sysctl
52963 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
52964 + created.
52965 +
52966 +config GRKERNSEC_CHROOT_FCHDIR
52967 + bool "Deny fchdir out of chroot"
52968 + default y if GRKERNSEC_CONFIG_AUTO
52969 + depends on GRKERNSEC_CHROOT
52970 + help
52971 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
52972 + to a file descriptor of the chrooting process that points to a directory
52973 + outside the filesystem will be stopped. If the sysctl option
52974 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
52975 +
52976 +config GRKERNSEC_CHROOT_MKNOD
52977 + bool "Deny mknod"
52978 + default y if GRKERNSEC_CONFIG_AUTO
52979 + depends on GRKERNSEC_CHROOT
52980 + help
52981 + If you say Y here, processes inside a chroot will not be allowed to
52982 + mknod. The problem with using mknod inside a chroot is that it
52983 + would allow an attacker to create a device entry that is the same
52984 + as one on the physical root of your system, which could range from
52985 + anything from the console device to a device for your harddrive (which
52986 + they could then use to wipe the drive or steal data). It is recommended
52987 + that you say Y here, unless you run into software incompatibilities.
52988 + If the sysctl option is enabled, a sysctl option with name
52989 + "chroot_deny_mknod" is created.
52990 +
52991 +config GRKERNSEC_CHROOT_SHMAT
52992 + bool "Deny shmat() out of chroot"
52993 + default y if GRKERNSEC_CONFIG_AUTO
52994 + depends on GRKERNSEC_CHROOT
52995 + help
52996 + If you say Y here, processes inside a chroot will not be able to attach
52997 + to shared memory segments that were created outside of the chroot jail.
52998 + It is recommended that you say Y here. If the sysctl option is enabled,
52999 + a sysctl option with name "chroot_deny_shmat" is created.
53000 +
53001 +config GRKERNSEC_CHROOT_UNIX
53002 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
53003 + default y if GRKERNSEC_CONFIG_AUTO
53004 + depends on GRKERNSEC_CHROOT
53005 + help
53006 + If you say Y here, processes inside a chroot will not be able to
53007 + connect to abstract (meaning not belonging to a filesystem) Unix
53008 + domain sockets that were bound outside of a chroot. It is recommended
53009 + that you say Y here. If the sysctl option is enabled, a sysctl option
53010 + with name "chroot_deny_unix" is created.
53011 +
53012 +config GRKERNSEC_CHROOT_FINDTASK
53013 + bool "Protect outside processes"
53014 + default y if GRKERNSEC_CONFIG_AUTO
53015 + depends on GRKERNSEC_CHROOT
53016 + help
53017 + If you say Y here, processes inside a chroot will not be able to
53018 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
53019 + getsid, or view any process outside of the chroot. If the sysctl
53020 + option is enabled, a sysctl option with name "chroot_findtask" is
53021 + created.
53022 +
53023 +config GRKERNSEC_CHROOT_NICE
53024 + bool "Restrict priority changes"
53025 + default y if GRKERNSEC_CONFIG_AUTO
53026 + depends on GRKERNSEC_CHROOT
53027 + help
53028 + If you say Y here, processes inside a chroot will not be able to raise
53029 + the priority of processes in the chroot, or alter the priority of
53030 + processes outside the chroot. This provides more security than simply
53031 + removing CAP_SYS_NICE from the process' capability set. If the
53032 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
53033 + is created.
53034 +
53035 +config GRKERNSEC_CHROOT_SYSCTL
53036 + bool "Deny sysctl writes"
53037 + default y if GRKERNSEC_CONFIG_AUTO
53038 + depends on GRKERNSEC_CHROOT
53039 + help
53040 + If you say Y here, an attacker in a chroot will not be able to
53041 + write to sysctl entries, either by sysctl(2) or through a /proc
53042 + interface. It is strongly recommended that you say Y here. If the
53043 + sysctl option is enabled, a sysctl option with name
53044 + "chroot_deny_sysctl" is created.
53045 +
53046 +config GRKERNSEC_CHROOT_CAPS
53047 + bool "Capability restrictions"
53048 + default y if GRKERNSEC_CONFIG_AUTO
53049 + depends on GRKERNSEC_CHROOT
53050 + help
53051 + If you say Y here, the capabilities on all processes within a
53052 + chroot jail will be lowered to stop module insertion, raw i/o,
53053 + system and net admin tasks, rebooting the system, modifying immutable
53054 + files, modifying IPC owned by another, and changing the system time.
53055 + This is left an option because it can break some apps. Disable this
53056 + if your chrooted apps are having problems performing those kinds of
53057 + tasks. If the sysctl option is enabled, a sysctl option with
53058 + name "chroot_caps" is created.
53059 +
53060 +endmenu
53061 +menu "Kernel Auditing"
53062 +depends on GRKERNSEC
53063 +
53064 +config GRKERNSEC_AUDIT_GROUP
53065 + bool "Single group for auditing"
53066 + help
53067 + If you say Y here, the exec and chdir logging features will only operate
53068 + on a group you specify. This option is recommended if you only want to
53069 + watch certain users instead of having a large amount of logs from the
53070 + entire system. If the sysctl option is enabled, a sysctl option with
53071 + name "audit_group" is created.
53072 +
53073 +config GRKERNSEC_AUDIT_GID
53074 + int "GID for auditing"
53075 + depends on GRKERNSEC_AUDIT_GROUP
53076 + default 1007
53077 +
53078 +config GRKERNSEC_EXECLOG
53079 + bool "Exec logging"
53080 + help
53081 + If you say Y here, all execve() calls will be logged (since the
53082 + other exec*() calls are frontends to execve(), all execution
53083 + will be logged). Useful for shell-servers that like to keep track
53084 + of their users. If the sysctl option is enabled, a sysctl option with
53085 + name "exec_logging" is created.
53086 + WARNING: This option when enabled will produce a LOT of logs, especially
53087 + on an active system.
53088 +
53089 +config GRKERNSEC_RESLOG
53090 + bool "Resource logging"
53091 + default y if GRKERNSEC_CONFIG_AUTO
53092 + help
53093 + If you say Y here, all attempts to overstep resource limits will
53094 + be logged with the resource name, the requested size, and the current
53095 + limit. It is highly recommended that you say Y here. If the sysctl
53096 + option is enabled, a sysctl option with name "resource_logging" is
53097 + created. If the RBAC system is enabled, the sysctl value is ignored.
53098 +
53099 +config GRKERNSEC_CHROOT_EXECLOG
53100 + bool "Log execs within chroot"
53101 + help
53102 + If you say Y here, all executions inside a chroot jail will be logged
53103 + to syslog. This can cause a large amount of logs if certain
53104 + applications (eg. djb's daemontools) are installed on the system, and
53105 + is therefore left as an option. If the sysctl option is enabled, a
53106 + sysctl option with name "chroot_execlog" is created.
53107 +
53108 +config GRKERNSEC_AUDIT_PTRACE
53109 + bool "Ptrace logging"
53110 + help
53111 + If you say Y here, all attempts to attach to a process via ptrace
53112 + will be logged. If the sysctl option is enabled, a sysctl option
53113 + with name "audit_ptrace" is created.
53114 +
53115 +config GRKERNSEC_AUDIT_CHDIR
53116 + bool "Chdir logging"
53117 + help
53118 + If you say Y here, all chdir() calls will be logged. If the sysctl
53119 + option is enabled, a sysctl option with name "audit_chdir" is created.
53120 +
53121 +config GRKERNSEC_AUDIT_MOUNT
53122 + bool "(Un)Mount logging"
53123 + help
53124 + If you say Y here, all mounts and unmounts will be logged. If the
53125 + sysctl option is enabled, a sysctl option with name "audit_mount" is
53126 + created.
53127 +
53128 +config GRKERNSEC_SIGNAL
53129 + bool "Signal logging"
53130 + default y if GRKERNSEC_CONFIG_AUTO
53131 + help
53132 + If you say Y here, certain important signals will be logged, such as
53133 + SIGSEGV, which will as a result inform you of when a error in a program
53134 + occurred, which in some cases could mean a possible exploit attempt.
53135 + If the sysctl option is enabled, a sysctl option with name
53136 + "signal_logging" is created.
53137 +
53138 +config GRKERNSEC_FORKFAIL
53139 + bool "Fork failure logging"
53140 + help
53141 + If you say Y here, all failed fork() attempts will be logged.
53142 + This could suggest a fork bomb, or someone attempting to overstep
53143 + their process limit. If the sysctl option is enabled, a sysctl option
53144 + with name "forkfail_logging" is created.
53145 +
53146 +config GRKERNSEC_TIME
53147 + bool "Time change logging"
53148 + default y if GRKERNSEC_CONFIG_AUTO
53149 + help
53150 + If you say Y here, any changes of the system clock will be logged.
53151 + If the sysctl option is enabled, a sysctl option with name
53152 + "timechange_logging" is created.
53153 +
53154 +config GRKERNSEC_PROC_IPADDR
53155 + bool "/proc/<pid>/ipaddr support"
53156 + default y if GRKERNSEC_CONFIG_AUTO
53157 + help
53158 + If you say Y here, a new entry will be added to each /proc/<pid>
53159 + directory that contains the IP address of the person using the task.
53160 + The IP is carried across local TCP and AF_UNIX stream sockets.
53161 + This information can be useful for IDS/IPSes to perform remote response
53162 + to a local attack. The entry is readable by only the owner of the
53163 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
53164 + the RBAC system), and thus does not create privacy concerns.
53165 +
53166 +config GRKERNSEC_RWXMAP_LOG
53167 + bool 'Denied RWX mmap/mprotect logging'
53168 + default y if GRKERNSEC_CONFIG_AUTO
53169 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
53170 + help
53171 + If you say Y here, calls to mmap() and mprotect() with explicit
53172 + usage of PROT_WRITE and PROT_EXEC together will be logged when
53173 + denied by the PAX_MPROTECT feature. If the sysctl option is
53174 + enabled, a sysctl option with name "rwxmap_logging" is created.
53175 +
53176 +config GRKERNSEC_AUDIT_TEXTREL
53177 + bool 'ELF text relocations logging (READ HELP)'
53178 + depends on PAX_MPROTECT
53179 + help
53180 + If you say Y here, text relocations will be logged with the filename
53181 + of the offending library or binary. The purpose of the feature is
53182 + to help Linux distribution developers get rid of libraries and
53183 + binaries that need text relocations which hinder the future progress
53184 + of PaX. Only Linux distribution developers should say Y here, and
53185 + never on a production machine, as this option creates an information
53186 + leak that could aid an attacker in defeating the randomization of
53187 + a single memory region. If the sysctl option is enabled, a sysctl
53188 + option with name "audit_textrel" is created.
53189 +
53190 +endmenu
53191 +
53192 +menu "Executable Protections"
53193 +depends on GRKERNSEC
53194 +
53195 +config GRKERNSEC_DMESG
53196 + bool "Dmesg(8) restriction"
53197 + default y if GRKERNSEC_CONFIG_AUTO
53198 + help
53199 + If you say Y here, non-root users will not be able to use dmesg(8)
53200 + to view the contents of the kernel's circular log buffer.
53201 + The kernel's log buffer often contains kernel addresses and other
53202 + identifying information useful to an attacker in fingerprinting a
53203 + system for a targeted exploit.
53204 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
53205 + created.
53206 +
53207 +config GRKERNSEC_HARDEN_PTRACE
53208 + bool "Deter ptrace-based process snooping"
53209 + default y if GRKERNSEC_CONFIG_AUTO
53210 + help
53211 + If you say Y here, TTY sniffers and other malicious monitoring
53212 + programs implemented through ptrace will be defeated. If you
53213 + have been using the RBAC system, this option has already been
53214 + enabled for several years for all users, with the ability to make
53215 + fine-grained exceptions.
53216 +
53217 + This option only affects the ability of non-root users to ptrace
53218 + processes that are not a descendent of the ptracing process.
53219 + This means that strace ./binary and gdb ./binary will still work,
53220 + but attaching to arbitrary processes will not. If the sysctl
53221 + option is enabled, a sysctl option with name "harden_ptrace" is
53222 + created.
53223 +
53224 +config GRKERNSEC_PTRACE_READEXEC
53225 + bool "Require read access to ptrace sensitive binaries"
53226 + default y if GRKERNSEC_CONFIG_AUTO
53227 + help
53228 + If you say Y here, unprivileged users will not be able to ptrace unreadable
53229 + binaries. This option is useful in environments that
53230 + remove the read bits (e.g. file mode 4711) from suid binaries to
53231 + prevent infoleaking of their contents. This option adds
53232 + consistency to the use of that file mode, as the binary could normally
53233 + be read out when run without privileges while ptracing.
53234 +
53235 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
53236 + is created.
53237 +
53238 +config GRKERNSEC_SETXID
53239 + bool "Enforce consistent multithreaded privileges"
53240 + default y if GRKERNSEC_CONFIG_AUTO
53241 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
53242 + help
53243 + If you say Y here, a change from a root uid to a non-root uid
53244 + in a multithreaded application will cause the resulting uids,
53245 + gids, supplementary groups, and capabilities in that thread
53246 + to be propagated to the other threads of the process. In most
53247 + cases this is unnecessary, as glibc will emulate this behavior
53248 + on behalf of the application. Other libcs do not act in the
53249 + same way, allowing the other threads of the process to continue
53250 + running with root privileges. If the sysctl option is enabled,
53251 + a sysctl option with name "consistent_setxid" is created.
53252 +
53253 +config GRKERNSEC_TPE
53254 + bool "Trusted Path Execution (TPE)"
53255 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
53256 + help
53257 + If you say Y here, you will be able to choose a gid to add to the
53258 + supplementary groups of users you want to mark as "untrusted."
53259 + These users will not be able to execute any files that are not in
53260 + root-owned directories writable only by root. If the sysctl option
53261 + is enabled, a sysctl option with name "tpe" is created.
53262 +
53263 +config GRKERNSEC_TPE_ALL
53264 + bool "Partially restrict all non-root users"
53265 + depends on GRKERNSEC_TPE
53266 + help
53267 + If you say Y here, all non-root users will be covered under
53268 + a weaker TPE restriction. This is separate from, and in addition to,
53269 + the main TPE options that you have selected elsewhere. Thus, if a
53270 + "trusted" GID is chosen, this restriction applies to even that GID.
53271 + Under this restriction, all non-root users will only be allowed to
53272 + execute files in directories they own that are not group or
53273 + world-writable, or in directories owned by root and writable only by
53274 + root. If the sysctl option is enabled, a sysctl option with name
53275 + "tpe_restrict_all" is created.
53276 +
53277 +config GRKERNSEC_TPE_INVERT
53278 + bool "Invert GID option"
53279 + depends on GRKERNSEC_TPE
53280 + help
53281 + If you say Y here, the group you specify in the TPE configuration will
53282 + decide what group TPE restrictions will be *disabled* for. This
53283 + option is useful if you want TPE restrictions to be applied to most
53284 + users on the system. If the sysctl option is enabled, a sysctl option
53285 + with name "tpe_invert" is created. Unlike other sysctl options, this
53286 + entry will default to on for backward-compatibility.
53287 +
53288 +config GRKERNSEC_TPE_GID
53289 + int
53290 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
53291 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
53292 +
53293 +config GRKERNSEC_TPE_UNTRUSTED_GID
53294 + int "GID for TPE-untrusted users"
53295 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
53296 + default 1005
53297 + help
53298 + Setting this GID determines what group TPE restrictions will be
53299 + *enabled* for. If the sysctl option is enabled, a sysctl option
53300 + with name "tpe_gid" is created.
53301 +
53302 +config GRKERNSEC_TPE_TRUSTED_GID
53303 + int "GID for TPE-trusted users"
53304 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
53305 + default 1005
53306 + help
53307 + Setting this GID determines what group TPE restrictions will be
53308 + *disabled* for. If the sysctl option is enabled, a sysctl option
53309 + with name "tpe_gid" is created.
53310 +
53311 +endmenu
53312 +menu "Network Protections"
53313 +depends on GRKERNSEC
53314 +
53315 +config GRKERNSEC_RANDNET
53316 + bool "Larger entropy pools"
53317 + default y if GRKERNSEC_CONFIG_AUTO
53318 + help
53319 + If you say Y here, the entropy pools used for many features of Linux
53320 + and grsecurity will be doubled in size. Since several grsecurity
53321 + features use additional randomness, it is recommended that you say Y
53322 + here. Saying Y here has a similar effect as modifying
53323 + /proc/sys/kernel/random/poolsize.
53324 +
53325 +config GRKERNSEC_BLACKHOLE
53326 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
53327 + default y if GRKERNSEC_CONFIG_AUTO
53328 + depends on NET
53329 + help
53330 + If you say Y here, neither TCP resets nor ICMP
53331 + destination-unreachable packets will be sent in response to packets
53332 + sent to ports for which no associated listening process exists.
53333 + This feature supports both IPV4 and IPV6 and exempts the
53334 + loopback interface from blackholing. Enabling this feature
53335 + makes a host more resilient to DoS attacks and reduces network
53336 + visibility against scanners.
53337 +
53338 + The blackhole feature as-implemented is equivalent to the FreeBSD
53339 + blackhole feature, as it prevents RST responses to all packets, not
53340 + just SYNs. Under most application behavior this causes no
53341 + problems, but applications (like haproxy) may not close certain
53342 + connections in a way that cleanly terminates them on the remote
53343 + end, leaving the remote host in LAST_ACK state. Because of this
53344 + side-effect and to prevent intentional LAST_ACK DoSes, this
53345 + feature also adds automatic mitigation against such attacks.
53346 + The mitigation drastically reduces the amount of time a socket
53347 + can spend in LAST_ACK state. If you're using haproxy and not
53348 + all servers it connects to have this option enabled, consider
53349 + disabling this feature on the haproxy host.
53350 +
53351 + If the sysctl option is enabled, two sysctl options with names
53352 + "ip_blackhole" and "lastack_retries" will be created.
53353 + While "ip_blackhole" takes the standard zero/non-zero on/off
53354 + toggle, "lastack_retries" uses the same kinds of values as
53355 + "tcp_retries1" and "tcp_retries2". The default value of 4
53356 + prevents a socket from lasting more than 45 seconds in LAST_ACK
53357 + state.
53358 +
53359 +config GRKERNSEC_NO_SIMULT_CONNECT
53360 + bool "Disable TCP Simultaneous Connect"
53361 + default y if GRKERNSEC_CONFIG_AUTO
53362 + depends on NET
53363 + help
53364 + If you say Y here, a feature by Willy Tarreau will be enabled that
53365 + removes a weakness in Linux's strict implementation of TCP that
53366 + allows two clients to connect to each other without either entering
53367 + a listening state. The weakness allows an attacker to easily prevent
53368 + a client from connecting to a known server provided the source port
53369 + for the connection is guessed correctly.
53370 +
53371 + As the weakness could be used to prevent an antivirus or IPS from
53372 + fetching updates, or prevent an SSL gateway from fetching a CRL,
53373 + it should be eliminated by enabling this option. Though Linux is
53374 + one of few operating systems supporting simultaneous connect, it
53375 + has no legitimate use in practice and is rarely supported by firewalls.
53376 +
53377 +config GRKERNSEC_SOCKET
53378 + bool "Socket restrictions"
53379 + depends on NET
53380 + help
53381 + If you say Y here, you will be able to choose from several options.
53382 + If you assign a GID on your system and add it to the supplementary
53383 + groups of users you want to restrict socket access to, this patch
53384 + will perform up to three things, based on the option(s) you choose.
53385 +
53386 +config GRKERNSEC_SOCKET_ALL
53387 + bool "Deny any sockets to group"
53388 + depends on GRKERNSEC_SOCKET
53389 + help
53390 + If you say Y here, you will be able to choose a GID of whose users will
53391 + be unable to connect to other hosts from your machine or run server
53392 + applications from your machine. If the sysctl option is enabled, a
53393 + sysctl option with name "socket_all" is created.
53394 +
53395 +config GRKERNSEC_SOCKET_ALL_GID
53396 + int "GID to deny all sockets for"
53397 + depends on GRKERNSEC_SOCKET_ALL
53398 + default 1004
53399 + help
53400 + Here you can choose the GID to disable socket access for. Remember to
53401 + add the users you want socket access disabled for to the GID
53402 + specified here. If the sysctl option is enabled, a sysctl option
53403 + with name "socket_all_gid" is created.
53404 +
53405 +config GRKERNSEC_SOCKET_CLIENT
53406 + bool "Deny client sockets to group"
53407 + depends on GRKERNSEC_SOCKET
53408 + help
53409 + If you say Y here, you will be able to choose a GID of whose users will
53410 + be unable to connect to other hosts from your machine, but will be
53411 + able to run servers. If this option is enabled, all users in the group
53412 + you specify will have to use passive mode when initiating ftp transfers
53413 + from the shell on your machine. If the sysctl option is enabled, a
53414 + sysctl option with name "socket_client" is created.
53415 +
53416 +config GRKERNSEC_SOCKET_CLIENT_GID
53417 + int "GID to deny client sockets for"
53418 + depends on GRKERNSEC_SOCKET_CLIENT
53419 + default 1003
53420 + help
53421 + Here you can choose the GID to disable client socket access for.
53422 + Remember to add the users you want client socket access disabled for to
53423 + the GID specified here. If the sysctl option is enabled, a sysctl
53424 + option with name "socket_client_gid" is created.
53425 +
53426 +config GRKERNSEC_SOCKET_SERVER
53427 + bool "Deny server sockets to group"
53428 + depends on GRKERNSEC_SOCKET
53429 + help
53430 + If you say Y here, you will be able to choose a GID of whose users will
53431 + be unable to run server applications from your machine. If the sysctl
53432 + option is enabled, a sysctl option with name "socket_server" is created.
53433 +
53434 +config GRKERNSEC_SOCKET_SERVER_GID
53435 + int "GID to deny server sockets for"
53436 + depends on GRKERNSEC_SOCKET_SERVER
53437 + default 1002
53438 + help
53439 + Here you can choose the GID to disable server socket access for.
53440 + Remember to add the users you want server socket access disabled for to
53441 + the GID specified here. If the sysctl option is enabled, a sysctl
53442 + option with name "socket_server_gid" is created.
53443 +
53444 +endmenu
53445 +menu "Sysctl Support"
53446 +depends on GRKERNSEC && SYSCTL
53447 +
53448 +config GRKERNSEC_SYSCTL
53449 + bool "Sysctl support"
53450 + default y if GRKERNSEC_CONFIG_AUTO
53451 + help
53452 + If you say Y here, you will be able to change the options that
53453 + grsecurity runs with at bootup, without having to recompile your
53454 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
53455 + to enable (1) or disable (0) various features. All the sysctl entries
53456 + are mutable until the "grsec_lock" entry is set to a non-zero value.
53457 + All features enabled in the kernel configuration are disabled at boot
53458 + if you do not say Y to the "Turn on features by default" option.
53459 + All options should be set at startup, and the grsec_lock entry should
53460 + be set to a non-zero value after all the options are set.
53461 + *THIS IS EXTREMELY IMPORTANT*
53462 +
53463 +config GRKERNSEC_SYSCTL_DISTRO
53464 + bool "Extra sysctl support for distro makers (READ HELP)"
53465 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
53466 + help
53467 + If you say Y here, additional sysctl options will be created
53468 + for features that affect processes running as root. Therefore,
53469 + it is critical when using this option that the grsec_lock entry be
53470 + enabled after boot. Only distros with prebuilt kernel packages
53471 + with this option enabled that can ensure grsec_lock is enabled
53472 + after boot should use this option.
53473 + *Failure to set grsec_lock after boot makes all grsec features
53474 + this option covers useless*
53475 +
53476 + Currently this option creates the following sysctl entries:
53477 + "Disable Privileged I/O": "disable_priv_io"
53478 +
53479 +config GRKERNSEC_SYSCTL_ON
53480 + bool "Turn on features by default"
53481 + default y if GRKERNSEC_CONFIG_AUTO
53482 + depends on GRKERNSEC_SYSCTL
53483 + help
53484 + If you say Y here, instead of having all features enabled in the
53485 + kernel configuration disabled at boot time, the features will be
53486 + enabled at boot time. It is recommended you say Y here unless
53487 + there is some reason you would want all sysctl-tunable features to
53488 + be disabled by default. As mentioned elsewhere, it is important
53489 + to enable the grsec_lock entry once you have finished modifying
53490 + the sysctl entries.
53491 +
53492 +endmenu
53493 +menu "Logging Options"
53494 +depends on GRKERNSEC
53495 +
53496 +config GRKERNSEC_FLOODTIME
53497 + int "Seconds in between log messages (minimum)"
53498 + default 10
53499 + help
53500 + This option allows you to enforce the number of seconds between
53501 + grsecurity log messages. The default should be suitable for most
53502 + people, however, if you choose to change it, choose a value small enough
53503 + to allow informative logs to be produced, but large enough to
53504 + prevent flooding.
53505 +
53506 +config GRKERNSEC_FLOODBURST
53507 + int "Number of messages in a burst (maximum)"
53508 + default 6
53509 + help
53510 + This option allows you to choose the maximum number of messages allowed
53511 + within the flood time interval you chose in a separate option. The
53512 + default should be suitable for most people, however if you find that
53513 + many of your logs are being interpreted as flooding, you may want to
53514 + raise this value.
53515 +
53516 +endmenu
53517 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
53518 new file mode 100644
53519 index 0000000..1b9afa9
53520 --- /dev/null
53521 +++ b/grsecurity/Makefile
53522 @@ -0,0 +1,38 @@
53523 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
53524 +# during 2001-2009 it has been completely redesigned by Brad Spengler
53525 +# into an RBAC system
53526 +#
53527 +# All code in this directory and various hooks inserted throughout the kernel
53528 +# are copyright Brad Spengler - Open Source Security, Inc., and released
53529 +# under the GPL v2 or higher
53530 +
53531 +KBUILD_CFLAGS += -Werror
53532 +
53533 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
53534 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
53535 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
53536 +
53537 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
53538 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
53539 + gracl_learn.o grsec_log.o
53540 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
53541 +
53542 +ifdef CONFIG_NET
53543 +obj-y += grsec_sock.o
53544 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
53545 +endif
53546 +
53547 +ifndef CONFIG_GRKERNSEC
53548 +obj-y += grsec_disabled.o
53549 +endif
53550 +
53551 +ifdef CONFIG_GRKERNSEC_HIDESYM
53552 +extra-y := grsec_hidesym.o
53553 +$(obj)/grsec_hidesym.o:
53554 + @-chmod -f 500 /boot
53555 + @-chmod -f 500 /lib/modules
53556 + @-chmod -f 500 /lib64/modules
53557 + @-chmod -f 500 /lib32/modules
53558 + @-chmod -f 700 .
53559 + @echo ' grsec: protected kernel image paths'
53560 +endif
53561 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
53562 new file mode 100644
53563 index 0000000..1caa60a
53564 --- /dev/null
53565 +++ b/grsecurity/gracl.c
53566 @@ -0,0 +1,4003 @@
53567 +#include <linux/kernel.h>
53568 +#include <linux/module.h>
53569 +#include <linux/sched.h>
53570 +#include <linux/mm.h>
53571 +#include <linux/file.h>
53572 +#include <linux/fs.h>
53573 +#include <linux/namei.h>
53574 +#include <linux/mount.h>
53575 +#include <linux/tty.h>
53576 +#include <linux/proc_fs.h>
53577 +#include <linux/lglock.h>
53578 +#include <linux/slab.h>
53579 +#include <linux/vmalloc.h>
53580 +#include <linux/types.h>
53581 +#include <linux/sysctl.h>
53582 +#include <linux/netdevice.h>
53583 +#include <linux/ptrace.h>
53584 +#include <linux/gracl.h>
53585 +#include <linux/gralloc.h>
53586 +#include <linux/security.h>
53587 +#include <linux/grinternal.h>
53588 +#include <linux/pid_namespace.h>
53589 +#include <linux/stop_machine.h>
53590 +#include <linux/fdtable.h>
53591 +#include <linux/percpu.h>
53592 +#include <linux/lglock.h>
53593 +#include "../fs/mount.h"
53594 +
53595 +#include <asm/uaccess.h>
53596 +#include <asm/errno.h>
53597 +#include <asm/mman.h>
53598 +
53599 +extern struct lglock vfsmount_lock;
53600 +
53601 +static struct acl_role_db acl_role_set;
53602 +static struct name_db name_set;
53603 +static struct inodev_db inodev_set;
53604 +
53605 +/* for keeping track of userspace pointers used for subjects, so we
53606 + can share references in the kernel as well
53607 +*/
53608 +
53609 +static struct path real_root;
53610 +
53611 +static struct acl_subj_map_db subj_map_set;
53612 +
53613 +static struct acl_role_label *default_role;
53614 +
53615 +static struct acl_role_label *role_list;
53616 +
53617 +static u16 acl_sp_role_value;
53618 +
53619 +extern char *gr_shared_page[4];
53620 +static DEFINE_MUTEX(gr_dev_mutex);
53621 +DEFINE_RWLOCK(gr_inode_lock);
53622 +
53623 +struct gr_arg *gr_usermode;
53624 +
53625 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
53626 +
53627 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
53628 +extern void gr_clear_learn_entries(void);
53629 +
53630 +unsigned char *gr_system_salt;
53631 +unsigned char *gr_system_sum;
53632 +
53633 +static struct sprole_pw **acl_special_roles = NULL;
53634 +static __u16 num_sprole_pws = 0;
53635 +
53636 +static struct acl_role_label *kernel_role = NULL;
53637 +
53638 +static unsigned int gr_auth_attempts = 0;
53639 +static unsigned long gr_auth_expires = 0UL;
53640 +
53641 +#ifdef CONFIG_NET
53642 +extern struct vfsmount *sock_mnt;
53643 +#endif
53644 +
53645 +extern struct vfsmount *pipe_mnt;
53646 +extern struct vfsmount *shm_mnt;
53647 +#ifdef CONFIG_HUGETLBFS
53648 +extern struct vfsmount *hugetlbfs_vfsmount;
53649 +#endif
53650 +
53651 +static struct acl_object_label *fakefs_obj_rw;
53652 +static struct acl_object_label *fakefs_obj_rwx;
53653 +
53654 +extern int gr_init_uidset(void);
53655 +extern void gr_free_uidset(void);
53656 +extern void gr_remove_uid(uid_t uid);
53657 +extern int gr_find_uid(uid_t uid);
53658 +
53659 +__inline__ int
53660 +gr_acl_is_enabled(void)
53661 +{
53662 + return (gr_status & GR_READY);
53663 +}
53664 +
53665 +#ifdef CONFIG_BTRFS_FS
53666 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
53667 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
53668 +#endif
53669 +
53670 +static inline dev_t __get_dev(const struct dentry *dentry)
53671 +{
53672 +#ifdef CONFIG_BTRFS_FS
53673 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
53674 + return get_btrfs_dev_from_inode(dentry->d_inode);
53675 + else
53676 +#endif
53677 + return dentry->d_inode->i_sb->s_dev;
53678 +}
53679 +
53680 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
53681 +{
53682 + return __get_dev(dentry);
53683 +}
53684 +
53685 +static char gr_task_roletype_to_char(struct task_struct *task)
53686 +{
53687 + switch (task->role->roletype &
53688 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
53689 + GR_ROLE_SPECIAL)) {
53690 + case GR_ROLE_DEFAULT:
53691 + return 'D';
53692 + case GR_ROLE_USER:
53693 + return 'U';
53694 + case GR_ROLE_GROUP:
53695 + return 'G';
53696 + case GR_ROLE_SPECIAL:
53697 + return 'S';
53698 + }
53699 +
53700 + return 'X';
53701 +}
53702 +
53703 +char gr_roletype_to_char(void)
53704 +{
53705 + return gr_task_roletype_to_char(current);
53706 +}
53707 +
53708 +__inline__ int
53709 +gr_acl_tpe_check(void)
53710 +{
53711 + if (unlikely(!(gr_status & GR_READY)))
53712 + return 0;
53713 + if (current->role->roletype & GR_ROLE_TPE)
53714 + return 1;
53715 + else
53716 + return 0;
53717 +}
53718 +
53719 +int
53720 +gr_handle_rawio(const struct inode *inode)
53721 +{
53722 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
53723 + if (inode && S_ISBLK(inode->i_mode) &&
53724 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
53725 + !capable(CAP_SYS_RAWIO))
53726 + return 1;
53727 +#endif
53728 + return 0;
53729 +}
53730 +
53731 +static int
53732 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
53733 +{
53734 + if (likely(lena != lenb))
53735 + return 0;
53736 +
53737 + return !memcmp(a, b, lena);
53738 +}
53739 +
53740 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
53741 +{
53742 + *buflen -= namelen;
53743 + if (*buflen < 0)
53744 + return -ENAMETOOLONG;
53745 + *buffer -= namelen;
53746 + memcpy(*buffer, str, namelen);
53747 + return 0;
53748 +}
53749 +
53750 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
53751 +{
53752 + return prepend(buffer, buflen, name->name, name->len);
53753 +}
53754 +
53755 +static int prepend_path(const struct path *path, struct path *root,
53756 + char **buffer, int *buflen)
53757 +{
53758 + struct dentry *dentry = path->dentry;
53759 + struct vfsmount *vfsmnt = path->mnt;
53760 + struct mount *mnt = real_mount(vfsmnt);
53761 + bool slash = false;
53762 + int error = 0;
53763 +
53764 + while (dentry != root->dentry || vfsmnt != root->mnt) {
53765 + struct dentry * parent;
53766 +
53767 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
53768 + /* Global root? */
53769 + if (!mnt_has_parent(mnt)) {
53770 + goto out;
53771 + }
53772 + dentry = mnt->mnt_mountpoint;
53773 + mnt = mnt->mnt_parent;
53774 + vfsmnt = &mnt->mnt;
53775 + continue;
53776 + }
53777 + parent = dentry->d_parent;
53778 + prefetch(parent);
53779 + spin_lock(&dentry->d_lock);
53780 + error = prepend_name(buffer, buflen, &dentry->d_name);
53781 + spin_unlock(&dentry->d_lock);
53782 + if (!error)
53783 + error = prepend(buffer, buflen, "/", 1);
53784 + if (error)
53785 + break;
53786 +
53787 + slash = true;
53788 + dentry = parent;
53789 + }
53790 +
53791 +out:
53792 + if (!error && !slash)
53793 + error = prepend(buffer, buflen, "/", 1);
53794 +
53795 + return error;
53796 +}
53797 +
53798 +/* this must be called with vfsmount_lock and rename_lock held */
53799 +
53800 +static char *__our_d_path(const struct path *path, struct path *root,
53801 + char *buf, int buflen)
53802 +{
53803 + char *res = buf + buflen;
53804 + int error;
53805 +
53806 + prepend(&res, &buflen, "\0", 1);
53807 + error = prepend_path(path, root, &res, &buflen);
53808 + if (error)
53809 + return ERR_PTR(error);
53810 +
53811 + return res;
53812 +}
53813 +
53814 +static char *
53815 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
53816 +{
53817 + char *retval;
53818 +
53819 + retval = __our_d_path(path, root, buf, buflen);
53820 + if (unlikely(IS_ERR(retval)))
53821 + retval = strcpy(buf, "<path too long>");
53822 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
53823 + retval[1] = '\0';
53824 +
53825 + return retval;
53826 +}
53827 +
53828 +static char *
53829 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53830 + char *buf, int buflen)
53831 +{
53832 + struct path path;
53833 + char *res;
53834 +
53835 + path.dentry = (struct dentry *)dentry;
53836 + path.mnt = (struct vfsmount *)vfsmnt;
53837 +
53838 + /* we can use real_root.dentry, real_root.mnt, because this is only called
53839 + by the RBAC system */
53840 + res = gen_full_path(&path, &real_root, buf, buflen);
53841 +
53842 + return res;
53843 +}
53844 +
53845 +static char *
53846 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53847 + char *buf, int buflen)
53848 +{
53849 + char *res;
53850 + struct path path;
53851 + struct path root;
53852 + struct task_struct *reaper = init_pid_ns.child_reaper;
53853 +
53854 + path.dentry = (struct dentry *)dentry;
53855 + path.mnt = (struct vfsmount *)vfsmnt;
53856 +
53857 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
53858 + get_fs_root(reaper->fs, &root);
53859 +
53860 + write_seqlock(&rename_lock);
53861 + br_read_lock(&vfsmount_lock);
53862 + res = gen_full_path(&path, &root, buf, buflen);
53863 + br_read_unlock(&vfsmount_lock);
53864 + write_sequnlock(&rename_lock);
53865 +
53866 + path_put(&root);
53867 + return res;
53868 +}
53869 +
53870 +static char *
53871 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53872 +{
53873 + char *ret;
53874 + write_seqlock(&rename_lock);
53875 + br_read_lock(&vfsmount_lock);
53876 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53877 + PAGE_SIZE);
53878 + br_read_unlock(&vfsmount_lock);
53879 + write_sequnlock(&rename_lock);
53880 + return ret;
53881 +}
53882 +
53883 +static char *
53884 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53885 +{
53886 + char *ret;
53887 + char *buf;
53888 + int buflen;
53889 +
53890 + write_seqlock(&rename_lock);
53891 + br_read_lock(&vfsmount_lock);
53892 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
53893 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
53894 + buflen = (int)(ret - buf);
53895 + if (buflen >= 5)
53896 + prepend(&ret, &buflen, "/proc", 5);
53897 + else
53898 + ret = strcpy(buf, "<path too long>");
53899 + br_read_unlock(&vfsmount_lock);
53900 + write_sequnlock(&rename_lock);
53901 + return ret;
53902 +}
53903 +
53904 +char *
53905 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
53906 +{
53907 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53908 + PAGE_SIZE);
53909 +}
53910 +
53911 +char *
53912 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
53913 +{
53914 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
53915 + PAGE_SIZE);
53916 +}
53917 +
53918 +char *
53919 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
53920 +{
53921 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
53922 + PAGE_SIZE);
53923 +}
53924 +
53925 +char *
53926 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
53927 +{
53928 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
53929 + PAGE_SIZE);
53930 +}
53931 +
53932 +char *
53933 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
53934 +{
53935 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
53936 + PAGE_SIZE);
53937 +}
53938 +
53939 +__inline__ __u32
53940 +to_gr_audit(const __u32 reqmode)
53941 +{
53942 + /* masks off auditable permission flags, then shifts them to create
53943 + auditing flags, and adds the special case of append auditing if
53944 + we're requesting write */
53945 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
53946 +}
53947 +
53948 +struct acl_subject_label *
53949 +lookup_subject_map(const struct acl_subject_label *userp)
53950 +{
53951 + unsigned int index = gr_shash(userp, subj_map_set.s_size);
53952 + struct subject_map *match;
53953 +
53954 + match = subj_map_set.s_hash[index];
53955 +
53956 + while (match && match->user != userp)
53957 + match = match->next;
53958 +
53959 + if (match != NULL)
53960 + return match->kernel;
53961 + else
53962 + return NULL;
53963 +}
53964 +
53965 +static void
53966 +insert_subj_map_entry(struct subject_map *subjmap)
53967 +{
53968 + unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
53969 + struct subject_map **curr;
53970 +
53971 + subjmap->prev = NULL;
53972 +
53973 + curr = &subj_map_set.s_hash[index];
53974 + if (*curr != NULL)
53975 + (*curr)->prev = subjmap;
53976 +
53977 + subjmap->next = *curr;
53978 + *curr = subjmap;
53979 +
53980 + return;
53981 +}
53982 +
53983 +static struct acl_role_label *
53984 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
53985 + const gid_t gid)
53986 +{
53987 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
53988 + struct acl_role_label *match;
53989 + struct role_allowed_ip *ipp;
53990 + unsigned int x;
53991 + u32 curr_ip = task->signal->curr_ip;
53992 +
53993 + task->signal->saved_ip = curr_ip;
53994 +
53995 + match = acl_role_set.r_hash[index];
53996 +
53997 + while (match) {
53998 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
53999 + for (x = 0; x < match->domain_child_num; x++) {
54000 + if (match->domain_children[x] == uid)
54001 + goto found;
54002 + }
54003 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
54004 + break;
54005 + match = match->next;
54006 + }
54007 +found:
54008 + if (match == NULL) {
54009 + try_group:
54010 + index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
54011 + match = acl_role_set.r_hash[index];
54012 +
54013 + while (match) {
54014 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
54015 + for (x = 0; x < match->domain_child_num; x++) {
54016 + if (match->domain_children[x] == gid)
54017 + goto found2;
54018 + }
54019 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
54020 + break;
54021 + match = match->next;
54022 + }
54023 +found2:
54024 + if (match == NULL)
54025 + match = default_role;
54026 + if (match->allowed_ips == NULL)
54027 + return match;
54028 + else {
54029 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54030 + if (likely
54031 + ((ntohl(curr_ip) & ipp->netmask) ==
54032 + (ntohl(ipp->addr) & ipp->netmask)))
54033 + return match;
54034 + }
54035 + match = default_role;
54036 + }
54037 + } else if (match->allowed_ips == NULL) {
54038 + return match;
54039 + } else {
54040 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54041 + if (likely
54042 + ((ntohl(curr_ip) & ipp->netmask) ==
54043 + (ntohl(ipp->addr) & ipp->netmask)))
54044 + return match;
54045 + }
54046 + goto try_group;
54047 + }
54048 +
54049 + return match;
54050 +}
54051 +
54052 +struct acl_subject_label *
54053 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
54054 + const struct acl_role_label *role)
54055 +{
54056 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54057 + struct acl_subject_label *match;
54058 +
54059 + match = role->subj_hash[index];
54060 +
54061 + while (match && (match->inode != ino || match->device != dev ||
54062 + (match->mode & GR_DELETED))) {
54063 + match = match->next;
54064 + }
54065 +
54066 + if (match && !(match->mode & GR_DELETED))
54067 + return match;
54068 + else
54069 + return NULL;
54070 +}
54071 +
54072 +struct acl_subject_label *
54073 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
54074 + const struct acl_role_label *role)
54075 +{
54076 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54077 + struct acl_subject_label *match;
54078 +
54079 + match = role->subj_hash[index];
54080 +
54081 + while (match && (match->inode != ino || match->device != dev ||
54082 + !(match->mode & GR_DELETED))) {
54083 + match = match->next;
54084 + }
54085 +
54086 + if (match && (match->mode & GR_DELETED))
54087 + return match;
54088 + else
54089 + return NULL;
54090 +}
54091 +
54092 +static struct acl_object_label *
54093 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
54094 + const struct acl_subject_label *subj)
54095 +{
54096 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54097 + struct acl_object_label *match;
54098 +
54099 + match = subj->obj_hash[index];
54100 +
54101 + while (match && (match->inode != ino || match->device != dev ||
54102 + (match->mode & GR_DELETED))) {
54103 + match = match->next;
54104 + }
54105 +
54106 + if (match && !(match->mode & GR_DELETED))
54107 + return match;
54108 + else
54109 + return NULL;
54110 +}
54111 +
54112 +static struct acl_object_label *
54113 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
54114 + const struct acl_subject_label *subj)
54115 +{
54116 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54117 + struct acl_object_label *match;
54118 +
54119 + match = subj->obj_hash[index];
54120 +
54121 + while (match && (match->inode != ino || match->device != dev ||
54122 + !(match->mode & GR_DELETED))) {
54123 + match = match->next;
54124 + }
54125 +
54126 + if (match && (match->mode & GR_DELETED))
54127 + return match;
54128 +
54129 + match = subj->obj_hash[index];
54130 +
54131 + while (match && (match->inode != ino || match->device != dev ||
54132 + (match->mode & GR_DELETED))) {
54133 + match = match->next;
54134 + }
54135 +
54136 + if (match && !(match->mode & GR_DELETED))
54137 + return match;
54138 + else
54139 + return NULL;
54140 +}
54141 +
54142 +static struct name_entry *
54143 +lookup_name_entry(const char *name)
54144 +{
54145 + unsigned int len = strlen(name);
54146 + unsigned int key = full_name_hash(name, len);
54147 + unsigned int index = key % name_set.n_size;
54148 + struct name_entry *match;
54149 +
54150 + match = name_set.n_hash[index];
54151 +
54152 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
54153 + match = match->next;
54154 +
54155 + return match;
54156 +}
54157 +
54158 +static struct name_entry *
54159 +lookup_name_entry_create(const char *name)
54160 +{
54161 + unsigned int len = strlen(name);
54162 + unsigned int key = full_name_hash(name, len);
54163 + unsigned int index = key % name_set.n_size;
54164 + struct name_entry *match;
54165 +
54166 + match = name_set.n_hash[index];
54167 +
54168 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
54169 + !match->deleted))
54170 + match = match->next;
54171 +
54172 + if (match && match->deleted)
54173 + return match;
54174 +
54175 + match = name_set.n_hash[index];
54176 +
54177 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
54178 + match->deleted))
54179 + match = match->next;
54180 +
54181 + if (match && !match->deleted)
54182 + return match;
54183 + else
54184 + return NULL;
54185 +}
54186 +
54187 +static struct inodev_entry *
54188 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
54189 +{
54190 + unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
54191 + struct inodev_entry *match;
54192 +
54193 + match = inodev_set.i_hash[index];
54194 +
54195 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
54196 + match = match->next;
54197 +
54198 + return match;
54199 +}
54200 +
54201 +static void
54202 +insert_inodev_entry(struct inodev_entry *entry)
54203 +{
54204 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
54205 + inodev_set.i_size);
54206 + struct inodev_entry **curr;
54207 +
54208 + entry->prev = NULL;
54209 +
54210 + curr = &inodev_set.i_hash[index];
54211 + if (*curr != NULL)
54212 + (*curr)->prev = entry;
54213 +
54214 + entry->next = *curr;
54215 + *curr = entry;
54216 +
54217 + return;
54218 +}
54219 +
54220 +static void
54221 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
54222 +{
54223 + unsigned int index =
54224 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
54225 + struct acl_role_label **curr;
54226 + struct acl_role_label *tmp, *tmp2;
54227 +
54228 + curr = &acl_role_set.r_hash[index];
54229 +
54230 + /* simple case, slot is empty, just set it to our role */
54231 + if (*curr == NULL) {
54232 + *curr = role;
54233 + } else {
54234 + /* example:
54235 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
54236 + 2 -> 3
54237 + */
54238 + /* first check to see if we can already be reached via this slot */
54239 + tmp = *curr;
54240 + while (tmp && tmp != role)
54241 + tmp = tmp->next;
54242 + if (tmp == role) {
54243 + /* we don't need to add ourselves to this slot's chain */
54244 + return;
54245 + }
54246 + /* we need to add ourselves to this chain, two cases */
54247 + if (role->next == NULL) {
54248 + /* simple case, append the current chain to our role */
54249 + role->next = *curr;
54250 + *curr = role;
54251 + } else {
54252 + /* 1 -> 2 -> 3 -> 4
54253 + 2 -> 3 -> 4
54254 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
54255 + */
54256 + /* trickier case: walk our role's chain until we find
54257 + the role for the start of the current slot's chain */
54258 + tmp = role;
54259 + tmp2 = *curr;
54260 + while (tmp->next && tmp->next != tmp2)
54261 + tmp = tmp->next;
54262 + if (tmp->next == tmp2) {
54263 + /* from example above, we found 3, so just
54264 + replace this slot's chain with ours */
54265 + *curr = role;
54266 + } else {
54267 + /* we didn't find a subset of our role's chain
54268 + in the current slot's chain, so append their
54269 + chain to ours, and set us as the first role in
54270 + the slot's chain
54271 +
54272 + we could fold this case with the case above,
54273 + but making it explicit for clarity
54274 + */
54275 + tmp->next = tmp2;
54276 + *curr = role;
54277 + }
54278 + }
54279 + }
54280 +
54281 + return;
54282 +}
54283 +
54284 +static void
54285 +insert_acl_role_label(struct acl_role_label *role)
54286 +{
54287 + int i;
54288 +
54289 + if (role_list == NULL) {
54290 + role_list = role;
54291 + role->prev = NULL;
54292 + } else {
54293 + role->prev = role_list;
54294 + role_list = role;
54295 + }
54296 +
54297 + /* used for hash chains */
54298 + role->next = NULL;
54299 +
54300 + if (role->roletype & GR_ROLE_DOMAIN) {
54301 + for (i = 0; i < role->domain_child_num; i++)
54302 + __insert_acl_role_label(role, role->domain_children[i]);
54303 + } else
54304 + __insert_acl_role_label(role, role->uidgid);
54305 +}
54306 +
54307 +static int
54308 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
54309 +{
54310 + struct name_entry **curr, *nentry;
54311 + struct inodev_entry *ientry;
54312 + unsigned int len = strlen(name);
54313 + unsigned int key = full_name_hash(name, len);
54314 + unsigned int index = key % name_set.n_size;
54315 +
54316 + curr = &name_set.n_hash[index];
54317 +
54318 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
54319 + curr = &((*curr)->next);
54320 +
54321 + if (*curr != NULL)
54322 + return 1;
54323 +
54324 + nentry = acl_alloc(sizeof (struct name_entry));
54325 + if (nentry == NULL)
54326 + return 0;
54327 + ientry = acl_alloc(sizeof (struct inodev_entry));
54328 + if (ientry == NULL)
54329 + return 0;
54330 + ientry->nentry = nentry;
54331 +
54332 + nentry->key = key;
54333 + nentry->name = name;
54334 + nentry->inode = inode;
54335 + nentry->device = device;
54336 + nentry->len = len;
54337 + nentry->deleted = deleted;
54338 +
54339 + nentry->prev = NULL;
54340 + curr = &name_set.n_hash[index];
54341 + if (*curr != NULL)
54342 + (*curr)->prev = nentry;
54343 + nentry->next = *curr;
54344 + *curr = nentry;
54345 +
54346 + /* insert us into the table searchable by inode/dev */
54347 + insert_inodev_entry(ientry);
54348 +
54349 + return 1;
54350 +}
54351 +
54352 +static void
54353 +insert_acl_obj_label(struct acl_object_label *obj,
54354 + struct acl_subject_label *subj)
54355 +{
54356 + unsigned int index =
54357 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
54358 + struct acl_object_label **curr;
54359 +
54360 +
54361 + obj->prev = NULL;
54362 +
54363 + curr = &subj->obj_hash[index];
54364 + if (*curr != NULL)
54365 + (*curr)->prev = obj;
54366 +
54367 + obj->next = *curr;
54368 + *curr = obj;
54369 +
54370 + return;
54371 +}
54372 +
54373 +static void
54374 +insert_acl_subj_label(struct acl_subject_label *obj,
54375 + struct acl_role_label *role)
54376 +{
54377 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
54378 + struct acl_subject_label **curr;
54379 +
54380 + obj->prev = NULL;
54381 +
54382 + curr = &role->subj_hash[index];
54383 + if (*curr != NULL)
54384 + (*curr)->prev = obj;
54385 +
54386 + obj->next = *curr;
54387 + *curr = obj;
54388 +
54389 + return;
54390 +}
54391 +
54392 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
54393 +
54394 +static void *
54395 +create_table(__u32 * len, int elementsize)
54396 +{
54397 + unsigned int table_sizes[] = {
54398 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
54399 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
54400 + 4194301, 8388593, 16777213, 33554393, 67108859
54401 + };
54402 + void *newtable = NULL;
54403 + unsigned int pwr = 0;
54404 +
54405 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
54406 + table_sizes[pwr] <= *len)
54407 + pwr++;
54408 +
54409 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
54410 + return newtable;
54411 +
54412 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
54413 + newtable =
54414 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
54415 + else
54416 + newtable = vmalloc(table_sizes[pwr] * elementsize);
54417 +
54418 + *len = table_sizes[pwr];
54419 +
54420 + return newtable;
54421 +}
54422 +
54423 +static int
54424 +init_variables(const struct gr_arg *arg)
54425 +{
54426 + struct task_struct *reaper = init_pid_ns.child_reaper;
54427 + unsigned int stacksize;
54428 +
54429 + subj_map_set.s_size = arg->role_db.num_subjects;
54430 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
54431 + name_set.n_size = arg->role_db.num_objects;
54432 + inodev_set.i_size = arg->role_db.num_objects;
54433 +
54434 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
54435 + !name_set.n_size || !inodev_set.i_size)
54436 + return 1;
54437 +
54438 + if (!gr_init_uidset())
54439 + return 1;
54440 +
54441 + /* set up the stack that holds allocation info */
54442 +
54443 + stacksize = arg->role_db.num_pointers + 5;
54444 +
54445 + if (!acl_alloc_stack_init(stacksize))
54446 + return 1;
54447 +
54448 + /* grab reference for the real root dentry and vfsmount */
54449 + get_fs_root(reaper->fs, &real_root);
54450 +
54451 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54452 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
54453 +#endif
54454 +
54455 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
54456 + if (fakefs_obj_rw == NULL)
54457 + return 1;
54458 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
54459 +
54460 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
54461 + if (fakefs_obj_rwx == NULL)
54462 + return 1;
54463 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
54464 +
54465 + subj_map_set.s_hash =
54466 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
54467 + acl_role_set.r_hash =
54468 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
54469 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
54470 + inodev_set.i_hash =
54471 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
54472 +
54473 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
54474 + !name_set.n_hash || !inodev_set.i_hash)
54475 + return 1;
54476 +
54477 + memset(subj_map_set.s_hash, 0,
54478 + sizeof(struct subject_map *) * subj_map_set.s_size);
54479 + memset(acl_role_set.r_hash, 0,
54480 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
54481 + memset(name_set.n_hash, 0,
54482 + sizeof (struct name_entry *) * name_set.n_size);
54483 + memset(inodev_set.i_hash, 0,
54484 + sizeof (struct inodev_entry *) * inodev_set.i_size);
54485 +
54486 + return 0;
54487 +}
54488 +
54489 +/* free information not needed after startup
54490 + currently contains user->kernel pointer mappings for subjects
54491 +*/
54492 +
54493 +static void
54494 +free_init_variables(void)
54495 +{
54496 + __u32 i;
54497 +
54498 + if (subj_map_set.s_hash) {
54499 + for (i = 0; i < subj_map_set.s_size; i++) {
54500 + if (subj_map_set.s_hash[i]) {
54501 + kfree(subj_map_set.s_hash[i]);
54502 + subj_map_set.s_hash[i] = NULL;
54503 + }
54504 + }
54505 +
54506 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
54507 + PAGE_SIZE)
54508 + kfree(subj_map_set.s_hash);
54509 + else
54510 + vfree(subj_map_set.s_hash);
54511 + }
54512 +
54513 + return;
54514 +}
54515 +
54516 +static void
54517 +free_variables(void)
54518 +{
54519 + struct acl_subject_label *s;
54520 + struct acl_role_label *r;
54521 + struct task_struct *task, *task2;
54522 + unsigned int x;
54523 +
54524 + gr_clear_learn_entries();
54525 +
54526 + read_lock(&tasklist_lock);
54527 + do_each_thread(task2, task) {
54528 + task->acl_sp_role = 0;
54529 + task->acl_role_id = 0;
54530 + task->acl = NULL;
54531 + task->role = NULL;
54532 + } while_each_thread(task2, task);
54533 + read_unlock(&tasklist_lock);
54534 +
54535 + /* release the reference to the real root dentry and vfsmount */
54536 + path_put(&real_root);
54537 + memset(&real_root, 0, sizeof(real_root));
54538 +
54539 + /* free all object hash tables */
54540 +
54541 + FOR_EACH_ROLE_START(r)
54542 + if (r->subj_hash == NULL)
54543 + goto next_role;
54544 + FOR_EACH_SUBJECT_START(r, s, x)
54545 + if (s->obj_hash == NULL)
54546 + break;
54547 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54548 + kfree(s->obj_hash);
54549 + else
54550 + vfree(s->obj_hash);
54551 + FOR_EACH_SUBJECT_END(s, x)
54552 + FOR_EACH_NESTED_SUBJECT_START(r, s)
54553 + if (s->obj_hash == NULL)
54554 + break;
54555 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54556 + kfree(s->obj_hash);
54557 + else
54558 + vfree(s->obj_hash);
54559 + FOR_EACH_NESTED_SUBJECT_END(s)
54560 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
54561 + kfree(r->subj_hash);
54562 + else
54563 + vfree(r->subj_hash);
54564 + r->subj_hash = NULL;
54565 +next_role:
54566 + FOR_EACH_ROLE_END(r)
54567 +
54568 + acl_free_all();
54569 +
54570 + if (acl_role_set.r_hash) {
54571 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
54572 + PAGE_SIZE)
54573 + kfree(acl_role_set.r_hash);
54574 + else
54575 + vfree(acl_role_set.r_hash);
54576 + }
54577 + if (name_set.n_hash) {
54578 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
54579 + PAGE_SIZE)
54580 + kfree(name_set.n_hash);
54581 + else
54582 + vfree(name_set.n_hash);
54583 + }
54584 +
54585 + if (inodev_set.i_hash) {
54586 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
54587 + PAGE_SIZE)
54588 + kfree(inodev_set.i_hash);
54589 + else
54590 + vfree(inodev_set.i_hash);
54591 + }
54592 +
54593 + gr_free_uidset();
54594 +
54595 + memset(&name_set, 0, sizeof (struct name_db));
54596 + memset(&inodev_set, 0, sizeof (struct inodev_db));
54597 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
54598 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
54599 +
54600 + default_role = NULL;
54601 + kernel_role = NULL;
54602 + role_list = NULL;
54603 +
54604 + return;
54605 +}
54606 +
54607 +static __u32
54608 +count_user_objs(struct acl_object_label *userp)
54609 +{
54610 + struct acl_object_label o_tmp;
54611 + __u32 num = 0;
54612 +
54613 + while (userp) {
54614 + if (copy_from_user(&o_tmp, userp,
54615 + sizeof (struct acl_object_label)))
54616 + break;
54617 +
54618 + userp = o_tmp.prev;
54619 + num++;
54620 + }
54621 +
54622 + return num;
54623 +}
54624 +
54625 +static struct acl_subject_label *
54626 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
54627 +
54628 +static int
54629 +copy_user_glob(struct acl_object_label *obj)
54630 +{
54631 + struct acl_object_label *g_tmp, **guser;
54632 + unsigned int len;
54633 + char *tmp;
54634 +
54635 + if (obj->globbed == NULL)
54636 + return 0;
54637 +
54638 + guser = &obj->globbed;
54639 + while (*guser) {
54640 + g_tmp = (struct acl_object_label *)
54641 + acl_alloc(sizeof (struct acl_object_label));
54642 + if (g_tmp == NULL)
54643 + return -ENOMEM;
54644 +
54645 + if (copy_from_user(g_tmp, *guser,
54646 + sizeof (struct acl_object_label)))
54647 + return -EFAULT;
54648 +
54649 + len = strnlen_user(g_tmp->filename, PATH_MAX);
54650 +
54651 + if (!len || len >= PATH_MAX)
54652 + return -EINVAL;
54653 +
54654 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54655 + return -ENOMEM;
54656 +
54657 + if (copy_from_user(tmp, g_tmp->filename, len))
54658 + return -EFAULT;
54659 + tmp[len-1] = '\0';
54660 + g_tmp->filename = tmp;
54661 +
54662 + *guser = g_tmp;
54663 + guser = &(g_tmp->next);
54664 + }
54665 +
54666 + return 0;
54667 +}
54668 +
54669 +static int
54670 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
54671 + struct acl_role_label *role)
54672 +{
54673 + struct acl_object_label *o_tmp;
54674 + unsigned int len;
54675 + int ret;
54676 + char *tmp;
54677 +
54678 + while (userp) {
54679 + if ((o_tmp = (struct acl_object_label *)
54680 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
54681 + return -ENOMEM;
54682 +
54683 + if (copy_from_user(o_tmp, userp,
54684 + sizeof (struct acl_object_label)))
54685 + return -EFAULT;
54686 +
54687 + userp = o_tmp->prev;
54688 +
54689 + len = strnlen_user(o_tmp->filename, PATH_MAX);
54690 +
54691 + if (!len || len >= PATH_MAX)
54692 + return -EINVAL;
54693 +
54694 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54695 + return -ENOMEM;
54696 +
54697 + if (copy_from_user(tmp, o_tmp->filename, len))
54698 + return -EFAULT;
54699 + tmp[len-1] = '\0';
54700 + o_tmp->filename = tmp;
54701 +
54702 + insert_acl_obj_label(o_tmp, subj);
54703 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
54704 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
54705 + return -ENOMEM;
54706 +
54707 + ret = copy_user_glob(o_tmp);
54708 + if (ret)
54709 + return ret;
54710 +
54711 + if (o_tmp->nested) {
54712 + int already_copied;
54713 +
54714 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
54715 + if (IS_ERR(o_tmp->nested))
54716 + return PTR_ERR(o_tmp->nested);
54717 +
54718 + /* insert into nested subject list if we haven't copied this one yet
54719 + to prevent duplicate entries */
54720 + if (!already_copied) {
54721 + o_tmp->nested->next = role->hash->first;
54722 + role->hash->first = o_tmp->nested;
54723 + }
54724 + }
54725 + }
54726 +
54727 + return 0;
54728 +}
54729 +
54730 +static __u32
54731 +count_user_subjs(struct acl_subject_label *userp)
54732 +{
54733 + struct acl_subject_label s_tmp;
54734 + __u32 num = 0;
54735 +
54736 + while (userp) {
54737 + if (copy_from_user(&s_tmp, userp,
54738 + sizeof (struct acl_subject_label)))
54739 + break;
54740 +
54741 + userp = s_tmp.prev;
54742 + }
54743 +
54744 + return num;
54745 +}
54746 +
54747 +static int
54748 +copy_user_allowedips(struct acl_role_label *rolep)
54749 +{
54750 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
54751 +
54752 + ruserip = rolep->allowed_ips;
54753 +
54754 + while (ruserip) {
54755 + rlast = rtmp;
54756 +
54757 + if ((rtmp = (struct role_allowed_ip *)
54758 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
54759 + return -ENOMEM;
54760 +
54761 + if (copy_from_user(rtmp, ruserip,
54762 + sizeof (struct role_allowed_ip)))
54763 + return -EFAULT;
54764 +
54765 + ruserip = rtmp->prev;
54766 +
54767 + if (!rlast) {
54768 + rtmp->prev = NULL;
54769 + rolep->allowed_ips = rtmp;
54770 + } else {
54771 + rlast->next = rtmp;
54772 + rtmp->prev = rlast;
54773 + }
54774 +
54775 + if (!ruserip)
54776 + rtmp->next = NULL;
54777 + }
54778 +
54779 + return 0;
54780 +}
54781 +
54782 +static int
54783 +copy_user_transitions(struct acl_role_label *rolep)
54784 +{
54785 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
54786 +
54787 + unsigned int len;
54788 + char *tmp;
54789 +
54790 + rusertp = rolep->transitions;
54791 +
54792 + while (rusertp) {
54793 + rlast = rtmp;
54794 +
54795 + if ((rtmp = (struct role_transition *)
54796 + acl_alloc(sizeof (struct role_transition))) == NULL)
54797 + return -ENOMEM;
54798 +
54799 + if (copy_from_user(rtmp, rusertp,
54800 + sizeof (struct role_transition)))
54801 + return -EFAULT;
54802 +
54803 + rusertp = rtmp->prev;
54804 +
54805 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
54806 +
54807 + if (!len || len >= GR_SPROLE_LEN)
54808 + return -EINVAL;
54809 +
54810 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54811 + return -ENOMEM;
54812 +
54813 + if (copy_from_user(tmp, rtmp->rolename, len))
54814 + return -EFAULT;
54815 + tmp[len-1] = '\0';
54816 + rtmp->rolename = tmp;
54817 +
54818 + if (!rlast) {
54819 + rtmp->prev = NULL;
54820 + rolep->transitions = rtmp;
54821 + } else {
54822 + rlast->next = rtmp;
54823 + rtmp->prev = rlast;
54824 + }
54825 +
54826 + if (!rusertp)
54827 + rtmp->next = NULL;
54828 + }
54829 +
54830 + return 0;
54831 +}
54832 +
54833 +static struct acl_subject_label *
54834 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
54835 +{
54836 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
54837 + unsigned int len;
54838 + char *tmp;
54839 + __u32 num_objs;
54840 + struct acl_ip_label **i_tmp, *i_utmp2;
54841 + struct gr_hash_struct ghash;
54842 + struct subject_map *subjmap;
54843 + unsigned int i_num;
54844 + int err;
54845 +
54846 + if (already_copied != NULL)
54847 + *already_copied = 0;
54848 +
54849 + s_tmp = lookup_subject_map(userp);
54850 +
54851 + /* we've already copied this subject into the kernel, just return
54852 + the reference to it, and don't copy it over again
54853 + */
54854 + if (s_tmp) {
54855 + if (already_copied != NULL)
54856 + *already_copied = 1;
54857 + return(s_tmp);
54858 + }
54859 +
54860 + if ((s_tmp = (struct acl_subject_label *)
54861 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
54862 + return ERR_PTR(-ENOMEM);
54863 +
54864 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
54865 + if (subjmap == NULL)
54866 + return ERR_PTR(-ENOMEM);
54867 +
54868 + subjmap->user = userp;
54869 + subjmap->kernel = s_tmp;
54870 + insert_subj_map_entry(subjmap);
54871 +
54872 + if (copy_from_user(s_tmp, userp,
54873 + sizeof (struct acl_subject_label)))
54874 + return ERR_PTR(-EFAULT);
54875 +
54876 + len = strnlen_user(s_tmp->filename, PATH_MAX);
54877 +
54878 + if (!len || len >= PATH_MAX)
54879 + return ERR_PTR(-EINVAL);
54880 +
54881 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54882 + return ERR_PTR(-ENOMEM);
54883 +
54884 + if (copy_from_user(tmp, s_tmp->filename, len))
54885 + return ERR_PTR(-EFAULT);
54886 + tmp[len-1] = '\0';
54887 + s_tmp->filename = tmp;
54888 +
54889 + if (!strcmp(s_tmp->filename, "/"))
54890 + role->root_label = s_tmp;
54891 +
54892 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
54893 + return ERR_PTR(-EFAULT);
54894 +
54895 + /* copy user and group transition tables */
54896 +
54897 + if (s_tmp->user_trans_num) {
54898 + uid_t *uidlist;
54899 +
54900 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
54901 + if (uidlist == NULL)
54902 + return ERR_PTR(-ENOMEM);
54903 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
54904 + return ERR_PTR(-EFAULT);
54905 +
54906 + s_tmp->user_transitions = uidlist;
54907 + }
54908 +
54909 + if (s_tmp->group_trans_num) {
54910 + gid_t *gidlist;
54911 +
54912 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
54913 + if (gidlist == NULL)
54914 + return ERR_PTR(-ENOMEM);
54915 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
54916 + return ERR_PTR(-EFAULT);
54917 +
54918 + s_tmp->group_transitions = gidlist;
54919 + }
54920 +
54921 + /* set up object hash table */
54922 + num_objs = count_user_objs(ghash.first);
54923 +
54924 + s_tmp->obj_hash_size = num_objs;
54925 + s_tmp->obj_hash =
54926 + (struct acl_object_label **)
54927 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
54928 +
54929 + if (!s_tmp->obj_hash)
54930 + return ERR_PTR(-ENOMEM);
54931 +
54932 + memset(s_tmp->obj_hash, 0,
54933 + s_tmp->obj_hash_size *
54934 + sizeof (struct acl_object_label *));
54935 +
54936 + /* add in objects */
54937 + err = copy_user_objs(ghash.first, s_tmp, role);
54938 +
54939 + if (err)
54940 + return ERR_PTR(err);
54941 +
54942 + /* set pointer for parent subject */
54943 + if (s_tmp->parent_subject) {
54944 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
54945 +
54946 + if (IS_ERR(s_tmp2))
54947 + return s_tmp2;
54948 +
54949 + s_tmp->parent_subject = s_tmp2;
54950 + }
54951 +
54952 + /* add in ip acls */
54953 +
54954 + if (!s_tmp->ip_num) {
54955 + s_tmp->ips = NULL;
54956 + goto insert;
54957 + }
54958 +
54959 + i_tmp =
54960 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
54961 + sizeof (struct acl_ip_label *));
54962 +
54963 + if (!i_tmp)
54964 + return ERR_PTR(-ENOMEM);
54965 +
54966 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
54967 + *(i_tmp + i_num) =
54968 + (struct acl_ip_label *)
54969 + acl_alloc(sizeof (struct acl_ip_label));
54970 + if (!*(i_tmp + i_num))
54971 + return ERR_PTR(-ENOMEM);
54972 +
54973 + if (copy_from_user
54974 + (&i_utmp2, s_tmp->ips + i_num,
54975 + sizeof (struct acl_ip_label *)))
54976 + return ERR_PTR(-EFAULT);
54977 +
54978 + if (copy_from_user
54979 + (*(i_tmp + i_num), i_utmp2,
54980 + sizeof (struct acl_ip_label)))
54981 + return ERR_PTR(-EFAULT);
54982 +
54983 + if ((*(i_tmp + i_num))->iface == NULL)
54984 + continue;
54985 +
54986 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
54987 + if (!len || len >= IFNAMSIZ)
54988 + return ERR_PTR(-EINVAL);
54989 + tmp = acl_alloc(len);
54990 + if (tmp == NULL)
54991 + return ERR_PTR(-ENOMEM);
54992 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
54993 + return ERR_PTR(-EFAULT);
54994 + (*(i_tmp + i_num))->iface = tmp;
54995 + }
54996 +
54997 + s_tmp->ips = i_tmp;
54998 +
54999 +insert:
55000 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
55001 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
55002 + return ERR_PTR(-ENOMEM);
55003 +
55004 + return s_tmp;
55005 +}
55006 +
55007 +static int
55008 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
55009 +{
55010 + struct acl_subject_label s_pre;
55011 + struct acl_subject_label * ret;
55012 + int err;
55013 +
55014 + while (userp) {
55015 + if (copy_from_user(&s_pre, userp,
55016 + sizeof (struct acl_subject_label)))
55017 + return -EFAULT;
55018 +
55019 + ret = do_copy_user_subj(userp, role, NULL);
55020 +
55021 + err = PTR_ERR(ret);
55022 + if (IS_ERR(ret))
55023 + return err;
55024 +
55025 + insert_acl_subj_label(ret, role);
55026 +
55027 + userp = s_pre.prev;
55028 + }
55029 +
55030 + return 0;
55031 +}
55032 +
55033 +static int
55034 +copy_user_acl(struct gr_arg *arg)
55035 +{
55036 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
55037 + struct acl_subject_label *subj_list;
55038 + struct sprole_pw *sptmp;
55039 + struct gr_hash_struct *ghash;
55040 + uid_t *domainlist;
55041 + unsigned int r_num;
55042 + unsigned int len;
55043 + char *tmp;
55044 + int err = 0;
55045 + __u16 i;
55046 + __u32 num_subjs;
55047 +
55048 + /* we need a default and kernel role */
55049 + if (arg->role_db.num_roles < 2)
55050 + return -EINVAL;
55051 +
55052 + /* copy special role authentication info from userspace */
55053 +
55054 + num_sprole_pws = arg->num_sprole_pws;
55055 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
55056 +
55057 + if (!acl_special_roles && num_sprole_pws)
55058 + return -ENOMEM;
55059 +
55060 + for (i = 0; i < num_sprole_pws; i++) {
55061 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
55062 + if (!sptmp)
55063 + return -ENOMEM;
55064 + if (copy_from_user(sptmp, arg->sprole_pws + i,
55065 + sizeof (struct sprole_pw)))
55066 + return -EFAULT;
55067 +
55068 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
55069 +
55070 + if (!len || len >= GR_SPROLE_LEN)
55071 + return -EINVAL;
55072 +
55073 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55074 + return -ENOMEM;
55075 +
55076 + if (copy_from_user(tmp, sptmp->rolename, len))
55077 + return -EFAULT;
55078 +
55079 + tmp[len-1] = '\0';
55080 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55081 + printk(KERN_ALERT "Copying special role %s\n", tmp);
55082 +#endif
55083 + sptmp->rolename = tmp;
55084 + acl_special_roles[i] = sptmp;
55085 + }
55086 +
55087 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
55088 +
55089 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
55090 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
55091 +
55092 + if (!r_tmp)
55093 + return -ENOMEM;
55094 +
55095 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
55096 + sizeof (struct acl_role_label *)))
55097 + return -EFAULT;
55098 +
55099 + if (copy_from_user(r_tmp, r_utmp2,
55100 + sizeof (struct acl_role_label)))
55101 + return -EFAULT;
55102 +
55103 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
55104 +
55105 + if (!len || len >= PATH_MAX)
55106 + return -EINVAL;
55107 +
55108 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55109 + return -ENOMEM;
55110 +
55111 + if (copy_from_user(tmp, r_tmp->rolename, len))
55112 + return -EFAULT;
55113 +
55114 + tmp[len-1] = '\0';
55115 + r_tmp->rolename = tmp;
55116 +
55117 + if (!strcmp(r_tmp->rolename, "default")
55118 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
55119 + default_role = r_tmp;
55120 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
55121 + kernel_role = r_tmp;
55122 + }
55123 +
55124 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
55125 + return -ENOMEM;
55126 +
55127 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
55128 + return -EFAULT;
55129 +
55130 + r_tmp->hash = ghash;
55131 +
55132 + num_subjs = count_user_subjs(r_tmp->hash->first);
55133 +
55134 + r_tmp->subj_hash_size = num_subjs;
55135 + r_tmp->subj_hash =
55136 + (struct acl_subject_label **)
55137 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
55138 +
55139 + if (!r_tmp->subj_hash)
55140 + return -ENOMEM;
55141 +
55142 + err = copy_user_allowedips(r_tmp);
55143 + if (err)
55144 + return err;
55145 +
55146 + /* copy domain info */
55147 + if (r_tmp->domain_children != NULL) {
55148 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
55149 + if (domainlist == NULL)
55150 + return -ENOMEM;
55151 +
55152 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
55153 + return -EFAULT;
55154 +
55155 + r_tmp->domain_children = domainlist;
55156 + }
55157 +
55158 + err = copy_user_transitions(r_tmp);
55159 + if (err)
55160 + return err;
55161 +
55162 + memset(r_tmp->subj_hash, 0,
55163 + r_tmp->subj_hash_size *
55164 + sizeof (struct acl_subject_label *));
55165 +
55166 + /* acquire the list of subjects, then NULL out
55167 + the list prior to parsing the subjects for this role,
55168 + as during this parsing the list is replaced with a list
55169 + of *nested* subjects for the role
55170 + */
55171 + subj_list = r_tmp->hash->first;
55172 +
55173 + /* set nested subject list to null */
55174 + r_tmp->hash->first = NULL;
55175 +
55176 + err = copy_user_subjs(subj_list, r_tmp);
55177 +
55178 + if (err)
55179 + return err;
55180 +
55181 + insert_acl_role_label(r_tmp);
55182 + }
55183 +
55184 + if (default_role == NULL || kernel_role == NULL)
55185 + return -EINVAL;
55186 +
55187 + return err;
55188 +}
55189 +
55190 +static int
55191 +gracl_init(struct gr_arg *args)
55192 +{
55193 + int error = 0;
55194 +
55195 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
55196 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
55197 +
55198 + if (init_variables(args)) {
55199 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
55200 + error = -ENOMEM;
55201 + free_variables();
55202 + goto out;
55203 + }
55204 +
55205 + error = copy_user_acl(args);
55206 + free_init_variables();
55207 + if (error) {
55208 + free_variables();
55209 + goto out;
55210 + }
55211 +
55212 + if ((error = gr_set_acls(0))) {
55213 + free_variables();
55214 + goto out;
55215 + }
55216 +
55217 + pax_open_kernel();
55218 + gr_status |= GR_READY;
55219 + pax_close_kernel();
55220 +
55221 + out:
55222 + return error;
55223 +}
55224 +
55225 +/* derived from glibc fnmatch() 0: match, 1: no match*/
55226 +
55227 +static int
55228 +glob_match(const char *p, const char *n)
55229 +{
55230 + char c;
55231 +
55232 + while ((c = *p++) != '\0') {
55233 + switch (c) {
55234 + case '?':
55235 + if (*n == '\0')
55236 + return 1;
55237 + else if (*n == '/')
55238 + return 1;
55239 + break;
55240 + case '\\':
55241 + if (*n != c)
55242 + return 1;
55243 + break;
55244 + case '*':
55245 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
55246 + if (*n == '/')
55247 + return 1;
55248 + else if (c == '?') {
55249 + if (*n == '\0')
55250 + return 1;
55251 + else
55252 + ++n;
55253 + }
55254 + }
55255 + if (c == '\0') {
55256 + return 0;
55257 + } else {
55258 + const char *endp;
55259 +
55260 + if ((endp = strchr(n, '/')) == NULL)
55261 + endp = n + strlen(n);
55262 +
55263 + if (c == '[') {
55264 + for (--p; n < endp; ++n)
55265 + if (!glob_match(p, n))
55266 + return 0;
55267 + } else if (c == '/') {
55268 + while (*n != '\0' && *n != '/')
55269 + ++n;
55270 + if (*n == '/' && !glob_match(p, n + 1))
55271 + return 0;
55272 + } else {
55273 + for (--p; n < endp; ++n)
55274 + if (*n == c && !glob_match(p, n))
55275 + return 0;
55276 + }
55277 +
55278 + return 1;
55279 + }
55280 + case '[':
55281 + {
55282 + int not;
55283 + char cold;
55284 +
55285 + if (*n == '\0' || *n == '/')
55286 + return 1;
55287 +
55288 + not = (*p == '!' || *p == '^');
55289 + if (not)
55290 + ++p;
55291 +
55292 + c = *p++;
55293 + for (;;) {
55294 + unsigned char fn = (unsigned char)*n;
55295 +
55296 + if (c == '\0')
55297 + return 1;
55298 + else {
55299 + if (c == fn)
55300 + goto matched;
55301 + cold = c;
55302 + c = *p++;
55303 +
55304 + if (c == '-' && *p != ']') {
55305 + unsigned char cend = *p++;
55306 +
55307 + if (cend == '\0')
55308 + return 1;
55309 +
55310 + if (cold <= fn && fn <= cend)
55311 + goto matched;
55312 +
55313 + c = *p++;
55314 + }
55315 + }
55316 +
55317 + if (c == ']')
55318 + break;
55319 + }
55320 + if (!not)
55321 + return 1;
55322 + break;
55323 + matched:
55324 + while (c != ']') {
55325 + if (c == '\0')
55326 + return 1;
55327 +
55328 + c = *p++;
55329 + }
55330 + if (not)
55331 + return 1;
55332 + }
55333 + break;
55334 + default:
55335 + if (c != *n)
55336 + return 1;
55337 + }
55338 +
55339 + ++n;
55340 + }
55341 +
55342 + if (*n == '\0')
55343 + return 0;
55344 +
55345 + if (*n == '/')
55346 + return 0;
55347 +
55348 + return 1;
55349 +}
55350 +
55351 +static struct acl_object_label *
55352 +chk_glob_label(struct acl_object_label *globbed,
55353 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
55354 +{
55355 + struct acl_object_label *tmp;
55356 +
55357 + if (*path == NULL)
55358 + *path = gr_to_filename_nolock(dentry, mnt);
55359 +
55360 + tmp = globbed;
55361 +
55362 + while (tmp) {
55363 + if (!glob_match(tmp->filename, *path))
55364 + return tmp;
55365 + tmp = tmp->next;
55366 + }
55367 +
55368 + return NULL;
55369 +}
55370 +
55371 +static struct acl_object_label *
55372 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
55373 + const ino_t curr_ino, const dev_t curr_dev,
55374 + const struct acl_subject_label *subj, char **path, const int checkglob)
55375 +{
55376 + struct acl_subject_label *tmpsubj;
55377 + struct acl_object_label *retval;
55378 + struct acl_object_label *retval2;
55379 +
55380 + tmpsubj = (struct acl_subject_label *) subj;
55381 + read_lock(&gr_inode_lock);
55382 + do {
55383 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
55384 + if (retval) {
55385 + if (checkglob && retval->globbed) {
55386 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
55387 + if (retval2)
55388 + retval = retval2;
55389 + }
55390 + break;
55391 + }
55392 + } while ((tmpsubj = tmpsubj->parent_subject));
55393 + read_unlock(&gr_inode_lock);
55394 +
55395 + return retval;
55396 +}
55397 +
55398 +static __inline__ struct acl_object_label *
55399 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
55400 + struct dentry *curr_dentry,
55401 + const struct acl_subject_label *subj, char **path, const int checkglob)
55402 +{
55403 + int newglob = checkglob;
55404 + ino_t inode;
55405 + dev_t device;
55406 +
55407 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
55408 + as we don't want a / * rule to match instead of the / object
55409 + don't do this for create lookups that call this function though, since they're looking up
55410 + on the parent and thus need globbing checks on all paths
55411 + */
55412 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
55413 + newglob = GR_NO_GLOB;
55414 +
55415 + spin_lock(&curr_dentry->d_lock);
55416 + inode = curr_dentry->d_inode->i_ino;
55417 + device = __get_dev(curr_dentry);
55418 + spin_unlock(&curr_dentry->d_lock);
55419 +
55420 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
55421 +}
55422 +
55423 +static struct acl_object_label *
55424 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55425 + const struct acl_subject_label *subj, char *path, const int checkglob)
55426 +{
55427 + struct dentry *dentry = (struct dentry *) l_dentry;
55428 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55429 + struct mount *real_mnt = real_mount(mnt);
55430 + struct acl_object_label *retval;
55431 + struct dentry *parent;
55432 +
55433 + write_seqlock(&rename_lock);
55434 + br_read_lock(&vfsmount_lock);
55435 +
55436 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
55437 +#ifdef CONFIG_NET
55438 + mnt == sock_mnt ||
55439 +#endif
55440 +#ifdef CONFIG_HUGETLBFS
55441 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
55442 +#endif
55443 + /* ignore Eric Biederman */
55444 + IS_PRIVATE(l_dentry->d_inode))) {
55445 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
55446 + goto out;
55447 + }
55448 +
55449 + for (;;) {
55450 + if (dentry == real_root.dentry && mnt == real_root.mnt)
55451 + break;
55452 +
55453 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55454 + if (!mnt_has_parent(real_mnt))
55455 + break;
55456 +
55457 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55458 + if (retval != NULL)
55459 + goto out;
55460 +
55461 + dentry = real_mnt->mnt_mountpoint;
55462 + real_mnt = real_mnt->mnt_parent;
55463 + mnt = &real_mnt->mnt;
55464 + continue;
55465 + }
55466 +
55467 + parent = dentry->d_parent;
55468 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55469 + if (retval != NULL)
55470 + goto out;
55471 +
55472 + dentry = parent;
55473 + }
55474 +
55475 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55476 +
55477 + /* real_root is pinned so we don't have to hold a reference */
55478 + if (retval == NULL)
55479 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
55480 +out:
55481 + br_read_unlock(&vfsmount_lock);
55482 + write_sequnlock(&rename_lock);
55483 +
55484 + BUG_ON(retval == NULL);
55485 +
55486 + return retval;
55487 +}
55488 +
55489 +static __inline__ struct acl_object_label *
55490 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55491 + const struct acl_subject_label *subj)
55492 +{
55493 + char *path = NULL;
55494 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
55495 +}
55496 +
55497 +static __inline__ struct acl_object_label *
55498 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55499 + const struct acl_subject_label *subj)
55500 +{
55501 + char *path = NULL;
55502 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
55503 +}
55504 +
55505 +static __inline__ struct acl_object_label *
55506 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55507 + const struct acl_subject_label *subj, char *path)
55508 +{
55509 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
55510 +}
55511 +
55512 +static struct acl_subject_label *
55513 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55514 + const struct acl_role_label *role)
55515 +{
55516 + struct dentry *dentry = (struct dentry *) l_dentry;
55517 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55518 + struct mount *real_mnt = real_mount(mnt);
55519 + struct acl_subject_label *retval;
55520 + struct dentry *parent;
55521 +
55522 + write_seqlock(&rename_lock);
55523 + br_read_lock(&vfsmount_lock);
55524 +
55525 + for (;;) {
55526 + if (dentry == real_root.dentry && mnt == real_root.mnt)
55527 + break;
55528 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55529 + if (!mnt_has_parent(real_mnt))
55530 + break;
55531 +
55532 + spin_lock(&dentry->d_lock);
55533 + read_lock(&gr_inode_lock);
55534 + retval =
55535 + lookup_acl_subj_label(dentry->d_inode->i_ino,
55536 + __get_dev(dentry), role);
55537 + read_unlock(&gr_inode_lock);
55538 + spin_unlock(&dentry->d_lock);
55539 + if (retval != NULL)
55540 + goto out;
55541 +
55542 + dentry = real_mnt->mnt_mountpoint;
55543 + real_mnt = real_mnt->mnt_parent;
55544 + mnt = &real_mnt->mnt;
55545 + continue;
55546 + }
55547 +
55548 + spin_lock(&dentry->d_lock);
55549 + read_lock(&gr_inode_lock);
55550 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55551 + __get_dev(dentry), role);
55552 + read_unlock(&gr_inode_lock);
55553 + parent = dentry->d_parent;
55554 + spin_unlock(&dentry->d_lock);
55555 +
55556 + if (retval != NULL)
55557 + goto out;
55558 +
55559 + dentry = parent;
55560 + }
55561 +
55562 + spin_lock(&dentry->d_lock);
55563 + read_lock(&gr_inode_lock);
55564 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55565 + __get_dev(dentry), role);
55566 + read_unlock(&gr_inode_lock);
55567 + spin_unlock(&dentry->d_lock);
55568 +
55569 + if (unlikely(retval == NULL)) {
55570 + /* real_root is pinned, we don't need to hold a reference */
55571 + read_lock(&gr_inode_lock);
55572 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
55573 + __get_dev(real_root.dentry), role);
55574 + read_unlock(&gr_inode_lock);
55575 + }
55576 +out:
55577 + br_read_unlock(&vfsmount_lock);
55578 + write_sequnlock(&rename_lock);
55579 +
55580 + BUG_ON(retval == NULL);
55581 +
55582 + return retval;
55583 +}
55584 +
55585 +static void
55586 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
55587 +{
55588 + struct task_struct *task = current;
55589 + const struct cred *cred = current_cred();
55590 +
55591 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
55592 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55593 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55594 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
55595 +
55596 + return;
55597 +}
55598 +
55599 +static void
55600 +gr_log_learn_id_change(const char type, const unsigned int real,
55601 + const unsigned int effective, const unsigned int fs)
55602 +{
55603 + struct task_struct *task = current;
55604 + const struct cred *cred = current_cred();
55605 +
55606 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
55607 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55608 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55609 + type, real, effective, fs, &task->signal->saved_ip);
55610 +
55611 + return;
55612 +}
55613 +
55614 +__u32
55615 +gr_search_file(const struct dentry * dentry, const __u32 mode,
55616 + const struct vfsmount * mnt)
55617 +{
55618 + __u32 retval = mode;
55619 + struct acl_subject_label *curracl;
55620 + struct acl_object_label *currobj;
55621 +
55622 + if (unlikely(!(gr_status & GR_READY)))
55623 + return (mode & ~GR_AUDITS);
55624 +
55625 + curracl = current->acl;
55626 +
55627 + currobj = chk_obj_label(dentry, mnt, curracl);
55628 + retval = currobj->mode & mode;
55629 +
55630 + /* if we're opening a specified transfer file for writing
55631 + (e.g. /dev/initctl), then transfer our role to init
55632 + */
55633 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
55634 + current->role->roletype & GR_ROLE_PERSIST)) {
55635 + struct task_struct *task = init_pid_ns.child_reaper;
55636 +
55637 + if (task->role != current->role) {
55638 + task->acl_sp_role = 0;
55639 + task->acl_role_id = current->acl_role_id;
55640 + task->role = current->role;
55641 + rcu_read_lock();
55642 + read_lock(&grsec_exec_file_lock);
55643 + gr_apply_subject_to_task(task);
55644 + read_unlock(&grsec_exec_file_lock);
55645 + rcu_read_unlock();
55646 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
55647 + }
55648 + }
55649 +
55650 + if (unlikely
55651 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
55652 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
55653 + __u32 new_mode = mode;
55654 +
55655 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55656 +
55657 + retval = new_mode;
55658 +
55659 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
55660 + new_mode |= GR_INHERIT;
55661 +
55662 + if (!(mode & GR_NOLEARN))
55663 + gr_log_learn(dentry, mnt, new_mode);
55664 + }
55665 +
55666 + return retval;
55667 +}
55668 +
55669 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
55670 + const struct dentry *parent,
55671 + const struct vfsmount *mnt)
55672 +{
55673 + struct name_entry *match;
55674 + struct acl_object_label *matchpo;
55675 + struct acl_subject_label *curracl;
55676 + char *path;
55677 +
55678 + if (unlikely(!(gr_status & GR_READY)))
55679 + return NULL;
55680 +
55681 + preempt_disable();
55682 + path = gr_to_filename_rbac(new_dentry, mnt);
55683 + match = lookup_name_entry_create(path);
55684 +
55685 + curracl = current->acl;
55686 +
55687 + if (match) {
55688 + read_lock(&gr_inode_lock);
55689 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
55690 + read_unlock(&gr_inode_lock);
55691 +
55692 + if (matchpo) {
55693 + preempt_enable();
55694 + return matchpo;
55695 + }
55696 + }
55697 +
55698 + // lookup parent
55699 +
55700 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
55701 +
55702 + preempt_enable();
55703 + return matchpo;
55704 +}
55705 +
55706 +__u32
55707 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
55708 + const struct vfsmount * mnt, const __u32 mode)
55709 +{
55710 + struct acl_object_label *matchpo;
55711 + __u32 retval;
55712 +
55713 + if (unlikely(!(gr_status & GR_READY)))
55714 + return (mode & ~GR_AUDITS);
55715 +
55716 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
55717 +
55718 + retval = matchpo->mode & mode;
55719 +
55720 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
55721 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
55722 + __u32 new_mode = mode;
55723 +
55724 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55725 +
55726 + gr_log_learn(new_dentry, mnt, new_mode);
55727 + return new_mode;
55728 + }
55729 +
55730 + return retval;
55731 +}
55732 +
55733 +__u32
55734 +gr_check_link(const struct dentry * new_dentry,
55735 + const struct dentry * parent_dentry,
55736 + const struct vfsmount * parent_mnt,
55737 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
55738 +{
55739 + struct acl_object_label *obj;
55740 + __u32 oldmode, newmode;
55741 + __u32 needmode;
55742 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
55743 + GR_DELETE | GR_INHERIT;
55744 +
55745 + if (unlikely(!(gr_status & GR_READY)))
55746 + return (GR_CREATE | GR_LINK);
55747 +
55748 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
55749 + oldmode = obj->mode;
55750 +
55751 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
55752 + newmode = obj->mode;
55753 +
55754 + needmode = newmode & checkmodes;
55755 +
55756 + // old name for hardlink must have at least the permissions of the new name
55757 + if ((oldmode & needmode) != needmode)
55758 + goto bad;
55759 +
55760 + // if old name had restrictions/auditing, make sure the new name does as well
55761 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
55762 +
55763 + // don't allow hardlinking of suid/sgid/fcapped files without permission
55764 + if (is_privileged_binary(old_dentry))
55765 + needmode |= GR_SETID;
55766 +
55767 + if ((newmode & needmode) != needmode)
55768 + goto bad;
55769 +
55770 + // enforce minimum permissions
55771 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
55772 + return newmode;
55773 +bad:
55774 + needmode = oldmode;
55775 + if (is_privileged_binary(old_dentry))
55776 + needmode |= GR_SETID;
55777 +
55778 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
55779 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
55780 + return (GR_CREATE | GR_LINK);
55781 + } else if (newmode & GR_SUPPRESS)
55782 + return GR_SUPPRESS;
55783 + else
55784 + return 0;
55785 +}
55786 +
55787 +int
55788 +gr_check_hidden_task(const struct task_struct *task)
55789 +{
55790 + if (unlikely(!(gr_status & GR_READY)))
55791 + return 0;
55792 +
55793 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
55794 + return 1;
55795 +
55796 + return 0;
55797 +}
55798 +
55799 +int
55800 +gr_check_protected_task(const struct task_struct *task)
55801 +{
55802 + if (unlikely(!(gr_status & GR_READY) || !task))
55803 + return 0;
55804 +
55805 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55806 + task->acl != current->acl)
55807 + return 1;
55808 +
55809 + return 0;
55810 +}
55811 +
55812 +int
55813 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
55814 +{
55815 + struct task_struct *p;
55816 + int ret = 0;
55817 +
55818 + if (unlikely(!(gr_status & GR_READY) || !pid))
55819 + return ret;
55820 +
55821 + read_lock(&tasklist_lock);
55822 + do_each_pid_task(pid, type, p) {
55823 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55824 + p->acl != current->acl) {
55825 + ret = 1;
55826 + goto out;
55827 + }
55828 + } while_each_pid_task(pid, type, p);
55829 +out:
55830 + read_unlock(&tasklist_lock);
55831 +
55832 + return ret;
55833 +}
55834 +
55835 +void
55836 +gr_copy_label(struct task_struct *tsk)
55837 +{
55838 + tsk->signal->used_accept = 0;
55839 + tsk->acl_sp_role = 0;
55840 + tsk->acl_role_id = current->acl_role_id;
55841 + tsk->acl = current->acl;
55842 + tsk->role = current->role;
55843 + tsk->signal->curr_ip = current->signal->curr_ip;
55844 + tsk->signal->saved_ip = current->signal->saved_ip;
55845 + if (current->exec_file)
55846 + get_file(current->exec_file);
55847 + tsk->exec_file = current->exec_file;
55848 + tsk->is_writable = current->is_writable;
55849 + if (unlikely(current->signal->used_accept)) {
55850 + current->signal->curr_ip = 0;
55851 + current->signal->saved_ip = 0;
55852 + }
55853 +
55854 + return;
55855 +}
55856 +
55857 +static void
55858 +gr_set_proc_res(struct task_struct *task)
55859 +{
55860 + struct acl_subject_label *proc;
55861 + unsigned short i;
55862 +
55863 + proc = task->acl;
55864 +
55865 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
55866 + return;
55867 +
55868 + for (i = 0; i < RLIM_NLIMITS; i++) {
55869 + if (!(proc->resmask & (1 << i)))
55870 + continue;
55871 +
55872 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
55873 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
55874 + }
55875 +
55876 + return;
55877 +}
55878 +
55879 +extern int __gr_process_user_ban(struct user_struct *user);
55880 +
55881 +int
55882 +gr_check_user_change(int real, int effective, int fs)
55883 +{
55884 + unsigned int i;
55885 + __u16 num;
55886 + uid_t *uidlist;
55887 + int curuid;
55888 + int realok = 0;
55889 + int effectiveok = 0;
55890 + int fsok = 0;
55891 +
55892 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
55893 + struct user_struct *user;
55894 +
55895 + if (real == -1)
55896 + goto skipit;
55897 +
55898 + user = find_user(real);
55899 + if (user == NULL)
55900 + goto skipit;
55901 +
55902 + if (__gr_process_user_ban(user)) {
55903 + /* for find_user */
55904 + free_uid(user);
55905 + return 1;
55906 + }
55907 +
55908 + /* for find_user */
55909 + free_uid(user);
55910 +
55911 +skipit:
55912 +#endif
55913 +
55914 + if (unlikely(!(gr_status & GR_READY)))
55915 + return 0;
55916 +
55917 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55918 + gr_log_learn_id_change('u', real, effective, fs);
55919 +
55920 + num = current->acl->user_trans_num;
55921 + uidlist = current->acl->user_transitions;
55922 +
55923 + if (uidlist == NULL)
55924 + return 0;
55925 +
55926 + if (real == -1)
55927 + realok = 1;
55928 + if (effective == -1)
55929 + effectiveok = 1;
55930 + if (fs == -1)
55931 + fsok = 1;
55932 +
55933 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
55934 + for (i = 0; i < num; i++) {
55935 + curuid = (int)uidlist[i];
55936 + if (real == curuid)
55937 + realok = 1;
55938 + if (effective == curuid)
55939 + effectiveok = 1;
55940 + if (fs == curuid)
55941 + fsok = 1;
55942 + }
55943 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
55944 + for (i = 0; i < num; i++) {
55945 + curuid = (int)uidlist[i];
55946 + if (real == curuid)
55947 + break;
55948 + if (effective == curuid)
55949 + break;
55950 + if (fs == curuid)
55951 + break;
55952 + }
55953 + /* not in deny list */
55954 + if (i == num) {
55955 + realok = 1;
55956 + effectiveok = 1;
55957 + fsok = 1;
55958 + }
55959 + }
55960 +
55961 + if (realok && effectiveok && fsok)
55962 + return 0;
55963 + else {
55964 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
55965 + return 1;
55966 + }
55967 +}
55968 +
55969 +int
55970 +gr_check_group_change(int real, int effective, int fs)
55971 +{
55972 + unsigned int i;
55973 + __u16 num;
55974 + gid_t *gidlist;
55975 + int curgid;
55976 + int realok = 0;
55977 + int effectiveok = 0;
55978 + int fsok = 0;
55979 +
55980 + if (unlikely(!(gr_status & GR_READY)))
55981 + return 0;
55982 +
55983 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55984 + gr_log_learn_id_change('g', real, effective, fs);
55985 +
55986 + num = current->acl->group_trans_num;
55987 + gidlist = current->acl->group_transitions;
55988 +
55989 + if (gidlist == NULL)
55990 + return 0;
55991 +
55992 + if (real == -1)
55993 + realok = 1;
55994 + if (effective == -1)
55995 + effectiveok = 1;
55996 + if (fs == -1)
55997 + fsok = 1;
55998 +
55999 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
56000 + for (i = 0; i < num; i++) {
56001 + curgid = (int)gidlist[i];
56002 + if (real == curgid)
56003 + realok = 1;
56004 + if (effective == curgid)
56005 + effectiveok = 1;
56006 + if (fs == curgid)
56007 + fsok = 1;
56008 + }
56009 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
56010 + for (i = 0; i < num; i++) {
56011 + curgid = (int)gidlist[i];
56012 + if (real == curgid)
56013 + break;
56014 + if (effective == curgid)
56015 + break;
56016 + if (fs == curgid)
56017 + break;
56018 + }
56019 + /* not in deny list */
56020 + if (i == num) {
56021 + realok = 1;
56022 + effectiveok = 1;
56023 + fsok = 1;
56024 + }
56025 + }
56026 +
56027 + if (realok && effectiveok && fsok)
56028 + return 0;
56029 + else {
56030 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56031 + return 1;
56032 + }
56033 +}
56034 +
56035 +extern int gr_acl_is_capable(const int cap);
56036 +
56037 +void
56038 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
56039 +{
56040 + struct acl_role_label *role = task->role;
56041 + struct acl_subject_label *subj = NULL;
56042 + struct acl_object_label *obj;
56043 + struct file *filp;
56044 +
56045 + if (unlikely(!(gr_status & GR_READY)))
56046 + return;
56047 +
56048 + filp = task->exec_file;
56049 +
56050 + /* kernel process, we'll give them the kernel role */
56051 + if (unlikely(!filp)) {
56052 + task->role = kernel_role;
56053 + task->acl = kernel_role->root_label;
56054 + return;
56055 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
56056 + role = lookup_acl_role_label(task, uid, gid);
56057 +
56058 + /* don't change the role if we're not a privileged process */
56059 + if (role && task->role != role &&
56060 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
56061 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
56062 + return;
56063 +
56064 + /* perform subject lookup in possibly new role
56065 + we can use this result below in the case where role == task->role
56066 + */
56067 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
56068 +
56069 + /* if we changed uid/gid, but result in the same role
56070 + and are using inheritance, don't lose the inherited subject
56071 + if current subject is other than what normal lookup
56072 + would result in, we arrived via inheritance, don't
56073 + lose subject
56074 + */
56075 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
56076 + (subj == task->acl)))
56077 + task->acl = subj;
56078 +
56079 + task->role = role;
56080 +
56081 + task->is_writable = 0;
56082 +
56083 + /* ignore additional mmap checks for processes that are writable
56084 + by the default ACL */
56085 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56086 + if (unlikely(obj->mode & GR_WRITE))
56087 + task->is_writable = 1;
56088 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
56089 + if (unlikely(obj->mode & GR_WRITE))
56090 + task->is_writable = 1;
56091 +
56092 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56093 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56094 +#endif
56095 +
56096 + gr_set_proc_res(task);
56097 +
56098 + return;
56099 +}
56100 +
56101 +int
56102 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
56103 + const int unsafe_flags)
56104 +{
56105 + struct task_struct *task = current;
56106 + struct acl_subject_label *newacl;
56107 + struct acl_object_label *obj;
56108 + __u32 retmode;
56109 +
56110 + if (unlikely(!(gr_status & GR_READY)))
56111 + return 0;
56112 +
56113 + newacl = chk_subj_label(dentry, mnt, task->role);
56114 +
56115 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
56116 + did an exec
56117 + */
56118 + rcu_read_lock();
56119 + read_lock(&tasklist_lock);
56120 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
56121 + (task->parent->acl->mode & GR_POVERRIDE))) {
56122 + read_unlock(&tasklist_lock);
56123 + rcu_read_unlock();
56124 + goto skip_check;
56125 + }
56126 + read_unlock(&tasklist_lock);
56127 + rcu_read_unlock();
56128 +
56129 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
56130 + !(task->role->roletype & GR_ROLE_GOD) &&
56131 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
56132 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
56133 + if (unsafe_flags & LSM_UNSAFE_SHARE)
56134 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
56135 + else
56136 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
56137 + return -EACCES;
56138 + }
56139 +
56140 +skip_check:
56141 +
56142 + obj = chk_obj_label(dentry, mnt, task->acl);
56143 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
56144 +
56145 + if (!(task->acl->mode & GR_INHERITLEARN) &&
56146 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
56147 + if (obj->nested)
56148 + task->acl = obj->nested;
56149 + else
56150 + task->acl = newacl;
56151 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
56152 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
56153 +
56154 + task->is_writable = 0;
56155 +
56156 + /* ignore additional mmap checks for processes that are writable
56157 + by the default ACL */
56158 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
56159 + if (unlikely(obj->mode & GR_WRITE))
56160 + task->is_writable = 1;
56161 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
56162 + if (unlikely(obj->mode & GR_WRITE))
56163 + task->is_writable = 1;
56164 +
56165 + gr_set_proc_res(task);
56166 +
56167 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56168 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56169 +#endif
56170 + return 0;
56171 +}
56172 +
56173 +/* always called with valid inodev ptr */
56174 +static void
56175 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
56176 +{
56177 + struct acl_object_label *matchpo;
56178 + struct acl_subject_label *matchps;
56179 + struct acl_subject_label *subj;
56180 + struct acl_role_label *role;
56181 + unsigned int x;
56182 +
56183 + FOR_EACH_ROLE_START(role)
56184 + FOR_EACH_SUBJECT_START(role, subj, x)
56185 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
56186 + matchpo->mode |= GR_DELETED;
56187 + FOR_EACH_SUBJECT_END(subj,x)
56188 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
56189 + /* nested subjects aren't in the role's subj_hash table */
56190 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
56191 + matchpo->mode |= GR_DELETED;
56192 + FOR_EACH_NESTED_SUBJECT_END(subj)
56193 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
56194 + matchps->mode |= GR_DELETED;
56195 + FOR_EACH_ROLE_END(role)
56196 +
56197 + inodev->nentry->deleted = 1;
56198 +
56199 + return;
56200 +}
56201 +
56202 +void
56203 +gr_handle_delete(const ino_t ino, const dev_t dev)
56204 +{
56205 + struct inodev_entry *inodev;
56206 +
56207 + if (unlikely(!(gr_status & GR_READY)))
56208 + return;
56209 +
56210 + write_lock(&gr_inode_lock);
56211 + inodev = lookup_inodev_entry(ino, dev);
56212 + if (inodev != NULL)
56213 + do_handle_delete(inodev, ino, dev);
56214 + write_unlock(&gr_inode_lock);
56215 +
56216 + return;
56217 +}
56218 +
56219 +static void
56220 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
56221 + const ino_t newinode, const dev_t newdevice,
56222 + struct acl_subject_label *subj)
56223 +{
56224 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
56225 + struct acl_object_label *match;
56226 +
56227 + match = subj->obj_hash[index];
56228 +
56229 + while (match && (match->inode != oldinode ||
56230 + match->device != olddevice ||
56231 + !(match->mode & GR_DELETED)))
56232 + match = match->next;
56233 +
56234 + if (match && (match->inode == oldinode)
56235 + && (match->device == olddevice)
56236 + && (match->mode & GR_DELETED)) {
56237 + if (match->prev == NULL) {
56238 + subj->obj_hash[index] = match->next;
56239 + if (match->next != NULL)
56240 + match->next->prev = NULL;
56241 + } else {
56242 + match->prev->next = match->next;
56243 + if (match->next != NULL)
56244 + match->next->prev = match->prev;
56245 + }
56246 + match->prev = NULL;
56247 + match->next = NULL;
56248 + match->inode = newinode;
56249 + match->device = newdevice;
56250 + match->mode &= ~GR_DELETED;
56251 +
56252 + insert_acl_obj_label(match, subj);
56253 + }
56254 +
56255 + return;
56256 +}
56257 +
56258 +static void
56259 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
56260 + const ino_t newinode, const dev_t newdevice,
56261 + struct acl_role_label *role)
56262 +{
56263 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
56264 + struct acl_subject_label *match;
56265 +
56266 + match = role->subj_hash[index];
56267 +
56268 + while (match && (match->inode != oldinode ||
56269 + match->device != olddevice ||
56270 + !(match->mode & GR_DELETED)))
56271 + match = match->next;
56272 +
56273 + if (match && (match->inode == oldinode)
56274 + && (match->device == olddevice)
56275 + && (match->mode & GR_DELETED)) {
56276 + if (match->prev == NULL) {
56277 + role->subj_hash[index] = match->next;
56278 + if (match->next != NULL)
56279 + match->next->prev = NULL;
56280 + } else {
56281 + match->prev->next = match->next;
56282 + if (match->next != NULL)
56283 + match->next->prev = match->prev;
56284 + }
56285 + match->prev = NULL;
56286 + match->next = NULL;
56287 + match->inode = newinode;
56288 + match->device = newdevice;
56289 + match->mode &= ~GR_DELETED;
56290 +
56291 + insert_acl_subj_label(match, role);
56292 + }
56293 +
56294 + return;
56295 +}
56296 +
56297 +static void
56298 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
56299 + const ino_t newinode, const dev_t newdevice)
56300 +{
56301 + unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
56302 + struct inodev_entry *match;
56303 +
56304 + match = inodev_set.i_hash[index];
56305 +
56306 + while (match && (match->nentry->inode != oldinode ||
56307 + match->nentry->device != olddevice || !match->nentry->deleted))
56308 + match = match->next;
56309 +
56310 + if (match && (match->nentry->inode == oldinode)
56311 + && (match->nentry->device == olddevice) &&
56312 + match->nentry->deleted) {
56313 + if (match->prev == NULL) {
56314 + inodev_set.i_hash[index] = match->next;
56315 + if (match->next != NULL)
56316 + match->next->prev = NULL;
56317 + } else {
56318 + match->prev->next = match->next;
56319 + if (match->next != NULL)
56320 + match->next->prev = match->prev;
56321 + }
56322 + match->prev = NULL;
56323 + match->next = NULL;
56324 + match->nentry->inode = newinode;
56325 + match->nentry->device = newdevice;
56326 + match->nentry->deleted = 0;
56327 +
56328 + insert_inodev_entry(match);
56329 + }
56330 +
56331 + return;
56332 +}
56333 +
56334 +static void
56335 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
56336 +{
56337 + struct acl_subject_label *subj;
56338 + struct acl_role_label *role;
56339 + unsigned int x;
56340 +
56341 + FOR_EACH_ROLE_START(role)
56342 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
56343 +
56344 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
56345 + if ((subj->inode == ino) && (subj->device == dev)) {
56346 + subj->inode = ino;
56347 + subj->device = dev;
56348 + }
56349 + /* nested subjects aren't in the role's subj_hash table */
56350 + update_acl_obj_label(matchn->inode, matchn->device,
56351 + ino, dev, subj);
56352 + FOR_EACH_NESTED_SUBJECT_END(subj)
56353 + FOR_EACH_SUBJECT_START(role, subj, x)
56354 + update_acl_obj_label(matchn->inode, matchn->device,
56355 + ino, dev, subj);
56356 + FOR_EACH_SUBJECT_END(subj,x)
56357 + FOR_EACH_ROLE_END(role)
56358 +
56359 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
56360 +
56361 + return;
56362 +}
56363 +
56364 +static void
56365 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
56366 + const struct vfsmount *mnt)
56367 +{
56368 + ino_t ino = dentry->d_inode->i_ino;
56369 + dev_t dev = __get_dev(dentry);
56370 +
56371 + __do_handle_create(matchn, ino, dev);
56372 +
56373 + return;
56374 +}
56375 +
56376 +void
56377 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
56378 +{
56379 + struct name_entry *matchn;
56380 +
56381 + if (unlikely(!(gr_status & GR_READY)))
56382 + return;
56383 +
56384 + preempt_disable();
56385 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
56386 +
56387 + if (unlikely((unsigned long)matchn)) {
56388 + write_lock(&gr_inode_lock);
56389 + do_handle_create(matchn, dentry, mnt);
56390 + write_unlock(&gr_inode_lock);
56391 + }
56392 + preempt_enable();
56393 +
56394 + return;
56395 +}
56396 +
56397 +void
56398 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56399 +{
56400 + struct name_entry *matchn;
56401 +
56402 + if (unlikely(!(gr_status & GR_READY)))
56403 + return;
56404 +
56405 + preempt_disable();
56406 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
56407 +
56408 + if (unlikely((unsigned long)matchn)) {
56409 + write_lock(&gr_inode_lock);
56410 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
56411 + write_unlock(&gr_inode_lock);
56412 + }
56413 + preempt_enable();
56414 +
56415 + return;
56416 +}
56417 +
56418 +void
56419 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
56420 + struct dentry *old_dentry,
56421 + struct dentry *new_dentry,
56422 + struct vfsmount *mnt, const __u8 replace)
56423 +{
56424 + struct name_entry *matchn;
56425 + struct inodev_entry *inodev;
56426 + struct inode *inode = new_dentry->d_inode;
56427 + ino_t old_ino = old_dentry->d_inode->i_ino;
56428 + dev_t old_dev = __get_dev(old_dentry);
56429 +
56430 + /* vfs_rename swaps the name and parent link for old_dentry and
56431 + new_dentry
56432 + at this point, old_dentry has the new name, parent link, and inode
56433 + for the renamed file
56434 + if a file is being replaced by a rename, new_dentry has the inode
56435 + and name for the replaced file
56436 + */
56437 +
56438 + if (unlikely(!(gr_status & GR_READY)))
56439 + return;
56440 +
56441 + preempt_disable();
56442 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
56443 +
56444 + /* we wouldn't have to check d_inode if it weren't for
56445 + NFS silly-renaming
56446 + */
56447 +
56448 + write_lock(&gr_inode_lock);
56449 + if (unlikely(replace && inode)) {
56450 + ino_t new_ino = inode->i_ino;
56451 + dev_t new_dev = __get_dev(new_dentry);
56452 +
56453 + inodev = lookup_inodev_entry(new_ino, new_dev);
56454 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
56455 + do_handle_delete(inodev, new_ino, new_dev);
56456 + }
56457 +
56458 + inodev = lookup_inodev_entry(old_ino, old_dev);
56459 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
56460 + do_handle_delete(inodev, old_ino, old_dev);
56461 +
56462 + if (unlikely((unsigned long)matchn))
56463 + do_handle_create(matchn, old_dentry, mnt);
56464 +
56465 + write_unlock(&gr_inode_lock);
56466 + preempt_enable();
56467 +
56468 + return;
56469 +}
56470 +
56471 +static int
56472 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
56473 + unsigned char **sum)
56474 +{
56475 + struct acl_role_label *r;
56476 + struct role_allowed_ip *ipp;
56477 + struct role_transition *trans;
56478 + unsigned int i;
56479 + int found = 0;
56480 + u32 curr_ip = current->signal->curr_ip;
56481 +
56482 + current->signal->saved_ip = curr_ip;
56483 +
56484 + /* check transition table */
56485 +
56486 + for (trans = current->role->transitions; trans; trans = trans->next) {
56487 + if (!strcmp(rolename, trans->rolename)) {
56488 + found = 1;
56489 + break;
56490 + }
56491 + }
56492 +
56493 + if (!found)
56494 + return 0;
56495 +
56496 + /* handle special roles that do not require authentication
56497 + and check ip */
56498 +
56499 + FOR_EACH_ROLE_START(r)
56500 + if (!strcmp(rolename, r->rolename) &&
56501 + (r->roletype & GR_ROLE_SPECIAL)) {
56502 + found = 0;
56503 + if (r->allowed_ips != NULL) {
56504 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
56505 + if ((ntohl(curr_ip) & ipp->netmask) ==
56506 + (ntohl(ipp->addr) & ipp->netmask))
56507 + found = 1;
56508 + }
56509 + } else
56510 + found = 2;
56511 + if (!found)
56512 + return 0;
56513 +
56514 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
56515 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
56516 + *salt = NULL;
56517 + *sum = NULL;
56518 + return 1;
56519 + }
56520 + }
56521 + FOR_EACH_ROLE_END(r)
56522 +
56523 + for (i = 0; i < num_sprole_pws; i++) {
56524 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
56525 + *salt = acl_special_roles[i]->salt;
56526 + *sum = acl_special_roles[i]->sum;
56527 + return 1;
56528 + }
56529 + }
56530 +
56531 + return 0;
56532 +}
56533 +
56534 +static void
56535 +assign_special_role(char *rolename)
56536 +{
56537 + struct acl_object_label *obj;
56538 + struct acl_role_label *r;
56539 + struct acl_role_label *assigned = NULL;
56540 + struct task_struct *tsk;
56541 + struct file *filp;
56542 +
56543 + FOR_EACH_ROLE_START(r)
56544 + if (!strcmp(rolename, r->rolename) &&
56545 + (r->roletype & GR_ROLE_SPECIAL)) {
56546 + assigned = r;
56547 + break;
56548 + }
56549 + FOR_EACH_ROLE_END(r)
56550 +
56551 + if (!assigned)
56552 + return;
56553 +
56554 + read_lock(&tasklist_lock);
56555 + read_lock(&grsec_exec_file_lock);
56556 +
56557 + tsk = current->real_parent;
56558 + if (tsk == NULL)
56559 + goto out_unlock;
56560 +
56561 + filp = tsk->exec_file;
56562 + if (filp == NULL)
56563 + goto out_unlock;
56564 +
56565 + tsk->is_writable = 0;
56566 +
56567 + tsk->acl_sp_role = 1;
56568 + tsk->acl_role_id = ++acl_sp_role_value;
56569 + tsk->role = assigned;
56570 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
56571 +
56572 + /* ignore additional mmap checks for processes that are writable
56573 + by the default ACL */
56574 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56575 + if (unlikely(obj->mode & GR_WRITE))
56576 + tsk->is_writable = 1;
56577 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
56578 + if (unlikely(obj->mode & GR_WRITE))
56579 + tsk->is_writable = 1;
56580 +
56581 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56582 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
56583 +#endif
56584 +
56585 +out_unlock:
56586 + read_unlock(&grsec_exec_file_lock);
56587 + read_unlock(&tasklist_lock);
56588 + return;
56589 +}
56590 +
56591 +int gr_check_secure_terminal(struct task_struct *task)
56592 +{
56593 + struct task_struct *p, *p2, *p3;
56594 + struct files_struct *files;
56595 + struct fdtable *fdt;
56596 + struct file *our_file = NULL, *file;
56597 + int i;
56598 +
56599 + if (task->signal->tty == NULL)
56600 + return 1;
56601 +
56602 + files = get_files_struct(task);
56603 + if (files != NULL) {
56604 + rcu_read_lock();
56605 + fdt = files_fdtable(files);
56606 + for (i=0; i < fdt->max_fds; i++) {
56607 + file = fcheck_files(files, i);
56608 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
56609 + get_file(file);
56610 + our_file = file;
56611 + }
56612 + }
56613 + rcu_read_unlock();
56614 + put_files_struct(files);
56615 + }
56616 +
56617 + if (our_file == NULL)
56618 + return 1;
56619 +
56620 + read_lock(&tasklist_lock);
56621 + do_each_thread(p2, p) {
56622 + files = get_files_struct(p);
56623 + if (files == NULL ||
56624 + (p->signal && p->signal->tty == task->signal->tty)) {
56625 + if (files != NULL)
56626 + put_files_struct(files);
56627 + continue;
56628 + }
56629 + rcu_read_lock();
56630 + fdt = files_fdtable(files);
56631 + for (i=0; i < fdt->max_fds; i++) {
56632 + file = fcheck_files(files, i);
56633 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
56634 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
56635 + p3 = task;
56636 + while (p3->pid > 0) {
56637 + if (p3 == p)
56638 + break;
56639 + p3 = p3->real_parent;
56640 + }
56641 + if (p3 == p)
56642 + break;
56643 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
56644 + gr_handle_alertkill(p);
56645 + rcu_read_unlock();
56646 + put_files_struct(files);
56647 + read_unlock(&tasklist_lock);
56648 + fput(our_file);
56649 + return 0;
56650 + }
56651 + }
56652 + rcu_read_unlock();
56653 + put_files_struct(files);
56654 + } while_each_thread(p2, p);
56655 + read_unlock(&tasklist_lock);
56656 +
56657 + fput(our_file);
56658 + return 1;
56659 +}
56660 +
56661 +static int gr_rbac_disable(void *unused)
56662 +{
56663 + pax_open_kernel();
56664 + gr_status &= ~GR_READY;
56665 + pax_close_kernel();
56666 +
56667 + return 0;
56668 +}
56669 +
56670 +ssize_t
56671 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
56672 +{
56673 + struct gr_arg_wrapper uwrap;
56674 + unsigned char *sprole_salt = NULL;
56675 + unsigned char *sprole_sum = NULL;
56676 + int error = sizeof (struct gr_arg_wrapper);
56677 + int error2 = 0;
56678 +
56679 + mutex_lock(&gr_dev_mutex);
56680 +
56681 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
56682 + error = -EPERM;
56683 + goto out;
56684 + }
56685 +
56686 + if (count != sizeof (struct gr_arg_wrapper)) {
56687 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
56688 + error = -EINVAL;
56689 + goto out;
56690 + }
56691 +
56692 +
56693 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
56694 + gr_auth_expires = 0;
56695 + gr_auth_attempts = 0;
56696 + }
56697 +
56698 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
56699 + error = -EFAULT;
56700 + goto out;
56701 + }
56702 +
56703 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
56704 + error = -EINVAL;
56705 + goto out;
56706 + }
56707 +
56708 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
56709 + error = -EFAULT;
56710 + goto out;
56711 + }
56712 +
56713 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56714 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56715 + time_after(gr_auth_expires, get_seconds())) {
56716 + error = -EBUSY;
56717 + goto out;
56718 + }
56719 +
56720 + /* if non-root trying to do anything other than use a special role,
56721 + do not attempt authentication, do not count towards authentication
56722 + locking
56723 + */
56724 +
56725 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
56726 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56727 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
56728 + error = -EPERM;
56729 + goto out;
56730 + }
56731 +
56732 + /* ensure pw and special role name are null terminated */
56733 +
56734 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
56735 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
56736 +
56737 + /* Okay.
56738 + * We have our enough of the argument structure..(we have yet
56739 + * to copy_from_user the tables themselves) . Copy the tables
56740 + * only if we need them, i.e. for loading operations. */
56741 +
56742 + switch (gr_usermode->mode) {
56743 + case GR_STATUS:
56744 + if (gr_status & GR_READY) {
56745 + error = 1;
56746 + if (!gr_check_secure_terminal(current))
56747 + error = 3;
56748 + } else
56749 + error = 2;
56750 + goto out;
56751 + case GR_SHUTDOWN:
56752 + if ((gr_status & GR_READY)
56753 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56754 + stop_machine(gr_rbac_disable, NULL, NULL);
56755 + free_variables();
56756 + memset(gr_usermode, 0, sizeof (struct gr_arg));
56757 + memset(gr_system_salt, 0, GR_SALT_LEN);
56758 + memset(gr_system_sum, 0, GR_SHA_LEN);
56759 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
56760 + } else if (gr_status & GR_READY) {
56761 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
56762 + error = -EPERM;
56763 + } else {
56764 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
56765 + error = -EAGAIN;
56766 + }
56767 + break;
56768 + case GR_ENABLE:
56769 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
56770 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
56771 + else {
56772 + if (gr_status & GR_READY)
56773 + error = -EAGAIN;
56774 + else
56775 + error = error2;
56776 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
56777 + }
56778 + break;
56779 + case GR_RELOAD:
56780 + if (!(gr_status & GR_READY)) {
56781 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
56782 + error = -EAGAIN;
56783 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56784 + stop_machine(gr_rbac_disable, NULL, NULL);
56785 + free_variables();
56786 + error2 = gracl_init(gr_usermode);
56787 + if (!error2)
56788 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
56789 + else {
56790 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56791 + error = error2;
56792 + }
56793 + } else {
56794 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56795 + error = -EPERM;
56796 + }
56797 + break;
56798 + case GR_SEGVMOD:
56799 + if (unlikely(!(gr_status & GR_READY))) {
56800 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
56801 + error = -EAGAIN;
56802 + break;
56803 + }
56804 +
56805 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56806 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
56807 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
56808 + struct acl_subject_label *segvacl;
56809 + segvacl =
56810 + lookup_acl_subj_label(gr_usermode->segv_inode,
56811 + gr_usermode->segv_device,
56812 + current->role);
56813 + if (segvacl) {
56814 + segvacl->crashes = 0;
56815 + segvacl->expires = 0;
56816 + }
56817 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
56818 + gr_remove_uid(gr_usermode->segv_uid);
56819 + }
56820 + } else {
56821 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
56822 + error = -EPERM;
56823 + }
56824 + break;
56825 + case GR_SPROLE:
56826 + case GR_SPROLEPAM:
56827 + if (unlikely(!(gr_status & GR_READY))) {
56828 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
56829 + error = -EAGAIN;
56830 + break;
56831 + }
56832 +
56833 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
56834 + current->role->expires = 0;
56835 + current->role->auth_attempts = 0;
56836 + }
56837 +
56838 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56839 + time_after(current->role->expires, get_seconds())) {
56840 + error = -EBUSY;
56841 + goto out;
56842 + }
56843 +
56844 + if (lookup_special_role_auth
56845 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
56846 + && ((!sprole_salt && !sprole_sum)
56847 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
56848 + char *p = "";
56849 + assign_special_role(gr_usermode->sp_role);
56850 + read_lock(&tasklist_lock);
56851 + if (current->real_parent)
56852 + p = current->real_parent->role->rolename;
56853 + read_unlock(&tasklist_lock);
56854 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
56855 + p, acl_sp_role_value);
56856 + } else {
56857 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
56858 + error = -EPERM;
56859 + if(!(current->role->auth_attempts++))
56860 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56861 +
56862 + goto out;
56863 + }
56864 + break;
56865 + case GR_UNSPROLE:
56866 + if (unlikely(!(gr_status & GR_READY))) {
56867 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
56868 + error = -EAGAIN;
56869 + break;
56870 + }
56871 +
56872 + if (current->role->roletype & GR_ROLE_SPECIAL) {
56873 + char *p = "";
56874 + int i = 0;
56875 +
56876 + read_lock(&tasklist_lock);
56877 + if (current->real_parent) {
56878 + p = current->real_parent->role->rolename;
56879 + i = current->real_parent->acl_role_id;
56880 + }
56881 + read_unlock(&tasklist_lock);
56882 +
56883 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
56884 + gr_set_acls(1);
56885 + } else {
56886 + error = -EPERM;
56887 + goto out;
56888 + }
56889 + break;
56890 + default:
56891 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
56892 + error = -EINVAL;
56893 + break;
56894 + }
56895 +
56896 + if (error != -EPERM)
56897 + goto out;
56898 +
56899 + if(!(gr_auth_attempts++))
56900 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56901 +
56902 + out:
56903 + mutex_unlock(&gr_dev_mutex);
56904 + return error;
56905 +}
56906 +
56907 +/* must be called with
56908 + rcu_read_lock();
56909 + read_lock(&tasklist_lock);
56910 + read_lock(&grsec_exec_file_lock);
56911 +*/
56912 +int gr_apply_subject_to_task(struct task_struct *task)
56913 +{
56914 + struct acl_object_label *obj;
56915 + char *tmpname;
56916 + struct acl_subject_label *tmpsubj;
56917 + struct file *filp;
56918 + struct name_entry *nmatch;
56919 +
56920 + filp = task->exec_file;
56921 + if (filp == NULL)
56922 + return 0;
56923 +
56924 + /* the following is to apply the correct subject
56925 + on binaries running when the RBAC system
56926 + is enabled, when the binaries have been
56927 + replaced or deleted since their execution
56928 + -----
56929 + when the RBAC system starts, the inode/dev
56930 + from exec_file will be one the RBAC system
56931 + is unaware of. It only knows the inode/dev
56932 + of the present file on disk, or the absence
56933 + of it.
56934 + */
56935 + preempt_disable();
56936 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
56937 +
56938 + nmatch = lookup_name_entry(tmpname);
56939 + preempt_enable();
56940 + tmpsubj = NULL;
56941 + if (nmatch) {
56942 + if (nmatch->deleted)
56943 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
56944 + else
56945 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
56946 + if (tmpsubj != NULL)
56947 + task->acl = tmpsubj;
56948 + }
56949 + if (tmpsubj == NULL)
56950 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
56951 + task->role);
56952 + if (task->acl) {
56953 + task->is_writable = 0;
56954 + /* ignore additional mmap checks for processes that are writable
56955 + by the default ACL */
56956 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56957 + if (unlikely(obj->mode & GR_WRITE))
56958 + task->is_writable = 1;
56959 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
56960 + if (unlikely(obj->mode & GR_WRITE))
56961 + task->is_writable = 1;
56962 +
56963 + gr_set_proc_res(task);
56964 +
56965 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56966 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56967 +#endif
56968 + } else {
56969 + return 1;
56970 + }
56971 +
56972 + return 0;
56973 +}
56974 +
56975 +int
56976 +gr_set_acls(const int type)
56977 +{
56978 + struct task_struct *task, *task2;
56979 + struct acl_role_label *role = current->role;
56980 + __u16 acl_role_id = current->acl_role_id;
56981 + const struct cred *cred;
56982 + int ret;
56983 +
56984 + rcu_read_lock();
56985 + read_lock(&tasklist_lock);
56986 + read_lock(&grsec_exec_file_lock);
56987 + do_each_thread(task2, task) {
56988 + /* check to see if we're called from the exit handler,
56989 + if so, only replace ACLs that have inherited the admin
56990 + ACL */
56991 +
56992 + if (type && (task->role != role ||
56993 + task->acl_role_id != acl_role_id))
56994 + continue;
56995 +
56996 + task->acl_role_id = 0;
56997 + task->acl_sp_role = 0;
56998 +
56999 + if (task->exec_file) {
57000 + cred = __task_cred(task);
57001 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
57002 + ret = gr_apply_subject_to_task(task);
57003 + if (ret) {
57004 + read_unlock(&grsec_exec_file_lock);
57005 + read_unlock(&tasklist_lock);
57006 + rcu_read_unlock();
57007 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
57008 + return ret;
57009 + }
57010 + } else {
57011 + // it's a kernel process
57012 + task->role = kernel_role;
57013 + task->acl = kernel_role->root_label;
57014 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
57015 + task->acl->mode &= ~GR_PROCFIND;
57016 +#endif
57017 + }
57018 + } while_each_thread(task2, task);
57019 + read_unlock(&grsec_exec_file_lock);
57020 + read_unlock(&tasklist_lock);
57021 + rcu_read_unlock();
57022 +
57023 + return 0;
57024 +}
57025 +
57026 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
57027 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
57028 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
57029 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
57030 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
57031 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
57032 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
57033 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
57034 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
57035 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
57036 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
57037 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
57038 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
57039 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
57040 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
57041 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
57042 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
57043 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
57044 +};
57045 +
57046 +void
57047 +gr_learn_resource(const struct task_struct *task,
57048 + const int res, const unsigned long wanted, const int gt)
57049 +{
57050 + struct acl_subject_label *acl;
57051 + const struct cred *cred;
57052 +
57053 + if (unlikely((gr_status & GR_READY) &&
57054 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
57055 + goto skip_reslog;
57056 +
57057 + gr_log_resource(task, res, wanted, gt);
57058 +skip_reslog:
57059 +
57060 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
57061 + return;
57062 +
57063 + acl = task->acl;
57064 +
57065 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
57066 + !(acl->resmask & (1 << (unsigned short) res))))
57067 + return;
57068 +
57069 + if (wanted >= acl->res[res].rlim_cur) {
57070 + unsigned long res_add;
57071 +
57072 + res_add = wanted + res_learn_bumps[res];
57073 +
57074 + acl->res[res].rlim_cur = res_add;
57075 +
57076 + if (wanted > acl->res[res].rlim_max)
57077 + acl->res[res].rlim_max = res_add;
57078 +
57079 + /* only log the subject filename, since resource logging is supported for
57080 + single-subject learning only */
57081 + rcu_read_lock();
57082 + cred = __task_cred(task);
57083 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57084 + task->role->roletype, cred->uid, cred->gid, acl->filename,
57085 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
57086 + "", (unsigned long) res, &task->signal->saved_ip);
57087 + rcu_read_unlock();
57088 + }
57089 +
57090 + return;
57091 +}
57092 +#endif
57093 +
57094 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
57095 +void
57096 +pax_set_initial_flags(struct linux_binprm *bprm)
57097 +{
57098 + struct task_struct *task = current;
57099 + struct acl_subject_label *proc;
57100 + unsigned long flags;
57101 +
57102 + if (unlikely(!(gr_status & GR_READY)))
57103 + return;
57104 +
57105 + flags = pax_get_flags(task);
57106 +
57107 + proc = task->acl;
57108 +
57109 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
57110 + flags &= ~MF_PAX_PAGEEXEC;
57111 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
57112 + flags &= ~MF_PAX_SEGMEXEC;
57113 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
57114 + flags &= ~MF_PAX_RANDMMAP;
57115 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
57116 + flags &= ~MF_PAX_EMUTRAMP;
57117 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
57118 + flags &= ~MF_PAX_MPROTECT;
57119 +
57120 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
57121 + flags |= MF_PAX_PAGEEXEC;
57122 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
57123 + flags |= MF_PAX_SEGMEXEC;
57124 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
57125 + flags |= MF_PAX_RANDMMAP;
57126 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
57127 + flags |= MF_PAX_EMUTRAMP;
57128 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
57129 + flags |= MF_PAX_MPROTECT;
57130 +
57131 + pax_set_flags(task, flags);
57132 +
57133 + return;
57134 +}
57135 +#endif
57136 +
57137 +int
57138 +gr_handle_proc_ptrace(struct task_struct *task)
57139 +{
57140 + struct file *filp;
57141 + struct task_struct *tmp = task;
57142 + struct task_struct *curtemp = current;
57143 + __u32 retmode;
57144 +
57145 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
57146 + if (unlikely(!(gr_status & GR_READY)))
57147 + return 0;
57148 +#endif
57149 +
57150 + read_lock(&tasklist_lock);
57151 + read_lock(&grsec_exec_file_lock);
57152 + filp = task->exec_file;
57153 +
57154 + while (tmp->pid > 0) {
57155 + if (tmp == curtemp)
57156 + break;
57157 + tmp = tmp->real_parent;
57158 + }
57159 +
57160 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
57161 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
57162 + read_unlock(&grsec_exec_file_lock);
57163 + read_unlock(&tasklist_lock);
57164 + return 1;
57165 + }
57166 +
57167 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57168 + if (!(gr_status & GR_READY)) {
57169 + read_unlock(&grsec_exec_file_lock);
57170 + read_unlock(&tasklist_lock);
57171 + return 0;
57172 + }
57173 +#endif
57174 +
57175 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
57176 + read_unlock(&grsec_exec_file_lock);
57177 + read_unlock(&tasklist_lock);
57178 +
57179 + if (retmode & GR_NOPTRACE)
57180 + return 1;
57181 +
57182 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
57183 + && (current->acl != task->acl || (current->acl != current->role->root_label
57184 + && current->pid != task->pid)))
57185 + return 1;
57186 +
57187 + return 0;
57188 +}
57189 +
57190 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
57191 +{
57192 + if (unlikely(!(gr_status & GR_READY)))
57193 + return;
57194 +
57195 + if (!(current->role->roletype & GR_ROLE_GOD))
57196 + return;
57197 +
57198 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
57199 + p->role->rolename, gr_task_roletype_to_char(p),
57200 + p->acl->filename);
57201 +}
57202 +
57203 +int
57204 +gr_handle_ptrace(struct task_struct *task, const long request)
57205 +{
57206 + struct task_struct *tmp = task;
57207 + struct task_struct *curtemp = current;
57208 + __u32 retmode;
57209 +
57210 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
57211 + if (unlikely(!(gr_status & GR_READY)))
57212 + return 0;
57213 +#endif
57214 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
57215 + read_lock(&tasklist_lock);
57216 + while (tmp->pid > 0) {
57217 + if (tmp == curtemp)
57218 + break;
57219 + tmp = tmp->real_parent;
57220 + }
57221 +
57222 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
57223 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
57224 + read_unlock(&tasklist_lock);
57225 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57226 + return 1;
57227 + }
57228 + read_unlock(&tasklist_lock);
57229 + }
57230 +
57231 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57232 + if (!(gr_status & GR_READY))
57233 + return 0;
57234 +#endif
57235 +
57236 + read_lock(&grsec_exec_file_lock);
57237 + if (unlikely(!task->exec_file)) {
57238 + read_unlock(&grsec_exec_file_lock);
57239 + return 0;
57240 + }
57241 +
57242 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
57243 + read_unlock(&grsec_exec_file_lock);
57244 +
57245 + if (retmode & GR_NOPTRACE) {
57246 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57247 + return 1;
57248 + }
57249 +
57250 + if (retmode & GR_PTRACERD) {
57251 + switch (request) {
57252 + case PTRACE_SEIZE:
57253 + case PTRACE_POKETEXT:
57254 + case PTRACE_POKEDATA:
57255 + case PTRACE_POKEUSR:
57256 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
57257 + case PTRACE_SETREGS:
57258 + case PTRACE_SETFPREGS:
57259 +#endif
57260 +#ifdef CONFIG_X86
57261 + case PTRACE_SETFPXREGS:
57262 +#endif
57263 +#ifdef CONFIG_ALTIVEC
57264 + case PTRACE_SETVRREGS:
57265 +#endif
57266 + return 1;
57267 + default:
57268 + return 0;
57269 + }
57270 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
57271 + !(current->role->roletype & GR_ROLE_GOD) &&
57272 + (current->acl != task->acl)) {
57273 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57274 + return 1;
57275 + }
57276 +
57277 + return 0;
57278 +}
57279 +
57280 +static int is_writable_mmap(const struct file *filp)
57281 +{
57282 + struct task_struct *task = current;
57283 + struct acl_object_label *obj, *obj2;
57284 +
57285 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
57286 + !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))) {
57287 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57288 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
57289 + task->role->root_label);
57290 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
57291 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
57292 + return 1;
57293 + }
57294 + }
57295 + return 0;
57296 +}
57297 +
57298 +int
57299 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
57300 +{
57301 + __u32 mode;
57302 +
57303 + if (unlikely(!file || !(prot & PROT_EXEC)))
57304 + return 1;
57305 +
57306 + if (is_writable_mmap(file))
57307 + return 0;
57308 +
57309 + mode =
57310 + gr_search_file(file->f_path.dentry,
57311 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
57312 + file->f_path.mnt);
57313 +
57314 + if (!gr_tpe_allow(file))
57315 + return 0;
57316 +
57317 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
57318 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57319 + return 0;
57320 + } else if (unlikely(!(mode & GR_EXEC))) {
57321 + return 0;
57322 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
57323 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57324 + return 1;
57325 + }
57326 +
57327 + return 1;
57328 +}
57329 +
57330 +int
57331 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57332 +{
57333 + __u32 mode;
57334 +
57335 + if (unlikely(!file || !(prot & PROT_EXEC)))
57336 + return 1;
57337 +
57338 + if (is_writable_mmap(file))
57339 + return 0;
57340 +
57341 + mode =
57342 + gr_search_file(file->f_path.dentry,
57343 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
57344 + file->f_path.mnt);
57345 +
57346 + if (!gr_tpe_allow(file))
57347 + return 0;
57348 +
57349 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
57350 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57351 + return 0;
57352 + } else if (unlikely(!(mode & GR_EXEC))) {
57353 + return 0;
57354 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
57355 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57356 + return 1;
57357 + }
57358 +
57359 + return 1;
57360 +}
57361 +
57362 +void
57363 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57364 +{
57365 + unsigned long runtime;
57366 + unsigned long cputime;
57367 + unsigned int wday, cday;
57368 + __u8 whr, chr;
57369 + __u8 wmin, cmin;
57370 + __u8 wsec, csec;
57371 + struct timespec timeval;
57372 +
57373 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
57374 + !(task->acl->mode & GR_PROCACCT)))
57375 + return;
57376 +
57377 + do_posix_clock_monotonic_gettime(&timeval);
57378 + runtime = timeval.tv_sec - task->start_time.tv_sec;
57379 + wday = runtime / (3600 * 24);
57380 + runtime -= wday * (3600 * 24);
57381 + whr = runtime / 3600;
57382 + runtime -= whr * 3600;
57383 + wmin = runtime / 60;
57384 + runtime -= wmin * 60;
57385 + wsec = runtime;
57386 +
57387 + cputime = (task->utime + task->stime) / HZ;
57388 + cday = cputime / (3600 * 24);
57389 + cputime -= cday * (3600 * 24);
57390 + chr = cputime / 3600;
57391 + cputime -= chr * 3600;
57392 + cmin = cputime / 60;
57393 + cputime -= cmin * 60;
57394 + csec = cputime;
57395 +
57396 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
57397 +
57398 + return;
57399 +}
57400 +
57401 +void gr_set_kernel_label(struct task_struct *task)
57402 +{
57403 + if (gr_status & GR_READY) {
57404 + task->role = kernel_role;
57405 + task->acl = kernel_role->root_label;
57406 + }
57407 + return;
57408 +}
57409 +
57410 +#ifdef CONFIG_TASKSTATS
57411 +int gr_is_taskstats_denied(int pid)
57412 +{
57413 + struct task_struct *task;
57414 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57415 + const struct cred *cred;
57416 +#endif
57417 + int ret = 0;
57418 +
57419 + /* restrict taskstats viewing to un-chrooted root users
57420 + who have the 'view' subject flag if the RBAC system is enabled
57421 + */
57422 +
57423 + rcu_read_lock();
57424 + read_lock(&tasklist_lock);
57425 + task = find_task_by_vpid(pid);
57426 + if (task) {
57427 +#ifdef CONFIG_GRKERNSEC_CHROOT
57428 + if (proc_is_chrooted(task))
57429 + ret = -EACCES;
57430 +#endif
57431 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57432 + cred = __task_cred(task);
57433 +#ifdef CONFIG_GRKERNSEC_PROC_USER
57434 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
57435 + ret = -EACCES;
57436 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57437 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
57438 + ret = -EACCES;
57439 +#endif
57440 +#endif
57441 + if (gr_status & GR_READY) {
57442 + if (!(task->acl->mode & GR_VIEW))
57443 + ret = -EACCES;
57444 + }
57445 + } else
57446 + ret = -ENOENT;
57447 +
57448 + read_unlock(&tasklist_lock);
57449 + rcu_read_unlock();
57450 +
57451 + return ret;
57452 +}
57453 +#endif
57454 +
57455 +/* AUXV entries are filled via a descendant of search_binary_handler
57456 + after we've already applied the subject for the target
57457 +*/
57458 +int gr_acl_enable_at_secure(void)
57459 +{
57460 + if (unlikely(!(gr_status & GR_READY)))
57461 + return 0;
57462 +
57463 + if (current->acl->mode & GR_ATSECURE)
57464 + return 1;
57465 +
57466 + return 0;
57467 +}
57468 +
57469 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
57470 +{
57471 + struct task_struct *task = current;
57472 + struct dentry *dentry = file->f_path.dentry;
57473 + struct vfsmount *mnt = file->f_path.mnt;
57474 + struct acl_object_label *obj, *tmp;
57475 + struct acl_subject_label *subj;
57476 + unsigned int bufsize;
57477 + int is_not_root;
57478 + char *path;
57479 + dev_t dev = __get_dev(dentry);
57480 +
57481 + if (unlikely(!(gr_status & GR_READY)))
57482 + return 1;
57483 +
57484 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
57485 + return 1;
57486 +
57487 + /* ignore Eric Biederman */
57488 + if (IS_PRIVATE(dentry->d_inode))
57489 + return 1;
57490 +
57491 + subj = task->acl;
57492 + read_lock(&gr_inode_lock);
57493 + do {
57494 + obj = lookup_acl_obj_label(ino, dev, subj);
57495 + if (obj != NULL) {
57496 + read_unlock(&gr_inode_lock);
57497 + return (obj->mode & GR_FIND) ? 1 : 0;
57498 + }
57499 + } while ((subj = subj->parent_subject));
57500 + read_unlock(&gr_inode_lock);
57501 +
57502 + /* this is purely an optimization since we're looking for an object
57503 + for the directory we're doing a readdir on
57504 + if it's possible for any globbed object to match the entry we're
57505 + filling into the directory, then the object we find here will be
57506 + an anchor point with attached globbed objects
57507 + */
57508 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
57509 + if (obj->globbed == NULL)
57510 + return (obj->mode & GR_FIND) ? 1 : 0;
57511 +
57512 + is_not_root = ((obj->filename[0] == '/') &&
57513 + (obj->filename[1] == '\0')) ? 0 : 1;
57514 + bufsize = PAGE_SIZE - namelen - is_not_root;
57515 +
57516 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
57517 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
57518 + return 1;
57519 +
57520 + preempt_disable();
57521 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57522 + bufsize);
57523 +
57524 + bufsize = strlen(path);
57525 +
57526 + /* if base is "/", don't append an additional slash */
57527 + if (is_not_root)
57528 + *(path + bufsize) = '/';
57529 + memcpy(path + bufsize + is_not_root, name, namelen);
57530 + *(path + bufsize + namelen + is_not_root) = '\0';
57531 +
57532 + tmp = obj->globbed;
57533 + while (tmp) {
57534 + if (!glob_match(tmp->filename, path)) {
57535 + preempt_enable();
57536 + return (tmp->mode & GR_FIND) ? 1 : 0;
57537 + }
57538 + tmp = tmp->next;
57539 + }
57540 + preempt_enable();
57541 + return (obj->mode & GR_FIND) ? 1 : 0;
57542 +}
57543 +
57544 +void gr_put_exec_file(struct task_struct *task)
57545 +{
57546 + struct file *filp;
57547 +
57548 + write_lock(&grsec_exec_file_lock);
57549 + filp = task->exec_file;
57550 + task->exec_file = NULL;
57551 + write_unlock(&grsec_exec_file_lock);
57552 +
57553 + if (filp)
57554 + fput(filp);
57555 +
57556 + return;
57557 +}
57558 +
57559 +
57560 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
57561 +EXPORT_SYMBOL(gr_acl_is_enabled);
57562 +#endif
57563 +EXPORT_SYMBOL(gr_learn_resource);
57564 +EXPORT_SYMBOL(gr_set_kernel_label);
57565 +#ifdef CONFIG_SECURITY
57566 +EXPORT_SYMBOL(gr_check_user_change);
57567 +EXPORT_SYMBOL(gr_check_group_change);
57568 +#endif
57569 +
57570 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
57571 new file mode 100644
57572 index 0000000..34fefda
57573 --- /dev/null
57574 +++ b/grsecurity/gracl_alloc.c
57575 @@ -0,0 +1,105 @@
57576 +#include <linux/kernel.h>
57577 +#include <linux/mm.h>
57578 +#include <linux/slab.h>
57579 +#include <linux/vmalloc.h>
57580 +#include <linux/gracl.h>
57581 +#include <linux/grsecurity.h>
57582 +
57583 +static unsigned long alloc_stack_next = 1;
57584 +static unsigned long alloc_stack_size = 1;
57585 +static void **alloc_stack;
57586 +
57587 +static __inline__ int
57588 +alloc_pop(void)
57589 +{
57590 + if (alloc_stack_next == 1)
57591 + return 0;
57592 +
57593 + kfree(alloc_stack[alloc_stack_next - 2]);
57594 +
57595 + alloc_stack_next--;
57596 +
57597 + return 1;
57598 +}
57599 +
57600 +static __inline__ int
57601 +alloc_push(void *buf)
57602 +{
57603 + if (alloc_stack_next >= alloc_stack_size)
57604 + return 1;
57605 +
57606 + alloc_stack[alloc_stack_next - 1] = buf;
57607 +
57608 + alloc_stack_next++;
57609 +
57610 + return 0;
57611 +}
57612 +
57613 +void *
57614 +acl_alloc(unsigned long len)
57615 +{
57616 + void *ret = NULL;
57617 +
57618 + if (!len || len > PAGE_SIZE)
57619 + goto out;
57620 +
57621 + ret = kmalloc(len, GFP_KERNEL);
57622 +
57623 + if (ret) {
57624 + if (alloc_push(ret)) {
57625 + kfree(ret);
57626 + ret = NULL;
57627 + }
57628 + }
57629 +
57630 +out:
57631 + return ret;
57632 +}
57633 +
57634 +void *
57635 +acl_alloc_num(unsigned long num, unsigned long len)
57636 +{
57637 + if (!len || (num > (PAGE_SIZE / len)))
57638 + return NULL;
57639 +
57640 + return acl_alloc(num * len);
57641 +}
57642 +
57643 +void
57644 +acl_free_all(void)
57645 +{
57646 + if (gr_acl_is_enabled() || !alloc_stack)
57647 + return;
57648 +
57649 + while (alloc_pop()) ;
57650 +
57651 + if (alloc_stack) {
57652 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
57653 + kfree(alloc_stack);
57654 + else
57655 + vfree(alloc_stack);
57656 + }
57657 +
57658 + alloc_stack = NULL;
57659 + alloc_stack_size = 1;
57660 + alloc_stack_next = 1;
57661 +
57662 + return;
57663 +}
57664 +
57665 +int
57666 +acl_alloc_stack_init(unsigned long size)
57667 +{
57668 + if ((size * sizeof (void *)) <= PAGE_SIZE)
57669 + alloc_stack =
57670 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
57671 + else
57672 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
57673 +
57674 + alloc_stack_size = size;
57675 +
57676 + if (!alloc_stack)
57677 + return 0;
57678 + else
57679 + return 1;
57680 +}
57681 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
57682 new file mode 100644
57683 index 0000000..6d21049
57684 --- /dev/null
57685 +++ b/grsecurity/gracl_cap.c
57686 @@ -0,0 +1,110 @@
57687 +#include <linux/kernel.h>
57688 +#include <linux/module.h>
57689 +#include <linux/sched.h>
57690 +#include <linux/gracl.h>
57691 +#include <linux/grsecurity.h>
57692 +#include <linux/grinternal.h>
57693 +
57694 +extern const char *captab_log[];
57695 +extern int captab_log_entries;
57696 +
57697 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57698 +{
57699 + struct acl_subject_label *curracl;
57700 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57701 + kernel_cap_t cap_audit = __cap_empty_set;
57702 +
57703 + if (!gr_acl_is_enabled())
57704 + return 1;
57705 +
57706 + curracl = task->acl;
57707 +
57708 + cap_drop = curracl->cap_lower;
57709 + cap_mask = curracl->cap_mask;
57710 + cap_audit = curracl->cap_invert_audit;
57711 +
57712 + while ((curracl = curracl->parent_subject)) {
57713 + /* if the cap isn't specified in the current computed mask but is specified in the
57714 + current level subject, and is lowered in the current level subject, then add
57715 + it to the set of dropped capabilities
57716 + otherwise, add the current level subject's mask to the current computed mask
57717 + */
57718 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57719 + cap_raise(cap_mask, cap);
57720 + if (cap_raised(curracl->cap_lower, cap))
57721 + cap_raise(cap_drop, cap);
57722 + if (cap_raised(curracl->cap_invert_audit, cap))
57723 + cap_raise(cap_audit, cap);
57724 + }
57725 + }
57726 +
57727 + if (!cap_raised(cap_drop, cap)) {
57728 + if (cap_raised(cap_audit, cap))
57729 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
57730 + return 1;
57731 + }
57732 +
57733 + curracl = task->acl;
57734 +
57735 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
57736 + && cap_raised(cred->cap_effective, cap)) {
57737 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57738 + task->role->roletype, cred->uid,
57739 + cred->gid, task->exec_file ?
57740 + gr_to_filename(task->exec_file->f_path.dentry,
57741 + task->exec_file->f_path.mnt) : curracl->filename,
57742 + curracl->filename, 0UL,
57743 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
57744 + return 1;
57745 + }
57746 +
57747 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
57748 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
57749 +
57750 + return 0;
57751 +}
57752 +
57753 +int
57754 +gr_acl_is_capable(const int cap)
57755 +{
57756 + return gr_task_acl_is_capable(current, current_cred(), cap);
57757 +}
57758 +
57759 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
57760 +{
57761 + struct acl_subject_label *curracl;
57762 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57763 +
57764 + if (!gr_acl_is_enabled())
57765 + return 1;
57766 +
57767 + curracl = task->acl;
57768 +
57769 + cap_drop = curracl->cap_lower;
57770 + cap_mask = curracl->cap_mask;
57771 +
57772 + while ((curracl = curracl->parent_subject)) {
57773 + /* if the cap isn't specified in the current computed mask but is specified in the
57774 + current level subject, and is lowered in the current level subject, then add
57775 + it to the set of dropped capabilities
57776 + otherwise, add the current level subject's mask to the current computed mask
57777 + */
57778 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57779 + cap_raise(cap_mask, cap);
57780 + if (cap_raised(curracl->cap_lower, cap))
57781 + cap_raise(cap_drop, cap);
57782 + }
57783 + }
57784 +
57785 + if (!cap_raised(cap_drop, cap))
57786 + return 1;
57787 +
57788 + return 0;
57789 +}
57790 +
57791 +int
57792 +gr_acl_is_capable_nolog(const int cap)
57793 +{
57794 + return gr_task_acl_is_capable_nolog(current, cap);
57795 +}
57796 +
57797 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
57798 new file mode 100644
57799 index 0000000..a340c17
57800 --- /dev/null
57801 +++ b/grsecurity/gracl_fs.c
57802 @@ -0,0 +1,431 @@
57803 +#include <linux/kernel.h>
57804 +#include <linux/sched.h>
57805 +#include <linux/types.h>
57806 +#include <linux/fs.h>
57807 +#include <linux/file.h>
57808 +#include <linux/stat.h>
57809 +#include <linux/grsecurity.h>
57810 +#include <linux/grinternal.h>
57811 +#include <linux/gracl.h>
57812 +
57813 +umode_t
57814 +gr_acl_umask(void)
57815 +{
57816 + if (unlikely(!gr_acl_is_enabled()))
57817 + return 0;
57818 +
57819 + return current->role->umask;
57820 +}
57821 +
57822 +__u32
57823 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57824 + const struct vfsmount * mnt)
57825 +{
57826 + __u32 mode;
57827 +
57828 + if (unlikely(!dentry->d_inode))
57829 + return GR_FIND;
57830 +
57831 + mode =
57832 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
57833 +
57834 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
57835 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57836 + return mode;
57837 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
57838 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57839 + return 0;
57840 + } else if (unlikely(!(mode & GR_FIND)))
57841 + return 0;
57842 +
57843 + return GR_FIND;
57844 +}
57845 +
57846 +__u32
57847 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57848 + int acc_mode)
57849 +{
57850 + __u32 reqmode = GR_FIND;
57851 + __u32 mode;
57852 +
57853 + if (unlikely(!dentry->d_inode))
57854 + return reqmode;
57855 +
57856 + if (acc_mode & MAY_APPEND)
57857 + reqmode |= GR_APPEND;
57858 + else if (acc_mode & MAY_WRITE)
57859 + reqmode |= GR_WRITE;
57860 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
57861 + reqmode |= GR_READ;
57862 +
57863 + mode =
57864 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
57865 + mnt);
57866 +
57867 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57868 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57869 + reqmode & GR_READ ? " reading" : "",
57870 + reqmode & GR_WRITE ? " writing" : reqmode &
57871 + GR_APPEND ? " appending" : "");
57872 + return reqmode;
57873 + } else
57874 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57875 + {
57876 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57877 + reqmode & GR_READ ? " reading" : "",
57878 + reqmode & GR_WRITE ? " writing" : reqmode &
57879 + GR_APPEND ? " appending" : "");
57880 + return 0;
57881 + } else if (unlikely((mode & reqmode) != reqmode))
57882 + return 0;
57883 +
57884 + return reqmode;
57885 +}
57886 +
57887 +__u32
57888 +gr_acl_handle_creat(const struct dentry * dentry,
57889 + const struct dentry * p_dentry,
57890 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57891 + const int imode)
57892 +{
57893 + __u32 reqmode = GR_WRITE | GR_CREATE;
57894 + __u32 mode;
57895 +
57896 + if (acc_mode & MAY_APPEND)
57897 + reqmode |= GR_APPEND;
57898 + // if a directory was required or the directory already exists, then
57899 + // don't count this open as a read
57900 + if ((acc_mode & MAY_READ) &&
57901 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
57902 + reqmode |= GR_READ;
57903 + if ((open_flags & O_CREAT) &&
57904 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
57905 + reqmode |= GR_SETID;
57906 +
57907 + mode =
57908 + gr_check_create(dentry, p_dentry, p_mnt,
57909 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
57910 +
57911 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57912 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
57913 + reqmode & GR_READ ? " reading" : "",
57914 + reqmode & GR_WRITE ? " writing" : reqmode &
57915 + GR_APPEND ? " appending" : "");
57916 + return reqmode;
57917 + } else
57918 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57919 + {
57920 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
57921 + reqmode & GR_READ ? " reading" : "",
57922 + reqmode & GR_WRITE ? " writing" : reqmode &
57923 + GR_APPEND ? " appending" : "");
57924 + return 0;
57925 + } else if (unlikely((mode & reqmode) != reqmode))
57926 + return 0;
57927 +
57928 + return reqmode;
57929 +}
57930 +
57931 +__u32
57932 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
57933 + const int fmode)
57934 +{
57935 + __u32 mode, reqmode = GR_FIND;
57936 +
57937 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
57938 + reqmode |= GR_EXEC;
57939 + if (fmode & S_IWOTH)
57940 + reqmode |= GR_WRITE;
57941 + if (fmode & S_IROTH)
57942 + reqmode |= GR_READ;
57943 +
57944 + mode =
57945 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
57946 + mnt);
57947 +
57948 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57949 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
57950 + reqmode & GR_READ ? " reading" : "",
57951 + reqmode & GR_WRITE ? " writing" : "",
57952 + reqmode & GR_EXEC ? " executing" : "");
57953 + return reqmode;
57954 + } else
57955 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57956 + {
57957 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
57958 + reqmode & GR_READ ? " reading" : "",
57959 + reqmode & GR_WRITE ? " writing" : "",
57960 + reqmode & GR_EXEC ? " executing" : "");
57961 + return 0;
57962 + } else if (unlikely((mode & reqmode) != reqmode))
57963 + return 0;
57964 +
57965 + return reqmode;
57966 +}
57967 +
57968 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
57969 +{
57970 + __u32 mode;
57971 +
57972 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
57973 +
57974 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
57975 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
57976 + return mode;
57977 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
57978 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
57979 + return 0;
57980 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
57981 + return 0;
57982 +
57983 + return (reqmode);
57984 +}
57985 +
57986 +__u32
57987 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57988 +{
57989 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
57990 +}
57991 +
57992 +__u32
57993 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
57994 +{
57995 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
57996 +}
57997 +
57998 +__u32
57999 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
58000 +{
58001 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
58002 +}
58003 +
58004 +__u32
58005 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
58006 +{
58007 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
58008 +}
58009 +
58010 +__u32
58011 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
58012 + umode_t *modeptr)
58013 +{
58014 + umode_t mode;
58015 +
58016 + *modeptr &= ~gr_acl_umask();
58017 + mode = *modeptr;
58018 +
58019 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
58020 + return 1;
58021 +
58022 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
58023 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
58024 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
58025 + GR_CHMOD_ACL_MSG);
58026 + } else {
58027 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
58028 + }
58029 +}
58030 +
58031 +__u32
58032 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
58033 +{
58034 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
58035 +}
58036 +
58037 +__u32
58038 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
58039 +{
58040 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
58041 +}
58042 +
58043 +__u32
58044 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
58045 +{
58046 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
58047 +}
58048 +
58049 +__u32
58050 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
58051 +{
58052 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
58053 + GR_UNIXCONNECT_ACL_MSG);
58054 +}
58055 +
58056 +/* hardlinks require at minimum create and link permission,
58057 + any additional privilege required is based on the
58058 + privilege of the file being linked to
58059 +*/
58060 +__u32
58061 +gr_acl_handle_link(const struct dentry * new_dentry,
58062 + const struct dentry * parent_dentry,
58063 + const struct vfsmount * parent_mnt,
58064 + const struct dentry * old_dentry,
58065 + const struct vfsmount * old_mnt, const struct filename *to)
58066 +{
58067 + __u32 mode;
58068 + __u32 needmode = GR_CREATE | GR_LINK;
58069 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
58070 +
58071 + mode =
58072 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
58073 + old_mnt);
58074 +
58075 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
58076 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58077 + return mode;
58078 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58079 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58080 + return 0;
58081 + } else if (unlikely((mode & needmode) != needmode))
58082 + return 0;
58083 +
58084 + return 1;
58085 +}
58086 +
58087 +__u32
58088 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58089 + const struct dentry * parent_dentry,
58090 + const struct vfsmount * parent_mnt, const struct filename *from)
58091 +{
58092 + __u32 needmode = GR_WRITE | GR_CREATE;
58093 + __u32 mode;
58094 +
58095 + mode =
58096 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
58097 + GR_CREATE | GR_AUDIT_CREATE |
58098 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
58099 +
58100 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
58101 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
58102 + return mode;
58103 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58104 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
58105 + return 0;
58106 + } else if (unlikely((mode & needmode) != needmode))
58107 + return 0;
58108 +
58109 + return (GR_WRITE | GR_CREATE);
58110 +}
58111 +
58112 +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)
58113 +{
58114 + __u32 mode;
58115 +
58116 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
58117 +
58118 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58119 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
58120 + return mode;
58121 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58122 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
58123 + return 0;
58124 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
58125 + return 0;
58126 +
58127 + return (reqmode);
58128 +}
58129 +
58130 +__u32
58131 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58132 + const struct dentry * parent_dentry,
58133 + const struct vfsmount * parent_mnt,
58134 + const int mode)
58135 +{
58136 + __u32 reqmode = GR_WRITE | GR_CREATE;
58137 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
58138 + reqmode |= GR_SETID;
58139 +
58140 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
58141 + reqmode, GR_MKNOD_ACL_MSG);
58142 +}
58143 +
58144 +__u32
58145 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
58146 + const struct dentry *parent_dentry,
58147 + const struct vfsmount *parent_mnt)
58148 +{
58149 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
58150 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
58151 +}
58152 +
58153 +#define RENAME_CHECK_SUCCESS(old, new) \
58154 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
58155 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
58156 +
58157 +int
58158 +gr_acl_handle_rename(struct dentry *new_dentry,
58159 + struct dentry *parent_dentry,
58160 + const struct vfsmount *parent_mnt,
58161 + struct dentry *old_dentry,
58162 + struct inode *old_parent_inode,
58163 + struct vfsmount *old_mnt, const struct filename *newname)
58164 +{
58165 + __u32 comp1, comp2;
58166 + int error = 0;
58167 +
58168 + if (unlikely(!gr_acl_is_enabled()))
58169 + return 0;
58170 +
58171 + if (!new_dentry->d_inode) {
58172 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
58173 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
58174 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
58175 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
58176 + GR_DELETE | GR_AUDIT_DELETE |
58177 + GR_AUDIT_READ | GR_AUDIT_WRITE |
58178 + GR_SUPPRESS, old_mnt);
58179 + } else {
58180 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
58181 + GR_CREATE | GR_DELETE |
58182 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
58183 + GR_AUDIT_READ | GR_AUDIT_WRITE |
58184 + GR_SUPPRESS, parent_mnt);
58185 + comp2 =
58186 + gr_search_file(old_dentry,
58187 + GR_READ | GR_WRITE | GR_AUDIT_READ |
58188 + GR_DELETE | GR_AUDIT_DELETE |
58189 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
58190 + }
58191 +
58192 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
58193 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
58194 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
58195 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
58196 + && !(comp2 & GR_SUPPRESS)) {
58197 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
58198 + error = -EACCES;
58199 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
58200 + error = -EACCES;
58201 +
58202 + return error;
58203 +}
58204 +
58205 +void
58206 +gr_acl_handle_exit(void)
58207 +{
58208 + u16 id;
58209 + char *rolename;
58210 +
58211 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
58212 + !(current->role->roletype & GR_ROLE_PERSIST))) {
58213 + id = current->acl_role_id;
58214 + rolename = current->role->rolename;
58215 + gr_set_acls(1);
58216 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
58217 + }
58218 +
58219 + gr_put_exec_file(current);
58220 + return;
58221 +}
58222 +
58223 +int
58224 +gr_acl_handle_procpidmem(const struct task_struct *task)
58225 +{
58226 + if (unlikely(!gr_acl_is_enabled()))
58227 + return 0;
58228 +
58229 + if (task != current && task->acl->mode & GR_PROTPROCFD)
58230 + return -EACCES;
58231 +
58232 + return 0;
58233 +}
58234 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
58235 new file mode 100644
58236 index 0000000..58800a7
58237 --- /dev/null
58238 +++ b/grsecurity/gracl_ip.c
58239 @@ -0,0 +1,384 @@
58240 +#include <linux/kernel.h>
58241 +#include <asm/uaccess.h>
58242 +#include <asm/errno.h>
58243 +#include <net/sock.h>
58244 +#include <linux/file.h>
58245 +#include <linux/fs.h>
58246 +#include <linux/net.h>
58247 +#include <linux/in.h>
58248 +#include <linux/skbuff.h>
58249 +#include <linux/ip.h>
58250 +#include <linux/udp.h>
58251 +#include <linux/types.h>
58252 +#include <linux/sched.h>
58253 +#include <linux/netdevice.h>
58254 +#include <linux/inetdevice.h>
58255 +#include <linux/gracl.h>
58256 +#include <linux/grsecurity.h>
58257 +#include <linux/grinternal.h>
58258 +
58259 +#define GR_BIND 0x01
58260 +#define GR_CONNECT 0x02
58261 +#define GR_INVERT 0x04
58262 +#define GR_BINDOVERRIDE 0x08
58263 +#define GR_CONNECTOVERRIDE 0x10
58264 +#define GR_SOCK_FAMILY 0x20
58265 +
58266 +static const char * gr_protocols[IPPROTO_MAX] = {
58267 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
58268 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
58269 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
58270 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
58271 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
58272 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
58273 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
58274 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
58275 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
58276 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
58277 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
58278 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
58279 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
58280 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
58281 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
58282 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
58283 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
58284 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
58285 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
58286 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
58287 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
58288 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
58289 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
58290 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
58291 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
58292 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
58293 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
58294 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
58295 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
58296 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
58297 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
58298 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
58299 + };
58300 +
58301 +static const char * gr_socktypes[SOCK_MAX] = {
58302 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
58303 + "unknown:7", "unknown:8", "unknown:9", "packet"
58304 + };
58305 +
58306 +static const char * gr_sockfamilies[AF_MAX+1] = {
58307 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
58308 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
58309 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
58310 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
58311 + };
58312 +
58313 +const char *
58314 +gr_proto_to_name(unsigned char proto)
58315 +{
58316 + return gr_protocols[proto];
58317 +}
58318 +
58319 +const char *
58320 +gr_socktype_to_name(unsigned char type)
58321 +{
58322 + return gr_socktypes[type];
58323 +}
58324 +
58325 +const char *
58326 +gr_sockfamily_to_name(unsigned char family)
58327 +{
58328 + return gr_sockfamilies[family];
58329 +}
58330 +
58331 +int
58332 +gr_search_socket(const int domain, const int type, const int protocol)
58333 +{
58334 + struct acl_subject_label *curr;
58335 + const struct cred *cred = current_cred();
58336 +
58337 + if (unlikely(!gr_acl_is_enabled()))
58338 + goto exit;
58339 +
58340 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
58341 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
58342 + goto exit; // let the kernel handle it
58343 +
58344 + curr = current->acl;
58345 +
58346 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
58347 + /* the family is allowed, if this is PF_INET allow it only if
58348 + the extra sock type/protocol checks pass */
58349 + if (domain == PF_INET)
58350 + goto inet_check;
58351 + goto exit;
58352 + } else {
58353 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58354 + __u32 fakeip = 0;
58355 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58356 + current->role->roletype, cred->uid,
58357 + cred->gid, current->exec_file ?
58358 + gr_to_filename(current->exec_file->f_path.dentry,
58359 + current->exec_file->f_path.mnt) :
58360 + curr->filename, curr->filename,
58361 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
58362 + &current->signal->saved_ip);
58363 + goto exit;
58364 + }
58365 + goto exit_fail;
58366 + }
58367 +
58368 +inet_check:
58369 + /* the rest of this checking is for IPv4 only */
58370 + if (!curr->ips)
58371 + goto exit;
58372 +
58373 + if ((curr->ip_type & (1 << type)) &&
58374 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
58375 + goto exit;
58376 +
58377 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58378 + /* we don't place acls on raw sockets , and sometimes
58379 + dgram/ip sockets are opened for ioctl and not
58380 + bind/connect, so we'll fake a bind learn log */
58381 + if (type == SOCK_RAW || type == SOCK_PACKET) {
58382 + __u32 fakeip = 0;
58383 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58384 + current->role->roletype, cred->uid,
58385 + cred->gid, current->exec_file ?
58386 + gr_to_filename(current->exec_file->f_path.dentry,
58387 + current->exec_file->f_path.mnt) :
58388 + curr->filename, curr->filename,
58389 + &fakeip, 0, type,
58390 + protocol, GR_CONNECT, &current->signal->saved_ip);
58391 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
58392 + __u32 fakeip = 0;
58393 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58394 + current->role->roletype, cred->uid,
58395 + cred->gid, current->exec_file ?
58396 + gr_to_filename(current->exec_file->f_path.dentry,
58397 + current->exec_file->f_path.mnt) :
58398 + curr->filename, curr->filename,
58399 + &fakeip, 0, type,
58400 + protocol, GR_BIND, &current->signal->saved_ip);
58401 + }
58402 + /* we'll log when they use connect or bind */
58403 + goto exit;
58404 + }
58405 +
58406 +exit_fail:
58407 + if (domain == PF_INET)
58408 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
58409 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
58410 + else
58411 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
58412 + gr_socktype_to_name(type), protocol);
58413 +
58414 + return 0;
58415 +exit:
58416 + return 1;
58417 +}
58418 +
58419 +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)
58420 +{
58421 + if ((ip->mode & mode) &&
58422 + (ip_port >= ip->low) &&
58423 + (ip_port <= ip->high) &&
58424 + ((ntohl(ip_addr) & our_netmask) ==
58425 + (ntohl(our_addr) & our_netmask))
58426 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
58427 + && (ip->type & (1 << type))) {
58428 + if (ip->mode & GR_INVERT)
58429 + return 2; // specifically denied
58430 + else
58431 + return 1; // allowed
58432 + }
58433 +
58434 + return 0; // not specifically allowed, may continue parsing
58435 +}
58436 +
58437 +static int
58438 +gr_search_connectbind(const int full_mode, struct sock *sk,
58439 + struct sockaddr_in *addr, const int type)
58440 +{
58441 + char iface[IFNAMSIZ] = {0};
58442 + struct acl_subject_label *curr;
58443 + struct acl_ip_label *ip;
58444 + struct inet_sock *isk;
58445 + struct net_device *dev;
58446 + struct in_device *idev;
58447 + unsigned long i;
58448 + int ret;
58449 + int mode = full_mode & (GR_BIND | GR_CONNECT);
58450 + __u32 ip_addr = 0;
58451 + __u32 our_addr;
58452 + __u32 our_netmask;
58453 + char *p;
58454 + __u16 ip_port = 0;
58455 + const struct cred *cred = current_cred();
58456 +
58457 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
58458 + return 0;
58459 +
58460 + curr = current->acl;
58461 + isk = inet_sk(sk);
58462 +
58463 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
58464 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
58465 + addr->sin_addr.s_addr = curr->inaddr_any_override;
58466 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
58467 + struct sockaddr_in saddr;
58468 + int err;
58469 +
58470 + saddr.sin_family = AF_INET;
58471 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
58472 + saddr.sin_port = isk->inet_sport;
58473 +
58474 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58475 + if (err)
58476 + return err;
58477 +
58478 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58479 + if (err)
58480 + return err;
58481 + }
58482 +
58483 + if (!curr->ips)
58484 + return 0;
58485 +
58486 + ip_addr = addr->sin_addr.s_addr;
58487 + ip_port = ntohs(addr->sin_port);
58488 +
58489 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58490 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58491 + current->role->roletype, cred->uid,
58492 + cred->gid, current->exec_file ?
58493 + gr_to_filename(current->exec_file->f_path.dentry,
58494 + current->exec_file->f_path.mnt) :
58495 + curr->filename, curr->filename,
58496 + &ip_addr, ip_port, type,
58497 + sk->sk_protocol, mode, &current->signal->saved_ip);
58498 + return 0;
58499 + }
58500 +
58501 + for (i = 0; i < curr->ip_num; i++) {
58502 + ip = *(curr->ips + i);
58503 + if (ip->iface != NULL) {
58504 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
58505 + p = strchr(iface, ':');
58506 + if (p != NULL)
58507 + *p = '\0';
58508 + dev = dev_get_by_name(sock_net(sk), iface);
58509 + if (dev == NULL)
58510 + continue;
58511 + idev = in_dev_get(dev);
58512 + if (idev == NULL) {
58513 + dev_put(dev);
58514 + continue;
58515 + }
58516 + rcu_read_lock();
58517 + for_ifa(idev) {
58518 + if (!strcmp(ip->iface, ifa->ifa_label)) {
58519 + our_addr = ifa->ifa_address;
58520 + our_netmask = 0xffffffff;
58521 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58522 + if (ret == 1) {
58523 + rcu_read_unlock();
58524 + in_dev_put(idev);
58525 + dev_put(dev);
58526 + return 0;
58527 + } else if (ret == 2) {
58528 + rcu_read_unlock();
58529 + in_dev_put(idev);
58530 + dev_put(dev);
58531 + goto denied;
58532 + }
58533 + }
58534 + } endfor_ifa(idev);
58535 + rcu_read_unlock();
58536 + in_dev_put(idev);
58537 + dev_put(dev);
58538 + } else {
58539 + our_addr = ip->addr;
58540 + our_netmask = ip->netmask;
58541 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58542 + if (ret == 1)
58543 + return 0;
58544 + else if (ret == 2)
58545 + goto denied;
58546 + }
58547 + }
58548 +
58549 +denied:
58550 + if (mode == GR_BIND)
58551 + 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));
58552 + else if (mode == GR_CONNECT)
58553 + 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));
58554 +
58555 + return -EACCES;
58556 +}
58557 +
58558 +int
58559 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
58560 +{
58561 + /* always allow disconnection of dgram sockets with connect */
58562 + if (addr->sin_family == AF_UNSPEC)
58563 + return 0;
58564 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
58565 +}
58566 +
58567 +int
58568 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
58569 +{
58570 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
58571 +}
58572 +
58573 +int gr_search_listen(struct socket *sock)
58574 +{
58575 + struct sock *sk = sock->sk;
58576 + struct sockaddr_in addr;
58577 +
58578 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58579 + addr.sin_port = inet_sk(sk)->inet_sport;
58580 +
58581 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58582 +}
58583 +
58584 +int gr_search_accept(struct socket *sock)
58585 +{
58586 + struct sock *sk = sock->sk;
58587 + struct sockaddr_in addr;
58588 +
58589 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58590 + addr.sin_port = inet_sk(sk)->inet_sport;
58591 +
58592 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58593 +}
58594 +
58595 +int
58596 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
58597 +{
58598 + if (addr)
58599 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
58600 + else {
58601 + struct sockaddr_in sin;
58602 + const struct inet_sock *inet = inet_sk(sk);
58603 +
58604 + sin.sin_addr.s_addr = inet->inet_daddr;
58605 + sin.sin_port = inet->inet_dport;
58606 +
58607 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58608 + }
58609 +}
58610 +
58611 +int
58612 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
58613 +{
58614 + struct sockaddr_in sin;
58615 +
58616 + if (unlikely(skb->len < sizeof (struct udphdr)))
58617 + return 0; // skip this packet
58618 +
58619 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
58620 + sin.sin_port = udp_hdr(skb)->source;
58621 +
58622 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58623 +}
58624 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
58625 new file mode 100644
58626 index 0000000..25f54ef
58627 --- /dev/null
58628 +++ b/grsecurity/gracl_learn.c
58629 @@ -0,0 +1,207 @@
58630 +#include <linux/kernel.h>
58631 +#include <linux/mm.h>
58632 +#include <linux/sched.h>
58633 +#include <linux/poll.h>
58634 +#include <linux/string.h>
58635 +#include <linux/file.h>
58636 +#include <linux/types.h>
58637 +#include <linux/vmalloc.h>
58638 +#include <linux/grinternal.h>
58639 +
58640 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
58641 + size_t count, loff_t *ppos);
58642 +extern int gr_acl_is_enabled(void);
58643 +
58644 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
58645 +static int gr_learn_attached;
58646 +
58647 +/* use a 512k buffer */
58648 +#define LEARN_BUFFER_SIZE (512 * 1024)
58649 +
58650 +static DEFINE_SPINLOCK(gr_learn_lock);
58651 +static DEFINE_MUTEX(gr_learn_user_mutex);
58652 +
58653 +/* we need to maintain two buffers, so that the kernel context of grlearn
58654 + uses a semaphore around the userspace copying, and the other kernel contexts
58655 + use a spinlock when copying into the buffer, since they cannot sleep
58656 +*/
58657 +static char *learn_buffer;
58658 +static char *learn_buffer_user;
58659 +static int learn_buffer_len;
58660 +static int learn_buffer_user_len;
58661 +
58662 +static ssize_t
58663 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
58664 +{
58665 + DECLARE_WAITQUEUE(wait, current);
58666 + ssize_t retval = 0;
58667 +
58668 + add_wait_queue(&learn_wait, &wait);
58669 + set_current_state(TASK_INTERRUPTIBLE);
58670 + do {
58671 + mutex_lock(&gr_learn_user_mutex);
58672 + spin_lock(&gr_learn_lock);
58673 + if (learn_buffer_len)
58674 + break;
58675 + spin_unlock(&gr_learn_lock);
58676 + mutex_unlock(&gr_learn_user_mutex);
58677 + if (file->f_flags & O_NONBLOCK) {
58678 + retval = -EAGAIN;
58679 + goto out;
58680 + }
58681 + if (signal_pending(current)) {
58682 + retval = -ERESTARTSYS;
58683 + goto out;
58684 + }
58685 +
58686 + schedule();
58687 + } while (1);
58688 +
58689 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
58690 + learn_buffer_user_len = learn_buffer_len;
58691 + retval = learn_buffer_len;
58692 + learn_buffer_len = 0;
58693 +
58694 + spin_unlock(&gr_learn_lock);
58695 +
58696 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
58697 + retval = -EFAULT;
58698 +
58699 + mutex_unlock(&gr_learn_user_mutex);
58700 +out:
58701 + set_current_state(TASK_RUNNING);
58702 + remove_wait_queue(&learn_wait, &wait);
58703 + return retval;
58704 +}
58705 +
58706 +static unsigned int
58707 +poll_learn(struct file * file, poll_table * wait)
58708 +{
58709 + poll_wait(file, &learn_wait, wait);
58710 +
58711 + if (learn_buffer_len)
58712 + return (POLLIN | POLLRDNORM);
58713 +
58714 + return 0;
58715 +}
58716 +
58717 +void
58718 +gr_clear_learn_entries(void)
58719 +{
58720 + char *tmp;
58721 +
58722 + mutex_lock(&gr_learn_user_mutex);
58723 + spin_lock(&gr_learn_lock);
58724 + tmp = learn_buffer;
58725 + learn_buffer = NULL;
58726 + spin_unlock(&gr_learn_lock);
58727 + if (tmp)
58728 + vfree(tmp);
58729 + if (learn_buffer_user != NULL) {
58730 + vfree(learn_buffer_user);
58731 + learn_buffer_user = NULL;
58732 + }
58733 + learn_buffer_len = 0;
58734 + mutex_unlock(&gr_learn_user_mutex);
58735 +
58736 + return;
58737 +}
58738 +
58739 +void
58740 +gr_add_learn_entry(const char *fmt, ...)
58741 +{
58742 + va_list args;
58743 + unsigned int len;
58744 +
58745 + if (!gr_learn_attached)
58746 + return;
58747 +
58748 + spin_lock(&gr_learn_lock);
58749 +
58750 + /* leave a gap at the end so we know when it's "full" but don't have to
58751 + compute the exact length of the string we're trying to append
58752 + */
58753 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
58754 + spin_unlock(&gr_learn_lock);
58755 + wake_up_interruptible(&learn_wait);
58756 + return;
58757 + }
58758 + if (learn_buffer == NULL) {
58759 + spin_unlock(&gr_learn_lock);
58760 + return;
58761 + }
58762 +
58763 + va_start(args, fmt);
58764 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
58765 + va_end(args);
58766 +
58767 + learn_buffer_len += len + 1;
58768 +
58769 + spin_unlock(&gr_learn_lock);
58770 + wake_up_interruptible(&learn_wait);
58771 +
58772 + return;
58773 +}
58774 +
58775 +static int
58776 +open_learn(struct inode *inode, struct file *file)
58777 +{
58778 + if (file->f_mode & FMODE_READ && gr_learn_attached)
58779 + return -EBUSY;
58780 + if (file->f_mode & FMODE_READ) {
58781 + int retval = 0;
58782 + mutex_lock(&gr_learn_user_mutex);
58783 + if (learn_buffer == NULL)
58784 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
58785 + if (learn_buffer_user == NULL)
58786 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
58787 + if (learn_buffer == NULL) {
58788 + retval = -ENOMEM;
58789 + goto out_error;
58790 + }
58791 + if (learn_buffer_user == NULL) {
58792 + retval = -ENOMEM;
58793 + goto out_error;
58794 + }
58795 + learn_buffer_len = 0;
58796 + learn_buffer_user_len = 0;
58797 + gr_learn_attached = 1;
58798 +out_error:
58799 + mutex_unlock(&gr_learn_user_mutex);
58800 + return retval;
58801 + }
58802 + return 0;
58803 +}
58804 +
58805 +static int
58806 +close_learn(struct inode *inode, struct file *file)
58807 +{
58808 + if (file->f_mode & FMODE_READ) {
58809 + char *tmp = NULL;
58810 + mutex_lock(&gr_learn_user_mutex);
58811 + spin_lock(&gr_learn_lock);
58812 + tmp = learn_buffer;
58813 + learn_buffer = NULL;
58814 + spin_unlock(&gr_learn_lock);
58815 + if (tmp)
58816 + vfree(tmp);
58817 + if (learn_buffer_user != NULL) {
58818 + vfree(learn_buffer_user);
58819 + learn_buffer_user = NULL;
58820 + }
58821 + learn_buffer_len = 0;
58822 + learn_buffer_user_len = 0;
58823 + gr_learn_attached = 0;
58824 + mutex_unlock(&gr_learn_user_mutex);
58825 + }
58826 +
58827 + return 0;
58828 +}
58829 +
58830 +const struct file_operations grsec_fops = {
58831 + .read = read_learn,
58832 + .write = write_grsec_handler,
58833 + .open = open_learn,
58834 + .release = close_learn,
58835 + .poll = poll_learn,
58836 +};
58837 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
58838 new file mode 100644
58839 index 0000000..39645c9
58840 --- /dev/null
58841 +++ b/grsecurity/gracl_res.c
58842 @@ -0,0 +1,68 @@
58843 +#include <linux/kernel.h>
58844 +#include <linux/sched.h>
58845 +#include <linux/gracl.h>
58846 +#include <linux/grinternal.h>
58847 +
58848 +static const char *restab_log[] = {
58849 + [RLIMIT_CPU] = "RLIMIT_CPU",
58850 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
58851 + [RLIMIT_DATA] = "RLIMIT_DATA",
58852 + [RLIMIT_STACK] = "RLIMIT_STACK",
58853 + [RLIMIT_CORE] = "RLIMIT_CORE",
58854 + [RLIMIT_RSS] = "RLIMIT_RSS",
58855 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
58856 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
58857 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
58858 + [RLIMIT_AS] = "RLIMIT_AS",
58859 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
58860 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
58861 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
58862 + [RLIMIT_NICE] = "RLIMIT_NICE",
58863 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
58864 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
58865 + [GR_CRASH_RES] = "RLIMIT_CRASH"
58866 +};
58867 +
58868 +void
58869 +gr_log_resource(const struct task_struct *task,
58870 + const int res, const unsigned long wanted, const int gt)
58871 +{
58872 + const struct cred *cred;
58873 + unsigned long rlim;
58874 +
58875 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
58876 + return;
58877 +
58878 + // not yet supported resource
58879 + if (unlikely(!restab_log[res]))
58880 + return;
58881 +
58882 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
58883 + rlim = task_rlimit_max(task, res);
58884 + else
58885 + rlim = task_rlimit(task, res);
58886 +
58887 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
58888 + return;
58889 +
58890 + rcu_read_lock();
58891 + cred = __task_cred(task);
58892 +
58893 + if (res == RLIMIT_NPROC &&
58894 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
58895 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
58896 + goto out_rcu_unlock;
58897 + else if (res == RLIMIT_MEMLOCK &&
58898 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
58899 + goto out_rcu_unlock;
58900 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
58901 + goto out_rcu_unlock;
58902 + rcu_read_unlock();
58903 +
58904 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
58905 +
58906 + return;
58907 +out_rcu_unlock:
58908 + rcu_read_unlock();
58909 + return;
58910 +}
58911 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
58912 new file mode 100644
58913 index 0000000..25197e9
58914 --- /dev/null
58915 +++ b/grsecurity/gracl_segv.c
58916 @@ -0,0 +1,299 @@
58917 +#include <linux/kernel.h>
58918 +#include <linux/mm.h>
58919 +#include <asm/uaccess.h>
58920 +#include <asm/errno.h>
58921 +#include <asm/mman.h>
58922 +#include <net/sock.h>
58923 +#include <linux/file.h>
58924 +#include <linux/fs.h>
58925 +#include <linux/net.h>
58926 +#include <linux/in.h>
58927 +#include <linux/slab.h>
58928 +#include <linux/types.h>
58929 +#include <linux/sched.h>
58930 +#include <linux/timer.h>
58931 +#include <linux/gracl.h>
58932 +#include <linux/grsecurity.h>
58933 +#include <linux/grinternal.h>
58934 +
58935 +static struct crash_uid *uid_set;
58936 +static unsigned short uid_used;
58937 +static DEFINE_SPINLOCK(gr_uid_lock);
58938 +extern rwlock_t gr_inode_lock;
58939 +extern struct acl_subject_label *
58940 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
58941 + struct acl_role_label *role);
58942 +
58943 +#ifdef CONFIG_BTRFS_FS
58944 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
58945 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
58946 +#endif
58947 +
58948 +static inline dev_t __get_dev(const struct dentry *dentry)
58949 +{
58950 +#ifdef CONFIG_BTRFS_FS
58951 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
58952 + return get_btrfs_dev_from_inode(dentry->d_inode);
58953 + else
58954 +#endif
58955 + return dentry->d_inode->i_sb->s_dev;
58956 +}
58957 +
58958 +int
58959 +gr_init_uidset(void)
58960 +{
58961 + uid_set =
58962 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
58963 + uid_used = 0;
58964 +
58965 + return uid_set ? 1 : 0;
58966 +}
58967 +
58968 +void
58969 +gr_free_uidset(void)
58970 +{
58971 + if (uid_set)
58972 + kfree(uid_set);
58973 +
58974 + return;
58975 +}
58976 +
58977 +int
58978 +gr_find_uid(const uid_t uid)
58979 +{
58980 + struct crash_uid *tmp = uid_set;
58981 + uid_t buid;
58982 + int low = 0, high = uid_used - 1, mid;
58983 +
58984 + while (high >= low) {
58985 + mid = (low + high) >> 1;
58986 + buid = tmp[mid].uid;
58987 + if (buid == uid)
58988 + return mid;
58989 + if (buid > uid)
58990 + high = mid - 1;
58991 + if (buid < uid)
58992 + low = mid + 1;
58993 + }
58994 +
58995 + return -1;
58996 +}
58997 +
58998 +static __inline__ void
58999 +gr_insertsort(void)
59000 +{
59001 + unsigned short i, j;
59002 + struct crash_uid index;
59003 +
59004 + for (i = 1; i < uid_used; i++) {
59005 + index = uid_set[i];
59006 + j = i;
59007 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
59008 + uid_set[j] = uid_set[j - 1];
59009 + j--;
59010 + }
59011 + uid_set[j] = index;
59012 + }
59013 +
59014 + return;
59015 +}
59016 +
59017 +static __inline__ void
59018 +gr_insert_uid(const uid_t uid, const unsigned long expires)
59019 +{
59020 + int loc;
59021 +
59022 + if (uid_used == GR_UIDTABLE_MAX)
59023 + return;
59024 +
59025 + loc = gr_find_uid(uid);
59026 +
59027 + if (loc >= 0) {
59028 + uid_set[loc].expires = expires;
59029 + return;
59030 + }
59031 +
59032 + uid_set[uid_used].uid = uid;
59033 + uid_set[uid_used].expires = expires;
59034 + uid_used++;
59035 +
59036 + gr_insertsort();
59037 +
59038 + return;
59039 +}
59040 +
59041 +void
59042 +gr_remove_uid(const unsigned short loc)
59043 +{
59044 + unsigned short i;
59045 +
59046 + for (i = loc + 1; i < uid_used; i++)
59047 + uid_set[i - 1] = uid_set[i];
59048 +
59049 + uid_used--;
59050 +
59051 + return;
59052 +}
59053 +
59054 +int
59055 +gr_check_crash_uid(const uid_t uid)
59056 +{
59057 + int loc;
59058 + int ret = 0;
59059 +
59060 + if (unlikely(!gr_acl_is_enabled()))
59061 + return 0;
59062 +
59063 + spin_lock(&gr_uid_lock);
59064 + loc = gr_find_uid(uid);
59065 +
59066 + if (loc < 0)
59067 + goto out_unlock;
59068 +
59069 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
59070 + gr_remove_uid(loc);
59071 + else
59072 + ret = 1;
59073 +
59074 +out_unlock:
59075 + spin_unlock(&gr_uid_lock);
59076 + return ret;
59077 +}
59078 +
59079 +static __inline__ int
59080 +proc_is_setxid(const struct cred *cred)
59081 +{
59082 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
59083 + !uid_eq(cred->uid, cred->fsuid))
59084 + return 1;
59085 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
59086 + !uid_eq(cred->gid, cred->fsgid))
59087 + return 1;
59088 +
59089 + return 0;
59090 +}
59091 +
59092 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
59093 +
59094 +void
59095 +gr_handle_crash(struct task_struct *task, const int sig)
59096 +{
59097 + struct acl_subject_label *curr;
59098 + struct task_struct *tsk, *tsk2;
59099 + const struct cred *cred;
59100 + const struct cred *cred2;
59101 +
59102 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
59103 + return;
59104 +
59105 + if (unlikely(!gr_acl_is_enabled()))
59106 + return;
59107 +
59108 + curr = task->acl;
59109 +
59110 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
59111 + return;
59112 +
59113 + if (time_before_eq(curr->expires, get_seconds())) {
59114 + curr->expires = 0;
59115 + curr->crashes = 0;
59116 + }
59117 +
59118 + curr->crashes++;
59119 +
59120 + if (!curr->expires)
59121 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
59122 +
59123 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
59124 + time_after(curr->expires, get_seconds())) {
59125 + rcu_read_lock();
59126 + cred = __task_cred(task);
59127 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
59128 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
59129 + spin_lock(&gr_uid_lock);
59130 + gr_insert_uid(cred->uid, curr->expires);
59131 + spin_unlock(&gr_uid_lock);
59132 + curr->expires = 0;
59133 + curr->crashes = 0;
59134 + read_lock(&tasklist_lock);
59135 + do_each_thread(tsk2, tsk) {
59136 + cred2 = __task_cred(tsk);
59137 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
59138 + gr_fake_force_sig(SIGKILL, tsk);
59139 + } while_each_thread(tsk2, tsk);
59140 + read_unlock(&tasklist_lock);
59141 + } else {
59142 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
59143 + read_lock(&tasklist_lock);
59144 + read_lock(&grsec_exec_file_lock);
59145 + do_each_thread(tsk2, tsk) {
59146 + if (likely(tsk != task)) {
59147 + // if this thread has the same subject as the one that triggered
59148 + // RES_CRASH and it's the same binary, kill it
59149 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
59150 + gr_fake_force_sig(SIGKILL, tsk);
59151 + }
59152 + } while_each_thread(tsk2, tsk);
59153 + read_unlock(&grsec_exec_file_lock);
59154 + read_unlock(&tasklist_lock);
59155 + }
59156 + rcu_read_unlock();
59157 + }
59158 +
59159 + return;
59160 +}
59161 +
59162 +int
59163 +gr_check_crash_exec(const struct file *filp)
59164 +{
59165 + struct acl_subject_label *curr;
59166 +
59167 + if (unlikely(!gr_acl_is_enabled()))
59168 + return 0;
59169 +
59170 + read_lock(&gr_inode_lock);
59171 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
59172 + __get_dev(filp->f_path.dentry),
59173 + current->role);
59174 + read_unlock(&gr_inode_lock);
59175 +
59176 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
59177 + (!curr->crashes && !curr->expires))
59178 + return 0;
59179 +
59180 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
59181 + time_after(curr->expires, get_seconds()))
59182 + return 1;
59183 + else if (time_before_eq(curr->expires, get_seconds())) {
59184 + curr->crashes = 0;
59185 + curr->expires = 0;
59186 + }
59187 +
59188 + return 0;
59189 +}
59190 +
59191 +void
59192 +gr_handle_alertkill(struct task_struct *task)
59193 +{
59194 + struct acl_subject_label *curracl;
59195 + __u32 curr_ip;
59196 + struct task_struct *p, *p2;
59197 +
59198 + if (unlikely(!gr_acl_is_enabled()))
59199 + return;
59200 +
59201 + curracl = task->acl;
59202 + curr_ip = task->signal->curr_ip;
59203 +
59204 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
59205 + read_lock(&tasklist_lock);
59206 + do_each_thread(p2, p) {
59207 + if (p->signal->curr_ip == curr_ip)
59208 + gr_fake_force_sig(SIGKILL, p);
59209 + } while_each_thread(p2, p);
59210 + read_unlock(&tasklist_lock);
59211 + } else if (curracl->mode & GR_KILLPROC)
59212 + gr_fake_force_sig(SIGKILL, task);
59213 +
59214 + return;
59215 +}
59216 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
59217 new file mode 100644
59218 index 0000000..9d83a69
59219 --- /dev/null
59220 +++ b/grsecurity/gracl_shm.c
59221 @@ -0,0 +1,40 @@
59222 +#include <linux/kernel.h>
59223 +#include <linux/mm.h>
59224 +#include <linux/sched.h>
59225 +#include <linux/file.h>
59226 +#include <linux/ipc.h>
59227 +#include <linux/gracl.h>
59228 +#include <linux/grsecurity.h>
59229 +#include <linux/grinternal.h>
59230 +
59231 +int
59232 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59233 + const time_t shm_createtime, const uid_t cuid, const int shmid)
59234 +{
59235 + struct task_struct *task;
59236 +
59237 + if (!gr_acl_is_enabled())
59238 + return 1;
59239 +
59240 + rcu_read_lock();
59241 + read_lock(&tasklist_lock);
59242 +
59243 + task = find_task_by_vpid(shm_cprid);
59244 +
59245 + if (unlikely(!task))
59246 + task = find_task_by_vpid(shm_lapid);
59247 +
59248 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
59249 + (task->pid == shm_lapid)) &&
59250 + (task->acl->mode & GR_PROTSHM) &&
59251 + (task->acl != current->acl))) {
59252 + read_unlock(&tasklist_lock);
59253 + rcu_read_unlock();
59254 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
59255 + return 0;
59256 + }
59257 + read_unlock(&tasklist_lock);
59258 + rcu_read_unlock();
59259 +
59260 + return 1;
59261 +}
59262 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
59263 new file mode 100644
59264 index 0000000..bc0be01
59265 --- /dev/null
59266 +++ b/grsecurity/grsec_chdir.c
59267 @@ -0,0 +1,19 @@
59268 +#include <linux/kernel.h>
59269 +#include <linux/sched.h>
59270 +#include <linux/fs.h>
59271 +#include <linux/file.h>
59272 +#include <linux/grsecurity.h>
59273 +#include <linux/grinternal.h>
59274 +
59275 +void
59276 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
59277 +{
59278 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59279 + if ((grsec_enable_chdir && grsec_enable_group &&
59280 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
59281 + !grsec_enable_group)) {
59282 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
59283 + }
59284 +#endif
59285 + return;
59286 +}
59287 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
59288 new file mode 100644
59289 index 0000000..70fe0ae
59290 --- /dev/null
59291 +++ b/grsecurity/grsec_chroot.c
59292 @@ -0,0 +1,357 @@
59293 +#include <linux/kernel.h>
59294 +#include <linux/module.h>
59295 +#include <linux/sched.h>
59296 +#include <linux/file.h>
59297 +#include <linux/fs.h>
59298 +#include <linux/mount.h>
59299 +#include <linux/types.h>
59300 +#include "../fs/mount.h"
59301 +#include <linux/grsecurity.h>
59302 +#include <linux/grinternal.h>
59303 +
59304 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
59305 +{
59306 +#ifdef CONFIG_GRKERNSEC
59307 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
59308 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
59309 + task->gr_is_chrooted = 1;
59310 + else
59311 + task->gr_is_chrooted = 0;
59312 +
59313 + task->gr_chroot_dentry = path->dentry;
59314 +#endif
59315 + return;
59316 +}
59317 +
59318 +void gr_clear_chroot_entries(struct task_struct *task)
59319 +{
59320 +#ifdef CONFIG_GRKERNSEC
59321 + task->gr_is_chrooted = 0;
59322 + task->gr_chroot_dentry = NULL;
59323 +#endif
59324 + return;
59325 +}
59326 +
59327 +int
59328 +gr_handle_chroot_unix(const pid_t pid)
59329 +{
59330 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59331 + struct task_struct *p;
59332 +
59333 + if (unlikely(!grsec_enable_chroot_unix))
59334 + return 1;
59335 +
59336 + if (likely(!proc_is_chrooted(current)))
59337 + return 1;
59338 +
59339 + rcu_read_lock();
59340 + read_lock(&tasklist_lock);
59341 + p = find_task_by_vpid_unrestricted(pid);
59342 + if (unlikely(p && !have_same_root(current, p))) {
59343 + read_unlock(&tasklist_lock);
59344 + rcu_read_unlock();
59345 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
59346 + return 0;
59347 + }
59348 + read_unlock(&tasklist_lock);
59349 + rcu_read_unlock();
59350 +#endif
59351 + return 1;
59352 +}
59353 +
59354 +int
59355 +gr_handle_chroot_nice(void)
59356 +{
59357 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59358 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
59359 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
59360 + return -EPERM;
59361 + }
59362 +#endif
59363 + return 0;
59364 +}
59365 +
59366 +int
59367 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
59368 +{
59369 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59370 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
59371 + && proc_is_chrooted(current)) {
59372 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
59373 + return -EACCES;
59374 + }
59375 +#endif
59376 + return 0;
59377 +}
59378 +
59379 +int
59380 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
59381 +{
59382 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59383 + struct task_struct *p;
59384 + int ret = 0;
59385 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
59386 + return ret;
59387 +
59388 + read_lock(&tasklist_lock);
59389 + do_each_pid_task(pid, type, p) {
59390 + if (!have_same_root(current, p)) {
59391 + ret = 1;
59392 + goto out;
59393 + }
59394 + } while_each_pid_task(pid, type, p);
59395 +out:
59396 + read_unlock(&tasklist_lock);
59397 + return ret;
59398 +#endif
59399 + return 0;
59400 +}
59401 +
59402 +int
59403 +gr_pid_is_chrooted(struct task_struct *p)
59404 +{
59405 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59406 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
59407 + return 0;
59408 +
59409 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
59410 + !have_same_root(current, p)) {
59411 + return 1;
59412 + }
59413 +#endif
59414 + return 0;
59415 +}
59416 +
59417 +EXPORT_SYMBOL(gr_pid_is_chrooted);
59418 +
59419 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
59420 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
59421 +{
59422 + struct path path, currentroot;
59423 + int ret = 0;
59424 +
59425 + path.dentry = (struct dentry *)u_dentry;
59426 + path.mnt = (struct vfsmount *)u_mnt;
59427 + get_fs_root(current->fs, &currentroot);
59428 + if (path_is_under(&path, &currentroot))
59429 + ret = 1;
59430 + path_put(&currentroot);
59431 +
59432 + return ret;
59433 +}
59434 +#endif
59435 +
59436 +int
59437 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
59438 +{
59439 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59440 + if (!grsec_enable_chroot_fchdir)
59441 + return 1;
59442 +
59443 + if (!proc_is_chrooted(current))
59444 + return 1;
59445 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
59446 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
59447 + return 0;
59448 + }
59449 +#endif
59450 + return 1;
59451 +}
59452 +
59453 +int
59454 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59455 + const time_t shm_createtime)
59456 +{
59457 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59458 + struct task_struct *p;
59459 + time_t starttime;
59460 +
59461 + if (unlikely(!grsec_enable_chroot_shmat))
59462 + return 1;
59463 +
59464 + if (likely(!proc_is_chrooted(current)))
59465 + return 1;
59466 +
59467 + rcu_read_lock();
59468 + read_lock(&tasklist_lock);
59469 +
59470 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
59471 + starttime = p->start_time.tv_sec;
59472 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
59473 + if (have_same_root(current, p)) {
59474 + goto allow;
59475 + } else {
59476 + read_unlock(&tasklist_lock);
59477 + rcu_read_unlock();
59478 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59479 + return 0;
59480 + }
59481 + }
59482 + /* creator exited, pid reuse, fall through to next check */
59483 + }
59484 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
59485 + if (unlikely(!have_same_root(current, p))) {
59486 + read_unlock(&tasklist_lock);
59487 + rcu_read_unlock();
59488 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59489 + return 0;
59490 + }
59491 + }
59492 +
59493 +allow:
59494 + read_unlock(&tasklist_lock);
59495 + rcu_read_unlock();
59496 +#endif
59497 + return 1;
59498 +}
59499 +
59500 +void
59501 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
59502 +{
59503 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59504 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
59505 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
59506 +#endif
59507 + return;
59508 +}
59509 +
59510 +int
59511 +gr_handle_chroot_mknod(const struct dentry *dentry,
59512 + const struct vfsmount *mnt, const int mode)
59513 +{
59514 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59515 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
59516 + proc_is_chrooted(current)) {
59517 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
59518 + return -EPERM;
59519 + }
59520 +#endif
59521 + return 0;
59522 +}
59523 +
59524 +int
59525 +gr_handle_chroot_mount(const struct dentry *dentry,
59526 + const struct vfsmount *mnt, const char *dev_name)
59527 +{
59528 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59529 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
59530 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
59531 + return -EPERM;
59532 + }
59533 +#endif
59534 + return 0;
59535 +}
59536 +
59537 +int
59538 +gr_handle_chroot_pivot(void)
59539 +{
59540 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59541 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
59542 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
59543 + return -EPERM;
59544 + }
59545 +#endif
59546 + return 0;
59547 +}
59548 +
59549 +int
59550 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
59551 +{
59552 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59553 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
59554 + !gr_is_outside_chroot(dentry, mnt)) {
59555 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
59556 + return -EPERM;
59557 + }
59558 +#endif
59559 + return 0;
59560 +}
59561 +
59562 +extern const char *captab_log[];
59563 +extern int captab_log_entries;
59564 +
59565 +int
59566 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
59567 +{
59568 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59569 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59570 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59571 + if (cap_raised(chroot_caps, cap)) {
59572 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
59573 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
59574 + }
59575 + return 0;
59576 + }
59577 + }
59578 +#endif
59579 + return 1;
59580 +}
59581 +
59582 +int
59583 +gr_chroot_is_capable(const int cap)
59584 +{
59585 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59586 + return gr_task_chroot_is_capable(current, current_cred(), cap);
59587 +#endif
59588 + return 1;
59589 +}
59590 +
59591 +int
59592 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
59593 +{
59594 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59595 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59596 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59597 + if (cap_raised(chroot_caps, cap)) {
59598 + return 0;
59599 + }
59600 + }
59601 +#endif
59602 + return 1;
59603 +}
59604 +
59605 +int
59606 +gr_chroot_is_capable_nolog(const int cap)
59607 +{
59608 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59609 + return gr_task_chroot_is_capable_nolog(current, cap);
59610 +#endif
59611 + return 1;
59612 +}
59613 +
59614 +int
59615 +gr_handle_chroot_sysctl(const int op)
59616 +{
59617 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59618 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
59619 + proc_is_chrooted(current))
59620 + return -EACCES;
59621 +#endif
59622 + return 0;
59623 +}
59624 +
59625 +void
59626 +gr_handle_chroot_chdir(struct path *path)
59627 +{
59628 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59629 + if (grsec_enable_chroot_chdir)
59630 + set_fs_pwd(current->fs, path);
59631 +#endif
59632 + return;
59633 +}
59634 +
59635 +int
59636 +gr_handle_chroot_chmod(const struct dentry *dentry,
59637 + const struct vfsmount *mnt, const int mode)
59638 +{
59639 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59640 + /* allow chmod +s on directories, but not files */
59641 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
59642 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
59643 + proc_is_chrooted(current)) {
59644 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
59645 + return -EPERM;
59646 + }
59647 +#endif
59648 + return 0;
59649 +}
59650 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
59651 new file mode 100644
59652 index 0000000..e6796b3
59653 --- /dev/null
59654 +++ b/grsecurity/grsec_disabled.c
59655 @@ -0,0 +1,434 @@
59656 +#include <linux/kernel.h>
59657 +#include <linux/module.h>
59658 +#include <linux/sched.h>
59659 +#include <linux/file.h>
59660 +#include <linux/fs.h>
59661 +#include <linux/kdev_t.h>
59662 +#include <linux/net.h>
59663 +#include <linux/in.h>
59664 +#include <linux/ip.h>
59665 +#include <linux/skbuff.h>
59666 +#include <linux/sysctl.h>
59667 +
59668 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59669 +void
59670 +pax_set_initial_flags(struct linux_binprm *bprm)
59671 +{
59672 + return;
59673 +}
59674 +#endif
59675 +
59676 +#ifdef CONFIG_SYSCTL
59677 +__u32
59678 +gr_handle_sysctl(const struct ctl_table * table, const int op)
59679 +{
59680 + return 0;
59681 +}
59682 +#endif
59683 +
59684 +#ifdef CONFIG_TASKSTATS
59685 +int gr_is_taskstats_denied(int pid)
59686 +{
59687 + return 0;
59688 +}
59689 +#endif
59690 +
59691 +int
59692 +gr_acl_is_enabled(void)
59693 +{
59694 + return 0;
59695 +}
59696 +
59697 +void
59698 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
59699 +{
59700 + return;
59701 +}
59702 +
59703 +int
59704 +gr_handle_rawio(const struct inode *inode)
59705 +{
59706 + return 0;
59707 +}
59708 +
59709 +void
59710 +gr_acl_handle_psacct(struct task_struct *task, const long code)
59711 +{
59712 + return;
59713 +}
59714 +
59715 +int
59716 +gr_handle_ptrace(struct task_struct *task, const long request)
59717 +{
59718 + return 0;
59719 +}
59720 +
59721 +int
59722 +gr_handle_proc_ptrace(struct task_struct *task)
59723 +{
59724 + return 0;
59725 +}
59726 +
59727 +int
59728 +gr_set_acls(const int type)
59729 +{
59730 + return 0;
59731 +}
59732 +
59733 +int
59734 +gr_check_hidden_task(const struct task_struct *tsk)
59735 +{
59736 + return 0;
59737 +}
59738 +
59739 +int
59740 +gr_check_protected_task(const struct task_struct *task)
59741 +{
59742 + return 0;
59743 +}
59744 +
59745 +int
59746 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59747 +{
59748 + return 0;
59749 +}
59750 +
59751 +void
59752 +gr_copy_label(struct task_struct *tsk)
59753 +{
59754 + return;
59755 +}
59756 +
59757 +void
59758 +gr_set_pax_flags(struct task_struct *task)
59759 +{
59760 + return;
59761 +}
59762 +
59763 +int
59764 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59765 + const int unsafe_share)
59766 +{
59767 + return 0;
59768 +}
59769 +
59770 +void
59771 +gr_handle_delete(const ino_t ino, const dev_t dev)
59772 +{
59773 + return;
59774 +}
59775 +
59776 +void
59777 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
59778 +{
59779 + return;
59780 +}
59781 +
59782 +void
59783 +gr_handle_crash(struct task_struct *task, const int sig)
59784 +{
59785 + return;
59786 +}
59787 +
59788 +int
59789 +gr_check_crash_exec(const struct file *filp)
59790 +{
59791 + return 0;
59792 +}
59793 +
59794 +int
59795 +gr_check_crash_uid(const uid_t uid)
59796 +{
59797 + return 0;
59798 +}
59799 +
59800 +void
59801 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59802 + struct dentry *old_dentry,
59803 + struct dentry *new_dentry,
59804 + struct vfsmount *mnt, const __u8 replace)
59805 +{
59806 + return;
59807 +}
59808 +
59809 +int
59810 +gr_search_socket(const int family, const int type, const int protocol)
59811 +{
59812 + return 1;
59813 +}
59814 +
59815 +int
59816 +gr_search_connectbind(const int mode, const struct socket *sock,
59817 + const struct sockaddr_in *addr)
59818 +{
59819 + return 0;
59820 +}
59821 +
59822 +void
59823 +gr_handle_alertkill(struct task_struct *task)
59824 +{
59825 + return;
59826 +}
59827 +
59828 +__u32
59829 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
59830 +{
59831 + return 1;
59832 +}
59833 +
59834 +__u32
59835 +gr_acl_handle_hidden_file(const struct dentry * dentry,
59836 + const struct vfsmount * mnt)
59837 +{
59838 + return 1;
59839 +}
59840 +
59841 +__u32
59842 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
59843 + int acc_mode)
59844 +{
59845 + return 1;
59846 +}
59847 +
59848 +__u32
59849 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
59850 +{
59851 + return 1;
59852 +}
59853 +
59854 +__u32
59855 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
59856 +{
59857 + return 1;
59858 +}
59859 +
59860 +int
59861 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
59862 + unsigned int *vm_flags)
59863 +{
59864 + return 1;
59865 +}
59866 +
59867 +__u32
59868 +gr_acl_handle_truncate(const struct dentry * dentry,
59869 + const struct vfsmount * mnt)
59870 +{
59871 + return 1;
59872 +}
59873 +
59874 +__u32
59875 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
59876 +{
59877 + return 1;
59878 +}
59879 +
59880 +__u32
59881 +gr_acl_handle_access(const struct dentry * dentry,
59882 + const struct vfsmount * mnt, const int fmode)
59883 +{
59884 + return 1;
59885 +}
59886 +
59887 +__u32
59888 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
59889 + umode_t *mode)
59890 +{
59891 + return 1;
59892 +}
59893 +
59894 +__u32
59895 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
59896 +{
59897 + return 1;
59898 +}
59899 +
59900 +__u32
59901 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
59902 +{
59903 + return 1;
59904 +}
59905 +
59906 +void
59907 +grsecurity_init(void)
59908 +{
59909 + return;
59910 +}
59911 +
59912 +umode_t gr_acl_umask(void)
59913 +{
59914 + return 0;
59915 +}
59916 +
59917 +__u32
59918 +gr_acl_handle_mknod(const struct dentry * new_dentry,
59919 + const struct dentry * parent_dentry,
59920 + const struct vfsmount * parent_mnt,
59921 + const int mode)
59922 +{
59923 + return 1;
59924 +}
59925 +
59926 +__u32
59927 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
59928 + const struct dentry * parent_dentry,
59929 + const struct vfsmount * parent_mnt)
59930 +{
59931 + return 1;
59932 +}
59933 +
59934 +__u32
59935 +gr_acl_handle_symlink(const struct dentry * new_dentry,
59936 + const struct dentry * parent_dentry,
59937 + const struct vfsmount * parent_mnt, const struct filename *from)
59938 +{
59939 + return 1;
59940 +}
59941 +
59942 +__u32
59943 +gr_acl_handle_link(const struct dentry * new_dentry,
59944 + const struct dentry * parent_dentry,
59945 + const struct vfsmount * parent_mnt,
59946 + const struct dentry * old_dentry,
59947 + const struct vfsmount * old_mnt, const struct filename *to)
59948 +{
59949 + return 1;
59950 +}
59951 +
59952 +int
59953 +gr_acl_handle_rename(const struct dentry *new_dentry,
59954 + const struct dentry *parent_dentry,
59955 + const struct vfsmount *parent_mnt,
59956 + const struct dentry *old_dentry,
59957 + const struct inode *old_parent_inode,
59958 + const struct vfsmount *old_mnt, const struct filename *newname)
59959 +{
59960 + return 0;
59961 +}
59962 +
59963 +int
59964 +gr_acl_handle_filldir(const struct file *file, const char *name,
59965 + const int namelen, const ino_t ino)
59966 +{
59967 + return 1;
59968 +}
59969 +
59970 +int
59971 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59972 + const time_t shm_createtime, const uid_t cuid, const int shmid)
59973 +{
59974 + return 1;
59975 +}
59976 +
59977 +int
59978 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
59979 +{
59980 + return 0;
59981 +}
59982 +
59983 +int
59984 +gr_search_accept(const struct socket *sock)
59985 +{
59986 + return 0;
59987 +}
59988 +
59989 +int
59990 +gr_search_listen(const struct socket *sock)
59991 +{
59992 + return 0;
59993 +}
59994 +
59995 +int
59996 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
59997 +{
59998 + return 0;
59999 +}
60000 +
60001 +__u32
60002 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
60003 +{
60004 + return 1;
60005 +}
60006 +
60007 +__u32
60008 +gr_acl_handle_creat(const struct dentry * dentry,
60009 + const struct dentry * p_dentry,
60010 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
60011 + const int imode)
60012 +{
60013 + return 1;
60014 +}
60015 +
60016 +void
60017 +gr_acl_handle_exit(void)
60018 +{
60019 + return;
60020 +}
60021 +
60022 +int
60023 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
60024 +{
60025 + return 1;
60026 +}
60027 +
60028 +void
60029 +gr_set_role_label(const uid_t uid, const gid_t gid)
60030 +{
60031 + return;
60032 +}
60033 +
60034 +int
60035 +gr_acl_handle_procpidmem(const struct task_struct *task)
60036 +{
60037 + return 0;
60038 +}
60039 +
60040 +int
60041 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
60042 +{
60043 + return 0;
60044 +}
60045 +
60046 +int
60047 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
60048 +{
60049 + return 0;
60050 +}
60051 +
60052 +void
60053 +gr_set_kernel_label(struct task_struct *task)
60054 +{
60055 + return;
60056 +}
60057 +
60058 +int
60059 +gr_check_user_change(int real, int effective, int fs)
60060 +{
60061 + return 0;
60062 +}
60063 +
60064 +int
60065 +gr_check_group_change(int real, int effective, int fs)
60066 +{
60067 + return 0;
60068 +}
60069 +
60070 +int gr_acl_enable_at_secure(void)
60071 +{
60072 + return 0;
60073 +}
60074 +
60075 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
60076 +{
60077 + return dentry->d_inode->i_sb->s_dev;
60078 +}
60079 +
60080 +void gr_put_exec_file(struct task_struct *task)
60081 +{
60082 + return;
60083 +}
60084 +
60085 +EXPORT_SYMBOL(gr_set_kernel_label);
60086 +#ifdef CONFIG_SECURITY
60087 +EXPORT_SYMBOL(gr_check_user_change);
60088 +EXPORT_SYMBOL(gr_check_group_change);
60089 +#endif
60090 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
60091 new file mode 100644
60092 index 0000000..abfa971
60093 --- /dev/null
60094 +++ b/grsecurity/grsec_exec.c
60095 @@ -0,0 +1,174 @@
60096 +#include <linux/kernel.h>
60097 +#include <linux/sched.h>
60098 +#include <linux/file.h>
60099 +#include <linux/binfmts.h>
60100 +#include <linux/fs.h>
60101 +#include <linux/types.h>
60102 +#include <linux/grdefs.h>
60103 +#include <linux/grsecurity.h>
60104 +#include <linux/grinternal.h>
60105 +#include <linux/capability.h>
60106 +#include <linux/module.h>
60107 +
60108 +#include <asm/uaccess.h>
60109 +
60110 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60111 +static char gr_exec_arg_buf[132];
60112 +static DEFINE_MUTEX(gr_exec_arg_mutex);
60113 +#endif
60114 +
60115 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
60116 +
60117 +void
60118 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
60119 +{
60120 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60121 + char *grarg = gr_exec_arg_buf;
60122 + unsigned int i, x, execlen = 0;
60123 + char c;
60124 +
60125 + if (!((grsec_enable_execlog && grsec_enable_group &&
60126 + in_group_p(grsec_audit_gid))
60127 + || (grsec_enable_execlog && !grsec_enable_group)))
60128 + return;
60129 +
60130 + mutex_lock(&gr_exec_arg_mutex);
60131 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
60132 +
60133 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
60134 + const char __user *p;
60135 + unsigned int len;
60136 +
60137 + p = get_user_arg_ptr(argv, i);
60138 + if (IS_ERR(p))
60139 + goto log;
60140 +
60141 + len = strnlen_user(p, 128 - execlen);
60142 + if (len > 128 - execlen)
60143 + len = 128 - execlen;
60144 + else if (len > 0)
60145 + len--;
60146 + if (copy_from_user(grarg + execlen, p, len))
60147 + goto log;
60148 +
60149 + /* rewrite unprintable characters */
60150 + for (x = 0; x < len; x++) {
60151 + c = *(grarg + execlen + x);
60152 + if (c < 32 || c > 126)
60153 + *(grarg + execlen + x) = ' ';
60154 + }
60155 +
60156 + execlen += len;
60157 + *(grarg + execlen) = ' ';
60158 + *(grarg + execlen + 1) = '\0';
60159 + execlen++;
60160 + }
60161 +
60162 + log:
60163 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
60164 + bprm->file->f_path.mnt, grarg);
60165 + mutex_unlock(&gr_exec_arg_mutex);
60166 +#endif
60167 + return;
60168 +}
60169 +
60170 +#ifdef CONFIG_GRKERNSEC
60171 +extern int gr_acl_is_capable(const int cap);
60172 +extern int gr_acl_is_capable_nolog(const int cap);
60173 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60174 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
60175 +extern int gr_chroot_is_capable(const int cap);
60176 +extern int gr_chroot_is_capable_nolog(const int cap);
60177 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60178 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
60179 +#endif
60180 +
60181 +const char *captab_log[] = {
60182 + "CAP_CHOWN",
60183 + "CAP_DAC_OVERRIDE",
60184 + "CAP_DAC_READ_SEARCH",
60185 + "CAP_FOWNER",
60186 + "CAP_FSETID",
60187 + "CAP_KILL",
60188 + "CAP_SETGID",
60189 + "CAP_SETUID",
60190 + "CAP_SETPCAP",
60191 + "CAP_LINUX_IMMUTABLE",
60192 + "CAP_NET_BIND_SERVICE",
60193 + "CAP_NET_BROADCAST",
60194 + "CAP_NET_ADMIN",
60195 + "CAP_NET_RAW",
60196 + "CAP_IPC_LOCK",
60197 + "CAP_IPC_OWNER",
60198 + "CAP_SYS_MODULE",
60199 + "CAP_SYS_RAWIO",
60200 + "CAP_SYS_CHROOT",
60201 + "CAP_SYS_PTRACE",
60202 + "CAP_SYS_PACCT",
60203 + "CAP_SYS_ADMIN",
60204 + "CAP_SYS_BOOT",
60205 + "CAP_SYS_NICE",
60206 + "CAP_SYS_RESOURCE",
60207 + "CAP_SYS_TIME",
60208 + "CAP_SYS_TTY_CONFIG",
60209 + "CAP_MKNOD",
60210 + "CAP_LEASE",
60211 + "CAP_AUDIT_WRITE",
60212 + "CAP_AUDIT_CONTROL",
60213 + "CAP_SETFCAP",
60214 + "CAP_MAC_OVERRIDE",
60215 + "CAP_MAC_ADMIN",
60216 + "CAP_SYSLOG",
60217 + "CAP_WAKE_ALARM"
60218 +};
60219 +
60220 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
60221 +
60222 +int gr_is_capable(const int cap)
60223 +{
60224 +#ifdef CONFIG_GRKERNSEC
60225 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
60226 + return 1;
60227 + return 0;
60228 +#else
60229 + return 1;
60230 +#endif
60231 +}
60232 +
60233 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60234 +{
60235 +#ifdef CONFIG_GRKERNSEC
60236 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
60237 + return 1;
60238 + return 0;
60239 +#else
60240 + return 1;
60241 +#endif
60242 +}
60243 +
60244 +int gr_is_capable_nolog(const int cap)
60245 +{
60246 +#ifdef CONFIG_GRKERNSEC
60247 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
60248 + return 1;
60249 + return 0;
60250 +#else
60251 + return 1;
60252 +#endif
60253 +}
60254 +
60255 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
60256 +{
60257 +#ifdef CONFIG_GRKERNSEC
60258 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
60259 + return 1;
60260 + return 0;
60261 +#else
60262 + return 1;
60263 +#endif
60264 +}
60265 +
60266 +EXPORT_SYMBOL(gr_is_capable);
60267 +EXPORT_SYMBOL(gr_is_capable_nolog);
60268 +EXPORT_SYMBOL(gr_task_is_capable);
60269 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
60270 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
60271 new file mode 100644
60272 index 0000000..d3ee748
60273 --- /dev/null
60274 +++ b/grsecurity/grsec_fifo.c
60275 @@ -0,0 +1,24 @@
60276 +#include <linux/kernel.h>
60277 +#include <linux/sched.h>
60278 +#include <linux/fs.h>
60279 +#include <linux/file.h>
60280 +#include <linux/grinternal.h>
60281 +
60282 +int
60283 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
60284 + const struct dentry *dir, const int flag, const int acc_mode)
60285 +{
60286 +#ifdef CONFIG_GRKERNSEC_FIFO
60287 + const struct cred *cred = current_cred();
60288 +
60289 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
60290 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
60291 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
60292 + (cred->fsuid != dentry->d_inode->i_uid)) {
60293 + if (!inode_permission(dentry->d_inode, acc_mode))
60294 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
60295 + return -EACCES;
60296 + }
60297 +#endif
60298 + return 0;
60299 +}
60300 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
60301 new file mode 100644
60302 index 0000000..8ca18bf
60303 --- /dev/null
60304 +++ b/grsecurity/grsec_fork.c
60305 @@ -0,0 +1,23 @@
60306 +#include <linux/kernel.h>
60307 +#include <linux/sched.h>
60308 +#include <linux/grsecurity.h>
60309 +#include <linux/grinternal.h>
60310 +#include <linux/errno.h>
60311 +
60312 +void
60313 +gr_log_forkfail(const int retval)
60314 +{
60315 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60316 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
60317 + switch (retval) {
60318 + case -EAGAIN:
60319 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
60320 + break;
60321 + case -ENOMEM:
60322 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
60323 + break;
60324 + }
60325 + }
60326 +#endif
60327 + return;
60328 +}
60329 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
60330 new file mode 100644
60331 index 0000000..05a6015
60332 --- /dev/null
60333 +++ b/grsecurity/grsec_init.c
60334 @@ -0,0 +1,283 @@
60335 +#include <linux/kernel.h>
60336 +#include <linux/sched.h>
60337 +#include <linux/mm.h>
60338 +#include <linux/gracl.h>
60339 +#include <linux/slab.h>
60340 +#include <linux/vmalloc.h>
60341 +#include <linux/percpu.h>
60342 +#include <linux/module.h>
60343 +
60344 +int grsec_enable_ptrace_readexec;
60345 +int grsec_enable_setxid;
60346 +int grsec_enable_symlinkown;
60347 +int grsec_symlinkown_gid;
60348 +int grsec_enable_brute;
60349 +int grsec_enable_link;
60350 +int grsec_enable_dmesg;
60351 +int grsec_enable_harden_ptrace;
60352 +int grsec_enable_fifo;
60353 +int grsec_enable_execlog;
60354 +int grsec_enable_signal;
60355 +int grsec_enable_forkfail;
60356 +int grsec_enable_audit_ptrace;
60357 +int grsec_enable_time;
60358 +int grsec_enable_audit_textrel;
60359 +int grsec_enable_group;
60360 +int grsec_audit_gid;
60361 +int grsec_enable_chdir;
60362 +int grsec_enable_mount;
60363 +int grsec_enable_rofs;
60364 +int grsec_enable_chroot_findtask;
60365 +int grsec_enable_chroot_mount;
60366 +int grsec_enable_chroot_shmat;
60367 +int grsec_enable_chroot_fchdir;
60368 +int grsec_enable_chroot_double;
60369 +int grsec_enable_chroot_pivot;
60370 +int grsec_enable_chroot_chdir;
60371 +int grsec_enable_chroot_chmod;
60372 +int grsec_enable_chroot_mknod;
60373 +int grsec_enable_chroot_nice;
60374 +int grsec_enable_chroot_execlog;
60375 +int grsec_enable_chroot_caps;
60376 +int grsec_enable_chroot_sysctl;
60377 +int grsec_enable_chroot_unix;
60378 +int grsec_enable_tpe;
60379 +int grsec_tpe_gid;
60380 +int grsec_enable_blackhole;
60381 +#ifdef CONFIG_IPV6_MODULE
60382 +EXPORT_SYMBOL(grsec_enable_blackhole);
60383 +#endif
60384 +int grsec_lastack_retries;
60385 +int grsec_enable_tpe_all;
60386 +int grsec_enable_tpe_invert;
60387 +int grsec_enable_socket_all;
60388 +int grsec_socket_all_gid;
60389 +int grsec_enable_socket_client;
60390 +int grsec_socket_client_gid;
60391 +int grsec_enable_socket_server;
60392 +int grsec_socket_server_gid;
60393 +int grsec_resource_logging;
60394 +int grsec_disable_privio;
60395 +int grsec_enable_log_rwxmaps;
60396 +int grsec_lock;
60397 +
60398 +DEFINE_SPINLOCK(grsec_alert_lock);
60399 +unsigned long grsec_alert_wtime = 0;
60400 +unsigned long grsec_alert_fyet = 0;
60401 +
60402 +DEFINE_SPINLOCK(grsec_audit_lock);
60403 +
60404 +DEFINE_RWLOCK(grsec_exec_file_lock);
60405 +
60406 +char *gr_shared_page[4];
60407 +
60408 +char *gr_alert_log_fmt;
60409 +char *gr_audit_log_fmt;
60410 +char *gr_alert_log_buf;
60411 +char *gr_audit_log_buf;
60412 +
60413 +extern struct gr_arg *gr_usermode;
60414 +extern unsigned char *gr_system_salt;
60415 +extern unsigned char *gr_system_sum;
60416 +
60417 +void __init
60418 +grsecurity_init(void)
60419 +{
60420 + int j;
60421 + /* create the per-cpu shared pages */
60422 +
60423 +#ifdef CONFIG_X86
60424 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
60425 +#endif
60426 +
60427 + for (j = 0; j < 4; j++) {
60428 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
60429 + if (gr_shared_page[j] == NULL) {
60430 + panic("Unable to allocate grsecurity shared page");
60431 + return;
60432 + }
60433 + }
60434 +
60435 + /* allocate log buffers */
60436 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
60437 + if (!gr_alert_log_fmt) {
60438 + panic("Unable to allocate grsecurity alert log format buffer");
60439 + return;
60440 + }
60441 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
60442 + if (!gr_audit_log_fmt) {
60443 + panic("Unable to allocate grsecurity audit log format buffer");
60444 + return;
60445 + }
60446 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60447 + if (!gr_alert_log_buf) {
60448 + panic("Unable to allocate grsecurity alert log buffer");
60449 + return;
60450 + }
60451 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60452 + if (!gr_audit_log_buf) {
60453 + panic("Unable to allocate grsecurity audit log buffer");
60454 + return;
60455 + }
60456 +
60457 + /* allocate memory for authentication structure */
60458 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
60459 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
60460 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
60461 +
60462 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
60463 + panic("Unable to allocate grsecurity authentication structure");
60464 + return;
60465 + }
60466 +
60467 +
60468 +#ifdef CONFIG_GRKERNSEC_IO
60469 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
60470 + grsec_disable_privio = 1;
60471 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60472 + grsec_disable_privio = 1;
60473 +#else
60474 + grsec_disable_privio = 0;
60475 +#endif
60476 +#endif
60477 +
60478 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60479 + /* for backward compatibility, tpe_invert always defaults to on if
60480 + enabled in the kernel
60481 + */
60482 + grsec_enable_tpe_invert = 1;
60483 +#endif
60484 +
60485 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60486 +#ifndef CONFIG_GRKERNSEC_SYSCTL
60487 + grsec_lock = 1;
60488 +#endif
60489 +
60490 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60491 + grsec_enable_audit_textrel = 1;
60492 +#endif
60493 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60494 + grsec_enable_log_rwxmaps = 1;
60495 +#endif
60496 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60497 + grsec_enable_group = 1;
60498 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
60499 +#endif
60500 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60501 + grsec_enable_ptrace_readexec = 1;
60502 +#endif
60503 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60504 + grsec_enable_chdir = 1;
60505 +#endif
60506 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60507 + grsec_enable_harden_ptrace = 1;
60508 +#endif
60509 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60510 + grsec_enable_mount = 1;
60511 +#endif
60512 +#ifdef CONFIG_GRKERNSEC_LINK
60513 + grsec_enable_link = 1;
60514 +#endif
60515 +#ifdef CONFIG_GRKERNSEC_BRUTE
60516 + grsec_enable_brute = 1;
60517 +#endif
60518 +#ifdef CONFIG_GRKERNSEC_DMESG
60519 + grsec_enable_dmesg = 1;
60520 +#endif
60521 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60522 + grsec_enable_blackhole = 1;
60523 + grsec_lastack_retries = 4;
60524 +#endif
60525 +#ifdef CONFIG_GRKERNSEC_FIFO
60526 + grsec_enable_fifo = 1;
60527 +#endif
60528 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60529 + grsec_enable_execlog = 1;
60530 +#endif
60531 +#ifdef CONFIG_GRKERNSEC_SETXID
60532 + grsec_enable_setxid = 1;
60533 +#endif
60534 +#ifdef CONFIG_GRKERNSEC_SIGNAL
60535 + grsec_enable_signal = 1;
60536 +#endif
60537 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60538 + grsec_enable_forkfail = 1;
60539 +#endif
60540 +#ifdef CONFIG_GRKERNSEC_TIME
60541 + grsec_enable_time = 1;
60542 +#endif
60543 +#ifdef CONFIG_GRKERNSEC_RESLOG
60544 + grsec_resource_logging = 1;
60545 +#endif
60546 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60547 + grsec_enable_chroot_findtask = 1;
60548 +#endif
60549 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60550 + grsec_enable_chroot_unix = 1;
60551 +#endif
60552 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60553 + grsec_enable_chroot_mount = 1;
60554 +#endif
60555 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60556 + grsec_enable_chroot_fchdir = 1;
60557 +#endif
60558 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60559 + grsec_enable_chroot_shmat = 1;
60560 +#endif
60561 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60562 + grsec_enable_audit_ptrace = 1;
60563 +#endif
60564 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60565 + grsec_enable_chroot_double = 1;
60566 +#endif
60567 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60568 + grsec_enable_chroot_pivot = 1;
60569 +#endif
60570 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60571 + grsec_enable_chroot_chdir = 1;
60572 +#endif
60573 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60574 + grsec_enable_chroot_chmod = 1;
60575 +#endif
60576 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60577 + grsec_enable_chroot_mknod = 1;
60578 +#endif
60579 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60580 + grsec_enable_chroot_nice = 1;
60581 +#endif
60582 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60583 + grsec_enable_chroot_execlog = 1;
60584 +#endif
60585 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60586 + grsec_enable_chroot_caps = 1;
60587 +#endif
60588 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60589 + grsec_enable_chroot_sysctl = 1;
60590 +#endif
60591 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60592 + grsec_enable_symlinkown = 1;
60593 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
60594 +#endif
60595 +#ifdef CONFIG_GRKERNSEC_TPE
60596 + grsec_enable_tpe = 1;
60597 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
60598 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60599 + grsec_enable_tpe_all = 1;
60600 +#endif
60601 +#endif
60602 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60603 + grsec_enable_socket_all = 1;
60604 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
60605 +#endif
60606 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60607 + grsec_enable_socket_client = 1;
60608 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
60609 +#endif
60610 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60611 + grsec_enable_socket_server = 1;
60612 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
60613 +#endif
60614 +#endif
60615 +
60616 + return;
60617 +}
60618 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
60619 new file mode 100644
60620 index 0000000..6095407
60621 --- /dev/null
60622 +++ b/grsecurity/grsec_link.c
60623 @@ -0,0 +1,58 @@
60624 +#include <linux/kernel.h>
60625 +#include <linux/sched.h>
60626 +#include <linux/fs.h>
60627 +#include <linux/file.h>
60628 +#include <linux/grinternal.h>
60629 +
60630 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
60631 +{
60632 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60633 + const struct inode *link_inode = link->dentry->d_inode;
60634 +
60635 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
60636 + /* ignore root-owned links, e.g. /proc/self */
60637 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
60638 + !uid_eq(link_inode->i_uid, target->i_uid)) {
60639 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
60640 + return 1;
60641 + }
60642 +#endif
60643 + return 0;
60644 +}
60645 +
60646 +int
60647 +gr_handle_follow_link(const struct inode *parent,
60648 + const struct inode *inode,
60649 + const struct dentry *dentry, const struct vfsmount *mnt)
60650 +{
60651 +#ifdef CONFIG_GRKERNSEC_LINK
60652 + const struct cred *cred = current_cred();
60653 +
60654 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
60655 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
60656 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
60657 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
60658 + return -EACCES;
60659 + }
60660 +#endif
60661 + return 0;
60662 +}
60663 +
60664 +int
60665 +gr_handle_hardlink(const struct dentry *dentry,
60666 + const struct vfsmount *mnt,
60667 + struct inode *inode, const int mode, const struct filename *to)
60668 +{
60669 +#ifdef CONFIG_GRKERNSEC_LINK
60670 + const struct cred *cred = current_cred();
60671 +
60672 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
60673 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
60674 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
60675 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
60676 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
60677 + return -EPERM;
60678 + }
60679 +#endif
60680 + return 0;
60681 +}
60682 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
60683 new file mode 100644
60684 index 0000000..7bd6c2b
60685 --- /dev/null
60686 +++ b/grsecurity/grsec_log.c
60687 @@ -0,0 +1,329 @@
60688 +#include <linux/kernel.h>
60689 +#include <linux/sched.h>
60690 +#include <linux/file.h>
60691 +#include <linux/tty.h>
60692 +#include <linux/fs.h>
60693 +#include <linux/grinternal.h>
60694 +
60695 +#ifdef CONFIG_TREE_PREEMPT_RCU
60696 +#define DISABLE_PREEMPT() preempt_disable()
60697 +#define ENABLE_PREEMPT() preempt_enable()
60698 +#else
60699 +#define DISABLE_PREEMPT()
60700 +#define ENABLE_PREEMPT()
60701 +#endif
60702 +
60703 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
60704 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
60705 +
60706 +#define BEGIN_LOCKS(x) \
60707 + DISABLE_PREEMPT(); \
60708 + rcu_read_lock(); \
60709 + read_lock(&tasklist_lock); \
60710 + read_lock(&grsec_exec_file_lock); \
60711 + if (x != GR_DO_AUDIT) \
60712 + spin_lock(&grsec_alert_lock); \
60713 + else \
60714 + spin_lock(&grsec_audit_lock)
60715 +
60716 +#define END_LOCKS(x) \
60717 + if (x != GR_DO_AUDIT) \
60718 + spin_unlock(&grsec_alert_lock); \
60719 + else \
60720 + spin_unlock(&grsec_audit_lock); \
60721 + read_unlock(&grsec_exec_file_lock); \
60722 + read_unlock(&tasklist_lock); \
60723 + rcu_read_unlock(); \
60724 + ENABLE_PREEMPT(); \
60725 + if (x == GR_DONT_AUDIT) \
60726 + gr_handle_alertkill(current)
60727 +
60728 +enum {
60729 + FLOODING,
60730 + NO_FLOODING
60731 +};
60732 +
60733 +extern char *gr_alert_log_fmt;
60734 +extern char *gr_audit_log_fmt;
60735 +extern char *gr_alert_log_buf;
60736 +extern char *gr_audit_log_buf;
60737 +
60738 +static int gr_log_start(int audit)
60739 +{
60740 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
60741 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
60742 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60743 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
60744 + unsigned long curr_secs = get_seconds();
60745 +
60746 + if (audit == GR_DO_AUDIT)
60747 + goto set_fmt;
60748 +
60749 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
60750 + grsec_alert_wtime = curr_secs;
60751 + grsec_alert_fyet = 0;
60752 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
60753 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
60754 + grsec_alert_fyet++;
60755 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
60756 + grsec_alert_wtime = curr_secs;
60757 + grsec_alert_fyet++;
60758 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
60759 + return FLOODING;
60760 + }
60761 + else return FLOODING;
60762 +
60763 +set_fmt:
60764 +#endif
60765 + memset(buf, 0, PAGE_SIZE);
60766 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
60767 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
60768 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60769 + } else if (current->signal->curr_ip) {
60770 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
60771 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
60772 + } else if (gr_acl_is_enabled()) {
60773 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
60774 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60775 + } else {
60776 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
60777 + strcpy(buf, fmt);
60778 + }
60779 +
60780 + return NO_FLOODING;
60781 +}
60782 +
60783 +static void gr_log_middle(int audit, const char *msg, va_list ap)
60784 + __attribute__ ((format (printf, 2, 0)));
60785 +
60786 +static void gr_log_middle(int audit, const char *msg, va_list ap)
60787 +{
60788 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60789 + unsigned int len = strlen(buf);
60790 +
60791 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60792 +
60793 + return;
60794 +}
60795 +
60796 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
60797 + __attribute__ ((format (printf, 2, 3)));
60798 +
60799 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
60800 +{
60801 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60802 + unsigned int len = strlen(buf);
60803 + va_list ap;
60804 +
60805 + va_start(ap, msg);
60806 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60807 + va_end(ap);
60808 +
60809 + return;
60810 +}
60811 +
60812 +static void gr_log_end(int audit, int append_default)
60813 +{
60814 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60815 + if (append_default) {
60816 + struct task_struct *task = current;
60817 + struct task_struct *parent = task->real_parent;
60818 + const struct cred *cred = __task_cred(task);
60819 + const struct cred *pcred = __task_cred(parent);
60820 + unsigned int len = strlen(buf);
60821 +
60822 + 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));
60823 + }
60824 +
60825 + printk("%s\n", buf);
60826 +
60827 + return;
60828 +}
60829 +
60830 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
60831 +{
60832 + int logtype;
60833 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
60834 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
60835 + void *voidptr = NULL;
60836 + int num1 = 0, num2 = 0;
60837 + unsigned long ulong1 = 0, ulong2 = 0;
60838 + struct dentry *dentry = NULL;
60839 + struct vfsmount *mnt = NULL;
60840 + struct file *file = NULL;
60841 + struct task_struct *task = NULL;
60842 + const struct cred *cred, *pcred;
60843 + va_list ap;
60844 +
60845 + BEGIN_LOCKS(audit);
60846 + logtype = gr_log_start(audit);
60847 + if (logtype == FLOODING) {
60848 + END_LOCKS(audit);
60849 + return;
60850 + }
60851 + va_start(ap, argtypes);
60852 + switch (argtypes) {
60853 + case GR_TTYSNIFF:
60854 + task = va_arg(ap, struct task_struct *);
60855 + 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));
60856 + break;
60857 + case GR_SYSCTL_HIDDEN:
60858 + str1 = va_arg(ap, char *);
60859 + gr_log_middle_varargs(audit, msg, result, str1);
60860 + break;
60861 + case GR_RBAC:
60862 + dentry = va_arg(ap, struct dentry *);
60863 + mnt = va_arg(ap, struct vfsmount *);
60864 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
60865 + break;
60866 + case GR_RBAC_STR:
60867 + dentry = va_arg(ap, struct dentry *);
60868 + mnt = va_arg(ap, struct vfsmount *);
60869 + str1 = va_arg(ap, char *);
60870 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
60871 + break;
60872 + case GR_STR_RBAC:
60873 + str1 = va_arg(ap, char *);
60874 + dentry = va_arg(ap, struct dentry *);
60875 + mnt = va_arg(ap, struct vfsmount *);
60876 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
60877 + break;
60878 + case GR_RBAC_MODE2:
60879 + dentry = va_arg(ap, struct dentry *);
60880 + mnt = va_arg(ap, struct vfsmount *);
60881 + str1 = va_arg(ap, char *);
60882 + str2 = va_arg(ap, char *);
60883 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
60884 + break;
60885 + case GR_RBAC_MODE3:
60886 + dentry = va_arg(ap, struct dentry *);
60887 + mnt = va_arg(ap, struct vfsmount *);
60888 + str1 = va_arg(ap, char *);
60889 + str2 = va_arg(ap, char *);
60890 + str3 = va_arg(ap, char *);
60891 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
60892 + break;
60893 + case GR_FILENAME:
60894 + dentry = va_arg(ap, struct dentry *);
60895 + mnt = va_arg(ap, struct vfsmount *);
60896 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
60897 + break;
60898 + case GR_STR_FILENAME:
60899 + str1 = va_arg(ap, char *);
60900 + dentry = va_arg(ap, struct dentry *);
60901 + mnt = va_arg(ap, struct vfsmount *);
60902 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
60903 + break;
60904 + case GR_FILENAME_STR:
60905 + dentry = va_arg(ap, struct dentry *);
60906 + mnt = va_arg(ap, struct vfsmount *);
60907 + str1 = va_arg(ap, char *);
60908 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
60909 + break;
60910 + case GR_FILENAME_TWO_INT:
60911 + dentry = va_arg(ap, struct dentry *);
60912 + mnt = va_arg(ap, struct vfsmount *);
60913 + num1 = va_arg(ap, int);
60914 + num2 = va_arg(ap, int);
60915 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
60916 + break;
60917 + case GR_FILENAME_TWO_INT_STR:
60918 + dentry = va_arg(ap, struct dentry *);
60919 + mnt = va_arg(ap, struct vfsmount *);
60920 + num1 = va_arg(ap, int);
60921 + num2 = va_arg(ap, int);
60922 + str1 = va_arg(ap, char *);
60923 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
60924 + break;
60925 + case GR_TEXTREL:
60926 + file = va_arg(ap, struct file *);
60927 + ulong1 = va_arg(ap, unsigned long);
60928 + ulong2 = va_arg(ap, unsigned long);
60929 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
60930 + break;
60931 + case GR_PTRACE:
60932 + task = va_arg(ap, struct task_struct *);
60933 + 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));
60934 + break;
60935 + case GR_RESOURCE:
60936 + task = va_arg(ap, struct task_struct *);
60937 + cred = __task_cred(task);
60938 + pcred = __task_cred(task->real_parent);
60939 + ulong1 = va_arg(ap, unsigned long);
60940 + str1 = va_arg(ap, char *);
60941 + ulong2 = va_arg(ap, unsigned long);
60942 + 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));
60943 + break;
60944 + case GR_CAP:
60945 + task = va_arg(ap, struct task_struct *);
60946 + cred = __task_cred(task);
60947 + pcred = __task_cred(task->real_parent);
60948 + str1 = va_arg(ap, char *);
60949 + 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));
60950 + break;
60951 + case GR_SIG:
60952 + str1 = va_arg(ap, char *);
60953 + voidptr = va_arg(ap, void *);
60954 + gr_log_middle_varargs(audit, msg, str1, voidptr);
60955 + break;
60956 + case GR_SIG2:
60957 + task = va_arg(ap, struct task_struct *);
60958 + cred = __task_cred(task);
60959 + pcred = __task_cred(task->real_parent);
60960 + num1 = va_arg(ap, int);
60961 + 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));
60962 + break;
60963 + case GR_CRASH1:
60964 + task = va_arg(ap, struct task_struct *);
60965 + cred = __task_cred(task);
60966 + pcred = __task_cred(task->real_parent);
60967 + ulong1 = va_arg(ap, unsigned long);
60968 + 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);
60969 + break;
60970 + case GR_CRASH2:
60971 + task = va_arg(ap, struct task_struct *);
60972 + cred = __task_cred(task);
60973 + pcred = __task_cred(task->real_parent);
60974 + ulong1 = va_arg(ap, unsigned long);
60975 + 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);
60976 + break;
60977 + case GR_RWXMAP:
60978 + file = va_arg(ap, struct file *);
60979 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
60980 + break;
60981 + case GR_PSACCT:
60982 + {
60983 + unsigned int wday, cday;
60984 + __u8 whr, chr;
60985 + __u8 wmin, cmin;
60986 + __u8 wsec, csec;
60987 + char cur_tty[64] = { 0 };
60988 + char parent_tty[64] = { 0 };
60989 +
60990 + task = va_arg(ap, struct task_struct *);
60991 + wday = va_arg(ap, unsigned int);
60992 + cday = va_arg(ap, unsigned int);
60993 + whr = va_arg(ap, int);
60994 + chr = va_arg(ap, int);
60995 + wmin = va_arg(ap, int);
60996 + cmin = va_arg(ap, int);
60997 + wsec = va_arg(ap, int);
60998 + csec = va_arg(ap, int);
60999 + ulong1 = va_arg(ap, unsigned long);
61000 + cred = __task_cred(task);
61001 + pcred = __task_cred(task->real_parent);
61002 +
61003 + 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));
61004 + }
61005 + break;
61006 + default:
61007 + gr_log_middle(audit, msg, ap);
61008 + }
61009 + va_end(ap);
61010 + // these don't need DEFAULTSECARGS printed on the end
61011 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
61012 + gr_log_end(audit, 0);
61013 + else
61014 + gr_log_end(audit, 1);
61015 + END_LOCKS(audit);
61016 +}
61017 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
61018 new file mode 100644
61019 index 0000000..f536303
61020 --- /dev/null
61021 +++ b/grsecurity/grsec_mem.c
61022 @@ -0,0 +1,40 @@
61023 +#include <linux/kernel.h>
61024 +#include <linux/sched.h>
61025 +#include <linux/mm.h>
61026 +#include <linux/mman.h>
61027 +#include <linux/grinternal.h>
61028 +
61029 +void
61030 +gr_handle_ioperm(void)
61031 +{
61032 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
61033 + return;
61034 +}
61035 +
61036 +void
61037 +gr_handle_iopl(void)
61038 +{
61039 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
61040 + return;
61041 +}
61042 +
61043 +void
61044 +gr_handle_mem_readwrite(u64 from, u64 to)
61045 +{
61046 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
61047 + return;
61048 +}
61049 +
61050 +void
61051 +gr_handle_vm86(void)
61052 +{
61053 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
61054 + return;
61055 +}
61056 +
61057 +void
61058 +gr_log_badprocpid(const char *entry)
61059 +{
61060 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
61061 + return;
61062 +}
61063 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
61064 new file mode 100644
61065 index 0000000..2131422
61066 --- /dev/null
61067 +++ b/grsecurity/grsec_mount.c
61068 @@ -0,0 +1,62 @@
61069 +#include <linux/kernel.h>
61070 +#include <linux/sched.h>
61071 +#include <linux/mount.h>
61072 +#include <linux/grsecurity.h>
61073 +#include <linux/grinternal.h>
61074 +
61075 +void
61076 +gr_log_remount(const char *devname, const int retval)
61077 +{
61078 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61079 + if (grsec_enable_mount && (retval >= 0))
61080 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
61081 +#endif
61082 + return;
61083 +}
61084 +
61085 +void
61086 +gr_log_unmount(const char *devname, const int retval)
61087 +{
61088 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61089 + if (grsec_enable_mount && (retval >= 0))
61090 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
61091 +#endif
61092 + return;
61093 +}
61094 +
61095 +void
61096 +gr_log_mount(const char *from, const char *to, const int retval)
61097 +{
61098 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61099 + if (grsec_enable_mount && (retval >= 0))
61100 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
61101 +#endif
61102 + return;
61103 +}
61104 +
61105 +int
61106 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
61107 +{
61108 +#ifdef CONFIG_GRKERNSEC_ROFS
61109 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
61110 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
61111 + return -EPERM;
61112 + } else
61113 + return 0;
61114 +#endif
61115 + return 0;
61116 +}
61117 +
61118 +int
61119 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
61120 +{
61121 +#ifdef CONFIG_GRKERNSEC_ROFS
61122 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
61123 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
61124 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
61125 + return -EPERM;
61126 + } else
61127 + return 0;
61128 +#endif
61129 + return 0;
61130 +}
61131 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
61132 new file mode 100644
61133 index 0000000..a3b12a0
61134 --- /dev/null
61135 +++ b/grsecurity/grsec_pax.c
61136 @@ -0,0 +1,36 @@
61137 +#include <linux/kernel.h>
61138 +#include <linux/sched.h>
61139 +#include <linux/mm.h>
61140 +#include <linux/file.h>
61141 +#include <linux/grinternal.h>
61142 +#include <linux/grsecurity.h>
61143 +
61144 +void
61145 +gr_log_textrel(struct vm_area_struct * vma)
61146 +{
61147 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61148 + if (grsec_enable_audit_textrel)
61149 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
61150 +#endif
61151 + return;
61152 +}
61153 +
61154 +void
61155 +gr_log_rwxmmap(struct file *file)
61156 +{
61157 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61158 + if (grsec_enable_log_rwxmaps)
61159 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
61160 +#endif
61161 + return;
61162 +}
61163 +
61164 +void
61165 +gr_log_rwxmprotect(struct file *file)
61166 +{
61167 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61168 + if (grsec_enable_log_rwxmaps)
61169 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
61170 +#endif
61171 + return;
61172 +}
61173 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
61174 new file mode 100644
61175 index 0000000..f7f29aa
61176 --- /dev/null
61177 +++ b/grsecurity/grsec_ptrace.c
61178 @@ -0,0 +1,30 @@
61179 +#include <linux/kernel.h>
61180 +#include <linux/sched.h>
61181 +#include <linux/grinternal.h>
61182 +#include <linux/security.h>
61183 +
61184 +void
61185 +gr_audit_ptrace(struct task_struct *task)
61186 +{
61187 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61188 + if (grsec_enable_audit_ptrace)
61189 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
61190 +#endif
61191 + return;
61192 +}
61193 +
61194 +int
61195 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
61196 +{
61197 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61198 + const struct dentry *dentry = file->f_path.dentry;
61199 + const struct vfsmount *mnt = file->f_path.mnt;
61200 +
61201 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
61202 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
61203 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
61204 + return -EACCES;
61205 + }
61206 +#endif
61207 + return 0;
61208 +}
61209 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
61210 new file mode 100644
61211 index 0000000..5c00416
61212 --- /dev/null
61213 +++ b/grsecurity/grsec_sig.c
61214 @@ -0,0 +1,222 @@
61215 +#include <linux/kernel.h>
61216 +#include <linux/sched.h>
61217 +#include <linux/delay.h>
61218 +#include <linux/grsecurity.h>
61219 +#include <linux/grinternal.h>
61220 +#include <linux/hardirq.h>
61221 +
61222 +char *signames[] = {
61223 + [SIGSEGV] = "Segmentation fault",
61224 + [SIGILL] = "Illegal instruction",
61225 + [SIGABRT] = "Abort",
61226 + [SIGBUS] = "Invalid alignment/Bus error"
61227 +};
61228 +
61229 +void
61230 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
61231 +{
61232 +#ifdef CONFIG_GRKERNSEC_SIGNAL
61233 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
61234 + (sig == SIGABRT) || (sig == SIGBUS))) {
61235 + if (t->pid == current->pid) {
61236 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
61237 + } else {
61238 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
61239 + }
61240 + }
61241 +#endif
61242 + return;
61243 +}
61244 +
61245 +int
61246 +gr_handle_signal(const struct task_struct *p, const int sig)
61247 +{
61248 +#ifdef CONFIG_GRKERNSEC
61249 + /* ignore the 0 signal for protected task checks */
61250 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
61251 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
61252 + return -EPERM;
61253 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
61254 + return -EPERM;
61255 + }
61256 +#endif
61257 + return 0;
61258 +}
61259 +
61260 +#ifdef CONFIG_GRKERNSEC
61261 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
61262 +
61263 +int gr_fake_force_sig(int sig, struct task_struct *t)
61264 +{
61265 + unsigned long int flags;
61266 + int ret, blocked, ignored;
61267 + struct k_sigaction *action;
61268 +
61269 + spin_lock_irqsave(&t->sighand->siglock, flags);
61270 + action = &t->sighand->action[sig-1];
61271 + ignored = action->sa.sa_handler == SIG_IGN;
61272 + blocked = sigismember(&t->blocked, sig);
61273 + if (blocked || ignored) {
61274 + action->sa.sa_handler = SIG_DFL;
61275 + if (blocked) {
61276 + sigdelset(&t->blocked, sig);
61277 + recalc_sigpending_and_wake(t);
61278 + }
61279 + }
61280 + if (action->sa.sa_handler == SIG_DFL)
61281 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
61282 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
61283 +
61284 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
61285 +
61286 + return ret;
61287 +}
61288 +#endif
61289 +
61290 +#ifdef CONFIG_GRKERNSEC_BRUTE
61291 +#define GR_USER_BAN_TIME (15 * 60)
61292 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
61293 +
61294 +static int __get_dumpable(unsigned long mm_flags)
61295 +{
61296 + int ret;
61297 +
61298 + ret = mm_flags & MMF_DUMPABLE_MASK;
61299 + return (ret >= 2) ? 2 : ret;
61300 +}
61301 +#endif
61302 +
61303 +void gr_handle_brute_attach(unsigned long mm_flags)
61304 +{
61305 +#ifdef CONFIG_GRKERNSEC_BRUTE
61306 + struct task_struct *p = current;
61307 + kuid_t uid = GLOBAL_ROOT_UID;
61308 + int daemon = 0;
61309 +
61310 + if (!grsec_enable_brute)
61311 + return;
61312 +
61313 + rcu_read_lock();
61314 + read_lock(&tasklist_lock);
61315 + read_lock(&grsec_exec_file_lock);
61316 + if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
61317 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
61318 + p->real_parent->brute = 1;
61319 + daemon = 1;
61320 + } else {
61321 + const struct cred *cred = __task_cred(p), *cred2;
61322 + struct task_struct *tsk, *tsk2;
61323 +
61324 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
61325 + struct user_struct *user;
61326 +
61327 + uid = cred->uid;
61328 +
61329 + /* this is put upon execution past expiration */
61330 + user = find_user(uid);
61331 + if (user == NULL)
61332 + goto unlock;
61333 + user->banned = 1;
61334 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
61335 + if (user->ban_expires == ~0UL)
61336 + user->ban_expires--;
61337 +
61338 + do_each_thread(tsk2, tsk) {
61339 + cred2 = __task_cred(tsk);
61340 + if (tsk != p && uid_eq(cred2->uid, uid))
61341 + gr_fake_force_sig(SIGKILL, tsk);
61342 + } while_each_thread(tsk2, tsk);
61343 + }
61344 + }
61345 +unlock:
61346 + read_unlock(&grsec_exec_file_lock);
61347 + read_unlock(&tasklist_lock);
61348 + rcu_read_unlock();
61349 +
61350 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
61351 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
61352 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
61353 + else if (daemon)
61354 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
61355 +
61356 +#endif
61357 + return;
61358 +}
61359 +
61360 +void gr_handle_brute_check(void)
61361 +{
61362 +#ifdef CONFIG_GRKERNSEC_BRUTE
61363 + struct task_struct *p = current;
61364 +
61365 + if (unlikely(p->brute)) {
61366 + if (!grsec_enable_brute)
61367 + p->brute = 0;
61368 + else if (time_before(get_seconds(), p->brute_expires))
61369 + msleep(30 * 1000);
61370 + }
61371 +#endif
61372 + return;
61373 +}
61374 +
61375 +void gr_handle_kernel_exploit(void)
61376 +{
61377 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
61378 + const struct cred *cred;
61379 + struct task_struct *tsk, *tsk2;
61380 + struct user_struct *user;
61381 + kuid_t uid;
61382 +
61383 + if (in_irq() || in_serving_softirq() || in_nmi())
61384 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
61385 +
61386 + uid = current_uid();
61387 +
61388 + if (uid_eq(uid, GLOBAL_ROOT_UID))
61389 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
61390 + else {
61391 + /* kill all the processes of this user, hold a reference
61392 + to their creds struct, and prevent them from creating
61393 + another process until system reset
61394 + */
61395 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
61396 + from_kuid_munged(&init_user_ns, uid));
61397 + /* we intentionally leak this ref */
61398 + user = get_uid(current->cred->user);
61399 + if (user) {
61400 + user->banned = 1;
61401 + user->ban_expires = ~0UL;
61402 + }
61403 +
61404 + read_lock(&tasklist_lock);
61405 + do_each_thread(tsk2, tsk) {
61406 + cred = __task_cred(tsk);
61407 + if (uid_eq(cred->uid, uid))
61408 + gr_fake_force_sig(SIGKILL, tsk);
61409 + } while_each_thread(tsk2, tsk);
61410 + read_unlock(&tasklist_lock);
61411 + }
61412 +#endif
61413 +}
61414 +
61415 +int __gr_process_user_ban(struct user_struct *user)
61416 +{
61417 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61418 + if (unlikely(user->banned)) {
61419 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
61420 + user->banned = 0;
61421 + user->ban_expires = 0;
61422 + free_uid(user);
61423 + } else
61424 + return -EPERM;
61425 + }
61426 +#endif
61427 + return 0;
61428 +}
61429 +
61430 +int gr_process_user_ban(void)
61431 +{
61432 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61433 + return __gr_process_user_ban(current->cred->user);
61434 +#endif
61435 + return 0;
61436 +}
61437 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
61438 new file mode 100644
61439 index 0000000..4030d57
61440 --- /dev/null
61441 +++ b/grsecurity/grsec_sock.c
61442 @@ -0,0 +1,244 @@
61443 +#include <linux/kernel.h>
61444 +#include <linux/module.h>
61445 +#include <linux/sched.h>
61446 +#include <linux/file.h>
61447 +#include <linux/net.h>
61448 +#include <linux/in.h>
61449 +#include <linux/ip.h>
61450 +#include <net/sock.h>
61451 +#include <net/inet_sock.h>
61452 +#include <linux/grsecurity.h>
61453 +#include <linux/grinternal.h>
61454 +#include <linux/gracl.h>
61455 +
61456 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
61457 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
61458 +
61459 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
61460 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
61461 +
61462 +#ifdef CONFIG_UNIX_MODULE
61463 +EXPORT_SYMBOL(gr_acl_handle_unix);
61464 +EXPORT_SYMBOL(gr_acl_handle_mknod);
61465 +EXPORT_SYMBOL(gr_handle_chroot_unix);
61466 +EXPORT_SYMBOL(gr_handle_create);
61467 +#endif
61468 +
61469 +#ifdef CONFIG_GRKERNSEC
61470 +#define gr_conn_table_size 32749
61471 +struct conn_table_entry {
61472 + struct conn_table_entry *next;
61473 + struct signal_struct *sig;
61474 +};
61475 +
61476 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
61477 +DEFINE_SPINLOCK(gr_conn_table_lock);
61478 +
61479 +extern const char * gr_socktype_to_name(unsigned char type);
61480 +extern const char * gr_proto_to_name(unsigned char proto);
61481 +extern const char * gr_sockfamily_to_name(unsigned char family);
61482 +
61483 +static __inline__ int
61484 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
61485 +{
61486 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
61487 +}
61488 +
61489 +static __inline__ int
61490 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
61491 + __u16 sport, __u16 dport)
61492 +{
61493 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
61494 + sig->gr_sport == sport && sig->gr_dport == dport))
61495 + return 1;
61496 + else
61497 + return 0;
61498 +}
61499 +
61500 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
61501 +{
61502 + struct conn_table_entry **match;
61503 + unsigned int index;
61504 +
61505 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61506 + sig->gr_sport, sig->gr_dport,
61507 + gr_conn_table_size);
61508 +
61509 + newent->sig = sig;
61510 +
61511 + match = &gr_conn_table[index];
61512 + newent->next = *match;
61513 + *match = newent;
61514 +
61515 + return;
61516 +}
61517 +
61518 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
61519 +{
61520 + struct conn_table_entry *match, *last = NULL;
61521 + unsigned int index;
61522 +
61523 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61524 + sig->gr_sport, sig->gr_dport,
61525 + gr_conn_table_size);
61526 +
61527 + match = gr_conn_table[index];
61528 + while (match && !conn_match(match->sig,
61529 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
61530 + sig->gr_dport)) {
61531 + last = match;
61532 + match = match->next;
61533 + }
61534 +
61535 + if (match) {
61536 + if (last)
61537 + last->next = match->next;
61538 + else
61539 + gr_conn_table[index] = NULL;
61540 + kfree(match);
61541 + }
61542 +
61543 + return;
61544 +}
61545 +
61546 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
61547 + __u16 sport, __u16 dport)
61548 +{
61549 + struct conn_table_entry *match;
61550 + unsigned int index;
61551 +
61552 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
61553 +
61554 + match = gr_conn_table[index];
61555 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
61556 + match = match->next;
61557 +
61558 + if (match)
61559 + return match->sig;
61560 + else
61561 + return NULL;
61562 +}
61563 +
61564 +#endif
61565 +
61566 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
61567 +{
61568 +#ifdef CONFIG_GRKERNSEC
61569 + struct signal_struct *sig = task->signal;
61570 + struct conn_table_entry *newent;
61571 +
61572 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
61573 + if (newent == NULL)
61574 + return;
61575 + /* no bh lock needed since we are called with bh disabled */
61576 + spin_lock(&gr_conn_table_lock);
61577 + gr_del_task_from_ip_table_nolock(sig);
61578 + sig->gr_saddr = inet->inet_rcv_saddr;
61579 + sig->gr_daddr = inet->inet_daddr;
61580 + sig->gr_sport = inet->inet_sport;
61581 + sig->gr_dport = inet->inet_dport;
61582 + gr_add_to_task_ip_table_nolock(sig, newent);
61583 + spin_unlock(&gr_conn_table_lock);
61584 +#endif
61585 + return;
61586 +}
61587 +
61588 +void gr_del_task_from_ip_table(struct task_struct *task)
61589 +{
61590 +#ifdef CONFIG_GRKERNSEC
61591 + spin_lock_bh(&gr_conn_table_lock);
61592 + gr_del_task_from_ip_table_nolock(task->signal);
61593 + spin_unlock_bh(&gr_conn_table_lock);
61594 +#endif
61595 + return;
61596 +}
61597 +
61598 +void
61599 +gr_attach_curr_ip(const struct sock *sk)
61600 +{
61601 +#ifdef CONFIG_GRKERNSEC
61602 + struct signal_struct *p, *set;
61603 + const struct inet_sock *inet = inet_sk(sk);
61604 +
61605 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
61606 + return;
61607 +
61608 + set = current->signal;
61609 +
61610 + spin_lock_bh(&gr_conn_table_lock);
61611 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
61612 + inet->inet_dport, inet->inet_sport);
61613 + if (unlikely(p != NULL)) {
61614 + set->curr_ip = p->curr_ip;
61615 + set->used_accept = 1;
61616 + gr_del_task_from_ip_table_nolock(p);
61617 + spin_unlock_bh(&gr_conn_table_lock);
61618 + return;
61619 + }
61620 + spin_unlock_bh(&gr_conn_table_lock);
61621 +
61622 + set->curr_ip = inet->inet_daddr;
61623 + set->used_accept = 1;
61624 +#endif
61625 + return;
61626 +}
61627 +
61628 +int
61629 +gr_handle_sock_all(const int family, const int type, const int protocol)
61630 +{
61631 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61632 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
61633 + (family != AF_UNIX)) {
61634 + if (family == AF_INET)
61635 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
61636 + else
61637 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
61638 + return -EACCES;
61639 + }
61640 +#endif
61641 + return 0;
61642 +}
61643 +
61644 +int
61645 +gr_handle_sock_server(const struct sockaddr *sck)
61646 +{
61647 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61648 + if (grsec_enable_socket_server &&
61649 + in_group_p(grsec_socket_server_gid) &&
61650 + sck && (sck->sa_family != AF_UNIX) &&
61651 + (sck->sa_family != AF_LOCAL)) {
61652 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61653 + return -EACCES;
61654 + }
61655 +#endif
61656 + return 0;
61657 +}
61658 +
61659 +int
61660 +gr_handle_sock_server_other(const struct sock *sck)
61661 +{
61662 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61663 + if (grsec_enable_socket_server &&
61664 + in_group_p(grsec_socket_server_gid) &&
61665 + sck && (sck->sk_family != AF_UNIX) &&
61666 + (sck->sk_family != AF_LOCAL)) {
61667 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61668 + return -EACCES;
61669 + }
61670 +#endif
61671 + return 0;
61672 +}
61673 +
61674 +int
61675 +gr_handle_sock_client(const struct sockaddr *sck)
61676 +{
61677 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61678 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
61679 + sck && (sck->sa_family != AF_UNIX) &&
61680 + (sck->sa_family != AF_LOCAL)) {
61681 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
61682 + return -EACCES;
61683 + }
61684 +#endif
61685 + return 0;
61686 +}
61687 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
61688 new file mode 100644
61689 index 0000000..f55ef0f
61690 --- /dev/null
61691 +++ b/grsecurity/grsec_sysctl.c
61692 @@ -0,0 +1,469 @@
61693 +#include <linux/kernel.h>
61694 +#include <linux/sched.h>
61695 +#include <linux/sysctl.h>
61696 +#include <linux/grsecurity.h>
61697 +#include <linux/grinternal.h>
61698 +
61699 +int
61700 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
61701 +{
61702 +#ifdef CONFIG_GRKERNSEC_SYSCTL
61703 + if (dirname == NULL || name == NULL)
61704 + return 0;
61705 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
61706 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
61707 + return -EACCES;
61708 + }
61709 +#endif
61710 + return 0;
61711 +}
61712 +
61713 +#ifdef CONFIG_GRKERNSEC_ROFS
61714 +static int __maybe_unused one = 1;
61715 +#endif
61716 +
61717 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
61718 +struct ctl_table grsecurity_table[] = {
61719 +#ifdef CONFIG_GRKERNSEC_SYSCTL
61720 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
61721 +#ifdef CONFIG_GRKERNSEC_IO
61722 + {
61723 + .procname = "disable_priv_io",
61724 + .data = &grsec_disable_privio,
61725 + .maxlen = sizeof(int),
61726 + .mode = 0600,
61727 + .proc_handler = &proc_dointvec,
61728 + },
61729 +#endif
61730 +#endif
61731 +#ifdef CONFIG_GRKERNSEC_LINK
61732 + {
61733 + .procname = "linking_restrictions",
61734 + .data = &grsec_enable_link,
61735 + .maxlen = sizeof(int),
61736 + .mode = 0600,
61737 + .proc_handler = &proc_dointvec,
61738 + },
61739 +#endif
61740 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61741 + {
61742 + .procname = "enforce_symlinksifowner",
61743 + .data = &grsec_enable_symlinkown,
61744 + .maxlen = sizeof(int),
61745 + .mode = 0600,
61746 + .proc_handler = &proc_dointvec,
61747 + },
61748 + {
61749 + .procname = "symlinkown_gid",
61750 + .data = &grsec_symlinkown_gid,
61751 + .maxlen = sizeof(int),
61752 + .mode = 0600,
61753 + .proc_handler = &proc_dointvec,
61754 + },
61755 +#endif
61756 +#ifdef CONFIG_GRKERNSEC_BRUTE
61757 + {
61758 + .procname = "deter_bruteforce",
61759 + .data = &grsec_enable_brute,
61760 + .maxlen = sizeof(int),
61761 + .mode = 0600,
61762 + .proc_handler = &proc_dointvec,
61763 + },
61764 +#endif
61765 +#ifdef CONFIG_GRKERNSEC_FIFO
61766 + {
61767 + .procname = "fifo_restrictions",
61768 + .data = &grsec_enable_fifo,
61769 + .maxlen = sizeof(int),
61770 + .mode = 0600,
61771 + .proc_handler = &proc_dointvec,
61772 + },
61773 +#endif
61774 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61775 + {
61776 + .procname = "ptrace_readexec",
61777 + .data = &grsec_enable_ptrace_readexec,
61778 + .maxlen = sizeof(int),
61779 + .mode = 0600,
61780 + .proc_handler = &proc_dointvec,
61781 + },
61782 +#endif
61783 +#ifdef CONFIG_GRKERNSEC_SETXID
61784 + {
61785 + .procname = "consistent_setxid",
61786 + .data = &grsec_enable_setxid,
61787 + .maxlen = sizeof(int),
61788 + .mode = 0600,
61789 + .proc_handler = &proc_dointvec,
61790 + },
61791 +#endif
61792 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
61793 + {
61794 + .procname = "ip_blackhole",
61795 + .data = &grsec_enable_blackhole,
61796 + .maxlen = sizeof(int),
61797 + .mode = 0600,
61798 + .proc_handler = &proc_dointvec,
61799 + },
61800 + {
61801 + .procname = "lastack_retries",
61802 + .data = &grsec_lastack_retries,
61803 + .maxlen = sizeof(int),
61804 + .mode = 0600,
61805 + .proc_handler = &proc_dointvec,
61806 + },
61807 +#endif
61808 +#ifdef CONFIG_GRKERNSEC_EXECLOG
61809 + {
61810 + .procname = "exec_logging",
61811 + .data = &grsec_enable_execlog,
61812 + .maxlen = sizeof(int),
61813 + .mode = 0600,
61814 + .proc_handler = &proc_dointvec,
61815 + },
61816 +#endif
61817 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61818 + {
61819 + .procname = "rwxmap_logging",
61820 + .data = &grsec_enable_log_rwxmaps,
61821 + .maxlen = sizeof(int),
61822 + .mode = 0600,
61823 + .proc_handler = &proc_dointvec,
61824 + },
61825 +#endif
61826 +#ifdef CONFIG_GRKERNSEC_SIGNAL
61827 + {
61828 + .procname = "signal_logging",
61829 + .data = &grsec_enable_signal,
61830 + .maxlen = sizeof(int),
61831 + .mode = 0600,
61832 + .proc_handler = &proc_dointvec,
61833 + },
61834 +#endif
61835 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
61836 + {
61837 + .procname = "forkfail_logging",
61838 + .data = &grsec_enable_forkfail,
61839 + .maxlen = sizeof(int),
61840 + .mode = 0600,
61841 + .proc_handler = &proc_dointvec,
61842 + },
61843 +#endif
61844 +#ifdef CONFIG_GRKERNSEC_TIME
61845 + {
61846 + .procname = "timechange_logging",
61847 + .data = &grsec_enable_time,
61848 + .maxlen = sizeof(int),
61849 + .mode = 0600,
61850 + .proc_handler = &proc_dointvec,
61851 + },
61852 +#endif
61853 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61854 + {
61855 + .procname = "chroot_deny_shmat",
61856 + .data = &grsec_enable_chroot_shmat,
61857 + .maxlen = sizeof(int),
61858 + .mode = 0600,
61859 + .proc_handler = &proc_dointvec,
61860 + },
61861 +#endif
61862 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61863 + {
61864 + .procname = "chroot_deny_unix",
61865 + .data = &grsec_enable_chroot_unix,
61866 + .maxlen = sizeof(int),
61867 + .mode = 0600,
61868 + .proc_handler = &proc_dointvec,
61869 + },
61870 +#endif
61871 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61872 + {
61873 + .procname = "chroot_deny_mount",
61874 + .data = &grsec_enable_chroot_mount,
61875 + .maxlen = sizeof(int),
61876 + .mode = 0600,
61877 + .proc_handler = &proc_dointvec,
61878 + },
61879 +#endif
61880 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61881 + {
61882 + .procname = "chroot_deny_fchdir",
61883 + .data = &grsec_enable_chroot_fchdir,
61884 + .maxlen = sizeof(int),
61885 + .mode = 0600,
61886 + .proc_handler = &proc_dointvec,
61887 + },
61888 +#endif
61889 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61890 + {
61891 + .procname = "chroot_deny_chroot",
61892 + .data = &grsec_enable_chroot_double,
61893 + .maxlen = sizeof(int),
61894 + .mode = 0600,
61895 + .proc_handler = &proc_dointvec,
61896 + },
61897 +#endif
61898 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61899 + {
61900 + .procname = "chroot_deny_pivot",
61901 + .data = &grsec_enable_chroot_pivot,
61902 + .maxlen = sizeof(int),
61903 + .mode = 0600,
61904 + .proc_handler = &proc_dointvec,
61905 + },
61906 +#endif
61907 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61908 + {
61909 + .procname = "chroot_enforce_chdir",
61910 + .data = &grsec_enable_chroot_chdir,
61911 + .maxlen = sizeof(int),
61912 + .mode = 0600,
61913 + .proc_handler = &proc_dointvec,
61914 + },
61915 +#endif
61916 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61917 + {
61918 + .procname = "chroot_deny_chmod",
61919 + .data = &grsec_enable_chroot_chmod,
61920 + .maxlen = sizeof(int),
61921 + .mode = 0600,
61922 + .proc_handler = &proc_dointvec,
61923 + },
61924 +#endif
61925 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61926 + {
61927 + .procname = "chroot_deny_mknod",
61928 + .data = &grsec_enable_chroot_mknod,
61929 + .maxlen = sizeof(int),
61930 + .mode = 0600,
61931 + .proc_handler = &proc_dointvec,
61932 + },
61933 +#endif
61934 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61935 + {
61936 + .procname = "chroot_restrict_nice",
61937 + .data = &grsec_enable_chroot_nice,
61938 + .maxlen = sizeof(int),
61939 + .mode = 0600,
61940 + .proc_handler = &proc_dointvec,
61941 + },
61942 +#endif
61943 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61944 + {
61945 + .procname = "chroot_execlog",
61946 + .data = &grsec_enable_chroot_execlog,
61947 + .maxlen = sizeof(int),
61948 + .mode = 0600,
61949 + .proc_handler = &proc_dointvec,
61950 + },
61951 +#endif
61952 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61953 + {
61954 + .procname = "chroot_caps",
61955 + .data = &grsec_enable_chroot_caps,
61956 + .maxlen = sizeof(int),
61957 + .mode = 0600,
61958 + .proc_handler = &proc_dointvec,
61959 + },
61960 +#endif
61961 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61962 + {
61963 + .procname = "chroot_deny_sysctl",
61964 + .data = &grsec_enable_chroot_sysctl,
61965 + .maxlen = sizeof(int),
61966 + .mode = 0600,
61967 + .proc_handler = &proc_dointvec,
61968 + },
61969 +#endif
61970 +#ifdef CONFIG_GRKERNSEC_TPE
61971 + {
61972 + .procname = "tpe",
61973 + .data = &grsec_enable_tpe,
61974 + .maxlen = sizeof(int),
61975 + .mode = 0600,
61976 + .proc_handler = &proc_dointvec,
61977 + },
61978 + {
61979 + .procname = "tpe_gid",
61980 + .data = &grsec_tpe_gid,
61981 + .maxlen = sizeof(int),
61982 + .mode = 0600,
61983 + .proc_handler = &proc_dointvec,
61984 + },
61985 +#endif
61986 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
61987 + {
61988 + .procname = "tpe_invert",
61989 + .data = &grsec_enable_tpe_invert,
61990 + .maxlen = sizeof(int),
61991 + .mode = 0600,
61992 + .proc_handler = &proc_dointvec,
61993 + },
61994 +#endif
61995 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
61996 + {
61997 + .procname = "tpe_restrict_all",
61998 + .data = &grsec_enable_tpe_all,
61999 + .maxlen = sizeof(int),
62000 + .mode = 0600,
62001 + .proc_handler = &proc_dointvec,
62002 + },
62003 +#endif
62004 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62005 + {
62006 + .procname = "socket_all",
62007 + .data = &grsec_enable_socket_all,
62008 + .maxlen = sizeof(int),
62009 + .mode = 0600,
62010 + .proc_handler = &proc_dointvec,
62011 + },
62012 + {
62013 + .procname = "socket_all_gid",
62014 + .data = &grsec_socket_all_gid,
62015 + .maxlen = sizeof(int),
62016 + .mode = 0600,
62017 + .proc_handler = &proc_dointvec,
62018 + },
62019 +#endif
62020 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62021 + {
62022 + .procname = "socket_client",
62023 + .data = &grsec_enable_socket_client,
62024 + .maxlen = sizeof(int),
62025 + .mode = 0600,
62026 + .proc_handler = &proc_dointvec,
62027 + },
62028 + {
62029 + .procname = "socket_client_gid",
62030 + .data = &grsec_socket_client_gid,
62031 + .maxlen = sizeof(int),
62032 + .mode = 0600,
62033 + .proc_handler = &proc_dointvec,
62034 + },
62035 +#endif
62036 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62037 + {
62038 + .procname = "socket_server",
62039 + .data = &grsec_enable_socket_server,
62040 + .maxlen = sizeof(int),
62041 + .mode = 0600,
62042 + .proc_handler = &proc_dointvec,
62043 + },
62044 + {
62045 + .procname = "socket_server_gid",
62046 + .data = &grsec_socket_server_gid,
62047 + .maxlen = sizeof(int),
62048 + .mode = 0600,
62049 + .proc_handler = &proc_dointvec,
62050 + },
62051 +#endif
62052 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
62053 + {
62054 + .procname = "audit_group",
62055 + .data = &grsec_enable_group,
62056 + .maxlen = sizeof(int),
62057 + .mode = 0600,
62058 + .proc_handler = &proc_dointvec,
62059 + },
62060 + {
62061 + .procname = "audit_gid",
62062 + .data = &grsec_audit_gid,
62063 + .maxlen = sizeof(int),
62064 + .mode = 0600,
62065 + .proc_handler = &proc_dointvec,
62066 + },
62067 +#endif
62068 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62069 + {
62070 + .procname = "audit_chdir",
62071 + .data = &grsec_enable_chdir,
62072 + .maxlen = sizeof(int),
62073 + .mode = 0600,
62074 + .proc_handler = &proc_dointvec,
62075 + },
62076 +#endif
62077 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62078 + {
62079 + .procname = "audit_mount",
62080 + .data = &grsec_enable_mount,
62081 + .maxlen = sizeof(int),
62082 + .mode = 0600,
62083 + .proc_handler = &proc_dointvec,
62084 + },
62085 +#endif
62086 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
62087 + {
62088 + .procname = "audit_textrel",
62089 + .data = &grsec_enable_audit_textrel,
62090 + .maxlen = sizeof(int),
62091 + .mode = 0600,
62092 + .proc_handler = &proc_dointvec,
62093 + },
62094 +#endif
62095 +#ifdef CONFIG_GRKERNSEC_DMESG
62096 + {
62097 + .procname = "dmesg",
62098 + .data = &grsec_enable_dmesg,
62099 + .maxlen = sizeof(int),
62100 + .mode = 0600,
62101 + .proc_handler = &proc_dointvec,
62102 + },
62103 +#endif
62104 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62105 + {
62106 + .procname = "chroot_findtask",
62107 + .data = &grsec_enable_chroot_findtask,
62108 + .maxlen = sizeof(int),
62109 + .mode = 0600,
62110 + .proc_handler = &proc_dointvec,
62111 + },
62112 +#endif
62113 +#ifdef CONFIG_GRKERNSEC_RESLOG
62114 + {
62115 + .procname = "resource_logging",
62116 + .data = &grsec_resource_logging,
62117 + .maxlen = sizeof(int),
62118 + .mode = 0600,
62119 + .proc_handler = &proc_dointvec,
62120 + },
62121 +#endif
62122 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62123 + {
62124 + .procname = "audit_ptrace",
62125 + .data = &grsec_enable_audit_ptrace,
62126 + .maxlen = sizeof(int),
62127 + .mode = 0600,
62128 + .proc_handler = &proc_dointvec,
62129 + },
62130 +#endif
62131 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62132 + {
62133 + .procname = "harden_ptrace",
62134 + .data = &grsec_enable_harden_ptrace,
62135 + .maxlen = sizeof(int),
62136 + .mode = 0600,
62137 + .proc_handler = &proc_dointvec,
62138 + },
62139 +#endif
62140 + {
62141 + .procname = "grsec_lock",
62142 + .data = &grsec_lock,
62143 + .maxlen = sizeof(int),
62144 + .mode = 0600,
62145 + .proc_handler = &proc_dointvec,
62146 + },
62147 +#endif
62148 +#ifdef CONFIG_GRKERNSEC_ROFS
62149 + {
62150 + .procname = "romount_protect",
62151 + .data = &grsec_enable_rofs,
62152 + .maxlen = sizeof(int),
62153 + .mode = 0600,
62154 + .proc_handler = &proc_dointvec_minmax,
62155 + .extra1 = &one,
62156 + .extra2 = &one,
62157 + },
62158 +#endif
62159 + { }
62160 +};
62161 +#endif
62162 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
62163 new file mode 100644
62164 index 0000000..0dc13c3
62165 --- /dev/null
62166 +++ b/grsecurity/grsec_time.c
62167 @@ -0,0 +1,16 @@
62168 +#include <linux/kernel.h>
62169 +#include <linux/sched.h>
62170 +#include <linux/grinternal.h>
62171 +#include <linux/module.h>
62172 +
62173 +void
62174 +gr_log_timechange(void)
62175 +{
62176 +#ifdef CONFIG_GRKERNSEC_TIME
62177 + if (grsec_enable_time)
62178 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
62179 +#endif
62180 + return;
62181 +}
62182 +
62183 +EXPORT_SYMBOL(gr_log_timechange);
62184 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
62185 new file mode 100644
62186 index 0000000..07e0dc0
62187 --- /dev/null
62188 +++ b/grsecurity/grsec_tpe.c
62189 @@ -0,0 +1,73 @@
62190 +#include <linux/kernel.h>
62191 +#include <linux/sched.h>
62192 +#include <linux/file.h>
62193 +#include <linux/fs.h>
62194 +#include <linux/grinternal.h>
62195 +
62196 +extern int gr_acl_tpe_check(void);
62197 +
62198 +int
62199 +gr_tpe_allow(const struct file *file)
62200 +{
62201 +#ifdef CONFIG_GRKERNSEC
62202 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
62203 + const struct cred *cred = current_cred();
62204 + char *msg = NULL;
62205 + char *msg2 = NULL;
62206 +
62207 + // never restrict root
62208 + if (!cred->uid)
62209 + return 1;
62210 +
62211 + if (grsec_enable_tpe) {
62212 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62213 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
62214 + msg = "not being in trusted group";
62215 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
62216 + msg = "being in untrusted group";
62217 +#else
62218 + if (in_group_p(grsec_tpe_gid))
62219 + msg = "being in untrusted group";
62220 +#endif
62221 + }
62222 + if (!msg && gr_acl_tpe_check())
62223 + msg = "being in untrusted role";
62224 +
62225 + // not in any affected group/role
62226 + if (!msg)
62227 + goto next_check;
62228 +
62229 + if (inode->i_uid)
62230 + msg2 = "file in non-root-owned directory";
62231 + else if (inode->i_mode & S_IWOTH)
62232 + msg2 = "file in world-writable directory";
62233 + else if (inode->i_mode & S_IWGRP)
62234 + msg2 = "file in group-writable directory";
62235 +
62236 + if (msg && msg2) {
62237 + char fullmsg[70] = {0};
62238 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
62239 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
62240 + return 0;
62241 + }
62242 + msg = NULL;
62243 +next_check:
62244 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
62245 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
62246 + return 1;
62247 +
62248 + if (inode->i_uid && (inode->i_uid != cred->uid))
62249 + msg = "directory not owned by user";
62250 + else if (inode->i_mode & S_IWOTH)
62251 + msg = "file in world-writable directory";
62252 + else if (inode->i_mode & S_IWGRP)
62253 + msg = "file in group-writable directory";
62254 +
62255 + if (msg) {
62256 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
62257 + return 0;
62258 + }
62259 +#endif
62260 +#endif
62261 + return 1;
62262 +}
62263 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
62264 new file mode 100644
62265 index 0000000..9f7b1ac
62266 --- /dev/null
62267 +++ b/grsecurity/grsum.c
62268 @@ -0,0 +1,61 @@
62269 +#include <linux/err.h>
62270 +#include <linux/kernel.h>
62271 +#include <linux/sched.h>
62272 +#include <linux/mm.h>
62273 +#include <linux/scatterlist.h>
62274 +#include <linux/crypto.h>
62275 +#include <linux/gracl.h>
62276 +
62277 +
62278 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
62279 +#error "crypto and sha256 must be built into the kernel"
62280 +#endif
62281 +
62282 +int
62283 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
62284 +{
62285 + char *p;
62286 + struct crypto_hash *tfm;
62287 + struct hash_desc desc;
62288 + struct scatterlist sg;
62289 + unsigned char temp_sum[GR_SHA_LEN];
62290 + volatile int retval = 0;
62291 + volatile int dummy = 0;
62292 + unsigned int i;
62293 +
62294 + sg_init_table(&sg, 1);
62295 +
62296 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
62297 + if (IS_ERR(tfm)) {
62298 + /* should never happen, since sha256 should be built in */
62299 + return 1;
62300 + }
62301 +
62302 + desc.tfm = tfm;
62303 + desc.flags = 0;
62304 +
62305 + crypto_hash_init(&desc);
62306 +
62307 + p = salt;
62308 + sg_set_buf(&sg, p, GR_SALT_LEN);
62309 + crypto_hash_update(&desc, &sg, sg.length);
62310 +
62311 + p = entry->pw;
62312 + sg_set_buf(&sg, p, strlen(p));
62313 +
62314 + crypto_hash_update(&desc, &sg, sg.length);
62315 +
62316 + crypto_hash_final(&desc, temp_sum);
62317 +
62318 + memset(entry->pw, 0, GR_PW_LEN);
62319 +
62320 + for (i = 0; i < GR_SHA_LEN; i++)
62321 + if (sum[i] != temp_sum[i])
62322 + retval = 1;
62323 + else
62324 + dummy = 1; // waste a cycle
62325 +
62326 + crypto_free_hash(tfm);
62327 +
62328 + return retval;
62329 +}
62330 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
62331 index 77ff547..181834f 100644
62332 --- a/include/asm-generic/4level-fixup.h
62333 +++ b/include/asm-generic/4level-fixup.h
62334 @@ -13,8 +13,10 @@
62335 #define pmd_alloc(mm, pud, address) \
62336 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
62337 NULL: pmd_offset(pud, address))
62338 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
62339
62340 #define pud_alloc(mm, pgd, address) (pgd)
62341 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
62342 #define pud_offset(pgd, start) (pgd)
62343 #define pud_none(pud) 0
62344 #define pud_bad(pud) 0
62345 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
62346 index b7babf0..04ad282 100644
62347 --- a/include/asm-generic/atomic-long.h
62348 +++ b/include/asm-generic/atomic-long.h
62349 @@ -22,6 +22,12 @@
62350
62351 typedef atomic64_t atomic_long_t;
62352
62353 +#ifdef CONFIG_PAX_REFCOUNT
62354 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
62355 +#else
62356 +typedef atomic64_t atomic_long_unchecked_t;
62357 +#endif
62358 +
62359 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
62360
62361 static inline long atomic_long_read(atomic_long_t *l)
62362 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62363 return (long)atomic64_read(v);
62364 }
62365
62366 +#ifdef CONFIG_PAX_REFCOUNT
62367 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62368 +{
62369 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62370 +
62371 + return (long)atomic64_read_unchecked(v);
62372 +}
62373 +#endif
62374 +
62375 static inline void atomic_long_set(atomic_long_t *l, long i)
62376 {
62377 atomic64_t *v = (atomic64_t *)l;
62378 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62379 atomic64_set(v, i);
62380 }
62381
62382 +#ifdef CONFIG_PAX_REFCOUNT
62383 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62384 +{
62385 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62386 +
62387 + atomic64_set_unchecked(v, i);
62388 +}
62389 +#endif
62390 +
62391 static inline void atomic_long_inc(atomic_long_t *l)
62392 {
62393 atomic64_t *v = (atomic64_t *)l;
62394 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62395 atomic64_inc(v);
62396 }
62397
62398 +#ifdef CONFIG_PAX_REFCOUNT
62399 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62400 +{
62401 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62402 +
62403 + atomic64_inc_unchecked(v);
62404 +}
62405 +#endif
62406 +
62407 static inline void atomic_long_dec(atomic_long_t *l)
62408 {
62409 atomic64_t *v = (atomic64_t *)l;
62410 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62411 atomic64_dec(v);
62412 }
62413
62414 +#ifdef CONFIG_PAX_REFCOUNT
62415 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62416 +{
62417 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62418 +
62419 + atomic64_dec_unchecked(v);
62420 +}
62421 +#endif
62422 +
62423 static inline void atomic_long_add(long i, atomic_long_t *l)
62424 {
62425 atomic64_t *v = (atomic64_t *)l;
62426 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62427 atomic64_add(i, v);
62428 }
62429
62430 +#ifdef CONFIG_PAX_REFCOUNT
62431 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62432 +{
62433 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62434 +
62435 + atomic64_add_unchecked(i, v);
62436 +}
62437 +#endif
62438 +
62439 static inline void atomic_long_sub(long i, atomic_long_t *l)
62440 {
62441 atomic64_t *v = (atomic64_t *)l;
62442 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62443 atomic64_sub(i, v);
62444 }
62445
62446 +#ifdef CONFIG_PAX_REFCOUNT
62447 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62448 +{
62449 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62450 +
62451 + atomic64_sub_unchecked(i, v);
62452 +}
62453 +#endif
62454 +
62455 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62456 {
62457 atomic64_t *v = (atomic64_t *)l;
62458 @@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62459 return (long)atomic64_add_return(i, v);
62460 }
62461
62462 +#ifdef CONFIG_PAX_REFCOUNT
62463 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62464 +{
62465 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62466 +
62467 + return (long)atomic64_add_return_unchecked(i, v);
62468 +}
62469 +#endif
62470 +
62471 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62472 {
62473 atomic64_t *v = (atomic64_t *)l;
62474 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62475 return (long)atomic64_inc_return(v);
62476 }
62477
62478 +#ifdef CONFIG_PAX_REFCOUNT
62479 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62480 +{
62481 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62482 +
62483 + return (long)atomic64_inc_return_unchecked(v);
62484 +}
62485 +#endif
62486 +
62487 static inline long atomic_long_dec_return(atomic_long_t *l)
62488 {
62489 atomic64_t *v = (atomic64_t *)l;
62490 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62491
62492 typedef atomic_t atomic_long_t;
62493
62494 +#ifdef CONFIG_PAX_REFCOUNT
62495 +typedef atomic_unchecked_t atomic_long_unchecked_t;
62496 +#else
62497 +typedef atomic_t atomic_long_unchecked_t;
62498 +#endif
62499 +
62500 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
62501 static inline long atomic_long_read(atomic_long_t *l)
62502 {
62503 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62504 return (long)atomic_read(v);
62505 }
62506
62507 +#ifdef CONFIG_PAX_REFCOUNT
62508 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62509 +{
62510 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62511 +
62512 + return (long)atomic_read_unchecked(v);
62513 +}
62514 +#endif
62515 +
62516 static inline void atomic_long_set(atomic_long_t *l, long i)
62517 {
62518 atomic_t *v = (atomic_t *)l;
62519 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62520 atomic_set(v, i);
62521 }
62522
62523 +#ifdef CONFIG_PAX_REFCOUNT
62524 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62525 +{
62526 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62527 +
62528 + atomic_set_unchecked(v, i);
62529 +}
62530 +#endif
62531 +
62532 static inline void atomic_long_inc(atomic_long_t *l)
62533 {
62534 atomic_t *v = (atomic_t *)l;
62535 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62536 atomic_inc(v);
62537 }
62538
62539 +#ifdef CONFIG_PAX_REFCOUNT
62540 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62541 +{
62542 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62543 +
62544 + atomic_inc_unchecked(v);
62545 +}
62546 +#endif
62547 +
62548 static inline void atomic_long_dec(atomic_long_t *l)
62549 {
62550 atomic_t *v = (atomic_t *)l;
62551 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62552 atomic_dec(v);
62553 }
62554
62555 +#ifdef CONFIG_PAX_REFCOUNT
62556 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62557 +{
62558 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62559 +
62560 + atomic_dec_unchecked(v);
62561 +}
62562 +#endif
62563 +
62564 static inline void atomic_long_add(long i, atomic_long_t *l)
62565 {
62566 atomic_t *v = (atomic_t *)l;
62567 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62568 atomic_add(i, v);
62569 }
62570
62571 +#ifdef CONFIG_PAX_REFCOUNT
62572 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62573 +{
62574 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62575 +
62576 + atomic_add_unchecked(i, v);
62577 +}
62578 +#endif
62579 +
62580 static inline void atomic_long_sub(long i, atomic_long_t *l)
62581 {
62582 atomic_t *v = (atomic_t *)l;
62583 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62584 atomic_sub(i, v);
62585 }
62586
62587 +#ifdef CONFIG_PAX_REFCOUNT
62588 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62589 +{
62590 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62591 +
62592 + atomic_sub_unchecked(i, v);
62593 +}
62594 +#endif
62595 +
62596 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62597 {
62598 atomic_t *v = (atomic_t *)l;
62599 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62600 return (long)atomic_add_return(i, v);
62601 }
62602
62603 +#ifdef CONFIG_PAX_REFCOUNT
62604 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62605 +{
62606 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62607 +
62608 + return (long)atomic_add_return_unchecked(i, v);
62609 +}
62610 +
62611 +#endif
62612 +
62613 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62614 {
62615 atomic_t *v = (atomic_t *)l;
62616 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62617 return (long)atomic_inc_return(v);
62618 }
62619
62620 +#ifdef CONFIG_PAX_REFCOUNT
62621 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62622 +{
62623 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62624 +
62625 + return (long)atomic_inc_return_unchecked(v);
62626 +}
62627 +#endif
62628 +
62629 static inline long atomic_long_dec_return(atomic_long_t *l)
62630 {
62631 atomic_t *v = (atomic_t *)l;
62632 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62633
62634 #endif /* BITS_PER_LONG == 64 */
62635
62636 +#ifdef CONFIG_PAX_REFCOUNT
62637 +static inline void pax_refcount_needs_these_functions(void)
62638 +{
62639 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
62640 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
62641 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
62642 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
62643 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
62644 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
62645 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
62646 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
62647 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
62648 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
62649 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
62650 +#ifdef CONFIG_X86
62651 + atomic_clear_mask_unchecked(0, NULL);
62652 + atomic_set_mask_unchecked(0, NULL);
62653 +#endif
62654 +
62655 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
62656 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
62657 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
62658 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
62659 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
62660 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
62661 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
62662 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
62663 +}
62664 +#else
62665 +#define atomic_read_unchecked(v) atomic_read(v)
62666 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
62667 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
62668 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
62669 +#define atomic_inc_unchecked(v) atomic_inc(v)
62670 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
62671 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
62672 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
62673 +#define atomic_dec_unchecked(v) atomic_dec(v)
62674 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
62675 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
62676 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
62677 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
62678 +
62679 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
62680 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
62681 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
62682 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
62683 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
62684 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
62685 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
62686 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
62687 +#endif
62688 +
62689 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
62690 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
62691 index 1ced641..c896ee8 100644
62692 --- a/include/asm-generic/atomic.h
62693 +++ b/include/asm-generic/atomic.h
62694 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
62695 * Atomically clears the bits set in @mask from @v
62696 */
62697 #ifndef atomic_clear_mask
62698 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
62699 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
62700 {
62701 unsigned long flags;
62702
62703 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
62704 index b18ce4f..2ee2843 100644
62705 --- a/include/asm-generic/atomic64.h
62706 +++ b/include/asm-generic/atomic64.h
62707 @@ -16,6 +16,8 @@ typedef struct {
62708 long long counter;
62709 } atomic64_t;
62710
62711 +typedef atomic64_t atomic64_unchecked_t;
62712 +
62713 #define ATOMIC64_INIT(i) { (i) }
62714
62715 extern long long atomic64_read(const atomic64_t *v);
62716 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
62717 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
62718 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
62719
62720 +#define atomic64_read_unchecked(v) atomic64_read(v)
62721 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
62722 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
62723 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
62724 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
62725 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
62726 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
62727 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
62728 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
62729 +
62730 #endif /* _ASM_GENERIC_ATOMIC64_H */
62731 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
62732 index 1bfcfe5..e04c5c9 100644
62733 --- a/include/asm-generic/cache.h
62734 +++ b/include/asm-generic/cache.h
62735 @@ -6,7 +6,7 @@
62736 * cache lines need to provide their own cache.h.
62737 */
62738
62739 -#define L1_CACHE_SHIFT 5
62740 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
62741 +#define L1_CACHE_SHIFT 5UL
62742 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
62743
62744 #endif /* __ASM_GENERIC_CACHE_H */
62745 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
62746 index 0d68a1e..b74a761 100644
62747 --- a/include/asm-generic/emergency-restart.h
62748 +++ b/include/asm-generic/emergency-restart.h
62749 @@ -1,7 +1,7 @@
62750 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
62751 #define _ASM_GENERIC_EMERGENCY_RESTART_H
62752
62753 -static inline void machine_emergency_restart(void)
62754 +static inline __noreturn void machine_emergency_restart(void)
62755 {
62756 machine_restart(NULL);
62757 }
62758 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
62759 index 90f99c7..00ce236 100644
62760 --- a/include/asm-generic/kmap_types.h
62761 +++ b/include/asm-generic/kmap_types.h
62762 @@ -2,9 +2,9 @@
62763 #define _ASM_GENERIC_KMAP_TYPES_H
62764
62765 #ifdef __WITH_KM_FENCE
62766 -# define KM_TYPE_NR 41
62767 +# define KM_TYPE_NR 42
62768 #else
62769 -# define KM_TYPE_NR 20
62770 +# define KM_TYPE_NR 21
62771 #endif
62772
62773 #endif
62774 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
62775 index 9ceb03b..62b0b8f 100644
62776 --- a/include/asm-generic/local.h
62777 +++ b/include/asm-generic/local.h
62778 @@ -23,24 +23,37 @@ typedef struct
62779 atomic_long_t a;
62780 } local_t;
62781
62782 +typedef struct {
62783 + atomic_long_unchecked_t a;
62784 +} local_unchecked_t;
62785 +
62786 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
62787
62788 #define local_read(l) atomic_long_read(&(l)->a)
62789 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
62790 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
62791 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
62792 #define local_inc(l) atomic_long_inc(&(l)->a)
62793 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
62794 #define local_dec(l) atomic_long_dec(&(l)->a)
62795 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
62796 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
62797 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
62798 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
62799 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
62800
62801 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
62802 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
62803 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
62804 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
62805 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
62806 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
62807 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
62808 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
62809 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
62810
62811 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62812 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62813 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
62814 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
62815 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
62816 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
62817 index 725612b..9cc513a 100644
62818 --- a/include/asm-generic/pgtable-nopmd.h
62819 +++ b/include/asm-generic/pgtable-nopmd.h
62820 @@ -1,14 +1,19 @@
62821 #ifndef _PGTABLE_NOPMD_H
62822 #define _PGTABLE_NOPMD_H
62823
62824 -#ifndef __ASSEMBLY__
62825 -
62826 #include <asm-generic/pgtable-nopud.h>
62827
62828 -struct mm_struct;
62829 -
62830 #define __PAGETABLE_PMD_FOLDED
62831
62832 +#define PMD_SHIFT PUD_SHIFT
62833 +#define PTRS_PER_PMD 1
62834 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
62835 +#define PMD_MASK (~(PMD_SIZE-1))
62836 +
62837 +#ifndef __ASSEMBLY__
62838 +
62839 +struct mm_struct;
62840 +
62841 /*
62842 * Having the pmd type consist of a pud gets the size right, and allows
62843 * us to conceptually access the pud entry that this pmd is folded into
62844 @@ -16,11 +21,6 @@ struct mm_struct;
62845 */
62846 typedef struct { pud_t pud; } pmd_t;
62847
62848 -#define PMD_SHIFT PUD_SHIFT
62849 -#define PTRS_PER_PMD 1
62850 -#define PMD_SIZE (1UL << PMD_SHIFT)
62851 -#define PMD_MASK (~(PMD_SIZE-1))
62852 -
62853 /*
62854 * The "pud_xxx()" functions here are trivial for a folded two-level
62855 * setup: the pmd is never bad, and a pmd always exists (as it's folded
62856 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
62857 index 810431d..0ec4804f 100644
62858 --- a/include/asm-generic/pgtable-nopud.h
62859 +++ b/include/asm-generic/pgtable-nopud.h
62860 @@ -1,10 +1,15 @@
62861 #ifndef _PGTABLE_NOPUD_H
62862 #define _PGTABLE_NOPUD_H
62863
62864 -#ifndef __ASSEMBLY__
62865 -
62866 #define __PAGETABLE_PUD_FOLDED
62867
62868 +#define PUD_SHIFT PGDIR_SHIFT
62869 +#define PTRS_PER_PUD 1
62870 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
62871 +#define PUD_MASK (~(PUD_SIZE-1))
62872 +
62873 +#ifndef __ASSEMBLY__
62874 +
62875 /*
62876 * Having the pud type consist of a pgd gets the size right, and allows
62877 * us to conceptually access the pgd entry that this pud is folded into
62878 @@ -12,11 +17,6 @@
62879 */
62880 typedef struct { pgd_t pgd; } pud_t;
62881
62882 -#define PUD_SHIFT PGDIR_SHIFT
62883 -#define PTRS_PER_PUD 1
62884 -#define PUD_SIZE (1UL << PUD_SHIFT)
62885 -#define PUD_MASK (~(PUD_SIZE-1))
62886 -
62887 /*
62888 * The "pgd_xxx()" functions here are trivial for a folded two-level
62889 * setup: the pud is never bad, and a pud always exists (as it's folded
62890 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
62891 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
62892
62893 #define pgd_populate(mm, pgd, pud) do { } while (0)
62894 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
62895 /*
62896 * (puds are folded into pgds so this doesn't get actually called,
62897 * but the define is needed for a generic inline function.)
62898 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
62899 index b36ce40..019426d 100644
62900 --- a/include/asm-generic/pgtable.h
62901 +++ b/include/asm-generic/pgtable.h
62902 @@ -554,6 +554,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
62903 #endif
62904 }
62905
62906 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
62907 +static inline unsigned long pax_open_kernel(void) { return 0; }
62908 +#endif
62909 +
62910 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
62911 +static inline unsigned long pax_close_kernel(void) { return 0; }
62912 +#endif
62913 +
62914 #endif /* CONFIG_MMU */
62915
62916 #endif /* !__ASSEMBLY__ */
62917 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
62918 index d1ea7ce..b1ebf2a 100644
62919 --- a/include/asm-generic/vmlinux.lds.h
62920 +++ b/include/asm-generic/vmlinux.lds.h
62921 @@ -218,6 +218,7 @@
62922 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
62923 VMLINUX_SYMBOL(__start_rodata) = .; \
62924 *(.rodata) *(.rodata.*) \
62925 + *(.data..read_only) \
62926 *(__vermagic) /* Kernel version magic */ \
62927 . = ALIGN(8); \
62928 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
62929 @@ -725,17 +726,18 @@
62930 * section in the linker script will go there too. @phdr should have
62931 * a leading colon.
62932 *
62933 - * Note that this macros defines __per_cpu_load as an absolute symbol.
62934 + * Note that this macros defines per_cpu_load as an absolute symbol.
62935 * If there is no need to put the percpu section at a predetermined
62936 * address, use PERCPU_SECTION.
62937 */
62938 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
62939 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
62940 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
62941 + per_cpu_load = .; \
62942 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
62943 - LOAD_OFFSET) { \
62944 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
62945 PERCPU_INPUT(cacheline) \
62946 } phdr \
62947 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
62948 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
62949
62950 /**
62951 * PERCPU_SECTION - define output section for percpu area, simple version
62952 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
62953 index 418d270..bfd2794 100644
62954 --- a/include/crypto/algapi.h
62955 +++ b/include/crypto/algapi.h
62956 @@ -34,7 +34,7 @@ struct crypto_type {
62957 unsigned int maskclear;
62958 unsigned int maskset;
62959 unsigned int tfmsize;
62960 -};
62961 +} __do_const;
62962
62963 struct crypto_instance {
62964 struct crypto_alg alg;
62965 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
62966 index 3fd8280..2b3c415 100644
62967 --- a/include/drm/drmP.h
62968 +++ b/include/drm/drmP.h
62969 @@ -72,6 +72,7 @@
62970 #include <linux/workqueue.h>
62971 #include <linux/poll.h>
62972 #include <asm/pgalloc.h>
62973 +#include <asm/local.h>
62974 #include <drm/drm.h>
62975 #include <drm/drm_sarea.h>
62976
62977 @@ -1068,7 +1069,7 @@ struct drm_device {
62978
62979 /** \name Usage Counters */
62980 /*@{ */
62981 - int open_count; /**< Outstanding files open */
62982 + local_t open_count; /**< Outstanding files open */
62983 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
62984 atomic_t vma_count; /**< Outstanding vma areas open */
62985 int buf_use; /**< Buffers in use -- cannot alloc */
62986 @@ -1079,7 +1080,7 @@ struct drm_device {
62987 /*@{ */
62988 unsigned long counters;
62989 enum drm_stat_type types[15];
62990 - atomic_t counts[15];
62991 + atomic_unchecked_t counts[15];
62992 /*@} */
62993
62994 struct list_head filelist;
62995 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
62996 index e01cc80..6fb6f25 100644
62997 --- a/include/drm/drm_crtc_helper.h
62998 +++ b/include/drm/drm_crtc_helper.h
62999 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
63000 struct drm_connector *connector);
63001 /* disable encoder when not in use - more explicit than dpms off */
63002 void (*disable)(struct drm_encoder *encoder);
63003 -};
63004 +} __no_const;
63005
63006 /**
63007 * drm_connector_helper_funcs - helper operations for connectors
63008 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
63009 index d6d1da4..fdd1ac5 100644
63010 --- a/include/drm/ttm/ttm_memory.h
63011 +++ b/include/drm/ttm/ttm_memory.h
63012 @@ -48,7 +48,7 @@
63013
63014 struct ttm_mem_shrink {
63015 int (*do_shrink) (struct ttm_mem_shrink *);
63016 -};
63017 +} __no_const;
63018
63019 /**
63020 * struct ttm_mem_global - Global memory accounting structure.
63021 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
63022 index 22ef21c..75904ba 100644
63023 --- a/include/linux/atmdev.h
63024 +++ b/include/linux/atmdev.h
63025 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
63026 #endif
63027
63028 struct k_atm_aal_stats {
63029 -#define __HANDLE_ITEM(i) atomic_t i
63030 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63031 __AAL_STAT_ITEMS
63032 #undef __HANDLE_ITEM
63033 };
63034 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
63035 index de0628e..38f42eb 100644
63036 --- a/include/linux/binfmts.h
63037 +++ b/include/linux/binfmts.h
63038 @@ -75,6 +75,7 @@ struct linux_binfmt {
63039 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
63040 int (*load_shlib)(struct file *);
63041 int (*core_dump)(struct coredump_params *cprm);
63042 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
63043 unsigned long min_coredump; /* minimal dump size */
63044 };
63045
63046 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
63047 index 1756001..ab117ec 100644
63048 --- a/include/linux/blkdev.h
63049 +++ b/include/linux/blkdev.h
63050 @@ -1478,7 +1478,7 @@ struct block_device_operations {
63051 /* this callback is with swap_lock and sometimes page table lock held */
63052 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
63053 struct module *owner;
63054 -};
63055 +} __do_const;
63056
63057 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
63058 unsigned long);
63059 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
63060 index 7c2e030..b72475d 100644
63061 --- a/include/linux/blktrace_api.h
63062 +++ b/include/linux/blktrace_api.h
63063 @@ -23,7 +23,7 @@ struct blk_trace {
63064 struct dentry *dir;
63065 struct dentry *dropped_file;
63066 struct dentry *msg_file;
63067 - atomic_t dropped;
63068 + atomic_unchecked_t dropped;
63069 };
63070
63071 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
63072 diff --git a/include/linux/cache.h b/include/linux/cache.h
63073 index 4c57065..4307975 100644
63074 --- a/include/linux/cache.h
63075 +++ b/include/linux/cache.h
63076 @@ -16,6 +16,10 @@
63077 #define __read_mostly
63078 #endif
63079
63080 +#ifndef __read_only
63081 +#define __read_only __read_mostly
63082 +#endif
63083 +
63084 #ifndef ____cacheline_aligned
63085 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
63086 #endif
63087 diff --git a/include/linux/capability.h b/include/linux/capability.h
63088 index 98503b7..cc36d18 100644
63089 --- a/include/linux/capability.h
63090 +++ b/include/linux/capability.h
63091 @@ -211,8 +211,13 @@ extern bool capable(int cap);
63092 extern bool ns_capable(struct user_namespace *ns, int cap);
63093 extern bool nsown_capable(int cap);
63094 extern bool inode_capable(const struct inode *inode, int cap);
63095 +extern bool capable_nolog(int cap);
63096 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
63097 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
63098
63099 /* audit system wants to get cap info from files as well */
63100 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
63101
63102 +extern int is_privileged_binary(const struct dentry *dentry);
63103 +
63104 #endif /* !_LINUX_CAPABILITY_H */
63105 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
63106 index 8609d57..86e4d79 100644
63107 --- a/include/linux/cdrom.h
63108 +++ b/include/linux/cdrom.h
63109 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
63110
63111 /* driver specifications */
63112 const int capability; /* capability flags */
63113 - int n_minors; /* number of active minor devices */
63114 /* handle uniform packets for scsi type devices (scsi,atapi) */
63115 int (*generic_packet) (struct cdrom_device_info *,
63116 struct packet_command *);
63117 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
63118 index 42e55de..1cd0e66 100644
63119 --- a/include/linux/cleancache.h
63120 +++ b/include/linux/cleancache.h
63121 @@ -31,7 +31,7 @@ struct cleancache_ops {
63122 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
63123 void (*invalidate_inode)(int, struct cleancache_filekey);
63124 void (*invalidate_fs)(int);
63125 -};
63126 +} __no_const;
63127
63128 extern struct cleancache_ops
63129 cleancache_register_ops(struct cleancache_ops *ops);
63130 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
63131 index 412bc6c..c31666e 100644
63132 --- a/include/linux/compiler-gcc4.h
63133 +++ b/include/linux/compiler-gcc4.h
63134 @@ -32,6 +32,21 @@
63135 #define __linktime_error(message) __attribute__((__error__(message)))
63136
63137 #if __GNUC_MINOR__ >= 5
63138 +
63139 +#ifdef CONSTIFY_PLUGIN
63140 +#define __no_const __attribute__((no_const))
63141 +#define __do_const __attribute__((do_const))
63142 +#endif
63143 +
63144 +#ifdef SIZE_OVERFLOW_PLUGIN
63145 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
63146 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
63147 +#endif
63148 +
63149 +#ifdef LATENT_ENTROPY_PLUGIN
63150 +#define __latent_entropy __attribute__((latent_entropy))
63151 +#endif
63152 +
63153 /*
63154 * Mark a position in code as unreachable. This can be used to
63155 * suppress control flow warnings after asm blocks that transfer
63156 @@ -47,6 +62,11 @@
63157 #define __noclone __attribute__((__noclone__))
63158
63159 #endif
63160 +
63161 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
63162 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
63163 +#define __bos0(ptr) __bos((ptr), 0)
63164 +#define __bos1(ptr) __bos((ptr), 1)
63165 #endif
63166
63167 #if __GNUC_MINOR__ >= 6
63168 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
63169 index f430e41..38be90f 100644
63170 --- a/include/linux/compiler.h
63171 +++ b/include/linux/compiler.h
63172 @@ -5,31 +5,62 @@
63173
63174 #ifdef __CHECKER__
63175 # define __user __attribute__((noderef, address_space(1)))
63176 +# define __force_user __force __user
63177 # define __kernel __attribute__((address_space(0)))
63178 +# define __force_kernel __force __kernel
63179 # define __safe __attribute__((safe))
63180 # define __force __attribute__((force))
63181 # define __nocast __attribute__((nocast))
63182 # define __iomem __attribute__((noderef, address_space(2)))
63183 +# define __force_iomem __force __iomem
63184 # define __acquires(x) __attribute__((context(x,0,1)))
63185 # define __releases(x) __attribute__((context(x,1,0)))
63186 # define __acquire(x) __context__(x,1)
63187 # define __release(x) __context__(x,-1)
63188 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
63189 # define __percpu __attribute__((noderef, address_space(3)))
63190 +# define __force_percpu __force __percpu
63191 #ifdef CONFIG_SPARSE_RCU_POINTER
63192 # define __rcu __attribute__((noderef, address_space(4)))
63193 +# define __force_rcu __force __rcu
63194 #else
63195 # define __rcu
63196 +# define __force_rcu
63197 #endif
63198 extern void __chk_user_ptr(const volatile void __user *);
63199 extern void __chk_io_ptr(const volatile void __iomem *);
63200 +#elif defined(CHECKER_PLUGIN)
63201 +//# define __user
63202 +//# define __force_user
63203 +//# define __kernel
63204 +//# define __force_kernel
63205 +# define __safe
63206 +# define __force
63207 +# define __nocast
63208 +# define __iomem
63209 +# define __force_iomem
63210 +# define __chk_user_ptr(x) (void)0
63211 +# define __chk_io_ptr(x) (void)0
63212 +# define __builtin_warning(x, y...) (1)
63213 +# define __acquires(x)
63214 +# define __releases(x)
63215 +# define __acquire(x) (void)0
63216 +# define __release(x) (void)0
63217 +# define __cond_lock(x,c) (c)
63218 +# define __percpu
63219 +# define __force_percpu
63220 +# define __rcu
63221 +# define __force_rcu
63222 #else
63223 # define __user
63224 +# define __force_user
63225 # define __kernel
63226 +# define __force_kernel
63227 # define __safe
63228 # define __force
63229 # define __nocast
63230 # define __iomem
63231 +# define __force_iomem
63232 # define __chk_user_ptr(x) (void)0
63233 # define __chk_io_ptr(x) (void)0
63234 # define __builtin_warning(x, y...) (1)
63235 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
63236 # define __release(x) (void)0
63237 # define __cond_lock(x,c) (c)
63238 # define __percpu
63239 +# define __force_percpu
63240 # define __rcu
63241 +# define __force_rcu
63242 #endif
63243
63244 #ifdef __KERNEL__
63245 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63246 # define __attribute_const__ /* unimplemented */
63247 #endif
63248
63249 +#ifndef __no_const
63250 +# define __no_const
63251 +#endif
63252 +
63253 +#ifndef __do_const
63254 +# define __do_const
63255 +#endif
63256 +
63257 +#ifndef __size_overflow
63258 +# define __size_overflow(...)
63259 +#endif
63260 +
63261 +#ifndef __intentional_overflow
63262 +# define __intentional_overflow(...)
63263 +#endif
63264 +
63265 +#ifndef __latent_entropy
63266 +# define __latent_entropy
63267 +#endif
63268 +
63269 /*
63270 * Tell gcc if a function is cold. The compiler will assume any path
63271 * directly leading to the call is unlikely.
63272 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63273 #define __cold
63274 #endif
63275
63276 +#ifndef __alloc_size
63277 +#define __alloc_size(...)
63278 +#endif
63279 +
63280 +#ifndef __bos
63281 +#define __bos(ptr, arg)
63282 +#endif
63283 +
63284 +#ifndef __bos0
63285 +#define __bos0(ptr)
63286 +#endif
63287 +
63288 +#ifndef __bos1
63289 +#define __bos1(ptr)
63290 +#endif
63291 +
63292 /* Simple shorthand for a section definition */
63293 #ifndef __section
63294 # define __section(S) __attribute__ ((__section__(#S)))
63295 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63296 * use is to mediate communication between process-level code and irq/NMI
63297 * handlers, all running on the same CPU.
63298 */
63299 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
63300 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
63301 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
63302
63303 #endif /* __LINUX_COMPILER_H */
63304 diff --git a/include/linux/cred.h b/include/linux/cred.h
63305 index ebbed2c..908cc2c 100644
63306 --- a/include/linux/cred.h
63307 +++ b/include/linux/cred.h
63308 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
63309 static inline void validate_process_creds(void)
63310 {
63311 }
63312 +static inline void validate_task_creds(struct task_struct *task)
63313 +{
63314 +}
63315 #endif
63316
63317 /**
63318 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
63319 index b92eadf..b4ecdc1 100644
63320 --- a/include/linux/crypto.h
63321 +++ b/include/linux/crypto.h
63322 @@ -373,7 +373,7 @@ struct cipher_tfm {
63323 const u8 *key, unsigned int keylen);
63324 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63325 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63326 -};
63327 +} __no_const;
63328
63329 struct hash_tfm {
63330 int (*init)(struct hash_desc *desc);
63331 @@ -394,13 +394,13 @@ struct compress_tfm {
63332 int (*cot_decompress)(struct crypto_tfm *tfm,
63333 const u8 *src, unsigned int slen,
63334 u8 *dst, unsigned int *dlen);
63335 -};
63336 +} __no_const;
63337
63338 struct rng_tfm {
63339 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
63340 unsigned int dlen);
63341 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
63342 -};
63343 +} __no_const;
63344
63345 #define crt_ablkcipher crt_u.ablkcipher
63346 #define crt_aead crt_u.aead
63347 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
63348 index 7925bf0..d5143d2 100644
63349 --- a/include/linux/decompress/mm.h
63350 +++ b/include/linux/decompress/mm.h
63351 @@ -77,7 +77,7 @@ static void free(void *where)
63352 * warnings when not needed (indeed large_malloc / large_free are not
63353 * needed by inflate */
63354
63355 -#define malloc(a) kmalloc(a, GFP_KERNEL)
63356 +#define malloc(a) kmalloc((a), GFP_KERNEL)
63357 #define free(a) kfree(a)
63358
63359 #define large_malloc(a) vmalloc(a)
63360 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
63361 index 94af418..b1ca7a2 100644
63362 --- a/include/linux/dma-mapping.h
63363 +++ b/include/linux/dma-mapping.h
63364 @@ -54,7 +54,7 @@ struct dma_map_ops {
63365 u64 (*get_required_mask)(struct device *dev);
63366 #endif
63367 int is_phys;
63368 -};
63369 +} __do_const;
63370
63371 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
63372
63373 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
63374 index d3201e4..8281e63 100644
63375 --- a/include/linux/dmaengine.h
63376 +++ b/include/linux/dmaengine.h
63377 @@ -1018,9 +1018,9 @@ struct dma_pinned_list {
63378 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
63379 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
63380
63381 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63382 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63383 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
63384 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63385 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63386 struct dma_pinned_list *pinned_list, struct page *page,
63387 unsigned int offset, size_t len);
63388
63389 diff --git a/include/linux/elf.h b/include/linux/elf.h
63390 index 8c9048e..16a4665 100644
63391 --- a/include/linux/elf.h
63392 +++ b/include/linux/elf.h
63393 @@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
63394 #define elf_note elf32_note
63395 #define elf_addr_t Elf32_Off
63396 #define Elf_Half Elf32_Half
63397 +#define elf_dyn Elf32_Dyn
63398
63399 #else
63400
63401 @@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
63402 #define elf_note elf64_note
63403 #define elf_addr_t Elf64_Off
63404 #define Elf_Half Elf64_Half
63405 +#define elf_dyn Elf64_Dyn
63406
63407 #endif
63408
63409 diff --git a/include/linux/filter.h b/include/linux/filter.h
63410 index 24d251f..7afb83d 100644
63411 --- a/include/linux/filter.h
63412 +++ b/include/linux/filter.h
63413 @@ -20,6 +20,7 @@ struct compat_sock_fprog {
63414
63415 struct sk_buff;
63416 struct sock;
63417 +struct bpf_jit_work;
63418
63419 struct sk_filter
63420 {
63421 @@ -27,6 +28,9 @@ struct sk_filter
63422 unsigned int len; /* Number of filter blocks */
63423 unsigned int (*bpf_func)(const struct sk_buff *skb,
63424 const struct sock_filter *filter);
63425 +#ifdef CONFIG_BPF_JIT
63426 + struct bpf_jit_work *work;
63427 +#endif
63428 struct rcu_head rcu;
63429 struct sock_filter insns[0];
63430 };
63431 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
63432 index 3044254..9767f41 100644
63433 --- a/include/linux/frontswap.h
63434 +++ b/include/linux/frontswap.h
63435 @@ -11,7 +11,7 @@ struct frontswap_ops {
63436 int (*load)(unsigned, pgoff_t, struct page *);
63437 void (*invalidate_page)(unsigned, pgoff_t);
63438 void (*invalidate_area)(unsigned);
63439 -};
63440 +} __no_const;
63441
63442 extern bool frontswap_enabled;
63443 extern struct frontswap_ops
63444 diff --git a/include/linux/fs.h b/include/linux/fs.h
63445 index 75fe9a1..8417cac 100644
63446 --- a/include/linux/fs.h
63447 +++ b/include/linux/fs.h
63448 @@ -1543,7 +1543,8 @@ struct file_operations {
63449 int (*setlease)(struct file *, long, struct file_lock **);
63450 long (*fallocate)(struct file *file, int mode, loff_t offset,
63451 loff_t len);
63452 -};
63453 +} __do_const;
63454 +typedef struct file_operations __no_const file_operations_no_const;
63455
63456 struct inode_operations {
63457 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
63458 @@ -2667,4 +2668,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
63459 inode->i_flags |= S_NOSEC;
63460 }
63461
63462 +static inline bool is_sidechannel_device(const struct inode *inode)
63463 +{
63464 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
63465 + umode_t mode = inode->i_mode;
63466 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
63467 +#else
63468 + return false;
63469 +#endif
63470 +}
63471 +
63472 #endif /* _LINUX_FS_H */
63473 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
63474 index 003dc0f..3c4ea97 100644
63475 --- a/include/linux/fs_struct.h
63476 +++ b/include/linux/fs_struct.h
63477 @@ -6,7 +6,7 @@
63478 #include <linux/seqlock.h>
63479
63480 struct fs_struct {
63481 - int users;
63482 + atomic_t users;
63483 spinlock_t lock;
63484 seqcount_t seq;
63485 int umask;
63486 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
63487 index ce31408..b1ad003 100644
63488 --- a/include/linux/fscache-cache.h
63489 +++ b/include/linux/fscache-cache.h
63490 @@ -102,7 +102,7 @@ struct fscache_operation {
63491 fscache_operation_release_t release;
63492 };
63493
63494 -extern atomic_t fscache_op_debug_id;
63495 +extern atomic_unchecked_t fscache_op_debug_id;
63496 extern void fscache_op_work_func(struct work_struct *work);
63497
63498 extern void fscache_enqueue_operation(struct fscache_operation *);
63499 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
63500 {
63501 INIT_WORK(&op->work, fscache_op_work_func);
63502 atomic_set(&op->usage, 1);
63503 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
63504 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63505 op->processor = processor;
63506 op->release = release;
63507 INIT_LIST_HEAD(&op->pend_link);
63508 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
63509 index 0fbfb46..508eb0d 100644
63510 --- a/include/linux/fsnotify.h
63511 +++ b/include/linux/fsnotify.h
63512 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
63513 struct inode *inode = path->dentry->d_inode;
63514 __u32 mask = FS_ACCESS;
63515
63516 + if (is_sidechannel_device(inode))
63517 + return;
63518 +
63519 if (S_ISDIR(inode->i_mode))
63520 mask |= FS_ISDIR;
63521
63522 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
63523 struct inode *inode = path->dentry->d_inode;
63524 __u32 mask = FS_MODIFY;
63525
63526 + if (is_sidechannel_device(inode))
63527 + return;
63528 +
63529 if (S_ISDIR(inode->i_mode))
63530 mask |= FS_ISDIR;
63531
63532 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
63533 */
63534 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
63535 {
63536 - return kstrdup(name, GFP_KERNEL);
63537 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
63538 }
63539
63540 /*
63541 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
63542 index 642928c..93afe6a 100644
63543 --- a/include/linux/ftrace_event.h
63544 +++ b/include/linux/ftrace_event.h
63545 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
63546 extern int trace_add_event_call(struct ftrace_event_call *call);
63547 extern void trace_remove_event_call(struct ftrace_event_call *call);
63548
63549 -#define is_signed_type(type) (((type)(-1)) < 0)
63550 +#define is_signed_type(type) (((type)(-1)) < (type)1)
63551
63552 int trace_set_clr_event(const char *system, const char *event, int set);
63553
63554 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
63555 index 4f440b3..342233a 100644
63556 --- a/include/linux/genhd.h
63557 +++ b/include/linux/genhd.h
63558 @@ -190,7 +190,7 @@ struct gendisk {
63559 struct kobject *slave_dir;
63560
63561 struct timer_rand_state *random;
63562 - atomic_t sync_io; /* RAID */
63563 + atomic_unchecked_t sync_io; /* RAID */
63564 struct disk_events *ev;
63565 #ifdef CONFIG_BLK_DEV_INTEGRITY
63566 struct blk_integrity *integrity;
63567 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
63568 index d0a7967..63c4c47 100644
63569 --- a/include/linux/gfp.h
63570 +++ b/include/linux/gfp.h
63571 @@ -35,6 +35,12 @@ struct vm_area_struct;
63572 #define ___GFP_OTHER_NODE 0x800000u
63573 #define ___GFP_WRITE 0x1000000u
63574
63575 +#ifdef CONFIG_PAX_USERCOPY_SLABS
63576 +#define ___GFP_USERCOPY 0x2000000u
63577 +#else
63578 +#define ___GFP_USERCOPY 0
63579 +#endif
63580 +
63581 /*
63582 * GFP bitmasks..
63583 *
63584 @@ -89,6 +95,7 @@ struct vm_area_struct;
63585 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
63586 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
63587 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
63588 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
63589
63590 /*
63591 * This may seem redundant, but it's a way of annotating false positives vs.
63592 @@ -96,7 +103,7 @@ struct vm_area_struct;
63593 */
63594 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
63595
63596 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
63597 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
63598 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
63599
63600 /* This equals 0, but use constants in case they ever change */
63601 @@ -150,6 +157,8 @@ struct vm_area_struct;
63602 /* 4GB DMA on some platforms */
63603 #define GFP_DMA32 __GFP_DMA32
63604
63605 +#define GFP_USERCOPY __GFP_USERCOPY
63606 +
63607 /* Convert GFP flags to their corresponding migrate type */
63608 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
63609 {
63610 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
63611 new file mode 100644
63612 index 0000000..ebe6d72
63613 --- /dev/null
63614 +++ b/include/linux/gracl.h
63615 @@ -0,0 +1,319 @@
63616 +#ifndef GR_ACL_H
63617 +#define GR_ACL_H
63618 +
63619 +#include <linux/grdefs.h>
63620 +#include <linux/resource.h>
63621 +#include <linux/capability.h>
63622 +#include <linux/dcache.h>
63623 +#include <asm/resource.h>
63624 +
63625 +/* Major status information */
63626 +
63627 +#define GR_VERSION "grsecurity 2.9.1"
63628 +#define GRSECURITY_VERSION 0x2901
63629 +
63630 +enum {
63631 + GR_SHUTDOWN = 0,
63632 + GR_ENABLE = 1,
63633 + GR_SPROLE = 2,
63634 + GR_RELOAD = 3,
63635 + GR_SEGVMOD = 4,
63636 + GR_STATUS = 5,
63637 + GR_UNSPROLE = 6,
63638 + GR_PASSSET = 7,
63639 + GR_SPROLEPAM = 8,
63640 +};
63641 +
63642 +/* Password setup definitions
63643 + * kernel/grhash.c */
63644 +enum {
63645 + GR_PW_LEN = 128,
63646 + GR_SALT_LEN = 16,
63647 + GR_SHA_LEN = 32,
63648 +};
63649 +
63650 +enum {
63651 + GR_SPROLE_LEN = 64,
63652 +};
63653 +
63654 +enum {
63655 + GR_NO_GLOB = 0,
63656 + GR_REG_GLOB,
63657 + GR_CREATE_GLOB
63658 +};
63659 +
63660 +#define GR_NLIMITS 32
63661 +
63662 +/* Begin Data Structures */
63663 +
63664 +struct sprole_pw {
63665 + unsigned char *rolename;
63666 + unsigned char salt[GR_SALT_LEN];
63667 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
63668 +};
63669 +
63670 +struct name_entry {
63671 + __u32 key;
63672 + ino_t inode;
63673 + dev_t device;
63674 + char *name;
63675 + __u16 len;
63676 + __u8 deleted;
63677 + struct name_entry *prev;
63678 + struct name_entry *next;
63679 +};
63680 +
63681 +struct inodev_entry {
63682 + struct name_entry *nentry;
63683 + struct inodev_entry *prev;
63684 + struct inodev_entry *next;
63685 +};
63686 +
63687 +struct acl_role_db {
63688 + struct acl_role_label **r_hash;
63689 + __u32 r_size;
63690 +};
63691 +
63692 +struct inodev_db {
63693 + struct inodev_entry **i_hash;
63694 + __u32 i_size;
63695 +};
63696 +
63697 +struct name_db {
63698 + struct name_entry **n_hash;
63699 + __u32 n_size;
63700 +};
63701 +
63702 +struct crash_uid {
63703 + uid_t uid;
63704 + unsigned long expires;
63705 +};
63706 +
63707 +struct gr_hash_struct {
63708 + void **table;
63709 + void **nametable;
63710 + void *first;
63711 + __u32 table_size;
63712 + __u32 used_size;
63713 + int type;
63714 +};
63715 +
63716 +/* Userspace Grsecurity ACL data structures */
63717 +
63718 +struct acl_subject_label {
63719 + char *filename;
63720 + ino_t inode;
63721 + dev_t device;
63722 + __u32 mode;
63723 + kernel_cap_t cap_mask;
63724 + kernel_cap_t cap_lower;
63725 + kernel_cap_t cap_invert_audit;
63726 +
63727 + struct rlimit res[GR_NLIMITS];
63728 + __u32 resmask;
63729 +
63730 + __u8 user_trans_type;
63731 + __u8 group_trans_type;
63732 + uid_t *user_transitions;
63733 + gid_t *group_transitions;
63734 + __u16 user_trans_num;
63735 + __u16 group_trans_num;
63736 +
63737 + __u32 sock_families[2];
63738 + __u32 ip_proto[8];
63739 + __u32 ip_type;
63740 + struct acl_ip_label **ips;
63741 + __u32 ip_num;
63742 + __u32 inaddr_any_override;
63743 +
63744 + __u32 crashes;
63745 + unsigned long expires;
63746 +
63747 + struct acl_subject_label *parent_subject;
63748 + struct gr_hash_struct *hash;
63749 + struct acl_subject_label *prev;
63750 + struct acl_subject_label *next;
63751 +
63752 + struct acl_object_label **obj_hash;
63753 + __u32 obj_hash_size;
63754 + __u16 pax_flags;
63755 +};
63756 +
63757 +struct role_allowed_ip {
63758 + __u32 addr;
63759 + __u32 netmask;
63760 +
63761 + struct role_allowed_ip *prev;
63762 + struct role_allowed_ip *next;
63763 +};
63764 +
63765 +struct role_transition {
63766 + char *rolename;
63767 +
63768 + struct role_transition *prev;
63769 + struct role_transition *next;
63770 +};
63771 +
63772 +struct acl_role_label {
63773 + char *rolename;
63774 + uid_t uidgid;
63775 + __u16 roletype;
63776 +
63777 + __u16 auth_attempts;
63778 + unsigned long expires;
63779 +
63780 + struct acl_subject_label *root_label;
63781 + struct gr_hash_struct *hash;
63782 +
63783 + struct acl_role_label *prev;
63784 + struct acl_role_label *next;
63785 +
63786 + struct role_transition *transitions;
63787 + struct role_allowed_ip *allowed_ips;
63788 + uid_t *domain_children;
63789 + __u16 domain_child_num;
63790 +
63791 + umode_t umask;
63792 +
63793 + struct acl_subject_label **subj_hash;
63794 + __u32 subj_hash_size;
63795 +};
63796 +
63797 +struct user_acl_role_db {
63798 + struct acl_role_label **r_table;
63799 + __u32 num_pointers; /* Number of allocations to track */
63800 + __u32 num_roles; /* Number of roles */
63801 + __u32 num_domain_children; /* Number of domain children */
63802 + __u32 num_subjects; /* Number of subjects */
63803 + __u32 num_objects; /* Number of objects */
63804 +};
63805 +
63806 +struct acl_object_label {
63807 + char *filename;
63808 + ino_t inode;
63809 + dev_t device;
63810 + __u32 mode;
63811 +
63812 + struct acl_subject_label *nested;
63813 + struct acl_object_label *globbed;
63814 +
63815 + /* next two structures not used */
63816 +
63817 + struct acl_object_label *prev;
63818 + struct acl_object_label *next;
63819 +};
63820 +
63821 +struct acl_ip_label {
63822 + char *iface;
63823 + __u32 addr;
63824 + __u32 netmask;
63825 + __u16 low, high;
63826 + __u8 mode;
63827 + __u32 type;
63828 + __u32 proto[8];
63829 +
63830 + /* next two structures not used */
63831 +
63832 + struct acl_ip_label *prev;
63833 + struct acl_ip_label *next;
63834 +};
63835 +
63836 +struct gr_arg {
63837 + struct user_acl_role_db role_db;
63838 + unsigned char pw[GR_PW_LEN];
63839 + unsigned char salt[GR_SALT_LEN];
63840 + unsigned char sum[GR_SHA_LEN];
63841 + unsigned char sp_role[GR_SPROLE_LEN];
63842 + struct sprole_pw *sprole_pws;
63843 + dev_t segv_device;
63844 + ino_t segv_inode;
63845 + uid_t segv_uid;
63846 + __u16 num_sprole_pws;
63847 + __u16 mode;
63848 +};
63849 +
63850 +struct gr_arg_wrapper {
63851 + struct gr_arg *arg;
63852 + __u32 version;
63853 + __u32 size;
63854 +};
63855 +
63856 +struct subject_map {
63857 + struct acl_subject_label *user;
63858 + struct acl_subject_label *kernel;
63859 + struct subject_map *prev;
63860 + struct subject_map *next;
63861 +};
63862 +
63863 +struct acl_subj_map_db {
63864 + struct subject_map **s_hash;
63865 + __u32 s_size;
63866 +};
63867 +
63868 +/* End Data Structures Section */
63869 +
63870 +/* Hash functions generated by empirical testing by Brad Spengler
63871 + Makes good use of the low bits of the inode. Generally 0-1 times
63872 + in loop for successful match. 0-3 for unsuccessful match.
63873 + Shift/add algorithm with modulus of table size and an XOR*/
63874 +
63875 +static __inline__ unsigned int
63876 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
63877 +{
63878 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
63879 +}
63880 +
63881 + static __inline__ unsigned int
63882 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
63883 +{
63884 + return ((const unsigned long)userp % sz);
63885 +}
63886 +
63887 +static __inline__ unsigned int
63888 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
63889 +{
63890 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
63891 +}
63892 +
63893 +static __inline__ unsigned int
63894 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
63895 +{
63896 + return full_name_hash((const unsigned char *)name, len) % sz;
63897 +}
63898 +
63899 +#define FOR_EACH_ROLE_START(role) \
63900 + role = role_list; \
63901 + while (role) {
63902 +
63903 +#define FOR_EACH_ROLE_END(role) \
63904 + role = role->prev; \
63905 + }
63906 +
63907 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
63908 + subj = NULL; \
63909 + iter = 0; \
63910 + while (iter < role->subj_hash_size) { \
63911 + if (subj == NULL) \
63912 + subj = role->subj_hash[iter]; \
63913 + if (subj == NULL) { \
63914 + iter++; \
63915 + continue; \
63916 + }
63917 +
63918 +#define FOR_EACH_SUBJECT_END(subj,iter) \
63919 + subj = subj->next; \
63920 + if (subj == NULL) \
63921 + iter++; \
63922 + }
63923 +
63924 +
63925 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
63926 + subj = role->hash->first; \
63927 + while (subj != NULL) {
63928 +
63929 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
63930 + subj = subj->next; \
63931 + }
63932 +
63933 +#endif
63934 +
63935 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
63936 new file mode 100644
63937 index 0000000..323ecf2
63938 --- /dev/null
63939 +++ b/include/linux/gralloc.h
63940 @@ -0,0 +1,9 @@
63941 +#ifndef __GRALLOC_H
63942 +#define __GRALLOC_H
63943 +
63944 +void acl_free_all(void);
63945 +int acl_alloc_stack_init(unsigned long size);
63946 +void *acl_alloc(unsigned long len);
63947 +void *acl_alloc_num(unsigned long num, unsigned long len);
63948 +
63949 +#endif
63950 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
63951 new file mode 100644
63952 index 0000000..be66033
63953 --- /dev/null
63954 +++ b/include/linux/grdefs.h
63955 @@ -0,0 +1,140 @@
63956 +#ifndef GRDEFS_H
63957 +#define GRDEFS_H
63958 +
63959 +/* Begin grsecurity status declarations */
63960 +
63961 +enum {
63962 + GR_READY = 0x01,
63963 + GR_STATUS_INIT = 0x00 // disabled state
63964 +};
63965 +
63966 +/* Begin ACL declarations */
63967 +
63968 +/* Role flags */
63969 +
63970 +enum {
63971 + GR_ROLE_USER = 0x0001,
63972 + GR_ROLE_GROUP = 0x0002,
63973 + GR_ROLE_DEFAULT = 0x0004,
63974 + GR_ROLE_SPECIAL = 0x0008,
63975 + GR_ROLE_AUTH = 0x0010,
63976 + GR_ROLE_NOPW = 0x0020,
63977 + GR_ROLE_GOD = 0x0040,
63978 + GR_ROLE_LEARN = 0x0080,
63979 + GR_ROLE_TPE = 0x0100,
63980 + GR_ROLE_DOMAIN = 0x0200,
63981 + GR_ROLE_PAM = 0x0400,
63982 + GR_ROLE_PERSIST = 0x0800
63983 +};
63984 +
63985 +/* ACL Subject and Object mode flags */
63986 +enum {
63987 + GR_DELETED = 0x80000000
63988 +};
63989 +
63990 +/* ACL Object-only mode flags */
63991 +enum {
63992 + GR_READ = 0x00000001,
63993 + GR_APPEND = 0x00000002,
63994 + GR_WRITE = 0x00000004,
63995 + GR_EXEC = 0x00000008,
63996 + GR_FIND = 0x00000010,
63997 + GR_INHERIT = 0x00000020,
63998 + GR_SETID = 0x00000040,
63999 + GR_CREATE = 0x00000080,
64000 + GR_DELETE = 0x00000100,
64001 + GR_LINK = 0x00000200,
64002 + GR_AUDIT_READ = 0x00000400,
64003 + GR_AUDIT_APPEND = 0x00000800,
64004 + GR_AUDIT_WRITE = 0x00001000,
64005 + GR_AUDIT_EXEC = 0x00002000,
64006 + GR_AUDIT_FIND = 0x00004000,
64007 + GR_AUDIT_INHERIT= 0x00008000,
64008 + GR_AUDIT_SETID = 0x00010000,
64009 + GR_AUDIT_CREATE = 0x00020000,
64010 + GR_AUDIT_DELETE = 0x00040000,
64011 + GR_AUDIT_LINK = 0x00080000,
64012 + GR_PTRACERD = 0x00100000,
64013 + GR_NOPTRACE = 0x00200000,
64014 + GR_SUPPRESS = 0x00400000,
64015 + GR_NOLEARN = 0x00800000,
64016 + GR_INIT_TRANSFER= 0x01000000
64017 +};
64018 +
64019 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
64020 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
64021 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
64022 +
64023 +/* ACL subject-only mode flags */
64024 +enum {
64025 + GR_KILL = 0x00000001,
64026 + GR_VIEW = 0x00000002,
64027 + GR_PROTECTED = 0x00000004,
64028 + GR_LEARN = 0x00000008,
64029 + GR_OVERRIDE = 0x00000010,
64030 + /* just a placeholder, this mode is only used in userspace */
64031 + GR_DUMMY = 0x00000020,
64032 + GR_PROTSHM = 0x00000040,
64033 + GR_KILLPROC = 0x00000080,
64034 + GR_KILLIPPROC = 0x00000100,
64035 + /* just a placeholder, this mode is only used in userspace */
64036 + GR_NOTROJAN = 0x00000200,
64037 + GR_PROTPROCFD = 0x00000400,
64038 + GR_PROCACCT = 0x00000800,
64039 + GR_RELAXPTRACE = 0x00001000,
64040 + //GR_NESTED = 0x00002000,
64041 + GR_INHERITLEARN = 0x00004000,
64042 + GR_PROCFIND = 0x00008000,
64043 + GR_POVERRIDE = 0x00010000,
64044 + GR_KERNELAUTH = 0x00020000,
64045 + GR_ATSECURE = 0x00040000,
64046 + GR_SHMEXEC = 0x00080000
64047 +};
64048 +
64049 +enum {
64050 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
64051 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
64052 + GR_PAX_ENABLE_MPROTECT = 0x0004,
64053 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
64054 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
64055 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
64056 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
64057 + GR_PAX_DISABLE_MPROTECT = 0x0400,
64058 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
64059 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
64060 +};
64061 +
64062 +enum {
64063 + GR_ID_USER = 0x01,
64064 + GR_ID_GROUP = 0x02,
64065 +};
64066 +
64067 +enum {
64068 + GR_ID_ALLOW = 0x01,
64069 + GR_ID_DENY = 0x02,
64070 +};
64071 +
64072 +#define GR_CRASH_RES 31
64073 +#define GR_UIDTABLE_MAX 500
64074 +
64075 +/* begin resource learning section */
64076 +enum {
64077 + GR_RLIM_CPU_BUMP = 60,
64078 + GR_RLIM_FSIZE_BUMP = 50000,
64079 + GR_RLIM_DATA_BUMP = 10000,
64080 + GR_RLIM_STACK_BUMP = 1000,
64081 + GR_RLIM_CORE_BUMP = 10000,
64082 + GR_RLIM_RSS_BUMP = 500000,
64083 + GR_RLIM_NPROC_BUMP = 1,
64084 + GR_RLIM_NOFILE_BUMP = 5,
64085 + GR_RLIM_MEMLOCK_BUMP = 50000,
64086 + GR_RLIM_AS_BUMP = 500000,
64087 + GR_RLIM_LOCKS_BUMP = 2,
64088 + GR_RLIM_SIGPENDING_BUMP = 5,
64089 + GR_RLIM_MSGQUEUE_BUMP = 10000,
64090 + GR_RLIM_NICE_BUMP = 1,
64091 + GR_RLIM_RTPRIO_BUMP = 1,
64092 + GR_RLIM_RTTIME_BUMP = 1000000
64093 +};
64094 +
64095 +#endif
64096 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
64097 new file mode 100644
64098 index 0000000..baa6e96
64099 --- /dev/null
64100 +++ b/include/linux/grinternal.h
64101 @@ -0,0 +1,215 @@
64102 +#ifndef __GRINTERNAL_H
64103 +#define __GRINTERNAL_H
64104 +
64105 +#ifdef CONFIG_GRKERNSEC
64106 +
64107 +#include <linux/fs.h>
64108 +#include <linux/mnt_namespace.h>
64109 +#include <linux/nsproxy.h>
64110 +#include <linux/gracl.h>
64111 +#include <linux/grdefs.h>
64112 +#include <linux/grmsg.h>
64113 +
64114 +void gr_add_learn_entry(const char *fmt, ...)
64115 + __attribute__ ((format (printf, 1, 2)));
64116 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
64117 + const struct vfsmount *mnt);
64118 +__u32 gr_check_create(const struct dentry *new_dentry,
64119 + const struct dentry *parent,
64120 + const struct vfsmount *mnt, const __u32 mode);
64121 +int gr_check_protected_task(const struct task_struct *task);
64122 +__u32 to_gr_audit(const __u32 reqmode);
64123 +int gr_set_acls(const int type);
64124 +int gr_apply_subject_to_task(struct task_struct *task);
64125 +int gr_acl_is_enabled(void);
64126 +char gr_roletype_to_char(void);
64127 +
64128 +void gr_handle_alertkill(struct task_struct *task);
64129 +char *gr_to_filename(const struct dentry *dentry,
64130 + const struct vfsmount *mnt);
64131 +char *gr_to_filename1(const struct dentry *dentry,
64132 + const struct vfsmount *mnt);
64133 +char *gr_to_filename2(const struct dentry *dentry,
64134 + const struct vfsmount *mnt);
64135 +char *gr_to_filename3(const struct dentry *dentry,
64136 + const struct vfsmount *mnt);
64137 +
64138 +extern int grsec_enable_ptrace_readexec;
64139 +extern int grsec_enable_harden_ptrace;
64140 +extern int grsec_enable_link;
64141 +extern int grsec_enable_fifo;
64142 +extern int grsec_enable_execve;
64143 +extern int grsec_enable_shm;
64144 +extern int grsec_enable_execlog;
64145 +extern int grsec_enable_signal;
64146 +extern int grsec_enable_audit_ptrace;
64147 +extern int grsec_enable_forkfail;
64148 +extern int grsec_enable_time;
64149 +extern int grsec_enable_rofs;
64150 +extern int grsec_enable_chroot_shmat;
64151 +extern int grsec_enable_chroot_mount;
64152 +extern int grsec_enable_chroot_double;
64153 +extern int grsec_enable_chroot_pivot;
64154 +extern int grsec_enable_chroot_chdir;
64155 +extern int grsec_enable_chroot_chmod;
64156 +extern int grsec_enable_chroot_mknod;
64157 +extern int grsec_enable_chroot_fchdir;
64158 +extern int grsec_enable_chroot_nice;
64159 +extern int grsec_enable_chroot_execlog;
64160 +extern int grsec_enable_chroot_caps;
64161 +extern int grsec_enable_chroot_sysctl;
64162 +extern int grsec_enable_chroot_unix;
64163 +extern int grsec_enable_symlinkown;
64164 +extern int grsec_symlinkown_gid;
64165 +extern int grsec_enable_tpe;
64166 +extern int grsec_tpe_gid;
64167 +extern int grsec_enable_tpe_all;
64168 +extern int grsec_enable_tpe_invert;
64169 +extern int grsec_enable_socket_all;
64170 +extern int grsec_socket_all_gid;
64171 +extern int grsec_enable_socket_client;
64172 +extern int grsec_socket_client_gid;
64173 +extern int grsec_enable_socket_server;
64174 +extern int grsec_socket_server_gid;
64175 +extern int grsec_audit_gid;
64176 +extern int grsec_enable_group;
64177 +extern int grsec_enable_audit_textrel;
64178 +extern int grsec_enable_log_rwxmaps;
64179 +extern int grsec_enable_mount;
64180 +extern int grsec_enable_chdir;
64181 +extern int grsec_resource_logging;
64182 +extern int grsec_enable_blackhole;
64183 +extern int grsec_lastack_retries;
64184 +extern int grsec_enable_brute;
64185 +extern int grsec_lock;
64186 +
64187 +extern spinlock_t grsec_alert_lock;
64188 +extern unsigned long grsec_alert_wtime;
64189 +extern unsigned long grsec_alert_fyet;
64190 +
64191 +extern spinlock_t grsec_audit_lock;
64192 +
64193 +extern rwlock_t grsec_exec_file_lock;
64194 +
64195 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
64196 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
64197 + (tsk)->exec_file->f_vfsmnt) : "/")
64198 +
64199 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
64200 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
64201 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
64202 +
64203 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
64204 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
64205 + (tsk)->exec_file->f_vfsmnt) : "/")
64206 +
64207 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
64208 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
64209 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
64210 +
64211 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
64212 +
64213 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
64214 +
64215 +#define GR_CHROOT_CAPS {{ \
64216 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
64217 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
64218 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
64219 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
64220 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
64221 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
64222 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
64223 +
64224 +#define security_learn(normal_msg,args...) \
64225 +({ \
64226 + read_lock(&grsec_exec_file_lock); \
64227 + gr_add_learn_entry(normal_msg "\n", ## args); \
64228 + read_unlock(&grsec_exec_file_lock); \
64229 +})
64230 +
64231 +enum {
64232 + GR_DO_AUDIT,
64233 + GR_DONT_AUDIT,
64234 + /* used for non-audit messages that we shouldn't kill the task on */
64235 + GR_DONT_AUDIT_GOOD
64236 +};
64237 +
64238 +enum {
64239 + GR_TTYSNIFF,
64240 + GR_RBAC,
64241 + GR_RBAC_STR,
64242 + GR_STR_RBAC,
64243 + GR_RBAC_MODE2,
64244 + GR_RBAC_MODE3,
64245 + GR_FILENAME,
64246 + GR_SYSCTL_HIDDEN,
64247 + GR_NOARGS,
64248 + GR_ONE_INT,
64249 + GR_ONE_INT_TWO_STR,
64250 + GR_ONE_STR,
64251 + GR_STR_INT,
64252 + GR_TWO_STR_INT,
64253 + GR_TWO_INT,
64254 + GR_TWO_U64,
64255 + GR_THREE_INT,
64256 + GR_FIVE_INT_TWO_STR,
64257 + GR_TWO_STR,
64258 + GR_THREE_STR,
64259 + GR_FOUR_STR,
64260 + GR_STR_FILENAME,
64261 + GR_FILENAME_STR,
64262 + GR_FILENAME_TWO_INT,
64263 + GR_FILENAME_TWO_INT_STR,
64264 + GR_TEXTREL,
64265 + GR_PTRACE,
64266 + GR_RESOURCE,
64267 + GR_CAP,
64268 + GR_SIG,
64269 + GR_SIG2,
64270 + GR_CRASH1,
64271 + GR_CRASH2,
64272 + GR_PSACCT,
64273 + GR_RWXMAP
64274 +};
64275 +
64276 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
64277 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
64278 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
64279 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
64280 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
64281 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
64282 +#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)
64283 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
64284 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
64285 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
64286 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
64287 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
64288 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
64289 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
64290 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
64291 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
64292 +#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)
64293 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
64294 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
64295 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
64296 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
64297 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
64298 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
64299 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
64300 +#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)
64301 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
64302 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
64303 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
64304 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
64305 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
64306 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
64307 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
64308 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
64309 +#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)
64310 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
64311 +
64312 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
64313 +
64314 +#endif
64315 +
64316 +#endif
64317 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
64318 new file mode 100644
64319 index 0000000..2bd4c8d
64320 --- /dev/null
64321 +++ b/include/linux/grmsg.h
64322 @@ -0,0 +1,111 @@
64323 +#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"
64324 +#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"
64325 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
64326 +#define GR_STOPMOD_MSG "denied modification of module state by "
64327 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
64328 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
64329 +#define GR_IOPERM_MSG "denied use of ioperm() by "
64330 +#define GR_IOPL_MSG "denied use of iopl() by "
64331 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
64332 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
64333 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
64334 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
64335 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
64336 +#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"
64337 +#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"
64338 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
64339 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
64340 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
64341 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
64342 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
64343 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
64344 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
64345 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
64346 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
64347 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
64348 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
64349 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
64350 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
64351 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
64352 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
64353 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
64354 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
64355 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
64356 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
64357 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
64358 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
64359 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
64360 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
64361 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
64362 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
64363 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
64364 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
64365 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
64366 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
64367 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
64368 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
64369 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
64370 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
64371 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
64372 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
64373 +#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"
64374 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
64375 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
64376 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
64377 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
64378 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
64379 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
64380 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
64381 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
64382 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
64383 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
64384 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
64385 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
64386 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
64387 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
64388 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
64389 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
64390 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
64391 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
64392 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
64393 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
64394 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
64395 +#define GR_NICE_CHROOT_MSG "denied priority change by "
64396 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
64397 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
64398 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
64399 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
64400 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
64401 +#define GR_TIME_MSG "time set by "
64402 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
64403 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
64404 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
64405 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
64406 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
64407 +#define GR_BIND_MSG "denied bind() by "
64408 +#define GR_CONNECT_MSG "denied connect() by "
64409 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
64410 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
64411 +#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"
64412 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
64413 +#define GR_CAP_ACL_MSG "use of %s denied for "
64414 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
64415 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
64416 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
64417 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
64418 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
64419 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
64420 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
64421 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
64422 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
64423 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
64424 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
64425 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
64426 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
64427 +#define GR_VM86_MSG "denied use of vm86 by "
64428 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
64429 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
64430 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
64431 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
64432 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
64433 +#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 "
64434 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
64435 new file mode 100644
64436 index 0000000..72fff8d
64437 --- /dev/null
64438 +++ b/include/linux/grsecurity.h
64439 @@ -0,0 +1,259 @@
64440 +#ifndef GR_SECURITY_H
64441 +#define GR_SECURITY_H
64442 +#include <linux/fs.h>
64443 +#include <linux/fs_struct.h>
64444 +#include <linux/binfmts.h>
64445 +#include <linux/gracl.h>
64446 +
64447 +/* notify of brain-dead configs */
64448 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64449 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
64450 +#endif
64451 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
64452 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
64453 +#endif
64454 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
64455 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
64456 +#endif
64457 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
64458 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
64459 +#endif
64460 +
64461 +#include <linux/compat.h>
64462 +
64463 +struct user_arg_ptr {
64464 +#ifdef CONFIG_COMPAT
64465 + bool is_compat;
64466 +#endif
64467 + union {
64468 + const char __user *const __user *native;
64469 +#ifdef CONFIG_COMPAT
64470 + const compat_uptr_t __user *compat;
64471 +#endif
64472 + } ptr;
64473 +};
64474 +
64475 +void gr_handle_brute_attach(unsigned long mm_flags);
64476 +void gr_handle_brute_check(void);
64477 +void gr_handle_kernel_exploit(void);
64478 +int gr_process_user_ban(void);
64479 +
64480 +char gr_roletype_to_char(void);
64481 +
64482 +int gr_acl_enable_at_secure(void);
64483 +
64484 +int gr_check_user_change(int real, int effective, int fs);
64485 +int gr_check_group_change(int real, int effective, int fs);
64486 +
64487 +void gr_del_task_from_ip_table(struct task_struct *p);
64488 +
64489 +int gr_pid_is_chrooted(struct task_struct *p);
64490 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
64491 +int gr_handle_chroot_nice(void);
64492 +int gr_handle_chroot_sysctl(const int op);
64493 +int gr_handle_chroot_setpriority(struct task_struct *p,
64494 + const int niceval);
64495 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
64496 +int gr_handle_chroot_chroot(const struct dentry *dentry,
64497 + const struct vfsmount *mnt);
64498 +void gr_handle_chroot_chdir(struct path *path);
64499 +int gr_handle_chroot_chmod(const struct dentry *dentry,
64500 + const struct vfsmount *mnt, const int mode);
64501 +int gr_handle_chroot_mknod(const struct dentry *dentry,
64502 + const struct vfsmount *mnt, const int mode);
64503 +int gr_handle_chroot_mount(const struct dentry *dentry,
64504 + const struct vfsmount *mnt,
64505 + const char *dev_name);
64506 +int gr_handle_chroot_pivot(void);
64507 +int gr_handle_chroot_unix(const pid_t pid);
64508 +
64509 +int gr_handle_rawio(const struct inode *inode);
64510 +
64511 +void gr_handle_ioperm(void);
64512 +void gr_handle_iopl(void);
64513 +
64514 +umode_t gr_acl_umask(void);
64515 +
64516 +int gr_tpe_allow(const struct file *file);
64517 +
64518 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
64519 +void gr_clear_chroot_entries(struct task_struct *task);
64520 +
64521 +void gr_log_forkfail(const int retval);
64522 +void gr_log_timechange(void);
64523 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
64524 +void gr_log_chdir(const struct dentry *dentry,
64525 + const struct vfsmount *mnt);
64526 +void gr_log_chroot_exec(const struct dentry *dentry,
64527 + const struct vfsmount *mnt);
64528 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
64529 +void gr_log_remount(const char *devname, const int retval);
64530 +void gr_log_unmount(const char *devname, const int retval);
64531 +void gr_log_mount(const char *from, const char *to, const int retval);
64532 +void gr_log_textrel(struct vm_area_struct *vma);
64533 +void gr_log_rwxmmap(struct file *file);
64534 +void gr_log_rwxmprotect(struct file *file);
64535 +
64536 +int gr_handle_follow_link(const struct inode *parent,
64537 + const struct inode *inode,
64538 + const struct dentry *dentry,
64539 + const struct vfsmount *mnt);
64540 +int gr_handle_fifo(const struct dentry *dentry,
64541 + const struct vfsmount *mnt,
64542 + const struct dentry *dir, const int flag,
64543 + const int acc_mode);
64544 +int gr_handle_hardlink(const struct dentry *dentry,
64545 + const struct vfsmount *mnt,
64546 + struct inode *inode,
64547 + const int mode, const struct filename *to);
64548 +
64549 +int gr_is_capable(const int cap);
64550 +int gr_is_capable_nolog(const int cap);
64551 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64552 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
64553 +
64554 +void gr_learn_resource(const struct task_struct *task, const int limit,
64555 + const unsigned long wanted, const int gt);
64556 +void gr_copy_label(struct task_struct *tsk);
64557 +void gr_handle_crash(struct task_struct *task, const int sig);
64558 +int gr_handle_signal(const struct task_struct *p, const int sig);
64559 +int gr_check_crash_uid(const uid_t uid);
64560 +int gr_check_protected_task(const struct task_struct *task);
64561 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
64562 +int gr_acl_handle_mmap(const struct file *file,
64563 + const unsigned long prot);
64564 +int gr_acl_handle_mprotect(const struct file *file,
64565 + const unsigned long prot);
64566 +int gr_check_hidden_task(const struct task_struct *tsk);
64567 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
64568 + const struct vfsmount *mnt);
64569 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
64570 + const struct vfsmount *mnt);
64571 +__u32 gr_acl_handle_access(const struct dentry *dentry,
64572 + const struct vfsmount *mnt, const int fmode);
64573 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
64574 + const struct vfsmount *mnt, umode_t *mode);
64575 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
64576 + const struct vfsmount *mnt);
64577 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
64578 + const struct vfsmount *mnt);
64579 +int gr_handle_ptrace(struct task_struct *task, const long request);
64580 +int gr_handle_proc_ptrace(struct task_struct *task);
64581 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
64582 + const struct vfsmount *mnt);
64583 +int gr_check_crash_exec(const struct file *filp);
64584 +int gr_acl_is_enabled(void);
64585 +void gr_set_kernel_label(struct task_struct *task);
64586 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
64587 + const gid_t gid);
64588 +int gr_set_proc_label(const struct dentry *dentry,
64589 + const struct vfsmount *mnt,
64590 + const int unsafe_flags);
64591 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
64592 + const struct vfsmount *mnt);
64593 +__u32 gr_acl_handle_open(const struct dentry *dentry,
64594 + const struct vfsmount *mnt, int acc_mode);
64595 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
64596 + const struct dentry *p_dentry,
64597 + const struct vfsmount *p_mnt,
64598 + int open_flags, int acc_mode, const int imode);
64599 +void gr_handle_create(const struct dentry *dentry,
64600 + const struct vfsmount *mnt);
64601 +void gr_handle_proc_create(const struct dentry *dentry,
64602 + const struct inode *inode);
64603 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
64604 + const struct dentry *parent_dentry,
64605 + const struct vfsmount *parent_mnt,
64606 + const int mode);
64607 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
64608 + const struct dentry *parent_dentry,
64609 + const struct vfsmount *parent_mnt);
64610 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
64611 + const struct vfsmount *mnt);
64612 +void gr_handle_delete(const ino_t ino, const dev_t dev);
64613 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
64614 + const struct vfsmount *mnt);
64615 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
64616 + const struct dentry *parent_dentry,
64617 + const struct vfsmount *parent_mnt,
64618 + const struct filename *from);
64619 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
64620 + const struct dentry *parent_dentry,
64621 + const struct vfsmount *parent_mnt,
64622 + const struct dentry *old_dentry,
64623 + const struct vfsmount *old_mnt, const struct filename *to);
64624 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
64625 +int gr_acl_handle_rename(struct dentry *new_dentry,
64626 + struct dentry *parent_dentry,
64627 + const struct vfsmount *parent_mnt,
64628 + struct dentry *old_dentry,
64629 + struct inode *old_parent_inode,
64630 + struct vfsmount *old_mnt, const struct filename *newname);
64631 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64632 + struct dentry *old_dentry,
64633 + struct dentry *new_dentry,
64634 + struct vfsmount *mnt, const __u8 replace);
64635 +__u32 gr_check_link(const struct dentry *new_dentry,
64636 + const struct dentry *parent_dentry,
64637 + const struct vfsmount *parent_mnt,
64638 + const struct dentry *old_dentry,
64639 + const struct vfsmount *old_mnt);
64640 +int gr_acl_handle_filldir(const struct file *file, const char *name,
64641 + const unsigned int namelen, const ino_t ino);
64642 +
64643 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
64644 + const struct vfsmount *mnt);
64645 +void gr_acl_handle_exit(void);
64646 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
64647 +int gr_acl_handle_procpidmem(const struct task_struct *task);
64648 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
64649 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
64650 +void gr_audit_ptrace(struct task_struct *task);
64651 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
64652 +void gr_put_exec_file(struct task_struct *task);
64653 +
64654 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
64655 +
64656 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
64657 +extern void gr_learn_resource(const struct task_struct *task, const int res,
64658 + const unsigned long wanted, const int gt);
64659 +#else
64660 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
64661 + const unsigned long wanted, const int gt)
64662 +{
64663 +}
64664 +#endif
64665 +
64666 +#ifdef CONFIG_GRKERNSEC_RESLOG
64667 +extern void gr_log_resource(const struct task_struct *task, const int res,
64668 + const unsigned long wanted, const int gt);
64669 +#else
64670 +static inline void gr_log_resource(const struct task_struct *task, const int res,
64671 + const unsigned long wanted, const int gt)
64672 +{
64673 +}
64674 +#endif
64675 +
64676 +#ifdef CONFIG_GRKERNSEC
64677 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
64678 +void gr_handle_vm86(void);
64679 +void gr_handle_mem_readwrite(u64 from, u64 to);
64680 +
64681 +void gr_log_badprocpid(const char *entry);
64682 +
64683 +extern int grsec_enable_dmesg;
64684 +extern int grsec_disable_privio;
64685 +
64686 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64687 +extern int grsec_proc_gid;
64688 +#endif
64689 +
64690 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64691 +extern int grsec_enable_chroot_findtask;
64692 +#endif
64693 +#ifdef CONFIG_GRKERNSEC_SETXID
64694 +extern int grsec_enable_setxid;
64695 +#endif
64696 +#endif
64697 +
64698 +#endif
64699 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
64700 new file mode 100644
64701 index 0000000..e7ffaaf
64702 --- /dev/null
64703 +++ b/include/linux/grsock.h
64704 @@ -0,0 +1,19 @@
64705 +#ifndef __GRSOCK_H
64706 +#define __GRSOCK_H
64707 +
64708 +extern void gr_attach_curr_ip(const struct sock *sk);
64709 +extern int gr_handle_sock_all(const int family, const int type,
64710 + const int protocol);
64711 +extern int gr_handle_sock_server(const struct sockaddr *sck);
64712 +extern int gr_handle_sock_server_other(const struct sock *sck);
64713 +extern int gr_handle_sock_client(const struct sockaddr *sck);
64714 +extern int gr_search_connect(struct socket * sock,
64715 + struct sockaddr_in * addr);
64716 +extern int gr_search_bind(struct socket * sock,
64717 + struct sockaddr_in * addr);
64718 +extern int gr_search_listen(struct socket * sock);
64719 +extern int gr_search_accept(struct socket * sock);
64720 +extern int gr_search_socket(const int domain, const int type,
64721 + const int protocol);
64722 +
64723 +#endif
64724 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
64725 index ef788b5..ac41b7b 100644
64726 --- a/include/linux/highmem.h
64727 +++ b/include/linux/highmem.h
64728 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
64729 kunmap_atomic(kaddr);
64730 }
64731
64732 +static inline void sanitize_highpage(struct page *page)
64733 +{
64734 + void *kaddr;
64735 + unsigned long flags;
64736 +
64737 + local_irq_save(flags);
64738 + kaddr = kmap_atomic(page);
64739 + clear_page(kaddr);
64740 + kunmap_atomic(kaddr);
64741 + local_irq_restore(flags);
64742 +}
64743 +
64744 static inline void zero_user_segments(struct page *page,
64745 unsigned start1, unsigned end1,
64746 unsigned start2, unsigned end2)
64747 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
64748 index 800de22..7a2fa46 100644
64749 --- a/include/linux/i2c.h
64750 +++ b/include/linux/i2c.h
64751 @@ -367,6 +367,7 @@ struct i2c_algorithm {
64752 /* To determine what the adapter supports */
64753 u32 (*functionality) (struct i2c_adapter *);
64754 };
64755 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
64756
64757 /*
64758 * i2c_adapter is the structure used to identify a physical i2c bus along
64759 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
64760 index d23c3c2..eb63c81 100644
64761 --- a/include/linux/i2o.h
64762 +++ b/include/linux/i2o.h
64763 @@ -565,7 +565,7 @@ struct i2o_controller {
64764 struct i2o_device *exec; /* Executive */
64765 #if BITS_PER_LONG == 64
64766 spinlock_t context_list_lock; /* lock for context_list */
64767 - atomic_t context_list_counter; /* needed for unique contexts */
64768 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
64769 struct list_head context_list; /* list of context id's
64770 and pointers */
64771 #endif
64772 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
64773 index aff7ad8..3942bbd 100644
64774 --- a/include/linux/if_pppox.h
64775 +++ b/include/linux/if_pppox.h
64776 @@ -76,7 +76,7 @@ struct pppox_proto {
64777 int (*ioctl)(struct socket *sock, unsigned int cmd,
64778 unsigned long arg);
64779 struct module *owner;
64780 -};
64781 +} __do_const;
64782
64783 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
64784 extern void unregister_pppox_proto(int proto_num);
64785 diff --git a/include/linux/init.h b/include/linux/init.h
64786 index e59041e..df0a975 100644
64787 --- a/include/linux/init.h
64788 +++ b/include/linux/init.h
64789 @@ -39,9 +39,36 @@
64790 * Also note, that this data cannot be "const".
64791 */
64792
64793 +#ifdef MODULE
64794 +#define add_init_latent_entropy
64795 +#define add_devinit_latent_entropy
64796 +#define add_cpuinit_latent_entropy
64797 +#define add_meminit_latent_entropy
64798 +#else
64799 +#define add_init_latent_entropy __latent_entropy
64800 +
64801 +#ifdef CONFIG_HOTPLUG
64802 +#define add_devinit_latent_entropy
64803 +#else
64804 +#define add_devinit_latent_entropy __latent_entropy
64805 +#endif
64806 +
64807 +#ifdef CONFIG_HOTPLUG_CPU
64808 +#define add_cpuinit_latent_entropy
64809 +#else
64810 +#define add_cpuinit_latent_entropy __latent_entropy
64811 +#endif
64812 +
64813 +#ifdef CONFIG_MEMORY_HOTPLUG
64814 +#define add_meminit_latent_entropy
64815 +#else
64816 +#define add_meminit_latent_entropy __latent_entropy
64817 +#endif
64818 +#endif
64819 +
64820 /* These are for everybody (although not all archs will actually
64821 discard it in modules) */
64822 -#define __init __section(.init.text) __cold notrace
64823 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
64824 #define __initdata __section(.init.data)
64825 #define __initconst __constsection(.init.rodata)
64826 #define __exitdata __section(.exit.data)
64827 @@ -94,7 +121,7 @@
64828 #define __exit __section(.exit.text) __exitused __cold notrace
64829
64830 /* Used for HOTPLUG */
64831 -#define __devinit __section(.devinit.text) __cold notrace
64832 +#define __devinit __section(.devinit.text) __cold notrace add_devinit_latent_entropy
64833 #define __devinitdata __section(.devinit.data)
64834 #define __devinitconst __constsection(.devinit.rodata)
64835 #define __devexit __section(.devexit.text) __exitused __cold notrace
64836 @@ -102,7 +129,7 @@
64837 #define __devexitconst __constsection(.devexit.rodata)
64838
64839 /* Used for HOTPLUG_CPU */
64840 -#define __cpuinit __section(.cpuinit.text) __cold notrace
64841 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
64842 #define __cpuinitdata __section(.cpuinit.data)
64843 #define __cpuinitconst __constsection(.cpuinit.rodata)
64844 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
64845 @@ -110,7 +137,7 @@
64846 #define __cpuexitconst __constsection(.cpuexit.rodata)
64847
64848 /* Used for MEMORY_HOTPLUG */
64849 -#define __meminit __section(.meminit.text) __cold notrace
64850 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
64851 #define __meminitdata __section(.meminit.data)
64852 #define __meminitconst __constsection(.meminit.rodata)
64853 #define __memexit __section(.memexit.text) __exitused __cold notrace
64854 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
64855 index 6d087c5..401cab8 100644
64856 --- a/include/linux/init_task.h
64857 +++ b/include/linux/init_task.h
64858 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
64859
64860 #define INIT_TASK_COMM "swapper"
64861
64862 +#ifdef CONFIG_X86
64863 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
64864 +#else
64865 +#define INIT_TASK_THREAD_INFO
64866 +#endif
64867 +
64868 /*
64869 * INIT_TASK is used to set up the first task table, touch at
64870 * your own risk!. Base=0, limit=0x1fffff (=2MB)
64871 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
64872 RCU_POINTER_INITIALIZER(cred, &init_cred), \
64873 .comm = INIT_TASK_COMM, \
64874 .thread = INIT_THREAD, \
64875 + INIT_TASK_THREAD_INFO \
64876 .fs = &init_fs, \
64877 .files = &init_files, \
64878 .signal = &init_signals, \
64879 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
64880 index 5e4e617..eee383d 100644
64881 --- a/include/linux/interrupt.h
64882 +++ b/include/linux/interrupt.h
64883 @@ -435,7 +435,7 @@ enum
64884 /* map softirq index to softirq name. update 'softirq_to_name' in
64885 * kernel/softirq.c when adding a new softirq.
64886 */
64887 -extern char *softirq_to_name[NR_SOFTIRQS];
64888 +extern const char * const softirq_to_name[NR_SOFTIRQS];
64889
64890 /* softirq mask and active fields moved to irq_cpustat_t in
64891 * asm/hardirq.h to get better cache usage. KAO
64892 @@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
64893
64894 struct softirq_action
64895 {
64896 - void (*action)(struct softirq_action *);
64897 + void (*action)(void);
64898 };
64899
64900 asmlinkage void do_softirq(void);
64901 asmlinkage void __do_softirq(void);
64902 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
64903 +extern void open_softirq(int nr, void (*action)(void));
64904 extern void softirq_init(void);
64905 extern void __raise_softirq_irqoff(unsigned int nr);
64906
64907 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
64908 index 6883e19..06992b1 100644
64909 --- a/include/linux/kallsyms.h
64910 +++ b/include/linux/kallsyms.h
64911 @@ -15,7 +15,8 @@
64912
64913 struct module;
64914
64915 -#ifdef CONFIG_KALLSYMS
64916 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
64917 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64918 /* Lookup the address for a symbol. Returns 0 if not found. */
64919 unsigned long kallsyms_lookup_name(const char *name);
64920
64921 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
64922 /* Stupid that this does nothing, but I didn't create this mess. */
64923 #define __print_symbol(fmt, addr)
64924 #endif /*CONFIG_KALLSYMS*/
64925 +#else /* when included by kallsyms.c, vsnprintf.c, or
64926 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
64927 +extern void __print_symbol(const char *fmt, unsigned long address);
64928 +extern int sprint_backtrace(char *buffer, unsigned long address);
64929 +extern int sprint_symbol(char *buffer, unsigned long address);
64930 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
64931 +const char *kallsyms_lookup(unsigned long addr,
64932 + unsigned long *symbolsize,
64933 + unsigned long *offset,
64934 + char **modname, char *namebuf);
64935 +#endif
64936
64937 /* This macro allows us to keep printk typechecking */
64938 static __printf(1, 2)
64939 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
64940 index 4dff0c6..1ca9b72 100644
64941 --- a/include/linux/kgdb.h
64942 +++ b/include/linux/kgdb.h
64943 @@ -53,7 +53,7 @@ extern int kgdb_connected;
64944 extern int kgdb_io_module_registered;
64945
64946 extern atomic_t kgdb_setting_breakpoint;
64947 -extern atomic_t kgdb_cpu_doing_single_step;
64948 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
64949
64950 extern struct task_struct *kgdb_usethread;
64951 extern struct task_struct *kgdb_contthread;
64952 @@ -255,7 +255,7 @@ struct kgdb_arch {
64953 void (*correct_hw_break)(void);
64954
64955 void (*enable_nmi)(bool on);
64956 -};
64957 +} __do_const;
64958
64959 /**
64960 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
64961 @@ -280,7 +280,7 @@ struct kgdb_io {
64962 void (*pre_exception) (void);
64963 void (*post_exception) (void);
64964 int is_console;
64965 -};
64966 +} __do_const;
64967
64968 extern struct kgdb_arch arch_kgdb_ops;
64969
64970 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
64971 index 5398d58..5883a34 100644
64972 --- a/include/linux/kmod.h
64973 +++ b/include/linux/kmod.h
64974 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
64975 * usually useless though. */
64976 extern __printf(2, 3)
64977 int __request_module(bool wait, const char *name, ...);
64978 +extern __printf(3, 4)
64979 +int ___request_module(bool wait, char *param_name, const char *name, ...);
64980 #define request_module(mod...) __request_module(true, mod)
64981 #define request_module_nowait(mod...) __request_module(false, mod)
64982 #define try_then_request_module(x, mod...) \
64983 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
64984 index 1e57449..4fede7b 100644
64985 --- a/include/linux/kobject.h
64986 +++ b/include/linux/kobject.h
64987 @@ -111,7 +111,7 @@ struct kobj_type {
64988 struct attribute **default_attrs;
64989 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
64990 const void *(*namespace)(struct kobject *kobj);
64991 -};
64992 +} __do_const;
64993
64994 struct kobj_uevent_env {
64995 char *envp[UEVENT_NUM_ENVP];
64996 diff --git a/include/linux/kref.h b/include/linux/kref.h
64997 index 65af688..0592677 100644
64998 --- a/include/linux/kref.h
64999 +++ b/include/linux/kref.h
65000 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
65001 static inline int kref_sub(struct kref *kref, unsigned int count,
65002 void (*release)(struct kref *kref))
65003 {
65004 - WARN_ON(release == NULL);
65005 + BUG_ON(release == NULL);
65006
65007 if (atomic_sub_and_test((int) count, &kref->refcount)) {
65008 release(kref);
65009 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
65010 index ecc5543..0e96bcc 100644
65011 --- a/include/linux/kvm_host.h
65012 +++ b/include/linux/kvm_host.h
65013 @@ -403,7 +403,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
65014 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
65015 void vcpu_put(struct kvm_vcpu *vcpu);
65016
65017 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65018 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65019 struct module *module);
65020 void kvm_exit(void);
65021
65022 @@ -558,7 +558,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
65023 struct kvm_guest_debug *dbg);
65024 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
65025
65026 -int kvm_arch_init(void *opaque);
65027 +int kvm_arch_init(const void *opaque);
65028 void kvm_arch_exit(void);
65029
65030 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
65031 diff --git a/include/linux/libata.h b/include/linux/libata.h
65032 index 1e36c63..0c5046e 100644
65033 --- a/include/linux/libata.h
65034 +++ b/include/linux/libata.h
65035 @@ -915,7 +915,7 @@ struct ata_port_operations {
65036 * fields must be pointers.
65037 */
65038 const struct ata_port_operations *inherits;
65039 -};
65040 +} __do_const;
65041
65042 struct ata_port_info {
65043 unsigned long flags;
65044 diff --git a/include/linux/list.h b/include/linux/list.h
65045 index cc6d2aa..71febca 100644
65046 --- a/include/linux/list.h
65047 +++ b/include/linux/list.h
65048 @@ -112,6 +112,9 @@ extern void __list_del_entry(struct list_head *entry);
65049 extern void list_del(struct list_head *entry);
65050 #endif
65051
65052 +extern void pax_list_add_tail(struct list_head *new, struct list_head *head);
65053 +extern void pax_list_del(struct list_head *entry);
65054 +
65055 /**
65056 * list_replace - replace old entry by new one
65057 * @old : the element to be replaced
65058 diff --git a/include/linux/mm.h b/include/linux/mm.h
65059 index 280dae5..39046ec 100644
65060 --- a/include/linux/mm.h
65061 +++ b/include/linux/mm.h
65062 @@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
65063 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
65064 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
65065 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
65066 +
65067 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
65068 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
65069 +#endif
65070 +
65071 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
65072
65073 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
65074 @@ -1039,34 +1044,6 @@ int set_page_dirty(struct page *page);
65075 int set_page_dirty_lock(struct page *page);
65076 int clear_page_dirty_for_io(struct page *page);
65077
65078 -/* Is the vma a continuation of the stack vma above it? */
65079 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
65080 -{
65081 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
65082 -}
65083 -
65084 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
65085 - unsigned long addr)
65086 -{
65087 - return (vma->vm_flags & VM_GROWSDOWN) &&
65088 - (vma->vm_start == addr) &&
65089 - !vma_growsdown(vma->vm_prev, addr);
65090 -}
65091 -
65092 -/* Is the vma a continuation of the stack vma below it? */
65093 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
65094 -{
65095 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
65096 -}
65097 -
65098 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
65099 - unsigned long addr)
65100 -{
65101 - return (vma->vm_flags & VM_GROWSUP) &&
65102 - (vma->vm_end == addr) &&
65103 - !vma_growsup(vma->vm_next, addr);
65104 -}
65105 -
65106 extern pid_t
65107 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
65108
65109 @@ -1166,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
65110 }
65111 #endif
65112
65113 +#ifdef CONFIG_MMU
65114 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
65115 +#else
65116 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
65117 +{
65118 + return __pgprot(0);
65119 +}
65120 +#endif
65121 +
65122 int vma_wants_writenotify(struct vm_area_struct *vma);
65123
65124 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
65125 @@ -1184,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
65126 {
65127 return 0;
65128 }
65129 +
65130 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
65131 + unsigned long address)
65132 +{
65133 + return 0;
65134 +}
65135 #else
65136 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
65137 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
65138 #endif
65139
65140 #ifdef __PAGETABLE_PMD_FOLDED
65141 @@ -1194,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
65142 {
65143 return 0;
65144 }
65145 +
65146 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
65147 + unsigned long address)
65148 +{
65149 + return 0;
65150 +}
65151 #else
65152 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
65153 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
65154 #endif
65155
65156 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
65157 @@ -1213,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
65158 NULL: pud_offset(pgd, address);
65159 }
65160
65161 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
65162 +{
65163 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
65164 + NULL: pud_offset(pgd, address);
65165 +}
65166 +
65167 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
65168 {
65169 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
65170 NULL: pmd_offset(pud, address);
65171 }
65172 +
65173 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
65174 +{
65175 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
65176 + NULL: pmd_offset(pud, address);
65177 +}
65178 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
65179
65180 #if USE_SPLIT_PTLOCKS
65181 @@ -1447,6 +1459,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
65182 unsigned long, unsigned long,
65183 unsigned long, unsigned long);
65184 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
65185 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
65186
65187 /* These take the mm semaphore themselves */
65188 extern unsigned long vm_brk(unsigned long, unsigned long);
65189 @@ -1510,6 +1523,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
65190 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
65191 struct vm_area_struct **pprev);
65192
65193 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
65194 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
65195 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
65196 +
65197 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
65198 NULL if none. Assume start_addr < end_addr. */
65199 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
65200 @@ -1538,15 +1555,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
65201 return vma;
65202 }
65203
65204 -#ifdef CONFIG_MMU
65205 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
65206 -#else
65207 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
65208 -{
65209 - return __pgprot(0);
65210 -}
65211 -#endif
65212 -
65213 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
65214 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
65215 unsigned long pfn, unsigned long size, pgprot_t);
65216 @@ -1652,7 +1660,7 @@ extern int unpoison_memory(unsigned long pfn);
65217 extern int sysctl_memory_failure_early_kill;
65218 extern int sysctl_memory_failure_recovery;
65219 extern void shake_page(struct page *p, int access);
65220 -extern atomic_long_t mce_bad_pages;
65221 +extern atomic_long_unchecked_t mce_bad_pages;
65222 extern int soft_offline_page(struct page *page, int flags);
65223
65224 extern void dump_page(struct page *page);
65225 @@ -1683,5 +1691,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
65226 static inline bool page_is_guard(struct page *page) { return false; }
65227 #endif /* CONFIG_DEBUG_PAGEALLOC */
65228
65229 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
65230 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
65231 +#else
65232 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
65233 +#endif
65234 +
65235 #endif /* __KERNEL__ */
65236 #endif /* _LINUX_MM_H */
65237 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
65238 index 31f8a3a..499f1db 100644
65239 --- a/include/linux/mm_types.h
65240 +++ b/include/linux/mm_types.h
65241 @@ -275,6 +275,8 @@ struct vm_area_struct {
65242 #ifdef CONFIG_NUMA
65243 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
65244 #endif
65245 +
65246 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
65247 };
65248
65249 struct core_thread {
65250 @@ -348,7 +350,7 @@ struct mm_struct {
65251 unsigned long def_flags;
65252 unsigned long nr_ptes; /* Page table pages */
65253 unsigned long start_code, end_code, start_data, end_data;
65254 - unsigned long start_brk, brk, start_stack;
65255 + unsigned long brk_gap, start_brk, brk, start_stack;
65256 unsigned long arg_start, arg_end, env_start, env_end;
65257
65258 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
65259 @@ -399,6 +401,24 @@ struct mm_struct {
65260 struct cpumask cpumask_allocation;
65261 #endif
65262 struct uprobes_state uprobes_state;
65263 +
65264 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65265 + unsigned long pax_flags;
65266 +#endif
65267 +
65268 +#ifdef CONFIG_PAX_DLRESOLVE
65269 + unsigned long call_dl_resolve;
65270 +#endif
65271 +
65272 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
65273 + unsigned long call_syscall;
65274 +#endif
65275 +
65276 +#ifdef CONFIG_PAX_ASLR
65277 + unsigned long delta_mmap; /* randomized offset */
65278 + unsigned long delta_stack; /* randomized offset */
65279 +#endif
65280 +
65281 };
65282
65283 static inline void mm_init_cpumask(struct mm_struct *mm)
65284 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
65285 index c5d5278..f0b68c8 100644
65286 --- a/include/linux/mmiotrace.h
65287 +++ b/include/linux/mmiotrace.h
65288 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
65289 /* Called from ioremap.c */
65290 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
65291 void __iomem *addr);
65292 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
65293 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
65294
65295 /* For anyone to insert markers. Remember trailing newline. */
65296 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
65297 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
65298 {
65299 }
65300
65301 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
65302 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
65303 {
65304 }
65305
65306 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
65307 index a23923b..073fee4 100644
65308 --- a/include/linux/mmzone.h
65309 +++ b/include/linux/mmzone.h
65310 @@ -421,7 +421,7 @@ struct zone {
65311 unsigned long flags; /* zone flags, see below */
65312
65313 /* Zone statistics */
65314 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65315 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65316
65317 /*
65318 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
65319 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
65320 index fed3def..7cc3f93 100644
65321 --- a/include/linux/mod_devicetable.h
65322 +++ b/include/linux/mod_devicetable.h
65323 @@ -12,7 +12,7 @@
65324 typedef unsigned long kernel_ulong_t;
65325 #endif
65326
65327 -#define PCI_ANY_ID (~0)
65328 +#define PCI_ANY_ID ((__u16)~0)
65329
65330 struct pci_device_id {
65331 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
65332 @@ -139,7 +139,7 @@ struct usb_device_id {
65333 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
65334 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
65335
65336 -#define HID_ANY_ID (~0)
65337 +#define HID_ANY_ID (~0U)
65338 #define HID_BUS_ANY 0xffff
65339 #define HID_GROUP_ANY 0x0000
65340
65341 diff --git a/include/linux/module.h b/include/linux/module.h
65342 index 1375ee3..d631af0 100644
65343 --- a/include/linux/module.h
65344 +++ b/include/linux/module.h
65345 @@ -17,9 +17,11 @@
65346 #include <linux/moduleparam.h>
65347 #include <linux/tracepoint.h>
65348 #include <linux/export.h>
65349 +#include <linux/fs.h>
65350
65351 #include <linux/percpu.h>
65352 #include <asm/module.h>
65353 +#include <asm/pgtable.h>
65354
65355 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
65356 #define MODULE_SIG_STRING "~Module signature appended~\n"
65357 @@ -281,19 +283,16 @@ struct module
65358 int (*init)(void);
65359
65360 /* If this is non-NULL, vfree after init() returns */
65361 - void *module_init;
65362 + void *module_init_rx, *module_init_rw;
65363
65364 /* Here is the actual code + data, vfree'd on unload. */
65365 - void *module_core;
65366 + void *module_core_rx, *module_core_rw;
65367
65368 /* Here are the sizes of the init and core sections */
65369 - unsigned int init_size, core_size;
65370 + unsigned int init_size_rw, core_size_rw;
65371
65372 /* The size of the executable code in each section. */
65373 - unsigned int init_text_size, core_text_size;
65374 -
65375 - /* Size of RO sections of the module (text+rodata) */
65376 - unsigned int init_ro_size, core_ro_size;
65377 + unsigned int init_size_rx, core_size_rx;
65378
65379 /* Arch-specific module values */
65380 struct mod_arch_specific arch;
65381 @@ -349,6 +348,10 @@ struct module
65382 #ifdef CONFIG_EVENT_TRACING
65383 struct ftrace_event_call **trace_events;
65384 unsigned int num_trace_events;
65385 + struct file_operations trace_id;
65386 + struct file_operations trace_enable;
65387 + struct file_operations trace_format;
65388 + struct file_operations trace_filter;
65389 #endif
65390 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
65391 unsigned int num_ftrace_callsites;
65392 @@ -396,16 +399,46 @@ bool is_module_address(unsigned long addr);
65393 bool is_module_percpu_address(unsigned long addr);
65394 bool is_module_text_address(unsigned long addr);
65395
65396 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
65397 +{
65398 +
65399 +#ifdef CONFIG_PAX_KERNEXEC
65400 + if (ktla_ktva(addr) >= (unsigned long)start &&
65401 + ktla_ktva(addr) < (unsigned long)start + size)
65402 + return 1;
65403 +#endif
65404 +
65405 + return ((void *)addr >= start && (void *)addr < start + size);
65406 +}
65407 +
65408 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
65409 +{
65410 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
65411 +}
65412 +
65413 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
65414 +{
65415 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
65416 +}
65417 +
65418 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
65419 +{
65420 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
65421 +}
65422 +
65423 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
65424 +{
65425 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
65426 +}
65427 +
65428 static inline int within_module_core(unsigned long addr, struct module *mod)
65429 {
65430 - return (unsigned long)mod->module_core <= addr &&
65431 - addr < (unsigned long)mod->module_core + mod->core_size;
65432 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
65433 }
65434
65435 static inline int within_module_init(unsigned long addr, struct module *mod)
65436 {
65437 - return (unsigned long)mod->module_init <= addr &&
65438 - addr < (unsigned long)mod->module_init + mod->init_size;
65439 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
65440 }
65441
65442 /* Search for module by name: must hold module_mutex. */
65443 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
65444 index 560ca53..5ee8d73 100644
65445 --- a/include/linux/moduleloader.h
65446 +++ b/include/linux/moduleloader.h
65447 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
65448
65449 /* Allocator used for allocating struct module, core sections and init
65450 sections. Returns NULL on failure. */
65451 -void *module_alloc(unsigned long size);
65452 +void *module_alloc(unsigned long size) __size_overflow(1);
65453 +
65454 +#ifdef CONFIG_PAX_KERNEXEC
65455 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
65456 +#else
65457 +#define module_alloc_exec(x) module_alloc(x)
65458 +#endif
65459
65460 /* Free memory returned from module_alloc. */
65461 void module_free(struct module *mod, void *module_region);
65462
65463 +#ifdef CONFIG_PAX_KERNEXEC
65464 +void module_free_exec(struct module *mod, void *module_region);
65465 +#else
65466 +#define module_free_exec(x, y) module_free((x), (y))
65467 +#endif
65468 +
65469 /*
65470 * Apply the given relocation to the (simplified) ELF. Return -error
65471 * or 0.
65472 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
65473 unsigned int relsec,
65474 struct module *me)
65475 {
65476 +#ifdef CONFIG_MODULES
65477 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65478 +#endif
65479 return -ENOEXEC;
65480 }
65481 #endif
65482 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
65483 unsigned int relsec,
65484 struct module *me)
65485 {
65486 +#ifdef CONFIG_MODULES
65487 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65488 +#endif
65489 return -ENOEXEC;
65490 }
65491 #endif
65492 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
65493 index d6a5806..7c13347 100644
65494 --- a/include/linux/moduleparam.h
65495 +++ b/include/linux/moduleparam.h
65496 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
65497 * @len is usually just sizeof(string).
65498 */
65499 #define module_param_string(name, string, len, perm) \
65500 - static const struct kparam_string __param_string_##name \
65501 + static const struct kparam_string __param_string_##name __used \
65502 = { len, string }; \
65503 __module_param_call(MODULE_PARAM_PREFIX, name, \
65504 &param_ops_string, \
65505 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
65506 */
65507 #define module_param_array_named(name, array, type, nump, perm) \
65508 param_check_##type(name, &(array)[0]); \
65509 - static const struct kparam_array __param_arr_##name \
65510 + static const struct kparam_array __param_arr_##name __used \
65511 = { .max = ARRAY_SIZE(array), .num = nump, \
65512 .ops = &param_ops_##type, \
65513 .elemsize = sizeof(array[0]), .elem = array }; \
65514 diff --git a/include/linux/namei.h b/include/linux/namei.h
65515 index 4bf19d8..5268cea 100644
65516 --- a/include/linux/namei.h
65517 +++ b/include/linux/namei.h
65518 @@ -18,7 +18,7 @@ struct nameidata {
65519 unsigned seq;
65520 int last_type;
65521 unsigned depth;
65522 - char *saved_names[MAX_NESTED_LINKS + 1];
65523 + const char *saved_names[MAX_NESTED_LINKS + 1];
65524 };
65525
65526 /*
65527 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
65528
65529 extern void nd_jump_link(struct nameidata *nd, struct path *path);
65530
65531 -static inline void nd_set_link(struct nameidata *nd, char *path)
65532 +static inline void nd_set_link(struct nameidata *nd, const char *path)
65533 {
65534 nd->saved_names[nd->depth] = path;
65535 }
65536
65537 -static inline char *nd_get_link(struct nameidata *nd)
65538 +static inline const char *nd_get_link(const struct nameidata *nd)
65539 {
65540 return nd->saved_names[nd->depth];
65541 }
65542 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
65543 index a848ffc..3bbbaee 100644
65544 --- a/include/linux/netdevice.h
65545 +++ b/include/linux/netdevice.h
65546 @@ -999,6 +999,7 @@ struct net_device_ops {
65547 struct net_device *dev,
65548 int idx);
65549 };
65550 +typedef struct net_device_ops __no_const net_device_ops_no_const;
65551
65552 /*
65553 * The DEVICE structure.
65554 @@ -1059,7 +1060,7 @@ struct net_device {
65555 int iflink;
65556
65557 struct net_device_stats stats;
65558 - atomic_long_t rx_dropped; /* dropped packets by core network
65559 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
65560 * Do not use this in drivers.
65561 */
65562
65563 diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
65564 index 7958e84..ed74d7a 100644
65565 --- a/include/linux/netfilter/ipset/ip_set.h
65566 +++ b/include/linux/netfilter/ipset/ip_set.h
65567 @@ -98,7 +98,7 @@ struct ip_set_type_variant {
65568 /* Return true if "b" set is the same as "a"
65569 * according to the create set parameters */
65570 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
65571 -};
65572 +} __do_const;
65573
65574 /* The core set type structure */
65575 struct ip_set_type {
65576 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
65577 index 4966dde..7d8ce06 100644
65578 --- a/include/linux/netfilter/nfnetlink.h
65579 +++ b/include/linux/netfilter/nfnetlink.h
65580 @@ -16,7 +16,7 @@ struct nfnl_callback {
65581 const struct nlattr * const cda[]);
65582 const struct nla_policy *policy; /* netlink attribute policy */
65583 const u_int16_t attr_count; /* number of nlattr's */
65584 -};
65585 +} __do_const;
65586
65587 struct nfnetlink_subsystem {
65588 const char *name;
65589 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
65590 new file mode 100644
65591 index 0000000..33f4af8
65592 --- /dev/null
65593 +++ b/include/linux/netfilter/xt_gradm.h
65594 @@ -0,0 +1,9 @@
65595 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
65596 +#define _LINUX_NETFILTER_XT_GRADM_H 1
65597 +
65598 +struct xt_gradm_mtinfo {
65599 + __u16 flags;
65600 + __u16 invflags;
65601 +};
65602 +
65603 +#endif
65604 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
65605 index d65746e..62e72c2 100644
65606 --- a/include/linux/notifier.h
65607 +++ b/include/linux/notifier.h
65608 @@ -51,7 +51,8 @@ struct notifier_block {
65609 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
65610 struct notifier_block __rcu *next;
65611 int priority;
65612 -};
65613 +} __do_const;
65614 +typedef struct notifier_block __no_const notifier_block_no_const;
65615
65616 struct atomic_notifier_head {
65617 spinlock_t lock;
65618 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
65619 index a4c5624..79d6d88 100644
65620 --- a/include/linux/oprofile.h
65621 +++ b/include/linux/oprofile.h
65622 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
65623 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
65624 char const * name, ulong * val);
65625
65626 -/** Create a file for read-only access to an atomic_t. */
65627 +/** Create a file for read-only access to an atomic_unchecked_t. */
65628 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
65629 - char const * name, atomic_t * val);
65630 + char const * name, atomic_unchecked_t * val);
65631
65632 /** create a directory */
65633 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
65634 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
65635 index 6bfb2faa..1204767 100644
65636 --- a/include/linux/perf_event.h
65637 +++ b/include/linux/perf_event.h
65638 @@ -328,8 +328,8 @@ struct perf_event {
65639
65640 enum perf_event_active_state state;
65641 unsigned int attach_state;
65642 - local64_t count;
65643 - atomic64_t child_count;
65644 + local64_t count; /* PaX: fix it one day */
65645 + atomic64_unchecked_t child_count;
65646
65647 /*
65648 * These are the total time in nanoseconds that the event
65649 @@ -380,8 +380,8 @@ struct perf_event {
65650 * These accumulate total time (in nanoseconds) that children
65651 * events have been enabled and running, respectively.
65652 */
65653 - atomic64_t child_total_time_enabled;
65654 - atomic64_t child_total_time_running;
65655 + atomic64_unchecked_t child_total_time_enabled;
65656 + atomic64_unchecked_t child_total_time_running;
65657
65658 /*
65659 * Protect attach/detach and child_list:
65660 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
65661 index ad1a427..6419649 100644
65662 --- a/include/linux/pipe_fs_i.h
65663 +++ b/include/linux/pipe_fs_i.h
65664 @@ -45,9 +45,9 @@ struct pipe_buffer {
65665 struct pipe_inode_info {
65666 wait_queue_head_t wait;
65667 unsigned int nrbufs, curbuf, buffers;
65668 - unsigned int readers;
65669 - unsigned int writers;
65670 - unsigned int waiting_writers;
65671 + atomic_t readers;
65672 + atomic_t writers;
65673 + atomic_t waiting_writers;
65674 unsigned int r_counter;
65675 unsigned int w_counter;
65676 struct page *tmp_page;
65677 diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
65678 index 5f28cae..3d23723 100644
65679 --- a/include/linux/platform_data/usb-ehci-s5p.h
65680 +++ b/include/linux/platform_data/usb-ehci-s5p.h
65681 @@ -14,7 +14,7 @@
65682 struct s5p_ehci_platdata {
65683 int (*phy_init)(struct platform_device *pdev, int type);
65684 int (*phy_exit)(struct platform_device *pdev, int type);
65685 -};
65686 +} __no_const;
65687
65688 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
65689
65690 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
65691 index f271860..6b3bec5 100644
65692 --- a/include/linux/pm_runtime.h
65693 +++ b/include/linux/pm_runtime.h
65694 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
65695
65696 static inline void pm_runtime_mark_last_busy(struct device *dev)
65697 {
65698 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
65699 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
65700 }
65701
65702 #else /* !CONFIG_PM_RUNTIME */
65703 diff --git a/include/linux/poison.h b/include/linux/poison.h
65704 index 2110a81..13a11bb 100644
65705 --- a/include/linux/poison.h
65706 +++ b/include/linux/poison.h
65707 @@ -19,8 +19,8 @@
65708 * under normal circumstances, used to verify that nobody uses
65709 * non-initialized list entries.
65710 */
65711 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
65712 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
65713 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
65714 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
65715
65716 /********** include/linux/timer.h **********/
65717 /*
65718 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
65719 index 4a496eb..d9c5659 100644
65720 --- a/include/linux/power/smartreflex.h
65721 +++ b/include/linux/power/smartreflex.h
65722 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
65723 int (*notify)(struct omap_sr *sr, u32 status);
65724 u8 notify_flags;
65725 u8 class_type;
65726 -};
65727 +} __do_const;
65728
65729 /**
65730 * struct omap_sr_nvalue_table - Smartreflex n-target value info
65731 diff --git a/include/linux/printk.h b/include/linux/printk.h
65732 index 9afc01e..92c32e8 100644
65733 --- a/include/linux/printk.h
65734 +++ b/include/linux/printk.h
65735 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
65736 extern int printk_needs_cpu(int cpu);
65737 extern void printk_tick(void);
65738
65739 +extern int kptr_restrict;
65740 +
65741 #ifdef CONFIG_PRINTK
65742 asmlinkage __printf(5, 0)
65743 int vprintk_emit(int facility, int level,
65744 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
65745
65746 extern int printk_delay_msec;
65747 extern int dmesg_restrict;
65748 -extern int kptr_restrict;
65749
65750 void log_buf_kexec_setup(void);
65751 void __init setup_log_buf(int early);
65752 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
65753 index 3fd2e87..75db910 100644
65754 --- a/include/linux/proc_fs.h
65755 +++ b/include/linux/proc_fs.h
65756 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
65757 return proc_create_data(name, mode, parent, proc_fops, NULL);
65758 }
65759
65760 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
65761 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
65762 +{
65763 +#ifdef CONFIG_GRKERNSEC_PROC_USER
65764 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
65765 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65766 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
65767 +#else
65768 + return proc_create_data(name, mode, parent, proc_fops, NULL);
65769 +#endif
65770 +}
65771 +
65772 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
65773 umode_t mode, struct proc_dir_entry *base,
65774 read_proc_t *read_proc, void * data)
65775 diff --git a/include/linux/random.h b/include/linux/random.h
65776 index 6330ed4..419c6c3 100644
65777 --- a/include/linux/random.h
65778 +++ b/include/linux/random.h
65779 @@ -30,12 +30,17 @@ void srandom32(u32 seed);
65780
65781 u32 prandom32(struct rnd_state *);
65782
65783 +static inline unsigned long pax_get_random_long(void)
65784 +{
65785 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
65786 +}
65787 +
65788 /*
65789 * Handle minimum values for seeds
65790 */
65791 static inline u32 __seed(u32 x, u32 m)
65792 {
65793 - return (x < m) ? x + m : x;
65794 + return (x <= m) ? x + m + 1 : x;
65795 }
65796
65797 /**
65798 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
65799 index 23b3630..e1bc12b 100644
65800 --- a/include/linux/reboot.h
65801 +++ b/include/linux/reboot.h
65802 @@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
65803 * Architecture-specific implementations of sys_reboot commands.
65804 */
65805
65806 -extern void machine_restart(char *cmd);
65807 -extern void machine_halt(void);
65808 -extern void machine_power_off(void);
65809 +extern void machine_restart(char *cmd) __noreturn;
65810 +extern void machine_halt(void) __noreturn;
65811 +extern void machine_power_off(void) __noreturn;
65812
65813 extern void machine_shutdown(void);
65814 struct pt_regs;
65815 @@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
65816 */
65817
65818 extern void kernel_restart_prepare(char *cmd);
65819 -extern void kernel_restart(char *cmd);
65820 -extern void kernel_halt(void);
65821 -extern void kernel_power_off(void);
65822 +extern void kernel_restart(char *cmd) __noreturn;
65823 +extern void kernel_halt(void) __noreturn;
65824 +extern void kernel_power_off(void) __noreturn;
65825
65826 extern int C_A_D; /* for sysctl */
65827 void ctrl_alt_del(void);
65828 @@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
65829 * Emergency restart, callable from an interrupt handler.
65830 */
65831
65832 -extern void emergency_restart(void);
65833 +extern void emergency_restart(void) __noreturn;
65834 #include <asm/emergency-restart.h>
65835
65836 #endif /* _LINUX_REBOOT_H */
65837 diff --git a/include/linux/regset.h b/include/linux/regset.h
65838 index 8e0c9fe..fdb64bc 100644
65839 --- a/include/linux/regset.h
65840 +++ b/include/linux/regset.h
65841 @@ -161,7 +161,7 @@ struct user_regset {
65842 unsigned int align;
65843 unsigned int bias;
65844 unsigned int core_note_type;
65845 -};
65846 +} __do_const;
65847
65848 /**
65849 * struct user_regset_view - available regsets
65850 diff --git a/include/linux/relay.h b/include/linux/relay.h
65851 index 91cacc3..b55ff74 100644
65852 --- a/include/linux/relay.h
65853 +++ b/include/linux/relay.h
65854 @@ -160,7 +160,7 @@ struct rchan_callbacks
65855 * The callback should return 0 if successful, negative if not.
65856 */
65857 int (*remove_buf_file)(struct dentry *dentry);
65858 -};
65859 +} __no_const;
65860
65861 /*
65862 * CONFIG_RELAY kernel API, kernel/relay.c
65863 diff --git a/include/linux/rio.h b/include/linux/rio.h
65864 index a3e7842..d973ca6 100644
65865 --- a/include/linux/rio.h
65866 +++ b/include/linux/rio.h
65867 @@ -339,7 +339,7 @@ struct rio_ops {
65868 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
65869 u64 rstart, u32 size, u32 flags);
65870 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
65871 -};
65872 +} __no_const;
65873
65874 #define RIO_RESOURCE_MEM 0x00000100
65875 #define RIO_RESOURCE_DOORBELL 0x00000200
65876 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
65877 index bfe1f47..6a33ee3 100644
65878 --- a/include/linux/rmap.h
65879 +++ b/include/linux/rmap.h
65880 @@ -134,8 +134,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
65881 void anon_vma_init(void); /* create anon_vma_cachep */
65882 int anon_vma_prepare(struct vm_area_struct *);
65883 void unlink_anon_vmas(struct vm_area_struct *);
65884 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
65885 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
65886 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
65887 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
65888
65889 static inline void anon_vma_merge(struct vm_area_struct *vma,
65890 struct vm_area_struct *next)
65891 diff --git a/include/linux/sched.h b/include/linux/sched.h
65892 index 3e63925..1d69dff 100644
65893 --- a/include/linux/sched.h
65894 +++ b/include/linux/sched.h
65895 @@ -61,6 +61,7 @@ struct bio_list;
65896 struct fs_struct;
65897 struct perf_event_context;
65898 struct blk_plug;
65899 +struct linux_binprm;
65900
65901 /*
65902 * List of flags we want to share for kernel threads,
65903 @@ -344,10 +345,23 @@ struct user_namespace;
65904 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
65905
65906 extern int sysctl_max_map_count;
65907 +extern unsigned long sysctl_heap_stack_gap;
65908
65909 #include <linux/aio.h>
65910
65911 #ifdef CONFIG_MMU
65912 +
65913 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
65914 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
65915 +#else
65916 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
65917 +{
65918 + return 0;
65919 +}
65920 +#endif
65921 +
65922 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
65923 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
65924 extern void arch_pick_mmap_layout(struct mm_struct *mm);
65925 extern unsigned long
65926 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
65927 @@ -614,6 +628,17 @@ struct signal_struct {
65928 #ifdef CONFIG_TASKSTATS
65929 struct taskstats *stats;
65930 #endif
65931 +
65932 +#ifdef CONFIG_GRKERNSEC
65933 + u32 curr_ip;
65934 + u32 saved_ip;
65935 + u32 gr_saddr;
65936 + u32 gr_daddr;
65937 + u16 gr_sport;
65938 + u16 gr_dport;
65939 + u8 used_accept:1;
65940 +#endif
65941 +
65942 #ifdef CONFIG_AUDIT
65943 unsigned audit_tty;
65944 struct tty_audit_buf *tty_audit_buf;
65945 @@ -691,6 +716,11 @@ struct user_struct {
65946 struct key *session_keyring; /* UID's default session keyring */
65947 #endif
65948
65949 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65950 + unsigned int banned;
65951 + unsigned long ban_expires;
65952 +#endif
65953 +
65954 /* Hash table maintenance information */
65955 struct hlist_node uidhash_node;
65956 kuid_t uid;
65957 @@ -1312,8 +1342,8 @@ struct task_struct {
65958 struct list_head thread_group;
65959
65960 struct completion *vfork_done; /* for vfork() */
65961 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
65962 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
65963 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
65964 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
65965
65966 cputime_t utime, stime, utimescaled, stimescaled;
65967 cputime_t gtime;
65968 @@ -1329,11 +1359,6 @@ struct task_struct {
65969 struct task_cputime cputime_expires;
65970 struct list_head cpu_timers[3];
65971
65972 -/* process credentials */
65973 - const struct cred __rcu *real_cred; /* objective and real subjective task
65974 - * credentials (COW) */
65975 - const struct cred __rcu *cred; /* effective (overridable) subjective task
65976 - * credentials (COW) */
65977 char comm[TASK_COMM_LEN]; /* executable name excluding path
65978 - access with [gs]et_task_comm (which lock
65979 it with task_lock())
65980 @@ -1350,6 +1375,10 @@ struct task_struct {
65981 #endif
65982 /* CPU-specific state of this task */
65983 struct thread_struct thread;
65984 +/* thread_info moved to task_struct */
65985 +#ifdef CONFIG_X86
65986 + struct thread_info tinfo;
65987 +#endif
65988 /* filesystem information */
65989 struct fs_struct *fs;
65990 /* open file information */
65991 @@ -1423,6 +1452,10 @@ struct task_struct {
65992 gfp_t lockdep_reclaim_gfp;
65993 #endif
65994
65995 +/* process credentials */
65996 + const struct cred __rcu *real_cred; /* objective and real subjective task
65997 + * credentials (COW) */
65998 +
65999 /* journalling filesystem info */
66000 void *journal_info;
66001
66002 @@ -1461,6 +1494,10 @@ struct task_struct {
66003 /* cg_list protected by css_set_lock and tsk->alloc_lock */
66004 struct list_head cg_list;
66005 #endif
66006 +
66007 + const struct cred __rcu *cred; /* effective (overridable) subjective task
66008 + * credentials (COW) */
66009 +
66010 #ifdef CONFIG_FUTEX
66011 struct robust_list_head __user *robust_list;
66012 #ifdef CONFIG_COMPAT
66013 @@ -1548,8 +1585,75 @@ struct task_struct {
66014 #ifdef CONFIG_UPROBES
66015 struct uprobe_task *utask;
66016 #endif
66017 +
66018 +#ifdef CONFIG_GRKERNSEC
66019 + /* grsecurity */
66020 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66021 + u64 exec_id;
66022 +#endif
66023 +#ifdef CONFIG_GRKERNSEC_SETXID
66024 + const struct cred *delayed_cred;
66025 +#endif
66026 + struct dentry *gr_chroot_dentry;
66027 + struct acl_subject_label *acl;
66028 + struct acl_role_label *role;
66029 + struct file *exec_file;
66030 + unsigned long brute_expires;
66031 + u16 acl_role_id;
66032 + /* is this the task that authenticated to the special role */
66033 + u8 acl_sp_role;
66034 + u8 is_writable;
66035 + u8 brute;
66036 + u8 gr_is_chrooted;
66037 +#endif
66038 +
66039 };
66040
66041 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
66042 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
66043 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
66044 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
66045 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
66046 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
66047 +
66048 +#ifdef CONFIG_PAX_SOFTMODE
66049 +extern int pax_softmode;
66050 +#endif
66051 +
66052 +extern int pax_check_flags(unsigned long *);
66053 +
66054 +/* if tsk != current then task_lock must be held on it */
66055 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66056 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
66057 +{
66058 + if (likely(tsk->mm))
66059 + return tsk->mm->pax_flags;
66060 + else
66061 + return 0UL;
66062 +}
66063 +
66064 +/* if tsk != current then task_lock must be held on it */
66065 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
66066 +{
66067 + if (likely(tsk->mm)) {
66068 + tsk->mm->pax_flags = flags;
66069 + return 0;
66070 + }
66071 + return -EINVAL;
66072 +}
66073 +#endif
66074 +
66075 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
66076 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
66077 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
66078 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
66079 +#endif
66080 +
66081 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
66082 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
66083 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
66084 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
66085 +
66086 /* Future-safe accessor for struct task_struct's cpus_allowed. */
66087 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
66088
66089 @@ -2092,7 +2196,9 @@ void yield(void);
66090 extern struct exec_domain default_exec_domain;
66091
66092 union thread_union {
66093 +#ifndef CONFIG_X86
66094 struct thread_info thread_info;
66095 +#endif
66096 unsigned long stack[THREAD_SIZE/sizeof(long)];
66097 };
66098
66099 @@ -2125,6 +2231,7 @@ extern struct pid_namespace init_pid_ns;
66100 */
66101
66102 extern struct task_struct *find_task_by_vpid(pid_t nr);
66103 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
66104 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
66105 struct pid_namespace *ns);
66106
66107 @@ -2281,7 +2388,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
66108 extern void exit_itimers(struct signal_struct *);
66109 extern void flush_itimer_signals(void);
66110
66111 -extern void do_group_exit(int);
66112 +extern __noreturn void do_group_exit(int);
66113
66114 extern void daemonize(const char *, ...);
66115 extern int allow_signal(int);
66116 @@ -2485,9 +2592,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
66117
66118 #endif
66119
66120 -static inline int object_is_on_stack(void *obj)
66121 +static inline int object_starts_on_stack(void *obj)
66122 {
66123 - void *stack = task_stack_page(current);
66124 + const void *stack = task_stack_page(current);
66125
66126 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
66127 }
66128 diff --git a/include/linux/security.h b/include/linux/security.h
66129 index 05e88bd..5cda002 100644
66130 --- a/include/linux/security.h
66131 +++ b/include/linux/security.h
66132 @@ -26,6 +26,7 @@
66133 #include <linux/capability.h>
66134 #include <linux/slab.h>
66135 #include <linux/err.h>
66136 +#include <linux/grsecurity.h>
66137
66138 struct linux_binprm;
66139 struct cred;
66140 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
66141 index 68a04a3..866e6a1 100644
66142 --- a/include/linux/seq_file.h
66143 +++ b/include/linux/seq_file.h
66144 @@ -26,6 +26,9 @@ struct seq_file {
66145 struct mutex lock;
66146 const struct seq_operations *op;
66147 int poll_event;
66148 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66149 + u64 exec_id;
66150 +#endif
66151 #ifdef CONFIG_USER_NS
66152 struct user_namespace *user_ns;
66153 #endif
66154 @@ -38,6 +41,7 @@ struct seq_operations {
66155 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
66156 int (*show) (struct seq_file *m, void *v);
66157 };
66158 +typedef struct seq_operations __no_const seq_operations_no_const;
66159
66160 #define SEQ_SKIP 1
66161
66162 diff --git a/include/linux/shm.h b/include/linux/shm.h
66163 index bcf8a6a..4d0af77 100644
66164 --- a/include/linux/shm.h
66165 +++ b/include/linux/shm.h
66166 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
66167
66168 /* The task created the shm object. NULL if the task is dead. */
66169 struct task_struct *shm_creator;
66170 +#ifdef CONFIG_GRKERNSEC
66171 + time_t shm_createtime;
66172 + pid_t shm_lapid;
66173 +#endif
66174 };
66175
66176 /* shm_mode upper byte flags */
66177 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
66178 index 6a2c34e..a1f320f 100644
66179 --- a/include/linux/skbuff.h
66180 +++ b/include/linux/skbuff.h
66181 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
66182 extern struct sk_buff *__alloc_skb(unsigned int size,
66183 gfp_t priority, int flags, int node);
66184 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
66185 -static inline struct sk_buff *alloc_skb(unsigned int size,
66186 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
66187 gfp_t priority)
66188 {
66189 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
66190 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
66191 */
66192 static inline int skb_queue_empty(const struct sk_buff_head *list)
66193 {
66194 - return list->next == (struct sk_buff *)list;
66195 + return list->next == (const struct sk_buff *)list;
66196 }
66197
66198 /**
66199 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
66200 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
66201 const struct sk_buff *skb)
66202 {
66203 - return skb->next == (struct sk_buff *)list;
66204 + return skb->next == (const struct sk_buff *)list;
66205 }
66206
66207 /**
66208 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
66209 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
66210 const struct sk_buff *skb)
66211 {
66212 - return skb->prev == (struct sk_buff *)list;
66213 + return skb->prev == (const struct sk_buff *)list;
66214 }
66215
66216 /**
66217 @@ -1626,7 +1626,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
66218 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
66219 */
66220 #ifndef NET_SKB_PAD
66221 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
66222 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
66223 #endif
66224
66225 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
66226 @@ -2204,7 +2204,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
66227 int noblock, int *err);
66228 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
66229 struct poll_table_struct *wait);
66230 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
66231 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
66232 int offset, struct iovec *to,
66233 int size);
66234 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
66235 diff --git a/include/linux/slab.h b/include/linux/slab.h
66236 index 83d1a14..e23d723 100644
66237 --- a/include/linux/slab.h
66238 +++ b/include/linux/slab.h
66239 @@ -11,12 +11,20 @@
66240
66241 #include <linux/gfp.h>
66242 #include <linux/types.h>
66243 +#include <linux/err.h>
66244
66245 /*
66246 * Flags to pass to kmem_cache_create().
66247 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
66248 */
66249 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
66250 +
66251 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66252 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
66253 +#else
66254 +#define SLAB_USERCOPY 0x00000000UL
66255 +#endif
66256 +
66257 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
66258 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
66259 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
66260 @@ -87,10 +95,13 @@
66261 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
66262 * Both make kfree a no-op.
66263 */
66264 -#define ZERO_SIZE_PTR ((void *)16)
66265 +#define ZERO_SIZE_PTR \
66266 +({ \
66267 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
66268 + (void *)(-MAX_ERRNO-1L); \
66269 +})
66270
66271 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
66272 - (unsigned long)ZERO_SIZE_PTR)
66273 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
66274
66275 /*
66276 * Common fields provided in kmem_cache by all slab allocators
66277 @@ -110,7 +121,7 @@ struct kmem_cache {
66278 unsigned int align; /* Alignment as calculated */
66279 unsigned long flags; /* Active flags on the slab */
66280 const char *name; /* Slab name for sysfs */
66281 - int refcount; /* Use counter */
66282 + atomic_t refcount; /* Use counter */
66283 void (*ctor)(void *); /* Called on object slot creation */
66284 struct list_head list; /* List of all slab caches on the system */
66285 };
66286 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
66287 void kfree(const void *);
66288 void kzfree(const void *);
66289 size_t ksize(const void *);
66290 +const char *check_heap_object(const void *ptr, unsigned long n);
66291 +bool is_usercopy_object(const void *ptr);
66292
66293 /*
66294 * Allocator specific definitions. These are mainly used to establish optimized
66295 @@ -264,8 +277,18 @@ size_t ksize(const void *);
66296 * for general use, and so are not documented here. For a full list of
66297 * potential flags, always refer to linux/gfp.h.
66298 */
66299 +
66300 +extern void kmalloc_array_error(void)
66301 +#if defined(CONFIG_GCOV_KERNEL) && defined(CONFIG_PAX_SIZE_OVERFLOW)
66302 +__compiletime_warning("kmalloc_array called with swapped arguments?");
66303 +#else
66304 +__compiletime_error("kmalloc_array called with swapped arguments?");
66305 +#endif
66306 +
66307 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
66308 {
66309 + if (__builtin_constant_p(n) && !__builtin_constant_p(size))
66310 + kmalloc_array_error();
66311 if (size != 0 && n > SIZE_MAX / size)
66312 return NULL;
66313 return __kmalloc(n * size, flags);
66314 @@ -323,7 +346,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
66315 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66316 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66317 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66318 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66319 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
66320 #define kmalloc_track_caller(size, flags) \
66321 __kmalloc_track_caller(size, flags, _RET_IP_)
66322 #else
66323 @@ -343,7 +366,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66324 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66325 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66326 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66327 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
66328 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
66329 #define kmalloc_node_track_caller(size, flags, node) \
66330 __kmalloc_node_track_caller(size, flags, node, \
66331 _RET_IP_)
66332 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
66333 index cc290f0..0ba60931 100644
66334 --- a/include/linux/slab_def.h
66335 +++ b/include/linux/slab_def.h
66336 @@ -52,7 +52,7 @@ struct kmem_cache {
66337 /* 4) cache creation/removal */
66338 const char *name;
66339 struct list_head list;
66340 - int refcount;
66341 + atomic_t refcount;
66342 int object_size;
66343 int align;
66344
66345 @@ -68,10 +68,10 @@ struct kmem_cache {
66346 unsigned long node_allocs;
66347 unsigned long node_frees;
66348 unsigned long node_overflow;
66349 - atomic_t allochit;
66350 - atomic_t allocmiss;
66351 - atomic_t freehit;
66352 - atomic_t freemiss;
66353 + atomic_unchecked_t allochit;
66354 + atomic_unchecked_t allocmiss;
66355 + atomic_unchecked_t freehit;
66356 + atomic_unchecked_t freemiss;
66357
66358 /*
66359 * If debugging is enabled, then the allocator can add additional
66360 @@ -104,11 +104,16 @@ struct cache_sizes {
66361 #ifdef CONFIG_ZONE_DMA
66362 struct kmem_cache *cs_dmacachep;
66363 #endif
66364 +
66365 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66366 + struct kmem_cache *cs_usercopycachep;
66367 +#endif
66368 +
66369 };
66370 extern struct cache_sizes malloc_sizes[];
66371
66372 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66373 -void *__kmalloc(size_t size, gfp_t flags);
66374 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
66375
66376 #ifdef CONFIG_TRACING
66377 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
66378 @@ -145,6 +150,13 @@ found:
66379 cachep = malloc_sizes[i].cs_dmacachep;
66380 else
66381 #endif
66382 +
66383 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66384 + if (flags & GFP_USERCOPY)
66385 + cachep = malloc_sizes[i].cs_usercopycachep;
66386 + else
66387 +#endif
66388 +
66389 cachep = malloc_sizes[i].cs_cachep;
66390
66391 ret = kmem_cache_alloc_trace(cachep, flags, size);
66392 @@ -155,7 +167,7 @@ found:
66393 }
66394
66395 #ifdef CONFIG_NUMA
66396 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
66397 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66398 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66399
66400 #ifdef CONFIG_TRACING
66401 @@ -198,6 +210,13 @@ found:
66402 cachep = malloc_sizes[i].cs_dmacachep;
66403 else
66404 #endif
66405 +
66406 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66407 + if (flags & GFP_USERCOPY)
66408 + cachep = malloc_sizes[i].cs_usercopycachep;
66409 + else
66410 +#endif
66411 +
66412 cachep = malloc_sizes[i].cs_cachep;
66413
66414 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
66415 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
66416 index f28e14a..7831211 100644
66417 --- a/include/linux/slob_def.h
66418 +++ b/include/linux/slob_def.h
66419 @@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
66420 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
66421 }
66422
66423 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
66424 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66425
66426 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
66427 {
66428 @@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66429 return __kmalloc_node(size, flags, NUMA_NO_NODE);
66430 }
66431
66432 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
66433 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
66434 {
66435 return kmalloc(size, flags);
66436 }
66437 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
66438 index df448ad..b99e7f6 100644
66439 --- a/include/linux/slub_def.h
66440 +++ b/include/linux/slub_def.h
66441 @@ -91,7 +91,7 @@ struct kmem_cache {
66442 struct kmem_cache_order_objects max;
66443 struct kmem_cache_order_objects min;
66444 gfp_t allocflags; /* gfp flags to use on each alloc */
66445 - int refcount; /* Refcount for slab cache destroy */
66446 + atomic_t refcount; /* Refcount for slab cache destroy */
66447 void (*ctor)(void *);
66448 int inuse; /* Offset to metadata */
66449 int align; /* Alignment */
66450 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
66451 * Sorry that the following has to be that ugly but some versions of GCC
66452 * have trouble with constant propagation and loops.
66453 */
66454 -static __always_inline int kmalloc_index(size_t size)
66455 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
66456 {
66457 if (!size)
66458 return 0;
66459 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
66460 }
66461
66462 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66463 -void *__kmalloc(size_t size, gfp_t flags);
66464 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
66465
66466 static __always_inline void *
66467 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
66468 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
66469 }
66470 #endif
66471
66472 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
66473 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
66474 {
66475 unsigned int order = get_order(size);
66476 return kmalloc_order_trace(size, flags, order);
66477 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66478 }
66479
66480 #ifdef CONFIG_NUMA
66481 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
66482 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66483 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66484
66485 #ifdef CONFIG_TRACING
66486 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
66487 index 680f9a3..f13aeb0 100644
66488 --- a/include/linux/sonet.h
66489 +++ b/include/linux/sonet.h
66490 @@ -7,7 +7,7 @@
66491 #include <uapi/linux/sonet.h>
66492
66493 struct k_sonet_stats {
66494 -#define __HANDLE_ITEM(i) atomic_t i
66495 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
66496 __SONET_ITEMS
66497 #undef __HANDLE_ITEM
66498 };
66499 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
66500 index 34206b8..f019e06 100644
66501 --- a/include/linux/sunrpc/clnt.h
66502 +++ b/include/linux/sunrpc/clnt.h
66503 @@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
66504 {
66505 switch (sap->sa_family) {
66506 case AF_INET:
66507 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
66508 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
66509 case AF_INET6:
66510 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
66511 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
66512 }
66513 return 0;
66514 }
66515 @@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
66516 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
66517 const struct sockaddr *src)
66518 {
66519 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
66520 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
66521 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
66522
66523 dsin->sin_family = ssin->sin_family;
66524 @@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
66525 if (sa->sa_family != AF_INET6)
66526 return 0;
66527
66528 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
66529 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
66530 }
66531
66532 #endif /* __KERNEL__ */
66533 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
66534 index 0b8e3e6..33e0a01 100644
66535 --- a/include/linux/sunrpc/svc_rdma.h
66536 +++ b/include/linux/sunrpc/svc_rdma.h
66537 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
66538 extern unsigned int svcrdma_max_requests;
66539 extern unsigned int svcrdma_max_req_size;
66540
66541 -extern atomic_t rdma_stat_recv;
66542 -extern atomic_t rdma_stat_read;
66543 -extern atomic_t rdma_stat_write;
66544 -extern atomic_t rdma_stat_sq_starve;
66545 -extern atomic_t rdma_stat_rq_starve;
66546 -extern atomic_t rdma_stat_rq_poll;
66547 -extern atomic_t rdma_stat_rq_prod;
66548 -extern atomic_t rdma_stat_sq_poll;
66549 -extern atomic_t rdma_stat_sq_prod;
66550 +extern atomic_unchecked_t rdma_stat_recv;
66551 +extern atomic_unchecked_t rdma_stat_read;
66552 +extern atomic_unchecked_t rdma_stat_write;
66553 +extern atomic_unchecked_t rdma_stat_sq_starve;
66554 +extern atomic_unchecked_t rdma_stat_rq_starve;
66555 +extern atomic_unchecked_t rdma_stat_rq_poll;
66556 +extern atomic_unchecked_t rdma_stat_rq_prod;
66557 +extern atomic_unchecked_t rdma_stat_sq_poll;
66558 +extern atomic_unchecked_t rdma_stat_sq_prod;
66559
66560 #define RPCRDMA_VERSION 1
66561
66562 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
66563 index cd844a6..3ca3592 100644
66564 --- a/include/linux/sysctl.h
66565 +++ b/include/linux/sysctl.h
66566 @@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
66567
66568 extern int proc_dostring(struct ctl_table *, int,
66569 void __user *, size_t *, loff_t *);
66570 +extern int proc_dostring_modpriv(struct ctl_table *, int,
66571 + void __user *, size_t *, loff_t *);
66572 extern int proc_dointvec(struct ctl_table *, int,
66573 void __user *, size_t *, loff_t *);
66574 extern int proc_dointvec_minmax(struct ctl_table *, int,
66575 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
66576 index 7faf933..eb6f5e3 100644
66577 --- a/include/linux/sysrq.h
66578 +++ b/include/linux/sysrq.h
66579 @@ -36,7 +36,7 @@ struct sysrq_key_op {
66580 char *help_msg;
66581 char *action_msg;
66582 int enable_mask;
66583 -};
66584 +} __do_const;
66585
66586 #ifdef CONFIG_MAGIC_SYSRQ
66587
66588 diff --git a/include/linux/tty.h b/include/linux/tty.h
66589 index f0b4eb4..1c4854e 100644
66590 --- a/include/linux/tty.h
66591 +++ b/include/linux/tty.h
66592 @@ -192,7 +192,7 @@ struct tty_port {
66593 const struct tty_port_operations *ops; /* Port operations */
66594 spinlock_t lock; /* Lock protecting tty field */
66595 int blocked_open; /* Waiting to open */
66596 - int count; /* Usage count */
66597 + atomic_t count; /* Usage count */
66598 wait_queue_head_t open_wait; /* Open waiters */
66599 wait_queue_head_t close_wait; /* Close waiters */
66600 wait_queue_head_t delta_msr_wait; /* Modem status change */
66601 @@ -513,7 +513,7 @@ extern int tty_port_open(struct tty_port *port,
66602 struct tty_struct *tty, struct file *filp);
66603 static inline int tty_port_users(struct tty_port *port)
66604 {
66605 - return port->count + port->blocked_open;
66606 + return atomic_read(&port->count) + port->blocked_open;
66607 }
66608
66609 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
66610 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
66611 index dd976cf..e272742 100644
66612 --- a/include/linux/tty_driver.h
66613 +++ b/include/linux/tty_driver.h
66614 @@ -284,7 +284,7 @@ struct tty_operations {
66615 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
66616 #endif
66617 const struct file_operations *proc_fops;
66618 -};
66619 +} __do_const;
66620
66621 struct tty_driver {
66622 int magic; /* magic number for this structure */
66623 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
66624 index fb79dd8d..07d4773 100644
66625 --- a/include/linux/tty_ldisc.h
66626 +++ b/include/linux/tty_ldisc.h
66627 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
66628
66629 struct module *owner;
66630
66631 - int refcount;
66632 + atomic_t refcount;
66633 };
66634
66635 struct tty_ldisc {
66636 diff --git a/include/linux/types.h b/include/linux/types.h
66637 index 1cc0e4b..0d50edf 100644
66638 --- a/include/linux/types.h
66639 +++ b/include/linux/types.h
66640 @@ -175,10 +175,26 @@ typedef struct {
66641 int counter;
66642 } atomic_t;
66643
66644 +#ifdef CONFIG_PAX_REFCOUNT
66645 +typedef struct {
66646 + int counter;
66647 +} atomic_unchecked_t;
66648 +#else
66649 +typedef atomic_t atomic_unchecked_t;
66650 +#endif
66651 +
66652 #ifdef CONFIG_64BIT
66653 typedef struct {
66654 long counter;
66655 } atomic64_t;
66656 +
66657 +#ifdef CONFIG_PAX_REFCOUNT
66658 +typedef struct {
66659 + long counter;
66660 +} atomic64_unchecked_t;
66661 +#else
66662 +typedef atomic64_t atomic64_unchecked_t;
66663 +#endif
66664 #endif
66665
66666 struct list_head {
66667 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
66668 index 5ca0951..ab496a5 100644
66669 --- a/include/linux/uaccess.h
66670 +++ b/include/linux/uaccess.h
66671 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
66672 long ret; \
66673 mm_segment_t old_fs = get_fs(); \
66674 \
66675 - set_fs(KERNEL_DS); \
66676 pagefault_disable(); \
66677 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
66678 - pagefault_enable(); \
66679 + set_fs(KERNEL_DS); \
66680 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
66681 set_fs(old_fs); \
66682 + pagefault_enable(); \
66683 ret; \
66684 })
66685
66686 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
66687 index 99c1b4d..bb94261 100644
66688 --- a/include/linux/unaligned/access_ok.h
66689 +++ b/include/linux/unaligned/access_ok.h
66690 @@ -6,32 +6,32 @@
66691
66692 static inline u16 get_unaligned_le16(const void *p)
66693 {
66694 - return le16_to_cpup((__le16 *)p);
66695 + return le16_to_cpup((const __le16 *)p);
66696 }
66697
66698 static inline u32 get_unaligned_le32(const void *p)
66699 {
66700 - return le32_to_cpup((__le32 *)p);
66701 + return le32_to_cpup((const __le32 *)p);
66702 }
66703
66704 static inline u64 get_unaligned_le64(const void *p)
66705 {
66706 - return le64_to_cpup((__le64 *)p);
66707 + return le64_to_cpup((const __le64 *)p);
66708 }
66709
66710 static inline u16 get_unaligned_be16(const void *p)
66711 {
66712 - return be16_to_cpup((__be16 *)p);
66713 + return be16_to_cpup((const __be16 *)p);
66714 }
66715
66716 static inline u32 get_unaligned_be32(const void *p)
66717 {
66718 - return be32_to_cpup((__be32 *)p);
66719 + return be32_to_cpup((const __be32 *)p);
66720 }
66721
66722 static inline u64 get_unaligned_be64(const void *p)
66723 {
66724 - return be64_to_cpup((__be64 *)p);
66725 + return be64_to_cpup((const __be64 *)p);
66726 }
66727
66728 static inline void put_unaligned_le16(u16 val, void *p)
66729 diff --git a/include/linux/usb.h b/include/linux/usb.h
66730 index 10278d1..e21ec3c 100644
66731 --- a/include/linux/usb.h
66732 +++ b/include/linux/usb.h
66733 @@ -551,7 +551,7 @@ struct usb_device {
66734 int maxchild;
66735
66736 u32 quirks;
66737 - atomic_t urbnum;
66738 + atomic_unchecked_t urbnum;
66739
66740 unsigned long active_duration;
66741
66742 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
66743 index c5d36c6..108f4f9 100644
66744 --- a/include/linux/usb/renesas_usbhs.h
66745 +++ b/include/linux/usb/renesas_usbhs.h
66746 @@ -39,7 +39,7 @@ enum {
66747 */
66748 struct renesas_usbhs_driver_callback {
66749 int (*notify_hotplug)(struct platform_device *pdev);
66750 -};
66751 +} __no_const;
66752
66753 /*
66754 * callback functions for platform
66755 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
66756 index 6f8fbcf..8259001 100644
66757 --- a/include/linux/vermagic.h
66758 +++ b/include/linux/vermagic.h
66759 @@ -25,9 +25,35 @@
66760 #define MODULE_ARCH_VERMAGIC ""
66761 #endif
66762
66763 +#ifdef CONFIG_PAX_REFCOUNT
66764 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
66765 +#else
66766 +#define MODULE_PAX_REFCOUNT ""
66767 +#endif
66768 +
66769 +#ifdef CONSTIFY_PLUGIN
66770 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
66771 +#else
66772 +#define MODULE_CONSTIFY_PLUGIN ""
66773 +#endif
66774 +
66775 +#ifdef STACKLEAK_PLUGIN
66776 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
66777 +#else
66778 +#define MODULE_STACKLEAK_PLUGIN ""
66779 +#endif
66780 +
66781 +#ifdef CONFIG_GRKERNSEC
66782 +#define MODULE_GRSEC "GRSEC "
66783 +#else
66784 +#define MODULE_GRSEC ""
66785 +#endif
66786 +
66787 #define VERMAGIC_STRING \
66788 UTS_RELEASE " " \
66789 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
66790 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
66791 - MODULE_ARCH_VERMAGIC
66792 + MODULE_ARCH_VERMAGIC \
66793 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
66794 + MODULE_GRSEC
66795
66796 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
66797 index 6071e91..ca6a489 100644
66798 --- a/include/linux/vmalloc.h
66799 +++ b/include/linux/vmalloc.h
66800 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
66801 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
66802 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
66803 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
66804 +
66805 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
66806 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
66807 +#endif
66808 +
66809 /* bits [20..32] reserved for arch specific ioremap internals */
66810
66811 /*
66812 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
66813 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
66814 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
66815 unsigned long start, unsigned long end, gfp_t gfp_mask,
66816 - pgprot_t prot, int node, const void *caller);
66817 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
66818 extern void vfree(const void *addr);
66819
66820 extern void *vmap(struct page **pages, unsigned int count,
66821 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
66822 extern void free_vm_area(struct vm_struct *area);
66823
66824 /* for /dev/kmem */
66825 -extern long vread(char *buf, char *addr, unsigned long count);
66826 -extern long vwrite(char *buf, char *addr, unsigned long count);
66827 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
66828 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
66829
66830 /*
66831 * Internals. Dont't use..
66832 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
66833 index 92a86b2..1d9eb3c 100644
66834 --- a/include/linux/vmstat.h
66835 +++ b/include/linux/vmstat.h
66836 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
66837 /*
66838 * Zone based page accounting with per cpu differentials.
66839 */
66840 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66841 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66842
66843 static inline void zone_page_state_add(long x, struct zone *zone,
66844 enum zone_stat_item item)
66845 {
66846 - atomic_long_add(x, &zone->vm_stat[item]);
66847 - atomic_long_add(x, &vm_stat[item]);
66848 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
66849 + atomic_long_add_unchecked(x, &vm_stat[item]);
66850 }
66851
66852 static inline unsigned long global_page_state(enum zone_stat_item item)
66853 {
66854 - long x = atomic_long_read(&vm_stat[item]);
66855 + long x = atomic_long_read_unchecked(&vm_stat[item]);
66856 #ifdef CONFIG_SMP
66857 if (x < 0)
66858 x = 0;
66859 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
66860 static inline unsigned long zone_page_state(struct zone *zone,
66861 enum zone_stat_item item)
66862 {
66863 - long x = atomic_long_read(&zone->vm_stat[item]);
66864 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
66865 #ifdef CONFIG_SMP
66866 if (x < 0)
66867 x = 0;
66868 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
66869 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
66870 enum zone_stat_item item)
66871 {
66872 - long x = atomic_long_read(&zone->vm_stat[item]);
66873 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
66874
66875 #ifdef CONFIG_SMP
66876 int cpu;
66877 @@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
66878
66879 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
66880 {
66881 - atomic_long_inc(&zone->vm_stat[item]);
66882 - atomic_long_inc(&vm_stat[item]);
66883 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
66884 + atomic_long_inc_unchecked(&vm_stat[item]);
66885 }
66886
66887 static inline void __inc_zone_page_state(struct page *page,
66888 @@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
66889
66890 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
66891 {
66892 - atomic_long_dec(&zone->vm_stat[item]);
66893 - atomic_long_dec(&vm_stat[item]);
66894 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
66895 + atomic_long_dec_unchecked(&vm_stat[item]);
66896 }
66897
66898 static inline void __dec_zone_page_state(struct page *page,
66899 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
66900 index 95d1c91..6798cca 100644
66901 --- a/include/media/v4l2-dev.h
66902 +++ b/include/media/v4l2-dev.h
66903 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
66904 int (*mmap) (struct file *, struct vm_area_struct *);
66905 int (*open) (struct file *);
66906 int (*release) (struct file *);
66907 -};
66908 +} __do_const;
66909
66910 /*
66911 * Newer version of video_device, handled by videodev2.c
66912 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
66913 index e48b571..7e40de4 100644
66914 --- a/include/media/v4l2-ioctl.h
66915 +++ b/include/media/v4l2-ioctl.h
66916 @@ -282,7 +282,6 @@ struct v4l2_ioctl_ops {
66917 bool valid_prio, int cmd, void *arg);
66918 };
66919
66920 -
66921 /* v4l debugging and diagnostics */
66922
66923 /* Debug bitmask flags to be used on V4L2 */
66924 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
66925 index 9e5425b..8136ffc 100644
66926 --- a/include/net/caif/cfctrl.h
66927 +++ b/include/net/caif/cfctrl.h
66928 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
66929 void (*radioset_rsp)(void);
66930 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
66931 struct cflayer *client_layer);
66932 -};
66933 +} __no_const;
66934
66935 /* Link Setup Parameters for CAIF-Links. */
66936 struct cfctrl_link_param {
66937 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
66938 struct cfctrl {
66939 struct cfsrvl serv;
66940 struct cfctrl_rsp res;
66941 - atomic_t req_seq_no;
66942 - atomic_t rsp_seq_no;
66943 + atomic_unchecked_t req_seq_no;
66944 + atomic_unchecked_t rsp_seq_no;
66945 struct list_head list;
66946 /* Protects from simultaneous access to first_req list */
66947 spinlock_t info_list_lock;
66948 diff --git a/include/net/flow.h b/include/net/flow.h
66949 index 628e11b..4c475df 100644
66950 --- a/include/net/flow.h
66951 +++ b/include/net/flow.h
66952 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
66953
66954 extern void flow_cache_flush(void);
66955 extern void flow_cache_flush_deferred(void);
66956 -extern atomic_t flow_cache_genid;
66957 +extern atomic_unchecked_t flow_cache_genid;
66958
66959 #endif
66960 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
66961 index e5062c9..48a9a4b 100644
66962 --- a/include/net/gro_cells.h
66963 +++ b/include/net/gro_cells.h
66964 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
66965 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
66966
66967 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
66968 - atomic_long_inc(&dev->rx_dropped);
66969 + atomic_long_inc_unchecked(&dev->rx_dropped);
66970 kfree_skb(skb);
66971 return;
66972 }
66973 @@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
66974 int i;
66975
66976 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
66977 - gcells->cells = kcalloc(sizeof(struct gro_cell),
66978 - gcells->gro_cells_mask + 1,
66979 + gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
66980 + sizeof(struct gro_cell),
66981 GFP_KERNEL);
66982 if (!gcells->cells)
66983 return -ENOMEM;
66984 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
66985 index 1832927..ce39aea 100644
66986 --- a/include/net/inet_connection_sock.h
66987 +++ b/include/net/inet_connection_sock.h
66988 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
66989 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
66990 int (*bind_conflict)(const struct sock *sk,
66991 const struct inet_bind_bucket *tb, bool relax);
66992 -};
66993 +} __do_const;
66994
66995 /** inet_connection_sock - INET connection oriented sock
66996 *
66997 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
66998 index 53f464d..ba76aaa 100644
66999 --- a/include/net/inetpeer.h
67000 +++ b/include/net/inetpeer.h
67001 @@ -47,8 +47,8 @@ struct inet_peer {
67002 */
67003 union {
67004 struct {
67005 - atomic_t rid; /* Frag reception counter */
67006 - atomic_t ip_id_count; /* IP ID for the next packet */
67007 + atomic_unchecked_t rid; /* Frag reception counter */
67008 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
67009 };
67010 struct rcu_head rcu;
67011 struct inet_peer *gc_next;
67012 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
67013 more++;
67014 inet_peer_refcheck(p);
67015 do {
67016 - old = atomic_read(&p->ip_id_count);
67017 + old = atomic_read_unchecked(&p->ip_id_count);
67018 new = old + more;
67019 if (!new)
67020 new = 1;
67021 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
67022 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
67023 return new;
67024 }
67025
67026 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
67027 index 9497be1..5a4fafe 100644
67028 --- a/include/net/ip_fib.h
67029 +++ b/include/net/ip_fib.h
67030 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
67031
67032 #define FIB_RES_SADDR(net, res) \
67033 ((FIB_RES_NH(res).nh_saddr_genid == \
67034 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
67035 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
67036 FIB_RES_NH(res).nh_saddr : \
67037 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
67038 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
67039 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
67040 index ee75ccd..2cc2b95 100644
67041 --- a/include/net/ip_vs.h
67042 +++ b/include/net/ip_vs.h
67043 @@ -510,7 +510,7 @@ struct ip_vs_conn {
67044 struct ip_vs_conn *control; /* Master control connection */
67045 atomic_t n_control; /* Number of controlled ones */
67046 struct ip_vs_dest *dest; /* real server */
67047 - atomic_t in_pkts; /* incoming packet counter */
67048 + atomic_unchecked_t in_pkts; /* incoming packet counter */
67049
67050 /* packet transmitter for different forwarding methods. If it
67051 mangles the packet, it must return NF_DROP or better NF_STOLEN,
67052 @@ -648,7 +648,7 @@ struct ip_vs_dest {
67053 __be16 port; /* port number of the server */
67054 union nf_inet_addr addr; /* IP address of the server */
67055 volatile unsigned int flags; /* dest status flags */
67056 - atomic_t conn_flags; /* flags to copy to conn */
67057 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
67058 atomic_t weight; /* server weight */
67059
67060 atomic_t refcnt; /* reference counter */
67061 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
67062 index 80ffde3..968b0f4 100644
67063 --- a/include/net/irda/ircomm_tty.h
67064 +++ b/include/net/irda/ircomm_tty.h
67065 @@ -35,6 +35,7 @@
67066 #include <linux/termios.h>
67067 #include <linux/timer.h>
67068 #include <linux/tty.h> /* struct tty_struct */
67069 +#include <asm/local.h>
67070
67071 #include <net/irda/irias_object.h>
67072 #include <net/irda/ircomm_core.h>
67073 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
67074 index cc7c197..9f2da2a 100644
67075 --- a/include/net/iucv/af_iucv.h
67076 +++ b/include/net/iucv/af_iucv.h
67077 @@ -141,7 +141,7 @@ struct iucv_sock {
67078 struct iucv_sock_list {
67079 struct hlist_head head;
67080 rwlock_t lock;
67081 - atomic_t autobind_name;
67082 + atomic_unchecked_t autobind_name;
67083 };
67084
67085 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
67086 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
67087 index 0dab173..1b76af0 100644
67088 --- a/include/net/neighbour.h
67089 +++ b/include/net/neighbour.h
67090 @@ -123,7 +123,7 @@ struct neigh_ops {
67091 void (*error_report)(struct neighbour *, struct sk_buff *);
67092 int (*output)(struct neighbour *, struct sk_buff *);
67093 int (*connected_output)(struct neighbour *, struct sk_buff *);
67094 -};
67095 +} __do_const;
67096
67097 struct pneigh_entry {
67098 struct pneigh_entry *next;
67099 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
67100 index 95e6466..251016d 100644
67101 --- a/include/net/net_namespace.h
67102 +++ b/include/net/net_namespace.h
67103 @@ -110,7 +110,7 @@ struct net {
67104 #endif
67105 struct netns_ipvs *ipvs;
67106 struct sock *diag_nlsk;
67107 - atomic_t rt_genid;
67108 + atomic_unchecked_t rt_genid;
67109 };
67110
67111 /*
67112 @@ -320,12 +320,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
67113
67114 static inline int rt_genid(struct net *net)
67115 {
67116 - return atomic_read(&net->rt_genid);
67117 + return atomic_read_unchecked(&net->rt_genid);
67118 }
67119
67120 static inline void rt_genid_bump(struct net *net)
67121 {
67122 - atomic_inc(&net->rt_genid);
67123 + atomic_inc_unchecked(&net->rt_genid);
67124 }
67125
67126 #endif /* __NET_NET_NAMESPACE_H */
67127 diff --git a/include/net/netdma.h b/include/net/netdma.h
67128 index 8ba8ce2..99b7fff 100644
67129 --- a/include/net/netdma.h
67130 +++ b/include/net/netdma.h
67131 @@ -24,7 +24,7 @@
67132 #include <linux/dmaengine.h>
67133 #include <linux/skbuff.h>
67134
67135 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
67136 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
67137 struct sk_buff *skb, int offset, struct iovec *to,
67138 size_t len, struct dma_pinned_list *pinned_list);
67139
67140 diff --git a/include/net/netfilter/nf_queue.h b/include/net/netfilter/nf_queue.h
67141 index 252fd10..aa1421f 100644
67142 --- a/include/net/netfilter/nf_queue.h
67143 +++ b/include/net/netfilter/nf_queue.h
67144 @@ -22,7 +22,7 @@ struct nf_queue_handler {
67145 int (*outfn)(struct nf_queue_entry *entry,
67146 unsigned int queuenum);
67147 char *name;
67148 -};
67149 +} __do_const;
67150
67151 extern int nf_register_queue_handler(u_int8_t pf,
67152 const struct nf_queue_handler *qh);
67153 diff --git a/include/net/netlink.h b/include/net/netlink.h
67154 index 9690b0f..87aded7 100644
67155 --- a/include/net/netlink.h
67156 +++ b/include/net/netlink.h
67157 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
67158 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
67159 {
67160 if (mark)
67161 - skb_trim(skb, (unsigned char *) mark - skb->data);
67162 + skb_trim(skb, (const unsigned char *) mark - skb->data);
67163 }
67164
67165 /**
67166 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
67167 index 2ae2b83..dbdc85e 100644
67168 --- a/include/net/netns/ipv4.h
67169 +++ b/include/net/netns/ipv4.h
67170 @@ -64,7 +64,7 @@ struct netns_ipv4 {
67171 kgid_t sysctl_ping_group_range[2];
67172 long sysctl_tcp_mem[3];
67173
67174 - atomic_t dev_addr_genid;
67175 + atomic_unchecked_t dev_addr_genid;
67176
67177 #ifdef CONFIG_IP_MROUTE
67178 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
67179 diff --git a/include/net/protocol.h b/include/net/protocol.h
67180 index 929528c..c84d4f6 100644
67181 --- a/include/net/protocol.h
67182 +++ b/include/net/protocol.h
67183 @@ -48,7 +48,7 @@ struct net_protocol {
67184 int (*gro_complete)(struct sk_buff *skb);
67185 unsigned int no_policy:1,
67186 netns_ok:1;
67187 -};
67188 +} __do_const;
67189
67190 #if IS_ENABLED(CONFIG_IPV6)
67191 struct inet6_protocol {
67192 @@ -69,7 +69,7 @@ struct inet6_protocol {
67193 int (*gro_complete)(struct sk_buff *skb);
67194
67195 unsigned int flags; /* INET6_PROTO_xxx */
67196 -};
67197 +} __do_const;
67198
67199 #define INET6_PROTO_NOPOLICY 0x1
67200 #define INET6_PROTO_FINAL 0x2
67201 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
67202 index 9c6414f..fbd0524 100644
67203 --- a/include/net/sctp/sctp.h
67204 +++ b/include/net/sctp/sctp.h
67205 @@ -318,9 +318,9 @@ do { \
67206
67207 #else /* SCTP_DEBUG */
67208
67209 -#define SCTP_DEBUG_PRINTK(whatever...)
67210 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
67211 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
67212 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
67213 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
67214 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
67215 #define SCTP_ENABLE_DEBUG
67216 #define SCTP_DISABLE_DEBUG
67217 #define SCTP_ASSERT(expr, str, func)
67218 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
67219 index 64158aa..b65533c 100644
67220 --- a/include/net/sctp/structs.h
67221 +++ b/include/net/sctp/structs.h
67222 @@ -496,7 +496,7 @@ struct sctp_af {
67223 int sockaddr_len;
67224 sa_family_t sa_family;
67225 struct list_head list;
67226 -};
67227 +} __do_const;
67228
67229 struct sctp_af *sctp_get_af_specific(sa_family_t);
67230 int sctp_register_af(struct sctp_af *);
67231 @@ -516,7 +516,7 @@ struct sctp_pf {
67232 struct sctp_association *asoc);
67233 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
67234 struct sctp_af *af;
67235 -};
67236 +} __do_const;
67237
67238
67239 /* Structure to track chunk fragments that have been acked, but peer
67240 diff --git a/include/net/sock.h b/include/net/sock.h
67241 index c945fba..e162e56 100644
67242 --- a/include/net/sock.h
67243 +++ b/include/net/sock.h
67244 @@ -304,7 +304,7 @@ struct sock {
67245 #ifdef CONFIG_RPS
67246 __u32 sk_rxhash;
67247 #endif
67248 - atomic_t sk_drops;
67249 + atomic_unchecked_t sk_drops;
67250 int sk_rcvbuf;
67251
67252 struct sk_filter __rcu *sk_filter;
67253 @@ -1763,7 +1763,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
67254 }
67255
67256 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
67257 - char __user *from, char *to,
67258 + char __user *from, unsigned char *to,
67259 int copy, int offset)
67260 {
67261 if (skb->ip_summed == CHECKSUM_NONE) {
67262 @@ -2022,7 +2022,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
67263 }
67264 }
67265
67266 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67267 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67268
67269 /**
67270 * sk_page_frag - return an appropriate page_frag
67271 diff --git a/include/net/tcp.h b/include/net/tcp.h
67272 index 4af45e3..af97861 100644
67273 --- a/include/net/tcp.h
67274 +++ b/include/net/tcp.h
67275 @@ -531,7 +531,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
67276 extern void tcp_xmit_retransmit_queue(struct sock *);
67277 extern void tcp_simple_retransmit(struct sock *);
67278 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
67279 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67280 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67281
67282 extern void tcp_send_probe0(struct sock *);
67283 extern void tcp_send_partial(struct sock *);
67284 @@ -702,8 +702,8 @@ struct tcp_skb_cb {
67285 struct inet6_skb_parm h6;
67286 #endif
67287 } header; /* For incoming frames */
67288 - __u32 seq; /* Starting sequence number */
67289 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
67290 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
67291 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
67292 __u32 when; /* used to compute rtt's */
67293 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
67294
67295 @@ -717,7 +717,7 @@ struct tcp_skb_cb {
67296
67297 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
67298 /* 1 byte hole */
67299 - __u32 ack_seq; /* Sequence number ACK'd */
67300 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
67301 };
67302
67303 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
67304 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
67305 index 63445ed..74ef61d 100644
67306 --- a/include/net/xfrm.h
67307 +++ b/include/net/xfrm.h
67308 @@ -423,7 +423,7 @@ struct xfrm_mode {
67309 struct module *owner;
67310 unsigned int encap;
67311 int flags;
67312 -};
67313 +} __do_const;
67314
67315 /* Flags for xfrm_mode. */
67316 enum {
67317 @@ -514,7 +514,7 @@ struct xfrm_policy {
67318 struct timer_list timer;
67319
67320 struct flow_cache_object flo;
67321 - atomic_t genid;
67322 + atomic_unchecked_t genid;
67323 u32 priority;
67324 u32 index;
67325 struct xfrm_mark mark;
67326 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
67327 index 1a046b1..ee0bef0 100644
67328 --- a/include/rdma/iw_cm.h
67329 +++ b/include/rdma/iw_cm.h
67330 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
67331 int backlog);
67332
67333 int (*destroy_listen)(struct iw_cm_id *cm_id);
67334 -};
67335 +} __no_const;
67336
67337 /**
67338 * iw_create_cm_id - Create an IW CM identifier.
67339 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
67340 index 399162b..b337f1a 100644
67341 --- a/include/scsi/libfc.h
67342 +++ b/include/scsi/libfc.h
67343 @@ -762,6 +762,7 @@ struct libfc_function_template {
67344 */
67345 void (*disc_stop_final) (struct fc_lport *);
67346 };
67347 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
67348
67349 /**
67350 * struct fc_disc - Discovery context
67351 @@ -866,7 +867,7 @@ struct fc_lport {
67352 struct fc_vport *vport;
67353
67354 /* Operational Information */
67355 - struct libfc_function_template tt;
67356 + libfc_function_template_no_const tt;
67357 u8 link_up;
67358 u8 qfull;
67359 enum fc_lport_state state;
67360 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
67361 index 55367b0..d97bd2a 100644
67362 --- a/include/scsi/scsi_device.h
67363 +++ b/include/scsi/scsi_device.h
67364 @@ -169,9 +169,9 @@ struct scsi_device {
67365 unsigned int max_device_blocked; /* what device_blocked counts down from */
67366 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
67367
67368 - atomic_t iorequest_cnt;
67369 - atomic_t iodone_cnt;
67370 - atomic_t ioerr_cnt;
67371 + atomic_unchecked_t iorequest_cnt;
67372 + atomic_unchecked_t iodone_cnt;
67373 + atomic_unchecked_t ioerr_cnt;
67374
67375 struct device sdev_gendev,
67376 sdev_dev;
67377 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
67378 index b797e8f..8e2c3aa 100644
67379 --- a/include/scsi/scsi_transport_fc.h
67380 +++ b/include/scsi/scsi_transport_fc.h
67381 @@ -751,7 +751,8 @@ struct fc_function_template {
67382 unsigned long show_host_system_hostname:1;
67383
67384 unsigned long disable_target_scan:1;
67385 -};
67386 +} __do_const;
67387 +typedef struct fc_function_template __no_const fc_function_template_no_const;
67388
67389
67390 /**
67391 diff --git a/include/sound/soc.h b/include/sound/soc.h
67392 index 91244a0..89ca1a7 100644
67393 --- a/include/sound/soc.h
67394 +++ b/include/sound/soc.h
67395 @@ -769,7 +769,7 @@ struct snd_soc_codec_driver {
67396 /* probe ordering - for components with runtime dependencies */
67397 int probe_order;
67398 int remove_order;
67399 -};
67400 +} __do_const;
67401
67402 /* SoC platform interface */
67403 struct snd_soc_platform_driver {
67404 @@ -815,7 +815,7 @@ struct snd_soc_platform_driver {
67405 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
67406 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
67407 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
67408 -};
67409 +} __do_const;
67410
67411 struct snd_soc_platform {
67412 const char *name;
67413 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
67414 index fca8bbe..c0242ea 100644
67415 --- a/include/target/target_core_base.h
67416 +++ b/include/target/target_core_base.h
67417 @@ -760,7 +760,7 @@ struct se_device {
67418 spinlock_t stats_lock;
67419 /* Active commands on this virtual SE device */
67420 atomic_t simple_cmds;
67421 - atomic_t dev_ordered_id;
67422 + atomic_unchecked_t dev_ordered_id;
67423 atomic_t dev_ordered_sync;
67424 atomic_t dev_qf_count;
67425 struct se_obj dev_obj;
67426 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
67427 new file mode 100644
67428 index 0000000..fb634b7
67429 --- /dev/null
67430 +++ b/include/trace/events/fs.h
67431 @@ -0,0 +1,53 @@
67432 +#undef TRACE_SYSTEM
67433 +#define TRACE_SYSTEM fs
67434 +
67435 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
67436 +#define _TRACE_FS_H
67437 +
67438 +#include <linux/fs.h>
67439 +#include <linux/tracepoint.h>
67440 +
67441 +TRACE_EVENT(do_sys_open,
67442 +
67443 + TP_PROTO(const char *filename, int flags, int mode),
67444 +
67445 + TP_ARGS(filename, flags, mode),
67446 +
67447 + TP_STRUCT__entry(
67448 + __string( filename, filename )
67449 + __field( int, flags )
67450 + __field( int, mode )
67451 + ),
67452 +
67453 + TP_fast_assign(
67454 + __assign_str(filename, filename);
67455 + __entry->flags = flags;
67456 + __entry->mode = mode;
67457 + ),
67458 +
67459 + TP_printk("\"%s\" %x %o",
67460 + __get_str(filename), __entry->flags, __entry->mode)
67461 +);
67462 +
67463 +TRACE_EVENT(open_exec,
67464 +
67465 + TP_PROTO(const char *filename),
67466 +
67467 + TP_ARGS(filename),
67468 +
67469 + TP_STRUCT__entry(
67470 + __string( filename, filename )
67471 + ),
67472 +
67473 + TP_fast_assign(
67474 + __assign_str(filename, filename);
67475 + ),
67476 +
67477 + TP_printk("\"%s\"",
67478 + __get_str(filename))
67479 +);
67480 +
67481 +#endif /* _TRACE_FS_H */
67482 +
67483 +/* This part must be outside protection */
67484 +#include <trace/define_trace.h>
67485 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
67486 index 1c09820..7f5ec79 100644
67487 --- a/include/trace/events/irq.h
67488 +++ b/include/trace/events/irq.h
67489 @@ -36,7 +36,7 @@ struct softirq_action;
67490 */
67491 TRACE_EVENT(irq_handler_entry,
67492
67493 - TP_PROTO(int irq, struct irqaction *action),
67494 + TP_PROTO(int irq, const struct irqaction *action),
67495
67496 TP_ARGS(irq, action),
67497
67498 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
67499 */
67500 TRACE_EVENT(irq_handler_exit,
67501
67502 - TP_PROTO(int irq, struct irqaction *action, int ret),
67503 + TP_PROTO(int irq, const struct irqaction *action, int ret),
67504
67505 TP_ARGS(irq, action, ret),
67506
67507 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
67508 index 7caf44c..23c6f27 100644
67509 --- a/include/uapi/linux/a.out.h
67510 +++ b/include/uapi/linux/a.out.h
67511 @@ -39,6 +39,14 @@ enum machine_type {
67512 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
67513 };
67514
67515 +/* Constants for the N_FLAGS field */
67516 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67517 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
67518 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
67519 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
67520 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67521 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67522 +
67523 #if !defined (N_MAGIC)
67524 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
67525 #endif
67526 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
67527 index d876736..b36014e 100644
67528 --- a/include/uapi/linux/byteorder/little_endian.h
67529 +++ b/include/uapi/linux/byteorder/little_endian.h
67530 @@ -42,51 +42,51 @@
67531
67532 static inline __le64 __cpu_to_le64p(const __u64 *p)
67533 {
67534 - return (__force __le64)*p;
67535 + return (__force const __le64)*p;
67536 }
67537 static inline __u64 __le64_to_cpup(const __le64 *p)
67538 {
67539 - return (__force __u64)*p;
67540 + return (__force const __u64)*p;
67541 }
67542 static inline __le32 __cpu_to_le32p(const __u32 *p)
67543 {
67544 - return (__force __le32)*p;
67545 + return (__force const __le32)*p;
67546 }
67547 static inline __u32 __le32_to_cpup(const __le32 *p)
67548 {
67549 - return (__force __u32)*p;
67550 + return (__force const __u32)*p;
67551 }
67552 static inline __le16 __cpu_to_le16p(const __u16 *p)
67553 {
67554 - return (__force __le16)*p;
67555 + return (__force const __le16)*p;
67556 }
67557 static inline __u16 __le16_to_cpup(const __le16 *p)
67558 {
67559 - return (__force __u16)*p;
67560 + return (__force const __u16)*p;
67561 }
67562 static inline __be64 __cpu_to_be64p(const __u64 *p)
67563 {
67564 - return (__force __be64)__swab64p(p);
67565 + return (__force const __be64)__swab64p(p);
67566 }
67567 static inline __u64 __be64_to_cpup(const __be64 *p)
67568 {
67569 - return __swab64p((__u64 *)p);
67570 + return __swab64p((const __u64 *)p);
67571 }
67572 static inline __be32 __cpu_to_be32p(const __u32 *p)
67573 {
67574 - return (__force __be32)__swab32p(p);
67575 + return (__force const __be32)__swab32p(p);
67576 }
67577 static inline __u32 __be32_to_cpup(const __be32 *p)
67578 {
67579 - return __swab32p((__u32 *)p);
67580 + return __swab32p((const __u32 *)p);
67581 }
67582 static inline __be16 __cpu_to_be16p(const __u16 *p)
67583 {
67584 - return (__force __be16)__swab16p(p);
67585 + return (__force const __be16)__swab16p(p);
67586 }
67587 static inline __u16 __be16_to_cpup(const __be16 *p)
67588 {
67589 - return __swab16p((__u16 *)p);
67590 + return __swab16p((const __u16 *)p);
67591 }
67592 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
67593 #define __le64_to_cpus(x) do { (void)(x); } while (0)
67594 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
67595 index 126a817..d522bd1 100644
67596 --- a/include/uapi/linux/elf.h
67597 +++ b/include/uapi/linux/elf.h
67598 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
67599 #define PT_GNU_EH_FRAME 0x6474e550
67600
67601 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
67602 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
67603 +
67604 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
67605 +
67606 +/* Constants for the e_flags field */
67607 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67608 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
67609 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
67610 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
67611 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67612 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67613
67614 /*
67615 * Extended Numbering
67616 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
67617 #define DT_DEBUG 21
67618 #define DT_TEXTREL 22
67619 #define DT_JMPREL 23
67620 +#define DT_FLAGS 30
67621 + #define DF_TEXTREL 0x00000004
67622 #define DT_ENCODING 32
67623 #define OLD_DT_LOOS 0x60000000
67624 #define DT_LOOS 0x6000000d
67625 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
67626 #define PF_W 0x2
67627 #define PF_X 0x1
67628
67629 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
67630 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
67631 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
67632 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
67633 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
67634 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
67635 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
67636 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
67637 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
67638 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
67639 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
67640 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
67641 +
67642 typedef struct elf32_phdr{
67643 Elf32_Word p_type;
67644 Elf32_Off p_offset;
67645 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
67646 #define EI_OSABI 7
67647 #define EI_PAD 8
67648
67649 +#define EI_PAX 14
67650 +
67651 #define ELFMAG0 0x7f /* EI_MAG */
67652 #define ELFMAG1 'E'
67653 #define ELFMAG2 'L'
67654 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
67655 index aa169c4..6a2771d 100644
67656 --- a/include/uapi/linux/personality.h
67657 +++ b/include/uapi/linux/personality.h
67658 @@ -30,6 +30,7 @@ enum {
67659 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
67660 ADDR_NO_RANDOMIZE | \
67661 ADDR_COMPAT_LAYOUT | \
67662 + ADDR_LIMIT_3GB | \
67663 MMAP_PAGE_ZERO)
67664
67665 /*
67666 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
67667 index 7530e74..e714828 100644
67668 --- a/include/uapi/linux/screen_info.h
67669 +++ b/include/uapi/linux/screen_info.h
67670 @@ -43,7 +43,8 @@ struct screen_info {
67671 __u16 pages; /* 0x32 */
67672 __u16 vesa_attributes; /* 0x34 */
67673 __u32 capabilities; /* 0x36 */
67674 - __u8 _reserved[6]; /* 0x3a */
67675 + __u16 vesapm_size; /* 0x3a */
67676 + __u8 _reserved[4]; /* 0x3c */
67677 } __attribute__((packed));
67678
67679 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
67680 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
67681 index 6d67213..8dab561 100644
67682 --- a/include/uapi/linux/sysctl.h
67683 +++ b/include/uapi/linux/sysctl.h
67684 @@ -155,7 +155,11 @@ enum
67685 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
67686 };
67687
67688 -
67689 +#ifdef CONFIG_PAX_SOFTMODE
67690 +enum {
67691 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
67692 +};
67693 +#endif
67694
67695 /* CTL_VM names: */
67696 enum
67697 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
67698 index 26607bd..588b65f 100644
67699 --- a/include/uapi/linux/xattr.h
67700 +++ b/include/uapi/linux/xattr.h
67701 @@ -60,5 +60,9 @@
67702 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
67703 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
67704
67705 +/* User namespace */
67706 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
67707 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
67708 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
67709
67710 #endif /* _UAPI_LINUX_XATTR_H */
67711 diff --git a/include/video/omapdss.h b/include/video/omapdss.h
67712 index 3729173..7b2df7e 100644
67713 --- a/include/video/omapdss.h
67714 +++ b/include/video/omapdss.h
67715 @@ -323,7 +323,7 @@ struct omap_dss_board_info {
67716 int (*dsi_enable_pads)(int dsi_id, unsigned lane_mask);
67717 void (*dsi_disable_pads)(int dsi_id, unsigned lane_mask);
67718 int (*set_min_bus_tput)(struct device *dev, unsigned long r);
67719 -};
67720 +} __do_const;
67721
67722 /* Init with the board info */
67723 extern int omap_display_init(struct omap_dss_board_info *board_data);
67724 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
67725 index f9466fa..f4e2b81 100644
67726 --- a/include/video/udlfb.h
67727 +++ b/include/video/udlfb.h
67728 @@ -53,10 +53,10 @@ struct dlfb_data {
67729 u32 pseudo_palette[256];
67730 int blank_mode; /*one of FB_BLANK_ */
67731 /* blit-only rendering path metrics, exposed through sysfs */
67732 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67733 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
67734 - atomic_t bytes_sent; /* to usb, after compression including overhead */
67735 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
67736 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67737 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
67738 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
67739 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
67740 };
67741
67742 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
67743 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
67744 index 0993a22..32ba2fe 100644
67745 --- a/include/video/uvesafb.h
67746 +++ b/include/video/uvesafb.h
67747 @@ -177,6 +177,7 @@ struct uvesafb_par {
67748 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
67749 u8 pmi_setpal; /* PMI for palette changes */
67750 u16 *pmi_base; /* protected mode interface location */
67751 + u8 *pmi_code; /* protected mode code location */
67752 void *pmi_start;
67753 void *pmi_pal;
67754 u8 *vbe_state_orig; /*
67755 diff --git a/init/Kconfig b/init/Kconfig
67756 index 6fdd6e3..5b01610 100644
67757 --- a/init/Kconfig
67758 +++ b/init/Kconfig
67759 @@ -925,6 +925,7 @@ endif # CGROUPS
67760
67761 config CHECKPOINT_RESTORE
67762 bool "Checkpoint/restore support" if EXPERT
67763 + depends on !GRKERNSEC
67764 default n
67765 help
67766 Enables additional kernel features in a sake of checkpoint/restore.
67767 @@ -1016,6 +1017,8 @@ config UIDGID_CONVERTED
67768 depends on OCFS2_FS = n
67769 depends on XFS_FS = n
67770
67771 + depends on GRKERNSEC = n
67772 +
67773 config UIDGID_STRICT_TYPE_CHECKS
67774 bool "Require conversions between uid/gids and their internal representation"
67775 depends on UIDGID_CONVERTED
67776 @@ -1405,7 +1408,7 @@ config SLUB_DEBUG
67777
67778 config COMPAT_BRK
67779 bool "Disable heap randomization"
67780 - default y
67781 + default n
67782 help
67783 Randomizing heap placement makes heap exploits harder, but it
67784 also breaks ancient binaries (including anything libc5 based).
67785 @@ -1648,7 +1651,7 @@ config INIT_ALL_POSSIBLE
67786 config STOP_MACHINE
67787 bool
67788 default y
67789 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
67790 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
67791 help
67792 Need stop_machine() primitive.
67793
67794 diff --git a/init/Makefile b/init/Makefile
67795 index 7bc47ee..6da2dc7 100644
67796 --- a/init/Makefile
67797 +++ b/init/Makefile
67798 @@ -2,6 +2,9 @@
67799 # Makefile for the linux kernel.
67800 #
67801
67802 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
67803 +asflags-y := $(GCC_PLUGINS_AFLAGS)
67804 +
67805 obj-y := main.o version.o mounts.o
67806 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
67807 obj-y += noinitramfs.o
67808 diff --git a/init/do_mounts.c b/init/do_mounts.c
67809 index f8a6642..4e5ee1b 100644
67810 --- a/init/do_mounts.c
67811 +++ b/init/do_mounts.c
67812 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
67813 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
67814 {
67815 struct super_block *s;
67816 - int err = sys_mount(name, "/root", fs, flags, data);
67817 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
67818 if (err)
67819 return err;
67820
67821 - sys_chdir("/root");
67822 + sys_chdir((const char __force_user *)"/root");
67823 s = current->fs->pwd.dentry->d_sb;
67824 ROOT_DEV = s->s_dev;
67825 printk(KERN_INFO
67826 @@ -461,18 +461,18 @@ void __init change_floppy(char *fmt, ...)
67827 va_start(args, fmt);
67828 vsprintf(buf, fmt, args);
67829 va_end(args);
67830 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
67831 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
67832 if (fd >= 0) {
67833 sys_ioctl(fd, FDEJECT, 0);
67834 sys_close(fd);
67835 }
67836 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
67837 - fd = sys_open("/dev/console", O_RDWR, 0);
67838 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
67839 if (fd >= 0) {
67840 sys_ioctl(fd, TCGETS, (long)&termios);
67841 termios.c_lflag &= ~ICANON;
67842 sys_ioctl(fd, TCSETSF, (long)&termios);
67843 - sys_read(fd, &c, 1);
67844 + sys_read(fd, (char __user *)&c, 1);
67845 termios.c_lflag |= ICANON;
67846 sys_ioctl(fd, TCSETSF, (long)&termios);
67847 sys_close(fd);
67848 @@ -566,6 +566,6 @@ void __init prepare_namespace(void)
67849 mount_root();
67850 out:
67851 devtmpfs_mount("dev");
67852 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
67853 - sys_chroot(".");
67854 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
67855 + sys_chroot((const char __force_user *)".");
67856 }
67857 diff --git a/init/do_mounts.h b/init/do_mounts.h
67858 index f5b978a..69dbfe8 100644
67859 --- a/init/do_mounts.h
67860 +++ b/init/do_mounts.h
67861 @@ -15,15 +15,15 @@ extern int root_mountflags;
67862
67863 static inline int create_dev(char *name, dev_t dev)
67864 {
67865 - sys_unlink(name);
67866 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
67867 + sys_unlink((char __force_user *)name);
67868 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
67869 }
67870
67871 #if BITS_PER_LONG == 32
67872 static inline u32 bstat(char *name)
67873 {
67874 struct stat64 stat;
67875 - if (sys_stat64(name, &stat) != 0)
67876 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
67877 return 0;
67878 if (!S_ISBLK(stat.st_mode))
67879 return 0;
67880 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
67881 static inline u32 bstat(char *name)
67882 {
67883 struct stat stat;
67884 - if (sys_newstat(name, &stat) != 0)
67885 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
67886 return 0;
67887 if (!S_ISBLK(stat.st_mode))
67888 return 0;
67889 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
67890 index f9acf71..1e19144 100644
67891 --- a/init/do_mounts_initrd.c
67892 +++ b/init/do_mounts_initrd.c
67893 @@ -58,8 +58,8 @@ static void __init handle_initrd(void)
67894 create_dev("/dev/root.old", Root_RAM0);
67895 /* mount initrd on rootfs' /root */
67896 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
67897 - sys_mkdir("/old", 0700);
67898 - sys_chdir("/old");
67899 + sys_mkdir((const char __force_user *)"/old", 0700);
67900 + sys_chdir((const char __force_user *)"/old");
67901
67902 /*
67903 * In case that a resume from disk is carried out by linuxrc or one of
67904 @@ -73,31 +73,31 @@ static void __init handle_initrd(void)
67905 current->flags &= ~PF_FREEZER_SKIP;
67906
67907 /* move initrd to rootfs' /old */
67908 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
67909 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
67910 /* switch root and cwd back to / of rootfs */
67911 - sys_chroot("..");
67912 + sys_chroot((const char __force_user *)"..");
67913
67914 if (new_decode_dev(real_root_dev) == Root_RAM0) {
67915 - sys_chdir("/old");
67916 + sys_chdir((const char __force_user *)"/old");
67917 return;
67918 }
67919
67920 - sys_chdir("/");
67921 + sys_chdir((const char __force_user *)"/");
67922 ROOT_DEV = new_decode_dev(real_root_dev);
67923 mount_root();
67924
67925 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
67926 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
67927 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
67928 if (!error)
67929 printk("okay\n");
67930 else {
67931 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
67932 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
67933 if (error == -ENOENT)
67934 printk("/initrd does not exist. Ignored.\n");
67935 else
67936 printk("failed\n");
67937 printk(KERN_NOTICE "Unmounting old root\n");
67938 - sys_umount("/old", MNT_DETACH);
67939 + sys_umount((char __force_user *)"/old", MNT_DETACH);
67940 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
67941 if (fd < 0) {
67942 error = fd;
67943 @@ -120,11 +120,11 @@ int __init initrd_load(void)
67944 * mounted in the normal path.
67945 */
67946 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
67947 - sys_unlink("/initrd.image");
67948 + sys_unlink((const char __force_user *)"/initrd.image");
67949 handle_initrd();
67950 return 1;
67951 }
67952 }
67953 - sys_unlink("/initrd.image");
67954 + sys_unlink((const char __force_user *)"/initrd.image");
67955 return 0;
67956 }
67957 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
67958 index 8cb6db5..d729f50 100644
67959 --- a/init/do_mounts_md.c
67960 +++ b/init/do_mounts_md.c
67961 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
67962 partitioned ? "_d" : "", minor,
67963 md_setup_args[ent].device_names);
67964
67965 - fd = sys_open(name, 0, 0);
67966 + fd = sys_open((char __force_user *)name, 0, 0);
67967 if (fd < 0) {
67968 printk(KERN_ERR "md: open failed - cannot start "
67969 "array %s\n", name);
67970 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
67971 * array without it
67972 */
67973 sys_close(fd);
67974 - fd = sys_open(name, 0, 0);
67975 + fd = sys_open((char __force_user *)name, 0, 0);
67976 sys_ioctl(fd, BLKRRPART, 0);
67977 }
67978 sys_close(fd);
67979 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
67980
67981 wait_for_device_probe();
67982
67983 - fd = sys_open("/dev/md0", 0, 0);
67984 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
67985 if (fd >= 0) {
67986 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
67987 sys_close(fd);
67988 diff --git a/init/init_task.c b/init/init_task.c
67989 index 8b2f399..f0797c9 100644
67990 --- a/init/init_task.c
67991 +++ b/init/init_task.c
67992 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
67993 * Initial thread structure. Alignment of this is handled by a special
67994 * linker map entry.
67995 */
67996 +#ifdef CONFIG_X86
67997 +union thread_union init_thread_union __init_task_data;
67998 +#else
67999 union thread_union init_thread_union __init_task_data =
68000 { INIT_THREAD_INFO(init_task) };
68001 +#endif
68002 diff --git a/init/initramfs.c b/init/initramfs.c
68003 index 84c6bf1..8899338 100644
68004 --- a/init/initramfs.c
68005 +++ b/init/initramfs.c
68006 @@ -84,7 +84,7 @@ static void __init free_hash(void)
68007 }
68008 }
68009
68010 -static long __init do_utime(char *filename, time_t mtime)
68011 +static long __init do_utime(char __force_user *filename, time_t mtime)
68012 {
68013 struct timespec t[2];
68014
68015 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
68016 struct dir_entry *de, *tmp;
68017 list_for_each_entry_safe(de, tmp, &dir_list, list) {
68018 list_del(&de->list);
68019 - do_utime(de->name, de->mtime);
68020 + do_utime((char __force_user *)de->name, de->mtime);
68021 kfree(de->name);
68022 kfree(de);
68023 }
68024 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
68025 if (nlink >= 2) {
68026 char *old = find_link(major, minor, ino, mode, collected);
68027 if (old)
68028 - return (sys_link(old, collected) < 0) ? -1 : 1;
68029 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
68030 }
68031 return 0;
68032 }
68033 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
68034 {
68035 struct stat st;
68036
68037 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
68038 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
68039 if (S_ISDIR(st.st_mode))
68040 - sys_rmdir(path);
68041 + sys_rmdir((char __force_user *)path);
68042 else
68043 - sys_unlink(path);
68044 + sys_unlink((char __force_user *)path);
68045 }
68046 }
68047
68048 @@ -315,7 +315,7 @@ static int __init do_name(void)
68049 int openflags = O_WRONLY|O_CREAT;
68050 if (ml != 1)
68051 openflags |= O_TRUNC;
68052 - wfd = sys_open(collected, openflags, mode);
68053 + wfd = sys_open((char __force_user *)collected, openflags, mode);
68054
68055 if (wfd >= 0) {
68056 sys_fchown(wfd, uid, gid);
68057 @@ -327,17 +327,17 @@ static int __init do_name(void)
68058 }
68059 }
68060 } else if (S_ISDIR(mode)) {
68061 - sys_mkdir(collected, mode);
68062 - sys_chown(collected, uid, gid);
68063 - sys_chmod(collected, mode);
68064 + sys_mkdir((char __force_user *)collected, mode);
68065 + sys_chown((char __force_user *)collected, uid, gid);
68066 + sys_chmod((char __force_user *)collected, mode);
68067 dir_add(collected, mtime);
68068 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
68069 S_ISFIFO(mode) || S_ISSOCK(mode)) {
68070 if (maybe_link() == 0) {
68071 - sys_mknod(collected, mode, rdev);
68072 - sys_chown(collected, uid, gid);
68073 - sys_chmod(collected, mode);
68074 - do_utime(collected, mtime);
68075 + sys_mknod((char __force_user *)collected, mode, rdev);
68076 + sys_chown((char __force_user *)collected, uid, gid);
68077 + sys_chmod((char __force_user *)collected, mode);
68078 + do_utime((char __force_user *)collected, mtime);
68079 }
68080 }
68081 return 0;
68082 @@ -346,15 +346,15 @@ static int __init do_name(void)
68083 static int __init do_copy(void)
68084 {
68085 if (count >= body_len) {
68086 - sys_write(wfd, victim, body_len);
68087 + sys_write(wfd, (char __force_user *)victim, body_len);
68088 sys_close(wfd);
68089 - do_utime(vcollected, mtime);
68090 + do_utime((char __force_user *)vcollected, mtime);
68091 kfree(vcollected);
68092 eat(body_len);
68093 state = SkipIt;
68094 return 0;
68095 } else {
68096 - sys_write(wfd, victim, count);
68097 + sys_write(wfd, (char __force_user *)victim, count);
68098 body_len -= count;
68099 eat(count);
68100 return 1;
68101 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
68102 {
68103 collected[N_ALIGN(name_len) + body_len] = '\0';
68104 clean_path(collected, 0);
68105 - sys_symlink(collected + N_ALIGN(name_len), collected);
68106 - sys_lchown(collected, uid, gid);
68107 - do_utime(collected, mtime);
68108 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
68109 + sys_lchown((char __force_user *)collected, uid, gid);
68110 + do_utime((char __force_user *)collected, mtime);
68111 state = SkipIt;
68112 next_state = Reset;
68113 return 0;
68114 diff --git a/init/main.c b/init/main.c
68115 index 857166f..9df1d8e 100644
68116 --- a/init/main.c
68117 +++ b/init/main.c
68118 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
68119 extern void tc_init(void);
68120 #endif
68121
68122 +extern void grsecurity_init(void);
68123 +
68124 /*
68125 * Debug helper: via this flag we know that we are in 'early bootup code'
68126 * where only the boot processor is running with IRQ disabled. This means
68127 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
68128
68129 __setup("reset_devices", set_reset_devices);
68130
68131 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68132 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
68133 +static int __init setup_grsec_proc_gid(char *str)
68134 +{
68135 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
68136 + return 1;
68137 +}
68138 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
68139 +#endif
68140 +
68141 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
68142 +extern char pax_enter_kernel_user[];
68143 +extern char pax_exit_kernel_user[];
68144 +extern pgdval_t clone_pgd_mask;
68145 +#endif
68146 +
68147 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
68148 +static int __init setup_pax_nouderef(char *str)
68149 +{
68150 +#ifdef CONFIG_X86_32
68151 + unsigned int cpu;
68152 + struct desc_struct *gdt;
68153 +
68154 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
68155 + gdt = get_cpu_gdt_table(cpu);
68156 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
68157 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
68158 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
68159 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
68160 + }
68161 + loadsegment(ds, __KERNEL_DS);
68162 + loadsegment(es, __KERNEL_DS);
68163 + loadsegment(ss, __KERNEL_DS);
68164 +#else
68165 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
68166 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
68167 + clone_pgd_mask = ~(pgdval_t)0UL;
68168 +#endif
68169 +
68170 + return 0;
68171 +}
68172 +early_param("pax_nouderef", setup_pax_nouderef);
68173 +#endif
68174 +
68175 +#ifdef CONFIG_PAX_SOFTMODE
68176 +int pax_softmode;
68177 +
68178 +static int __init setup_pax_softmode(char *str)
68179 +{
68180 + get_option(&str, &pax_softmode);
68181 + return 1;
68182 +}
68183 +__setup("pax_softmode=", setup_pax_softmode);
68184 +#endif
68185 +
68186 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
68187 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
68188 static const char *panic_later, *panic_param;
68189 @@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
68190 {
68191 int count = preempt_count();
68192 int ret;
68193 + const char *msg1 = "", *msg2 = "";
68194
68195 if (initcall_debug)
68196 ret = do_one_initcall_debug(fn);
68197 @@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
68198 sprintf(msgbuf, "error code %d ", ret);
68199
68200 if (preempt_count() != count) {
68201 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
68202 + msg1 = " preemption imbalance";
68203 preempt_count() = count;
68204 }
68205 if (irqs_disabled()) {
68206 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
68207 + msg2 = " disabled interrupts";
68208 local_irq_enable();
68209 }
68210 - if (msgbuf[0]) {
68211 - printk("initcall %pF returned with %s\n", fn, msgbuf);
68212 + if (msgbuf[0] || *msg1 || *msg2) {
68213 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
68214 }
68215
68216 return ret;
68217 @@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
68218 "late",
68219 };
68220
68221 +#ifdef CONFIG_PAX_LATENT_ENTROPY
68222 +u64 latent_entropy;
68223 +#endif
68224 +
68225 static void __init do_initcall_level(int level)
68226 {
68227 extern const struct kernel_param __start___param[], __stop___param[];
68228 @@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
68229 level, level,
68230 &repair_env_string);
68231
68232 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
68233 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
68234 do_one_initcall(*fn);
68235 +
68236 +#ifdef CONFIG_PAX_LATENT_ENTROPY
68237 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
68238 +#endif
68239 +
68240 + }
68241 }
68242
68243 static void __init do_initcalls(void)
68244 @@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
68245 {
68246 initcall_t *fn;
68247
68248 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
68249 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
68250 do_one_initcall(*fn);
68251 +
68252 +#ifdef CONFIG_PAX_LATENT_ENTROPY
68253 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
68254 +#endif
68255 +
68256 + }
68257 }
68258
68259 static int run_init_process(const char *init_filename)
68260 @@ -876,7 +950,7 @@ static noinline void __init kernel_init_freeable(void)
68261 do_basic_setup();
68262
68263 /* Open the /dev/console on the rootfs, this should never fail */
68264 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
68265 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
68266 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
68267
68268 (void) sys_dup(0);
68269 @@ -889,11 +963,13 @@ static noinline void __init kernel_init_freeable(void)
68270 if (!ramdisk_execute_command)
68271 ramdisk_execute_command = "/init";
68272
68273 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
68274 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
68275 ramdisk_execute_command = NULL;
68276 prepare_namespace();
68277 }
68278
68279 + grsecurity_init();
68280 +
68281 /*
68282 * Ok, we have completed the initial bootup, and
68283 * we're essentially up and running. Get rid of the
68284 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
68285 index 71a3ca1..cc330ee 100644
68286 --- a/ipc/mqueue.c
68287 +++ b/ipc/mqueue.c
68288 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
68289 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
68290 info->attr.mq_msgsize);
68291
68292 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
68293 spin_lock(&mq_lock);
68294 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
68295 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
68296 diff --git a/ipc/msg.c b/ipc/msg.c
68297 index a71af5a..a90a110 100644
68298 --- a/ipc/msg.c
68299 +++ b/ipc/msg.c
68300 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
68301 return security_msg_queue_associate(msq, msgflg);
68302 }
68303
68304 +static struct ipc_ops msg_ops = {
68305 + .getnew = newque,
68306 + .associate = msg_security,
68307 + .more_checks = NULL
68308 +};
68309 +
68310 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
68311 {
68312 struct ipc_namespace *ns;
68313 - struct ipc_ops msg_ops;
68314 struct ipc_params msg_params;
68315
68316 ns = current->nsproxy->ipc_ns;
68317
68318 - msg_ops.getnew = newque;
68319 - msg_ops.associate = msg_security;
68320 - msg_ops.more_checks = NULL;
68321 -
68322 msg_params.key = key;
68323 msg_params.flg = msgflg;
68324
68325 diff --git a/ipc/sem.c b/ipc/sem.c
68326 index 58d31f1..cce7a55 100644
68327 --- a/ipc/sem.c
68328 +++ b/ipc/sem.c
68329 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
68330 return 0;
68331 }
68332
68333 +static struct ipc_ops sem_ops = {
68334 + .getnew = newary,
68335 + .associate = sem_security,
68336 + .more_checks = sem_more_checks
68337 +};
68338 +
68339 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68340 {
68341 struct ipc_namespace *ns;
68342 - struct ipc_ops sem_ops;
68343 struct ipc_params sem_params;
68344
68345 ns = current->nsproxy->ipc_ns;
68346 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68347 if (nsems < 0 || nsems > ns->sc_semmsl)
68348 return -EINVAL;
68349
68350 - sem_ops.getnew = newary;
68351 - sem_ops.associate = sem_security;
68352 - sem_ops.more_checks = sem_more_checks;
68353 -
68354 sem_params.key = key;
68355 sem_params.flg = semflg;
68356 sem_params.u.nsems = nsems;
68357 diff --git a/ipc/shm.c b/ipc/shm.c
68358 index dff40c9..9450e27 100644
68359 --- a/ipc/shm.c
68360 +++ b/ipc/shm.c
68361 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
68362 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
68363 #endif
68364
68365 +#ifdef CONFIG_GRKERNSEC
68366 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68367 + const time_t shm_createtime, const uid_t cuid,
68368 + const int shmid);
68369 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68370 + const time_t shm_createtime);
68371 +#endif
68372 +
68373 void shm_init_ns(struct ipc_namespace *ns)
68374 {
68375 ns->shm_ctlmax = SHMMAX;
68376 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
68377 shp->shm_lprid = 0;
68378 shp->shm_atim = shp->shm_dtim = 0;
68379 shp->shm_ctim = get_seconds();
68380 +#ifdef CONFIG_GRKERNSEC
68381 + {
68382 + struct timespec timeval;
68383 + do_posix_clock_monotonic_gettime(&timeval);
68384 +
68385 + shp->shm_createtime = timeval.tv_sec;
68386 + }
68387 +#endif
68388 shp->shm_segsz = size;
68389 shp->shm_nattch = 0;
68390 shp->shm_file = file;
68391 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
68392 return 0;
68393 }
68394
68395 +static struct ipc_ops shm_ops = {
68396 + .getnew = newseg,
68397 + .associate = shm_security,
68398 + .more_checks = shm_more_checks
68399 +};
68400 +
68401 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
68402 {
68403 struct ipc_namespace *ns;
68404 - struct ipc_ops shm_ops;
68405 struct ipc_params shm_params;
68406
68407 ns = current->nsproxy->ipc_ns;
68408
68409 - shm_ops.getnew = newseg;
68410 - shm_ops.associate = shm_security;
68411 - shm_ops.more_checks = shm_more_checks;
68412 -
68413 shm_params.key = key;
68414 shm_params.flg = shmflg;
68415 shm_params.u.size = size;
68416 @@ -1003,6 +1020,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68417 f_mode = FMODE_READ | FMODE_WRITE;
68418 }
68419 if (shmflg & SHM_EXEC) {
68420 +
68421 +#ifdef CONFIG_PAX_MPROTECT
68422 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
68423 + goto out;
68424 +#endif
68425 +
68426 prot |= PROT_EXEC;
68427 acc_mode |= S_IXUGO;
68428 }
68429 @@ -1026,9 +1049,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68430 if (err)
68431 goto out_unlock;
68432
68433 +#ifdef CONFIG_GRKERNSEC
68434 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
68435 + shp->shm_perm.cuid, shmid) ||
68436 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
68437 + err = -EACCES;
68438 + goto out_unlock;
68439 + }
68440 +#endif
68441 +
68442 path = shp->shm_file->f_path;
68443 path_get(&path);
68444 shp->shm_nattch++;
68445 +#ifdef CONFIG_GRKERNSEC
68446 + shp->shm_lapid = current->pid;
68447 +#endif
68448 size = i_size_read(path.dentry->d_inode);
68449 shm_unlock(shp);
68450
68451 diff --git a/kernel/acct.c b/kernel/acct.c
68452 index 051e071..15e0920 100644
68453 --- a/kernel/acct.c
68454 +++ b/kernel/acct.c
68455 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
68456 */
68457 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
68458 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
68459 - file->f_op->write(file, (char *)&ac,
68460 + file->f_op->write(file, (char __force_user *)&ac,
68461 sizeof(acct_t), &file->f_pos);
68462 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
68463 set_fs(fs);
68464 diff --git a/kernel/audit.c b/kernel/audit.c
68465 index 40414e9..c920b72 100644
68466 --- a/kernel/audit.c
68467 +++ b/kernel/audit.c
68468 @@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
68469 3) suppressed due to audit_rate_limit
68470 4) suppressed due to audit_backlog_limit
68471 */
68472 -static atomic_t audit_lost = ATOMIC_INIT(0);
68473 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
68474
68475 /* The netlink socket. */
68476 static struct sock *audit_sock;
68477 @@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
68478 unsigned long now;
68479 int print;
68480
68481 - atomic_inc(&audit_lost);
68482 + atomic_inc_unchecked(&audit_lost);
68483
68484 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
68485
68486 @@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
68487 printk(KERN_WARNING
68488 "audit: audit_lost=%d audit_rate_limit=%d "
68489 "audit_backlog_limit=%d\n",
68490 - atomic_read(&audit_lost),
68491 + atomic_read_unchecked(&audit_lost),
68492 audit_rate_limit,
68493 audit_backlog_limit);
68494 audit_panic(message);
68495 @@ -677,7 +677,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
68496 status_set.pid = audit_pid;
68497 status_set.rate_limit = audit_rate_limit;
68498 status_set.backlog_limit = audit_backlog_limit;
68499 - status_set.lost = atomic_read(&audit_lost);
68500 + status_set.lost = atomic_read_unchecked(&audit_lost);
68501 status_set.backlog = skb_queue_len(&audit_skb_queue);
68502 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
68503 &status_set, sizeof(status_set));
68504 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
68505 index 157e989..b28b365 100644
68506 --- a/kernel/auditsc.c
68507 +++ b/kernel/auditsc.c
68508 @@ -2352,7 +2352,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
68509 }
68510
68511 /* global counter which is incremented every time something logs in */
68512 -static atomic_t session_id = ATOMIC_INIT(0);
68513 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
68514
68515 /**
68516 * audit_set_loginuid - set current task's audit_context loginuid
68517 @@ -2376,7 +2376,7 @@ int audit_set_loginuid(kuid_t loginuid)
68518 return -EPERM;
68519 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
68520
68521 - sessionid = atomic_inc_return(&session_id);
68522 + sessionid = atomic_inc_return_unchecked(&session_id);
68523 if (context && context->in_syscall) {
68524 struct audit_buffer *ab;
68525
68526 diff --git a/kernel/capability.c b/kernel/capability.c
68527 index 493d972..ea17248 100644
68528 --- a/kernel/capability.c
68529 +++ b/kernel/capability.c
68530 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
68531 * before modification is attempted and the application
68532 * fails.
68533 */
68534 + if (tocopy > ARRAY_SIZE(kdata))
68535 + return -EFAULT;
68536 +
68537 if (copy_to_user(dataptr, kdata, tocopy
68538 * sizeof(struct __user_cap_data_struct))) {
68539 return -EFAULT;
68540 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
68541 int ret;
68542
68543 rcu_read_lock();
68544 - ret = security_capable(__task_cred(t), ns, cap);
68545 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
68546 + gr_task_is_capable(t, __task_cred(t), cap);
68547 rcu_read_unlock();
68548
68549 - return (ret == 0);
68550 + return ret;
68551 }
68552
68553 /**
68554 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
68555 int ret;
68556
68557 rcu_read_lock();
68558 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
68559 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
68560 rcu_read_unlock();
68561
68562 - return (ret == 0);
68563 + return ret;
68564 }
68565
68566 /**
68567 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
68568 BUG();
68569 }
68570
68571 - if (security_capable(current_cred(), ns, cap) == 0) {
68572 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
68573 current->flags |= PF_SUPERPRIV;
68574 return true;
68575 }
68576 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
68577 }
68578 EXPORT_SYMBOL(ns_capable);
68579
68580 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
68581 +{
68582 + if (unlikely(!cap_valid(cap))) {
68583 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
68584 + BUG();
68585 + }
68586 +
68587 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
68588 + current->flags |= PF_SUPERPRIV;
68589 + return true;
68590 + }
68591 + return false;
68592 +}
68593 +EXPORT_SYMBOL(ns_capable_nolog);
68594 +
68595 /**
68596 * capable - Determine if the current task has a superior capability in effect
68597 * @cap: The capability to be tested for
68598 @@ -408,6 +427,12 @@ bool capable(int cap)
68599 }
68600 EXPORT_SYMBOL(capable);
68601
68602 +bool capable_nolog(int cap)
68603 +{
68604 + return ns_capable_nolog(&init_user_ns, cap);
68605 +}
68606 +EXPORT_SYMBOL(capable_nolog);
68607 +
68608 /**
68609 * nsown_capable - Check superior capability to one's own user_ns
68610 * @cap: The capability in question
68611 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
68612
68613 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68614 }
68615 +
68616 +bool inode_capable_nolog(const struct inode *inode, int cap)
68617 +{
68618 + struct user_namespace *ns = current_user_ns();
68619 +
68620 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68621 +}
68622 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
68623 index ad99830..992d8a7 100644
68624 --- a/kernel/cgroup.c
68625 +++ b/kernel/cgroup.c
68626 @@ -5514,7 +5514,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
68627 struct css_set *cg = link->cg;
68628 struct task_struct *task;
68629 int count = 0;
68630 - seq_printf(seq, "css_set %p\n", cg);
68631 + seq_printf(seq, "css_set %pK\n", cg);
68632 list_for_each_entry(task, &cg->tasks, cg_list) {
68633 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
68634 seq_puts(seq, " ...\n");
68635 diff --git a/kernel/compat.c b/kernel/compat.c
68636 index c28a306..b4d0cf3 100644
68637 --- a/kernel/compat.c
68638 +++ b/kernel/compat.c
68639 @@ -13,6 +13,7 @@
68640
68641 #include <linux/linkage.h>
68642 #include <linux/compat.h>
68643 +#include <linux/module.h>
68644 #include <linux/errno.h>
68645 #include <linux/time.h>
68646 #include <linux/signal.h>
68647 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
68648 mm_segment_t oldfs;
68649 long ret;
68650
68651 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
68652 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
68653 oldfs = get_fs();
68654 set_fs(KERNEL_DS);
68655 ret = hrtimer_nanosleep_restart(restart);
68656 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
68657 oldfs = get_fs();
68658 set_fs(KERNEL_DS);
68659 ret = hrtimer_nanosleep(&tu,
68660 - rmtp ? (struct timespec __user *)&rmt : NULL,
68661 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
68662 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
68663 set_fs(oldfs);
68664
68665 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
68666 mm_segment_t old_fs = get_fs();
68667
68668 set_fs(KERNEL_DS);
68669 - ret = sys_sigpending((old_sigset_t __user *) &s);
68670 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
68671 set_fs(old_fs);
68672 if (ret == 0)
68673 ret = put_user(s, set);
68674 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
68675 mm_segment_t old_fs = get_fs();
68676
68677 set_fs(KERNEL_DS);
68678 - ret = sys_old_getrlimit(resource, &r);
68679 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
68680 set_fs(old_fs);
68681
68682 if (!ret) {
68683 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
68684 mm_segment_t old_fs = get_fs();
68685
68686 set_fs(KERNEL_DS);
68687 - ret = sys_getrusage(who, (struct rusage __user *) &r);
68688 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
68689 set_fs(old_fs);
68690
68691 if (ret)
68692 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
68693 set_fs (KERNEL_DS);
68694 ret = sys_wait4(pid,
68695 (stat_addr ?
68696 - (unsigned int __user *) &status : NULL),
68697 - options, (struct rusage __user *) &r);
68698 + (unsigned int __force_user *) &status : NULL),
68699 + options, (struct rusage __force_user *) &r);
68700 set_fs (old_fs);
68701
68702 if (ret > 0) {
68703 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
68704 memset(&info, 0, sizeof(info));
68705
68706 set_fs(KERNEL_DS);
68707 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
68708 - uru ? (struct rusage __user *)&ru : NULL);
68709 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
68710 + uru ? (struct rusage __force_user *)&ru : NULL);
68711 set_fs(old_fs);
68712
68713 if ((ret < 0) || (info.si_signo == 0))
68714 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
68715 oldfs = get_fs();
68716 set_fs(KERNEL_DS);
68717 err = sys_timer_settime(timer_id, flags,
68718 - (struct itimerspec __user *) &newts,
68719 - (struct itimerspec __user *) &oldts);
68720 + (struct itimerspec __force_user *) &newts,
68721 + (struct itimerspec __force_user *) &oldts);
68722 set_fs(oldfs);
68723 if (!err && old && put_compat_itimerspec(old, &oldts))
68724 return -EFAULT;
68725 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
68726 oldfs = get_fs();
68727 set_fs(KERNEL_DS);
68728 err = sys_timer_gettime(timer_id,
68729 - (struct itimerspec __user *) &ts);
68730 + (struct itimerspec __force_user *) &ts);
68731 set_fs(oldfs);
68732 if (!err && put_compat_itimerspec(setting, &ts))
68733 return -EFAULT;
68734 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
68735 oldfs = get_fs();
68736 set_fs(KERNEL_DS);
68737 err = sys_clock_settime(which_clock,
68738 - (struct timespec __user *) &ts);
68739 + (struct timespec __force_user *) &ts);
68740 set_fs(oldfs);
68741 return err;
68742 }
68743 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
68744 oldfs = get_fs();
68745 set_fs(KERNEL_DS);
68746 err = sys_clock_gettime(which_clock,
68747 - (struct timespec __user *) &ts);
68748 + (struct timespec __force_user *) &ts);
68749 set_fs(oldfs);
68750 if (!err && put_compat_timespec(&ts, tp))
68751 return -EFAULT;
68752 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
68753
68754 oldfs = get_fs();
68755 set_fs(KERNEL_DS);
68756 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
68757 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
68758 set_fs(oldfs);
68759
68760 err = compat_put_timex(utp, &txc);
68761 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
68762 oldfs = get_fs();
68763 set_fs(KERNEL_DS);
68764 err = sys_clock_getres(which_clock,
68765 - (struct timespec __user *) &ts);
68766 + (struct timespec __force_user *) &ts);
68767 set_fs(oldfs);
68768 if (!err && tp && put_compat_timespec(&ts, tp))
68769 return -EFAULT;
68770 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
68771 long err;
68772 mm_segment_t oldfs;
68773 struct timespec tu;
68774 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
68775 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
68776
68777 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
68778 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
68779 oldfs = get_fs();
68780 set_fs(KERNEL_DS);
68781 err = clock_nanosleep_restart(restart);
68782 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
68783 oldfs = get_fs();
68784 set_fs(KERNEL_DS);
68785 err = sys_clock_nanosleep(which_clock, flags,
68786 - (struct timespec __user *) &in,
68787 - (struct timespec __user *) &out);
68788 + (struct timespec __force_user *) &in,
68789 + (struct timespec __force_user *) &out);
68790 set_fs(oldfs);
68791
68792 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
68793 diff --git a/kernel/configs.c b/kernel/configs.c
68794 index 42e8fa0..9e7406b 100644
68795 --- a/kernel/configs.c
68796 +++ b/kernel/configs.c
68797 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
68798 struct proc_dir_entry *entry;
68799
68800 /* create the current config file */
68801 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
68802 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
68803 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
68804 + &ikconfig_file_ops);
68805 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68806 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
68807 + &ikconfig_file_ops);
68808 +#endif
68809 +#else
68810 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
68811 &ikconfig_file_ops);
68812 +#endif
68813 +
68814 if (!entry)
68815 return -ENOMEM;
68816
68817 diff --git a/kernel/cred.c b/kernel/cred.c
68818 index 48cea3d..3476734 100644
68819 --- a/kernel/cred.c
68820 +++ b/kernel/cred.c
68821 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
68822 validate_creds(cred);
68823 alter_cred_subscribers(cred, -1);
68824 put_cred(cred);
68825 +
68826 +#ifdef CONFIG_GRKERNSEC_SETXID
68827 + cred = (struct cred *) tsk->delayed_cred;
68828 + if (cred != NULL) {
68829 + tsk->delayed_cred = NULL;
68830 + validate_creds(cred);
68831 + alter_cred_subscribers(cred, -1);
68832 + put_cred(cred);
68833 + }
68834 +#endif
68835 }
68836
68837 /**
68838 @@ -469,7 +479,7 @@ error_put:
68839 * Always returns 0 thus allowing this function to be tail-called at the end
68840 * of, say, sys_setgid().
68841 */
68842 -int commit_creds(struct cred *new)
68843 +static int __commit_creds(struct cred *new)
68844 {
68845 struct task_struct *task = current;
68846 const struct cred *old = task->real_cred;
68847 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
68848
68849 get_cred(new); /* we will require a ref for the subj creds too */
68850
68851 + gr_set_role_label(task, new->uid, new->gid);
68852 +
68853 /* dumpability changes */
68854 if (!uid_eq(old->euid, new->euid) ||
68855 !gid_eq(old->egid, new->egid) ||
68856 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
68857 put_cred(old);
68858 return 0;
68859 }
68860 +#ifdef CONFIG_GRKERNSEC_SETXID
68861 +extern int set_user(struct cred *new);
68862 +
68863 +void gr_delayed_cred_worker(void)
68864 +{
68865 + const struct cred *new = current->delayed_cred;
68866 + struct cred *ncred;
68867 +
68868 + current->delayed_cred = NULL;
68869 +
68870 + if (current_uid() && new != NULL) {
68871 + // from doing get_cred on it when queueing this
68872 + put_cred(new);
68873 + return;
68874 + } else if (new == NULL)
68875 + return;
68876 +
68877 + ncred = prepare_creds();
68878 + if (!ncred)
68879 + goto die;
68880 + // uids
68881 + ncred->uid = new->uid;
68882 + ncred->euid = new->euid;
68883 + ncred->suid = new->suid;
68884 + ncred->fsuid = new->fsuid;
68885 + // gids
68886 + ncred->gid = new->gid;
68887 + ncred->egid = new->egid;
68888 + ncred->sgid = new->sgid;
68889 + ncred->fsgid = new->fsgid;
68890 + // groups
68891 + if (set_groups(ncred, new->group_info) < 0) {
68892 + abort_creds(ncred);
68893 + goto die;
68894 + }
68895 + // caps
68896 + ncred->securebits = new->securebits;
68897 + ncred->cap_inheritable = new->cap_inheritable;
68898 + ncred->cap_permitted = new->cap_permitted;
68899 + ncred->cap_effective = new->cap_effective;
68900 + ncred->cap_bset = new->cap_bset;
68901 +
68902 + if (set_user(ncred)) {
68903 + abort_creds(ncred);
68904 + goto die;
68905 + }
68906 +
68907 + // from doing get_cred on it when queueing this
68908 + put_cred(new);
68909 +
68910 + __commit_creds(ncred);
68911 + return;
68912 +die:
68913 + // from doing get_cred on it when queueing this
68914 + put_cred(new);
68915 + do_group_exit(SIGKILL);
68916 +}
68917 +#endif
68918 +
68919 +int commit_creds(struct cred *new)
68920 +{
68921 +#ifdef CONFIG_GRKERNSEC_SETXID
68922 + int ret;
68923 + int schedule_it = 0;
68924 + struct task_struct *t;
68925 +
68926 + /* we won't get called with tasklist_lock held for writing
68927 + and interrupts disabled as the cred struct in that case is
68928 + init_cred
68929 + */
68930 + if (grsec_enable_setxid && !current_is_single_threaded() &&
68931 + !current_uid() && new->uid) {
68932 + schedule_it = 1;
68933 + }
68934 + ret = __commit_creds(new);
68935 + if (schedule_it) {
68936 + rcu_read_lock();
68937 + read_lock(&tasklist_lock);
68938 + for (t = next_thread(current); t != current;
68939 + t = next_thread(t)) {
68940 + if (t->delayed_cred == NULL) {
68941 + t->delayed_cred = get_cred(new);
68942 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
68943 + set_tsk_need_resched(t);
68944 + }
68945 + }
68946 + read_unlock(&tasklist_lock);
68947 + rcu_read_unlock();
68948 + }
68949 + return ret;
68950 +#else
68951 + return __commit_creds(new);
68952 +#endif
68953 +}
68954 +
68955 EXPORT_SYMBOL(commit_creds);
68956
68957 /**
68958 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
68959 index 9a61738..c5c8f3a 100644
68960 --- a/kernel/debug/debug_core.c
68961 +++ b/kernel/debug/debug_core.c
68962 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
68963 */
68964 static atomic_t masters_in_kgdb;
68965 static atomic_t slaves_in_kgdb;
68966 -static atomic_t kgdb_break_tasklet_var;
68967 +static atomic_unchecked_t kgdb_break_tasklet_var;
68968 atomic_t kgdb_setting_breakpoint;
68969
68970 struct task_struct *kgdb_usethread;
68971 @@ -132,7 +132,7 @@ int kgdb_single_step;
68972 static pid_t kgdb_sstep_pid;
68973
68974 /* to keep track of the CPU which is doing the single stepping*/
68975 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
68976 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
68977
68978 /*
68979 * If you are debugging a problem where roundup (the collection of
68980 @@ -540,7 +540,7 @@ return_normal:
68981 * kernel will only try for the value of sstep_tries before
68982 * giving up and continuing on.
68983 */
68984 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
68985 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
68986 (kgdb_info[cpu].task &&
68987 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
68988 atomic_set(&kgdb_active, -1);
68989 @@ -634,8 +634,8 @@ cpu_master_loop:
68990 }
68991
68992 kgdb_restore:
68993 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
68994 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
68995 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
68996 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
68997 if (kgdb_info[sstep_cpu].task)
68998 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
68999 else
69000 @@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
69001 static void kgdb_tasklet_bpt(unsigned long ing)
69002 {
69003 kgdb_breakpoint();
69004 - atomic_set(&kgdb_break_tasklet_var, 0);
69005 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
69006 }
69007
69008 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
69009
69010 void kgdb_schedule_breakpoint(void)
69011 {
69012 - if (atomic_read(&kgdb_break_tasklet_var) ||
69013 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
69014 atomic_read(&kgdb_active) != -1 ||
69015 atomic_read(&kgdb_setting_breakpoint))
69016 return;
69017 - atomic_inc(&kgdb_break_tasklet_var);
69018 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
69019 tasklet_schedule(&kgdb_tasklet_breakpoint);
69020 }
69021 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
69022 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
69023 index 8875254..7cf4928 100644
69024 --- a/kernel/debug/kdb/kdb_main.c
69025 +++ b/kernel/debug/kdb/kdb_main.c
69026 @@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
69027 continue;
69028
69029 kdb_printf("%-20s%8u 0x%p ", mod->name,
69030 - mod->core_size, (void *)mod);
69031 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
69032 #ifdef CONFIG_MODULE_UNLOAD
69033 kdb_printf("%4ld ", module_refcount(mod));
69034 #endif
69035 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
69036 kdb_printf(" (Loading)");
69037 else
69038 kdb_printf(" (Live)");
69039 - kdb_printf(" 0x%p", mod->module_core);
69040 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
69041
69042 #ifdef CONFIG_MODULE_UNLOAD
69043 {
69044 diff --git a/kernel/events/core.c b/kernel/events/core.c
69045 index dbccf83..8c66482 100644
69046 --- a/kernel/events/core.c
69047 +++ b/kernel/events/core.c
69048 @@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
69049 return 0;
69050 }
69051
69052 -static atomic64_t perf_event_id;
69053 +static atomic64_unchecked_t perf_event_id;
69054
69055 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
69056 enum event_type_t event_type);
69057 @@ -2668,7 +2668,7 @@ static void __perf_event_read(void *info)
69058
69059 static inline u64 perf_event_count(struct perf_event *event)
69060 {
69061 - return local64_read(&event->count) + atomic64_read(&event->child_count);
69062 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
69063 }
69064
69065 static u64 perf_event_read(struct perf_event *event)
69066 @@ -2998,9 +2998,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
69067 mutex_lock(&event->child_mutex);
69068 total += perf_event_read(event);
69069 *enabled += event->total_time_enabled +
69070 - atomic64_read(&event->child_total_time_enabled);
69071 + atomic64_read_unchecked(&event->child_total_time_enabled);
69072 *running += event->total_time_running +
69073 - atomic64_read(&event->child_total_time_running);
69074 + atomic64_read_unchecked(&event->child_total_time_running);
69075
69076 list_for_each_entry(child, &event->child_list, child_list) {
69077 total += perf_event_read(child);
69078 @@ -3403,10 +3403,10 @@ void perf_event_update_userpage(struct perf_event *event)
69079 userpg->offset -= local64_read(&event->hw.prev_count);
69080
69081 userpg->time_enabled = enabled +
69082 - atomic64_read(&event->child_total_time_enabled);
69083 + atomic64_read_unchecked(&event->child_total_time_enabled);
69084
69085 userpg->time_running = running +
69086 - atomic64_read(&event->child_total_time_running);
69087 + atomic64_read_unchecked(&event->child_total_time_running);
69088
69089 arch_perf_update_userpage(userpg, now);
69090
69091 @@ -3965,11 +3965,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
69092 values[n++] = perf_event_count(event);
69093 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
69094 values[n++] = enabled +
69095 - atomic64_read(&event->child_total_time_enabled);
69096 + atomic64_read_unchecked(&event->child_total_time_enabled);
69097 }
69098 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
69099 values[n++] = running +
69100 - atomic64_read(&event->child_total_time_running);
69101 + atomic64_read_unchecked(&event->child_total_time_running);
69102 }
69103 if (read_format & PERF_FORMAT_ID)
69104 values[n++] = primary_event_id(event);
69105 @@ -4712,12 +4712,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
69106 * need to add enough zero bytes after the string to handle
69107 * the 64bit alignment we do later.
69108 */
69109 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
69110 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
69111 if (!buf) {
69112 name = strncpy(tmp, "//enomem", sizeof(tmp));
69113 goto got_name;
69114 }
69115 - name = d_path(&file->f_path, buf, PATH_MAX);
69116 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
69117 if (IS_ERR(name)) {
69118 name = strncpy(tmp, "//toolong", sizeof(tmp));
69119 goto got_name;
69120 @@ -6156,7 +6156,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
69121 event->parent = parent_event;
69122
69123 event->ns = get_pid_ns(current->nsproxy->pid_ns);
69124 - event->id = atomic64_inc_return(&perf_event_id);
69125 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
69126
69127 event->state = PERF_EVENT_STATE_INACTIVE;
69128
69129 @@ -6774,10 +6774,10 @@ static void sync_child_event(struct perf_event *child_event,
69130 /*
69131 * Add back the child's count to the parent's count:
69132 */
69133 - atomic64_add(child_val, &parent_event->child_count);
69134 - atomic64_add(child_event->total_time_enabled,
69135 + atomic64_add_unchecked(child_val, &parent_event->child_count);
69136 + atomic64_add_unchecked(child_event->total_time_enabled,
69137 &parent_event->child_total_time_enabled);
69138 - atomic64_add(child_event->total_time_running,
69139 + atomic64_add_unchecked(child_event->total_time_running,
69140 &parent_event->child_total_time_running);
69141
69142 /*
69143 diff --git a/kernel/exit.c b/kernel/exit.c
69144 index 346616c..f103b28 100644
69145 --- a/kernel/exit.c
69146 +++ b/kernel/exit.c
69147 @@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
69148 struct task_struct *leader;
69149 int zap_leader;
69150 repeat:
69151 +#ifdef CONFIG_NET
69152 + gr_del_task_from_ip_table(p);
69153 +#endif
69154 +
69155 /* don't need to get the RCU readlock here - the process is dead and
69156 * can't be modifying its own credentials. But shut RCU-lockdep up */
69157 rcu_read_lock();
69158 @@ -394,7 +398,7 @@ int allow_signal(int sig)
69159 * know it'll be handled, so that they don't get converted to
69160 * SIGKILL or just silently dropped.
69161 */
69162 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
69163 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
69164 recalc_sigpending();
69165 spin_unlock_irq(&current->sighand->siglock);
69166 return 0;
69167 @@ -430,6 +434,9 @@ void daemonize(const char *name, ...)
69168 vsnprintf(current->comm, sizeof(current->comm), name, args);
69169 va_end(args);
69170
69171 + gr_put_exec_file(current);
69172 + gr_set_kernel_label(current);
69173 +
69174 /*
69175 * If we were started as result of loading a module, close all of the
69176 * user space pages. We don't need them, and if we didn't close them
69177 @@ -812,6 +819,8 @@ void do_exit(long code)
69178 struct task_struct *tsk = current;
69179 int group_dead;
69180
69181 + set_fs(USER_DS);
69182 +
69183 profile_task_exit(tsk);
69184
69185 WARN_ON(blk_needs_flush_plug(tsk));
69186 @@ -828,7 +837,6 @@ void do_exit(long code)
69187 * mm_release()->clear_child_tid() from writing to a user-controlled
69188 * kernel address.
69189 */
69190 - set_fs(USER_DS);
69191
69192 ptrace_event(PTRACE_EVENT_EXIT, code);
69193
69194 @@ -887,6 +895,9 @@ void do_exit(long code)
69195 tsk->exit_code = code;
69196 taskstats_exit(tsk, group_dead);
69197
69198 + gr_acl_handle_psacct(tsk, code);
69199 + gr_acl_handle_exit();
69200 +
69201 exit_mm(tsk);
69202
69203 if (group_dead)
69204 @@ -1007,7 +1018,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
69205 * Take down every thread in the group. This is called by fatal signals
69206 * as well as by sys_exit_group (below).
69207 */
69208 -void
69209 +__noreturn void
69210 do_group_exit(int exit_code)
69211 {
69212 struct signal_struct *sig = current->signal;
69213 diff --git a/kernel/fork.c b/kernel/fork.c
69214 index acc4cb6..b524cb5 100644
69215 --- a/kernel/fork.c
69216 +++ b/kernel/fork.c
69217 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
69218 *stackend = STACK_END_MAGIC; /* for overflow detection */
69219
69220 #ifdef CONFIG_CC_STACKPROTECTOR
69221 - tsk->stack_canary = get_random_int();
69222 + tsk->stack_canary = pax_get_random_long();
69223 #endif
69224
69225 /*
69226 @@ -344,13 +344,81 @@ free_tsk:
69227 }
69228
69229 #ifdef CONFIG_MMU
69230 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
69231 +{
69232 + struct vm_area_struct *tmp;
69233 + unsigned long charge;
69234 + struct mempolicy *pol;
69235 + struct file *file;
69236 +
69237 + charge = 0;
69238 + if (mpnt->vm_flags & VM_ACCOUNT) {
69239 + unsigned long len = vma_pages(mpnt);
69240 +
69241 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
69242 + goto fail_nomem;
69243 + charge = len;
69244 + }
69245 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69246 + if (!tmp)
69247 + goto fail_nomem;
69248 + *tmp = *mpnt;
69249 + tmp->vm_mm = mm;
69250 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
69251 + pol = mpol_dup(vma_policy(mpnt));
69252 + if (IS_ERR(pol))
69253 + goto fail_nomem_policy;
69254 + vma_set_policy(tmp, pol);
69255 + if (anon_vma_fork(tmp, mpnt))
69256 + goto fail_nomem_anon_vma_fork;
69257 + tmp->vm_flags &= ~VM_LOCKED;
69258 + tmp->vm_next = tmp->vm_prev = NULL;
69259 + tmp->vm_mirror = NULL;
69260 + file = tmp->vm_file;
69261 + if (file) {
69262 + struct inode *inode = file->f_path.dentry->d_inode;
69263 + struct address_space *mapping = file->f_mapping;
69264 +
69265 + get_file(file);
69266 + if (tmp->vm_flags & VM_DENYWRITE)
69267 + atomic_dec(&inode->i_writecount);
69268 + mutex_lock(&mapping->i_mmap_mutex);
69269 + if (tmp->vm_flags & VM_SHARED)
69270 + mapping->i_mmap_writable++;
69271 + flush_dcache_mmap_lock(mapping);
69272 + /* insert tmp into the share list, just after mpnt */
69273 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69274 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
69275 + else
69276 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
69277 + flush_dcache_mmap_unlock(mapping);
69278 + mutex_unlock(&mapping->i_mmap_mutex);
69279 + }
69280 +
69281 + /*
69282 + * Clear hugetlb-related page reserves for children. This only
69283 + * affects MAP_PRIVATE mappings. Faults generated by the child
69284 + * are not guaranteed to succeed, even if read-only
69285 + */
69286 + if (is_vm_hugetlb_page(tmp))
69287 + reset_vma_resv_huge_pages(tmp);
69288 +
69289 + return tmp;
69290 +
69291 +fail_nomem_anon_vma_fork:
69292 + mpol_put(pol);
69293 +fail_nomem_policy:
69294 + kmem_cache_free(vm_area_cachep, tmp);
69295 +fail_nomem:
69296 + vm_unacct_memory(charge);
69297 + return NULL;
69298 +}
69299 +
69300 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69301 {
69302 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
69303 struct rb_node **rb_link, *rb_parent;
69304 int retval;
69305 - unsigned long charge;
69306 - struct mempolicy *pol;
69307
69308 down_write(&oldmm->mmap_sem);
69309 flush_cache_dup_mm(oldmm);
69310 @@ -363,8 +431,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69311 mm->locked_vm = 0;
69312 mm->mmap = NULL;
69313 mm->mmap_cache = NULL;
69314 - mm->free_area_cache = oldmm->mmap_base;
69315 - mm->cached_hole_size = ~0UL;
69316 + mm->free_area_cache = oldmm->free_area_cache;
69317 + mm->cached_hole_size = oldmm->cached_hole_size;
69318 mm->map_count = 0;
69319 cpumask_clear(mm_cpumask(mm));
69320 mm->mm_rb = RB_ROOT;
69321 @@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69322
69323 prev = NULL;
69324 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
69325 - struct file *file;
69326 -
69327 if (mpnt->vm_flags & VM_DONTCOPY) {
69328 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
69329 -vma_pages(mpnt));
69330 continue;
69331 }
69332 - charge = 0;
69333 - if (mpnt->vm_flags & VM_ACCOUNT) {
69334 - unsigned long len = vma_pages(mpnt);
69335 -
69336 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
69337 - goto fail_nomem;
69338 - charge = len;
69339 - }
69340 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69341 - if (!tmp)
69342 - goto fail_nomem;
69343 - *tmp = *mpnt;
69344 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
69345 - pol = mpol_dup(vma_policy(mpnt));
69346 - retval = PTR_ERR(pol);
69347 - if (IS_ERR(pol))
69348 - goto fail_nomem_policy;
69349 - vma_set_policy(tmp, pol);
69350 - tmp->vm_mm = mm;
69351 - if (anon_vma_fork(tmp, mpnt))
69352 - goto fail_nomem_anon_vma_fork;
69353 - tmp->vm_flags &= ~VM_LOCKED;
69354 - tmp->vm_next = tmp->vm_prev = NULL;
69355 - file = tmp->vm_file;
69356 - if (file) {
69357 - struct inode *inode = file->f_path.dentry->d_inode;
69358 - struct address_space *mapping = file->f_mapping;
69359 -
69360 - get_file(file);
69361 - if (tmp->vm_flags & VM_DENYWRITE)
69362 - atomic_dec(&inode->i_writecount);
69363 - mutex_lock(&mapping->i_mmap_mutex);
69364 - if (tmp->vm_flags & VM_SHARED)
69365 - mapping->i_mmap_writable++;
69366 - flush_dcache_mmap_lock(mapping);
69367 - /* insert tmp into the share list, just after mpnt */
69368 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69369 - vma_nonlinear_insert(tmp,
69370 - &mapping->i_mmap_nonlinear);
69371 - else
69372 - vma_interval_tree_insert_after(tmp, mpnt,
69373 - &mapping->i_mmap);
69374 - flush_dcache_mmap_unlock(mapping);
69375 - mutex_unlock(&mapping->i_mmap_mutex);
69376 + tmp = dup_vma(mm, oldmm, mpnt);
69377 + if (!tmp) {
69378 + retval = -ENOMEM;
69379 + goto out;
69380 }
69381
69382 /*
69383 @@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69384 if (retval)
69385 goto out;
69386 }
69387 +
69388 +#ifdef CONFIG_PAX_SEGMEXEC
69389 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
69390 + struct vm_area_struct *mpnt_m;
69391 +
69392 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
69393 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
69394 +
69395 + if (!mpnt->vm_mirror)
69396 + continue;
69397 +
69398 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
69399 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
69400 + mpnt->vm_mirror = mpnt_m;
69401 + } else {
69402 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
69403 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
69404 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
69405 + mpnt->vm_mirror->vm_mirror = mpnt;
69406 + }
69407 + }
69408 + BUG_ON(mpnt_m);
69409 + }
69410 +#endif
69411 +
69412 /* a new mm has just been created */
69413 arch_dup_mmap(oldmm, mm);
69414 retval = 0;
69415 @@ -470,14 +521,6 @@ out:
69416 flush_tlb_mm(oldmm);
69417 up_write(&oldmm->mmap_sem);
69418 return retval;
69419 -fail_nomem_anon_vma_fork:
69420 - mpol_put(pol);
69421 -fail_nomem_policy:
69422 - kmem_cache_free(vm_area_cachep, tmp);
69423 -fail_nomem:
69424 - retval = -ENOMEM;
69425 - vm_unacct_memory(charge);
69426 - goto out;
69427 }
69428
69429 static inline int mm_alloc_pgd(struct mm_struct *mm)
69430 @@ -692,8 +735,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
69431 return ERR_PTR(err);
69432
69433 mm = get_task_mm(task);
69434 - if (mm && mm != current->mm &&
69435 - !ptrace_may_access(task, mode)) {
69436 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
69437 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
69438 mmput(mm);
69439 mm = ERR_PTR(-EACCES);
69440 }
69441 @@ -912,13 +955,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
69442 spin_unlock(&fs->lock);
69443 return -EAGAIN;
69444 }
69445 - fs->users++;
69446 + atomic_inc(&fs->users);
69447 spin_unlock(&fs->lock);
69448 return 0;
69449 }
69450 tsk->fs = copy_fs_struct(fs);
69451 if (!tsk->fs)
69452 return -ENOMEM;
69453 + /* Carry through gr_chroot_dentry and is_chrooted instead
69454 + of recomputing it here. Already copied when the task struct
69455 + is duplicated. This allows pivot_root to not be treated as
69456 + a chroot
69457 + */
69458 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
69459 +
69460 return 0;
69461 }
69462
69463 @@ -1183,6 +1233,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69464 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
69465 #endif
69466 retval = -EAGAIN;
69467 +
69468 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
69469 +
69470 if (atomic_read(&p->real_cred->user->processes) >=
69471 task_rlimit(p, RLIMIT_NPROC)) {
69472 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
69473 @@ -1422,6 +1475,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69474 goto bad_fork_free_pid;
69475 }
69476
69477 + /* synchronizes with gr_set_acls()
69478 + we need to call this past the point of no return for fork()
69479 + */
69480 + gr_copy_label(p);
69481 +
69482 if (clone_flags & CLONE_THREAD) {
69483 current->signal->nr_threads++;
69484 atomic_inc(&current->signal->live);
69485 @@ -1505,6 +1563,8 @@ bad_fork_cleanup_count:
69486 bad_fork_free:
69487 free_task(p);
69488 fork_out:
69489 + gr_log_forkfail(retval);
69490 +
69491 return ERR_PTR(retval);
69492 }
69493
69494 @@ -1605,6 +1665,8 @@ long do_fork(unsigned long clone_flags,
69495 if (clone_flags & CLONE_PARENT_SETTID)
69496 put_user(nr, parent_tidptr);
69497
69498 + gr_handle_brute_check();
69499 +
69500 if (clone_flags & CLONE_VFORK) {
69501 p->vfork_done = &vfork;
69502 init_completion(&vfork);
69503 @@ -1714,7 +1776,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
69504 return 0;
69505
69506 /* don't need lock here; in the worst case we'll do useless copy */
69507 - if (fs->users == 1)
69508 + if (atomic_read(&fs->users) == 1)
69509 return 0;
69510
69511 *new_fsp = copy_fs_struct(fs);
69512 @@ -1803,7 +1865,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
69513 fs = current->fs;
69514 spin_lock(&fs->lock);
69515 current->fs = new_fs;
69516 - if (--fs->users)
69517 + gr_set_chroot_entries(current, &current->fs->root);
69518 + if (atomic_dec_return(&fs->users))
69519 new_fs = NULL;
69520 else
69521 new_fs = fs;
69522 diff --git a/kernel/futex.c b/kernel/futex.c
69523 index 19eb089..b8c65ea 100644
69524 --- a/kernel/futex.c
69525 +++ b/kernel/futex.c
69526 @@ -54,6 +54,7 @@
69527 #include <linux/mount.h>
69528 #include <linux/pagemap.h>
69529 #include <linux/syscalls.h>
69530 +#include <linux/ptrace.h>
69531 #include <linux/signal.h>
69532 #include <linux/export.h>
69533 #include <linux/magic.h>
69534 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
69535 struct page *page, *page_head;
69536 int err, ro = 0;
69537
69538 +#ifdef CONFIG_PAX_SEGMEXEC
69539 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
69540 + return -EFAULT;
69541 +#endif
69542 +
69543 /*
69544 * The futex address must be "naturally" aligned.
69545 */
69546 @@ -2733,6 +2739,7 @@ static int __init futex_init(void)
69547 {
69548 u32 curval;
69549 int i;
69550 + mm_segment_t oldfs;
69551
69552 /*
69553 * This will fail and we want it. Some arch implementations do
69554 @@ -2744,8 +2751,11 @@ static int __init futex_init(void)
69555 * implementation, the non-functional ones will return
69556 * -ENOSYS.
69557 */
69558 + oldfs = get_fs();
69559 + set_fs(USER_DS);
69560 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
69561 futex_cmpxchg_enabled = 1;
69562 + set_fs(oldfs);
69563
69564 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
69565 plist_head_init(&futex_queues[i].chain);
69566 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
69567 index 9b22d03..6295b62 100644
69568 --- a/kernel/gcov/base.c
69569 +++ b/kernel/gcov/base.c
69570 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
69571 }
69572
69573 #ifdef CONFIG_MODULES
69574 -static inline int within(void *addr, void *start, unsigned long size)
69575 -{
69576 - return ((addr >= start) && (addr < start + size));
69577 -}
69578 -
69579 /* Update list and generate events when modules are unloaded. */
69580 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69581 void *data)
69582 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69583 prev = NULL;
69584 /* Remove entries located in module from linked list. */
69585 for (info = gcov_info_head; info; info = info->next) {
69586 - if (within(info, mod->module_core, mod->core_size)) {
69587 + if (within_module_core_rw((unsigned long)info, mod)) {
69588 if (prev)
69589 prev->next = info->next;
69590 else
69591 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
69592 index 6db7a5e..25b6648 100644
69593 --- a/kernel/hrtimer.c
69594 +++ b/kernel/hrtimer.c
69595 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
69596 local_irq_restore(flags);
69597 }
69598
69599 -static void run_hrtimer_softirq(struct softirq_action *h)
69600 +static void run_hrtimer_softirq(void)
69601 {
69602 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
69603
69604 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
69605 index 60f48fa..7f3a770 100644
69606 --- a/kernel/jump_label.c
69607 +++ b/kernel/jump_label.c
69608 @@ -13,6 +13,7 @@
69609 #include <linux/sort.h>
69610 #include <linux/err.h>
69611 #include <linux/static_key.h>
69612 +#include <linux/mm.h>
69613
69614 #ifdef HAVE_JUMP_LABEL
69615
69616 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
69617
69618 size = (((unsigned long)stop - (unsigned long)start)
69619 / sizeof(struct jump_entry));
69620 + pax_open_kernel();
69621 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
69622 + pax_close_kernel();
69623 }
69624
69625 static void jump_label_update(struct static_key *key, int enable);
69626 @@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
69627 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
69628 struct jump_entry *iter;
69629
69630 + pax_open_kernel();
69631 for (iter = iter_start; iter < iter_stop; iter++) {
69632 if (within_module_init(iter->code, mod))
69633 iter->code = 0;
69634 }
69635 + pax_close_kernel();
69636 }
69637
69638 static int
69639 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
69640 index 2169fee..45c017a 100644
69641 --- a/kernel/kallsyms.c
69642 +++ b/kernel/kallsyms.c
69643 @@ -11,6 +11,9 @@
69644 * Changed the compression method from stem compression to "table lookup"
69645 * compression (see scripts/kallsyms.c for a more complete description)
69646 */
69647 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69648 +#define __INCLUDED_BY_HIDESYM 1
69649 +#endif
69650 #include <linux/kallsyms.h>
69651 #include <linux/module.h>
69652 #include <linux/init.h>
69653 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
69654
69655 static inline int is_kernel_inittext(unsigned long addr)
69656 {
69657 + if (system_state != SYSTEM_BOOTING)
69658 + return 0;
69659 +
69660 if (addr >= (unsigned long)_sinittext
69661 && addr <= (unsigned long)_einittext)
69662 return 1;
69663 return 0;
69664 }
69665
69666 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69667 +#ifdef CONFIG_MODULES
69668 +static inline int is_module_text(unsigned long addr)
69669 +{
69670 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
69671 + return 1;
69672 +
69673 + addr = ktla_ktva(addr);
69674 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
69675 +}
69676 +#else
69677 +static inline int is_module_text(unsigned long addr)
69678 +{
69679 + return 0;
69680 +}
69681 +#endif
69682 +#endif
69683 +
69684 static inline int is_kernel_text(unsigned long addr)
69685 {
69686 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
69687 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
69688
69689 static inline int is_kernel(unsigned long addr)
69690 {
69691 +
69692 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69693 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
69694 + return 1;
69695 +
69696 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
69697 +#else
69698 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
69699 +#endif
69700 +
69701 return 1;
69702 return in_gate_area_no_mm(addr);
69703 }
69704
69705 static int is_ksym_addr(unsigned long addr)
69706 {
69707 +
69708 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69709 + if (is_module_text(addr))
69710 + return 0;
69711 +#endif
69712 +
69713 if (all_var)
69714 return is_kernel(addr);
69715
69716 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
69717
69718 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
69719 {
69720 - iter->name[0] = '\0';
69721 iter->nameoff = get_symbol_offset(new_pos);
69722 iter->pos = new_pos;
69723 }
69724 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
69725 {
69726 struct kallsym_iter *iter = m->private;
69727
69728 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69729 + if (current_uid())
69730 + return 0;
69731 +#endif
69732 +
69733 /* Some debugging symbols have no name. Ignore them. */
69734 if (!iter->name[0])
69735 return 0;
69736 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
69737 */
69738 type = iter->exported ? toupper(iter->type) :
69739 tolower(iter->type);
69740 +
69741 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
69742 type, iter->name, iter->module_name);
69743 } else
69744 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
69745 struct kallsym_iter *iter;
69746 int ret;
69747
69748 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
69749 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
69750 if (!iter)
69751 return -ENOMEM;
69752 reset_iter(iter, 0);
69753 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
69754 index 30b7b22..c726387 100644
69755 --- a/kernel/kcmp.c
69756 +++ b/kernel/kcmp.c
69757 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
69758 struct task_struct *task1, *task2;
69759 int ret;
69760
69761 +#ifdef CONFIG_GRKERNSEC
69762 + return -ENOSYS;
69763 +#endif
69764 +
69765 rcu_read_lock();
69766
69767 /*
69768 diff --git a/kernel/kexec.c b/kernel/kexec.c
69769 index 5e4bd78..00c5b91 100644
69770 --- a/kernel/kexec.c
69771 +++ b/kernel/kexec.c
69772 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
69773 unsigned long flags)
69774 {
69775 struct compat_kexec_segment in;
69776 - struct kexec_segment out, __user *ksegments;
69777 + struct kexec_segment out;
69778 + struct kexec_segment __user *ksegments;
69779 unsigned long i, result;
69780
69781 /* Don't allow clients that don't understand the native
69782 diff --git a/kernel/kmod.c b/kernel/kmod.c
69783 index 1c317e3..4a92a55 100644
69784 --- a/kernel/kmod.c
69785 +++ b/kernel/kmod.c
69786 @@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
69787 kfree(info->argv);
69788 }
69789
69790 -static int call_modprobe(char *module_name, int wait)
69791 +static int call_modprobe(char *module_name, char *module_param, int wait)
69792 {
69793 static char *envp[] = {
69794 "HOME=/",
69795 @@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
69796 NULL
69797 };
69798
69799 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
69800 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
69801 if (!argv)
69802 goto out;
69803
69804 @@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
69805 argv[1] = "-q";
69806 argv[2] = "--";
69807 argv[3] = module_name; /* check free_modprobe_argv() */
69808 - argv[4] = NULL;
69809 + argv[4] = module_param;
69810 + argv[5] = NULL;
69811
69812 return call_usermodehelper_fns(modprobe_path, argv, envp,
69813 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
69814 @@ -120,9 +121,8 @@ out:
69815 * If module auto-loading support is disabled then this function
69816 * becomes a no-operation.
69817 */
69818 -int __request_module(bool wait, const char *fmt, ...)
69819 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
69820 {
69821 - va_list args;
69822 char module_name[MODULE_NAME_LEN];
69823 unsigned int max_modprobes;
69824 int ret;
69825 @@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
69826 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
69827 static int kmod_loop_msg;
69828
69829 - va_start(args, fmt);
69830 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
69831 - va_end(args);
69832 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
69833 if (ret >= MODULE_NAME_LEN)
69834 return -ENAMETOOLONG;
69835
69836 @@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
69837 if (ret)
69838 return ret;
69839
69840 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
69841 + if (!current_uid()) {
69842 + /* hack to workaround consolekit/udisks stupidity */
69843 + read_lock(&tasklist_lock);
69844 + if (!strcmp(current->comm, "mount") &&
69845 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
69846 + read_unlock(&tasklist_lock);
69847 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
69848 + return -EPERM;
69849 + }
69850 + read_unlock(&tasklist_lock);
69851 + }
69852 +#endif
69853 +
69854 /* If modprobe needs a service that is in a module, we get a recursive
69855 * loop. Limit the number of running kmod threads to max_threads/2 or
69856 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
69857 @@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
69858
69859 trace_module_request(module_name, wait, _RET_IP_);
69860
69861 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
69862 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
69863
69864 atomic_dec(&kmod_concurrent);
69865 return ret;
69866 }
69867 +
69868 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
69869 +{
69870 + va_list args;
69871 + int ret;
69872 +
69873 + va_start(args, fmt);
69874 + ret = ____request_module(wait, module_param, fmt, args);
69875 + va_end(args);
69876 +
69877 + return ret;
69878 +}
69879 +
69880 +int __request_module(bool wait, const char *fmt, ...)
69881 +{
69882 + va_list args;
69883 + int ret;
69884 +
69885 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
69886 + if (current_uid()) {
69887 + char module_param[MODULE_NAME_LEN];
69888 +
69889 + memset(module_param, 0, sizeof(module_param));
69890 +
69891 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
69892 +
69893 + va_start(args, fmt);
69894 + ret = ____request_module(wait, module_param, fmt, args);
69895 + va_end(args);
69896 +
69897 + return ret;
69898 + }
69899 +#endif
69900 +
69901 + va_start(args, fmt);
69902 + ret = ____request_module(wait, NULL, fmt, args);
69903 + va_end(args);
69904 +
69905 + return ret;
69906 +}
69907 +
69908 EXPORT_SYMBOL(__request_module);
69909 #endif /* CONFIG_MODULES */
69910
69911 @@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
69912 *
69913 * Thus the __user pointer cast is valid here.
69914 */
69915 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
69916 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
69917
69918 /*
69919 * If ret is 0, either ____call_usermodehelper failed and the
69920 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
69921 index 098f396..fe85ff1 100644
69922 --- a/kernel/kprobes.c
69923 +++ b/kernel/kprobes.c
69924 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
69925 * kernel image and loaded module images reside. This is required
69926 * so x86_64 can correctly handle the %rip-relative fixups.
69927 */
69928 - kip->insns = module_alloc(PAGE_SIZE);
69929 + kip->insns = module_alloc_exec(PAGE_SIZE);
69930 if (!kip->insns) {
69931 kfree(kip);
69932 return NULL;
69933 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
69934 */
69935 if (!list_is_singular(&kip->list)) {
69936 list_del(&kip->list);
69937 - module_free(NULL, kip->insns);
69938 + module_free_exec(NULL, kip->insns);
69939 kfree(kip);
69940 }
69941 return 1;
69942 @@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
69943 {
69944 int i, err = 0;
69945 unsigned long offset = 0, size = 0;
69946 - char *modname, namebuf[128];
69947 + char *modname, namebuf[KSYM_NAME_LEN];
69948 const char *symbol_name;
69949 void *addr;
69950 struct kprobe_blackpoint *kb;
69951 @@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
69952 kprobe_type = "k";
69953
69954 if (sym)
69955 - seq_printf(pi, "%p %s %s+0x%x %s ",
69956 + seq_printf(pi, "%pK %s %s+0x%x %s ",
69957 p->addr, kprobe_type, sym, offset,
69958 (modname ? modname : " "));
69959 else
69960 - seq_printf(pi, "%p %s %p ",
69961 + seq_printf(pi, "%pK %s %pK ",
69962 p->addr, kprobe_type, p->addr);
69963
69964 if (!pp)
69965 @@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
69966 const char *sym = NULL;
69967 unsigned int i = *(loff_t *) v;
69968 unsigned long offset = 0;
69969 - char *modname, namebuf[128];
69970 + char *modname, namebuf[KSYM_NAME_LEN];
69971
69972 head = &kprobe_table[i];
69973 preempt_disable();
69974 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
69975 index 4e316e1..5501eef 100644
69976 --- a/kernel/ksysfs.c
69977 +++ b/kernel/ksysfs.c
69978 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
69979 {
69980 if (count+1 > UEVENT_HELPER_PATH_LEN)
69981 return -ENOENT;
69982 + if (!capable(CAP_SYS_ADMIN))
69983 + return -EPERM;
69984 memcpy(uevent_helper, buf, count);
69985 uevent_helper[count] = '\0';
69986 if (count && uevent_helper[count-1] == '\n')
69987 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
69988 index 7981e5b..7f2105c 100644
69989 --- a/kernel/lockdep.c
69990 +++ b/kernel/lockdep.c
69991 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
69992 end = (unsigned long) &_end,
69993 addr = (unsigned long) obj;
69994
69995 +#ifdef CONFIG_PAX_KERNEXEC
69996 + start = ktla_ktva(start);
69997 +#endif
69998 +
69999 /*
70000 * static variable?
70001 */
70002 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
70003 if (!static_obj(lock->key)) {
70004 debug_locks_off();
70005 printk("INFO: trying to register non-static key.\n");
70006 + printk("lock:%pS key:%pS.\n", lock, lock->key);
70007 printk("the code is fine but needs lockdep annotation.\n");
70008 printk("turning off the locking correctness validator.\n");
70009 dump_stack();
70010 @@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
70011 if (!class)
70012 return 0;
70013 }
70014 - atomic_inc((atomic_t *)&class->ops);
70015 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
70016 if (very_verbose(class)) {
70017 printk("\nacquire class [%p] %s", class->key, class->name);
70018 if (class->name_version > 1)
70019 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
70020 index 91c32a0..7b88d63 100644
70021 --- a/kernel/lockdep_proc.c
70022 +++ b/kernel/lockdep_proc.c
70023 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
70024
70025 static void print_name(struct seq_file *m, struct lock_class *class)
70026 {
70027 - char str[128];
70028 + char str[KSYM_NAME_LEN];
70029 const char *name = class->name;
70030
70031 if (!name) {
70032 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
70033 return 0;
70034 }
70035
70036 - seq_printf(m, "%p", class->key);
70037 + seq_printf(m, "%pK", class->key);
70038 #ifdef CONFIG_DEBUG_LOCKDEP
70039 seq_printf(m, " OPS:%8ld", class->ops);
70040 #endif
70041 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
70042
70043 list_for_each_entry(entry, &class->locks_after, entry) {
70044 if (entry->distance == 1) {
70045 - seq_printf(m, " -> [%p] ", entry->class->key);
70046 + seq_printf(m, " -> [%pK] ", entry->class->key);
70047 print_name(m, entry->class);
70048 seq_puts(m, "\n");
70049 }
70050 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
70051 if (!class->key)
70052 continue;
70053
70054 - seq_printf(m, "[%p] ", class->key);
70055 + seq_printf(m, "[%pK] ", class->key);
70056 print_name(m, class);
70057 seq_puts(m, "\n");
70058 }
70059 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70060 if (!i)
70061 seq_line(m, '-', 40-namelen, namelen);
70062
70063 - snprintf(ip, sizeof(ip), "[<%p>]",
70064 + snprintf(ip, sizeof(ip), "[<%pK>]",
70065 (void *)class->contention_point[i]);
70066 seq_printf(m, "%40s %14lu %29s %pS\n",
70067 name, stats->contention_point[i],
70068 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70069 if (!i)
70070 seq_line(m, '-', 40-namelen, namelen);
70071
70072 - snprintf(ip, sizeof(ip), "[<%p>]",
70073 + snprintf(ip, sizeof(ip), "[<%pK>]",
70074 (void *)class->contending_point[i]);
70075 seq_printf(m, "%40s %14lu %29s %pS\n",
70076 name, stats->contending_point[i],
70077 diff --git a/kernel/module.c b/kernel/module.c
70078 index 3e544f4..096cb73 100644
70079 --- a/kernel/module.c
70080 +++ b/kernel/module.c
70081 @@ -59,6 +59,7 @@
70082 #include <linux/pfn.h>
70083 #include <linux/bsearch.h>
70084 #include <linux/fips.h>
70085 +#include <linux/grsecurity.h>
70086 #include "module-internal.h"
70087
70088 #define CREATE_TRACE_POINTS
70089 @@ -153,7 +154,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
70090
70091 /* Bounds of module allocation, for speeding __module_address.
70092 * Protected by module_mutex. */
70093 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
70094 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
70095 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
70096
70097 int register_module_notifier(struct notifier_block * nb)
70098 {
70099 @@ -319,7 +321,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70100 return true;
70101
70102 list_for_each_entry_rcu(mod, &modules, list) {
70103 - struct symsearch arr[] = {
70104 + struct symsearch modarr[] = {
70105 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
70106 NOT_GPL_ONLY, false },
70107 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
70108 @@ -344,7 +346,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70109 if (mod->state == MODULE_STATE_UNFORMED)
70110 continue;
70111
70112 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
70113 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
70114 return true;
70115 }
70116 return false;
70117 @@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
70118 static int percpu_modalloc(struct module *mod,
70119 unsigned long size, unsigned long align)
70120 {
70121 - if (align > PAGE_SIZE) {
70122 + if (align-1 >= PAGE_SIZE) {
70123 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
70124 mod->name, align, PAGE_SIZE);
70125 align = PAGE_SIZE;
70126 @@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
70127 static ssize_t show_coresize(struct module_attribute *mattr,
70128 struct module_kobject *mk, char *buffer)
70129 {
70130 - return sprintf(buffer, "%u\n", mk->mod->core_size);
70131 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
70132 }
70133
70134 static struct module_attribute modinfo_coresize =
70135 @@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
70136 static ssize_t show_initsize(struct module_attribute *mattr,
70137 struct module_kobject *mk, char *buffer)
70138 {
70139 - return sprintf(buffer, "%u\n", mk->mod->init_size);
70140 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
70141 }
70142
70143 static struct module_attribute modinfo_initsize =
70144 @@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
70145 */
70146 #ifdef CONFIG_SYSFS
70147
70148 -#ifdef CONFIG_KALLSYMS
70149 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70150 static inline bool sect_empty(const Elf_Shdr *sect)
70151 {
70152 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
70153 @@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
70154
70155 static void unset_module_core_ro_nx(struct module *mod)
70156 {
70157 - set_page_attributes(mod->module_core + mod->core_text_size,
70158 - mod->module_core + mod->core_size,
70159 + set_page_attributes(mod->module_core_rw,
70160 + mod->module_core_rw + mod->core_size_rw,
70161 set_memory_x);
70162 - set_page_attributes(mod->module_core,
70163 - mod->module_core + mod->core_ro_size,
70164 + set_page_attributes(mod->module_core_rx,
70165 + mod->module_core_rx + mod->core_size_rx,
70166 set_memory_rw);
70167 }
70168
70169 static void unset_module_init_ro_nx(struct module *mod)
70170 {
70171 - set_page_attributes(mod->module_init + mod->init_text_size,
70172 - mod->module_init + mod->init_size,
70173 + set_page_attributes(mod->module_init_rw,
70174 + mod->module_init_rw + mod->init_size_rw,
70175 set_memory_x);
70176 - set_page_attributes(mod->module_init,
70177 - mod->module_init + mod->init_ro_size,
70178 + set_page_attributes(mod->module_init_rx,
70179 + mod->module_init_rx + mod->init_size_rx,
70180 set_memory_rw);
70181 }
70182
70183 @@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
70184 list_for_each_entry_rcu(mod, &modules, list) {
70185 if (mod->state == MODULE_STATE_UNFORMED)
70186 continue;
70187 - if ((mod->module_core) && (mod->core_text_size)) {
70188 - set_page_attributes(mod->module_core,
70189 - mod->module_core + mod->core_text_size,
70190 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
70191 + set_page_attributes(mod->module_core_rx,
70192 + mod->module_core_rx + mod->core_size_rx,
70193 set_memory_rw);
70194 }
70195 - if ((mod->module_init) && (mod->init_text_size)) {
70196 - set_page_attributes(mod->module_init,
70197 - mod->module_init + mod->init_text_size,
70198 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
70199 + set_page_attributes(mod->module_init_rx,
70200 + mod->module_init_rx + mod->init_size_rx,
70201 set_memory_rw);
70202 }
70203 }
70204 @@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
70205 list_for_each_entry_rcu(mod, &modules, list) {
70206 if (mod->state == MODULE_STATE_UNFORMED)
70207 continue;
70208 - if ((mod->module_core) && (mod->core_text_size)) {
70209 - set_page_attributes(mod->module_core,
70210 - mod->module_core + mod->core_text_size,
70211 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
70212 + set_page_attributes(mod->module_core_rx,
70213 + mod->module_core_rx + mod->core_size_rx,
70214 set_memory_ro);
70215 }
70216 - if ((mod->module_init) && (mod->init_text_size)) {
70217 - set_page_attributes(mod->module_init,
70218 - mod->module_init + mod->init_text_size,
70219 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
70220 + set_page_attributes(mod->module_init_rx,
70221 + mod->module_init_rx + mod->init_size_rx,
70222 set_memory_ro);
70223 }
70224 }
70225 @@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
70226
70227 /* This may be NULL, but that's OK */
70228 unset_module_init_ro_nx(mod);
70229 - module_free(mod, mod->module_init);
70230 + module_free(mod, mod->module_init_rw);
70231 + module_free_exec(mod, mod->module_init_rx);
70232 kfree(mod->args);
70233 percpu_modfree(mod);
70234
70235 /* Free lock-classes: */
70236 - lockdep_free_key_range(mod->module_core, mod->core_size);
70237 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
70238 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
70239
70240 /* Finally, free the core (containing the module structure) */
70241 unset_module_core_ro_nx(mod);
70242 - module_free(mod, mod->module_core);
70243 + module_free_exec(mod, mod->module_core_rx);
70244 + module_free(mod, mod->module_core_rw);
70245
70246 #ifdef CONFIG_MPU
70247 update_protections(current->mm);
70248 @@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70249 int ret = 0;
70250 const struct kernel_symbol *ksym;
70251
70252 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70253 + int is_fs_load = 0;
70254 + int register_filesystem_found = 0;
70255 + char *p;
70256 +
70257 + p = strstr(mod->args, "grsec_modharden_fs");
70258 + if (p) {
70259 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
70260 + /* copy \0 as well */
70261 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
70262 + is_fs_load = 1;
70263 + }
70264 +#endif
70265 +
70266 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
70267 const char *name = info->strtab + sym[i].st_name;
70268
70269 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70270 + /* it's a real shame this will never get ripped and copied
70271 + upstream! ;(
70272 + */
70273 + if (is_fs_load && !strcmp(name, "register_filesystem"))
70274 + register_filesystem_found = 1;
70275 +#endif
70276 +
70277 switch (sym[i].st_shndx) {
70278 case SHN_COMMON:
70279 /* We compiled with -fno-common. These are not
70280 @@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70281 ksym = resolve_symbol_wait(mod, info, name);
70282 /* Ok if resolved. */
70283 if (ksym && !IS_ERR(ksym)) {
70284 + pax_open_kernel();
70285 sym[i].st_value = ksym->value;
70286 + pax_close_kernel();
70287 break;
70288 }
70289
70290 @@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70291 secbase = (unsigned long)mod_percpu(mod);
70292 else
70293 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
70294 + pax_open_kernel();
70295 sym[i].st_value += secbase;
70296 + pax_close_kernel();
70297 break;
70298 }
70299 }
70300
70301 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70302 + if (is_fs_load && !register_filesystem_found) {
70303 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
70304 + ret = -EPERM;
70305 + }
70306 +#endif
70307 +
70308 return ret;
70309 }
70310
70311 @@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
70312 || s->sh_entsize != ~0UL
70313 || strstarts(sname, ".init"))
70314 continue;
70315 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
70316 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70317 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
70318 + else
70319 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
70320 pr_debug("\t%s\n", sname);
70321 }
70322 - switch (m) {
70323 - case 0: /* executable */
70324 - mod->core_size = debug_align(mod->core_size);
70325 - mod->core_text_size = mod->core_size;
70326 - break;
70327 - case 1: /* RO: text and ro-data */
70328 - mod->core_size = debug_align(mod->core_size);
70329 - mod->core_ro_size = mod->core_size;
70330 - break;
70331 - case 3: /* whole core */
70332 - mod->core_size = debug_align(mod->core_size);
70333 - break;
70334 - }
70335 }
70336
70337 pr_debug("Init section allocation order:\n");
70338 @@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
70339 || s->sh_entsize != ~0UL
70340 || !strstarts(sname, ".init"))
70341 continue;
70342 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
70343 - | INIT_OFFSET_MASK);
70344 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70345 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
70346 + else
70347 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
70348 + s->sh_entsize |= INIT_OFFSET_MASK;
70349 pr_debug("\t%s\n", sname);
70350 }
70351 - switch (m) {
70352 - case 0: /* executable */
70353 - mod->init_size = debug_align(mod->init_size);
70354 - mod->init_text_size = mod->init_size;
70355 - break;
70356 - case 1: /* RO: text and ro-data */
70357 - mod->init_size = debug_align(mod->init_size);
70358 - mod->init_ro_size = mod->init_size;
70359 - break;
70360 - case 3: /* whole init */
70361 - mod->init_size = debug_align(mod->init_size);
70362 - break;
70363 - }
70364 }
70365 }
70366
70367 @@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70368
70369 /* Put symbol section at end of init part of module. */
70370 symsect->sh_flags |= SHF_ALLOC;
70371 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
70372 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
70373 info->index.sym) | INIT_OFFSET_MASK;
70374 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
70375
70376 @@ -2326,13 +2344,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70377 }
70378
70379 /* Append room for core symbols at end of core part. */
70380 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
70381 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
70382 - mod->core_size += strtab_size;
70383 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
70384 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
70385 + mod->core_size_rx += strtab_size;
70386
70387 /* Put string table section at end of init part of module. */
70388 strsect->sh_flags |= SHF_ALLOC;
70389 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
70390 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
70391 info->index.str) | INIT_OFFSET_MASK;
70392 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
70393 }
70394 @@ -2350,12 +2368,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70395 /* Make sure we get permanent strtab: don't use info->strtab. */
70396 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
70397
70398 + pax_open_kernel();
70399 +
70400 /* Set types up while we still have access to sections. */
70401 for (i = 0; i < mod->num_symtab; i++)
70402 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
70403
70404 - mod->core_symtab = dst = mod->module_core + info->symoffs;
70405 - mod->core_strtab = s = mod->module_core + info->stroffs;
70406 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
70407 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
70408 src = mod->symtab;
70409 *s++ = 0;
70410 for (ndst = i = 0; i < mod->num_symtab; i++) {
70411 @@ -2368,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70412 }
70413 }
70414 mod->core_num_syms = ndst;
70415 +
70416 + pax_close_kernel();
70417 }
70418 #else
70419 static inline void layout_symtab(struct module *mod, struct load_info *info)
70420 @@ -2401,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
70421 return size == 0 ? NULL : vmalloc_exec(size);
70422 }
70423
70424 -static void *module_alloc_update_bounds(unsigned long size)
70425 +static void *module_alloc_update_bounds_rw(unsigned long size)
70426 {
70427 void *ret = module_alloc(size);
70428
70429 if (ret) {
70430 mutex_lock(&module_mutex);
70431 /* Update module bounds. */
70432 - if ((unsigned long)ret < module_addr_min)
70433 - module_addr_min = (unsigned long)ret;
70434 - if ((unsigned long)ret + size > module_addr_max)
70435 - module_addr_max = (unsigned long)ret + size;
70436 + if ((unsigned long)ret < module_addr_min_rw)
70437 + module_addr_min_rw = (unsigned long)ret;
70438 + if ((unsigned long)ret + size > module_addr_max_rw)
70439 + module_addr_max_rw = (unsigned long)ret + size;
70440 + mutex_unlock(&module_mutex);
70441 + }
70442 + return ret;
70443 +}
70444 +
70445 +static void *module_alloc_update_bounds_rx(unsigned long size)
70446 +{
70447 + void *ret = module_alloc_exec(size);
70448 +
70449 + if (ret) {
70450 + mutex_lock(&module_mutex);
70451 + /* Update module bounds. */
70452 + if ((unsigned long)ret < module_addr_min_rx)
70453 + module_addr_min_rx = (unsigned long)ret;
70454 + if ((unsigned long)ret + size > module_addr_max_rx)
70455 + module_addr_max_rx = (unsigned long)ret + size;
70456 mutex_unlock(&module_mutex);
70457 }
70458 return ret;
70459 @@ -2630,8 +2668,14 @@ static struct module *setup_load_info(struct load_info *info)
70460 static int check_modinfo(struct module *mod, struct load_info *info)
70461 {
70462 const char *modmagic = get_modinfo(info, "vermagic");
70463 + const char *license = get_modinfo(info, "license");
70464 int err;
70465
70466 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
70467 + if (!license || !license_is_gpl_compatible(license))
70468 + return -ENOEXEC;
70469 +#endif
70470 +
70471 /* This is allowed: modprobe --force will invalidate it. */
70472 if (!modmagic) {
70473 err = try_to_force_load(mod, "bad vermagic");
70474 @@ -2654,7 +2698,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
70475 }
70476
70477 /* Set up license info based on the info section */
70478 - set_license(mod, get_modinfo(info, "license"));
70479 + set_license(mod, license);
70480
70481 return 0;
70482 }
70483 @@ -2748,7 +2792,7 @@ static int move_module(struct module *mod, struct load_info *info)
70484 void *ptr;
70485
70486 /* Do the allocs. */
70487 - ptr = module_alloc_update_bounds(mod->core_size);
70488 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
70489 /*
70490 * The pointer to this block is stored in the module structure
70491 * which is inside the block. Just mark it as not being a
70492 @@ -2758,23 +2802,50 @@ static int move_module(struct module *mod, struct load_info *info)
70493 if (!ptr)
70494 return -ENOMEM;
70495
70496 - memset(ptr, 0, mod->core_size);
70497 - mod->module_core = ptr;
70498 + memset(ptr, 0, mod->core_size_rw);
70499 + mod->module_core_rw = ptr;
70500
70501 - ptr = module_alloc_update_bounds(mod->init_size);
70502 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
70503 /*
70504 * The pointer to this block is stored in the module structure
70505 * which is inside the block. This block doesn't need to be
70506 * scanned as it contains data and code that will be freed
70507 * after the module is initialized.
70508 */
70509 - kmemleak_ignore(ptr);
70510 - if (!ptr && mod->init_size) {
70511 - module_free(mod, mod->module_core);
70512 + kmemleak_not_leak(ptr);
70513 + if (!ptr && mod->init_size_rw) {
70514 + module_free(mod, mod->module_core_rw);
70515 return -ENOMEM;
70516 }
70517 - memset(ptr, 0, mod->init_size);
70518 - mod->module_init = ptr;
70519 + memset(ptr, 0, mod->init_size_rw);
70520 + mod->module_init_rw = ptr;
70521 +
70522 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
70523 + kmemleak_not_leak(ptr);
70524 + if (!ptr) {
70525 + module_free(mod, mod->module_init_rw);
70526 + module_free(mod, mod->module_core_rw);
70527 + return -ENOMEM;
70528 + }
70529 +
70530 + pax_open_kernel();
70531 + memset(ptr, 0, mod->core_size_rx);
70532 + pax_close_kernel();
70533 + mod->module_core_rx = ptr;
70534 +
70535 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
70536 + kmemleak_not_leak(ptr);
70537 + if (!ptr && mod->init_size_rx) {
70538 + module_free_exec(mod, mod->module_core_rx);
70539 + module_free(mod, mod->module_init_rw);
70540 + module_free(mod, mod->module_core_rw);
70541 + return -ENOMEM;
70542 + }
70543 +
70544 + pax_open_kernel();
70545 + memset(ptr, 0, mod->init_size_rx);
70546 + pax_close_kernel();
70547 + mod->module_init_rx = ptr;
70548
70549 /* Transfer each section which specifies SHF_ALLOC */
70550 pr_debug("final section addresses:\n");
70551 @@ -2785,16 +2856,45 @@ static int move_module(struct module *mod, struct load_info *info)
70552 if (!(shdr->sh_flags & SHF_ALLOC))
70553 continue;
70554
70555 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
70556 - dest = mod->module_init
70557 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70558 - else
70559 - dest = mod->module_core + shdr->sh_entsize;
70560 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
70561 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70562 + dest = mod->module_init_rw
70563 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70564 + else
70565 + dest = mod->module_init_rx
70566 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70567 + } else {
70568 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70569 + dest = mod->module_core_rw + shdr->sh_entsize;
70570 + else
70571 + dest = mod->module_core_rx + shdr->sh_entsize;
70572 + }
70573 +
70574 + if (shdr->sh_type != SHT_NOBITS) {
70575 +
70576 +#ifdef CONFIG_PAX_KERNEXEC
70577 +#ifdef CONFIG_X86_64
70578 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
70579 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
70580 +#endif
70581 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
70582 + pax_open_kernel();
70583 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70584 + pax_close_kernel();
70585 + } else
70586 +#endif
70587
70588 - if (shdr->sh_type != SHT_NOBITS)
70589 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70590 + }
70591 /* Update sh_addr to point to copy in image. */
70592 - shdr->sh_addr = (unsigned long)dest;
70593 +
70594 +#ifdef CONFIG_PAX_KERNEXEC
70595 + if (shdr->sh_flags & SHF_EXECINSTR)
70596 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
70597 + else
70598 +#endif
70599 +
70600 + shdr->sh_addr = (unsigned long)dest;
70601 pr_debug("\t0x%lx %s\n",
70602 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
70603 }
70604 @@ -2849,12 +2949,12 @@ static void flush_module_icache(const struct module *mod)
70605 * Do it before processing of module parameters, so the module
70606 * can provide parameter accessor functions of its own.
70607 */
70608 - if (mod->module_init)
70609 - flush_icache_range((unsigned long)mod->module_init,
70610 - (unsigned long)mod->module_init
70611 - + mod->init_size);
70612 - flush_icache_range((unsigned long)mod->module_core,
70613 - (unsigned long)mod->module_core + mod->core_size);
70614 + if (mod->module_init_rx)
70615 + flush_icache_range((unsigned long)mod->module_init_rx,
70616 + (unsigned long)mod->module_init_rx
70617 + + mod->init_size_rx);
70618 + flush_icache_range((unsigned long)mod->module_core_rx,
70619 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
70620
70621 set_fs(old_fs);
70622 }
70623 @@ -2924,8 +3024,10 @@ out:
70624 static void module_deallocate(struct module *mod, struct load_info *info)
70625 {
70626 percpu_modfree(mod);
70627 - module_free(mod, mod->module_init);
70628 - module_free(mod, mod->module_core);
70629 + module_free_exec(mod, mod->module_init_rx);
70630 + module_free_exec(mod, mod->module_core_rx);
70631 + module_free(mod, mod->module_init_rw);
70632 + module_free(mod, mod->module_core_rw);
70633 }
70634
70635 int __weak module_finalize(const Elf_Ehdr *hdr,
70636 @@ -2938,7 +3040,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
70637 static int post_relocation(struct module *mod, const struct load_info *info)
70638 {
70639 /* Sort exception table now relocations are done. */
70640 + pax_open_kernel();
70641 sort_extable(mod->extable, mod->extable + mod->num_exentries);
70642 + pax_close_kernel();
70643
70644 /* Copy relocated percpu area over. */
70645 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
70646 @@ -3036,9 +3140,38 @@ again:
70647 if (err)
70648 goto free_unload;
70649
70650 + /* Now copy in args */
70651 + mod->args = strndup_user(uargs, ~0UL >> 1);
70652 + if (IS_ERR(mod->args)) {
70653 + err = PTR_ERR(mod->args);
70654 + goto free_unload;
70655 + }
70656 +
70657 /* Set up MODINFO_ATTR fields */
70658 setup_modinfo(mod, &info);
70659
70660 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70661 + {
70662 + char *p, *p2;
70663 +
70664 + if (strstr(mod->args, "grsec_modharden_netdev")) {
70665 + 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);
70666 + err = -EPERM;
70667 + goto free_modinfo;
70668 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
70669 + p += sizeof("grsec_modharden_normal") - 1;
70670 + p2 = strstr(p, "_");
70671 + if (p2) {
70672 + *p2 = '\0';
70673 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
70674 + *p2 = '_';
70675 + }
70676 + err = -EPERM;
70677 + goto free_modinfo;
70678 + }
70679 + }
70680 +#endif
70681 +
70682 /* Fix up syms, so that st_value is a pointer to location. */
70683 err = simplify_symbols(mod, &info);
70684 if (err < 0)
70685 @@ -3104,11 +3237,11 @@ again:
70686 mutex_unlock(&module_mutex);
70687 dynamic_debug_remove(info.debug);
70688 synchronize_sched();
70689 - kfree(mod->args);
70690 free_arch_cleanup:
70691 module_arch_cleanup(mod);
70692 free_modinfo:
70693 free_modinfo(mod);
70694 + kfree(mod->args);
70695 free_unload:
70696 module_unload_free(mod);
70697 unlink_mod:
70698 @@ -3155,16 +3288,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70699 MODULE_STATE_COMING, mod);
70700
70701 /* Set RO and NX regions for core */
70702 - set_section_ro_nx(mod->module_core,
70703 - mod->core_text_size,
70704 - mod->core_ro_size,
70705 - mod->core_size);
70706 + set_section_ro_nx(mod->module_core_rx,
70707 + mod->core_size_rx,
70708 + mod->core_size_rx,
70709 + mod->core_size_rx);
70710
70711 /* Set RO and NX regions for init */
70712 - set_section_ro_nx(mod->module_init,
70713 - mod->init_text_size,
70714 - mod->init_ro_size,
70715 - mod->init_size);
70716 + set_section_ro_nx(mod->module_init_rx,
70717 + mod->init_size_rx,
70718 + mod->init_size_rx,
70719 + mod->init_size_rx);
70720
70721 do_mod_ctors(mod);
70722 /* Start the module */
70723 @@ -3209,11 +3342,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70724 mod->strtab = mod->core_strtab;
70725 #endif
70726 unset_module_init_ro_nx(mod);
70727 - module_free(mod, mod->module_init);
70728 - mod->module_init = NULL;
70729 - mod->init_size = 0;
70730 - mod->init_ro_size = 0;
70731 - mod->init_text_size = 0;
70732 + module_free(mod, mod->module_init_rw);
70733 + module_free_exec(mod, mod->module_init_rx);
70734 + mod->module_init_rw = NULL;
70735 + mod->module_init_rx = NULL;
70736 + mod->init_size_rw = 0;
70737 + mod->init_size_rx = 0;
70738 mutex_unlock(&module_mutex);
70739 wake_up_all(&module_wq);
70740
70741 @@ -3245,10 +3379,16 @@ static const char *get_ksymbol(struct module *mod,
70742 unsigned long nextval;
70743
70744 /* At worse, next value is at end of module */
70745 - if (within_module_init(addr, mod))
70746 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
70747 + if (within_module_init_rx(addr, mod))
70748 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
70749 + else if (within_module_init_rw(addr, mod))
70750 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
70751 + else if (within_module_core_rx(addr, mod))
70752 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
70753 + else if (within_module_core_rw(addr, mod))
70754 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
70755 else
70756 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
70757 + return NULL;
70758
70759 /* Scan for closest preceding symbol, and next symbol. (ELF
70760 starts real symbols at 1). */
70761 @@ -3501,7 +3641,7 @@ static int m_show(struct seq_file *m, void *p)
70762 return 0;
70763
70764 seq_printf(m, "%s %u",
70765 - mod->name, mod->init_size + mod->core_size);
70766 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
70767 print_unload_info(m, mod);
70768
70769 /* Informative for users. */
70770 @@ -3510,7 +3650,7 @@ static int m_show(struct seq_file *m, void *p)
70771 mod->state == MODULE_STATE_COMING ? "Loading":
70772 "Live");
70773 /* Used by oprofile and other similar tools. */
70774 - seq_printf(m, " 0x%pK", mod->module_core);
70775 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
70776
70777 /* Taints info */
70778 if (mod->taints)
70779 @@ -3546,7 +3686,17 @@ static const struct file_operations proc_modules_operations = {
70780
70781 static int __init proc_modules_init(void)
70782 {
70783 +#ifndef CONFIG_GRKERNSEC_HIDESYM
70784 +#ifdef CONFIG_GRKERNSEC_PROC_USER
70785 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70786 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70787 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
70788 +#else
70789 proc_create("modules", 0, NULL, &proc_modules_operations);
70790 +#endif
70791 +#else
70792 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70793 +#endif
70794 return 0;
70795 }
70796 module_init(proc_modules_init);
70797 @@ -3607,14 +3757,14 @@ struct module *__module_address(unsigned long addr)
70798 {
70799 struct module *mod;
70800
70801 - if (addr < module_addr_min || addr > module_addr_max)
70802 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
70803 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
70804 return NULL;
70805
70806 list_for_each_entry_rcu(mod, &modules, list) {
70807 if (mod->state == MODULE_STATE_UNFORMED)
70808 continue;
70809 - if (within_module_core(addr, mod)
70810 - || within_module_init(addr, mod))
70811 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
70812 return mod;
70813 }
70814 return NULL;
70815 @@ -3649,11 +3799,20 @@ bool is_module_text_address(unsigned long addr)
70816 */
70817 struct module *__module_text_address(unsigned long addr)
70818 {
70819 - struct module *mod = __module_address(addr);
70820 + struct module *mod;
70821 +
70822 +#ifdef CONFIG_X86_32
70823 + addr = ktla_ktva(addr);
70824 +#endif
70825 +
70826 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
70827 + return NULL;
70828 +
70829 + mod = __module_address(addr);
70830 +
70831 if (mod) {
70832 /* Make sure it's within the text section. */
70833 - if (!within(addr, mod->module_init, mod->init_text_size)
70834 - && !within(addr, mod->module_core, mod->core_text_size))
70835 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
70836 mod = NULL;
70837 }
70838 return mod;
70839 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
70840 index 7e3443f..b2a1e6b 100644
70841 --- a/kernel/mutex-debug.c
70842 +++ b/kernel/mutex-debug.c
70843 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
70844 }
70845
70846 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70847 - struct thread_info *ti)
70848 + struct task_struct *task)
70849 {
70850 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
70851
70852 /* Mark the current thread as blocked on the lock: */
70853 - ti->task->blocked_on = waiter;
70854 + task->blocked_on = waiter;
70855 }
70856
70857 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70858 - struct thread_info *ti)
70859 + struct task_struct *task)
70860 {
70861 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
70862 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
70863 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
70864 - ti->task->blocked_on = NULL;
70865 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
70866 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
70867 + task->blocked_on = NULL;
70868
70869 list_del_init(&waiter->list);
70870 waiter->task = NULL;
70871 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
70872 index 0799fd3..d06ae3b 100644
70873 --- a/kernel/mutex-debug.h
70874 +++ b/kernel/mutex-debug.h
70875 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
70876 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
70877 extern void debug_mutex_add_waiter(struct mutex *lock,
70878 struct mutex_waiter *waiter,
70879 - struct thread_info *ti);
70880 + struct task_struct *task);
70881 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70882 - struct thread_info *ti);
70883 + struct task_struct *task);
70884 extern void debug_mutex_unlock(struct mutex *lock);
70885 extern void debug_mutex_init(struct mutex *lock, const char *name,
70886 struct lock_class_key *key);
70887 diff --git a/kernel/mutex.c b/kernel/mutex.c
70888 index a307cc9..27fd2e9 100644
70889 --- a/kernel/mutex.c
70890 +++ b/kernel/mutex.c
70891 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70892 spin_lock_mutex(&lock->wait_lock, flags);
70893
70894 debug_mutex_lock_common(lock, &waiter);
70895 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
70896 + debug_mutex_add_waiter(lock, &waiter, task);
70897
70898 /* add waiting tasks to the end of the waitqueue (FIFO): */
70899 list_add_tail(&waiter.list, &lock->wait_list);
70900 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70901 * TASK_UNINTERRUPTIBLE case.)
70902 */
70903 if (unlikely(signal_pending_state(state, task))) {
70904 - mutex_remove_waiter(lock, &waiter,
70905 - task_thread_info(task));
70906 + mutex_remove_waiter(lock, &waiter, task);
70907 mutex_release(&lock->dep_map, 1, ip);
70908 spin_unlock_mutex(&lock->wait_lock, flags);
70909
70910 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70911 done:
70912 lock_acquired(&lock->dep_map, ip);
70913 /* got the lock - rejoice! */
70914 - mutex_remove_waiter(lock, &waiter, current_thread_info());
70915 + mutex_remove_waiter(lock, &waiter, task);
70916 mutex_set_owner(lock);
70917
70918 /* set it to 0 if there are no waiters left: */
70919 diff --git a/kernel/notifier.c b/kernel/notifier.c
70920 index 2d5cc4c..d9ea600 100644
70921 --- a/kernel/notifier.c
70922 +++ b/kernel/notifier.c
70923 @@ -5,6 +5,7 @@
70924 #include <linux/rcupdate.h>
70925 #include <linux/vmalloc.h>
70926 #include <linux/reboot.h>
70927 +#include <linux/mm.h>
70928
70929 /*
70930 * Notifier list for kernel code which wants to be called
70931 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
70932 while ((*nl) != NULL) {
70933 if (n->priority > (*nl)->priority)
70934 break;
70935 - nl = &((*nl)->next);
70936 + nl = (struct notifier_block **)&((*nl)->next);
70937 }
70938 - n->next = *nl;
70939 + pax_open_kernel();
70940 + *(const void **)&n->next = *nl;
70941 rcu_assign_pointer(*nl, n);
70942 + pax_close_kernel();
70943 return 0;
70944 }
70945
70946 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
70947 return 0;
70948 if (n->priority > (*nl)->priority)
70949 break;
70950 - nl = &((*nl)->next);
70951 + nl = (struct notifier_block **)&((*nl)->next);
70952 }
70953 - n->next = *nl;
70954 + pax_open_kernel();
70955 + *(const void **)&n->next = *nl;
70956 rcu_assign_pointer(*nl, n);
70957 + pax_close_kernel();
70958 return 0;
70959 }
70960
70961 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
70962 {
70963 while ((*nl) != NULL) {
70964 if ((*nl) == n) {
70965 + pax_open_kernel();
70966 rcu_assign_pointer(*nl, n->next);
70967 + pax_close_kernel();
70968 return 0;
70969 }
70970 - nl = &((*nl)->next);
70971 + nl = (struct notifier_block **)&((*nl)->next);
70972 }
70973 return -ENOENT;
70974 }
70975 diff --git a/kernel/panic.c b/kernel/panic.c
70976 index e1b2822..5edc1d9 100644
70977 --- a/kernel/panic.c
70978 +++ b/kernel/panic.c
70979 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
70980 const char *board;
70981
70982 printk(KERN_WARNING "------------[ cut here ]------------\n");
70983 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
70984 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
70985 board = dmi_get_system_info(DMI_PRODUCT_NAME);
70986 if (board)
70987 printk(KERN_WARNING "Hardware name: %s\n", board);
70988 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
70989 */
70990 void __stack_chk_fail(void)
70991 {
70992 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
70993 + dump_stack();
70994 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
70995 __builtin_return_address(0));
70996 }
70997 EXPORT_SYMBOL(__stack_chk_fail);
70998 diff --git a/kernel/pid.c b/kernel/pid.c
70999 index aebd4f5..1693c13 100644
71000 --- a/kernel/pid.c
71001 +++ b/kernel/pid.c
71002 @@ -33,6 +33,7 @@
71003 #include <linux/rculist.h>
71004 #include <linux/bootmem.h>
71005 #include <linux/hash.h>
71006 +#include <linux/security.h>
71007 #include <linux/pid_namespace.h>
71008 #include <linux/init_task.h>
71009 #include <linux/syscalls.h>
71010 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
71011
71012 int pid_max = PID_MAX_DEFAULT;
71013
71014 -#define RESERVED_PIDS 300
71015 +#define RESERVED_PIDS 500
71016
71017 int pid_max_min = RESERVED_PIDS + 1;
71018 int pid_max_max = PID_MAX_LIMIT;
71019 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
71020 */
71021 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
71022 {
71023 + struct task_struct *task;
71024 +
71025 rcu_lockdep_assert(rcu_read_lock_held(),
71026 "find_task_by_pid_ns() needs rcu_read_lock()"
71027 " protection");
71028 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71029 +
71030 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71031 +
71032 + if (gr_pid_is_chrooted(task))
71033 + return NULL;
71034 +
71035 + return task;
71036 }
71037
71038 struct task_struct *find_task_by_vpid(pid_t vnr)
71039 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
71040 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
71041 }
71042
71043 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
71044 +{
71045 + rcu_lockdep_assert(rcu_read_lock_held(),
71046 + "find_task_by_pid_ns() needs rcu_read_lock()"
71047 + " protection");
71048 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
71049 +}
71050 +
71051 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
71052 {
71053 struct pid *pid;
71054 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
71055 index 125cb67..2e5c8ad 100644
71056 --- a/kernel/posix-cpu-timers.c
71057 +++ b/kernel/posix-cpu-timers.c
71058 @@ -6,9 +6,11 @@
71059 #include <linux/posix-timers.h>
71060 #include <linux/errno.h>
71061 #include <linux/math64.h>
71062 +#include <linux/security.h>
71063 #include <asm/uaccess.h>
71064 #include <linux/kernel_stat.h>
71065 #include <trace/events/timer.h>
71066 +#include <linux/random.h>
71067
71068 /*
71069 * Called after updating RLIMIT_CPU to run cpu timer and update
71070 @@ -494,6 +496,8 @@ static void cleanup_timers(struct list_head *head,
71071 */
71072 void posix_cpu_timers_exit(struct task_struct *tsk)
71073 {
71074 + add_device_randomness((const void*) &tsk->se.sum_exec_runtime,
71075 + sizeof(unsigned long long));
71076 cleanup_timers(tsk->cpu_timers,
71077 tsk->utime, tsk->stime, tsk->se.sum_exec_runtime);
71078
71079 @@ -1578,14 +1582,14 @@ struct k_clock clock_posix_cpu = {
71080
71081 static __init int init_posix_cpu_timers(void)
71082 {
71083 - struct k_clock process = {
71084 + static struct k_clock process = {
71085 .clock_getres = process_cpu_clock_getres,
71086 .clock_get = process_cpu_clock_get,
71087 .timer_create = process_cpu_timer_create,
71088 .nsleep = process_cpu_nsleep,
71089 .nsleep_restart = process_cpu_nsleep_restart,
71090 };
71091 - struct k_clock thread = {
71092 + static struct k_clock thread = {
71093 .clock_getres = thread_cpu_clock_getres,
71094 .clock_get = thread_cpu_clock_get,
71095 .timer_create = thread_cpu_timer_create,
71096 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
71097 index 69185ae..cc2847a 100644
71098 --- a/kernel/posix-timers.c
71099 +++ b/kernel/posix-timers.c
71100 @@ -43,6 +43,7 @@
71101 #include <linux/idr.h>
71102 #include <linux/posix-clock.h>
71103 #include <linux/posix-timers.h>
71104 +#include <linux/grsecurity.h>
71105 #include <linux/syscalls.h>
71106 #include <linux/wait.h>
71107 #include <linux/workqueue.h>
71108 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
71109 * which we beg off on and pass to do_sys_settimeofday().
71110 */
71111
71112 -static struct k_clock posix_clocks[MAX_CLOCKS];
71113 +static struct k_clock *posix_clocks[MAX_CLOCKS];
71114
71115 /*
71116 * These ones are defined below.
71117 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
71118 */
71119 static __init int init_posix_timers(void)
71120 {
71121 - struct k_clock clock_realtime = {
71122 + static struct k_clock clock_realtime = {
71123 .clock_getres = hrtimer_get_res,
71124 .clock_get = posix_clock_realtime_get,
71125 .clock_set = posix_clock_realtime_set,
71126 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
71127 .timer_get = common_timer_get,
71128 .timer_del = common_timer_del,
71129 };
71130 - struct k_clock clock_monotonic = {
71131 + static struct k_clock clock_monotonic = {
71132 .clock_getres = hrtimer_get_res,
71133 .clock_get = posix_ktime_get_ts,
71134 .nsleep = common_nsleep,
71135 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
71136 .timer_get = common_timer_get,
71137 .timer_del = common_timer_del,
71138 };
71139 - struct k_clock clock_monotonic_raw = {
71140 + static struct k_clock clock_monotonic_raw = {
71141 .clock_getres = hrtimer_get_res,
71142 .clock_get = posix_get_monotonic_raw,
71143 };
71144 - struct k_clock clock_realtime_coarse = {
71145 + static struct k_clock clock_realtime_coarse = {
71146 .clock_getres = posix_get_coarse_res,
71147 .clock_get = posix_get_realtime_coarse,
71148 };
71149 - struct k_clock clock_monotonic_coarse = {
71150 + static struct k_clock clock_monotonic_coarse = {
71151 .clock_getres = posix_get_coarse_res,
71152 .clock_get = posix_get_monotonic_coarse,
71153 };
71154 - struct k_clock clock_boottime = {
71155 + static struct k_clock clock_boottime = {
71156 .clock_getres = hrtimer_get_res,
71157 .clock_get = posix_get_boottime,
71158 .nsleep = common_nsleep,
71159 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
71160 return;
71161 }
71162
71163 - posix_clocks[clock_id] = *new_clock;
71164 + posix_clocks[clock_id] = new_clock;
71165 }
71166 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
71167
71168 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
71169 return (id & CLOCKFD_MASK) == CLOCKFD ?
71170 &clock_posix_dynamic : &clock_posix_cpu;
71171
71172 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
71173 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
71174 return NULL;
71175 - return &posix_clocks[id];
71176 + return posix_clocks[id];
71177 }
71178
71179 static int common_timer_create(struct k_itimer *new_timer)
71180 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
71181 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
71182 return -EFAULT;
71183
71184 + /* only the CLOCK_REALTIME clock can be set, all other clocks
71185 + have their clock_set fptr set to a nosettime dummy function
71186 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
71187 + call common_clock_set, which calls do_sys_settimeofday, which
71188 + we hook
71189 + */
71190 +
71191 return kc->clock_set(which_clock, &new_tp);
71192 }
71193
71194 diff --git a/kernel/power/process.c b/kernel/power/process.c
71195 index 87da817..30ddd13 100644
71196 --- a/kernel/power/process.c
71197 +++ b/kernel/power/process.c
71198 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
71199 u64 elapsed_csecs64;
71200 unsigned int elapsed_csecs;
71201 bool wakeup = false;
71202 + bool timedout = false;
71203
71204 do_gettimeofday(&start);
71205
71206 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
71207
71208 while (true) {
71209 todo = 0;
71210 + if (time_after(jiffies, end_time))
71211 + timedout = true;
71212 read_lock(&tasklist_lock);
71213 do_each_thread(g, p) {
71214 if (p == current || !freeze_task(p))
71215 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
71216 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
71217 * transition can't race with task state testing here.
71218 */
71219 - if (!task_is_stopped_or_traced(p) &&
71220 - !freezer_should_skip(p))
71221 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
71222 todo++;
71223 + if (timedout) {
71224 + printk(KERN_ERR "Task refusing to freeze:\n");
71225 + sched_show_task(p);
71226 + }
71227 + }
71228 } while_each_thread(g, p);
71229 read_unlock(&tasklist_lock);
71230
71231 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
71232 todo += wq_busy;
71233 }
71234
71235 - if (!todo || time_after(jiffies, end_time))
71236 + if (!todo || timedout)
71237 break;
71238
71239 if (pm_wakeup_pending()) {
71240 diff --git a/kernel/printk.c b/kernel/printk.c
71241 index f8e0b5a..dda2a5c 100644
71242 --- a/kernel/printk.c
71243 +++ b/kernel/printk.c
71244 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
71245 if (from_file && type != SYSLOG_ACTION_OPEN)
71246 return 0;
71247
71248 +#ifdef CONFIG_GRKERNSEC_DMESG
71249 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
71250 + return -EPERM;
71251 +#endif
71252 +
71253 if (syslog_action_restricted(type)) {
71254 if (capable(CAP_SYSLOG))
71255 return 0;
71256 diff --git a/kernel/profile.c b/kernel/profile.c
71257 index 76b8e77..a2930e8 100644
71258 --- a/kernel/profile.c
71259 +++ b/kernel/profile.c
71260 @@ -39,7 +39,7 @@ struct profile_hit {
71261 /* Oprofile timer tick hook */
71262 static int (*timer_hook)(struct pt_regs *) __read_mostly;
71263
71264 -static atomic_t *prof_buffer;
71265 +static atomic_unchecked_t *prof_buffer;
71266 static unsigned long prof_len, prof_shift;
71267
71268 int prof_on __read_mostly;
71269 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
71270 hits[i].pc = 0;
71271 continue;
71272 }
71273 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71274 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71275 hits[i].hits = hits[i].pc = 0;
71276 }
71277 }
71278 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71279 * Add the current hit(s) and flush the write-queue out
71280 * to the global buffer:
71281 */
71282 - atomic_add(nr_hits, &prof_buffer[pc]);
71283 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
71284 for (i = 0; i < NR_PROFILE_HIT; ++i) {
71285 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71286 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71287 hits[i].pc = hits[i].hits = 0;
71288 }
71289 out:
71290 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71291 {
71292 unsigned long pc;
71293 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
71294 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71295 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71296 }
71297 #endif /* !CONFIG_SMP */
71298
71299 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
71300 return -EFAULT;
71301 buf++; p++; count--; read++;
71302 }
71303 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
71304 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
71305 if (copy_to_user(buf, (void *)pnt, count))
71306 return -EFAULT;
71307 read += count;
71308 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
71309 }
71310 #endif
71311 profile_discard_flip_buffers();
71312 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
71313 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
71314 return count;
71315 }
71316
71317 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
71318 index fbea91d..9bf15e8 100644
71319 --- a/kernel/ptrace.c
71320 +++ b/kernel/ptrace.c
71321 @@ -319,7 +319,7 @@ static int ptrace_attach(struct task_struct *task, long request,
71322
71323 if (seize)
71324 flags |= PT_SEIZED;
71325 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
71326 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
71327 flags |= PT_PTRACE_CAP;
71328 task->ptrace = flags;
71329
71330 @@ -526,7 +526,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
71331 break;
71332 return -EIO;
71333 }
71334 - if (copy_to_user(dst, buf, retval))
71335 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
71336 return -EFAULT;
71337 copied += retval;
71338 src += retval;
71339 @@ -711,7 +711,7 @@ int ptrace_request(struct task_struct *child, long request,
71340 bool seized = child->ptrace & PT_SEIZED;
71341 int ret = -EIO;
71342 siginfo_t siginfo, *si;
71343 - void __user *datavp = (void __user *) data;
71344 + void __user *datavp = (__force void __user *) data;
71345 unsigned long __user *datalp = datavp;
71346 unsigned long flags;
71347
71348 @@ -913,14 +913,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
71349 goto out;
71350 }
71351
71352 + if (gr_handle_ptrace(child, request)) {
71353 + ret = -EPERM;
71354 + goto out_put_task_struct;
71355 + }
71356 +
71357 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71358 ret = ptrace_attach(child, request, addr, data);
71359 /*
71360 * Some architectures need to do book-keeping after
71361 * a ptrace attach.
71362 */
71363 - if (!ret)
71364 + if (!ret) {
71365 arch_ptrace_attach(child);
71366 + gr_audit_ptrace(child);
71367 + }
71368 goto out_put_task_struct;
71369 }
71370
71371 @@ -948,7 +955,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
71372 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
71373 if (copied != sizeof(tmp))
71374 return -EIO;
71375 - return put_user(tmp, (unsigned long __user *)data);
71376 + return put_user(tmp, (__force unsigned long __user *)data);
71377 }
71378
71379 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
71380 @@ -1058,14 +1065,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
71381 goto out;
71382 }
71383
71384 + if (gr_handle_ptrace(child, request)) {
71385 + ret = -EPERM;
71386 + goto out_put_task_struct;
71387 + }
71388 +
71389 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71390 ret = ptrace_attach(child, request, addr, data);
71391 /*
71392 * Some architectures need to do book-keeping after
71393 * a ptrace attach.
71394 */
71395 - if (!ret)
71396 + if (!ret) {
71397 arch_ptrace_attach(child);
71398 + gr_audit_ptrace(child);
71399 + }
71400 goto out_put_task_struct;
71401 }
71402
71403 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
71404 index e4c6a59..c86621a 100644
71405 --- a/kernel/rcutiny.c
71406 +++ b/kernel/rcutiny.c
71407 @@ -46,7 +46,7 @@
71408 struct rcu_ctrlblk;
71409 static void invoke_rcu_callbacks(void);
71410 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
71411 -static void rcu_process_callbacks(struct softirq_action *unused);
71412 +static void rcu_process_callbacks(void);
71413 static void __call_rcu(struct rcu_head *head,
71414 void (*func)(struct rcu_head *rcu),
71415 struct rcu_ctrlblk *rcp);
71416 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
71417 rcu_is_callbacks_kthread()));
71418 }
71419
71420 -static void rcu_process_callbacks(struct softirq_action *unused)
71421 +static void rcu_process_callbacks(void)
71422 {
71423 __rcu_process_callbacks(&rcu_sched_ctrlblk);
71424 __rcu_process_callbacks(&rcu_bh_ctrlblk);
71425 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
71426 index 3d01902..afbf46e 100644
71427 --- a/kernel/rcutiny_plugin.h
71428 +++ b/kernel/rcutiny_plugin.h
71429 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
71430 have_rcu_kthread_work = morework;
71431 local_irq_restore(flags);
71432 if (work)
71433 - rcu_process_callbacks(NULL);
71434 + rcu_process_callbacks();
71435 schedule_timeout_interruptible(1); /* Leave CPU for others. */
71436 }
71437
71438 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
71439 index aaa7b9f..055ff1e 100644
71440 --- a/kernel/rcutorture.c
71441 +++ b/kernel/rcutorture.c
71442 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
71443 { 0 };
71444 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
71445 { 0 };
71446 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71447 -static atomic_t n_rcu_torture_alloc;
71448 -static atomic_t n_rcu_torture_alloc_fail;
71449 -static atomic_t n_rcu_torture_free;
71450 -static atomic_t n_rcu_torture_mberror;
71451 -static atomic_t n_rcu_torture_error;
71452 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71453 +static atomic_unchecked_t n_rcu_torture_alloc;
71454 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
71455 +static atomic_unchecked_t n_rcu_torture_free;
71456 +static atomic_unchecked_t n_rcu_torture_mberror;
71457 +static atomic_unchecked_t n_rcu_torture_error;
71458 static long n_rcu_torture_barrier_error;
71459 static long n_rcu_torture_boost_ktrerror;
71460 static long n_rcu_torture_boost_rterror;
71461 @@ -272,11 +272,11 @@ rcu_torture_alloc(void)
71462
71463 spin_lock_bh(&rcu_torture_lock);
71464 if (list_empty(&rcu_torture_freelist)) {
71465 - atomic_inc(&n_rcu_torture_alloc_fail);
71466 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
71467 spin_unlock_bh(&rcu_torture_lock);
71468 return NULL;
71469 }
71470 - atomic_inc(&n_rcu_torture_alloc);
71471 + atomic_inc_unchecked(&n_rcu_torture_alloc);
71472 p = rcu_torture_freelist.next;
71473 list_del_init(p);
71474 spin_unlock_bh(&rcu_torture_lock);
71475 @@ -289,7 +289,7 @@ rcu_torture_alloc(void)
71476 static void
71477 rcu_torture_free(struct rcu_torture *p)
71478 {
71479 - atomic_inc(&n_rcu_torture_free);
71480 + atomic_inc_unchecked(&n_rcu_torture_free);
71481 spin_lock_bh(&rcu_torture_lock);
71482 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
71483 spin_unlock_bh(&rcu_torture_lock);
71484 @@ -410,7 +410,7 @@ rcu_torture_cb(struct rcu_head *p)
71485 i = rp->rtort_pipe_count;
71486 if (i > RCU_TORTURE_PIPE_LEN)
71487 i = RCU_TORTURE_PIPE_LEN;
71488 - atomic_inc(&rcu_torture_wcount[i]);
71489 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
71490 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71491 rp->rtort_mbtest = 0;
71492 rcu_torture_free(rp);
71493 @@ -459,7 +459,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
71494 i = rp->rtort_pipe_count;
71495 if (i > RCU_TORTURE_PIPE_LEN)
71496 i = RCU_TORTURE_PIPE_LEN;
71497 - atomic_inc(&rcu_torture_wcount[i]);
71498 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
71499 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71500 rp->rtort_mbtest = 0;
71501 list_del(&rp->rtort_free);
71502 @@ -1002,7 +1002,7 @@ rcu_torture_writer(void *arg)
71503 i = old_rp->rtort_pipe_count;
71504 if (i > RCU_TORTURE_PIPE_LEN)
71505 i = RCU_TORTURE_PIPE_LEN;
71506 - atomic_inc(&rcu_torture_wcount[i]);
71507 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
71508 old_rp->rtort_pipe_count++;
71509 cur_ops->deferred_free(old_rp);
71510 }
71511 @@ -1087,7 +1087,7 @@ static void rcu_torture_timer(unsigned long unused)
71512 }
71513 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71514 if (p->rtort_mbtest == 0)
71515 - atomic_inc(&n_rcu_torture_mberror);
71516 + atomic_inc_unchecked(&n_rcu_torture_mberror);
71517 spin_lock(&rand_lock);
71518 cur_ops->read_delay(&rand);
71519 n_rcu_torture_timers++;
71520 @@ -1151,7 +1151,7 @@ rcu_torture_reader(void *arg)
71521 }
71522 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71523 if (p->rtort_mbtest == 0)
71524 - atomic_inc(&n_rcu_torture_mberror);
71525 + atomic_inc_unchecked(&n_rcu_torture_mberror);
71526 cur_ops->read_delay(&rand);
71527 preempt_disable();
71528 pipe_count = p->rtort_pipe_count;
71529 @@ -1210,11 +1210,11 @@ rcu_torture_printk(char *page)
71530 rcu_torture_current,
71531 rcu_torture_current_version,
71532 list_empty(&rcu_torture_freelist),
71533 - atomic_read(&n_rcu_torture_alloc),
71534 - atomic_read(&n_rcu_torture_alloc_fail),
71535 - atomic_read(&n_rcu_torture_free));
71536 + atomic_read_unchecked(&n_rcu_torture_alloc),
71537 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
71538 + atomic_read_unchecked(&n_rcu_torture_free));
71539 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
71540 - atomic_read(&n_rcu_torture_mberror),
71541 + atomic_read_unchecked(&n_rcu_torture_mberror),
71542 n_rcu_torture_boost_ktrerror,
71543 n_rcu_torture_boost_rterror);
71544 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
71545 @@ -1233,14 +1233,14 @@ rcu_torture_printk(char *page)
71546 n_barrier_attempts,
71547 n_rcu_torture_barrier_error);
71548 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
71549 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
71550 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
71551 n_rcu_torture_barrier_error != 0 ||
71552 n_rcu_torture_boost_ktrerror != 0 ||
71553 n_rcu_torture_boost_rterror != 0 ||
71554 n_rcu_torture_boost_failure != 0 ||
71555 i > 1) {
71556 cnt += sprintf(&page[cnt], "!!! ");
71557 - atomic_inc(&n_rcu_torture_error);
71558 + atomic_inc_unchecked(&n_rcu_torture_error);
71559 WARN_ON_ONCE(1);
71560 }
71561 cnt += sprintf(&page[cnt], "Reader Pipe: ");
71562 @@ -1254,7 +1254,7 @@ rcu_torture_printk(char *page)
71563 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
71564 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71565 cnt += sprintf(&page[cnt], " %d",
71566 - atomic_read(&rcu_torture_wcount[i]));
71567 + atomic_read_unchecked(&rcu_torture_wcount[i]));
71568 }
71569 cnt += sprintf(&page[cnt], "\n");
71570 if (cur_ops->stats)
71571 @@ -1938,7 +1938,7 @@ rcu_torture_cleanup(void)
71572
71573 if (cur_ops->cleanup)
71574 cur_ops->cleanup();
71575 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71576 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71577 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
71578 else if (n_online_successes != n_online_attempts ||
71579 n_offline_successes != n_offline_attempts)
71580 @@ -2007,18 +2007,18 @@ rcu_torture_init(void)
71581
71582 rcu_torture_current = NULL;
71583 rcu_torture_current_version = 0;
71584 - atomic_set(&n_rcu_torture_alloc, 0);
71585 - atomic_set(&n_rcu_torture_alloc_fail, 0);
71586 - atomic_set(&n_rcu_torture_free, 0);
71587 - atomic_set(&n_rcu_torture_mberror, 0);
71588 - atomic_set(&n_rcu_torture_error, 0);
71589 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
71590 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
71591 + atomic_set_unchecked(&n_rcu_torture_free, 0);
71592 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
71593 + atomic_set_unchecked(&n_rcu_torture_error, 0);
71594 n_rcu_torture_barrier_error = 0;
71595 n_rcu_torture_boost_ktrerror = 0;
71596 n_rcu_torture_boost_rterror = 0;
71597 n_rcu_torture_boost_failure = 0;
71598 n_rcu_torture_boosts = 0;
71599 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
71600 - atomic_set(&rcu_torture_wcount[i], 0);
71601 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
71602 for_each_possible_cpu(cpu) {
71603 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71604 per_cpu(rcu_torture_count, cpu)[i] = 0;
71605 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
71606 index 2682295..0f2297e 100644
71607 --- a/kernel/rcutree.c
71608 +++ b/kernel/rcutree.c
71609 @@ -348,9 +348,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
71610 rcu_prepare_for_idle(smp_processor_id());
71611 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71612 smp_mb__before_atomic_inc(); /* See above. */
71613 - atomic_inc(&rdtp->dynticks);
71614 + atomic_inc_unchecked(&rdtp->dynticks);
71615 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
71616 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71617 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71618
71619 /*
71620 * It is illegal to enter an extended quiescent state while
71621 @@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
71622 int user)
71623 {
71624 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
71625 - atomic_inc(&rdtp->dynticks);
71626 + atomic_inc_unchecked(&rdtp->dynticks);
71627 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71628 smp_mb__after_atomic_inc(); /* See above. */
71629 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71630 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71631 rcu_cleanup_after_idle(smp_processor_id());
71632 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
71633 if (!user && !is_idle_task(current)) {
71634 @@ -670,14 +670,14 @@ void rcu_nmi_enter(void)
71635 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
71636
71637 if (rdtp->dynticks_nmi_nesting == 0 &&
71638 - (atomic_read(&rdtp->dynticks) & 0x1))
71639 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
71640 return;
71641 rdtp->dynticks_nmi_nesting++;
71642 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
71643 - atomic_inc(&rdtp->dynticks);
71644 + atomic_inc_unchecked(&rdtp->dynticks);
71645 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71646 smp_mb__after_atomic_inc(); /* See above. */
71647 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71648 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71649 }
71650
71651 /**
71652 @@ -696,9 +696,9 @@ void rcu_nmi_exit(void)
71653 return;
71654 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71655 smp_mb__before_atomic_inc(); /* See above. */
71656 - atomic_inc(&rdtp->dynticks);
71657 + atomic_inc_unchecked(&rdtp->dynticks);
71658 smp_mb__after_atomic_inc(); /* Force delay to next write. */
71659 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71660 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71661 }
71662
71663 /**
71664 @@ -712,7 +712,7 @@ int rcu_is_cpu_idle(void)
71665 int ret;
71666
71667 preempt_disable();
71668 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71669 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71670 preempt_enable();
71671 return ret;
71672 }
71673 @@ -795,7 +795,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
71674 */
71675 static int dyntick_save_progress_counter(struct rcu_data *rdp)
71676 {
71677 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
71678 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71679 return (rdp->dynticks_snap & 0x1) == 0;
71680 }
71681
71682 @@ -810,7 +810,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
71683 unsigned int curr;
71684 unsigned int snap;
71685
71686 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
71687 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71688 snap = (unsigned int)rdp->dynticks_snap;
71689
71690 /*
71691 @@ -858,10 +858,10 @@ static int jiffies_till_stall_check(void)
71692 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
71693 */
71694 if (till_stall_check < 3) {
71695 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
71696 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
71697 till_stall_check = 3;
71698 } else if (till_stall_check > 300) {
71699 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
71700 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
71701 till_stall_check = 300;
71702 }
71703 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
71704 @@ -1589,7 +1589,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
71705 rsp->qlen += rdp->qlen;
71706 rdp->n_cbs_orphaned += rdp->qlen;
71707 rdp->qlen_lazy = 0;
71708 - ACCESS_ONCE(rdp->qlen) = 0;
71709 + ACCESS_ONCE_RW(rdp->qlen) = 0;
71710 }
71711
71712 /*
71713 @@ -1831,7 +1831,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
71714 }
71715 smp_mb(); /* List handling before counting for rcu_barrier(). */
71716 rdp->qlen_lazy -= count_lazy;
71717 - ACCESS_ONCE(rdp->qlen) -= count;
71718 + ACCESS_ONCE_RW(rdp->qlen) -= count;
71719 rdp->n_cbs_invoked += count;
71720
71721 /* Reinstate batch limit if we have worked down the excess. */
71722 @@ -2024,7 +2024,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
71723 /*
71724 * Do RCU core processing for the current CPU.
71725 */
71726 -static void rcu_process_callbacks(struct softirq_action *unused)
71727 +static void rcu_process_callbacks(void)
71728 {
71729 struct rcu_state *rsp;
71730
71731 @@ -2136,7 +2136,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
71732 local_irq_restore(flags);
71733 return;
71734 }
71735 - ACCESS_ONCE(rdp->qlen)++;
71736 + ACCESS_ONCE_RW(rdp->qlen)++;
71737 if (lazy)
71738 rdp->qlen_lazy++;
71739 else
71740 @@ -2250,8 +2250,8 @@ void synchronize_rcu_bh(void)
71741 }
71742 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
71743
71744 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
71745 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
71746 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
71747 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
71748
71749 static int synchronize_sched_expedited_cpu_stop(void *data)
71750 {
71751 @@ -2312,7 +2312,7 @@ void synchronize_sched_expedited(void)
71752 int firstsnap, s, snap, trycount = 0;
71753
71754 /* Note that atomic_inc_return() implies full memory barrier. */
71755 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
71756 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
71757 get_online_cpus();
71758 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
71759
71760 @@ -2334,7 +2334,7 @@ void synchronize_sched_expedited(void)
71761 }
71762
71763 /* Check to see if someone else did our work for us. */
71764 - s = atomic_read(&sync_sched_expedited_done);
71765 + s = atomic_read_unchecked(&sync_sched_expedited_done);
71766 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
71767 smp_mb(); /* ensure test happens before caller kfree */
71768 return;
71769 @@ -2349,7 +2349,7 @@ void synchronize_sched_expedited(void)
71770 * grace period works for us.
71771 */
71772 get_online_cpus();
71773 - snap = atomic_read(&sync_sched_expedited_started);
71774 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
71775 smp_mb(); /* ensure read is before try_stop_cpus(). */
71776 }
71777
71778 @@ -2360,12 +2360,12 @@ void synchronize_sched_expedited(void)
71779 * than we did beat us to the punch.
71780 */
71781 do {
71782 - s = atomic_read(&sync_sched_expedited_done);
71783 + s = atomic_read_unchecked(&sync_sched_expedited_done);
71784 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
71785 smp_mb(); /* ensure test happens before caller kfree */
71786 break;
71787 }
71788 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
71789 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
71790
71791 put_online_cpus();
71792 }
71793 @@ -2539,7 +2539,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71794 * ACCESS_ONCE() to prevent the compiler from speculating
71795 * the increment to precede the early-exit check.
71796 */
71797 - ACCESS_ONCE(rsp->n_barrier_done)++;
71798 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71799 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
71800 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
71801 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
71802 @@ -2581,7 +2581,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71803
71804 /* Increment ->n_barrier_done to prevent duplicate work. */
71805 smp_mb(); /* Keep increment after above mechanism. */
71806 - ACCESS_ONCE(rsp->n_barrier_done)++;
71807 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71808 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
71809 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
71810 smp_mb(); /* Keep increment before caller's subsequent code. */
71811 @@ -2626,10 +2626,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
71812 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
71813 init_callback_list(rdp);
71814 rdp->qlen_lazy = 0;
71815 - ACCESS_ONCE(rdp->qlen) = 0;
71816 + ACCESS_ONCE_RW(rdp->qlen) = 0;
71817 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
71818 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
71819 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
71820 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
71821 #ifdef CONFIG_RCU_USER_QS
71822 WARN_ON_ONCE(rdp->dynticks->in_user);
71823 #endif
71824 @@ -2664,8 +2664,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
71825 rdp->blimit = blimit;
71826 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
71827 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
71828 - atomic_set(&rdp->dynticks->dynticks,
71829 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
71830 + atomic_set_unchecked(&rdp->dynticks->dynticks,
71831 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
71832 rcu_prepare_for_idle_init(cpu);
71833 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
71834
71835 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
71836 index a240f03..d469618 100644
71837 --- a/kernel/rcutree.h
71838 +++ b/kernel/rcutree.h
71839 @@ -86,7 +86,7 @@ struct rcu_dynticks {
71840 long long dynticks_nesting; /* Track irq/process nesting level. */
71841 /* Process level is worth LLONG_MAX/2. */
71842 int dynticks_nmi_nesting; /* Track NMI nesting level. */
71843 - atomic_t dynticks; /* Even value for idle, else odd. */
71844 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
71845 #ifdef CONFIG_RCU_FAST_NO_HZ
71846 int dyntick_drain; /* Prepare-for-idle state variable. */
71847 unsigned long dyntick_holdoff;
71848 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
71849 index f921154..34c4873 100644
71850 --- a/kernel/rcutree_plugin.h
71851 +++ b/kernel/rcutree_plugin.h
71852 @@ -865,7 +865,7 @@ void synchronize_rcu_expedited(void)
71853
71854 /* Clean up and exit. */
71855 smp_mb(); /* ensure expedited GP seen before counter increment. */
71856 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
71857 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
71858 unlock_mb_ret:
71859 mutex_unlock(&sync_rcu_preempt_exp_mutex);
71860 mb_ret:
71861 @@ -2040,7 +2040,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
71862 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
71863 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
71864 cpu, ticks_value, ticks_title,
71865 - atomic_read(&rdtp->dynticks) & 0xfff,
71866 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
71867 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
71868 fast_no_hz);
71869 }
71870 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
71871 index 693513b..b9f1d63 100644
71872 --- a/kernel/rcutree_trace.c
71873 +++ b/kernel/rcutree_trace.c
71874 @@ -92,7 +92,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
71875 rdp->completed, rdp->gpnum,
71876 rdp->passed_quiesce, rdp->qs_pending);
71877 seq_printf(m, " dt=%d/%llx/%d df=%lu",
71878 - atomic_read(&rdp->dynticks->dynticks),
71879 + atomic_read_unchecked(&rdp->dynticks->dynticks),
71880 rdp->dynticks->dynticks_nesting,
71881 rdp->dynticks->dynticks_nmi_nesting,
71882 rdp->dynticks_fqs);
71883 @@ -154,7 +154,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
71884 rdp->completed, rdp->gpnum,
71885 rdp->passed_quiesce, rdp->qs_pending);
71886 seq_printf(m, ",%d,%llx,%d,%lu",
71887 - atomic_read(&rdp->dynticks->dynticks),
71888 + atomic_read_unchecked(&rdp->dynticks->dynticks),
71889 rdp->dynticks->dynticks_nesting,
71890 rdp->dynticks->dynticks_nmi_nesting,
71891 rdp->dynticks_fqs);
71892 diff --git a/kernel/resource.c b/kernel/resource.c
71893 index 73f35d4..4684fc4 100644
71894 --- a/kernel/resource.c
71895 +++ b/kernel/resource.c
71896 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
71897
71898 static int __init ioresources_init(void)
71899 {
71900 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
71901 +#ifdef CONFIG_GRKERNSEC_PROC_USER
71902 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
71903 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
71904 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71905 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
71906 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
71907 +#endif
71908 +#else
71909 proc_create("ioports", 0, NULL, &proc_ioports_operations);
71910 proc_create("iomem", 0, NULL, &proc_iomem_operations);
71911 +#endif
71912 return 0;
71913 }
71914 __initcall(ioresources_init);
71915 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
71916 index 98ec494..4241d6d 100644
71917 --- a/kernel/rtmutex-tester.c
71918 +++ b/kernel/rtmutex-tester.c
71919 @@ -20,7 +20,7 @@
71920 #define MAX_RT_TEST_MUTEXES 8
71921
71922 static spinlock_t rttest_lock;
71923 -static atomic_t rttest_event;
71924 +static atomic_unchecked_t rttest_event;
71925
71926 struct test_thread_data {
71927 int opcode;
71928 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71929
71930 case RTTEST_LOCKCONT:
71931 td->mutexes[td->opdata] = 1;
71932 - td->event = atomic_add_return(1, &rttest_event);
71933 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71934 return 0;
71935
71936 case RTTEST_RESET:
71937 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71938 return 0;
71939
71940 case RTTEST_RESETEVENT:
71941 - atomic_set(&rttest_event, 0);
71942 + atomic_set_unchecked(&rttest_event, 0);
71943 return 0;
71944
71945 default:
71946 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71947 return ret;
71948
71949 td->mutexes[id] = 1;
71950 - td->event = atomic_add_return(1, &rttest_event);
71951 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71952 rt_mutex_lock(&mutexes[id]);
71953 - td->event = atomic_add_return(1, &rttest_event);
71954 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71955 td->mutexes[id] = 4;
71956 return 0;
71957
71958 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71959 return ret;
71960
71961 td->mutexes[id] = 1;
71962 - td->event = atomic_add_return(1, &rttest_event);
71963 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71964 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
71965 - td->event = atomic_add_return(1, &rttest_event);
71966 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71967 td->mutexes[id] = ret ? 0 : 4;
71968 return ret ? -EINTR : 0;
71969
71970 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71971 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
71972 return ret;
71973
71974 - td->event = atomic_add_return(1, &rttest_event);
71975 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71976 rt_mutex_unlock(&mutexes[id]);
71977 - td->event = atomic_add_return(1, &rttest_event);
71978 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71979 td->mutexes[id] = 0;
71980 return 0;
71981
71982 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
71983 break;
71984
71985 td->mutexes[dat] = 2;
71986 - td->event = atomic_add_return(1, &rttest_event);
71987 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71988 break;
71989
71990 default:
71991 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
71992 return;
71993
71994 td->mutexes[dat] = 3;
71995 - td->event = atomic_add_return(1, &rttest_event);
71996 + td->event = atomic_add_return_unchecked(1, &rttest_event);
71997 break;
71998
71999 case RTTEST_LOCKNOWAIT:
72000 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72001 return;
72002
72003 td->mutexes[dat] = 1;
72004 - td->event = atomic_add_return(1, &rttest_event);
72005 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72006 return;
72007
72008 default:
72009 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
72010 index 15f60d0..7e50319 100644
72011 --- a/kernel/sched/auto_group.c
72012 +++ b/kernel/sched/auto_group.c
72013 @@ -11,7 +11,7 @@
72014
72015 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
72016 static struct autogroup autogroup_default;
72017 -static atomic_t autogroup_seq_nr;
72018 +static atomic_unchecked_t autogroup_seq_nr;
72019
72020 void __init autogroup_init(struct task_struct *init_task)
72021 {
72022 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
72023
72024 kref_init(&ag->kref);
72025 init_rwsem(&ag->lock);
72026 - ag->id = atomic_inc_return(&autogroup_seq_nr);
72027 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
72028 ag->tg = tg;
72029 #ifdef CONFIG_RT_GROUP_SCHED
72030 /*
72031 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
72032 index c529d00..d00b4f3 100644
72033 --- a/kernel/sched/core.c
72034 +++ b/kernel/sched/core.c
72035 @@ -3563,6 +3563,8 @@ int can_nice(const struct task_struct *p, const int nice)
72036 /* convert nice value [19,-20] to rlimit style value [1,40] */
72037 int nice_rlim = 20 - nice;
72038
72039 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
72040 +
72041 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
72042 capable(CAP_SYS_NICE));
72043 }
72044 @@ -3596,7 +3598,8 @@ SYSCALL_DEFINE1(nice, int, increment)
72045 if (nice > 19)
72046 nice = 19;
72047
72048 - if (increment < 0 && !can_nice(current, nice))
72049 + if (increment < 0 && (!can_nice(current, nice) ||
72050 + gr_handle_chroot_nice()))
72051 return -EPERM;
72052
72053 retval = security_task_setnice(current, nice);
72054 @@ -3750,6 +3753,7 @@ recheck:
72055 unsigned long rlim_rtprio =
72056 task_rlimit(p, RLIMIT_RTPRIO);
72057
72058 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
72059 /* can't set/change the rt policy */
72060 if (policy != p->policy && !rlim_rtprio)
72061 return -EPERM;
72062 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
72063 index 6b800a1..0c36227 100644
72064 --- a/kernel/sched/fair.c
72065 +++ b/kernel/sched/fair.c
72066 @@ -4890,7 +4890,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
72067 * run_rebalance_domains is triggered when needed from the scheduler tick.
72068 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
72069 */
72070 -static void run_rebalance_domains(struct softirq_action *h)
72071 +static void run_rebalance_domains(void)
72072 {
72073 int this_cpu = smp_processor_id();
72074 struct rq *this_rq = cpu_rq(this_cpu);
72075 diff --git a/kernel/signal.c b/kernel/signal.c
72076 index 57dde52..2c561f0 100644
72077 --- a/kernel/signal.c
72078 +++ b/kernel/signal.c
72079 @@ -49,12 +49,12 @@ static struct kmem_cache *sigqueue_cachep;
72080
72081 int print_fatal_signals __read_mostly;
72082
72083 -static void __user *sig_handler(struct task_struct *t, int sig)
72084 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
72085 {
72086 return t->sighand->action[sig - 1].sa.sa_handler;
72087 }
72088
72089 -static int sig_handler_ignored(void __user *handler, int sig)
72090 +static int sig_handler_ignored(__sighandler_t handler, int sig)
72091 {
72092 /* Is it explicitly or implicitly ignored? */
72093 return handler == SIG_IGN ||
72094 @@ -63,7 +63,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
72095
72096 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
72097 {
72098 - void __user *handler;
72099 + __sighandler_t handler;
72100
72101 handler = sig_handler(t, sig);
72102
72103 @@ -367,6 +367,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
72104 atomic_inc(&user->sigpending);
72105 rcu_read_unlock();
72106
72107 + if (!override_rlimit)
72108 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
72109 +
72110 if (override_rlimit ||
72111 atomic_read(&user->sigpending) <=
72112 task_rlimit(t, RLIMIT_SIGPENDING)) {
72113 @@ -491,7 +494,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
72114
72115 int unhandled_signal(struct task_struct *tsk, int sig)
72116 {
72117 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
72118 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
72119 if (is_global_init(tsk))
72120 return 1;
72121 if (handler != SIG_IGN && handler != SIG_DFL)
72122 @@ -811,6 +814,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
72123 }
72124 }
72125
72126 + /* allow glibc communication via tgkill to other threads in our
72127 + thread group */
72128 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
72129 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
72130 + && gr_handle_signal(t, sig))
72131 + return -EPERM;
72132 +
72133 return security_task_kill(t, info, sig, 0);
72134 }
72135
72136 @@ -1192,7 +1202,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
72137 return send_signal(sig, info, p, 1);
72138 }
72139
72140 -static int
72141 +int
72142 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72143 {
72144 return send_signal(sig, info, t, 0);
72145 @@ -1229,6 +1239,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72146 unsigned long int flags;
72147 int ret, blocked, ignored;
72148 struct k_sigaction *action;
72149 + int is_unhandled = 0;
72150
72151 spin_lock_irqsave(&t->sighand->siglock, flags);
72152 action = &t->sighand->action[sig-1];
72153 @@ -1243,9 +1254,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72154 }
72155 if (action->sa.sa_handler == SIG_DFL)
72156 t->signal->flags &= ~SIGNAL_UNKILLABLE;
72157 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
72158 + is_unhandled = 1;
72159 ret = specific_send_sig_info(sig, info, t);
72160 spin_unlock_irqrestore(&t->sighand->siglock, flags);
72161
72162 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
72163 + normal operation */
72164 + if (is_unhandled) {
72165 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
72166 + gr_handle_crash(t, sig);
72167 + }
72168 +
72169 return ret;
72170 }
72171
72172 @@ -1312,8 +1332,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
72173 ret = check_kill_permission(sig, info, p);
72174 rcu_read_unlock();
72175
72176 - if (!ret && sig)
72177 + if (!ret && sig) {
72178 ret = do_send_sig_info(sig, info, p, true);
72179 + if (!ret)
72180 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
72181 + }
72182
72183 return ret;
72184 }
72185 @@ -2863,7 +2886,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
72186 int error = -ESRCH;
72187
72188 rcu_read_lock();
72189 - p = find_task_by_vpid(pid);
72190 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72191 + /* allow glibc communication via tgkill to other threads in our
72192 + thread group */
72193 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
72194 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
72195 + p = find_task_by_vpid_unrestricted(pid);
72196 + else
72197 +#endif
72198 + p = find_task_by_vpid(pid);
72199 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
72200 error = check_kill_permission(sig, info, p);
72201 /*
72202 diff --git a/kernel/softirq.c b/kernel/softirq.c
72203 index cc96bdc..8bb9750 100644
72204 --- a/kernel/softirq.c
72205 +++ b/kernel/softirq.c
72206 @@ -57,7 +57,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
72207
72208 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
72209
72210 -char *softirq_to_name[NR_SOFTIRQS] = {
72211 +const char * const softirq_to_name[NR_SOFTIRQS] = {
72212 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
72213 "TASKLET", "SCHED", "HRTIMER", "RCU"
72214 };
72215 @@ -244,7 +244,7 @@ restart:
72216 kstat_incr_softirqs_this_cpu(vec_nr);
72217
72218 trace_softirq_entry(vec_nr);
72219 - h->action(h);
72220 + h->action();
72221 trace_softirq_exit(vec_nr);
72222 if (unlikely(prev_count != preempt_count())) {
72223 printk(KERN_ERR "huh, entered softirq %u %s %p"
72224 @@ -391,9 +391,11 @@ void __raise_softirq_irqoff(unsigned int nr)
72225 or_softirq_pending(1UL << nr);
72226 }
72227
72228 -void open_softirq(int nr, void (*action)(struct softirq_action *))
72229 +void open_softirq(int nr, void (*action)(void))
72230 {
72231 - softirq_vec[nr].action = action;
72232 + pax_open_kernel();
72233 + *(void **)&softirq_vec[nr].action = action;
72234 + pax_close_kernel();
72235 }
72236
72237 /*
72238 @@ -447,7 +449,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
72239
72240 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
72241
72242 -static void tasklet_action(struct softirq_action *a)
72243 +static void tasklet_action(void)
72244 {
72245 struct tasklet_struct *list;
72246
72247 @@ -482,7 +484,7 @@ static void tasklet_action(struct softirq_action *a)
72248 }
72249 }
72250
72251 -static void tasklet_hi_action(struct softirq_action *a)
72252 +static void tasklet_hi_action(void)
72253 {
72254 struct tasklet_struct *list;
72255
72256 diff --git a/kernel/srcu.c b/kernel/srcu.c
72257 index 97c465e..d83f3bb 100644
72258 --- a/kernel/srcu.c
72259 +++ b/kernel/srcu.c
72260 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
72261 preempt_disable();
72262 idx = rcu_dereference_index_check(sp->completed,
72263 rcu_read_lock_sched_held()) & 0x1;
72264 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
72265 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
72266 smp_mb(); /* B */ /* Avoid leaking the critical section. */
72267 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
72268 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
72269 preempt_enable();
72270 return idx;
72271 }
72272 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
72273 {
72274 preempt_disable();
72275 smp_mb(); /* C */ /* Avoid leaking the critical section. */
72276 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72277 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72278 preempt_enable();
72279 }
72280 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
72281 diff --git a/kernel/sys.c b/kernel/sys.c
72282 index e6e0ece..1f2e413 100644
72283 --- a/kernel/sys.c
72284 +++ b/kernel/sys.c
72285 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
72286 error = -EACCES;
72287 goto out;
72288 }
72289 +
72290 + if (gr_handle_chroot_setpriority(p, niceval)) {
72291 + error = -EACCES;
72292 + goto out;
72293 + }
72294 +
72295 no_nice = security_task_setnice(p, niceval);
72296 if (no_nice) {
72297 error = no_nice;
72298 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
72299 goto error;
72300 }
72301
72302 + if (gr_check_group_change(new->gid, new->egid, -1))
72303 + goto error;
72304 +
72305 if (rgid != (gid_t) -1 ||
72306 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
72307 new->sgid = new->egid;
72308 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
72309 old = current_cred();
72310
72311 retval = -EPERM;
72312 +
72313 + if (gr_check_group_change(kgid, kgid, kgid))
72314 + goto error;
72315 +
72316 if (nsown_capable(CAP_SETGID))
72317 new->gid = new->egid = new->sgid = new->fsgid = kgid;
72318 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
72319 @@ -647,7 +660,7 @@ error:
72320 /*
72321 * change the user struct in a credentials set to match the new UID
72322 */
72323 -static int set_user(struct cred *new)
72324 +int set_user(struct cred *new)
72325 {
72326 struct user_struct *new_user;
72327
72328 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
72329 goto error;
72330 }
72331
72332 + if (gr_check_user_change(new->uid, new->euid, -1))
72333 + goto error;
72334 +
72335 if (!uid_eq(new->uid, old->uid)) {
72336 retval = set_user(new);
72337 if (retval < 0)
72338 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
72339 old = current_cred();
72340
72341 retval = -EPERM;
72342 +
72343 + if (gr_check_crash_uid(kuid))
72344 + goto error;
72345 + if (gr_check_user_change(kuid, kuid, kuid))
72346 + goto error;
72347 +
72348 if (nsown_capable(CAP_SETUID)) {
72349 new->suid = new->uid = kuid;
72350 if (!uid_eq(kuid, old->uid)) {
72351 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
72352 goto error;
72353 }
72354
72355 + if (gr_check_user_change(kruid, keuid, -1))
72356 + goto error;
72357 +
72358 if (ruid != (uid_t) -1) {
72359 new->uid = kruid;
72360 if (!uid_eq(kruid, old->uid)) {
72361 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
72362 goto error;
72363 }
72364
72365 + if (gr_check_group_change(krgid, kegid, -1))
72366 + goto error;
72367 +
72368 if (rgid != (gid_t) -1)
72369 new->gid = krgid;
72370 if (egid != (gid_t) -1)
72371 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72372 if (!uid_valid(kuid))
72373 return old_fsuid;
72374
72375 + if (gr_check_user_change(-1, -1, kuid))
72376 + goto error;
72377 +
72378 new = prepare_creds();
72379 if (!new)
72380 return old_fsuid;
72381 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72382 }
72383 }
72384
72385 +error:
72386 abort_creds(new);
72387 return old_fsuid;
72388
72389 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
72390 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
72391 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
72392 nsown_capable(CAP_SETGID)) {
72393 + if (gr_check_group_change(-1, -1, kgid))
72394 + goto error;
72395 +
72396 if (!gid_eq(kgid, old->fsgid)) {
72397 new->fsgid = kgid;
72398 goto change_okay;
72399 }
72400 }
72401
72402 +error:
72403 abort_creds(new);
72404 return old_fsgid;
72405
72406 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
72407 return -EFAULT;
72408
72409 down_read(&uts_sem);
72410 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
72411 + error = __copy_to_user(name->sysname, &utsname()->sysname,
72412 __OLD_UTS_LEN);
72413 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
72414 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
72415 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
72416 __OLD_UTS_LEN);
72417 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
72418 - error |= __copy_to_user(&name->release, &utsname()->release,
72419 + error |= __copy_to_user(name->release, &utsname()->release,
72420 __OLD_UTS_LEN);
72421 error |= __put_user(0, name->release + __OLD_UTS_LEN);
72422 - error |= __copy_to_user(&name->version, &utsname()->version,
72423 + error |= __copy_to_user(name->version, &utsname()->version,
72424 __OLD_UTS_LEN);
72425 error |= __put_user(0, name->version + __OLD_UTS_LEN);
72426 - error |= __copy_to_user(&name->machine, &utsname()->machine,
72427 + error |= __copy_to_user(name->machine, &utsname()->machine,
72428 __OLD_UTS_LEN);
72429 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
72430 up_read(&uts_sem);
72431 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
72432 error = get_dumpable(me->mm);
72433 break;
72434 case PR_SET_DUMPABLE:
72435 - if (arg2 < 0 || arg2 > 1) {
72436 + if (arg2 > 1) {
72437 error = -EINVAL;
72438 break;
72439 }
72440 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
72441 index 26f65ea..df8e5ad 100644
72442 --- a/kernel/sysctl.c
72443 +++ b/kernel/sysctl.c
72444 @@ -92,7 +92,6 @@
72445
72446
72447 #if defined(CONFIG_SYSCTL)
72448 -
72449 /* External variables not in a header file. */
72450 extern int sysctl_overcommit_memory;
72451 extern int sysctl_overcommit_ratio;
72452 @@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
72453 void __user *buffer, size_t *lenp, loff_t *ppos);
72454 #endif
72455
72456 -#ifdef CONFIG_PRINTK
72457 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72458 void __user *buffer, size_t *lenp, loff_t *ppos);
72459 -#endif
72460
72461 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
72462 void __user *buffer, size_t *lenp, loff_t *ppos);
72463 @@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
72464
72465 #endif
72466
72467 +extern struct ctl_table grsecurity_table[];
72468 +
72469 static struct ctl_table kern_table[];
72470 static struct ctl_table vm_table[];
72471 static struct ctl_table fs_table[];
72472 @@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
72473 int sysctl_legacy_va_layout;
72474 #endif
72475
72476 +#ifdef CONFIG_PAX_SOFTMODE
72477 +static ctl_table pax_table[] = {
72478 + {
72479 + .procname = "softmode",
72480 + .data = &pax_softmode,
72481 + .maxlen = sizeof(unsigned int),
72482 + .mode = 0600,
72483 + .proc_handler = &proc_dointvec,
72484 + },
72485 +
72486 + { }
72487 +};
72488 +#endif
72489 +
72490 /* The default sysctl tables: */
72491
72492 static struct ctl_table sysctl_base_table[] = {
72493 @@ -266,6 +279,22 @@ static int max_extfrag_threshold = 1000;
72494 #endif
72495
72496 static struct ctl_table kern_table[] = {
72497 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
72498 + {
72499 + .procname = "grsecurity",
72500 + .mode = 0500,
72501 + .child = grsecurity_table,
72502 + },
72503 +#endif
72504 +
72505 +#ifdef CONFIG_PAX_SOFTMODE
72506 + {
72507 + .procname = "pax",
72508 + .mode = 0500,
72509 + .child = pax_table,
72510 + },
72511 +#endif
72512 +
72513 {
72514 .procname = "sched_child_runs_first",
72515 .data = &sysctl_sched_child_runs_first,
72516 @@ -552,7 +581,7 @@ static struct ctl_table kern_table[] = {
72517 .data = &modprobe_path,
72518 .maxlen = KMOD_PATH_LEN,
72519 .mode = 0644,
72520 - .proc_handler = proc_dostring,
72521 + .proc_handler = proc_dostring_modpriv,
72522 },
72523 {
72524 .procname = "modules_disabled",
72525 @@ -719,16 +748,20 @@ static struct ctl_table kern_table[] = {
72526 .extra1 = &zero,
72527 .extra2 = &one,
72528 },
72529 +#endif
72530 {
72531 .procname = "kptr_restrict",
72532 .data = &kptr_restrict,
72533 .maxlen = sizeof(int),
72534 .mode = 0644,
72535 .proc_handler = proc_dointvec_minmax_sysadmin,
72536 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72537 + .extra1 = &two,
72538 +#else
72539 .extra1 = &zero,
72540 +#endif
72541 .extra2 = &two,
72542 },
72543 -#endif
72544 {
72545 .procname = "ngroups_max",
72546 .data = &ngroups_max,
72547 @@ -1225,6 +1258,13 @@ static struct ctl_table vm_table[] = {
72548 .proc_handler = proc_dointvec_minmax,
72549 .extra1 = &zero,
72550 },
72551 + {
72552 + .procname = "heap_stack_gap",
72553 + .data = &sysctl_heap_stack_gap,
72554 + .maxlen = sizeof(sysctl_heap_stack_gap),
72555 + .mode = 0644,
72556 + .proc_handler = proc_doulongvec_minmax,
72557 + },
72558 #else
72559 {
72560 .procname = "nr_trim_pages",
72561 @@ -1675,6 +1715,16 @@ int proc_dostring(struct ctl_table *table, int write,
72562 buffer, lenp, ppos);
72563 }
72564
72565 +int proc_dostring_modpriv(struct ctl_table *table, int write,
72566 + void __user *buffer, size_t *lenp, loff_t *ppos)
72567 +{
72568 + if (write && !capable(CAP_SYS_MODULE))
72569 + return -EPERM;
72570 +
72571 + return _proc_do_string(table->data, table->maxlen, write,
72572 + buffer, lenp, ppos);
72573 +}
72574 +
72575 static size_t proc_skip_spaces(char **buf)
72576 {
72577 size_t ret;
72578 @@ -1780,6 +1830,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
72579 len = strlen(tmp);
72580 if (len > *size)
72581 len = *size;
72582 + if (len > sizeof(tmp))
72583 + len = sizeof(tmp);
72584 if (copy_to_user(*buf, tmp, len))
72585 return -EFAULT;
72586 *size -= len;
72587 @@ -1972,7 +2024,6 @@ static int proc_taint(struct ctl_table *table, int write,
72588 return err;
72589 }
72590
72591 -#ifdef CONFIG_PRINTK
72592 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72593 void __user *buffer, size_t *lenp, loff_t *ppos)
72594 {
72595 @@ -1981,7 +2032,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72596
72597 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
72598 }
72599 -#endif
72600
72601 struct do_proc_dointvec_minmax_conv_param {
72602 int *min;
72603 @@ -2128,8 +2178,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
72604 *i = val;
72605 } else {
72606 val = convdiv * (*i) / convmul;
72607 - if (!first)
72608 + if (!first) {
72609 err = proc_put_char(&buffer, &left, '\t');
72610 + if (err)
72611 + break;
72612 + }
72613 err = proc_put_long(&buffer, &left, val, false);
72614 if (err)
72615 break;
72616 @@ -2521,6 +2574,12 @@ int proc_dostring(struct ctl_table *table, int write,
72617 return -ENOSYS;
72618 }
72619
72620 +int proc_dostring_modpriv(struct ctl_table *table, int write,
72621 + void __user *buffer, size_t *lenp, loff_t *ppos)
72622 +{
72623 + return -ENOSYS;
72624 +}
72625 +
72626 int proc_dointvec(struct ctl_table *table, int write,
72627 void __user *buffer, size_t *lenp, loff_t *ppos)
72628 {
72629 @@ -2577,5 +2636,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
72630 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
72631 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
72632 EXPORT_SYMBOL(proc_dostring);
72633 +EXPORT_SYMBOL(proc_dostring_modpriv);
72634 EXPORT_SYMBOL(proc_doulongvec_minmax);
72635 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
72636 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
72637 index 65bdcf1..21eb831 100644
72638 --- a/kernel/sysctl_binary.c
72639 +++ b/kernel/sysctl_binary.c
72640 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
72641 int i;
72642
72643 set_fs(KERNEL_DS);
72644 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72645 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72646 set_fs(old_fs);
72647 if (result < 0)
72648 goto out_kfree;
72649 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
72650 }
72651
72652 set_fs(KERNEL_DS);
72653 - result = vfs_write(file, buffer, str - buffer, &pos);
72654 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72655 set_fs(old_fs);
72656 if (result < 0)
72657 goto out_kfree;
72658 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
72659 int i;
72660
72661 set_fs(KERNEL_DS);
72662 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72663 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72664 set_fs(old_fs);
72665 if (result < 0)
72666 goto out_kfree;
72667 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
72668 }
72669
72670 set_fs(KERNEL_DS);
72671 - result = vfs_write(file, buffer, str - buffer, &pos);
72672 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72673 set_fs(old_fs);
72674 if (result < 0)
72675 goto out_kfree;
72676 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
72677 int i;
72678
72679 set_fs(KERNEL_DS);
72680 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72681 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72682 set_fs(old_fs);
72683 if (result < 0)
72684 goto out;
72685 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72686 __le16 dnaddr;
72687
72688 set_fs(KERNEL_DS);
72689 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72690 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72691 set_fs(old_fs);
72692 if (result < 0)
72693 goto out;
72694 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72695 le16_to_cpu(dnaddr) & 0x3ff);
72696
72697 set_fs(KERNEL_DS);
72698 - result = vfs_write(file, buf, len, &pos);
72699 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
72700 set_fs(old_fs);
72701 if (result < 0)
72702 goto out;
72703 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
72704 index 145bb4d..b2aa969 100644
72705 --- a/kernel/taskstats.c
72706 +++ b/kernel/taskstats.c
72707 @@ -28,9 +28,12 @@
72708 #include <linux/fs.h>
72709 #include <linux/file.h>
72710 #include <linux/pid_namespace.h>
72711 +#include <linux/grsecurity.h>
72712 #include <net/genetlink.h>
72713 #include <linux/atomic.h>
72714
72715 +extern int gr_is_taskstats_denied(int pid);
72716 +
72717 /*
72718 * Maximum length of a cpumask that can be specified in
72719 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
72720 @@ -570,6 +573,9 @@ err:
72721
72722 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
72723 {
72724 + if (gr_is_taskstats_denied(current->pid))
72725 + return -EACCES;
72726 +
72727 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
72728 return cmd_attr_register_cpumask(info);
72729 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
72730 diff --git a/kernel/time.c b/kernel/time.c
72731 index d226c6a..c7c0960 100644
72732 --- a/kernel/time.c
72733 +++ b/kernel/time.c
72734 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
72735 return error;
72736
72737 if (tz) {
72738 + /* we log in do_settimeofday called below, so don't log twice
72739 + */
72740 + if (!tv)
72741 + gr_log_timechange();
72742 +
72743 sys_tz = *tz;
72744 update_vsyscall_tz();
72745 if (firsttime) {
72746 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
72747 index f11d83b..d016d91 100644
72748 --- a/kernel/time/alarmtimer.c
72749 +++ b/kernel/time/alarmtimer.c
72750 @@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
72751 struct platform_device *pdev;
72752 int error = 0;
72753 int i;
72754 - struct k_clock alarm_clock = {
72755 + static struct k_clock alarm_clock = {
72756 .clock_getres = alarm_clock_getres,
72757 .clock_get = alarm_clock_get,
72758 .timer_create = alarm_timer_create,
72759 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
72760 index f113755..ec24223 100644
72761 --- a/kernel/time/tick-broadcast.c
72762 +++ b/kernel/time/tick-broadcast.c
72763 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
72764 * then clear the broadcast bit.
72765 */
72766 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
72767 - int cpu = smp_processor_id();
72768 + cpu = smp_processor_id();
72769
72770 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
72771 tick_broadcast_clear_oneshot(cpu);
72772 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
72773 index e424970..4c7962b 100644
72774 --- a/kernel/time/timekeeping.c
72775 +++ b/kernel/time/timekeeping.c
72776 @@ -15,6 +15,7 @@
72777 #include <linux/init.h>
72778 #include <linux/mm.h>
72779 #include <linux/sched.h>
72780 +#include <linux/grsecurity.h>
72781 #include <linux/syscore_ops.h>
72782 #include <linux/clocksource.h>
72783 #include <linux/jiffies.h>
72784 @@ -368,6 +369,8 @@ int do_settimeofday(const struct timespec *tv)
72785 if (!timespec_valid_strict(tv))
72786 return -EINVAL;
72787
72788 + gr_log_timechange();
72789 +
72790 write_seqlock_irqsave(&tk->lock, flags);
72791
72792 timekeeping_forward_now(tk);
72793 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
72794 index af5a7e9..715611a 100644
72795 --- a/kernel/time/timer_list.c
72796 +++ b/kernel/time/timer_list.c
72797 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
72798
72799 static void print_name_offset(struct seq_file *m, void *sym)
72800 {
72801 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72802 + SEQ_printf(m, "<%p>", NULL);
72803 +#else
72804 char symname[KSYM_NAME_LEN];
72805
72806 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
72807 SEQ_printf(m, "<%pK>", sym);
72808 else
72809 SEQ_printf(m, "%s", symname);
72810 +#endif
72811 }
72812
72813 static void
72814 @@ -112,7 +116,11 @@ next_one:
72815 static void
72816 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
72817 {
72818 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72819 + SEQ_printf(m, " .base: %p\n", NULL);
72820 +#else
72821 SEQ_printf(m, " .base: %pK\n", base);
72822 +#endif
72823 SEQ_printf(m, " .index: %d\n",
72824 base->index);
72825 SEQ_printf(m, " .resolution: %Lu nsecs\n",
72826 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
72827 {
72828 struct proc_dir_entry *pe;
72829
72830 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
72831 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
72832 +#else
72833 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
72834 +#endif
72835 if (!pe)
72836 return -ENOMEM;
72837 return 0;
72838 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
72839 index 0b537f2..40d6c20 100644
72840 --- a/kernel/time/timer_stats.c
72841 +++ b/kernel/time/timer_stats.c
72842 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
72843 static unsigned long nr_entries;
72844 static struct entry entries[MAX_ENTRIES];
72845
72846 -static atomic_t overflow_count;
72847 +static atomic_unchecked_t overflow_count;
72848
72849 /*
72850 * The entries are in a hash-table, for fast lookup:
72851 @@ -140,7 +140,7 @@ static void reset_entries(void)
72852 nr_entries = 0;
72853 memset(entries, 0, sizeof(entries));
72854 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
72855 - atomic_set(&overflow_count, 0);
72856 + atomic_set_unchecked(&overflow_count, 0);
72857 }
72858
72859 static struct entry *alloc_entry(void)
72860 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
72861 if (likely(entry))
72862 entry->count++;
72863 else
72864 - atomic_inc(&overflow_count);
72865 + atomic_inc_unchecked(&overflow_count);
72866
72867 out_unlock:
72868 raw_spin_unlock_irqrestore(lock, flags);
72869 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
72870
72871 static void print_name_offset(struct seq_file *m, unsigned long addr)
72872 {
72873 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72874 + seq_printf(m, "<%p>", NULL);
72875 +#else
72876 char symname[KSYM_NAME_LEN];
72877
72878 if (lookup_symbol_name(addr, symname) < 0)
72879 - seq_printf(m, "<%p>", (void *)addr);
72880 + seq_printf(m, "<%pK>", (void *)addr);
72881 else
72882 seq_printf(m, "%s", symname);
72883 +#endif
72884 }
72885
72886 static int tstats_show(struct seq_file *m, void *v)
72887 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
72888
72889 seq_puts(m, "Timer Stats Version: v0.2\n");
72890 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
72891 - if (atomic_read(&overflow_count))
72892 + if (atomic_read_unchecked(&overflow_count))
72893 seq_printf(m, "Overflow: %d entries\n",
72894 - atomic_read(&overflow_count));
72895 + atomic_read_unchecked(&overflow_count));
72896
72897 for (i = 0; i < nr_entries; i++) {
72898 entry = entries + i;
72899 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
72900 {
72901 struct proc_dir_entry *pe;
72902
72903 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
72904 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
72905 +#else
72906 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
72907 +#endif
72908 if (!pe)
72909 return -ENOMEM;
72910 return 0;
72911 diff --git a/kernel/timer.c b/kernel/timer.c
72912 index 367d008..46857a0 100644
72913 --- a/kernel/timer.c
72914 +++ b/kernel/timer.c
72915 @@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
72916 /*
72917 * This function runs timers and the timer-tq in bottom half context.
72918 */
72919 -static void run_timer_softirq(struct softirq_action *h)
72920 +static void run_timer_softirq(void)
72921 {
72922 struct tvec_base *base = __this_cpu_read(tvec_bases);
72923
72924 @@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
72925 return NOTIFY_OK;
72926 }
72927
72928 -static struct notifier_block __cpuinitdata timers_nb = {
72929 +static struct notifier_block __cpuinitconst timers_nb = {
72930 .notifier_call = timer_cpu_notify,
72931 };
72932
72933 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
72934 index c0bd030..62a1927 100644
72935 --- a/kernel/trace/blktrace.c
72936 +++ b/kernel/trace/blktrace.c
72937 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
72938 struct blk_trace *bt = filp->private_data;
72939 char buf[16];
72940
72941 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
72942 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
72943
72944 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
72945 }
72946 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
72947 return 1;
72948
72949 bt = buf->chan->private_data;
72950 - atomic_inc(&bt->dropped);
72951 + atomic_inc_unchecked(&bt->dropped);
72952 return 0;
72953 }
72954
72955 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
72956
72957 bt->dir = dir;
72958 bt->dev = dev;
72959 - atomic_set(&bt->dropped, 0);
72960 + atomic_set_unchecked(&bt->dropped, 0);
72961
72962 ret = -EIO;
72963 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
72964 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
72965 index 356bc2f..7c94fc0 100644
72966 --- a/kernel/trace/ftrace.c
72967 +++ b/kernel/trace/ftrace.c
72968 @@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
72969 if (unlikely(ftrace_disabled))
72970 return 0;
72971
72972 + ret = ftrace_arch_code_modify_prepare();
72973 + FTRACE_WARN_ON(ret);
72974 + if (ret)
72975 + return 0;
72976 +
72977 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
72978 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
72979 if (ret) {
72980 ftrace_bug(ret, ip);
72981 - return 0;
72982 }
72983 - return 1;
72984 + return ret ? 0 : 1;
72985 }
72986
72987 /*
72988 @@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
72989
72990 int
72991 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
72992 - void *data)
72993 + void *data)
72994 {
72995 struct ftrace_func_probe *entry;
72996 struct ftrace_page *pg;
72997 @@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
72998 if (!count)
72999 return 0;
73000
73001 + pax_open_kernel();
73002 sort(start, count, sizeof(*start),
73003 ftrace_cmp_ips, ftrace_swap_ips);
73004 + pax_close_kernel();
73005
73006 start_pg = ftrace_allocate_pages(count);
73007 if (!start_pg)
73008 @@ -4541,8 +4548,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
73009 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
73010
73011 static int ftrace_graph_active;
73012 -static struct notifier_block ftrace_suspend_notifier;
73013 -
73014 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
73015 {
73016 return 0;
73017 @@ -4686,6 +4691,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
73018 return NOTIFY_DONE;
73019 }
73020
73021 +static struct notifier_block ftrace_suspend_notifier = {
73022 + .notifier_call = ftrace_suspend_notifier_call
73023 +};
73024 +
73025 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
73026 trace_func_graph_ent_t entryfunc)
73027 {
73028 @@ -4699,7 +4708,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
73029 goto out;
73030 }
73031
73032 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
73033 register_pm_notifier(&ftrace_suspend_notifier);
73034
73035 ftrace_graph_active++;
73036 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
73037 index 4cb5e51..e7e05d9 100644
73038 --- a/kernel/trace/ring_buffer.c
73039 +++ b/kernel/trace/ring_buffer.c
73040 @@ -346,9 +346,9 @@ struct buffer_data_page {
73041 */
73042 struct buffer_page {
73043 struct list_head list; /* list of buffer pages */
73044 - local_t write; /* index for next write */
73045 + local_unchecked_t write; /* index for next write */
73046 unsigned read; /* index for next read */
73047 - local_t entries; /* entries on this page */
73048 + local_unchecked_t entries; /* entries on this page */
73049 unsigned long real_end; /* real end of data */
73050 struct buffer_data_page *page; /* Actual data page */
73051 };
73052 @@ -460,8 +460,8 @@ struct ring_buffer_per_cpu {
73053 unsigned long lost_events;
73054 unsigned long last_overrun;
73055 local_t entries_bytes;
73056 - local_t commit_overrun;
73057 - local_t overrun;
73058 + local_unchecked_t commit_overrun;
73059 + local_unchecked_t overrun;
73060 local_t entries;
73061 local_t committing;
73062 local_t commits;
73063 @@ -860,8 +860,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
73064 *
73065 * We add a counter to the write field to denote this.
73066 */
73067 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
73068 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
73069 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
73070 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
73071
73072 /*
73073 * Just make sure we have seen our old_write and synchronize
73074 @@ -889,8 +889,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
73075 * cmpxchg to only update if an interrupt did not already
73076 * do it for us. If the cmpxchg fails, we don't care.
73077 */
73078 - (void)local_cmpxchg(&next_page->write, old_write, val);
73079 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
73080 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
73081 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
73082
73083 /*
73084 * No need to worry about races with clearing out the commit.
73085 @@ -1249,12 +1249,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
73086
73087 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
73088 {
73089 - return local_read(&bpage->entries) & RB_WRITE_MASK;
73090 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
73091 }
73092
73093 static inline unsigned long rb_page_write(struct buffer_page *bpage)
73094 {
73095 - return local_read(&bpage->write) & RB_WRITE_MASK;
73096 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
73097 }
73098
73099 static int
73100 @@ -1349,7 +1349,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
73101 * bytes consumed in ring buffer from here.
73102 * Increment overrun to account for the lost events.
73103 */
73104 - local_add(page_entries, &cpu_buffer->overrun);
73105 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
73106 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
73107 }
73108
73109 @@ -1905,7 +1905,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
73110 * it is our responsibility to update
73111 * the counters.
73112 */
73113 - local_add(entries, &cpu_buffer->overrun);
73114 + local_add_unchecked(entries, &cpu_buffer->overrun);
73115 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
73116
73117 /*
73118 @@ -2055,7 +2055,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73119 if (tail == BUF_PAGE_SIZE)
73120 tail_page->real_end = 0;
73121
73122 - local_sub(length, &tail_page->write);
73123 + local_sub_unchecked(length, &tail_page->write);
73124 return;
73125 }
73126
73127 @@ -2090,7 +2090,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73128 rb_event_set_padding(event);
73129
73130 /* Set the write back to the previous setting */
73131 - local_sub(length, &tail_page->write);
73132 + local_sub_unchecked(length, &tail_page->write);
73133 return;
73134 }
73135
73136 @@ -2102,7 +2102,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73137
73138 /* Set write to end of buffer */
73139 length = (tail + length) - BUF_PAGE_SIZE;
73140 - local_sub(length, &tail_page->write);
73141 + local_sub_unchecked(length, &tail_page->write);
73142 }
73143
73144 /*
73145 @@ -2128,7 +2128,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
73146 * about it.
73147 */
73148 if (unlikely(next_page == commit_page)) {
73149 - local_inc(&cpu_buffer->commit_overrun);
73150 + local_inc_unchecked(&cpu_buffer->commit_overrun);
73151 goto out_reset;
73152 }
73153
73154 @@ -2182,7 +2182,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
73155 cpu_buffer->tail_page) &&
73156 (cpu_buffer->commit_page ==
73157 cpu_buffer->reader_page))) {
73158 - local_inc(&cpu_buffer->commit_overrun);
73159 + local_inc_unchecked(&cpu_buffer->commit_overrun);
73160 goto out_reset;
73161 }
73162 }
73163 @@ -2230,7 +2230,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
73164 length += RB_LEN_TIME_EXTEND;
73165
73166 tail_page = cpu_buffer->tail_page;
73167 - write = local_add_return(length, &tail_page->write);
73168 + write = local_add_return_unchecked(length, &tail_page->write);
73169
73170 /* set write to only the index of the write */
73171 write &= RB_WRITE_MASK;
73172 @@ -2247,7 +2247,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
73173 kmemcheck_annotate_bitfield(event, bitfield);
73174 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
73175
73176 - local_inc(&tail_page->entries);
73177 + local_inc_unchecked(&tail_page->entries);
73178
73179 /*
73180 * If this is the first commit on the page, then update
73181 @@ -2280,7 +2280,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
73182
73183 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
73184 unsigned long write_mask =
73185 - local_read(&bpage->write) & ~RB_WRITE_MASK;
73186 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
73187 unsigned long event_length = rb_event_length(event);
73188 /*
73189 * This is on the tail page. It is possible that
73190 @@ -2290,7 +2290,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
73191 */
73192 old_index += write_mask;
73193 new_index += write_mask;
73194 - index = local_cmpxchg(&bpage->write, old_index, new_index);
73195 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
73196 if (index == old_index) {
73197 /* update counters */
73198 local_sub(event_length, &cpu_buffer->entries_bytes);
73199 @@ -2629,7 +2629,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
73200
73201 /* Do the likely case first */
73202 if (likely(bpage->page == (void *)addr)) {
73203 - local_dec(&bpage->entries);
73204 + local_dec_unchecked(&bpage->entries);
73205 return;
73206 }
73207
73208 @@ -2641,7 +2641,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
73209 start = bpage;
73210 do {
73211 if (bpage->page == (void *)addr) {
73212 - local_dec(&bpage->entries);
73213 + local_dec_unchecked(&bpage->entries);
73214 return;
73215 }
73216 rb_inc_page(cpu_buffer, &bpage);
73217 @@ -2923,7 +2923,7 @@ static inline unsigned long
73218 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
73219 {
73220 return local_read(&cpu_buffer->entries) -
73221 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
73222 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
73223 }
73224
73225 /**
73226 @@ -3011,7 +3011,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
73227 return 0;
73228
73229 cpu_buffer = buffer->buffers[cpu];
73230 - ret = local_read(&cpu_buffer->overrun);
73231 + ret = local_read_unchecked(&cpu_buffer->overrun);
73232
73233 return ret;
73234 }
73235 @@ -3032,7 +3032,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
73236 return 0;
73237
73238 cpu_buffer = buffer->buffers[cpu];
73239 - ret = local_read(&cpu_buffer->commit_overrun);
73240 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
73241
73242 return ret;
73243 }
73244 @@ -3077,7 +3077,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
73245 /* if you care about this being correct, lock the buffer */
73246 for_each_buffer_cpu(buffer, cpu) {
73247 cpu_buffer = buffer->buffers[cpu];
73248 - overruns += local_read(&cpu_buffer->overrun);
73249 + overruns += local_read_unchecked(&cpu_buffer->overrun);
73250 }
73251
73252 return overruns;
73253 @@ -3253,8 +3253,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
73254 /*
73255 * Reset the reader page to size zero.
73256 */
73257 - local_set(&cpu_buffer->reader_page->write, 0);
73258 - local_set(&cpu_buffer->reader_page->entries, 0);
73259 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
73260 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
73261 local_set(&cpu_buffer->reader_page->page->commit, 0);
73262 cpu_buffer->reader_page->real_end = 0;
73263
73264 @@ -3288,7 +3288,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
73265 * want to compare with the last_overrun.
73266 */
73267 smp_mb();
73268 - overwrite = local_read(&(cpu_buffer->overrun));
73269 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
73270
73271 /*
73272 * Here's the tricky part.
73273 @@ -3858,8 +3858,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73274
73275 cpu_buffer->head_page
73276 = list_entry(cpu_buffer->pages, struct buffer_page, list);
73277 - local_set(&cpu_buffer->head_page->write, 0);
73278 - local_set(&cpu_buffer->head_page->entries, 0);
73279 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
73280 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
73281 local_set(&cpu_buffer->head_page->page->commit, 0);
73282
73283 cpu_buffer->head_page->read = 0;
73284 @@ -3869,14 +3869,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73285
73286 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
73287 INIT_LIST_HEAD(&cpu_buffer->new_pages);
73288 - local_set(&cpu_buffer->reader_page->write, 0);
73289 - local_set(&cpu_buffer->reader_page->entries, 0);
73290 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
73291 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
73292 local_set(&cpu_buffer->reader_page->page->commit, 0);
73293 cpu_buffer->reader_page->read = 0;
73294
73295 - local_set(&cpu_buffer->commit_overrun, 0);
73296 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
73297 local_set(&cpu_buffer->entries_bytes, 0);
73298 - local_set(&cpu_buffer->overrun, 0);
73299 + local_set_unchecked(&cpu_buffer->overrun, 0);
73300 local_set(&cpu_buffer->entries, 0);
73301 local_set(&cpu_buffer->committing, 0);
73302 local_set(&cpu_buffer->commits, 0);
73303 @@ -4279,8 +4279,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
73304 rb_init_page(bpage);
73305 bpage = reader->page;
73306 reader->page = *data_page;
73307 - local_set(&reader->write, 0);
73308 - local_set(&reader->entries, 0);
73309 + local_set_unchecked(&reader->write, 0);
73310 + local_set_unchecked(&reader->entries, 0);
73311 reader->read = 0;
73312 *data_page = bpage;
73313
73314 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
73315 index 31e4f55..62da00f 100644
73316 --- a/kernel/trace/trace.c
73317 +++ b/kernel/trace/trace.c
73318 @@ -4436,10 +4436,9 @@ static const struct file_operations tracing_dyn_info_fops = {
73319 };
73320 #endif
73321
73322 -static struct dentry *d_tracer;
73323 -
73324 struct dentry *tracing_init_dentry(void)
73325 {
73326 + static struct dentry *d_tracer;
73327 static int once;
73328
73329 if (d_tracer)
73330 @@ -4459,10 +4458,9 @@ struct dentry *tracing_init_dentry(void)
73331 return d_tracer;
73332 }
73333
73334 -static struct dentry *d_percpu;
73335 -
73336 struct dentry *tracing_dentry_percpu(void)
73337 {
73338 + static struct dentry *d_percpu;
73339 static int once;
73340 struct dentry *d_tracer;
73341
73342 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
73343 index d608d09..7eddcb1 100644
73344 --- a/kernel/trace/trace_events.c
73345 +++ b/kernel/trace/trace_events.c
73346 @@ -1320,10 +1320,6 @@ static LIST_HEAD(ftrace_module_file_list);
73347 struct ftrace_module_file_ops {
73348 struct list_head list;
73349 struct module *mod;
73350 - struct file_operations id;
73351 - struct file_operations enable;
73352 - struct file_operations format;
73353 - struct file_operations filter;
73354 };
73355
73356 static struct ftrace_module_file_ops *
73357 @@ -1344,17 +1340,12 @@ trace_create_file_ops(struct module *mod)
73358
73359 file_ops->mod = mod;
73360
73361 - file_ops->id = ftrace_event_id_fops;
73362 - file_ops->id.owner = mod;
73363 -
73364 - file_ops->enable = ftrace_enable_fops;
73365 - file_ops->enable.owner = mod;
73366 -
73367 - file_ops->filter = ftrace_event_filter_fops;
73368 - file_ops->filter.owner = mod;
73369 -
73370 - file_ops->format = ftrace_event_format_fops;
73371 - file_ops->format.owner = mod;
73372 + pax_open_kernel();
73373 + *(void **)&mod->trace_id.owner = mod;
73374 + *(void **)&mod->trace_enable.owner = mod;
73375 + *(void **)&mod->trace_filter.owner = mod;
73376 + *(void **)&mod->trace_format.owner = mod;
73377 + pax_close_kernel();
73378
73379 list_add(&file_ops->list, &ftrace_module_file_list);
73380
73381 @@ -1378,8 +1369,8 @@ static void trace_module_add_events(struct module *mod)
73382
73383 for_each_event(call, start, end) {
73384 __trace_add_event_call(*call, mod,
73385 - &file_ops->id, &file_ops->enable,
73386 - &file_ops->filter, &file_ops->format);
73387 + &mod->trace_id, &mod->trace_enable,
73388 + &mod->trace_filter, &mod->trace_format);
73389 }
73390 }
73391
73392 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
73393 index fd3c8aa..5f324a6 100644
73394 --- a/kernel/trace/trace_mmiotrace.c
73395 +++ b/kernel/trace/trace_mmiotrace.c
73396 @@ -24,7 +24,7 @@ struct header_iter {
73397 static struct trace_array *mmio_trace_array;
73398 static bool overrun_detected;
73399 static unsigned long prev_overruns;
73400 -static atomic_t dropped_count;
73401 +static atomic_unchecked_t dropped_count;
73402
73403 static void mmio_reset_data(struct trace_array *tr)
73404 {
73405 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
73406
73407 static unsigned long count_overruns(struct trace_iterator *iter)
73408 {
73409 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
73410 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
73411 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
73412
73413 if (over > prev_overruns)
73414 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
73415 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
73416 sizeof(*entry), 0, pc);
73417 if (!event) {
73418 - atomic_inc(&dropped_count);
73419 + atomic_inc_unchecked(&dropped_count);
73420 return;
73421 }
73422 entry = ring_buffer_event_data(event);
73423 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
73424 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
73425 sizeof(*entry), 0, pc);
73426 if (!event) {
73427 - atomic_inc(&dropped_count);
73428 + atomic_inc_unchecked(&dropped_count);
73429 return;
73430 }
73431 entry = ring_buffer_event_data(event);
73432 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
73433 index 123b189..1e9e2a6 100644
73434 --- a/kernel/trace/trace_output.c
73435 +++ b/kernel/trace/trace_output.c
73436 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
73437
73438 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
73439 if (!IS_ERR(p)) {
73440 - p = mangle_path(s->buffer + s->len, p, "\n");
73441 + p = mangle_path(s->buffer + s->len, p, "\n\\");
73442 if (p) {
73443 s->len = p - s->buffer;
73444 return 1;
73445 @@ -824,14 +824,16 @@ int register_ftrace_event(struct trace_event *event)
73446 goto out;
73447 }
73448
73449 + pax_open_kernel();
73450 if (event->funcs->trace == NULL)
73451 - event->funcs->trace = trace_nop_print;
73452 + *(void **)&event->funcs->trace = trace_nop_print;
73453 if (event->funcs->raw == NULL)
73454 - event->funcs->raw = trace_nop_print;
73455 + *(void **)&event->funcs->raw = trace_nop_print;
73456 if (event->funcs->hex == NULL)
73457 - event->funcs->hex = trace_nop_print;
73458 + *(void **)&event->funcs->hex = trace_nop_print;
73459 if (event->funcs->binary == NULL)
73460 - event->funcs->binary = trace_nop_print;
73461 + *(void **)&event->funcs->binary = trace_nop_print;
73462 + pax_close_kernel();
73463
73464 key = event->type & (EVENT_HASHSIZE - 1);
73465
73466 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
73467 index 0c1b1657..95337e9 100644
73468 --- a/kernel/trace/trace_stack.c
73469 +++ b/kernel/trace/trace_stack.c
73470 @@ -53,7 +53,7 @@ static inline void check_stack(void)
73471 return;
73472
73473 /* we do not handle interrupt stacks yet */
73474 - if (!object_is_on_stack(&this_size))
73475 + if (!object_starts_on_stack(&this_size))
73476 return;
73477
73478 local_irq_save(flags);
73479 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
73480 index 28e9d6c9..50381bd 100644
73481 --- a/lib/Kconfig.debug
73482 +++ b/lib/Kconfig.debug
73483 @@ -1278,6 +1278,7 @@ config LATENCYTOP
73484 depends on DEBUG_KERNEL
73485 depends on STACKTRACE_SUPPORT
73486 depends on PROC_FS
73487 + depends on !GRKERNSEC_HIDESYM
73488 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
73489 select KALLSYMS
73490 select KALLSYMS_ALL
73491 @@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
73492
73493 config PROVIDE_OHCI1394_DMA_INIT
73494 bool "Remote debugging over FireWire early on boot"
73495 - depends on PCI && X86
73496 + depends on PCI && X86 && !GRKERNSEC
73497 help
73498 If you want to debug problems which hang or crash the kernel early
73499 on boot and the crashing machine has a FireWire port, you can use
73500 @@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
73501
73502 config FIREWIRE_OHCI_REMOTE_DMA
73503 bool "Remote debugging over FireWire with firewire-ohci"
73504 - depends on FIREWIRE_OHCI
73505 + depends on FIREWIRE_OHCI && !GRKERNSEC
73506 help
73507 This option lets you use the FireWire bus for remote debugging
73508 with help of the firewire-ohci driver. It enables unfiltered
73509 diff --git a/lib/Makefile b/lib/Makefile
73510 index a08b791..a3ff1eb 100644
73511 --- a/lib/Makefile
73512 +++ b/lib/Makefile
73513 @@ -46,7 +46,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
73514
73515 obj-$(CONFIG_BTREE) += btree.o
73516 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
73517 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
73518 +obj-y += list_debug.o
73519 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
73520
73521 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
73522 diff --git a/lib/bitmap.c b/lib/bitmap.c
73523 index 06fdfa1..97c5c7d 100644
73524 --- a/lib/bitmap.c
73525 +++ b/lib/bitmap.c
73526 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
73527 {
73528 int c, old_c, totaldigits, ndigits, nchunks, nbits;
73529 u32 chunk;
73530 - const char __user __force *ubuf = (const char __user __force *)buf;
73531 + const char __user *ubuf = (const char __force_user *)buf;
73532
73533 bitmap_zero(maskp, nmaskbits);
73534
73535 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
73536 {
73537 if (!access_ok(VERIFY_READ, ubuf, ulen))
73538 return -EFAULT;
73539 - return __bitmap_parse((const char __force *)ubuf,
73540 + return __bitmap_parse((const char __force_kernel *)ubuf,
73541 ulen, 1, maskp, nmaskbits);
73542
73543 }
73544 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
73545 {
73546 unsigned a, b;
73547 int c, old_c, totaldigits;
73548 - const char __user __force *ubuf = (const char __user __force *)buf;
73549 + const char __user *ubuf = (const char __force_user *)buf;
73550 int exp_digit, in_range;
73551
73552 totaldigits = c = 0;
73553 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
73554 {
73555 if (!access_ok(VERIFY_READ, ubuf, ulen))
73556 return -EFAULT;
73557 - return __bitmap_parselist((const char __force *)ubuf,
73558 + return __bitmap_parselist((const char __force_kernel *)ubuf,
73559 ulen, 1, maskp, nmaskbits);
73560 }
73561 EXPORT_SYMBOL(bitmap_parselist_user);
73562 diff --git a/lib/bug.c b/lib/bug.c
73563 index d0cdf14..4d07bd2 100644
73564 --- a/lib/bug.c
73565 +++ b/lib/bug.c
73566 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
73567 return BUG_TRAP_TYPE_NONE;
73568
73569 bug = find_bug(bugaddr);
73570 + if (!bug)
73571 + return BUG_TRAP_TYPE_NONE;
73572
73573 file = NULL;
73574 line = 0;
73575 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
73576 index d11808c..dc2d6f8 100644
73577 --- a/lib/debugobjects.c
73578 +++ b/lib/debugobjects.c
73579 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
73580 if (limit > 4)
73581 return;
73582
73583 - is_on_stack = object_is_on_stack(addr);
73584 + is_on_stack = object_starts_on_stack(addr);
73585 if (is_on_stack == onstack)
73586 return;
73587
73588 diff --git a/lib/devres.c b/lib/devres.c
73589 index 80b9c76..9e32279 100644
73590 --- a/lib/devres.c
73591 +++ b/lib/devres.c
73592 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
73593 void devm_iounmap(struct device *dev, void __iomem *addr)
73594 {
73595 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
73596 - (void *)addr));
73597 + (void __force *)addr));
73598 iounmap(addr);
73599 }
73600 EXPORT_SYMBOL(devm_iounmap);
73601 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
73602 {
73603 ioport_unmap(addr);
73604 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
73605 - devm_ioport_map_match, (void *)addr));
73606 + devm_ioport_map_match, (void __force *)addr));
73607 }
73608 EXPORT_SYMBOL(devm_ioport_unmap);
73609
73610 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
73611 index d84beb9..da44791 100644
73612 --- a/lib/dma-debug.c
73613 +++ b/lib/dma-debug.c
73614 @@ -754,7 +754,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
73615
73616 void dma_debug_add_bus(struct bus_type *bus)
73617 {
73618 - struct notifier_block *nb;
73619 + notifier_block_no_const *nb;
73620
73621 if (global_disable)
73622 return;
73623 @@ -919,7 +919,7 @@ out:
73624
73625 static void check_for_stack(struct device *dev, void *addr)
73626 {
73627 - if (object_is_on_stack(addr))
73628 + if (object_starts_on_stack(addr))
73629 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
73630 "stack [addr=%p]\n", addr);
73631 }
73632 diff --git a/lib/inflate.c b/lib/inflate.c
73633 index 013a761..c28f3fc 100644
73634 --- a/lib/inflate.c
73635 +++ b/lib/inflate.c
73636 @@ -269,7 +269,7 @@ static void free(void *where)
73637 malloc_ptr = free_mem_ptr;
73638 }
73639 #else
73640 -#define malloc(a) kmalloc(a, GFP_KERNEL)
73641 +#define malloc(a) kmalloc((a), GFP_KERNEL)
73642 #define free(a) kfree(a)
73643 #endif
73644
73645 diff --git a/lib/ioremap.c b/lib/ioremap.c
73646 index 0c9216c..863bd89 100644
73647 --- a/lib/ioremap.c
73648 +++ b/lib/ioremap.c
73649 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
73650 unsigned long next;
73651
73652 phys_addr -= addr;
73653 - pmd = pmd_alloc(&init_mm, pud, addr);
73654 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
73655 if (!pmd)
73656 return -ENOMEM;
73657 do {
73658 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
73659 unsigned long next;
73660
73661 phys_addr -= addr;
73662 - pud = pud_alloc(&init_mm, pgd, addr);
73663 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
73664 if (!pud)
73665 return -ENOMEM;
73666 do {
73667 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
73668 index bd2bea9..6b3c95e 100644
73669 --- a/lib/is_single_threaded.c
73670 +++ b/lib/is_single_threaded.c
73671 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
73672 struct task_struct *p, *t;
73673 bool ret;
73674
73675 + if (!mm)
73676 + return true;
73677 +
73678 if (atomic_read(&task->signal->live) != 1)
73679 return false;
73680
73681 diff --git a/lib/list_debug.c b/lib/list_debug.c
73682 index c24c2f7..3fc5da0 100644
73683 --- a/lib/list_debug.c
73684 +++ b/lib/list_debug.c
73685 @@ -11,7 +11,9 @@
73686 #include <linux/bug.h>
73687 #include <linux/kernel.h>
73688 #include <linux/rculist.h>
73689 +#include <linux/mm.h>
73690
73691 +#ifdef CONFIG_DEBUG_LIST
73692 /*
73693 * Insert a new entry between two known consecutive entries.
73694 *
73695 @@ -19,21 +21,32 @@
73696 * the prev/next entries already!
73697 */
73698
73699 -void __list_add(struct list_head *new,
73700 - struct list_head *prev,
73701 - struct list_head *next)
73702 +static bool __list_add_debug(struct list_head *new,
73703 + struct list_head *prev,
73704 + struct list_head *next)
73705 {
73706 - WARN(next->prev != prev,
73707 + if (WARN(next->prev != prev,
73708 "list_add corruption. next->prev should be "
73709 "prev (%p), but was %p. (next=%p).\n",
73710 - prev, next->prev, next);
73711 - WARN(prev->next != next,
73712 + prev, next->prev, next) ||
73713 + WARN(prev->next != next,
73714 "list_add corruption. prev->next should be "
73715 "next (%p), but was %p. (prev=%p).\n",
73716 - next, prev->next, prev);
73717 - WARN(new == prev || new == next,
73718 + next, prev->next, prev) ||
73719 + WARN(new == prev || new == next,
73720 "list_add double add: new=%p, prev=%p, next=%p.\n",
73721 - new, prev, next);
73722 + new, prev, next))
73723 + return false;
73724 + return true;
73725 +}
73726 +
73727 +void __list_add(struct list_head *new,
73728 + struct list_head *prev,
73729 + struct list_head *next)
73730 +{
73731 + if (!__list_add_debug(new, prev, next))
73732 + return;
73733 +
73734 next->prev = new;
73735 new->next = next;
73736 new->prev = prev;
73737 @@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
73738 }
73739 EXPORT_SYMBOL(__list_add);
73740
73741 -void __list_del_entry(struct list_head *entry)
73742 +static bool __list_del_entry_debug(struct list_head *entry)
73743 {
73744 struct list_head *prev, *next;
73745
73746 @@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
73747 WARN(next->prev != entry,
73748 "list_del corruption. next->prev should be %p, "
73749 "but was %p\n", entry, next->prev))
73750 + return false;
73751 + return true;
73752 +}
73753 +
73754 +void __list_del_entry(struct list_head *entry)
73755 +{
73756 + if (!__list_del_entry_debug(entry))
73757 return;
73758
73759 - __list_del(prev, next);
73760 + __list_del(entry->prev, entry->next);
73761 }
73762 EXPORT_SYMBOL(__list_del_entry);
73763
73764 @@ -86,15 +106,54 @@ EXPORT_SYMBOL(list_del);
73765 void __list_add_rcu(struct list_head *new,
73766 struct list_head *prev, struct list_head *next)
73767 {
73768 - WARN(next->prev != prev,
73769 + if (WARN(next->prev != prev,
73770 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
73771 - prev, next->prev, next);
73772 - WARN(prev->next != next,
73773 + prev, next->prev, next) ||
73774 + WARN(prev->next != next,
73775 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
73776 - next, prev->next, prev);
73777 + next, prev->next, prev))
73778 + return;
73779 +
73780 new->next = next;
73781 new->prev = prev;
73782 rcu_assign_pointer(list_next_rcu(prev), new);
73783 next->prev = new;
73784 }
73785 EXPORT_SYMBOL(__list_add_rcu);
73786 +#endif
73787 +
73788 +void pax_list_add_tail(struct list_head *new, struct list_head *head)
73789 +{
73790 + struct list_head *prev, *next;
73791 +
73792 + prev = head->prev;
73793 + next = head;
73794 +
73795 +#ifdef CONFIG_DEBUG_LIST
73796 + if (!__list_add_debug(new, prev, next))
73797 + return;
73798 +#endif
73799 +
73800 + pax_open_kernel();
73801 + next->prev = new;
73802 + new->next = next;
73803 + new->prev = prev;
73804 + prev->next = new;
73805 + pax_close_kernel();
73806 +}
73807 +EXPORT_SYMBOL(pax_list_add_tail);
73808 +
73809 +void pax_list_del(struct list_head *entry)
73810 +{
73811 +#ifdef CONFIG_DEBUG_LIST
73812 + if (!__list_del_entry_debug(entry))
73813 + return;
73814 +#endif
73815 +
73816 + pax_open_kernel();
73817 + __list_del(entry->prev, entry->next);
73818 + entry->next = LIST_POISON1;
73819 + entry->prev = LIST_POISON2;
73820 + pax_close_kernel();
73821 +}
73822 +EXPORT_SYMBOL(pax_list_del);
73823 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
73824 index e796429..6e38f9f 100644
73825 --- a/lib/radix-tree.c
73826 +++ b/lib/radix-tree.c
73827 @@ -92,7 +92,7 @@ struct radix_tree_preload {
73828 int nr;
73829 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
73830 };
73831 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
73832 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
73833
73834 static inline void *ptr_to_indirect(void *ptr)
73835 {
73836 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
73837 index bb2b201..46abaf9 100644
73838 --- a/lib/strncpy_from_user.c
73839 +++ b/lib/strncpy_from_user.c
73840 @@ -21,7 +21,7 @@
73841 */
73842 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
73843 {
73844 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73845 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73846 long res = 0;
73847
73848 /*
73849 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
73850 index a28df52..3d55877 100644
73851 --- a/lib/strnlen_user.c
73852 +++ b/lib/strnlen_user.c
73853 @@ -26,7 +26,7 @@
73854 */
73855 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
73856 {
73857 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73858 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73859 long align, res = 0;
73860 unsigned long c;
73861
73862 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
73863 index 39c99fe..18f060b 100644
73864 --- a/lib/vsprintf.c
73865 +++ b/lib/vsprintf.c
73866 @@ -16,6 +16,9 @@
73867 * - scnprintf and vscnprintf
73868 */
73869
73870 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73871 +#define __INCLUDED_BY_HIDESYM 1
73872 +#endif
73873 #include <stdarg.h>
73874 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
73875 #include <linux/types.h>
73876 @@ -533,7 +536,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
73877 char sym[KSYM_SYMBOL_LEN];
73878 if (ext == 'B')
73879 sprint_backtrace(sym, value);
73880 - else if (ext != 'f' && ext != 's')
73881 + else if (ext != 'f' && ext != 's' && ext != 'a')
73882 sprint_symbol(sym, value);
73883 else
73884 sprint_symbol_no_offset(sym, value);
73885 @@ -966,7 +969,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
73886 return number(buf, end, *(const netdev_features_t *)addr, spec);
73887 }
73888
73889 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73890 +int kptr_restrict __read_mostly = 2;
73891 +#else
73892 int kptr_restrict __read_mostly;
73893 +#endif
73894
73895 /*
73896 * Show a '%p' thing. A kernel extension is that the '%p' is followed
73897 @@ -980,6 +987,8 @@ int kptr_restrict __read_mostly;
73898 * - 'S' For symbolic direct pointers with offset
73899 * - 's' For symbolic direct pointers without offset
73900 * - 'B' For backtraced symbolic direct pointers with offset
73901 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
73902 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
73903 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
73904 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
73905 * - 'M' For a 6-byte MAC address, it prints the address in the
73906 @@ -1035,12 +1044,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73907
73908 if (!ptr && *fmt != 'K') {
73909 /*
73910 - * Print (null) with the same width as a pointer so it makes
73911 + * Print (nil) with the same width as a pointer so it makes
73912 * tabular output look nice.
73913 */
73914 if (spec.field_width == -1)
73915 spec.field_width = default_width;
73916 - return string(buf, end, "(null)", spec);
73917 + return string(buf, end, "(nil)", spec);
73918 }
73919
73920 switch (*fmt) {
73921 @@ -1050,6 +1059,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73922 /* Fallthrough */
73923 case 'S':
73924 case 's':
73925 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73926 + break;
73927 +#else
73928 + return symbol_string(buf, end, ptr, spec, *fmt);
73929 +#endif
73930 + case 'A':
73931 + case 'a':
73932 case 'B':
73933 return symbol_string(buf, end, ptr, spec, *fmt);
73934 case 'R':
73935 @@ -1090,6 +1106,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73936 va_end(va);
73937 return buf;
73938 }
73939 + case 'P':
73940 + break;
73941 case 'K':
73942 /*
73943 * %pK cannot be used in IRQ context because its test
73944 @@ -1113,6 +1131,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73945 }
73946 break;
73947 }
73948 +
73949 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73950 + /* 'P' = approved pointers to copy to userland,
73951 + as in the /proc/kallsyms case, as we make it display nothing
73952 + for non-root users, and the real contents for root users
73953 + Also ignore 'K' pointers, since we force their NULLing for non-root users
73954 + above
73955 + */
73956 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
73957 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
73958 + dump_stack();
73959 + ptr = NULL;
73960 + }
73961 +#endif
73962 +
73963 spec.flags |= SMALL;
73964 if (spec.field_width == -1) {
73965 spec.field_width = default_width;
73966 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
73967 typeof(type) value; \
73968 if (sizeof(type) == 8) { \
73969 args = PTR_ALIGN(args, sizeof(u32)); \
73970 - *(u32 *)&value = *(u32 *)args; \
73971 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
73972 + *(u32 *)&value = *(const u32 *)args; \
73973 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
73974 } else { \
73975 args = PTR_ALIGN(args, sizeof(type)); \
73976 - value = *(typeof(type) *)args; \
73977 + value = *(const typeof(type) *)args; \
73978 } \
73979 args += sizeof(type); \
73980 value; \
73981 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
73982 case FORMAT_TYPE_STR: {
73983 const char *str_arg = args;
73984 args += strlen(str_arg) + 1;
73985 - str = string(str, end, (char *)str_arg, spec);
73986 + str = string(str, end, str_arg, spec);
73987 break;
73988 }
73989
73990 diff --git a/localversion-grsec b/localversion-grsec
73991 new file mode 100644
73992 index 0000000..7cd6065
73993 --- /dev/null
73994 +++ b/localversion-grsec
73995 @@ -0,0 +1 @@
73996 +-grsec
73997 diff --git a/mm/Kconfig b/mm/Kconfig
73998 index a3f8ddd..f31e92e 100644
73999 --- a/mm/Kconfig
74000 +++ b/mm/Kconfig
74001 @@ -252,10 +252,10 @@ config KSM
74002 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
74003
74004 config DEFAULT_MMAP_MIN_ADDR
74005 - int "Low address space to protect from user allocation"
74006 + int "Low address space to protect from user allocation"
74007 depends on MMU
74008 - default 4096
74009 - help
74010 + default 65536
74011 + help
74012 This is the portion of low virtual memory which should be protected
74013 from userspace allocation. Keeping a user from writing to low pages
74014 can help reduce the impact of kernel NULL pointer bugs.
74015 @@ -286,7 +286,7 @@ config MEMORY_FAILURE
74016
74017 config HWPOISON_INJECT
74018 tristate "HWPoison pages injector"
74019 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
74020 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
74021 select PROC_PAGE_MONITOR
74022
74023 config NOMMU_INITIAL_TRIM_EXCESS
74024 diff --git a/mm/filemap.c b/mm/filemap.c
74025 index 83efee7..3f99381 100644
74026 --- a/mm/filemap.c
74027 +++ b/mm/filemap.c
74028 @@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
74029 struct address_space *mapping = file->f_mapping;
74030
74031 if (!mapping->a_ops->readpage)
74032 - return -ENOEXEC;
74033 + return -ENODEV;
74034 file_accessed(file);
74035 vma->vm_ops = &generic_file_vm_ops;
74036 return 0;
74037 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
74038 *pos = i_size_read(inode);
74039
74040 if (limit != RLIM_INFINITY) {
74041 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
74042 if (*pos >= limit) {
74043 send_sig(SIGXFSZ, current, 0);
74044 return -EFBIG;
74045 diff --git a/mm/fremap.c b/mm/fremap.c
74046 index a0aaf0e..20325c3 100644
74047 --- a/mm/fremap.c
74048 +++ b/mm/fremap.c
74049 @@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
74050 retry:
74051 vma = find_vma(mm, start);
74052
74053 +#ifdef CONFIG_PAX_SEGMEXEC
74054 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
74055 + goto out;
74056 +#endif
74057 +
74058 /*
74059 * Make sure the vma is shared, that it supports prefaulting,
74060 * and that the remapped range is valid and fully within
74061 diff --git a/mm/highmem.c b/mm/highmem.c
74062 index 09fc744..3936897 100644
74063 --- a/mm/highmem.c
74064 +++ b/mm/highmem.c
74065 @@ -138,9 +138,10 @@ static void flush_all_zero_pkmaps(void)
74066 * So no dangers, even with speculative execution.
74067 */
74068 page = pte_page(pkmap_page_table[i]);
74069 + pax_open_kernel();
74070 pte_clear(&init_mm, (unsigned long)page_address(page),
74071 &pkmap_page_table[i]);
74072 -
74073 + pax_close_kernel();
74074 set_page_address(page, NULL);
74075 need_flush = 1;
74076 }
74077 @@ -199,9 +200,11 @@ start:
74078 }
74079 }
74080 vaddr = PKMAP_ADDR(last_pkmap_nr);
74081 +
74082 + pax_open_kernel();
74083 set_pte_at(&init_mm, vaddr,
74084 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
74085 -
74086 + pax_close_kernel();
74087 pkmap_count[last_pkmap_nr] = 1;
74088 set_page_address(page, (void *)vaddr);
74089
74090 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
74091 index 40f17c3..c1cc011 100644
74092 --- a/mm/huge_memory.c
74093 +++ b/mm/huge_memory.c
74094 @@ -710,7 +710,7 @@ out:
74095 * run pte_offset_map on the pmd, if an huge pmd could
74096 * materialize from under us from a different thread.
74097 */
74098 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
74099 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
74100 return VM_FAULT_OOM;
74101 /* if an huge pmd materialized from under us just retry later */
74102 if (unlikely(pmd_trans_huge(*pmd)))
74103 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
74104 index f198aca..a19a5a5 100644
74105 --- a/mm/hugetlb.c
74106 +++ b/mm/hugetlb.c
74107 @@ -2509,6 +2509,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
74108 return 1;
74109 }
74110
74111 +#ifdef CONFIG_PAX_SEGMEXEC
74112 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
74113 +{
74114 + struct mm_struct *mm = vma->vm_mm;
74115 + struct vm_area_struct *vma_m;
74116 + unsigned long address_m;
74117 + pte_t *ptep_m;
74118 +
74119 + vma_m = pax_find_mirror_vma(vma);
74120 + if (!vma_m)
74121 + return;
74122 +
74123 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74124 + address_m = address + SEGMEXEC_TASK_SIZE;
74125 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
74126 + get_page(page_m);
74127 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
74128 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
74129 +}
74130 +#endif
74131 +
74132 /*
74133 * Hugetlb_cow() should be called with page lock of the original hugepage held.
74134 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
74135 @@ -2627,6 +2648,11 @@ retry_avoidcopy:
74136 make_huge_pte(vma, new_page, 1));
74137 page_remove_rmap(old_page);
74138 hugepage_add_new_anon_rmap(new_page, vma, address);
74139 +
74140 +#ifdef CONFIG_PAX_SEGMEXEC
74141 + pax_mirror_huge_pte(vma, address, new_page);
74142 +#endif
74143 +
74144 /* Make the old page be freed below */
74145 new_page = old_page;
74146 }
74147 @@ -2786,6 +2812,10 @@ retry:
74148 && (vma->vm_flags & VM_SHARED)));
74149 set_huge_pte_at(mm, address, ptep, new_pte);
74150
74151 +#ifdef CONFIG_PAX_SEGMEXEC
74152 + pax_mirror_huge_pte(vma, address, page);
74153 +#endif
74154 +
74155 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
74156 /* Optimization, do the COW without a second fault */
74157 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
74158 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74159 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
74160 struct hstate *h = hstate_vma(vma);
74161
74162 +#ifdef CONFIG_PAX_SEGMEXEC
74163 + struct vm_area_struct *vma_m;
74164 +#endif
74165 +
74166 address &= huge_page_mask(h);
74167
74168 ptep = huge_pte_offset(mm, address);
74169 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74170 VM_FAULT_SET_HINDEX(hstate_index(h));
74171 }
74172
74173 +#ifdef CONFIG_PAX_SEGMEXEC
74174 + vma_m = pax_find_mirror_vma(vma);
74175 + if (vma_m) {
74176 + unsigned long address_m;
74177 +
74178 + if (vma->vm_start > vma_m->vm_start) {
74179 + address_m = address;
74180 + address -= SEGMEXEC_TASK_SIZE;
74181 + vma = vma_m;
74182 + h = hstate_vma(vma);
74183 + } else
74184 + address_m = address + SEGMEXEC_TASK_SIZE;
74185 +
74186 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
74187 + return VM_FAULT_OOM;
74188 + address_m &= HPAGE_MASK;
74189 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
74190 + }
74191 +#endif
74192 +
74193 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
74194 if (!ptep)
74195 return VM_FAULT_OOM;
74196 diff --git a/mm/internal.h b/mm/internal.h
74197 index 3c5197d..08d0065 100644
74198 --- a/mm/internal.h
74199 +++ b/mm/internal.h
74200 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
74201 * in mm/page_alloc.c
74202 */
74203 extern void __free_pages_bootmem(struct page *page, unsigned int order);
74204 +extern void free_compound_page(struct page *page);
74205 extern void prep_compound_page(struct page *page, unsigned long order);
74206 #ifdef CONFIG_MEMORY_FAILURE
74207 extern bool is_free_buddy_page(struct page *page);
74208 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
74209 index a217cc5..44b2b35 100644
74210 --- a/mm/kmemleak.c
74211 +++ b/mm/kmemleak.c
74212 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
74213
74214 for (i = 0; i < object->trace_len; i++) {
74215 void *ptr = (void *)object->trace[i];
74216 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
74217 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
74218 }
74219 }
74220
74221 @@ -1852,7 +1852,7 @@ static int __init kmemleak_late_init(void)
74222 return -ENOMEM;
74223 }
74224
74225 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
74226 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
74227 &kmemleak_fops);
74228 if (!dentry)
74229 pr_warning("Failed to create the debugfs kmemleak file\n");
74230 diff --git a/mm/maccess.c b/mm/maccess.c
74231 index d53adf9..03a24bf 100644
74232 --- a/mm/maccess.c
74233 +++ b/mm/maccess.c
74234 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
74235 set_fs(KERNEL_DS);
74236 pagefault_disable();
74237 ret = __copy_from_user_inatomic(dst,
74238 - (__force const void __user *)src, size);
74239 + (const void __force_user *)src, size);
74240 pagefault_enable();
74241 set_fs(old_fs);
74242
74243 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
74244
74245 set_fs(KERNEL_DS);
74246 pagefault_disable();
74247 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
74248 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
74249 pagefault_enable();
74250 set_fs(old_fs);
74251
74252 diff --git a/mm/madvise.c b/mm/madvise.c
74253 index 03dfa5c..b032917 100644
74254 --- a/mm/madvise.c
74255 +++ b/mm/madvise.c
74256 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
74257 pgoff_t pgoff;
74258 unsigned long new_flags = vma->vm_flags;
74259
74260 +#ifdef CONFIG_PAX_SEGMEXEC
74261 + struct vm_area_struct *vma_m;
74262 +#endif
74263 +
74264 switch (behavior) {
74265 case MADV_NORMAL:
74266 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
74267 @@ -123,6 +127,13 @@ success:
74268 /*
74269 * vm_flags is protected by the mmap_sem held in write mode.
74270 */
74271 +
74272 +#ifdef CONFIG_PAX_SEGMEXEC
74273 + vma_m = pax_find_mirror_vma(vma);
74274 + if (vma_m)
74275 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
74276 +#endif
74277 +
74278 vma->vm_flags = new_flags;
74279
74280 out:
74281 @@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74282 struct vm_area_struct ** prev,
74283 unsigned long start, unsigned long end)
74284 {
74285 +
74286 +#ifdef CONFIG_PAX_SEGMEXEC
74287 + struct vm_area_struct *vma_m;
74288 +#endif
74289 +
74290 *prev = vma;
74291 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
74292 return -EINVAL;
74293 @@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74294 zap_page_range(vma, start, end - start, &details);
74295 } else
74296 zap_page_range(vma, start, end - start, NULL);
74297 +
74298 +#ifdef CONFIG_PAX_SEGMEXEC
74299 + vma_m = pax_find_mirror_vma(vma);
74300 + if (vma_m) {
74301 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
74302 + struct zap_details details = {
74303 + .nonlinear_vma = vma_m,
74304 + .last_index = ULONG_MAX,
74305 + };
74306 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
74307 + } else
74308 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
74309 + }
74310 +#endif
74311 +
74312 return 0;
74313 }
74314
74315 @@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
74316 if (end < start)
74317 goto out;
74318
74319 +#ifdef CONFIG_PAX_SEGMEXEC
74320 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74321 + if (end > SEGMEXEC_TASK_SIZE)
74322 + goto out;
74323 + } else
74324 +#endif
74325 +
74326 + if (end > TASK_SIZE)
74327 + goto out;
74328 +
74329 error = 0;
74330 if (end == start)
74331 goto out;
74332 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
74333 index 8b20278..05dac18 100644
74334 --- a/mm/memory-failure.c
74335 +++ b/mm/memory-failure.c
74336 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
74337
74338 int sysctl_memory_failure_recovery __read_mostly = 1;
74339
74340 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74341 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74342
74343 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
74344
74345 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
74346 pfn, t->comm, t->pid);
74347 si.si_signo = SIGBUS;
74348 si.si_errno = 0;
74349 - si.si_addr = (void *)addr;
74350 + si.si_addr = (void __user *)addr;
74351 #ifdef __ARCH_SI_TRAPNO
74352 si.si_trapno = trapno;
74353 #endif
74354 @@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74355 }
74356
74357 nr_pages = 1 << compound_trans_order(hpage);
74358 - atomic_long_add(nr_pages, &mce_bad_pages);
74359 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
74360
74361 /*
74362 * We need/can do nothing about count=0 pages.
74363 @@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74364 if (!PageHWPoison(hpage)
74365 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
74366 || (p != hpage && TestSetPageHWPoison(hpage))) {
74367 - atomic_long_sub(nr_pages, &mce_bad_pages);
74368 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74369 return 0;
74370 }
74371 set_page_hwpoison_huge_page(hpage);
74372 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74373 }
74374 if (hwpoison_filter(p)) {
74375 if (TestClearPageHWPoison(p))
74376 - atomic_long_sub(nr_pages, &mce_bad_pages);
74377 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74378 unlock_page(hpage);
74379 put_page(hpage);
74380 return 0;
74381 @@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
74382 return 0;
74383 }
74384 if (TestClearPageHWPoison(p))
74385 - atomic_long_sub(nr_pages, &mce_bad_pages);
74386 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74387 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
74388 return 0;
74389 }
74390 @@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
74391 */
74392 if (TestClearPageHWPoison(page)) {
74393 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
74394 - atomic_long_sub(nr_pages, &mce_bad_pages);
74395 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74396 freeit = 1;
74397 if (PageHuge(page))
74398 clear_page_hwpoison_huge_page(page);
74399 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
74400 }
74401 done:
74402 if (!PageHWPoison(hpage))
74403 - atomic_long_add(1 << compound_trans_order(hpage),
74404 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
74405 &mce_bad_pages);
74406 set_page_hwpoison_huge_page(hpage);
74407 dequeue_hwpoisoned_huge_page(hpage);
74408 @@ -1582,7 +1582,7 @@ int soft_offline_page(struct page *page, int flags)
74409 return ret;
74410
74411 done:
74412 - atomic_long_add(1, &mce_bad_pages);
74413 + atomic_long_add_unchecked(1, &mce_bad_pages);
74414 SetPageHWPoison(page);
74415 /* keep elevated page count for bad page */
74416 return ret;
74417 diff --git a/mm/memory.c b/mm/memory.c
74418 index f2973b2..fd020a7 100644
74419 --- a/mm/memory.c
74420 +++ b/mm/memory.c
74421 @@ -431,6 +431,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74422 free_pte_range(tlb, pmd, addr);
74423 } while (pmd++, addr = next, addr != end);
74424
74425 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
74426 start &= PUD_MASK;
74427 if (start < floor)
74428 return;
74429 @@ -445,6 +446,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74430 pmd = pmd_offset(pud, start);
74431 pud_clear(pud);
74432 pmd_free_tlb(tlb, pmd, start);
74433 +#endif
74434 +
74435 }
74436
74437 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74438 @@ -464,6 +467,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74439 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
74440 } while (pud++, addr = next, addr != end);
74441
74442 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
74443 start &= PGDIR_MASK;
74444 if (start < floor)
74445 return;
74446 @@ -478,6 +482,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74447 pud = pud_offset(pgd, start);
74448 pgd_clear(pgd);
74449 pud_free_tlb(tlb, pud, start);
74450 +#endif
74451 +
74452 }
74453
74454 /*
74455 @@ -1626,12 +1632,6 @@ no_page_table:
74456 return page;
74457 }
74458
74459 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
74460 -{
74461 - return stack_guard_page_start(vma, addr) ||
74462 - stack_guard_page_end(vma, addr+PAGE_SIZE);
74463 -}
74464 -
74465 /**
74466 * __get_user_pages() - pin user pages in memory
74467 * @tsk: task_struct of target task
74468 @@ -1704,10 +1704,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74469 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
74470 i = 0;
74471
74472 - do {
74473 + while (nr_pages) {
74474 struct vm_area_struct *vma;
74475
74476 - vma = find_extend_vma(mm, start);
74477 + vma = find_vma(mm, start);
74478 if (!vma && in_gate_area(mm, start)) {
74479 unsigned long pg = start & PAGE_MASK;
74480 pgd_t *pgd;
74481 @@ -1755,7 +1755,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74482 goto next_page;
74483 }
74484
74485 - if (!vma ||
74486 + if (!vma || start < vma->vm_start ||
74487 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
74488 !(vm_flags & vma->vm_flags))
74489 return i ? : -EFAULT;
74490 @@ -1782,11 +1782,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74491 int ret;
74492 unsigned int fault_flags = 0;
74493
74494 - /* For mlock, just skip the stack guard page. */
74495 - if (foll_flags & FOLL_MLOCK) {
74496 - if (stack_guard_page(vma, start))
74497 - goto next_page;
74498 - }
74499 if (foll_flags & FOLL_WRITE)
74500 fault_flags |= FAULT_FLAG_WRITE;
74501 if (nonblocking)
74502 @@ -1860,7 +1855,7 @@ next_page:
74503 start += PAGE_SIZE;
74504 nr_pages--;
74505 } while (nr_pages && start < vma->vm_end);
74506 - } while (nr_pages);
74507 + }
74508 return i;
74509 }
74510 EXPORT_SYMBOL(__get_user_pages);
74511 @@ -2067,6 +2062,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
74512 page_add_file_rmap(page);
74513 set_pte_at(mm, addr, pte, mk_pte(page, prot));
74514
74515 +#ifdef CONFIG_PAX_SEGMEXEC
74516 + pax_mirror_file_pte(vma, addr, page, ptl);
74517 +#endif
74518 +
74519 retval = 0;
74520 pte_unmap_unlock(pte, ptl);
74521 return retval;
74522 @@ -2111,9 +2110,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
74523 if (!page_count(page))
74524 return -EINVAL;
74525 if (!(vma->vm_flags & VM_MIXEDMAP)) {
74526 +
74527 +#ifdef CONFIG_PAX_SEGMEXEC
74528 + struct vm_area_struct *vma_m;
74529 +#endif
74530 +
74531 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
74532 BUG_ON(vma->vm_flags & VM_PFNMAP);
74533 vma->vm_flags |= VM_MIXEDMAP;
74534 +
74535 +#ifdef CONFIG_PAX_SEGMEXEC
74536 + vma_m = pax_find_mirror_vma(vma);
74537 + if (vma_m)
74538 + vma_m->vm_flags |= VM_MIXEDMAP;
74539 +#endif
74540 +
74541 }
74542 return insert_page(vma, addr, page, vma->vm_page_prot);
74543 }
74544 @@ -2196,6 +2207,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
74545 unsigned long pfn)
74546 {
74547 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
74548 + BUG_ON(vma->vm_mirror);
74549
74550 if (addr < vma->vm_start || addr >= vma->vm_end)
74551 return -EFAULT;
74552 @@ -2396,7 +2408,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
74553
74554 BUG_ON(pud_huge(*pud));
74555
74556 - pmd = pmd_alloc(mm, pud, addr);
74557 + pmd = (mm == &init_mm) ?
74558 + pmd_alloc_kernel(mm, pud, addr) :
74559 + pmd_alloc(mm, pud, addr);
74560 if (!pmd)
74561 return -ENOMEM;
74562 do {
74563 @@ -2416,7 +2430,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
74564 unsigned long next;
74565 int err;
74566
74567 - pud = pud_alloc(mm, pgd, addr);
74568 + pud = (mm == &init_mm) ?
74569 + pud_alloc_kernel(mm, pgd, addr) :
74570 + pud_alloc(mm, pgd, addr);
74571 if (!pud)
74572 return -ENOMEM;
74573 do {
74574 @@ -2504,6 +2520,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
74575 copy_user_highpage(dst, src, va, vma);
74576 }
74577
74578 +#ifdef CONFIG_PAX_SEGMEXEC
74579 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
74580 +{
74581 + struct mm_struct *mm = vma->vm_mm;
74582 + spinlock_t *ptl;
74583 + pte_t *pte, entry;
74584 +
74585 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
74586 + entry = *pte;
74587 + if (!pte_present(entry)) {
74588 + if (!pte_none(entry)) {
74589 + BUG_ON(pte_file(entry));
74590 + free_swap_and_cache(pte_to_swp_entry(entry));
74591 + pte_clear_not_present_full(mm, address, pte, 0);
74592 + }
74593 + } else {
74594 + struct page *page;
74595 +
74596 + flush_cache_page(vma, address, pte_pfn(entry));
74597 + entry = ptep_clear_flush(vma, address, pte);
74598 + BUG_ON(pte_dirty(entry));
74599 + page = vm_normal_page(vma, address, entry);
74600 + if (page) {
74601 + update_hiwater_rss(mm);
74602 + if (PageAnon(page))
74603 + dec_mm_counter_fast(mm, MM_ANONPAGES);
74604 + else
74605 + dec_mm_counter_fast(mm, MM_FILEPAGES);
74606 + page_remove_rmap(page);
74607 + page_cache_release(page);
74608 + }
74609 + }
74610 + pte_unmap_unlock(pte, ptl);
74611 +}
74612 +
74613 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
74614 + *
74615 + * the ptl of the lower mapped page is held on entry and is not released on exit
74616 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
74617 + */
74618 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74619 +{
74620 + struct mm_struct *mm = vma->vm_mm;
74621 + unsigned long address_m;
74622 + spinlock_t *ptl_m;
74623 + struct vm_area_struct *vma_m;
74624 + pmd_t *pmd_m;
74625 + pte_t *pte_m, entry_m;
74626 +
74627 + BUG_ON(!page_m || !PageAnon(page_m));
74628 +
74629 + vma_m = pax_find_mirror_vma(vma);
74630 + if (!vma_m)
74631 + return;
74632 +
74633 + BUG_ON(!PageLocked(page_m));
74634 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74635 + address_m = address + SEGMEXEC_TASK_SIZE;
74636 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74637 + pte_m = pte_offset_map(pmd_m, address_m);
74638 + ptl_m = pte_lockptr(mm, pmd_m);
74639 + if (ptl != ptl_m) {
74640 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74641 + if (!pte_none(*pte_m))
74642 + goto out;
74643 + }
74644 +
74645 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74646 + page_cache_get(page_m);
74647 + page_add_anon_rmap(page_m, vma_m, address_m);
74648 + inc_mm_counter_fast(mm, MM_ANONPAGES);
74649 + set_pte_at(mm, address_m, pte_m, entry_m);
74650 + update_mmu_cache(vma_m, address_m, entry_m);
74651 +out:
74652 + if (ptl != ptl_m)
74653 + spin_unlock(ptl_m);
74654 + pte_unmap(pte_m);
74655 + unlock_page(page_m);
74656 +}
74657 +
74658 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74659 +{
74660 + struct mm_struct *mm = vma->vm_mm;
74661 + unsigned long address_m;
74662 + spinlock_t *ptl_m;
74663 + struct vm_area_struct *vma_m;
74664 + pmd_t *pmd_m;
74665 + pte_t *pte_m, entry_m;
74666 +
74667 + BUG_ON(!page_m || PageAnon(page_m));
74668 +
74669 + vma_m = pax_find_mirror_vma(vma);
74670 + if (!vma_m)
74671 + return;
74672 +
74673 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74674 + address_m = address + SEGMEXEC_TASK_SIZE;
74675 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74676 + pte_m = pte_offset_map(pmd_m, address_m);
74677 + ptl_m = pte_lockptr(mm, pmd_m);
74678 + if (ptl != ptl_m) {
74679 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74680 + if (!pte_none(*pte_m))
74681 + goto out;
74682 + }
74683 +
74684 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74685 + page_cache_get(page_m);
74686 + page_add_file_rmap(page_m);
74687 + inc_mm_counter_fast(mm, MM_FILEPAGES);
74688 + set_pte_at(mm, address_m, pte_m, entry_m);
74689 + update_mmu_cache(vma_m, address_m, entry_m);
74690 +out:
74691 + if (ptl != ptl_m)
74692 + spin_unlock(ptl_m);
74693 + pte_unmap(pte_m);
74694 +}
74695 +
74696 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
74697 +{
74698 + struct mm_struct *mm = vma->vm_mm;
74699 + unsigned long address_m;
74700 + spinlock_t *ptl_m;
74701 + struct vm_area_struct *vma_m;
74702 + pmd_t *pmd_m;
74703 + pte_t *pte_m, entry_m;
74704 +
74705 + vma_m = pax_find_mirror_vma(vma);
74706 + if (!vma_m)
74707 + return;
74708 +
74709 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74710 + address_m = address + SEGMEXEC_TASK_SIZE;
74711 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74712 + pte_m = pte_offset_map(pmd_m, address_m);
74713 + ptl_m = pte_lockptr(mm, pmd_m);
74714 + if (ptl != ptl_m) {
74715 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74716 + if (!pte_none(*pte_m))
74717 + goto out;
74718 + }
74719 +
74720 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
74721 + set_pte_at(mm, address_m, pte_m, entry_m);
74722 +out:
74723 + if (ptl != ptl_m)
74724 + spin_unlock(ptl_m);
74725 + pte_unmap(pte_m);
74726 +}
74727 +
74728 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
74729 +{
74730 + struct page *page_m;
74731 + pte_t entry;
74732 +
74733 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
74734 + goto out;
74735 +
74736 + entry = *pte;
74737 + page_m = vm_normal_page(vma, address, entry);
74738 + if (!page_m)
74739 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
74740 + else if (PageAnon(page_m)) {
74741 + if (pax_find_mirror_vma(vma)) {
74742 + pte_unmap_unlock(pte, ptl);
74743 + lock_page(page_m);
74744 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
74745 + if (pte_same(entry, *pte))
74746 + pax_mirror_anon_pte(vma, address, page_m, ptl);
74747 + else
74748 + unlock_page(page_m);
74749 + }
74750 + } else
74751 + pax_mirror_file_pte(vma, address, page_m, ptl);
74752 +
74753 +out:
74754 + pte_unmap_unlock(pte, ptl);
74755 +}
74756 +#endif
74757 +
74758 /*
74759 * This routine handles present pages, when users try to write
74760 * to a shared page. It is done by copying the page to a new address
74761 @@ -2720,6 +2916,12 @@ gotten:
74762 */
74763 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74764 if (likely(pte_same(*page_table, orig_pte))) {
74765 +
74766 +#ifdef CONFIG_PAX_SEGMEXEC
74767 + if (pax_find_mirror_vma(vma))
74768 + BUG_ON(!trylock_page(new_page));
74769 +#endif
74770 +
74771 if (old_page) {
74772 if (!PageAnon(old_page)) {
74773 dec_mm_counter_fast(mm, MM_FILEPAGES);
74774 @@ -2771,6 +2973,10 @@ gotten:
74775 page_remove_rmap(old_page);
74776 }
74777
74778 +#ifdef CONFIG_PAX_SEGMEXEC
74779 + pax_mirror_anon_pte(vma, address, new_page, ptl);
74780 +#endif
74781 +
74782 /* Free the old page.. */
74783 new_page = old_page;
74784 ret |= VM_FAULT_WRITE;
74785 @@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74786 swap_free(entry);
74787 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
74788 try_to_free_swap(page);
74789 +
74790 +#ifdef CONFIG_PAX_SEGMEXEC
74791 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
74792 +#endif
74793 +
74794 unlock_page(page);
74795 if (swapcache) {
74796 /*
74797 @@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74798
74799 /* No need to invalidate - it was non-present before */
74800 update_mmu_cache(vma, address, page_table);
74801 +
74802 +#ifdef CONFIG_PAX_SEGMEXEC
74803 + pax_mirror_anon_pte(vma, address, page, ptl);
74804 +#endif
74805 +
74806 unlock:
74807 pte_unmap_unlock(page_table, ptl);
74808 out:
74809 @@ -3093,40 +3309,6 @@ out_release:
74810 }
74811
74812 /*
74813 - * This is like a special single-page "expand_{down|up}wards()",
74814 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
74815 - * doesn't hit another vma.
74816 - */
74817 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
74818 -{
74819 - address &= PAGE_MASK;
74820 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
74821 - struct vm_area_struct *prev = vma->vm_prev;
74822 -
74823 - /*
74824 - * Is there a mapping abutting this one below?
74825 - *
74826 - * That's only ok if it's the same stack mapping
74827 - * that has gotten split..
74828 - */
74829 - if (prev && prev->vm_end == address)
74830 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
74831 -
74832 - expand_downwards(vma, address - PAGE_SIZE);
74833 - }
74834 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
74835 - struct vm_area_struct *next = vma->vm_next;
74836 -
74837 - /* As VM_GROWSDOWN but s/below/above/ */
74838 - if (next && next->vm_start == address + PAGE_SIZE)
74839 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
74840 -
74841 - expand_upwards(vma, address + PAGE_SIZE);
74842 - }
74843 - return 0;
74844 -}
74845 -
74846 -/*
74847 * We enter with non-exclusive mmap_sem (to exclude vma changes,
74848 * but allow concurrent faults), and pte mapped but not yet locked.
74849 * We return with mmap_sem still held, but pte unmapped and unlocked.
74850 @@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74851 unsigned long address, pte_t *page_table, pmd_t *pmd,
74852 unsigned int flags)
74853 {
74854 - struct page *page;
74855 + struct page *page = NULL;
74856 spinlock_t *ptl;
74857 pte_t entry;
74858
74859 - pte_unmap(page_table);
74860 -
74861 - /* Check if we need to add a guard page to the stack */
74862 - if (check_stack_guard_page(vma, address) < 0)
74863 - return VM_FAULT_SIGBUS;
74864 -
74865 - /* Use the zero-page for reads */
74866 if (!(flags & FAULT_FLAG_WRITE)) {
74867 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
74868 vma->vm_page_prot));
74869 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74870 + ptl = pte_lockptr(mm, pmd);
74871 + spin_lock(ptl);
74872 if (!pte_none(*page_table))
74873 goto unlock;
74874 goto setpte;
74875 }
74876
74877 /* Allocate our own private page. */
74878 + pte_unmap(page_table);
74879 +
74880 if (unlikely(anon_vma_prepare(vma)))
74881 goto oom;
74882 page = alloc_zeroed_user_highpage_movable(vma, address);
74883 @@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74884 if (!pte_none(*page_table))
74885 goto release;
74886
74887 +#ifdef CONFIG_PAX_SEGMEXEC
74888 + if (pax_find_mirror_vma(vma))
74889 + BUG_ON(!trylock_page(page));
74890 +#endif
74891 +
74892 inc_mm_counter_fast(mm, MM_ANONPAGES);
74893 page_add_new_anon_rmap(page, vma, address);
74894 setpte:
74895 @@ -3181,6 +3364,12 @@ setpte:
74896
74897 /* No need to invalidate - it was non-present before */
74898 update_mmu_cache(vma, address, page_table);
74899 +
74900 +#ifdef CONFIG_PAX_SEGMEXEC
74901 + if (page)
74902 + pax_mirror_anon_pte(vma, address, page, ptl);
74903 +#endif
74904 +
74905 unlock:
74906 pte_unmap_unlock(page_table, ptl);
74907 return 0;
74908 @@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74909 */
74910 /* Only go through if we didn't race with anybody else... */
74911 if (likely(pte_same(*page_table, orig_pte))) {
74912 +
74913 +#ifdef CONFIG_PAX_SEGMEXEC
74914 + if (anon && pax_find_mirror_vma(vma))
74915 + BUG_ON(!trylock_page(page));
74916 +#endif
74917 +
74918 flush_icache_page(vma, page);
74919 entry = mk_pte(page, vma->vm_page_prot);
74920 if (flags & FAULT_FLAG_WRITE)
74921 @@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74922
74923 /* no need to invalidate: a not-present page won't be cached */
74924 update_mmu_cache(vma, address, page_table);
74925 +
74926 +#ifdef CONFIG_PAX_SEGMEXEC
74927 + if (anon)
74928 + pax_mirror_anon_pte(vma, address, page, ptl);
74929 + else
74930 + pax_mirror_file_pte(vma, address, page, ptl);
74931 +#endif
74932 +
74933 } else {
74934 if (cow_page)
74935 mem_cgroup_uncharge_page(cow_page);
74936 @@ -3497,6 +3700,12 @@ int handle_pte_fault(struct mm_struct *mm,
74937 if (flags & FAULT_FLAG_WRITE)
74938 flush_tlb_fix_spurious_fault(vma, address);
74939 }
74940 +
74941 +#ifdef CONFIG_PAX_SEGMEXEC
74942 + pax_mirror_pte(vma, address, pte, pmd, ptl);
74943 + return 0;
74944 +#endif
74945 +
74946 unlock:
74947 pte_unmap_unlock(pte, ptl);
74948 return 0;
74949 @@ -3513,6 +3722,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74950 pmd_t *pmd;
74951 pte_t *pte;
74952
74953 +#ifdef CONFIG_PAX_SEGMEXEC
74954 + struct vm_area_struct *vma_m;
74955 +#endif
74956 +
74957 __set_current_state(TASK_RUNNING);
74958
74959 count_vm_event(PGFAULT);
74960 @@ -3524,6 +3737,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74961 if (unlikely(is_vm_hugetlb_page(vma)))
74962 return hugetlb_fault(mm, vma, address, flags);
74963
74964 +#ifdef CONFIG_PAX_SEGMEXEC
74965 + vma_m = pax_find_mirror_vma(vma);
74966 + if (vma_m) {
74967 + unsigned long address_m;
74968 + pgd_t *pgd_m;
74969 + pud_t *pud_m;
74970 + pmd_t *pmd_m;
74971 +
74972 + if (vma->vm_start > vma_m->vm_start) {
74973 + address_m = address;
74974 + address -= SEGMEXEC_TASK_SIZE;
74975 + vma = vma_m;
74976 + } else
74977 + address_m = address + SEGMEXEC_TASK_SIZE;
74978 +
74979 + pgd_m = pgd_offset(mm, address_m);
74980 + pud_m = pud_alloc(mm, pgd_m, address_m);
74981 + if (!pud_m)
74982 + return VM_FAULT_OOM;
74983 + pmd_m = pmd_alloc(mm, pud_m, address_m);
74984 + if (!pmd_m)
74985 + return VM_FAULT_OOM;
74986 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
74987 + return VM_FAULT_OOM;
74988 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
74989 + }
74990 +#endif
74991 +
74992 retry:
74993 pgd = pgd_offset(mm, address);
74994 pud = pud_alloc(mm, pgd, address);
74995 @@ -3565,7 +3806,7 @@ retry:
74996 * run pte_offset_map on the pmd, if an huge pmd could
74997 * materialize from under us from a different thread.
74998 */
74999 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
75000 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
75001 return VM_FAULT_OOM;
75002 /* if an huge pmd materialized from under us just retry later */
75003 if (unlikely(pmd_trans_huge(*pmd)))
75004 @@ -3602,6 +3843,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75005 spin_unlock(&mm->page_table_lock);
75006 return 0;
75007 }
75008 +
75009 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75010 +{
75011 + pud_t *new = pud_alloc_one(mm, address);
75012 + if (!new)
75013 + return -ENOMEM;
75014 +
75015 + smp_wmb(); /* See comment in __pte_alloc */
75016 +
75017 + spin_lock(&mm->page_table_lock);
75018 + if (pgd_present(*pgd)) /* Another has populated it */
75019 + pud_free(mm, new);
75020 + else
75021 + pgd_populate_kernel(mm, pgd, new);
75022 + spin_unlock(&mm->page_table_lock);
75023 + return 0;
75024 +}
75025 #endif /* __PAGETABLE_PUD_FOLDED */
75026
75027 #ifndef __PAGETABLE_PMD_FOLDED
75028 @@ -3632,6 +3890,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
75029 spin_unlock(&mm->page_table_lock);
75030 return 0;
75031 }
75032 +
75033 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
75034 +{
75035 + pmd_t *new = pmd_alloc_one(mm, address);
75036 + if (!new)
75037 + return -ENOMEM;
75038 +
75039 + smp_wmb(); /* See comment in __pte_alloc */
75040 +
75041 + spin_lock(&mm->page_table_lock);
75042 +#ifndef __ARCH_HAS_4LEVEL_HACK
75043 + if (pud_present(*pud)) /* Another has populated it */
75044 + pmd_free(mm, new);
75045 + else
75046 + pud_populate_kernel(mm, pud, new);
75047 +#else
75048 + if (pgd_present(*pud)) /* Another has populated it */
75049 + pmd_free(mm, new);
75050 + else
75051 + pgd_populate_kernel(mm, pud, new);
75052 +#endif /* __ARCH_HAS_4LEVEL_HACK */
75053 + spin_unlock(&mm->page_table_lock);
75054 + return 0;
75055 +}
75056 #endif /* __PAGETABLE_PMD_FOLDED */
75057
75058 int make_pages_present(unsigned long addr, unsigned long end)
75059 @@ -3669,7 +3951,7 @@ static int __init gate_vma_init(void)
75060 gate_vma.vm_start = FIXADDR_USER_START;
75061 gate_vma.vm_end = FIXADDR_USER_END;
75062 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
75063 - gate_vma.vm_page_prot = __P101;
75064 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
75065
75066 return 0;
75067 }
75068 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
75069 index 002c281..9429765 100644
75070 --- a/mm/mempolicy.c
75071 +++ b/mm/mempolicy.c
75072 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
75073 unsigned long vmstart;
75074 unsigned long vmend;
75075
75076 +#ifdef CONFIG_PAX_SEGMEXEC
75077 + struct vm_area_struct *vma_m;
75078 +#endif
75079 +
75080 vma = find_vma(mm, start);
75081 if (!vma || vma->vm_start > start)
75082 return -EFAULT;
75083 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
75084 if (err)
75085 goto out;
75086 }
75087 +
75088 err = vma_replace_policy(vma, new_pol);
75089 if (err)
75090 goto out;
75091 +
75092 +#ifdef CONFIG_PAX_SEGMEXEC
75093 + vma_m = pax_find_mirror_vma(vma);
75094 + if (vma_m) {
75095 + err = vma_replace_policy(vma_m, new_pol);
75096 + if (err)
75097 + goto out;
75098 + }
75099 +#endif
75100 +
75101 }
75102
75103 out:
75104 @@ -1150,6 +1165,17 @@ static long do_mbind(unsigned long start, unsigned long len,
75105
75106 if (end < start)
75107 return -EINVAL;
75108 +
75109 +#ifdef CONFIG_PAX_SEGMEXEC
75110 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
75111 + if (end > SEGMEXEC_TASK_SIZE)
75112 + return -EINVAL;
75113 + } else
75114 +#endif
75115 +
75116 + if (end > TASK_SIZE)
75117 + return -EINVAL;
75118 +
75119 if (end == start)
75120 return 0;
75121
75122 @@ -1373,8 +1399,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
75123 */
75124 tcred = __task_cred(task);
75125 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
75126 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
75127 - !capable(CAP_SYS_NICE)) {
75128 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
75129 rcu_read_unlock();
75130 err = -EPERM;
75131 goto out_put;
75132 @@ -1405,6 +1430,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
75133 goto out;
75134 }
75135
75136 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
75137 + if (mm != current->mm &&
75138 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
75139 + mmput(mm);
75140 + err = -EPERM;
75141 + goto out;
75142 + }
75143 +#endif
75144 +
75145 err = do_migrate_pages(mm, old, new,
75146 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
75147
75148 diff --git a/mm/migrate.c b/mm/migrate.c
75149 index 77ed2d7..317d528 100644
75150 --- a/mm/migrate.c
75151 +++ b/mm/migrate.c
75152 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
75153 */
75154 tcred = __task_cred(task);
75155 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
75156 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
75157 - !capable(CAP_SYS_NICE)) {
75158 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
75159 rcu_read_unlock();
75160 err = -EPERM;
75161 goto out;
75162 diff --git a/mm/mlock.c b/mm/mlock.c
75163 index f0b9ce5..da8d069 100644
75164 --- a/mm/mlock.c
75165 +++ b/mm/mlock.c
75166 @@ -13,6 +13,7 @@
75167 #include <linux/pagemap.h>
75168 #include <linux/mempolicy.h>
75169 #include <linux/syscalls.h>
75170 +#include <linux/security.h>
75171 #include <linux/sched.h>
75172 #include <linux/export.h>
75173 #include <linux/rmap.h>
75174 @@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
75175 {
75176 unsigned long nstart, end, tmp;
75177 struct vm_area_struct * vma, * prev;
75178 - int error;
75179 + int error = 0;
75180
75181 VM_BUG_ON(start & ~PAGE_MASK);
75182 VM_BUG_ON(len != PAGE_ALIGN(len));
75183 @@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
75184 return -EINVAL;
75185 if (end == start)
75186 return 0;
75187 + if (end > TASK_SIZE)
75188 + return -EINVAL;
75189 +
75190 vma = find_vma(current->mm, start);
75191 if (!vma || vma->vm_start > start)
75192 return -ENOMEM;
75193 @@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
75194 for (nstart = start ; ; ) {
75195 vm_flags_t newflags;
75196
75197 +#ifdef CONFIG_PAX_SEGMEXEC
75198 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
75199 + break;
75200 +#endif
75201 +
75202 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
75203
75204 newflags = vma->vm_flags | VM_LOCKED;
75205 @@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
75206 lock_limit >>= PAGE_SHIFT;
75207
75208 /* check against resource limits */
75209 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
75210 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
75211 error = do_mlock(start, len, 1);
75212 up_write(&current->mm->mmap_sem);
75213 @@ -517,17 +527,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
75214 static int do_mlockall(int flags)
75215 {
75216 struct vm_area_struct * vma, * prev = NULL;
75217 - unsigned int def_flags = 0;
75218
75219 if (flags & MCL_FUTURE)
75220 - def_flags = VM_LOCKED;
75221 - current->mm->def_flags = def_flags;
75222 + current->mm->def_flags |= VM_LOCKED;
75223 + else
75224 + current->mm->def_flags &= ~VM_LOCKED;
75225 if (flags == MCL_FUTURE)
75226 goto out;
75227
75228 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
75229 vm_flags_t newflags;
75230
75231 +#ifdef CONFIG_PAX_SEGMEXEC
75232 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
75233 + break;
75234 +#endif
75235 +
75236 + BUG_ON(vma->vm_end > TASK_SIZE);
75237 newflags = vma->vm_flags | VM_LOCKED;
75238 if (!(flags & MCL_CURRENT))
75239 newflags &= ~VM_LOCKED;
75240 @@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
75241 lock_limit >>= PAGE_SHIFT;
75242
75243 ret = -ENOMEM;
75244 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
75245 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
75246 capable(CAP_IPC_LOCK))
75247 ret = do_mlockall(flags);
75248 diff --git a/mm/mmap.c b/mm/mmap.c
75249 index 9a796c4..21f8e50 100644
75250 --- a/mm/mmap.c
75251 +++ b/mm/mmap.c
75252 @@ -31,6 +31,7 @@
75253 #include <linux/audit.h>
75254 #include <linux/khugepaged.h>
75255 #include <linux/uprobes.h>
75256 +#include <linux/random.h>
75257
75258 #include <asm/uaccess.h>
75259 #include <asm/cacheflush.h>
75260 @@ -47,6 +48,16 @@
75261 #define arch_rebalance_pgtables(addr, len) (addr)
75262 #endif
75263
75264 +static inline void verify_mm_writelocked(struct mm_struct *mm)
75265 +{
75266 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
75267 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
75268 + up_read(&mm->mmap_sem);
75269 + BUG();
75270 + }
75271 +#endif
75272 +}
75273 +
75274 static void unmap_region(struct mm_struct *mm,
75275 struct vm_area_struct *vma, struct vm_area_struct *prev,
75276 unsigned long start, unsigned long end);
75277 @@ -66,22 +77,32 @@ static void unmap_region(struct mm_struct *mm,
75278 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
75279 *
75280 */
75281 -pgprot_t protection_map[16] = {
75282 +pgprot_t protection_map[16] __read_only = {
75283 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
75284 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
75285 };
75286
75287 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
75288 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
75289 {
75290 - return __pgprot(pgprot_val(protection_map[vm_flags &
75291 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
75292 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
75293 pgprot_val(arch_vm_get_page_prot(vm_flags)));
75294 +
75295 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75296 + if (!(__supported_pte_mask & _PAGE_NX) &&
75297 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
75298 + (vm_flags & (VM_READ | VM_WRITE)))
75299 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
75300 +#endif
75301 +
75302 + return prot;
75303 }
75304 EXPORT_SYMBOL(vm_get_page_prot);
75305
75306 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
75307 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
75308 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
75309 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
75310 /*
75311 * Make sure vm_committed_as in one cacheline and not cacheline shared with
75312 * other variables. It can be updated by several CPUs frequently.
75313 @@ -223,6 +244,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
75314 struct vm_area_struct *next = vma->vm_next;
75315
75316 might_sleep();
75317 + BUG_ON(vma->vm_mirror);
75318 if (vma->vm_ops && vma->vm_ops->close)
75319 vma->vm_ops->close(vma);
75320 if (vma->vm_file)
75321 @@ -266,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
75322 * not page aligned -Ram Gupta
75323 */
75324 rlim = rlimit(RLIMIT_DATA);
75325 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
75326 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
75327 (mm->end_data - mm->start_data) > rlim)
75328 goto out;
75329 @@ -736,6 +759,12 @@ static int
75330 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
75331 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75332 {
75333 +
75334 +#ifdef CONFIG_PAX_SEGMEXEC
75335 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
75336 + return 0;
75337 +#endif
75338 +
75339 if (is_mergeable_vma(vma, file, vm_flags) &&
75340 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75341 if (vma->vm_pgoff == vm_pgoff)
75342 @@ -755,6 +784,12 @@ static int
75343 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75344 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75345 {
75346 +
75347 +#ifdef CONFIG_PAX_SEGMEXEC
75348 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
75349 + return 0;
75350 +#endif
75351 +
75352 if (is_mergeable_vma(vma, file, vm_flags) &&
75353 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75354 pgoff_t vm_pglen;
75355 @@ -797,13 +832,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75356 struct vm_area_struct *vma_merge(struct mm_struct *mm,
75357 struct vm_area_struct *prev, unsigned long addr,
75358 unsigned long end, unsigned long vm_flags,
75359 - struct anon_vma *anon_vma, struct file *file,
75360 + struct anon_vma *anon_vma, struct file *file,
75361 pgoff_t pgoff, struct mempolicy *policy)
75362 {
75363 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
75364 struct vm_area_struct *area, *next;
75365 int err;
75366
75367 +#ifdef CONFIG_PAX_SEGMEXEC
75368 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
75369 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
75370 +
75371 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
75372 +#endif
75373 +
75374 /*
75375 * We later require that vma->vm_flags == vm_flags,
75376 * so this tests vma->vm_flags & VM_SPECIAL, too.
75377 @@ -819,6 +861,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75378 if (next && next->vm_end == end) /* cases 6, 7, 8 */
75379 next = next->vm_next;
75380
75381 +#ifdef CONFIG_PAX_SEGMEXEC
75382 + if (prev)
75383 + prev_m = pax_find_mirror_vma(prev);
75384 + if (area)
75385 + area_m = pax_find_mirror_vma(area);
75386 + if (next)
75387 + next_m = pax_find_mirror_vma(next);
75388 +#endif
75389 +
75390 /*
75391 * Can it merge with the predecessor?
75392 */
75393 @@ -838,9 +889,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75394 /* cases 1, 6 */
75395 err = vma_adjust(prev, prev->vm_start,
75396 next->vm_end, prev->vm_pgoff, NULL);
75397 - } else /* cases 2, 5, 7 */
75398 +
75399 +#ifdef CONFIG_PAX_SEGMEXEC
75400 + if (!err && prev_m)
75401 + err = vma_adjust(prev_m, prev_m->vm_start,
75402 + next_m->vm_end, prev_m->vm_pgoff, NULL);
75403 +#endif
75404 +
75405 + } else { /* cases 2, 5, 7 */
75406 err = vma_adjust(prev, prev->vm_start,
75407 end, prev->vm_pgoff, NULL);
75408 +
75409 +#ifdef CONFIG_PAX_SEGMEXEC
75410 + if (!err && prev_m)
75411 + err = vma_adjust(prev_m, prev_m->vm_start,
75412 + end_m, prev_m->vm_pgoff, NULL);
75413 +#endif
75414 +
75415 + }
75416 if (err)
75417 return NULL;
75418 khugepaged_enter_vma_merge(prev);
75419 @@ -854,12 +920,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75420 mpol_equal(policy, vma_policy(next)) &&
75421 can_vma_merge_before(next, vm_flags,
75422 anon_vma, file, pgoff+pglen)) {
75423 - if (prev && addr < prev->vm_end) /* case 4 */
75424 + if (prev && addr < prev->vm_end) { /* case 4 */
75425 err = vma_adjust(prev, prev->vm_start,
75426 addr, prev->vm_pgoff, NULL);
75427 - else /* cases 3, 8 */
75428 +
75429 +#ifdef CONFIG_PAX_SEGMEXEC
75430 + if (!err && prev_m)
75431 + err = vma_adjust(prev_m, prev_m->vm_start,
75432 + addr_m, prev_m->vm_pgoff, NULL);
75433 +#endif
75434 +
75435 + } else { /* cases 3, 8 */
75436 err = vma_adjust(area, addr, next->vm_end,
75437 next->vm_pgoff - pglen, NULL);
75438 +
75439 +#ifdef CONFIG_PAX_SEGMEXEC
75440 + if (!err && area_m)
75441 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
75442 + next_m->vm_pgoff - pglen, NULL);
75443 +#endif
75444 +
75445 + }
75446 if (err)
75447 return NULL;
75448 khugepaged_enter_vma_merge(area);
75449 @@ -968,16 +1049,13 @@ none:
75450 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
75451 struct file *file, long pages)
75452 {
75453 - const unsigned long stack_flags
75454 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
75455 -
75456 mm->total_vm += pages;
75457
75458 if (file) {
75459 mm->shared_vm += pages;
75460 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
75461 mm->exec_vm += pages;
75462 - } else if (flags & stack_flags)
75463 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
75464 mm->stack_vm += pages;
75465 }
75466 #endif /* CONFIG_PROC_FS */
75467 @@ -1013,7 +1091,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75468 * (the exception is when the underlying filesystem is noexec
75469 * mounted, in which case we dont add PROT_EXEC.)
75470 */
75471 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
75472 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
75473 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
75474 prot |= PROT_EXEC;
75475
75476 @@ -1039,7 +1117,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75477 /* Obtain the address to map to. we verify (or select) it and ensure
75478 * that it represents a valid section of the address space.
75479 */
75480 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
75481 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
75482 if (addr & ~PAGE_MASK)
75483 return addr;
75484
75485 @@ -1050,6 +1128,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75486 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
75487 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
75488
75489 +#ifdef CONFIG_PAX_MPROTECT
75490 + if (mm->pax_flags & MF_PAX_MPROTECT) {
75491 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
75492 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
75493 + gr_log_rwxmmap(file);
75494 +
75495 +#ifdef CONFIG_PAX_EMUPLT
75496 + vm_flags &= ~VM_EXEC;
75497 +#else
75498 + return -EPERM;
75499 +#endif
75500 +
75501 + }
75502 +
75503 + if (!(vm_flags & VM_EXEC))
75504 + vm_flags &= ~VM_MAYEXEC;
75505 +#else
75506 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
75507 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
75508 +#endif
75509 + else
75510 + vm_flags &= ~VM_MAYWRITE;
75511 + }
75512 +#endif
75513 +
75514 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75515 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
75516 + vm_flags &= ~VM_PAGEEXEC;
75517 +#endif
75518 +
75519 if (flags & MAP_LOCKED)
75520 if (!can_do_mlock())
75521 return -EPERM;
75522 @@ -1061,6 +1169,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75523 locked += mm->locked_vm;
75524 lock_limit = rlimit(RLIMIT_MEMLOCK);
75525 lock_limit >>= PAGE_SHIFT;
75526 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
75527 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
75528 return -EAGAIN;
75529 }
75530 @@ -1127,6 +1236,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75531 }
75532 }
75533
75534 + if (!gr_acl_handle_mmap(file, prot))
75535 + return -EACCES;
75536 +
75537 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
75538 }
75539
75540 @@ -1203,7 +1315,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
75541 vm_flags_t vm_flags = vma->vm_flags;
75542
75543 /* If it was private or non-writable, the write bit is already clear */
75544 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
75545 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
75546 return 0;
75547
75548 /* The backer wishes to know when pages are first written to? */
75549 @@ -1252,13 +1364,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
75550 unsigned long charged = 0;
75551 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
75552
75553 +#ifdef CONFIG_PAX_SEGMEXEC
75554 + struct vm_area_struct *vma_m = NULL;
75555 +#endif
75556 +
75557 + /*
75558 + * mm->mmap_sem is required to protect against another thread
75559 + * changing the mappings in case we sleep.
75560 + */
75561 + verify_mm_writelocked(mm);
75562 +
75563 /* Clear old maps */
75564 error = -ENOMEM;
75565 -munmap_back:
75566 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
75567 if (do_munmap(mm, addr, len))
75568 return -ENOMEM;
75569 - goto munmap_back;
75570 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
75571 }
75572
75573 /* Check against address space limit. */
75574 @@ -1307,6 +1428,16 @@ munmap_back:
75575 goto unacct_error;
75576 }
75577
75578 +#ifdef CONFIG_PAX_SEGMEXEC
75579 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
75580 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
75581 + if (!vma_m) {
75582 + error = -ENOMEM;
75583 + goto free_vma;
75584 + }
75585 + }
75586 +#endif
75587 +
75588 vma->vm_mm = mm;
75589 vma->vm_start = addr;
75590 vma->vm_end = addr + len;
75591 @@ -1331,6 +1462,13 @@ munmap_back:
75592 if (error)
75593 goto unmap_and_free_vma;
75594
75595 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75596 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
75597 + vma->vm_flags |= VM_PAGEEXEC;
75598 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
75599 + }
75600 +#endif
75601 +
75602 /* Can addr have changed??
75603 *
75604 * Answer: Yes, several device drivers can do it in their
75605 @@ -1365,6 +1503,11 @@ munmap_back:
75606 vma_link(mm, vma, prev, rb_link, rb_parent);
75607 file = vma->vm_file;
75608
75609 +#ifdef CONFIG_PAX_SEGMEXEC
75610 + if (vma_m)
75611 + BUG_ON(pax_mirror_vma(vma_m, vma));
75612 +#endif
75613 +
75614 /* Once vma denies write, undo our temporary denial count */
75615 if (correct_wcount)
75616 atomic_inc(&inode->i_writecount);
75617 @@ -1372,6 +1515,7 @@ out:
75618 perf_event_mmap(vma);
75619
75620 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
75621 + track_exec_limit(mm, addr, addr + len, vm_flags);
75622 if (vm_flags & VM_LOCKED) {
75623 if (!mlock_vma_pages_range(vma, addr, addr + len))
75624 mm->locked_vm += (len >> PAGE_SHIFT);
75625 @@ -1393,6 +1537,12 @@ unmap_and_free_vma:
75626 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
75627 charged = 0;
75628 free_vma:
75629 +
75630 +#ifdef CONFIG_PAX_SEGMEXEC
75631 + if (vma_m)
75632 + kmem_cache_free(vm_area_cachep, vma_m);
75633 +#endif
75634 +
75635 kmem_cache_free(vm_area_cachep, vma);
75636 unacct_error:
75637 if (charged)
75638 @@ -1400,6 +1550,62 @@ unacct_error:
75639 return error;
75640 }
75641
75642 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
75643 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
75644 +{
75645 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
75646 + return (random32() & 0xFF) << PAGE_SHIFT;
75647 +
75648 + return 0;
75649 +}
75650 +#endif
75651 +
75652 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
75653 +{
75654 + if (!vma) {
75655 +#ifdef CONFIG_STACK_GROWSUP
75656 + if (addr > sysctl_heap_stack_gap)
75657 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
75658 + else
75659 + vma = find_vma(current->mm, 0);
75660 + if (vma && (vma->vm_flags & VM_GROWSUP))
75661 + return false;
75662 +#endif
75663 + return true;
75664 + }
75665 +
75666 + if (addr + len > vma->vm_start)
75667 + return false;
75668 +
75669 + if (vma->vm_flags & VM_GROWSDOWN)
75670 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
75671 +#ifdef CONFIG_STACK_GROWSUP
75672 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
75673 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
75674 +#endif
75675 + else if (offset)
75676 + return offset <= vma->vm_start - addr - len;
75677 +
75678 + return true;
75679 +}
75680 +
75681 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
75682 +{
75683 + if (vma->vm_start < len)
75684 + return -ENOMEM;
75685 +
75686 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
75687 + if (offset <= vma->vm_start - len)
75688 + return vma->vm_start - len - offset;
75689 + else
75690 + return -ENOMEM;
75691 + }
75692 +
75693 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
75694 + return vma->vm_start - len - sysctl_heap_stack_gap;
75695 + return -ENOMEM;
75696 +}
75697 +
75698 /* Get an address range which is currently unmapped.
75699 * For shmat() with addr=0.
75700 *
75701 @@ -1426,18 +1632,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
75702 if (flags & MAP_FIXED)
75703 return addr;
75704
75705 +#ifdef CONFIG_PAX_RANDMMAP
75706 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75707 +#endif
75708 +
75709 if (addr) {
75710 addr = PAGE_ALIGN(addr);
75711 - vma = find_vma(mm, addr);
75712 - if (TASK_SIZE - len >= addr &&
75713 - (!vma || addr + len <= vma->vm_start))
75714 - return addr;
75715 + if (TASK_SIZE - len >= addr) {
75716 + vma = find_vma(mm, addr);
75717 + if (check_heap_stack_gap(vma, addr, len))
75718 + return addr;
75719 + }
75720 }
75721 if (len > mm->cached_hole_size) {
75722 - start_addr = addr = mm->free_area_cache;
75723 + start_addr = addr = mm->free_area_cache;
75724 } else {
75725 - start_addr = addr = TASK_UNMAPPED_BASE;
75726 - mm->cached_hole_size = 0;
75727 + start_addr = addr = mm->mmap_base;
75728 + mm->cached_hole_size = 0;
75729 }
75730
75731 full_search:
75732 @@ -1448,34 +1659,40 @@ full_search:
75733 * Start a new search - just in case we missed
75734 * some holes.
75735 */
75736 - if (start_addr != TASK_UNMAPPED_BASE) {
75737 - addr = TASK_UNMAPPED_BASE;
75738 - start_addr = addr;
75739 + if (start_addr != mm->mmap_base) {
75740 + start_addr = addr = mm->mmap_base;
75741 mm->cached_hole_size = 0;
75742 goto full_search;
75743 }
75744 return -ENOMEM;
75745 }
75746 - if (!vma || addr + len <= vma->vm_start) {
75747 - /*
75748 - * Remember the place where we stopped the search:
75749 - */
75750 - mm->free_area_cache = addr + len;
75751 - return addr;
75752 - }
75753 + if (check_heap_stack_gap(vma, addr, len))
75754 + break;
75755 if (addr + mm->cached_hole_size < vma->vm_start)
75756 mm->cached_hole_size = vma->vm_start - addr;
75757 addr = vma->vm_end;
75758 }
75759 +
75760 + /*
75761 + * Remember the place where we stopped the search:
75762 + */
75763 + mm->free_area_cache = addr + len;
75764 + return addr;
75765 }
75766 #endif
75767
75768 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
75769 {
75770 +
75771 +#ifdef CONFIG_PAX_SEGMEXEC
75772 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
75773 + return;
75774 +#endif
75775 +
75776 /*
75777 * Is this a new hole at the lowest possible address?
75778 */
75779 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
75780 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
75781 mm->free_area_cache = addr;
75782 }
75783
75784 @@ -1491,7 +1708,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75785 {
75786 struct vm_area_struct *vma;
75787 struct mm_struct *mm = current->mm;
75788 - unsigned long addr = addr0, start_addr;
75789 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
75790
75791 /* requested length too big for entire address space */
75792 if (len > TASK_SIZE)
75793 @@ -1500,13 +1717,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75794 if (flags & MAP_FIXED)
75795 return addr;
75796
75797 +#ifdef CONFIG_PAX_RANDMMAP
75798 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75799 +#endif
75800 +
75801 /* requesting a specific address */
75802 if (addr) {
75803 addr = PAGE_ALIGN(addr);
75804 - vma = find_vma(mm, addr);
75805 - if (TASK_SIZE - len >= addr &&
75806 - (!vma || addr + len <= vma->vm_start))
75807 - return addr;
75808 + if (TASK_SIZE - len >= addr) {
75809 + vma = find_vma(mm, addr);
75810 + if (check_heap_stack_gap(vma, addr, len))
75811 + return addr;
75812 + }
75813 }
75814
75815 /* check if free_area_cache is useful for us */
75816 @@ -1530,7 +1752,7 @@ try_again:
75817 * return with success:
75818 */
75819 vma = find_vma(mm, addr);
75820 - if (!vma || addr+len <= vma->vm_start)
75821 + if (check_heap_stack_gap(vma, addr, len))
75822 /* remember the address as a hint for next time */
75823 return (mm->free_area_cache = addr);
75824
75825 @@ -1539,8 +1761,8 @@ try_again:
75826 mm->cached_hole_size = vma->vm_start - addr;
75827
75828 /* try just below the current vma->vm_start */
75829 - addr = vma->vm_start-len;
75830 - } while (len < vma->vm_start);
75831 + addr = skip_heap_stack_gap(vma, len);
75832 + } while (!IS_ERR_VALUE(addr));
75833
75834 fail:
75835 /*
75836 @@ -1563,13 +1785,21 @@ fail:
75837 * can happen with large stack limits and large mmap()
75838 * allocations.
75839 */
75840 + mm->mmap_base = TASK_UNMAPPED_BASE;
75841 +
75842 +#ifdef CONFIG_PAX_RANDMMAP
75843 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75844 + mm->mmap_base += mm->delta_mmap;
75845 +#endif
75846 +
75847 + mm->free_area_cache = mm->mmap_base;
75848 mm->cached_hole_size = ~0UL;
75849 - mm->free_area_cache = TASK_UNMAPPED_BASE;
75850 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
75851 /*
75852 * Restore the topdown base:
75853 */
75854 - mm->free_area_cache = mm->mmap_base;
75855 + mm->mmap_base = base;
75856 + mm->free_area_cache = base;
75857 mm->cached_hole_size = ~0UL;
75858
75859 return addr;
75860 @@ -1578,6 +1808,12 @@ fail:
75861
75862 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
75863 {
75864 +
75865 +#ifdef CONFIG_PAX_SEGMEXEC
75866 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
75867 + return;
75868 +#endif
75869 +
75870 /*
75871 * Is this a new hole at the highest possible address?
75872 */
75873 @@ -1585,8 +1821,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
75874 mm->free_area_cache = addr;
75875
75876 /* dont allow allocations above current base */
75877 - if (mm->free_area_cache > mm->mmap_base)
75878 + if (mm->free_area_cache > mm->mmap_base) {
75879 mm->free_area_cache = mm->mmap_base;
75880 + mm->cached_hole_size = ~0UL;
75881 + }
75882 }
75883
75884 unsigned long
75885 @@ -1685,6 +1923,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
75886 return vma;
75887 }
75888
75889 +#ifdef CONFIG_PAX_SEGMEXEC
75890 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
75891 +{
75892 + struct vm_area_struct *vma_m;
75893 +
75894 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
75895 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
75896 + BUG_ON(vma->vm_mirror);
75897 + return NULL;
75898 + }
75899 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
75900 + vma_m = vma->vm_mirror;
75901 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
75902 + BUG_ON(vma->vm_file != vma_m->vm_file);
75903 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
75904 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
75905 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
75906 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
75907 + return vma_m;
75908 +}
75909 +#endif
75910 +
75911 /*
75912 * Verify that the stack growth is acceptable and
75913 * update accounting. This is shared with both the
75914 @@ -1701,6 +1961,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
75915 return -ENOMEM;
75916
75917 /* Stack limit test */
75918 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
75919 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
75920 return -ENOMEM;
75921
75922 @@ -1711,6 +1972,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
75923 locked = mm->locked_vm + grow;
75924 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
75925 limit >>= PAGE_SHIFT;
75926 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
75927 if (locked > limit && !capable(CAP_IPC_LOCK))
75928 return -ENOMEM;
75929 }
75930 @@ -1740,37 +2002,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
75931 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
75932 * vma is the last one with address > vma->vm_end. Have to extend vma.
75933 */
75934 +#ifndef CONFIG_IA64
75935 +static
75936 +#endif
75937 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
75938 {
75939 int error;
75940 + bool locknext;
75941
75942 if (!(vma->vm_flags & VM_GROWSUP))
75943 return -EFAULT;
75944
75945 + /* Also guard against wrapping around to address 0. */
75946 + if (address < PAGE_ALIGN(address+1))
75947 + address = PAGE_ALIGN(address+1);
75948 + else
75949 + return -ENOMEM;
75950 +
75951 /*
75952 * We must make sure the anon_vma is allocated
75953 * so that the anon_vma locking is not a noop.
75954 */
75955 if (unlikely(anon_vma_prepare(vma)))
75956 return -ENOMEM;
75957 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
75958 + if (locknext && anon_vma_prepare(vma->vm_next))
75959 + return -ENOMEM;
75960 vma_lock_anon_vma(vma);
75961 + if (locknext)
75962 + vma_lock_anon_vma(vma->vm_next);
75963
75964 /*
75965 * vma->vm_start/vm_end cannot change under us because the caller
75966 * is required to hold the mmap_sem in read mode. We need the
75967 - * anon_vma lock to serialize against concurrent expand_stacks.
75968 - * Also guard against wrapping around to address 0.
75969 + * anon_vma locks to serialize against concurrent expand_stacks
75970 + * and expand_upwards.
75971 */
75972 - if (address < PAGE_ALIGN(address+4))
75973 - address = PAGE_ALIGN(address+4);
75974 - else {
75975 - vma_unlock_anon_vma(vma);
75976 - return -ENOMEM;
75977 - }
75978 error = 0;
75979
75980 /* Somebody else might have raced and expanded it already */
75981 - if (address > vma->vm_end) {
75982 + 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)
75983 + error = -ENOMEM;
75984 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
75985 unsigned long size, grow;
75986
75987 size = address - vma->vm_start;
75988 @@ -1787,6 +2060,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
75989 }
75990 }
75991 }
75992 + if (locknext)
75993 + vma_unlock_anon_vma(vma->vm_next);
75994 vma_unlock_anon_vma(vma);
75995 khugepaged_enter_vma_merge(vma);
75996 validate_mm(vma->vm_mm);
75997 @@ -1801,6 +2076,8 @@ int expand_downwards(struct vm_area_struct *vma,
75998 unsigned long address)
75999 {
76000 int error;
76001 + bool lockprev = false;
76002 + struct vm_area_struct *prev;
76003
76004 /*
76005 * We must make sure the anon_vma is allocated
76006 @@ -1814,6 +2091,15 @@ int expand_downwards(struct vm_area_struct *vma,
76007 if (error)
76008 return error;
76009
76010 + prev = vma->vm_prev;
76011 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
76012 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
76013 +#endif
76014 + if (lockprev && anon_vma_prepare(prev))
76015 + return -ENOMEM;
76016 + if (lockprev)
76017 + vma_lock_anon_vma(prev);
76018 +
76019 vma_lock_anon_vma(vma);
76020
76021 /*
76022 @@ -1823,9 +2109,17 @@ int expand_downwards(struct vm_area_struct *vma,
76023 */
76024
76025 /* Somebody else might have raced and expanded it already */
76026 - if (address < vma->vm_start) {
76027 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
76028 + error = -ENOMEM;
76029 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
76030 unsigned long size, grow;
76031
76032 +#ifdef CONFIG_PAX_SEGMEXEC
76033 + struct vm_area_struct *vma_m;
76034 +
76035 + vma_m = pax_find_mirror_vma(vma);
76036 +#endif
76037 +
76038 size = vma->vm_end - address;
76039 grow = (vma->vm_start - address) >> PAGE_SHIFT;
76040
76041 @@ -1837,6 +2131,17 @@ int expand_downwards(struct vm_area_struct *vma,
76042 vma->vm_start = address;
76043 vma->vm_pgoff -= grow;
76044 anon_vma_interval_tree_post_update_vma(vma);
76045 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
76046 +
76047 +#ifdef CONFIG_PAX_SEGMEXEC
76048 + if (vma_m) {
76049 + anon_vma_interval_tree_pre_update_vma(vma_m);
76050 + vma_m->vm_start -= grow << PAGE_SHIFT;
76051 + vma_m->vm_pgoff -= grow;
76052 + anon_vma_interval_tree_post_update_vma(vma_m);
76053 + }
76054 +#endif
76055 +
76056 perf_event_mmap(vma);
76057 }
76058 }
76059 @@ -1914,6 +2219,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
76060 do {
76061 long nrpages = vma_pages(vma);
76062
76063 +#ifdef CONFIG_PAX_SEGMEXEC
76064 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
76065 + vma = remove_vma(vma);
76066 + continue;
76067 + }
76068 +#endif
76069 +
76070 if (vma->vm_flags & VM_ACCOUNT)
76071 nr_accounted += nrpages;
76072 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
76073 @@ -1959,6 +2271,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
76074 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
76075 vma->vm_prev = NULL;
76076 do {
76077 +
76078 +#ifdef CONFIG_PAX_SEGMEXEC
76079 + if (vma->vm_mirror) {
76080 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
76081 + vma->vm_mirror->vm_mirror = NULL;
76082 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
76083 + vma->vm_mirror = NULL;
76084 + }
76085 +#endif
76086 +
76087 rb_erase(&vma->vm_rb, &mm->mm_rb);
76088 mm->map_count--;
76089 tail_vma = vma;
76090 @@ -1987,14 +2309,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76091 struct vm_area_struct *new;
76092 int err = -ENOMEM;
76093
76094 +#ifdef CONFIG_PAX_SEGMEXEC
76095 + struct vm_area_struct *vma_m, *new_m = NULL;
76096 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
76097 +#endif
76098 +
76099 if (is_vm_hugetlb_page(vma) && (addr &
76100 ~(huge_page_mask(hstate_vma(vma)))))
76101 return -EINVAL;
76102
76103 +#ifdef CONFIG_PAX_SEGMEXEC
76104 + vma_m = pax_find_mirror_vma(vma);
76105 +#endif
76106 +
76107 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
76108 if (!new)
76109 goto out_err;
76110
76111 +#ifdef CONFIG_PAX_SEGMEXEC
76112 + if (vma_m) {
76113 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
76114 + if (!new_m) {
76115 + kmem_cache_free(vm_area_cachep, new);
76116 + goto out_err;
76117 + }
76118 + }
76119 +#endif
76120 +
76121 /* most fields are the same, copy all, and then fixup */
76122 *new = *vma;
76123
76124 @@ -2007,6 +2348,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76125 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
76126 }
76127
76128 +#ifdef CONFIG_PAX_SEGMEXEC
76129 + if (vma_m) {
76130 + *new_m = *vma_m;
76131 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
76132 + new_m->vm_mirror = new;
76133 + new->vm_mirror = new_m;
76134 +
76135 + if (new_below)
76136 + new_m->vm_end = addr_m;
76137 + else {
76138 + new_m->vm_start = addr_m;
76139 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
76140 + }
76141 + }
76142 +#endif
76143 +
76144 pol = mpol_dup(vma_policy(vma));
76145 if (IS_ERR(pol)) {
76146 err = PTR_ERR(pol);
76147 @@ -2029,6 +2386,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76148 else
76149 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
76150
76151 +#ifdef CONFIG_PAX_SEGMEXEC
76152 + if (!err && vma_m) {
76153 + if (anon_vma_clone(new_m, vma_m))
76154 + goto out_free_mpol;
76155 +
76156 + mpol_get(pol);
76157 + vma_set_policy(new_m, pol);
76158 +
76159 + if (new_m->vm_file)
76160 + get_file(new_m->vm_file);
76161 +
76162 + if (new_m->vm_ops && new_m->vm_ops->open)
76163 + new_m->vm_ops->open(new_m);
76164 +
76165 + if (new_below)
76166 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
76167 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
76168 + else
76169 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
76170 +
76171 + if (err) {
76172 + if (new_m->vm_ops && new_m->vm_ops->close)
76173 + new_m->vm_ops->close(new_m);
76174 + if (new_m->vm_file)
76175 + fput(new_m->vm_file);
76176 + mpol_put(pol);
76177 + }
76178 + }
76179 +#endif
76180 +
76181 /* Success. */
76182 if (!err)
76183 return 0;
76184 @@ -2038,10 +2425,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76185 new->vm_ops->close(new);
76186 if (new->vm_file)
76187 fput(new->vm_file);
76188 - unlink_anon_vmas(new);
76189 out_free_mpol:
76190 mpol_put(pol);
76191 out_free_vma:
76192 +
76193 +#ifdef CONFIG_PAX_SEGMEXEC
76194 + if (new_m) {
76195 + unlink_anon_vmas(new_m);
76196 + kmem_cache_free(vm_area_cachep, new_m);
76197 + }
76198 +#endif
76199 +
76200 + unlink_anon_vmas(new);
76201 kmem_cache_free(vm_area_cachep, new);
76202 out_err:
76203 return err;
76204 @@ -2054,6 +2449,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76205 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76206 unsigned long addr, int new_below)
76207 {
76208 +
76209 +#ifdef CONFIG_PAX_SEGMEXEC
76210 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76211 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
76212 + if (mm->map_count >= sysctl_max_map_count-1)
76213 + return -ENOMEM;
76214 + } else
76215 +#endif
76216 +
76217 if (mm->map_count >= sysctl_max_map_count)
76218 return -ENOMEM;
76219
76220 @@ -2065,11 +2469,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76221 * work. This now handles partial unmappings.
76222 * Jeremy Fitzhardinge <jeremy@goop.org>
76223 */
76224 +#ifdef CONFIG_PAX_SEGMEXEC
76225 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76226 {
76227 + int ret = __do_munmap(mm, start, len);
76228 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
76229 + return ret;
76230 +
76231 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
76232 +}
76233 +
76234 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76235 +#else
76236 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76237 +#endif
76238 +{
76239 unsigned long end;
76240 struct vm_area_struct *vma, *prev, *last;
76241
76242 + /*
76243 + * mm->mmap_sem is required to protect against another thread
76244 + * changing the mappings in case we sleep.
76245 + */
76246 + verify_mm_writelocked(mm);
76247 +
76248 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
76249 return -EINVAL;
76250
76251 @@ -2144,6 +2567,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76252 /* Fix up all other VM information */
76253 remove_vma_list(mm, vma);
76254
76255 + track_exec_limit(mm, start, end, 0UL);
76256 +
76257 return 0;
76258 }
76259
76260 @@ -2152,6 +2577,13 @@ int vm_munmap(unsigned long start, size_t len)
76261 int ret;
76262 struct mm_struct *mm = current->mm;
76263
76264 +
76265 +#ifdef CONFIG_PAX_SEGMEXEC
76266 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
76267 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
76268 + return -EINVAL;
76269 +#endif
76270 +
76271 down_write(&mm->mmap_sem);
76272 ret = do_munmap(mm, start, len);
76273 up_write(&mm->mmap_sem);
76274 @@ -2165,16 +2597,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
76275 return vm_munmap(addr, len);
76276 }
76277
76278 -static inline void verify_mm_writelocked(struct mm_struct *mm)
76279 -{
76280 -#ifdef CONFIG_DEBUG_VM
76281 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76282 - WARN_ON(1);
76283 - up_read(&mm->mmap_sem);
76284 - }
76285 -#endif
76286 -}
76287 -
76288 /*
76289 * this is really a simplified "do_mmap". it only handles
76290 * anonymous maps. eventually we may be able to do some
76291 @@ -2188,6 +2610,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76292 struct rb_node ** rb_link, * rb_parent;
76293 pgoff_t pgoff = addr >> PAGE_SHIFT;
76294 int error;
76295 + unsigned long charged;
76296
76297 len = PAGE_ALIGN(len);
76298 if (!len)
76299 @@ -2195,16 +2618,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76300
76301 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
76302
76303 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
76304 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
76305 + flags &= ~VM_EXEC;
76306 +
76307 +#ifdef CONFIG_PAX_MPROTECT
76308 + if (mm->pax_flags & MF_PAX_MPROTECT)
76309 + flags &= ~VM_MAYEXEC;
76310 +#endif
76311 +
76312 + }
76313 +#endif
76314 +
76315 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
76316 if (error & ~PAGE_MASK)
76317 return error;
76318
76319 + charged = len >> PAGE_SHIFT;
76320 +
76321 /*
76322 * mlock MCL_FUTURE?
76323 */
76324 if (mm->def_flags & VM_LOCKED) {
76325 unsigned long locked, lock_limit;
76326 - locked = len >> PAGE_SHIFT;
76327 + locked = charged;
76328 locked += mm->locked_vm;
76329 lock_limit = rlimit(RLIMIT_MEMLOCK);
76330 lock_limit >>= PAGE_SHIFT;
76331 @@ -2221,21 +2658,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76332 /*
76333 * Clear old maps. this also does some error checking for us
76334 */
76335 - munmap_back:
76336 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
76337 if (do_munmap(mm, addr, len))
76338 return -ENOMEM;
76339 - goto munmap_back;
76340 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
76341 }
76342
76343 /* Check against address space limits *after* clearing old maps... */
76344 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
76345 + if (!may_expand_vm(mm, charged))
76346 return -ENOMEM;
76347
76348 if (mm->map_count > sysctl_max_map_count)
76349 return -ENOMEM;
76350
76351 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
76352 + if (security_vm_enough_memory_mm(mm, charged))
76353 return -ENOMEM;
76354
76355 /* Can we just expand an old private anonymous mapping? */
76356 @@ -2249,7 +2685,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76357 */
76358 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76359 if (!vma) {
76360 - vm_unacct_memory(len >> PAGE_SHIFT);
76361 + vm_unacct_memory(charged);
76362 return -ENOMEM;
76363 }
76364
76365 @@ -2263,11 +2699,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76366 vma_link(mm, vma, prev, rb_link, rb_parent);
76367 out:
76368 perf_event_mmap(vma);
76369 - mm->total_vm += len >> PAGE_SHIFT;
76370 + mm->total_vm += charged;
76371 if (flags & VM_LOCKED) {
76372 if (!mlock_vma_pages_range(vma, addr, addr + len))
76373 - mm->locked_vm += (len >> PAGE_SHIFT);
76374 + mm->locked_vm += charged;
76375 }
76376 + track_exec_limit(mm, addr, addr + len, flags);
76377 return addr;
76378 }
76379
76380 @@ -2325,6 +2762,7 @@ void exit_mmap(struct mm_struct *mm)
76381 while (vma) {
76382 if (vma->vm_flags & VM_ACCOUNT)
76383 nr_accounted += vma_pages(vma);
76384 + vma->vm_mirror = NULL;
76385 vma = remove_vma(vma);
76386 }
76387 vm_unacct_memory(nr_accounted);
76388 @@ -2341,6 +2779,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
76389 struct vm_area_struct *prev;
76390 struct rb_node **rb_link, *rb_parent;
76391
76392 +#ifdef CONFIG_PAX_SEGMEXEC
76393 + struct vm_area_struct *vma_m = NULL;
76394 +#endif
76395 +
76396 + if (security_mmap_addr(vma->vm_start))
76397 + return -EPERM;
76398 +
76399 /*
76400 * The vm_pgoff of a purely anonymous vma should be irrelevant
76401 * until its first write fault, when page's anon_vma and index
76402 @@ -2364,7 +2809,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
76403 security_vm_enough_memory_mm(mm, vma_pages(vma)))
76404 return -ENOMEM;
76405
76406 +#ifdef CONFIG_PAX_SEGMEXEC
76407 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
76408 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76409 + if (!vma_m)
76410 + return -ENOMEM;
76411 + }
76412 +#endif
76413 +
76414 vma_link(mm, vma, prev, rb_link, rb_parent);
76415 +
76416 +#ifdef CONFIG_PAX_SEGMEXEC
76417 + if (vma_m)
76418 + BUG_ON(pax_mirror_vma(vma_m, vma));
76419 +#endif
76420 +
76421 return 0;
76422 }
76423
76424 @@ -2384,6 +2843,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
76425 struct mempolicy *pol;
76426 bool faulted_in_anon_vma = true;
76427
76428 + BUG_ON(vma->vm_mirror);
76429 +
76430 /*
76431 * If anonymous vma has not yet been faulted, update new pgoff
76432 * to match new location, to increase its chance of merging.
76433 @@ -2450,6 +2911,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
76434 return NULL;
76435 }
76436
76437 +#ifdef CONFIG_PAX_SEGMEXEC
76438 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
76439 +{
76440 + struct vm_area_struct *prev_m;
76441 + struct rb_node **rb_link_m, *rb_parent_m;
76442 + struct mempolicy *pol_m;
76443 +
76444 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
76445 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
76446 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
76447 + *vma_m = *vma;
76448 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
76449 + if (anon_vma_clone(vma_m, vma))
76450 + return -ENOMEM;
76451 + pol_m = vma_policy(vma_m);
76452 + mpol_get(pol_m);
76453 + vma_set_policy(vma_m, pol_m);
76454 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
76455 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
76456 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
76457 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
76458 + if (vma_m->vm_file)
76459 + get_file(vma_m->vm_file);
76460 + if (vma_m->vm_ops && vma_m->vm_ops->open)
76461 + vma_m->vm_ops->open(vma_m);
76462 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
76463 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
76464 + vma_m->vm_mirror = vma;
76465 + vma->vm_mirror = vma_m;
76466 + return 0;
76467 +}
76468 +#endif
76469 +
76470 /*
76471 * Return true if the calling process may expand its vm space by the passed
76472 * number of pages
76473 @@ -2461,6 +2955,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
76474
76475 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
76476
76477 +#ifdef CONFIG_PAX_RANDMMAP
76478 + if (mm->pax_flags & MF_PAX_RANDMMAP)
76479 + cur -= mm->brk_gap;
76480 +#endif
76481 +
76482 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
76483 if (cur + npages > lim)
76484 return 0;
76485 return 1;
76486 @@ -2531,6 +3031,22 @@ int install_special_mapping(struct mm_struct *mm,
76487 vma->vm_start = addr;
76488 vma->vm_end = addr + len;
76489
76490 +#ifdef CONFIG_PAX_MPROTECT
76491 + if (mm->pax_flags & MF_PAX_MPROTECT) {
76492 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
76493 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
76494 + return -EPERM;
76495 + if (!(vm_flags & VM_EXEC))
76496 + vm_flags &= ~VM_MAYEXEC;
76497 +#else
76498 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76499 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76500 +#endif
76501 + else
76502 + vm_flags &= ~VM_MAYWRITE;
76503 + }
76504 +#endif
76505 +
76506 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
76507 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76508
76509 diff --git a/mm/mprotect.c b/mm/mprotect.c
76510 index a409926..8b32e6d 100644
76511 --- a/mm/mprotect.c
76512 +++ b/mm/mprotect.c
76513 @@ -23,10 +23,17 @@
76514 #include <linux/mmu_notifier.h>
76515 #include <linux/migrate.h>
76516 #include <linux/perf_event.h>
76517 +
76518 +#ifdef CONFIG_PAX_MPROTECT
76519 +#include <linux/elf.h>
76520 +#include <linux/binfmts.h>
76521 +#endif
76522 +
76523 #include <asm/uaccess.h>
76524 #include <asm/pgtable.h>
76525 #include <asm/cacheflush.h>
76526 #include <asm/tlbflush.h>
76527 +#include <asm/mmu_context.h>
76528
76529 #ifndef pgprot_modify
76530 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
76531 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
76532 flush_tlb_range(vma, start, end);
76533 }
76534
76535 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76536 +/* called while holding the mmap semaphor for writing except stack expansion */
76537 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
76538 +{
76539 + unsigned long oldlimit, newlimit = 0UL;
76540 +
76541 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
76542 + return;
76543 +
76544 + spin_lock(&mm->page_table_lock);
76545 + oldlimit = mm->context.user_cs_limit;
76546 + if ((prot & VM_EXEC) && oldlimit < end)
76547 + /* USER_CS limit moved up */
76548 + newlimit = end;
76549 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
76550 + /* USER_CS limit moved down */
76551 + newlimit = start;
76552 +
76553 + if (newlimit) {
76554 + mm->context.user_cs_limit = newlimit;
76555 +
76556 +#ifdef CONFIG_SMP
76557 + wmb();
76558 + cpus_clear(mm->context.cpu_user_cs_mask);
76559 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
76560 +#endif
76561 +
76562 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
76563 + }
76564 + spin_unlock(&mm->page_table_lock);
76565 + if (newlimit == end) {
76566 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
76567 +
76568 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
76569 + if (is_vm_hugetlb_page(vma))
76570 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
76571 + else
76572 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
76573 + }
76574 +}
76575 +#endif
76576 +
76577 int
76578 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76579 unsigned long start, unsigned long end, unsigned long newflags)
76580 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76581 int error;
76582 int dirty_accountable = 0;
76583
76584 +#ifdef CONFIG_PAX_SEGMEXEC
76585 + struct vm_area_struct *vma_m = NULL;
76586 + unsigned long start_m, end_m;
76587 +
76588 + start_m = start + SEGMEXEC_TASK_SIZE;
76589 + end_m = end + SEGMEXEC_TASK_SIZE;
76590 +#endif
76591 +
76592 if (newflags == oldflags) {
76593 *pprev = vma;
76594 return 0;
76595 }
76596
76597 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
76598 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
76599 +
76600 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
76601 + return -ENOMEM;
76602 +
76603 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
76604 + return -ENOMEM;
76605 + }
76606 +
76607 /*
76608 * If we make a private mapping writable we increase our commit;
76609 * but (without finer accounting) cannot reduce our commit if we
76610 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76611 }
76612 }
76613
76614 +#ifdef CONFIG_PAX_SEGMEXEC
76615 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
76616 + if (start != vma->vm_start) {
76617 + error = split_vma(mm, vma, start, 1);
76618 + if (error)
76619 + goto fail;
76620 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
76621 + *pprev = (*pprev)->vm_next;
76622 + }
76623 +
76624 + if (end != vma->vm_end) {
76625 + error = split_vma(mm, vma, end, 0);
76626 + if (error)
76627 + goto fail;
76628 + }
76629 +
76630 + if (pax_find_mirror_vma(vma)) {
76631 + error = __do_munmap(mm, start_m, end_m - start_m);
76632 + if (error)
76633 + goto fail;
76634 + } else {
76635 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76636 + if (!vma_m) {
76637 + error = -ENOMEM;
76638 + goto fail;
76639 + }
76640 + vma->vm_flags = newflags;
76641 + error = pax_mirror_vma(vma_m, vma);
76642 + if (error) {
76643 + vma->vm_flags = oldflags;
76644 + goto fail;
76645 + }
76646 + }
76647 + }
76648 +#endif
76649 +
76650 /*
76651 * First try to merge with previous and/or next vma.
76652 */
76653 @@ -204,9 +307,21 @@ success:
76654 * vm_flags and vm_page_prot are protected by the mmap_sem
76655 * held in write mode.
76656 */
76657 +
76658 +#ifdef CONFIG_PAX_SEGMEXEC
76659 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
76660 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
76661 +#endif
76662 +
76663 vma->vm_flags = newflags;
76664 +
76665 +#ifdef CONFIG_PAX_MPROTECT
76666 + if (mm->binfmt && mm->binfmt->handle_mprotect)
76667 + mm->binfmt->handle_mprotect(vma, newflags);
76668 +#endif
76669 +
76670 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
76671 - vm_get_page_prot(newflags));
76672 + vm_get_page_prot(vma->vm_flags));
76673
76674 if (vma_wants_writenotify(vma)) {
76675 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
76676 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76677 end = start + len;
76678 if (end <= start)
76679 return -ENOMEM;
76680 +
76681 +#ifdef CONFIG_PAX_SEGMEXEC
76682 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
76683 + if (end > SEGMEXEC_TASK_SIZE)
76684 + return -EINVAL;
76685 + } else
76686 +#endif
76687 +
76688 + if (end > TASK_SIZE)
76689 + return -EINVAL;
76690 +
76691 if (!arch_validate_prot(prot))
76692 return -EINVAL;
76693
76694 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76695 /*
76696 * Does the application expect PROT_READ to imply PROT_EXEC:
76697 */
76698 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76699 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76700 prot |= PROT_EXEC;
76701
76702 vm_flags = calc_vm_prot_bits(prot);
76703 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76704 if (start > vma->vm_start)
76705 prev = vma;
76706
76707 +#ifdef CONFIG_PAX_MPROTECT
76708 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
76709 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
76710 +#endif
76711 +
76712 for (nstart = start ; ; ) {
76713 unsigned long newflags;
76714
76715 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76716
76717 /* newflags >> 4 shift VM_MAY% in place of VM_% */
76718 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
76719 + if (prot & (PROT_WRITE | PROT_EXEC))
76720 + gr_log_rwxmprotect(vma->vm_file);
76721 +
76722 + error = -EACCES;
76723 + goto out;
76724 + }
76725 +
76726 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
76727 error = -EACCES;
76728 goto out;
76729 }
76730 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76731 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
76732 if (error)
76733 goto out;
76734 +
76735 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
76736 +
76737 nstart = tmp;
76738
76739 if (nstart < prev->vm_end)
76740 diff --git a/mm/mremap.c b/mm/mremap.c
76741 index 1b61c2d..1cc0e3c 100644
76742 --- a/mm/mremap.c
76743 +++ b/mm/mremap.c
76744 @@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
76745 continue;
76746 pte = ptep_get_and_clear(mm, old_addr, old_pte);
76747 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
76748 +
76749 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76750 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
76751 + pte = pte_exprotect(pte);
76752 +#endif
76753 +
76754 set_pte_at(mm, new_addr, new_pte, pte);
76755 }
76756
76757 @@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
76758 if (is_vm_hugetlb_page(vma))
76759 goto Einval;
76760
76761 +#ifdef CONFIG_PAX_SEGMEXEC
76762 + if (pax_find_mirror_vma(vma))
76763 + goto Einval;
76764 +#endif
76765 +
76766 /* We can't remap across vm area boundaries */
76767 if (old_len > vma->vm_end - addr)
76768 goto Efault;
76769 @@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
76770 unsigned long ret = -EINVAL;
76771 unsigned long charged = 0;
76772 unsigned long map_flags;
76773 + unsigned long pax_task_size = TASK_SIZE;
76774
76775 if (new_addr & ~PAGE_MASK)
76776 goto out;
76777
76778 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
76779 +#ifdef CONFIG_PAX_SEGMEXEC
76780 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
76781 + pax_task_size = SEGMEXEC_TASK_SIZE;
76782 +#endif
76783 +
76784 + pax_task_size -= PAGE_SIZE;
76785 +
76786 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
76787 goto out;
76788
76789 /* Check if the location we're moving into overlaps the
76790 * old location at all, and fail if it does.
76791 */
76792 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
76793 - goto out;
76794 -
76795 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
76796 + if (addr + old_len > new_addr && new_addr + new_len > addr)
76797 goto out;
76798
76799 ret = do_munmap(mm, new_addr, new_len);
76800 @@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76801 struct vm_area_struct *vma;
76802 unsigned long ret = -EINVAL;
76803 unsigned long charged = 0;
76804 + unsigned long pax_task_size = TASK_SIZE;
76805
76806 down_write(&current->mm->mmap_sem);
76807
76808 @@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76809 if (!new_len)
76810 goto out;
76811
76812 +#ifdef CONFIG_PAX_SEGMEXEC
76813 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
76814 + pax_task_size = SEGMEXEC_TASK_SIZE;
76815 +#endif
76816 +
76817 + pax_task_size -= PAGE_SIZE;
76818 +
76819 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
76820 + old_len > pax_task_size || addr > pax_task_size-old_len)
76821 + goto out;
76822 +
76823 if (flags & MREMAP_FIXED) {
76824 if (flags & MREMAP_MAYMOVE)
76825 ret = mremap_to(addr, old_len, new_addr, new_len);
76826 @@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76827 addr + new_len);
76828 }
76829 ret = addr;
76830 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
76831 goto out;
76832 }
76833 }
76834 @@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76835 goto out;
76836 }
76837
76838 + map_flags = vma->vm_flags;
76839 ret = move_vma(vma, addr, old_len, new_len, new_addr);
76840 + if (!(ret & ~PAGE_MASK)) {
76841 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
76842 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
76843 + }
76844 }
76845 out:
76846 if (ret & ~PAGE_MASK)
76847 diff --git a/mm/nommu.c b/mm/nommu.c
76848 index 45131b4..c521665 100644
76849 --- a/mm/nommu.c
76850 +++ b/mm/nommu.c
76851 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
76852 int sysctl_overcommit_ratio = 50; /* default is 50% */
76853 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
76854 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
76855 -int heap_stack_gap = 0;
76856
76857 atomic_long_t mmap_pages_allocated;
76858
76859 @@ -824,15 +823,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
76860 EXPORT_SYMBOL(find_vma);
76861
76862 /*
76863 - * find a VMA
76864 - * - we don't extend stack VMAs under NOMMU conditions
76865 - */
76866 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
76867 -{
76868 - return find_vma(mm, addr);
76869 -}
76870 -
76871 -/*
76872 * expand a stack to a given address
76873 * - not supported under NOMMU conditions
76874 */
76875 @@ -1540,6 +1530,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76876
76877 /* most fields are the same, copy all, and then fixup */
76878 *new = *vma;
76879 + INIT_LIST_HEAD(&new->anon_vma_chain);
76880 *region = *vma->vm_region;
76881 new->vm_region = region;
76882
76883 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
76884 index ceb4168..d7774f2 100644
76885 --- a/mm/page_alloc.c
76886 +++ b/mm/page_alloc.c
76887 @@ -340,7 +340,7 @@ out:
76888 * This usage means that zero-order pages may not be compound.
76889 */
76890
76891 -static void free_compound_page(struct page *page)
76892 +void free_compound_page(struct page *page)
76893 {
76894 __free_pages_ok(page, compound_order(page));
76895 }
76896 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
76897 int i;
76898 int bad = 0;
76899
76900 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
76901 + unsigned long index = 1UL << order;
76902 +#endif
76903 +
76904 trace_mm_page_free(page, order);
76905 kmemcheck_free_shadow(page, order);
76906
76907 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
76908 debug_check_no_obj_freed(page_address(page),
76909 PAGE_SIZE << order);
76910 }
76911 +
76912 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
76913 + for (; index; --index)
76914 + sanitize_highpage(page + index - 1);
76915 +#endif
76916 +
76917 arch_free_page(page, order);
76918 kernel_map_pages(page, 1 << order, 0);
76919
76920 @@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
76921 arch_alloc_page(page, order);
76922 kernel_map_pages(page, 1 << order, 1);
76923
76924 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
76925 if (gfp_flags & __GFP_ZERO)
76926 prep_zero_page(page, order, gfp_flags);
76927 +#endif
76928
76929 if (order && (gfp_flags & __GFP_COMP))
76930 prep_compound_page(page, order);
76931 @@ -3684,7 +3696,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
76932 unsigned long pfn;
76933
76934 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
76935 +#ifdef CONFIG_X86_32
76936 + /* boot failures in VMware 8 on 32bit vanilla since
76937 + this change */
76938 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
76939 +#else
76940 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
76941 +#endif
76942 return 1;
76943 }
76944 return 0;
76945 diff --git a/mm/percpu.c b/mm/percpu.c
76946 index ddc5efb..f632d2c 100644
76947 --- a/mm/percpu.c
76948 +++ b/mm/percpu.c
76949 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
76950 static unsigned int pcpu_high_unit_cpu __read_mostly;
76951
76952 /* the address of the first chunk which starts with the kernel static area */
76953 -void *pcpu_base_addr __read_mostly;
76954 +void *pcpu_base_addr __read_only;
76955 EXPORT_SYMBOL_GPL(pcpu_base_addr);
76956
76957 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
76958 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
76959 index 926b466..b23df53 100644
76960 --- a/mm/process_vm_access.c
76961 +++ b/mm/process_vm_access.c
76962 @@ -13,6 +13,7 @@
76963 #include <linux/uio.h>
76964 #include <linux/sched.h>
76965 #include <linux/highmem.h>
76966 +#include <linux/security.h>
76967 #include <linux/ptrace.h>
76968 #include <linux/slab.h>
76969 #include <linux/syscalls.h>
76970 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
76971 size_t iov_l_curr_offset = 0;
76972 ssize_t iov_len;
76973
76974 + return -ENOSYS; // PaX: until properly audited
76975 +
76976 /*
76977 * Work out how many pages of struct pages we're going to need
76978 * when eventually calling get_user_pages
76979 */
76980 for (i = 0; i < riovcnt; i++) {
76981 iov_len = rvec[i].iov_len;
76982 - if (iov_len > 0) {
76983 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
76984 - + iov_len)
76985 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
76986 - / PAGE_SIZE + 1;
76987 - nr_pages = max(nr_pages, nr_pages_iov);
76988 - }
76989 + if (iov_len <= 0)
76990 + continue;
76991 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
76992 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
76993 + nr_pages = max(nr_pages, nr_pages_iov);
76994 }
76995
76996 if (nr_pages == 0)
76997 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
76998 goto free_proc_pages;
76999 }
77000
77001 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
77002 + rc = -EPERM;
77003 + goto put_task_struct;
77004 + }
77005 +
77006 mm = mm_access(task, PTRACE_MODE_ATTACH);
77007 if (!mm || IS_ERR(mm)) {
77008 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
77009 diff --git a/mm/rmap.c b/mm/rmap.c
77010 index 2ee1ef0..2e175ba 100644
77011 --- a/mm/rmap.c
77012 +++ b/mm/rmap.c
77013 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77014 struct anon_vma *anon_vma = vma->anon_vma;
77015 struct anon_vma_chain *avc;
77016
77017 +#ifdef CONFIG_PAX_SEGMEXEC
77018 + struct anon_vma_chain *avc_m = NULL;
77019 +#endif
77020 +
77021 might_sleep();
77022 if (unlikely(!anon_vma)) {
77023 struct mm_struct *mm = vma->vm_mm;
77024 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77025 if (!avc)
77026 goto out_enomem;
77027
77028 +#ifdef CONFIG_PAX_SEGMEXEC
77029 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
77030 + if (!avc_m)
77031 + goto out_enomem_free_avc;
77032 +#endif
77033 +
77034 anon_vma = find_mergeable_anon_vma(vma);
77035 allocated = NULL;
77036 if (!anon_vma) {
77037 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77038 /* page_table_lock to protect against threads */
77039 spin_lock(&mm->page_table_lock);
77040 if (likely(!vma->anon_vma)) {
77041 +
77042 +#ifdef CONFIG_PAX_SEGMEXEC
77043 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
77044 +
77045 + if (vma_m) {
77046 + BUG_ON(vma_m->anon_vma);
77047 + vma_m->anon_vma = anon_vma;
77048 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
77049 + avc_m = NULL;
77050 + }
77051 +#endif
77052 +
77053 vma->anon_vma = anon_vma;
77054 anon_vma_chain_link(vma, avc, anon_vma);
77055 allocated = NULL;
77056 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77057
77058 if (unlikely(allocated))
77059 put_anon_vma(allocated);
77060 +
77061 +#ifdef CONFIG_PAX_SEGMEXEC
77062 + if (unlikely(avc_m))
77063 + anon_vma_chain_free(avc_m);
77064 +#endif
77065 +
77066 if (unlikely(avc))
77067 anon_vma_chain_free(avc);
77068 }
77069 return 0;
77070
77071 out_enomem_free_avc:
77072 +
77073 +#ifdef CONFIG_PAX_SEGMEXEC
77074 + if (avc_m)
77075 + anon_vma_chain_free(avc_m);
77076 +#endif
77077 +
77078 anon_vma_chain_free(avc);
77079 out_enomem:
77080 return -ENOMEM;
77081 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
77082 * Attach the anon_vmas from src to dst.
77083 * Returns 0 on success, -ENOMEM on failure.
77084 */
77085 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
77086 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
77087 {
77088 struct anon_vma_chain *avc, *pavc;
77089 struct anon_vma *root = NULL;
77090 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
77091 * the corresponding VMA in the parent process is attached to.
77092 * Returns 0 on success, non-zero on failure.
77093 */
77094 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
77095 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
77096 {
77097 struct anon_vma_chain *avc;
77098 struct anon_vma *anon_vma;
77099 diff --git a/mm/shmem.c b/mm/shmem.c
77100 index 50c5b8f..0bc87f7 100644
77101 --- a/mm/shmem.c
77102 +++ b/mm/shmem.c
77103 @@ -31,7 +31,7 @@
77104 #include <linux/export.h>
77105 #include <linux/swap.h>
77106
77107 -static struct vfsmount *shm_mnt;
77108 +struct vfsmount *shm_mnt;
77109
77110 #ifdef CONFIG_SHMEM
77111 /*
77112 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
77113 #define BOGO_DIRENT_SIZE 20
77114
77115 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
77116 -#define SHORT_SYMLINK_LEN 128
77117 +#define SHORT_SYMLINK_LEN 64
77118
77119 /*
77120 * shmem_fallocate and shmem_writepage communicate via inode->i_private
77121 @@ -2112,6 +2112,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
77122 static int shmem_xattr_validate(const char *name)
77123 {
77124 struct { const char *prefix; size_t len; } arr[] = {
77125 +
77126 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77127 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
77128 +#endif
77129 +
77130 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
77131 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
77132 };
77133 @@ -2167,6 +2172,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
77134 if (err)
77135 return err;
77136
77137 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77138 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
77139 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
77140 + return -EOPNOTSUPP;
77141 + if (size > 8)
77142 + return -EINVAL;
77143 + }
77144 +#endif
77145 +
77146 return simple_xattr_set(&info->xattrs, name, value, size, flags);
77147 }
77148
77149 @@ -2466,8 +2480,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
77150 int err = -ENOMEM;
77151
77152 /* Round up to L1_CACHE_BYTES to resist false sharing */
77153 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
77154 - L1_CACHE_BYTES), GFP_KERNEL);
77155 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
77156 if (!sbinfo)
77157 return -ENOMEM;
77158
77159 diff --git a/mm/slab.c b/mm/slab.c
77160 index 33d3363..93c6810 100644
77161 --- a/mm/slab.c
77162 +++ b/mm/slab.c
77163 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
77164
77165 /* Legal flag mask for kmem_cache_create(). */
77166 #if DEBUG
77167 -# define CREATE_MASK (SLAB_RED_ZONE | \
77168 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
77169 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
77170 SLAB_CACHE_DMA | \
77171 SLAB_STORE_USER | \
77172 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
77173 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
77174 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
77175 #else
77176 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
77177 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
77178 SLAB_CACHE_DMA | \
77179 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
77180 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
77181 @@ -322,7 +322,7 @@ struct kmem_list3 {
77182 * Need this for bootstrapping a per node allocator.
77183 */
77184 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
77185 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
77186 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
77187 #define CACHE_CACHE 0
77188 #define SIZE_AC MAX_NUMNODES
77189 #define SIZE_L3 (2 * MAX_NUMNODES)
77190 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
77191 if ((x)->max_freeable < i) \
77192 (x)->max_freeable = i; \
77193 } while (0)
77194 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
77195 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
77196 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
77197 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
77198 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
77199 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
77200 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
77201 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
77202 #else
77203 #define STATS_INC_ACTIVE(x) do { } while (0)
77204 #define STATS_DEC_ACTIVE(x) do { } while (0)
77205 @@ -534,7 +534,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
77206 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
77207 */
77208 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
77209 - const struct slab *slab, void *obj)
77210 + const struct slab *slab, const void *obj)
77211 {
77212 u32 offset = (obj - slab->s_mem);
77213 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
77214 @@ -555,12 +555,13 @@ EXPORT_SYMBOL(malloc_sizes);
77215 struct cache_names {
77216 char *name;
77217 char *name_dma;
77218 + char *name_usercopy;
77219 };
77220
77221 static struct cache_names __initdata cache_names[] = {
77222 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
77223 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
77224 #include <linux/kmalloc_sizes.h>
77225 - {NULL,}
77226 + {NULL}
77227 #undef CACHE
77228 };
77229
77230 @@ -721,6 +722,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
77231 if (unlikely(gfpflags & GFP_DMA))
77232 return csizep->cs_dmacachep;
77233 #endif
77234 +
77235 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77236 + if (unlikely(gfpflags & GFP_USERCOPY))
77237 + return csizep->cs_usercopycachep;
77238 +#endif
77239 +
77240 return csizep->cs_cachep;
77241 }
77242
77243 @@ -1676,7 +1683,7 @@ void __init kmem_cache_init(void)
77244 sizes[INDEX_AC].cs_cachep->size = sizes[INDEX_AC].cs_size;
77245 sizes[INDEX_AC].cs_cachep->object_size = sizes[INDEX_AC].cs_size;
77246 sizes[INDEX_AC].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77247 - __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77248 + __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77249 list_add(&sizes[INDEX_AC].cs_cachep->list, &slab_caches);
77250
77251 if (INDEX_AC != INDEX_L3) {
77252 @@ -1685,7 +1692,7 @@ void __init kmem_cache_init(void)
77253 sizes[INDEX_L3].cs_cachep->size = sizes[INDEX_L3].cs_size;
77254 sizes[INDEX_L3].cs_cachep->object_size = sizes[INDEX_L3].cs_size;
77255 sizes[INDEX_L3].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77256 - __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77257 + __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77258 list_add(&sizes[INDEX_L3].cs_cachep->list, &slab_caches);
77259 }
77260
77261 @@ -1705,7 +1712,7 @@ void __init kmem_cache_init(void)
77262 sizes->cs_cachep->size = sizes->cs_size;
77263 sizes->cs_cachep->object_size = sizes->cs_size;
77264 sizes->cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77265 - __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77266 + __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77267 list_add(&sizes->cs_cachep->list, &slab_caches);
77268 }
77269 #ifdef CONFIG_ZONE_DMA
77270 @@ -1718,6 +1725,17 @@ void __init kmem_cache_init(void)
77271 ARCH_KMALLOC_FLAGS|SLAB_CACHE_DMA| SLAB_PANIC);
77272 list_add(&sizes->cs_dmacachep->list, &slab_caches);
77273 #endif
77274 +
77275 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77276 + sizes->cs_usercopycachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
77277 + sizes->cs_usercopycachep->name = names->name_dma;
77278 + sizes->cs_usercopycachep->size = sizes->cs_size;
77279 + sizes->cs_usercopycachep->object_size = sizes->cs_size;
77280 + sizes->cs_usercopycachep->align = ARCH_KMALLOC_MINALIGN;
77281 + __kmem_cache_create(sizes->cs_usercopycachep, ARCH_KMALLOC_FLAGS| SLAB_PANIC|SLAB_USERCOPY);
77282 + list_add(&sizes->cs_usercopycachep->list, &slab_caches);
77283 +#endif
77284 +
77285 sizes++;
77286 names++;
77287 }
77288 @@ -4405,10 +4423,10 @@ static int s_show(struct seq_file *m, void *p)
77289 }
77290 /* cpu stats */
77291 {
77292 - unsigned long allochit = atomic_read(&cachep->allochit);
77293 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
77294 - unsigned long freehit = atomic_read(&cachep->freehit);
77295 - unsigned long freemiss = atomic_read(&cachep->freemiss);
77296 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
77297 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
77298 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
77299 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
77300
77301 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
77302 allochit, allocmiss, freehit, freemiss);
77303 @@ -4667,13 +4685,71 @@ static int __init slab_proc_init(void)
77304 {
77305 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
77306 #ifdef CONFIG_DEBUG_SLAB_LEAK
77307 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
77308 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
77309 #endif
77310 return 0;
77311 }
77312 module_init(slab_proc_init);
77313 #endif
77314
77315 +bool is_usercopy_object(const void *ptr)
77316 +{
77317 + struct page *page;
77318 + struct kmem_cache *cachep;
77319 +
77320 + if (ZERO_OR_NULL_PTR(ptr))
77321 + return false;
77322 +
77323 + if (!slab_is_available())
77324 + return false;
77325 +
77326 + if (!virt_addr_valid(ptr))
77327 + return false;
77328 +
77329 + page = virt_to_head_page(ptr);
77330 +
77331 + if (!PageSlab(page))
77332 + return false;
77333 +
77334 + cachep = page->slab_cache;
77335 + return cachep->flags & SLAB_USERCOPY;
77336 +}
77337 +
77338 +#ifdef CONFIG_PAX_USERCOPY
77339 +const char *check_heap_object(const void *ptr, unsigned long n)
77340 +{
77341 + struct page *page;
77342 + struct kmem_cache *cachep;
77343 + struct slab *slabp;
77344 + unsigned int objnr;
77345 + unsigned long offset;
77346 +
77347 + if (ZERO_OR_NULL_PTR(ptr))
77348 + return "<null>";
77349 +
77350 + if (!virt_addr_valid(ptr))
77351 + return NULL;
77352 +
77353 + page = virt_to_head_page(ptr);
77354 +
77355 + if (!PageSlab(page))
77356 + return NULL;
77357 +
77358 + cachep = page->slab_cache;
77359 + if (!(cachep->flags & SLAB_USERCOPY))
77360 + return cachep->name;
77361 +
77362 + slabp = page->slab_page;
77363 + objnr = obj_to_index(cachep, slabp, ptr);
77364 + BUG_ON(objnr >= cachep->num);
77365 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
77366 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
77367 + return NULL;
77368 +
77369 + return cachep->name;
77370 +}
77371 +#endif
77372 +
77373 /**
77374 * ksize - get the actual amount of memory allocated for a given object
77375 * @objp: Pointer to the object
77376 diff --git a/mm/slab_common.c b/mm/slab_common.c
77377 index 069a24e6..226a310 100644
77378 --- a/mm/slab_common.c
77379 +++ b/mm/slab_common.c
77380 @@ -127,7 +127,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align
77381 err = __kmem_cache_create(s, flags);
77382 if (!err) {
77383
77384 - s->refcount = 1;
77385 + atomic_set(&s->refcount, 1);
77386 list_add(&s->list, &slab_caches);
77387
77388 } else {
77389 @@ -163,8 +163,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
77390 {
77391 get_online_cpus();
77392 mutex_lock(&slab_mutex);
77393 - s->refcount--;
77394 - if (!s->refcount) {
77395 + if (atomic_dec_and_test(&s->refcount)) {
77396 list_del(&s->list);
77397
77398 if (!__kmem_cache_shutdown(s)) {
77399 diff --git a/mm/slob.c b/mm/slob.c
77400 index 1e921c5..1ce12c2 100644
77401 --- a/mm/slob.c
77402 +++ b/mm/slob.c
77403 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
77404 /*
77405 * Return the size of a slob block.
77406 */
77407 -static slobidx_t slob_units(slob_t *s)
77408 +static slobidx_t slob_units(const slob_t *s)
77409 {
77410 if (s->units > 0)
77411 return s->units;
77412 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
77413 /*
77414 * Return the next free slob block pointer after this one.
77415 */
77416 -static slob_t *slob_next(slob_t *s)
77417 +static slob_t *slob_next(const slob_t *s)
77418 {
77419 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
77420 slobidx_t next;
77421 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
77422 /*
77423 * Returns true if s is the last free block in its page.
77424 */
77425 -static int slob_last(slob_t *s)
77426 +static int slob_last(const slob_t *s)
77427 {
77428 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
77429 }
77430
77431 -static void *slob_new_pages(gfp_t gfp, int order, int node)
77432 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
77433 {
77434 - void *page;
77435 + struct page *page;
77436
77437 #ifdef CONFIG_NUMA
77438 if (node != NUMA_NO_NODE)
77439 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
77440 if (!page)
77441 return NULL;
77442
77443 - return page_address(page);
77444 + __SetPageSlab(page);
77445 + return page;
77446 }
77447
77448 -static void slob_free_pages(void *b, int order)
77449 +static void slob_free_pages(struct page *sp, int order)
77450 {
77451 if (current->reclaim_state)
77452 current->reclaim_state->reclaimed_slab += 1 << order;
77453 - free_pages((unsigned long)b, order);
77454 + __ClearPageSlab(sp);
77455 + reset_page_mapcount(sp);
77456 + sp->private = 0;
77457 + __free_pages(sp, order);
77458 }
77459
77460 /*
77461 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
77462
77463 /* Not enough space: must allocate a new page */
77464 if (!b) {
77465 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
77466 - if (!b)
77467 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
77468 + if (!sp)
77469 return NULL;
77470 - sp = virt_to_page(b);
77471 - __SetPageSlab(sp);
77472 + b = page_address(sp);
77473
77474 spin_lock_irqsave(&slob_lock, flags);
77475 sp->units = SLOB_UNITS(PAGE_SIZE);
77476 sp->freelist = b;
77477 + sp->private = 0;
77478 INIT_LIST_HEAD(&sp->list);
77479 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
77480 set_slob_page_free(sp, slob_list);
77481 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
77482 if (slob_page_free(sp))
77483 clear_slob_page_free(sp);
77484 spin_unlock_irqrestore(&slob_lock, flags);
77485 - __ClearPageSlab(sp);
77486 - reset_page_mapcount(sp);
77487 - slob_free_pages(b, 0);
77488 + slob_free_pages(sp, 0);
77489 return;
77490 }
77491
77492 @@ -426,11 +428,10 @@ out:
77493 */
77494
77495 static __always_inline void *
77496 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77497 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
77498 {
77499 - unsigned int *m;
77500 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77501 - void *ret;
77502 + slob_t *m;
77503 + void *ret = NULL;
77504
77505 gfp &= gfp_allowed_mask;
77506
77507 @@ -444,20 +445,23 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77508
77509 if (!m)
77510 return NULL;
77511 - *m = size;
77512 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
77513 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
77514 + m[0].units = size;
77515 + m[1].units = align;
77516 ret = (void *)m + align;
77517
77518 trace_kmalloc_node(caller, ret,
77519 size, size + align, gfp, node);
77520 } else {
77521 unsigned int order = get_order(size);
77522 + struct page *page;
77523
77524 if (likely(order))
77525 gfp |= __GFP_COMP;
77526 - ret = slob_new_pages(gfp, order, node);
77527 - if (ret) {
77528 - struct page *page;
77529 - page = virt_to_page(ret);
77530 + page = slob_new_pages(gfp, order, node);
77531 + if (page) {
77532 + ret = page_address(page);
77533 page->private = size;
77534 }
77535
77536 @@ -465,7 +469,17 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77537 size, PAGE_SIZE << order, gfp, node);
77538 }
77539
77540 - kmemleak_alloc(ret, size, 1, gfp);
77541 + return ret;
77542 +}
77543 +
77544 +static __always_inline void *
77545 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77546 +{
77547 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77548 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
77549 +
77550 + if (!ZERO_OR_NULL_PTR(ret))
77551 + kmemleak_alloc(ret, size, 1, gfp);
77552 return ret;
77553 }
77554
77555 @@ -501,15 +515,91 @@ void kfree(const void *block)
77556 kmemleak_free(block);
77557
77558 sp = virt_to_page(block);
77559 - if (PageSlab(sp)) {
77560 + VM_BUG_ON(!PageSlab(sp));
77561 + if (!sp->private) {
77562 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77563 - unsigned int *m = (unsigned int *)(block - align);
77564 - slob_free(m, *m + align);
77565 - } else
77566 + slob_t *m = (slob_t *)(block - align);
77567 + slob_free(m, m[0].units + align);
77568 + } else {
77569 + __ClearPageSlab(sp);
77570 + reset_page_mapcount(sp);
77571 + sp->private = 0;
77572 put_page(sp);
77573 + }
77574 }
77575 EXPORT_SYMBOL(kfree);
77576
77577 +bool is_usercopy_object(const void *ptr)
77578 +{
77579 + if (!slab_is_available())
77580 + return false;
77581 +
77582 + // PAX: TODO
77583 +
77584 + return false;
77585 +}
77586 +
77587 +#ifdef CONFIG_PAX_USERCOPY
77588 +const char *check_heap_object(const void *ptr, unsigned long n)
77589 +{
77590 + struct page *page;
77591 + const slob_t *free;
77592 + const void *base;
77593 + unsigned long flags;
77594 +
77595 + if (ZERO_OR_NULL_PTR(ptr))
77596 + return "<null>";
77597 +
77598 + if (!virt_addr_valid(ptr))
77599 + return NULL;
77600 +
77601 + page = virt_to_head_page(ptr);
77602 + if (!PageSlab(page))
77603 + return NULL;
77604 +
77605 + if (page->private) {
77606 + base = page;
77607 + if (base <= ptr && n <= page->private - (ptr - base))
77608 + return NULL;
77609 + return "<slob>";
77610 + }
77611 +
77612 + /* some tricky double walking to find the chunk */
77613 + spin_lock_irqsave(&slob_lock, flags);
77614 + base = (void *)((unsigned long)ptr & PAGE_MASK);
77615 + free = page->freelist;
77616 +
77617 + while (!slob_last(free) && (void *)free <= ptr) {
77618 + base = free + slob_units(free);
77619 + free = slob_next(free);
77620 + }
77621 +
77622 + while (base < (void *)free) {
77623 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
77624 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
77625 + int offset;
77626 +
77627 + if (ptr < base + align)
77628 + break;
77629 +
77630 + offset = ptr - base - align;
77631 + if (offset >= m) {
77632 + base += size;
77633 + continue;
77634 + }
77635 +
77636 + if (n > m - offset)
77637 + break;
77638 +
77639 + spin_unlock_irqrestore(&slob_lock, flags);
77640 + return NULL;
77641 + }
77642 +
77643 + spin_unlock_irqrestore(&slob_lock, flags);
77644 + return "<slob>";
77645 +}
77646 +#endif
77647 +
77648 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
77649 size_t ksize(const void *block)
77650 {
77651 @@ -520,10 +610,11 @@ size_t ksize(const void *block)
77652 return 0;
77653
77654 sp = virt_to_page(block);
77655 - if (PageSlab(sp)) {
77656 + VM_BUG_ON(!PageSlab(sp));
77657 + if (!sp->private) {
77658 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77659 - unsigned int *m = (unsigned int *)(block - align);
77660 - return SLOB_UNITS(*m) * SLOB_UNIT;
77661 + slob_t *m = (slob_t *)(block - align);
77662 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
77663 } else
77664 return sp->private;
77665 }
77666 @@ -550,23 +641,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
77667
77668 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
77669 {
77670 - void *b;
77671 + void *b = NULL;
77672
77673 flags &= gfp_allowed_mask;
77674
77675 lockdep_trace_alloc(flags);
77676
77677 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77678 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
77679 +#else
77680 if (c->size < PAGE_SIZE) {
77681 b = slob_alloc(c->size, flags, c->align, node);
77682 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
77683 SLOB_UNITS(c->size) * SLOB_UNIT,
77684 flags, node);
77685 } else {
77686 - b = slob_new_pages(flags, get_order(c->size), node);
77687 + struct page *sp;
77688 +
77689 + sp = slob_new_pages(flags, get_order(c->size), node);
77690 + if (sp) {
77691 + b = page_address(sp);
77692 + sp->private = c->size;
77693 + }
77694 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
77695 PAGE_SIZE << get_order(c->size),
77696 flags, node);
77697 }
77698 +#endif
77699
77700 if (c->ctor)
77701 c->ctor(b);
77702 @@ -578,10 +679,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
77703
77704 static void __kmem_cache_free(void *b, int size)
77705 {
77706 - if (size < PAGE_SIZE)
77707 + struct page *sp;
77708 +
77709 + sp = virt_to_page(b);
77710 + BUG_ON(!PageSlab(sp));
77711 + if (!sp->private)
77712 slob_free(b, size);
77713 else
77714 - slob_free_pages(b, get_order(size));
77715 + slob_free_pages(sp, get_order(size));
77716 }
77717
77718 static void kmem_rcu_free(struct rcu_head *head)
77719 @@ -594,17 +699,31 @@ static void kmem_rcu_free(struct rcu_head *head)
77720
77721 void kmem_cache_free(struct kmem_cache *c, void *b)
77722 {
77723 + int size = c->size;
77724 +
77725 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77726 + if (size + c->align < PAGE_SIZE) {
77727 + size += c->align;
77728 + b -= c->align;
77729 + }
77730 +#endif
77731 +
77732 kmemleak_free_recursive(b, c->flags);
77733 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
77734 struct slob_rcu *slob_rcu;
77735 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
77736 - slob_rcu->size = c->size;
77737 + slob_rcu = b + (size - sizeof(struct slob_rcu));
77738 + slob_rcu->size = size;
77739 call_rcu(&slob_rcu->head, kmem_rcu_free);
77740 } else {
77741 - __kmem_cache_free(b, c->size);
77742 + __kmem_cache_free(b, size);
77743 }
77744
77745 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77746 + trace_kfree(_RET_IP_, b);
77747 +#else
77748 trace_kmem_cache_free(_RET_IP_, b);
77749 +#endif
77750 +
77751 }
77752 EXPORT_SYMBOL(kmem_cache_free);
77753
77754 diff --git a/mm/slub.c b/mm/slub.c
77755 index 321afab..9595170 100644
77756 --- a/mm/slub.c
77757 +++ b/mm/slub.c
77758 @@ -201,7 +201,7 @@ struct track {
77759
77760 enum track_item { TRACK_ALLOC, TRACK_FREE };
77761
77762 -#ifdef CONFIG_SYSFS
77763 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77764 static int sysfs_slab_add(struct kmem_cache *);
77765 static int sysfs_slab_alias(struct kmem_cache *, const char *);
77766 static void sysfs_slab_remove(struct kmem_cache *);
77767 @@ -521,7 +521,7 @@ static void print_track(const char *s, struct track *t)
77768 if (!t->addr)
77769 return;
77770
77771 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
77772 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
77773 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
77774 #ifdef CONFIG_STACKTRACE
77775 {
77776 @@ -2623,6 +2623,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
77777
77778 page = virt_to_head_page(x);
77779
77780 + BUG_ON(!PageSlab(page));
77781 +
77782 if (kmem_cache_debug(s) && page->slab != s) {
77783 pr_err("kmem_cache_free: Wrong slab cache. %s but object"
77784 " is from %s\n", page->slab->name, s->name);
77785 @@ -2663,7 +2665,7 @@ static int slub_min_objects;
77786 * Merge control. If this is set then no merging of slab caches will occur.
77787 * (Could be removed. This was introduced to pacify the merge skeptics.)
77788 */
77789 -static int slub_nomerge;
77790 +static int slub_nomerge = 1;
77791
77792 /*
77793 * Calculate the order of allocation given an slab object size.
77794 @@ -3225,6 +3227,10 @@ EXPORT_SYMBOL(kmalloc_caches);
77795 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
77796 #endif
77797
77798 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77799 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
77800 +#endif
77801 +
77802 static int __init setup_slub_min_order(char *str)
77803 {
77804 get_option(&str, &slub_min_order);
77805 @@ -3279,7 +3285,7 @@ static struct kmem_cache *__init create_kmalloc_cache(const char *name,
77806 if (kmem_cache_open(s, flags))
77807 goto panic;
77808
77809 - s->refcount = 1;
77810 + atomic_set(&s->refcount, 1);
77811 list_add(&s->list, &slab_caches);
77812 return s;
77813
77814 @@ -3343,6 +3349,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
77815 return kmalloc_dma_caches[index];
77816
77817 #endif
77818 +
77819 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77820 + if (flags & SLAB_USERCOPY)
77821 + return kmalloc_usercopy_caches[index];
77822 +
77823 +#endif
77824 +
77825 return kmalloc_caches[index];
77826 }
77827
77828 @@ -3411,6 +3424,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
77829 EXPORT_SYMBOL(__kmalloc_node);
77830 #endif
77831
77832 +bool is_usercopy_object(const void *ptr)
77833 +{
77834 + struct page *page;
77835 + struct kmem_cache *s;
77836 +
77837 + if (ZERO_OR_NULL_PTR(ptr))
77838 + return false;
77839 +
77840 + if (!slab_is_available())
77841 + return false;
77842 +
77843 + if (!virt_addr_valid(ptr))
77844 + return false;
77845 +
77846 + page = virt_to_head_page(ptr);
77847 +
77848 + if (!PageSlab(page))
77849 + return false;
77850 +
77851 + s = page->slab;
77852 + return s->flags & SLAB_USERCOPY;
77853 +}
77854 +
77855 +#ifdef CONFIG_PAX_USERCOPY
77856 +const char *check_heap_object(const void *ptr, unsigned long n)
77857 +{
77858 + struct page *page;
77859 + struct kmem_cache *s;
77860 + unsigned long offset;
77861 +
77862 + if (ZERO_OR_NULL_PTR(ptr))
77863 + return "<null>";
77864 +
77865 + if (!virt_addr_valid(ptr))
77866 + return NULL;
77867 +
77868 + page = virt_to_head_page(ptr);
77869 +
77870 + if (!PageSlab(page))
77871 + return NULL;
77872 +
77873 + s = page->slab;
77874 + if (!(s->flags & SLAB_USERCOPY))
77875 + return s->name;
77876 +
77877 + offset = (ptr - page_address(page)) % s->size;
77878 + if (offset <= s->object_size && n <= s->object_size - offset)
77879 + return NULL;
77880 +
77881 + return s->name;
77882 +}
77883 +#endif
77884 +
77885 size_t ksize(const void *object)
77886 {
77887 struct page *page;
77888 @@ -3685,7 +3751,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
77889 int node;
77890
77891 list_add(&s->list, &slab_caches);
77892 - s->refcount = -1;
77893 + atomic_set(&s->refcount, -1);
77894
77895 for_each_node_state(node, N_NORMAL_MEMORY) {
77896 struct kmem_cache_node *n = get_node(s, node);
77897 @@ -3808,17 +3874,17 @@ void __init kmem_cache_init(void)
77898
77899 /* Caches that are not of the two-to-the-power-of size */
77900 if (KMALLOC_MIN_SIZE <= 32) {
77901 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
77902 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
77903 caches++;
77904 }
77905
77906 if (KMALLOC_MIN_SIZE <= 64) {
77907 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
77908 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
77909 caches++;
77910 }
77911
77912 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
77913 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
77914 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
77915 caches++;
77916 }
77917
77918 @@ -3860,6 +3926,22 @@ void __init kmem_cache_init(void)
77919 }
77920 }
77921 #endif
77922 +
77923 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77924 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
77925 + struct kmem_cache *s = kmalloc_caches[i];
77926 +
77927 + if (s && s->size) {
77928 + char *name = kasprintf(GFP_NOWAIT,
77929 + "usercopy-kmalloc-%d", s->object_size);
77930 +
77931 + BUG_ON(!name);
77932 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
77933 + s->object_size, SLAB_USERCOPY);
77934 + }
77935 + }
77936 +#endif
77937 +
77938 printk(KERN_INFO
77939 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
77940 " CPUs=%d, Nodes=%d\n",
77941 @@ -3886,7 +3968,7 @@ static int slab_unmergeable(struct kmem_cache *s)
77942 /*
77943 * We may have set a slab to be unmergeable during bootstrap.
77944 */
77945 - if (s->refcount < 0)
77946 + if (atomic_read(&s->refcount) < 0)
77947 return 1;
77948
77949 return 0;
77950 @@ -3940,7 +4022,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
77951
77952 s = find_mergeable(size, align, flags, name, ctor);
77953 if (s) {
77954 - s->refcount++;
77955 + atomic_inc(&s->refcount);
77956 /*
77957 * Adjust the object sizes so that we clear
77958 * the complete object on kzalloc.
77959 @@ -3949,7 +4031,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
77960 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
77961
77962 if (sysfs_slab_alias(s, name)) {
77963 - s->refcount--;
77964 + atomic_dec(&s->refcount);
77965 s = NULL;
77966 }
77967 }
77968 @@ -4064,7 +4146,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
77969 }
77970 #endif
77971
77972 -#ifdef CONFIG_SYSFS
77973 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77974 static int count_inuse(struct page *page)
77975 {
77976 return page->inuse;
77977 @@ -4451,12 +4533,12 @@ static void resiliency_test(void)
77978 validate_slab_cache(kmalloc_caches[9]);
77979 }
77980 #else
77981 -#ifdef CONFIG_SYSFS
77982 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77983 static void resiliency_test(void) {};
77984 #endif
77985 #endif
77986
77987 -#ifdef CONFIG_SYSFS
77988 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77989 enum slab_stat_type {
77990 SL_ALL, /* All slabs */
77991 SL_PARTIAL, /* Only partially allocated slabs */
77992 @@ -4700,7 +4782,7 @@ SLAB_ATTR_RO(ctor);
77993
77994 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
77995 {
77996 - return sprintf(buf, "%d\n", s->refcount - 1);
77997 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
77998 }
77999 SLAB_ATTR_RO(aliases);
78000
78001 @@ -5262,6 +5344,7 @@ static char *create_unique_id(struct kmem_cache *s)
78002 return name;
78003 }
78004
78005 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78006 static int sysfs_slab_add(struct kmem_cache *s)
78007 {
78008 int err;
78009 @@ -5324,6 +5407,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
78010 kobject_del(&s->kobj);
78011 kobject_put(&s->kobj);
78012 }
78013 +#endif
78014
78015 /*
78016 * Need to buffer aliases during bootup until sysfs becomes
78017 @@ -5337,6 +5421,7 @@ struct saved_alias {
78018
78019 static struct saved_alias *alias_list;
78020
78021 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78022 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78023 {
78024 struct saved_alias *al;
78025 @@ -5359,6 +5444,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78026 alias_list = al;
78027 return 0;
78028 }
78029 +#endif
78030
78031 static int __init slab_sysfs_init(void)
78032 {
78033 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
78034 index 1b7e22a..3fcd4f3 100644
78035 --- a/mm/sparse-vmemmap.c
78036 +++ b/mm/sparse-vmemmap.c
78037 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
78038 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
78039 if (!p)
78040 return NULL;
78041 - pud_populate(&init_mm, pud, p);
78042 + pud_populate_kernel(&init_mm, pud, p);
78043 }
78044 return pud;
78045 }
78046 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
78047 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
78048 if (!p)
78049 return NULL;
78050 - pgd_populate(&init_mm, pgd, p);
78051 + pgd_populate_kernel(&init_mm, pgd, p);
78052 }
78053 return pgd;
78054 }
78055 diff --git a/mm/swap.c b/mm/swap.c
78056 index 6310dc2..3662b3f 100644
78057 --- a/mm/swap.c
78058 +++ b/mm/swap.c
78059 @@ -30,6 +30,7 @@
78060 #include <linux/backing-dev.h>
78061 #include <linux/memcontrol.h>
78062 #include <linux/gfp.h>
78063 +#include <linux/hugetlb.h>
78064
78065 #include "internal.h"
78066
78067 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
78068
78069 __page_cache_release(page);
78070 dtor = get_compound_page_dtor(page);
78071 + if (!PageHuge(page))
78072 + BUG_ON(dtor != free_compound_page);
78073 (*dtor)(page);
78074 }
78075
78076 diff --git a/mm/swapfile.c b/mm/swapfile.c
78077 index f91a255..9dcac21 100644
78078 --- a/mm/swapfile.c
78079 +++ b/mm/swapfile.c
78080 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
78081
78082 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
78083 /* Activity counter to indicate that a swapon or swapoff has occurred */
78084 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
78085 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
78086
78087 static inline unsigned char swap_count(unsigned char ent)
78088 {
78089 @@ -1601,7 +1601,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
78090 }
78091 filp_close(swap_file, NULL);
78092 err = 0;
78093 - atomic_inc(&proc_poll_event);
78094 + atomic_inc_unchecked(&proc_poll_event);
78095 wake_up_interruptible(&proc_poll_wait);
78096
78097 out_dput:
78098 @@ -1618,8 +1618,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
78099
78100 poll_wait(file, &proc_poll_wait, wait);
78101
78102 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
78103 - seq->poll_event = atomic_read(&proc_poll_event);
78104 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
78105 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
78106 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
78107 }
78108
78109 @@ -1717,7 +1717,7 @@ static int swaps_open(struct inode *inode, struct file *file)
78110 return ret;
78111
78112 seq = file->private_data;
78113 - seq->poll_event = atomic_read(&proc_poll_event);
78114 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
78115 return 0;
78116 }
78117
78118 @@ -2059,7 +2059,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
78119 (frontswap_map) ? "FS" : "");
78120
78121 mutex_unlock(&swapon_mutex);
78122 - atomic_inc(&proc_poll_event);
78123 + atomic_inc_unchecked(&proc_poll_event);
78124 wake_up_interruptible(&proc_poll_wait);
78125
78126 if (S_ISREG(inode->i_mode))
78127 diff --git a/mm/util.c b/mm/util.c
78128 index dc3036c..b6c7c9d 100644
78129 --- a/mm/util.c
78130 +++ b/mm/util.c
78131 @@ -292,6 +292,12 @@ done:
78132 void arch_pick_mmap_layout(struct mm_struct *mm)
78133 {
78134 mm->mmap_base = TASK_UNMAPPED_BASE;
78135 +
78136 +#ifdef CONFIG_PAX_RANDMMAP
78137 + if (mm->pax_flags & MF_PAX_RANDMMAP)
78138 + mm->mmap_base += mm->delta_mmap;
78139 +#endif
78140 +
78141 mm->get_unmapped_area = arch_get_unmapped_area;
78142 mm->unmap_area = arch_unmap_area;
78143 }
78144 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
78145 index 78e0830..bc6bbd8 100644
78146 --- a/mm/vmalloc.c
78147 +++ b/mm/vmalloc.c
78148 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
78149
78150 pte = pte_offset_kernel(pmd, addr);
78151 do {
78152 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
78153 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
78154 +
78155 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78156 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
78157 + BUG_ON(!pte_exec(*pte));
78158 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
78159 + continue;
78160 + }
78161 +#endif
78162 +
78163 + {
78164 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
78165 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
78166 + }
78167 } while (pte++, addr += PAGE_SIZE, addr != end);
78168 }
78169
78170 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
78171 pte = pte_alloc_kernel(pmd, addr);
78172 if (!pte)
78173 return -ENOMEM;
78174 +
78175 + pax_open_kernel();
78176 do {
78177 struct page *page = pages[*nr];
78178
78179 - if (WARN_ON(!pte_none(*pte)))
78180 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78181 + if (pgprot_val(prot) & _PAGE_NX)
78182 +#endif
78183 +
78184 + if (!pte_none(*pte)) {
78185 + pax_close_kernel();
78186 + WARN_ON(1);
78187 return -EBUSY;
78188 - if (WARN_ON(!page))
78189 + }
78190 + if (!page) {
78191 + pax_close_kernel();
78192 + WARN_ON(1);
78193 return -ENOMEM;
78194 + }
78195 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
78196 (*nr)++;
78197 } while (pte++, addr += PAGE_SIZE, addr != end);
78198 + pax_close_kernel();
78199 return 0;
78200 }
78201
78202 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
78203 pmd_t *pmd;
78204 unsigned long next;
78205
78206 - pmd = pmd_alloc(&init_mm, pud, addr);
78207 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
78208 if (!pmd)
78209 return -ENOMEM;
78210 do {
78211 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
78212 pud_t *pud;
78213 unsigned long next;
78214
78215 - pud = pud_alloc(&init_mm, pgd, addr);
78216 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
78217 if (!pud)
78218 return -ENOMEM;
78219 do {
78220 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
78221 * and fall back on vmalloc() if that fails. Others
78222 * just put it in the vmalloc space.
78223 */
78224 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
78225 +#ifdef CONFIG_MODULES
78226 +#ifdef MODULES_VADDR
78227 unsigned long addr = (unsigned long)x;
78228 if (addr >= MODULES_VADDR && addr < MODULES_END)
78229 return 1;
78230 #endif
78231 +
78232 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78233 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
78234 + return 1;
78235 +#endif
78236 +
78237 +#endif
78238 +
78239 return is_vmalloc_addr(x);
78240 }
78241
78242 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
78243
78244 if (!pgd_none(*pgd)) {
78245 pud_t *pud = pud_offset(pgd, addr);
78246 +#ifdef CONFIG_X86
78247 + if (!pud_large(*pud))
78248 +#endif
78249 if (!pud_none(*pud)) {
78250 pmd_t *pmd = pmd_offset(pud, addr);
78251 +#ifdef CONFIG_X86
78252 + if (!pmd_large(*pmd))
78253 +#endif
78254 if (!pmd_none(*pmd)) {
78255 pte_t *ptep, pte;
78256
78257 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
78258 * Allocate a region of KVA of the specified size and alignment, within the
78259 * vstart and vend.
78260 */
78261 -static struct vmap_area *alloc_vmap_area(unsigned long size,
78262 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
78263 unsigned long align,
78264 unsigned long vstart, unsigned long vend,
78265 int node, gfp_t gfp_mask)
78266 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
78267 struct vm_struct *area;
78268
78269 BUG_ON(in_interrupt());
78270 +
78271 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78272 + if (flags & VM_KERNEXEC) {
78273 + if (start != VMALLOC_START || end != VMALLOC_END)
78274 + return NULL;
78275 + start = (unsigned long)MODULES_EXEC_VADDR;
78276 + end = (unsigned long)MODULES_EXEC_END;
78277 + }
78278 +#endif
78279 +
78280 if (flags & VM_IOREMAP) {
78281 int bit = fls(size);
78282
78283 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
78284 if (count > totalram_pages)
78285 return NULL;
78286
78287 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78288 + if (!(pgprot_val(prot) & _PAGE_NX))
78289 + flags |= VM_KERNEXEC;
78290 +#endif
78291 +
78292 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
78293 __builtin_return_address(0));
78294 if (!area)
78295 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
78296 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
78297 goto fail;
78298
78299 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78300 + if (!(pgprot_val(prot) & _PAGE_NX))
78301 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
78302 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
78303 + else
78304 +#endif
78305 +
78306 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
78307 start, end, node, gfp_mask, caller);
78308 if (!area)
78309 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
78310 * For tight control over page level allocator and protection flags
78311 * use __vmalloc() instead.
78312 */
78313 -
78314 void *vmalloc_exec(unsigned long size)
78315 {
78316 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
78317 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
78318 -1, __builtin_return_address(0));
78319 }
78320
78321 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
78322 unsigned long uaddr = vma->vm_start;
78323 unsigned long usize = vma->vm_end - vma->vm_start;
78324
78325 + BUG_ON(vma->vm_mirror);
78326 +
78327 if ((PAGE_SIZE-1) & (unsigned long)addr)
78328 return -EINVAL;
78329
78330 @@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
78331 v->addr, v->addr + v->size, v->size);
78332
78333 if (v->caller)
78334 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78335 + seq_printf(m, " %pK", v->caller);
78336 +#else
78337 seq_printf(m, " %pS", v->caller);
78338 +#endif
78339
78340 if (v->nr_pages)
78341 seq_printf(m, " pages=%d", v->nr_pages);
78342 diff --git a/mm/vmstat.c b/mm/vmstat.c
78343 index c737057..a49753a 100644
78344 --- a/mm/vmstat.c
78345 +++ b/mm/vmstat.c
78346 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
78347 *
78348 * vm_stat contains the global counters
78349 */
78350 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78351 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78352 EXPORT_SYMBOL(vm_stat);
78353
78354 #ifdef CONFIG_SMP
78355 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
78356 v = p->vm_stat_diff[i];
78357 p->vm_stat_diff[i] = 0;
78358 local_irq_restore(flags);
78359 - atomic_long_add(v, &zone->vm_stat[i]);
78360 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78361 global_diff[i] += v;
78362 #ifdef CONFIG_NUMA
78363 /* 3 seconds idle till flush */
78364 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
78365
78366 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
78367 if (global_diff[i])
78368 - atomic_long_add(global_diff[i], &vm_stat[i]);
78369 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
78370 }
78371
78372 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78373 @@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78374 if (pset->vm_stat_diff[i]) {
78375 int v = pset->vm_stat_diff[i];
78376 pset->vm_stat_diff[i] = 0;
78377 - atomic_long_add(v, &zone->vm_stat[i]);
78378 - atomic_long_add(v, &vm_stat[i]);
78379 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78380 + atomic_long_add_unchecked(v, &vm_stat[i]);
78381 }
78382 }
78383 #endif
78384 @@ -1224,10 +1224,20 @@ static int __init setup_vmstat(void)
78385 start_cpu_timer(cpu);
78386 #endif
78387 #ifdef CONFIG_PROC_FS
78388 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
78389 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
78390 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
78391 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
78392 + {
78393 + mode_t gr_mode = S_IRUGO;
78394 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
78395 + gr_mode = S_IRUSR;
78396 +#endif
78397 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
78398 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
78399 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78400 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
78401 +#else
78402 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
78403 +#endif
78404 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
78405 + }
78406 #endif
78407 return 0;
78408 }
78409 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
78410 index ee07072..593e3fd 100644
78411 --- a/net/8021q/vlan.c
78412 +++ b/net/8021q/vlan.c
78413 @@ -484,7 +484,7 @@ out:
78414 return NOTIFY_DONE;
78415 }
78416
78417 -static struct notifier_block vlan_notifier_block __read_mostly = {
78418 +static struct notifier_block vlan_notifier_block = {
78419 .notifier_call = vlan_device_event,
78420 };
78421
78422 @@ -559,8 +559,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
78423 err = -EPERM;
78424 if (!capable(CAP_NET_ADMIN))
78425 break;
78426 - if ((args.u.name_type >= 0) &&
78427 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
78428 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
78429 struct vlan_net *vn;
78430
78431 vn = net_generic(net, vlan_net_id);
78432 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
78433 index 02efb25..41541a9 100644
78434 --- a/net/9p/trans_fd.c
78435 +++ b/net/9p/trans_fd.c
78436 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
78437 oldfs = get_fs();
78438 set_fs(get_ds());
78439 /* The cast to a user pointer is valid due to the set_fs() */
78440 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
78441 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
78442 set_fs(oldfs);
78443
78444 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
78445 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
78446 index 876fbe8..8bbea9f 100644
78447 --- a/net/atm/atm_misc.c
78448 +++ b/net/atm/atm_misc.c
78449 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
78450 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
78451 return 1;
78452 atm_return(vcc, truesize);
78453 - atomic_inc(&vcc->stats->rx_drop);
78454 + atomic_inc_unchecked(&vcc->stats->rx_drop);
78455 return 0;
78456 }
78457 EXPORT_SYMBOL(atm_charge);
78458 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
78459 }
78460 }
78461 atm_return(vcc, guess);
78462 - atomic_inc(&vcc->stats->rx_drop);
78463 + atomic_inc_unchecked(&vcc->stats->rx_drop);
78464 return NULL;
78465 }
78466 EXPORT_SYMBOL(atm_alloc_charge);
78467 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
78468
78469 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78470 {
78471 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78472 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78473 __SONET_ITEMS
78474 #undef __HANDLE_ITEM
78475 }
78476 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
78477
78478 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78479 {
78480 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78481 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
78482 __SONET_ITEMS
78483 #undef __HANDLE_ITEM
78484 }
78485 diff --git a/net/atm/lec.h b/net/atm/lec.h
78486 index a86aff9..3a0d6f6 100644
78487 --- a/net/atm/lec.h
78488 +++ b/net/atm/lec.h
78489 @@ -48,7 +48,7 @@ struct lane2_ops {
78490 const u8 *tlvs, u32 sizeoftlvs);
78491 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
78492 const u8 *tlvs, u32 sizeoftlvs);
78493 -};
78494 +} __no_const;
78495
78496 /*
78497 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
78498 diff --git a/net/atm/proc.c b/net/atm/proc.c
78499 index 0d020de..011c7bb 100644
78500 --- a/net/atm/proc.c
78501 +++ b/net/atm/proc.c
78502 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
78503 const struct k_atm_aal_stats *stats)
78504 {
78505 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
78506 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
78507 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
78508 - atomic_read(&stats->rx_drop));
78509 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
78510 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
78511 + atomic_read_unchecked(&stats->rx_drop));
78512 }
78513
78514 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
78515 diff --git a/net/atm/resources.c b/net/atm/resources.c
78516 index 0447d5d..3cf4728 100644
78517 --- a/net/atm/resources.c
78518 +++ b/net/atm/resources.c
78519 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
78520 static void copy_aal_stats(struct k_atm_aal_stats *from,
78521 struct atm_aal_stats *to)
78522 {
78523 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78524 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78525 __AAL_STAT_ITEMS
78526 #undef __HANDLE_ITEM
78527 }
78528 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
78529 static void subtract_aal_stats(struct k_atm_aal_stats *from,
78530 struct atm_aal_stats *to)
78531 {
78532 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78533 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
78534 __AAL_STAT_ITEMS
78535 #undef __HANDLE_ITEM
78536 }
78537 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
78538 index c6fcc76..1270d14 100644
78539 --- a/net/batman-adv/bat_iv_ogm.c
78540 +++ b/net/batman-adv/bat_iv_ogm.c
78541 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
78542
78543 /* randomize initial seqno to avoid collision */
78544 get_random_bytes(&random_seqno, sizeof(random_seqno));
78545 - atomic_set(&hard_iface->seqno, random_seqno);
78546 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
78547
78548 hard_iface->packet_len = BATADV_OGM_HLEN;
78549 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
78550 @@ -608,9 +608,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
78551 batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
78552
78553 /* change sequence number to network order */
78554 - seqno = (uint32_t)atomic_read(&hard_iface->seqno);
78555 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->seqno);
78556 batadv_ogm_packet->seqno = htonl(seqno);
78557 - atomic_inc(&hard_iface->seqno);
78558 + atomic_inc_unchecked(&hard_iface->seqno);
78559
78560 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
78561 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
78562 @@ -1015,7 +1015,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
78563 return;
78564
78565 /* could be changed by schedule_own_packet() */
78566 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
78567 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
78568
78569 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
78570 has_directlink_flag = 1;
78571 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
78572 index d112fd6..686a447 100644
78573 --- a/net/batman-adv/hard-interface.c
78574 +++ b/net/batman-adv/hard-interface.c
78575 @@ -327,7 +327,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
78576 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
78577 dev_add_pack(&hard_iface->batman_adv_ptype);
78578
78579 - atomic_set(&hard_iface->frag_seqno, 1);
78580 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
78581 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
78582 hard_iface->net_dev->name);
78583
78584 @@ -450,7 +450,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
78585 /* This can't be called via a bat_priv callback because
78586 * we have no bat_priv yet.
78587 */
78588 - atomic_set(&hard_iface->seqno, 1);
78589 + atomic_set_unchecked(&hard_iface->seqno, 1);
78590 hard_iface->packet_buff = NULL;
78591
78592 return hard_iface;
78593 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
78594 index ce0684a..4a0cbf1 100644
78595 --- a/net/batman-adv/soft-interface.c
78596 +++ b/net/batman-adv/soft-interface.c
78597 @@ -234,7 +234,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
78598 primary_if->net_dev->dev_addr, ETH_ALEN);
78599
78600 /* set broadcast sequence number */
78601 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
78602 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
78603 bcast_packet->seqno = htonl(seqno);
78604
78605 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
78606 @@ -427,7 +427,7 @@ struct net_device *batadv_softif_create(const char *name)
78607 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
78608
78609 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
78610 - atomic_set(&bat_priv->bcast_seqno, 1);
78611 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
78612 atomic_set(&bat_priv->tt.vn, 0);
78613 atomic_set(&bat_priv->tt.local_changes, 0);
78614 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
78615 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
78616 index ac1e07a..4c846e2 100644
78617 --- a/net/batman-adv/types.h
78618 +++ b/net/batman-adv/types.h
78619 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
78620 int16_t if_num;
78621 char if_status;
78622 struct net_device *net_dev;
78623 - atomic_t seqno;
78624 - atomic_t frag_seqno;
78625 + atomic_unchecked_t seqno;
78626 + atomic_unchecked_t frag_seqno;
78627 unsigned char *packet_buff;
78628 int packet_len;
78629 struct kobject *hardif_obj;
78630 @@ -244,7 +244,7 @@ struct batadv_priv {
78631 atomic_t orig_interval; /* uint */
78632 atomic_t hop_penalty; /* uint */
78633 atomic_t log_level; /* uint */
78634 - atomic_t bcast_seqno;
78635 + atomic_unchecked_t bcast_seqno;
78636 atomic_t bcast_queue_left;
78637 atomic_t batman_queue_left;
78638 char num_ifaces;
78639 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
78640 index f397232..3206a33 100644
78641 --- a/net/batman-adv/unicast.c
78642 +++ b/net/batman-adv/unicast.c
78643 @@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
78644 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
78645 frag2->flags = large_tail;
78646
78647 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
78648 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
78649 frag1->seqno = htons(seqno - 1);
78650 frag2->seqno = htons(seqno);
78651
78652 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
78653 index 07f0739..3c42e34 100644
78654 --- a/net/bluetooth/hci_sock.c
78655 +++ b/net/bluetooth/hci_sock.c
78656 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
78657 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
78658 }
78659
78660 - len = min_t(unsigned int, len, sizeof(uf));
78661 + len = min((size_t)len, sizeof(uf));
78662 if (copy_from_user(&uf, optval, len)) {
78663 err = -EFAULT;
78664 break;
78665 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
78666 index a91239d..d7ed533 100644
78667 --- a/net/bluetooth/l2cap_core.c
78668 +++ b/net/bluetooth/l2cap_core.c
78669 @@ -3183,8 +3183,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
78670 break;
78671
78672 case L2CAP_CONF_RFC:
78673 - if (olen == sizeof(rfc))
78674 - memcpy(&rfc, (void *)val, olen);
78675 + if (olen != sizeof(rfc))
78676 + break;
78677 +
78678 + memcpy(&rfc, (void *)val, olen);
78679
78680 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
78681 rfc.mode != chan->mode)
78682 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
78683 index 083f2bf..799f9448 100644
78684 --- a/net/bluetooth/l2cap_sock.c
78685 +++ b/net/bluetooth/l2cap_sock.c
78686 @@ -471,7 +471,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78687 struct sock *sk = sock->sk;
78688 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
78689 struct l2cap_options opts;
78690 - int len, err = 0;
78691 + int err = 0;
78692 + size_t len = optlen;
78693 u32 opt;
78694
78695 BT_DBG("sk %p", sk);
78696 @@ -493,7 +494,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78697 opts.max_tx = chan->max_tx;
78698 opts.txwin_size = chan->tx_win;
78699
78700 - len = min_t(unsigned int, sizeof(opts), optlen);
78701 + len = min(sizeof(opts), len);
78702 if (copy_from_user((char *) &opts, optval, len)) {
78703 err = -EFAULT;
78704 break;
78705 @@ -571,7 +572,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78706 struct bt_security sec;
78707 struct bt_power pwr;
78708 struct l2cap_conn *conn;
78709 - int len, err = 0;
78710 + int err = 0;
78711 + size_t len = optlen;
78712 u32 opt;
78713
78714 BT_DBG("sk %p", sk);
78715 @@ -594,7 +596,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78716
78717 sec.level = BT_SECURITY_LOW;
78718
78719 - len = min_t(unsigned int, sizeof(sec), optlen);
78720 + len = min(sizeof(sec), len);
78721 if (copy_from_user((char *) &sec, optval, len)) {
78722 err = -EFAULT;
78723 break;
78724 @@ -691,7 +693,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78725
78726 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
78727
78728 - len = min_t(unsigned int, sizeof(pwr), optlen);
78729 + len = min(sizeof(pwr), len);
78730 if (copy_from_user((char *) &pwr, optval, len)) {
78731 err = -EFAULT;
78732 break;
78733 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
78734 index 868a909..d044bc3 100644
78735 --- a/net/bluetooth/rfcomm/sock.c
78736 +++ b/net/bluetooth/rfcomm/sock.c
78737 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78738 struct sock *sk = sock->sk;
78739 struct bt_security sec;
78740 int err = 0;
78741 - size_t len;
78742 + size_t len = optlen;
78743 u32 opt;
78744
78745 BT_DBG("sk %p", sk);
78746 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78747
78748 sec.level = BT_SECURITY_LOW;
78749
78750 - len = min_t(unsigned int, sizeof(sec), optlen);
78751 + len = min(sizeof(sec), len);
78752 if (copy_from_user((char *) &sec, optval, len)) {
78753 err = -EFAULT;
78754 break;
78755 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
78756 index ccc2487..921073d 100644
78757 --- a/net/bluetooth/rfcomm/tty.c
78758 +++ b/net/bluetooth/rfcomm/tty.c
78759 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
78760 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
78761
78762 spin_lock_irqsave(&dev->port.lock, flags);
78763 - if (dev->port.count > 0) {
78764 + if (atomic_read(&dev->port.count) > 0) {
78765 spin_unlock_irqrestore(&dev->port.lock, flags);
78766 return;
78767 }
78768 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
78769 return -ENODEV;
78770
78771 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
78772 - dev->channel, dev->port.count);
78773 + dev->channel, atomic_read(&dev->port.count));
78774
78775 spin_lock_irqsave(&dev->port.lock, flags);
78776 - if (++dev->port.count > 1) {
78777 + if (atomic_inc_return(&dev->port.count) > 1) {
78778 spin_unlock_irqrestore(&dev->port.lock, flags);
78779 return 0;
78780 }
78781 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
78782 return;
78783
78784 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
78785 - dev->port.count);
78786 + atomic_read(&dev->port.count));
78787
78788 spin_lock_irqsave(&dev->port.lock, flags);
78789 - if (!--dev->port.count) {
78790 + if (!atomic_dec_return(&dev->port.count)) {
78791 spin_unlock_irqrestore(&dev->port.lock, flags);
78792 if (dev->tty_dev->parent)
78793 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
78794 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
78795 index 5fe2ff3..121d696 100644
78796 --- a/net/bridge/netfilter/ebtables.c
78797 +++ b/net/bridge/netfilter/ebtables.c
78798 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78799 tmp.valid_hooks = t->table->valid_hooks;
78800 }
78801 mutex_unlock(&ebt_mutex);
78802 - if (copy_to_user(user, &tmp, *len) != 0){
78803 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
78804 BUGPRINT("c2u Didn't work\n");
78805 ret = -EFAULT;
78806 break;
78807 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78808 goto out;
78809 tmp.valid_hooks = t->valid_hooks;
78810
78811 - if (copy_to_user(user, &tmp, *len) != 0) {
78812 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78813 ret = -EFAULT;
78814 break;
78815 }
78816 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78817 tmp.entries_size = t->table->entries_size;
78818 tmp.valid_hooks = t->table->valid_hooks;
78819
78820 - if (copy_to_user(user, &tmp, *len) != 0) {
78821 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78822 ret = -EFAULT;
78823 break;
78824 }
78825 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
78826 index 44f270f..1f5602d 100644
78827 --- a/net/caif/cfctrl.c
78828 +++ b/net/caif/cfctrl.c
78829 @@ -10,6 +10,7 @@
78830 #include <linux/spinlock.h>
78831 #include <linux/slab.h>
78832 #include <linux/pkt_sched.h>
78833 +#include <linux/sched.h>
78834 #include <net/caif/caif_layer.h>
78835 #include <net/caif/cfpkt.h>
78836 #include <net/caif/cfctrl.h>
78837 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
78838 memset(&dev_info, 0, sizeof(dev_info));
78839 dev_info.id = 0xff;
78840 cfsrvl_init(&this->serv, 0, &dev_info, false);
78841 - atomic_set(&this->req_seq_no, 1);
78842 - atomic_set(&this->rsp_seq_no, 1);
78843 + atomic_set_unchecked(&this->req_seq_no, 1);
78844 + atomic_set_unchecked(&this->rsp_seq_no, 1);
78845 this->serv.layer.receive = cfctrl_recv;
78846 sprintf(this->serv.layer.name, "ctrl");
78847 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
78848 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
78849 struct cfctrl_request_info *req)
78850 {
78851 spin_lock_bh(&ctrl->info_list_lock);
78852 - atomic_inc(&ctrl->req_seq_no);
78853 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
78854 + atomic_inc_unchecked(&ctrl->req_seq_no);
78855 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
78856 list_add_tail(&req->list, &ctrl->list);
78857 spin_unlock_bh(&ctrl->info_list_lock);
78858 }
78859 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
78860 if (p != first)
78861 pr_warn("Requests are not received in order\n");
78862
78863 - atomic_set(&ctrl->rsp_seq_no,
78864 + atomic_set_unchecked(&ctrl->rsp_seq_no,
78865 p->sequence_no);
78866 list_del(&p->list);
78867 goto out;
78868 diff --git a/net/can/af_can.c b/net/can/af_can.c
78869 index ddac1ee..3ee0a78 100644
78870 --- a/net/can/af_can.c
78871 +++ b/net/can/af_can.c
78872 @@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
78873 };
78874
78875 /* notifier block for netdevice event */
78876 -static struct notifier_block can_netdev_notifier __read_mostly = {
78877 +static struct notifier_block can_netdev_notifier = {
78878 .notifier_call = can_notifier,
78879 };
78880
78881 diff --git a/net/can/gw.c b/net/can/gw.c
78882 index 1f5c978..ef714c7 100644
78883 --- a/net/can/gw.c
78884 +++ b/net/can/gw.c
78885 @@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
78886 MODULE_ALIAS("can-gw");
78887
78888 static HLIST_HEAD(cgw_list);
78889 -static struct notifier_block notifier;
78890
78891 static struct kmem_cache *cgw_cache __read_mostly;
78892
78893 @@ -887,6 +886,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
78894 return err;
78895 }
78896
78897 +static struct notifier_block notifier = {
78898 + .notifier_call = cgw_notifier
78899 +};
78900 +
78901 static __init int cgw_module_init(void)
78902 {
78903 printk(banner);
78904 @@ -898,7 +901,6 @@ static __init int cgw_module_init(void)
78905 return -ENOMEM;
78906
78907 /* set notifier */
78908 - notifier.notifier_call = cgw_notifier;
78909 register_netdevice_notifier(&notifier);
78910
78911 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
78912 diff --git a/net/compat.c b/net/compat.c
78913 index 79ae884..17c5c09 100644
78914 --- a/net/compat.c
78915 +++ b/net/compat.c
78916 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
78917 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
78918 __get_user(kmsg->msg_flags, &umsg->msg_flags))
78919 return -EFAULT;
78920 - kmsg->msg_name = compat_ptr(tmp1);
78921 - kmsg->msg_iov = compat_ptr(tmp2);
78922 - kmsg->msg_control = compat_ptr(tmp3);
78923 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
78924 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
78925 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
78926 return 0;
78927 }
78928
78929 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
78930
78931 if (kern_msg->msg_namelen) {
78932 if (mode == VERIFY_READ) {
78933 - int err = move_addr_to_kernel(kern_msg->msg_name,
78934 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
78935 kern_msg->msg_namelen,
78936 kern_address);
78937 if (err < 0)
78938 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
78939 kern_msg->msg_name = NULL;
78940
78941 tot_len = iov_from_user_compat_to_kern(kern_iov,
78942 - (struct compat_iovec __user *)kern_msg->msg_iov,
78943 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
78944 kern_msg->msg_iovlen);
78945 if (tot_len >= 0)
78946 kern_msg->msg_iov = kern_iov;
78947 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
78948
78949 #define CMSG_COMPAT_FIRSTHDR(msg) \
78950 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
78951 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
78952 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
78953 (struct compat_cmsghdr __user *)NULL)
78954
78955 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
78956 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
78957 (ucmlen) <= (unsigned long) \
78958 ((mhdr)->msg_controllen - \
78959 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
78960 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
78961
78962 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
78963 struct compat_cmsghdr __user *cmsg, int cmsg_len)
78964 {
78965 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
78966 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
78967 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
78968 msg->msg_controllen)
78969 return NULL;
78970 return (struct compat_cmsghdr __user *)ptr;
78971 @@ -219,7 +219,7 @@ Efault:
78972
78973 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
78974 {
78975 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
78976 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
78977 struct compat_cmsghdr cmhdr;
78978 struct compat_timeval ctv;
78979 struct compat_timespec cts[3];
78980 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
78981
78982 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
78983 {
78984 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
78985 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
78986 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
78987 int fdnum = scm->fp->count;
78988 struct file **fp = scm->fp->fp;
78989 @@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
78990 return -EFAULT;
78991 old_fs = get_fs();
78992 set_fs(KERNEL_DS);
78993 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
78994 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
78995 set_fs(old_fs);
78996
78997 return err;
78998 @@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
78999 len = sizeof(ktime);
79000 old_fs = get_fs();
79001 set_fs(KERNEL_DS);
79002 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
79003 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
79004 set_fs(old_fs);
79005
79006 if (!err) {
79007 @@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79008 case MCAST_JOIN_GROUP:
79009 case MCAST_LEAVE_GROUP:
79010 {
79011 - struct compat_group_req __user *gr32 = (void *)optval;
79012 + struct compat_group_req __user *gr32 = (void __user *)optval;
79013 struct group_req __user *kgr =
79014 compat_alloc_user_space(sizeof(struct group_req));
79015 u32 interface;
79016 @@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79017 case MCAST_BLOCK_SOURCE:
79018 case MCAST_UNBLOCK_SOURCE:
79019 {
79020 - struct compat_group_source_req __user *gsr32 = (void *)optval;
79021 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
79022 struct group_source_req __user *kgsr = compat_alloc_user_space(
79023 sizeof(struct group_source_req));
79024 u32 interface;
79025 @@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79026 }
79027 case MCAST_MSFILTER:
79028 {
79029 - struct compat_group_filter __user *gf32 = (void *)optval;
79030 + struct compat_group_filter __user *gf32 = (void __user *)optval;
79031 struct group_filter __user *kgf;
79032 u32 interface, fmode, numsrc;
79033
79034 @@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
79035 char __user *optval, int __user *optlen,
79036 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
79037 {
79038 - struct compat_group_filter __user *gf32 = (void *)optval;
79039 + struct compat_group_filter __user *gf32 = (void __user *)optval;
79040 struct group_filter __user *kgf;
79041 int __user *koptlen;
79042 u32 interface, fmode, numsrc;
79043 @@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
79044
79045 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
79046 return -EINVAL;
79047 - if (copy_from_user(a, args, nas[call]))
79048 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
79049 return -EFAULT;
79050 a0 = a[0];
79051 a1 = a[1];
79052 diff --git a/net/core/datagram.c b/net/core/datagram.c
79053 index 0337e2b..47914a0 100644
79054 --- a/net/core/datagram.c
79055 +++ b/net/core/datagram.c
79056 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
79057 }
79058
79059 kfree_skb(skb);
79060 - atomic_inc(&sk->sk_drops);
79061 + atomic_inc_unchecked(&sk->sk_drops);
79062 sk_mem_reclaim_partial(sk);
79063
79064 return err;
79065 diff --git a/net/core/dev.c b/net/core/dev.c
79066 index e5942bf..25998c3 100644
79067 --- a/net/core/dev.c
79068 +++ b/net/core/dev.c
79069 @@ -1162,9 +1162,13 @@ void dev_load(struct net *net, const char *name)
79070 if (no_module && capable(CAP_NET_ADMIN))
79071 no_module = request_module("netdev-%s", name);
79072 if (no_module && capable(CAP_SYS_MODULE)) {
79073 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
79074 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
79075 +#else
79076 if (!request_module("%s", name))
79077 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
79078 name);
79079 +#endif
79080 }
79081 }
79082 EXPORT_SYMBOL(dev_load);
79083 @@ -1627,7 +1631,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
79084 {
79085 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
79086 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
79087 - atomic_long_inc(&dev->rx_dropped);
79088 + atomic_long_inc_unchecked(&dev->rx_dropped);
79089 kfree_skb(skb);
79090 return NET_RX_DROP;
79091 }
79092 @@ -1637,7 +1641,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
79093 nf_reset(skb);
79094
79095 if (unlikely(!is_skb_forwardable(dev, skb))) {
79096 - atomic_long_inc(&dev->rx_dropped);
79097 + atomic_long_inc_unchecked(&dev->rx_dropped);
79098 kfree_skb(skb);
79099 return NET_RX_DROP;
79100 }
79101 @@ -2093,7 +2097,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
79102
79103 struct dev_gso_cb {
79104 void (*destructor)(struct sk_buff *skb);
79105 -};
79106 +} __no_const;
79107
79108 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
79109
79110 @@ -2955,7 +2959,7 @@ enqueue:
79111
79112 local_irq_restore(flags);
79113
79114 - atomic_long_inc(&skb->dev->rx_dropped);
79115 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
79116 kfree_skb(skb);
79117 return NET_RX_DROP;
79118 }
79119 @@ -3027,7 +3031,7 @@ int netif_rx_ni(struct sk_buff *skb)
79120 }
79121 EXPORT_SYMBOL(netif_rx_ni);
79122
79123 -static void net_tx_action(struct softirq_action *h)
79124 +static void net_tx_action(void)
79125 {
79126 struct softnet_data *sd = &__get_cpu_var(softnet_data);
79127
79128 @@ -3358,7 +3362,7 @@ ncls:
79129 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
79130 } else {
79131 drop:
79132 - atomic_long_inc(&skb->dev->rx_dropped);
79133 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
79134 kfree_skb(skb);
79135 /* Jamal, now you will not able to escape explaining
79136 * me how you were going to use this. :-)
79137 @@ -3944,7 +3948,7 @@ void netif_napi_del(struct napi_struct *napi)
79138 }
79139 EXPORT_SYMBOL(netif_napi_del);
79140
79141 -static void net_rx_action(struct softirq_action *h)
79142 +static void net_rx_action(void)
79143 {
79144 struct softnet_data *sd = &__get_cpu_var(softnet_data);
79145 unsigned long time_limit = jiffies + 2;
79146 @@ -4423,8 +4427,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
79147 else
79148 seq_printf(seq, "%04x", ntohs(pt->type));
79149
79150 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79151 + seq_printf(seq, " %-8s %p\n",
79152 + pt->dev ? pt->dev->name : "", NULL);
79153 +#else
79154 seq_printf(seq, " %-8s %pF\n",
79155 pt->dev ? pt->dev->name : "", pt->func);
79156 +#endif
79157 }
79158
79159 return 0;
79160 @@ -5987,7 +5996,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
79161 } else {
79162 netdev_stats_to_stats64(storage, &dev->stats);
79163 }
79164 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
79165 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
79166 return storage;
79167 }
79168 EXPORT_SYMBOL(dev_get_stats);
79169 diff --git a/net/core/flow.c b/net/core/flow.c
79170 index e318c7e..168b1d0 100644
79171 --- a/net/core/flow.c
79172 +++ b/net/core/flow.c
79173 @@ -61,7 +61,7 @@ struct flow_cache {
79174 struct timer_list rnd_timer;
79175 };
79176
79177 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
79178 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
79179 EXPORT_SYMBOL(flow_cache_genid);
79180 static struct flow_cache flow_cache_global;
79181 static struct kmem_cache *flow_cachep __read_mostly;
79182 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
79183
79184 static int flow_entry_valid(struct flow_cache_entry *fle)
79185 {
79186 - if (atomic_read(&flow_cache_genid) != fle->genid)
79187 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
79188 return 0;
79189 if (fle->object && !fle->object->ops->check(fle->object))
79190 return 0;
79191 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
79192 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
79193 fcp->hash_count++;
79194 }
79195 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
79196 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
79197 flo = fle->object;
79198 if (!flo)
79199 goto ret_object;
79200 @@ -280,7 +280,7 @@ nocache:
79201 }
79202 flo = resolver(net, key, family, dir, flo, ctx);
79203 if (fle) {
79204 - fle->genid = atomic_read(&flow_cache_genid);
79205 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
79206 if (!IS_ERR(flo))
79207 fle->object = flo;
79208 else
79209 diff --git a/net/core/iovec.c b/net/core/iovec.c
79210 index 7e7aeb0..2a998cb 100644
79211 --- a/net/core/iovec.c
79212 +++ b/net/core/iovec.c
79213 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
79214 if (m->msg_namelen) {
79215 if (mode == VERIFY_READ) {
79216 void __user *namep;
79217 - namep = (void __user __force *) m->msg_name;
79218 + namep = (void __force_user *) m->msg_name;
79219 err = move_addr_to_kernel(namep, m->msg_namelen,
79220 address);
79221 if (err < 0)
79222 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
79223 }
79224
79225 size = m->msg_iovlen * sizeof(struct iovec);
79226 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
79227 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
79228 return -EFAULT;
79229
79230 m->msg_iov = iov;
79231 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
79232 index fad649a..f2fdac4 100644
79233 --- a/net/core/rtnetlink.c
79234 +++ b/net/core/rtnetlink.c
79235 @@ -198,14 +198,16 @@ int __rtnl_register(int protocol, int msgtype,
79236 rtnl_msg_handlers[protocol] = tab;
79237 }
79238
79239 + pax_open_kernel();
79240 if (doit)
79241 - tab[msgindex].doit = doit;
79242 + *(void **)&tab[msgindex].doit = doit;
79243
79244 if (dumpit)
79245 - tab[msgindex].dumpit = dumpit;
79246 + *(void **)&tab[msgindex].dumpit = dumpit;
79247
79248 if (calcit)
79249 - tab[msgindex].calcit = calcit;
79250 + *(void **)&tab[msgindex].calcit = calcit;
79251 + pax_close_kernel();
79252
79253 return 0;
79254 }
79255 @@ -248,8 +250,10 @@ int rtnl_unregister(int protocol, int msgtype)
79256 if (rtnl_msg_handlers[protocol] == NULL)
79257 return -ENOENT;
79258
79259 - rtnl_msg_handlers[protocol][msgindex].doit = NULL;
79260 - rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
79261 + pax_open_kernel();
79262 + *(void **)&rtnl_msg_handlers[protocol][msgindex].doit = NULL;
79263 + *(void **)&rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
79264 + pax_close_kernel();
79265
79266 return 0;
79267 }
79268 diff --git a/net/core/scm.c b/net/core/scm.c
79269 index ab57084..0190c8f 100644
79270 --- a/net/core/scm.c
79271 +++ b/net/core/scm.c
79272 @@ -223,7 +223,7 @@ EXPORT_SYMBOL(__scm_send);
79273 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79274 {
79275 struct cmsghdr __user *cm
79276 - = (__force struct cmsghdr __user *)msg->msg_control;
79277 + = (struct cmsghdr __force_user *)msg->msg_control;
79278 struct cmsghdr cmhdr;
79279 int cmlen = CMSG_LEN(len);
79280 int err;
79281 @@ -246,7 +246,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79282 err = -EFAULT;
79283 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
79284 goto out;
79285 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
79286 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
79287 goto out;
79288 cmlen = CMSG_SPACE(len);
79289 if (msg->msg_controllen < cmlen)
79290 @@ -262,7 +262,7 @@ EXPORT_SYMBOL(put_cmsg);
79291 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79292 {
79293 struct cmsghdr __user *cm
79294 - = (__force struct cmsghdr __user*)msg->msg_control;
79295 + = (struct cmsghdr __force_user *)msg->msg_control;
79296
79297 int fdmax = 0;
79298 int fdnum = scm->fp->count;
79299 @@ -282,7 +282,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79300 if (fdnum < fdmax)
79301 fdmax = fdnum;
79302
79303 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
79304 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
79305 i++, cmfptr++)
79306 {
79307 struct socket *sock;
79308 diff --git a/net/core/sock.c b/net/core/sock.c
79309 index 8a146cf..ee08914d 100644
79310 --- a/net/core/sock.c
79311 +++ b/net/core/sock.c
79312 @@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79313 struct sk_buff_head *list = &sk->sk_receive_queue;
79314
79315 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
79316 - atomic_inc(&sk->sk_drops);
79317 + atomic_inc_unchecked(&sk->sk_drops);
79318 trace_sock_rcvqueue_full(sk, skb);
79319 return -ENOMEM;
79320 }
79321 @@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79322 return err;
79323
79324 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
79325 - atomic_inc(&sk->sk_drops);
79326 + atomic_inc_unchecked(&sk->sk_drops);
79327 return -ENOBUFS;
79328 }
79329
79330 @@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79331 skb_dst_force(skb);
79332
79333 spin_lock_irqsave(&list->lock, flags);
79334 - skb->dropcount = atomic_read(&sk->sk_drops);
79335 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
79336 __skb_queue_tail(list, skb);
79337 spin_unlock_irqrestore(&list->lock, flags);
79338
79339 @@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79340 skb->dev = NULL;
79341
79342 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
79343 - atomic_inc(&sk->sk_drops);
79344 + atomic_inc_unchecked(&sk->sk_drops);
79345 goto discard_and_relse;
79346 }
79347 if (nested)
79348 @@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79349 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
79350 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
79351 bh_unlock_sock(sk);
79352 - atomic_inc(&sk->sk_drops);
79353 + atomic_inc_unchecked(&sk->sk_drops);
79354 goto discard_and_relse;
79355 }
79356
79357 @@ -875,12 +875,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79358 struct timeval tm;
79359 } v;
79360
79361 - int lv = sizeof(int);
79362 - int len;
79363 + unsigned int lv = sizeof(int);
79364 + unsigned int len;
79365
79366 if (get_user(len, optlen))
79367 return -EFAULT;
79368 - if (len < 0)
79369 + if (len > INT_MAX)
79370 return -EINVAL;
79371
79372 memset(&v, 0, sizeof(v));
79373 @@ -1028,11 +1028,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79374
79375 case SO_PEERNAME:
79376 {
79377 - char address[128];
79378 + char address[_K_SS_MAXSIZE];
79379
79380 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
79381 return -ENOTCONN;
79382 - if (lv < len)
79383 + if (lv < len || sizeof address < len)
79384 return -EINVAL;
79385 if (copy_to_user(optval, address, len))
79386 return -EFAULT;
79387 @@ -1080,7 +1080,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79388
79389 if (len > lv)
79390 len = lv;
79391 - if (copy_to_user(optval, &v, len))
79392 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
79393 return -EFAULT;
79394 lenout:
79395 if (put_user(len, optlen))
79396 @@ -2212,7 +2212,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
79397 */
79398 smp_wmb();
79399 atomic_set(&sk->sk_refcnt, 1);
79400 - atomic_set(&sk->sk_drops, 0);
79401 + atomic_set_unchecked(&sk->sk_drops, 0);
79402 }
79403 EXPORT_SYMBOL(sock_init_data);
79404
79405 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
79406 index 602cd63..05c6c60 100644
79407 --- a/net/core/sock_diag.c
79408 +++ b/net/core/sock_diag.c
79409 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
79410
79411 int sock_diag_check_cookie(void *sk, __u32 *cookie)
79412 {
79413 +#ifndef CONFIG_GRKERNSEC_HIDESYM
79414 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
79415 cookie[1] != INET_DIAG_NOCOOKIE) &&
79416 ((u32)(unsigned long)sk != cookie[0] ||
79417 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
79418 return -ESTALE;
79419 else
79420 +#endif
79421 return 0;
79422 }
79423 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
79424
79425 void sock_diag_save_cookie(void *sk, __u32 *cookie)
79426 {
79427 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79428 + cookie[0] = 0;
79429 + cookie[1] = 0;
79430 +#else
79431 cookie[0] = (u32)(unsigned long)sk;
79432 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
79433 +#endif
79434 }
79435 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
79436
79437 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
79438 index a55eecc..dd8428c 100644
79439 --- a/net/decnet/sysctl_net_decnet.c
79440 +++ b/net/decnet/sysctl_net_decnet.c
79441 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
79442
79443 if (len > *lenp) len = *lenp;
79444
79445 - if (copy_to_user(buffer, addr, len))
79446 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
79447 return -EFAULT;
79448
79449 *lenp = len;
79450 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
79451
79452 if (len > *lenp) len = *lenp;
79453
79454 - if (copy_to_user(buffer, devname, len))
79455 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
79456 return -EFAULT;
79457
79458 *lenp = len;
79459 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
79460 index 2a6abc1..c379ba7 100644
79461 --- a/net/ipv4/devinet.c
79462 +++ b/net/ipv4/devinet.c
79463 @@ -822,9 +822,9 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg)
79464 if (!ifa) {
79465 ret = -ENOBUFS;
79466 ifa = inet_alloc_ifa();
79467 + if (!ifa)
79468 + break;
79469 INIT_HLIST_NODE(&ifa->hash);
79470 - if (!ifa)
79471 - break;
79472 if (colon)
79473 memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ);
79474 else
79475 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
79476 index 825c608..750ff29 100644
79477 --- a/net/ipv4/fib_frontend.c
79478 +++ b/net/ipv4/fib_frontend.c
79479 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
79480 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79481 fib_sync_up(dev);
79482 #endif
79483 - atomic_inc(&net->ipv4.dev_addr_genid);
79484 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79485 rt_cache_flush(dev_net(dev));
79486 break;
79487 case NETDEV_DOWN:
79488 fib_del_ifaddr(ifa, NULL);
79489 - atomic_inc(&net->ipv4.dev_addr_genid);
79490 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79491 if (ifa->ifa_dev->ifa_list == NULL) {
79492 /* Last address was deleted from this interface.
79493 * Disable IP.
79494 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
79495 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79496 fib_sync_up(dev);
79497 #endif
79498 - atomic_inc(&net->ipv4.dev_addr_genid);
79499 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79500 rt_cache_flush(net);
79501 break;
79502 case NETDEV_DOWN:
79503 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
79504 index 71b125c..f4c70b0 100644
79505 --- a/net/ipv4/fib_semantics.c
79506 +++ b/net/ipv4/fib_semantics.c
79507 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
79508 nh->nh_saddr = inet_select_addr(nh->nh_dev,
79509 nh->nh_gw,
79510 nh->nh_parent->fib_scope);
79511 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
79512 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
79513
79514 return nh->nh_saddr;
79515 }
79516 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
79517 index 7880af9..70f92a3 100644
79518 --- a/net/ipv4/inet_hashtables.c
79519 +++ b/net/ipv4/inet_hashtables.c
79520 @@ -18,12 +18,15 @@
79521 #include <linux/sched.h>
79522 #include <linux/slab.h>
79523 #include <linux/wait.h>
79524 +#include <linux/security.h>
79525
79526 #include <net/inet_connection_sock.h>
79527 #include <net/inet_hashtables.h>
79528 #include <net/secure_seq.h>
79529 #include <net/ip.h>
79530
79531 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
79532 +
79533 /*
79534 * Allocate and initialize a new local port bind bucket.
79535 * The bindhash mutex for snum's hash chain must be held here.
79536 @@ -530,6 +533,8 @@ ok:
79537 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
79538 spin_unlock(&head->lock);
79539
79540 + gr_update_task_in_ip_table(current, inet_sk(sk));
79541 +
79542 if (tw) {
79543 inet_twsk_deschedule(tw, death_row);
79544 while (twrefcnt) {
79545 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
79546 index 000e3d2..5472da3 100644
79547 --- a/net/ipv4/inetpeer.c
79548 +++ b/net/ipv4/inetpeer.c
79549 @@ -503,8 +503,8 @@ relookup:
79550 if (p) {
79551 p->daddr = *daddr;
79552 atomic_set(&p->refcnt, 1);
79553 - atomic_set(&p->rid, 0);
79554 - atomic_set(&p->ip_id_count,
79555 + atomic_set_unchecked(&p->rid, 0);
79556 + atomic_set_unchecked(&p->ip_id_count,
79557 (daddr->family == AF_INET) ?
79558 secure_ip_id(daddr->addr.a4) :
79559 secure_ipv6_id(daddr->addr.a6));
79560 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
79561 index 8d5cc75..821fd11 100644
79562 --- a/net/ipv4/ip_fragment.c
79563 +++ b/net/ipv4/ip_fragment.c
79564 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
79565 return 0;
79566
79567 start = qp->rid;
79568 - end = atomic_inc_return(&peer->rid);
79569 + end = atomic_inc_return_unchecked(&peer->rid);
79570 qp->rid = end;
79571
79572 rc = qp->q.fragments && (end - start) > max;
79573 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
79574 index 14bbfcf..644f472 100644
79575 --- a/net/ipv4/ip_sockglue.c
79576 +++ b/net/ipv4/ip_sockglue.c
79577 @@ -1151,7 +1151,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79578 len = min_t(unsigned int, len, opt->optlen);
79579 if (put_user(len, optlen))
79580 return -EFAULT;
79581 - if (copy_to_user(optval, opt->__data, len))
79582 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
79583 + copy_to_user(optval, opt->__data, len))
79584 return -EFAULT;
79585 return 0;
79586 }
79587 @@ -1282,7 +1283,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79588 if (sk->sk_type != SOCK_STREAM)
79589 return -ENOPROTOOPT;
79590
79591 - msg.msg_control = optval;
79592 + msg.msg_control = (void __force_kernel *)optval;
79593 msg.msg_controllen = len;
79594 msg.msg_flags = flags;
79595
79596 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
79597 index 798358b..73570b7 100644
79598 --- a/net/ipv4/ipconfig.c
79599 +++ b/net/ipv4/ipconfig.c
79600 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
79601
79602 mm_segment_t oldfs = get_fs();
79603 set_fs(get_ds());
79604 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79605 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79606 set_fs(oldfs);
79607 return res;
79608 }
79609 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
79610
79611 mm_segment_t oldfs = get_fs();
79612 set_fs(get_ds());
79613 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79614 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79615 set_fs(oldfs);
79616 return res;
79617 }
79618 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
79619
79620 mm_segment_t oldfs = get_fs();
79621 set_fs(get_ds());
79622 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
79623 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
79624 set_fs(oldfs);
79625 return res;
79626 }
79627 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
79628 index 97e61ea..cac1bbb 100644
79629 --- a/net/ipv4/netfilter/arp_tables.c
79630 +++ b/net/ipv4/netfilter/arp_tables.c
79631 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
79632 #endif
79633
79634 static int get_info(struct net *net, void __user *user,
79635 - const int *len, int compat)
79636 + int len, int compat)
79637 {
79638 char name[XT_TABLE_MAXNAMELEN];
79639 struct xt_table *t;
79640 int ret;
79641
79642 - if (*len != sizeof(struct arpt_getinfo)) {
79643 - duprintf("length %u != %Zu\n", *len,
79644 + if (len != sizeof(struct arpt_getinfo)) {
79645 + duprintf("length %u != %Zu\n", len,
79646 sizeof(struct arpt_getinfo));
79647 return -EINVAL;
79648 }
79649 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
79650 info.size = private->size;
79651 strcpy(info.name, name);
79652
79653 - if (copy_to_user(user, &info, *len) != 0)
79654 + if (copy_to_user(user, &info, len) != 0)
79655 ret = -EFAULT;
79656 else
79657 ret = 0;
79658 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
79659
79660 switch (cmd) {
79661 case ARPT_SO_GET_INFO:
79662 - ret = get_info(sock_net(sk), user, len, 1);
79663 + ret = get_info(sock_net(sk), user, *len, 1);
79664 break;
79665 case ARPT_SO_GET_ENTRIES:
79666 ret = compat_get_entries(sock_net(sk), user, len);
79667 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
79668
79669 switch (cmd) {
79670 case ARPT_SO_GET_INFO:
79671 - ret = get_info(sock_net(sk), user, len, 0);
79672 + ret = get_info(sock_net(sk), user, *len, 0);
79673 break;
79674
79675 case ARPT_SO_GET_ENTRIES:
79676 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
79677 index 170b1fd..6105b91 100644
79678 --- a/net/ipv4/netfilter/ip_tables.c
79679 +++ b/net/ipv4/netfilter/ip_tables.c
79680 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
79681 #endif
79682
79683 static int get_info(struct net *net, void __user *user,
79684 - const int *len, int compat)
79685 + int len, int compat)
79686 {
79687 char name[XT_TABLE_MAXNAMELEN];
79688 struct xt_table *t;
79689 int ret;
79690
79691 - if (*len != sizeof(struct ipt_getinfo)) {
79692 - duprintf("length %u != %zu\n", *len,
79693 + if (len != sizeof(struct ipt_getinfo)) {
79694 + duprintf("length %u != %zu\n", len,
79695 sizeof(struct ipt_getinfo));
79696 return -EINVAL;
79697 }
79698 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
79699 info.size = private->size;
79700 strcpy(info.name, name);
79701
79702 - if (copy_to_user(user, &info, *len) != 0)
79703 + if (copy_to_user(user, &info, len) != 0)
79704 ret = -EFAULT;
79705 else
79706 ret = 0;
79707 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79708
79709 switch (cmd) {
79710 case IPT_SO_GET_INFO:
79711 - ret = get_info(sock_net(sk), user, len, 1);
79712 + ret = get_info(sock_net(sk), user, *len, 1);
79713 break;
79714 case IPT_SO_GET_ENTRIES:
79715 ret = compat_get_entries(sock_net(sk), user, len);
79716 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79717
79718 switch (cmd) {
79719 case IPT_SO_GET_INFO:
79720 - ret = get_info(sock_net(sk), user, len, 0);
79721 + ret = get_info(sock_net(sk), user, *len, 0);
79722 break;
79723
79724 case IPT_SO_GET_ENTRIES:
79725 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
79726 index 8f3d054..c58d05d 100644
79727 --- a/net/ipv4/ping.c
79728 +++ b/net/ipv4/ping.c
79729 @@ -843,7 +843,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
79730 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
79731 0, sock_i_ino(sp),
79732 atomic_read(&sp->sk_refcnt), sp,
79733 - atomic_read(&sp->sk_drops), len);
79734 + atomic_read_unchecked(&sp->sk_drops), len);
79735 }
79736
79737 static int ping_seq_show(struct seq_file *seq, void *v)
79738 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
79739 index 73d1e4d..3af0e8f 100644
79740 --- a/net/ipv4/raw.c
79741 +++ b/net/ipv4/raw.c
79742 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
79743 int raw_rcv(struct sock *sk, struct sk_buff *skb)
79744 {
79745 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
79746 - atomic_inc(&sk->sk_drops);
79747 + atomic_inc_unchecked(&sk->sk_drops);
79748 kfree_skb(skb);
79749 return NET_RX_DROP;
79750 }
79751 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
79752
79753 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
79754 {
79755 + struct icmp_filter filter;
79756 +
79757 if (optlen > sizeof(struct icmp_filter))
79758 optlen = sizeof(struct icmp_filter);
79759 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
79760 + if (copy_from_user(&filter, optval, optlen))
79761 return -EFAULT;
79762 + raw_sk(sk)->filter = filter;
79763 return 0;
79764 }
79765
79766 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
79767 {
79768 int len, ret = -EFAULT;
79769 + struct icmp_filter filter;
79770
79771 if (get_user(len, optlen))
79772 goto out;
79773 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
79774 if (len > sizeof(struct icmp_filter))
79775 len = sizeof(struct icmp_filter);
79776 ret = -EFAULT;
79777 - if (put_user(len, optlen) ||
79778 - copy_to_user(optval, &raw_sk(sk)->filter, len))
79779 + filter = raw_sk(sk)->filter;
79780 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
79781 goto out;
79782 ret = 0;
79783 out: return ret;
79784 @@ -997,7 +1001,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
79785 0, 0L, 0,
79786 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
79787 0, sock_i_ino(sp),
79788 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
79789 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
79790 }
79791
79792 static int raw_seq_show(struct seq_file *seq, void *v)
79793 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
79794 index df25142..e92a82a 100644
79795 --- a/net/ipv4/route.c
79796 +++ b/net/ipv4/route.c
79797 @@ -2529,7 +2529,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
79798
79799 static __net_init int rt_genid_init(struct net *net)
79800 {
79801 - atomic_set(&net->rt_genid, 0);
79802 + atomic_set_unchecked(&net->rt_genid, 0);
79803 get_random_bytes(&net->ipv4.dev_addr_genid,
79804 sizeof(net->ipv4.dev_addr_genid));
79805 return 0;
79806 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
79807 index 181fc82..cc95f8c 100644
79808 --- a/net/ipv4/tcp_input.c
79809 +++ b/net/ipv4/tcp_input.c
79810 @@ -4704,7 +4704,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
79811 * simplifies code)
79812 */
79813 static void
79814 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
79815 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
79816 struct sk_buff *head, struct sk_buff *tail,
79817 u32 start, u32 end)
79818 {
79819 @@ -5536,6 +5536,9 @@ slow_path:
79820 if (len < (th->doff << 2) || tcp_checksum_complete_user(sk, skb))
79821 goto csum_error;
79822
79823 + if (!th->ack)
79824 + goto discard;
79825 +
79826 /*
79827 * Standard slow path.
79828 */
79829 @@ -5544,7 +5547,7 @@ slow_path:
79830 return 0;
79831
79832 step5:
79833 - if (th->ack && tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
79834 + if (tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
79835 goto discard;
79836
79837 /* ts_recent update must be made after we are sure that the packet
79838 @@ -5836,6 +5839,7 @@ discard:
79839 tcp_paws_reject(&tp->rx_opt, 0))
79840 goto discard_and_undo;
79841
79842 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
79843 if (th->syn) {
79844 /* We see SYN without ACK. It is attempt of
79845 * simultaneous connect with crossed SYNs.
79846 @@ -5886,6 +5890,7 @@ discard:
79847 goto discard;
79848 #endif
79849 }
79850 +#endif
79851 /* "fifth, if neither of the SYN or RST bits is set then
79852 * drop the segment and return."
79853 */
79854 @@ -5930,7 +5935,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79855 goto discard;
79856
79857 if (th->syn) {
79858 - if (th->fin)
79859 + if (th->fin || th->urg || th->psh)
79860 goto discard;
79861 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
79862 return 1;
79863 @@ -5977,11 +5982,15 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79864 if (tcp_check_req(sk, skb, req, NULL, true) == NULL)
79865 goto discard;
79866 }
79867 +
79868 + if (!th->ack)
79869 + goto discard;
79870 +
79871 if (!tcp_validate_incoming(sk, skb, th, 0))
79872 return 0;
79873
79874 /* step 5: check the ACK field */
79875 - if (th->ack) {
79876 + if (true) {
79877 int acceptable = tcp_ack(sk, skb, FLAG_SLOWPATH) > 0;
79878
79879 switch (sk->sk_state) {
79880 @@ -6131,8 +6140,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79881 }
79882 break;
79883 }
79884 - } else
79885 - goto discard;
79886 + }
79887
79888 /* ts_recent update must be made after we are sure that the packet
79889 * is in window.
79890 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
79891 index bc3cb46..815ccd6 100644
79892 --- a/net/ipv4/tcp_ipv4.c
79893 +++ b/net/ipv4/tcp_ipv4.c
79894 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
79895 EXPORT_SYMBOL(sysctl_tcp_low_latency);
79896
79897
79898 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79899 +extern int grsec_enable_blackhole;
79900 +#endif
79901 +
79902 #ifdef CONFIG_TCP_MD5SIG
79903 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
79904 __be32 daddr, __be32 saddr, const struct tcphdr *th);
79905 @@ -1899,6 +1903,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
79906 return 0;
79907
79908 reset:
79909 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79910 + if (!grsec_enable_blackhole)
79911 +#endif
79912 tcp_v4_send_reset(rsk, skb);
79913 discard:
79914 kfree_skb(skb);
79915 @@ -1999,12 +2006,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
79916 TCP_SKB_CB(skb)->sacked = 0;
79917
79918 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
79919 - if (!sk)
79920 + if (!sk) {
79921 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79922 + ret = 1;
79923 +#endif
79924 goto no_tcp_socket;
79925 -
79926 + }
79927 process:
79928 - if (sk->sk_state == TCP_TIME_WAIT)
79929 + if (sk->sk_state == TCP_TIME_WAIT) {
79930 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79931 + ret = 2;
79932 +#endif
79933 goto do_time_wait;
79934 + }
79935
79936 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
79937 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
79938 @@ -2055,6 +2069,10 @@ no_tcp_socket:
79939 bad_packet:
79940 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
79941 } else {
79942 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79943 + if (!grsec_enable_blackhole || (ret == 1 &&
79944 + (skb->dev->flags & IFF_LOOPBACK)))
79945 +#endif
79946 tcp_v4_send_reset(NULL, skb);
79947 }
79948
79949 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
79950 index a7302d9..e3ec754 100644
79951 --- a/net/ipv4/tcp_minisocks.c
79952 +++ b/net/ipv4/tcp_minisocks.c
79953 @@ -27,6 +27,10 @@
79954 #include <net/inet_common.h>
79955 #include <net/xfrm.h>
79956
79957 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79958 +extern int grsec_enable_blackhole;
79959 +#endif
79960 +
79961 int sysctl_tcp_syncookies __read_mostly = 1;
79962 EXPORT_SYMBOL(sysctl_tcp_syncookies);
79963
79964 @@ -742,7 +746,10 @@ embryonic_reset:
79965 * avoid becoming vulnerable to outside attack aiming at
79966 * resetting legit local connections.
79967 */
79968 - req->rsk_ops->send_reset(sk, skb);
79969 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79970 + if (!grsec_enable_blackhole)
79971 +#endif
79972 + req->rsk_ops->send_reset(sk, skb);
79973 } else if (fastopen) { /* received a valid RST pkt */
79974 reqsk_fastopen_remove(sk, req, true);
79975 tcp_reset(sk);
79976 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
79977 index 4526fe6..1a34e43 100644
79978 --- a/net/ipv4/tcp_probe.c
79979 +++ b/net/ipv4/tcp_probe.c
79980 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
79981 if (cnt + width >= len)
79982 break;
79983
79984 - if (copy_to_user(buf + cnt, tbuf, width))
79985 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
79986 return -EFAULT;
79987 cnt += width;
79988 }
79989 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
79990 index d47c1b4..b0584de 100644
79991 --- a/net/ipv4/tcp_timer.c
79992 +++ b/net/ipv4/tcp_timer.c
79993 @@ -22,6 +22,10 @@
79994 #include <linux/gfp.h>
79995 #include <net/tcp.h>
79996
79997 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79998 +extern int grsec_lastack_retries;
79999 +#endif
80000 +
80001 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
80002 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
80003 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
80004 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
80005 }
80006 }
80007
80008 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80009 + if ((sk->sk_state == TCP_LAST_ACK) &&
80010 + (grsec_lastack_retries > 0) &&
80011 + (grsec_lastack_retries < retry_until))
80012 + retry_until = grsec_lastack_retries;
80013 +#endif
80014 +
80015 if (retransmits_timed_out(sk, retry_until,
80016 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
80017 /* Has it gone just too far? */
80018 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
80019 index 79c8dbe..aceb1b6 100644
80020 --- a/net/ipv4/udp.c
80021 +++ b/net/ipv4/udp.c
80022 @@ -87,6 +87,7 @@
80023 #include <linux/types.h>
80024 #include <linux/fcntl.h>
80025 #include <linux/module.h>
80026 +#include <linux/security.h>
80027 #include <linux/socket.h>
80028 #include <linux/sockios.h>
80029 #include <linux/igmp.h>
80030 @@ -111,6 +112,10 @@
80031 #include <trace/events/skb.h>
80032 #include "udp_impl.h"
80033
80034 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80035 +extern int grsec_enable_blackhole;
80036 +#endif
80037 +
80038 struct udp_table udp_table __read_mostly;
80039 EXPORT_SYMBOL(udp_table);
80040
80041 @@ -569,6 +574,9 @@ found:
80042 return s;
80043 }
80044
80045 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
80046 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
80047 +
80048 /*
80049 * This routine is called by the ICMP module when it gets some
80050 * sort of error condition. If err < 0 then the socket should
80051 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
80052 dport = usin->sin_port;
80053 if (dport == 0)
80054 return -EINVAL;
80055 +
80056 + err = gr_search_udp_sendmsg(sk, usin);
80057 + if (err)
80058 + return err;
80059 } else {
80060 if (sk->sk_state != TCP_ESTABLISHED)
80061 return -EDESTADDRREQ;
80062 +
80063 + err = gr_search_udp_sendmsg(sk, NULL);
80064 + if (err)
80065 + return err;
80066 +
80067 daddr = inet->inet_daddr;
80068 dport = inet->inet_dport;
80069 /* Open fast path for connected socket.
80070 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
80071 udp_lib_checksum_complete(skb)) {
80072 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80073 IS_UDPLITE(sk));
80074 - atomic_inc(&sk->sk_drops);
80075 + atomic_inc_unchecked(&sk->sk_drops);
80076 __skb_unlink(skb, rcvq);
80077 __skb_queue_tail(&list_kill, skb);
80078 }
80079 @@ -1194,6 +1211,10 @@ try_again:
80080 if (!skb)
80081 goto out;
80082
80083 + err = gr_search_udp_recvmsg(sk, skb);
80084 + if (err)
80085 + goto out_free;
80086 +
80087 ulen = skb->len - sizeof(struct udphdr);
80088 copied = len;
80089 if (copied > ulen)
80090 @@ -1227,7 +1248,7 @@ try_again:
80091 if (unlikely(err)) {
80092 trace_kfree_skb(skb, udp_recvmsg);
80093 if (!peeked) {
80094 - atomic_inc(&sk->sk_drops);
80095 + atomic_inc_unchecked(&sk->sk_drops);
80096 UDP_INC_STATS_USER(sock_net(sk),
80097 UDP_MIB_INERRORS, is_udplite);
80098 }
80099 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80100
80101 drop:
80102 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
80103 - atomic_inc(&sk->sk_drops);
80104 + atomic_inc_unchecked(&sk->sk_drops);
80105 kfree_skb(skb);
80106 return -1;
80107 }
80108 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
80109 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
80110
80111 if (!skb1) {
80112 - atomic_inc(&sk->sk_drops);
80113 + atomic_inc_unchecked(&sk->sk_drops);
80114 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80115 IS_UDPLITE(sk));
80116 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80117 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80118 goto csum_error;
80119
80120 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80121 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80122 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80123 +#endif
80124 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
80125
80126 /*
80127 @@ -2119,7 +2143,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
80128 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
80129 0, sock_i_ino(sp),
80130 atomic_read(&sp->sk_refcnt), sp,
80131 - atomic_read(&sp->sk_drops), len);
80132 + atomic_read_unchecked(&sp->sk_drops), len);
80133 }
80134
80135 int udp4_seq_show(struct seq_file *seq, void *v)
80136 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
80137 index 0424e4e..308dd43 100644
80138 --- a/net/ipv6/addrconf.c
80139 +++ b/net/ipv6/addrconf.c
80140 @@ -2121,7 +2121,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
80141 p.iph.ihl = 5;
80142 p.iph.protocol = IPPROTO_IPV6;
80143 p.iph.ttl = 64;
80144 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
80145 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
80146
80147 if (ops->ndo_do_ioctl) {
80148 mm_segment_t oldfs = get_fs();
80149 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
80150 index d5cb3c4..b3e38d0 100644
80151 --- a/net/ipv6/ip6_gre.c
80152 +++ b/net/ipv6/ip6_gre.c
80153 @@ -1353,7 +1353,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
80154 }
80155
80156
80157 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
80158 +static struct inet6_protocol ip6gre_protocol = {
80159 .handler = ip6gre_rcv,
80160 .err_handler = ip6gre_err,
80161 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
80162 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
80163 index e02faed..9780f28 100644
80164 --- a/net/ipv6/ipv6_sockglue.c
80165 +++ b/net/ipv6/ipv6_sockglue.c
80166 @@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
80167 if (sk->sk_type != SOCK_STREAM)
80168 return -ENOPROTOOPT;
80169
80170 - msg.msg_control = optval;
80171 + msg.msg_control = (void __force_kernel *)optval;
80172 msg.msg_controllen = len;
80173 msg.msg_flags = flags;
80174
80175 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
80176 index d7cb045..8c0ded6 100644
80177 --- a/net/ipv6/netfilter/ip6_tables.c
80178 +++ b/net/ipv6/netfilter/ip6_tables.c
80179 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
80180 #endif
80181
80182 static int get_info(struct net *net, void __user *user,
80183 - const int *len, int compat)
80184 + int len, int compat)
80185 {
80186 char name[XT_TABLE_MAXNAMELEN];
80187 struct xt_table *t;
80188 int ret;
80189
80190 - if (*len != sizeof(struct ip6t_getinfo)) {
80191 - duprintf("length %u != %zu\n", *len,
80192 + if (len != sizeof(struct ip6t_getinfo)) {
80193 + duprintf("length %u != %zu\n", len,
80194 sizeof(struct ip6t_getinfo));
80195 return -EINVAL;
80196 }
80197 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
80198 info.size = private->size;
80199 strcpy(info.name, name);
80200
80201 - if (copy_to_user(user, &info, *len) != 0)
80202 + if (copy_to_user(user, &info, len) != 0)
80203 ret = -EFAULT;
80204 else
80205 ret = 0;
80206 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80207
80208 switch (cmd) {
80209 case IP6T_SO_GET_INFO:
80210 - ret = get_info(sock_net(sk), user, len, 1);
80211 + ret = get_info(sock_net(sk), user, *len, 1);
80212 break;
80213 case IP6T_SO_GET_ENTRIES:
80214 ret = compat_get_entries(sock_net(sk), user, len);
80215 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80216
80217 switch (cmd) {
80218 case IP6T_SO_GET_INFO:
80219 - ret = get_info(sock_net(sk), user, len, 0);
80220 + ret = get_info(sock_net(sk), user, *len, 0);
80221 break;
80222
80223 case IP6T_SO_GET_ENTRIES:
80224 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
80225 index d8e95c7..81422bc 100644
80226 --- a/net/ipv6/raw.c
80227 +++ b/net/ipv6/raw.c
80228 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
80229 {
80230 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
80231 skb_checksum_complete(skb)) {
80232 - atomic_inc(&sk->sk_drops);
80233 + atomic_inc_unchecked(&sk->sk_drops);
80234 kfree_skb(skb);
80235 return NET_RX_DROP;
80236 }
80237 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80238 struct raw6_sock *rp = raw6_sk(sk);
80239
80240 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
80241 - atomic_inc(&sk->sk_drops);
80242 + atomic_inc_unchecked(&sk->sk_drops);
80243 kfree_skb(skb);
80244 return NET_RX_DROP;
80245 }
80246 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80247
80248 if (inet->hdrincl) {
80249 if (skb_checksum_complete(skb)) {
80250 - atomic_inc(&sk->sk_drops);
80251 + atomic_inc_unchecked(&sk->sk_drops);
80252 kfree_skb(skb);
80253 return NET_RX_DROP;
80254 }
80255 @@ -604,7 +604,7 @@ out:
80256 return err;
80257 }
80258
80259 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
80260 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
80261 struct flowi6 *fl6, struct dst_entry **dstp,
80262 unsigned int flags)
80263 {
80264 @@ -916,12 +916,15 @@ do_confirm:
80265 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
80266 char __user *optval, int optlen)
80267 {
80268 + struct icmp6_filter filter;
80269 +
80270 switch (optname) {
80271 case ICMPV6_FILTER:
80272 if (optlen > sizeof(struct icmp6_filter))
80273 optlen = sizeof(struct icmp6_filter);
80274 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
80275 + if (copy_from_user(&filter, optval, optlen))
80276 return -EFAULT;
80277 + raw6_sk(sk)->filter = filter;
80278 return 0;
80279 default:
80280 return -ENOPROTOOPT;
80281 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80282 char __user *optval, int __user *optlen)
80283 {
80284 int len;
80285 + struct icmp6_filter filter;
80286
80287 switch (optname) {
80288 case ICMPV6_FILTER:
80289 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80290 len = sizeof(struct icmp6_filter);
80291 if (put_user(len, optlen))
80292 return -EFAULT;
80293 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
80294 + filter = raw6_sk(sk)->filter;
80295 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
80296 return -EFAULT;
80297 return 0;
80298 default:
80299 @@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80300 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
80301 0,
80302 sock_i_ino(sp),
80303 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80304 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
80305 }
80306
80307 static int raw6_seq_show(struct seq_file *seq, void *v)
80308 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
80309 index 73f2a6b..f8049a1 100644
80310 --- a/net/ipv6/tcp_ipv6.c
80311 +++ b/net/ipv6/tcp_ipv6.c
80312 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
80313 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
80314 }
80315
80316 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80317 +extern int grsec_enable_blackhole;
80318 +#endif
80319 +
80320 static void tcp_v6_hash(struct sock *sk)
80321 {
80322 if (sk->sk_state != TCP_CLOSE) {
80323 @@ -1525,6 +1529,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
80324 return 0;
80325
80326 reset:
80327 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80328 + if (!grsec_enable_blackhole)
80329 +#endif
80330 tcp_v6_send_reset(sk, skb);
80331 discard:
80332 if (opt_skb)
80333 @@ -1606,12 +1613,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
80334 TCP_SKB_CB(skb)->sacked = 0;
80335
80336 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80337 - if (!sk)
80338 + if (!sk) {
80339 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80340 + ret = 1;
80341 +#endif
80342 goto no_tcp_socket;
80343 + }
80344
80345 process:
80346 - if (sk->sk_state == TCP_TIME_WAIT)
80347 + if (sk->sk_state == TCP_TIME_WAIT) {
80348 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80349 + ret = 2;
80350 +#endif
80351 goto do_time_wait;
80352 + }
80353
80354 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
80355 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
80356 @@ -1660,6 +1675,10 @@ no_tcp_socket:
80357 bad_packet:
80358 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80359 } else {
80360 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80361 + if (!grsec_enable_blackhole || (ret == 1 &&
80362 + (skb->dev->flags & IFF_LOOPBACK)))
80363 +#endif
80364 tcp_v6_send_reset(NULL, skb);
80365 }
80366
80367 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
80368 index fc99972..69397e8 100644
80369 --- a/net/ipv6/udp.c
80370 +++ b/net/ipv6/udp.c
80371 @@ -51,6 +51,10 @@
80372 #include <trace/events/skb.h>
80373 #include "udp_impl.h"
80374
80375 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80376 +extern int grsec_enable_blackhole;
80377 +#endif
80378 +
80379 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
80380 {
80381 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
80382 @@ -395,7 +399,7 @@ try_again:
80383 if (unlikely(err)) {
80384 trace_kfree_skb(skb, udpv6_recvmsg);
80385 if (!peeked) {
80386 - atomic_inc(&sk->sk_drops);
80387 + atomic_inc_unchecked(&sk->sk_drops);
80388 if (is_udp4)
80389 UDP_INC_STATS_USER(sock_net(sk),
80390 UDP_MIB_INERRORS,
80391 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80392 return rc;
80393 drop:
80394 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
80395 - atomic_inc(&sk->sk_drops);
80396 + atomic_inc_unchecked(&sk->sk_drops);
80397 kfree_skb(skb);
80398 return -1;
80399 }
80400 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
80401 if (likely(skb1 == NULL))
80402 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
80403 if (!skb1) {
80404 - atomic_inc(&sk->sk_drops);
80405 + atomic_inc_unchecked(&sk->sk_drops);
80406 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80407 IS_UDPLITE(sk));
80408 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80409 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80410 goto discard;
80411
80412 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80413 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80414 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80415 +#endif
80416 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
80417
80418 kfree_skb(skb);
80419 @@ -1473,7 +1480,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
80420 0,
80421 sock_i_ino(sp),
80422 atomic_read(&sp->sk_refcnt), sp,
80423 - atomic_read(&sp->sk_drops));
80424 + atomic_read_unchecked(&sp->sk_drops));
80425 }
80426
80427 int udp6_seq_show(struct seq_file *seq, void *v)
80428 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
80429 index 496ce2c..f79fac8 100644
80430 --- a/net/irda/ircomm/ircomm_tty.c
80431 +++ b/net/irda/ircomm/ircomm_tty.c
80432 @@ -311,12 +311,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80433 add_wait_queue(&port->open_wait, &wait);
80434
80435 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
80436 - __FILE__, __LINE__, tty->driver->name, port->count);
80437 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80438
80439 spin_lock_irqsave(&port->lock, flags);
80440 if (!tty_hung_up_p(filp)) {
80441 extra_count = 1;
80442 - port->count--;
80443 + atomic_dec(&port->count);
80444 }
80445 spin_unlock_irqrestore(&port->lock, flags);
80446 port->blocked_open++;
80447 @@ -352,7 +352,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80448 }
80449
80450 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
80451 - __FILE__, __LINE__, tty->driver->name, port->count);
80452 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80453
80454 schedule();
80455 }
80456 @@ -363,13 +363,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80457 if (extra_count) {
80458 /* ++ is not atomic, so this should be protected - Jean II */
80459 spin_lock_irqsave(&port->lock, flags);
80460 - port->count++;
80461 + atomic_inc(&port->count);
80462 spin_unlock_irqrestore(&port->lock, flags);
80463 }
80464 port->blocked_open--;
80465
80466 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
80467 - __FILE__, __LINE__, tty->driver->name, port->count);
80468 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80469
80470 if (!retval)
80471 port->flags |= ASYNC_NORMAL_ACTIVE;
80472 @@ -443,12 +443,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
80473
80474 /* ++ is not atomic, so this should be protected - Jean II */
80475 spin_lock_irqsave(&self->port.lock, flags);
80476 - self->port.count++;
80477 + atomic_inc(&self->port.count);
80478 spin_unlock_irqrestore(&self->port.lock, flags);
80479 tty_port_tty_set(&self->port, tty);
80480
80481 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
80482 - self->line, self->port.count);
80483 + self->line, atomic_read(&self->port.count));
80484
80485 /* Not really used by us, but lets do it anyway */
80486 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
80487 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
80488 tty_kref_put(port->tty);
80489 }
80490 port->tty = NULL;
80491 - port->count = 0;
80492 + atomic_set(&port->count, 0);
80493 spin_unlock_irqrestore(&port->lock, flags);
80494
80495 wake_up_interruptible(&port->open_wait);
80496 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
80497 seq_putc(m, '\n');
80498
80499 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
80500 - seq_printf(m, "Open count: %d\n", self->port.count);
80501 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
80502 seq_printf(m, "Max data size: %d\n", self->max_data_size);
80503 seq_printf(m, "Max header size: %d\n", self->max_header_size);
80504
80505 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
80506 index cd6f7a9..e63fe89 100644
80507 --- a/net/iucv/af_iucv.c
80508 +++ b/net/iucv/af_iucv.c
80509 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
80510
80511 write_lock_bh(&iucv_sk_list.lock);
80512
80513 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
80514 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80515 while (__iucv_get_sock_by_name(name)) {
80516 sprintf(name, "%08x",
80517 - atomic_inc_return(&iucv_sk_list.autobind_name));
80518 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80519 }
80520
80521 write_unlock_bh(&iucv_sk_list.lock);
80522 diff --git a/net/key/af_key.c b/net/key/af_key.c
80523 index 08897a3..0b812ab 100644
80524 --- a/net/key/af_key.c
80525 +++ b/net/key/af_key.c
80526 @@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
80527 static u32 get_acqseq(void)
80528 {
80529 u32 res;
80530 - static atomic_t acqseq;
80531 + static atomic_unchecked_t acqseq;
80532
80533 do {
80534 - res = atomic_inc_return(&acqseq);
80535 + res = atomic_inc_return_unchecked(&acqseq);
80536 } while (!res);
80537 return res;
80538 }
80539 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
80540 index 494da7f..6ce2ffd 100644
80541 --- a/net/mac80211/cfg.c
80542 +++ b/net/mac80211/cfg.c
80543 @@ -2604,7 +2604,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
80544 else
80545 local->probe_req_reg--;
80546
80547 - if (!local->open_count)
80548 + if (!local_read(&local->open_count))
80549 break;
80550
80551 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
80552 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
80553 index 493e2e8..be76574 100644
80554 --- a/net/mac80211/ieee80211_i.h
80555 +++ b/net/mac80211/ieee80211_i.h
80556 @@ -28,6 +28,7 @@
80557 #include <net/ieee80211_radiotap.h>
80558 #include <net/cfg80211.h>
80559 #include <net/mac80211.h>
80560 +#include <asm/local.h>
80561 #include "key.h"
80562 #include "sta_info.h"
80563 #include "debug.h"
80564 @@ -852,7 +853,7 @@ struct ieee80211_local {
80565 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
80566 spinlock_t queue_stop_reason_lock;
80567
80568 - int open_count;
80569 + local_t open_count;
80570 int monitors, cooked_mntrs;
80571 /* number of interfaces with corresponding FIF_ flags */
80572 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
80573 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
80574 index 0f5af91..4dba9e7 100644
80575 --- a/net/mac80211/iface.c
80576 +++ b/net/mac80211/iface.c
80577 @@ -465,7 +465,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80578 break;
80579 }
80580
80581 - if (local->open_count == 0) {
80582 + if (local_read(&local->open_count) == 0) {
80583 res = drv_start(local);
80584 if (res)
80585 goto err_del_bss;
80586 @@ -508,7 +508,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80587 break;
80588 }
80589
80590 - if (local->monitors == 0 && local->open_count == 0) {
80591 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
80592 res = ieee80211_add_virtual_monitor(local);
80593 if (res)
80594 goto err_stop;
80595 @@ -616,7 +616,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80596 mutex_unlock(&local->mtx);
80597
80598 if (coming_up)
80599 - local->open_count++;
80600 + local_inc(&local->open_count);
80601
80602 if (hw_reconf_flags)
80603 ieee80211_hw_config(local, hw_reconf_flags);
80604 @@ -630,7 +630,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80605 err_del_interface:
80606 drv_remove_interface(local, sdata);
80607 err_stop:
80608 - if (!local->open_count)
80609 + if (!local_read(&local->open_count))
80610 drv_stop(local);
80611 err_del_bss:
80612 sdata->bss = NULL;
80613 @@ -762,7 +762,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80614 }
80615
80616 if (going_down)
80617 - local->open_count--;
80618 + local_dec(&local->open_count);
80619
80620 switch (sdata->vif.type) {
80621 case NL80211_IFTYPE_AP_VLAN:
80622 @@ -818,7 +818,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80623
80624 ieee80211_recalc_ps(local, -1);
80625
80626 - if (local->open_count == 0) {
80627 + if (local_read(&local->open_count) == 0) {
80628 if (local->ops->napi_poll)
80629 napi_disable(&local->napi);
80630 ieee80211_clear_tx_pending(local);
80631 @@ -850,7 +850,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80632 }
80633 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
80634
80635 - if (local->monitors == local->open_count && local->monitors > 0)
80636 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
80637 ieee80211_add_virtual_monitor(local);
80638 }
80639
80640 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
80641 index f57f597..e0a7c03 100644
80642 --- a/net/mac80211/main.c
80643 +++ b/net/mac80211/main.c
80644 @@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
80645 local->hw.conf.power_level = power;
80646 }
80647
80648 - if (changed && local->open_count) {
80649 + if (changed && local_read(&local->open_count)) {
80650 ret = drv_config(local, changed);
80651 /*
80652 * Goal:
80653 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
80654 index 5c572e7..ecf75ce 100644
80655 --- a/net/mac80211/pm.c
80656 +++ b/net/mac80211/pm.c
80657 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80658 struct ieee80211_sub_if_data *sdata;
80659 struct sta_info *sta;
80660
80661 - if (!local->open_count)
80662 + if (!local_read(&local->open_count))
80663 goto suspend;
80664
80665 ieee80211_scan_cancel(local);
80666 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80667 cancel_work_sync(&local->dynamic_ps_enable_work);
80668 del_timer_sync(&local->dynamic_ps_timer);
80669
80670 - local->wowlan = wowlan && local->open_count;
80671 + local->wowlan = wowlan && local_read(&local->open_count);
80672 if (local->wowlan) {
80673 int err = drv_suspend(local, wowlan);
80674 if (err < 0) {
80675 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80676 drv_remove_interface(local, sdata);
80677
80678 /* stop hardware - this must stop RX */
80679 - if (local->open_count)
80680 + if (local_read(&local->open_count))
80681 ieee80211_stop_device(local);
80682
80683 suspend:
80684 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
80685 index 3313c11..bec9f17 100644
80686 --- a/net/mac80211/rate.c
80687 +++ b/net/mac80211/rate.c
80688 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
80689
80690 ASSERT_RTNL();
80691
80692 - if (local->open_count)
80693 + if (local_read(&local->open_count))
80694 return -EBUSY;
80695
80696 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
80697 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
80698 index c97a065..ff61928 100644
80699 --- a/net/mac80211/rc80211_pid_debugfs.c
80700 +++ b/net/mac80211/rc80211_pid_debugfs.c
80701 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
80702
80703 spin_unlock_irqrestore(&events->lock, status);
80704
80705 - if (copy_to_user(buf, pb, p))
80706 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
80707 return -EFAULT;
80708
80709 return p;
80710 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
80711 index 0151ae3..26709d3 100644
80712 --- a/net/mac80211/util.c
80713 +++ b/net/mac80211/util.c
80714 @@ -1332,7 +1332,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
80715 }
80716 #endif
80717 /* everything else happens only if HW was up & running */
80718 - if (!local->open_count)
80719 + if (!local_read(&local->open_count))
80720 goto wake_up;
80721
80722 /*
80723 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
80724 index 49e96df..63a51c3 100644
80725 --- a/net/netfilter/Kconfig
80726 +++ b/net/netfilter/Kconfig
80727 @@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
80728
80729 To compile it as a module, choose M here. If unsure, say N.
80730
80731 +config NETFILTER_XT_MATCH_GRADM
80732 + tristate '"gradm" match support'
80733 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
80734 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
80735 + ---help---
80736 + The gradm match allows to match on grsecurity RBAC being enabled.
80737 + It is useful when iptables rules are applied early on bootup to
80738 + prevent connections to the machine (except from a trusted host)
80739 + while the RBAC system is disabled.
80740 +
80741 config NETFILTER_XT_MATCH_HASHLIMIT
80742 tristate '"hashlimit" match support'
80743 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
80744 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
80745 index 3259697..54d5393 100644
80746 --- a/net/netfilter/Makefile
80747 +++ b/net/netfilter/Makefile
80748 @@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
80749 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
80750 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
80751 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
80752 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
80753 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
80754 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
80755 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
80756 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
80757 index 1548df9..98ad9b4 100644
80758 --- a/net/netfilter/ipvs/ip_vs_conn.c
80759 +++ b/net/netfilter/ipvs/ip_vs_conn.c
80760 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
80761 /* Increase the refcnt counter of the dest */
80762 atomic_inc(&dest->refcnt);
80763
80764 - conn_flags = atomic_read(&dest->conn_flags);
80765 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
80766 if (cp->protocol != IPPROTO_UDP)
80767 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
80768 flags = cp->flags;
80769 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
80770 atomic_set(&cp->refcnt, 1);
80771
80772 atomic_set(&cp->n_control, 0);
80773 - atomic_set(&cp->in_pkts, 0);
80774 + atomic_set_unchecked(&cp->in_pkts, 0);
80775
80776 atomic_inc(&ipvs->conn_count);
80777 if (flags & IP_VS_CONN_F_NO_CPORT)
80778 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
80779
80780 /* Don't drop the entry if its number of incoming packets is not
80781 located in [0, 8] */
80782 - i = atomic_read(&cp->in_pkts);
80783 + i = atomic_read_unchecked(&cp->in_pkts);
80784 if (i > 8 || i < 0) return 0;
80785
80786 if (!todrop_rate[i]) return 0;
80787 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
80788 index 58918e2..4d177a9 100644
80789 --- a/net/netfilter/ipvs/ip_vs_core.c
80790 +++ b/net/netfilter/ipvs/ip_vs_core.c
80791 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
80792 ret = cp->packet_xmit(skb, cp, pd->pp);
80793 /* do not touch skb anymore */
80794
80795 - atomic_inc(&cp->in_pkts);
80796 + atomic_inc_unchecked(&cp->in_pkts);
80797 ip_vs_conn_put(cp);
80798 return ret;
80799 }
80800 @@ -1681,7 +1681,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
80801 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
80802 pkts = sysctl_sync_threshold(ipvs);
80803 else
80804 - pkts = atomic_add_return(1, &cp->in_pkts);
80805 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80806
80807 if (ipvs->sync_state & IP_VS_STATE_MASTER)
80808 ip_vs_sync_conn(net, cp, pkts);
80809 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
80810 index c4ee437..a774a74 100644
80811 --- a/net/netfilter/ipvs/ip_vs_ctl.c
80812 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
80813 @@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
80814 ip_vs_rs_hash(ipvs, dest);
80815 write_unlock_bh(&ipvs->rs_lock);
80816 }
80817 - atomic_set(&dest->conn_flags, conn_flags);
80818 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
80819
80820 /* bind the service */
80821 if (!dest->svc) {
80822 @@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
80823 " %-7s %-6d %-10d %-10d\n",
80824 &dest->addr.in6,
80825 ntohs(dest->port),
80826 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
80827 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
80828 atomic_read(&dest->weight),
80829 atomic_read(&dest->activeconns),
80830 atomic_read(&dest->inactconns));
80831 @@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
80832 "%-7s %-6d %-10d %-10d\n",
80833 ntohl(dest->addr.ip),
80834 ntohs(dest->port),
80835 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
80836 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
80837 atomic_read(&dest->weight),
80838 atomic_read(&dest->activeconns),
80839 atomic_read(&dest->inactconns));
80840 @@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
80841
80842 entry.addr = dest->addr.ip;
80843 entry.port = dest->port;
80844 - entry.conn_flags = atomic_read(&dest->conn_flags);
80845 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
80846 entry.weight = atomic_read(&dest->weight);
80847 entry.u_threshold = dest->u_threshold;
80848 entry.l_threshold = dest->l_threshold;
80849 @@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
80850 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
80851 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
80852 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
80853 - (atomic_read(&dest->conn_flags) &
80854 + (atomic_read_unchecked(&dest->conn_flags) &
80855 IP_VS_CONN_F_FWD_MASK)) ||
80856 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
80857 atomic_read(&dest->weight)) ||
80858 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
80859 index effa10c..9058928 100644
80860 --- a/net/netfilter/ipvs/ip_vs_sync.c
80861 +++ b/net/netfilter/ipvs/ip_vs_sync.c
80862 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
80863 cp = cp->control;
80864 if (cp) {
80865 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
80866 - pkts = atomic_add_return(1, &cp->in_pkts);
80867 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80868 else
80869 pkts = sysctl_sync_threshold(ipvs);
80870 ip_vs_sync_conn(net, cp->control, pkts);
80871 @@ -758,7 +758,7 @@ control:
80872 if (!cp)
80873 return;
80874 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
80875 - pkts = atomic_add_return(1, &cp->in_pkts);
80876 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80877 else
80878 pkts = sysctl_sync_threshold(ipvs);
80879 goto sloop;
80880 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
80881
80882 if (opt)
80883 memcpy(&cp->in_seq, opt, sizeof(*opt));
80884 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
80885 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
80886 cp->state = state;
80887 cp->old_state = cp->state;
80888 /*
80889 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
80890 index cc4c809..50f8fe5 100644
80891 --- a/net/netfilter/ipvs/ip_vs_xmit.c
80892 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
80893 @@ -1202,7 +1202,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
80894 else
80895 rc = NF_ACCEPT;
80896 /* do not touch skb anymore */
80897 - atomic_inc(&cp->in_pkts);
80898 + atomic_inc_unchecked(&cp->in_pkts);
80899 goto out;
80900 }
80901
80902 @@ -1323,7 +1323,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
80903 else
80904 rc = NF_ACCEPT;
80905 /* do not touch skb anymore */
80906 - atomic_inc(&cp->in_pkts);
80907 + atomic_inc_unchecked(&cp->in_pkts);
80908 goto out;
80909 }
80910
80911 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
80912 index ec02168..f0caab6 100644
80913 --- a/net/netfilter/nf_conntrack_core.c
80914 +++ b/net/netfilter/nf_conntrack_core.c
80915 @@ -1533,6 +1533,10 @@ err_extend:
80916 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
80917 #define DYING_NULLS_VAL ((1<<30)+1)
80918
80919 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80920 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
80921 +#endif
80922 +
80923 static int nf_conntrack_init_net(struct net *net)
80924 {
80925 int ret;
80926 @@ -1546,7 +1550,11 @@ static int nf_conntrack_init_net(struct net *net)
80927 goto err_stat;
80928 }
80929
80930 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80931 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
80932 +#else
80933 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
80934 +#endif
80935 if (!net->ct.slabname) {
80936 ret = -ENOMEM;
80937 goto err_slabname;
80938 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
80939 index 92fd8ec..3f6ea4b 100644
80940 --- a/net/netfilter/nfnetlink_log.c
80941 +++ b/net/netfilter/nfnetlink_log.c
80942 @@ -72,7 +72,7 @@ struct nfulnl_instance {
80943 };
80944
80945 static DEFINE_SPINLOCK(instances_lock);
80946 -static atomic_t global_seq;
80947 +static atomic_unchecked_t global_seq;
80948
80949 #define INSTANCE_BUCKETS 16
80950 static struct hlist_head instance_table[INSTANCE_BUCKETS];
80951 @@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
80952 /* global sequence number */
80953 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
80954 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
80955 - htonl(atomic_inc_return(&global_seq))))
80956 + htonl(atomic_inc_return_unchecked(&global_seq))))
80957 goto nla_put_failure;
80958
80959 if (data_len) {
80960 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
80961 new file mode 100644
80962 index 0000000..c566332
80963 --- /dev/null
80964 +++ b/net/netfilter/xt_gradm.c
80965 @@ -0,0 +1,51 @@
80966 +/*
80967 + * gradm match for netfilter
80968 + * Copyright © Zbigniew Krzystolik, 2010
80969 + *
80970 + * This program is free software; you can redistribute it and/or modify
80971 + * it under the terms of the GNU General Public License; either version
80972 + * 2 or 3 as published by the Free Software Foundation.
80973 + */
80974 +#include <linux/module.h>
80975 +#include <linux/moduleparam.h>
80976 +#include <linux/skbuff.h>
80977 +#include <linux/netfilter/x_tables.h>
80978 +#include <linux/grsecurity.h>
80979 +#include <linux/netfilter/xt_gradm.h>
80980 +
80981 +static bool
80982 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
80983 +{
80984 + const struct xt_gradm_mtinfo *info = par->matchinfo;
80985 + bool retval = false;
80986 + if (gr_acl_is_enabled())
80987 + retval = true;
80988 + return retval ^ info->invflags;
80989 +}
80990 +
80991 +static struct xt_match gradm_mt_reg __read_mostly = {
80992 + .name = "gradm",
80993 + .revision = 0,
80994 + .family = NFPROTO_UNSPEC,
80995 + .match = gradm_mt,
80996 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
80997 + .me = THIS_MODULE,
80998 +};
80999 +
81000 +static int __init gradm_mt_init(void)
81001 +{
81002 + return xt_register_match(&gradm_mt_reg);
81003 +}
81004 +
81005 +static void __exit gradm_mt_exit(void)
81006 +{
81007 + xt_unregister_match(&gradm_mt_reg);
81008 +}
81009 +
81010 +module_init(gradm_mt_init);
81011 +module_exit(gradm_mt_exit);
81012 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
81013 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
81014 +MODULE_LICENSE("GPL");
81015 +MODULE_ALIAS("ipt_gradm");
81016 +MODULE_ALIAS("ip6t_gradm");
81017 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
81018 index 4fe4fb4..87a89e5 100644
81019 --- a/net/netfilter/xt_statistic.c
81020 +++ b/net/netfilter/xt_statistic.c
81021 @@ -19,7 +19,7 @@
81022 #include <linux/module.h>
81023
81024 struct xt_statistic_priv {
81025 - atomic_t count;
81026 + atomic_unchecked_t count;
81027 } ____cacheline_aligned_in_smp;
81028
81029 MODULE_LICENSE("GPL");
81030 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
81031 break;
81032 case XT_STATISTIC_MODE_NTH:
81033 do {
81034 - oval = atomic_read(&info->master->count);
81035 + oval = atomic_read_unchecked(&info->master->count);
81036 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
81037 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
81038 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
81039 if (nval == 0)
81040 ret = !ret;
81041 break;
81042 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
81043 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
81044 if (info->master == NULL)
81045 return -ENOMEM;
81046 - atomic_set(&info->master->count, info->u.nth.count);
81047 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
81048
81049 return 0;
81050 }
81051 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
81052 index 4da797f..eb1df70 100644
81053 --- a/net/netlink/af_netlink.c
81054 +++ b/net/netlink/af_netlink.c
81055 @@ -782,7 +782,7 @@ static void netlink_overrun(struct sock *sk)
81056 sk->sk_error_report(sk);
81057 }
81058 }
81059 - atomic_inc(&sk->sk_drops);
81060 + atomic_inc_unchecked(&sk->sk_drops);
81061 }
81062
81063 static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
81064 @@ -2068,7 +2068,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
81065 sk_wmem_alloc_get(s),
81066 nlk->cb,
81067 atomic_read(&s->sk_refcnt),
81068 - atomic_read(&s->sk_drops),
81069 + atomic_read_unchecked(&s->sk_drops),
81070 sock_i_ino(s)
81071 );
81072
81073 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
81074 index 7261eb8..44e8ac6 100644
81075 --- a/net/netrom/af_netrom.c
81076 +++ b/net/netrom/af_netrom.c
81077 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
81078 struct sock *sk = sock->sk;
81079 struct nr_sock *nr = nr_sk(sk);
81080
81081 + memset(sax, 0, sizeof(*sax));
81082 lock_sock(sk);
81083 if (peer != 0) {
81084 if (sk->sk_state != TCP_ESTABLISHED) {
81085 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
81086 *uaddr_len = sizeof(struct full_sockaddr_ax25);
81087 } else {
81088 sax->fsa_ax25.sax25_family = AF_NETROM;
81089 - sax->fsa_ax25.sax25_ndigis = 0;
81090 sax->fsa_ax25.sax25_call = nr->source_addr;
81091 *uaddr_len = sizeof(struct sockaddr_ax25);
81092 }
81093 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
81094 index 94060ed..9c066f3 100644
81095 --- a/net/packet/af_packet.c
81096 +++ b/net/packet/af_packet.c
81097 @@ -1578,7 +1578,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
81098
81099 spin_lock(&sk->sk_receive_queue.lock);
81100 po->stats.tp_packets++;
81101 - skb->dropcount = atomic_read(&sk->sk_drops);
81102 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
81103 __skb_queue_tail(&sk->sk_receive_queue, skb);
81104 spin_unlock(&sk->sk_receive_queue.lock);
81105 sk->sk_data_ready(sk, skb->len);
81106 @@ -1587,7 +1587,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
81107 drop_n_acct:
81108 spin_lock(&sk->sk_receive_queue.lock);
81109 po->stats.tp_drops++;
81110 - atomic_inc(&sk->sk_drops);
81111 + atomic_inc_unchecked(&sk->sk_drops);
81112 spin_unlock(&sk->sk_receive_queue.lock);
81113
81114 drop_n_restore:
81115 @@ -2537,6 +2537,7 @@ out:
81116
81117 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
81118 {
81119 + struct sock_extended_err ee;
81120 struct sock_exterr_skb *serr;
81121 struct sk_buff *skb, *skb2;
81122 int copied, err;
81123 @@ -2558,8 +2559,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
81124 sock_recv_timestamp(msg, sk, skb);
81125
81126 serr = SKB_EXT_ERR(skb);
81127 + ee = serr->ee;
81128 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
81129 - sizeof(serr->ee), &serr->ee);
81130 + sizeof ee, &ee);
81131
81132 msg->msg_flags |= MSG_ERRQUEUE;
81133 err = copied;
81134 @@ -3171,7 +3173,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
81135 case PACKET_HDRLEN:
81136 if (len > sizeof(int))
81137 len = sizeof(int);
81138 - if (copy_from_user(&val, optval, len))
81139 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
81140 return -EFAULT;
81141 switch (val) {
81142 case TPACKET_V1:
81143 @@ -3210,7 +3212,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
81144 len = lv;
81145 if (put_user(len, optlen))
81146 return -EFAULT;
81147 - if (copy_to_user(optval, data, len))
81148 + if (len > sizeof(st) || copy_to_user(optval, data, len))
81149 return -EFAULT;
81150 return 0;
81151 }
81152 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
81153 index 5a940db..f0b9c12 100644
81154 --- a/net/phonet/af_phonet.c
81155 +++ b/net/phonet/af_phonet.c
81156 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
81157 {
81158 struct phonet_protocol *pp;
81159
81160 - if (protocol >= PHONET_NPROTO)
81161 + if (protocol < 0 || protocol >= PHONET_NPROTO)
81162 return NULL;
81163
81164 rcu_read_lock();
81165 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
81166 {
81167 int err = 0;
81168
81169 - if (protocol >= PHONET_NPROTO)
81170 + if (protocol < 0 || protocol >= PHONET_NPROTO)
81171 return -EINVAL;
81172
81173 err = proto_register(pp->prot, 1);
81174 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
81175 index 576f22c..bc7a71b 100644
81176 --- a/net/phonet/pep.c
81177 +++ b/net/phonet/pep.c
81178 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
81179
81180 case PNS_PEP_CTRL_REQ:
81181 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
81182 - atomic_inc(&sk->sk_drops);
81183 + atomic_inc_unchecked(&sk->sk_drops);
81184 break;
81185 }
81186 __skb_pull(skb, 4);
81187 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
81188 }
81189
81190 if (pn->rx_credits == 0) {
81191 - atomic_inc(&sk->sk_drops);
81192 + atomic_inc_unchecked(&sk->sk_drops);
81193 err = -ENOBUFS;
81194 break;
81195 }
81196 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
81197 }
81198
81199 if (pn->rx_credits == 0) {
81200 - atomic_inc(&sk->sk_drops);
81201 + atomic_inc_unchecked(&sk->sk_drops);
81202 err = NET_RX_DROP;
81203 break;
81204 }
81205 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
81206 index b7e9827..c264c85 100644
81207 --- a/net/phonet/socket.c
81208 +++ b/net/phonet/socket.c
81209 @@ -615,7 +615,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
81210 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
81211 sock_i_ino(sk),
81212 atomic_read(&sk->sk_refcnt), sk,
81213 - atomic_read(&sk->sk_drops), &len);
81214 + atomic_read_unchecked(&sk->sk_drops), &len);
81215 }
81216 seq_printf(seq, "%*s\n", 127 - len, "");
81217 return 0;
81218 diff --git a/net/rds/cong.c b/net/rds/cong.c
81219 index e5b65ac..f3b6fb7 100644
81220 --- a/net/rds/cong.c
81221 +++ b/net/rds/cong.c
81222 @@ -78,7 +78,7 @@
81223 * finds that the saved generation number is smaller than the global generation
81224 * number, it wakes up the process.
81225 */
81226 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
81227 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
81228
81229 /*
81230 * Congestion monitoring
81231 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
81232 rdsdebug("waking map %p for %pI4\n",
81233 map, &map->m_addr);
81234 rds_stats_inc(s_cong_update_received);
81235 - atomic_inc(&rds_cong_generation);
81236 + atomic_inc_unchecked(&rds_cong_generation);
81237 if (waitqueue_active(&map->m_waitq))
81238 wake_up(&map->m_waitq);
81239 if (waitqueue_active(&rds_poll_waitq))
81240 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
81241
81242 int rds_cong_updated_since(unsigned long *recent)
81243 {
81244 - unsigned long gen = atomic_read(&rds_cong_generation);
81245 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
81246
81247 if (likely(*recent == gen))
81248 return 0;
81249 diff --git a/net/rds/ib.h b/net/rds/ib.h
81250 index 8d2b3d5..227ec5b 100644
81251 --- a/net/rds/ib.h
81252 +++ b/net/rds/ib.h
81253 @@ -128,7 +128,7 @@ struct rds_ib_connection {
81254 /* sending acks */
81255 unsigned long i_ack_flags;
81256 #ifdef KERNEL_HAS_ATOMIC64
81257 - atomic64_t i_ack_next; /* next ACK to send */
81258 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
81259 #else
81260 spinlock_t i_ack_lock; /* protect i_ack_next */
81261 u64 i_ack_next; /* next ACK to send */
81262 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
81263 index a1e1162..265e129 100644
81264 --- a/net/rds/ib_cm.c
81265 +++ b/net/rds/ib_cm.c
81266 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
81267 /* Clear the ACK state */
81268 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
81269 #ifdef KERNEL_HAS_ATOMIC64
81270 - atomic64_set(&ic->i_ack_next, 0);
81271 + atomic64_set_unchecked(&ic->i_ack_next, 0);
81272 #else
81273 ic->i_ack_next = 0;
81274 #endif
81275 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
81276 index 8d19491..05a3e65 100644
81277 --- a/net/rds/ib_recv.c
81278 +++ b/net/rds/ib_recv.c
81279 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
81280 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
81281 int ack_required)
81282 {
81283 - atomic64_set(&ic->i_ack_next, seq);
81284 + atomic64_set_unchecked(&ic->i_ack_next, seq);
81285 if (ack_required) {
81286 smp_mb__before_clear_bit();
81287 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81288 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
81289 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81290 smp_mb__after_clear_bit();
81291
81292 - return atomic64_read(&ic->i_ack_next);
81293 + return atomic64_read_unchecked(&ic->i_ack_next);
81294 }
81295 #endif
81296
81297 diff --git a/net/rds/iw.h b/net/rds/iw.h
81298 index 04ce3b1..48119a6 100644
81299 --- a/net/rds/iw.h
81300 +++ b/net/rds/iw.h
81301 @@ -134,7 +134,7 @@ struct rds_iw_connection {
81302 /* sending acks */
81303 unsigned long i_ack_flags;
81304 #ifdef KERNEL_HAS_ATOMIC64
81305 - atomic64_t i_ack_next; /* next ACK to send */
81306 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
81307 #else
81308 spinlock_t i_ack_lock; /* protect i_ack_next */
81309 u64 i_ack_next; /* next ACK to send */
81310 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
81311 index a91e1db..cf3053f 100644
81312 --- a/net/rds/iw_cm.c
81313 +++ b/net/rds/iw_cm.c
81314 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
81315 /* Clear the ACK state */
81316 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
81317 #ifdef KERNEL_HAS_ATOMIC64
81318 - atomic64_set(&ic->i_ack_next, 0);
81319 + atomic64_set_unchecked(&ic->i_ack_next, 0);
81320 #else
81321 ic->i_ack_next = 0;
81322 #endif
81323 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
81324 index 4503335..db566b4 100644
81325 --- a/net/rds/iw_recv.c
81326 +++ b/net/rds/iw_recv.c
81327 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
81328 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
81329 int ack_required)
81330 {
81331 - atomic64_set(&ic->i_ack_next, seq);
81332 + atomic64_set_unchecked(&ic->i_ack_next, seq);
81333 if (ack_required) {
81334 smp_mb__before_clear_bit();
81335 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81336 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
81337 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81338 smp_mb__after_clear_bit();
81339
81340 - return atomic64_read(&ic->i_ack_next);
81341 + return atomic64_read_unchecked(&ic->i_ack_next);
81342 }
81343 #endif
81344
81345 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
81346 index edac9ef..16bcb98 100644
81347 --- a/net/rds/tcp.c
81348 +++ b/net/rds/tcp.c
81349 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
81350 int val = 1;
81351
81352 set_fs(KERNEL_DS);
81353 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
81354 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
81355 sizeof(val));
81356 set_fs(oldfs);
81357 }
81358 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
81359 index 81cf5a4..b5826ff 100644
81360 --- a/net/rds/tcp_send.c
81361 +++ b/net/rds/tcp_send.c
81362 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
81363
81364 oldfs = get_fs();
81365 set_fs(KERNEL_DS);
81366 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
81367 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
81368 sizeof(val));
81369 set_fs(oldfs);
81370 }
81371 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
81372 index 05996d0..5a1dfe0 100644
81373 --- a/net/rxrpc/af_rxrpc.c
81374 +++ b/net/rxrpc/af_rxrpc.c
81375 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
81376 __be32 rxrpc_epoch;
81377
81378 /* current debugging ID */
81379 -atomic_t rxrpc_debug_id;
81380 +atomic_unchecked_t rxrpc_debug_id;
81381
81382 /* count of skbs currently in use */
81383 atomic_t rxrpc_n_skbs;
81384 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
81385 index e4d9cbc..b229649 100644
81386 --- a/net/rxrpc/ar-ack.c
81387 +++ b/net/rxrpc/ar-ack.c
81388 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
81389
81390 _enter("{%d,%d,%d,%d},",
81391 call->acks_hard, call->acks_unacked,
81392 - atomic_read(&call->sequence),
81393 + atomic_read_unchecked(&call->sequence),
81394 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
81395
81396 stop = 0;
81397 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
81398
81399 /* each Tx packet has a new serial number */
81400 sp->hdr.serial =
81401 - htonl(atomic_inc_return(&call->conn->serial));
81402 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
81403
81404 hdr = (struct rxrpc_header *) txb->head;
81405 hdr->serial = sp->hdr.serial;
81406 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
81407 */
81408 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
81409 {
81410 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
81411 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
81412 }
81413
81414 /*
81415 @@ -629,7 +629,7 @@ process_further:
81416
81417 latest = ntohl(sp->hdr.serial);
81418 hard = ntohl(ack.firstPacket);
81419 - tx = atomic_read(&call->sequence);
81420 + tx = atomic_read_unchecked(&call->sequence);
81421
81422 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
81423 latest,
81424 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
81425 goto maybe_reschedule;
81426
81427 send_ACK_with_skew:
81428 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
81429 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
81430 ntohl(ack.serial));
81431 send_ACK:
81432 mtu = call->conn->trans->peer->if_mtu;
81433 @@ -1173,7 +1173,7 @@ send_ACK:
81434 ackinfo.rxMTU = htonl(5692);
81435 ackinfo.jumbo_max = htonl(4);
81436
81437 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
81438 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
81439 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
81440 ntohl(hdr.serial),
81441 ntohs(ack.maxSkew),
81442 @@ -1191,7 +1191,7 @@ send_ACK:
81443 send_message:
81444 _debug("send message");
81445
81446 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
81447 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
81448 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
81449 send_message_2:
81450
81451 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
81452 index a3bbb36..3341fb9 100644
81453 --- a/net/rxrpc/ar-call.c
81454 +++ b/net/rxrpc/ar-call.c
81455 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
81456 spin_lock_init(&call->lock);
81457 rwlock_init(&call->state_lock);
81458 atomic_set(&call->usage, 1);
81459 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
81460 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81461 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
81462
81463 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
81464 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
81465 index 4106ca9..a338d7a 100644
81466 --- a/net/rxrpc/ar-connection.c
81467 +++ b/net/rxrpc/ar-connection.c
81468 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
81469 rwlock_init(&conn->lock);
81470 spin_lock_init(&conn->state_lock);
81471 atomic_set(&conn->usage, 1);
81472 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
81473 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81474 conn->avail_calls = RXRPC_MAXCALLS;
81475 conn->size_align = 4;
81476 conn->header_size = sizeof(struct rxrpc_header);
81477 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
81478 index e7ed43a..6afa140 100644
81479 --- a/net/rxrpc/ar-connevent.c
81480 +++ b/net/rxrpc/ar-connevent.c
81481 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
81482
81483 len = iov[0].iov_len + iov[1].iov_len;
81484
81485 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
81486 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
81487 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
81488
81489 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
81490 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
81491 index 529572f..c758ca7 100644
81492 --- a/net/rxrpc/ar-input.c
81493 +++ b/net/rxrpc/ar-input.c
81494 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
81495 /* track the latest serial number on this connection for ACK packet
81496 * information */
81497 serial = ntohl(sp->hdr.serial);
81498 - hi_serial = atomic_read(&call->conn->hi_serial);
81499 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
81500 while (serial > hi_serial)
81501 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
81502 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
81503 serial);
81504
81505 /* request ACK generation for any ACK or DATA packet that requests
81506 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
81507 index a693aca..81e7293 100644
81508 --- a/net/rxrpc/ar-internal.h
81509 +++ b/net/rxrpc/ar-internal.h
81510 @@ -272,8 +272,8 @@ struct rxrpc_connection {
81511 int error; /* error code for local abort */
81512 int debug_id; /* debug ID for printks */
81513 unsigned int call_counter; /* call ID counter */
81514 - atomic_t serial; /* packet serial number counter */
81515 - atomic_t hi_serial; /* highest serial number received */
81516 + atomic_unchecked_t serial; /* packet serial number counter */
81517 + atomic_unchecked_t hi_serial; /* highest serial number received */
81518 u8 avail_calls; /* number of calls available */
81519 u8 size_align; /* data size alignment (for security) */
81520 u8 header_size; /* rxrpc + security header size */
81521 @@ -346,7 +346,7 @@ struct rxrpc_call {
81522 spinlock_t lock;
81523 rwlock_t state_lock; /* lock for state transition */
81524 atomic_t usage;
81525 - atomic_t sequence; /* Tx data packet sequence counter */
81526 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
81527 u32 abort_code; /* local/remote abort code */
81528 enum { /* current state of call */
81529 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
81530 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
81531 */
81532 extern atomic_t rxrpc_n_skbs;
81533 extern __be32 rxrpc_epoch;
81534 -extern atomic_t rxrpc_debug_id;
81535 +extern atomic_unchecked_t rxrpc_debug_id;
81536 extern struct workqueue_struct *rxrpc_workqueue;
81537
81538 /*
81539 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
81540 index 87f7135..74d3703 100644
81541 --- a/net/rxrpc/ar-local.c
81542 +++ b/net/rxrpc/ar-local.c
81543 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
81544 spin_lock_init(&local->lock);
81545 rwlock_init(&local->services_lock);
81546 atomic_set(&local->usage, 1);
81547 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
81548 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81549 memcpy(&local->srx, srx, sizeof(*srx));
81550 }
81551
81552 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
81553 index e1ac183..b43e10e 100644
81554 --- a/net/rxrpc/ar-output.c
81555 +++ b/net/rxrpc/ar-output.c
81556 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
81557 sp->hdr.cid = call->cid;
81558 sp->hdr.callNumber = call->call_id;
81559 sp->hdr.seq =
81560 - htonl(atomic_inc_return(&call->sequence));
81561 + htonl(atomic_inc_return_unchecked(&call->sequence));
81562 sp->hdr.serial =
81563 - htonl(atomic_inc_return(&conn->serial));
81564 + htonl(atomic_inc_return_unchecked(&conn->serial));
81565 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
81566 sp->hdr.userStatus = 0;
81567 sp->hdr.securityIndex = conn->security_ix;
81568 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
81569 index bebaa43..2644591 100644
81570 --- a/net/rxrpc/ar-peer.c
81571 +++ b/net/rxrpc/ar-peer.c
81572 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
81573 INIT_LIST_HEAD(&peer->error_targets);
81574 spin_lock_init(&peer->lock);
81575 atomic_set(&peer->usage, 1);
81576 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
81577 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81578 memcpy(&peer->srx, srx, sizeof(*srx));
81579
81580 rxrpc_assess_MTU_size(peer);
81581 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
81582 index 38047f7..9f48511 100644
81583 --- a/net/rxrpc/ar-proc.c
81584 +++ b/net/rxrpc/ar-proc.c
81585 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
81586 atomic_read(&conn->usage),
81587 rxrpc_conn_states[conn->state],
81588 key_serial(conn->key),
81589 - atomic_read(&conn->serial),
81590 - atomic_read(&conn->hi_serial));
81591 + atomic_read_unchecked(&conn->serial),
81592 + atomic_read_unchecked(&conn->hi_serial));
81593
81594 return 0;
81595 }
81596 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
81597 index 92df566..87ec1bf 100644
81598 --- a/net/rxrpc/ar-transport.c
81599 +++ b/net/rxrpc/ar-transport.c
81600 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
81601 spin_lock_init(&trans->client_lock);
81602 rwlock_init(&trans->conn_lock);
81603 atomic_set(&trans->usage, 1);
81604 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
81605 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81606
81607 if (peer->srx.transport.family == AF_INET) {
81608 switch (peer->srx.transport_type) {
81609 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
81610 index f226709..0e735a8 100644
81611 --- a/net/rxrpc/rxkad.c
81612 +++ b/net/rxrpc/rxkad.c
81613 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
81614
81615 len = iov[0].iov_len + iov[1].iov_len;
81616
81617 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
81618 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
81619 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
81620
81621 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
81622 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
81623
81624 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
81625
81626 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
81627 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
81628 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
81629
81630 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
81631 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
81632 index ea14cb4..834e8e4 100644
81633 --- a/net/sctp/ipv6.c
81634 +++ b/net/sctp/ipv6.c
81635 @@ -1037,7 +1037,7 @@ void sctp_v6_pf_init(void)
81636
81637 void sctp_v6_pf_exit(void)
81638 {
81639 - list_del(&sctp_af_inet6.list);
81640 + pax_list_del((struct list_head *)&sctp_af_inet6.list);
81641 }
81642
81643 /* Initialize IPv6 support and register with socket layer. */
81644 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
81645 index 9966e7b..540c575 100644
81646 --- a/net/sctp/proc.c
81647 +++ b/net/sctp/proc.c
81648 @@ -328,7 +328,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
81649 seq_printf(seq,
81650 "%8pK %8pK %-3d %-3d %-2d %-4d "
81651 "%4d %8d %8d %7d %5lu %-5d %5d ",
81652 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
81653 + assoc, sk,
81654 + sctp_sk(sk)->type, sk->sk_state,
81655 assoc->state, hash,
81656 assoc->assoc_id,
81657 assoc->sndbuf_used,
81658 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
81659 index 2d51842..150ba5c 100644
81660 --- a/net/sctp/protocol.c
81661 +++ b/net/sctp/protocol.c
81662 @@ -834,8 +834,10 @@ int sctp_register_af(struct sctp_af *af)
81663 return 0;
81664 }
81665
81666 - INIT_LIST_HEAD(&af->list);
81667 - list_add_tail(&af->list, &sctp_address_families);
81668 + pax_open_kernel();
81669 + INIT_LIST_HEAD((struct list_head *)&af->list);
81670 + pax_close_kernel();
81671 + pax_list_add_tail((struct list_head *)&af->list, &sctp_address_families);
81672 return 1;
81673 }
81674
81675 @@ -1122,7 +1124,7 @@ static void sctp_v4_pf_init(void)
81676
81677 static void sctp_v4_pf_exit(void)
81678 {
81679 - list_del(&sctp_af_inet.list);
81680 + pax_list_del((struct list_head *)&sctp_af_inet.list);
81681 }
81682
81683 static int sctp_v4_protosw_init(void)
81684 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
81685 index 406d957..543c737 100644
81686 --- a/net/sctp/socket.c
81687 +++ b/net/sctp/socket.c
81688 @@ -4661,6 +4661,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
81689 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
81690 if (space_left < addrlen)
81691 return -ENOMEM;
81692 + if (addrlen > sizeof(temp) || addrlen < 0)
81693 + return -EFAULT;
81694 if (copy_to_user(to, &temp, addrlen))
81695 return -EFAULT;
81696 to += addrlen;
81697 diff --git a/net/socket.c b/net/socket.c
81698 index d92c490..b4bc863 100644
81699 --- a/net/socket.c
81700 +++ b/net/socket.c
81701 @@ -89,6 +89,7 @@
81702 #include <linux/magic.h>
81703 #include <linux/slab.h>
81704 #include <linux/xattr.h>
81705 +#include <linux/in.h>
81706
81707 #include <asm/uaccess.h>
81708 #include <asm/unistd.h>
81709 @@ -106,6 +107,8 @@
81710 #include <linux/sockios.h>
81711 #include <linux/atalk.h>
81712
81713 +#include <linux/grsock.h>
81714 +
81715 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
81716 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
81717 unsigned long nr_segs, loff_t pos);
81718 @@ -322,7 +325,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
81719 &sockfs_dentry_operations, SOCKFS_MAGIC);
81720 }
81721
81722 -static struct vfsmount *sock_mnt __read_mostly;
81723 +struct vfsmount *sock_mnt __read_mostly;
81724
81725 static struct file_system_type sock_fs_type = {
81726 .name = "sockfs",
81727 @@ -1276,6 +1279,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
81728 return -EAFNOSUPPORT;
81729 if (type < 0 || type >= SOCK_MAX)
81730 return -EINVAL;
81731 + if (protocol < 0)
81732 + return -EINVAL;
81733
81734 /* Compatibility.
81735
81736 @@ -1407,6 +1412,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
81737 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
81738 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
81739
81740 + if(!gr_search_socket(family, type, protocol)) {
81741 + retval = -EACCES;
81742 + goto out;
81743 + }
81744 +
81745 + if (gr_handle_sock_all(family, type, protocol)) {
81746 + retval = -EACCES;
81747 + goto out;
81748 + }
81749 +
81750 retval = sock_create(family, type, protocol, &sock);
81751 if (retval < 0)
81752 goto out;
81753 @@ -1534,6 +1549,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
81754 if (sock) {
81755 err = move_addr_to_kernel(umyaddr, addrlen, &address);
81756 if (err >= 0) {
81757 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
81758 + err = -EACCES;
81759 + goto error;
81760 + }
81761 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
81762 + if (err)
81763 + goto error;
81764 +
81765 err = security_socket_bind(sock,
81766 (struct sockaddr *)&address,
81767 addrlen);
81768 @@ -1542,6 +1565,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
81769 (struct sockaddr *)
81770 &address, addrlen);
81771 }
81772 +error:
81773 fput_light(sock->file, fput_needed);
81774 }
81775 return err;
81776 @@ -1565,10 +1589,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
81777 if ((unsigned int)backlog > somaxconn)
81778 backlog = somaxconn;
81779
81780 + if (gr_handle_sock_server_other(sock->sk)) {
81781 + err = -EPERM;
81782 + goto error;
81783 + }
81784 +
81785 + err = gr_search_listen(sock);
81786 + if (err)
81787 + goto error;
81788 +
81789 err = security_socket_listen(sock, backlog);
81790 if (!err)
81791 err = sock->ops->listen(sock, backlog);
81792
81793 +error:
81794 fput_light(sock->file, fput_needed);
81795 }
81796 return err;
81797 @@ -1612,6 +1646,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
81798 newsock->type = sock->type;
81799 newsock->ops = sock->ops;
81800
81801 + if (gr_handle_sock_server_other(sock->sk)) {
81802 + err = -EPERM;
81803 + sock_release(newsock);
81804 + goto out_put;
81805 + }
81806 +
81807 + err = gr_search_accept(sock);
81808 + if (err) {
81809 + sock_release(newsock);
81810 + goto out_put;
81811 + }
81812 +
81813 /*
81814 * We don't need try_module_get here, as the listening socket (sock)
81815 * has the protocol module (sock->ops->owner) held.
81816 @@ -1657,6 +1703,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
81817 fd_install(newfd, newfile);
81818 err = newfd;
81819
81820 + gr_attach_curr_ip(newsock->sk);
81821 +
81822 out_put:
81823 fput_light(sock->file, fput_needed);
81824 out:
81825 @@ -1689,6 +1737,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
81826 int, addrlen)
81827 {
81828 struct socket *sock;
81829 + struct sockaddr *sck;
81830 struct sockaddr_storage address;
81831 int err, fput_needed;
81832
81833 @@ -1699,6 +1748,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
81834 if (err < 0)
81835 goto out_put;
81836
81837 + sck = (struct sockaddr *)&address;
81838 +
81839 + if (gr_handle_sock_client(sck)) {
81840 + err = -EACCES;
81841 + goto out_put;
81842 + }
81843 +
81844 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
81845 + if (err)
81846 + goto out_put;
81847 +
81848 err =
81849 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
81850 if (err)
81851 @@ -2053,7 +2113,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
81852 * checking falls down on this.
81853 */
81854 if (copy_from_user(ctl_buf,
81855 - (void __user __force *)msg_sys->msg_control,
81856 + (void __force_user *)msg_sys->msg_control,
81857 ctl_len))
81858 goto out_freectl;
81859 msg_sys->msg_control = ctl_buf;
81860 @@ -2221,7 +2281,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
81861 * kernel msghdr to use the kernel address space)
81862 */
81863
81864 - uaddr = (__force void __user *)msg_sys->msg_name;
81865 + uaddr = (void __force_user *)msg_sys->msg_name;
81866 uaddr_len = COMPAT_NAMELEN(msg);
81867 if (MSG_CMSG_COMPAT & flags) {
81868 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
81869 @@ -2844,7 +2904,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
81870 }
81871
81872 ifr = compat_alloc_user_space(buf_size);
81873 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
81874 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
81875
81876 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
81877 return -EFAULT;
81878 @@ -2868,12 +2928,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
81879 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
81880
81881 if (copy_in_user(rxnfc, compat_rxnfc,
81882 - (void *)(&rxnfc->fs.m_ext + 1) -
81883 - (void *)rxnfc) ||
81884 + (void __user *)(&rxnfc->fs.m_ext + 1) -
81885 + (void __user *)rxnfc) ||
81886 copy_in_user(&rxnfc->fs.ring_cookie,
81887 &compat_rxnfc->fs.ring_cookie,
81888 - (void *)(&rxnfc->fs.location + 1) -
81889 - (void *)&rxnfc->fs.ring_cookie) ||
81890 + (void __user *)(&rxnfc->fs.location + 1) -
81891 + (void __user *)&rxnfc->fs.ring_cookie) ||
81892 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
81893 sizeof(rxnfc->rule_cnt)))
81894 return -EFAULT;
81895 @@ -2885,12 +2945,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
81896
81897 if (convert_out) {
81898 if (copy_in_user(compat_rxnfc, rxnfc,
81899 - (const void *)(&rxnfc->fs.m_ext + 1) -
81900 - (const void *)rxnfc) ||
81901 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
81902 + (const void __user *)rxnfc) ||
81903 copy_in_user(&compat_rxnfc->fs.ring_cookie,
81904 &rxnfc->fs.ring_cookie,
81905 - (const void *)(&rxnfc->fs.location + 1) -
81906 - (const void *)&rxnfc->fs.ring_cookie) ||
81907 + (const void __user *)(&rxnfc->fs.location + 1) -
81908 + (const void __user *)&rxnfc->fs.ring_cookie) ||
81909 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
81910 sizeof(rxnfc->rule_cnt)))
81911 return -EFAULT;
81912 @@ -2960,7 +3020,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
81913 old_fs = get_fs();
81914 set_fs(KERNEL_DS);
81915 err = dev_ioctl(net, cmd,
81916 - (struct ifreq __user __force *) &kifr);
81917 + (struct ifreq __force_user *) &kifr);
81918 set_fs(old_fs);
81919
81920 return err;
81921 @@ -3069,7 +3129,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
81922
81923 old_fs = get_fs();
81924 set_fs(KERNEL_DS);
81925 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
81926 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
81927 set_fs(old_fs);
81928
81929 if (cmd == SIOCGIFMAP && !err) {
81930 @@ -3174,7 +3234,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
81931 ret |= __get_user(rtdev, &(ur4->rt_dev));
81932 if (rtdev) {
81933 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
81934 - r4.rt_dev = (char __user __force *)devname;
81935 + r4.rt_dev = (char __force_user *)devname;
81936 devname[15] = 0;
81937 } else
81938 r4.rt_dev = NULL;
81939 @@ -3400,8 +3460,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
81940 int __user *uoptlen;
81941 int err;
81942
81943 - uoptval = (char __user __force *) optval;
81944 - uoptlen = (int __user __force *) optlen;
81945 + uoptval = (char __force_user *) optval;
81946 + uoptlen = (int __force_user *) optlen;
81947
81948 set_fs(KERNEL_DS);
81949 if (level == SOL_SOCKET)
81950 @@ -3421,7 +3481,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
81951 char __user *uoptval;
81952 int err;
81953
81954 - uoptval = (char __user __force *) optval;
81955 + uoptval = (char __force_user *) optval;
81956
81957 set_fs(KERNEL_DS);
81958 if (level == SOL_SOCKET)
81959 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
81960 index 7865b44..174662e 100644
81961 --- a/net/sunrpc/sched.c
81962 +++ b/net/sunrpc/sched.c
81963 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
81964 #ifdef RPC_DEBUG
81965 static void rpc_task_set_debuginfo(struct rpc_task *task)
81966 {
81967 - static atomic_t rpc_pid;
81968 + static atomic_unchecked_t rpc_pid;
81969
81970 - task->tk_pid = atomic_inc_return(&rpc_pid);
81971 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
81972 }
81973 #else
81974 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
81975 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
81976 index 8343737..677025e 100644
81977 --- a/net/sunrpc/xprtrdma/svc_rdma.c
81978 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
81979 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
81980 static unsigned int min_max_inline = 4096;
81981 static unsigned int max_max_inline = 65536;
81982
81983 -atomic_t rdma_stat_recv;
81984 -atomic_t rdma_stat_read;
81985 -atomic_t rdma_stat_write;
81986 -atomic_t rdma_stat_sq_starve;
81987 -atomic_t rdma_stat_rq_starve;
81988 -atomic_t rdma_stat_rq_poll;
81989 -atomic_t rdma_stat_rq_prod;
81990 -atomic_t rdma_stat_sq_poll;
81991 -atomic_t rdma_stat_sq_prod;
81992 +atomic_unchecked_t rdma_stat_recv;
81993 +atomic_unchecked_t rdma_stat_read;
81994 +atomic_unchecked_t rdma_stat_write;
81995 +atomic_unchecked_t rdma_stat_sq_starve;
81996 +atomic_unchecked_t rdma_stat_rq_starve;
81997 +atomic_unchecked_t rdma_stat_rq_poll;
81998 +atomic_unchecked_t rdma_stat_rq_prod;
81999 +atomic_unchecked_t rdma_stat_sq_poll;
82000 +atomic_unchecked_t rdma_stat_sq_prod;
82001
82002 /* Temporary NFS request map and context caches */
82003 struct kmem_cache *svc_rdma_map_cachep;
82004 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
82005 len -= *ppos;
82006 if (len > *lenp)
82007 len = *lenp;
82008 - if (len && copy_to_user(buffer, str_buf, len))
82009 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
82010 return -EFAULT;
82011 *lenp = len;
82012 *ppos += len;
82013 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
82014 {
82015 .procname = "rdma_stat_read",
82016 .data = &rdma_stat_read,
82017 - .maxlen = sizeof(atomic_t),
82018 + .maxlen = sizeof(atomic_unchecked_t),
82019 .mode = 0644,
82020 .proc_handler = read_reset_stat,
82021 },
82022 {
82023 .procname = "rdma_stat_recv",
82024 .data = &rdma_stat_recv,
82025 - .maxlen = sizeof(atomic_t),
82026 + .maxlen = sizeof(atomic_unchecked_t),
82027 .mode = 0644,
82028 .proc_handler = read_reset_stat,
82029 },
82030 {
82031 .procname = "rdma_stat_write",
82032 .data = &rdma_stat_write,
82033 - .maxlen = sizeof(atomic_t),
82034 + .maxlen = sizeof(atomic_unchecked_t),
82035 .mode = 0644,
82036 .proc_handler = read_reset_stat,
82037 },
82038 {
82039 .procname = "rdma_stat_sq_starve",
82040 .data = &rdma_stat_sq_starve,
82041 - .maxlen = sizeof(atomic_t),
82042 + .maxlen = sizeof(atomic_unchecked_t),
82043 .mode = 0644,
82044 .proc_handler = read_reset_stat,
82045 },
82046 {
82047 .procname = "rdma_stat_rq_starve",
82048 .data = &rdma_stat_rq_starve,
82049 - .maxlen = sizeof(atomic_t),
82050 + .maxlen = sizeof(atomic_unchecked_t),
82051 .mode = 0644,
82052 .proc_handler = read_reset_stat,
82053 },
82054 {
82055 .procname = "rdma_stat_rq_poll",
82056 .data = &rdma_stat_rq_poll,
82057 - .maxlen = sizeof(atomic_t),
82058 + .maxlen = sizeof(atomic_unchecked_t),
82059 .mode = 0644,
82060 .proc_handler = read_reset_stat,
82061 },
82062 {
82063 .procname = "rdma_stat_rq_prod",
82064 .data = &rdma_stat_rq_prod,
82065 - .maxlen = sizeof(atomic_t),
82066 + .maxlen = sizeof(atomic_unchecked_t),
82067 .mode = 0644,
82068 .proc_handler = read_reset_stat,
82069 },
82070 {
82071 .procname = "rdma_stat_sq_poll",
82072 .data = &rdma_stat_sq_poll,
82073 - .maxlen = sizeof(atomic_t),
82074 + .maxlen = sizeof(atomic_unchecked_t),
82075 .mode = 0644,
82076 .proc_handler = read_reset_stat,
82077 },
82078 {
82079 .procname = "rdma_stat_sq_prod",
82080 .data = &rdma_stat_sq_prod,
82081 - .maxlen = sizeof(atomic_t),
82082 + .maxlen = sizeof(atomic_unchecked_t),
82083 .mode = 0644,
82084 .proc_handler = read_reset_stat,
82085 },
82086 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
82087 index 41cb63b..c4a1489 100644
82088 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
82089 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
82090 @@ -501,7 +501,7 @@ next_sge:
82091 svc_rdma_put_context(ctxt, 0);
82092 goto out;
82093 }
82094 - atomic_inc(&rdma_stat_read);
82095 + atomic_inc_unchecked(&rdma_stat_read);
82096
82097 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
82098 chl_map->ch[ch_no].count -= read_wr.num_sge;
82099 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
82100 dto_q);
82101 list_del_init(&ctxt->dto_q);
82102 } else {
82103 - atomic_inc(&rdma_stat_rq_starve);
82104 + atomic_inc_unchecked(&rdma_stat_rq_starve);
82105 clear_bit(XPT_DATA, &xprt->xpt_flags);
82106 ctxt = NULL;
82107 }
82108 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
82109 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
82110 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
82111 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
82112 - atomic_inc(&rdma_stat_recv);
82113 + atomic_inc_unchecked(&rdma_stat_recv);
82114
82115 /* Build up the XDR from the receive buffers. */
82116 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
82117 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
82118 index 42eb7ba..c887c45 100644
82119 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
82120 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
82121 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
82122 write_wr.wr.rdma.remote_addr = to;
82123
82124 /* Post It */
82125 - atomic_inc(&rdma_stat_write);
82126 + atomic_inc_unchecked(&rdma_stat_write);
82127 if (svc_rdma_send(xprt, &write_wr))
82128 goto err;
82129 return 0;
82130 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
82131 index 62e4f9b..dd3f2d7 100644
82132 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
82133 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
82134 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
82135 return;
82136
82137 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
82138 - atomic_inc(&rdma_stat_rq_poll);
82139 + atomic_inc_unchecked(&rdma_stat_rq_poll);
82140
82141 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
82142 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
82143 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
82144 }
82145
82146 if (ctxt)
82147 - atomic_inc(&rdma_stat_rq_prod);
82148 + atomic_inc_unchecked(&rdma_stat_rq_prod);
82149
82150 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
82151 /*
82152 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
82153 return;
82154
82155 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
82156 - atomic_inc(&rdma_stat_sq_poll);
82157 + atomic_inc_unchecked(&rdma_stat_sq_poll);
82158 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
82159 if (wc.status != IB_WC_SUCCESS)
82160 /* Close the transport */
82161 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
82162 }
82163
82164 if (ctxt)
82165 - atomic_inc(&rdma_stat_sq_prod);
82166 + atomic_inc_unchecked(&rdma_stat_sq_prod);
82167 }
82168
82169 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
82170 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
82171 spin_lock_bh(&xprt->sc_lock);
82172 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
82173 spin_unlock_bh(&xprt->sc_lock);
82174 - atomic_inc(&rdma_stat_sq_starve);
82175 + atomic_inc_unchecked(&rdma_stat_sq_starve);
82176
82177 /* See if we can opportunistically reap SQ WR to make room */
82178 sq_cq_reap(xprt);
82179 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
82180 index e3a6e37..be2ea77 100644
82181 --- a/net/sysctl_net.c
82182 +++ b/net/sysctl_net.c
82183 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
82184 struct ctl_table *table)
82185 {
82186 /* Allow network administrator to have same access as root. */
82187 - if (capable(CAP_NET_ADMIN)) {
82188 + if (capable_nolog(CAP_NET_ADMIN)) {
82189 int mode = (table->mode >> 6) & 7;
82190 return (mode << 6) | (mode << 3) | mode;
82191 }
82192 diff --git a/net/tipc/link.c b/net/tipc/link.c
82193 index a79c755..eca357d 100644
82194 --- a/net/tipc/link.c
82195 +++ b/net/tipc/link.c
82196 @@ -1169,7 +1169,7 @@ static int link_send_sections_long(struct tipc_port *sender,
82197 struct tipc_msg fragm_hdr;
82198 struct sk_buff *buf, *buf_chain, *prev;
82199 u32 fragm_crs, fragm_rest, hsz, sect_rest;
82200 - const unchar *sect_crs;
82201 + const unchar __user *sect_crs;
82202 int curr_sect;
82203 u32 fragm_no;
82204
82205 @@ -1210,7 +1210,7 @@ again:
82206
82207 if (!sect_rest) {
82208 sect_rest = msg_sect[++curr_sect].iov_len;
82209 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
82210 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
82211 }
82212
82213 if (sect_rest < fragm_rest)
82214 @@ -1229,7 +1229,7 @@ error:
82215 }
82216 } else
82217 skb_copy_to_linear_data_offset(buf, fragm_crs,
82218 - sect_crs, sz);
82219 + (const void __force_kernel *)sect_crs, sz);
82220 sect_crs += sz;
82221 sect_rest -= sz;
82222 fragm_crs += sz;
82223 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
82224 index f2db8a8..9245aa4 100644
82225 --- a/net/tipc/msg.c
82226 +++ b/net/tipc/msg.c
82227 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
82228 msg_sect[cnt].iov_len);
82229 else
82230 skb_copy_to_linear_data_offset(*buf, pos,
82231 - msg_sect[cnt].iov_base,
82232 + (const void __force_kernel *)msg_sect[cnt].iov_base,
82233 msg_sect[cnt].iov_len);
82234 pos += msg_sect[cnt].iov_len;
82235 }
82236 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
82237 index 0f7d0d0..00f89bf 100644
82238 --- a/net/tipc/subscr.c
82239 +++ b/net/tipc/subscr.c
82240 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
82241 {
82242 struct iovec msg_sect;
82243
82244 - msg_sect.iov_base = (void *)&sub->evt;
82245 + msg_sect.iov_base = (void __force_user *)&sub->evt;
82246 msg_sect.iov_len = sizeof(struct tipc_event);
82247
82248 sub->evt.event = htohl(event, sub->swap);
82249 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
82250 index 5b5c876..3127bf7 100644
82251 --- a/net/unix/af_unix.c
82252 +++ b/net/unix/af_unix.c
82253 @@ -786,6 +786,12 @@ static struct sock *unix_find_other(struct net *net,
82254 err = -ECONNREFUSED;
82255 if (!S_ISSOCK(inode->i_mode))
82256 goto put_fail;
82257 +
82258 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
82259 + err = -EACCES;
82260 + goto put_fail;
82261 + }
82262 +
82263 u = unix_find_socket_byinode(inode);
82264 if (!u)
82265 goto put_fail;
82266 @@ -806,6 +812,13 @@ static struct sock *unix_find_other(struct net *net,
82267 if (u) {
82268 struct dentry *dentry;
82269 dentry = unix_sk(u)->path.dentry;
82270 +
82271 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
82272 + err = -EPERM;
82273 + sock_put(u);
82274 + goto fail;
82275 + }
82276 +
82277 if (dentry)
82278 touch_atime(&unix_sk(u)->path);
82279 } else
82280 @@ -839,12 +852,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
82281 */
82282 err = security_path_mknod(&path, dentry, mode, 0);
82283 if (!err) {
82284 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
82285 + err = -EACCES;
82286 + goto out;
82287 + }
82288 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
82289 if (!err) {
82290 res->mnt = mntget(path.mnt);
82291 res->dentry = dget(dentry);
82292 + gr_handle_create(dentry, path.mnt);
82293 }
82294 }
82295 +out:
82296 done_path_create(&path, dentry);
82297 return err;
82298 }
82299 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
82300 index c8717c1..08539f5 100644
82301 --- a/net/wireless/wext-core.c
82302 +++ b/net/wireless/wext-core.c
82303 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
82304 */
82305
82306 /* Support for very large requests */
82307 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
82308 - (user_length > descr->max_tokens)) {
82309 + if (user_length > descr->max_tokens) {
82310 /* Allow userspace to GET more than max so
82311 * we can support any size GET requests.
82312 * There is still a limit : -ENOMEM.
82313 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
82314 }
82315 }
82316
82317 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
82318 - /*
82319 - * If this is a GET, but not NOMAX, it means that the extra
82320 - * data is not bounded by userspace, but by max_tokens. Thus
82321 - * set the length to max_tokens. This matches the extra data
82322 - * allocation.
82323 - * The driver should fill it with the number of tokens it
82324 - * provided, and it may check iwp->length rather than having
82325 - * knowledge of max_tokens. If the driver doesn't change the
82326 - * iwp->length, this ioctl just copies back max_token tokens
82327 - * filled with zeroes. Hopefully the driver isn't claiming
82328 - * them to be valid data.
82329 - */
82330 - iwp->length = descr->max_tokens;
82331 - }
82332 -
82333 err = handler(dev, info, (union iwreq_data *) iwp, extra);
82334
82335 iwp->length += essid_compat;
82336 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
82337 index 41eabc4..8d4e6d6 100644
82338 --- a/net/xfrm/xfrm_policy.c
82339 +++ b/net/xfrm/xfrm_policy.c
82340 @@ -317,7 +317,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
82341 {
82342 policy->walk.dead = 1;
82343
82344 - atomic_inc(&policy->genid);
82345 + atomic_inc_unchecked(&policy->genid);
82346
82347 if (del_timer(&policy->timer))
82348 xfrm_pol_put(policy);
82349 @@ -601,7 +601,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
82350 hlist_add_head(&policy->bydst, chain);
82351 xfrm_pol_hold(policy);
82352 net->xfrm.policy_count[dir]++;
82353 - atomic_inc(&flow_cache_genid);
82354 + atomic_inc_unchecked(&flow_cache_genid);
82355 rt_genid_bump(net);
82356 if (delpol)
82357 __xfrm_policy_unlink(delpol, dir);
82358 @@ -1550,7 +1550,7 @@ free_dst:
82359 goto out;
82360 }
82361
82362 -static int inline
82363 +static inline int
82364 xfrm_dst_alloc_copy(void **target, const void *src, int size)
82365 {
82366 if (!*target) {
82367 @@ -1562,7 +1562,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
82368 return 0;
82369 }
82370
82371 -static int inline
82372 +static inline int
82373 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
82374 {
82375 #ifdef CONFIG_XFRM_SUB_POLICY
82376 @@ -1574,7 +1574,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
82377 #endif
82378 }
82379
82380 -static int inline
82381 +static inline int
82382 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
82383 {
82384 #ifdef CONFIG_XFRM_SUB_POLICY
82385 @@ -1668,7 +1668,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
82386
82387 xdst->num_pols = num_pols;
82388 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
82389 - xdst->policy_genid = atomic_read(&pols[0]->genid);
82390 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
82391
82392 return xdst;
82393 }
82394 @@ -2369,7 +2369,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
82395 if (xdst->xfrm_genid != dst->xfrm->genid)
82396 return 0;
82397 if (xdst->num_pols > 0 &&
82398 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
82399 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
82400 return 0;
82401
82402 mtu = dst_mtu(dst->child);
82403 @@ -2896,7 +2896,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
82404 sizeof(pol->xfrm_vec[i].saddr));
82405 pol->xfrm_vec[i].encap_family = mp->new_family;
82406 /* flush bundles */
82407 - atomic_inc(&pol->genid);
82408 + atomic_inc_unchecked(&pol->genid);
82409 }
82410 }
82411
82412 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
82413 index 3459692..eefb515 100644
82414 --- a/net/xfrm/xfrm_state.c
82415 +++ b/net/xfrm/xfrm_state.c
82416 @@ -278,7 +278,9 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
82417 if (!try_module_get(afinfo->owner))
82418 goto out;
82419
82420 - mode->afinfo = afinfo;
82421 + pax_open_kernel();
82422 + *(void **)&mode->afinfo = afinfo;
82423 + pax_close_kernel();
82424 modemap[mode->encap] = mode;
82425 err = 0;
82426
82427 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
82428 index 0e801c3..5c8ad3b 100644
82429 --- a/scripts/Makefile.build
82430 +++ b/scripts/Makefile.build
82431 @@ -111,7 +111,7 @@ endif
82432 endif
82433
82434 # Do not include host rules unless needed
82435 -ifneq ($(hostprogs-y)$(hostprogs-m),)
82436 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
82437 include scripts/Makefile.host
82438 endif
82439
82440 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
82441 index 686cb0d..9d653bf 100644
82442 --- a/scripts/Makefile.clean
82443 +++ b/scripts/Makefile.clean
82444 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
82445 __clean-files := $(extra-y) $(always) \
82446 $(targets) $(clean-files) \
82447 $(host-progs) \
82448 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
82449 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
82450 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
82451
82452 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
82453
82454 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
82455 index 1ac414f..38575f7 100644
82456 --- a/scripts/Makefile.host
82457 +++ b/scripts/Makefile.host
82458 @@ -31,6 +31,8 @@
82459 # Note: Shared libraries consisting of C++ files are not supported
82460
82461 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
82462 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
82463 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
82464
82465 # C code
82466 # Executables compiled from a single .c file
82467 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
82468 # Shared libaries (only .c supported)
82469 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
82470 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
82471 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
82472 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
82473 # Remove .so files from "xxx-objs"
82474 host-cobjs := $(filter-out %.so,$(host-cobjs))
82475 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
82476
82477 -#Object (.o) files used by the shared libaries
82478 +# Object (.o) files used by the shared libaries
82479 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
82480 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
82481
82482 # output directory for programs/.o files
82483 # hostprogs-y := tools/build may have been specified. Retrieve directory
82484 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
82485 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
82486 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
82487 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
82488 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
82489 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
82490 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
82491 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
82492
82493 obj-dirs += $(host-objdirs)
82494 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
82495 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
82496 $(call if_changed_dep,host-cshobjs)
82497
82498 +# Compile .c file, create position independent .o file
82499 +# host-cxxshobjs -> .o
82500 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
82501 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
82502 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
82503 + $(call if_changed_dep,host-cxxshobjs)
82504 +
82505 # Link a shared library, based on position independent .o files
82506 # *.o -> .so shared library (host-cshlib)
82507 quiet_cmd_host-cshlib = HOSTLLD -shared $@
82508 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
82509 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
82510 $(call if_changed,host-cshlib)
82511
82512 +# Link a shared library, based on position independent .o files
82513 +# *.o -> .so shared library (host-cxxshlib)
82514 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
82515 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
82516 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
82517 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
82518 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
82519 + $(call if_changed,host-cxxshlib)
82520 +
82521 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
82522 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
82523 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
82524
82525 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
82526 index cb1f50c..cef2a7c 100644
82527 --- a/scripts/basic/fixdep.c
82528 +++ b/scripts/basic/fixdep.c
82529 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
82530 /*
82531 * Lookup a value in the configuration string.
82532 */
82533 -static int is_defined_config(const char *name, int len, unsigned int hash)
82534 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
82535 {
82536 struct item *aux;
82537
82538 @@ -211,10 +211,10 @@ static void clear_config(void)
82539 /*
82540 * Record the use of a CONFIG_* word.
82541 */
82542 -static void use_config(const char *m, int slen)
82543 +static void use_config(const char *m, unsigned int slen)
82544 {
82545 unsigned int hash = strhash(m, slen);
82546 - int c, i;
82547 + unsigned int c, i;
82548
82549 if (is_defined_config(m, slen, hash))
82550 return;
82551 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
82552
82553 static void parse_config_file(const char *map, size_t len)
82554 {
82555 - const int *end = (const int *) (map + len);
82556 + const unsigned int *end = (const unsigned int *) (map + len);
82557 /* start at +1, so that p can never be < map */
82558 - const int *m = (const int *) map + 1;
82559 + const unsigned int *m = (const unsigned int *) map + 1;
82560 const char *p, *q;
82561
82562 for (; m < end; m++) {
82563 @@ -406,7 +406,7 @@ static void print_deps(void)
82564 static void traps(void)
82565 {
82566 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
82567 - int *p = (int *)test;
82568 + unsigned int *p = (unsigned int *)test;
82569
82570 if (*p != INT_CONF) {
82571 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
82572 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
82573 new file mode 100644
82574 index 0000000..008ac1a
82575 --- /dev/null
82576 +++ b/scripts/gcc-plugin.sh
82577 @@ -0,0 +1,17 @@
82578 +#!/bin/bash
82579 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
82580 +#include "gcc-plugin.h"
82581 +#include "tree.h"
82582 +#include "tm.h"
82583 +#include "rtl.h"
82584 +#ifdef ENABLE_BUILD_WITH_CXX
82585 +#warning $2
82586 +#else
82587 +#warning $1
82588 +#endif
82589 +EOF`
82590 +if [ $? -eq 0 ]
82591 +then
82592 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
82593 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
82594 +fi
82595 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
82596 index b3d907e..a4782ab 100644
82597 --- a/scripts/link-vmlinux.sh
82598 +++ b/scripts/link-vmlinux.sh
82599 @@ -152,7 +152,7 @@ else
82600 fi;
82601
82602 # final build of init/
82603 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
82604 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
82605
82606 kallsymso=""
82607 kallsyms_vmlinux=""
82608 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
82609 index df4fc23..0ea719d 100644
82610 --- a/scripts/mod/file2alias.c
82611 +++ b/scripts/mod/file2alias.c
82612 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
82613 unsigned long size, unsigned long id_size,
82614 void *symval)
82615 {
82616 - int i;
82617 + unsigned int i;
82618
82619 if (size % id_size || size < id_size) {
82620 if (cross_build != 0)
82621 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
82622 /* USB is special because the bcdDevice can be matched against a numeric range */
82623 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
82624 static void do_usb_entry(struct usb_device_id *id,
82625 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
82626 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
82627 unsigned char range_lo, unsigned char range_hi,
82628 unsigned char max, struct module *mod)
82629 {
82630 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
82631 {
82632 unsigned int devlo, devhi;
82633 unsigned char chi, clo, max;
82634 - int ndigits;
82635 + unsigned int ndigits;
82636
82637 id->match_flags = TO_NATIVE(id->match_flags);
82638 id->idVendor = TO_NATIVE(id->idVendor);
82639 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
82640 for (i = 0; i < count; i++) {
82641 const char *id = (char *)devs[i].id;
82642 char acpi_id[sizeof(devs[0].id)];
82643 - int j;
82644 + unsigned int j;
82645
82646 buf_printf(&mod->dev_table_buf,
82647 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
82648 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
82649
82650 for (j = 0; j < PNP_MAX_DEVICES; j++) {
82651 const char *id = (char *)card->devs[j].id;
82652 - int i2, j2;
82653 + unsigned int i2, j2;
82654 int dup = 0;
82655
82656 if (!id[0])
82657 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
82658 /* add an individual alias for every device entry */
82659 if (!dup) {
82660 char acpi_id[sizeof(card->devs[0].id)];
82661 - int k;
82662 + unsigned int k;
82663
82664 buf_printf(&mod->dev_table_buf,
82665 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
82666 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
82667 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
82668 char *alias)
82669 {
82670 - int i, j;
82671 + unsigned int i, j;
82672
82673 sprintf(alias, "dmi*");
82674
82675 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
82676 index 0d93856..e828363 100644
82677 --- a/scripts/mod/modpost.c
82678 +++ b/scripts/mod/modpost.c
82679 @@ -933,6 +933,7 @@ enum mismatch {
82680 ANY_INIT_TO_ANY_EXIT,
82681 ANY_EXIT_TO_ANY_INIT,
82682 EXPORT_TO_INIT_EXIT,
82683 + DATA_TO_TEXT
82684 };
82685
82686 struct sectioncheck {
82687 @@ -1047,6 +1048,12 @@ const struct sectioncheck sectioncheck[] = {
82688 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
82689 .mismatch = EXPORT_TO_INIT_EXIT,
82690 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
82691 +},
82692 +/* Do not reference code from writable data */
82693 +{
82694 + .fromsec = { DATA_SECTIONS, NULL },
82695 + .tosec = { TEXT_SECTIONS, NULL },
82696 + .mismatch = DATA_TO_TEXT
82697 }
82698 };
82699
82700 @@ -1169,10 +1176,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
82701 continue;
82702 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
82703 continue;
82704 - if (sym->st_value == addr)
82705 - return sym;
82706 /* Find a symbol nearby - addr are maybe negative */
82707 d = sym->st_value - addr;
82708 + if (d == 0)
82709 + return sym;
82710 if (d < 0)
82711 d = addr - sym->st_value;
82712 if (d < distance) {
82713 @@ -1451,6 +1458,14 @@ static void report_sec_mismatch(const char *modname,
82714 tosym, prl_to, prl_to, tosym);
82715 free(prl_to);
82716 break;
82717 + case DATA_TO_TEXT:
82718 +#if 0
82719 + fprintf(stderr,
82720 + "The %s %s:%s references\n"
82721 + "the %s %s:%s%s\n",
82722 + from, fromsec, fromsym, to, tosec, tosym, to_p);
82723 +#endif
82724 + break;
82725 }
82726 fprintf(stderr, "\n");
82727 }
82728 @@ -1685,7 +1700,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
82729 static void check_sec_ref(struct module *mod, const char *modname,
82730 struct elf_info *elf)
82731 {
82732 - int i;
82733 + unsigned int i;
82734 Elf_Shdr *sechdrs = elf->sechdrs;
82735
82736 /* Walk through all sections */
82737 @@ -1783,7 +1798,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
82738 va_end(ap);
82739 }
82740
82741 -void buf_write(struct buffer *buf, const char *s, int len)
82742 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
82743 {
82744 if (buf->size - buf->pos < len) {
82745 buf->size += len + SZ;
82746 @@ -2001,7 +2016,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
82747 if (fstat(fileno(file), &st) < 0)
82748 goto close_write;
82749
82750 - if (st.st_size != b->pos)
82751 + if (st.st_size != (off_t)b->pos)
82752 goto close_write;
82753
82754 tmp = NOFAIL(malloc(b->pos));
82755 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
82756 index 51207e4..f7d603d 100644
82757 --- a/scripts/mod/modpost.h
82758 +++ b/scripts/mod/modpost.h
82759 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
82760
82761 struct buffer {
82762 char *p;
82763 - int pos;
82764 - int size;
82765 + unsigned int pos;
82766 + unsigned int size;
82767 };
82768
82769 void __attribute__((format(printf, 2, 3)))
82770 buf_printf(struct buffer *buf, const char *fmt, ...);
82771
82772 void
82773 -buf_write(struct buffer *buf, const char *s, int len);
82774 +buf_write(struct buffer *buf, const char *s, unsigned int len);
82775
82776 struct module {
82777 struct module *next;
82778 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
82779 index 9dfcd6d..099068e 100644
82780 --- a/scripts/mod/sumversion.c
82781 +++ b/scripts/mod/sumversion.c
82782 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
82783 goto out;
82784 }
82785
82786 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
82787 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
82788 warn("writing sum in %s failed: %s\n",
82789 filename, strerror(errno));
82790 goto out;
82791 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
82792 index 5c11312..72742b5 100644
82793 --- a/scripts/pnmtologo.c
82794 +++ b/scripts/pnmtologo.c
82795 @@ -237,14 +237,14 @@ static void write_header(void)
82796 fprintf(out, " * Linux logo %s\n", logoname);
82797 fputs(" */\n\n", out);
82798 fputs("#include <linux/linux_logo.h>\n\n", out);
82799 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
82800 + fprintf(out, "static unsigned char %s_data[] = {\n",
82801 logoname);
82802 }
82803
82804 static void write_footer(void)
82805 {
82806 fputs("\n};\n\n", out);
82807 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
82808 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
82809 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
82810 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
82811 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
82812 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
82813 fputs("\n};\n\n", out);
82814
82815 /* write logo clut */
82816 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
82817 + fprintf(out, "static unsigned char %s_clut[] = {\n",
82818 logoname);
82819 write_hex_cnt = 0;
82820 for (i = 0; i < logo_clutsize; i++) {
82821 diff --git a/security/Kconfig b/security/Kconfig
82822 index e9c6ac7..01c698c 100644
82823 --- a/security/Kconfig
82824 +++ b/security/Kconfig
82825 @@ -4,6 +4,902 @@
82826
82827 menu "Security options"
82828
82829 +menu "Grsecurity"
82830 +
82831 + config ARCH_TRACK_EXEC_LIMIT
82832 + bool
82833 +
82834 + config PAX_KERNEXEC_PLUGIN
82835 + bool
82836 +
82837 + config PAX_PER_CPU_PGD
82838 + bool
82839 +
82840 + config TASK_SIZE_MAX_SHIFT
82841 + int
82842 + depends on X86_64
82843 + default 47 if !PAX_PER_CPU_PGD
82844 + default 42 if PAX_PER_CPU_PGD
82845 +
82846 + config PAX_ENABLE_PAE
82847 + bool
82848 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
82849 +
82850 + config PAX_USERCOPY_SLABS
82851 + bool
82852 +
82853 +config GRKERNSEC
82854 + bool "Grsecurity"
82855 + select CRYPTO
82856 + select CRYPTO_SHA256
82857 + select PROC_FS
82858 + select STOP_MACHINE
82859 + help
82860 + If you say Y here, you will be able to configure many features
82861 + that will enhance the security of your system. It is highly
82862 + recommended that you say Y here and read through the help
82863 + for each option so that you fully understand the features and
82864 + can evaluate their usefulness for your machine.
82865 +
82866 +choice
82867 + prompt "Configuration Method"
82868 + depends on GRKERNSEC
82869 + default GRKERNSEC_CONFIG_CUSTOM
82870 + help
82871 +
82872 +config GRKERNSEC_CONFIG_AUTO
82873 + bool "Automatic"
82874 + help
82875 + If you choose this configuration method, you'll be able to answer a small
82876 + number of simple questions about how you plan to use this kernel.
82877 + The settings of grsecurity and PaX will be automatically configured for
82878 + the highest commonly-used settings within the provided constraints.
82879 +
82880 + If you require additional configuration, custom changes can still be made
82881 + from the "custom configuration" menu.
82882 +
82883 +config GRKERNSEC_CONFIG_CUSTOM
82884 + bool "Custom"
82885 + help
82886 + If you choose this configuration method, you'll be able to configure all
82887 + grsecurity and PaX settings manually. Via this method, no options are
82888 + automatically enabled.
82889 +
82890 +endchoice
82891 +
82892 +choice
82893 + prompt "Usage Type"
82894 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
82895 + default GRKERNSEC_CONFIG_SERVER
82896 + help
82897 +
82898 +config GRKERNSEC_CONFIG_SERVER
82899 + bool "Server"
82900 + help
82901 + Choose this option if you plan to use this kernel on a server.
82902 +
82903 +config GRKERNSEC_CONFIG_DESKTOP
82904 + bool "Desktop"
82905 + help
82906 + Choose this option if you plan to use this kernel on a desktop.
82907 +
82908 +endchoice
82909 +
82910 +choice
82911 + prompt "Virtualization Type"
82912 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
82913 + default GRKERNSEC_CONFIG_VIRT_NONE
82914 + help
82915 +
82916 +config GRKERNSEC_CONFIG_VIRT_NONE
82917 + bool "None"
82918 + help
82919 + Choose this option if this kernel will be run on bare metal.
82920 +
82921 +config GRKERNSEC_CONFIG_VIRT_GUEST
82922 + bool "Guest"
82923 + help
82924 + Choose this option if this kernel will be run as a VM guest.
82925 +
82926 +config GRKERNSEC_CONFIG_VIRT_HOST
82927 + bool "Host"
82928 + help
82929 + Choose this option if this kernel will be run as a VM host.
82930 +
82931 +endchoice
82932 +
82933 +choice
82934 + prompt "Virtualization Hardware"
82935 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
82936 + help
82937 +
82938 +config GRKERNSEC_CONFIG_VIRT_EPT
82939 + bool "EPT/RVI Processor Support"
82940 + depends on X86
82941 + help
82942 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
82943 + hardware virtualization. This allows for additional kernel hardening protections
82944 + to operate without additional performance impact.
82945 +
82946 + To see if your Intel processor supports EPT, see:
82947 + http://ark.intel.com/Products/VirtualizationTechnology
82948 + (Most Core i3/5/7 support EPT)
82949 +
82950 + To see if your AMD processor supports RVI, see:
82951 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
82952 +
82953 +config GRKERNSEC_CONFIG_VIRT_SOFT
82954 + bool "First-gen/No Hardware Virtualization"
82955 + help
82956 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
82957 + support hardware virtualization or doesn't support the EPT/RVI extensions.
82958 +
82959 +endchoice
82960 +
82961 +choice
82962 + prompt "Virtualization Software"
82963 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
82964 + help
82965 +
82966 +config GRKERNSEC_CONFIG_VIRT_XEN
82967 + bool "Xen"
82968 + help
82969 + Choose this option if this kernel is running as a Xen guest or host.
82970 +
82971 +config GRKERNSEC_CONFIG_VIRT_VMWARE
82972 + bool "VMWare"
82973 + help
82974 + Choose this option if this kernel is running as a VMWare guest or host.
82975 +
82976 +config GRKERNSEC_CONFIG_VIRT_KVM
82977 + bool "KVM"
82978 + help
82979 + Choose this option if this kernel is running as a KVM guest or host.
82980 +
82981 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
82982 + bool "VirtualBox"
82983 + help
82984 + Choose this option if this kernel is running as a VirtualBox guest or host.
82985 +
82986 +endchoice
82987 +
82988 +choice
82989 + prompt "Required Priorities"
82990 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
82991 + default GRKERNSEC_CONFIG_PRIORITY_PERF
82992 + help
82993 +
82994 +config GRKERNSEC_CONFIG_PRIORITY_PERF
82995 + bool "Performance"
82996 + help
82997 + Choose this option if performance is of highest priority for this deployment
82998 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
82999 + and freed memory sanitizing will be disabled.
83000 +
83001 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
83002 + bool "Security"
83003 + help
83004 + Choose this option if security is of highest priority for this deployment of
83005 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
83006 + be enabled for this kernel. In a worst-case scenario, these features can
83007 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
83008 +
83009 +endchoice
83010 +
83011 +menu "Default Special Groups"
83012 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
83013 +
83014 +config GRKERNSEC_PROC_GID
83015 + int "GID exempted from /proc restrictions"
83016 + default 1001
83017 + help
83018 + Setting this GID determines which group will be exempted from
83019 + grsecurity's /proc restrictions, allowing users of the specified
83020 + group to view network statistics and the existence of other users'
83021 + processes on the system. This GID may also be chosen at boot time
83022 + via "grsec_proc_gid=" on the kernel commandline.
83023 +
83024 +config GRKERNSEC_TPE_UNTRUSTED_GID
83025 + int "GID for TPE-untrusted users"
83026 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
83027 + default 1005
83028 + help
83029 + Setting this GID determines which group untrusted users should
83030 + be added to. These users will be placed under grsecurity's Trusted Path
83031 + Execution mechanism, preventing them from executing their own binaries.
83032 + The users will only be able to execute binaries in directories owned and
83033 + writable only by the root user. If the sysctl option is enabled, a sysctl
83034 + option with name "tpe_gid" is created.
83035 +
83036 +config GRKERNSEC_TPE_TRUSTED_GID
83037 + int "GID for TPE-trusted users"
83038 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
83039 + default 1005
83040 + help
83041 + Setting this GID determines what group TPE restrictions will be
83042 + *disabled* for. If the sysctl option is enabled, a sysctl option
83043 + with name "tpe_gid" is created.
83044 +
83045 +config GRKERNSEC_SYMLINKOWN_GID
83046 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
83047 + depends on GRKERNSEC_CONFIG_SERVER
83048 + default 1006
83049 + help
83050 + Setting this GID determines what group kernel-enforced
83051 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
83052 + is enabled, a sysctl option with name "symlinkown_gid" is created.
83053 +
83054 +
83055 +endmenu
83056 +
83057 +menu "Customize Configuration"
83058 +depends on GRKERNSEC
83059 +
83060 +menu "PaX"
83061 +
83062 +config PAX
83063 + bool "Enable various PaX features"
83064 + default y if GRKERNSEC_CONFIG_AUTO
83065 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
83066 + help
83067 + This allows you to enable various PaX features. PaX adds
83068 + intrusion prevention mechanisms to the kernel that reduce
83069 + the risks posed by exploitable memory corruption bugs.
83070 +
83071 +menu "PaX Control"
83072 + depends on PAX
83073 +
83074 +config PAX_SOFTMODE
83075 + bool 'Support soft mode'
83076 + help
83077 + Enabling this option will allow you to run PaX in soft mode, that
83078 + is, PaX features will not be enforced by default, only on executables
83079 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
83080 + support as they are the only way to mark executables for soft mode use.
83081 +
83082 + Soft mode can be activated by using the "pax_softmode=1" kernel command
83083 + line option on boot. Furthermore you can control various PaX features
83084 + at runtime via the entries in /proc/sys/kernel/pax.
83085 +
83086 +config PAX_EI_PAX
83087 + bool 'Use legacy ELF header marking'
83088 + default y if GRKERNSEC_CONFIG_AUTO
83089 + help
83090 + Enabling this option will allow you to control PaX features on
83091 + a per executable basis via the 'chpax' utility available at
83092 + http://pax.grsecurity.net/. The control flags will be read from
83093 + an otherwise reserved part of the ELF header. This marking has
83094 + numerous drawbacks (no support for soft-mode, toolchain does not
83095 + know about the non-standard use of the ELF header) therefore it
83096 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
83097 + support.
83098 +
83099 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
83100 + support as well, they will override the legacy EI_PAX marks.
83101 +
83102 + If you enable none of the marking options then all applications
83103 + will run with PaX enabled on them by default.
83104 +
83105 +config PAX_PT_PAX_FLAGS
83106 + bool 'Use ELF program header marking'
83107 + default y if GRKERNSEC_CONFIG_AUTO
83108 + help
83109 + Enabling this option will allow you to control PaX features on
83110 + a per executable basis via the 'paxctl' utility available at
83111 + http://pax.grsecurity.net/. The control flags will be read from
83112 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
83113 + has the benefits of supporting both soft mode and being fully
83114 + integrated into the toolchain (the binutils patch is available
83115 + from http://pax.grsecurity.net).
83116 +
83117 + Note that if you enable the legacy EI_PAX marking support as well,
83118 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
83119 +
83120 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
83121 + must make sure that the marks are the same if a binary has both marks.
83122 +
83123 + If you enable none of the marking options then all applications
83124 + will run with PaX enabled on them by default.
83125 +
83126 +config PAX_XATTR_PAX_FLAGS
83127 + bool 'Use filesystem extended attributes marking'
83128 + default y if GRKERNSEC_CONFIG_AUTO
83129 + select CIFS_XATTR if CIFS
83130 + select EXT2_FS_XATTR if EXT2_FS
83131 + select EXT3_FS_XATTR if EXT3_FS
83132 + select EXT4_FS_XATTR if EXT4_FS
83133 + select JFFS2_FS_XATTR if JFFS2_FS
83134 + select REISERFS_FS_XATTR if REISERFS_FS
83135 + select SQUASHFS_XATTR if SQUASHFS
83136 + select TMPFS_XATTR if TMPFS
83137 + select UBIFS_FS_XATTR if UBIFS_FS
83138 + help
83139 + Enabling this option will allow you to control PaX features on
83140 + a per executable basis via the 'setfattr' utility. The control
83141 + flags will be read from the user.pax.flags extended attribute of
83142 + the file. This marking has the benefit of supporting binary-only
83143 + applications that self-check themselves (e.g., skype) and would
83144 + not tolerate chpax/paxctl changes. The main drawback is that
83145 + extended attributes are not supported by some filesystems (e.g.,
83146 + isofs, udf, vfat) so copying files through such filesystems will
83147 + lose the extended attributes and these PaX markings.
83148 +
83149 + Note that if you enable the legacy EI_PAX marking support as well,
83150 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
83151 +
83152 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
83153 + must make sure that the marks are the same if a binary has both marks.
83154 +
83155 + If you enable none of the marking options then all applications
83156 + will run with PaX enabled on them by default.
83157 +
83158 +choice
83159 + prompt 'MAC system integration'
83160 + default PAX_HAVE_ACL_FLAGS
83161 + help
83162 + Mandatory Access Control systems have the option of controlling
83163 + PaX flags on a per executable basis, choose the method supported
83164 + by your particular system.
83165 +
83166 + - "none": if your MAC system does not interact with PaX,
83167 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
83168 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
83169 +
83170 + NOTE: this option is for developers/integrators only.
83171 +
83172 + config PAX_NO_ACL_FLAGS
83173 + bool 'none'
83174 +
83175 + config PAX_HAVE_ACL_FLAGS
83176 + bool 'direct'
83177 +
83178 + config PAX_HOOK_ACL_FLAGS
83179 + bool 'hook'
83180 +endchoice
83181 +
83182 +endmenu
83183 +
83184 +menu "Non-executable pages"
83185 + depends on PAX
83186 +
83187 +config PAX_NOEXEC
83188 + bool "Enforce non-executable pages"
83189 + default y if GRKERNSEC_CONFIG_AUTO
83190 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
83191 + help
83192 + By design some architectures do not allow for protecting memory
83193 + pages against execution or even if they do, Linux does not make
83194 + use of this feature. In practice this means that if a page is
83195 + readable (such as the stack or heap) it is also executable.
83196 +
83197 + There is a well known exploit technique that makes use of this
83198 + fact and a common programming mistake where an attacker can
83199 + introduce code of his choice somewhere in the attacked program's
83200 + memory (typically the stack or the heap) and then execute it.
83201 +
83202 + If the attacked program was running with different (typically
83203 + higher) privileges than that of the attacker, then he can elevate
83204 + his own privilege level (e.g. get a root shell, write to files for
83205 + which he does not have write access to, etc).
83206 +
83207 + Enabling this option will let you choose from various features
83208 + that prevent the injection and execution of 'foreign' code in
83209 + a program.
83210 +
83211 + This will also break programs that rely on the old behaviour and
83212 + expect that dynamically allocated memory via the malloc() family
83213 + of functions is executable (which it is not). Notable examples
83214 + are the XFree86 4.x server, the java runtime and wine.
83215 +
83216 +config PAX_PAGEEXEC
83217 + bool "Paging based non-executable pages"
83218 + default y if GRKERNSEC_CONFIG_AUTO
83219 + 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)
83220 + select S390_SWITCH_AMODE if S390
83221 + select S390_EXEC_PROTECT if S390
83222 + select ARCH_TRACK_EXEC_LIMIT if X86_32
83223 + help
83224 + This implementation is based on the paging feature of the CPU.
83225 + On i386 without hardware non-executable bit support there is a
83226 + variable but usually low performance impact, however on Intel's
83227 + P4 core based CPUs it is very high so you should not enable this
83228 + for kernels meant to be used on such CPUs.
83229 +
83230 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
83231 + with hardware non-executable bit support there is no performance
83232 + impact, on ppc the impact is negligible.
83233 +
83234 + Note that several architectures require various emulations due to
83235 + badly designed userland ABIs, this will cause a performance impact
83236 + but will disappear as soon as userland is fixed. For example, ppc
83237 + userland MUST have been built with secure-plt by a recent toolchain.
83238 +
83239 +config PAX_SEGMEXEC
83240 + bool "Segmentation based non-executable pages"
83241 + default y if GRKERNSEC_CONFIG_AUTO
83242 + depends on PAX_NOEXEC && X86_32
83243 + help
83244 + This implementation is based on the segmentation feature of the
83245 + CPU and has a very small performance impact, however applications
83246 + will be limited to a 1.5 GB address space instead of the normal
83247 + 3 GB.
83248 +
83249 +config PAX_EMUTRAMP
83250 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
83251 + default y if PARISC
83252 + help
83253 + There are some programs and libraries that for one reason or
83254 + another attempt to execute special small code snippets from
83255 + non-executable memory pages. Most notable examples are the
83256 + signal handler return code generated by the kernel itself and
83257 + the GCC trampolines.
83258 +
83259 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
83260 + such programs will no longer work under your kernel.
83261 +
83262 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
83263 + utilities to enable trampoline emulation for the affected programs
83264 + yet still have the protection provided by the non-executable pages.
83265 +
83266 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
83267 + your system will not even boot.
83268 +
83269 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
83270 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
83271 + for the affected files.
83272 +
83273 + NOTE: enabling this feature *may* open up a loophole in the
83274 + protection provided by non-executable pages that an attacker
83275 + could abuse. Therefore the best solution is to not have any
83276 + files on your system that would require this option. This can
83277 + be achieved by not using libc5 (which relies on the kernel
83278 + signal handler return code) and not using or rewriting programs
83279 + that make use of the nested function implementation of GCC.
83280 + Skilled users can just fix GCC itself so that it implements
83281 + nested function calls in a way that does not interfere with PaX.
83282 +
83283 +config PAX_EMUSIGRT
83284 + bool "Automatically emulate sigreturn trampolines"
83285 + depends on PAX_EMUTRAMP && PARISC
83286 + default y
83287 + help
83288 + Enabling this option will have the kernel automatically detect
83289 + and emulate signal return trampolines executing on the stack
83290 + that would otherwise lead to task termination.
83291 +
83292 + This solution is intended as a temporary one for users with
83293 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
83294 + Modula-3 runtime, etc) or executables linked to such, basically
83295 + everything that does not specify its own SA_RESTORER function in
83296 + normal executable memory like glibc 2.1+ does.
83297 +
83298 + On parisc you MUST enable this option, otherwise your system will
83299 + not even boot.
83300 +
83301 + NOTE: this feature cannot be disabled on a per executable basis
83302 + and since it *does* open up a loophole in the protection provided
83303 + by non-executable pages, the best solution is to not have any
83304 + files on your system that would require this option.
83305 +
83306 +config PAX_MPROTECT
83307 + bool "Restrict mprotect()"
83308 + default y if GRKERNSEC_CONFIG_AUTO
83309 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
83310 + help
83311 + Enabling this option will prevent programs from
83312 + - changing the executable status of memory pages that were
83313 + not originally created as executable,
83314 + - making read-only executable pages writable again,
83315 + - creating executable pages from anonymous memory,
83316 + - making read-only-after-relocations (RELRO) data pages writable again.
83317 +
83318 + You should say Y here to complete the protection provided by
83319 + the enforcement of non-executable pages.
83320 +
83321 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
83322 + this feature on a per file basis.
83323 +
83324 +config PAX_MPROTECT_COMPAT
83325 + bool "Use legacy/compat protection demoting (read help)"
83326 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
83327 + depends on PAX_MPROTECT
83328 + help
83329 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
83330 + by sending the proper error code to the application. For some broken
83331 + userland, this can cause problems with Python or other applications. The
83332 + current implementation however allows for applications like clamav to
83333 + detect if JIT compilation/execution is allowed and to fall back gracefully
83334 + to an interpreter-based mode if it does not. While we encourage everyone
83335 + to use the current implementation as-is and push upstream to fix broken
83336 + userland (note that the RWX logging option can assist with this), in some
83337 + environments this may not be possible. Having to disable MPROTECT
83338 + completely on certain binaries reduces the security benefit of PaX,
83339 + so this option is provided for those environments to revert to the old
83340 + behavior.
83341 +
83342 +config PAX_ELFRELOCS
83343 + bool "Allow ELF text relocations (read help)"
83344 + depends on PAX_MPROTECT
83345 + default n
83346 + help
83347 + Non-executable pages and mprotect() restrictions are effective
83348 + in preventing the introduction of new executable code into an
83349 + attacked task's address space. There remain only two venues
83350 + for this kind of attack: if the attacker can execute already
83351 + existing code in the attacked task then he can either have it
83352 + create and mmap() a file containing his code or have it mmap()
83353 + an already existing ELF library that does not have position
83354 + independent code in it and use mprotect() on it to make it
83355 + writable and copy his code there. While protecting against
83356 + the former approach is beyond PaX, the latter can be prevented
83357 + by having only PIC ELF libraries on one's system (which do not
83358 + need to relocate their code). If you are sure this is your case,
83359 + as is the case with all modern Linux distributions, then leave
83360 + this option disabled. You should say 'n' here.
83361 +
83362 +config PAX_ETEXECRELOCS
83363 + bool "Allow ELF ET_EXEC text relocations"
83364 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
83365 + select PAX_ELFRELOCS
83366 + default y
83367 + help
83368 + On some architectures there are incorrectly created applications
83369 + that require text relocations and would not work without enabling
83370 + this option. If you are an alpha, ia64 or parisc user, you should
83371 + enable this option and disable it once you have made sure that
83372 + none of your applications need it.
83373 +
83374 +config PAX_EMUPLT
83375 + bool "Automatically emulate ELF PLT"
83376 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
83377 + default y
83378 + help
83379 + Enabling this option will have the kernel automatically detect
83380 + and emulate the Procedure Linkage Table entries in ELF files.
83381 + On some architectures such entries are in writable memory, and
83382 + become non-executable leading to task termination. Therefore
83383 + it is mandatory that you enable this option on alpha, parisc,
83384 + sparc and sparc64, otherwise your system would not even boot.
83385 +
83386 + NOTE: this feature *does* open up a loophole in the protection
83387 + provided by the non-executable pages, therefore the proper
83388 + solution is to modify the toolchain to produce a PLT that does
83389 + not need to be writable.
83390 +
83391 +config PAX_DLRESOLVE
83392 + bool 'Emulate old glibc resolver stub'
83393 + depends on PAX_EMUPLT && SPARC
83394 + default n
83395 + help
83396 + This option is needed if userland has an old glibc (before 2.4)
83397 + that puts a 'save' instruction into the runtime generated resolver
83398 + stub that needs special emulation.
83399 +
83400 +config PAX_KERNEXEC
83401 + bool "Enforce non-executable kernel pages"
83402 + 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))
83403 + depends on (X86 || ARM_LPAE) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
83404 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
83405 + select PAX_KERNEXEC_PLUGIN if X86_64
83406 + help
83407 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
83408 + that is, enabling this option will make it harder to inject
83409 + and execute 'foreign' code in kernel memory itself.
83410 +
83411 +choice
83412 + prompt "Return Address Instrumentation Method"
83413 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
83414 + depends on PAX_KERNEXEC_PLUGIN
83415 + help
83416 + Select the method used to instrument function pointer dereferences.
83417 + Note that binary modules cannot be instrumented by this approach.
83418 +
83419 + Note that the implementation requires a gcc with plugin support,
83420 + i.e., gcc 4.5 or newer. You may need to install the supporting
83421 + headers explicitly in addition to the normal gcc package.
83422 +
83423 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
83424 + bool "bts"
83425 + help
83426 + This method is compatible with binary only modules but has
83427 + a higher runtime overhead.
83428 +
83429 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
83430 + bool "or"
83431 + depends on !PARAVIRT
83432 + help
83433 + This method is incompatible with binary only modules but has
83434 + a lower runtime overhead.
83435 +endchoice
83436 +
83437 +config PAX_KERNEXEC_PLUGIN_METHOD
83438 + string
83439 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
83440 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
83441 + default ""
83442 +
83443 +config PAX_KERNEXEC_MODULE_TEXT
83444 + int "Minimum amount of memory reserved for module code"
83445 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
83446 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
83447 + depends on PAX_KERNEXEC && X86_32 && MODULES
83448 + help
83449 + Due to implementation details the kernel must reserve a fixed
83450 + amount of memory for module code at compile time that cannot be
83451 + changed at runtime. Here you can specify the minimum amount
83452 + in MB that will be reserved. Due to the same implementation
83453 + details this size will always be rounded up to the next 2/4 MB
83454 + boundary (depends on PAE) so the actually available memory for
83455 + module code will usually be more than this minimum.
83456 +
83457 + The default 4 MB should be enough for most users but if you have
83458 + an excessive number of modules (e.g., most distribution configs
83459 + compile many drivers as modules) or use huge modules such as
83460 + nvidia's kernel driver, you will need to adjust this amount.
83461 + A good rule of thumb is to look at your currently loaded kernel
83462 + modules and add up their sizes.
83463 +
83464 +endmenu
83465 +
83466 +menu "Address Space Layout Randomization"
83467 + depends on PAX
83468 +
83469 +config PAX_ASLR
83470 + bool "Address Space Layout Randomization"
83471 + default y if GRKERNSEC_CONFIG_AUTO
83472 + help
83473 + Many if not most exploit techniques rely on the knowledge of
83474 + certain addresses in the attacked program. The following options
83475 + will allow the kernel to apply a certain amount of randomization
83476 + to specific parts of the program thereby forcing an attacker to
83477 + guess them in most cases. Any failed guess will most likely crash
83478 + the attacked program which allows the kernel to detect such attempts
83479 + and react on them. PaX itself provides no reaction mechanisms,
83480 + instead it is strongly encouraged that you make use of Nergal's
83481 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
83482 + (http://www.grsecurity.net/) built-in crash detection features or
83483 + develop one yourself.
83484 +
83485 + By saying Y here you can choose to randomize the following areas:
83486 + - top of the task's kernel stack
83487 + - top of the task's userland stack
83488 + - base address for mmap() requests that do not specify one
83489 + (this includes all libraries)
83490 + - base address of the main executable
83491 +
83492 + It is strongly recommended to say Y here as address space layout
83493 + randomization has negligible impact on performance yet it provides
83494 + a very effective protection.
83495 +
83496 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
83497 + this feature on a per file basis.
83498 +
83499 +config PAX_RANDKSTACK
83500 + bool "Randomize kernel stack base"
83501 + default y if GRKERNSEC_CONFIG_AUTO
83502 + depends on X86_TSC && X86
83503 + help
83504 + By saying Y here the kernel will randomize every task's kernel
83505 + stack on every system call. This will not only force an attacker
83506 + to guess it but also prevent him from making use of possible
83507 + leaked information about it.
83508 +
83509 + Since the kernel stack is a rather scarce resource, randomization
83510 + may cause unexpected stack overflows, therefore you should very
83511 + carefully test your system. Note that once enabled in the kernel
83512 + configuration, this feature cannot be disabled on a per file basis.
83513 +
83514 +config PAX_RANDUSTACK
83515 + bool "Randomize user stack base"
83516 + default y if GRKERNSEC_CONFIG_AUTO
83517 + depends on PAX_ASLR
83518 + help
83519 + By saying Y here the kernel will randomize every task's userland
83520 + stack. The randomization is done in two steps where the second
83521 + one may apply a big amount of shift to the top of the stack and
83522 + cause problems for programs that want to use lots of memory (more
83523 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
83524 + For this reason the second step can be controlled by 'chpax' or
83525 + 'paxctl' on a per file basis.
83526 +
83527 +config PAX_RANDMMAP
83528 + bool "Randomize mmap() base"
83529 + default y if GRKERNSEC_CONFIG_AUTO
83530 + depends on PAX_ASLR
83531 + help
83532 + By saying Y here the kernel will use a randomized base address for
83533 + mmap() requests that do not specify one themselves. As a result
83534 + all dynamically loaded libraries will appear at random addresses
83535 + and therefore be harder to exploit by a technique where an attacker
83536 + attempts to execute library code for his purposes (e.g. spawn a
83537 + shell from an exploited program that is running at an elevated
83538 + privilege level).
83539 +
83540 + Furthermore, if a program is relinked as a dynamic ELF file, its
83541 + base address will be randomized as well, completing the full
83542 + randomization of the address space layout. Attacking such programs
83543 + becomes a guess game. You can find an example of doing this at
83544 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
83545 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
83546 +
83547 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
83548 + feature on a per file basis.
83549 +
83550 +endmenu
83551 +
83552 +menu "Miscellaneous hardening features"
83553 +
83554 +config PAX_MEMORY_SANITIZE
83555 + bool "Sanitize all freed memory"
83556 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
83557 + depends on !HIBERNATION
83558 + help
83559 + By saying Y here the kernel will erase memory pages as soon as they
83560 + are freed. This in turn reduces the lifetime of data stored in the
83561 + pages, making it less likely that sensitive information such as
83562 + passwords, cryptographic secrets, etc stay in memory for too long.
83563 +
83564 + This is especially useful for programs whose runtime is short, long
83565 + lived processes and the kernel itself benefit from this as long as
83566 + they operate on whole memory pages and ensure timely freeing of pages
83567 + that may hold sensitive information.
83568 +
83569 + The tradeoff is performance impact, on a single CPU system kernel
83570 + compilation sees a 3% slowdown, other systems and workloads may vary
83571 + and you are advised to test this feature on your expected workload
83572 + before deploying it.
83573 +
83574 + Note that this feature does not protect data stored in live pages,
83575 + e.g., process memory swapped to disk may stay there for a long time.
83576 +
83577 +config PAX_MEMORY_STACKLEAK
83578 + bool "Sanitize kernel stack"
83579 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
83580 + depends on X86
83581 + help
83582 + By saying Y here the kernel will erase the kernel stack before it
83583 + returns from a system call. This in turn reduces the information
83584 + that a kernel stack leak bug can reveal.
83585 +
83586 + Note that such a bug can still leak information that was put on
83587 + the stack by the current system call (the one eventually triggering
83588 + the bug) but traces of earlier system calls on the kernel stack
83589 + cannot leak anymore.
83590 +
83591 + The tradeoff is performance impact: on a single CPU system kernel
83592 + compilation sees a 1% slowdown, other systems and workloads may vary
83593 + and you are advised to test this feature on your expected workload
83594 + before deploying it.
83595 +
83596 + Note that the full feature requires a gcc with plugin support,
83597 + i.e., gcc 4.5 or newer. You may need to install the supporting
83598 + headers explicitly in addition to the normal gcc package. Using
83599 + older gcc versions means that functions with large enough stack
83600 + frames may leave uninitialized memory behind that may be exposed
83601 + to a later syscall leaking the stack.
83602 +
83603 +config PAX_MEMORY_UDEREF
83604 + bool "Prevent invalid userland pointer dereference"
83605 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
83606 + depends on X86 && !UML_X86 && !XEN
83607 + select PAX_PER_CPU_PGD if X86_64
83608 + help
83609 + By saying Y here the kernel will be prevented from dereferencing
83610 + userland pointers in contexts where the kernel expects only kernel
83611 + pointers. This is both a useful runtime debugging feature and a
83612 + security measure that prevents exploiting a class of kernel bugs.
83613 +
83614 + The tradeoff is that some virtualization solutions may experience
83615 + a huge slowdown and therefore you should not enable this feature
83616 + for kernels meant to run in such environments. Whether a given VM
83617 + solution is affected or not is best determined by simply trying it
83618 + out, the performance impact will be obvious right on boot as this
83619 + mechanism engages from very early on. A good rule of thumb is that
83620 + VMs running on CPUs without hardware virtualization support (i.e.,
83621 + the majority of IA-32 CPUs) will likely experience the slowdown.
83622 +
83623 +config PAX_REFCOUNT
83624 + bool "Prevent various kernel object reference counter overflows"
83625 + default y if GRKERNSEC_CONFIG_AUTO
83626 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
83627 + help
83628 + By saying Y here the kernel will detect and prevent overflowing
83629 + various (but not all) kinds of object reference counters. Such
83630 + overflows can normally occur due to bugs only and are often, if
83631 + not always, exploitable.
83632 +
83633 + The tradeoff is that data structures protected by an overflowed
83634 + refcount will never be freed and therefore will leak memory. Note
83635 + that this leak also happens even without this protection but in
83636 + that case the overflow can eventually trigger the freeing of the
83637 + data structure while it is still being used elsewhere, resulting
83638 + in the exploitable situation that this feature prevents.
83639 +
83640 + Since this has a negligible performance impact, you should enable
83641 + this feature.
83642 +
83643 +config PAX_USERCOPY
83644 + bool "Harden heap object copies between kernel and userland"
83645 + default y if GRKERNSEC_CONFIG_AUTO
83646 + depends on ARM || IA64 || PPC || SPARC || X86
83647 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
83648 + select PAX_USERCOPY_SLABS
83649 + help
83650 + By saying Y here the kernel will enforce the size of heap objects
83651 + when they are copied in either direction between the kernel and
83652 + userland, even if only a part of the heap object is copied.
83653 +
83654 + Specifically, this checking prevents information leaking from the
83655 + kernel heap during kernel to userland copies (if the kernel heap
83656 + object is otherwise fully initialized) and prevents kernel heap
83657 + overflows during userland to kernel copies.
83658 +
83659 + Note that the current implementation provides the strictest bounds
83660 + checks for the SLUB allocator.
83661 +
83662 + Enabling this option also enables per-slab cache protection against
83663 + data in a given cache being copied into/out of via userland
83664 + accessors. Though the whitelist of regions will be reduced over
83665 + time, it notably protects important data structures like task structs.
83666 +
83667 + If frame pointers are enabled on x86, this option will also restrict
83668 + copies into and out of the kernel stack to local variables within a
83669 + single frame.
83670 +
83671 + Since this has a negligible performance impact, you should enable
83672 + this feature.
83673 +
83674 +
83675 +config PAX_USERCOPY_DEBUG
83676 + bool
83677 + depends on X86 && PAX_USERCOPY
83678 + default n
83679 +
83680 +config PAX_SIZE_OVERFLOW
83681 + bool "Prevent various integer overflows in function size parameters"
83682 + default y if GRKERNSEC_CONFIG_AUTO
83683 + depends on X86
83684 + help
83685 + By saying Y here the kernel recomputes expressions of function
83686 + arguments marked by a size_overflow attribute with double integer
83687 + precision (DImode/TImode for 32/64 bit integer types).
83688 +
83689 + The recomputed argument is checked against TYPE_MAX and an event
83690 + is logged on overflow and the triggering process is killed.
83691 +
83692 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
83693 +
83694 + Note that the implementation requires a gcc with plugin support,
83695 + i.e., gcc 4.5 or newer. You may need to install the supporting
83696 + headers explicitly in addition to the normal gcc package.
83697 +
83698 +config PAX_LATENT_ENTROPY
83699 + bool "Generate some entropy during boot"
83700 + default y if GRKERNSEC_CONFIG_AUTO
83701 + help
83702 + By saying Y here the kernel will instrument early boot code to
83703 + extract some entropy from both original and artificially created
83704 + program state. This will help especially embedded systems where
83705 + there is little 'natural' source of entropy normally. The cost
83706 + is some slowdown of the boot process.
83707 +
83708 + Note that the implementation requires a gcc with plugin support,
83709 + i.e., gcc 4.5 or newer. You may need to install the supporting
83710 + headers explicitly in addition to the normal gcc package.
83711 +
83712 + Note that entropy extracted this way is not cryptographically
83713 + secure!
83714 +
83715 +endmenu
83716 +
83717 +endmenu
83718 +
83719 +source grsecurity/Kconfig
83720 +
83721 +endmenu
83722 +
83723 +endmenu
83724 +
83725 source security/keys/Kconfig
83726
83727 config SECURITY_DMESG_RESTRICT
83728 @@ -103,7 +999,7 @@ config INTEL_TXT
83729 config LSM_MMAP_MIN_ADDR
83730 int "Low address space for LSM to protect from user allocation"
83731 depends on SECURITY && SECURITY_SELINUX
83732 - default 32768 if ARM
83733 + default 32768 if ALPHA || ARM || PARISC || SPARC32
83734 default 65536
83735 help
83736 This is the portion of low virtual memory which should be protected
83737 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
83738 index 8c2a7f6..b133ac9 100644
83739 --- a/security/apparmor/lsm.c
83740 +++ b/security/apparmor/lsm.c
83741 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
83742 return error;
83743 }
83744
83745 -static struct security_operations apparmor_ops = {
83746 +static struct security_operations apparmor_ops __read_only = {
83747 .name = "apparmor",
83748
83749 .ptrace_access_check = apparmor_ptrace_access_check,
83750 diff --git a/security/commoncap.c b/security/commoncap.c
83751 index 6dbae46..d5611fd 100644
83752 --- a/security/commoncap.c
83753 +++ b/security/commoncap.c
83754 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
83755 return 0;
83756 }
83757
83758 +/* returns:
83759 + 1 for suid privilege
83760 + 2 for sgid privilege
83761 + 3 for fscap privilege
83762 +*/
83763 +int is_privileged_binary(const struct dentry *dentry)
83764 +{
83765 + struct cpu_vfs_cap_data capdata;
83766 + struct inode *inode = dentry->d_inode;
83767 +
83768 + if (!inode || S_ISDIR(inode->i_mode))
83769 + return 0;
83770 +
83771 + if (inode->i_mode & S_ISUID)
83772 + return 1;
83773 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
83774 + return 2;
83775 +
83776 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
83777 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
83778 + return 3;
83779 + }
83780 +
83781 + return 0;
83782 +}
83783 +
83784 /*
83785 * Attempt to get the on-exec apply capability sets for an executable file from
83786 * its xattrs and, if present, apply them to the proposed credentials being
83787 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
83788 const struct cred *cred = current_cred();
83789 kuid_t root_uid = make_kuid(cred->user_ns, 0);
83790
83791 + if (gr_acl_enable_at_secure())
83792 + return 1;
83793 +
83794 if (!uid_eq(cred->uid, root_uid)) {
83795 if (bprm->cap_effective)
83796 return 1;
83797 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
83798 index 6ee8826..6350060 100644
83799 --- a/security/integrity/ima/ima.h
83800 +++ b/security/integrity/ima/ima.h
83801 @@ -96,8 +96,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
83802 extern spinlock_t ima_queue_lock;
83803
83804 struct ima_h_table {
83805 - atomic_long_t len; /* number of stored measurements in the list */
83806 - atomic_long_t violations;
83807 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
83808 + atomic_long_unchecked_t violations;
83809 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
83810 };
83811 extern struct ima_h_table ima_htable;
83812 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
83813 index b356884..fd9676e 100644
83814 --- a/security/integrity/ima/ima_api.c
83815 +++ b/security/integrity/ima/ima_api.c
83816 @@ -79,7 +79,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
83817 int result;
83818
83819 /* can overflow, only indicator */
83820 - atomic_long_inc(&ima_htable.violations);
83821 + atomic_long_inc_unchecked(&ima_htable.violations);
83822
83823 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
83824 if (!entry) {
83825 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
83826 index 38477c9..87a60c7 100644
83827 --- a/security/integrity/ima/ima_fs.c
83828 +++ b/security/integrity/ima/ima_fs.c
83829 @@ -28,12 +28,12 @@
83830 static int valid_policy = 1;
83831 #define TMPBUFLEN 12
83832 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
83833 - loff_t *ppos, atomic_long_t *val)
83834 + loff_t *ppos, atomic_long_unchecked_t *val)
83835 {
83836 char tmpbuf[TMPBUFLEN];
83837 ssize_t len;
83838
83839 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
83840 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
83841 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
83842 }
83843
83844 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
83845 index 55a6271..ad829c3 100644
83846 --- a/security/integrity/ima/ima_queue.c
83847 +++ b/security/integrity/ima/ima_queue.c
83848 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
83849 INIT_LIST_HEAD(&qe->later);
83850 list_add_tail_rcu(&qe->later, &ima_measurements);
83851
83852 - atomic_long_inc(&ima_htable.len);
83853 + atomic_long_inc_unchecked(&ima_htable.len);
83854 key = ima_hash_key(entry->digest);
83855 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
83856 return 0;
83857 diff --git a/security/keys/compat.c b/security/keys/compat.c
83858 index 1c26176..64a1ba2 100644
83859 --- a/security/keys/compat.c
83860 +++ b/security/keys/compat.c
83861 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
83862 if (ret == 0)
83863 goto no_payload_free;
83864
83865 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
83866 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
83867
83868 if (iov != iovstack)
83869 kfree(iov);
83870 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
83871 index 5d34b4e..2456674 100644
83872 --- a/security/keys/keyctl.c
83873 +++ b/security/keys/keyctl.c
83874 @@ -986,7 +986,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
83875 /*
83876 * Copy the iovec data from userspace
83877 */
83878 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
83879 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
83880 unsigned ioc)
83881 {
83882 for (; ioc > 0; ioc--) {
83883 @@ -1008,7 +1008,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
83884 * If successful, 0 will be returned.
83885 */
83886 long keyctl_instantiate_key_common(key_serial_t id,
83887 - const struct iovec *payload_iov,
83888 + const struct iovec __user *payload_iov,
83889 unsigned ioc,
83890 size_t plen,
83891 key_serial_t ringid)
83892 @@ -1103,7 +1103,7 @@ long keyctl_instantiate_key(key_serial_t id,
83893 [0].iov_len = plen
83894 };
83895
83896 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
83897 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
83898 }
83899
83900 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
83901 @@ -1136,7 +1136,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
83902 if (ret == 0)
83903 goto no_payload_free;
83904
83905 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
83906 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
83907
83908 if (iov != iovstack)
83909 kfree(iov);
83910 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
83911 index 6e42df1..aba52bd 100644
83912 --- a/security/keys/keyring.c
83913 +++ b/security/keys/keyring.c
83914 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
83915 ret = -EFAULT;
83916
83917 for (loop = 0; loop < klist->nkeys; loop++) {
83918 + key_serial_t serial;
83919 key = rcu_deref_link_locked(klist, loop,
83920 keyring);
83921 + serial = key->serial;
83922
83923 tmp = sizeof(key_serial_t);
83924 if (tmp > buflen)
83925 tmp = buflen;
83926
83927 - if (copy_to_user(buffer,
83928 - &key->serial,
83929 - tmp) != 0)
83930 + if (copy_to_user(buffer, &serial, tmp))
83931 goto error;
83932
83933 buflen -= tmp;
83934 diff --git a/security/min_addr.c b/security/min_addr.c
83935 index f728728..6457a0c 100644
83936 --- a/security/min_addr.c
83937 +++ b/security/min_addr.c
83938 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
83939 */
83940 static void update_mmap_min_addr(void)
83941 {
83942 +#ifndef SPARC
83943 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
83944 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
83945 mmap_min_addr = dac_mmap_min_addr;
83946 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
83947 #else
83948 mmap_min_addr = dac_mmap_min_addr;
83949 #endif
83950 +#endif
83951 }
83952
83953 /*
83954 diff --git a/security/security.c b/security/security.c
83955 index 8dcd4ae..1124de7 100644
83956 --- a/security/security.c
83957 +++ b/security/security.c
83958 @@ -20,6 +20,7 @@
83959 #include <linux/ima.h>
83960 #include <linux/evm.h>
83961 #include <linux/fsnotify.h>
83962 +#include <linux/mm.h>
83963 #include <linux/mman.h>
83964 #include <linux/mount.h>
83965 #include <linux/personality.h>
83966 @@ -32,8 +33,8 @@
83967 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
83968 CONFIG_DEFAULT_SECURITY;
83969
83970 -static struct security_operations *security_ops;
83971 -static struct security_operations default_security_ops = {
83972 +static struct security_operations *security_ops __read_only;
83973 +static struct security_operations default_security_ops __read_only = {
83974 .name = "default",
83975 };
83976
83977 @@ -74,7 +75,9 @@ int __init security_init(void)
83978
83979 void reset_security_ops(void)
83980 {
83981 + pax_open_kernel();
83982 security_ops = &default_security_ops;
83983 + pax_close_kernel();
83984 }
83985
83986 /* Save user chosen LSM */
83987 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
83988 index 61a5336..27215d8 100644
83989 --- a/security/selinux/hooks.c
83990 +++ b/security/selinux/hooks.c
83991 @@ -95,8 +95,6 @@
83992
83993 #define NUM_SEL_MNT_OPTS 5
83994
83995 -extern struct security_operations *security_ops;
83996 -
83997 /* SECMARK reference count */
83998 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
83999
84000 @@ -5476,7 +5474,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
84001
84002 #endif
84003
84004 -static struct security_operations selinux_ops = {
84005 +static struct security_operations selinux_ops __read_only = {
84006 .name = "selinux",
84007
84008 .ptrace_access_check = selinux_ptrace_access_check,
84009 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
84010 index 65f67cb..3f141ef 100644
84011 --- a/security/selinux/include/xfrm.h
84012 +++ b/security/selinux/include/xfrm.h
84013 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
84014
84015 static inline void selinux_xfrm_notify_policyload(void)
84016 {
84017 - atomic_inc(&flow_cache_genid);
84018 + atomic_inc_unchecked(&flow_cache_genid);
84019 rt_genid_bump(&init_net);
84020 }
84021 #else
84022 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
84023 index 38be92c..21f49ee 100644
84024 --- a/security/smack/smack_lsm.c
84025 +++ b/security/smack/smack_lsm.c
84026 @@ -3398,7 +3398,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
84027 return 0;
84028 }
84029
84030 -struct security_operations smack_ops = {
84031 +struct security_operations smack_ops __read_only = {
84032 .name = "smack",
84033
84034 .ptrace_access_check = smack_ptrace_access_check,
84035 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
84036 index a2ee362..5754f34 100644
84037 --- a/security/tomoyo/tomoyo.c
84038 +++ b/security/tomoyo/tomoyo.c
84039 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
84040 * tomoyo_security_ops is a "struct security_operations" which is used for
84041 * registering TOMOYO.
84042 */
84043 -static struct security_operations tomoyo_security_ops = {
84044 +static struct security_operations tomoyo_security_ops __read_only = {
84045 .name = "tomoyo",
84046 .cred_alloc_blank = tomoyo_cred_alloc_blank,
84047 .cred_prepare = tomoyo_cred_prepare,
84048 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
84049 index 20ef514..4182bed 100644
84050 --- a/security/yama/Kconfig
84051 +++ b/security/yama/Kconfig
84052 @@ -1,6 +1,6 @@
84053 config SECURITY_YAMA
84054 bool "Yama support"
84055 - depends on SECURITY
84056 + depends on SECURITY && !GRKERNSEC
84057 select SECURITYFS
84058 select SECURITY_PATH
84059 default n
84060 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
84061 index 4cedc69..e59d8a3 100644
84062 --- a/sound/aoa/codecs/onyx.c
84063 +++ b/sound/aoa/codecs/onyx.c
84064 @@ -54,7 +54,7 @@ struct onyx {
84065 spdif_locked:1,
84066 analog_locked:1,
84067 original_mute:2;
84068 - int open_count;
84069 + local_t open_count;
84070 struct codec_info *codec_info;
84071
84072 /* mutex serializes concurrent access to the device
84073 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
84074 struct onyx *onyx = cii->codec_data;
84075
84076 mutex_lock(&onyx->mutex);
84077 - onyx->open_count++;
84078 + local_inc(&onyx->open_count);
84079 mutex_unlock(&onyx->mutex);
84080
84081 return 0;
84082 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
84083 struct onyx *onyx = cii->codec_data;
84084
84085 mutex_lock(&onyx->mutex);
84086 - onyx->open_count--;
84087 - if (!onyx->open_count)
84088 + if (local_dec_and_test(&onyx->open_count))
84089 onyx->spdif_locked = onyx->analog_locked = 0;
84090 mutex_unlock(&onyx->mutex);
84091
84092 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
84093 index ffd2025..df062c9 100644
84094 --- a/sound/aoa/codecs/onyx.h
84095 +++ b/sound/aoa/codecs/onyx.h
84096 @@ -11,6 +11,7 @@
84097 #include <linux/i2c.h>
84098 #include <asm/pmac_low_i2c.h>
84099 #include <asm/prom.h>
84100 +#include <asm/local.h>
84101
84102 /* PCM3052 register definitions */
84103
84104 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
84105 index 4c1cc51..16040040 100644
84106 --- a/sound/core/oss/pcm_oss.c
84107 +++ b/sound/core/oss/pcm_oss.c
84108 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
84109 if (in_kernel) {
84110 mm_segment_t fs;
84111 fs = snd_enter_user();
84112 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
84113 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
84114 snd_leave_user(fs);
84115 } else {
84116 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
84117 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
84118 }
84119 if (ret != -EPIPE && ret != -ESTRPIPE)
84120 break;
84121 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
84122 if (in_kernel) {
84123 mm_segment_t fs;
84124 fs = snd_enter_user();
84125 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
84126 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
84127 snd_leave_user(fs);
84128 } else {
84129 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
84130 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
84131 }
84132 if (ret == -EPIPE) {
84133 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
84134 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
84135 struct snd_pcm_plugin_channel *channels;
84136 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
84137 if (!in_kernel) {
84138 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
84139 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
84140 return -EFAULT;
84141 buf = runtime->oss.buffer;
84142 }
84143 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
84144 }
84145 } else {
84146 tmp = snd_pcm_oss_write2(substream,
84147 - (const char __force *)buf,
84148 + (const char __force_kernel *)buf,
84149 runtime->oss.period_bytes, 0);
84150 if (tmp <= 0)
84151 goto err;
84152 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
84153 struct snd_pcm_runtime *runtime = substream->runtime;
84154 snd_pcm_sframes_t frames, frames1;
84155 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
84156 - char __user *final_dst = (char __force __user *)buf;
84157 + char __user *final_dst = (char __force_user *)buf;
84158 if (runtime->oss.plugin_first) {
84159 struct snd_pcm_plugin_channel *channels;
84160 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
84161 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
84162 xfer += tmp;
84163 runtime->oss.buffer_used -= tmp;
84164 } else {
84165 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
84166 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
84167 runtime->oss.period_bytes, 0);
84168 if (tmp <= 0)
84169 goto err;
84170 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
84171 size1);
84172 size1 /= runtime->channels; /* frames */
84173 fs = snd_enter_user();
84174 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
84175 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
84176 snd_leave_user(fs);
84177 }
84178 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
84179 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
84180 index 91cdf943..4085161 100644
84181 --- a/sound/core/pcm_compat.c
84182 +++ b/sound/core/pcm_compat.c
84183 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
84184 int err;
84185
84186 fs = snd_enter_user();
84187 - err = snd_pcm_delay(substream, &delay);
84188 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
84189 snd_leave_user(fs);
84190 if (err < 0)
84191 return err;
84192 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
84193 index f9ddecf..e27404d 100644
84194 --- a/sound/core/pcm_native.c
84195 +++ b/sound/core/pcm_native.c
84196 @@ -2804,11 +2804,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
84197 switch (substream->stream) {
84198 case SNDRV_PCM_STREAM_PLAYBACK:
84199 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
84200 - (void __user *)arg);
84201 + (void __force_user *)arg);
84202 break;
84203 case SNDRV_PCM_STREAM_CAPTURE:
84204 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
84205 - (void __user *)arg);
84206 + (void __force_user *)arg);
84207 break;
84208 default:
84209 result = -EINVAL;
84210 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
84211 index 60e8fc1..786abcb 100644
84212 --- a/sound/core/seq/seq_device.c
84213 +++ b/sound/core/seq/seq_device.c
84214 @@ -64,7 +64,7 @@ struct ops_list {
84215 int argsize; /* argument size */
84216
84217 /* operators */
84218 - struct snd_seq_dev_ops ops;
84219 + struct snd_seq_dev_ops *ops;
84220
84221 /* registred devices */
84222 struct list_head dev_list; /* list of devices */
84223 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
84224
84225 mutex_lock(&ops->reg_mutex);
84226 /* copy driver operators */
84227 - ops->ops = *entry;
84228 + ops->ops = entry;
84229 ops->driver |= DRIVER_LOADED;
84230 ops->argsize = argsize;
84231
84232 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
84233 dev->name, ops->id, ops->argsize, dev->argsize);
84234 return -EINVAL;
84235 }
84236 - if (ops->ops.init_device(dev) >= 0) {
84237 + if (ops->ops->init_device(dev) >= 0) {
84238 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
84239 ops->num_init_devices++;
84240 } else {
84241 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
84242 dev->name, ops->id, ops->argsize, dev->argsize);
84243 return -EINVAL;
84244 }
84245 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
84246 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
84247 dev->status = SNDRV_SEQ_DEVICE_FREE;
84248 dev->driver_data = NULL;
84249 ops->num_init_devices--;
84250 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
84251 index 2d5514b..3afae9c 100644
84252 --- a/sound/drivers/mts64.c
84253 +++ b/sound/drivers/mts64.c
84254 @@ -29,6 +29,7 @@
84255 #include <sound/initval.h>
84256 #include <sound/rawmidi.h>
84257 #include <sound/control.h>
84258 +#include <asm/local.h>
84259
84260 #define CARD_NAME "Miditerminal 4140"
84261 #define DRIVER_NAME "MTS64"
84262 @@ -67,7 +68,7 @@ struct mts64 {
84263 struct pardevice *pardev;
84264 int pardev_claimed;
84265
84266 - int open_count;
84267 + local_t open_count;
84268 int current_midi_output_port;
84269 int current_midi_input_port;
84270 u8 mode[MTS64_NUM_INPUT_PORTS];
84271 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
84272 {
84273 struct mts64 *mts = substream->rmidi->private_data;
84274
84275 - if (mts->open_count == 0) {
84276 + if (local_read(&mts->open_count) == 0) {
84277 /* We don't need a spinlock here, because this is just called
84278 if the device has not been opened before.
84279 So there aren't any IRQs from the device */
84280 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
84281
84282 msleep(50);
84283 }
84284 - ++(mts->open_count);
84285 + local_inc(&mts->open_count);
84286
84287 return 0;
84288 }
84289 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
84290 struct mts64 *mts = substream->rmidi->private_data;
84291 unsigned long flags;
84292
84293 - --(mts->open_count);
84294 - if (mts->open_count == 0) {
84295 + if (local_dec_return(&mts->open_count) == 0) {
84296 /* We need the spinlock_irqsave here because we can still
84297 have IRQs at this point */
84298 spin_lock_irqsave(&mts->lock, flags);
84299 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
84300
84301 msleep(500);
84302
84303 - } else if (mts->open_count < 0)
84304 - mts->open_count = 0;
84305 + } else if (local_read(&mts->open_count) < 0)
84306 + local_set(&mts->open_count, 0);
84307
84308 return 0;
84309 }
84310 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
84311 index b953fb4..1999c01 100644
84312 --- a/sound/drivers/opl4/opl4_lib.c
84313 +++ b/sound/drivers/opl4/opl4_lib.c
84314 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
84315 MODULE_DESCRIPTION("OPL4 driver");
84316 MODULE_LICENSE("GPL");
84317
84318 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
84319 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
84320 {
84321 int timeout = 10;
84322 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
84323 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
84324 index 8364855..59f2e2b 100644
84325 --- a/sound/drivers/portman2x4.c
84326 +++ b/sound/drivers/portman2x4.c
84327 @@ -48,6 +48,7 @@
84328 #include <sound/initval.h>
84329 #include <sound/rawmidi.h>
84330 #include <sound/control.h>
84331 +#include <asm/local.h>
84332
84333 #define CARD_NAME "Portman 2x4"
84334 #define DRIVER_NAME "portman"
84335 @@ -85,7 +86,7 @@ struct portman {
84336 struct pardevice *pardev;
84337 int pardev_claimed;
84338
84339 - int open_count;
84340 + local_t open_count;
84341 int mode[PORTMAN_NUM_INPUT_PORTS];
84342 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
84343 };
84344 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
84345 index ea995af..f1bfa37 100644
84346 --- a/sound/firewire/amdtp.c
84347 +++ b/sound/firewire/amdtp.c
84348 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
84349 ptr = s->pcm_buffer_pointer + data_blocks;
84350 if (ptr >= pcm->runtime->buffer_size)
84351 ptr -= pcm->runtime->buffer_size;
84352 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
84353 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
84354
84355 s->pcm_period_pointer += data_blocks;
84356 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
84357 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
84358 */
84359 void amdtp_out_stream_update(struct amdtp_out_stream *s)
84360 {
84361 - ACCESS_ONCE(s->source_node_id_field) =
84362 + ACCESS_ONCE_RW(s->source_node_id_field) =
84363 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
84364 }
84365 EXPORT_SYMBOL(amdtp_out_stream_update);
84366 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
84367 index b680c5e..061b7a0 100644
84368 --- a/sound/firewire/amdtp.h
84369 +++ b/sound/firewire/amdtp.h
84370 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
84371 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
84372 struct snd_pcm_substream *pcm)
84373 {
84374 - ACCESS_ONCE(s->pcm) = pcm;
84375 + ACCESS_ONCE_RW(s->pcm) = pcm;
84376 }
84377
84378 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
84379 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
84380 index d428ffe..751ef78 100644
84381 --- a/sound/firewire/isight.c
84382 +++ b/sound/firewire/isight.c
84383 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
84384 ptr += count;
84385 if (ptr >= runtime->buffer_size)
84386 ptr -= runtime->buffer_size;
84387 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
84388 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
84389
84390 isight->period_counter += count;
84391 if (isight->period_counter >= runtime->period_size) {
84392 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
84393 if (err < 0)
84394 return err;
84395
84396 - ACCESS_ONCE(isight->pcm_active) = true;
84397 + ACCESS_ONCE_RW(isight->pcm_active) = true;
84398
84399 return 0;
84400 }
84401 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
84402 {
84403 struct isight *isight = substream->private_data;
84404
84405 - ACCESS_ONCE(isight->pcm_active) = false;
84406 + ACCESS_ONCE_RW(isight->pcm_active) = false;
84407
84408 mutex_lock(&isight->mutex);
84409 isight_stop_streaming(isight);
84410 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
84411
84412 switch (cmd) {
84413 case SNDRV_PCM_TRIGGER_START:
84414 - ACCESS_ONCE(isight->pcm_running) = true;
84415 + ACCESS_ONCE_RW(isight->pcm_running) = true;
84416 break;
84417 case SNDRV_PCM_TRIGGER_STOP:
84418 - ACCESS_ONCE(isight->pcm_running) = false;
84419 + ACCESS_ONCE_RW(isight->pcm_running) = false;
84420 break;
84421 default:
84422 return -EINVAL;
84423 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
84424 index b2b3c01..e1c1e1f 100644
84425 --- a/sound/oss/sb_audio.c
84426 +++ b/sound/oss/sb_audio.c
84427 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
84428 buf16 = (signed short *)(localbuf + localoffs);
84429 while (c)
84430 {
84431 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
84432 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
84433 if (copy_from_user(lbuf8,
84434 userbuf+useroffs + p,
84435 locallen))
84436 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
84437 index 7d8803a..559f8d0 100644
84438 --- a/sound/oss/swarm_cs4297a.c
84439 +++ b/sound/oss/swarm_cs4297a.c
84440 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
84441 {
84442 struct cs4297a_state *s;
84443 u32 pwr, id;
84444 - mm_segment_t fs;
84445 int rval;
84446 #ifndef CONFIG_BCM_CS4297A_CSWARM
84447 u64 cfg;
84448 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
84449 if (!rval) {
84450 char *sb1250_duart_present;
84451
84452 +#if 0
84453 + mm_segment_t fs;
84454 fs = get_fs();
84455 set_fs(KERNEL_DS);
84456 -#if 0
84457 val = SOUND_MASK_LINE;
84458 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
84459 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
84460 val = initvol[i].vol;
84461 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
84462 }
84463 + set_fs(fs);
84464 // cs4297a_write_ac97(s, 0x18, 0x0808);
84465 #else
84466 // cs4297a_write_ac97(s, 0x5e, 0x180);
84467 cs4297a_write_ac97(s, 0x02, 0x0808);
84468 cs4297a_write_ac97(s, 0x18, 0x0808);
84469 #endif
84470 - set_fs(fs);
84471
84472 list_add(&s->list, &cs4297a_devs);
84473
84474 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
84475 index 4631a23..001ae57 100644
84476 --- a/sound/pci/ymfpci/ymfpci.h
84477 +++ b/sound/pci/ymfpci/ymfpci.h
84478 @@ -358,7 +358,7 @@ struct snd_ymfpci {
84479 spinlock_t reg_lock;
84480 spinlock_t voice_lock;
84481 wait_queue_head_t interrupt_sleep;
84482 - atomic_t interrupt_sleep_count;
84483 + atomic_unchecked_t interrupt_sleep_count;
84484 struct snd_info_entry *proc_entry;
84485 const struct firmware *dsp_microcode;
84486 const struct firmware *controller_microcode;
84487 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
84488 index 3a6f03f..bc5c86c 100644
84489 --- a/sound/pci/ymfpci/ymfpci_main.c
84490 +++ b/sound/pci/ymfpci/ymfpci_main.c
84491 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
84492 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
84493 break;
84494 }
84495 - if (atomic_read(&chip->interrupt_sleep_count)) {
84496 - atomic_set(&chip->interrupt_sleep_count, 0);
84497 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
84498 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
84499 wake_up(&chip->interrupt_sleep);
84500 }
84501 __end:
84502 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
84503 continue;
84504 init_waitqueue_entry(&wait, current);
84505 add_wait_queue(&chip->interrupt_sleep, &wait);
84506 - atomic_inc(&chip->interrupt_sleep_count);
84507 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
84508 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
84509 remove_wait_queue(&chip->interrupt_sleep, &wait);
84510 }
84511 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
84512 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
84513 spin_unlock(&chip->reg_lock);
84514
84515 - if (atomic_read(&chip->interrupt_sleep_count)) {
84516 - atomic_set(&chip->interrupt_sleep_count, 0);
84517 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
84518 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
84519 wake_up(&chip->interrupt_sleep);
84520 }
84521 }
84522 @@ -2420,7 +2420,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
84523 spin_lock_init(&chip->reg_lock);
84524 spin_lock_init(&chip->voice_lock);
84525 init_waitqueue_head(&chip->interrupt_sleep);
84526 - atomic_set(&chip->interrupt_sleep_count, 0);
84527 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
84528 chip->card = card;
84529 chip->pci = pci;
84530 chip->irq = -1;
84531 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
84532 new file mode 100644
84533 index 0000000..50f2f2f
84534 --- /dev/null
84535 +++ b/tools/gcc/.gitignore
84536 @@ -0,0 +1 @@
84537 +size_overflow_hash.h
84538 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
84539 new file mode 100644
84540 index 0000000..1d09b7e
84541 --- /dev/null
84542 +++ b/tools/gcc/Makefile
84543 @@ -0,0 +1,43 @@
84544 +#CC := gcc
84545 +#PLUGIN_SOURCE_FILES := pax_plugin.c
84546 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
84547 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
84548 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
84549 +
84550 +ifeq ($(PLUGINCC),$(HOSTCC))
84551 +HOSTLIBS := hostlibs
84552 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
84553 +else
84554 +HOSTLIBS := hostcxxlibs
84555 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
84556 +endif
84557 +
84558 +$(HOSTLIBS)-y := constify_plugin.so
84559 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
84560 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
84561 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
84562 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
84563 +$(HOSTLIBS)-y += colorize_plugin.so
84564 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
84565 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
84566 +
84567 +always := $($(HOSTLIBS)-y)
84568 +
84569 +constify_plugin-objs := constify_plugin.o
84570 +stackleak_plugin-objs := stackleak_plugin.o
84571 +kallocstat_plugin-objs := kallocstat_plugin.o
84572 +kernexec_plugin-objs := kernexec_plugin.o
84573 +checker_plugin-objs := checker_plugin.o
84574 +colorize_plugin-objs := colorize_plugin.o
84575 +size_overflow_plugin-objs := size_overflow_plugin.o
84576 +latent_entropy_plugin-objs := latent_entropy_plugin.o
84577 +
84578 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
84579 +
84580 +quiet_cmd_build_size_overflow_hash = GENHASH $@
84581 + cmd_build_size_overflow_hash = \
84582 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
84583 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
84584 + $(call if_changed,build_size_overflow_hash)
84585 +
84586 +targets += size_overflow_hash.h
84587 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
84588 new file mode 100644
84589 index 0000000..d41b5af
84590 --- /dev/null
84591 +++ b/tools/gcc/checker_plugin.c
84592 @@ -0,0 +1,171 @@
84593 +/*
84594 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
84595 + * Licensed under the GPL v2
84596 + *
84597 + * Note: the choice of the license means that the compilation process is
84598 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84599 + * but for the kernel it doesn't matter since it doesn't link against
84600 + * any of the gcc libraries
84601 + *
84602 + * gcc plugin to implement various sparse (source code checker) features
84603 + *
84604 + * TODO:
84605 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
84606 + *
84607 + * BUGS:
84608 + * - none known
84609 + */
84610 +#include "gcc-plugin.h"
84611 +#include "config.h"
84612 +#include "system.h"
84613 +#include "coretypes.h"
84614 +#include "tree.h"
84615 +#include "tree-pass.h"
84616 +#include "flags.h"
84617 +#include "intl.h"
84618 +#include "toplev.h"
84619 +#include "plugin.h"
84620 +//#include "expr.h" where are you...
84621 +#include "diagnostic.h"
84622 +#include "plugin-version.h"
84623 +#include "tm.h"
84624 +#include "function.h"
84625 +#include "basic-block.h"
84626 +#include "gimple.h"
84627 +#include "rtl.h"
84628 +#include "emit-rtl.h"
84629 +#include "tree-flow.h"
84630 +#include "target.h"
84631 +
84632 +extern void c_register_addr_space (const char *str, addr_space_t as);
84633 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
84634 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
84635 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
84636 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
84637 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
84638 +
84639 +extern void print_gimple_stmt(FILE *, gimple, int, int);
84640 +extern rtx emit_move_insn(rtx x, rtx y);
84641 +
84642 +int plugin_is_GPL_compatible;
84643 +
84644 +static struct plugin_info checker_plugin_info = {
84645 + .version = "201111150100",
84646 +};
84647 +
84648 +#define ADDR_SPACE_KERNEL 0
84649 +#define ADDR_SPACE_FORCE_KERNEL 1
84650 +#define ADDR_SPACE_USER 2
84651 +#define ADDR_SPACE_FORCE_USER 3
84652 +#define ADDR_SPACE_IOMEM 0
84653 +#define ADDR_SPACE_FORCE_IOMEM 0
84654 +#define ADDR_SPACE_PERCPU 0
84655 +#define ADDR_SPACE_FORCE_PERCPU 0
84656 +#define ADDR_SPACE_RCU 0
84657 +#define ADDR_SPACE_FORCE_RCU 0
84658 +
84659 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
84660 +{
84661 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
84662 +}
84663 +
84664 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
84665 +{
84666 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
84667 +}
84668 +
84669 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
84670 +{
84671 + return default_addr_space_valid_pointer_mode(mode, as);
84672 +}
84673 +
84674 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
84675 +{
84676 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
84677 +}
84678 +
84679 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
84680 +{
84681 + return default_addr_space_legitimize_address(x, oldx, mode, as);
84682 +}
84683 +
84684 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
84685 +{
84686 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
84687 + return true;
84688 +
84689 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
84690 + return true;
84691 +
84692 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
84693 + return true;
84694 +
84695 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
84696 + return true;
84697 +
84698 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
84699 + return true;
84700 +
84701 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
84702 + return true;
84703 +
84704 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
84705 + return true;
84706 +
84707 + return subset == superset;
84708 +}
84709 +
84710 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
84711 +{
84712 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
84713 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
84714 +
84715 + return op;
84716 +}
84717 +
84718 +static void register_checker_address_spaces(void *event_data, void *data)
84719 +{
84720 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
84721 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
84722 + c_register_addr_space("__user", ADDR_SPACE_USER);
84723 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
84724 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
84725 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
84726 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
84727 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
84728 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
84729 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
84730 +
84731 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
84732 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
84733 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
84734 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
84735 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
84736 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
84737 + targetm.addr_space.convert = checker_addr_space_convert;
84738 +}
84739 +
84740 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84741 +{
84742 + const char * const plugin_name = plugin_info->base_name;
84743 + const int argc = plugin_info->argc;
84744 + const struct plugin_argument * const argv = plugin_info->argv;
84745 + int i;
84746 +
84747 + if (!plugin_default_version_check(version, &gcc_version)) {
84748 + error(G_("incompatible gcc/plugin versions"));
84749 + return 1;
84750 + }
84751 +
84752 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
84753 +
84754 + for (i = 0; i < argc; ++i)
84755 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84756 +
84757 + if (TARGET_64BIT == 0)
84758 + return 0;
84759 +
84760 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
84761 +
84762 + return 0;
84763 +}
84764 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
84765 new file mode 100644
84766 index 0000000..846aeb0
84767 --- /dev/null
84768 +++ b/tools/gcc/colorize_plugin.c
84769 @@ -0,0 +1,148 @@
84770 +/*
84771 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
84772 + * Licensed under the GPL v2
84773 + *
84774 + * Note: the choice of the license means that the compilation process is
84775 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84776 + * but for the kernel it doesn't matter since it doesn't link against
84777 + * any of the gcc libraries
84778 + *
84779 + * gcc plugin to colorize diagnostic output
84780 + *
84781 + */
84782 +
84783 +#include "gcc-plugin.h"
84784 +#include "config.h"
84785 +#include "system.h"
84786 +#include "coretypes.h"
84787 +#include "tree.h"
84788 +#include "tree-pass.h"
84789 +#include "flags.h"
84790 +#include "intl.h"
84791 +#include "toplev.h"
84792 +#include "plugin.h"
84793 +#include "diagnostic.h"
84794 +#include "plugin-version.h"
84795 +#include "tm.h"
84796 +
84797 +int plugin_is_GPL_compatible;
84798 +
84799 +static struct plugin_info colorize_plugin_info = {
84800 + .version = "201203092200",
84801 + .help = NULL,
84802 +};
84803 +
84804 +#define GREEN "\033[32m\033[2m"
84805 +#define LIGHTGREEN "\033[32m\033[1m"
84806 +#define YELLOW "\033[33m\033[2m"
84807 +#define LIGHTYELLOW "\033[33m\033[1m"
84808 +#define RED "\033[31m\033[2m"
84809 +#define LIGHTRED "\033[31m\033[1m"
84810 +#define BLUE "\033[34m\033[2m"
84811 +#define LIGHTBLUE "\033[34m\033[1m"
84812 +#define BRIGHT "\033[m\033[1m"
84813 +#define NORMAL "\033[m"
84814 +
84815 +static diagnostic_starter_fn old_starter;
84816 +static diagnostic_finalizer_fn old_finalizer;
84817 +
84818 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
84819 +{
84820 + const char *color;
84821 + char *newprefix;
84822 +
84823 + switch (diagnostic->kind) {
84824 + case DK_NOTE:
84825 + color = LIGHTBLUE;
84826 + break;
84827 +
84828 + case DK_PEDWARN:
84829 + case DK_WARNING:
84830 + color = LIGHTYELLOW;
84831 + break;
84832 +
84833 + case DK_ERROR:
84834 + case DK_FATAL:
84835 + case DK_ICE:
84836 + case DK_PERMERROR:
84837 + case DK_SORRY:
84838 + color = LIGHTRED;
84839 + break;
84840 +
84841 + default:
84842 + color = NORMAL;
84843 + }
84844 +
84845 + old_starter(context, diagnostic);
84846 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
84847 + return;
84848 + pp_destroy_prefix(context->printer);
84849 + pp_set_prefix(context->printer, newprefix);
84850 +}
84851 +
84852 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
84853 +{
84854 + old_finalizer(context, diagnostic);
84855 +}
84856 +
84857 +static void colorize_arm(void)
84858 +{
84859 + old_starter = diagnostic_starter(global_dc);
84860 + old_finalizer = diagnostic_finalizer(global_dc);
84861 +
84862 + diagnostic_starter(global_dc) = start_colorize;
84863 + diagnostic_finalizer(global_dc) = finalize_colorize;
84864 +}
84865 +
84866 +static unsigned int execute_colorize_rearm(void)
84867 +{
84868 + if (diagnostic_starter(global_dc) == start_colorize)
84869 + return 0;
84870 +
84871 + colorize_arm();
84872 + return 0;
84873 +}
84874 +
84875 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
84876 + .pass = {
84877 + .type = SIMPLE_IPA_PASS,
84878 + .name = "colorize_rearm",
84879 + .gate = NULL,
84880 + .execute = execute_colorize_rearm,
84881 + .sub = NULL,
84882 + .next = NULL,
84883 + .static_pass_number = 0,
84884 + .tv_id = TV_NONE,
84885 + .properties_required = 0,
84886 + .properties_provided = 0,
84887 + .properties_destroyed = 0,
84888 + .todo_flags_start = 0,
84889 + .todo_flags_finish = 0
84890 + }
84891 +};
84892 +
84893 +static void colorize_start_unit(void *gcc_data, void *user_data)
84894 +{
84895 + colorize_arm();
84896 +}
84897 +
84898 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84899 +{
84900 + const char * const plugin_name = plugin_info->base_name;
84901 + struct register_pass_info colorize_rearm_pass_info = {
84902 + .pass = &pass_ipa_colorize_rearm.pass,
84903 + .reference_pass_name = "*free_lang_data",
84904 + .ref_pass_instance_number = 1,
84905 + .pos_op = PASS_POS_INSERT_AFTER
84906 + };
84907 +
84908 + if (!plugin_default_version_check(version, &gcc_version)) {
84909 + error(G_("incompatible gcc/plugin versions"));
84910 + return 1;
84911 + }
84912 +
84913 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
84914 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
84915 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
84916 + return 0;
84917 +}
84918 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
84919 new file mode 100644
84920 index 0000000..1742271
84921 --- /dev/null
84922 +++ b/tools/gcc/constify_plugin.c
84923 @@ -0,0 +1,349 @@
84924 +/*
84925 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
84926 + * Copyright 2011-2013 by PaX Team <pageexec@freemail.hu>
84927 + * Licensed under the GPL v2, or (at your option) v3
84928 + *
84929 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
84930 + *
84931 + * Homepage:
84932 + * http://www.grsecurity.net/~ephox/const_plugin/
84933 + *
84934 + * Usage:
84935 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
84936 + * $ gcc -fplugin=constify_plugin.so test.c -O2
84937 + */
84938 +
84939 +#include "gcc-plugin.h"
84940 +#include "config.h"
84941 +#include "system.h"
84942 +#include "coretypes.h"
84943 +#include "tree.h"
84944 +#include "tree-pass.h"
84945 +#include "flags.h"
84946 +#include "intl.h"
84947 +#include "toplev.h"
84948 +#include "plugin.h"
84949 +#include "diagnostic.h"
84950 +#include "plugin-version.h"
84951 +#include "tm.h"
84952 +#include "function.h"
84953 +#include "basic-block.h"
84954 +#include "gimple.h"
84955 +#include "rtl.h"
84956 +#include "emit-rtl.h"
84957 +#include "tree-flow.h"
84958 +
84959 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
84960 +
84961 +int plugin_is_GPL_compatible;
84962 +
84963 +static struct plugin_info const_plugin_info = {
84964 + .version = "201301150230",
84965 + .help = "no-constify\tturn off constification\n",
84966 +};
84967 +
84968 +static tree get_field_type(tree field)
84969 +{
84970 + return strip_array_types(TREE_TYPE(field));
84971 +}
84972 +
84973 +static bool walk_struct(tree node);
84974 +static void deconstify_tree(tree node);
84975 +
84976 +static void deconstify_type(tree type)
84977 +{
84978 + tree field;
84979 +
84980 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
84981 + tree fieldtype = get_field_type(field);
84982 +
84983 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
84984 + continue;
84985 + if (!TYPE_READONLY(fieldtype))
84986 + continue;
84987 + if (!walk_struct(fieldtype))
84988 + continue;
84989 +
84990 + deconstify_tree(field);
84991 + TREE_READONLY(field) = 0;
84992 + }
84993 + TYPE_READONLY(type) = 0;
84994 + C_TYPE_FIELDS_READONLY(type) = 0;
84995 +}
84996 +
84997 +static void deconstify_tree(tree node)
84998 +{
84999 + tree old_type, new_type, field;
85000 +
85001 +// TREE_READONLY(node) = 0;
85002 + old_type = TREE_TYPE(node);
85003 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
85004 + node = old_type;
85005 + old_type = TREE_TYPE(old_type);
85006 + }
85007 +
85008 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
85009 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
85010 +
85011 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
85012 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
85013 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
85014 + DECL_FIELD_CONTEXT(field) = new_type;
85015 +
85016 + deconstify_type(new_type);
85017 +
85018 + TREE_TYPE(node) = new_type;
85019 +}
85020 +
85021 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
85022 +{
85023 + tree type;
85024 +
85025 + *no_add_attrs = true;
85026 + if (TREE_CODE(*node) == FUNCTION_DECL) {
85027 + error("%qE attribute does not apply to functions", name);
85028 + return NULL_TREE;
85029 + }
85030 +
85031 + if (TREE_CODE(*node) == VAR_DECL) {
85032 + error("%qE attribute does not apply to variables", name);
85033 + return NULL_TREE;
85034 + }
85035 +
85036 + if (TYPE_P(*node)) {
85037 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
85038 + *no_add_attrs = false;
85039 + else
85040 + error("%qE attribute applies to struct and union types only", name);
85041 + return NULL_TREE;
85042 + }
85043 +
85044 + type = TREE_TYPE(*node);
85045 +
85046 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
85047 + error("%qE attribute applies to struct and union types only", name);
85048 + return NULL_TREE;
85049 + }
85050 +
85051 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
85052 + error("%qE attribute is already applied to the type", name);
85053 + return NULL_TREE;
85054 + }
85055 +
85056 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
85057 + error("%qE attribute used on type that is not constified", name);
85058 + return NULL_TREE;
85059 + }
85060 +
85061 + if (TREE_CODE(*node) == TYPE_DECL) {
85062 + deconstify_tree(*node);
85063 + return NULL_TREE;
85064 + }
85065 +
85066 + return NULL_TREE;
85067 +}
85068 +
85069 +static void constify_type(tree type)
85070 +{
85071 + TYPE_READONLY(type) = 1;
85072 + C_TYPE_FIELDS_READONLY(type) = 1;
85073 +}
85074 +
85075 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
85076 +{
85077 + *no_add_attrs = true;
85078 + if (!TYPE_P(*node)) {
85079 + error("%qE attribute applies to types only", name);
85080 + return NULL_TREE;
85081 + }
85082 +
85083 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
85084 + error("%qE attribute applies to struct and union types only", name);
85085 + return NULL_TREE;
85086 + }
85087 +
85088 + *no_add_attrs = false;
85089 + constify_type(*node);
85090 + return NULL_TREE;
85091 +}
85092 +
85093 +static struct attribute_spec no_const_attr = {
85094 + .name = "no_const",
85095 + .min_length = 0,
85096 + .max_length = 0,
85097 + .decl_required = false,
85098 + .type_required = false,
85099 + .function_type_required = false,
85100 + .handler = handle_no_const_attribute,
85101 +#if BUILDING_GCC_VERSION >= 4007
85102 + .affects_type_identity = true
85103 +#endif
85104 +};
85105 +
85106 +static struct attribute_spec do_const_attr = {
85107 + .name = "do_const",
85108 + .min_length = 0,
85109 + .max_length = 0,
85110 + .decl_required = false,
85111 + .type_required = false,
85112 + .function_type_required = false,
85113 + .handler = handle_do_const_attribute,
85114 +#if BUILDING_GCC_VERSION >= 4007
85115 + .affects_type_identity = true
85116 +#endif
85117 +};
85118 +
85119 +static void register_attributes(void *event_data, void *data)
85120 +{
85121 + register_attribute(&no_const_attr);
85122 + register_attribute(&do_const_attr);
85123 +}
85124 +
85125 +static bool is_fptr(tree field)
85126 +{
85127 + tree ptr = get_field_type(field);
85128 +
85129 + if (TREE_CODE(ptr) != POINTER_TYPE)
85130 + return false;
85131 +
85132 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
85133 +}
85134 +
85135 +static bool walk_struct(tree node)
85136 +{
85137 + tree field;
85138 +
85139 + if (TYPE_FIELDS(node) == NULL_TREE)
85140 + return false;
85141 +
85142 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node)))
85143 + return true;
85144 +
85145 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
85146 + gcc_assert(!TYPE_READONLY(node));
85147 + deconstify_type(node);
85148 + return false;
85149 + }
85150 +
85151 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
85152 + tree type = get_field_type(field);
85153 + enum tree_code code = TREE_CODE(type);
85154 +
85155 + if (node == type)
85156 + return false;
85157 + if (code == RECORD_TYPE || code == UNION_TYPE) {
85158 + if (!(walk_struct(type)))
85159 + return false;
85160 + } else if (!is_fptr(field) && !TREE_READONLY(field))
85161 + return false;
85162 + }
85163 + return true;
85164 +}
85165 +
85166 +static void finish_type(void *event_data, void *data)
85167 +{
85168 + tree type = (tree)event_data;
85169 +
85170 + if (type == NULL_TREE || type == error_mark_node)
85171 + return;
85172 +
85173 + if (TYPE_READONLY(type))
85174 + return;
85175 +
85176 + if (walk_struct(type))
85177 + constify_type(type);
85178 + else
85179 + deconstify_type(type);
85180 +}
85181 +
85182 +static unsigned int check_local_variables(void)
85183 +{
85184 + unsigned int ret = 0;
85185 + tree var;
85186 + referenced_var_iterator rvi;
85187 +
85188 +#if BUILDING_GCC_VERSION == 4005
85189 + FOR_EACH_REFERENCED_VAR(var, rvi) {
85190 +#else
85191 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
85192 +#endif
85193 + tree type = TREE_TYPE(var);
85194 +
85195 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
85196 + continue;
85197 +
85198 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
85199 + continue;
85200 +
85201 + if (!TYPE_READONLY(type))
85202 + continue;
85203 +
85204 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
85205 +// continue;
85206 +
85207 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
85208 +// continue;
85209 +
85210 + if (walk_struct(type)) {
85211 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
85212 + ret = 1;
85213 + }
85214 + }
85215 + return ret;
85216 +}
85217 +
85218 +struct gimple_opt_pass pass_local_variable = {
85219 + {
85220 + .type = GIMPLE_PASS,
85221 + .name = "check_local_variables",
85222 + .gate = NULL,
85223 + .execute = check_local_variables,
85224 + .sub = NULL,
85225 + .next = NULL,
85226 + .static_pass_number = 0,
85227 + .tv_id = TV_NONE,
85228 + .properties_required = 0,
85229 + .properties_provided = 0,
85230 + .properties_destroyed = 0,
85231 + .todo_flags_start = 0,
85232 + .todo_flags_finish = 0
85233 + }
85234 +};
85235 +
85236 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85237 +{
85238 + const char * const plugin_name = plugin_info->base_name;
85239 + const int argc = plugin_info->argc;
85240 + const struct plugin_argument * const argv = plugin_info->argv;
85241 + int i;
85242 + bool constify = true;
85243 +
85244 + struct register_pass_info local_variable_pass_info = {
85245 + .pass = &pass_local_variable.pass,
85246 + .reference_pass_name = "ssa",
85247 + .ref_pass_instance_number = 1,
85248 + .pos_op = PASS_POS_INSERT_BEFORE
85249 + };
85250 +
85251 + if (!plugin_default_version_check(version, &gcc_version)) {
85252 + error(G_("incompatible gcc/plugin versions"));
85253 + return 1;
85254 + }
85255 +
85256 + for (i = 0; i < argc; ++i) {
85257 + if (!(strcmp(argv[i].key, "no-constify"))) {
85258 + constify = false;
85259 + continue;
85260 + }
85261 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85262 + }
85263 +
85264 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
85265 + if (constify) {
85266 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
85267 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
85268 + }
85269 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
85270 +
85271 + return 0;
85272 +}
85273 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
85274 new file mode 100644
85275 index 0000000..e518932
85276 --- /dev/null
85277 +++ b/tools/gcc/generate_size_overflow_hash.sh
85278 @@ -0,0 +1,94 @@
85279 +#!/bin/bash
85280 +
85281 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
85282 +
85283 +header1="size_overflow_hash.h"
85284 +database="size_overflow_hash.data"
85285 +n=65536
85286 +
85287 +usage() {
85288 +cat <<EOF
85289 +usage: $0 options
85290 +OPTIONS:
85291 + -h|--help help
85292 + -o header file
85293 + -d database file
85294 + -n hash array size
85295 +EOF
85296 + return 0
85297 +}
85298 +
85299 +while true
85300 +do
85301 + case "$1" in
85302 + -h|--help) usage && exit 0;;
85303 + -n) n=$2; shift 2;;
85304 + -o) header1="$2"; shift 2;;
85305 + -d) database="$2"; shift 2;;
85306 + --) shift 1; break ;;
85307 + *) break ;;
85308 + esac
85309 +done
85310 +
85311 +create_defines() {
85312 + for i in `seq 0 31`
85313 + do
85314 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
85315 + done
85316 + echo >> "$header1"
85317 +}
85318 +
85319 +create_structs() {
85320 + rm -f "$header1"
85321 +
85322 + create_defines
85323 +
85324 + cat "$database" | while read data
85325 + do
85326 + data_array=($data)
85327 + struct_hash_name="${data_array[0]}"
85328 + funcn="${data_array[1]}"
85329 + params="${data_array[2]}"
85330 + next="${data_array[4]}"
85331 +
85332 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
85333 +
85334 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
85335 + echo -en "\t.param\t= " >> "$header1"
85336 + line=
85337 + for param_num in ${params//-/ };
85338 + do
85339 + line="${line}PARAM"$param_num"|"
85340 + done
85341 +
85342 + echo -e "${line%?},\n};\n" >> "$header1"
85343 + done
85344 +}
85345 +
85346 +create_headers() {
85347 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
85348 +}
85349 +
85350 +create_array_elements() {
85351 + index=0
85352 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
85353 + do
85354 + data_array=($data)
85355 + i="${data_array[3]}"
85356 + hash="${data_array[0]}"
85357 + while [[ $index -lt $i ]]
85358 + do
85359 + echo -e "\t["$index"]\t= NULL," >> "$header1"
85360 + index=$(($index + 1))
85361 + done
85362 + index=$(($index + 1))
85363 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
85364 + done
85365 + echo '};' >> $header1
85366 +}
85367 +
85368 +create_structs
85369 +create_headers
85370 +create_array_elements
85371 +
85372 +exit 0
85373 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
85374 new file mode 100644
85375 index 0000000..a86e422
85376 --- /dev/null
85377 +++ b/tools/gcc/kallocstat_plugin.c
85378 @@ -0,0 +1,167 @@
85379 +/*
85380 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
85381 + * Licensed under the GPL v2
85382 + *
85383 + * Note: the choice of the license means that the compilation process is
85384 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85385 + * but for the kernel it doesn't matter since it doesn't link against
85386 + * any of the gcc libraries
85387 + *
85388 + * gcc plugin to find the distribution of k*alloc sizes
85389 + *
85390 + * TODO:
85391 + *
85392 + * BUGS:
85393 + * - none known
85394 + */
85395 +#include "gcc-plugin.h"
85396 +#include "config.h"
85397 +#include "system.h"
85398 +#include "coretypes.h"
85399 +#include "tree.h"
85400 +#include "tree-pass.h"
85401 +#include "flags.h"
85402 +#include "intl.h"
85403 +#include "toplev.h"
85404 +#include "plugin.h"
85405 +//#include "expr.h" where are you...
85406 +#include "diagnostic.h"
85407 +#include "plugin-version.h"
85408 +#include "tm.h"
85409 +#include "function.h"
85410 +#include "basic-block.h"
85411 +#include "gimple.h"
85412 +#include "rtl.h"
85413 +#include "emit-rtl.h"
85414 +
85415 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85416 +
85417 +int plugin_is_GPL_compatible;
85418 +
85419 +static const char * const kalloc_functions[] = {
85420 + "__kmalloc",
85421 + "kmalloc",
85422 + "kmalloc_large",
85423 + "kmalloc_node",
85424 + "kmalloc_order",
85425 + "kmalloc_order_trace",
85426 + "kmalloc_slab",
85427 + "kzalloc",
85428 + "kzalloc_node",
85429 +};
85430 +
85431 +static struct plugin_info kallocstat_plugin_info = {
85432 + .version = "201111150100",
85433 +};
85434 +
85435 +static unsigned int execute_kallocstat(void);
85436 +
85437 +static struct gimple_opt_pass kallocstat_pass = {
85438 + .pass = {
85439 + .type = GIMPLE_PASS,
85440 + .name = "kallocstat",
85441 + .gate = NULL,
85442 + .execute = execute_kallocstat,
85443 + .sub = NULL,
85444 + .next = NULL,
85445 + .static_pass_number = 0,
85446 + .tv_id = TV_NONE,
85447 + .properties_required = 0,
85448 + .properties_provided = 0,
85449 + .properties_destroyed = 0,
85450 + .todo_flags_start = 0,
85451 + .todo_flags_finish = 0
85452 + }
85453 +};
85454 +
85455 +static bool is_kalloc(const char *fnname)
85456 +{
85457 + size_t i;
85458 +
85459 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
85460 + if (!strcmp(fnname, kalloc_functions[i]))
85461 + return true;
85462 + return false;
85463 +}
85464 +
85465 +static unsigned int execute_kallocstat(void)
85466 +{
85467 + basic_block bb;
85468 +
85469 + // 1. loop through BBs and GIMPLE statements
85470 + FOR_EACH_BB(bb) {
85471 + gimple_stmt_iterator gsi;
85472 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85473 + // gimple match:
85474 + tree fndecl, size;
85475 + gimple call_stmt;
85476 + const char *fnname;
85477 +
85478 + // is it a call
85479 + call_stmt = gsi_stmt(gsi);
85480 + if (!is_gimple_call(call_stmt))
85481 + continue;
85482 + fndecl = gimple_call_fndecl(call_stmt);
85483 + if (fndecl == NULL_TREE)
85484 + continue;
85485 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
85486 + continue;
85487 +
85488 + // is it a call to k*alloc
85489 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
85490 + if (!is_kalloc(fnname))
85491 + continue;
85492 +
85493 + // is the size arg the result of a simple const assignment
85494 + size = gimple_call_arg(call_stmt, 0);
85495 + while (true) {
85496 + gimple def_stmt;
85497 + expanded_location xloc;
85498 + size_t size_val;
85499 +
85500 + if (TREE_CODE(size) != SSA_NAME)
85501 + break;
85502 + def_stmt = SSA_NAME_DEF_STMT(size);
85503 + if (!def_stmt || !is_gimple_assign(def_stmt))
85504 + break;
85505 + if (gimple_num_ops(def_stmt) != 2)
85506 + break;
85507 + size = gimple_assign_rhs1(def_stmt);
85508 + if (!TREE_CONSTANT(size))
85509 + continue;
85510 + xloc = expand_location(gimple_location(def_stmt));
85511 + if (!xloc.file)
85512 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
85513 + size_val = TREE_INT_CST_LOW(size);
85514 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
85515 + break;
85516 + }
85517 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
85518 +//debug_tree(gimple_call_fn(call_stmt));
85519 +//print_node(stderr, "pax", fndecl, 4);
85520 + }
85521 + }
85522 +
85523 + return 0;
85524 +}
85525 +
85526 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85527 +{
85528 + const char * const plugin_name = plugin_info->base_name;
85529 + struct register_pass_info kallocstat_pass_info = {
85530 + .pass = &kallocstat_pass.pass,
85531 + .reference_pass_name = "ssa",
85532 + .ref_pass_instance_number = 1,
85533 + .pos_op = PASS_POS_INSERT_AFTER
85534 + };
85535 +
85536 + if (!plugin_default_version_check(version, &gcc_version)) {
85537 + error(G_("incompatible gcc/plugin versions"));
85538 + return 1;
85539 + }
85540 +
85541 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
85542 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
85543 +
85544 + return 0;
85545 +}
85546 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
85547 new file mode 100644
85548 index 0000000..8856202
85549 --- /dev/null
85550 +++ b/tools/gcc/kernexec_plugin.c
85551 @@ -0,0 +1,432 @@
85552 +/*
85553 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
85554 + * Licensed under the GPL v2
85555 + *
85556 + * Note: the choice of the license means that the compilation process is
85557 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85558 + * but for the kernel it doesn't matter since it doesn't link against
85559 + * any of the gcc libraries
85560 + *
85561 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
85562 + *
85563 + * TODO:
85564 + *
85565 + * BUGS:
85566 + * - none known
85567 + */
85568 +#include "gcc-plugin.h"
85569 +#include "config.h"
85570 +#include "system.h"
85571 +#include "coretypes.h"
85572 +#include "tree.h"
85573 +#include "tree-pass.h"
85574 +#include "flags.h"
85575 +#include "intl.h"
85576 +#include "toplev.h"
85577 +#include "plugin.h"
85578 +//#include "expr.h" where are you...
85579 +#include "diagnostic.h"
85580 +#include "plugin-version.h"
85581 +#include "tm.h"
85582 +#include "function.h"
85583 +#include "basic-block.h"
85584 +#include "gimple.h"
85585 +#include "rtl.h"
85586 +#include "emit-rtl.h"
85587 +#include "tree-flow.h"
85588 +
85589 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85590 +extern rtx emit_move_insn(rtx x, rtx y);
85591 +
85592 +#if BUILDING_GCC_VERSION <= 4006
85593 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
85594 +#endif
85595 +
85596 +int plugin_is_GPL_compatible;
85597 +
85598 +static struct plugin_info kernexec_plugin_info = {
85599 + .version = "201111291120",
85600 + .help = "method=[bts|or]\tinstrumentation method\n"
85601 +};
85602 +
85603 +static unsigned int execute_kernexec_reload(void);
85604 +static unsigned int execute_kernexec_fptr(void);
85605 +static unsigned int execute_kernexec_retaddr(void);
85606 +static bool kernexec_cmodel_check(void);
85607 +
85608 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
85609 +static void (*kernexec_instrument_retaddr)(rtx);
85610 +
85611 +static struct gimple_opt_pass kernexec_reload_pass = {
85612 + .pass = {
85613 + .type = GIMPLE_PASS,
85614 + .name = "kernexec_reload",
85615 + .gate = kernexec_cmodel_check,
85616 + .execute = execute_kernexec_reload,
85617 + .sub = NULL,
85618 + .next = NULL,
85619 + .static_pass_number = 0,
85620 + .tv_id = TV_NONE,
85621 + .properties_required = 0,
85622 + .properties_provided = 0,
85623 + .properties_destroyed = 0,
85624 + .todo_flags_start = 0,
85625 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
85626 + }
85627 +};
85628 +
85629 +static struct gimple_opt_pass kernexec_fptr_pass = {
85630 + .pass = {
85631 + .type = GIMPLE_PASS,
85632 + .name = "kernexec_fptr",
85633 + .gate = kernexec_cmodel_check,
85634 + .execute = execute_kernexec_fptr,
85635 + .sub = NULL,
85636 + .next = NULL,
85637 + .static_pass_number = 0,
85638 + .tv_id = TV_NONE,
85639 + .properties_required = 0,
85640 + .properties_provided = 0,
85641 + .properties_destroyed = 0,
85642 + .todo_flags_start = 0,
85643 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
85644 + }
85645 +};
85646 +
85647 +static struct rtl_opt_pass kernexec_retaddr_pass = {
85648 + .pass = {
85649 + .type = RTL_PASS,
85650 + .name = "kernexec_retaddr",
85651 + .gate = kernexec_cmodel_check,
85652 + .execute = execute_kernexec_retaddr,
85653 + .sub = NULL,
85654 + .next = NULL,
85655 + .static_pass_number = 0,
85656 + .tv_id = TV_NONE,
85657 + .properties_required = 0,
85658 + .properties_provided = 0,
85659 + .properties_destroyed = 0,
85660 + .todo_flags_start = 0,
85661 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
85662 + }
85663 +};
85664 +
85665 +static bool kernexec_cmodel_check(void)
85666 +{
85667 + tree section;
85668 +
85669 + if (ix86_cmodel != CM_KERNEL)
85670 + return false;
85671 +
85672 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
85673 + if (!section || !TREE_VALUE(section))
85674 + return true;
85675 +
85676 + section = TREE_VALUE(TREE_VALUE(section));
85677 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
85678 + return true;
85679 +
85680 + return false;
85681 +}
85682 +
85683 +/*
85684 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
85685 + */
85686 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
85687 +{
85688 + gimple asm_movabs_stmt;
85689 +
85690 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
85691 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
85692 + gimple_asm_set_volatile(asm_movabs_stmt, true);
85693 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
85694 + update_stmt(asm_movabs_stmt);
85695 +}
85696 +
85697 +/*
85698 + * find all asm() stmts that clobber r10 and add a reload of r10
85699 + */
85700 +static unsigned int execute_kernexec_reload(void)
85701 +{
85702 + basic_block bb;
85703 +
85704 + // 1. loop through BBs and GIMPLE statements
85705 + FOR_EACH_BB(bb) {
85706 + gimple_stmt_iterator gsi;
85707 +
85708 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85709 + // gimple match: __asm__ ("" : : : "r10");
85710 + gimple asm_stmt;
85711 + size_t nclobbers;
85712 +
85713 + // is it an asm ...
85714 + asm_stmt = gsi_stmt(gsi);
85715 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
85716 + continue;
85717 +
85718 + // ... clobbering r10
85719 + nclobbers = gimple_asm_nclobbers(asm_stmt);
85720 + while (nclobbers--) {
85721 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
85722 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
85723 + continue;
85724 + kernexec_reload_fptr_mask(&gsi);
85725 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
85726 + break;
85727 + }
85728 + }
85729 + }
85730 +
85731 + return 0;
85732 +}
85733 +
85734 +/*
85735 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
85736 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
85737 + */
85738 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
85739 +{
85740 + gimple assign_intptr, assign_new_fptr, call_stmt;
85741 + tree intptr, old_fptr, new_fptr, kernexec_mask;
85742 +
85743 + call_stmt = gsi_stmt(*gsi);
85744 + old_fptr = gimple_call_fn(call_stmt);
85745 +
85746 + // create temporary unsigned long variable used for bitops and cast fptr to it
85747 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
85748 + add_referenced_var(intptr);
85749 + mark_sym_for_renaming(intptr);
85750 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
85751 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
85752 + update_stmt(assign_intptr);
85753 +
85754 + // apply logical or to temporary unsigned long and bitmask
85755 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
85756 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
85757 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
85758 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
85759 + update_stmt(assign_intptr);
85760 +
85761 + // cast temporary unsigned long back to a temporary fptr variable
85762 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
85763 + add_referenced_var(new_fptr);
85764 + mark_sym_for_renaming(new_fptr);
85765 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
85766 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
85767 + update_stmt(assign_new_fptr);
85768 +
85769 + // replace call stmt fn with the new fptr
85770 + gimple_call_set_fn(call_stmt, new_fptr);
85771 + update_stmt(call_stmt);
85772 +}
85773 +
85774 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
85775 +{
85776 + gimple asm_or_stmt, call_stmt;
85777 + tree old_fptr, new_fptr, input, output;
85778 + VEC(tree, gc) *inputs = NULL;
85779 + VEC(tree, gc) *outputs = NULL;
85780 +
85781 + call_stmt = gsi_stmt(*gsi);
85782 + old_fptr = gimple_call_fn(call_stmt);
85783 +
85784 + // create temporary fptr variable
85785 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
85786 + add_referenced_var(new_fptr);
85787 + mark_sym_for_renaming(new_fptr);
85788 +
85789 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
85790 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
85791 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
85792 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
85793 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
85794 + VEC_safe_push(tree, gc, inputs, input);
85795 + VEC_safe_push(tree, gc, outputs, output);
85796 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
85797 + gimple_asm_set_volatile(asm_or_stmt, true);
85798 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
85799 + update_stmt(asm_or_stmt);
85800 +
85801 + // replace call stmt fn with the new fptr
85802 + gimple_call_set_fn(call_stmt, new_fptr);
85803 + update_stmt(call_stmt);
85804 +}
85805 +
85806 +/*
85807 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
85808 + */
85809 +static unsigned int execute_kernexec_fptr(void)
85810 +{
85811 + basic_block bb;
85812 +
85813 + // 1. loop through BBs and GIMPLE statements
85814 + FOR_EACH_BB(bb) {
85815 + gimple_stmt_iterator gsi;
85816 +
85817 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85818 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
85819 + tree fn;
85820 + gimple call_stmt;
85821 +
85822 + // is it a call ...
85823 + call_stmt = gsi_stmt(gsi);
85824 + if (!is_gimple_call(call_stmt))
85825 + continue;
85826 + fn = gimple_call_fn(call_stmt);
85827 + if (TREE_CODE(fn) == ADDR_EXPR)
85828 + continue;
85829 + if (TREE_CODE(fn) != SSA_NAME)
85830 + gcc_unreachable();
85831 +
85832 + // ... through a function pointer
85833 + fn = SSA_NAME_VAR(fn);
85834 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
85835 + continue;
85836 + fn = TREE_TYPE(fn);
85837 + if (TREE_CODE(fn) != POINTER_TYPE)
85838 + continue;
85839 + fn = TREE_TYPE(fn);
85840 + if (TREE_CODE(fn) != FUNCTION_TYPE)
85841 + continue;
85842 +
85843 + kernexec_instrument_fptr(&gsi);
85844 +
85845 +//debug_tree(gimple_call_fn(call_stmt));
85846 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
85847 + }
85848 + }
85849 +
85850 + return 0;
85851 +}
85852 +
85853 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
85854 +static void kernexec_instrument_retaddr_bts(rtx insn)
85855 +{
85856 + rtx btsq;
85857 + rtvec argvec, constraintvec, labelvec;
85858 + int line;
85859 +
85860 + // create asm volatile("btsq $63,(%%rsp)":::)
85861 + argvec = rtvec_alloc(0);
85862 + constraintvec = rtvec_alloc(0);
85863 + labelvec = rtvec_alloc(0);
85864 + line = expand_location(RTL_LOCATION(insn)).line;
85865 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
85866 + MEM_VOLATILE_P(btsq) = 1;
85867 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
85868 + emit_insn_before(btsq, insn);
85869 +}
85870 +
85871 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
85872 +static void kernexec_instrument_retaddr_or(rtx insn)
85873 +{
85874 + rtx orq;
85875 + rtvec argvec, constraintvec, labelvec;
85876 + int line;
85877 +
85878 + // create asm volatile("orq %%r10,(%%rsp)":::)
85879 + argvec = rtvec_alloc(0);
85880 + constraintvec = rtvec_alloc(0);
85881 + labelvec = rtvec_alloc(0);
85882 + line = expand_location(RTL_LOCATION(insn)).line;
85883 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
85884 + MEM_VOLATILE_P(orq) = 1;
85885 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
85886 + emit_insn_before(orq, insn);
85887 +}
85888 +
85889 +/*
85890 + * find all asm level function returns and forcibly set the highest bit of the return address
85891 + */
85892 +static unsigned int execute_kernexec_retaddr(void)
85893 +{
85894 + rtx insn;
85895 +
85896 + // 1. find function returns
85897 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
85898 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
85899 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
85900 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
85901 + rtx body;
85902 +
85903 + // is it a retn
85904 + if (!JUMP_P(insn))
85905 + continue;
85906 + body = PATTERN(insn);
85907 + if (GET_CODE(body) == PARALLEL)
85908 + body = XVECEXP(body, 0, 0);
85909 + if (!ANY_RETURN_P(body))
85910 + continue;
85911 + kernexec_instrument_retaddr(insn);
85912 + }
85913 +
85914 +// print_simple_rtl(stderr, get_insns());
85915 +// print_rtl(stderr, get_insns());
85916 +
85917 + return 0;
85918 +}
85919 +
85920 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85921 +{
85922 + const char * const plugin_name = plugin_info->base_name;
85923 + const int argc = plugin_info->argc;
85924 + const struct plugin_argument * const argv = plugin_info->argv;
85925 + int i;
85926 + struct register_pass_info kernexec_reload_pass_info = {
85927 + .pass = &kernexec_reload_pass.pass,
85928 + .reference_pass_name = "ssa",
85929 + .ref_pass_instance_number = 1,
85930 + .pos_op = PASS_POS_INSERT_AFTER
85931 + };
85932 + struct register_pass_info kernexec_fptr_pass_info = {
85933 + .pass = &kernexec_fptr_pass.pass,
85934 + .reference_pass_name = "ssa",
85935 + .ref_pass_instance_number = 1,
85936 + .pos_op = PASS_POS_INSERT_AFTER
85937 + };
85938 + struct register_pass_info kernexec_retaddr_pass_info = {
85939 + .pass = &kernexec_retaddr_pass.pass,
85940 + .reference_pass_name = "pro_and_epilogue",
85941 + .ref_pass_instance_number = 1,
85942 + .pos_op = PASS_POS_INSERT_AFTER
85943 + };
85944 +
85945 + if (!plugin_default_version_check(version, &gcc_version)) {
85946 + error(G_("incompatible gcc/plugin versions"));
85947 + return 1;
85948 + }
85949 +
85950 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
85951 +
85952 + if (TARGET_64BIT == 0)
85953 + return 0;
85954 +
85955 + for (i = 0; i < argc; ++i) {
85956 + if (!strcmp(argv[i].key, "method")) {
85957 + if (!argv[i].value) {
85958 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85959 + continue;
85960 + }
85961 + if (!strcmp(argv[i].value, "bts")) {
85962 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
85963 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
85964 + } else if (!strcmp(argv[i].value, "or")) {
85965 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
85966 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
85967 + fix_register("r10", 1, 1);
85968 + } else
85969 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
85970 + continue;
85971 + }
85972 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85973 + }
85974 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
85975 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
85976 +
85977 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
85978 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
85979 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
85980 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
85981 +
85982 + return 0;
85983 +}
85984 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
85985 new file mode 100644
85986 index 0000000..b8008f7
85987 --- /dev/null
85988 +++ b/tools/gcc/latent_entropy_plugin.c
85989 @@ -0,0 +1,295 @@
85990 +/*
85991 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
85992 + * Licensed under the GPL v2
85993 + *
85994 + * Note: the choice of the license means that the compilation process is
85995 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85996 + * but for the kernel it doesn't matter since it doesn't link against
85997 + * any of the gcc libraries
85998 + *
85999 + * gcc plugin to help generate a little bit of entropy from program state,
86000 + * used during boot in the kernel
86001 + *
86002 + * TODO:
86003 + * - add ipa pass to identify not explicitly marked candidate functions
86004 + * - mix in more program state (function arguments/return values, loop variables, etc)
86005 + * - more instrumentation control via attribute parameters
86006 + *
86007 + * BUGS:
86008 + * - LTO needs -flto-partition=none for now
86009 + */
86010 +#include "gcc-plugin.h"
86011 +#include "config.h"
86012 +#include "system.h"
86013 +#include "coretypes.h"
86014 +#include "tree.h"
86015 +#include "tree-pass.h"
86016 +#include "flags.h"
86017 +#include "intl.h"
86018 +#include "toplev.h"
86019 +#include "plugin.h"
86020 +//#include "expr.h" where are you...
86021 +#include "diagnostic.h"
86022 +#include "plugin-version.h"
86023 +#include "tm.h"
86024 +#include "function.h"
86025 +#include "basic-block.h"
86026 +#include "gimple.h"
86027 +#include "rtl.h"
86028 +#include "emit-rtl.h"
86029 +#include "tree-flow.h"
86030 +
86031 +int plugin_is_GPL_compatible;
86032 +
86033 +static tree latent_entropy_decl;
86034 +
86035 +static struct plugin_info latent_entropy_plugin_info = {
86036 + .version = "201207271820",
86037 + .help = NULL
86038 +};
86039 +
86040 +static unsigned int execute_latent_entropy(void);
86041 +static bool gate_latent_entropy(void);
86042 +
86043 +static struct gimple_opt_pass latent_entropy_pass = {
86044 + .pass = {
86045 + .type = GIMPLE_PASS,
86046 + .name = "latent_entropy",
86047 + .gate = gate_latent_entropy,
86048 + .execute = execute_latent_entropy,
86049 + .sub = NULL,
86050 + .next = NULL,
86051 + .static_pass_number = 0,
86052 + .tv_id = TV_NONE,
86053 + .properties_required = PROP_gimple_leh | PROP_cfg,
86054 + .properties_provided = 0,
86055 + .properties_destroyed = 0,
86056 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
86057 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
86058 + }
86059 +};
86060 +
86061 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
86062 +{
86063 + if (TREE_CODE(*node) != FUNCTION_DECL) {
86064 + *no_add_attrs = true;
86065 + error("%qE attribute only applies to functions", name);
86066 + }
86067 + return NULL_TREE;
86068 +}
86069 +
86070 +static struct attribute_spec latent_entropy_attr = {
86071 + .name = "latent_entropy",
86072 + .min_length = 0,
86073 + .max_length = 0,
86074 + .decl_required = true,
86075 + .type_required = false,
86076 + .function_type_required = false,
86077 + .handler = handle_latent_entropy_attribute,
86078 +#if BUILDING_GCC_VERSION >= 4007
86079 + .affects_type_identity = false
86080 +#endif
86081 +};
86082 +
86083 +static void register_attributes(void *event_data, void *data)
86084 +{
86085 + register_attribute(&latent_entropy_attr);
86086 +}
86087 +
86088 +static bool gate_latent_entropy(void)
86089 +{
86090 + tree latent_entropy_attr;
86091 +
86092 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
86093 + return latent_entropy_attr != NULL_TREE;
86094 +}
86095 +
86096 +static unsigned HOST_WIDE_INT seed;
86097 +static unsigned HOST_WIDE_INT get_random_const(void)
86098 +{
86099 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
86100 + return seed;
86101 +}
86102 +
86103 +static enum tree_code get_op(tree *rhs)
86104 +{
86105 + static enum tree_code op;
86106 + unsigned HOST_WIDE_INT random_const;
86107 +
86108 + random_const = get_random_const();
86109 +
86110 + switch (op) {
86111 + case BIT_XOR_EXPR:
86112 + op = PLUS_EXPR;
86113 + break;
86114 +
86115 + case PLUS_EXPR:
86116 + if (rhs) {
86117 + op = LROTATE_EXPR;
86118 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
86119 + break;
86120 + }
86121 +
86122 + case LROTATE_EXPR:
86123 + default:
86124 + op = BIT_XOR_EXPR;
86125 + break;
86126 + }
86127 + if (rhs)
86128 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
86129 + return op;
86130 +}
86131 +
86132 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
86133 +{
86134 + gimple_stmt_iterator gsi;
86135 + gimple assign;
86136 + tree addxorrol, rhs;
86137 + enum tree_code op;
86138 +
86139 + op = get_op(&rhs);
86140 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
86141 + assign = gimple_build_assign(local_entropy, addxorrol);
86142 + find_referenced_vars_in(assign);
86143 +//debug_bb(bb);
86144 + gsi = gsi_after_labels(bb);
86145 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
86146 + update_stmt(assign);
86147 +}
86148 +
86149 +static void perturb_latent_entropy(basic_block bb, tree rhs)
86150 +{
86151 + gimple_stmt_iterator gsi;
86152 + gimple assign;
86153 + tree addxorrol, temp;
86154 +
86155 + // 1. create temporary copy of latent_entropy
86156 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
86157 + add_referenced_var(temp);
86158 + mark_sym_for_renaming(temp);
86159 +
86160 + // 2. read...
86161 + assign = gimple_build_assign(temp, latent_entropy_decl);
86162 + find_referenced_vars_in(assign);
86163 + gsi = gsi_after_labels(bb);
86164 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86165 + update_stmt(assign);
86166 +
86167 + // 3. ...modify...
86168 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
86169 + assign = gimple_build_assign(temp, addxorrol);
86170 + find_referenced_vars_in(assign);
86171 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86172 + update_stmt(assign);
86173 +
86174 + // 4. ...write latent_entropy
86175 + assign = gimple_build_assign(latent_entropy_decl, temp);
86176 + find_referenced_vars_in(assign);
86177 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86178 + update_stmt(assign);
86179 +}
86180 +
86181 +static unsigned int execute_latent_entropy(void)
86182 +{
86183 + basic_block bb;
86184 + gimple assign;
86185 + gimple_stmt_iterator gsi;
86186 + tree local_entropy;
86187 +
86188 + if (!latent_entropy_decl) {
86189 + struct varpool_node *node;
86190 +
86191 + for (node = varpool_nodes; node; node = node->next) {
86192 + tree var = node->decl;
86193 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
86194 + continue;
86195 + latent_entropy_decl = var;
86196 +// debug_tree(var);
86197 + break;
86198 + }
86199 + if (!latent_entropy_decl) {
86200 +// debug_tree(current_function_decl);
86201 + return 0;
86202 + }
86203 + }
86204 +
86205 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
86206 +
86207 + // 1. create local entropy variable
86208 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
86209 + add_referenced_var(local_entropy);
86210 + mark_sym_for_renaming(local_entropy);
86211 +
86212 + // 2. initialize local entropy variable
86213 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
86214 + if (dom_info_available_p(CDI_DOMINATORS))
86215 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
86216 + gsi = gsi_start_bb(bb);
86217 +
86218 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
86219 +// gimple_set_location(assign, loc);
86220 + find_referenced_vars_in(assign);
86221 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86222 + update_stmt(assign);
86223 + bb = bb->next_bb;
86224 +
86225 + // 3. instrument each BB with an operation on the local entropy variable
86226 + while (bb != EXIT_BLOCK_PTR) {
86227 + perturb_local_entropy(bb, local_entropy);
86228 + bb = bb->next_bb;
86229 + };
86230 +
86231 + // 4. mix local entropy into the global entropy variable
86232 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
86233 + return 0;
86234 +}
86235 +
86236 +static void start_unit_callback(void *gcc_data, void *user_data)
86237 +{
86238 +#if BUILDING_GCC_VERSION >= 4007
86239 + seed = get_random_seed(false);
86240 +#else
86241 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
86242 + seed *= seed;
86243 +#endif
86244 +
86245 + if (in_lto_p)
86246 + return;
86247 +
86248 + // extern u64 latent_entropy
86249 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
86250 +
86251 + TREE_STATIC(latent_entropy_decl) = 1;
86252 + TREE_PUBLIC(latent_entropy_decl) = 1;
86253 + TREE_USED(latent_entropy_decl) = 1;
86254 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
86255 + DECL_EXTERNAL(latent_entropy_decl) = 1;
86256 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
86257 + DECL_INITIAL(latent_entropy_decl) = NULL;
86258 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
86259 +// varpool_finalize_decl(latent_entropy_decl);
86260 +// varpool_mark_needed_node(latent_entropy_decl);
86261 +}
86262 +
86263 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86264 +{
86265 + const char * const plugin_name = plugin_info->base_name;
86266 + struct register_pass_info latent_entropy_pass_info = {
86267 + .pass = &latent_entropy_pass.pass,
86268 + .reference_pass_name = "optimized",
86269 + .ref_pass_instance_number = 1,
86270 + .pos_op = PASS_POS_INSERT_BEFORE
86271 + };
86272 +
86273 + if (!plugin_default_version_check(version, &gcc_version)) {
86274 + error(G_("incompatible gcc/plugin versions"));
86275 + return 1;
86276 + }
86277 +
86278 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
86279 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
86280 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
86281 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
86282 +
86283 + return 0;
86284 +}
86285 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
86286 new file mode 100644
86287 index 0000000..5921fd7
86288 --- /dev/null
86289 +++ b/tools/gcc/size_overflow_hash.data
86290 @@ -0,0 +1,3713 @@
86291 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
86292 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
86293 +batadv_orig_node_del_if_4 batadv_orig_node_del_if 2 4 NULL
86294 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
86295 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
86296 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
86297 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
86298 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
86299 +diva_os_malloc_16406 diva_os_malloc 2 16406 NULL
86300 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
86301 +xfs_dir2_leaf_getdents_23841 xfs_dir2_leaf_getdents 3 23841 NULL
86302 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
86303 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
86304 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
86305 +create_log_8225 create_log 2 8225 NULL
86306 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
86307 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
86308 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
86309 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
86310 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
86311 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
86312 +padzero_55 padzero 1 55 &sel_read_policyvers_55
86313 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
86314 +alloc_wr_24635 alloc_wr 1-2 24635 NULL
86315 +read_file_blob_57406 read_file_blob 3 57406 NULL
86316 +add_rx_skb_8257 add_rx_skb 3 8257 NULL
86317 +enclosure_register_57412 enclosure_register 3 57412 NULL
86318 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
86319 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
86320 +gre_manip_pkt_57416 gre_manip_pkt 4 57416 NULL
86321 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
86322 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
86323 +DepcaSignature_80 DepcaSignature 2 80 NULL nohasharray
86324 +crypto_authenc_setkey_80 crypto_authenc_setkey 3 80 &DepcaSignature_80
86325 +init_cdev_8274 init_cdev 1 8274 NULL
86326 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
86327 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL nohasharray
86328 +alloc_ftrace_hash_57431 alloc_ftrace_hash 1 57431 &compat_keyctl_instantiate_key_iov_57431
86329 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
86330 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
86331 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
86332 +load_msg_95 load_msg 2 95 NULL
86333 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
86334 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
86335 +acpi_tb_check_xsdt_21862 acpi_tb_check_xsdt 1 21862 NULL
86336 +sys_pselect6_57449 sys_pselect6 1 57449 NULL
86337 +biovec_create_pools_9575 biovec_create_pools 2 9575 NULL
86338 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
86339 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
86340 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
86341 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
86342 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
86343 +send_midi_async_57463 send_midi_async 3 57463 NULL
86344 +sisusb_clear_vram_57466 sisusb_clear_vram 3-2 57466 NULL
86345 +ath6kl_usb_post_recv_transfers_32892 ath6kl_usb_post_recv_transfers 2 32892 NULL
86346 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL nohasharray
86347 +sep_lock_user_pages_57470 sep_lock_user_pages 2-3 57470 &ieee80211_if_read_flags_57470
86348 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
86349 +construct_key_and_link_8321 construct_key_and_link 4 8321 NULL
86350 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
86351 +init_q_132 init_q 4 132 NULL
86352 +roccat_read_41093 roccat_read 3 41093 NULL nohasharray
86353 +nvme_map_user_pages_41093 nvme_map_user_pages 3-4 41093 &roccat_read_41093
86354 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
86355 +unifi_net_data_malloc_24716 unifi_net_data_malloc 3 24716 NULL
86356 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
86357 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
86358 +uio_read_49300 uio_read 3 49300 NULL
86359 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
86360 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL
86361 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
86362 +firmwareUpload_32794 firmwareUpload 3 32794 NULL
86363 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
86364 +play_iframe_8219 play_iframe 3 8219 NULL
86365 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
86366 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
86367 +ath_rxbuf_alloc_24745 ath_rxbuf_alloc 2 24745 NULL
86368 +nvme_create_queue_170 nvme_create_queue 3 170 NULL
86369 +init_tag_map_57515 init_tag_map 3 57515 NULL
86370 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL
86371 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-3-4 49330 NULL
86372 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
86373 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
86374 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
86375 +DoC_Probe_57534 DoC_Probe 1 57534 NULL
86376 +cfpkt_setlen_49343 cfpkt_setlen 2 49343 NULL
86377 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
86378 +mI_alloc_skb_24770 mI_alloc_skb 1 24770 NULL
86379 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
86380 +virtblk_add_req_197 virtblk_add_req 2-3 197 NULL
86381 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
86382 +rds_tcp_data_recv_53476 rds_tcp_data_recv 3 53476 NULL
86383 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
86384 +skb_make_writable_24783 skb_make_writable 2 24783 NULL
86385 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
86386 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
86387 +cache_read_24790 cache_read 3 24790 NULL
86388 +px_raw_event_49371 px_raw_event 4 49371 NULL
86389 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
86390 +compat_filldir_32999 compat_filldir 3 32999 NULL
86391 +hci_si_event_1404 hci_si_event 3 1404 NULL
86392 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
86393 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
86394 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
86395 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
86396 +applesmc_create_nodes_49392 applesmc_create_nodes 2 49392 NULL
86397 +snd_usb_ctl_msg_8436 snd_usb_ctl_msg 8 8436 NULL
86398 +comedi_buf_alloc_24822 comedi_buf_alloc 3 24822 NULL
86399 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
86400 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
86401 +tun_alloc_skb_41216 tun_alloc_skb 2-4-3 41216 NULL
86402 +proc_scsi_write_proc_267 proc_scsi_write_proc 3 267 NULL
86403 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
86404 +sk_stream_alloc_skb_57622 sk_stream_alloc_skb 2 57622 NULL
86405 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
86406 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
86407 +mfd_add_devices_16668 mfd_add_devices 4 16668 NULL
86408 +packet_recv_error_16669 packet_recv_error 3 16669 NULL
86409 +osdmap_set_max_osd_57630 osdmap_set_max_osd 2 57630 NULL nohasharray
86410 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 &osdmap_set_max_osd_57630
86411 +mem_read_57631 mem_read 3 57631 NULL
86412 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
86413 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
86414 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
86415 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
86416 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
86417 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
86418 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
86419 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
86420 +queues_read_24877 queues_read 3 24877 NULL
86421 +__fprog_create_41263 __fprog_create 2 41263 NULL
86422 +syslog_print_307 syslog_print 2 307 NULL
86423 +platform_device_add_data_310 platform_device_add_data 3 310 NULL
86424 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
86425 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
86426 +sys_mq_timedsend_57661 sys_mq_timedsend 3 57661 NULL
86427 +r3964_write_57662 r3964_write 4 57662 NULL
86428 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
86429 +savu_sysfs_read_49473 savu_sysfs_read 6 49473 NULL
86430 +dn_nsp_do_disc_49474 dn_nsp_do_disc 6-2 49474 NULL
86431 +alloc_context_41283 alloc_context 1 41283 NULL
86432 +__lgwrite_57669 __lgwrite 4 57669 NULL
86433 +ath9k_wmi_cmd_327 ath9k_wmi_cmd 4 327 NULL
86434 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
86435 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
86436 +alloc_pg_vec_8533 alloc_pg_vec 2 8533 NULL
86437 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
86438 +ieee80211_fragment_33112 ieee80211_fragment 4 33112 NULL
86439 +arch_gnttab_map_shared_41306 arch_gnttab_map_shared 3 41306 NULL
86440 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
86441 +write_node_33121 write_node 4 33121 NULL
86442 +vring_new_virtqueue_54673 vring_new_virtqueue 2 54673 NULL
86443 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
86444 +profile_remove_8556 profile_remove 3 8556 NULL
86445 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
86446 +iscsi_recv_pdu_16755 iscsi_recv_pdu 4 16755 NULL
86447 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
86448 +cmtp_send_interopmsg_376 cmtp_send_interopmsg 7 376 NULL
86449 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
86450 +mga_ioremap_8571 mga_ioremap 1-2 8571 NULL
86451 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
86452 +sys_rt_sigpending_24961 sys_rt_sigpending 2 24961 NULL
86453 +tower_write_8580 tower_write 3 8580 NULL
86454 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
86455 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 NULL nohasharray
86456 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 &compat_sys_set_mempolicy_57742
86457 +jbd2_alloc_41359 jbd2_alloc 1 41359 NULL
86458 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
86459 +nf_nat_sdp_port_24977 nf_nat_sdp_port 7 24977 NULL
86460 +smk_write_access_49561 smk_write_access 3 49561 NULL
86461 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
86462 +kmp_init_41373 kmp_init 2 41373 NULL
86463 +context_alloc_24645 context_alloc 3 24645 NULL
86464 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
86465 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
86466 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
86467 +tipc_send2name_16809 tipc_send2name 6 16809 NULL
86468 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
86469 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
86470 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
86471 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
86472 +dm_vcalloc_16814 dm_vcalloc 1-2 16814 NULL
86473 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
86474 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
86475 +pp_read_33210 pp_read 3 33210 NULL
86476 +sys_flistxattr_41407 sys_flistxattr 3 41407 NULL
86477 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
86478 +ivtv_read_57796 ivtv_read 3 57796 NULL
86479 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
86480 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
86481 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
86482 +heap_init_49617 heap_init 2 49617 NULL
86483 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
86484 +ieee80211_send_probe_req_38307 ieee80211_send_probe_req 6-4 38307 NULL
86485 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
86486 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
86487 +_alloc_get_attr_desc_470 _alloc_get_attr_desc 2 470 NULL
86488 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
86489 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
86490 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
86491 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 4-6 41442 NULL
86492 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
86493 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
86494 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
86495 +st_write_16874 st_write 3 16874 NULL
86496 +copy_to_user_57835 copy_to_user 3 57835 NULL
86497 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
86498 +pidlist_resize_496 pidlist_resize 2 496 NULL
86499 +flash_read_57843 flash_read 3 57843 NULL
86500 +read_vbt_r0_503 read_vbt_r0 1 503 NULL
86501 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
86502 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
86503 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
86504 +arcfb_write_8702 arcfb_write 3 8702 NULL
86505 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
86506 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
86507 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
86508 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
86509 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
86510 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
86511 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
86512 +cxio_hal_init_rhdl_resource_25104 cxio_hal_init_rhdl_resource 1 25104 NULL
86513 +sock_wmalloc_16472 sock_wmalloc 2 16472 NULL
86514 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
86515 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
86516 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
86517 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
86518 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
86519 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
86520 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
86521 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
86522 +sys_gethostname_49698 sys_gethostname 2 49698 NULL
86523 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
86524 +ieee80211_rx_mgmt_probe_resp_6918 ieee80211_rx_mgmt_probe_resp 3 6918 NULL
86525 +devres_alloc_551 devres_alloc 2 551 NULL
86526 +ldisc_receive_41516 ldisc_receive 4 41516 NULL
86527 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
86528 +ip_append_data_16942 ip_append_data 5-6 16942 NULL
86529 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
86530 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
86531 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
86532 +emi26_writememory_57908 emi26_writememory 4 57908 NULL
86533 +start_isoc_chain_565 start_isoc_chain 2 565 NULL
86534 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
86535 +gsm_mux_rx_netchar_33336 gsm_mux_rx_netchar 3 33336 NULL
86536 +brcmu_pkt_buf_get_skb_5556 brcmu_pkt_buf_get_skb 1 5556 NULL
86537 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
86538 +sys_prctl_8766 sys_prctl 4 8766 NULL
86539 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
86540 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
86541 +compat_sys_preadv_583 compat_sys_preadv 3 583 NULL
86542 +sys_fsetxattr_49736 sys_fsetxattr 4 49736 NULL
86543 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
86544 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
86545 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
86546 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
86547 +sys_fgetxattr_25166 sys_fgetxattr 4 25166 NULL
86548 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
86549 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
86550 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
86551 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
86552 +ath6kl_buf_alloc_57304 ath6kl_buf_alloc 1 57304 NULL
86553 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
86554 +gserial_setup_41558 gserial_setup 2 41558 NULL
86555 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
86556 +rx_57944 rx 4 57944 NULL
86557 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
86558 +nci_skb_alloc_49757 nci_skb_alloc 2 49757 NULL
86559 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
86560 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
86561 +sctp_ulpevent_new_33377 sctp_ulpevent_new 1 33377 NULL
86562 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
86563 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
86564 +isku_sysfs_write_49767 isku_sysfs_write 6 49767 NULL
86565 +i915_cache_sharing_write_57961 i915_cache_sharing_write 3 57961 NULL
86566 +batadv_receive_client_update_packet_41578 batadv_receive_client_update_packet 3 41578 NULL
86567 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
86568 +handle_response_icmp_39574 handle_response_icmp 7 39574 NULL
86569 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
86570 +hfc_empty_fifo_57972 hfc_empty_fifo 2 57972 NULL
86571 +ceph_dns_resolve_name_62488 ceph_dns_resolve_name 2 62488 NULL
86572 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
86573 +icmpv6_manip_pkt_8833 icmpv6_manip_pkt 4 8833 NULL
86574 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
86575 +read_file_rx_chainmask_41605 read_file_rx_chainmask 3 41605 NULL
86576 +vmw_du_crtc_cursor_set_28479 vmw_du_crtc_cursor_set 4-5 28479 NULL
86577 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
86578 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
86579 +a2mp_send_41615 a2mp_send 4 41615 NULL
86580 +ceph_copy_user_to_page_vector_656 ceph_copy_user_to_page_vector 4-3 656 NULL
86581 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
86582 +arch_gnttab_map_status_49812 arch_gnttab_map_status 3 49812 NULL
86583 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
86584 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
86585 +tcf_csum_ipv6_udp_25241 tcf_csum_ipv6_udp 4 25241 NULL
86586 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
86587 +macvtap_alloc_skb_50629 macvtap_alloc_skb 2-4-3 50629 NULL
86588 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
86589 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6 49829 NULL
86590 +add_uuid_49831 add_uuid 4 49831 NULL
86591 +send_pages_8872 send_pages 3 8872 NULL
86592 +ath6kl_fwlog_block_read_49836 ath6kl_fwlog_block_read 3 49836 NULL
86593 +__btrfs_map_block_49839 __btrfs_map_block 3 49839 NULL
86594 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
86595 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
86596 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
86597 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
86598 +__kmalloc_reserve_17080 __kmalloc_reserve 1 17080 NULL
86599 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
86600 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
86601 +vfs_writev_25278 vfs_writev 3 25278 NULL
86602 +rtl8169_try_rx_copy_705 rtl8169_try_rx_copy 3 705 NULL
86603 +alloc_async_14208 alloc_async 1 14208 NULL
86604 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
86605 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
86606 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
86607 +create_entry_33479 create_entry 2 33479 NULL
86608 +mce_async_out_58056 mce_async_out 3 58056 NULL
86609 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
86610 +sys_preadv_17100 sys_preadv 3 17100 NULL
86611 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
86612 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
86613 +netxen_nic_hw_write_wx_128M_33488 netxen_nic_hw_write_wx_128M 2 33488 NULL
86614 +aac_src_ioremap_41688 aac_src_ioremap 2 41688 NULL
86615 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
86616 +res_counter_read_33499 res_counter_read 4 33499 NULL
86617 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
86618 +cm4040_write_58079 cm4040_write 3 58079 NULL
86619 +fb_read_33506 fb_read 3 33506 NULL
86620 +help_25316 help 5 25316 NULL nohasharray
86621 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 &help_25316
86622 +rfcomm_wmalloc_58090 rfcomm_wmalloc 2 58090 NULL
86623 +mwifiex_get_common_rates_17131 mwifiex_get_common_rates 3 17131 NULL
86624 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
86625 +ddp_set_map_751 ddp_set_map 4 751 NULL
86626 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
86627 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
86628 +dvb_video_write_754 dvb_video_write 3 754 NULL
86629 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
86630 +osd_req_add_get_attr_list_49278 osd_req_add_get_attr_list 3 49278 NULL
86631 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
86632 +bdx_tx_db_init_41719 bdx_tx_db_init 2 41719 NULL
86633 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
86634 +udi_log_event_58105 udi_log_event 3 58105 NULL
86635 +sys_pwritev_41722 sys_pwritev 3 41722 NULL
86636 +l2cap_sock_alloc_skb_cb_33532 l2cap_sock_alloc_skb_cb 2 33532 NULL
86637 +ib_send_cm_mra_60202 ib_send_cm_mra 4 60202 NULL nohasharray
86638 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 &ib_send_cm_mra_60202
86639 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
86640 +__copy_from_user_inatomic_nocache_49921 __copy_from_user_inatomic_nocache 3 49921 NULL
86641 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL
86642 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
86643 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
86644 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
86645 +vol_cdev_read_8968 vol_cdev_read 3 8968 NULL nohasharray
86646 +seq_open_net_8968 seq_open_net 4 8968 &vol_cdev_read_8968
86647 +sep_read_17161 sep_read 3 17161 NULL
86648 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
86649 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
86650 +dup_array_33551 dup_array 3 33551 NULL
86651 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
86652 +solo_enc_read_33553 solo_enc_read 3 33553 NULL
86653 +fillonedir_41746 fillonedir 3 41746 NULL
86654 +init_bch_64130 init_bch 1-2 64130 NULL
86655 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
86656 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
86657 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
86658 +btrfs_alloc_free_block_8986 btrfs_alloc_free_block 3 8986 NULL
86659 +savemem_58129 savemem 3 58129 NULL
86660 +batadv_tt_realloc_packet_buff_49960 batadv_tt_realloc_packet_buff 4 49960 NULL
86661 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
86662 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
86663 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
86664 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL
86665 +if_writecmd_815 if_writecmd 2 815 NULL
86666 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
86667 +read_fifo_826 read_fifo 3 826 NULL
86668 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
86669 +scsi_execute_33596 scsi_execute 5 33596 NULL
86670 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
86671 +ms_rw_17220 ms_rw 3-4 17220 NULL
86672 +read_tree_block_841 read_tree_block 3 841 NULL
86673 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
86674 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
86675 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
86676 +__pskb_copy_9038 __pskb_copy 2 9038 NULL
86677 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
86678 +asix_write_cmd_58192 asix_write_cmd 5 58192 NULL
86679 +um_idi_read_850 um_idi_read 3 850 NULL
86680 +__module_alloc_50004 __module_alloc 1 50004 NULL
86681 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
86682 +ts_read_44687 ts_read 3 44687 NULL
86683 +nci_send_cmd_58206 nci_send_cmd 3 58206 NULL
86684 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
86685 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
86686 +provide_user_output_41105 provide_user_output 3 41105 NULL
86687 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
86688 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
86689 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
86690 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
86691 +alloc_ep_17269 alloc_ep 1 17269 NULL
86692 +ath6kl_wmi_beginscan_cmd_25462 ath6kl_wmi_beginscan_cmd 8 25462 NULL
86693 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 NULL
86694 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
86695 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
86696 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
86697 +alloc_ebda_hpc_50046 alloc_ebda_hpc 1-2 50046 NULL
86698 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
86699 +create_queues_9088 create_queues 2-3 9088 NULL
86700 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
86701 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
86702 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
86703 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
86704 +rbd_alloc_coll_33678 rbd_alloc_coll 1 33678 NULL
86705 +read_file_debug_58256 read_file_debug 3 58256 NULL
86706 +skb_pad_17302 skb_pad 2 17302 NULL
86707 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
86708 +btmrvl_hsstate_read_920 btmrvl_hsstate_read 3 920 NULL
86709 +profile_load_58267 profile_load 3 58267 NULL
86710 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
86711 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4 25502 NULL
86712 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
86713 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
86714 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
86715 +pcpu_get_vm_areas_50085 pcpu_get_vm_areas 3 50085 NULL
86716 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
86717 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
86718 +sys_keyctl_33708 sys_keyctl 4 33708 NULL nohasharray
86719 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 &sys_keyctl_33708
86720 +ata_host_alloc_pinfo_17325 ata_host_alloc_pinfo 3 17325 NULL
86721 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
86722 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
86723 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
86724 +get_packet_41914 get_packet 3 41914 NULL
86725 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
86726 +ceph_get_direct_page_vector_41917 ceph_get_direct_page_vector 2 41917 NULL
86727 +read_file_slot_50111 read_file_slot 3 50111 NULL
86728 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
86729 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
86730 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
86731 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
86732 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
86733 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
86734 +copy_items_50140 copy_items 6 50140 NULL
86735 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
86736 +pcim_iomap_58334 pcim_iomap 3 58334 NULL
86737 +diva_init_dma_map_58336 diva_init_dma_map 3 58336 NULL
86738 +map_addr_56144 map_addr 7 56144 NULL
86739 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
86740 +btmrvl_psstate_read_50683 btmrvl_psstate_read 3 50683 NULL
86741 +hdlcdev_rx_997 hdlcdev_rx 3 997 NULL
86742 +portnames_read_41958 portnames_read 3 41958 NULL
86743 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 4 41959 NULL
86744 +hashtab_create_33769 hashtab_create 3 33769 NULL
86745 +alloc_group_attrs_9194 alloc_group_attrs 2 9194 NULL nohasharray
86746 +altera_swap_ir_9194 altera_swap_ir 2 9194 &alloc_group_attrs_9194
86747 +vmalloc_to_sg_58354 vmalloc_to_sg 2 58354 NULL
86748 +aac_nark_ioremap_50163 aac_nark_ioremap 2 50163 NULL nohasharray
86749 +kmalloc_node_50163 kmalloc_node 1 50163 &aac_nark_ioremap_50163
86750 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
86751 +odev_update_50169 odev_update 2 50169 NULL
86752 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL
86753 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
86754 +__devres_alloc_25598 __devres_alloc 2 25598 NULL
86755 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
86756 +netpoll_send_udp_58955 netpoll_send_udp 3 58955 NULL
86757 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
86758 +ib_send_cm_drep_50186 ib_send_cm_drep 3 50186 NULL
86759 +do_write_orph_node_64343 do_write_orph_node 2 64343 NULL
86760 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
86761 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
86762 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
86763 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
86764 +lguest_map_42008 lguest_map 1-2 42008 NULL
86765 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
86766 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
86767 +pool_allocate_42012 pool_allocate 3 42012 NULL
86768 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
86769 +sctp_make_init_58401 sctp_make_init 4 58401 NULL
86770 +ieee80211_skb_resize_50211 ieee80211_skb_resize 3 50211 NULL
86771 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
86772 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
86773 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
86774 +udplite_manip_pkt_33832 udplite_manip_pkt 4 33832 NULL
86775 +tcf_csum_ipv4_icmp_9258 tcf_csum_ipv4_icmp 3 9258 NULL
86776 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
86777 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
86778 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
86779 +sparse_early_usemaps_alloc_node_9269 sparse_early_usemaps_alloc_node 4 9269 NULL
86780 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
86781 +iscsi_offload_mesg_58425 iscsi_offload_mesg 5 58425 NULL
86782 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
86783 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
86784 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
86785 +nfs_pgarray_set_1085 nfs_pgarray_set 2 1085 NULL
86786 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
86787 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
86788 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
86789 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
86790 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
86791 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
86792 +__alloc_session_17485 __alloc_session 2-1 17485 NULL
86793 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
86794 +pm860x_bulk_write_43875 pm860x_bulk_write 3 43875 NULL
86795 +afs_extract_data_50261 afs_extract_data 5 50261 NULL
86796 +config_proc_write_33878 config_proc_write 3 33878 NULL
86797 +capabilities_read_58457 capabilities_read 3 58457 NULL
86798 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
86799 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
86800 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
86801 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
86802 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
86803 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
86804 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
86805 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
86806 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
86807 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
86808 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
86809 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
86810 +batadv_bla_is_backbone_gw_58488 batadv_bla_is_backbone_gw 3 58488 NULL
86811 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
86812 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
86813 +sel_write_context_25726 sel_write_context 3 25726 NULL nohasharray
86814 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 &sel_write_context_25726
86815 +sysfs_read_file_42113 sysfs_read_file 3 42113 NULL
86816 +mcs_unwrap_fir_25733 mcs_unwrap_fir 3 25733 NULL
86817 +vme_user_write_15587 vme_user_write 3 15587 NULL
86818 +xlog_do_log_recovery_17550 xlog_do_log_recovery 3 17550 NULL
86819 +__copy_to_user_17551 __copy_to_user 3 17551 NULL
86820 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
86821 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
86822 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
86823 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
86824 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
86825 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
86826 +v9fs_alloc_rdir_buf_42150 v9fs_alloc_rdir_buf 2 42150 NULL
86827 +roccat_common2_send_with_status_50343 roccat_common2_send_with_status 4 50343 NULL
86828 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
86829 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
86830 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
86831 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
86832 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
86833 +read_9397 read 3 9397 NULL
86834 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
86835 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
86836 +printer_write_60276 printer_write 3 60276 NULL
86837 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
86838 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
86839 +rts51x_write_mem_17598 rts51x_write_mem 4 17598 NULL
86840 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
86841 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
86842 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
86843 +osst_execute_17607 osst_execute 7-6 17607 NULL
86844 +nf_nat_sip_expect_9418 nf_nat_sip_expect 8 9418 NULL
86845 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
86846 +ipw_packet_received_skb_1230 ipw_packet_received_skb 2 1230 NULL
86847 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
86848 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
86849 +sys32_rt_sigpending_25814 sys32_rt_sigpending 2 25814 NULL
86850 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
86851 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
86852 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
86853 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
86854 +xip_file_read_58592 xip_file_read 3 58592 NULL
86855 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
86856 +kmalloc_array_9444 kmalloc_array 1-2 9444 NULL
86857 +__ntfs_malloc_34022 __ntfs_malloc 1 34022 NULL
86858 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
86859 +mcs_unwrap_mir_9455 mcs_unwrap_mir 3 9455 NULL
86860 +ppp_write_34034 ppp_write 3 34034 NULL
86861 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
86862 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
86863 +tty_insert_flip_string_34042 tty_insert_flip_string 3 34042 NULL
86864 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
86865 +batadv_tt_prepare_packet_buff_1280 batadv_tt_prepare_packet_buff 4 1280 NULL
86866 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
86867 +module_alloc_update_bounds_rx_58634 module_alloc_update_bounds_rx 1 58634 NULL nohasharray
86868 +efi_ioremap_58634 efi_ioremap 1-2 58634 &module_alloc_update_bounds_rx_58634
86869 +btmrvl_hsmode_write_42252 btmrvl_hsmode_write 3 42252 NULL
86870 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
86871 +dsp_tone_hw_message_17678 dsp_tone_hw_message 3 17678 NULL
86872 +netxen_nic_map_indirect_address_128M_42257 netxen_nic_map_indirect_address_128M 2 42257 NULL
86873 +ulog_alloc_skb_23427 ulog_alloc_skb 1 23427 NULL
86874 +__alloc_preds_9492 __alloc_preds 2 9492 NULL
86875 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
86876 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
86877 +read_file_ant_diversity_34071 read_file_ant_diversity 3 34071 NULL
86878 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
86879 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
86880 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
86881 +savu_sysfs_write_42273 savu_sysfs_write 6 42273 NULL
86882 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 NULL
86883 +lp_write_9511 lp_write 3 9511 NULL
86884 +__einj_error_trigger_17707 __einj_error_trigger 1 17707 NULL nohasharray
86885 +venus_rename_17707 venus_rename 5-4 17707 &__einj_error_trigger_17707
86886 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
86887 +nfs_readdir_make_qstr_12509 nfs_readdir_make_qstr 3 12509 NULL
86888 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
86889 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
86890 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
86891 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
86892 +read_file_dma_9530 read_file_dma 3 9530 NULL
86893 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
86894 +rcname_read_25919 rcname_read 3 25919 NULL
86895 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
86896 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
86897 +tps6586x_writes_58689 tps6586x_writes 3 58689 NULL
86898 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
86899 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
86900 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
86901 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
86902 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
86903 +key_flags_read_25931 key_flags_read 3 25931 NULL
86904 +audit_log_n_untrustedstring_9548 audit_log_n_untrustedstring 3 9548 NULL
86905 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
86906 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
86907 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
86908 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
86909 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
86910 +fw_node_create_9559 fw_node_create 2 9559 NULL
86911 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
86912 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
86913 +kobj_map_9566 kobj_map 2-3 9566 NULL
86914 +snd_pcm_plug_alloc_42339 snd_pcm_plug_alloc 2 42339 NULL
86915 +acpi_map_58725 acpi_map 1-2 58725 NULL
86916 +brcmf_usb_attach_17766 brcmf_usb_attach 2-3 17766 NULL
86917 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
86918 +fwnet_receive_packet_50537 fwnet_receive_packet 9 50537 NULL
86919 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
86920 +ieee80211_tdls_mgmt_9581 ieee80211_tdls_mgmt 8 9581 NULL
86921 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
86922 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
86923 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
86924 +file_read_actor_1401 file_read_actor 4 1401 NULL
86925 +av7110_ipack_init_46655 av7110_ipack_init 2 46655 NULL
86926 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
86927 +ubifs_leb_change_17789 ubifs_leb_change 4 17789 NULL
86928 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
86929 +do_sync_9604 do_sync 1 9604 NULL
86930 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5 9605 NULL
86931 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
86932 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
86933 +__do_config_autodelink_58763 __do_config_autodelink 3 58763 NULL
86934 +sctp_sf_abort_violation_1420 sctp_sf_abort_violation 7 1420 NULL
86935 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
86936 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
86937 +lpfc_sli_probe_sriov_nr_virtfn_26004 lpfc_sli_probe_sriov_nr_virtfn 2 26004 NULL
86938 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
86939 +fat_readpages_50582 fat_readpages 4 50582 NULL nohasharray
86940 +pep_reply_50582 pep_reply 5 50582 &fat_readpages_50582
86941 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
86942 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
86943 +_snd_pcm_lib_alloc_vmalloc_buffer_17820 _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 NULL
86944 +xfs_readdir_41200 xfs_readdir 3 41200 NULL
86945 +sge_rx_50594 sge_rx 3 50594 NULL
86946 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
86947 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
86948 +skb_padto_50759 skb_padto 2 50759 NULL
86949 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
86950 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
86951 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
86952 +isku_sysfs_read_58806 isku_sysfs_read 6 58806 NULL
86953 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
86954 +uvc_alloc_buffers_9656 uvc_alloc_buffers 2-3 9656 NULL
86955 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
86956 +ep_read_58813 ep_read 3 58813 NULL
86957 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
86958 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
86959 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
86960 +pci_enable_sriov_35745 pci_enable_sriov 2 35745 NULL
86961 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
86962 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
86963 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
86964 +dns_query_9676 dns_query 3 9676 NULL
86965 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
86966 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
86967 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
86968 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL
86969 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
86970 +command_write_58841 command_write 3 58841 NULL
86971 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
86972 +dev_config_8506 dev_config 3 8506 NULL
86973 +compat_sys_pwritev_17886 compat_sys_pwritev 3 17886 NULL
86974 +sys_readv_50664 sys_readv 3 50664 NULL
86975 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
86976 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
86977 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
86978 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
86979 +recover_head_17904 recover_head 3 17904 NULL
86980 +dccp_feat_register_sp_17914 dccp_feat_register_sp 5 17914 NULL
86981 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
86982 +brcmf_sdbrcm_bus_txctl_42492 brcmf_sdbrcm_bus_txctl 3 42492 NULL
86983 +srp_iu_pool_alloc_17920 srp_iu_pool_alloc 2 17920 NULL
86984 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
86985 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
86986 +cs553x_init_one_58886 cs553x_init_one 3 58886 NULL
86987 +ddb_input_read_9743 ddb_input_read 3 9743 NULL
86988 +skb_cow_26138 skb_cow 2 26138 NULL
86989 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
86990 +snd_emux_create_port_42533 snd_emux_create_port 3 42533 NULL
86991 +do_sigpending_9766 do_sigpending 2 9766 NULL
86992 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
86993 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
86994 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
86995 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
86996 +copy_oldmem_page_26164 copy_oldmem_page 3-1 26164 NULL
86997 +i915_ring_stop_read_42549 i915_ring_stop_read 3 42549 NULL nohasharray
86998 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 &i915_ring_stop_read_42549
86999 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 NULL
87000 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
87001 +fc_frame_alloc_1596 fc_frame_alloc 2 1596 NULL
87002 +rngapi_reset_34366 rngapi_reset 3 34366 NULL nohasharray
87003 +p54_alloc_skb_34366 p54_alloc_skb 3 34366 &rngapi_reset_34366
87004 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
87005 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
87006 +solo_v4l2_read_59247 solo_v4l2_read 3 59247 NULL
87007 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
87008 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
87009 +reiserfs_resize_34377 reiserfs_resize 2 34377 NULL
87010 +get_registers_26187 get_registers 3 26187 NULL
87011 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
87012 +ttm_bo_fbdev_io_9805 ttm_bo_fbdev_io 4 9805 NULL
87013 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
87014 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
87015 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
87016 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3 27332 NULL
87017 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
87018 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
87019 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL nohasharray
87020 +pipe_handler_request_50774 pipe_handler_request 5 50774 &tm6000_read_write_usb_50774
87021 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
87022 +mce_write_26201 mce_write 3 26201 NULL
87023 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
87024 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
87025 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
87026 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
87027 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
87028 +__pskb_pull_42602 __pskb_pull 2 42602 NULL
87029 +sctp_make_heartbeat_ack_34411 sctp_make_heartbeat_ack 4 34411 NULL
87030 +tpm_write_50798 tpm_write 3 50798 NULL
87031 +btmrvl_hsmode_read_1647 btmrvl_hsmode_read 3 1647 NULL
87032 +tun_do_read_50800 tun_do_read 4 50800 NULL
87033 +handle_rx_packet_58993 handle_rx_packet 3 58993 NULL
87034 +write_flush_50803 write_flush 3 50803 NULL
87035 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
87036 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
87037 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
87038 +dvb_play_50814 dvb_play 3 50814 NULL
87039 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
87040 +sys_move_pages_42626 sys_move_pages 2 42626 NULL
87041 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
87042 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
87043 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
87044 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
87045 +dma_attach_50831 dma_attach 6-7 50831 NULL
87046 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
87047 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
87048 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
87049 +packet_came_18072 packet_came 3 18072 NULL
87050 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
87051 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
87052 +sctp_make_abort_34459 sctp_make_abort 3 34459 NULL
87053 +_regmap_raw_write_42652 _regmap_raw_write 4 42652 NULL
87054 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
87055 +get_vm_area_18080 get_vm_area 1 18080 NULL
87056 +dvb_dvr_set_buffer_size_9840 dvb_dvr_set_buffer_size 2 9840 NULL
87057 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
87058 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
87059 +self_check_write_50856 self_check_write 5 50856 NULL
87060 +line6_dumpreq_init_34473 line6_dumpreq_init 3 34473 NULL
87061 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
87062 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
87063 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
87064 +l2tp_xmit_skb_42672 l2tp_xmit_skb 3 42672 NULL
87065 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
87066 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
87067 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
87068 +sis190_try_rx_copy_57069 sis190_try_rx_copy 3 57069 NULL
87069 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
87070 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
87071 +vb2_read_42703 vb2_read 3 42703 NULL
87072 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
87073 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
87074 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
87075 +snd_pcm_plugin_alloc_12580 snd_pcm_plugin_alloc 2 12580 NULL
87076 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
87077 +read_file_misc_9948 read_file_misc 3 9948 NULL
87078 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
87079 +set_rxd_buffer_pointer_9950 set_rxd_buffer_pointer 8 9950 NULL
87080 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
87081 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
87082 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL
87083 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
87084 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
87085 +cosa_write_1774 cosa_write 3 1774 NULL
87086 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
87087 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4 34547 NULL
87088 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
87089 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
87090 +bnx2fc_cmd_mgr_alloc_24873 bnx2fc_cmd_mgr_alloc 3-2 24873 NULL
87091 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
87092 +ath6kl_usb_submit_ctrl_out_9978 ath6kl_usb_submit_ctrl_out 6 9978 NULL
87093 +dup_to_netobj_26363 dup_to_netobj 3 26363 NULL
87094 +sock_bindtodevice_50942 sock_bindtodevice 3 50942 NULL
87095 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
87096 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
87097 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
87098 +mld_newpack_50950 mld_newpack 2 50950 NULL
87099 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL
87100 +i915_ring_stop_write_59010 i915_ring_stop_write 3 59010 NULL
87101 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
87102 +cfpkt_create_18197 cfpkt_create 1 18197 NULL
87103 +velocity_rx_copy_34583 velocity_rx_copy 2 34583 NULL
87104 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
87105 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
87106 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4 37428 NULL
87107 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
87108 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
87109 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
87110 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
87111 +handle_request_10024 handle_request 9 10024 NULL
87112 +__tty_alloc_driver_53799 __tty_alloc_driver 1 53799 NULL
87113 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
87114 +timeout_write_50991 timeout_write 3 50991 NULL
87115 +batadv_orig_hash_add_if_10033 batadv_orig_hash_add_if 2 10033 NULL
87116 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
87117 +ip_vs_create_timeout_table_64478 ip_vs_create_timeout_table 2 64478 NULL
87118 +proc_write_51003 proc_write 3 51003 NULL
87119 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
87120 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
87121 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
87122 +set_arg_42824 set_arg 3 42824 NULL
87123 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
87124 +fast_rx_path_59214 fast_rx_path 3 59214 NULL
87125 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
87126 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
87127 +audit_log_n_string_31705 audit_log_n_string 3 31705 NULL
87128 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
87129 +pstore_mkfile_50830 pstore_mkfile 5 50830 NULL
87130 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
87131 +hidp_queue_report_1881 hidp_queue_report 3 1881 NULL
87132 +dt3155_read_59226 dt3155_read 3 59226 NULL
87133 +xfs_buf_read_uncached_42844 xfs_buf_read_uncached 3 42844 NULL
87134 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
87135 +dump_midi_51040 dump_midi 3 51040 NULL
87136 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
87137 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
87138 +nf_nat_mangle_udp_packet_34661 nf_nat_mangle_udp_packet 8-6 34661 NULL
87139 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
87140 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
87141 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 NULL
87142 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
87143 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
87144 +em28xx_v4l2_read_16701 em28xx_v4l2_read 3 16701 NULL
87145 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
87146 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
87147 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
87148 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
87149 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 NULL
87150 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
87151 +pskb_expand_head_42881 pskb_expand_head 2-3 42881 NULL
87152 +ip6ip6_err_18308 ip6ip6_err 5 18308 NULL
87153 +read_vmcore_26501 read_vmcore 3 26501 NULL
87154 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
87155 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
87156 +tipc_port_recv_sections_42890 tipc_port_recv_sections 4 42890 NULL
87157 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 3-4 26507 NULL
87158 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
87159 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
87160 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
87161 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
87162 +SendTxCommandPacket_42901 SendTxCommandPacket 3 42901 NULL
87163 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
87164 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
87165 +ath6kl_wmi_send_probe_response_cmd_31728 ath6kl_wmi_send_probe_response_cmd 6 31728 NULL
87166 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
87167 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
87168 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
87169 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
87170 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
87171 +rds_message_inc_copy_to_user_26540 rds_message_inc_copy_to_user 3 26540 NULL
87172 +iscsi_nop_out_rsp_51117 iscsi_nop_out_rsp 4 51117 NULL
87173 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
87174 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
87175 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
87176 +sctp_make_datafrag_empty_34737 sctp_make_datafrag_empty 3 34737 NULL
87177 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
87178 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
87179 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
87180 +fd_copyout_59323 fd_copyout 3 59323 NULL
87181 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
87182 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
87183 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
87184 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
87185 +diva_alloc_dma_map_23798 diva_alloc_dma_map 2 23798 NULL
87186 +solos_param_store_34755 solos_param_store 4 34755 NULL
87187 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
87188 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
87189 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
87190 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
87191 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
87192 +ib_send_cm_rtu_63138 ib_send_cm_rtu 3 63138 NULL
87193 +compat_sys_pwritev64_51151 compat_sys_pwritev64 3 51151 NULL
87194 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL nohasharray
87195 +batadv_receive_server_sync_packet_26577 batadv_receive_server_sync_packet 3 26577 &rts51x_read_mem_26577
87196 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
87197 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
87198 +batadv_tt_commit_changes_2008 batadv_tt_commit_changes 4 2008 NULL
87199 +sep_prepare_input_dma_table_2009 sep_prepare_input_dma_table 2-3 2009 NULL
87200 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
87201 +ubifs_write_node_11258 ubifs_write_node 5-3 11258 NULL
87202 +reada_tree_block_flagged_18402 reada_tree_block_flagged 3 18402 NULL
87203 +iscsi_if_send_reply_52219 iscsi_if_send_reply 7 52219 NULL
87204 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
87205 +__copy_in_user_34790 __copy_in_user 3 34790 NULL
87206 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
87207 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL
87208 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
87209 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
87210 +devm_ioremap_nocache_2036 devm_ioremap_nocache 2-3 2036 NULL
87211 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
87212 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
87213 +batadv_orig_node_add_if_18433 batadv_orig_node_add_if 2 18433 NULL
87214 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
87215 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
87216 +nfc_alloc_recv_skb_10244 nfc_alloc_recv_skb 1 10244 NULL
87217 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
87218 +mangle_sdp_packet_30381 mangle_sdp_packet 10 30381 NULL
87219 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
87220 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
87221 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
87222 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
87223 +subbuf_read_actor_2071 subbuf_read_actor 3 2071 NULL
87224 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
87225 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
87226 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
87227 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
87228 +receive_DataRequest_9904 receive_DataRequest 3 9904 NULL
87229 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
87230 +tipc_send_51238 tipc_send 4 51238 NULL
87231 +drm_property_create_51239 drm_property_create 4 51239 NULL
87232 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
87233 +squashfs_read_data_59440 squashfs_read_data 6 59440 NULL
87234 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
87235 +audit_expand_2098 audit_expand 2 2098 NULL
87236 +st_read_51251 st_read 3 51251 NULL
87237 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
87238 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
87239 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
87240 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
87241 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
87242 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
87243 +rtsx_read_cfg_seq_48139 rtsx_read_cfg_seq 5-3 48139 NULL
87244 +__find_xattr_2117 __find_xattr 6 2117 NULL nohasharray
87245 +enable_read_2117 enable_read 3 2117 &__find_xattr_2117
87246 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
87247 +pcf50633_write_block_2124 pcf50633_write_block 3 2124 NULL
87248 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
87249 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
87250 +c4_add_card_54968 c4_add_card 3 54968 NULL
87251 +rtllib_authentication_req_26713 rtllib_authentication_req 3 26713 NULL
87252 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
87253 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
87254 +fd_do_readv_51297 fd_do_readv 3 51297 NULL
87255 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 5-6-9 18530 NULL
87256 +nfc_hci_send_cmd_async_26723 nfc_hci_send_cmd_async 5 26723 NULL
87257 +mlx4_init_icm_table_2151 mlx4_init_icm_table 5-4 2151 NULL
87258 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
87259 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
87260 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
87261 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
87262 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
87263 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
87264 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
87265 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
87266 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
87267 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
87268 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
87269 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
87270 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
87271 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
87272 +set_bypass_pwoff_pfs_27669 set_bypass_pwoff_pfs 3 27669 NULL
87273 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
87274 +srp_ring_alloc_26760 srp_ring_alloc 2 26760 NULL
87275 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
87276 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
87277 +ntfs_malloc_nofs_nofail_63631 ntfs_malloc_nofs_nofail 1 63631 NULL
87278 +cosa_net_setup_rx_38594 cosa_net_setup_rx 2 38594 NULL
87279 +skb_gro_header_slow_34958 skb_gro_header_slow 2 34958 NULL
87280 +debug_output_18575 debug_output 3 18575 NULL
87281 +Realloc_34961 Realloc 2 34961 NULL
87282 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
87283 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
87284 +_rtl92s_firmware_downloadcode_14021 _rtl92s_firmware_downloadcode 3 14021 NULL
87285 +__netdev_alloc_skb_18595 __netdev_alloc_skb 2 18595 NULL
87286 +slabinfo_write_18600 slabinfo_write 3 18600 NULL
87287 +ssb_bus_ssbbus_register_2217 ssb_bus_ssbbus_register 2 2217 NULL
87288 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
87289 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
87290 +vhci_write_2224 vhci_write 3 2224 NULL
87291 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
87292 +acpi_os_ioremap_49523 acpi_os_ioremap 1-2 49523 NULL
87293 +rb_alloc_3102 rb_alloc 1 3102 NULL
87294 +uf_create_device_nodes_24948 uf_create_device_nodes 2 24948 NULL
87295 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
87296 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
87297 +write_pbl_59583 write_pbl 4 59583 NULL
87298 +from_buffer_18625 from_buffer 3 18625 NULL
87299 +uio_write_43202 uio_write 3 43202 NULL
87300 +memdup_user_59590 memdup_user 2 59590 NULL
87301 +ieee80211_wx_set_gen_ie_51399 ieee80211_wx_set_gen_ie 3 51399 NULL
87302 +iso_callback_43208 iso_callback 3 43208 NULL
87303 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
87304 +smk_write_load_26829 smk_write_load 3 26829 NULL
87305 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
87306 +do_update_counters_2259 do_update_counters 4 2259 NULL
87307 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
87308 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
87309 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
87310 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
87311 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
87312 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
87313 +mtrr_write_59622 mtrr_write 3 59622 NULL
87314 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
87315 +ip_vs_icmp_xmit_59624 ip_vs_icmp_xmit 4 59624 NULL
87316 +netxen_nic_hw_read_wx_128M_26858 netxen_nic_hw_read_wx_128M 2 26858 NULL
87317 +edge_tty_recv_18667 edge_tty_recv 4 18667 NULL nohasharray
87318 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 &edge_tty_recv_18667
87319 +btmrvl_gpiogap_write_35053 btmrvl_gpiogap_write 3 35053 NULL
87320 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
87321 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
87322 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
87323 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
87324 +fixup_leb_43256 fixup_leb 3 43256 NULL
87325 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
87326 +ubifs_recover_log_leb_12079 ubifs_recover_log_leb 3 12079 NULL
87327 +ubifs_setxattr_59650 ubifs_setxattr 4 59650 NULL nohasharray
87328 +hidraw_read_59650 hidraw_read 3 59650 &ubifs_setxattr_59650
87329 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
87330 +ca91cx42_alloc_resource_10502 ca91cx42_alloc_resource 2 10502 NULL
87331 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
87332 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
87333 +evtchn_write_43278 evtchn_write 3 43278 NULL
87334 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
87335 +store_ifalias_35088 store_ifalias 4 35088 NULL
87336 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
87337 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
87338 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
87339 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
87340 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
87341 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
87342 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
87343 +get_vm_area_caller_10527 get_vm_area_caller 1 10527 NULL
87344 +capi_write_35104 capi_write 3 35104 NULL nohasharray
87345 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
87346 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
87347 +sys_semtimedop_4486 sys_semtimedop 3 4486 NULL
87348 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
87349 +osd_req_write_sg_50908 osd_req_write_sg 5 50908 NULL
87350 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
87351 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
87352 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
87353 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
87354 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
87355 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 NULL nohasharray
87356 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 &pwr_ps_enter_read_26935
87357 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
87358 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 NULL
87359 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
87360 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
87361 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
87362 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
87363 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
87364 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
87365 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
87366 +do_trimming_26952 do_trimming 3 26952 NULL
87367 +ath6kl_wmi_set_ie_cmd_37260 ath6kl_wmi_set_ie_cmd 6 37260 NULL
87368 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
87369 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
87370 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
87371 +alloc_buf_34532 alloc_buf 1 34532 NULL
87372 +sock_rmalloc_59740 sock_rmalloc 2 59740 NULL nohasharray
87373 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 &sock_rmalloc_59740
87374 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
87375 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
87376 +otp_read_10594 otp_read 2-4-5 10594 NULL
87377 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
87378 +sctp_manip_pkt_59749 sctp_manip_pkt 4 59749 NULL
87379 +icmp_manip_pkt_51560 icmp_manip_pkt 4 51560 NULL
87380 +brcmf_sdbrcm_read_control_22721 brcmf_sdbrcm_read_control 3 22721 NULL
87381 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
87382 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
87383 +roccat_common2_send_2422 roccat_common2_send 4 2422 NULL
87384 +ieee80211_auth_challenge_18810 ieee80211_auth_challenge 3 18810 NULL
87385 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
87386 +cxgb3_get_cpl_reply_skb_10620 cxgb3_get_cpl_reply_skb 2 10620 NULL
87387 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
87388 +venus_remove_59781 venus_remove 4 59781 NULL
87389 +ioremap_nocache_2439 ioremap_nocache 1-2 2439 NULL
87390 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
87391 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
87392 +tty_buffer_find_2443 tty_buffer_find 2 2443 NULL
87393 +xlog_do_recover_59789 xlog_do_recover 3 59789 NULL
87394 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
87395 +rfcomm_tty_write_51603 rfcomm_tty_write 3 51603 NULL
87396 +xenfb_write_43412 xenfb_write 3 43412 NULL
87397 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
87398 +nfs4_alloc_slots_2454 nfs4_alloc_slots 1 2454 NULL nohasharray
87399 +ath6kl_usb_bmi_write_2454 ath6kl_usb_bmi_write 3 2454 &nfs4_alloc_slots_2454
87400 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
87401 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
87402 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
87403 +gdm_wimax_netif_rx_43423 gdm_wimax_netif_rx 3 43423 &__alloc_bootmem_low_43423
87404 +rtllib_wx_set_gen_ie_59808 rtllib_wx_set_gen_ie 3 59808 NULL
87405 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
87406 +udp_manip_pkt_45467 udp_manip_pkt 4 45467 NULL
87407 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
87408 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
87409 +ni65_alloc_mem_10664 ni65_alloc_mem 3 10664 NULL
87410 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
87411 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
87412 +cmd_complete_51629 cmd_complete 6 51629 NULL
87413 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
87414 +btmrvl_txdnldready_read_413 btmrvl_txdnldready_read 3 413 NULL
87415 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
87416 +set_fd_set_35249 set_fd_set 1 35249 NULL
87417 +wiphy_new_2482 wiphy_new 2 2482 NULL
87418 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
87419 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
87420 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
87421 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
87422 +tcp_push_10680 tcp_push 3 10680 NULL
87423 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
87424 +c101_run_37279 c101_run 2 37279 NULL
87425 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
87426 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
87427 +tun_put_user_59849 tun_put_user 4 59849 NULL
87428 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
87429 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
87430 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
87431 +dm_write_2513 dm_write 3 2513 NULL
87432 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
87433 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
87434 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL
87435 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
87436 +ntfs_malloc_nofs_49572 ntfs_malloc_nofs 1 49572 NULL
87437 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
87438 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
87439 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
87440 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
87441 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
87442 +__iscsi_complete_pdu_10726 __iscsi_complete_pdu 4 10726 NULL
87443 +sfi_sysfs_install_table_51688 sfi_sysfs_install_table 1 51688 NULL
87444 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
87445 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
87446 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
87447 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
87448 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 NULL nohasharray
87449 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 &brcmf_sdio_forensic_read_35311
87450 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
87451 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL
87452 +compat_sys_msgsnd_10738 compat_sys_msgsnd 2 10738 NULL
87453 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
87454 +sel_write_access_51704 sel_write_access 3 51704 NULL
87455 +sys_syslog_10746 sys_syslog 3 10746 NULL
87456 +alloc_one_pg_vec_page_10747 alloc_one_pg_vec_page 1 10747 NULL
87457 +new_bind_ctl_35324 new_bind_ctl 2 35324 NULL
87458 +do_readlink_43518 do_readlink 2 43518 NULL
87459 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
87460 +gem_alloc_skb_51715 gem_alloc_skb 2 51715 NULL
87461 +fallback_on_nodma_alloc_35332 fallback_on_nodma_alloc 2 35332 NULL
87462 +read_file_reset_52310 read_file_reset 3 52310 NULL
87463 +pms_capture_27142 pms_capture 4 27142 NULL
87464 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
87465 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
87466 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
87467 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
87468 +msg_set_51725 msg_set 3 51725 NULL
87469 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
87470 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
87471 +hpi_alloc_control_cache_35351 hpi_alloc_control_cache 1 35351 NULL
87472 +hid_parse_report_51737 hid_parse_report 3 51737 NULL
87473 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
87474 +alc_auto_create_extra_outs_18975 alc_auto_create_extra_outs 2 18975 NULL
87475 +i2400m_net_rx_27170 i2400m_net_rx 5 27170 NULL
87476 +l3_alloc_skb_32289 l3_alloc_skb 1 32289 NULL
87477 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
87478 +ath_rx_init_43564 ath_rx_init 2 43564 NULL
87479 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 NULL nohasharray
87480 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 &il_dbgfs_rxon_flags_read_59950
87481 +sys_bind_10799 sys_bind 3 10799 NULL
87482 +_fc_frame_alloc_43568 _fc_frame_alloc 1 43568 NULL
87483 +nfcwilink_send_bts_cmd_10802 nfcwilink_send_bts_cmd 3 10802 NULL
87484 +ioremap_prot_51764 ioremap_prot 1-2 51764 NULL
87485 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
87486 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 2-3 33204 NULL
87487 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
87488 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
87489 +drm_vblank_init_11362 drm_vblank_init 2 11362 NULL
87490 +send_command_10832 send_command 4 10832 NULL
87491 +lro_gen_skb_2644 lro_gen_skb 6 2644 NULL
87492 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
87493 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
87494 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
87495 +proc_read_43614 proc_read 3 43614 NULL
87496 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
87497 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
87498 +drm_fb_helper_init_19044 drm_fb_helper_init 3-4 19044 NULL
87499 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
87500 +xlbd_reserve_minors_18365 xlbd_reserve_minors 1-2 18365 NULL
87501 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
87502 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
87503 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
87504 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
87505 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
87506 +vmalloc_15464 vmalloc 1 15464 NULL
87507 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
87508 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
87509 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
87510 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
87511 +cfpkt_add_trail_27260 cfpkt_add_trail 3 27260 NULL
87512 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
87513 +sys_sched_getaffinity_60033 sys_sched_getaffinity 2 60033 NULL
87514 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 NULL
87515 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
87516 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
87517 +adu_write_30487 adu_write 3 30487 NULL
87518 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
87519 +get_scq_10897 get_scq 2 10897 NULL
87520 +sys_process_vm_readv_19090 sys_process_vm_readv 3-5 19090 NULL nohasharray
87521 +brcmf_usbdev_qinit_19090 brcmf_usbdev_qinit 2 19090 &sys_process_vm_readv_19090
87522 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
87523 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
87524 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
87525 +load_module_60056 load_module 2 60056 NULL nohasharray
87526 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 &load_module_60056
87527 +__videobuf_alloc_cached_12740 __videobuf_alloc_cached 1 12740 NULL
87528 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
87529 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4-2 43679 NULL
87530 +ieee80211_build_probe_req_60064 ieee80211_build_probe_req 8-6 60064 NULL
87531 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
87532 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
87533 +__netdev_alloc_skb_ip_align_55067 __netdev_alloc_skb_ip_align 2 55067 NULL
87534 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
87535 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
87536 +__copy_from_user_10918 __copy_from_user 3 10918 NULL
87537 +user_read_51881 user_read 3 51881 NULL
87538 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
87539 +__xip_file_write_2733 __xip_file_write 4-3 2733 NULL
87540 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL
87541 +ath6kl_wmi_test_cmd_27312 ath6kl_wmi_test_cmd 3 27312 NULL
87542 +max77693_bulk_write_43698 max77693_bulk_write 3 43698 NULL
87543 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
87544 +hidp_send_ctrl_message_43702 hidp_send_ctrl_message 4 43702 NULL
87545 +async_setkey_35521 async_setkey 3 35521 NULL
87546 +set_dev_class_39645 set_dev_class 4 39645 NULL nohasharray
87547 +dm_exception_table_init_39645 dm_exception_table_init 2 39645 &set_dev_class_39645
87548 +cxgb4_pktgl_to_skb_61899 cxgb4_pktgl_to_skb 2 61899 NULL
87549 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
87550 +iio_read_first_n_sw_rb_51911 iio_read_first_n_sw_rb 2 51911 NULL
87551 +hid_report_raw_event_2762 hid_report_raw_event 4 2762 NULL
87552 +add_tty_40055 add_tty 1 40055 NULL nohasharray
87553 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 &add_tty_40055
87554 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
87555 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
87556 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
87557 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
87558 +ttm_bo_kmap_60118 ttm_bo_kmap 3-2 60118 NULL
87559 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
87560 +alloc_context_3194 alloc_context 1 3194 NULL
87561 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
87562 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
87563 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
87564 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
87565 +i915_min_freq_write_10981 i915_min_freq_write 3 10981 NULL
87566 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
87567 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
87568 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
87569 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
87570 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
87571 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
87572 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
87573 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
87574 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
87575 +init_state_60165 init_state 2 60165 NULL
87576 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
87577 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
87578 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3 19214 NULL
87579 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
87580 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
87581 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
87582 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
87583 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
87584 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
87585 +calc_hmac_32010 calc_hmac 3 32010 NULL
87586 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
87587 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
87588 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1 43806 NULL
87589 +kernel_readv_35617 kernel_readv 3 35617 NULL
87590 +hci_send_cmd_43810 hci_send_cmd 3 43810 NULL
87591 +sys_lgetxattr_45531 sys_lgetxattr 4 45531 NULL
87592 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
87593 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
87594 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
87595 +dccp_manip_pkt_476 dccp_manip_pkt 4 476 NULL
87596 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
87597 +set_tap_pfs_60203 set_tap_pfs 3 60203 NULL
87598 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
87599 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
87600 +carl9170_handle_mpdu_11056 carl9170_handle_mpdu 3 11056 NULL
87601 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
87602 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
87603 +vxge_rx_alloc_52024 vxge_rx_alloc 3 52024 NULL
87604 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
87605 +__ip_append_data_16864 __ip_append_data 8-9 16864 NULL
87606 +p54_download_eeprom_43842 p54_download_eeprom 4 43842 NULL
87607 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
87608 +store_debug_level_35652 store_debug_level 3 35652 NULL
87609 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
87610 +read_flush_43851 read_flush 3 43851 NULL
87611 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
87612 +cmm_write_2896 cmm_write 3 2896 NULL
87613 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
87614 +io_mapping_map_wc_19284 io_mapping_map_wc 2 19284 NULL
87615 +tunables_write_59563 tunables_write 3 59563 NULL
87616 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
87617 +rtsx_write_cfg_seq_27485 rtsx_write_cfg_seq 5-3 27485 NULL
87618 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
87619 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
87620 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
87621 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
87622 +dm_table_create_35687 dm_table_create 3 35687 NULL
87623 +qib_create_cq_27497 qib_create_cq 2 27497 NULL
87624 +nfc_hci_execute_cmd_43882 nfc_hci_execute_cmd 5 43882 NULL
87625 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
87626 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
87627 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
87628 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
87629 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
87630 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
87631 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
87632 +debug_read_19322 debug_read 3 19322 NULL
87633 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
87634 +__pskb_pull_tail_60287 __pskb_pull_tail 2 60287 NULL
87635 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
87636 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL
87637 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
87638 +dn_nsp_return_disc_60296 dn_nsp_return_disc 2 60296 NULL
87639 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
87640 +prism2_sta_send_mgmt_43916 prism2_sta_send_mgmt 5 43916 NULL
87641 +mgmt_device_found_14146 mgmt_device_found 10 14146 NULL
87642 +snd_seq_oss_readq_new_14283 snd_seq_oss_readq_new 2 14283 NULL
87643 +doc_probe_23285 doc_probe 1 23285 NULL
87644 +ppp_cp_event_2965 ppp_cp_event 6 2965 NULL
87645 +SendString_43928 SendString 3 43928 NULL
87646 +acpi_os_map_memory_11161 acpi_os_map_memory 1-2 11161 NULL
87647 +ceph_parse_server_name_60318 ceph_parse_server_name 2 60318 NULL
87648 +retry_count_read_52129 retry_count_read 3 52129 NULL
87649 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
87650 +ioat2_alloc_ring_11172 ioat2_alloc_ring 2 11172 NULL
87651 +read_zero_19366 read_zero 3 19366 NULL
87652 +bch_alloc_4593 bch_alloc 1 4593 NULL
87653 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
87654 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
87655 +libipw_alloc_txb_27579 libipw_alloc_txb 1-2-3 27579 NULL
87656 +raid5_resize_63306 raid5_resize 2 63306 NULL
87657 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
87658 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
87659 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
87660 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
87661 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
87662 +depth_write_3021 depth_write 3 3021 NULL
87663 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
87664 +read_file_stations_35795 read_file_stations 3 35795 NULL
87665 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
87666 +tipc_cfg_reply_alloc_27606 tipc_cfg_reply_alloc 1 27606 NULL
87667 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 NULL
87668 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
87669 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 5 60379 NULL
87670 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 NULL
87671 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
87672 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
87673 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
87674 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
87675 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
87676 +driver_names_read_60399 driver_names_read 3 60399 NULL
87677 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL
87678 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
87679 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
87680 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
87681 +_alloc_mISDN_skb_52232 _alloc_mISDN_skb 3 52232 NULL
87682 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
87683 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
87684 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
87685 +do_dmabuf_dirty_ldu_52241 do_dmabuf_dirty_ldu 6 52241 NULL
87686 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
87687 +rx_data_60442 rx_data 4 60442 NULL
87688 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
87689 +efivar_create_sysfs_entry_19485 efivar_create_sysfs_entry 2 19485 NULL
87690 +tcf_csum_ipv4_igmp_60446 tcf_csum_ipv4_igmp 3 60446 NULL
87691 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
87692 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
87693 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
87694 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
87695 +__tty_buffer_request_room_27700 __tty_buffer_request_room 2 27700 NULL
87696 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
87697 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
87698 +tcp_mark_head_lost_35895 tcp_mark_head_lost 2 35895 NULL
87699 +skb_realloc_headroom_19516 skb_realloc_headroom 2 19516 NULL
87700 +atm_alloc_charge_19517 atm_alloc_charge 2 19517 NULL nohasharray
87701 +dev_alloc_skb_19517 dev_alloc_skb 1 19517 &atm_alloc_charge_19517
87702 +construct_key_11329 construct_key 3 11329 NULL
87703 +evm_write_key_27715 evm_write_key 3 27715 NULL
87704 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
87705 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
87706 +filldir_55137 filldir 3 55137 NULL
87707 +igmpv3_newpack_35912 igmpv3_newpack 2 35912 NULL
87708 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
87709 +reg_w_buf_27724 reg_w_buf 3 27724 NULL
87710 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
87711 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
87712 +a4t_cs_init_27734 a4t_cs_init 3 27734 NULL
87713 +sel_write_create_11353 sel_write_create 3 11353 NULL
87714 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
87715 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
87716 +hwflags_read_52318 hwflags_read 3 52318 NULL
87717 +nfc_alloc_send_skb_3167 nfc_alloc_send_skb 4 3167 NULL
87718 +batadv_skb_head_push_11360 batadv_skb_head_push 2 11360 NULL
87719 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
87720 +vmw_gmr_bind_44130 vmw_gmr_bind 3 44130 NULL
87721 +ath_tx_init_60515 ath_tx_init 2 60515 NULL
87722 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
87723 +ntfs_rl_split_52328 ntfs_rl_split 2-4 52328 NULL
87724 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
87725 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
87726 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
87727 +nfsd_read_19568 nfsd_read 5 19568 NULL
87728 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
87729 +hysdn_sched_rx_60533 hysdn_sched_rx 3 60533 NULL
87730 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
87731 +kcalloc_27770 kcalloc 1-2 27770 NULL
87732 +shmem_pread_slow_3198 shmem_pread_slow 3 3198 NULL
87733 +bm_status_read_19583 bm_status_read 3 19583 NULL
87734 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
87735 +zd_mac_rx_38296 zd_mac_rx 3 38296 NULL
87736 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
87737 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL
87738 +acl_alloc_35979 acl_alloc 1 35979 NULL
87739 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
87740 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
87741 +str_to_user_11411 str_to_user 2 11411 NULL
87742 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
87743 +koneplus_sysfs_write_35993 koneplus_sysfs_write 6 35993 NULL
87744 +trace_options_read_11419 trace_options_read 3 11419 NULL
87745 +ttm_object_file_init_27804 ttm_object_file_init 2 27804 NULL
87746 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
87747 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
87748 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
87749 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
87750 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
87751 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
87752 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
87753 +console_store_36007 console_store 4 36007 NULL
87754 +bttv_read_11432 bttv_read 3 11432 NULL
87755 +key_key_read_3241 key_key_read 3 3241 NULL
87756 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
87757 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
87758 +__feat_register_sp_64712 __feat_register_sp 6 64712 NULL
87759 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
87760 +check_vendor_extension_3254 check_vendor_extension 1 3254 NULL
87761 +ieee80211_amsdu_to_8023s_15561 ieee80211_amsdu_to_8023s 5 15561 NULL
87762 +sys_listxattr_27833 sys_listxattr 3 27833 NULL
87763 +aac_rx_ioremap_52410 aac_rx_ioremap 2 52410 NULL
87764 +ubi_eba_write_leb_36029 ubi_eba_write_leb 5-6 36029 NULL
87765 +um_idi_write_18293 um_idi_write 3 18293 NULL
87766 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
87767 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
87768 +usbvision_rvmalloc_19655 usbvision_rvmalloc 1 19655 NULL
87769 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
87770 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
87771 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
87772 +sys_init_module_36047 sys_init_module 2 36047 NULL
87773 +read_profile_27859 read_profile 3 27859 NULL
87774 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
87775 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
87776 +enlarge_skb_44248 enlarge_skb 2 44248 NULL nohasharray
87777 +xfs_buf_readahead_map_44248 xfs_buf_readahead_map 3 44248 &enlarge_skb_44248
87778 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
87779 +refill_pool_19477 refill_pool 2 19477 NULL
87780 +ubifs_recover_leb_60639 ubifs_recover_leb 3 60639 NULL
87781 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
87782 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
87783 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
87784 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
87785 +tcp_sacktag_walk_49703 tcp_sacktag_walk 6 49703 NULL
87786 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
87787 +arvo_sysfs_write_3311 arvo_sysfs_write 6 3311 NULL
87788 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
87789 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
87790 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
87791 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
87792 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
87793 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1-2 52477 NULL
87794 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
87795 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
87796 +venus_symlink_23570 venus_symlink 4-6 23570 NULL
87797 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
87798 +aac_rkt_ioremap_3333 aac_rkt_ioremap 2 3333 NULL
87799 +sctp_make_init_ack_3335 sctp_make_init_ack 4 3335 NULL
87800 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
87801 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
87802 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
87803 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
87804 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
87805 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
87806 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
87807 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
87808 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
87809 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
87810 +ath6kl_usb_ctrl_msg_exchange_33327 ath6kl_usb_ctrl_msg_exchange 4 33327 NULL
87811 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
87812 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
87813 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
87814 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
87815 +vmalloc_exec_36132 vmalloc_exec 1 36132 NULL
87816 +init_data_container_60709 init_data_container 1 60709 NULL
87817 +p9_client_read_19750 p9_client_read 5 19750 NULL
87818 +skb_cow_data_11565 skb_cow_data 2 11565 NULL
87819 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
87820 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
87821 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
87822 +mlx4_init_cmpt_table_11569 mlx4_init_cmpt_table 3 11569 NULL
87823 +iwl_trans_txq_alloc_36147 iwl_trans_txq_alloc 3 36147 NULL
87824 +alloc_vm_area_36149 alloc_vm_area 1 36149 NULL
87825 +ubi_eba_write_leb_st_44343 ubi_eba_write_leb_st 5 44343 NULL
87826 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
87827 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
87828 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
87829 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
87830 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
87831 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
87832 +saa7146_vmalloc_build_pgtable_19780 saa7146_vmalloc_build_pgtable 2 19780 NULL
87833 +send_stream_3397 send_stream 4 3397 NULL
87834 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
87835 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
87836 +ipx_recvmsg_44366 ipx_recvmsg 4 44366 NULL
87837 +hycapi_rx_capipkt_11602 hycapi_rx_capipkt 3 11602 NULL
87838 +msix_map_region_3411 msix_map_region 3 3411 NULL
87839 +sys_kexec_load_14222 sys_kexec_load 2 14222 NULL
87840 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
87841 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
87842 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
87843 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
87844 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
87845 +opticon_write_60775 opticon_write 4 60775 NULL
87846 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
87847 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
87848 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
87849 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
87850 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
87851 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
87852 +vip_read_19832 vip_read 3 19832 NULL
87853 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
87854 +llc_shdlc_alloc_skb_11645 llc_shdlc_alloc_skb 2 11645 NULL
87855 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
87856 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
87857 +nfqnl_mangle_36226 nfqnl_mangle 4-2 36226 NULL
87858 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
87859 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
87860 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
87861 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
87862 +alloc_skb_fclone_3467 alloc_skb_fclone 1 3467 NULL
87863 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
87864 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
87865 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2 28053 NULL
87866 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
87867 +llcp_allocate_pdu_19866 llcp_allocate_pdu 3 19866 NULL
87868 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
87869 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
87870 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
87871 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
87872 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
87873 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
87874 +split_11691 split 2 11691 NULL
87875 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
87876 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
87877 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
87878 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL
87879 +__kfifo_alloc_22173 __kfifo_alloc 2-3 22173 NULL
87880 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
87881 +gdth_init_isa_28091 gdth_init_isa 1 28091 NULL
87882 +readahead_tree_block_36285 readahead_tree_block 3 36285 NULL
87883 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL nohasharray
87884 +ieee80211_wx_set_gen_ie_rsl_3521 ieee80211_wx_set_gen_ie_rsl 3 3521 &mem_tx_free_mem_blks_read_3521
87885 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
87886 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
87887 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
87888 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
87889 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
87890 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
87891 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
87892 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 NULL
87893 +tcf_csum_ipv6_icmp_11738 tcf_csum_ipv6_icmp 4 11738 NULL
87894 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
87895 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
87896 +spidev_write_44510 spidev_write 3 44510 NULL
87897 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
87898 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
87899 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
87900 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
87901 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
87902 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
87903 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
87904 +kone_receive_4690 kone_receive 4 4690 NULL
87905 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
87906 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
87907 +evtchn_read_3569 evtchn_read 3 3569 NULL
87908 +video_read_28148 video_read 3 28148 NULL
87909 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
87910 +sys_msgsnd_44537 sys_msgsnd 3 44537 NULL nohasharray
87911 +comm_write_44537 comm_write 3 44537 &sys_msgsnd_44537
87912 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
87913 +ax25_send_frame_19964 ax25_send_frame 2 19964 NULL
87914 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
87915 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
87916 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
87917 +vc_resize_3585 vc_resize 2-3 3585 NULL
87918 +gluebi_write_27905 gluebi_write 3 27905 NULL
87919 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
87920 +c4iw_reject_cr_28174 c4iw_reject_cr 3 28174 NULL
87921 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
87922 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
87923 +compat_sys_semtimedop_3606 compat_sys_semtimedop 3 3606 NULL
87924 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
87925 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
87926 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
87927 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
87928 +pti_char_write_60960 pti_char_write 3 60960 NULL
87929 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
87930 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
87931 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
87932 +read_vbt_r10_60679 read_vbt_r10 1 60679 NULL
87933 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
87934 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
87935 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL nohasharray
87936 +fwnet_pd_new_39947 fwnet_pd_new 4 39947 &error_error_frame_read_39947
87937 +snd_pcm_alloc_vmalloc_buffer_44595 snd_pcm_alloc_vmalloc_buffer 2 44595 NULL
87938 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
87939 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
87940 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
87941 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
87942 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
87943 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
87944 +cm_copy_private_data_3649 cm_copy_private_data 2 3649 NULL
87945 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
87946 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 NULL nohasharray
87947 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 &ieee80211_if_read_auto_open_plinks_38268
87948 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL
87949 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
87950 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
87951 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
87952 +cfpkt_add_body_44630 cfpkt_add_body 3 44630 NULL
87953 +nf_nat_sdp_media_11863 nf_nat_sdp_media 9 11863 NULL
87954 +alloc_extent_buffer_52824 alloc_extent_buffer 3 52824 NULL
87955 +skb_cow_head_52495 skb_cow_head 2 52495 NULL
87956 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
87957 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
87958 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
87959 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
87960 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
87961 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
87962 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
87963 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
87964 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
87965 +btmrvl_psmode_write_3703 btmrvl_psmode_write 3 3703 NULL
87966 +symtab_init_61050 symtab_init 2 61050 NULL
87967 +team_options_register_20091 team_options_register 3 20091 NULL
87968 +videobuf_pages_to_sg_3708 videobuf_pages_to_sg 2 3708 NULL
87969 +mon_bin_get_event_52863 mon_bin_get_event 4 52863 NULL
87970 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
87971 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
87972 +mpi_resize_44674 mpi_resize 2 44674 NULL
87973 +ip6_append_data_36490 ip6_append_data 4-5 36490 NULL nohasharray
87974 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
87975 +kmalloc_slab_11917 kmalloc_slab 1 11917 NULL
87976 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
87977 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
87978 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
87979 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
87980 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
87981 +xfs_trans_read_buf_map_37487 xfs_trans_read_buf_map 5 37487 NULL
87982 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
87983 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
87984 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
87985 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL
87986 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
87987 +dccp_feat_clone_sp_val_11942 dccp_feat_clone_sp_val 3 11942 NULL
87988 +pms_read_53873 pms_read 3 53873 NULL
87989 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
87990 +get_derived_key_61100 get_derived_key 4 61100 NULL
87991 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
87992 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
87993 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
87994 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
87995 +dm_read_15674 dm_read 3 15674 NULL
87996 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
87997 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
87998 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
87999 +kone_send_63435 kone_send 4 63435 NULL
88000 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
88001 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
88002 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
88003 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
88004 +__kfifo_to_user_36555 __kfifo_to_user 3 36555 NULL nohasharray
88005 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
88006 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
88007 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
88008 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
88009 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
88010 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
88011 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
88012 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
88013 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
88014 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
88015 +send_packet_52960 send_packet 4 52960 NULL
88016 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
88017 +ssb_bus_scan_36578 ssb_bus_scan 2 36578 NULL
88018 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
88019 +tipc_port_reject_sections_55229 tipc_port_reject_sections 5 55229 NULL
88020 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
88021 +set_bypass_pfs_28395 set_bypass_pfs 3 28395 NULL
88022 +put_cmsg_36589 put_cmsg 4 36589 NULL
88023 +__vmalloc_61168 __vmalloc 1 61168 NULL
88024 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
88025 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
88026 +read_file_tx_chainmask_3829 read_file_tx_chainmask 3 3829 NULL
88027 +pcnet32_realloc_rx_ring_36598 pcnet32_realloc_rx_ring 3 36598 NULL
88028 +event_oom_late_read_61175 event_oom_late_read 3 61175 NULL nohasharray
88029 +pair_device_61175 pair_device 4 61175 &event_oom_late_read_61175
88030 +sys_lsetxattr_61177 sys_lsetxattr 4 61177 NULL
88031 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
88032 +nfs4_alloc_pages_48426 nfs4_alloc_pages 1 48426 NULL
88033 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
88034 +batadv_check_management_packet_52993 batadv_check_management_packet 3 52993 NULL
88035 +tpci200_slot_map_space_3848 tpci200_slot_map_space 2 3848 NULL
88036 +regmap_bulk_write_59049 regmap_bulk_write 4 59049 NULL
88037 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
88038 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
88039 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
88040 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
88041 +cfpkt_append_61206 cfpkt_append 3 61206 NULL
88042 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
88043 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
88044 +get_fd_set_3866 get_fd_set 1 3866 NULL
88045 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
88046 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
88047 +unlink_queued_645 unlink_queued 3-4 645 NULL
88048 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
88049 +sisusb_write_44834 sisusb_write 3 44834 NULL
88050 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
88051 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
88052 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
88053 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
88054 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
88055 +uea_send_modem_cmd_3888 uea_send_modem_cmd 3 3888 NULL
88056 +h5_prepare_pkt_12085 h5_prepare_pkt 4 12085 NULL
88057 +nvram_write_3894 nvram_write 3 3894 NULL
88058 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
88059 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
88060 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
88061 +vcs_write_3910 vcs_write 3 3910 NULL
88062 +sctp_make_abort_violation_27959 sctp_make_abort_violation 4 27959 NULL
88063 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
88064 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
88065 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL
88066 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
88067 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
88068 +do_tty_write_44896 do_tty_write 5 44896 NULL
88069 +set_powered_12129 set_powered 4 12129 NULL
88070 +qib_resize_cq_53090 qib_resize_cq 2 53090 NULL
88071 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
88072 +nfs_writedata_alloc_12133 nfs_writedata_alloc 2 12133 NULL
88073 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
88074 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
88075 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
88076 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
88077 +vmw_fifo_reserve_12141 vmw_fifo_reserve 2 12141 NULL
88078 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
88079 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
88080 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
88081 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
88082 +capinc_tty_write_28539 capinc_tty_write 3 28539 NULL
88083 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
88084 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL
88085 +line6_dumpreq_initbuf_53123 line6_dumpreq_initbuf 3 53123 NULL
88086 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4 36740 NULL
88087 +gather_array_56641 gather_array 3 56641 NULL
88088 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
88089 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
88090 +dma_memcpy_to_iovec_12173 dma_memcpy_to_iovec 5 12173 NULL
88091 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
88092 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
88093 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
88094 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
88095 +regcache_rbtree_insert_to_block_58009 regcache_rbtree_insert_to_block 5 58009 NULL
88096 +do_add_counters_3992 do_add_counters 3 3992 NULL
88097 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
88098 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
88099 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
88100 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
88101 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
88102 +ip4ip6_err_36772 ip4ip6_err 5 36772 NULL
88103 +mei_write_4005 mei_write 3 4005 NULL
88104 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
88105 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
88106 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL
88107 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
88108 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
88109 +receive_copy_12216 receive_copy 3 12216 NULL
88110 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 NULL
88111 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
88112 +bcsp_prepare_pkt_12961 bcsp_prepare_pkt 3 12961 NULL
88113 +ftdi_process_packet_45005 ftdi_process_packet 5 45005 NULL
88114 +change_xattr_61390 change_xattr 5 61390 NULL
88115 +find_skb_20431 find_skb 2 20431 NULL
88116 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
88117 +fmc_send_cmd_20435 fmc_send_cmd 5 20435 NULL
88118 +tcp_fragment_20436 tcp_fragment 3 20436 NULL
88119 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
88120 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
88121 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
88122 +sys_sethostname_42962 sys_sethostname 2 42962 NULL
88123 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
88124 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
88125 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
88126 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
88127 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
88128 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
88129 +sctp_make_asconf_4078 sctp_make_asconf 3 4078 NULL
88130 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
88131 +ip_vs_icmp_xmit_v6_20464 ip_vs_icmp_xmit_v6 4 20464 NULL
88132 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
88133 +read_buf_20469 read_buf 2 20469 NULL
88134 +cm_write_36858 cm_write 3 36858 NULL
88135 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
88136 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
88137 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 NULL
88138 +sel_write_user_45060 sel_write_user 3 45060 NULL
88139 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
88140 +__dev_alloc_skb_28681 __dev_alloc_skb 1 28681 NULL
88141 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
88142 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
88143 +fast_user_write_20494 fast_user_write 5 20494 NULL
88144 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
88145 +sctp_make_fwdtsn_53265 sctp_make_fwdtsn 3 53265 NULL
88146 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
88147 +hidraw_report_event_20503 hidraw_report_event 3 20503 NULL
88148 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
88149 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
88150 +lirc_buffer_init_53282 lirc_buffer_init 3-2 53282 NULL
88151 +tipc_msg_build_12326 tipc_msg_build 4 12326 NULL
88152 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
88153 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
88154 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
88155 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
88156 +osst_read_40237 osst_read 3 40237 NULL
88157 +tm6000_read_4151 tm6000_read 3 4151 NULL
88158 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
88159 +usbdev_read_45114 usbdev_read 3 45114 NULL
88160 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
88161 +spi_execute_28736 spi_execute 5 28736 NULL
88162 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
88163 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
88164 +get_alua_req_4166 get_alua_req 3 4166 NULL
88165 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
88166 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
88167 +venus_create_20555 venus_create 4 20555 NULL
88168 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
88169 +batadv_interface_rx_53325 batadv_interface_rx 4 53325 NULL
88170 +receive_packet_12367 receive_packet 2 12367 NULL
88171 +squashfs_cache_init_41656 squashfs_cache_init 2 41656 NULL
88172 +mem_write_22232 mem_write 3 22232 NULL
88173 +read_file_bool_4180 read_file_bool 3 4180 NULL
88174 +send_to_tty_45141 send_to_tty 3 45141 NULL
88175 +fops_read_40672 fops_read 3 40672 NULL
88176 +cxio_init_resource_fifo_28764 cxio_init_resource_fifo 3 28764 NULL
88177 +write_leb_36957 write_leb 5 36957 NULL
88178 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
88179 +device_write_45156 device_write 3 45156 NULL
88180 +i915_max_freq_read_20581 i915_max_freq_read 3 20581 NULL
88181 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
88182 +sparse_early_mem_maps_alloc_node_36971 sparse_early_mem_maps_alloc_node 4 36971 NULL
88183 +batadv_tt_append_diff_20588 batadv_tt_append_diff 4 20588 NULL
88184 +dvb_net_sec_callback_28786 dvb_net_sec_callback 2 28786 NULL
88185 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
88186 +isp1760_register_628 isp1760_register 1-2 628 NULL
88187 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
88188 +lirc_write_20604 lirc_write 3 20604 NULL
88189 +sel_write_member_28800 sel_write_member 3 28800 NULL
88190 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
88191 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
88192 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
88193 +sys_msgrcv_959 sys_msgrcv 3 959 NULL
88194 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL
88195 +pskb_network_may_pull_35336 pskb_network_may_pull 2 35336 NULL
88196 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
88197 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
88198 +setxattr_37006 setxattr 4 37006 NULL
88199 +add_child_45201 add_child 4 45201 NULL
88200 +seq_open_private_61589 seq_open_private 3 61589 NULL
88201 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
88202 +__get_vm_area_61599 __get_vm_area 1 61599 NULL
88203 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
88204 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
88205 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3 20646 NULL
88206 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
88207 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
88208 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
88209 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
88210 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
88211 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL
88212 +ieee80211_rx_bss_info_61630 ieee80211_rx_bss_info 3 61630 NULL
88213 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
88214 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
88215 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
88216 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
88217 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
88218 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 4 20682 NULL
88219 +get_packet_pg_28023 get_packet_pg 4 28023 NULL
88220 +rtllib_auth_challenge_12493 rtllib_auth_challenge 3 12493 NULL
88221 +acpi_tb_parse_root_table_53455 acpi_tb_parse_root_table 1 53455 NULL
88222 +resize_stripes_61650 resize_stripes 2 61650 NULL
88223 +n2_run_53459 n2_run 3 53459 NULL
88224 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
88225 +parse_command_37079 parse_command 2 37079 NULL
88226 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
88227 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
88228 +ttm_page_pool_free_61661 ttm_page_pool_free 2 61661 NULL
88229 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
88230 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
88231 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
88232 +insert_one_name_61668 insert_one_name 7 61668 NULL
88233 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
88234 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
88235 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
88236 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
88237 +lock_loop_61681 lock_loop 1 61681 NULL
88238 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
88239 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
88240 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
88241 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
88242 +vring_add_indirect_20737 vring_add_indirect 3-4 20737 NULL
88243 +push_rx_28939 push_rx 3 28939 NULL
88244 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3 4365 NULL
88245 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
88246 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
88247 +sys_setdomainname_4373 sys_setdomainname 2 4373 NULL
88248 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
88249 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
88250 +nouveau_dmaobj_create__61730 nouveau_dmaobj_create_ 6 61730 NULL
88251 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3 28963 NULL
88252 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
88253 +aac_srcv_ioremap_6659 aac_srcv_ioremap 2 6659 NULL
88254 +ubi_leb_change_10289 ubi_leb_change 4 10289 NULL
88255 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
88256 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
88257 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
88258 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
88259 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
88260 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL
88261 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
88262 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
88263 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL
88264 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
88265 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
88266 +tstats_write_60432 tstats_write 3 60432 NULL nohasharray
88267 +kmalloc_60432 kmalloc 1 60432 &tstats_write_60432
88268 +bin_uuid_28999 bin_uuid 3 28999 NULL
88269 +sys_sendto_20809 sys_sendto 6 20809 NULL
88270 +alloc_page_cgroup_2919 alloc_page_cgroup 1 2919 NULL
88271 +set_registers_53582 set_registers 3 53582 NULL
88272 +fc_fcp_frame_alloc_12624 fc_fcp_frame_alloc 2 12624 NULL
88273 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
88274 +lane2_associate_req_45398 lane2_associate_req 4 45398 NULL
88275 +tcf_csum_ipv4_udp_30777 tcf_csum_ipv4_udp 4 30777 NULL
88276 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
88277 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2 37213 NULL
88278 +keymap_store_45406 keymap_store 4 45406 NULL
88279 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
88280 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
88281 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
88282 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
88283 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
88284 +xz_dec_init_29029 xz_dec_init 2 29029 NULL
88285 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
88286 +tcp_dma_try_early_copy_4457 tcp_dma_try_early_copy 3 4457 NULL
88287 +__do_replace_37227 __do_replace 5 37227 NULL
88288 +dn_alloc_send_pskb_4465 dn_alloc_send_pskb 2 4465 NULL
88289 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
88290 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
88291 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
88292 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
88293 +tso_fragment_29050 tso_fragment 3 29050 NULL
88294 +__alloc_pred_stack_26687 __alloc_pred_stack 2 26687 NULL
88295 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
88296 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
88297 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
88298 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
88299 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
88300 +__iio_allocate_sw_ring_buffer_4843 __iio_allocate_sw_ring_buffer 3 4843 NULL
88301 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
88302 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
88303 +intel_render_ring_init_dri_45446 intel_render_ring_init_dri 2-3 45446 NULL
88304 +udp_sendmsg_4492 udp_sendmsg 4 4492 NULL
88305 +ieee80211_probereq_get_29069 ieee80211_probereq_get 4-6 29069 NULL
88306 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
88307 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
88308 +_alloc_cdb_cont_23609 _alloc_cdb_cont 2 23609 NULL
88309 +set_link_security_4502 set_link_security 4 4502 NULL
88310 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
88311 +l1oip_socket_parse_4507 l1oip_socket_parse 4 4507 NULL
88312 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
88313 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
88314 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
88315 +srp_target_alloc_37288 srp_target_alloc 3 37288 NULL
88316 +mmio_read_40348 mmio_read 4 40348 NULL
88317 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
88318 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
88319 +compat_sys_readv_20911 compat_sys_readv 3 20911 NULL
88320 +ivtv_write_12721 ivtv_write 3 12721 NULL
88321 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4 53682 NULL
88322 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
88323 +sys_llistxattr_4532 sys_llistxattr 3 4532 NULL
88324 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
88325 +da9052_group_write_4534 da9052_group_write 3 4534 NULL
88326 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
88327 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
88328 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
88329 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
88330 +videobuf_vmalloc_to_sg_4548 videobuf_vmalloc_to_sg 2 4548 NULL
88331 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
88332 +ieee80211_rtl_auth_challenge_61897 ieee80211_rtl_auth_challenge 3 61897 NULL
88333 +send_msg_37323 send_msg 4 37323 NULL
88334 +brcmf_sdbrcm_membytes_37324 brcmf_sdbrcm_membytes 3-5 37324 NULL
88335 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
88336 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
88337 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
88338 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
88339 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
88340 +virtqueue_add_buf_59470 virtqueue_add_buf 3-4 59470 NULL
88341 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
88342 +dsp_buffer_alloc_11684 dsp_buffer_alloc 2 11684 NULL
88343 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
88344 +reshape_ring_29147 reshape_ring 2 29147 NULL
88345 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
88346 +au0828_init_isoc_61917 au0828_init_isoc 3-2 61917 NULL
88347 +copy_macs_45534 copy_macs 4 45534 NULL
88348 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
88349 +listxattr_12769 listxattr 3 12769 NULL
88350 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
88351 +wdm_write_53735 wdm_write 3 53735 NULL
88352 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
88353 +send_bulk_static_data_61932 send_bulk_static_data 3 61932 NULL
88354 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
88355 +mempool_create_29437 mempool_create 1 29437 NULL
88356 +platform_create_bundle_12785 platform_create_bundle 4-6 12785 NULL
88357 +brcmf_tx_frame_20978 brcmf_tx_frame 3 20978 NULL
88358 +sock_alloc_send_pskb_21246 sock_alloc_send_pskb 2 21246 NULL
88359 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
88360 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
88361 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
88362 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
88363 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL
88364 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
88365 +mgmt_event_12810 mgmt_event 4 12810 NULL
88366 +ntfs_rl_realloc_nofail_32173 ntfs_rl_realloc_nofail 3 32173 NULL
88367 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
88368 +ipath_create_cq_45586 ipath_create_cq 2 45586 NULL
88369 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL nohasharray
88370 +alloc_group_attrs_29203 alloc_group_attrs 3 29203 &wusb_prf_256_29203
88371 +comedi_alloc_subdevices_29207 comedi_alloc_subdevices 2 29207 NULL
88372 +rdma_set_ib_paths_45592 rdma_set_ib_paths 3 45592 NULL
88373 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
88374 +rds_iw_inc_copy_to_user_29214 rds_iw_inc_copy_to_user 3 29214 NULL
88375 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
88376 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
88377 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
88378 +virtnet_send_command_61993 virtnet_send_command 5-6 61993 NULL
88379 +sys_getxattr_37418 sys_getxattr 4 37418 NULL
88380 +regmap_raw_write_53803 regmap_raw_write 4 53803 NULL
88381 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
88382 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
88383 +t4vf_pktgl_to_skb_39005 t4vf_pktgl_to_skb 2 39005 NULL
88384 +audit_log_n_hex_45617 audit_log_n_hex 3 45617 NULL
88385 +devm_ioremap_29235 devm_ioremap 2-3 29235 NULL
88386 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
88387 +recover_peb_29238 recover_peb 6-7 29238 NULL
88388 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
88389 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
88390 +i915_gem_execbuffer_relocate_slow_25355 i915_gem_execbuffer_relocate_slow 7 25355 NULL
88391 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
88392 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
88393 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
88394 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
88395 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
88396 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
88397 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
88398 +ppp_tx_cp_62044 ppp_tx_cp 5 62044 NULL
88399 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
88400 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
88401 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
88402 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
88403 +do_pselect_62061 do_pselect 1 62061 NULL
88404 +btmrvl_gpiogap_read_4718 btmrvl_gpiogap_read 3 4718 NULL
88405 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
88406 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
88407 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
88408 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
88409 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
88410 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
88411 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
88412 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
88413 +sg_read_25799 sg_read 3 25799 NULL
88414 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
88415 +ci_ll_init_12930 ci_ll_init 3 12930 NULL
88416 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL
88417 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
88418 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
88419 +vmalloc_32_user_37519 vmalloc_32_user 1 37519 NULL
88420 +fd_do_writev_29329 fd_do_writev 3 29329 NULL
88421 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
88422 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
88423 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
88424 +dvb_ca_en50221_init_45718 dvb_ca_en50221_init 4 45718 NULL
88425 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
88426 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
88427 +new_skb_21148 new_skb 1 21148 NULL
88428 +ath6kl_mgmt_tx_21153 ath6kl_mgmt_tx 9 21153 NULL
88429 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
88430 +bm_status_write_12964 bm_status_write 3 12964 NULL
88431 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
88432 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
88433 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
88434 +ip6_ufo_append_data_4780 ip6_ufo_append_data 5-6-7 4780 NULL
88435 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL nohasharray
88436 +nf_nat_mangle_tcp_packet_37551 nf_nat_mangle_tcp_packet 6-8 37551 &sep_create_dcb_dmatables_context_37551
88437 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
88438 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3 45748 NULL nohasharray
88439 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
88440 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
88441 +gnttab_expand_15817 gnttab_expand 1 15817 NULL
88442 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
88443 +sctp_make_chunk_12986 sctp_make_chunk 4 12986 NULL
88444 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
88445 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
88446 +mthca_setup_cmd_doorbells_53954 mthca_setup_cmd_doorbells 2 53954 NULL
88447 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
88448 +video_usercopy_62151 video_usercopy 2 62151 NULL
88449 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
88450 +repair_io_failure_4815 repair_io_failure 4 4815 NULL
88451 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
88452 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
88453 +bnx2i_send_nl_mesg_53353 bnx2i_send_nl_mesg 4 53353 NULL
88454 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
88455 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
88456 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
88457 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL
88458 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
88459 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
88460 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
88461 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
88462 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
88463 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
88464 +input_ff_create_21240 input_ff_create 2 21240 NULL
88465 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
88466 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
88467 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL
88468 +amthi_read_45831 amthi_read 4 45831 NULL
88469 +cmpk_message_handle_tx_54024 cmpk_message_handle_tx 4 54024 NULL
88470 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
88471 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
88472 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
88473 +sys_ipc_4889 sys_ipc 3 4889 NULL
88474 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
88475 +smp_build_cmd_45853 smp_build_cmd 3 45853 NULL
88476 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
88477 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
88478 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
88479 +do_register_entry_29478 do_register_entry 4 29478 NULL
88480 +isdn_write_45863 isdn_write 3 45863 NULL
88481 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
88482 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
88483 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
88484 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
88485 +vmw_gmr2_bind_21305 vmw_gmr2_bind 3 21305 NULL
88486 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
88487 +_malloc_54077 _malloc 1 54077 NULL
88488 +add_res_range_21310 add_res_range 4 21310 NULL
88489 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
88490 +sys_process_vm_writev_4928 sys_process_vm_writev 3-5 4928 NULL
88491 +ntfs_rl_insert_4931 ntfs_rl_insert 2-4 4931 NULL
88492 +ip_make_skb_13129 ip_make_skb 5-6 13129 NULL
88493 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
88494 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
88495 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
88496 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL
88497 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
88498 +create_xattr_54106 create_xattr 5 54106 NULL
88499 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
88500 +ep_write_59008 ep_write 3 59008 NULL
88501 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
88502 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
88503 +devm_kzalloc_4966 devm_kzalloc 2 4966 NULL
88504 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
88505 +udf_sb_alloc_partition_maps_62313 udf_sb_alloc_partition_maps 2 62313 NULL
88506 +alloc_mr_45935 alloc_mr 1 45935 NULL
88507 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
88508 +isku_receive_54130 isku_receive 4 54130 NULL
88509 +hfcpci_empty_bfifo_62323 hfcpci_empty_bfifo 4 62323 NULL
88510 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
88511 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
88512 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
88513 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
88514 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
88515 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
88516 +i915_max_freq_write_11350 i915_max_freq_write 3 11350 NULL
88517 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
88518 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
88519 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
88520 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
88521 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
88522 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
88523 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
88524 +alloc_ldt_21972 alloc_ldt 2 21972 NULL
88525 +ipath_resize_cq_712 ipath_resize_cq 2 712 NULL
88526 +comedi_read_13199 comedi_read 3 13199 NULL
88527 +flash_write_62354 flash_write 3 62354 NULL
88528 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
88529 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
88530 +i2400m_zrealloc_2x_54166 i2400m_zrealloc_2x 3 54166 NULL nohasharray
88531 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 &i2400m_zrealloc_2x_54166
88532 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
88533 +proc_file_read_53905 proc_file_read 3 53905 NULL
88534 +mtd_device_parse_register_5024 mtd_device_parse_register 5 5024 NULL
88535 +acpi_tb_install_table_12988 acpi_tb_install_table 1 12988 NULL
88536 +set_wd_exp_mode_pfs_62372 set_wd_exp_mode_pfs 3 62372 NULL
88537 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
88538 +acpi_os_read_memory_54186 acpi_os_read_memory 1-3 54186 NULL
88539 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
88540 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
88541 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
88542 +cru_detect_11272 cru_detect 1 11272 NULL
88543 +altera_irscan_62396 altera_irscan 2 62396 NULL
88544 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
88545 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
88546 +fw_download_code_13249 fw_download_code 3 13249 NULL
88547 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
88548 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
88549 +set_ssp_62411 set_ssp 4 62411 NULL
88550 +nfc_hci_send_event_21452 nfc_hci_send_event 5 21452 NULL
88551 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
88552 +get_free_entries_46030 get_free_entries 1 46030 NULL
88553 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
88554 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
88555 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
88556 +carl9170_rx_13272 carl9170_rx 3 13272 NULL
88557 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
88558 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL
88559 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
88560 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3 5091 NULL
88561 +netdev_alloc_skb_62437 netdev_alloc_skb 2 62437 NULL
88562 +dma_memcpy_pg_to_iovec_1725 dma_memcpy_pg_to_iovec 6 1725 NULL
88563 +platform_device_add_resources_13289 platform_device_add_resources 3 13289 NULL
88564 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
88565 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
88566 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
88567 +e1000_check_copybreak_62448 e1000_check_copybreak 3 62448 NULL
88568 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
88569 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
88570 +wusb_prf_54261 wusb_prf 7 54261 NULL nohasharray
88571 +audio_write_54261 audio_write 4 54261 &wusb_prf_54261
88572 +sys_setxattr_37880 sys_setxattr 4 37880 NULL
88573 +dvb_net_sec_37884 dvb_net_sec 3 37884 NULL
88574 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
88575 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
88576 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
88577 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
88578 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL nohasharray
88579 +xz_dec_lzma2_create_36353 xz_dec_lzma2_create 2 36353 &v9fs_file_readn_36353
88580 +vfio_config_do_rw_46091 vfio_config_do_rw 3 46091 NULL
88581 +dma_skb_copy_datagram_iovec_21516 dma_skb_copy_datagram_iovec 3-5 21516 NULL
88582 +ata_host_alloc_46094 ata_host_alloc 2 46094 NULL
88583 +probes_write_29711 probes_write 3 29711 NULL
88584 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
88585 +us122l_ctl_msg_13330 us122l_ctl_msg 8 13330 NULL
88586 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
88587 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
88588 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
88589 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
88590 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL
88591 +tipc_link_send_sections_fast_37920 tipc_link_send_sections_fast 4 37920 NULL
88592 +mlx4_en_create_rx_ring_62498 mlx4_en_create_rx_ring 3 62498 NULL
88593 +emi62_writememory_29731 emi62_writememory 4 29731 NULL
88594 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
88595 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
88596 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL
88597 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
88598 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
88599 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
88600 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
88601 +pn_raw_send_54330 pn_raw_send 2 54330 NULL
88602 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
88603 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
88604 +sfi_map_memory_5183 sfi_map_memory 1-2 5183 NULL
88605 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
88606 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
88607 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
88608 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
88609 +ddp_clear_map_46152 ddp_clear_map 4 46152 NULL
88610 +cxio_hal_init_resource_29771 cxio_hal_init_resource 2-6-7 29771 NULL nohasharray
88611 +ip_vs_conn_fill_param_sync_29771 ip_vs_conn_fill_param_sync 6 29771 &cxio_hal_init_resource_29771
88612 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
88613 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
88614 +_osd_realloc_seg_54352 _osd_realloc_seg 3 54352 NULL
88615 +pipe_set_size_5204 pipe_set_size 2 5204 NULL
88616 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
88617 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
88618 +isdn_read_50021 isdn_read 3 50021 NULL
88619 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
88620 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
88621 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
88622 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
88623 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
88624 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
88625 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
88626 +ssb_ioremap_5228 ssb_ioremap 2 5228 NULL
88627 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
88628 +xlog_do_recovery_pass_21618 xlog_do_recovery_pass 3 21618 NULL
88629 +isdn_ppp_skb_push_5236 isdn_ppp_skb_push 2 5236 NULL
88630 +get_subdir_62581 get_subdir 3 62581 NULL
88631 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
88632 +sctp_abort_pkt_new_5241 sctp_abort_pkt_new 6 5241 NULL
88633 +vfs_readv_38011 vfs_readv 3 38011 NULL
88634 +keyring_read_13438 keyring_read 3 13438 NULL
88635 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL nohasharray
88636 +set_tap_pwup_pfs_13440 set_tap_pwup_pfs 3 13440 &sctp_setsockopt_peer_primary_addr_13440
88637 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
88638 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
88639 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
88640 +packet_alloc_skb_62602 packet_alloc_skb 2-5-4 62602 NULL
88641 +prism2_send_mgmt_62605 prism2_send_mgmt 4 62605 NULL nohasharray
88642 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 &prism2_send_mgmt_62605
88643 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
88644 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
88645 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
88646 +ftrace_write_29551 ftrace_write 3 29551 NULL
88647 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL
88648 +iscsi_post_host_event_13473 iscsi_post_host_event 4 13473 NULL
88649 +ems_pcmcia_add_card_62627 ems_pcmcia_add_card 2 62627 NULL
88650 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
88651 +dev_write_7708 dev_write 3 7708 NULL
88652 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
88653 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
88654 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
88655 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
88656 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
88657 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
88658 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
88659 +nf_nat_ftp_46265 nf_nat_ftp 6 46265 NULL
88660 +nfc_targets_found_29886 nfc_targets_found 3 29886 NULL
88661 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
88662 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
88663 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
88664 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
88665 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
88666 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
88667 +bm_init_13529 bm_init 2 13529 NULL
88668 +check586_29914 check586 2 29914 NULL
88669 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
88670 +pep_alloc_skb_46303 pep_alloc_skb 3 46303 NULL
88671 +reiserfs_allocate_list_bitmaps_21732 reiserfs_allocate_list_bitmaps 3 21732 NULL
88672 +ioremap_wc_62695 ioremap_wc 1-2 62695 NULL
88673 +pg_read_17276 pg_read 3 17276 NULL
88674 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
88675 +ep0_read_38095 ep0_read 3 38095 NULL
88676 +batadv_iv_ogm_queue_add_46319 batadv_iv_ogm_queue_add 3 46319 NULL
88677 +__nf_nat_mangle_tcp_packet_21744 __nf_nat_mangle_tcp_packet 8-6 21744 NULL
88678 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
88679 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
88680 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
88681 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
88682 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
88683 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
88684 +l2down_create_21755 l2down_create 4 21755 NULL
88685 +alloc_tio_13564 alloc_tio 3 13564 NULL
88686 +viacam_read_54526 viacam_read 3 54526 NULL
88687 +btrfs_mksubvol_58240 btrfs_mksubvol 3 58240 NULL
88688 +tunables_read_36385 tunables_read 3 36385 NULL
88689 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
88690 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
88691 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
88692 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4 38153 NULL
88693 +setsockopt_54539 setsockopt 5 54539 NULL
88694 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
88695 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
88696 +tty_register_device_4544 tty_register_device 2 4544 NULL
88697 +cache_write_13589 cache_write 3 13589 NULL
88698 +mpt_lan_receive_post_turbo_13592 mpt_lan_receive_post_turbo 2 13592 NULL
88699 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
88700 +key_replays_read_62746 key_replays_read 3 62746 NULL
88701 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
88702 +aac_sa_ioremap_13596 aac_sa_ioremap 2 13596 NULL nohasharray
88703 +irias_new_octseq_value_13596 irias_new_octseq_value 2 13596 &aac_sa_ioremap_13596
88704 +mwifiex_usb_submit_rx_urb_54558 mwifiex_usb_submit_rx_urb 2 54558 NULL
88705 +irias_add_octseq_attrib_29983 irias_add_octseq_attrib 4 29983 NULL
88706 +cdev_add_38176 cdev_add 2-3 38176 NULL
88707 +brcmf_sdcard_recv_buf_38179 brcmf_sdcard_recv_buf 6 38179 NULL
88708 +__ioremap_caller_21800 __ioremap_caller 1-2 21800 NULL
88709 +alloc_and_copy_ftrace_hash_29368 alloc_and_copy_ftrace_hash 1 29368 NULL
88710 +ubi_dump_flash_46381 ubi_dump_flash 4 46381 NULL
88711 +swap_cgroup_swapon_13614 swap_cgroup_swapon 2 13614 NULL
88712 +wm8994_bulk_write_13615 wm8994_bulk_write 3 13615 NULL
88713 +init_chip_wc_pat_62768 init_chip_wc_pat 2 62768 NULL
88714 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
88715 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
88716 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
88717 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
88718 +vmalloc_user_32308 vmalloc_user 1 32308 NULL
88719 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
88720 +ath6kl_wmi_startscan_cmd_33674 ath6kl_wmi_startscan_cmd 8 33674 NULL
88721 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
88722 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL
88723 +packet_snd_13634 packet_snd 3 13634 NULL
88724 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
88725 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
88726 +sfi_map_table_5462 sfi_map_table 1 5462 NULL
88727 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
88728 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
88729 +fwSendNullPacket_54618 fwSendNullPacket 2 54618 NULL
88730 +drp_wmove_30043 drp_wmove 4 30043 NULL
88731 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
88732 +cache_downcall_13666 cache_downcall 3 13666 NULL
88733 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
88734 +ubi_leb_write_5478 ubi_leb_write 4-5 5478 NULL
88735 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
88736 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
88737 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
88738 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
88739 +tty_write_5494 tty_write 3 5494 NULL
88740 +iscsi_ping_comp_event_38263 iscsi_ping_comp_event 5 38263 NULL
88741 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL
88742 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
88743 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
88744 +teiup_create_43201 teiup_create 3 43201 NULL
88745 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
88746 +filldir64_46469 filldir64 3 46469 NULL
88747 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL nohasharray
88748 +set_dis_disc_pfs_28225 set_dis_disc_pfs 3 28225 &line6_alloc_sysex_buffer_28225
88749 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
88750 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
88751 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
88752 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
88753 +tg3_run_loopback_30093 tg3_run_loopback 2 30093 NULL
88754 +spidev_message_5518 spidev_message 3 5518 NULL
88755 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
88756 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
88757 +ezusb_writememory_45976 ezusb_writememory 4 45976 NULL
88758 +evm_read_key_54674 evm_read_key 3 54674 NULL
88759 +sctp_make_op_error_space_5528 sctp_make_op_error_space 3 5528 NULL
88760 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
88761 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
88762 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
88763 +em28xx_init_isoc_62883 em28xx_init_isoc 4 62883 NULL nohasharray
88764 +aoechr_write_62883 aoechr_write 3 62883 &em28xx_init_isoc_62883
88765 +resize_info_buffer_62889 resize_info_buffer 2 62889 NULL
88766 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
88767 +u32_array_read_2219 u32_array_read 3 2219 NULL
88768 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
88769 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
88770 +sys_add_key_61288 sys_add_key 4 61288 NULL
88771 +kmsg_read_46514 kmsg_read 3 46514 NULL
88772 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
88773 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
88774 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
88775 +recv_stream_30138 recv_stream 4 30138 NULL
88776 +u_memcpya_30139 u_memcpya 2-3 30139 NULL
88777 +getdqbuf_62908 getdqbuf 1 62908 NULL
88778 +bdx_rxdb_create_46525 bdx_rxdb_create 1 46525 NULL
88779 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
88780 +_add_sg_continuation_descriptor_54721 _add_sg_continuation_descriptor 3 54721 NULL
88781 +fc_frame_alloc_fill_59394 fc_frame_alloc_fill 2 59394 NULL
88782 +fir16_create_5574 fir16_create 3 5574 NULL
88783 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
88784 +pt_write_40159 pt_write 3 40159 NULL
88785 +bioset_create_5580 bioset_create 1 5580 NULL
88786 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
88787 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
88788 +oz_ep_alloc_5587 oz_ep_alloc 2 5587 NULL
88789 +kzalloc_54740 kzalloc 1 54740 NULL
88790 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
88791 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
88792 +do_msgrcv_5590 do_msgrcv 4 5590 NULL
88793 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
88794 +link_send_sections_long_46556 link_send_sections_long 4 46556 NULL
88795 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
88796 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
88797 +batadv_iv_ogm_aggregate_new_54761 batadv_iv_ogm_aggregate_new 2 54761 NULL
88798 +ldm_frag_add_5611 ldm_frag_add 2 5611 NULL
88799 +cx25821_video_ioctl_30188 cx25821_video_ioctl 2 30188 NULL
88800 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
88801 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 NULL nohasharray
88802 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3 22001 &rxpipe_descr_host_int_trig_rx_data_read_22001
88803 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
88804 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
88805 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
88806 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
88807 +hidp_output_raw_report_5629 hidp_output_raw_report 3 5629 NULL
88808 +nfs_idmap_request_key_30208 nfs_idmap_request_key 3 30208 NULL
88809 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
88810 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
88811 +snd_ac97_pcm_assign_30218 snd_ac97_pcm_assign 2 30218 NULL
88812 +ti_recv_22027 ti_recv 4 22027 NULL
88813 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2 34135 NULL
88814 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
88815 +nfsd_write_54809 nfsd_write 6 54809 NULL
88816 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
88817 +pcnet32_realloc_tx_ring_38428 pcnet32_realloc_tx_ring 3 38428 NULL
88818 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
88819 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
88820 +get_skb_63008 get_skb 2 63008 NULL
88821 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
88822 +netlink_send_38434 netlink_send 5 38434 NULL
88823 +atalk_recvmsg_22053 atalk_recvmsg 4 22053 NULL
88824 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL nohasharray
88825 +alloc_trace_uprobe_13870 alloc_trace_uprobe 3 13870 &compat_ip_setsockopt_13870
88826 +aircable_process_packet_46639 aircable_process_packet 5 46639 NULL
88827 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
88828 +write_rio_54837 write_rio 3 54837 NULL
88829 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 NULL
88830 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
88831 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
88832 +get_arg_5694 get_arg 3 5694 NULL
88833 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
88834 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
88835 +compat_readv_30273 compat_readv 3 30273 NULL
88836 +printer_read_54851 printer_read 3 54851 NULL
88837 +mem_rw_22085 mem_rw 3 22085 NULL
88838 +i915_min_freq_read_38470 i915_min_freq_read 3 38470 NULL
88839 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
88840 +lowpan_fragment_xmit_22095 lowpan_fragment_xmit 3-4 22095 NULL
88841 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
88842 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
88843 +unlink1_63059 unlink1 3 63059 NULL
88844 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL
88845 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
88846 +__do_krealloc_54389 __do_krealloc 2 54389 NULL
88847 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
88848 +tcf_csum_ipv6_tcp_54877 tcf_csum_ipv6_tcp 4 54877 NULL
88849 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
88850 +replay_log_leb_18704 replay_log_leb 3 18704 NULL
88851 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
88852 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
88853 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
88854 +dev_names_read_38509 dev_names_read 3 38509 NULL
88855 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
88856 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 NULL
88857 +get_packet_5747 get_packet 3 5747 NULL
88858 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL
88859 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
88860 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
88861 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
88862 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
88863 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
88864 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
88865 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
88866 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
88867 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
88868 +_l2_alloc_skb_11883 _l2_alloc_skb 1 11883 NULL
88869 +resource_from_user_30341 resource_from_user 3 30341 NULL
88870 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
88871 +sound_write_5102 sound_write 3 5102 NULL
88872 +pn533_dep_link_up_22154 pn533_dep_link_up 5 22154 NULL
88873 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
88874 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
88875 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
88876 +__vmalloc_node_flags_30352 __vmalloc_node_flags 1 30352 NULL
88877 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
88878 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
88879 +com90xx_found_13974 com90xx_found 3 13974 NULL
88880 +compat_sys_writev_5784 compat_sys_writev 3 5784 NULL
88881 +qcam_read_13977 qcam_read 3 13977 NULL
88882 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
88883 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
88884 +virtblk_add_buf_wait_54943 virtblk_add_buf_wait 3-4 54943 NULL
88885 +wl12xx_cmd_build_probe_req_54946 wl12xx_cmd_build_probe_req 6-8 54946 NULL
88886 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
88887 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
88888 +generic_readlink_32654 generic_readlink 3 32654 NULL
88889 +ieee80211_bss_info_update_13991 ieee80211_bss_info_update 4 13991 NULL
88890 +sys_get_mempolicy_30379 sys_get_mempolicy 3 30379 NULL
88891 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
88892 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
88893 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
88894 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL
88895 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
88896 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
88897 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
88898 +__proc_file_read_54978 __proc_file_read 3 54978 NULL
88899 +concat_writev_21451 concat_writev 3 21451 NULL
88900 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
88901 +_queue_data_54983 _queue_data 4 54983 NULL
88902 +_sys_packet_req_46793 _sys_packet_req 4 46793 NULL
88903 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
88904 +extend_netdev_table_21453 extend_netdev_table 2 21453 NULL
88905 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
88906 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
88907 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
88908 +ixgb_check_copybreak_5847 ixgb_check_copybreak 3 5847 NULL
88909 +setup_req_5848 setup_req 3 5848 NULL
88910 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
88911 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
88912 +rds_ib_inc_copy_to_user_55007 rds_ib_inc_copy_to_user 3 55007 NULL
88913 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
88914 +rbd_create_rw_ops_55297 rbd_create_rw_ops 1 55297 NULL
88915 +compat_sys_move_pages_5861 compat_sys_move_pages 2 5861 NULL
88916 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
88917 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
88918 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
88919 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
88920 +cma_create_area_38642 cma_create_area 2 38642 NULL
88921 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
88922 +sriov_enable_59689 sriov_enable 2 59689 NULL
88923 +enable_write_30456 enable_write 3 30456 NULL
88924 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
88925 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
88926 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
88927 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
88928 +tcp_manip_pkt_16563 tcp_manip_pkt 4 16563 NULL
88929 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
88930 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
88931 +ieee80211_mgmt_tx_46860 ieee80211_mgmt_tx 9 46860 NULL
88932 +port_show_regs_5904 port_show_regs 3 5904 NULL
88933 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
88934 +ptp_read_63251 ptp_read 4 63251 NULL
88935 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
88936 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
88937 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
88938 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL
88939 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
88940 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
88941 +ttm_bo_kmap_ttm_5922 ttm_bo_kmap_ttm 3 5922 NULL
88942 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
88943 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
88944 +iscsi_iser_recv_41948 iscsi_iser_recv 4 41948 NULL
88945 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
88946 +em28xx_alloc_isoc_46892 em28xx_alloc_isoc 4 46892 NULL
88947 +read_dma_55086 read_dma 3 55086 NULL
88948 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
88949 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
88950 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
88951 +ntfs_rl_replace_14136 ntfs_rl_replace 2-4 14136 NULL
88952 +ip_send_unicast_reply_38714 ip_send_unicast_reply 6 38714 NULL
88953 +tcp_collapse_63294 tcp_collapse 6-5 63294 NULL
88954 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
88955 +isdn_ppp_ccp_xmit_reset_63297 isdn_ppp_ccp_xmit_reset 6 63297 NULL
88956 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
88957 +tipc_subseq_alloc_5957 tipc_subseq_alloc 1 5957 NULL
88958 +em_canid_change_14150 em_canid_change 3 14150 NULL
88959 +tracing_ctrl_read_46922 tracing_ctrl_read 3 46922 NULL
88960 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
88961 +fb_write_46924 fb_write 3 46924 NULL
88962 +btmrvl_curpsmode_read_46939 btmrvl_curpsmode_read 3 46939 NULL
88963 +wlcore_alloc_hw_22365 wlcore_alloc_hw 1 22365 NULL
88964 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
88965 +br_send_bpdu_29669 br_send_bpdu 3 29669 NULL
88966 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
88967 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
88968 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
88969 +udf_readpages_38761 udf_readpages 4 38761 NULL
88970 +reada_add_block_54247 reada_add_block 2 54247 NULL
88971 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
88972 +proc_info_read_63344 proc_info_read 3 63344 NULL
88973 +pep_indicate_38611 pep_indicate 5 38611 NULL
88974 +set_le_30581 set_le 4 30581 NULL
88975 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
88976 +btmrvl_psmode_read_22395 btmrvl_psmode_read 3 22395 NULL
88977 +alloc_private_22399 alloc_private 2 22399 NULL
88978 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
88979 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
88980 +zoran_write_22404 zoran_write 3 22404 NULL
88981 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL
88982 +idmouse_read_63374 idmouse_read 3 63374 NULL
88983 +queue_reply_22416 queue_reply 3 22416 NULL
88984 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
88985 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
88986 +ntfs_rl_append_6037 ntfs_rl_append 2-4 6037 NULL
88987 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
88988 +ttm_bo_io_47000 ttm_bo_io 5 47000 NULL
88989 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
88990 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
88991 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL
88992 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
88993 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
88994 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4-2 14244 NULL
88995 +snd_soc_hw_bulk_write_raw_14245 snd_soc_hw_bulk_write_raw 4 14245 NULL
88996 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL nohasharray
88997 +isdn_net_ciscohdlck_alloc_skb_55209 isdn_net_ciscohdlck_alloc_skb 2 55209 &ht40allow_map_read_55209
88998 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
88999 +sys_select_38827 sys_select 1 38827 NULL
89000 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
89001 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
89002 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2 47024 NULL
89003 +direct_entry_38836 direct_entry 3 38836 NULL
89004 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
89005 +gntdev_alloc_map_35145 gntdev_alloc_map 2 35145 NULL
89006 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
89007 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
89008 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
89009 +write_head_30481 write_head 4 30481 NULL
89010 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
89011 +set_dis_bypass_pfs_47038 set_dis_bypass_pfs 3 47038 NULL
89012 +add_numbered_child_14273 add_numbered_child 5 14273 NULL
89013 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
89014 +OS_mem_token_alloc_14276 OS_mem_token_alloc 1 14276 NULL
89015 +sep_prepare_input_output_dma_table_63429 sep_prepare_input_output_dma_table 2-4-3 63429 NULL
89016 +register_unifi_sdio_55239 register_unifi_sdio 2 55239 NULL
89017 +ath6kl_wmi_get_new_buf_52304 ath6kl_wmi_get_new_buf 1 52304 NULL
89018 +agp_remap_30665 agp_remap 2 30665 NULL
89019 +interfaces_38859 interfaces 2 38859 NULL
89020 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
89021 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
89022 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
89023 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
89024 +qc_capture_19298 qc_capture 3 19298 NULL
89025 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
89026 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
89027 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
89028 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
89029 +rtl_port_map_2385 rtl_port_map 1-2 2385 NULL
89030 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
89031 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
89032 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
89033 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
89034 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
89035 +process_bulk_data_command_38906 process_bulk_data_command 4 38906 NULL
89036 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
89037 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
89038 +read_kcore_63488 read_kcore 3 63488 NULL
89039 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
89040 +__skb_cow_39254 __skb_cow 2 39254 NULL
89041 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
89042 +__get_vm_area_node_55305 __get_vm_area_node 1 55305 NULL
89043 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
89044 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
89045 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
89046 +pskb_may_pull_22546 pskb_may_pull 2 22546 NULL
89047 +mousedev_read_47123 mousedev_read 3 47123 NULL
89048 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
89049 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
89050 +vdma_mem_alloc_6171 vdma_mem_alloc 1 6171 NULL
89051 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
89052 +ses_recv_diag_47143 ses_recv_diag 4 47143 NULL nohasharray
89053 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 &ses_recv_diag_47143
89054 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
89055 +vme_user_read_55338 vme_user_read 3 55338 NULL
89056 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL
89057 +cxio_init_resource_fifo_random_47151 cxio_init_resource_fifo_random 3 47151 NULL
89058 +persistent_ram_iomap_47156 persistent_ram_iomap 1-2 47156 NULL
89059 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
89060 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
89061 +__hidp_send_ctrl_message_28303 __hidp_send_ctrl_message 4 28303 NULL
89062 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
89063 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
89064 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
89065 +acpi_system_read_event_55362 acpi_system_read_event 3 55362 NULL
89066 +dbg_leb_write_63555 dbg_leb_write 4-5 63555 NULL nohasharray
89067 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 &dbg_leb_write_63555
89068 +snapshot_read_22601 snapshot_read 3 22601 NULL
89069 +OSDSetBlock_38986 OSDSetBlock 4-2 38986 NULL
89070 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
89071 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
89072 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
89073 +ioremap_cache_47189 ioremap_cache 1-2 47189 NULL
89074 +__send_to_port_55383 __send_to_port 3 55383 NULL
89075 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
89076 +nf_nat_ipv4_manip_pkt_55387 nf_nat_ipv4_manip_pkt 2 55387 NULL
89077 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
89078 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
89079 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
89080 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
89081 +get_nodes_39012 get_nodes 3 39012 NULL
89082 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
89083 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
89084 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
89085 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
89086 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
89087 +create_subvol_30836 create_subvol 4 30836 NULL
89088 +mthca_map_reg_5664 mthca_map_reg 2-3 5664 NULL
89089 +ci13xxx_add_device_14456 ci13xxx_add_device 3 14456 NULL
89090 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
89091 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
89092 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
89093 +read_oldmem_55658 read_oldmem 3 55658 NULL
89094 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
89095 +xenbus_file_write_6282 xenbus_file_write 3 6282 NULL
89096 +options_write_47243 options_write 3 47243 NULL
89097 +module_alloc_63630 module_alloc 1 63630 NULL
89098 +alloc_skb_55439 alloc_skb 1 55439 NULL
89099 +nf_nat_ipv6_manip_pkt_6289 nf_nat_ipv6_manip_pkt 2 6289 NULL
89100 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
89101 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
89102 +ubifs_leb_write_22679 ubifs_leb_write 4-5 22679 NULL
89103 +nf_nat_sack_adjust_6297 nf_nat_sack_adjust 2 6297 NULL
89104 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
89105 +mid_get_vbt_data_r10_6308 mid_get_vbt_data_r10 2 6308 NULL
89106 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
89107 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
89108 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
89109 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
89110 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
89111 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
89112 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
89113 +tty_audit_log_47280 tty_audit_log 8 47280 NULL
89114 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
89115 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
89116 +fc_host_post_vendor_event_30903 fc_host_post_vendor_event 3 30903 NULL
89117 +vbi_read_63673 vbi_read 3 63673 NULL
89118 +tun_get_user_39099 tun_get_user 4 39099 NULL
89119 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
89120 +alloc_tty_driver_63681 alloc_tty_driver 1 63681 NULL
89121 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
89122 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
89123 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
89124 +nfc_hci_hcp_message_tx_14534 nfc_hci_hcp_message_tx 6 14534 NULL
89125 +iommu_map_mmio_space_30919 iommu_map_mmio_space 1 30919 NULL
89126 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
89127 +dataflash_read_user_otp_14536 dataflash_read_user_otp 2-3 14536 &ep0_write_14536
89128 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
89129 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4 22735 NULL
89130 +ax25_output_22736 ax25_output 2 22736 NULL
89131 +__kfifo_to_user_r_39123 __kfifo_to_user_r 3 39123 NULL
89132 +l2cap_send_cmd_14548 l2cap_send_cmd 4 14548 NULL
89133 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
89134 +drm_vmalloc_dma_14550 drm_vmalloc_dma 1 14550 NULL
89135 +cfpkt_pad_trail_55511 cfpkt_pad_trail 2 55511 NULL nohasharray
89136 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 &cfpkt_pad_trail_55511
89137 +cmtp_add_msgpart_9252 cmtp_add_msgpart 4 9252 NULL
89138 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
89139 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
89140 +hid_input_report_32458 hid_input_report 4 32458 NULL
89141 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
89142 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
89143 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
89144 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
89145 +alloc_ring_39151 alloc_ring 2-4 39151 NULL
89146 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
89147 +create_bounce_buffer_39155 create_bounce_buffer 3 39155 NULL
89148 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
89149 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
89150 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
89151 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
89152 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
89153 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
89154 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
89155 +bt_skb_alloc_6404 bt_skb_alloc 1 6404 NULL
89156 +get_info_55681 get_info 3 55681 NULL
89157 +setkey_14987 setkey 3 14987 NULL
89158 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
89159 +init_list_set_39188 init_list_set 2-3 39188 NULL
89160 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
89161 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
89162 +l2up_create_6430 l2up_create 3 6430 NULL
89163 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
89164 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
89165 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
89166 +add_partition_55588 add_partition 2 55588 NULL
89167 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
89168 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
89169 +depth_read_31112 depth_read 3 31112 NULL
89170 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
89171 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
89172 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
89173 +profile_replace_14652 profile_replace 3 14652 NULL
89174 +vzalloc_47421 vzalloc 1 47421 NULL
89175 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
89176 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
89177 +sys_writev_28384 sys_writev 3 28384 NULL
89178 +batadv_tt_response_fill_table_39236 batadv_tt_response_fill_table 1 39236 NULL
89179 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
89180 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4 44769 NULL
89181 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
89182 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL
89183 +create_attr_set_22861 create_attr_set 1 22861 NULL
89184 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
89185 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
89186 +compat_sys_mq_timedsend_31060 compat_sys_mq_timedsend 3 31060 NULL
89187 +sel_write_load_63830 sel_write_load 3 63830 NULL
89188 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
89189 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
89190 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
89191 +dvb_dmxdev_set_buffer_size_55643 dvb_dmxdev_set_buffer_size 2 55643 NULL
89192 +tsi148_master_set_14685 tsi148_master_set 4 14685 NULL
89193 +ath6kl_wmi_set_appie_cmd_39266 ath6kl_wmi_set_appie_cmd 5 39266 NULL
89194 +probe_bios_17467 probe_bios 1 17467 NULL
89195 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
89196 +ttm_bo_ioremap_31082 ttm_bo_ioremap 2-3 31082 NULL
89197 +mei_read_6507 mei_read 3 6507 NULL
89198 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
89199 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
89200 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
89201 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
89202 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
89203 +SetArea_50835 SetArea 4 50835 NULL
89204 +tpm_read_50344 tpm_read 3 50344 NULL
89205 +newpart_47485 newpart 6 47485 NULL
89206 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
89207 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
89208 +core_sys_select_47494 core_sys_select 1 47494 NULL
89209 +read_file_disable_ani_6536 read_file_disable_ani 3 6536 NULL
89210 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
89211 +__vmalloc_node_39308 __vmalloc_node 1 39308 NULL
89212 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
89213 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
89214 +unlink_simple_47506 unlink_simple 3 47506 NULL
89215 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
89216 +wdm_read_6549 wdm_read 3 6549 NULL
89217 +init_map_ipmac_63896 init_map_ipmac 4-3 63896 NULL
89218 +tipc_multicast_49144 tipc_multicast 5 49144 NULL
89219 +nfs4_realloc_slot_table_22859 nfs4_realloc_slot_table 2 22859 NULL
89220 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
89221 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
89222 +__videobuf_alloc_uncached_55711 __videobuf_alloc_uncached 1 55711 NULL
89223 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
89224 +nfc_hci_send_cmd_55714 nfc_hci_send_cmd 5 55714 NULL
89225 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
89226 +filter_read_61692 filter_read 3 61692 NULL
89227 +mtdswap_init_55719 mtdswap_init 2 55719 NULL
89228 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
89229 +debugfs_read_62535 debugfs_read 3 62535 NULL
89230 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
89231 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL
89232 +divas_write_63901 divas_write 3 63901 NULL
89233 +alloc_sglist_22960 alloc_sglist 1-2-3 22960 NULL
89234 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
89235 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
89236 +cfpkt_split_47541 cfpkt_split 2 47541 NULL
89237 +__copy_from_user_nocache_39351 __copy_from_user_nocache 3 39351 NULL
89238 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
89239 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 3-2 55738 NULL
89240 +ipw_write_59807 ipw_write 3 59807 NULL
89241 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
89242 +tipc_send2port_63935 tipc_send2port 5 63935 NULL
89243 +do_write_log_from_user_39362 do_write_log_from_user 3 39362 NULL
89244 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
89245 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
89246 +mwifiex_cfg80211_mgmt_tx_12022 mwifiex_cfg80211_mgmt_tx 9 12022 NULL
89247 +cycx_setup_47562 cycx_setup 4 47562 NULL
89248 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
89249 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
89250 +set_local_name_55757 set_local_name 4 55757 NULL
89251 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
89252 +btrfs_init_new_buffer_55761 btrfs_init_new_buffer 4 55761 NULL
89253 +read_ldt_47570 read_ldt 2 47570 NULL
89254 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
89255 +pci_iomap_47575 pci_iomap 3 47575 NULL
89256 +acpi_ex_system_memory_space_handler_31192 acpi_ex_system_memory_space_handler 2 31192 NULL
89257 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
89258 +module_alloc_update_bounds_rw_63233 module_alloc_update_bounds_rw 1 63233 NULL
89259 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
89260 +drm_ht_create_18853 drm_ht_create 2 18853 NULL
89261 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
89262 +qlcnic_alloc_msix_entries_46160 qlcnic_alloc_msix_entries 2 46160 NULL
89263 +ieee80211_authentication_req_63973 ieee80211_authentication_req 3 63973 NULL
89264 +dn_alloc_skb_6631 dn_alloc_skb 2 6631 NULL
89265 +conf_read_55786 conf_read 3 55786 NULL
89266 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
89267 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
89268 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
89269 +virtscsi_alloc_tgt_6643 virtscsi_alloc_tgt 2 6643 NULL
89270 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
89271 +user_power_read_39414 user_power_read 3 39414 NULL
89272 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
89273 +uea_request_47613 uea_request 4 47613 NULL
89274 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
89275 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
89276 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
89277 +btrfs_find_create_tree_block_55812 btrfs_find_create_tree_block 3 55812 NULL
89278 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
89279 +lcd_write_14857 lcd_write 3 14857 NULL nohasharray
89280 +__krealloc_14857 __krealloc 2 14857 &lcd_write_14857
89281 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
89282 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
89283 +kmemdup_64015 kmemdup 2 64015 NULL
89284 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
89285 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
89286 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
89287 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
89288 +tcf_csum_skb_nextlayer_64025 tcf_csum_skb_nextlayer 3 64025 NULL
89289 +oz_events_read_47535 oz_events_read 3 47535 NULL
89290 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
89291 +resize_async_buffer_64031 resize_async_buffer 4 64031 NULL
89292 +sys_semop_39457 sys_semop 3 39457 NULL
89293 +vm_map_ram_23078 vm_map_ram 2 23078 NULL nohasharray
89294 +raw_sendmsg_23078 raw_sendmsg 4 23078 &vm_map_ram_23078
89295 +update_pmkid_2481 update_pmkid 4 2481 NULL
89296 +sriov_enable_migration_14889 sriov_enable_migration 2 14889 NULL
89297 +sep_lli_table_secure_dma_64042 sep_lli_table_secure_dma 2-3 64042 NULL
89298 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
89299 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
89300 +hysdn_rx_netpkt_16136 hysdn_rx_netpkt 3 16136 NULL
89301 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
89302 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
89303 +mpeg_read_6708 mpeg_read 3 6708 NULL
89304 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
89305 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
89306 +sky2_receive_13407 sky2_receive 2 13407 NULL
89307 +krealloc_14908 krealloc 2 14908 NULL
89308 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
89309 +bt_skb_send_alloc_6581 bt_skb_send_alloc 2 6581 NULL
89310 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
89311 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
89312 +video_proc_write_6724 video_proc_write 3 6724 NULL
89313 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
89314 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
89315 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
89316 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
89317 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
89318 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
89319 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
89320 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
89321 +command_file_write_31318 command_file_write 3 31318 NULL
89322 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
89323 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
89324 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
89325 +i915_cache_sharing_read_24775 i915_cache_sharing_read 3 24775 NULL
89326 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
89327 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
89328 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
89329 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
89330 +ca91cx42_master_set_23146 ca91cx42_master_set 4 23146 NULL
89331 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
89332 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
89333 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
89334 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
89335 +sfi_check_table_6772 sfi_check_table 1 6772 NULL
89336 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
89337 +int_proc_write_39542 int_proc_write 3 39542 NULL
89338 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
89339 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
89340 +read_file_ani_23161 read_file_ani 3 23161 NULL
89341 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
89342 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
89343 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
89344 +pp_write_39554 pp_write 3 39554 NULL
89345 +ioremap_23172 ioremap 1-2 23172 NULL
89346 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
89347 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
89348 +usblp_write_23178 usblp_write 3 23178 NULL
89349 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
89350 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
89351 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3 31374 NULL
89352 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
89353 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
89354 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
89355 +fix_unclean_leb_23188 fix_unclean_leb 3 23188 NULL
89356 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
89357 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
89358 +vmalloc_32_1135 vmalloc_32 1 1135 NULL
89359 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
89360 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
89361 +__team_options_register_63941 __team_options_register 3 63941 NULL
89362 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
89363 +ip_ufo_append_data_12775 ip_ufo_append_data 6-7-8 12775 NULL
89364 +rvmalloc_46873 rvmalloc 1 46873 NULL
89365 +vmap_15025 vmap 2 15025 NULL
89366 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
89367 +mcs7830_set_reg_31413 mcs7830_set_reg 3 31413 NULL
89368 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
89369 +tty_buffer_request_room_23228 tty_buffer_request_room 2 23228 NULL
89370 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
89371 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
89372 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
89373 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
89374 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
89375 +ttm_object_device_init_10321 ttm_object_device_init 2 10321 NULL
89376 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
89377 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
89378 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL
89379 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
89380 +ssb_bus_pcmciabus_register_56020 ssb_bus_pcmciabus_register 3 56020 NULL
89381 +fm_send_cmd_39639 fm_send_cmd 5 39639 NULL
89382 +ip6gre_err_19869 ip6gre_err 5 19869 NULL
89383 +nvme_alloc_iod_56027 nvme_alloc_iod 1 56027 NULL
89384 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
89385 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
89386 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5 15072 NULL
89387 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
89388 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
89389 +get_new_cssid_51665 get_new_cssid 2 51665 NULL
89390 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL
89391 +prism2_info_hostscanresults_39657 prism2_info_hostscanresults 3 39657 NULL
89392 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
89393 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
89394 +__videobuf_alloc_vb_5665 __videobuf_alloc_vb 1 5665 NULL
89395 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
89396 +redrat3_transmit_ir_64244 redrat3_transmit_ir 3 64244 NULL
89397 +__alloc_extent_buffer_15093 __alloc_extent_buffer 3 15093 NULL
89398 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
89399 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
89400 +alg_setkey_31485 alg_setkey 3 31485 NULL
89401 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
89402 +spi_show_regs_6911 spi_show_regs 3 6911 NULL nohasharray
89403 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 &spi_show_regs_6911
89404 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
89405 +vhci_read_47878 vhci_read 3 47878 NULL
89406 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
89407 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
89408 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
89409 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
89410 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
89411 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
89412 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
89413 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
89414 +osd_req_read_sg_47905 osd_req_read_sg 5 47905 NULL
89415 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
89416 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
89417 +timeout_read_47915 timeout_read 3 47915 NULL
89418 +hidraw_write_31536 hidraw_write 3 31536 NULL
89419 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
89420 +page_readlink_23346 page_readlink 3 23346 NULL
89421 +videobuf_dma_init_kernel_6963 videobuf_dma_init_kernel 3 6963 NULL
89422 +comedi_write_47926 comedi_write 3 47926 NULL
89423 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
89424 +dsp_write_46218 dsp_write 2 46218 NULL
89425 +kmem_zalloc_large_56128 kmem_zalloc_large 1 56128 NULL
89426 +usbvision_read_31555 usbvision_read 3 31555 NULL
89427 +pd_video_read_24510 pd_video_read 3 24510 NULL
89428 +crypto_authenc_esn_setkey_6985 crypto_authenc_esn_setkey 3 6985 NULL
89429 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
89430 +request_key_async_6990 request_key_async 4 6990 NULL
89431 +ts_write_64336 ts_write 3 64336 NULL
89432 +handle_response_55951 handle_response 5 55951 NULL
89433 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
89434 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
89435 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
89436 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
89437 +osst_write_31581 osst_write 3 31581 NULL
89438 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
89439 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
89440 +wm8350_block_write_19727 wm8350_block_write 3 19727 NULL
89441 +diva_xdi_write_63975 diva_xdi_write 4 63975 NULL
89442 +llc_alloc_frame_64366 llc_alloc_frame 4 64366 NULL
89443 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 NULL nohasharray
89444 +mempool_resize_47983 mempool_resize 2 47983 &iwl_dbgfs_ucode_tracing_read_47983
89445 +mangle_packet_18920 mangle_packet 7-9 18920 NULL
89446 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
89447 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
89448 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
89449 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
89450 +ilo_write_64378 ilo_write 3 64378 NULL
89451 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
89452 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
89453 +vzalloc_node_23424 vzalloc_node 1 23424 NULL
89454 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
89455 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
89456 +variax_alloc_sysex_buffer_15237 variax_alloc_sysex_buffer 3 15237 NULL
89457 +copy_from_user_17559 copy_from_user 3 17559 NULL
89458 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
89459 +sys_migrate_pages_39825 sys_migrate_pages 2 39825 NULL
89460 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
89461 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
89462 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
89463 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
89464 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
89465 +beiscsi_process_async_pdu_39834 beiscsi_process_async_pdu 7 39834 NULL
89466 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
89467 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
89468 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
89469 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
89470 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
89471 +cp210x_get_config_56229 cp210x_get_config 4 56229 NULL
89472 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
89473 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
89474 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
89475 +dn_nsp_send_disc_23469 dn_nsp_send_disc 2 23469 NULL
89476 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
89477 +ping_sendmsg_3782 ping_sendmsg 4 3782 NULL
89478 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
89479 +__lgread_31668 __lgread 4 31668 NULL
89480 +scrub_setup_recheck_block_56245 scrub_setup_recheck_block 4-3 56245 NULL
89481 +fd_copyin_56247 fd_copyin 3 56247 NULL
89482 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
89483 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
89484 +sys_connect_15291 sys_connect 3 15291 NULL nohasharray
89485 +xlate_dev_mem_ptr_15291 xlate_dev_mem_ptr 1 15291 &sys_connect_15291
89486 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
89487 +divasa_remap_pci_bar_23485 divasa_remap_pci_bar 3-4 23485 &linear_conf_23485
89488 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
89489 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
89490 +_usb_writeN_sync_31682 _usb_writeN_sync 4 31682 NULL
89491 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
89492 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
89493 +event_filter_read_23494 event_filter_read 3 23494 NULL
89494 +tpm_tis_init_15304 tpm_tis_init 2-3 15304 NULL
89495 +fcoe_ctlr_send_keep_alive_15308 fcoe_ctlr_send_keep_alive 3 15308 NULL
89496 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
89497 +sys_setsockopt_35320 sys_setsockopt 5 35320 NULL
89498 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
89499 +pkt_add_39897 pkt_add 3 39897 NULL
89500 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
89501 +send_mpa_reject_7135 send_mpa_reject 3 7135 NULL
89502 +sctp_make_op_error_7057 sctp_make_op_error 5-6 7057 NULL
89503 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
89504 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
89505 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
89506 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
89507 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
89508 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
89509 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
89510 +sctp_make_asconf_ack_31726 sctp_make_asconf_ack 3 31726 NULL
89511 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
89512 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
89513 +alloc_ring_15345 alloc_ring 2-4 15345 NULL
89514 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
89515 +remove_uuid_64505 remove_uuid 4 64505 NULL
89516 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3 31741 NULL
89517 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 NULL
89518 +create_table_16213 create_table 2 16213 NULL
89519 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
89520 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
89521 +dbg_leb_change_23555 dbg_leb_change 4 23555 NULL
89522 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
89523 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
89524 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
89525 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
89526 +set_discoverable_48141 set_discoverable 4 48141 NULL
89527 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
89528 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
89529 +tcp_match_skb_to_sack_23568 tcp_match_skb_to_sack 4 23568 NULL
89530 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
89531 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
89532 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3 39955 NULL
89533 +__tcp_push_pending_frames_48148 __tcp_push_pending_frames 2 48148 NULL
89534 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
89535 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
89536 +ipv6_recv_error_56347 ipv6_recv_error 3 56347 NULL
89537 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
89538 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
89539 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
89540 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
89541 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
89542 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
89543 +cfpkt_create_pfx_23594 cfpkt_create_pfx 1-2 23594 NULL
89544 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
89545 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4 56368 NULL
89546 +dev_read_56369 dev_read 3 56369 NULL
89547 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
89548 +alloc_dummy_extent_buffer_56374 alloc_dummy_extent_buffer 2 56374 NULL
89549 +diva_os_alloc_message_buffer_64568 diva_os_alloc_message_buffer 1 64568 NULL
89550 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
89551 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
89552 +init_ipath_48187 init_ipath 1 48187 NULL
89553 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
89554 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4 15423 NULL
89555 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
89556 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
89557 +sys32_ipc_7238 sys32_ipc 3 7238 NULL
89558 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
89559 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1-2 21687 NULL
89560 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
89561 +ddp_ppod_write_idata_25610 ddp_ppod_write_idata 5 25610 NULL
89562 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
89563 +nf_nat_icmpv6_reply_translation_40023 nf_nat_icmpv6_reply_translation 5 40023 NULL nohasharray
89564 +ivtvfb_write_40023 ivtvfb_write 3 40023 &nf_nat_icmpv6_reply_translation_40023
89565 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
89566 +tcp_write_xmit_64602 tcp_write_xmit 2 64602 NULL
89567 +use_pool_64607 use_pool 2 64607 NULL
89568 +__get_vm_area_caller_56416 __get_vm_area_caller 1 56416 NULL nohasharray
89569 +acpi_os_write_memory_56416 acpi_os_write_memory 1-3 56416 &__get_vm_area_caller_56416
89570 +store_msg_56417 store_msg 3 56417 NULL
89571 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
89572 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
89573 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
89574 +read_file_recv_48232 read_file_recv 3 48232 NULL
89575 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
89576 +set_tpl_pfs_27490 set_tpl_pfs 3 27490 NULL
89577 +fanotify_write_64623 fanotify_write 3 64623 NULL
89578 +batadv_add_packet_12136 batadv_add_packet 3 12136 NULL
89579 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
89580 +fl_create_56435 fl_create 5 56435 NULL
89581 +gnttab_map_56439 gnttab_map 2 56439 NULL
89582 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
89583 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
89584 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
89585 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2 56453 NULL
89586 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
89587 +set_connectable_56458 set_connectable 4 56458 NULL
89588 +a2mp_chan_alloc_skb_cb_27159 a2mp_chan_alloc_skb_cb 2 27159 NULL
89589 +nfc_hci_send_response_56462 nfc_hci_send_response 5 56462 NULL
89590 +add_port_54941 add_port 2 54941 NULL
89591 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
89592 +cx18_read_23699 cx18_read 3 23699 NULL
89593 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL
89594 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
89595 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
89596 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
89597 +ddb_output_write_31902 ddb_output_write 3 31902 NULL
89598 +send_set_info_48288 send_set_info 7 48288 NULL
89599 +sock_alloc_send_skb_23720 sock_alloc_send_skb 2 23720 NULL
89600 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
89601 +set_disc_pwup_pfs_48300 set_disc_pwup_pfs 3 48300 NULL
89602 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
89603 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
89604 +new_dir_31919 new_dir 3 31919 NULL
89605 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
89606 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
89607 +sec_bulk_write_64691 sec_bulk_write 3 64691 NULL
89608 +mgmt_control_7349 mgmt_control 3 7349 NULL
89609 +hash_setkey_48310 hash_setkey 3 48310 NULL
89610 +ql_process_mac_rx_page_15543 ql_process_mac_rx_page 4 15543 NULL
89611 +hfcpci_empty_fifo_2427 hfcpci_empty_fifo 4 2427 NULL
89612 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
89613 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
89614 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
89615 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
89616 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4 31942 NULL
89617 +ql_process_mac_rx_skb_6689 ql_process_mac_rx_skb 4 6689 NULL
89618 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
89619 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
89620 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
89621 +vb2_write_31948 vb2_write 3 31948 NULL
89622 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
89623 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
89624 +l1oip_socket_recv_56537 l1oip_socket_recv 6 56537 NULL
89625 +ip_options_get_56538 ip_options_get 4 56538 NULL
89626 +write_62671 write 3 62671 NULL
89627 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
89628 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
89629 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
89630 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
89631 +ceph_copy_page_vector_to_user_31270 ceph_copy_page_vector_to_user 3-4 31270 NULL
89632 +allocate_cnodes_5329 allocate_cnodes 1 5329 NULL
89633 +skb_add_data_48363 skb_add_data 3 48363 NULL
89634 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
89635 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
89636 +iscsi_complete_pdu_48372 iscsi_complete_pdu 4 48372 NULL
89637 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
89638 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
89639 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
89640 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
89641 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
89642 +set_dis_tap_pfs_15621 set_dis_tap_pfs 3 15621 NULL
89643 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
89644 +dsp_cmx_send_member_15625 dsp_cmx_send_member 2 15625 NULL
89645 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
89646 +system_enable_read_25815 system_enable_read 3 25815 NULL
89647 +allocate_probes_40204 allocate_probes 1 40204 NULL
89648 +sd_alloc_ctl_entry_29708 sd_alloc_ctl_entry 1 29708 NULL
89649 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
89650 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
89651 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
89652 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
89653 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
89654 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
89655 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
89656 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642
89657 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
89658 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
89659 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
89660 +fs_path_add_15648 fs_path_add 3 15648 NULL
89661 +event_filter_write_56609 event_filter_write 3 56609 NULL
89662 +xfs_buf_read_map_40226 xfs_buf_read_map 3 40226 NULL
89663 +ms_rw_multi_sector_7459 ms_rw_multi_sector 3-4 7459 NULL
89664 +xsd_read_15653 xsd_read 3 15653 NULL
89665 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
89666 +p54_init_common_23850 p54_init_common 1 23850 NULL
89667 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
89668 +vmw_cursor_update_dmabuf_32045 vmw_cursor_update_dmabuf 3-4 32045 NULL
89669 +sys_sched_setaffinity_32046 sys_sched_setaffinity 2 32046 NULL
89670 +garp_request_join_7471 garp_request_join 4 7471 NULL
89671 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
89672 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
89673 +unifi_read_14899 unifi_read 3 14899 NULL
89674 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
89675 +compat_sys_msgrcv_7482 compat_sys_msgrcv 2 7482 NULL
89676 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
89677 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
89678 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
89679 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
89680 +ipv6_recv_rxpmtu_7142 ipv6_recv_rxpmtu 3 7142 NULL
89681 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
89682 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
89683 +ieee80211_if_read_channel_type_23884 ieee80211_if_read_channel_type 3 23884 NULL
89684 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
89685 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
89686 +uf_sme_queue_message_15697 uf_sme_queue_message 3 15697 NULL
89687 +gdth_search_isa_58595 gdth_search_isa 1 58595 NULL
89688 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 NULL
89689 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
89690 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
89691 +iwch_reject_cr_23901 iwch_reject_cr 3 23901 NULL
89692 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
89693 +bio_alloc_32095 bio_alloc 2 32095 NULL
89694 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
89695 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
89696 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
89697 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL
89698 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
89699 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
89700 +ubi_io_write_data_40305 ubi_io_write_data 4-5 40305 NULL
89701 +send_control_msg_48498 send_control_msg 6 48498 NULL
89702 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
89703 +mlx4_en_create_tx_ring_48501 mlx4_en_create_tx_ring 4 48501 NULL
89704 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
89705 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
89706 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
89707 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3 56702 NULL
89708 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
89709 +batadv_tt_changes_fill_buff_40323 batadv_tt_changes_fill_buff 4 40323 NULL
89710 +__alloc_skb_23940 __alloc_skb 1 23940 NULL
89711 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
89712 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
89713 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
89714 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
89715 +alloc_tx_32143 alloc_tx 2 32143 NULL
89716 +wiimote_hid_send_48528 wiimote_hid_send 3 48528 NULL
89717 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
89718 +hsc_write_55875 hsc_write 3 55875 NULL
89719 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
89720 +do_test_15766 do_test 1 15766 NULL
89721 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
89722 +ip_recv_error_23109 ip_recv_error 3 23109 NULL
89723 +named_distribute_48544 named_distribute 4 48544 NULL
89724 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
89725 +venus_link_32165 venus_link 5 32165 NULL
89726 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
89727 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
89728 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
89729 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
89730 +set_std_nic_pfs_15792 set_std_nic_pfs 3 15792 NULL
89731 +ubifs_wbuf_write_nolock_64946 ubifs_wbuf_write_nolock 3 64946 NULL
89732 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
89733 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
89734 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
89735 +fwnet_incoming_packet_40380 fwnet_incoming_packet 3 40380 NULL
89736 +groups_alloc_7614 groups_alloc 1 7614 NULL
89737 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
89738 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
89739 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
89740 +ext_sd_execute_read_data_48589 ext_sd_execute_read_data 9 48589 NULL
89741 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
89742 +__carl9170_rx_56784 __carl9170_rx 3 56784 NULL
89743 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL
89744 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
89745 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
89746 +tcf_csum_ipv4_tcp_39713 tcf_csum_ipv4_tcp 4 39713 NULL
89747 +snapshot_write_28351 snapshot_write 3 28351 NULL
89748 +event_enable_read_7074 event_enable_read 3 7074 NULL
89749 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
89750 +do_syslog_56807 do_syslog 3 56807 NULL
89751 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
89752 +pskb_pull_65005 pskb_pull 2 65005 NULL
89753 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
89754 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
89755 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
89756 +unifi_write_65012 unifi_write 3 65012 NULL
89757 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL
89758 +nfs_readdata_alloc_65015 nfs_readdata_alloc 2 65015 NULL
89759 +ubi_io_write_15870 ubi_io_write 5-4 15870 NULL nohasharray
89760 +media_entity_init_15870 media_entity_init 2-4 15870 &ubi_io_write_15870
89761 +mtdchar_write_56831 mtdchar_write 3 56831 NULL nohasharray
89762 +ntfs_rl_realloc_56831 ntfs_rl_realloc 3 56831 &mtdchar_write_56831
89763 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
89764 +mid_get_vbt_data_r1_26170 mid_get_vbt_data_r1 2 26170 NULL
89765 +skb_copy_expand_7685 skb_copy_expand 2-3 7685 NULL nohasharray
89766 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 &skb_copy_expand_7685
89767 +if_write_51756 if_write 3 51756 NULL
89768 +insert_dent_65034 insert_dent 7 65034 NULL
89769 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
89770 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4 56847 NULL
89771 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
89772 +brcmf_sdcard_rwdata_65041 brcmf_sdcard_rwdata 5 65041 NULL
89773 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
89774 +lc_create_48662 lc_create 3 48662 NULL
89775 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
89776 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL nohasharray
89777 +sys_setgroups_48668 sys_setgroups 1 48668 &sm501_create_subdev_48668
89778 +ath9k_multi_regread_65056 ath9k_multi_regread 4 65056 NULL
89779 +brcmf_sdcard_send_buf_7713 brcmf_sdcard_send_buf 6 7713 NULL
89780 +l2cap_build_cmd_48676 l2cap_build_cmd 4 48676 NULL
89781 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
89782 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
89783 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
89784 +bnx2fc_process_l2_frame_compl_65072 bnx2fc_process_l2_frame_compl 3 65072 NULL
89785 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
89786 +persistent_ram_new_40501 persistent_ram_new 1-2 40501 NULL
89787 +ieee80211_send_auth_24121 ieee80211_send_auth 5 24121 NULL
89788 +altera_drscan_48698 altera_drscan 2 48698 NULL
89789 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
89790 +set_bypass_pwup_pfs_7742 set_bypass_pwup_pfs 3 7742 NULL
89791 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
89792 +power_read_15939 power_read 3 15939 NULL
89793 +recv_msg_48709 recv_msg 4 48709 NULL
89794 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL
89795 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
89796 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
89797 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
89798 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
89799 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
89800 +process_vm_rw_pages_15954 process_vm_rw_pages 6-5 15954 NULL
89801 +revalidate_19043 revalidate 2 19043 NULL
89802 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
89803 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 NULL
89804 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
89805 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
89806 +check_header_56930 check_header 2 56930 NULL
89807 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
89808 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
89809 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
89810 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
89811 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
89812 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
89813 +frame_alloc_15981 frame_alloc 4 15981 NULL
89814 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
89815 +nf_nat_seq_adjust_44989 nf_nat_seq_adjust 4 44989 NULL
89816 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL
89817 +adu_read_24177 adu_read 3 24177 NULL
89818 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
89819 +send_mpa_reply_32372 send_mpa_reply 3 32372 NULL
89820 +alloc_vm_area_15989 alloc_vm_area 1 15989 NULL
89821 +variax_set_raw2_32374 variax_set_raw2 4 32374 NULL
89822 +vfd_write_14717 vfd_write 3 14717 NULL
89823 +carl9170_rx_copy_data_21656 carl9170_rx_copy_data 2 21656 NULL
89824 +usbtmc_read_32377 usbtmc_read 3 32377 NULL
89825 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
89826 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
89827 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
89828 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
89829 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
89830 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
89831 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
89832 +__cxio_init_resource_fifo_23447 __cxio_init_resource_fifo 3 23447 NULL
89833 +skge_rx_get_40598 skge_rx_get 3 40598 NULL
89834 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
89835 +register_device_60015 register_device 2-3 60015 NULL
89836 +got_frame_16028 got_frame 2 16028 NULL
89837 +ssb_bus_register_65183 ssb_bus_register 3 65183 NULL
89838 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 1-2-3 24224 NULL
89839 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
89840 +scsi_register_49094 scsi_register 2 49094 NULL
89841 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
89842 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
89843 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
89844 +batadv_check_unicast_packet_10866 batadv_check_unicast_packet 2 10866 NULL
89845 +tcp_push_one_48816 tcp_push_one 2 48816 NULL
89846 +nfulnl_alloc_skb_65207 nfulnl_alloc_skb 2 65207 NULL
89847 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
89848 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
89849 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
89850 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
89851 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
89852 +svc_pool_map_alloc_arrays_47181 svc_pool_map_alloc_arrays 2 47181 NULL
89853 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
89854 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
89855 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
89856 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
89857 +compat_sys_preadv64_24283 compat_sys_preadv64 3 24283 NULL
89858 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
89859 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL
89860 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
89861 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
89862 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
89863 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
89864 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
89865 +mid_get_vbt_data_r0_10876 mid_get_vbt_data_r0 2 10876 NULL
89866 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
89867 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
89868 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 NULL nohasharray
89869 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 &dma_tx_requested_read_16110
89870 +sys_setgroups16_48882 sys_setgroups16 1 48882 NULL
89871 +kmem_zalloc_greedy_65268 kmem_zalloc_greedy 3-2 65268 NULL
89872 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
89873 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
89874 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
89875 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
89876 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
89877 +mac_drv_rx_init_48898 mac_drv_rx_init 2 48898 NULL
89878 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
89879 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
89880 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
89881 +fsm_init_16134 fsm_init 2 16134 NULL
89882 +ext_sd_execute_write_data_8175 ext_sd_execute_write_data 9 8175 NULL
89883 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
89884 +disconnect_32521 disconnect 4 32521 NULL
89885 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
89886 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
89887 +ath6kl_wmi_add_wow_pattern_cmd_12842 ath6kl_wmi_add_wow_pattern_cmd 4 12842 NULL
89888 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
89889 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
89890 +ilo_read_32531 ilo_read 3 32531 NULL
89891 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
89892 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
89893 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
89894 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
89895 +gdth_isa_probe_one_48925 gdth_isa_probe_one 1 48925 NULL
89896 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
89897 +nfc_hci_execute_cmd_async_65314 nfc_hci_execute_cmd_async 5 65314 NULL
89898 +msnd_fifo_alloc_23179 msnd_fifo_alloc 2 23179 NULL
89899 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
89900 +nfcwilink_skb_alloc_16167 nfcwilink_skb_alloc 1 16167 NULL
89901 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
89902 +remap_pci_mem_15966 remap_pci_mem 1-2 15966 NULL
89903 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
89904 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
89905 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
89906 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
89907 +card_send_command_40757 card_send_command 3 40757 NULL
89908 +sys_mbind_7990 sys_mbind 5 7990 NULL
89909 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
89910 +pg_write_40766 pg_write 3 40766 NULL
89911 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
89912 +uea_idma_write_64139 uea_idma_write 3 64139 NULL
89913 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
89914 +carl9170_rx_stream_1334 carl9170_rx_stream 3 1334 NULL
89915 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
89916 +ath_descdma_setup_12257 ath_descdma_setup 5 12257 NULL
89917 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
89918 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
89919 +batadv_orig_hash_del_if_48972 batadv_orig_hash_del_if 2 48972 NULL
89920 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
89921 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 NULL nohasharray
89922 +getxattr_24398 getxattr 4 24398 &pvr2_v4l2_ioctl_24398
89923 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
89924 +vcs_read_8017 vcs_read 3 8017 NULL
89925 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
89926 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
89927 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
89928 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
89929 +_alloc_set_attr_list_48991 _alloc_set_attr_list 4 48991 NULL
89930 +sys_set_mempolicy_32608 sys_set_mempolicy 3 32608 NULL
89931 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
89932 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
89933 +copy_and_check_19089 copy_and_check 3 19089 NULL
89934 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
89935 +netdev_alloc_skb_ip_align_40811 netdev_alloc_skb_ip_align 2 40811 NULL
89936 +i915_wedged_read_35474 i915_wedged_read 3 35474 NULL
89937 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
89938 +iser_rcv_completion_8048 iser_rcv_completion 2 8048 NULL
89939 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
89940 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
89941 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
89942 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
89943 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
89944 +smk_user_access_24440 smk_user_access 3 24440 NULL
89945 +xd_rw_49020 xd_rw 3-4 49020 NULL
89946 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
89947 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
89948 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
89949 +kvmalloc_32646 kvmalloc 1 32646 NULL
89950 +alloc_targets_8074 alloc_targets 2 8074 NULL nohasharray
89951 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 &alloc_targets_8074
89952 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
89953 +drm_calloc_large_65421 drm_calloc_large 1-2 65421 NULL
89954 +set_disc_pfs_16270 set_disc_pfs 3 16270 NULL
89955 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
89956 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
89957 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL
89958 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
89959 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
89960 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
89961 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
89962 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
89963 +pn533_init_target_frame_65438 pn533_init_target_frame 3 65438 NULL
89964 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
89965 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
89966 +i915_wedged_write_47771 i915_wedged_write 3 47771 NULL
89967 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
89968 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
89969 +l2cap_bredr_sig_cmd_49065 l2cap_bredr_sig_cmd 3 49065 NULL
89970 +tipc_buf_acquire_60437 tipc_buf_acquire 1 60437 NULL
89971 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
89972 +venus_lookup_8121 venus_lookup 4 8121 NULL
89973 +compat_writev_60063 compat_writev 3 60063 NULL
89974 +io_mapping_create_wc_1354 io_mapping_create_wc 1-2 1354 NULL
89975 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
89976 +read_file_queue_40895 read_file_queue 3 40895 NULL
89977 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
89978 +waiters_read_40902 waiters_read 3 40902 NULL
89979 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
89980 +vmalloc_node_58700 vmalloc_node 1 58700 NULL
89981 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
89982 +ath_rx_edma_init_65483 ath_rx_edma_init 2 65483 NULL
89983 +vmw_cursor_update_image_16332 vmw_cursor_update_image 3-4 16332 NULL
89984 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
89985 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
89986 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
89987 +named_prepare_buf_24532 named_prepare_buf 2 24532 NULL
89988 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
89989 +alloc_dr_65495 alloc_dr 2 65495 NULL
89990 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
89991 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
89992 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
89993 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
89994 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
89995 +rbd_add_16366 rbd_add 3 16366 NULL
89996 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
89997 +pt_read_49136 pt_read 3 49136 NULL
89998 +tsi148_alloc_resource_24563 tsi148_alloc_resource 2 24563 NULL
89999 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
90000 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
90001 +check_mirror_57342 check_mirror 1-2 57342 NULL nohasharray
90002 +usblp_read_57342 usblp_read 3 57342 &check_mirror_57342
90003 +atyfb_setup_generic_49151 atyfb_setup_generic 3 49151 NULL
90004 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
90005 new file mode 100644
90006 index 0000000..792ee60
90007 --- /dev/null
90008 +++ b/tools/gcc/size_overflow_plugin.c
90009 @@ -0,0 +1,1930 @@
90010 +/*
90011 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
90012 + * Licensed under the GPL v2, or (at your option) v3
90013 + *
90014 + * Homepage:
90015 + * http://www.grsecurity.net/~ephox/overflow_plugin/
90016 + *
90017 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
90018 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
90019 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
90020 + *
90021 + * Usage:
90022 + * $ 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
90023 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
90024 + */
90025 +
90026 +#include "gcc-plugin.h"
90027 +#include "config.h"
90028 +#include "system.h"
90029 +#include "coretypes.h"
90030 +#include "tree.h"
90031 +#include "tree-pass.h"
90032 +#include "intl.h"
90033 +#include "plugin-version.h"
90034 +#include "tm.h"
90035 +#include "toplev.h"
90036 +#include "function.h"
90037 +#include "tree-flow.h"
90038 +#include "plugin.h"
90039 +#include "gimple.h"
90040 +#include "c-common.h"
90041 +#include "diagnostic.h"
90042 +#include "cfgloop.h"
90043 +
90044 +#if BUILDING_GCC_VERSION >= 4007
90045 +#include "c-tree.h"
90046 +#else
90047 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
90048 +#endif
90049 +
90050 +struct size_overflow_hash {
90051 + const struct size_overflow_hash * const next;
90052 + const char * const name;
90053 + const unsigned int param;
90054 +};
90055 +
90056 +#include "size_overflow_hash.h"
90057 +
90058 +enum marked {
90059 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
90060 +};
90061 +
90062 +static unsigned int call_count = 0;
90063 +
90064 +#define __unused __attribute__((__unused__))
90065 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
90066 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
90067 +#define BEFORE_STMT true
90068 +#define AFTER_STMT false
90069 +#define CREATE_NEW_VAR NULL_TREE
90070 +#define CODES_LIMIT 32
90071 +#define MAX_PARAM 32
90072 +#define MY_STMT GF_PLF_1
90073 +#define NO_CAST_CHECK GF_PLF_2
90074 +
90075 +#if BUILDING_GCC_VERSION == 4005
90076 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
90077 +#endif
90078 +
90079 +int plugin_is_GPL_compatible;
90080 +void debug_gimple_stmt(gimple gs);
90081 +
90082 +static tree expand(struct pointer_set_t *visited, tree lhs);
90083 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
90084 +static tree report_size_overflow_decl;
90085 +static const_tree const_char_ptr_type_node;
90086 +static unsigned int handle_function(void);
90087 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
90088 +static tree get_size_overflow_type(gimple stmt, const_tree node);
90089 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
90090 +
90091 +static struct plugin_info size_overflow_plugin_info = {
90092 + .version = "20130109beta",
90093 + .help = "no-size-overflow\tturn off size overflow checking\n",
90094 +};
90095 +
90096 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
90097 +{
90098 + unsigned int arg_count;
90099 + enum tree_code code = TREE_CODE(*node);
90100 +
90101 + switch (code) {
90102 + case FUNCTION_DECL:
90103 + arg_count = type_num_arguments(TREE_TYPE(*node));
90104 + break;
90105 + case FUNCTION_TYPE:
90106 + case METHOD_TYPE:
90107 + arg_count = type_num_arguments(*node);
90108 + break;
90109 + default:
90110 + *no_add_attrs = true;
90111 + error("%s: %qE attribute only applies to functions", __func__, name);
90112 + return NULL_TREE;
90113 + }
90114 +
90115 + for (; args; args = TREE_CHAIN(args)) {
90116 + tree position = TREE_VALUE(args);
90117 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
90118 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
90119 + *no_add_attrs = true;
90120 + }
90121 + }
90122 + return NULL_TREE;
90123 +}
90124 +
90125 +static const char* get_asm_name(tree node)
90126 +{
90127 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
90128 +}
90129 +
90130 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
90131 +{
90132 + unsigned int arg_count, arg_num;
90133 + enum tree_code code = TREE_CODE(*node);
90134 +
90135 + switch (code) {
90136 + case FUNCTION_DECL:
90137 + arg_count = type_num_arguments(TREE_TYPE(*node));
90138 + break;
90139 + case FUNCTION_TYPE:
90140 + case METHOD_TYPE:
90141 + arg_count = type_num_arguments(*node);
90142 + break;
90143 + case FIELD_DECL:
90144 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
90145 + if (arg_num != 0) {
90146 + *no_add_attrs = true;
90147 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
90148 + }
90149 + return NULL_TREE;
90150 + default:
90151 + *no_add_attrs = true;
90152 + error("%qE attribute only applies to functions", name);
90153 + return NULL_TREE;
90154 + }
90155 +
90156 + for (; args; args = TREE_CHAIN(args)) {
90157 + tree position = TREE_VALUE(args);
90158 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
90159 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
90160 + *no_add_attrs = true;
90161 + }
90162 + }
90163 + return NULL_TREE;
90164 +}
90165 +
90166 +static struct attribute_spec size_overflow_attr = {
90167 + .name = "size_overflow",
90168 + .min_length = 1,
90169 + .max_length = -1,
90170 + .decl_required = true,
90171 + .type_required = false,
90172 + .function_type_required = false,
90173 + .handler = handle_size_overflow_attribute,
90174 +#if BUILDING_GCC_VERSION >= 4007
90175 + .affects_type_identity = false
90176 +#endif
90177 +};
90178 +
90179 +static struct attribute_spec intentional_overflow_attr = {
90180 + .name = "intentional_overflow",
90181 + .min_length = 1,
90182 + .max_length = -1,
90183 + .decl_required = true,
90184 + .type_required = false,
90185 + .function_type_required = false,
90186 + .handler = handle_intentional_overflow_attribute,
90187 +#if BUILDING_GCC_VERSION >= 4007
90188 + .affects_type_identity = false
90189 +#endif
90190 +};
90191 +
90192 +static void register_attributes(void __unused *event_data, void __unused *data)
90193 +{
90194 + register_attribute(&size_overflow_attr);
90195 + register_attribute(&intentional_overflow_attr);
90196 +}
90197 +
90198 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
90199 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
90200 +{
90201 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
90202 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
90203 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
90204 +
90205 + unsigned int m = 0x57559429;
90206 + unsigned int n = 0x5052acdb;
90207 + const unsigned int *key4 = (const unsigned int *)key;
90208 + unsigned int h = len;
90209 + unsigned int k = len + seed + n;
90210 + unsigned long long p;
90211 +
90212 + while (len >= 8) {
90213 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
90214 + len -= 8;
90215 + }
90216 + if (len >= 4) {
90217 + cwmixb(key4[0]) key4 += 1;
90218 + len -= 4;
90219 + }
90220 + if (len)
90221 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
90222 + cwmixb(h ^ (k + n));
90223 + return k ^ h;
90224 +
90225 +#undef cwfold
90226 +#undef cwmixa
90227 +#undef cwmixb
90228 +}
90229 +
90230 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
90231 +{
90232 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
90233 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
90234 + return fn ^ codes;
90235 +}
90236 +
90237 +static inline tree get_original_function_decl(tree fndecl)
90238 +{
90239 + if (DECL_ABSTRACT_ORIGIN(fndecl))
90240 + return DECL_ABSTRACT_ORIGIN(fndecl);
90241 + return fndecl;
90242 +}
90243 +
90244 +static inline gimple get_def_stmt(const_tree node)
90245 +{
90246 + gcc_assert(node != NULL_TREE);
90247 + gcc_assert(TREE_CODE(node) == SSA_NAME);
90248 + return SSA_NAME_DEF_STMT(node);
90249 +}
90250 +
90251 +static unsigned char get_tree_code(const_tree type)
90252 +{
90253 + switch (TREE_CODE(type)) {
90254 + case ARRAY_TYPE:
90255 + return 0;
90256 + case BOOLEAN_TYPE:
90257 + return 1;
90258 + case ENUMERAL_TYPE:
90259 + return 2;
90260 + case FUNCTION_TYPE:
90261 + return 3;
90262 + case INTEGER_TYPE:
90263 + return 4;
90264 + case POINTER_TYPE:
90265 + return 5;
90266 + case RECORD_TYPE:
90267 + return 6;
90268 + case UNION_TYPE:
90269 + return 7;
90270 + case VOID_TYPE:
90271 + return 8;
90272 + case REAL_TYPE:
90273 + return 9;
90274 + case VECTOR_TYPE:
90275 + return 10;
90276 + case REFERENCE_TYPE:
90277 + return 11;
90278 + case OFFSET_TYPE:
90279 + return 12;
90280 + case COMPLEX_TYPE:
90281 + return 13;
90282 + default:
90283 + debug_tree((tree)type);
90284 + gcc_unreachable();
90285 + }
90286 +}
90287 +
90288 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
90289 +{
90290 + gcc_assert(type != NULL_TREE);
90291 +
90292 + while (type && len < CODES_LIMIT) {
90293 + tree_codes[len] = get_tree_code(type);
90294 + len++;
90295 + type = TREE_TYPE(type);
90296 + }
90297 + return len;
90298 +}
90299 +
90300 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
90301 +{
90302 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
90303 + enum tree_code code = TREE_CODE(type);
90304 + size_t len = 0;
90305 +
90306 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
90307 +
90308 + arg = TYPE_ARG_TYPES(type);
90309 + // skip builtins __builtin_constant_p
90310 + if (!arg && DECL_BUILT_IN(fndecl))
90311 + return 0;
90312 +
90313 + if (TREE_CODE_CLASS(code) == tcc_type)
90314 + result = type;
90315 + else
90316 + result = DECL_RESULT(fndecl);
90317 +
90318 + gcc_assert(result != NULL_TREE);
90319 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
90320 +
90321 + if (arg == NULL_TREE) {
90322 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
90323 + arg_field = DECL_ARGUMENT_FLD(fndecl);
90324 + if (arg_field == NULL_TREE)
90325 + return 0;
90326 + arg = TREE_TYPE(arg_field);
90327 + len = add_type_codes(arg, tree_codes, len);
90328 + gcc_assert(len != 0);
90329 + return len;
90330 + }
90331 +
90332 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
90333 + while (arg && len < CODES_LIMIT) {
90334 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
90335 + arg = TREE_CHAIN(arg);
90336 + }
90337 +
90338 + gcc_assert(len != 0);
90339 + return len;
90340 +}
90341 +
90342 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
90343 +{
90344 + unsigned int hash;
90345 + const struct size_overflow_hash *entry;
90346 + unsigned char tree_codes[CODES_LIMIT];
90347 + size_t len;
90348 + const char *func_name = get_asm_name(fndecl);
90349 +
90350 + len = get_function_decl(fndecl, tree_codes);
90351 + if (len == 0)
90352 + return NULL;
90353 +
90354 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
90355 +
90356 + entry = size_overflow_hash[hash];
90357 + while (entry) {
90358 + if (!strcmp(entry->name, func_name))
90359 + return entry;
90360 + entry = entry->next;
90361 + }
90362 +
90363 + return NULL;
90364 +}
90365 +
90366 +static void check_arg_type(const_tree arg)
90367 +{
90368 + const_tree type = TREE_TYPE(arg);
90369 + enum tree_code code = TREE_CODE(type);
90370 +
90371 + if (code == BOOLEAN_TYPE)
90372 + return;
90373 +
90374 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
90375 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
90376 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
90377 +}
90378 +
90379 +static unsigned int find_arg_number(const_tree arg, tree func)
90380 +{
90381 + tree var;
90382 + unsigned int argnum = 1;
90383 +
90384 + if (TREE_CODE(arg) == SSA_NAME)
90385 + arg = SSA_NAME_VAR(arg);
90386 +
90387 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
90388 + if (strcmp(NAME(arg), NAME(var))) {
90389 + argnum++;
90390 + continue;
90391 + }
90392 + check_arg_type(var);
90393 + return argnum;
90394 + }
90395 + gcc_unreachable();
90396 +}
90397 +
90398 +static tree create_new_var(tree type)
90399 +{
90400 + tree new_var = create_tmp_var(type, "cicus");
90401 +
90402 + add_referenced_var(new_var);
90403 + mark_sym_for_renaming(new_var);
90404 + return new_var;
90405 +}
90406 +
90407 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
90408 +{
90409 + gimple assign;
90410 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
90411 + tree type = TREE_TYPE(rhs1);
90412 + tree lhs = create_new_var(type);
90413 +
90414 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
90415 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
90416 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
90417 +
90418 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
90419 + update_stmt(assign);
90420 + gimple_set_plf(assign, MY_STMT, true);
90421 + return assign;
90422 +}
90423 +
90424 +static bool is_bool(const_tree node)
90425 +{
90426 + const_tree type;
90427 +
90428 + if (node == NULL_TREE)
90429 + return false;
90430 +
90431 + type = TREE_TYPE(node);
90432 + if (!INTEGRAL_TYPE_P(type))
90433 + return false;
90434 + if (TREE_CODE(type) == BOOLEAN_TYPE)
90435 + return true;
90436 + if (TYPE_PRECISION(type) == 1)
90437 + return true;
90438 + return false;
90439 +}
90440 +
90441 +static tree cast_a_tree(tree type, tree var)
90442 +{
90443 + gcc_assert(type != NULL_TREE);
90444 + gcc_assert(var != NULL_TREE);
90445 + gcc_assert(fold_convertible_p(type, var));
90446 +
90447 + return fold_convert(type, var);
90448 +}
90449 +
90450 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
90451 +{
90452 + gimple assign;
90453 +
90454 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
90455 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
90456 + gcc_unreachable();
90457 +
90458 + if (lhs == CREATE_NEW_VAR)
90459 + lhs = create_new_var(dst_type);
90460 +
90461 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
90462 +
90463 + if (!gsi_end_p(*gsi)) {
90464 + location_t loc = gimple_location(gsi_stmt(*gsi));
90465 + gimple_set_location(assign, loc);
90466 + }
90467 +
90468 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
90469 +
90470 + if (before)
90471 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
90472 + else
90473 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
90474 + update_stmt(assign);
90475 + gimple_set_plf(assign, MY_STMT, true);
90476 +
90477 + return assign;
90478 +}
90479 +
90480 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
90481 +{
90482 + gimple assign;
90483 + gimple_stmt_iterator gsi;
90484 +
90485 + if (rhs == NULL_TREE)
90486 + return NULL_TREE;
90487 +
90488 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
90489 + return rhs;
90490 +
90491 + gsi = gsi_for_stmt(stmt);
90492 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
90493 + gimple_set_plf(assign, MY_STMT, true);
90494 + return gimple_get_lhs(assign);
90495 +}
90496 +
90497 +static tree cast_to_TI_type(gimple stmt, tree node)
90498 +{
90499 + gimple_stmt_iterator gsi;
90500 + gimple cast_stmt;
90501 + tree type = TREE_TYPE(node);
90502 +
90503 + if (types_compatible_p(type, intTI_type_node))
90504 + return node;
90505 +
90506 + gsi = gsi_for_stmt(stmt);
90507 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
90508 + gimple_set_plf(cast_stmt, MY_STMT, true);
90509 + return gimple_get_lhs(cast_stmt);
90510 +}
90511 +
90512 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
90513 +{
90514 + tree lhs;
90515 + gimple_stmt_iterator gsi;
90516 +
90517 + if (rhs1 == NULL_TREE) {
90518 + debug_gimple_stmt(oldstmt);
90519 + error("%s: rhs1 is NULL_TREE", __func__);
90520 + gcc_unreachable();
90521 + }
90522 +
90523 + switch (gimple_code(oldstmt)) {
90524 + case GIMPLE_ASM:
90525 + lhs = rhs1;
90526 + break;
90527 + case GIMPLE_CALL:
90528 + lhs = gimple_call_lhs(oldstmt);
90529 + break;
90530 + case GIMPLE_ASSIGN:
90531 + lhs = gimple_get_lhs(oldstmt);
90532 + break;
90533 + default:
90534 + debug_gimple_stmt(oldstmt);
90535 + gcc_unreachable();
90536 + }
90537 +
90538 + gsi = gsi_for_stmt(oldstmt);
90539 + pointer_set_insert(visited, oldstmt);
90540 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
90541 + basic_block next_bb, cur_bb;
90542 + const_edge e;
90543 +
90544 + gcc_assert(before == false);
90545 + gcc_assert(stmt_can_throw_internal(oldstmt));
90546 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
90547 + gcc_assert(!gsi_end_p(gsi));
90548 +
90549 + cur_bb = gimple_bb(oldstmt);
90550 + next_bb = cur_bb->next_bb;
90551 + e = find_edge(cur_bb, next_bb);
90552 + gcc_assert(e != NULL);
90553 + gcc_assert(e->flags & EDGE_FALLTHRU);
90554 +
90555 + gsi = gsi_after_labels(next_bb);
90556 + gcc_assert(!gsi_end_p(gsi));
90557 +
90558 + before = true;
90559 + oldstmt = gsi_stmt(gsi);
90560 + }
90561 +
90562 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
90563 +}
90564 +
90565 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
90566 +{
90567 + gimple stmt;
90568 + gimple_stmt_iterator gsi;
90569 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
90570 +
90571 + if (gimple_plf(oldstmt, MY_STMT))
90572 + return lhs;
90573 +
90574 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
90575 + rhs1 = gimple_assign_rhs1(oldstmt);
90576 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
90577 + }
90578 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
90579 + rhs2 = gimple_assign_rhs2(oldstmt);
90580 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
90581 + }
90582 +
90583 + stmt = gimple_copy(oldstmt);
90584 + gimple_set_location(stmt, gimple_location(oldstmt));
90585 + gimple_set_plf(stmt, MY_STMT, true);
90586 +
90587 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
90588 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
90589 +
90590 + size_overflow_type = get_size_overflow_type(oldstmt, node);
90591 +
90592 + if (is_bool(lhs))
90593 + new_var = SSA_NAME_VAR(lhs);
90594 + else
90595 + new_var = create_new_var(size_overflow_type);
90596 + new_var = make_ssa_name(new_var, stmt);
90597 + gimple_set_lhs(stmt, new_var);
90598 +
90599 + if (rhs1 != NULL_TREE)
90600 + gimple_assign_set_rhs1(stmt, rhs1);
90601 +
90602 + if (rhs2 != NULL_TREE)
90603 + gimple_assign_set_rhs2(stmt, rhs2);
90604 +#if BUILDING_GCC_VERSION >= 4007
90605 + if (rhs3 != NULL_TREE)
90606 + gimple_assign_set_rhs3(stmt, rhs3);
90607 +#endif
90608 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
90609 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
90610 +
90611 + gsi = gsi_for_stmt(oldstmt);
90612 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
90613 + update_stmt(stmt);
90614 + pointer_set_insert(visited, oldstmt);
90615 + return gimple_get_lhs(stmt);
90616 +}
90617 +
90618 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
90619 +{
90620 + basic_block bb;
90621 + gimple phi;
90622 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
90623 +
90624 + bb = gsi_bb(gsi);
90625 +
90626 + phi = create_phi_node(result, bb);
90627 + gsi = gsi_last(phi_nodes(bb));
90628 + gsi_remove(&gsi, false);
90629 +
90630 + gsi = gsi_for_stmt(oldstmt);
90631 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
90632 + gimple_set_bb(phi, bb);
90633 + gimple_set_plf(phi, MY_STMT, true);
90634 + return phi;
90635 +}
90636 +
90637 +static basic_block create_a_first_bb(void)
90638 +{
90639 + basic_block first_bb;
90640 +
90641 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
90642 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
90643 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
90644 + return first_bb;
90645 +}
90646 +
90647 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
90648 +{
90649 + basic_block bb;
90650 + const_gimple newstmt;
90651 + gimple_stmt_iterator gsi;
90652 + bool before = BEFORE_STMT;
90653 +
90654 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
90655 + gsi = gsi_for_stmt(get_def_stmt(arg));
90656 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
90657 + return gimple_get_lhs(newstmt);
90658 + }
90659 +
90660 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
90661 + gsi = gsi_after_labels(bb);
90662 + if (bb->index == 0) {
90663 + bb = create_a_first_bb();
90664 + gsi = gsi_start_bb(bb);
90665 + }
90666 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
90667 + return gimple_get_lhs(newstmt);
90668 +}
90669 +
90670 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
90671 +{
90672 + gimple newstmt;
90673 + gimple_stmt_iterator gsi;
90674 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
90675 + gimple def_newstmt = get_def_stmt(new_rhs);
90676 +
90677 + gsi_insert = gsi_insert_after;
90678 + gsi = gsi_for_stmt(def_newstmt);
90679 +
90680 + switch (gimple_code(get_def_stmt(arg))) {
90681 + case GIMPLE_PHI:
90682 + newstmt = gimple_build_assign(new_var, new_rhs);
90683 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
90684 + gsi_insert = gsi_insert_before;
90685 + break;
90686 + case GIMPLE_ASM:
90687 + case GIMPLE_CALL:
90688 + newstmt = gimple_build_assign(new_var, new_rhs);
90689 + break;
90690 + case GIMPLE_ASSIGN:
90691 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
90692 + break;
90693 + default:
90694 + /* unknown gimple_code (handle_build_new_phi_arg) */
90695 + gcc_unreachable();
90696 + }
90697 +
90698 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
90699 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
90700 + gimple_set_plf(newstmt, MY_STMT, true);
90701 + update_stmt(newstmt);
90702 + return newstmt;
90703 +}
90704 +
90705 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
90706 +{
90707 + const_gimple newstmt;
90708 + gimple def_stmt;
90709 + tree new_rhs;
90710 +
90711 + new_rhs = expand(visited, arg);
90712 + if (new_rhs == NULL_TREE)
90713 + return NULL_TREE;
90714 +
90715 + def_stmt = get_def_stmt(new_rhs);
90716 + if (gimple_code(def_stmt) == GIMPLE_NOP)
90717 + return NULL_TREE;
90718 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
90719 +
90720 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
90721 + return gimple_get_lhs(newstmt);
90722 +}
90723 +
90724 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
90725 +{
90726 + gimple phi, oldstmt = get_def_stmt(orig_result);
90727 + tree new_result, size_overflow_type;
90728 + unsigned int i;
90729 + unsigned int n = gimple_phi_num_args(oldstmt);
90730 +
90731 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
90732 +
90733 + new_result = create_new_var(size_overflow_type);
90734 +
90735 + pointer_set_insert(visited, oldstmt);
90736 + phi = overflow_create_phi_node(oldstmt, new_result);
90737 + for (i = 0; i < n; i++) {
90738 + tree arg, lhs;
90739 +
90740 + arg = gimple_phi_arg_def(oldstmt, i);
90741 + if (is_gimple_constant(arg))
90742 + arg = cast_a_tree(size_overflow_type, arg);
90743 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
90744 + if (lhs == NULL_TREE)
90745 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
90746 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
90747 + }
90748 +
90749 + update_stmt(phi);
90750 + return gimple_phi_result(phi);
90751 +}
90752 +
90753 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
90754 +{
90755 + const_gimple assign;
90756 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
90757 + tree origtype = TREE_TYPE(orig_rhs);
90758 +
90759 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
90760 +
90761 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
90762 + return gimple_get_lhs(assign);
90763 +}
90764 +
90765 +static void change_rhs1(gimple stmt, tree new_rhs1)
90766 +{
90767 + tree assign_rhs;
90768 + const_tree rhs = gimple_assign_rhs1(stmt);
90769 +
90770 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
90771 + gimple_assign_set_rhs1(stmt, assign_rhs);
90772 + update_stmt(stmt);
90773 +}
90774 +
90775 +static bool check_mode_type(const_gimple stmt)
90776 +{
90777 + const_tree lhs = gimple_get_lhs(stmt);
90778 + const_tree lhs_type = TREE_TYPE(lhs);
90779 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
90780 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
90781 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
90782 +
90783 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
90784 + return false;
90785 +
90786 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
90787 + return false;
90788 +
90789 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast
90790 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
90791 + return false;
90792 +
90793 + return true;
90794 +}
90795 +
90796 +static bool check_undefined_integer_operation(const_gimple stmt)
90797 +{
90798 + const_gimple def_stmt;
90799 + const_tree lhs = gimple_get_lhs(stmt);
90800 + const_tree rhs1 = gimple_assign_rhs1(stmt);
90801 + const_tree rhs1_type = TREE_TYPE(rhs1);
90802 + const_tree lhs_type = TREE_TYPE(lhs);
90803 +
90804 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
90805 + return false;
90806 +
90807 + def_stmt = get_def_stmt(rhs1);
90808 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
90809 + return false;
90810 +
90811 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
90812 + return false;
90813 + return true;
90814 +}
90815 +
90816 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
90817 +{
90818 + const_tree rhs1, lhs, rhs1_type, lhs_type;
90819 + enum machine_mode lhs_mode, rhs_mode;
90820 + gimple def_stmt = get_def_stmt(no_const_rhs);
90821 +
90822 + if (!gimple_assign_cast_p(def_stmt))
90823 + return false;
90824 +
90825 + rhs1 = gimple_assign_rhs1(def_stmt);
90826 + lhs = gimple_get_lhs(def_stmt);
90827 + rhs1_type = TREE_TYPE(rhs1);
90828 + lhs_type = TREE_TYPE(lhs);
90829 + rhs_mode = TYPE_MODE(rhs1_type);
90830 + lhs_mode = TYPE_MODE(lhs_type);
90831 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
90832 + return false;
90833 +
90834 + return true;
90835 +}
90836 +
90837 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
90838 +{
90839 + tree rhs1 = gimple_assign_rhs1(stmt);
90840 + tree lhs = gimple_get_lhs(stmt);
90841 + const_tree rhs1_type = TREE_TYPE(rhs1);
90842 + const_tree lhs_type = TREE_TYPE(lhs);
90843 +
90844 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
90845 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90846 +
90847 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
90848 +}
90849 +
90850 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
90851 +{
90852 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
90853 + tree new_rhs1 = NULL_TREE;
90854 + tree rhs1 = gimple_assign_rhs1(stmt);
90855 + const_tree rhs1_type = TREE_TYPE(rhs1);
90856 + const_tree lhs_type = TREE_TYPE(lhs);
90857 +
90858 + if (gimple_plf(stmt, MY_STMT))
90859 + return lhs;
90860 +
90861 + if (TREE_CODE(rhs1_type) == POINTER_TYPE)
90862 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90863 +
90864 + new_rhs1 = expand(visited, rhs1);
90865 +
90866 + if (new_rhs1 == NULL_TREE)
90867 + return create_cast_assign(visited, stmt);
90868 +
90869 + if (gimple_plf(stmt, NO_CAST_CHECK))
90870 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
90871 +
90872 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
90873 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
90874 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
90875 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
90876 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90877 + }
90878 +
90879 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
90880 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
90881 +
90882 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
90883 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
90884 +
90885 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
90886 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
90887 +
90888 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
90889 +
90890 + change_rhs1(stmt, new_rhs1);
90891 +
90892 + if (!check_mode_type(stmt))
90893 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90894 +
90895 + size_overflow_type = get_size_overflow_type(stmt, lhs);
90896 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
90897 +
90898 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
90899 +
90900 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90901 +}
90902 +
90903 +static tree handle_unary_ops(struct pointer_set_t *visited, gimple stmt)
90904 +{
90905 + tree rhs1, lhs = gimple_get_lhs(stmt);
90906 + gimple def_stmt = get_def_stmt(lhs);
90907 +
90908 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
90909 + rhs1 = gimple_assign_rhs1(def_stmt);
90910 +
90911 + if (is_gimple_constant(rhs1))
90912 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
90913 +
90914 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
90915 + switch (TREE_CODE(rhs1)) {
90916 + case SSA_NAME:
90917 + return handle_unary_rhs(visited, def_stmt);
90918 + case ARRAY_REF:
90919 + case BIT_FIELD_REF:
90920 + case ADDR_EXPR:
90921 + case COMPONENT_REF:
90922 + case INDIRECT_REF:
90923 +#if BUILDING_GCC_VERSION >= 4006
90924 + case MEM_REF:
90925 +#endif
90926 + case TARGET_MEM_REF:
90927 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
90928 + case PARM_DECL:
90929 + case VAR_DECL:
90930 + return create_assign(visited, stmt, lhs, AFTER_STMT);
90931 +
90932 + default:
90933 + debug_gimple_stmt(def_stmt);
90934 + debug_tree(rhs1);
90935 + gcc_unreachable();
90936 + }
90937 +}
90938 +
90939 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
90940 +{
90941 + gimple cond_stmt;
90942 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
90943 +
90944 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
90945 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
90946 + update_stmt(cond_stmt);
90947 +}
90948 +
90949 +static tree create_string_param(tree string)
90950 +{
90951 + tree i_type, a_type;
90952 + const int length = TREE_STRING_LENGTH(string);
90953 +
90954 + gcc_assert(length > 0);
90955 +
90956 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
90957 + a_type = build_array_type(char_type_node, i_type);
90958 +
90959 + TREE_TYPE(string) = a_type;
90960 + TREE_CONSTANT(string) = 1;
90961 + TREE_READONLY(string) = 1;
90962 +
90963 + return build1(ADDR_EXPR, ptr_type_node, string);
90964 +}
90965 +
90966 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
90967 +{
90968 + gimple func_stmt;
90969 + const_gimple def_stmt;
90970 + const_tree loc_line;
90971 + tree loc_file, ssa_name, current_func;
90972 + expanded_location xloc;
90973 + char *ssa_name_buf;
90974 + int len;
90975 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
90976 +
90977 + def_stmt = get_def_stmt(arg);
90978 + xloc = expand_location(gimple_location(def_stmt));
90979 +
90980 + if (!gimple_has_location(def_stmt)) {
90981 + xloc = expand_location(gimple_location(stmt));
90982 + if (!gimple_has_location(stmt))
90983 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
90984 + }
90985 +
90986 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
90987 +
90988 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
90989 + loc_file = create_string_param(loc_file);
90990 +
90991 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
90992 + current_func = create_string_param(current_func);
90993 +
90994 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
90995 + call_count++;
90996 + 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);
90997 + gcc_assert(len > 0);
90998 + ssa_name = build_string(len + 1, ssa_name_buf);
90999 + free(ssa_name_buf);
91000 + ssa_name = create_string_param(ssa_name);
91001 +
91002 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
91003 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
91004 +
91005 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
91006 +}
91007 +
91008 +static void __unused print_the_code_insertions(const_gimple stmt)
91009 +{
91010 + location_t loc = gimple_location(stmt);
91011 +
91012 + inform(loc, "Integer size_overflow check applied here.");
91013 +}
91014 +
91015 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
91016 +{
91017 + basic_block cond_bb, join_bb, bb_true;
91018 + edge e;
91019 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
91020 +
91021 + cond_bb = gimple_bb(stmt);
91022 + if (before)
91023 + gsi_prev(&gsi);
91024 + if (gsi_end_p(gsi))
91025 + e = split_block_after_labels(cond_bb);
91026 + else
91027 + e = split_block(cond_bb, gsi_stmt(gsi));
91028 + cond_bb = e->src;
91029 + join_bb = e->dest;
91030 + e->flags = EDGE_FALSE_VALUE;
91031 + e->probability = REG_BR_PROB_BASE;
91032 +
91033 + bb_true = create_empty_bb(cond_bb);
91034 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
91035 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
91036 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
91037 +
91038 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
91039 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
91040 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
91041 +
91042 + if (current_loops != NULL) {
91043 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
91044 + add_bb_to_loop(bb_true, cond_bb->loop_father);
91045 + }
91046 +
91047 + insert_cond(cond_bb, arg, cond_code, type_value);
91048 + insert_cond_result(bb_true, stmt, arg, min);
91049 +
91050 +// print_the_code_insertions(stmt);
91051 +}
91052 +
91053 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
91054 +{
91055 + const_tree rhs_type = TREE_TYPE(rhs);
91056 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
91057 +
91058 + gcc_assert(rhs_type != NULL_TREE);
91059 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
91060 + return;
91061 +
91062 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
91063 +
91064 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
91065 + // typemax (-1) < typemin (0)
91066 + if (TREE_OVERFLOW(type_max))
91067 + return;
91068 +
91069 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
91070 +
91071 + cast_rhs_type = TREE_TYPE(cast_rhs);
91072 + type_max_type = TREE_TYPE(type_max);
91073 + type_min_type = TREE_TYPE(type_min);
91074 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
91075 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
91076 +
91077 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
91078 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
91079 +}
91080 +
91081 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
91082 +{
91083 + gimple change_rhs_def_stmt;
91084 + tree lhs = gimple_get_lhs(def_stmt);
91085 + tree lhs_type = TREE_TYPE(lhs);
91086 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
91087 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
91088 +
91089 + if (change_rhs == NULL_TREE)
91090 + return get_size_overflow_type(def_stmt, lhs);
91091 +
91092 + change_rhs_def_stmt = get_def_stmt(change_rhs);
91093 +
91094 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
91095 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
91096 +
91097 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
91098 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
91099 +
91100 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
91101 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
91102 +
91103 + if (!types_compatible_p(lhs_type, rhs1_type) || !types_compatible_p(rhs1_type, rhs2_type)) {
91104 + debug_gimple_stmt(def_stmt);
91105 + gcc_unreachable();
91106 + }
91107 +
91108 + return get_size_overflow_type(def_stmt, lhs);
91109 +}
91110 +
91111 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
91112 +{
91113 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
91114 + return false;
91115 + if (!is_gimple_constant(rhs))
91116 + return false;
91117 + return true;
91118 +}
91119 +
91120 +static bool is_subtraction_special(const_gimple stmt)
91121 +{
91122 + gimple rhs1_def_stmt, rhs2_def_stmt;
91123 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
91124 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
91125 + const_tree rhs1 = gimple_assign_rhs1(stmt);
91126 + const_tree rhs2 = gimple_assign_rhs2(stmt);
91127 +
91128 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
91129 + return false;
91130 +
91131 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
91132 +
91133 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
91134 + return false;
91135 +
91136 + rhs1_def_stmt = get_def_stmt(rhs1);
91137 + rhs2_def_stmt = get_def_stmt(rhs2);
91138 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
91139 + return false;
91140 +
91141 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
91142 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
91143 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
91144 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
91145 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
91146 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
91147 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
91148 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
91149 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
91150 + return false;
91151 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
91152 + return false;
91153 +
91154 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
91155 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
91156 + return true;
91157 +}
91158 +
91159 +static tree get_def_stmt_rhs(const_tree var)
91160 +{
91161 + tree rhs1, def_stmt_rhs1;
91162 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
91163 +
91164 + def_stmt = get_def_stmt(var);
91165 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
91166 +
91167 + rhs1 = gimple_assign_rhs1(def_stmt);
91168 + rhs1_def_stmt = get_def_stmt(rhs1);
91169 + if (!gimple_assign_cast_p(rhs1_def_stmt))
91170 + return rhs1;
91171 +
91172 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
91173 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
91174 +
91175 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
91176 + case GIMPLE_CALL:
91177 + case GIMPLE_NOP:
91178 + case GIMPLE_ASM:
91179 + return def_stmt_rhs1;
91180 + case GIMPLE_ASSIGN:
91181 + return rhs1;
91182 + default:
91183 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
91184 + gcc_unreachable();
91185 + }
91186 +}
91187 +
91188 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
91189 +{
91190 + tree new_rhs1, new_rhs2;
91191 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
91192 + gimple assign, stmt = get_def_stmt(lhs);
91193 + tree rhs1 = gimple_assign_rhs1(stmt);
91194 + tree rhs2 = gimple_assign_rhs2(stmt);
91195 +
91196 + if (!is_subtraction_special(stmt))
91197 + return NULL_TREE;
91198 +
91199 + new_rhs1 = expand(visited, rhs1);
91200 + new_rhs2 = expand(visited, rhs2);
91201 +
91202 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
91203 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
91204 +
91205 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
91206 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
91207 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
91208 + }
91209 +
91210 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
91211 + new_lhs = gimple_get_lhs(assign);
91212 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
91213 +
91214 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
91215 +}
91216 +
91217 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
91218 +{
91219 + const_gimple def_stmt;
91220 +
91221 + if (TREE_CODE(rhs) != SSA_NAME)
91222 + return false;
91223 +
91224 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
91225 + return false;
91226 +
91227 + def_stmt = get_def_stmt(rhs);
91228 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
91229 + return false;
91230 +
91231 + return true;
91232 +}
91233 +
91234 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
91235 +{
91236 + tree new_rhs, size_overflow_type, orig_rhs;
91237 + void (*gimple_assign_set_rhs)(gimple, tree);
91238 + tree rhs1 = gimple_assign_rhs1(stmt);
91239 + tree rhs2 = gimple_assign_rhs2(stmt);
91240 + tree lhs = gimple_get_lhs(stmt);
91241 +
91242 + if (change_rhs == NULL_TREE)
91243 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91244 +
91245 + if (new_rhs2 == NULL_TREE) {
91246 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
91247 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
91248 + orig_rhs = rhs1;
91249 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
91250 + } else {
91251 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
91252 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
91253 + orig_rhs = rhs2;
91254 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
91255 + }
91256 +
91257 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
91258 +
91259 + if (check_overflow)
91260 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
91261 +
91262 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
91263 + gimple_assign_set_rhs(stmt, new_rhs);
91264 + update_stmt(stmt);
91265 +
91266 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91267 +}
91268 +
91269 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
91270 +{
91271 + tree rhs1, rhs2, new_lhs;
91272 + gimple def_stmt = get_def_stmt(lhs);
91273 + tree new_rhs1 = NULL_TREE;
91274 + tree new_rhs2 = NULL_TREE;
91275 +
91276 + rhs1 = gimple_assign_rhs1(def_stmt);
91277 + rhs2 = gimple_assign_rhs2(def_stmt);
91278 +
91279 + /* no DImode/TImode division in the 32/64 bit kernel */
91280 + switch (gimple_assign_rhs_code(def_stmt)) {
91281 + case RDIV_EXPR:
91282 + case TRUNC_DIV_EXPR:
91283 + case CEIL_DIV_EXPR:
91284 + case FLOOR_DIV_EXPR:
91285 + case ROUND_DIV_EXPR:
91286 + case TRUNC_MOD_EXPR:
91287 + case CEIL_MOD_EXPR:
91288 + case FLOOR_MOD_EXPR:
91289 + case ROUND_MOD_EXPR:
91290 + case EXACT_DIV_EXPR:
91291 + case POINTER_PLUS_EXPR:
91292 + case BIT_AND_EXPR:
91293 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
91294 + default:
91295 + break;
91296 + }
91297 +
91298 + new_lhs = handle_integer_truncation(visited, lhs);
91299 + if (new_lhs != NULL_TREE)
91300 + return new_lhs;
91301 +
91302 + if (TREE_CODE(rhs1) == SSA_NAME)
91303 + new_rhs1 = expand(visited, rhs1);
91304 + if (TREE_CODE(rhs2) == SSA_NAME)
91305 + new_rhs2 = expand(visited, rhs2);
91306 +
91307 + if (is_a_neg_overflow(def_stmt, rhs2))
91308 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
91309 + if (is_a_neg_overflow(def_stmt, rhs1))
91310 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
91311 +
91312 + if (is_a_constant_overflow(def_stmt, rhs2))
91313 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
91314 + if (is_a_constant_overflow(def_stmt, rhs1))
91315 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
91316 +
91317 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
91318 +}
91319 +
91320 +#if BUILDING_GCC_VERSION >= 4007
91321 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
91322 +{
91323 + if (is_gimple_constant(rhs))
91324 + return cast_a_tree(size_overflow_type, rhs);
91325 + if (TREE_CODE(rhs) != SSA_NAME)
91326 + return NULL_TREE;
91327 + return expand(visited, rhs);
91328 +}
91329 +
91330 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
91331 +{
91332 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
91333 + gimple def_stmt = get_def_stmt(lhs);
91334 +
91335 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
91336 +
91337 + rhs1 = gimple_assign_rhs1(def_stmt);
91338 + rhs2 = gimple_assign_rhs2(def_stmt);
91339 + rhs3 = gimple_assign_rhs3(def_stmt);
91340 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
91341 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
91342 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
91343 +
91344 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
91345 +}
91346 +#endif
91347 +
91348 +static tree get_size_overflow_type(gimple stmt, const_tree node)
91349 +{
91350 + const_tree type;
91351 + tree new_type;
91352 +
91353 + gcc_assert(node != NULL_TREE);
91354 +
91355 + type = TREE_TYPE(node);
91356 +
91357 + if (gimple_plf(stmt, MY_STMT))
91358 + return TREE_TYPE(node);
91359 +
91360 + switch (TYPE_MODE(type)) {
91361 + case QImode:
91362 + new_type = intHI_type_node;
91363 + break;
91364 + case HImode:
91365 + new_type = intSI_type_node;
91366 + break;
91367 + case SImode:
91368 + new_type = intDI_type_node;
91369 + break;
91370 + case DImode:
91371 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
91372 + new_type = intDI_type_node;
91373 + else
91374 + new_type = intTI_type_node;
91375 + break;
91376 + default:
91377 + debug_tree((tree)node);
91378 + error("%s: unsupported gcc configuration.", __func__);
91379 + gcc_unreachable();
91380 + }
91381 +
91382 + if (TYPE_QUALS(type) != 0)
91383 + return build_qualified_type(new_type, TYPE_QUALS(type));
91384 + return new_type;
91385 +}
91386 +
91387 +static tree expand_visited(gimple def_stmt)
91388 +{
91389 + const_gimple next_stmt;
91390 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
91391 +
91392 + gsi_next(&gsi);
91393 + next_stmt = gsi_stmt(gsi);
91394 +
91395 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
91396 +
91397 + switch (gimple_code(next_stmt)) {
91398 + case GIMPLE_ASSIGN:
91399 + return gimple_get_lhs(next_stmt);
91400 + case GIMPLE_PHI:
91401 + return gimple_phi_result(next_stmt);
91402 + case GIMPLE_CALL:
91403 + return gimple_call_lhs(next_stmt);
91404 + default:
91405 + return NULL_TREE;
91406 + }
91407 +}
91408 +
91409 +static tree expand(struct pointer_set_t *visited, tree lhs)
91410 +{
91411 + gimple def_stmt;
91412 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
91413 +
91414 + if (is_gimple_constant(lhs))
91415 + return NULL_TREE;
91416 +
91417 + if (TREE_CODE(lhs) == ADDR_EXPR)
91418 + return NULL_TREE;
91419 +
91420 + if (code == REAL_TYPE)
91421 + return NULL_TREE;
91422 +
91423 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
91424 +
91425 + def_stmt = get_def_stmt(lhs);
91426 +
91427 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
91428 + return NULL_TREE;
91429 +
91430 + if (gimple_plf(def_stmt, MY_STMT))
91431 + return lhs;
91432 +
91433 + if (pointer_set_contains(visited, def_stmt))
91434 + return expand_visited(def_stmt);
91435 +
91436 + switch (gimple_code(def_stmt)) {
91437 + case GIMPLE_PHI:
91438 + return build_new_phi(visited, lhs);
91439 + case GIMPLE_CALL:
91440 + case GIMPLE_ASM:
91441 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
91442 + case GIMPLE_ASSIGN:
91443 + switch (gimple_num_ops(def_stmt)) {
91444 + case 2:
91445 + return handle_unary_ops(visited, def_stmt);
91446 + case 3:
91447 + return handle_binary_ops(visited, lhs);
91448 +#if BUILDING_GCC_VERSION >= 4007
91449 + case 4:
91450 + return handle_ternary_ops(visited, lhs);
91451 +#endif
91452 + }
91453 + default:
91454 + debug_gimple_stmt(def_stmt);
91455 + error("%s: unknown gimple code", __func__);
91456 + gcc_unreachable();
91457 + }
91458 +}
91459 +
91460 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
91461 +{
91462 + const_gimple assign;
91463 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
91464 + tree origtype = TREE_TYPE(origarg);
91465 +
91466 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
91467 +
91468 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
91469 +
91470 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
91471 + update_stmt(stmt);
91472 +}
91473 +
91474 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
91475 +{
91476 + const char *origid;
91477 + tree arg;
91478 + const_tree origarg;
91479 +
91480 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
91481 + return true;
91482 +
91483 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
91484 + while (origarg && *argnum) {
91485 + (*argnum)--;
91486 + origarg = TREE_CHAIN(origarg);
91487 + }
91488 +
91489 + gcc_assert(*argnum == 0);
91490 +
91491 + gcc_assert(origarg != NULL_TREE);
91492 + origid = NAME(origarg);
91493 + *argnum = 0;
91494 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
91495 + if (!strcmp(origid, NAME(arg)))
91496 + return true;
91497 + (*argnum)++;
91498 + }
91499 + return false;
91500 +}
91501 +
91502 +static bool skip_types(const_tree var)
91503 +{
91504 + const_tree type;
91505 +
91506 + switch (TREE_CODE(var)) {
91507 + case ADDR_EXPR:
91508 +#if BUILDING_GCC_VERSION >= 4006
91509 + case MEM_REF:
91510 +#endif
91511 + case ARRAY_REF:
91512 + case BIT_FIELD_REF:
91513 + case INDIRECT_REF:
91514 + case TARGET_MEM_REF:
91515 + case VAR_DECL:
91516 + return true;
91517 + default:
91518 + break;
91519 + }
91520 +
91521 + type = TREE_TYPE(TREE_TYPE(var));
91522 + if (!type)
91523 + return false;
91524 + switch (TREE_CODE(type)) {
91525 + case RECORD_TYPE:
91526 + return true;
91527 + default:
91528 + break;
91529 + }
91530 +
91531 + return false;
91532 +}
91533 +
91534 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
91535 +{
91536 + gimple phi = get_def_stmt(result);
91537 + unsigned int i, n = gimple_phi_num_args(phi);
91538 +
91539 + if (!phi)
91540 + return false;
91541 +
91542 + pointer_set_insert(visited, phi);
91543 + for (i = 0; i < n; i++) {
91544 + const_tree arg = gimple_phi_arg_def(phi, i);
91545 + if (pre_expand(visited, arg))
91546 + return true;
91547 + }
91548 + return false;
91549 +}
91550 +
91551 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
91552 +{
91553 + gimple def_stmt = get_def_stmt(lhs);
91554 + const_tree rhs;
91555 +
91556 + if (!def_stmt)
91557 + return false;
91558 +
91559 + rhs = gimple_assign_rhs1(def_stmt);
91560 + if (pre_expand(visited, rhs))
91561 + return true;
91562 + return false;
91563 +}
91564 +
91565 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
91566 +{
91567 + bool rhs1_found, rhs2_found;
91568 + gimple def_stmt = get_def_stmt(lhs);
91569 + const_tree rhs1, rhs2;
91570 +
91571 + if (!def_stmt)
91572 + return false;
91573 +
91574 + rhs1 = gimple_assign_rhs1(def_stmt);
91575 + rhs2 = gimple_assign_rhs2(def_stmt);
91576 + rhs1_found = pre_expand(visited, rhs1);
91577 + rhs2_found = pre_expand(visited, rhs2);
91578 +
91579 + return rhs1_found || rhs2_found;
91580 +}
91581 +
91582 +static const_tree search_field_decl(const_tree comp_ref)
91583 +{
91584 + const_tree field = NULL_TREE;
91585 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
91586 +
91587 + for (i = 0; i < len; i++) {
91588 + field = TREE_OPERAND(comp_ref, i);
91589 + if (TREE_CODE(field) == FIELD_DECL)
91590 + break;
91591 + }
91592 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
91593 + return field;
91594 +}
91595 +
91596 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
91597 +{
91598 + const_tree attr, p;
91599 +
91600 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
91601 + if (!attr || !TREE_VALUE(attr))
91602 + return MARKED_NO;
91603 +
91604 + p = TREE_VALUE(attr);
91605 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
91606 + return MARKED_NOT_INTENTIONAL;
91607 +
91608 + do {
91609 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
91610 + return MARKED_YES;
91611 + p = TREE_CHAIN(p);
91612 + } while (p);
91613 +
91614 + return MARKED_NO;
91615 +}
91616 +
91617 +static void print_missing_msg(tree func, unsigned int argnum)
91618 +{
91619 + unsigned int new_hash;
91620 + size_t len;
91621 + unsigned char tree_codes[CODES_LIMIT];
91622 + location_t loc = DECL_SOURCE_LOCATION(func);
91623 + const char *curfunc = get_asm_name(func);
91624 +
91625 + len = get_function_decl(func, tree_codes);
91626 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
91627 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
91628 +}
91629 +
91630 +static unsigned int search_missing_attribute(const_tree arg)
91631 +{
91632 + const_tree type = TREE_TYPE(arg);
91633 + tree func = get_original_function_decl(current_function_decl);
91634 + unsigned int argnum;
91635 + const struct size_overflow_hash *hash;
91636 +
91637 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
91638 +
91639 + if (TREE_CODE(type) == POINTER_TYPE)
91640 + return 0;
91641 +
91642 + argnum = find_arg_number(arg, func);
91643 + if (argnum == 0)
91644 + return 0;
91645 +
91646 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
91647 + return argnum;
91648 +
91649 + hash = get_function_hash(func);
91650 + if (!hash || !(hash->param & (1U << argnum))) {
91651 + print_missing_msg(func, argnum);
91652 + return 0;
91653 + }
91654 + return argnum;
91655 +}
91656 +
91657 +static bool is_already_marked(const_tree lhs)
91658 +{
91659 + unsigned int argnum;
91660 + const_tree fndecl;
91661 +
91662 + argnum = search_missing_attribute(lhs);
91663 + fndecl = get_original_function_decl(current_function_decl);
91664 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
91665 + return true;
91666 + return false;
91667 +}
91668 +
91669 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
91670 +{
91671 + const_gimple def_stmt;
91672 +
91673 + if (is_gimple_constant(lhs))
91674 + return false;
91675 +
91676 + if (skip_types(lhs))
91677 + return false;
91678 +
91679 + // skip char type (FIXME: only kernel)
91680 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode)
91681 + return false;
91682 +
91683 + if (TREE_CODE(lhs) == PARM_DECL)
91684 + return is_already_marked(lhs);
91685 +
91686 + if (TREE_CODE(lhs) == COMPONENT_REF) {
91687 + const_tree field, attr;
91688 +
91689 + field = search_field_decl(lhs);
91690 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
91691 + if (!attr || !TREE_VALUE(attr))
91692 + return false;
91693 + return true;
91694 + }
91695 +
91696 + def_stmt = get_def_stmt(lhs);
91697 +
91698 + if (!def_stmt)
91699 + return false;
91700 +
91701 + if (pointer_set_contains(visited, def_stmt))
91702 + return false;
91703 +
91704 + switch (gimple_code(def_stmt)) {
91705 + case GIMPLE_NOP:
91706 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
91707 + return is_already_marked(lhs);
91708 + return false;
91709 + case GIMPLE_PHI:
91710 + return walk_phi(visited, lhs);
91711 + case GIMPLE_CALL:
91712 + case GIMPLE_ASM:
91713 + return false;
91714 + case GIMPLE_ASSIGN:
91715 + switch (gimple_num_ops(def_stmt)) {
91716 + case 2:
91717 + return walk_unary_ops(visited, lhs);
91718 + case 3:
91719 + return walk_binary_ops(visited, lhs);
91720 + }
91721 + default:
91722 + debug_gimple_stmt((gimple)def_stmt);
91723 + error("%s: unknown gimple code", __func__);
91724 + gcc_unreachable();
91725 + }
91726 +}
91727 +
91728 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
91729 +{
91730 + struct pointer_set_t *visited;
91731 + bool is_found;
91732 + enum marked is_marked;
91733 + location_t loc;
91734 +
91735 + visited = pointer_set_create();
91736 + is_found = pre_expand(visited, arg);
91737 + pointer_set_destroy(visited);
91738 +
91739 + is_marked = mark_status(fndecl, argnum + 1);
91740 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
91741 + return true;
91742 +
91743 + if (is_found) {
91744 + loc = DECL_SOURCE_LOCATION(fndecl);
91745 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
91746 + return true;
91747 + }
91748 + return false;
91749 +}
91750 +
91751 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
91752 +{
91753 + struct pointer_set_t *visited;
91754 + tree arg, newarg;
91755 + bool match;
91756 +
91757 + match = get_function_arg(&argnum, fndecl);
91758 + if (!match)
91759 + return;
91760 + gcc_assert(gimple_call_num_args(stmt) > argnum);
91761 + arg = gimple_call_arg(stmt, argnum);
91762 + if (arg == NULL_TREE)
91763 + return;
91764 +
91765 + if (is_gimple_constant(arg))
91766 + return;
91767 +
91768 + if (search_attributes(fndecl, arg, argnum))
91769 + return;
91770 +
91771 + if (TREE_CODE(arg) != SSA_NAME)
91772 + return;
91773 +
91774 + check_arg_type(arg);
91775 +
91776 + visited = pointer_set_create();
91777 + newarg = expand(visited, arg);
91778 + pointer_set_destroy(visited);
91779 +
91780 + if (newarg == NULL_TREE)
91781 + return;
91782 +
91783 + change_function_arg(stmt, arg, argnum, newarg);
91784 +
91785 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
91786 +}
91787 +
91788 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
91789 +{
91790 + tree p = TREE_VALUE(attr);
91791 + do {
91792 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
91793 + p = TREE_CHAIN(p);
91794 + } while (p);
91795 +}
91796 +
91797 +static void handle_function_by_hash(gimple stmt, tree fndecl)
91798 +{
91799 + tree orig_fndecl;
91800 + unsigned int num;
91801 + const struct size_overflow_hash *hash;
91802 +
91803 + orig_fndecl = get_original_function_decl(fndecl);
91804 + if (C_DECL_IMPLICIT(orig_fndecl))
91805 + return;
91806 + hash = get_function_hash(orig_fndecl);
91807 + if (!hash)
91808 + return;
91809 +
91810 + for (num = 1; num <= MAX_PARAM; num++)
91811 + if (hash->param & (1U << num))
91812 + handle_function_arg(stmt, fndecl, num - 1);
91813 +}
91814 +
91815 +static void set_plf_false(void)
91816 +{
91817 + basic_block bb;
91818 +
91819 + FOR_ALL_BB(bb) {
91820 + gimple_stmt_iterator si;
91821 +
91822 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
91823 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
91824 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
91825 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
91826 + }
91827 +}
91828 +
91829 +static unsigned int handle_function(void)
91830 +{
91831 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
91832 +
91833 + set_plf_false();
91834 +
91835 + do {
91836 + gimple_stmt_iterator gsi;
91837 + next = bb->next_bb;
91838 +
91839 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
91840 + tree fndecl, attr;
91841 + gimple stmt = gsi_stmt(gsi);
91842 +
91843 + if (!(is_gimple_call(stmt)))
91844 + continue;
91845 + fndecl = gimple_call_fndecl(stmt);
91846 + if (fndecl == NULL_TREE)
91847 + continue;
91848 + if (gimple_call_num_args(stmt) == 0)
91849 + continue;
91850 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
91851 + if (!attr || !TREE_VALUE(attr))
91852 + handle_function_by_hash(stmt, fndecl);
91853 + else
91854 + handle_function_by_attribute(stmt, attr, fndecl);
91855 + gsi = gsi_for_stmt(stmt);
91856 + next = gimple_bb(stmt)->next_bb;
91857 + }
91858 + bb = next;
91859 + } while (bb);
91860 + return 0;
91861 +}
91862 +
91863 +static struct gimple_opt_pass size_overflow_pass = {
91864 + .pass = {
91865 + .type = GIMPLE_PASS,
91866 + .name = "size_overflow",
91867 + .gate = NULL,
91868 + .execute = handle_function,
91869 + .sub = NULL,
91870 + .next = NULL,
91871 + .static_pass_number = 0,
91872 + .tv_id = TV_NONE,
91873 + .properties_required = PROP_cfg | PROP_referenced_vars,
91874 + .properties_provided = 0,
91875 + .properties_destroyed = 0,
91876 + .todo_flags_start = 0,
91877 + .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
91878 + }
91879 +};
91880 +
91881 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
91882 +{
91883 + tree fntype;
91884 +
91885 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
91886 +
91887 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
91888 + fntype = build_function_type_list(void_type_node,
91889 + const_char_ptr_type_node,
91890 + unsigned_type_node,
91891 + const_char_ptr_type_node,
91892 + const_char_ptr_type_node,
91893 + NULL_TREE);
91894 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
91895 +
91896 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
91897 + TREE_PUBLIC(report_size_overflow_decl) = 1;
91898 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
91899 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
91900 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
91901 +}
91902 +
91903 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
91904 +{
91905 + int i;
91906 + const char * const plugin_name = plugin_info->base_name;
91907 + const int argc = plugin_info->argc;
91908 + const struct plugin_argument * const argv = plugin_info->argv;
91909 + bool enable = true;
91910 +
91911 + struct register_pass_info size_overflow_pass_info = {
91912 + .pass = &size_overflow_pass.pass,
91913 + .reference_pass_name = "ssa",
91914 + .ref_pass_instance_number = 1,
91915 + .pos_op = PASS_POS_INSERT_AFTER
91916 + };
91917 +
91918 + if (!plugin_default_version_check(version, &gcc_version)) {
91919 + error(G_("incompatible gcc/plugin versions"));
91920 + return 1;
91921 + }
91922 +
91923 + for (i = 0; i < argc; ++i) {
91924 + if (!strcmp(argv[i].key, "no-size-overflow")) {
91925 + enable = false;
91926 + continue;
91927 + }
91928 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
91929 + }
91930 +
91931 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
91932 + if (enable) {
91933 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
91934 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
91935 + }
91936 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
91937 +
91938 + return 0;
91939 +}
91940 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
91941 new file mode 100644
91942 index 0000000..38d2014
91943 --- /dev/null
91944 +++ b/tools/gcc/stackleak_plugin.c
91945 @@ -0,0 +1,313 @@
91946 +/*
91947 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
91948 + * Licensed under the GPL v2
91949 + *
91950 + * Note: the choice of the license means that the compilation process is
91951 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
91952 + * but for the kernel it doesn't matter since it doesn't link against
91953 + * any of the gcc libraries
91954 + *
91955 + * gcc plugin to help implement various PaX features
91956 + *
91957 + * - track lowest stack pointer
91958 + *
91959 + * TODO:
91960 + * - initialize all local variables
91961 + *
91962 + * BUGS:
91963 + * - none known
91964 + */
91965 +#include "gcc-plugin.h"
91966 +#include "config.h"
91967 +#include "system.h"
91968 +#include "coretypes.h"
91969 +#include "tree.h"
91970 +#include "tree-pass.h"
91971 +#include "flags.h"
91972 +#include "intl.h"
91973 +#include "toplev.h"
91974 +#include "plugin.h"
91975 +//#include "expr.h" where are you...
91976 +#include "diagnostic.h"
91977 +#include "plugin-version.h"
91978 +#include "tm.h"
91979 +#include "function.h"
91980 +#include "basic-block.h"
91981 +#include "gimple.h"
91982 +#include "rtl.h"
91983 +#include "emit-rtl.h"
91984 +
91985 +extern void print_gimple_stmt(FILE *, gimple, int, int);
91986 +
91987 +int plugin_is_GPL_compatible;
91988 +
91989 +static int track_frame_size = -1;
91990 +static const char track_function[] = "pax_track_stack";
91991 +static const char check_function[] = "pax_check_alloca";
91992 +static bool init_locals;
91993 +
91994 +static struct plugin_info stackleak_plugin_info = {
91995 + .version = "201203140940",
91996 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
91997 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
91998 +};
91999 +
92000 +static bool gate_stackleak_track_stack(void);
92001 +static unsigned int execute_stackleak_tree_instrument(void);
92002 +static unsigned int execute_stackleak_final(void);
92003 +
92004 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
92005 + .pass = {
92006 + .type = GIMPLE_PASS,
92007 + .name = "stackleak_tree_instrument",
92008 + .gate = gate_stackleak_track_stack,
92009 + .execute = execute_stackleak_tree_instrument,
92010 + .sub = NULL,
92011 + .next = NULL,
92012 + .static_pass_number = 0,
92013 + .tv_id = TV_NONE,
92014 + .properties_required = PROP_gimple_leh | PROP_cfg,
92015 + .properties_provided = 0,
92016 + .properties_destroyed = 0,
92017 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
92018 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
92019 + }
92020 +};
92021 +
92022 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
92023 + .pass = {
92024 + .type = RTL_PASS,
92025 + .name = "stackleak_final",
92026 + .gate = gate_stackleak_track_stack,
92027 + .execute = execute_stackleak_final,
92028 + .sub = NULL,
92029 + .next = NULL,
92030 + .static_pass_number = 0,
92031 + .tv_id = TV_NONE,
92032 + .properties_required = 0,
92033 + .properties_provided = 0,
92034 + .properties_destroyed = 0,
92035 + .todo_flags_start = 0,
92036 + .todo_flags_finish = TODO_dump_func
92037 + }
92038 +};
92039 +
92040 +static bool gate_stackleak_track_stack(void)
92041 +{
92042 + return track_frame_size >= 0;
92043 +}
92044 +
92045 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
92046 +{
92047 + gimple check_alloca;
92048 + tree fntype, fndecl, alloca_size;
92049 +
92050 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
92051 + fndecl = build_fn_decl(check_function, fntype);
92052 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
92053 +
92054 + // insert call to void pax_check_alloca(unsigned long size)
92055 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
92056 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
92057 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
92058 +}
92059 +
92060 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
92061 +{
92062 + gimple track_stack;
92063 + tree fntype, fndecl;
92064 +
92065 + fntype = build_function_type_list(void_type_node, NULL_TREE);
92066 + fndecl = build_fn_decl(track_function, fntype);
92067 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
92068 +
92069 + // insert call to void pax_track_stack(void)
92070 + track_stack = gimple_build_call(fndecl, 0);
92071 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
92072 +}
92073 +
92074 +#if BUILDING_GCC_VERSION == 4005
92075 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
92076 +{
92077 + tree fndecl;
92078 +
92079 + if (!is_gimple_call(stmt))
92080 + return false;
92081 + fndecl = gimple_call_fndecl(stmt);
92082 + if (!fndecl)
92083 + return false;
92084 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
92085 + return false;
92086 +// print_node(stderr, "pax", fndecl, 4);
92087 + return DECL_FUNCTION_CODE(fndecl) == code;
92088 +}
92089 +#endif
92090 +
92091 +static bool is_alloca(gimple stmt)
92092 +{
92093 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
92094 + return true;
92095 +
92096 +#if BUILDING_GCC_VERSION >= 4007
92097 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
92098 + return true;
92099 +#endif
92100 +
92101 + return false;
92102 +}
92103 +
92104 +static unsigned int execute_stackleak_tree_instrument(void)
92105 +{
92106 + basic_block bb, entry_bb;
92107 + bool prologue_instrumented = false, is_leaf = true;
92108 +
92109 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
92110 +
92111 + // 1. loop through BBs and GIMPLE statements
92112 + FOR_EACH_BB(bb) {
92113 + gimple_stmt_iterator gsi;
92114 +
92115 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92116 + gimple stmt;
92117 +
92118 + stmt = gsi_stmt(gsi);
92119 +
92120 + if (is_gimple_call(stmt))
92121 + is_leaf = false;
92122 +
92123 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
92124 + if (!is_alloca(stmt))
92125 + continue;
92126 +
92127 + // 2. insert stack overflow check before each __builtin_alloca call
92128 + stackleak_check_alloca(&gsi);
92129 +
92130 + // 3. insert track call after each __builtin_alloca call
92131 + stackleak_add_instrumentation(&gsi);
92132 + if (bb == entry_bb)
92133 + prologue_instrumented = true;
92134 + }
92135 + }
92136 +
92137 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
92138 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
92139 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
92140 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
92141 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
92142 + return 0;
92143 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
92144 + return 0;
92145 +
92146 + // 4. insert track call at the beginning
92147 + if (!prologue_instrumented) {
92148 + gimple_stmt_iterator gsi;
92149 +
92150 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
92151 + if (dom_info_available_p(CDI_DOMINATORS))
92152 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
92153 + gsi = gsi_start_bb(bb);
92154 + stackleak_add_instrumentation(&gsi);
92155 + }
92156 +
92157 + return 0;
92158 +}
92159 +
92160 +static unsigned int execute_stackleak_final(void)
92161 +{
92162 + rtx insn;
92163 +
92164 + if (cfun->calls_alloca)
92165 + return 0;
92166 +
92167 + // keep calls only if function frame is big enough
92168 + if (get_frame_size() >= track_frame_size)
92169 + return 0;
92170 +
92171 + // 1. find pax_track_stack calls
92172 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
92173 + // 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))
92174 + rtx body;
92175 +
92176 + if (!CALL_P(insn))
92177 + continue;
92178 + body = PATTERN(insn);
92179 + if (GET_CODE(body) != CALL)
92180 + continue;
92181 + body = XEXP(body, 0);
92182 + if (GET_CODE(body) != MEM)
92183 + continue;
92184 + body = XEXP(body, 0);
92185 + if (GET_CODE(body) != SYMBOL_REF)
92186 + continue;
92187 + if (strcmp(XSTR(body, 0), track_function))
92188 + continue;
92189 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
92190 + // 2. delete call
92191 + insn = delete_insn_and_edges(insn);
92192 +#if BUILDING_GCC_VERSION >= 4007
92193 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
92194 + insn = delete_insn_and_edges(insn);
92195 +#endif
92196 + }
92197 +
92198 +// print_simple_rtl(stderr, get_insns());
92199 +// print_rtl(stderr, get_insns());
92200 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
92201 +
92202 + return 0;
92203 +}
92204 +
92205 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92206 +{
92207 + const char * const plugin_name = plugin_info->base_name;
92208 + const int argc = plugin_info->argc;
92209 + const struct plugin_argument * const argv = plugin_info->argv;
92210 + int i;
92211 + struct register_pass_info stackleak_tree_instrument_pass_info = {
92212 + .pass = &stackleak_tree_instrument_pass.pass,
92213 +// .reference_pass_name = "tree_profile",
92214 + .reference_pass_name = "optimized",
92215 + .ref_pass_instance_number = 1,
92216 + .pos_op = PASS_POS_INSERT_BEFORE
92217 + };
92218 + struct register_pass_info stackleak_final_pass_info = {
92219 + .pass = &stackleak_final_rtl_opt_pass.pass,
92220 + .reference_pass_name = "final",
92221 + .ref_pass_instance_number = 1,
92222 + .pos_op = PASS_POS_INSERT_BEFORE
92223 + };
92224 +
92225 + if (!plugin_default_version_check(version, &gcc_version)) {
92226 + error(G_("incompatible gcc/plugin versions"));
92227 + return 1;
92228 + }
92229 +
92230 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
92231 +
92232 + for (i = 0; i < argc; ++i) {
92233 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
92234 + if (!argv[i].value) {
92235 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92236 + continue;
92237 + }
92238 + track_frame_size = atoi(argv[i].value);
92239 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
92240 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
92241 + continue;
92242 + }
92243 + if (!strcmp(argv[i].key, "initialize-locals")) {
92244 + if (argv[i].value) {
92245 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
92246 + continue;
92247 + }
92248 + init_locals = true;
92249 + continue;
92250 + }
92251 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92252 + }
92253 +
92254 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
92255 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
92256 +
92257 + return 0;
92258 +}
92259 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
92260 index 6789d78..4afd019e 100644
92261 --- a/tools/perf/util/include/asm/alternative-asm.h
92262 +++ b/tools/perf/util/include/asm/alternative-asm.h
92263 @@ -5,4 +5,7 @@
92264
92265 #define altinstruction_entry #
92266
92267 + .macro pax_force_retaddr rip=0, reload=0
92268 + .endm
92269 +
92270 #endif
92271 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
92272 index 6e8fa7e..37f02a5 100644
92273 --- a/virt/kvm/kvm_main.c
92274 +++ b/virt/kvm/kvm_main.c
92275 @@ -75,12 +75,17 @@ LIST_HEAD(vm_list);
92276
92277 static cpumask_var_t cpus_hardware_enabled;
92278 static int kvm_usage_count = 0;
92279 -static atomic_t hardware_enable_failed;
92280 +static atomic_unchecked_t hardware_enable_failed;
92281
92282 struct kmem_cache *kvm_vcpu_cache;
92283 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
92284
92285 -static __read_mostly struct preempt_ops kvm_preempt_ops;
92286 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
92287 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
92288 +static struct preempt_ops kvm_preempt_ops = {
92289 + .sched_in = kvm_sched_in,
92290 + .sched_out = kvm_sched_out,
92291 +};
92292
92293 struct dentry *kvm_debugfs_dir;
92294
92295 @@ -726,7 +731,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
92296 /* We can read the guest memory with __xxx_user() later on. */
92297 if (user_alloc &&
92298 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
92299 - !access_ok(VERIFY_WRITE,
92300 + !__access_ok(VERIFY_WRITE,
92301 (void __user *)(unsigned long)mem->userspace_addr,
92302 mem->memory_size)))
92303 goto out;
92304 @@ -2450,7 +2455,7 @@ static void hardware_enable_nolock(void *junk)
92305
92306 if (r) {
92307 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
92308 - atomic_inc(&hardware_enable_failed);
92309 + atomic_inc_unchecked(&hardware_enable_failed);
92310 printk(KERN_INFO "kvm: enabling virtualization on "
92311 "CPU%d failed\n", cpu);
92312 }
92313 @@ -2504,10 +2509,10 @@ static int hardware_enable_all(void)
92314
92315 kvm_usage_count++;
92316 if (kvm_usage_count == 1) {
92317 - atomic_set(&hardware_enable_failed, 0);
92318 + atomic_set_unchecked(&hardware_enable_failed, 0);
92319 on_each_cpu(hardware_enable_nolock, NULL, 1);
92320
92321 - if (atomic_read(&hardware_enable_failed)) {
92322 + if (atomic_read_unchecked(&hardware_enable_failed)) {
92323 hardware_disable_all_nolock();
92324 r = -EBUSY;
92325 }
92326 @@ -2865,7 +2870,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
92327 kvm_arch_vcpu_put(vcpu);
92328 }
92329
92330 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92331 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92332 struct module *module)
92333 {
92334 int r;
92335 @@ -2901,7 +2906,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92336 if (!vcpu_align)
92337 vcpu_align = __alignof__(struct kvm_vcpu);
92338 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
92339 - 0, NULL);
92340 + SLAB_USERCOPY, NULL);
92341 if (!kvm_vcpu_cache) {
92342 r = -ENOMEM;
92343 goto out_free_3;
92344 @@ -2911,9 +2916,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92345 if (r)
92346 goto out_free;
92347
92348 - kvm_chardev_ops.owner = module;
92349 - kvm_vm_fops.owner = module;
92350 - kvm_vcpu_fops.owner = module;
92351 + pax_open_kernel();
92352 + *(void **)&kvm_chardev_ops.owner = module;
92353 + *(void **)&kvm_vm_fops.owner = module;
92354 + *(void **)&kvm_vcpu_fops.owner = module;
92355 + pax_close_kernel();
92356
92357 r = misc_register(&kvm_dev);
92358 if (r) {
92359 @@ -2923,9 +2930,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92360
92361 register_syscore_ops(&kvm_syscore_ops);
92362
92363 - kvm_preempt_ops.sched_in = kvm_sched_in;
92364 - kvm_preempt_ops.sched_out = kvm_sched_out;
92365 -
92366 r = kvm_init_debug();
92367 if (r) {
92368 printk(KERN_ERR "kvm: create debugfs files failed\n");