]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.7.8-201302142042.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.7.8-201302142042.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 ad48987..d808c2d 100644
255 --- a/Makefile
256 +++ b/Makefile
257 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
258
259 HOSTCC = gcc
260 HOSTCXX = g++
261 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
262 -HOSTCXXFLAGS = -O2
263 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
264 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
265 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
266
267 # Decide whether to build built-in, modular, or both.
268 # Normally, just do built-in.
269 @@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
270 # Rules shared between *config targets and build targets
271
272 # Basic helpers built in scripts/
273 -PHONY += scripts_basic
274 -scripts_basic:
275 +PHONY += scripts_basic gcc-plugins
276 +scripts_basic: gcc-plugins
277 $(Q)$(MAKE) $(build)=scripts/basic
278 $(Q)rm -f .tmp_quiet_recordmcount
279
280 @@ -575,6 +576,60 @@ else
281 KBUILD_CFLAGS += -O2
282 endif
283
284 +ifndef DISABLE_PAX_PLUGINS
285 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
286 +ifneq ($(PLUGINCC),)
287 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
288 +ifndef CONFIG_UML
289 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
290 +endif
291 +endif
292 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
293 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
294 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
295 +endif
296 +ifdef CONFIG_KALLOCSTAT_PLUGIN
297 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
298 +endif
299 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
300 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
301 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
302 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
303 +endif
304 +ifdef CONFIG_CHECKER_PLUGIN
305 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
306 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
307 +endif
308 +endif
309 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
310 +ifdef CONFIG_PAX_SIZE_OVERFLOW
311 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
312 +endif
313 +ifdef CONFIG_PAX_LATENT_ENTROPY
314 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
315 +endif
316 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
317 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
318 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
319 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
320 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
321 +ifeq ($(KBUILD_EXTMOD),)
322 +gcc-plugins:
323 + $(Q)$(MAKE) $(build)=tools/gcc
324 +else
325 +gcc-plugins: ;
326 +endif
327 +else
328 +gcc-plugins:
329 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
330 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
331 +else
332 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
333 +endif
334 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
335 +endif
336 +endif
337 +
338 include $(srctree)/arch/$(SRCARCH)/Makefile
339
340 ifdef CONFIG_READABLE_ASM
341 @@ -731,7 +786,7 @@ export mod_sign_cmd
342
343
344 ifeq ($(KBUILD_EXTMOD),)
345 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
346 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
347
348 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
349 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
350 @@ -778,6 +833,8 @@ endif
351
352 # The actual objects are generated when descending,
353 # make sure no implicit rule kicks in
354 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
355 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
356 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
357
358 # Handle descending into subdirectories listed in $(vmlinux-dirs)
359 @@ -787,7 +844,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
360 # Error messages still appears in the original language
361
362 PHONY += $(vmlinux-dirs)
363 -$(vmlinux-dirs): prepare scripts
364 +$(vmlinux-dirs): gcc-plugins prepare scripts
365 $(Q)$(MAKE) $(build)=$@
366
367 # Store (new) KERNELRELASE string in include/config/kernel.release
368 @@ -831,6 +888,7 @@ prepare0: archprepare FORCE
369 $(Q)$(MAKE) $(build)=.
370
371 # All the preparing..
372 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
373 prepare: prepare0
374
375 # Generate some files
376 @@ -938,6 +996,8 @@ all: modules
377 # using awk while concatenating to the final file.
378
379 PHONY += modules
380 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
381 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
382 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
383 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
384 @$(kecho) ' Building modules, stage 2.';
385 @@ -953,7 +1013,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
386
387 # Target to prepare building external modules
388 PHONY += modules_prepare
389 -modules_prepare: prepare scripts
390 +modules_prepare: gcc-plugins prepare scripts
391
392 # Target to install modules
393 PHONY += modules_install
394 @@ -1013,7 +1073,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
395 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
396 signing_key.priv signing_key.x509 x509.genkey \
397 extra_certificates signing_key.x509.keyid \
398 - signing_key.x509.signer
399 + signing_key.x509.signer tools/gcc/size_overflow_hash.h
400
401 # clean - Delete most, but leave enough to build external modules
402 #
403 @@ -1053,6 +1113,7 @@ distclean: mrproper
404 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
405 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
406 -o -name '.*.rej' \
407 + -o -name '.*.rej' -o -name '*.so' \
408 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
409 -type f -print | xargs rm -f
410
411 @@ -1213,6 +1274,8 @@ PHONY += $(module-dirs) modules
412 $(module-dirs): crmodverdir $(objtree)/Module.symvers
413 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
414
415 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(module-dirs)
418 @$(kecho) ' Building modules, stage 2.';
419 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
420 @@ -1349,17 +1412,21 @@ else
421 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
422 endif
423
424 -%.s: %.c prepare scripts FORCE
425 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
426 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
427 +%.s: %.c gcc-plugins prepare scripts FORCE
428 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
429 %.i: %.c prepare scripts FORCE
430 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
431 -%.o: %.c prepare scripts FORCE
432 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434 +%.o: %.c gcc-plugins prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436 %.lst: %.c prepare scripts FORCE
437 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
438 -%.s: %.S prepare scripts FORCE
439 +%.s: %.S gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 -%.o: %.S prepare scripts FORCE
442 +%.o: %.S gcc-plugins prepare scripts FORCE
443 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
444 %.symtypes: %.c prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 @@ -1369,11 +1436,15 @@ endif
447 $(cmd_crmodverdir)
448 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
449 $(build)=$(build-dir)
450 -%/: prepare scripts FORCE
451 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
452 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
453 +%/: gcc-plugins prepare scripts FORCE
454 $(cmd_crmodverdir)
455 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
456 $(build)=$(build-dir)
457 -%.ko: prepare scripts FORCE
458 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
459 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
460 +%.ko: gcc-plugins prepare scripts FORCE
461 $(cmd_crmodverdir)
462 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
463 $(build)=$(build-dir) $(@:.ko=.o)
464 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
465 index c2cbe4f..f7264b4 100644
466 --- a/arch/alpha/include/asm/atomic.h
467 +++ b/arch/alpha/include/asm/atomic.h
468 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
469 #define atomic_dec(v) atomic_sub(1,(v))
470 #define atomic64_dec(v) atomic64_sub(1,(v))
471
472 +#define atomic64_read_unchecked(v) atomic64_read(v)
473 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
474 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
475 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
476 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
477 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
478 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
479 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
480 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
481 +
482 #define smp_mb__before_atomic_dec() smp_mb()
483 #define smp_mb__after_atomic_dec() smp_mb()
484 #define smp_mb__before_atomic_inc() smp_mb()
485 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
486 index ad368a9..fbe0f25 100644
487 --- a/arch/alpha/include/asm/cache.h
488 +++ b/arch/alpha/include/asm/cache.h
489 @@ -4,19 +4,19 @@
490 #ifndef __ARCH_ALPHA_CACHE_H
491 #define __ARCH_ALPHA_CACHE_H
492
493 +#include <linux/const.h>
494
495 /* Bytes per L1 (data) cache line. */
496 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
497 -# define L1_CACHE_BYTES 64
498 # define L1_CACHE_SHIFT 6
499 #else
500 /* Both EV4 and EV5 are write-through, read-allocate,
501 direct-mapped, physical.
502 */
503 -# define L1_CACHE_BYTES 32
504 # define L1_CACHE_SHIFT 5
505 #endif
506
507 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
508 #define SMP_CACHE_BYTES L1_CACHE_BYTES
509
510 #endif
511 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
512 index 968d999..d36b2df 100644
513 --- a/arch/alpha/include/asm/elf.h
514 +++ b/arch/alpha/include/asm/elf.h
515 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
516
517 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
518
519 +#ifdef CONFIG_PAX_ASLR
520 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
521 +
522 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
523 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
524 +#endif
525 +
526 /* $0 is set by ld.so to a pointer to a function which might be
527 registered using atexit. This provides a mean for the dynamic
528 linker to call DT_FINI functions for shared libraries that have
529 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
530 index bc2a0da..8ad11ee 100644
531 --- a/arch/alpha/include/asm/pgalloc.h
532 +++ b/arch/alpha/include/asm/pgalloc.h
533 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
534 pgd_set(pgd, pmd);
535 }
536
537 +static inline void
538 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539 +{
540 + pgd_populate(mm, pgd, pmd);
541 +}
542 +
543 extern pgd_t *pgd_alloc(struct mm_struct *mm);
544
545 static inline void
546 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
547 index 81a4342..348b927 100644
548 --- a/arch/alpha/include/asm/pgtable.h
549 +++ b/arch/alpha/include/asm/pgtable.h
550 @@ -102,6 +102,17 @@ struct vm_area_struct;
551 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
552 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
553 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
554 +
555 +#ifdef CONFIG_PAX_PAGEEXEC
556 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
557 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
558 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
559 +#else
560 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
561 +# define PAGE_COPY_NOEXEC PAGE_COPY
562 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
563 +#endif
564 +
565 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
566
567 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
568 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
569 index 2fd00b7..cfd5069 100644
570 --- a/arch/alpha/kernel/module.c
571 +++ b/arch/alpha/kernel/module.c
572 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
573
574 /* The small sections were sorted to the end of the segment.
575 The following should definitely cover them. */
576 - gp = (u64)me->module_core + me->core_size - 0x8000;
577 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
578 got = sechdrs[me->arch.gotsecindex].sh_addr;
579
580 for (i = 0; i < n; i++) {
581 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
582 index 14db93e..47bed62 100644
583 --- a/arch/alpha/kernel/osf_sys.c
584 +++ b/arch/alpha/kernel/osf_sys.c
585 @@ -1295,16 +1295,16 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
586 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
587
588 static unsigned long
589 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
590 - unsigned long limit)
591 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
592 + unsigned long limit, unsigned long flags)
593 {
594 struct vm_area_struct *vma = find_vma(current->mm, addr);
595 -
596 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
597 while (1) {
598 /* At this point: (!vma || addr < vma->vm_end). */
599 if (limit - len < addr)
600 return -ENOMEM;
601 - if (!vma || addr + len <= vma->vm_start)
602 + if (check_heap_stack_gap(vma, addr, len, offset))
603 return addr;
604 addr = vma->vm_end;
605 vma = vma->vm_next;
606 @@ -1340,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
607 merely specific addresses, but regions of memory -- perhaps
608 this feature should be incorporated into all ports? */
609
610 +#ifdef CONFIG_PAX_RANDMMAP
611 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
612 +#endif
613 +
614 if (addr) {
615 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
616 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
617 if (addr != (unsigned long) -ENOMEM)
618 return addr;
619 }
620
621 /* Next, try allocating at TASK_UNMAPPED_BASE. */
622 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
623 - len, limit);
624 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
625 +
626 if (addr != (unsigned long) -ENOMEM)
627 return addr;
628
629 /* Finally, try allocating in low memory. */
630 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
631 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
632
633 return addr;
634 }
635 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
636 index 0c4132d..88f0d53 100644
637 --- a/arch/alpha/mm/fault.c
638 +++ b/arch/alpha/mm/fault.c
639 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
640 __reload_thread(pcb);
641 }
642
643 +#ifdef CONFIG_PAX_PAGEEXEC
644 +/*
645 + * PaX: decide what to do with offenders (regs->pc = fault address)
646 + *
647 + * returns 1 when task should be killed
648 + * 2 when patched PLT trampoline was detected
649 + * 3 when unpatched PLT trampoline was detected
650 + */
651 +static int pax_handle_fetch_fault(struct pt_regs *regs)
652 +{
653 +
654 +#ifdef CONFIG_PAX_EMUPLT
655 + int err;
656 +
657 + do { /* PaX: patched PLT emulation #1 */
658 + unsigned int ldah, ldq, jmp;
659 +
660 + err = get_user(ldah, (unsigned int *)regs->pc);
661 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
662 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
663 +
664 + if (err)
665 + break;
666 +
667 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
668 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
669 + jmp == 0x6BFB0000U)
670 + {
671 + unsigned long r27, addr;
672 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
673 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
674 +
675 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
676 + err = get_user(r27, (unsigned long *)addr);
677 + if (err)
678 + break;
679 +
680 + regs->r27 = r27;
681 + regs->pc = r27;
682 + return 2;
683 + }
684 + } while (0);
685 +
686 + do { /* PaX: patched PLT emulation #2 */
687 + unsigned int ldah, lda, br;
688 +
689 + err = get_user(ldah, (unsigned int *)regs->pc);
690 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
691 + err |= get_user(br, (unsigned int *)(regs->pc+8));
692 +
693 + if (err)
694 + break;
695 +
696 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
697 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
698 + (br & 0xFFE00000U) == 0xC3E00000U)
699 + {
700 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
701 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
702 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
703 +
704 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
705 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
706 + return 2;
707 + }
708 + } while (0);
709 +
710 + do { /* PaX: unpatched PLT emulation */
711 + unsigned int br;
712 +
713 + err = get_user(br, (unsigned int *)regs->pc);
714 +
715 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
716 + unsigned int br2, ldq, nop, jmp;
717 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
718 +
719 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
720 + err = get_user(br2, (unsigned int *)addr);
721 + err |= get_user(ldq, (unsigned int *)(addr+4));
722 + err |= get_user(nop, (unsigned int *)(addr+8));
723 + err |= get_user(jmp, (unsigned int *)(addr+12));
724 + err |= get_user(resolver, (unsigned long *)(addr+16));
725 +
726 + if (err)
727 + break;
728 +
729 + if (br2 == 0xC3600000U &&
730 + ldq == 0xA77B000CU &&
731 + nop == 0x47FF041FU &&
732 + jmp == 0x6B7B0000U)
733 + {
734 + regs->r28 = regs->pc+4;
735 + regs->r27 = addr+16;
736 + regs->pc = resolver;
737 + return 3;
738 + }
739 + }
740 + } while (0);
741 +#endif
742 +
743 + return 1;
744 +}
745 +
746 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
747 +{
748 + unsigned long i;
749 +
750 + printk(KERN_ERR "PAX: bytes at PC: ");
751 + for (i = 0; i < 5; i++) {
752 + unsigned int c;
753 + if (get_user(c, (unsigned int *)pc+i))
754 + printk(KERN_CONT "???????? ");
755 + else
756 + printk(KERN_CONT "%08x ", c);
757 + }
758 + printk("\n");
759 +}
760 +#endif
761
762 /*
763 * This routine handles page faults. It determines the address,
764 @@ -133,8 +251,29 @@ retry:
765 good_area:
766 si_code = SEGV_ACCERR;
767 if (cause < 0) {
768 - if (!(vma->vm_flags & VM_EXEC))
769 + if (!(vma->vm_flags & VM_EXEC)) {
770 +
771 +#ifdef CONFIG_PAX_PAGEEXEC
772 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
773 + goto bad_area;
774 +
775 + up_read(&mm->mmap_sem);
776 + switch (pax_handle_fetch_fault(regs)) {
777 +
778 +#ifdef CONFIG_PAX_EMUPLT
779 + case 2:
780 + case 3:
781 + return;
782 +#endif
783 +
784 + }
785 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
786 + do_group_exit(SIGKILL);
787 +#else
788 goto bad_area;
789 +#endif
790 +
791 + }
792 } else if (!cause) {
793 /* Allow reads even for write-only mappings */
794 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
795 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
796 index c79f61f..9ac0642 100644
797 --- a/arch/arm/include/asm/atomic.h
798 +++ b/arch/arm/include/asm/atomic.h
799 @@ -17,17 +17,35 @@
800 #include <asm/barrier.h>
801 #include <asm/cmpxchg.h>
802
803 +#ifdef CONFIG_GENERIC_ATOMIC64
804 +#include <asm-generic/atomic64.h>
805 +#endif
806 +
807 #define ATOMIC_INIT(i) { (i) }
808
809 #ifdef __KERNEL__
810
811 +#define _ASM_EXTABLE(from, to) \
812 +" .pushsection __ex_table,\"a\"\n"\
813 +" .align 3\n" \
814 +" .long " #from ", " #to"\n" \
815 +" .popsection"
816 +
817 /*
818 * On ARM, ordinary assignment (str instruction) doesn't clear the local
819 * strex/ldrex monitor on some implementations. The reason we can use it for
820 * atomic_set() is the clrex or dummy strex done on every exception return.
821 */
822 #define atomic_read(v) (*(volatile int *)&(v)->counter)
823 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
824 +{
825 + return v->counter;
826 +}
827 #define atomic_set(v,i) (((v)->counter) = (i))
828 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
829 +{
830 + v->counter = i;
831 +}
832
833 #if __LINUX_ARM_ARCH__ >= 6
834
835 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
836 int result;
837
838 __asm__ __volatile__("@ atomic_add\n"
839 +"1: ldrex %1, [%3]\n"
840 +" adds %0, %1, %4\n"
841 +
842 +#ifdef CONFIG_PAX_REFCOUNT
843 +" bvc 3f\n"
844 +"2: bkpt 0xf103\n"
845 +"3:\n"
846 +#endif
847 +
848 +" strex %1, %0, [%3]\n"
849 +" teq %1, #0\n"
850 +" bne 1b"
851 +
852 +#ifdef CONFIG_PAX_REFCOUNT
853 +"\n4:\n"
854 + _ASM_EXTABLE(2b, 4b)
855 +#endif
856 +
857 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
858 + : "r" (&v->counter), "Ir" (i)
859 + : "cc");
860 +}
861 +
862 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
863 +{
864 + unsigned long tmp;
865 + int result;
866 +
867 + __asm__ __volatile__("@ atomic_add_unchecked\n"
868 "1: ldrex %0, [%3]\n"
869 " add %0, %0, %4\n"
870 " strex %1, %0, [%3]\n"
871 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
872 smp_mb();
873
874 __asm__ __volatile__("@ atomic_add_return\n"
875 +"1: ldrex %1, [%3]\n"
876 +" adds %0, %1, %4\n"
877 +
878 +#ifdef CONFIG_PAX_REFCOUNT
879 +" bvc 3f\n"
880 +" mov %0, %1\n"
881 +"2: bkpt 0xf103\n"
882 +"3:\n"
883 +#endif
884 +
885 +" strex %1, %0, [%3]\n"
886 +" teq %1, #0\n"
887 +" bne 1b"
888 +
889 +#ifdef CONFIG_PAX_REFCOUNT
890 +"\n4:\n"
891 + _ASM_EXTABLE(2b, 4b)
892 +#endif
893 +
894 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
895 + : "r" (&v->counter), "Ir" (i)
896 + : "cc");
897 +
898 + smp_mb();
899 +
900 + return result;
901 +}
902 +
903 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
904 +{
905 + unsigned long tmp;
906 + int result;
907 +
908 + smp_mb();
909 +
910 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
911 "1: ldrex %0, [%3]\n"
912 " add %0, %0, %4\n"
913 " strex %1, %0, [%3]\n"
914 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
915 int result;
916
917 __asm__ __volatile__("@ atomic_sub\n"
918 +"1: ldrex %1, [%3]\n"
919 +" subs %0, %1, %4\n"
920 +
921 +#ifdef CONFIG_PAX_REFCOUNT
922 +" bvc 3f\n"
923 +"2: bkpt 0xf103\n"
924 +"3:\n"
925 +#endif
926 +
927 +" strex %1, %0, [%3]\n"
928 +" teq %1, #0\n"
929 +" bne 1b"
930 +
931 +#ifdef CONFIG_PAX_REFCOUNT
932 +"\n4:\n"
933 + _ASM_EXTABLE(2b, 4b)
934 +#endif
935 +
936 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
937 + : "r" (&v->counter), "Ir" (i)
938 + : "cc");
939 +}
940 +
941 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
942 +{
943 + unsigned long tmp;
944 + int result;
945 +
946 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
947 "1: ldrex %0, [%3]\n"
948 " sub %0, %0, %4\n"
949 " strex %1, %0, [%3]\n"
950 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
951 smp_mb();
952
953 __asm__ __volatile__("@ atomic_sub_return\n"
954 -"1: ldrex %0, [%3]\n"
955 -" sub %0, %0, %4\n"
956 +"1: ldrex %1, [%3]\n"
957 +" subs %0, %1, %4\n"
958 +
959 +#ifdef CONFIG_PAX_REFCOUNT
960 +" bvc 3f\n"
961 +" mov %0, %1\n"
962 +"2: bkpt 0xf103\n"
963 +"3:\n"
964 +#endif
965 +
966 " strex %1, %0, [%3]\n"
967 " teq %1, #0\n"
968 " bne 1b"
969 +
970 +#ifdef CONFIG_PAX_REFCOUNT
971 +"\n4:\n"
972 + _ASM_EXTABLE(2b, 4b)
973 +#endif
974 +
975 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
976 : "r" (&v->counter), "Ir" (i)
977 : "cc");
978 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
979 return oldval;
980 }
981
982 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
983 +{
984 + unsigned long oldval, res;
985 +
986 + smp_mb();
987 +
988 + do {
989 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
990 + "ldrex %1, [%3]\n"
991 + "mov %0, #0\n"
992 + "teq %1, %4\n"
993 + "strexeq %0, %5, [%3]\n"
994 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
995 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
996 + : "cc");
997 + } while (res);
998 +
999 + smp_mb();
1000 +
1001 + return oldval;
1002 +}
1003 +
1004 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1005 {
1006 unsigned long tmp, tmp2;
1007 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1008
1009 return val;
1010 }
1011 +
1012 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1013 +{
1014 + return atomic_add_return(i, v);
1015 +}
1016 +
1017 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1018 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1019 +{
1020 + (void) atomic_add_return(i, v);
1021 +}
1022
1023 static inline int atomic_sub_return(int i, atomic_t *v)
1024 {
1025 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1026 return val;
1027 }
1028 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1029 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1030 +{
1031 + (void) atomic_sub_return(i, v);
1032 +}
1033
1034 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1035 {
1036 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1037 return ret;
1038 }
1039
1040 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1041 +{
1042 + return atomic_cmpxchg(v, old, new);
1043 +}
1044 +
1045 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1046 {
1047 unsigned long flags;
1048 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1049 #endif /* __LINUX_ARM_ARCH__ */
1050
1051 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1052 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1053 +{
1054 + return xchg(&v->counter, new);
1055 +}
1056
1057 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1058 {
1059 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1060 }
1061
1062 #define atomic_inc(v) atomic_add(1, v)
1063 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1064 +{
1065 + atomic_add_unchecked(1, v);
1066 +}
1067 #define atomic_dec(v) atomic_sub(1, v)
1068 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1069 +{
1070 + atomic_sub_unchecked(1, v);
1071 +}
1072
1073 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1074 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1075 +{
1076 + return atomic_add_return_unchecked(1, v) == 0;
1077 +}
1078 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1079 #define atomic_inc_return(v) (atomic_add_return(1, v))
1080 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1081 +{
1082 + return atomic_add_return_unchecked(1, v);
1083 +}
1084 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1085 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1086
1087 @@ -241,6 +428,14 @@ typedef struct {
1088 u64 __aligned(8) counter;
1089 } atomic64_t;
1090
1091 +#ifdef CONFIG_PAX_REFCOUNT
1092 +typedef struct {
1093 + u64 __aligned(8) counter;
1094 +} atomic64_unchecked_t;
1095 +#else
1096 +typedef atomic64_t atomic64_unchecked_t;
1097 +#endif
1098 +
1099 #define ATOMIC64_INIT(i) { (i) }
1100
1101 static inline u64 atomic64_read(const atomic64_t *v)
1102 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1103 return result;
1104 }
1105
1106 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1107 +{
1108 + u64 result;
1109 +
1110 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1111 +" ldrexd %0, %H0, [%1]"
1112 + : "=&r" (result)
1113 + : "r" (&v->counter), "Qo" (v->counter)
1114 + );
1115 +
1116 + return result;
1117 +}
1118 +
1119 static inline void atomic64_set(atomic64_t *v, u64 i)
1120 {
1121 u64 tmp;
1122 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1123 : "cc");
1124 }
1125
1126 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1127 +{
1128 + u64 tmp;
1129 +
1130 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1131 +"1: ldrexd %0, %H0, [%2]\n"
1132 +" strexd %0, %3, %H3, [%2]\n"
1133 +" teq %0, #0\n"
1134 +" bne 1b"
1135 + : "=&r" (tmp), "=Qo" (v->counter)
1136 + : "r" (&v->counter), "r" (i)
1137 + : "cc");
1138 +}
1139 +
1140 static inline void atomic64_add(u64 i, atomic64_t *v)
1141 {
1142 u64 result;
1143 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1144 __asm__ __volatile__("@ atomic64_add\n"
1145 "1: ldrexd %0, %H0, [%3]\n"
1146 " adds %0, %0, %4\n"
1147 +" adcs %H0, %H0, %H4\n"
1148 +
1149 +#ifdef CONFIG_PAX_REFCOUNT
1150 +" bvc 3f\n"
1151 +"2: bkpt 0xf103\n"
1152 +"3:\n"
1153 +#endif
1154 +
1155 +" strexd %1, %0, %H0, [%3]\n"
1156 +" teq %1, #0\n"
1157 +" bne 1b"
1158 +
1159 +#ifdef CONFIG_PAX_REFCOUNT
1160 +"\n4:\n"
1161 + _ASM_EXTABLE(2b, 4b)
1162 +#endif
1163 +
1164 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1165 + : "r" (&v->counter), "r" (i)
1166 + : "cc");
1167 +}
1168 +
1169 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1170 +{
1171 + u64 result;
1172 + unsigned long tmp;
1173 +
1174 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1175 +"1: ldrexd %0, %H0, [%3]\n"
1176 +" adds %0, %0, %4\n"
1177 " adc %H0, %H0, %H4\n"
1178 " strexd %1, %0, %H0, [%3]\n"
1179 " teq %1, #0\n"
1180 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1181
1182 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1183 {
1184 - u64 result;
1185 - unsigned long tmp;
1186 + u64 result, tmp;
1187
1188 smp_mb();
1189
1190 __asm__ __volatile__("@ atomic64_add_return\n"
1191 +"1: ldrexd %1, %H1, [%3]\n"
1192 +" adds %0, %1, %4\n"
1193 +" adcs %H0, %H1, %H4\n"
1194 +
1195 +#ifdef CONFIG_PAX_REFCOUNT
1196 +" bvc 3f\n"
1197 +" mov %0, %1\n"
1198 +" mov %H0, %H1\n"
1199 +"2: bkpt 0xf103\n"
1200 +"3:\n"
1201 +#endif
1202 +
1203 +" strexd %1, %0, %H0, [%3]\n"
1204 +" teq %1, #0\n"
1205 +" bne 1b"
1206 +
1207 +#ifdef CONFIG_PAX_REFCOUNT
1208 +"\n4:\n"
1209 + _ASM_EXTABLE(2b, 4b)
1210 +#endif
1211 +
1212 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1213 + : "r" (&v->counter), "r" (i)
1214 + : "cc");
1215 +
1216 + smp_mb();
1217 +
1218 + return result;
1219 +}
1220 +
1221 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1222 +{
1223 + u64 result;
1224 + unsigned long tmp;
1225 +
1226 + smp_mb();
1227 +
1228 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1229 "1: ldrexd %0, %H0, [%3]\n"
1230 " adds %0, %0, %4\n"
1231 " adc %H0, %H0, %H4\n"
1232 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1233 __asm__ __volatile__("@ atomic64_sub\n"
1234 "1: ldrexd %0, %H0, [%3]\n"
1235 " subs %0, %0, %4\n"
1236 +" sbcs %H0, %H0, %H4\n"
1237 +
1238 +#ifdef CONFIG_PAX_REFCOUNT
1239 +" bvc 3f\n"
1240 +"2: bkpt 0xf103\n"
1241 +"3:\n"
1242 +#endif
1243 +
1244 +" strexd %1, %0, %H0, [%3]\n"
1245 +" teq %1, #0\n"
1246 +" bne 1b"
1247 +
1248 +#ifdef CONFIG_PAX_REFCOUNT
1249 +"\n4:\n"
1250 + _ASM_EXTABLE(2b, 4b)
1251 +#endif
1252 +
1253 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1254 + : "r" (&v->counter), "r" (i)
1255 + : "cc");
1256 +}
1257 +
1258 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1259 +{
1260 + u64 result;
1261 + unsigned long tmp;
1262 +
1263 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1264 +"1: ldrexd %0, %H0, [%3]\n"
1265 +" subs %0, %0, %4\n"
1266 " sbc %H0, %H0, %H4\n"
1267 " strexd %1, %0, %H0, [%3]\n"
1268 " teq %1, #0\n"
1269 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1270
1271 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1272 {
1273 - u64 result;
1274 - unsigned long tmp;
1275 + u64 result, tmp;
1276
1277 smp_mb();
1278
1279 __asm__ __volatile__("@ atomic64_sub_return\n"
1280 -"1: ldrexd %0, %H0, [%3]\n"
1281 -" subs %0, %0, %4\n"
1282 -" sbc %H0, %H0, %H4\n"
1283 +"1: ldrexd %1, %H1, [%3]\n"
1284 +" subs %0, %1, %4\n"
1285 +" sbcs %H0, %H1, %H4\n"
1286 +
1287 +#ifdef CONFIG_PAX_REFCOUNT
1288 +" bvc 3f\n"
1289 +" mov %0, %1\n"
1290 +" mov %H0, %H1\n"
1291 +"2: bkpt 0xf103\n"
1292 +"3:\n"
1293 +#endif
1294 +
1295 " strexd %1, %0, %H0, [%3]\n"
1296 " teq %1, #0\n"
1297 " bne 1b"
1298 +
1299 +#ifdef CONFIG_PAX_REFCOUNT
1300 +"\n4:\n"
1301 + _ASM_EXTABLE(2b, 4b)
1302 +#endif
1303 +
1304 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1305 : "r" (&v->counter), "r" (i)
1306 : "cc");
1307 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1308 return oldval;
1309 }
1310
1311 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1312 +{
1313 + u64 oldval;
1314 + unsigned long res;
1315 +
1316 + smp_mb();
1317 +
1318 + do {
1319 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1320 + "ldrexd %1, %H1, [%3]\n"
1321 + "mov %0, #0\n"
1322 + "teq %1, %4\n"
1323 + "teqeq %H1, %H4\n"
1324 + "strexdeq %0, %5, %H5, [%3]"
1325 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1326 + : "r" (&ptr->counter), "r" (old), "r" (new)
1327 + : "cc");
1328 + } while (res);
1329 +
1330 + smp_mb();
1331 +
1332 + return oldval;
1333 +}
1334 +
1335 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1336 {
1337 u64 result;
1338 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1339
1340 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1341 {
1342 - u64 result;
1343 - unsigned long tmp;
1344 + u64 result, tmp;
1345
1346 smp_mb();
1347
1348 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1349 -"1: ldrexd %0, %H0, [%3]\n"
1350 -" subs %0, %0, #1\n"
1351 -" sbc %H0, %H0, #0\n"
1352 +"1: ldrexd %1, %H1, [%3]\n"
1353 +" subs %0, %1, #1\n"
1354 +" sbcs %H0, %H1, #0\n"
1355 +
1356 +#ifdef CONFIG_PAX_REFCOUNT
1357 +" bvc 3f\n"
1358 +" mov %0, %1\n"
1359 +" mov %H0, %H1\n"
1360 +"2: bkpt 0xf103\n"
1361 +"3:\n"
1362 +#endif
1363 +
1364 " teq %H0, #0\n"
1365 -" bmi 2f\n"
1366 +" bmi 4f\n"
1367 " strexd %1, %0, %H0, [%3]\n"
1368 " teq %1, #0\n"
1369 " bne 1b\n"
1370 -"2:"
1371 +"4:\n"
1372 +
1373 +#ifdef CONFIG_PAX_REFCOUNT
1374 + _ASM_EXTABLE(2b, 4b)
1375 +#endif
1376 +
1377 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1378 : "r" (&v->counter)
1379 : "cc");
1380 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1381 " teq %0, %5\n"
1382 " teqeq %H0, %H5\n"
1383 " moveq %1, #0\n"
1384 -" beq 2f\n"
1385 +" beq 4f\n"
1386 " adds %0, %0, %6\n"
1387 -" adc %H0, %H0, %H6\n"
1388 +" adcs %H0, %H0, %H6\n"
1389 +
1390 +#ifdef CONFIG_PAX_REFCOUNT
1391 +" bvc 3f\n"
1392 +"2: bkpt 0xf103\n"
1393 +"3:\n"
1394 +#endif
1395 +
1396 " strexd %2, %0, %H0, [%4]\n"
1397 " teq %2, #0\n"
1398 " bne 1b\n"
1399 -"2:"
1400 +"4:\n"
1401 +
1402 +#ifdef CONFIG_PAX_REFCOUNT
1403 + _ASM_EXTABLE(2b, 4b)
1404 +#endif
1405 +
1406 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1407 : "r" (&v->counter), "r" (u), "r" (a)
1408 : "cc");
1409 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1410
1411 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1412 #define atomic64_inc(v) atomic64_add(1LL, (v))
1413 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1414 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1415 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1416 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1417 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1418 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1419 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1420 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1421 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1422 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1423 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1424 index 75fe66b..ba3dee4 100644
1425 --- a/arch/arm/include/asm/cache.h
1426 +++ b/arch/arm/include/asm/cache.h
1427 @@ -4,8 +4,10 @@
1428 #ifndef __ASMARM_CACHE_H
1429 #define __ASMARM_CACHE_H
1430
1431 +#include <linux/const.h>
1432 +
1433 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1434 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1435 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1436
1437 /*
1438 * Memory returned by kmalloc() may be used for DMA, so we must make
1439 @@ -24,5 +26,6 @@
1440 #endif
1441
1442 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1443 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1444
1445 #endif
1446 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1447 index e1489c5..d418304 100644
1448 --- a/arch/arm/include/asm/cacheflush.h
1449 +++ b/arch/arm/include/asm/cacheflush.h
1450 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1451 void (*dma_unmap_area)(const void *, size_t, int);
1452
1453 void (*dma_flush_range)(const void *, const void *);
1454 -};
1455 +} __no_const;
1456
1457 /*
1458 * Select the calling method
1459 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1460 index 7eb18c1..e38b6d2 100644
1461 --- a/arch/arm/include/asm/cmpxchg.h
1462 +++ b/arch/arm/include/asm/cmpxchg.h
1463 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1464
1465 #define xchg(ptr,x) \
1466 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1467 +#define xchg_unchecked(ptr,x) \
1468 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1469
1470 #include <asm-generic/cmpxchg-local.h>
1471
1472 diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1473 index ab98fdd..6b19938 100644
1474 --- a/arch/arm/include/asm/delay.h
1475 +++ b/arch/arm/include/asm/delay.h
1476 @@ -24,9 +24,9 @@ extern struct arm_delay_ops {
1477 void (*delay)(unsigned long);
1478 void (*const_udelay)(unsigned long);
1479 void (*udelay)(unsigned long);
1480 -} arm_delay_ops;
1481 +} *arm_delay_ops;
1482
1483 -#define __delay(n) arm_delay_ops.delay(n)
1484 +#define __delay(n) arm_delay_ops->delay(n)
1485
1486 /*
1487 * This function intentionally does not exist; if you see references to
1488 @@ -47,8 +47,8 @@ extern void __bad_udelay(void);
1489 * first constant multiplications gets optimized away if the delay is
1490 * a constant)
1491 */
1492 -#define __udelay(n) arm_delay_ops.udelay(n)
1493 -#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1494 +#define __udelay(n) arm_delay_ops->udelay(n)
1495 +#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1496
1497 #define udelay(n) \
1498 (__builtin_constant_p(n) ? \
1499 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1500 index 38050b1..9d90e8b 100644
1501 --- a/arch/arm/include/asm/elf.h
1502 +++ b/arch/arm/include/asm/elf.h
1503 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1504 the loader. We need to make sure that it is out of the way of the program
1505 that it will "exec", and that there is sufficient room for the brk. */
1506
1507 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1508 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1509 +
1510 +#ifdef CONFIG_PAX_ASLR
1511 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1512 +
1513 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1514 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1515 +#endif
1516
1517 /* When the program starts, a1 contains a pointer to a function to be
1518 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1519 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1520 extern void elf_set_personality(const struct elf32_hdr *);
1521 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1522
1523 -struct mm_struct;
1524 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1525 -#define arch_randomize_brk arch_randomize_brk
1526 -
1527 #endif
1528 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1529 index 83eb2f7..ed77159 100644
1530 --- a/arch/arm/include/asm/kmap_types.h
1531 +++ b/arch/arm/include/asm/kmap_types.h
1532 @@ -4,6 +4,6 @@
1533 /*
1534 * This is the "bare minimum". AIO seems to require this.
1535 */
1536 -#define KM_TYPE_NR 16
1537 +#define KM_TYPE_NR 17
1538
1539 #endif
1540 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1541 index 9e614a1..3302cca 100644
1542 --- a/arch/arm/include/asm/mach/dma.h
1543 +++ b/arch/arm/include/asm/mach/dma.h
1544 @@ -22,7 +22,7 @@ struct dma_ops {
1545 int (*residue)(unsigned int, dma_t *); /* optional */
1546 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1547 const char *type;
1548 -};
1549 +} __do_const;
1550
1551 struct dma_struct {
1552 void *addr; /* single DMA address */
1553 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1554 index 195ac2f..2272f0d 100644
1555 --- a/arch/arm/include/asm/mach/map.h
1556 +++ b/arch/arm/include/asm/mach/map.h
1557 @@ -34,6 +34,9 @@ struct map_desc {
1558 #define MT_MEMORY_ITCM 13
1559 #define MT_MEMORY_SO 14
1560 #define MT_MEMORY_DMA_READY 15
1561 +#define MT_MEMORY_R 16
1562 +#define MT_MEMORY_RW 17
1563 +#define MT_MEMORY_RX 18
1564
1565 #ifdef CONFIG_MMU
1566 extern void iotable_init(struct map_desc *, int);
1567 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1568 index 53426c6..c7baff3 100644
1569 --- a/arch/arm/include/asm/outercache.h
1570 +++ b/arch/arm/include/asm/outercache.h
1571 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1572 #endif
1573 void (*set_debug)(unsigned long);
1574 void (*resume)(void);
1575 -};
1576 +} __no_const;
1577
1578 #ifdef CONFIG_OUTER_CACHE
1579
1580 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1581 index 812a494..71fc0b6 100644
1582 --- a/arch/arm/include/asm/page.h
1583 +++ b/arch/arm/include/asm/page.h
1584 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1585 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1586 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1587 unsigned long vaddr, struct vm_area_struct *vma);
1588 -};
1589 +} __no_const;
1590
1591 #ifdef MULTI_USER
1592 extern struct cpu_user_fns cpu_user;
1593 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1594 index 943504f..84d0f84 100644
1595 --- a/arch/arm/include/asm/pgalloc.h
1596 +++ b/arch/arm/include/asm/pgalloc.h
1597 @@ -17,6 +17,7 @@
1598 #include <asm/processor.h>
1599 #include <asm/cacheflush.h>
1600 #include <asm/tlbflush.h>
1601 +#include <asm/system_info.h>
1602
1603 #define check_pgt_cache() do { } while (0)
1604
1605 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1606 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1607 }
1608
1609 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1610 +{
1611 + pud_populate(mm, pud, pmd);
1612 +}
1613 +
1614 #else /* !CONFIG_ARM_LPAE */
1615
1616 /*
1617 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1618 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1619 #define pmd_free(mm, pmd) do { } while (0)
1620 #define pud_populate(mm,pmd,pte) BUG()
1621 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1622
1623 #endif /* CONFIG_ARM_LPAE */
1624
1625 @@ -126,6 +133,16 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1626 __free_page(pte);
1627 }
1628
1629 +static inline void __pmd_update(pmd_t *pmdp, pmdval_t prot)
1630 +{
1631 + pmdval_t pmdval = pmd_val(*pmdp) | prot;
1632 + pmdp[0] = __pmd(pmdval);
1633 +#ifndef CONFIG_ARM_LPAE
1634 + pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
1635 +#endif
1636 + flush_pmd_entry(pmdp);
1637 +}
1638 +
1639 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1640 pmdval_t prot)
1641 {
1642 @@ -155,7 +172,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1643 static inline void
1644 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1645 {
1646 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1647 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1648 }
1649 #define pmd_pgtable(pmd) pmd_page(pmd)
1650
1651 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1652 index 5cfba15..d437dc2 100644
1653 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1654 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1655 @@ -20,12 +20,15 @@
1656 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1657 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1658 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1659 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* PXN */
1660 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1661 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1662 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1663 +
1664 /*
1665 * - section
1666 */
1667 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0)
1668 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1669 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1670 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1671 @@ -37,6 +40,7 @@
1672 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1673 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1674 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1675 +#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 0))
1676
1677 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1678 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1679 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1680 index 2317a71..1897391 100644
1681 --- a/arch/arm/include/asm/pgtable-2level.h
1682 +++ b/arch/arm/include/asm/pgtable-2level.h
1683 @@ -123,6 +123,7 @@
1684 #define L_PTE_USER (_AT(pteval_t, 1) << 8)
1685 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1686 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1687 +#define L_PTE_PXN (_AT(pteval_t, 1) << 11) /* v7*/
1688
1689 /*
1690 * These are the memory types, defined to be compatible with
1691 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1692 index d795282..d82ff13 100644
1693 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1694 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1695 @@ -32,6 +32,7 @@
1696 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1697 #define PMD_BIT4 (_AT(pmdval_t, 0))
1698 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1699 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1700
1701 /*
1702 * - section
1703 @@ -41,9 +42,11 @@
1704 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1705 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1706 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1707 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1708 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1709 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1710 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1711 +#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 1) << 7)
1712 #define PMD_SECT_TEX(x) (_AT(pmdval_t, 0))
1713
1714 /*
1715 @@ -66,6 +69,7 @@
1716 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1717 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1718 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1719 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1720 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1721
1722 /*
1723 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1724 index b249035..4ab204b 100644
1725 --- a/arch/arm/include/asm/pgtable-3level.h
1726 +++ b/arch/arm/include/asm/pgtable-3level.h
1727 @@ -73,6 +73,7 @@
1728 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1729 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1730 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1731 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1732 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1733 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1734 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1735 @@ -80,6 +81,7 @@
1736 /*
1737 * To be used in assembly code with the upper page attributes.
1738 */
1739 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
1740 #define L_PTE_XN_HIGH (1 << (54 - 32))
1741 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1742
1743 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1744 index 08c1231..1031bb4 100644
1745 --- a/arch/arm/include/asm/pgtable.h
1746 +++ b/arch/arm/include/asm/pgtable.h
1747 @@ -30,6 +30,9 @@
1748 #include <asm/pgtable-2level.h>
1749 #endif
1750
1751 +#define ktla_ktva(addr) (addr)
1752 +#define ktva_ktla(addr) (addr)
1753 +
1754 /*
1755 * Just any arbitrary offset to the start of the vmalloc VM area: the
1756 * current 8MB value just means that there will be a 8MB "hole" after the
1757 @@ -45,6 +48,9 @@
1758 #define LIBRARY_TEXT_START 0x0c000000
1759
1760 #ifndef __ASSEMBLY__
1761 +extern pteval_t __supported_pte_mask;
1762 +extern pmdval_t __supported_pmd_mask;
1763 +
1764 extern void __pte_error(const char *file, int line, pte_t);
1765 extern void __pmd_error(const char *file, int line, pmd_t);
1766 extern void __pgd_error(const char *file, int line, pgd_t);
1767 @@ -53,6 +59,17 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1768 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1769 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1770
1771 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
1772 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1773 +
1774 +#ifdef CONFIG_PAX_KERNEXEC
1775 +static inline unsigned long pax_open_kernel(void) { return 0; /* TODO */ }
1776 +static inline unsigned long pax_close_kernel(void) { return 0; /* TODO */ }
1777 +#else
1778 +static inline unsigned long pax_open_kernel(void) { return 0; }
1779 +static inline unsigned long pax_close_kernel(void) { return 0; }
1780 +#endif
1781 +
1782 /*
1783 * This is the lowest virtual address we can permit any user space
1784 * mapping to be mapped at. This is particularly important for
1785 @@ -63,8 +80,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1786 /*
1787 * The pgprot_* and protection_map entries will be fixed up in runtime
1788 * to include the cachable and bufferable bits based on memory policy,
1789 - * as well as any architecture dependent bits like global/ASID and SMP
1790 - * shared mapping bits.
1791 + * as well as any architecture dependent bits like global/ASID, PXN,
1792 + * and SMP shared mapping bits.
1793 */
1794 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
1795
1796 @@ -242,7 +259,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
1797
1798 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
1799 {
1800 - const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER;
1801 + const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | __supported_pte_mask;
1802 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
1803 return pte;
1804 }
1805 diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
1806 index f3628fb..a0672dd 100644
1807 --- a/arch/arm/include/asm/proc-fns.h
1808 +++ b/arch/arm/include/asm/proc-fns.h
1809 @@ -75,7 +75,7 @@ extern struct processor {
1810 unsigned int suspend_size;
1811 void (*do_suspend)(void *);
1812 void (*do_resume)(void *);
1813 -} processor;
1814 +} __do_const processor;
1815
1816 #ifndef MULTI_CPU
1817 extern void cpu_proc_init(void);
1818 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
1819 index 2e3be16..4dc90fc 100644
1820 --- a/arch/arm/include/asm/smp.h
1821 +++ b/arch/arm/include/asm/smp.h
1822 @@ -106,7 +106,7 @@ struct smp_operations {
1823 int (*cpu_disable)(unsigned int cpu);
1824 #endif
1825 #endif
1826 -};
1827 +} __no_const;
1828
1829 /*
1830 * set platform specific SMP operations
1831 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1832 index 8477b4c..801a6a9 100644
1833 --- a/arch/arm/include/asm/thread_info.h
1834 +++ b/arch/arm/include/asm/thread_info.h
1835 @@ -151,6 +151,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1836 #define TIF_SYSCALL_TRACE 8
1837 #define TIF_SYSCALL_AUDIT 9
1838 #define TIF_SYSCALL_TRACEPOINT 10
1839 +
1840 +/* within 8 bits of TIF_SYSCALL_TRACE
1841 + to meet flexible second operand requirements
1842 +*/
1843 +#define TIF_GRSEC_SETXID 11
1844 +
1845 #define TIF_USING_IWMMXT 17
1846 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1847 #define TIF_RESTORE_SIGMASK 20
1848 @@ -165,9 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1849 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
1850 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1851 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1852 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1853
1854 /* Checks for any syscall work in entry-common.S */
1855 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
1856 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | \
1857 + _TIF_GRSEC_SETXID)
1858
1859 /*
1860 * Change these and you break ASM code in entry-common.S
1861 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1862 index 7e1f760..f2c37b1 100644
1863 --- a/arch/arm/include/asm/uaccess.h
1864 +++ b/arch/arm/include/asm/uaccess.h
1865 @@ -418,8 +418,23 @@ do { \
1866
1867
1868 #ifdef CONFIG_MMU
1869 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1870 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1871 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1872 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1873 +
1874 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1875 +{
1876 + check_object_size(to, n, false);
1877 +
1878 + return ___copy_from_user(to, from, n);
1879 +}
1880 +
1881 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1882 +{
1883 + check_object_size(from, n, true);
1884 +
1885 + return ___copy_to_user(to, from, n);
1886 +}
1887 +
1888 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1889 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1890 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1891 @@ -431,6 +446,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1892
1893 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1894 {
1895 + if ((long)n < 0)
1896 + return n;
1897 +
1898 if (access_ok(VERIFY_READ, from, n))
1899 n = __copy_from_user(to, from, n);
1900 else /* security hole - plug it */
1901 @@ -440,6 +458,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1902
1903 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1904 {
1905 + if ((long)n < 0)
1906 + return n;
1907 +
1908 if (access_ok(VERIFY_WRITE, to, n))
1909 n = __copy_to_user(to, from, n);
1910 return n;
1911 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
1912 index 96ee092..37f1844 100644
1913 --- a/arch/arm/include/uapi/asm/ptrace.h
1914 +++ b/arch/arm/include/uapi/asm/ptrace.h
1915 @@ -73,7 +73,7 @@
1916 * ARMv7 groups of PSR bits
1917 */
1918 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
1919 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
1920 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
1921 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
1922 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
1923
1924 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1925 index 60d3b73..9168db0 100644
1926 --- a/arch/arm/kernel/armksyms.c
1927 +++ b/arch/arm/kernel/armksyms.c
1928 @@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1929 #ifdef CONFIG_MMU
1930 EXPORT_SYMBOL(copy_page);
1931
1932 -EXPORT_SYMBOL(__copy_from_user);
1933 -EXPORT_SYMBOL(__copy_to_user);
1934 +EXPORT_SYMBOL(___copy_from_user);
1935 +EXPORT_SYMBOL(___copy_to_user);
1936 EXPORT_SYMBOL(__clear_user);
1937
1938 EXPORT_SYMBOL(__get_user_1);
1939 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
1940 index 486a15a..d95523a 100644
1941 --- a/arch/arm/kernel/head.S
1942 +++ b/arch/arm/kernel/head.S
1943 @@ -52,7 +52,9 @@
1944 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
1945
1946 .macro pgtbl, rd, phys
1947 - add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
1948 + mov \rd, #TEXT_OFFSET
1949 + sub \rd, #PG_DIR_SIZE
1950 + add \rd, \rd, \phys
1951 .endm
1952
1953 /*
1954 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
1955 index 1e9be5d..03edbc2 100644
1956 --- a/arch/arm/kernel/module.c
1957 +++ b/arch/arm/kernel/module.c
1958 @@ -37,12 +37,37 @@
1959 #endif
1960
1961 #ifdef CONFIG_MMU
1962 -void *module_alloc(unsigned long size)
1963 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
1964 {
1965 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
1966 + return NULL;
1967 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
1968 - GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
1969 + GFP_KERNEL, prot, -1,
1970 __builtin_return_address(0));
1971 }
1972 +
1973 +void *module_alloc(unsigned long size)
1974 +{
1975 +
1976 +#ifdef CONFIG_PAX_KERNEXEC
1977 + return __module_alloc(size, PAGE_KERNEL);
1978 +#else
1979 + return __module_alloc(size, PAGE_KERNEL_EXEC);
1980 +#endif
1981 +
1982 +}
1983 +
1984 +#ifdef CONFIG_PAX_KERNEXEC
1985 +void module_free_exec(struct module *mod, void *module_region)
1986 +{
1987 + module_free(mod, module_region);
1988 +}
1989 +
1990 +void *module_alloc_exec(unsigned long size)
1991 +{
1992 + return __module_alloc(size, PAGE_KERNEL_EXEC);
1993 +}
1994 +#endif
1995 #endif
1996
1997 int
1998 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1999 index 90084a6..a8b26bc 100644
2000 --- a/arch/arm/kernel/process.c
2001 +++ b/arch/arm/kernel/process.c
2002 @@ -28,7 +28,6 @@
2003 #include <linux/tick.h>
2004 #include <linux/utsname.h>
2005 #include <linux/uaccess.h>
2006 -#include <linux/random.h>
2007 #include <linux/hw_breakpoint.h>
2008 #include <linux/cpuidle.h>
2009 #include <linux/leds.h>
2010 @@ -256,9 +255,10 @@ void machine_power_off(void)
2011 machine_shutdown();
2012 if (pm_power_off)
2013 pm_power_off();
2014 + BUG();
2015 }
2016
2017 -void machine_restart(char *cmd)
2018 +__noreturn void machine_restart(char *cmd)
2019 {
2020 machine_shutdown();
2021
2022 @@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2023 init_utsname()->release,
2024 (int)strcspn(init_utsname()->version, " "),
2025 init_utsname()->version);
2026 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2027 - print_symbol("LR is at %s\n", regs->ARM_lr);
2028 + printk("PC is at %pA\n", instruction_pointer(regs));
2029 + printk("LR is at %pA\n", regs->ARM_lr);
2030 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2031 "sp : %08lx ip : %08lx fp : %08lx\n",
2032 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2033 @@ -451,12 +451,6 @@ unsigned long get_wchan(struct task_struct *p)
2034 return 0;
2035 }
2036
2037 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2038 -{
2039 - unsigned long range_end = mm->brk + 0x02000000;
2040 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2041 -}
2042 -
2043 #ifdef CONFIG_MMU
2044 /*
2045 * The vectors page is always readable from user space for the
2046 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2047 index 739db3a..7f4a272 100644
2048 --- a/arch/arm/kernel/ptrace.c
2049 +++ b/arch/arm/kernel/ptrace.c
2050 @@ -916,6 +916,10 @@ enum ptrace_syscall_dir {
2051 PTRACE_SYSCALL_EXIT,
2052 };
2053
2054 +#ifdef CONFIG_GRKERNSEC_SETXID
2055 +extern void gr_delayed_cred_worker(void);
2056 +#endif
2057 +
2058 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2059 enum ptrace_syscall_dir dir)
2060 {
2061 @@ -923,6 +927,11 @@ static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2062
2063 current_thread_info()->syscall = scno;
2064
2065 +#ifdef CONFIG_GRKERNSEC_SETXID
2066 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2067 + gr_delayed_cred_worker();
2068 +#endif
2069 +
2070 if (!test_thread_flag(TIF_SYSCALL_TRACE))
2071 return scno;
2072
2073 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2074 index da1d1aa..ef9bc58 100644
2075 --- a/arch/arm/kernel/setup.c
2076 +++ b/arch/arm/kernel/setup.c
2077 @@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2078 unsigned int elf_hwcap __read_mostly;
2079 EXPORT_SYMBOL(elf_hwcap);
2080
2081 +pteval_t __supported_pte_mask __read_only;
2082 +pmdval_t __supported_pmd_mask __read_only;
2083
2084 #ifdef MULTI_CPU
2085 -struct processor processor __read_mostly;
2086 +struct processor processor;
2087 #endif
2088 #ifdef MULTI_TLB
2089 -struct cpu_tlb_fns cpu_tlb __read_mostly;
2090 +struct cpu_tlb_fns cpu_tlb __read_only;
2091 #endif
2092 #ifdef MULTI_USER
2093 -struct cpu_user_fns cpu_user __read_mostly;
2094 +struct cpu_user_fns cpu_user __read_only;
2095 #endif
2096 #ifdef MULTI_CACHE
2097 -struct cpu_cache_fns cpu_cache __read_mostly;
2098 +struct cpu_cache_fns cpu_cache __read_only;
2099 #endif
2100 #ifdef CONFIG_OUTER_CACHE
2101 -struct outer_cache_fns outer_cache __read_mostly;
2102 +struct outer_cache_fns outer_cache __read_only;
2103 EXPORT_SYMBOL(outer_cache);
2104 #endif
2105
2106 @@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2107 asm("mrc p15, 0, %0, c0, c1, 4"
2108 : "=r" (mmfr0));
2109 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2110 - (mmfr0 & 0x000000f0) >= 0x00000030)
2111 + (mmfr0 & 0x000000f0) >= 0x00000030) {
2112 cpu_arch = CPU_ARCH_ARMv7;
2113 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2114 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2115 + __supported_pte_mask |= L_PTE_PXN;
2116 + __supported_pmd_mask |= PMD_PXNTABLE;
2117 + }
2118 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2119 (mmfr0 & 0x000000f0) == 0x00000020)
2120 cpu_arch = CPU_ARCH_ARMv6;
2121 else
2122 @@ -455,7 +461,7 @@ static void __init setup_processor(void)
2123 __cpu_architecture = __get_cpu_architecture();
2124
2125 #ifdef MULTI_CPU
2126 - processor = *list->proc;
2127 + memcpy((void *)&processor, list->proc, sizeof processor);
2128 #endif
2129 #ifdef MULTI_TLB
2130 cpu_tlb = *list->tlb;
2131 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2132 index fbc8b26..000ded0 100644
2133 --- a/arch/arm/kernel/smp.c
2134 +++ b/arch/arm/kernel/smp.c
2135 @@ -70,7 +70,7 @@ enum ipi_msg_type {
2136
2137 static DECLARE_COMPLETION(cpu_running);
2138
2139 -static struct smp_operations smp_ops;
2140 +static struct smp_operations smp_ops __read_only;
2141
2142 void __init smp_set_ops(struct smp_operations *ops)
2143 {
2144 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2145 index b0179b8..7713948 100644
2146 --- a/arch/arm/kernel/traps.c
2147 +++ b/arch/arm/kernel/traps.c
2148 @@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
2149 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
2150 {
2151 #ifdef CONFIG_KALLSYMS
2152 - printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
2153 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
2154 #else
2155 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
2156 #endif
2157 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2158 static int die_owner = -1;
2159 static unsigned int die_nest_count;
2160
2161 +extern void gr_handle_kernel_exploit(void);
2162 +
2163 static unsigned long oops_begin(void)
2164 {
2165 int cpu;
2166 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
2167 panic("Fatal exception in interrupt");
2168 if (panic_on_oops)
2169 panic("Fatal exception");
2170 +
2171 + gr_handle_kernel_exploit();
2172 +
2173 if (signr)
2174 do_exit(signr);
2175 }
2176 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
2177 index 36ff15b..75d9e9d 100644
2178 --- a/arch/arm/kernel/vmlinux.lds.S
2179 +++ b/arch/arm/kernel/vmlinux.lds.S
2180 @@ -8,7 +8,11 @@
2181 #include <asm/thread_info.h>
2182 #include <asm/memory.h>
2183 #include <asm/page.h>
2184 -
2185 +
2186 +#ifdef CONFIG_PAX_KERNEXEC
2187 +#include <asm/pgtable.h>
2188 +#endif
2189 +
2190 #define PROC_INFO \
2191 . = ALIGN(4); \
2192 VMLINUX_SYMBOL(__proc_info_begin) = .; \
2193 @@ -90,6 +94,11 @@ SECTIONS
2194 _text = .;
2195 HEAD_TEXT
2196 }
2197 +
2198 +#ifdef CONFIG_PAX_KERNEXEC
2199 + . = ALIGN(1<<SECTION_SHIFT);
2200 +#endif
2201 +
2202 .text : { /* Real text segment */
2203 _stext = .; /* Text and read-only data */
2204 __exception_text_start = .;
2205 @@ -133,6 +142,10 @@ SECTIONS
2206
2207 _etext = .; /* End of text and rodata section */
2208
2209 +#ifdef CONFIG_PAX_KERNEXEC
2210 + . = ALIGN(1<<SECTION_SHIFT);
2211 +#endif
2212 +
2213 #ifndef CONFIG_XIP_KERNEL
2214 . = ALIGN(PAGE_SIZE);
2215 __init_begin = .;
2216 @@ -192,6 +205,11 @@ SECTIONS
2217 . = PAGE_OFFSET + TEXT_OFFSET;
2218 #else
2219 __init_end = .;
2220 +
2221 +#ifdef CONFIG_PAX_KERNEXEC
2222 + . = ALIGN(1<<SECTION_SHIFT);
2223 +#endif
2224 +
2225 . = ALIGN(THREAD_SIZE);
2226 __data_loc = .;
2227 #endif
2228 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
2229 index 66a477a..bee61d3 100644
2230 --- a/arch/arm/lib/copy_from_user.S
2231 +++ b/arch/arm/lib/copy_from_user.S
2232 @@ -16,7 +16,7 @@
2233 /*
2234 * Prototype:
2235 *
2236 - * size_t __copy_from_user(void *to, const void *from, size_t n)
2237 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
2238 *
2239 * Purpose:
2240 *
2241 @@ -84,11 +84,11 @@
2242
2243 .text
2244
2245 -ENTRY(__copy_from_user)
2246 +ENTRY(___copy_from_user)
2247
2248 #include "copy_template.S"
2249
2250 -ENDPROC(__copy_from_user)
2251 +ENDPROC(___copy_from_user)
2252
2253 .pushsection .fixup,"ax"
2254 .align 0
2255 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
2256 index 6ee2f67..d1cce76 100644
2257 --- a/arch/arm/lib/copy_page.S
2258 +++ b/arch/arm/lib/copy_page.S
2259 @@ -10,6 +10,7 @@
2260 * ASM optimised string functions
2261 */
2262 #include <linux/linkage.h>
2263 +#include <linux/const.h>
2264 #include <asm/assembler.h>
2265 #include <asm/asm-offsets.h>
2266 #include <asm/cache.h>
2267 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
2268 index d066df6..df28194 100644
2269 --- a/arch/arm/lib/copy_to_user.S
2270 +++ b/arch/arm/lib/copy_to_user.S
2271 @@ -16,7 +16,7 @@
2272 /*
2273 * Prototype:
2274 *
2275 - * size_t __copy_to_user(void *to, const void *from, size_t n)
2276 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
2277 *
2278 * Purpose:
2279 *
2280 @@ -88,11 +88,11 @@
2281 .text
2282
2283 ENTRY(__copy_to_user_std)
2284 -WEAK(__copy_to_user)
2285 +WEAK(___copy_to_user)
2286
2287 #include "copy_template.S"
2288
2289 -ENDPROC(__copy_to_user)
2290 +ENDPROC(___copy_to_user)
2291 ENDPROC(__copy_to_user_std)
2292
2293 .pushsection .fixup,"ax"
2294 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
2295 index 0dc5385..45833ef 100644
2296 --- a/arch/arm/lib/delay.c
2297 +++ b/arch/arm/lib/delay.c
2298 @@ -28,12 +28,14 @@
2299 /*
2300 * Default to the loop-based delay implementation.
2301 */
2302 -struct arm_delay_ops arm_delay_ops = {
2303 +static struct arm_delay_ops arm_loop_delay_ops = {
2304 .delay = __loop_delay,
2305 .const_udelay = __loop_const_udelay,
2306 .udelay = __loop_udelay,
2307 };
2308
2309 +struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
2310 +
2311 static const struct delay_timer *delay_timer;
2312 static bool delay_calibrated;
2313
2314 @@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
2315 __timer_const_udelay(usecs * UDELAY_MULT);
2316 }
2317
2318 +static struct arm_delay_ops arm_timer_delay_ops = {
2319 + .delay = __timer_delay,
2320 + .const_udelay = __timer_const_udelay,
2321 + .udelay = __timer_udelay,
2322 +};
2323 +
2324 void __init register_current_timer_delay(const struct delay_timer *timer)
2325 {
2326 if (!delay_calibrated) {
2327 @@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
2328 delay_timer = timer;
2329 lpj_fine = timer->freq / HZ;
2330 loops_per_jiffy = lpj_fine;
2331 - arm_delay_ops.delay = __timer_delay;
2332 - arm_delay_ops.const_udelay = __timer_const_udelay;
2333 - arm_delay_ops.udelay = __timer_udelay;
2334 + arm_delay_ops = &arm_timer_delay_ops;
2335 delay_calibrated = true;
2336 } else {
2337 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
2338 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
2339 index 025f742..8432b08 100644
2340 --- a/arch/arm/lib/uaccess_with_memcpy.c
2341 +++ b/arch/arm/lib/uaccess_with_memcpy.c
2342 @@ -104,7 +104,7 @@ out:
2343 }
2344
2345 unsigned long
2346 -__copy_to_user(void __user *to, const void *from, unsigned long n)
2347 +___copy_to_user(void __user *to, const void *from, unsigned long n)
2348 {
2349 /*
2350 * This test is stubbed out of the main function above to keep
2351 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
2352 index 2c6c218..2b87c2d 100644
2353 --- a/arch/arm/mach-kirkwood/common.c
2354 +++ b/arch/arm/mach-kirkwood/common.c
2355 @@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
2356 clk_gate_ops.disable(hw);
2357 }
2358
2359 -static struct clk_ops clk_gate_fn_ops;
2360 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
2361 +{
2362 + return clk_gate_ops.is_enabled(hw);
2363 +}
2364 +
2365 +static struct clk_ops clk_gate_fn_ops = {
2366 + .enable = clk_gate_fn_enable,
2367 + .disable = clk_gate_fn_disable,
2368 + .is_enabled = clk_gate_fn_is_enabled,
2369 +};
2370
2371 static struct clk __init *clk_register_gate_fn(struct device *dev,
2372 const char *name,
2373 @@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
2374 gate_fn->fn_en = fn_en;
2375 gate_fn->fn_dis = fn_dis;
2376
2377 - /* ops is the gate ops, but with our enable/disable functions */
2378 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
2379 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
2380 - clk_gate_fn_ops = clk_gate_ops;
2381 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
2382 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
2383 - }
2384 -
2385 clk = clk_register(dev, &gate_fn->gate.hw);
2386
2387 if (IS_ERR(clk))
2388 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
2389 index d95f727..12f10dd 100644
2390 --- a/arch/arm/mach-omap2/board-n8x0.c
2391 +++ b/arch/arm/mach-omap2/board-n8x0.c
2392 @@ -589,7 +589,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
2393 }
2394 #endif
2395
2396 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
2397 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
2398 .late_init = n8x0_menelaus_late_init,
2399 };
2400
2401 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
2402 index 87cc6d0..fd4f248 100644
2403 --- a/arch/arm/mach-omap2/omap_hwmod.c
2404 +++ b/arch/arm/mach-omap2/omap_hwmod.c
2405 @@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
2406 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
2407 struct omap_hwmod_rst_info *ohri);
2408 int (*init_clkdm)(struct omap_hwmod *oh);
2409 -};
2410 +} __no_const;
2411
2412 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
2413 -static struct omap_hwmod_soc_ops soc_ops;
2414 +static struct omap_hwmod_soc_ops soc_ops __read_only;
2415
2416 /* omap_hwmod_list contains all registered struct omap_hwmods */
2417 static LIST_HEAD(omap_hwmod_list);
2418 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
2419 index 5dbf13f..9be36fd 100644
2420 --- a/arch/arm/mm/fault.c
2421 +++ b/arch/arm/mm/fault.c
2422 @@ -25,6 +25,7 @@
2423 #include <asm/system_misc.h>
2424 #include <asm/system_info.h>
2425 #include <asm/tlbflush.h>
2426 +#include <asm/sections.h>
2427
2428 #include "fault.h"
2429
2430 @@ -138,6 +139,19 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
2431 if (fixup_exception(regs))
2432 return;
2433
2434 +#ifdef CONFIG_PAX_KERNEXEC
2435 + if (fsr & FSR_WRITE) {
2436 + if (((unsigned long)_stext <= addr && addr < init_mm.end_code) || (MODULES_VADDR <= addr && addr < MODULES_END)) {
2437 + if (current->signal->curr_ip)
2438 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2439 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
2440 + else
2441 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2442 + current->comm, task_pid_nr(current), current_uid(), current_euid());
2443 + }
2444 + }
2445 +#endif
2446 +
2447 /*
2448 * No handler, we'll have to terminate things with extreme prejudice.
2449 */
2450 @@ -174,6 +188,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
2451 }
2452 #endif
2453
2454 +#ifdef CONFIG_PAX_PAGEEXEC
2455 + if (fsr & FSR_LNX_PF) {
2456 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
2457 + do_group_exit(SIGKILL);
2458 + }
2459 +#endif
2460 +
2461 tsk->thread.address = addr;
2462 tsk->thread.error_code = fsr;
2463 tsk->thread.trap_no = 14;
2464 @@ -398,6 +419,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
2465 }
2466 #endif /* CONFIG_MMU */
2467
2468 +#ifdef CONFIG_PAX_PAGEEXEC
2469 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2470 +{
2471 + long i;
2472 +
2473 + printk(KERN_ERR "PAX: bytes at PC: ");
2474 + for (i = 0; i < 20; i++) {
2475 + unsigned char c;
2476 + if (get_user(c, (__force unsigned char __user *)pc+i))
2477 + printk(KERN_CONT "?? ");
2478 + else
2479 + printk(KERN_CONT "%02x ", c);
2480 + }
2481 + printk("\n");
2482 +
2483 + printk(KERN_ERR "PAX: bytes at SP-4: ");
2484 + for (i = -1; i < 20; i++) {
2485 + unsigned long c;
2486 + if (get_user(c, (__force unsigned long __user *)sp+i))
2487 + printk(KERN_CONT "???????? ");
2488 + else
2489 + printk(KERN_CONT "%08lx ", c);
2490 + }
2491 + printk("\n");
2492 +}
2493 +#endif
2494 +
2495 /*
2496 * First Level Translation Fault Handler
2497 *
2498 @@ -575,12 +623,41 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
2499 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
2500 struct siginfo info;
2501
2502 +#ifdef CONFIG_PAX_KERNEXEC
2503 + if (!user_mode(regs) && is_xn_fault(ifsr)) {
2504 + if (current->signal->curr_ip)
2505 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2506 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid(),
2507 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2508 + else
2509 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2510 + current->comm, task_pid_nr(current), current_uid(), current_euid(),
2511 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2512 + goto die;
2513 + }
2514 +#endif
2515 +
2516 +#ifdef CONFIG_PAX_REFCOUNT
2517 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
2518 + unsigned int bkpt;
2519 +
2520 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
2521 + current->thread.error_code = ifsr;
2522 + current->thread.trap_no = 0;
2523 + pax_report_refcount_overflow(regs);
2524 + fixup_exception(regs);
2525 + return;
2526 + }
2527 + }
2528 +#endif
2529 +
2530 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
2531 return;
2532
2533 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
2534 inf->name, ifsr, addr);
2535
2536 +die:
2537 info.si_signo = inf->sig;
2538 info.si_errno = 0;
2539 info.si_code = inf->code;
2540 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
2541 index cf08bdf..f1a0383 100644
2542 --- a/arch/arm/mm/fault.h
2543 +++ b/arch/arm/mm/fault.h
2544 @@ -3,6 +3,7 @@
2545
2546 /*
2547 * Fault status register encodings. We steal bit 31 for our own purposes.
2548 + * Set when the FSR value is from an instruction fault.
2549 */
2550 #define FSR_LNX_PF (1 << 31)
2551 #define FSR_WRITE (1 << 11)
2552 @@ -22,6 +23,12 @@ static inline int fsr_fs(unsigned int fsr)
2553 }
2554 #endif
2555
2556 +/* valid for LPAE and !LPAE */
2557 +static inline int is_xn_fault(unsigned int fsr)
2558 +{
2559 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
2560 +}
2561 +
2562 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
2563 unsigned long search_exception_table(unsigned long addr);
2564
2565 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
2566 index ad722f1..46b670e 100644
2567 --- a/arch/arm/mm/init.c
2568 +++ b/arch/arm/mm/init.c
2569 @@ -734,9 +734,43 @@ void __init mem_init(void)
2570
2571 void free_initmem(void)
2572 {
2573 +
2574 +#ifdef CONFIG_PAX_KERNEXEC
2575 + unsigned long addr;
2576 + pgd_t *pgd;
2577 + pud_t *pud;
2578 + pmd_t *pmd;
2579 +#endif
2580 +
2581 #ifdef CONFIG_HAVE_TCM
2582 extern char __tcm_start, __tcm_end;
2583 +#endif
2584
2585 +#ifdef CONFIG_PAX_KERNEXEC
2586 + /* make pages tables, etc before .text NX */
2587 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += PMD_SIZE) {
2588 + pgd = pgd_offset_k(addr);
2589 + pud = pud_offset(pgd, addr);
2590 + pmd = pmd_offset(pud, addr);
2591 + __pmd_update(pmd, PMD_SECT_XN);
2592 + }
2593 + /* make init NX */
2594 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += PMD_SIZE) {
2595 + pgd = pgd_offset_k(addr);
2596 + pud = pud_offset(pgd, addr);
2597 + pmd = pmd_offset(pud, addr);
2598 + __pmd_update(pmd, PMD_SECT_XN);
2599 + }
2600 + /* make kernel code/rodata read-only */
2601 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += PMD_SIZE) {
2602 + pgd = pgd_offset_k(addr);
2603 + pud = pud_offset(pgd, addr);
2604 + pmd = pmd_offset(pud, addr);
2605 + __pmd_update(pmd, PMD_SECT_AP_RDONLY);
2606 + }
2607 +#endif
2608 +
2609 +#ifdef CONFIG_HAVE_TCM
2610 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
2611 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
2612 __phys_to_pfn(__pa(&__tcm_end)),
2613 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
2614 index ce8cb19..061aa14 100644
2615 --- a/arch/arm/mm/mmap.c
2616 +++ b/arch/arm/mm/mmap.c
2617 @@ -72,6 +72,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2618 unsigned long start_addr;
2619 int do_align = 0;
2620 int aliasing = cache_is_vipt_aliasing();
2621 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
2622
2623 /*
2624 * We only need to do colour alignment if either the I or D
2625 @@ -93,6 +94,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2626 if (len > TASK_SIZE)
2627 return -ENOMEM;
2628
2629 +#ifdef CONFIG_PAX_RANDMMAP
2630 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2631 +#endif
2632 +
2633 if (addr) {
2634 if (do_align)
2635 addr = COLOUR_ALIGN(addr, pgoff);
2636 @@ -100,15 +105,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2637 addr = PAGE_ALIGN(addr);
2638
2639 vma = find_vma(mm, addr);
2640 - if (TASK_SIZE - len >= addr &&
2641 - (!vma || addr + len <= vma->vm_start))
2642 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
2643 return addr;
2644 }
2645 if (len > mm->cached_hole_size) {
2646 - start_addr = addr = mm->free_area_cache;
2647 + start_addr = addr = mm->free_area_cache;
2648 } else {
2649 - start_addr = addr = mm->mmap_base;
2650 - mm->cached_hole_size = 0;
2651 + start_addr = addr = mm->mmap_base;
2652 + mm->cached_hole_size = 0;
2653 }
2654
2655 full_search:
2656 @@ -124,14 +128,14 @@ full_search:
2657 * Start a new search - just in case we missed
2658 * some holes.
2659 */
2660 - if (start_addr != TASK_UNMAPPED_BASE) {
2661 - start_addr = addr = TASK_UNMAPPED_BASE;
2662 + if (start_addr != mm->mmap_base) {
2663 + start_addr = addr = mm->mmap_base;
2664 mm->cached_hole_size = 0;
2665 goto full_search;
2666 }
2667 return -ENOMEM;
2668 }
2669 - if (!vma || addr + len <= vma->vm_start) {
2670 + if (check_heap_stack_gap(vma, addr, len, offset)) {
2671 /*
2672 * Remember the place where we stopped the search:
2673 */
2674 @@ -156,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2675 unsigned long addr = addr0;
2676 int do_align = 0;
2677 int aliasing = cache_is_vipt_aliasing();
2678 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
2679
2680 /*
2681 * We only need to do colour alignment if either the I or D
2682 @@ -175,6 +180,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2683 return addr;
2684 }
2685
2686 +#ifdef CONFIG_PAX_RANDMMAP
2687 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2688 +#endif
2689 +
2690 /* requesting a specific address */
2691 if (addr) {
2692 if (do_align)
2693 @@ -182,8 +191,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2694 else
2695 addr = PAGE_ALIGN(addr);
2696 vma = find_vma(mm, addr);
2697 - if (TASK_SIZE - len >= addr &&
2698 - (!vma || addr + len <= vma->vm_start))
2699 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
2700 return addr;
2701 }
2702
2703 @@ -203,7 +211,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2704 /* make sure it can fit in the remaining address space */
2705 if (addr > len) {
2706 vma = find_vma(mm, addr-len);
2707 - if (!vma || addr <= vma->vm_start)
2708 + if (check_heap_stack_gap(vma, addr - len, len, offset))
2709 /* remember the address as a hint for next time */
2710 return (mm->free_area_cache = addr-len);
2711 }
2712 @@ -212,17 +220,17 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2713 goto bottomup;
2714
2715 addr = mm->mmap_base - len;
2716 - if (do_align)
2717 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2718
2719 do {
2720 + if (do_align)
2721 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2722 /*
2723 * Lookup failure means no vma is above this address,
2724 * else if new region fits below vma->vm_start,
2725 * return with success:
2726 */
2727 vma = find_vma(mm, addr);
2728 - if (!vma || addr+len <= vma->vm_start)
2729 + if (check_heap_stack_gap(vma, addr, len, offset))
2730 /* remember the address as a hint for next time */
2731 return (mm->free_area_cache = addr);
2732
2733 @@ -231,10 +239,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2734 mm->cached_hole_size = vma->vm_start - addr;
2735
2736 /* try just below the current vma->vm_start */
2737 - addr = vma->vm_start - len;
2738 - if (do_align)
2739 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2740 - } while (len < vma->vm_start);
2741 + addr = skip_heap_stack_gap(vma, len, offset);
2742 + } while (!IS_ERR_VALUE(addr));
2743
2744 bottomup:
2745 /*
2746 @@ -259,6 +265,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2747 {
2748 unsigned long random_factor = 0UL;
2749
2750 +#ifdef CONFIG_PAX_RANDMMAP
2751 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2752 +#endif
2753 +
2754 /* 8 bits of randomness in 20 address space bits */
2755 if ((current->flags & PF_RANDOMIZE) &&
2756 !(current->personality & ADDR_NO_RANDOMIZE))
2757 @@ -266,10 +276,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2758
2759 if (mmap_is_legacy()) {
2760 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2761 +
2762 +#ifdef CONFIG_PAX_RANDMMAP
2763 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2764 + mm->mmap_base += mm->delta_mmap;
2765 +#endif
2766 +
2767 mm->get_unmapped_area = arch_get_unmapped_area;
2768 mm->unmap_area = arch_unmap_area;
2769 } else {
2770 mm->mmap_base = mmap_base(random_factor);
2771 +
2772 +#ifdef CONFIG_PAX_RANDMMAP
2773 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2774 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2775 +#endif
2776 +
2777 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2778 mm->unmap_area = arch_unmap_area_topdown;
2779 }
2780 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
2781 index 99b47b9..579b667 100644
2782 --- a/arch/arm/mm/mmu.c
2783 +++ b/arch/arm/mm/mmu.c
2784 @@ -227,16 +227,16 @@ static struct mem_type mem_types[] = {
2785 [MT_UNCACHED] = {
2786 .prot_pte = PROT_PTE_DEVICE,
2787 .prot_l1 = PMD_TYPE_TABLE,
2788 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2789 + .prot_sect = PROT_SECT_DEVICE | PMD_SECT_XN,
2790 .domain = DOMAIN_IO,
2791 },
2792 [MT_CACHECLEAN] = {
2793 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2794 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2795 .domain = DOMAIN_KERNEL,
2796 },
2797 #ifndef CONFIG_ARM_LPAE
2798 [MT_MINICLEAN] = {
2799 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
2800 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE | PMD_SECT_AP_RDONLY,
2801 .domain = DOMAIN_KERNEL,
2802 },
2803 #endif
2804 @@ -258,8 +258,26 @@ static struct mem_type mem_types[] = {
2805 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
2806 .domain = DOMAIN_KERNEL,
2807 },
2808 + [MT_MEMORY_R] = {
2809 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY | L_PTE_XN,
2810 + .prot_l1 = PMD_TYPE_TABLE,
2811 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY | PMD_SECT_XN,
2812 + .domain = DOMAIN_KERNEL,
2813 + },
2814 + [MT_MEMORY_RW] = {
2815 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_XN,
2816 + .prot_l1 = PMD_TYPE_TABLE,
2817 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_XN,
2818 + .domain = DOMAIN_KERNEL,
2819 + },
2820 + [MT_MEMORY_RX] = {
2821 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY,
2822 + .prot_l1 = PMD_TYPE_TABLE,
2823 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2824 + .domain = DOMAIN_KERNEL,
2825 + },
2826 [MT_ROM] = {
2827 - .prot_sect = PMD_TYPE_SECT,
2828 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2829 .domain = DOMAIN_KERNEL,
2830 },
2831 [MT_MEMORY_NONCACHED] = {
2832 @@ -273,7 +291,7 @@ static struct mem_type mem_types[] = {
2833 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
2834 L_PTE_XN,
2835 .prot_l1 = PMD_TYPE_TABLE,
2836 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2837 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2838 .domain = DOMAIN_KERNEL,
2839 },
2840 [MT_MEMORY_ITCM] = {
2841 @@ -432,6 +450,8 @@ static void __init build_mem_type_table(void)
2842 * from SVC mode and no access from userspace.
2843 */
2844 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2845 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2846 + mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2847 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2848 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2849 #endif
2850 @@ -450,6 +470,12 @@ static void __init build_mem_type_table(void)
2851 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
2852 mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
2853 mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
2854 + mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_S;
2855 + mem_types[MT_MEMORY_R].prot_pte |= L_PTE_SHARED;
2856 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
2857 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
2858 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
2859 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
2860 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
2861 mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
2862 mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
2863 @@ -487,6 +513,8 @@ static void __init build_mem_type_table(void)
2864 vecs_pgprot |= PTE_EXT_AF;
2865 #endif
2866
2867 + user_pgprot |= __supported_pte_mask;
2868 +
2869 for (i = 0; i < 16; i++) {
2870 pteval_t v = pgprot_val(protection_map[i]);
2871 protection_map[i] = __pgprot(v | user_pgprot);
2872 @@ -503,6 +531,12 @@ static void __init build_mem_type_table(void)
2873 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
2874 mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
2875 mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
2876 + mem_types[MT_MEMORY_R].prot_sect |= ecc_mask | cp->pmd;
2877 + mem_types[MT_MEMORY_R].prot_pte |= kern_pgprot;
2878 + mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
2879 + mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
2880 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
2881 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
2882 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
2883 mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
2884 mem_types[MT_ROM].prot_sect |= cp->pmd;
2885 @@ -1198,7 +1232,41 @@ static void __init map_lowmem(void)
2886 map.pfn = __phys_to_pfn(start);
2887 map.virtual = __phys_to_virt(start);
2888 map.length = end - start;
2889 +
2890 +#ifdef CONFIG_PAX_KERNEXEC
2891 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
2892 + struct map_desc kernel;
2893 + struct map_desc initmap;
2894 +
2895 + /* when freeing initmem we will make this RW */
2896 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
2897 + initmap.virtual = (unsigned long)__init_begin;
2898 + initmap.length = _sdata - __init_begin;
2899 + initmap.type = MT_MEMORY;
2900 + create_mapping(&initmap);
2901 +
2902 + /* when freeing initmem we will make this RX */
2903 + kernel.pfn = __phys_to_pfn(__pa(_stext));
2904 + kernel.virtual = (unsigned long)_stext;
2905 + kernel.length = __init_begin - _stext;
2906 + kernel.type = MT_MEMORY;
2907 + create_mapping(&kernel);
2908 +
2909 + if (map.virtual < (unsigned long)_stext) {
2910 + map.length = (unsigned long)_stext - map.virtual;
2911 + map.type = MT_MEMORY;
2912 + create_mapping(&map);
2913 + }
2914 +
2915 + map.pfn = __phys_to_pfn(__pa(_sdata));
2916 + map.virtual = (unsigned long)_sdata;
2917 + map.length = end - __pa(_sdata);
2918 + }
2919 +
2920 + map.type = MT_MEMORY_RW;
2921 +#else
2922 map.type = MT_MEMORY;
2923 +#endif
2924
2925 create_mapping(&map);
2926 }
2927 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2928 index ec63e4a..62aa5f1d 100644
2929 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2930 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2931 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2932 value in bridge_virt_base */
2933 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2934 const int win);
2935 -};
2936 +} __no_const;
2937
2938 /*
2939 * Information needed to setup one address mapping.
2940 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2941 index f5144cd..71f6d1f 100644
2942 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2943 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2944 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
2945 int (*started)(unsigned ch);
2946 int (*flush)(unsigned ch);
2947 int (*stop)(unsigned ch);
2948 -};
2949 +} __no_const;
2950
2951 extern void *samsung_dmadev_get_ops(void);
2952 extern void *s3c_dma_get_ops(void);
2953 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2954 index c3a58a1..78fbf54 100644
2955 --- a/arch/avr32/include/asm/cache.h
2956 +++ b/arch/avr32/include/asm/cache.h
2957 @@ -1,8 +1,10 @@
2958 #ifndef __ASM_AVR32_CACHE_H
2959 #define __ASM_AVR32_CACHE_H
2960
2961 +#include <linux/const.h>
2962 +
2963 #define L1_CACHE_SHIFT 5
2964 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2965 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2966
2967 /*
2968 * Memory returned by kmalloc() may be used for DMA, so we must make
2969 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2970 index e2c3287..6c4f98c 100644
2971 --- a/arch/avr32/include/asm/elf.h
2972 +++ b/arch/avr32/include/asm/elf.h
2973 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2974 the loader. We need to make sure that it is out of the way of the program
2975 that it will "exec", and that there is sufficient room for the brk. */
2976
2977 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2978 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2979
2980 +#ifdef CONFIG_PAX_ASLR
2981 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2982 +
2983 +#define PAX_DELTA_MMAP_LEN 15
2984 +#define PAX_DELTA_STACK_LEN 15
2985 +#endif
2986
2987 /* This yields a mask that user programs can use to figure out what
2988 instruction set this CPU supports. This could be done in user space,
2989 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2990 index 479330b..53717a8 100644
2991 --- a/arch/avr32/include/asm/kmap_types.h
2992 +++ b/arch/avr32/include/asm/kmap_types.h
2993 @@ -2,9 +2,9 @@
2994 #define __ASM_AVR32_KMAP_TYPES_H
2995
2996 #ifdef CONFIG_DEBUG_HIGHMEM
2997 -# define KM_TYPE_NR 29
2998 +# define KM_TYPE_NR 30
2999 #else
3000 -# define KM_TYPE_NR 14
3001 +# define KM_TYPE_NR 15
3002 #endif
3003
3004 #endif /* __ASM_AVR32_KMAP_TYPES_H */
3005 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
3006 index b2f2d2d..d1c85cb 100644
3007 --- a/arch/avr32/mm/fault.c
3008 +++ b/arch/avr32/mm/fault.c
3009 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
3010
3011 int exception_trace = 1;
3012
3013 +#ifdef CONFIG_PAX_PAGEEXEC
3014 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3015 +{
3016 + unsigned long i;
3017 +
3018 + printk(KERN_ERR "PAX: bytes at PC: ");
3019 + for (i = 0; i < 20; i++) {
3020 + unsigned char c;
3021 + if (get_user(c, (unsigned char *)pc+i))
3022 + printk(KERN_CONT "???????? ");
3023 + else
3024 + printk(KERN_CONT "%02x ", c);
3025 + }
3026 + printk("\n");
3027 +}
3028 +#endif
3029 +
3030 /*
3031 * This routine handles page faults. It determines the address and the
3032 * problem, and then passes it off to one of the appropriate routines.
3033 @@ -174,6 +191,16 @@ bad_area:
3034 up_read(&mm->mmap_sem);
3035
3036 if (user_mode(regs)) {
3037 +
3038 +#ifdef CONFIG_PAX_PAGEEXEC
3039 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
3040 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
3041 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
3042 + do_group_exit(SIGKILL);
3043 + }
3044 + }
3045 +#endif
3046 +
3047 if (exception_trace && printk_ratelimit())
3048 printk("%s%s[%d]: segfault at %08lx pc %08lx "
3049 "sp %08lx ecr %lu\n",
3050 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
3051 index 568885a..f8008df 100644
3052 --- a/arch/blackfin/include/asm/cache.h
3053 +++ b/arch/blackfin/include/asm/cache.h
3054 @@ -7,6 +7,7 @@
3055 #ifndef __ARCH_BLACKFIN_CACHE_H
3056 #define __ARCH_BLACKFIN_CACHE_H
3057
3058 +#include <linux/const.h>
3059 #include <linux/linkage.h> /* for asmlinkage */
3060
3061 /*
3062 @@ -14,7 +15,7 @@
3063 * Blackfin loads 32 bytes for cache
3064 */
3065 #define L1_CACHE_SHIFT 5
3066 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3067 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3068 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3069
3070 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
3071 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
3072 index aea2718..3639a60 100644
3073 --- a/arch/cris/include/arch-v10/arch/cache.h
3074 +++ b/arch/cris/include/arch-v10/arch/cache.h
3075 @@ -1,8 +1,9 @@
3076 #ifndef _ASM_ARCH_CACHE_H
3077 #define _ASM_ARCH_CACHE_H
3078
3079 +#include <linux/const.h>
3080 /* Etrax 100LX have 32-byte cache-lines. */
3081 -#define L1_CACHE_BYTES 32
3082 #define L1_CACHE_SHIFT 5
3083 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3084
3085 #endif /* _ASM_ARCH_CACHE_H */
3086 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
3087 index 7caf25d..ee65ac5 100644
3088 --- a/arch/cris/include/arch-v32/arch/cache.h
3089 +++ b/arch/cris/include/arch-v32/arch/cache.h
3090 @@ -1,11 +1,12 @@
3091 #ifndef _ASM_CRIS_ARCH_CACHE_H
3092 #define _ASM_CRIS_ARCH_CACHE_H
3093
3094 +#include <linux/const.h>
3095 #include <arch/hwregs/dma.h>
3096
3097 /* A cache-line is 32 bytes. */
3098 -#define L1_CACHE_BYTES 32
3099 #define L1_CACHE_SHIFT 5
3100 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3101
3102 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
3103
3104 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
3105 index b86329d..6709906 100644
3106 --- a/arch/frv/include/asm/atomic.h
3107 +++ b/arch/frv/include/asm/atomic.h
3108 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
3109 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
3110 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
3111
3112 +#define atomic64_read_unchecked(v) atomic64_read(v)
3113 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3114 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3115 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3116 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3117 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3118 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3119 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3120 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3121 +
3122 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
3123 {
3124 int c, old;
3125 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
3126 index 2797163..c2a401d 100644
3127 --- a/arch/frv/include/asm/cache.h
3128 +++ b/arch/frv/include/asm/cache.h
3129 @@ -12,10 +12,11 @@
3130 #ifndef __ASM_CACHE_H
3131 #define __ASM_CACHE_H
3132
3133 +#include <linux/const.h>
3134
3135 /* bytes per L1 cache line */
3136 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
3137 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3138 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3139
3140 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3141 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3142 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
3143 index 43901f2..0d8b865 100644
3144 --- a/arch/frv/include/asm/kmap_types.h
3145 +++ b/arch/frv/include/asm/kmap_types.h
3146 @@ -2,6 +2,6 @@
3147 #ifndef _ASM_KMAP_TYPES_H
3148 #define _ASM_KMAP_TYPES_H
3149
3150 -#define KM_TYPE_NR 17
3151 +#define KM_TYPE_NR 18
3152
3153 #endif
3154 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
3155 index 385fd30..3aaf4fe 100644
3156 --- a/arch/frv/mm/elf-fdpic.c
3157 +++ b/arch/frv/mm/elf-fdpic.c
3158 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3159 {
3160 struct vm_area_struct *vma;
3161 unsigned long limit;
3162 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
3163
3164 if (len > TASK_SIZE)
3165 return -ENOMEM;
3166 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3167 if (addr) {
3168 addr = PAGE_ALIGN(addr);
3169 vma = find_vma(current->mm, addr);
3170 - if (TASK_SIZE - len >= addr &&
3171 - (!vma || addr + len <= vma->vm_start))
3172 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3173 goto success;
3174 }
3175
3176 @@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3177 for (; vma; vma = vma->vm_next) {
3178 if (addr > limit)
3179 break;
3180 - if (addr + len <= vma->vm_start)
3181 + if (check_heap_stack_gap(vma, addr, len, offset))
3182 goto success;
3183 addr = vma->vm_end;
3184 }
3185 @@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3186 for (; vma; vma = vma->vm_next) {
3187 if (addr > limit)
3188 break;
3189 - if (addr + len <= vma->vm_start)
3190 + if (check_heap_stack_gap(vma, addr, len, offset))
3191 goto success;
3192 addr = vma->vm_end;
3193 }
3194 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
3195 index f4ca594..adc72fd6 100644
3196 --- a/arch/hexagon/include/asm/cache.h
3197 +++ b/arch/hexagon/include/asm/cache.h
3198 @@ -21,9 +21,11 @@
3199 #ifndef __ASM_CACHE_H
3200 #define __ASM_CACHE_H
3201
3202 +#include <linux/const.h>
3203 +
3204 /* Bytes per L1 cache line */
3205 -#define L1_CACHE_SHIFT (5)
3206 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3207 +#define L1_CACHE_SHIFT 5
3208 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3209
3210 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
3211 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
3212 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
3213 index 6e6fe18..a6ae668 100644
3214 --- a/arch/ia64/include/asm/atomic.h
3215 +++ b/arch/ia64/include/asm/atomic.h
3216 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
3217 #define atomic64_inc(v) atomic64_add(1, (v))
3218 #define atomic64_dec(v) atomic64_sub(1, (v))
3219
3220 +#define atomic64_read_unchecked(v) atomic64_read(v)
3221 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3222 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3223 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3224 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3225 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3226 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3227 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3228 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3229 +
3230 /* Atomic operations are already serializing */
3231 #define smp_mb__before_atomic_dec() barrier()
3232 #define smp_mb__after_atomic_dec() barrier()
3233 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
3234 index 988254a..e1ee885 100644
3235 --- a/arch/ia64/include/asm/cache.h
3236 +++ b/arch/ia64/include/asm/cache.h
3237 @@ -1,6 +1,7 @@
3238 #ifndef _ASM_IA64_CACHE_H
3239 #define _ASM_IA64_CACHE_H
3240
3241 +#include <linux/const.h>
3242
3243 /*
3244 * Copyright (C) 1998-2000 Hewlett-Packard Co
3245 @@ -9,7 +10,7 @@
3246
3247 /* Bytes per L1 (data) cache line. */
3248 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
3249 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3250 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3251
3252 #ifdef CONFIG_SMP
3253 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3254 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
3255 index b5298eb..67c6e62 100644
3256 --- a/arch/ia64/include/asm/elf.h
3257 +++ b/arch/ia64/include/asm/elf.h
3258 @@ -42,6 +42,13 @@
3259 */
3260 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
3261
3262 +#ifdef CONFIG_PAX_ASLR
3263 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
3264 +
3265 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3266 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3267 +#endif
3268 +
3269 #define PT_IA_64_UNWIND 0x70000001
3270
3271 /* IA-64 relocations: */
3272 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
3273 index 96a8d92..617a1cf 100644
3274 --- a/arch/ia64/include/asm/pgalloc.h
3275 +++ b/arch/ia64/include/asm/pgalloc.h
3276 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3277 pgd_val(*pgd_entry) = __pa(pud);
3278 }
3279
3280 +static inline void
3281 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3282 +{
3283 + pgd_populate(mm, pgd_entry, pud);
3284 +}
3285 +
3286 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3287 {
3288 return quicklist_alloc(0, GFP_KERNEL, NULL);
3289 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3290 pud_val(*pud_entry) = __pa(pmd);
3291 }
3292
3293 +static inline void
3294 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3295 +{
3296 + pud_populate(mm, pud_entry, pmd);
3297 +}
3298 +
3299 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
3300 {
3301 return quicklist_alloc(0, GFP_KERNEL, NULL);
3302 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
3303 index 815810c..d60bd4c 100644
3304 --- a/arch/ia64/include/asm/pgtable.h
3305 +++ b/arch/ia64/include/asm/pgtable.h
3306 @@ -12,7 +12,7 @@
3307 * David Mosberger-Tang <davidm@hpl.hp.com>
3308 */
3309
3310 -
3311 +#include <linux/const.h>
3312 #include <asm/mman.h>
3313 #include <asm/page.h>
3314 #include <asm/processor.h>
3315 @@ -142,6 +142,17 @@
3316 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3317 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3318 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
3319 +
3320 +#ifdef CONFIG_PAX_PAGEEXEC
3321 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
3322 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3323 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3324 +#else
3325 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3326 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3327 +# define PAGE_COPY_NOEXEC PAGE_COPY
3328 +#endif
3329 +
3330 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
3331 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
3332 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
3333 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
3334 index 54ff557..70c88b7 100644
3335 --- a/arch/ia64/include/asm/spinlock.h
3336 +++ b/arch/ia64/include/asm/spinlock.h
3337 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
3338 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
3339
3340 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
3341 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
3342 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
3343 }
3344
3345 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
3346 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
3347 index 449c8c0..50cdf87 100644
3348 --- a/arch/ia64/include/asm/uaccess.h
3349 +++ b/arch/ia64/include/asm/uaccess.h
3350 @@ -42,6 +42,8 @@
3351 #include <asm/pgtable.h>
3352 #include <asm/io.h>
3353
3354 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3355 +
3356 /*
3357 * For historical reasons, the following macros are grossly misnamed:
3358 */
3359 @@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
3360 static inline unsigned long
3361 __copy_to_user (void __user *to, const void *from, unsigned long count)
3362 {
3363 + if (count > INT_MAX)
3364 + return count;
3365 +
3366 + if (!__builtin_constant_p(count))
3367 + check_object_size(from, count, true);
3368 +
3369 return __copy_user(to, (__force void __user *) from, count);
3370 }
3371
3372 static inline unsigned long
3373 __copy_from_user (void *to, const void __user *from, unsigned long count)
3374 {
3375 + if (count > INT_MAX)
3376 + return count;
3377 +
3378 + if (!__builtin_constant_p(count))
3379 + check_object_size(to, count, false);
3380 +
3381 return __copy_user((__force void __user *) to, from, count);
3382 }
3383
3384 @@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3385 ({ \
3386 void __user *__cu_to = (to); \
3387 const void *__cu_from = (from); \
3388 - long __cu_len = (n); \
3389 + unsigned long __cu_len = (n); \
3390 \
3391 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
3392 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
3393 + if (!__builtin_constant_p(n)) \
3394 + check_object_size(__cu_from, __cu_len, true); \
3395 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
3396 + } \
3397 __cu_len; \
3398 })
3399
3400 @@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3401 ({ \
3402 void *__cu_to = (to); \
3403 const void __user *__cu_from = (from); \
3404 - long __cu_len = (n); \
3405 + unsigned long __cu_len = (n); \
3406 \
3407 __chk_user_ptr(__cu_from); \
3408 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
3409 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
3410 + if (!__builtin_constant_p(n)) \
3411 + check_object_size(__cu_to, __cu_len, false); \
3412 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
3413 + } \
3414 __cu_len; \
3415 })
3416
3417 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
3418 index 24603be..948052d 100644
3419 --- a/arch/ia64/kernel/module.c
3420 +++ b/arch/ia64/kernel/module.c
3421 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
3422 void
3423 module_free (struct module *mod, void *module_region)
3424 {
3425 - if (mod && mod->arch.init_unw_table &&
3426 - module_region == mod->module_init) {
3427 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
3428 unw_remove_unwind_table(mod->arch.init_unw_table);
3429 mod->arch.init_unw_table = NULL;
3430 }
3431 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
3432 }
3433
3434 static inline int
3435 +in_init_rx (const struct module *mod, uint64_t addr)
3436 +{
3437 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
3438 +}
3439 +
3440 +static inline int
3441 +in_init_rw (const struct module *mod, uint64_t addr)
3442 +{
3443 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
3444 +}
3445 +
3446 +static inline int
3447 in_init (const struct module *mod, uint64_t addr)
3448 {
3449 - return addr - (uint64_t) mod->module_init < mod->init_size;
3450 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
3451 +}
3452 +
3453 +static inline int
3454 +in_core_rx (const struct module *mod, uint64_t addr)
3455 +{
3456 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
3457 +}
3458 +
3459 +static inline int
3460 +in_core_rw (const struct module *mod, uint64_t addr)
3461 +{
3462 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
3463 }
3464
3465 static inline int
3466 in_core (const struct module *mod, uint64_t addr)
3467 {
3468 - return addr - (uint64_t) mod->module_core < mod->core_size;
3469 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
3470 }
3471
3472 static inline int
3473 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
3474 break;
3475
3476 case RV_BDREL:
3477 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
3478 + if (in_init_rx(mod, val))
3479 + val -= (uint64_t) mod->module_init_rx;
3480 + else if (in_init_rw(mod, val))
3481 + val -= (uint64_t) mod->module_init_rw;
3482 + else if (in_core_rx(mod, val))
3483 + val -= (uint64_t) mod->module_core_rx;
3484 + else if (in_core_rw(mod, val))
3485 + val -= (uint64_t) mod->module_core_rw;
3486 break;
3487
3488 case RV_LTV:
3489 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
3490 * addresses have been selected...
3491 */
3492 uint64_t gp;
3493 - if (mod->core_size > MAX_LTOFF)
3494 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
3495 /*
3496 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
3497 * at the end of the module.
3498 */
3499 - gp = mod->core_size - MAX_LTOFF / 2;
3500 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
3501 else
3502 - gp = mod->core_size / 2;
3503 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
3504 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
3505 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
3506 mod->arch.gp = gp;
3507 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
3508 }
3509 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
3510 index d9439ef..d0cac6b 100644
3511 --- a/arch/ia64/kernel/sys_ia64.c
3512 +++ b/arch/ia64/kernel/sys_ia64.c
3513 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3514 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
3515 struct mm_struct *mm = current->mm;
3516 struct vm_area_struct *vma;
3517 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3518
3519 if (len > RGN_MAP_LIMIT)
3520 return -ENOMEM;
3521 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3522 if (REGION_NUMBER(addr) == RGN_HPAGE)
3523 addr = 0;
3524 #endif
3525 +
3526 +#ifdef CONFIG_PAX_RANDMMAP
3527 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3528 + addr = mm->free_area_cache;
3529 + else
3530 +#endif
3531 +
3532 if (!addr)
3533 addr = mm->free_area_cache;
3534
3535 @@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3536 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
3537 /* At this point: (!vma || addr < vma->vm_end). */
3538 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
3539 - if (start_addr != TASK_UNMAPPED_BASE) {
3540 + if (start_addr != mm->mmap_base) {
3541 /* Start a new search --- just in case we missed some holes. */
3542 - addr = TASK_UNMAPPED_BASE;
3543 + addr = mm->mmap_base;
3544 goto full_search;
3545 }
3546 return -ENOMEM;
3547 }
3548 - if (!vma || addr + len <= vma->vm_start) {
3549 + if (check_heap_stack_gap(vma, addr, len, offset)) {
3550 /* Remember the address where we stopped this search: */
3551 mm->free_area_cache = addr + len;
3552 return addr;
3553 diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
3554 index c64460b..4d250a6 100644
3555 --- a/arch/ia64/kernel/topology.c
3556 +++ b/arch/ia64/kernel/topology.c
3557 @@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
3558 return NOTIFY_OK;
3559 }
3560
3561 -static struct notifier_block __cpuinitdata cache_cpu_notifier =
3562 +static struct notifier_block cache_cpu_notifier =
3563 {
3564 .notifier_call = cache_cpu_callback
3565 };
3566 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
3567 index 0ccb28f..8992469 100644
3568 --- a/arch/ia64/kernel/vmlinux.lds.S
3569 +++ b/arch/ia64/kernel/vmlinux.lds.S
3570 @@ -198,7 +198,7 @@ SECTIONS {
3571 /* Per-cpu data: */
3572 . = ALIGN(PERCPU_PAGE_SIZE);
3573 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
3574 - __phys_per_cpu_start = __per_cpu_load;
3575 + __phys_per_cpu_start = per_cpu_load;
3576 /*
3577 * ensure percpu data fits
3578 * into percpu page size
3579 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
3580 index 6cf0341..d352594 100644
3581 --- a/arch/ia64/mm/fault.c
3582 +++ b/arch/ia64/mm/fault.c
3583 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
3584 return pte_present(pte);
3585 }
3586
3587 +#ifdef CONFIG_PAX_PAGEEXEC
3588 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3589 +{
3590 + unsigned long i;
3591 +
3592 + printk(KERN_ERR "PAX: bytes at PC: ");
3593 + for (i = 0; i < 8; i++) {
3594 + unsigned int c;
3595 + if (get_user(c, (unsigned int *)pc+i))
3596 + printk(KERN_CONT "???????? ");
3597 + else
3598 + printk(KERN_CONT "%08x ", c);
3599 + }
3600 + printk("\n");
3601 +}
3602 +#endif
3603 +
3604 # define VM_READ_BIT 0
3605 # define VM_WRITE_BIT 1
3606 # define VM_EXEC_BIT 2
3607 @@ -149,8 +166,21 @@ retry:
3608 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
3609 goto bad_area;
3610
3611 - if ((vma->vm_flags & mask) != mask)
3612 + if ((vma->vm_flags & mask) != mask) {
3613 +
3614 +#ifdef CONFIG_PAX_PAGEEXEC
3615 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
3616 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
3617 + goto bad_area;
3618 +
3619 + up_read(&mm->mmap_sem);
3620 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
3621 + do_group_exit(SIGKILL);
3622 + }
3623 +#endif
3624 +
3625 goto bad_area;
3626 + }
3627
3628 /*
3629 * If for any reason at all we couldn't handle the fault, make
3630 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
3631 index 5ca674b..127c3cb 100644
3632 --- a/arch/ia64/mm/hugetlbpage.c
3633 +++ b/arch/ia64/mm/hugetlbpage.c
3634 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3635 unsigned long pgoff, unsigned long flags)
3636 {
3637 struct vm_area_struct *vmm;
3638 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
3639
3640 if (len > RGN_MAP_LIMIT)
3641 return -ENOMEM;
3642 @@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3643 /* At this point: (!vmm || addr < vmm->vm_end). */
3644 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
3645 return -ENOMEM;
3646 - if (!vmm || (addr + len) <= vmm->vm_start)
3647 + if (check_heap_stack_gap(vmm, addr, len, offset))
3648 return addr;
3649 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
3650 }
3651 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
3652 index 082e383..fb7be80 100644
3653 --- a/arch/ia64/mm/init.c
3654 +++ b/arch/ia64/mm/init.c
3655 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
3656 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
3657 vma->vm_end = vma->vm_start + PAGE_SIZE;
3658 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
3659 +
3660 +#ifdef CONFIG_PAX_PAGEEXEC
3661 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
3662 + vma->vm_flags &= ~VM_EXEC;
3663 +
3664 +#ifdef CONFIG_PAX_MPROTECT
3665 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
3666 + vma->vm_flags &= ~VM_MAYEXEC;
3667 +#endif
3668 +
3669 + }
3670 +#endif
3671 +
3672 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
3673 down_write(&current->mm->mmap_sem);
3674 if (insert_vm_struct(current->mm, vma)) {
3675 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
3676 index 40b3ee9..8c2c112 100644
3677 --- a/arch/m32r/include/asm/cache.h
3678 +++ b/arch/m32r/include/asm/cache.h
3679 @@ -1,8 +1,10 @@
3680 #ifndef _ASM_M32R_CACHE_H
3681 #define _ASM_M32R_CACHE_H
3682
3683 +#include <linux/const.h>
3684 +
3685 /* L1 cache line size */
3686 #define L1_CACHE_SHIFT 4
3687 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3688 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3689
3690 #endif /* _ASM_M32R_CACHE_H */
3691 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
3692 index 82abd15..d95ae5d 100644
3693 --- a/arch/m32r/lib/usercopy.c
3694 +++ b/arch/m32r/lib/usercopy.c
3695 @@ -14,6 +14,9 @@
3696 unsigned long
3697 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3698 {
3699 + if ((long)n < 0)
3700 + return n;
3701 +
3702 prefetch(from);
3703 if (access_ok(VERIFY_WRITE, to, n))
3704 __copy_user(to,from,n);
3705 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3706 unsigned long
3707 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
3708 {
3709 + if ((long)n < 0)
3710 + return n;
3711 +
3712 prefetchw(to);
3713 if (access_ok(VERIFY_READ, from, n))
3714 __copy_user_zeroing(to,from,n);
3715 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
3716 index 0395c51..5f26031 100644
3717 --- a/arch/m68k/include/asm/cache.h
3718 +++ b/arch/m68k/include/asm/cache.h
3719 @@ -4,9 +4,11 @@
3720 #ifndef __ARCH_M68K_CACHE_H
3721 #define __ARCH_M68K_CACHE_H
3722
3723 +#include <linux/const.h>
3724 +
3725 /* bytes per L1 cache line */
3726 #define L1_CACHE_SHIFT 4
3727 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
3728 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3729
3730 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
3731
3732 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
3733 index 4efe96a..60e8699 100644
3734 --- a/arch/microblaze/include/asm/cache.h
3735 +++ b/arch/microblaze/include/asm/cache.h
3736 @@ -13,11 +13,12 @@
3737 #ifndef _ASM_MICROBLAZE_CACHE_H
3738 #define _ASM_MICROBLAZE_CACHE_H
3739
3740 +#include <linux/const.h>
3741 #include <asm/registers.h>
3742
3743 #define L1_CACHE_SHIFT 5
3744 /* word-granular cache in microblaze */
3745 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3746 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3747
3748 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3749
3750 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
3751 index 01cc6ba..bcb7a5d 100644
3752 --- a/arch/mips/include/asm/atomic.h
3753 +++ b/arch/mips/include/asm/atomic.h
3754 @@ -21,6 +21,10 @@
3755 #include <asm/cmpxchg.h>
3756 #include <asm/war.h>
3757
3758 +#ifdef CONFIG_GENERIC_ATOMIC64
3759 +#include <asm-generic/atomic64.h>
3760 +#endif
3761 +
3762 #define ATOMIC_INIT(i) { (i) }
3763
3764 /*
3765 @@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3766 */
3767 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
3768
3769 +#define atomic64_read_unchecked(v) atomic64_read(v)
3770 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3771 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3772 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3773 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3774 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3775 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3776 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3777 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3778 +
3779 #endif /* CONFIG_64BIT */
3780
3781 /*
3782 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
3783 index b4db69f..8f3b093 100644
3784 --- a/arch/mips/include/asm/cache.h
3785 +++ b/arch/mips/include/asm/cache.h
3786 @@ -9,10 +9,11 @@
3787 #ifndef _ASM_CACHE_H
3788 #define _ASM_CACHE_H
3789
3790 +#include <linux/const.h>
3791 #include <kmalloc.h>
3792
3793 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
3794 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3795 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3796
3797 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3798 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3799 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
3800 index 455c0ac..ad65fbe 100644
3801 --- a/arch/mips/include/asm/elf.h
3802 +++ b/arch/mips/include/asm/elf.h
3803 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
3804 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
3805 #endif
3806
3807 +#ifdef CONFIG_PAX_ASLR
3808 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3809 +
3810 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3811 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3812 +#endif
3813 +
3814 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
3815 struct linux_binprm;
3816 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3817 int uses_interp);
3818
3819 -struct mm_struct;
3820 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3821 -#define arch_randomize_brk arch_randomize_brk
3822 -
3823 #endif /* _ASM_ELF_H */
3824 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
3825 index c1f6afa..38cc6e9 100644
3826 --- a/arch/mips/include/asm/exec.h
3827 +++ b/arch/mips/include/asm/exec.h
3828 @@ -12,6 +12,6 @@
3829 #ifndef _ASM_EXEC_H
3830 #define _ASM_EXEC_H
3831
3832 -extern unsigned long arch_align_stack(unsigned long sp);
3833 +#define arch_align_stack(x) ((x) & ~0xfUL)
3834
3835 #endif /* _ASM_EXEC_H */
3836 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
3837 index da9bd7d..91aa7ab 100644
3838 --- a/arch/mips/include/asm/page.h
3839 +++ b/arch/mips/include/asm/page.h
3840 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
3841 #ifdef CONFIG_CPU_MIPS32
3842 typedef struct { unsigned long pte_low, pte_high; } pte_t;
3843 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
3844 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
3845 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
3846 #else
3847 typedef struct { unsigned long long pte; } pte_t;
3848 #define pte_val(x) ((x).pte)
3849 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
3850 index 881d18b..cea38bc 100644
3851 --- a/arch/mips/include/asm/pgalloc.h
3852 +++ b/arch/mips/include/asm/pgalloc.h
3853 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3854 {
3855 set_pud(pud, __pud((unsigned long)pmd));
3856 }
3857 +
3858 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3859 +{
3860 + pud_populate(mm, pud, pmd);
3861 +}
3862 #endif
3863
3864 /*
3865 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
3866 index 18806a5..141ffcf 100644
3867 --- a/arch/mips/include/asm/thread_info.h
3868 +++ b/arch/mips/include/asm/thread_info.h
3869 @@ -110,6 +110,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
3870 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
3871 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
3872 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
3873 +/* li takes a 32bit immediate */
3874 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
3875 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
3876
3877 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3878 @@ -125,15 +127,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
3879 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
3880 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
3881 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
3882 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3883 +
3884 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3885
3886 /* work to do in syscall_trace_leave() */
3887 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
3888 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3889
3890 /* work to do on interrupt/exception return */
3891 #define _TIF_WORK_MASK \
3892 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
3893 /* work to do on any return to u-space */
3894 -#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
3895 +#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
3896
3897 #endif /* __KERNEL__ */
3898
3899 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
3900 index 9fdd8bc..4bd7f1a 100644
3901 --- a/arch/mips/kernel/binfmt_elfn32.c
3902 +++ b/arch/mips/kernel/binfmt_elfn32.c
3903 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3904 #undef ELF_ET_DYN_BASE
3905 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3906
3907 +#ifdef CONFIG_PAX_ASLR
3908 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3909 +
3910 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3911 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3912 +#endif
3913 +
3914 #include <asm/processor.h>
3915 #include <linux/module.h>
3916 #include <linux/elfcore.h>
3917 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
3918 index ff44823..97f8906 100644
3919 --- a/arch/mips/kernel/binfmt_elfo32.c
3920 +++ b/arch/mips/kernel/binfmt_elfo32.c
3921 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3922 #undef ELF_ET_DYN_BASE
3923 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3924
3925 +#ifdef CONFIG_PAX_ASLR
3926 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3927 +
3928 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3929 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3930 +#endif
3931 +
3932 #include <asm/processor.h>
3933
3934 /*
3935 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
3936 index 69b17a9..9db82f9 100644
3937 --- a/arch/mips/kernel/process.c
3938 +++ b/arch/mips/kernel/process.c
3939 @@ -478,15 +478,3 @@ unsigned long get_wchan(struct task_struct *task)
3940 out:
3941 return pc;
3942 }
3943 -
3944 -/*
3945 - * Don't forget that the stack pointer must be aligned on a 8 bytes
3946 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
3947 - */
3948 -unsigned long arch_align_stack(unsigned long sp)
3949 -{
3950 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3951 - sp -= get_random_int() & ~PAGE_MASK;
3952 -
3953 - return sp & ALMASK;
3954 -}
3955 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
3956 index 4812c6d..2069554 100644
3957 --- a/arch/mips/kernel/ptrace.c
3958 +++ b/arch/mips/kernel/ptrace.c
3959 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
3960 return arch;
3961 }
3962
3963 +#ifdef CONFIG_GRKERNSEC_SETXID
3964 +extern void gr_delayed_cred_worker(void);
3965 +#endif
3966 +
3967 /*
3968 * Notification of system call entry/exit
3969 * - triggered by current->work.syscall_trace
3970 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3971 /* do the secure computing check first */
3972 secure_computing_strict(regs->regs[2]);
3973
3974 +#ifdef CONFIG_GRKERNSEC_SETXID
3975 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3976 + gr_delayed_cred_worker();
3977 +#endif
3978 +
3979 if (!(current->ptrace & PT_PTRACED))
3980 goto out;
3981
3982 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3983 index 374f66e..1c882a0 100644
3984 --- a/arch/mips/kernel/scall32-o32.S
3985 +++ b/arch/mips/kernel/scall32-o32.S
3986 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3987
3988 stack_done:
3989 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3990 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3991 + li t1, _TIF_SYSCALL_WORK
3992 and t0, t1
3993 bnez t0, syscall_trace_entry # -> yes
3994
3995 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3996 index 169de6a..f594a89 100644
3997 --- a/arch/mips/kernel/scall64-64.S
3998 +++ b/arch/mips/kernel/scall64-64.S
3999 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
4000
4001 sd a3, PT_R26(sp) # save a3 for syscall restarting
4002
4003 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4004 + li t1, _TIF_SYSCALL_WORK
4005 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4006 and t0, t1, t0
4007 bnez t0, syscall_trace_entry
4008 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
4009 index 86ec03f..1235baf 100644
4010 --- a/arch/mips/kernel/scall64-n32.S
4011 +++ b/arch/mips/kernel/scall64-n32.S
4012 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
4013
4014 sd a3, PT_R26(sp) # save a3 for syscall restarting
4015
4016 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4017 + li t1, _TIF_SYSCALL_WORK
4018 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4019 and t0, t1, t0
4020 bnez t0, n32_syscall_trace_entry
4021 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
4022 index 53c2d72..3734584 100644
4023 --- a/arch/mips/kernel/scall64-o32.S
4024 +++ b/arch/mips/kernel/scall64-o32.S
4025 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
4026 PTR 4b, bad_stack
4027 .previous
4028
4029 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4030 + li t1, _TIF_SYSCALL_WORK
4031 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4032 and t0, t1, t0
4033 bnez t0, trace_a_syscall
4034 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
4035 index ddcec1e..c7f983e 100644
4036 --- a/arch/mips/mm/fault.c
4037 +++ b/arch/mips/mm/fault.c
4038 @@ -27,6 +27,23 @@
4039 #include <asm/highmem.h> /* For VMALLOC_END */
4040 #include <linux/kdebug.h>
4041
4042 +#ifdef CONFIG_PAX_PAGEEXEC
4043 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4044 +{
4045 + unsigned long i;
4046 +
4047 + printk(KERN_ERR "PAX: bytes at PC: ");
4048 + for (i = 0; i < 5; i++) {
4049 + unsigned int c;
4050 + if (get_user(c, (unsigned int *)pc+i))
4051 + printk(KERN_CONT "???????? ");
4052 + else
4053 + printk(KERN_CONT "%08x ", c);
4054 + }
4055 + printk("\n");
4056 +}
4057 +#endif
4058 +
4059 /*
4060 * This routine handles page faults. It determines the address,
4061 * and the problem, and then passes it off to one of the appropriate
4062 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
4063 index 302d779..6459dc0 100644
4064 --- a/arch/mips/mm/mmap.c
4065 +++ b/arch/mips/mm/mmap.c
4066 @@ -71,6 +71,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4067 struct vm_area_struct *vma;
4068 unsigned long addr = addr0;
4069 int do_color_align;
4070 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4071
4072 if (unlikely(len > TASK_SIZE))
4073 return -ENOMEM;
4074 @@ -95,6 +96,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4075 do_color_align = 1;
4076
4077 /* requesting a specific address */
4078 +
4079 +#ifdef CONFIG_PAX_RANDMMAP
4080 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
4081 +#endif
4082 +
4083 if (addr) {
4084 if (do_color_align)
4085 addr = COLOUR_ALIGN(addr, pgoff);
4086 @@ -102,8 +108,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4087 addr = PAGE_ALIGN(addr);
4088
4089 vma = find_vma(mm, addr);
4090 - if (TASK_SIZE - len >= addr &&
4091 - (!vma || addr + len <= vma->vm_start))
4092 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
4093 return addr;
4094 }
4095
4096 @@ -118,7 +123,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4097 /* At this point: (!vma || addr < vma->vm_end). */
4098 if (TASK_SIZE - len < addr)
4099 return -ENOMEM;
4100 - if (!vma || addr + len <= vma->vm_start)
4101 + if (check_heap_stack_gap(vmm, addr, len, offset))
4102 return addr;
4103 addr = vma->vm_end;
4104 if (do_color_align)
4105 @@ -145,7 +150,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4106 /* make sure it can fit in the remaining address space */
4107 if (likely(addr > len)) {
4108 vma = find_vma(mm, addr - len);
4109 - if (!vma || addr <= vma->vm_start) {
4110 + if (check_heap_stack_gap(vmm, addr - len, len, offset))
4111 /* cache the address as a hint for next time */
4112 return mm->free_area_cache = addr - len;
4113 }
4114 @@ -155,17 +160,17 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4115 goto bottomup;
4116
4117 addr = mm->mmap_base - len;
4118 - if (do_color_align)
4119 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4120
4121 do {
4122 + if (do_color_align)
4123 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4124 /*
4125 * Lookup failure means no vma is above this address,
4126 * else if new region fits below vma->vm_start,
4127 * return with success:
4128 */
4129 vma = find_vma(mm, addr);
4130 - if (likely(!vma || addr + len <= vma->vm_start)) {
4131 + if (check_heap_stack_gap(vmm, addr, len, offset)) {
4132 /* cache the address as a hint for next time */
4133 return mm->free_area_cache = addr;
4134 }
4135 @@ -175,10 +180,8 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4136 mm->cached_hole_size = vma->vm_start - addr;
4137
4138 /* try just below the current vma->vm_start */
4139 - addr = vma->vm_start - len;
4140 - if (do_color_align)
4141 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4142 - } while (likely(len < vma->vm_start));
4143 + addr = skip_heap_stack_gap(vma, len, offset);
4144 + } while (!IS_ERR_VALUE(addr));
4145
4146 bottomup:
4147 /*
4148 @@ -223,6 +226,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4149 {
4150 unsigned long random_factor = 0UL;
4151
4152 +#ifdef CONFIG_PAX_RANDMMAP
4153 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
4154 +#endif
4155 +
4156 if (current->flags & PF_RANDOMIZE) {
4157 random_factor = get_random_int();
4158 random_factor = random_factor << PAGE_SHIFT;
4159 @@ -234,38 +241,23 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4160
4161 if (mmap_is_legacy()) {
4162 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4163 +
4164 +#ifdef CONFIG_PAX_RANDMMAP
4165 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4166 + mm->mmap_base += mm->delta_mmap;
4167 +#endif
4168 +
4169 mm->get_unmapped_area = arch_get_unmapped_area;
4170 mm->unmap_area = arch_unmap_area;
4171 } else {
4172 mm->mmap_base = mmap_base(random_factor);
4173 +
4174 +#ifdef CONFIG_PAX_RANDMMAP
4175 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4176 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4177 +#endif
4178 +
4179 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4180 mm->unmap_area = arch_unmap_area_topdown;
4181 }
4182 }
4183 -
4184 -static inline unsigned long brk_rnd(void)
4185 -{
4186 - unsigned long rnd = get_random_int();
4187 -
4188 - rnd = rnd << PAGE_SHIFT;
4189 - /* 8MB for 32bit, 256MB for 64bit */
4190 - if (TASK_IS_32BIT_ADDR)
4191 - rnd = rnd & 0x7ffffful;
4192 - else
4193 - rnd = rnd & 0xffffffful;
4194 -
4195 - return rnd;
4196 -}
4197 -
4198 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4199 -{
4200 - unsigned long base = mm->brk;
4201 - unsigned long ret;
4202 -
4203 - ret = PAGE_ALIGN(base + brk_rnd());
4204 -
4205 - if (ret < mm->brk)
4206 - return mm->brk;
4207 -
4208 - return ret;
4209 -}
4210 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
4211 index 967d144..db12197 100644
4212 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
4213 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
4214 @@ -11,12 +11,14 @@
4215 #ifndef _ASM_PROC_CACHE_H
4216 #define _ASM_PROC_CACHE_H
4217
4218 +#include <linux/const.h>
4219 +
4220 /* L1 cache */
4221
4222 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4223 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
4224 -#define L1_CACHE_BYTES 16 /* bytes per entry */
4225 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
4226 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4227 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
4228
4229 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4230 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4231 index bcb5df2..84fabd2 100644
4232 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4233 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4234 @@ -16,13 +16,15 @@
4235 #ifndef _ASM_PROC_CACHE_H
4236 #define _ASM_PROC_CACHE_H
4237
4238 +#include <linux/const.h>
4239 +
4240 /*
4241 * L1 cache
4242 */
4243 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4244 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
4245 -#define L1_CACHE_BYTES 32 /* bytes per entry */
4246 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
4247 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4248 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
4249
4250 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4251 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
4252 index 4ce7a01..449202a 100644
4253 --- a/arch/openrisc/include/asm/cache.h
4254 +++ b/arch/openrisc/include/asm/cache.h
4255 @@ -19,11 +19,13 @@
4256 #ifndef __ASM_OPENRISC_CACHE_H
4257 #define __ASM_OPENRISC_CACHE_H
4258
4259 +#include <linux/const.h>
4260 +
4261 /* FIXME: How can we replace these with values from the CPU...
4262 * they shouldn't be hard-coded!
4263 */
4264
4265 -#define L1_CACHE_BYTES 16
4266 #define L1_CACHE_SHIFT 4
4267 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4268
4269 #endif /* __ASM_OPENRISC_CACHE_H */
4270 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
4271 index af9cf30..2aae9b2 100644
4272 --- a/arch/parisc/include/asm/atomic.h
4273 +++ b/arch/parisc/include/asm/atomic.h
4274 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
4275
4276 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4277
4278 +#define atomic64_read_unchecked(v) atomic64_read(v)
4279 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4280 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4281 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4282 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4283 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4284 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4285 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4286 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4287 +
4288 #endif /* !CONFIG_64BIT */
4289
4290
4291 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
4292 index 47f11c7..3420df2 100644
4293 --- a/arch/parisc/include/asm/cache.h
4294 +++ b/arch/parisc/include/asm/cache.h
4295 @@ -5,6 +5,7 @@
4296 #ifndef __ARCH_PARISC_CACHE_H
4297 #define __ARCH_PARISC_CACHE_H
4298
4299 +#include <linux/const.h>
4300
4301 /*
4302 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
4303 @@ -15,13 +16,13 @@
4304 * just ruin performance.
4305 */
4306 #ifdef CONFIG_PA20
4307 -#define L1_CACHE_BYTES 64
4308 #define L1_CACHE_SHIFT 6
4309 #else
4310 -#define L1_CACHE_BYTES 32
4311 #define L1_CACHE_SHIFT 5
4312 #endif
4313
4314 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4315 +
4316 #ifndef __ASSEMBLY__
4317
4318 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4319 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
4320 index 19f6cb1..6c78cf2 100644
4321 --- a/arch/parisc/include/asm/elf.h
4322 +++ b/arch/parisc/include/asm/elf.h
4323 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
4324
4325 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
4326
4327 +#ifdef CONFIG_PAX_ASLR
4328 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
4329 +
4330 +#define PAX_DELTA_MMAP_LEN 16
4331 +#define PAX_DELTA_STACK_LEN 16
4332 +#endif
4333 +
4334 /* This yields a mask that user programs can use to figure out what
4335 instruction set this CPU supports. This could be done in user space,
4336 but it's not easy, and we've already done it here. */
4337 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
4338 index fc987a1..6e068ef 100644
4339 --- a/arch/parisc/include/asm/pgalloc.h
4340 +++ b/arch/parisc/include/asm/pgalloc.h
4341 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4342 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
4343 }
4344
4345 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4346 +{
4347 + pgd_populate(mm, pgd, pmd);
4348 +}
4349 +
4350 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
4351 {
4352 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
4353 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
4354 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
4355 #define pmd_free(mm, x) do { } while (0)
4356 #define pgd_populate(mm, pmd, pte) BUG()
4357 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
4358
4359 #endif
4360
4361 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
4362 index ee99f23..802b0a1 100644
4363 --- a/arch/parisc/include/asm/pgtable.h
4364 +++ b/arch/parisc/include/asm/pgtable.h
4365 @@ -212,6 +212,17 @@ struct vm_area_struct;
4366 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
4367 #define PAGE_COPY PAGE_EXECREAD
4368 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
4369 +
4370 +#ifdef CONFIG_PAX_PAGEEXEC
4371 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
4372 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4373 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4374 +#else
4375 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4376 +# define PAGE_COPY_NOEXEC PAGE_COPY
4377 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4378 +#endif
4379 +
4380 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
4381 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
4382 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
4383 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
4384 index 4ba2c93..f5e3974 100644
4385 --- a/arch/parisc/include/asm/uaccess.h
4386 +++ b/arch/parisc/include/asm/uaccess.h
4387 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
4388 const void __user *from,
4389 unsigned long n)
4390 {
4391 - int sz = __compiletime_object_size(to);
4392 + size_t sz = __compiletime_object_size(to);
4393 int ret = -EFAULT;
4394
4395 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
4396 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
4397 ret = __copy_from_user(to, from, n);
4398 else
4399 copy_from_user_overflow();
4400 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
4401 index 5e34ccf..672bc9c 100644
4402 --- a/arch/parisc/kernel/module.c
4403 +++ b/arch/parisc/kernel/module.c
4404 @@ -98,16 +98,38 @@
4405
4406 /* three functions to determine where in the module core
4407 * or init pieces the location is */
4408 +static inline int in_init_rx(struct module *me, void *loc)
4409 +{
4410 + return (loc >= me->module_init_rx &&
4411 + loc < (me->module_init_rx + me->init_size_rx));
4412 +}
4413 +
4414 +static inline int in_init_rw(struct module *me, void *loc)
4415 +{
4416 + return (loc >= me->module_init_rw &&
4417 + loc < (me->module_init_rw + me->init_size_rw));
4418 +}
4419 +
4420 static inline int in_init(struct module *me, void *loc)
4421 {
4422 - return (loc >= me->module_init &&
4423 - loc <= (me->module_init + me->init_size));
4424 + return in_init_rx(me, loc) || in_init_rw(me, loc);
4425 +}
4426 +
4427 +static inline int in_core_rx(struct module *me, void *loc)
4428 +{
4429 + return (loc >= me->module_core_rx &&
4430 + loc < (me->module_core_rx + me->core_size_rx));
4431 +}
4432 +
4433 +static inline int in_core_rw(struct module *me, void *loc)
4434 +{
4435 + return (loc >= me->module_core_rw &&
4436 + loc < (me->module_core_rw + me->core_size_rw));
4437 }
4438
4439 static inline int in_core(struct module *me, void *loc)
4440 {
4441 - return (loc >= me->module_core &&
4442 - loc <= (me->module_core + me->core_size));
4443 + return in_core_rx(me, loc) || in_core_rw(me, loc);
4444 }
4445
4446 static inline int in_local(struct module *me, void *loc)
4447 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
4448 }
4449
4450 /* align things a bit */
4451 - me->core_size = ALIGN(me->core_size, 16);
4452 - me->arch.got_offset = me->core_size;
4453 - me->core_size += gots * sizeof(struct got_entry);
4454 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
4455 + me->arch.got_offset = me->core_size_rw;
4456 + me->core_size_rw += gots * sizeof(struct got_entry);
4457
4458 - me->core_size = ALIGN(me->core_size, 16);
4459 - me->arch.fdesc_offset = me->core_size;
4460 - me->core_size += fdescs * sizeof(Elf_Fdesc);
4461 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
4462 + me->arch.fdesc_offset = me->core_size_rw;
4463 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
4464
4465 me->arch.got_max = gots;
4466 me->arch.fdesc_max = fdescs;
4467 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4468
4469 BUG_ON(value == 0);
4470
4471 - got = me->module_core + me->arch.got_offset;
4472 + got = me->module_core_rw + me->arch.got_offset;
4473 for (i = 0; got[i].addr; i++)
4474 if (got[i].addr == value)
4475 goto out;
4476 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4477 #ifdef CONFIG_64BIT
4478 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4479 {
4480 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
4481 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
4482
4483 if (!value) {
4484 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
4485 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4486
4487 /* Create new one */
4488 fdesc->addr = value;
4489 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4490 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4491 return (Elf_Addr)fdesc;
4492 }
4493 #endif /* CONFIG_64BIT */
4494 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
4495
4496 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
4497 end = table + sechdrs[me->arch.unwind_section].sh_size;
4498 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4499 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4500
4501 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
4502 me->arch.unwind_section, table, end, gp);
4503 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
4504 index f76c108..92bad82 100644
4505 --- a/arch/parisc/kernel/sys_parisc.c
4506 +++ b/arch/parisc/kernel/sys_parisc.c
4507 @@ -33,9 +33,11 @@
4508 #include <linux/utsname.h>
4509 #include <linux/personality.h>
4510
4511 -static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4512 +static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
4513 + unsigned long flags)
4514 {
4515 struct vm_area_struct *vma;
4516 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4517
4518 addr = PAGE_ALIGN(addr);
4519
4520 @@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4521 /* At this point: (!vma || addr < vma->vm_end). */
4522 if (TASK_SIZE - len < addr)
4523 return -ENOMEM;
4524 - if (!vma || addr + len <= vma->vm_start)
4525 + if (check_heap_stack_gap(vma, addr, len, offset))
4526 return addr;
4527 addr = vma->vm_end;
4528 }
4529 @@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
4530 return offset & 0x3FF000;
4531 }
4532
4533 -static unsigned long get_shared_area(struct address_space *mapping,
4534 - unsigned long addr, unsigned long len, unsigned long pgoff)
4535 +static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
4536 + unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
4537 {
4538 struct vm_area_struct *vma;
4539 int offset = mapping ? get_offset(mapping) : 0;
4540 + unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4541
4542 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
4543
4544 @@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
4545 /* At this point: (!vma || addr < vma->vm_end). */
4546 if (TASK_SIZE - len < addr)
4547 return -ENOMEM;
4548 - if (!vma || addr + len <= vma->vm_start)
4549 + if (check_heap_stack_gap(vma, addr, len, rand_offset))
4550 return addr;
4551 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
4552 if (addr < vma->vm_end) /* handle wraparound */
4553 @@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4554 if (flags & MAP_FIXED)
4555 return addr;
4556 if (!addr)
4557 - addr = TASK_UNMAPPED_BASE;
4558 + addr = current->mm->mmap_base;
4559
4560 if (filp) {
4561 - addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
4562 + addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
4563 } else if(flags & MAP_SHARED) {
4564 - addr = get_shared_area(NULL, addr, len, pgoff);
4565 + addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
4566 } else {
4567 - addr = get_unshared_area(addr, len);
4568 + addr = get_unshared_area(filp, addr, len, flags);
4569 }
4570 return addr;
4571 }
4572 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
4573 index 45ba99f..8e22c33 100644
4574 --- a/arch/parisc/kernel/traps.c
4575 +++ b/arch/parisc/kernel/traps.c
4576 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
4577
4578 down_read(&current->mm->mmap_sem);
4579 vma = find_vma(current->mm,regs->iaoq[0]);
4580 - if (vma && (regs->iaoq[0] >= vma->vm_start)
4581 - && (vma->vm_flags & VM_EXEC)) {
4582 -
4583 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
4584 fault_address = regs->iaoq[0];
4585 fault_space = regs->iasq[0];
4586
4587 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
4588 index 18162ce..94de376 100644
4589 --- a/arch/parisc/mm/fault.c
4590 +++ b/arch/parisc/mm/fault.c
4591 @@ -15,6 +15,7 @@
4592 #include <linux/sched.h>
4593 #include <linux/interrupt.h>
4594 #include <linux/module.h>
4595 +#include <linux/unistd.h>
4596
4597 #include <asm/uaccess.h>
4598 #include <asm/traps.h>
4599 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
4600 static unsigned long
4601 parisc_acctyp(unsigned long code, unsigned int inst)
4602 {
4603 - if (code == 6 || code == 16)
4604 + if (code == 6 || code == 7 || code == 16)
4605 return VM_EXEC;
4606
4607 switch (inst & 0xf0000000) {
4608 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
4609 }
4610 #endif
4611
4612 +#ifdef CONFIG_PAX_PAGEEXEC
4613 +/*
4614 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
4615 + *
4616 + * returns 1 when task should be killed
4617 + * 2 when rt_sigreturn trampoline was detected
4618 + * 3 when unpatched PLT trampoline was detected
4619 + */
4620 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4621 +{
4622 +
4623 +#ifdef CONFIG_PAX_EMUPLT
4624 + int err;
4625 +
4626 + do { /* PaX: unpatched PLT emulation */
4627 + unsigned int bl, depwi;
4628 +
4629 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
4630 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
4631 +
4632 + if (err)
4633 + break;
4634 +
4635 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
4636 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
4637 +
4638 + err = get_user(ldw, (unsigned int *)addr);
4639 + err |= get_user(bv, (unsigned int *)(addr+4));
4640 + err |= get_user(ldw2, (unsigned int *)(addr+8));
4641 +
4642 + if (err)
4643 + break;
4644 +
4645 + if (ldw == 0x0E801096U &&
4646 + bv == 0xEAC0C000U &&
4647 + ldw2 == 0x0E881095U)
4648 + {
4649 + unsigned int resolver, map;
4650 +
4651 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
4652 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
4653 + if (err)
4654 + break;
4655 +
4656 + regs->gr[20] = instruction_pointer(regs)+8;
4657 + regs->gr[21] = map;
4658 + regs->gr[22] = resolver;
4659 + regs->iaoq[0] = resolver | 3UL;
4660 + regs->iaoq[1] = regs->iaoq[0] + 4;
4661 + return 3;
4662 + }
4663 + }
4664 + } while (0);
4665 +#endif
4666 +
4667 +#ifdef CONFIG_PAX_EMUTRAMP
4668 +
4669 +#ifndef CONFIG_PAX_EMUSIGRT
4670 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
4671 + return 1;
4672 +#endif
4673 +
4674 + do { /* PaX: rt_sigreturn emulation */
4675 + unsigned int ldi1, ldi2, bel, nop;
4676 +
4677 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
4678 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
4679 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
4680 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
4681 +
4682 + if (err)
4683 + break;
4684 +
4685 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
4686 + ldi2 == 0x3414015AU &&
4687 + bel == 0xE4008200U &&
4688 + nop == 0x08000240U)
4689 + {
4690 + regs->gr[25] = (ldi1 & 2) >> 1;
4691 + regs->gr[20] = __NR_rt_sigreturn;
4692 + regs->gr[31] = regs->iaoq[1] + 16;
4693 + regs->sr[0] = regs->iasq[1];
4694 + regs->iaoq[0] = 0x100UL;
4695 + regs->iaoq[1] = regs->iaoq[0] + 4;
4696 + regs->iasq[0] = regs->sr[2];
4697 + regs->iasq[1] = regs->sr[2];
4698 + return 2;
4699 + }
4700 + } while (0);
4701 +#endif
4702 +
4703 + return 1;
4704 +}
4705 +
4706 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4707 +{
4708 + unsigned long i;
4709 +
4710 + printk(KERN_ERR "PAX: bytes at PC: ");
4711 + for (i = 0; i < 5; i++) {
4712 + unsigned int c;
4713 + if (get_user(c, (unsigned int *)pc+i))
4714 + printk(KERN_CONT "???????? ");
4715 + else
4716 + printk(KERN_CONT "%08x ", c);
4717 + }
4718 + printk("\n");
4719 +}
4720 +#endif
4721 +
4722 int fixup_exception(struct pt_regs *regs)
4723 {
4724 const struct exception_table_entry *fix;
4725 @@ -192,8 +303,33 @@ good_area:
4726
4727 acc_type = parisc_acctyp(code,regs->iir);
4728
4729 - if ((vma->vm_flags & acc_type) != acc_type)
4730 + if ((vma->vm_flags & acc_type) != acc_type) {
4731 +
4732 +#ifdef CONFIG_PAX_PAGEEXEC
4733 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
4734 + (address & ~3UL) == instruction_pointer(regs))
4735 + {
4736 + up_read(&mm->mmap_sem);
4737 + switch (pax_handle_fetch_fault(regs)) {
4738 +
4739 +#ifdef CONFIG_PAX_EMUPLT
4740 + case 3:
4741 + return;
4742 +#endif
4743 +
4744 +#ifdef CONFIG_PAX_EMUTRAMP
4745 + case 2:
4746 + return;
4747 +#endif
4748 +
4749 + }
4750 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
4751 + do_group_exit(SIGKILL);
4752 + }
4753 +#endif
4754 +
4755 goto bad_area;
4756 + }
4757
4758 /*
4759 * If for any reason at all we couldn't handle the fault, make
4760 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
4761 index e3b1d41..8e81edf 100644
4762 --- a/arch/powerpc/include/asm/atomic.h
4763 +++ b/arch/powerpc/include/asm/atomic.h
4764 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
4765 return t1;
4766 }
4767
4768 +#define atomic64_read_unchecked(v) atomic64_read(v)
4769 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4770 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4771 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4772 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4773 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4774 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4775 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4776 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4777 +
4778 #endif /* __powerpc64__ */
4779
4780 #endif /* __KERNEL__ */
4781 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
4782 index 9e495c9..b6878e5 100644
4783 --- a/arch/powerpc/include/asm/cache.h
4784 +++ b/arch/powerpc/include/asm/cache.h
4785 @@ -3,6 +3,7 @@
4786
4787 #ifdef __KERNEL__
4788
4789 +#include <linux/const.h>
4790
4791 /* bytes per L1 cache line */
4792 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
4793 @@ -22,7 +23,7 @@
4794 #define L1_CACHE_SHIFT 7
4795 #endif
4796
4797 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4798 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4799
4800 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4801
4802 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
4803 index 6abf0a1..459d0f1 100644
4804 --- a/arch/powerpc/include/asm/elf.h
4805 +++ b/arch/powerpc/include/asm/elf.h
4806 @@ -28,8 +28,19 @@
4807 the loader. We need to make sure that it is out of the way of the program
4808 that it will "exec", and that there is sufficient room for the brk. */
4809
4810 -extern unsigned long randomize_et_dyn(unsigned long base);
4811 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
4812 +#define ELF_ET_DYN_BASE (0x20000000)
4813 +
4814 +#ifdef CONFIG_PAX_ASLR
4815 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
4816 +
4817 +#ifdef __powerpc64__
4818 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
4819 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
4820 +#else
4821 +#define PAX_DELTA_MMAP_LEN 15
4822 +#define PAX_DELTA_STACK_LEN 15
4823 +#endif
4824 +#endif
4825
4826 /*
4827 * Our registers are always unsigned longs, whether we're a 32 bit
4828 @@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
4829 (0x7ff >> (PAGE_SHIFT - 12)) : \
4830 (0x3ffff >> (PAGE_SHIFT - 12)))
4831
4832 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4833 -#define arch_randomize_brk arch_randomize_brk
4834 -
4835 -
4836 #ifdef CONFIG_SPU_BASE
4837 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
4838 #define NT_SPU 1
4839 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
4840 index 8196e9c..d83a9f3 100644
4841 --- a/arch/powerpc/include/asm/exec.h
4842 +++ b/arch/powerpc/include/asm/exec.h
4843 @@ -4,6 +4,6 @@
4844 #ifndef _ASM_POWERPC_EXEC_H
4845 #define _ASM_POWERPC_EXEC_H
4846
4847 -extern unsigned long arch_align_stack(unsigned long sp);
4848 +#define arch_align_stack(x) ((x) & ~0xfUL)
4849
4850 #endif /* _ASM_POWERPC_EXEC_H */
4851 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
4852 index 5acabbd..7ea14fa 100644
4853 --- a/arch/powerpc/include/asm/kmap_types.h
4854 +++ b/arch/powerpc/include/asm/kmap_types.h
4855 @@ -10,7 +10,7 @@
4856 * 2 of the License, or (at your option) any later version.
4857 */
4858
4859 -#define KM_TYPE_NR 16
4860 +#define KM_TYPE_NR 17
4861
4862 #endif /* __KERNEL__ */
4863 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
4864 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
4865 index 8565c25..2865190 100644
4866 --- a/arch/powerpc/include/asm/mman.h
4867 +++ b/arch/powerpc/include/asm/mman.h
4868 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
4869 }
4870 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
4871
4872 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
4873 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
4874 {
4875 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
4876 }
4877 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
4878 index f072e97..b436dee 100644
4879 --- a/arch/powerpc/include/asm/page.h
4880 +++ b/arch/powerpc/include/asm/page.h
4881 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
4882 * and needs to be executable. This means the whole heap ends
4883 * up being executable.
4884 */
4885 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4886 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4887 +#define VM_DATA_DEFAULT_FLAGS32 \
4888 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4889 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4890
4891 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4892 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4893 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
4894 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
4895 #endif
4896
4897 +#define ktla_ktva(addr) (addr)
4898 +#define ktva_ktla(addr) (addr)
4899 +
4900 /*
4901 * Use the top bit of the higher-level page table entries to indicate whether
4902 * the entries we point to contain hugepages. This works because we know that
4903 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
4904 index cd915d6..c10cee8 100644
4905 --- a/arch/powerpc/include/asm/page_64.h
4906 +++ b/arch/powerpc/include/asm/page_64.h
4907 @@ -154,15 +154,18 @@ do { \
4908 * stack by default, so in the absence of a PT_GNU_STACK program header
4909 * we turn execute permission off.
4910 */
4911 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4912 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4913 +#define VM_STACK_DEFAULT_FLAGS32 \
4914 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4915 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4916
4917 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4918 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4919
4920 +#ifndef CONFIG_PAX_PAGEEXEC
4921 #define VM_STACK_DEFAULT_FLAGS \
4922 (is_32bit_task() ? \
4923 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
4924 +#endif
4925
4926 #include <asm-generic/getorder.h>
4927
4928 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
4929 index 292725c..f87ae14 100644
4930 --- a/arch/powerpc/include/asm/pgalloc-64.h
4931 +++ b/arch/powerpc/include/asm/pgalloc-64.h
4932 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
4933 #ifndef CONFIG_PPC_64K_PAGES
4934
4935 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
4936 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
4937
4938 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4939 {
4940 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4941 pud_set(pud, (unsigned long)pmd);
4942 }
4943
4944 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4945 +{
4946 + pud_populate(mm, pud, pmd);
4947 +}
4948 +
4949 #define pmd_populate(mm, pmd, pte_page) \
4950 pmd_populate_kernel(mm, pmd, page_address(pte_page))
4951 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
4952 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4953 #else /* CONFIG_PPC_64K_PAGES */
4954
4955 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
4956 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
4957
4958 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
4959 pte_t *pte)
4960 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
4961 index a9cbd3b..3b67efa 100644
4962 --- a/arch/powerpc/include/asm/pgtable.h
4963 +++ b/arch/powerpc/include/asm/pgtable.h
4964 @@ -2,6 +2,7 @@
4965 #define _ASM_POWERPC_PGTABLE_H
4966 #ifdef __KERNEL__
4967
4968 +#include <linux/const.h>
4969 #ifndef __ASSEMBLY__
4970 #include <asm/processor.h> /* For TASK_SIZE */
4971 #include <asm/mmu.h>
4972 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
4973 index 4aad413..85d86bf 100644
4974 --- a/arch/powerpc/include/asm/pte-hash32.h
4975 +++ b/arch/powerpc/include/asm/pte-hash32.h
4976 @@ -21,6 +21,7 @@
4977 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
4978 #define _PAGE_USER 0x004 /* usermode access allowed */
4979 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
4980 +#define _PAGE_EXEC _PAGE_GUARDED
4981 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
4982 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
4983 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
4984 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
4985 index d24c141..b60696e 100644
4986 --- a/arch/powerpc/include/asm/reg.h
4987 +++ b/arch/powerpc/include/asm/reg.h
4988 @@ -215,6 +215,7 @@
4989 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
4990 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
4991 #define DSISR_NOHPTE 0x40000000 /* no translation found */
4992 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
4993 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
4994 #define DSISR_ISSTORE 0x02000000 /* access was a store */
4995 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
4996 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
4997 index 406b7b9..af63426 100644
4998 --- a/arch/powerpc/include/asm/thread_info.h
4999 +++ b/arch/powerpc/include/asm/thread_info.h
5000 @@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
5001 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
5002 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
5003 #define TIF_SINGLESTEP 8 /* singlestepping active */
5004 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
5005 #define TIF_SECCOMP 10 /* secure computing */
5006 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
5007 #define TIF_NOERROR 12 /* Force successful syscall return */
5008 @@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
5009 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
5010 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
5011 for stack store? */
5012 +#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
5013 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
5014 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
5015
5016 /* as above, but as bit values */
5017 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5018 @@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
5019 #define _TIF_UPROBE (1<<TIF_UPROBE)
5020 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5021 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
5022 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5023 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
5024 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
5025 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
5026 + _TIF_GRSEC_SETXID)
5027
5028 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
5029 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
5030 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
5031 index 4db4959..335e00c 100644
5032 --- a/arch/powerpc/include/asm/uaccess.h
5033 +++ b/arch/powerpc/include/asm/uaccess.h
5034 @@ -13,6 +13,8 @@
5035 #define VERIFY_READ 0
5036 #define VERIFY_WRITE 1
5037
5038 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5039 +
5040 /*
5041 * The fs value determines whether argument validity checking should be
5042 * performed or not. If get_fs() == USER_DS, checking is performed, with
5043 @@ -318,52 +320,6 @@ do { \
5044 extern unsigned long __copy_tofrom_user(void __user *to,
5045 const void __user *from, unsigned long size);
5046
5047 -#ifndef __powerpc64__
5048 -
5049 -static inline unsigned long copy_from_user(void *to,
5050 - const void __user *from, unsigned long n)
5051 -{
5052 - unsigned long over;
5053 -
5054 - if (access_ok(VERIFY_READ, from, n))
5055 - return __copy_tofrom_user((__force void __user *)to, from, n);
5056 - if ((unsigned long)from < TASK_SIZE) {
5057 - over = (unsigned long)from + n - TASK_SIZE;
5058 - return __copy_tofrom_user((__force void __user *)to, from,
5059 - n - over) + over;
5060 - }
5061 - return n;
5062 -}
5063 -
5064 -static inline unsigned long copy_to_user(void __user *to,
5065 - const void *from, unsigned long n)
5066 -{
5067 - unsigned long over;
5068 -
5069 - if (access_ok(VERIFY_WRITE, to, n))
5070 - return __copy_tofrom_user(to, (__force void __user *)from, n);
5071 - if ((unsigned long)to < TASK_SIZE) {
5072 - over = (unsigned long)to + n - TASK_SIZE;
5073 - return __copy_tofrom_user(to, (__force void __user *)from,
5074 - n - over) + over;
5075 - }
5076 - return n;
5077 -}
5078 -
5079 -#else /* __powerpc64__ */
5080 -
5081 -#define __copy_in_user(to, from, size) \
5082 - __copy_tofrom_user((to), (from), (size))
5083 -
5084 -extern unsigned long copy_from_user(void *to, const void __user *from,
5085 - unsigned long n);
5086 -extern unsigned long copy_to_user(void __user *to, const void *from,
5087 - unsigned long n);
5088 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
5089 - unsigned long n);
5090 -
5091 -#endif /* __powerpc64__ */
5092 -
5093 static inline unsigned long __copy_from_user_inatomic(void *to,
5094 const void __user *from, unsigned long n)
5095 {
5096 @@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
5097 if (ret == 0)
5098 return 0;
5099 }
5100 +
5101 + if (!__builtin_constant_p(n))
5102 + check_object_size(to, n, false);
5103 +
5104 return __copy_tofrom_user((__force void __user *)to, from, n);
5105 }
5106
5107 @@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
5108 if (ret == 0)
5109 return 0;
5110 }
5111 +
5112 + if (!__builtin_constant_p(n))
5113 + check_object_size(from, n, true);
5114 +
5115 return __copy_tofrom_user(to, (__force const void __user *)from, n);
5116 }
5117
5118 @@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
5119 return __copy_to_user_inatomic(to, from, size);
5120 }
5121
5122 +#ifndef __powerpc64__
5123 +
5124 +static inline unsigned long __must_check copy_from_user(void *to,
5125 + const void __user *from, unsigned long n)
5126 +{
5127 + unsigned long over;
5128 +
5129 + if ((long)n < 0)
5130 + return n;
5131 +
5132 + if (access_ok(VERIFY_READ, from, n)) {
5133 + if (!__builtin_constant_p(n))
5134 + check_object_size(to, n, false);
5135 + return __copy_tofrom_user((__force void __user *)to, from, n);
5136 + }
5137 + if ((unsigned long)from < TASK_SIZE) {
5138 + over = (unsigned long)from + n - TASK_SIZE;
5139 + if (!__builtin_constant_p(n - over))
5140 + check_object_size(to, n - over, false);
5141 + return __copy_tofrom_user((__force void __user *)to, from,
5142 + n - over) + over;
5143 + }
5144 + return n;
5145 +}
5146 +
5147 +static inline unsigned long __must_check copy_to_user(void __user *to,
5148 + const void *from, unsigned long n)
5149 +{
5150 + unsigned long over;
5151 +
5152 + if ((long)n < 0)
5153 + return n;
5154 +
5155 + if (access_ok(VERIFY_WRITE, to, n)) {
5156 + if (!__builtin_constant_p(n))
5157 + check_object_size(from, n, true);
5158 + return __copy_tofrom_user(to, (__force void __user *)from, n);
5159 + }
5160 + if ((unsigned long)to < TASK_SIZE) {
5161 + over = (unsigned long)to + n - TASK_SIZE;
5162 + if (!__builtin_constant_p(n))
5163 + check_object_size(from, n - over, true);
5164 + return __copy_tofrom_user(to, (__force void __user *)from,
5165 + n - over) + over;
5166 + }
5167 + return n;
5168 +}
5169 +
5170 +#else /* __powerpc64__ */
5171 +
5172 +#define __copy_in_user(to, from, size) \
5173 + __copy_tofrom_user((to), (from), (size))
5174 +
5175 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
5176 +{
5177 + if ((long)n < 0 || n > INT_MAX)
5178 + return n;
5179 +
5180 + if (!__builtin_constant_p(n))
5181 + check_object_size(to, n, false);
5182 +
5183 + if (likely(access_ok(VERIFY_READ, from, n)))
5184 + n = __copy_from_user(to, from, n);
5185 + else
5186 + memset(to, 0, n);
5187 + return n;
5188 +}
5189 +
5190 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
5191 +{
5192 + if ((long)n < 0 || n > INT_MAX)
5193 + return n;
5194 +
5195 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
5196 + if (!__builtin_constant_p(n))
5197 + check_object_size(from, n, true);
5198 + n = __copy_to_user(to, from, n);
5199 + }
5200 + return n;
5201 +}
5202 +
5203 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
5204 + unsigned long n);
5205 +
5206 +#endif /* __powerpc64__ */
5207 +
5208 extern unsigned long __clear_user(void __user *addr, unsigned long size);
5209
5210 static inline unsigned long clear_user(void __user *addr, unsigned long size)
5211 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
5212 index 4684e33..acc4d19e 100644
5213 --- a/arch/powerpc/kernel/exceptions-64e.S
5214 +++ b/arch/powerpc/kernel/exceptions-64e.S
5215 @@ -715,6 +715,7 @@ storage_fault_common:
5216 std r14,_DAR(r1)
5217 std r15,_DSISR(r1)
5218 addi r3,r1,STACK_FRAME_OVERHEAD
5219 + bl .save_nvgprs
5220 mr r4,r14
5221 mr r5,r15
5222 ld r14,PACA_EXGEN+EX_R14(r13)
5223 @@ -723,8 +724,7 @@ storage_fault_common:
5224 cmpdi r3,0
5225 bne- 1f
5226 b .ret_from_except_lite
5227 -1: bl .save_nvgprs
5228 - mr r5,r3
5229 +1: mr r5,r3
5230 addi r3,r1,STACK_FRAME_OVERHEAD
5231 ld r4,_DAR(r1)
5232 bl .bad_page_fault
5233 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
5234 index 10b658a..e542888 100644
5235 --- a/arch/powerpc/kernel/exceptions-64s.S
5236 +++ b/arch/powerpc/kernel/exceptions-64s.S
5237 @@ -1013,10 +1013,10 @@ handle_page_fault:
5238 11: ld r4,_DAR(r1)
5239 ld r5,_DSISR(r1)
5240 addi r3,r1,STACK_FRAME_OVERHEAD
5241 + bl .save_nvgprs
5242 bl .do_page_fault
5243 cmpdi r3,0
5244 beq+ 12f
5245 - bl .save_nvgprs
5246 mr r5,r3
5247 addi r3,r1,STACK_FRAME_OVERHEAD
5248 lwz r4,_DAR(r1)
5249 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
5250 index 2e3200c..72095ce 100644
5251 --- a/arch/powerpc/kernel/module_32.c
5252 +++ b/arch/powerpc/kernel/module_32.c
5253 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
5254 me->arch.core_plt_section = i;
5255 }
5256 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
5257 - printk("Module doesn't contain .plt or .init.plt sections.\n");
5258 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
5259 return -ENOEXEC;
5260 }
5261
5262 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
5263
5264 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
5265 /* Init, or core PLT? */
5266 - if (location >= mod->module_core
5267 - && location < mod->module_core + mod->core_size)
5268 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
5269 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
5270 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
5271 - else
5272 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
5273 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
5274 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
5275 + else {
5276 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
5277 + return ~0UL;
5278 + }
5279
5280 /* Find this entry, or if that fails, the next avail. entry */
5281 while (entry->jump[0]) {
5282 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
5283 index ba48233..16ac31d 100644
5284 --- a/arch/powerpc/kernel/process.c
5285 +++ b/arch/powerpc/kernel/process.c
5286 @@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
5287 * Lookup NIP late so we have the best change of getting the
5288 * above info out without failing
5289 */
5290 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
5291 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
5292 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
5293 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
5294 #endif
5295 show_stack(current, (unsigned long *) regs->gpr[1]);
5296 if (!user_mode(regs))
5297 @@ -1175,10 +1175,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5298 newsp = stack[0];
5299 ip = stack[STACK_FRAME_LR_SAVE];
5300 if (!firstframe || ip != lr) {
5301 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
5302 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
5303 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
5304 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
5305 - printk(" (%pS)",
5306 + printk(" (%pA)",
5307 (void *)current->ret_stack[curr_frame].ret);
5308 curr_frame--;
5309 }
5310 @@ -1198,7 +1198,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5311 struct pt_regs *regs = (struct pt_regs *)
5312 (sp + STACK_FRAME_OVERHEAD);
5313 lr = regs->link;
5314 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
5315 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
5316 regs->trap, (void *)regs->nip, (void *)lr);
5317 firstframe = 1;
5318 }
5319 @@ -1240,58 +1240,3 @@ void __ppc64_runlatch_off(void)
5320 mtspr(SPRN_CTRLT, ctrl);
5321 }
5322 #endif /* CONFIG_PPC64 */
5323 -
5324 -unsigned long arch_align_stack(unsigned long sp)
5325 -{
5326 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5327 - sp -= get_random_int() & ~PAGE_MASK;
5328 - return sp & ~0xf;
5329 -}
5330 -
5331 -static inline unsigned long brk_rnd(void)
5332 -{
5333 - unsigned long rnd = 0;
5334 -
5335 - /* 8MB for 32bit, 1GB for 64bit */
5336 - if (is_32bit_task())
5337 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
5338 - else
5339 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
5340 -
5341 - return rnd << PAGE_SHIFT;
5342 -}
5343 -
5344 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5345 -{
5346 - unsigned long base = mm->brk;
5347 - unsigned long ret;
5348 -
5349 -#ifdef CONFIG_PPC_STD_MMU_64
5350 - /*
5351 - * If we are using 1TB segments and we are allowed to randomise
5352 - * the heap, we can put it above 1TB so it is backed by a 1TB
5353 - * segment. Otherwise the heap will be in the bottom 1TB
5354 - * which always uses 256MB segments and this may result in a
5355 - * performance penalty.
5356 - */
5357 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
5358 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
5359 -#endif
5360 -
5361 - ret = PAGE_ALIGN(base + brk_rnd());
5362 -
5363 - if (ret < mm->brk)
5364 - return mm->brk;
5365 -
5366 - return ret;
5367 -}
5368 -
5369 -unsigned long randomize_et_dyn(unsigned long base)
5370 -{
5371 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5372 -
5373 - if (ret < base)
5374 - return base;
5375 -
5376 - return ret;
5377 -}
5378 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
5379 index 79d8e56..38ffcbb 100644
5380 --- a/arch/powerpc/kernel/ptrace.c
5381 +++ b/arch/powerpc/kernel/ptrace.c
5382 @@ -1663,6 +1663,10 @@ long arch_ptrace(struct task_struct *child, long request,
5383 return ret;
5384 }
5385
5386 +#ifdef CONFIG_GRKERNSEC_SETXID
5387 +extern void gr_delayed_cred_worker(void);
5388 +#endif
5389 +
5390 /*
5391 * We must return the syscall number to actually look up in the table.
5392 * This can be -1L to skip running any syscall at all.
5393 @@ -1673,6 +1677,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
5394
5395 secure_computing_strict(regs->gpr[0]);
5396
5397 +#ifdef CONFIG_GRKERNSEC_SETXID
5398 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5399 + gr_delayed_cred_worker();
5400 +#endif
5401 +
5402 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
5403 tracehook_report_syscall_entry(regs))
5404 /*
5405 @@ -1707,6 +1716,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
5406 {
5407 int step;
5408
5409 +#ifdef CONFIG_GRKERNSEC_SETXID
5410 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5411 + gr_delayed_cred_worker();
5412 +#endif
5413 +
5414 audit_syscall_exit(regs);
5415
5416 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5417 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
5418 index 804e323..79181c1 100644
5419 --- a/arch/powerpc/kernel/signal_32.c
5420 +++ b/arch/powerpc/kernel/signal_32.c
5421 @@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
5422 /* Save user registers on the stack */
5423 frame = &rt_sf->uc.uc_mcontext;
5424 addr = frame;
5425 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
5426 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5427 if (save_user_regs(regs, frame, 0, 1))
5428 goto badframe;
5429 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
5430 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
5431 index d183f87..1867f1a 100644
5432 --- a/arch/powerpc/kernel/signal_64.c
5433 +++ b/arch/powerpc/kernel/signal_64.c
5434 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
5435 current->thread.fpscr.val = 0;
5436
5437 /* Set up to return from userspace. */
5438 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
5439 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5440 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
5441 } else {
5442 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
5443 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
5444 index 3251840..3f7c77a 100644
5445 --- a/arch/powerpc/kernel/traps.c
5446 +++ b/arch/powerpc/kernel/traps.c
5447 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
5448 return flags;
5449 }
5450
5451 +extern void gr_handle_kernel_exploit(void);
5452 +
5453 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5454 int signr)
5455 {
5456 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5457 panic("Fatal exception in interrupt");
5458 if (panic_on_oops)
5459 panic("Fatal exception");
5460 +
5461 + gr_handle_kernel_exploit();
5462 +
5463 do_exit(signr);
5464 }
5465
5466 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
5467 index 1b2076f..835e4be 100644
5468 --- a/arch/powerpc/kernel/vdso.c
5469 +++ b/arch/powerpc/kernel/vdso.c
5470 @@ -34,6 +34,7 @@
5471 #include <asm/firmware.h>
5472 #include <asm/vdso.h>
5473 #include <asm/vdso_datapage.h>
5474 +#include <asm/mman.h>
5475
5476 #include "setup.h"
5477
5478 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5479 vdso_base = VDSO32_MBASE;
5480 #endif
5481
5482 - current->mm->context.vdso_base = 0;
5483 + current->mm->context.vdso_base = ~0UL;
5484
5485 /* vDSO has a problem and was disabled, just don't "enable" it for the
5486 * process
5487 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5488 vdso_base = get_unmapped_area(NULL, vdso_base,
5489 (vdso_pages << PAGE_SHIFT) +
5490 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
5491 - 0, 0);
5492 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
5493 if (IS_ERR_VALUE(vdso_base)) {
5494 rc = vdso_base;
5495 goto fail_mmapsem;
5496 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
5497 index 5eea6f3..5d10396 100644
5498 --- a/arch/powerpc/lib/usercopy_64.c
5499 +++ b/arch/powerpc/lib/usercopy_64.c
5500 @@ -9,22 +9,6 @@
5501 #include <linux/module.h>
5502 #include <asm/uaccess.h>
5503
5504 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5505 -{
5506 - if (likely(access_ok(VERIFY_READ, from, n)))
5507 - n = __copy_from_user(to, from, n);
5508 - else
5509 - memset(to, 0, n);
5510 - return n;
5511 -}
5512 -
5513 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5514 -{
5515 - if (likely(access_ok(VERIFY_WRITE, to, n)))
5516 - n = __copy_to_user(to, from, n);
5517 - return n;
5518 -}
5519 -
5520 unsigned long copy_in_user(void __user *to, const void __user *from,
5521 unsigned long n)
5522 {
5523 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
5524 return n;
5525 }
5526
5527 -EXPORT_SYMBOL(copy_from_user);
5528 -EXPORT_SYMBOL(copy_to_user);
5529 EXPORT_SYMBOL(copy_in_user);
5530
5531 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
5532 index 0a6b283..7674925 100644
5533 --- a/arch/powerpc/mm/fault.c
5534 +++ b/arch/powerpc/mm/fault.c
5535 @@ -32,6 +32,10 @@
5536 #include <linux/perf_event.h>
5537 #include <linux/magic.h>
5538 #include <linux/ratelimit.h>
5539 +#include <linux/slab.h>
5540 +#include <linux/pagemap.h>
5541 +#include <linux/compiler.h>
5542 +#include <linux/unistd.h>
5543
5544 #include <asm/firmware.h>
5545 #include <asm/page.h>
5546 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
5547 }
5548 #endif
5549
5550 +#ifdef CONFIG_PAX_PAGEEXEC
5551 +/*
5552 + * PaX: decide what to do with offenders (regs->nip = fault address)
5553 + *
5554 + * returns 1 when task should be killed
5555 + */
5556 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5557 +{
5558 + return 1;
5559 +}
5560 +
5561 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5562 +{
5563 + unsigned long i;
5564 +
5565 + printk(KERN_ERR "PAX: bytes at PC: ");
5566 + for (i = 0; i < 5; i++) {
5567 + unsigned int c;
5568 + if (get_user(c, (unsigned int __user *)pc+i))
5569 + printk(KERN_CONT "???????? ");
5570 + else
5571 + printk(KERN_CONT "%08x ", c);
5572 + }
5573 + printk("\n");
5574 +}
5575 +#endif
5576 +
5577 /*
5578 * Check whether the instruction at regs->nip is a store using
5579 * an update addressing form which will update r1.
5580 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
5581 * indicate errors in DSISR but can validly be set in SRR1.
5582 */
5583 if (trap == 0x400)
5584 - error_code &= 0x48200000;
5585 + error_code &= 0x58200000;
5586 else
5587 is_write = error_code & DSISR_ISSTORE;
5588 #else
5589 @@ -367,7 +398,7 @@ good_area:
5590 * "undefined". Of those that can be set, this is the only
5591 * one which seems bad.
5592 */
5593 - if (error_code & 0x10000000)
5594 + if (error_code & DSISR_GUARDED)
5595 /* Guarded storage error. */
5596 goto bad_area;
5597 #endif /* CONFIG_8xx */
5598 @@ -382,7 +413,7 @@ good_area:
5599 * processors use the same I/D cache coherency mechanism
5600 * as embedded.
5601 */
5602 - if (error_code & DSISR_PROTFAULT)
5603 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
5604 goto bad_area;
5605 #endif /* CONFIG_PPC_STD_MMU */
5606
5607 @@ -465,6 +496,23 @@ bad_area:
5608 bad_area_nosemaphore:
5609 /* User mode accesses cause a SIGSEGV */
5610 if (user_mode(regs)) {
5611 +
5612 +#ifdef CONFIG_PAX_PAGEEXEC
5613 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5614 +#ifdef CONFIG_PPC_STD_MMU
5615 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
5616 +#else
5617 + if (is_exec && regs->nip == address) {
5618 +#endif
5619 + switch (pax_handle_fetch_fault(regs)) {
5620 + }
5621 +
5622 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
5623 + do_group_exit(SIGKILL);
5624 + }
5625 + }
5626 +#endif
5627 +
5628 _exception(SIGSEGV, regs, code, address);
5629 return 0;
5630 }
5631 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
5632 index 67a42ed..c16ef80 100644
5633 --- a/arch/powerpc/mm/mmap_64.c
5634 +++ b/arch/powerpc/mm/mmap_64.c
5635 @@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
5636 {
5637 unsigned long rnd = 0;
5638
5639 +#ifdef CONFIG_PAX_RANDMMAP
5640 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5641 +#endif
5642 +
5643 if (current->flags & PF_RANDOMIZE) {
5644 /* 8MB for 32bit, 1GB for 64bit */
5645 if (is_32bit_task())
5646 @@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5647 */
5648 if (mmap_is_legacy()) {
5649 mm->mmap_base = TASK_UNMAPPED_BASE;
5650 +
5651 +#ifdef CONFIG_PAX_RANDMMAP
5652 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5653 + mm->mmap_base += mm->delta_mmap;
5654 +#endif
5655 +
5656 mm->get_unmapped_area = arch_get_unmapped_area;
5657 mm->unmap_area = arch_unmap_area;
5658 } else {
5659 mm->mmap_base = mmap_base();
5660 +
5661 +#ifdef CONFIG_PAX_RANDMMAP
5662 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5663 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5664 +#endif
5665 +
5666 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5667 mm->unmap_area = arch_unmap_area_topdown;
5668 }
5669 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
5670 index 5829d2a..af84242 100644
5671 --- a/arch/powerpc/mm/slice.c
5672 +++ b/arch/powerpc/mm/slice.c
5673 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
5674 if ((mm->task_size - len) < addr)
5675 return 0;
5676 vma = find_vma(mm, addr);
5677 - return (!vma || (addr + len) <= vma->vm_start);
5678 + return check_heap_stack_gap(vma, addr, len, 0);
5679 }
5680
5681 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
5682 @@ -272,7 +272,7 @@ full_search:
5683 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
5684 continue;
5685 }
5686 - if (!vma || addr + len <= vma->vm_start) {
5687 + if (check_heap_stack_gap(vma, addr, len, 0)) {
5688 /*
5689 * Remember the place where we stopped the search:
5690 */
5691 @@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5692 }
5693 }
5694
5695 - addr = mm->mmap_base;
5696 - while (addr > len) {
5697 + if (mm->mmap_base < len)
5698 + addr = -ENOMEM;
5699 + else
5700 + addr = mm->mmap_base - len;
5701 +
5702 + while (!IS_ERR_VALUE(addr)) {
5703 /* Go down by chunk size */
5704 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
5705 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
5706
5707 /* Check for hit with different page size */
5708 mask = slice_range_to_mask(addr, len);
5709 @@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5710 * return with success:
5711 */
5712 vma = find_vma(mm, addr);
5713 - if (!vma || (addr + len) <= vma->vm_start) {
5714 + if (check_heap_stack_gap(vma, addr, len, 0)) {
5715 /* remember the address as a hint for next time */
5716 if (use_cache)
5717 mm->free_area_cache = addr;
5718 @@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5719 mm->cached_hole_size = vma->vm_start - addr;
5720
5721 /* try just below the current vma->vm_start */
5722 - addr = vma->vm_start;
5723 + addr = skip_heap_stack_gap(vma, len, 0);
5724 }
5725
5726 /*
5727 @@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
5728 if (fixed && addr > (mm->task_size - len))
5729 return -EINVAL;
5730
5731 +#ifdef CONFIG_PAX_RANDMMAP
5732 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
5733 + addr = 0;
5734 +#endif
5735 +
5736 /* If hint, make sure it matches our alignment restrictions */
5737 if (!fixed && addr) {
5738 addr = _ALIGN_UP(addr, 1ul << pshift);
5739 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
5740 index c797832..ce575c8 100644
5741 --- a/arch/s390/include/asm/atomic.h
5742 +++ b/arch/s390/include/asm/atomic.h
5743 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
5744 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
5745 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5746
5747 +#define atomic64_read_unchecked(v) atomic64_read(v)
5748 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5749 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5750 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5751 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5752 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5753 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5754 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5755 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5756 +
5757 #define smp_mb__before_atomic_dec() smp_mb()
5758 #define smp_mb__after_atomic_dec() smp_mb()
5759 #define smp_mb__before_atomic_inc() smp_mb()
5760 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
5761 index 4d7ccac..d03d0ad 100644
5762 --- a/arch/s390/include/asm/cache.h
5763 +++ b/arch/s390/include/asm/cache.h
5764 @@ -9,8 +9,10 @@
5765 #ifndef __ARCH_S390_CACHE_H
5766 #define __ARCH_S390_CACHE_H
5767
5768 -#define L1_CACHE_BYTES 256
5769 +#include <linux/const.h>
5770 +
5771 #define L1_CACHE_SHIFT 8
5772 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5773 #define NET_SKB_PAD 32
5774
5775 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5776 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
5777 index 178ff96..8c93bd1 100644
5778 --- a/arch/s390/include/asm/elf.h
5779 +++ b/arch/s390/include/asm/elf.h
5780 @@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
5781 the loader. We need to make sure that it is out of the way of the program
5782 that it will "exec", and that there is sufficient room for the brk. */
5783
5784 -extern unsigned long randomize_et_dyn(unsigned long base);
5785 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
5786 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
5787 +
5788 +#ifdef CONFIG_PAX_ASLR
5789 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
5790 +
5791 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5792 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5793 +#endif
5794
5795 /* This yields a mask that user programs can use to figure out what
5796 instruction set this CPU supports. */
5797 @@ -210,9 +216,6 @@ struct linux_binprm;
5798 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5799 int arch_setup_additional_pages(struct linux_binprm *, int);
5800
5801 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5802 -#define arch_randomize_brk arch_randomize_brk
5803 -
5804 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
5805
5806 #endif
5807 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
5808 index c4a93d6..4d2a9b4 100644
5809 --- a/arch/s390/include/asm/exec.h
5810 +++ b/arch/s390/include/asm/exec.h
5811 @@ -7,6 +7,6 @@
5812 #ifndef __ASM_EXEC_H
5813 #define __ASM_EXEC_H
5814
5815 -extern unsigned long arch_align_stack(unsigned long sp);
5816 +#define arch_align_stack(x) ((x) & ~0xfUL)
5817
5818 #endif /* __ASM_EXEC_H */
5819 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
5820 index 34268df..ea97318 100644
5821 --- a/arch/s390/include/asm/uaccess.h
5822 +++ b/arch/s390/include/asm/uaccess.h
5823 @@ -252,6 +252,10 @@ static inline unsigned long __must_check
5824 copy_to_user(void __user *to, const void *from, unsigned long n)
5825 {
5826 might_fault();
5827 +
5828 + if ((long)n < 0)
5829 + return n;
5830 +
5831 if (access_ok(VERIFY_WRITE, to, n))
5832 n = __copy_to_user(to, from, n);
5833 return n;
5834 @@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
5835 static inline unsigned long __must_check
5836 __copy_from_user(void *to, const void __user *from, unsigned long n)
5837 {
5838 + if ((long)n < 0)
5839 + return n;
5840 +
5841 if (__builtin_constant_p(n) && (n <= 256))
5842 return uaccess.copy_from_user_small(n, from, to);
5843 else
5844 @@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
5845 static inline unsigned long __must_check
5846 copy_from_user(void *to, const void __user *from, unsigned long n)
5847 {
5848 - unsigned int sz = __compiletime_object_size(to);
5849 + size_t sz = __compiletime_object_size(to);
5850
5851 might_fault();
5852 - if (unlikely(sz != -1 && sz < n)) {
5853 +
5854 + if ((long)n < 0)
5855 + return n;
5856 +
5857 + if (unlikely(sz != (size_t)-1 && sz < n)) {
5858 copy_from_user_overflow();
5859 return n;
5860 }
5861 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
5862 index 4610dea..cf0af21 100644
5863 --- a/arch/s390/kernel/module.c
5864 +++ b/arch/s390/kernel/module.c
5865 @@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
5866
5867 /* Increase core size by size of got & plt and set start
5868 offsets for got and plt. */
5869 - me->core_size = ALIGN(me->core_size, 4);
5870 - me->arch.got_offset = me->core_size;
5871 - me->core_size += me->arch.got_size;
5872 - me->arch.plt_offset = me->core_size;
5873 - me->core_size += me->arch.plt_size;
5874 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
5875 + me->arch.got_offset = me->core_size_rw;
5876 + me->core_size_rw += me->arch.got_size;
5877 + me->arch.plt_offset = me->core_size_rx;
5878 + me->core_size_rx += me->arch.plt_size;
5879 return 0;
5880 }
5881
5882 @@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5883 if (info->got_initialized == 0) {
5884 Elf_Addr *gotent;
5885
5886 - gotent = me->module_core + me->arch.got_offset +
5887 + gotent = me->module_core_rw + me->arch.got_offset +
5888 info->got_offset;
5889 *gotent = val;
5890 info->got_initialized = 1;
5891 @@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5892 else if (r_type == R_390_GOTENT ||
5893 r_type == R_390_GOTPLTENT)
5894 *(unsigned int *) loc =
5895 - (val + (Elf_Addr) me->module_core - loc) >> 1;
5896 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
5897 else if (r_type == R_390_GOT64 ||
5898 r_type == R_390_GOTPLT64)
5899 *(unsigned long *) loc = val;
5900 @@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5901 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
5902 if (info->plt_initialized == 0) {
5903 unsigned int *ip;
5904 - ip = me->module_core + me->arch.plt_offset +
5905 + ip = me->module_core_rx + me->arch.plt_offset +
5906 info->plt_offset;
5907 #ifndef CONFIG_64BIT
5908 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
5909 @@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5910 val - loc + 0xffffUL < 0x1ffffeUL) ||
5911 (r_type == R_390_PLT32DBL &&
5912 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
5913 - val = (Elf_Addr) me->module_core +
5914 + val = (Elf_Addr) me->module_core_rx +
5915 me->arch.plt_offset +
5916 info->plt_offset;
5917 val += rela->r_addend - loc;
5918 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5919 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
5920 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
5921 val = val + rela->r_addend -
5922 - ((Elf_Addr) me->module_core + me->arch.got_offset);
5923 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
5924 if (r_type == R_390_GOTOFF16)
5925 *(unsigned short *) loc = val;
5926 else if (r_type == R_390_GOTOFF32)
5927 @@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5928 break;
5929 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
5930 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
5931 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
5932 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
5933 rela->r_addend - loc;
5934 if (r_type == R_390_GOTPC)
5935 *(unsigned int *) loc = val;
5936 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
5937 index cd31ad4..201c5a3 100644
5938 --- a/arch/s390/kernel/process.c
5939 +++ b/arch/s390/kernel/process.c
5940 @@ -283,39 +283,3 @@ unsigned long get_wchan(struct task_struct *p)
5941 }
5942 return 0;
5943 }
5944 -
5945 -unsigned long arch_align_stack(unsigned long sp)
5946 -{
5947 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5948 - sp -= get_random_int() & ~PAGE_MASK;
5949 - return sp & ~0xf;
5950 -}
5951 -
5952 -static inline unsigned long brk_rnd(void)
5953 -{
5954 - /* 8MB for 32bit, 1GB for 64bit */
5955 - if (is_32bit_task())
5956 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
5957 - else
5958 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
5959 -}
5960 -
5961 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5962 -{
5963 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
5964 -
5965 - if (ret < mm->brk)
5966 - return mm->brk;
5967 - return ret;
5968 -}
5969 -
5970 -unsigned long randomize_et_dyn(unsigned long base)
5971 -{
5972 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5973 -
5974 - if (!(current->flags & PF_RANDOMIZE))
5975 - return base;
5976 - if (ret < base)
5977 - return base;
5978 - return ret;
5979 -}
5980 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
5981 index c59a5ef..3fae59c 100644
5982 --- a/arch/s390/mm/mmap.c
5983 +++ b/arch/s390/mm/mmap.c
5984 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5985 */
5986 if (mmap_is_legacy()) {
5987 mm->mmap_base = TASK_UNMAPPED_BASE;
5988 +
5989 +#ifdef CONFIG_PAX_RANDMMAP
5990 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5991 + mm->mmap_base += mm->delta_mmap;
5992 +#endif
5993 +
5994 mm->get_unmapped_area = arch_get_unmapped_area;
5995 mm->unmap_area = arch_unmap_area;
5996 } else {
5997 mm->mmap_base = mmap_base();
5998 +
5999 +#ifdef CONFIG_PAX_RANDMMAP
6000 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6001 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6002 +#endif
6003 +
6004 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6005 mm->unmap_area = arch_unmap_area_topdown;
6006 }
6007 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6008 */
6009 if (mmap_is_legacy()) {
6010 mm->mmap_base = TASK_UNMAPPED_BASE;
6011 +
6012 +#ifdef CONFIG_PAX_RANDMMAP
6013 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6014 + mm->mmap_base += mm->delta_mmap;
6015 +#endif
6016 +
6017 mm->get_unmapped_area = s390_get_unmapped_area;
6018 mm->unmap_area = arch_unmap_area;
6019 } else {
6020 mm->mmap_base = mmap_base();
6021 +
6022 +#ifdef CONFIG_PAX_RANDMMAP
6023 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6024 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6025 +#endif
6026 +
6027 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
6028 mm->unmap_area = arch_unmap_area_topdown;
6029 }
6030 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
6031 index ae3d59f..f65f075 100644
6032 --- a/arch/score/include/asm/cache.h
6033 +++ b/arch/score/include/asm/cache.h
6034 @@ -1,7 +1,9 @@
6035 #ifndef _ASM_SCORE_CACHE_H
6036 #define _ASM_SCORE_CACHE_H
6037
6038 +#include <linux/const.h>
6039 +
6040 #define L1_CACHE_SHIFT 4
6041 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6042 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6043
6044 #endif /* _ASM_SCORE_CACHE_H */
6045 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
6046 index f9f3cd5..58ff438 100644
6047 --- a/arch/score/include/asm/exec.h
6048 +++ b/arch/score/include/asm/exec.h
6049 @@ -1,6 +1,6 @@
6050 #ifndef _ASM_SCORE_EXEC_H
6051 #define _ASM_SCORE_EXEC_H
6052
6053 -extern unsigned long arch_align_stack(unsigned long sp);
6054 +#define arch_align_stack(x) (x)
6055
6056 #endif /* _ASM_SCORE_EXEC_H */
6057 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
6058 index 637970c..0b6556b 100644
6059 --- a/arch/score/kernel/process.c
6060 +++ b/arch/score/kernel/process.c
6061 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
6062
6063 return task_pt_regs(task)->cp0_epc;
6064 }
6065 -
6066 -unsigned long arch_align_stack(unsigned long sp)
6067 -{
6068 - return sp;
6069 -}
6070 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
6071 index ef9e555..331bd29 100644
6072 --- a/arch/sh/include/asm/cache.h
6073 +++ b/arch/sh/include/asm/cache.h
6074 @@ -9,10 +9,11 @@
6075 #define __ASM_SH_CACHE_H
6076 #ifdef __KERNEL__
6077
6078 +#include <linux/const.h>
6079 #include <linux/init.h>
6080 #include <cpu/cache.h>
6081
6082 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6083 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6084
6085 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
6086
6087 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
6088 index afeb710..e8366ef 100644
6089 --- a/arch/sh/mm/mmap.c
6090 +++ b/arch/sh/mm/mmap.c
6091 @@ -49,6 +49,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6092 struct vm_area_struct *vma;
6093 unsigned long start_addr;
6094 int do_colour_align;
6095 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6096
6097 if (flags & MAP_FIXED) {
6098 /* We do not accept a shared mapping if it would violate
6099 @@ -74,8 +75,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6100 addr = PAGE_ALIGN(addr);
6101
6102 vma = find_vma(mm, addr);
6103 - if (TASK_SIZE - len >= addr &&
6104 - (!vma || addr + len <= vma->vm_start))
6105 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6106 return addr;
6107 }
6108
6109 @@ -106,7 +106,7 @@ full_search:
6110 }
6111 return -ENOMEM;
6112 }
6113 - if (likely(!vma || addr + len <= vma->vm_start)) {
6114 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6115 /*
6116 * Remember the place where we stopped the search:
6117 */
6118 @@ -131,6 +131,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6119 struct mm_struct *mm = current->mm;
6120 unsigned long addr = addr0;
6121 int do_colour_align;
6122 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6123
6124 if (flags & MAP_FIXED) {
6125 /* We do not accept a shared mapping if it would violate
6126 @@ -157,8 +158,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6127 addr = PAGE_ALIGN(addr);
6128
6129 vma = find_vma(mm, addr);
6130 - if (TASK_SIZE - len >= addr &&
6131 - (!vma || addr + len <= vma->vm_start))
6132 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6133 return addr;
6134 }
6135
6136 @@ -179,7 +179,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6137 /* make sure it can fit in the remaining address space */
6138 if (likely(addr > len)) {
6139 vma = find_vma(mm, addr-len);
6140 - if (!vma || addr <= vma->vm_start) {
6141 + if (check_heap_stack_gap(vma, addr - len, len, offset)) {
6142 /* remember the address as a hint for next time */
6143 return (mm->free_area_cache = addr-len);
6144 }
6145 @@ -188,18 +188,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6146 if (unlikely(mm->mmap_base < len))
6147 goto bottomup;
6148
6149 - addr = mm->mmap_base-len;
6150 - if (do_colour_align)
6151 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6152 + addr = mm->mmap_base - len;
6153
6154 do {
6155 + if (do_colour_align)
6156 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6157 /*
6158 * Lookup failure means no vma is above this address,
6159 * else if new region fits below vma->vm_start,
6160 * return with success:
6161 */
6162 vma = find_vma(mm, addr);
6163 - if (likely(!vma || addr+len <= vma->vm_start)) {
6164 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6165 /* remember the address as a hint for next time */
6166 return (mm->free_area_cache = addr);
6167 }
6168 @@ -209,10 +209,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6169 mm->cached_hole_size = vma->vm_start - addr;
6170
6171 /* try just below the current vma->vm_start */
6172 - addr = vma->vm_start-len;
6173 - if (do_colour_align)
6174 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6175 - } while (likely(len < vma->vm_start));
6176 + addr = skip_heap_stack_gap(vma, len, offset);
6177 + } while (!IS_ERR_VALUE(addr));
6178
6179 bottomup:
6180 /*
6181 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
6182 index be56a24..443328f 100644
6183 --- a/arch/sparc/include/asm/atomic_64.h
6184 +++ b/arch/sparc/include/asm/atomic_64.h
6185 @@ -14,18 +14,40 @@
6186 #define ATOMIC64_INIT(i) { (i) }
6187
6188 #define atomic_read(v) (*(volatile int *)&(v)->counter)
6189 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6190 +{
6191 + return v->counter;
6192 +}
6193 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
6194 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6195 +{
6196 + return v->counter;
6197 +}
6198
6199 #define atomic_set(v, i) (((v)->counter) = i)
6200 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6201 +{
6202 + v->counter = i;
6203 +}
6204 #define atomic64_set(v, i) (((v)->counter) = i)
6205 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6206 +{
6207 + v->counter = i;
6208 +}
6209
6210 extern void atomic_add(int, atomic_t *);
6211 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
6212 extern void atomic64_add(long, atomic64_t *);
6213 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
6214 extern void atomic_sub(int, atomic_t *);
6215 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
6216 extern void atomic64_sub(long, atomic64_t *);
6217 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
6218
6219 extern int atomic_add_ret(int, atomic_t *);
6220 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
6221 extern long atomic64_add_ret(long, atomic64_t *);
6222 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
6223 extern int atomic_sub_ret(int, atomic_t *);
6224 extern long atomic64_sub_ret(long, atomic64_t *);
6225
6226 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6227 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
6228
6229 #define atomic_inc_return(v) atomic_add_ret(1, v)
6230 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6231 +{
6232 + return atomic_add_ret_unchecked(1, v);
6233 +}
6234 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
6235 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
6236 +{
6237 + return atomic64_add_ret_unchecked(1, v);
6238 +}
6239
6240 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
6241 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
6242
6243 #define atomic_add_return(i, v) atomic_add_ret(i, v)
6244 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6245 +{
6246 + return atomic_add_ret_unchecked(i, v);
6247 +}
6248 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
6249 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6250 +{
6251 + return atomic64_add_ret_unchecked(i, v);
6252 +}
6253
6254 /*
6255 * atomic_inc_and_test - increment and test
6256 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6257 * other cases.
6258 */
6259 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6260 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6261 +{
6262 + return atomic_inc_return_unchecked(v) == 0;
6263 +}
6264 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6265
6266 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
6267 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6268 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
6269
6270 #define atomic_inc(v) atomic_add(1, v)
6271 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
6272 +{
6273 + atomic_add_unchecked(1, v);
6274 +}
6275 #define atomic64_inc(v) atomic64_add(1, v)
6276 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
6277 +{
6278 + atomic64_add_unchecked(1, v);
6279 +}
6280
6281 #define atomic_dec(v) atomic_sub(1, v)
6282 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
6283 +{
6284 + atomic_sub_unchecked(1, v);
6285 +}
6286 #define atomic64_dec(v) atomic64_sub(1, v)
6287 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
6288 +{
6289 + atomic64_sub_unchecked(1, v);
6290 +}
6291
6292 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
6293 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
6294
6295 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6296 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
6297 +{
6298 + return cmpxchg(&v->counter, old, new);
6299 +}
6300 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
6301 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6302 +{
6303 + return xchg(&v->counter, new);
6304 +}
6305
6306 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6307 {
6308 - int c, old;
6309 + int c, old, new;
6310 c = atomic_read(v);
6311 for (;;) {
6312 - if (unlikely(c == (u)))
6313 + if (unlikely(c == u))
6314 break;
6315 - old = atomic_cmpxchg((v), c, c + (a));
6316 +
6317 + asm volatile("addcc %2, %0, %0\n"
6318 +
6319 +#ifdef CONFIG_PAX_REFCOUNT
6320 + "tvs %%icc, 6\n"
6321 +#endif
6322 +
6323 + : "=r" (new)
6324 + : "0" (c), "ir" (a)
6325 + : "cc");
6326 +
6327 + old = atomic_cmpxchg(v, c, new);
6328 if (likely(old == c))
6329 break;
6330 c = old;
6331 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6332 #define atomic64_cmpxchg(v, o, n) \
6333 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6334 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
6335 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6336 +{
6337 + return xchg(&v->counter, new);
6338 +}
6339
6340 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
6341 {
6342 - long c, old;
6343 + long c, old, new;
6344 c = atomic64_read(v);
6345 for (;;) {
6346 - if (unlikely(c == (u)))
6347 + if (unlikely(c == u))
6348 break;
6349 - old = atomic64_cmpxchg((v), c, c + (a));
6350 +
6351 + asm volatile("addcc %2, %0, %0\n"
6352 +
6353 +#ifdef CONFIG_PAX_REFCOUNT
6354 + "tvs %%xcc, 6\n"
6355 +#endif
6356 +
6357 + : "=r" (new)
6358 + : "0" (c), "ir" (a)
6359 + : "cc");
6360 +
6361 + old = atomic64_cmpxchg(v, c, new);
6362 if (likely(old == c))
6363 break;
6364 c = old;
6365 }
6366 - return c != (u);
6367 + return c != u;
6368 }
6369
6370 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6371 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
6372 index 5bb6991..5c2132e 100644
6373 --- a/arch/sparc/include/asm/cache.h
6374 +++ b/arch/sparc/include/asm/cache.h
6375 @@ -7,10 +7,12 @@
6376 #ifndef _SPARC_CACHE_H
6377 #define _SPARC_CACHE_H
6378
6379 +#include <linux/const.h>
6380 +
6381 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
6382
6383 #define L1_CACHE_SHIFT 5
6384 -#define L1_CACHE_BYTES 32
6385 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6386
6387 #ifdef CONFIG_SPARC32
6388 #define SMP_CACHE_BYTES_SHIFT 5
6389 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
6390 index ac74a2c..a9e58af 100644
6391 --- a/arch/sparc/include/asm/elf_32.h
6392 +++ b/arch/sparc/include/asm/elf_32.h
6393 @@ -114,6 +114,13 @@ typedef struct {
6394
6395 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
6396
6397 +#ifdef CONFIG_PAX_ASLR
6398 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
6399 +
6400 +#define PAX_DELTA_MMAP_LEN 16
6401 +#define PAX_DELTA_STACK_LEN 16
6402 +#endif
6403 +
6404 /* This yields a mask that user programs can use to figure out what
6405 instruction set this cpu supports. This can NOT be done in userspace
6406 on Sparc. */
6407 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
6408 index 370ca1e..d4f4a98 100644
6409 --- a/arch/sparc/include/asm/elf_64.h
6410 +++ b/arch/sparc/include/asm/elf_64.h
6411 @@ -189,6 +189,13 @@ typedef struct {
6412 #define ELF_ET_DYN_BASE 0x0000010000000000UL
6413 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
6414
6415 +#ifdef CONFIG_PAX_ASLR
6416 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
6417 +
6418 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
6419 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
6420 +#endif
6421 +
6422 extern unsigned long sparc64_elf_hwcap;
6423 #define ELF_HWCAP sparc64_elf_hwcap
6424
6425 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
6426 index 9b1c36d..209298b 100644
6427 --- a/arch/sparc/include/asm/pgalloc_32.h
6428 +++ b/arch/sparc/include/asm/pgalloc_32.h
6429 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
6430 }
6431
6432 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
6433 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
6434
6435 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
6436 unsigned long address)
6437 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
6438 index bcfe063..b333142 100644
6439 --- a/arch/sparc/include/asm/pgalloc_64.h
6440 +++ b/arch/sparc/include/asm/pgalloc_64.h
6441 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6442 }
6443
6444 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
6445 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
6446
6447 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
6448 {
6449 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
6450 index 6fc1348..390c50a 100644
6451 --- a/arch/sparc/include/asm/pgtable_32.h
6452 +++ b/arch/sparc/include/asm/pgtable_32.h
6453 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
6454 #define PAGE_SHARED SRMMU_PAGE_SHARED
6455 #define PAGE_COPY SRMMU_PAGE_COPY
6456 #define PAGE_READONLY SRMMU_PAGE_RDONLY
6457 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
6458 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
6459 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
6460 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
6461
6462 /* Top-level page directory - dummy used by init-mm.
6463 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
6464
6465 /* xwr */
6466 #define __P000 PAGE_NONE
6467 -#define __P001 PAGE_READONLY
6468 -#define __P010 PAGE_COPY
6469 -#define __P011 PAGE_COPY
6470 +#define __P001 PAGE_READONLY_NOEXEC
6471 +#define __P010 PAGE_COPY_NOEXEC
6472 +#define __P011 PAGE_COPY_NOEXEC
6473 #define __P100 PAGE_READONLY
6474 #define __P101 PAGE_READONLY
6475 #define __P110 PAGE_COPY
6476 #define __P111 PAGE_COPY
6477
6478 #define __S000 PAGE_NONE
6479 -#define __S001 PAGE_READONLY
6480 -#define __S010 PAGE_SHARED
6481 -#define __S011 PAGE_SHARED
6482 +#define __S001 PAGE_READONLY_NOEXEC
6483 +#define __S010 PAGE_SHARED_NOEXEC
6484 +#define __S011 PAGE_SHARED_NOEXEC
6485 #define __S100 PAGE_READONLY
6486 #define __S101 PAGE_READONLY
6487 #define __S110 PAGE_SHARED
6488 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
6489 index 79da178..c2eede8 100644
6490 --- a/arch/sparc/include/asm/pgtsrmmu.h
6491 +++ b/arch/sparc/include/asm/pgtsrmmu.h
6492 @@ -115,6 +115,11 @@
6493 SRMMU_EXEC | SRMMU_REF)
6494 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
6495 SRMMU_EXEC | SRMMU_REF)
6496 +
6497 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
6498 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6499 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6500 +
6501 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
6502 SRMMU_DIRTY | SRMMU_REF)
6503
6504 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
6505 index 9689176..63c18ea 100644
6506 --- a/arch/sparc/include/asm/spinlock_64.h
6507 +++ b/arch/sparc/include/asm/spinlock_64.h
6508 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
6509
6510 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
6511
6512 -static void inline arch_read_lock(arch_rwlock_t *lock)
6513 +static inline void arch_read_lock(arch_rwlock_t *lock)
6514 {
6515 unsigned long tmp1, tmp2;
6516
6517 __asm__ __volatile__ (
6518 "1: ldsw [%2], %0\n"
6519 " brlz,pn %0, 2f\n"
6520 -"4: add %0, 1, %1\n"
6521 +"4: addcc %0, 1, %1\n"
6522 +
6523 +#ifdef CONFIG_PAX_REFCOUNT
6524 +" tvs %%icc, 6\n"
6525 +#endif
6526 +
6527 " cas [%2], %0, %1\n"
6528 " cmp %0, %1\n"
6529 " bne,pn %%icc, 1b\n"
6530 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
6531 " .previous"
6532 : "=&r" (tmp1), "=&r" (tmp2)
6533 : "r" (lock)
6534 - : "memory");
6535 + : "memory", "cc");
6536 }
6537
6538 -static int inline arch_read_trylock(arch_rwlock_t *lock)
6539 +static inline int arch_read_trylock(arch_rwlock_t *lock)
6540 {
6541 int tmp1, tmp2;
6542
6543 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6544 "1: ldsw [%2], %0\n"
6545 " brlz,a,pn %0, 2f\n"
6546 " mov 0, %0\n"
6547 -" add %0, 1, %1\n"
6548 +" addcc %0, 1, %1\n"
6549 +
6550 +#ifdef CONFIG_PAX_REFCOUNT
6551 +" tvs %%icc, 6\n"
6552 +#endif
6553 +
6554 " cas [%2], %0, %1\n"
6555 " cmp %0, %1\n"
6556 " bne,pn %%icc, 1b\n"
6557 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6558 return tmp1;
6559 }
6560
6561 -static void inline arch_read_unlock(arch_rwlock_t *lock)
6562 +static inline void arch_read_unlock(arch_rwlock_t *lock)
6563 {
6564 unsigned long tmp1, tmp2;
6565
6566 __asm__ __volatile__(
6567 "1: lduw [%2], %0\n"
6568 -" sub %0, 1, %1\n"
6569 +" subcc %0, 1, %1\n"
6570 +
6571 +#ifdef CONFIG_PAX_REFCOUNT
6572 +" tvs %%icc, 6\n"
6573 +#endif
6574 +
6575 " cas [%2], %0, %1\n"
6576 " cmp %0, %1\n"
6577 " bne,pn %%xcc, 1b\n"
6578 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
6579 : "memory");
6580 }
6581
6582 -static void inline arch_write_lock(arch_rwlock_t *lock)
6583 +static inline void arch_write_lock(arch_rwlock_t *lock)
6584 {
6585 unsigned long mask, tmp1, tmp2;
6586
6587 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
6588 : "memory");
6589 }
6590
6591 -static void inline arch_write_unlock(arch_rwlock_t *lock)
6592 +static inline void arch_write_unlock(arch_rwlock_t *lock)
6593 {
6594 __asm__ __volatile__(
6595 " stw %%g0, [%0]"
6596 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
6597 : "memory");
6598 }
6599
6600 -static int inline arch_write_trylock(arch_rwlock_t *lock)
6601 +static inline int arch_write_trylock(arch_rwlock_t *lock)
6602 {
6603 unsigned long mask, tmp1, tmp2, result;
6604
6605 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
6606 index 25849ae..924c54b 100644
6607 --- a/arch/sparc/include/asm/thread_info_32.h
6608 +++ b/arch/sparc/include/asm/thread_info_32.h
6609 @@ -49,6 +49,8 @@ struct thread_info {
6610 unsigned long w_saved;
6611
6612 struct restart_block restart_block;
6613 +
6614 + unsigned long lowest_stack;
6615 };
6616
6617 /*
6618 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
6619 index a3fe4dc..cae132a 100644
6620 --- a/arch/sparc/include/asm/thread_info_64.h
6621 +++ b/arch/sparc/include/asm/thread_info_64.h
6622 @@ -63,6 +63,8 @@ struct thread_info {
6623 struct pt_regs *kern_una_regs;
6624 unsigned int kern_una_insn;
6625
6626 + unsigned long lowest_stack;
6627 +
6628 unsigned long fpregs[0] __attribute__ ((aligned(64)));
6629 };
6630
6631 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
6632 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
6633 /* flag bit 6 is available */
6634 #define TIF_32BIT 7 /* 32-bit binary */
6635 -/* flag bit 8 is available */
6636 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
6637 #define TIF_SECCOMP 9 /* secure computing */
6638 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
6639 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
6640 +
6641 /* NOTE: Thread flags >= 12 should be ones we have no interest
6642 * in using in assembly, else we can't use the mask as
6643 * an immediate value in instructions such as andcc.
6644 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
6645 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
6646 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6647 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
6648 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6649
6650 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
6651 _TIF_DO_NOTIFY_RESUME_MASK | \
6652 _TIF_NEED_RESCHED)
6653 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
6654
6655 +#define _TIF_WORK_SYSCALL \
6656 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
6657 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6658 +
6659 +
6660 /*
6661 * Thread-synchronous status.
6662 *
6663 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
6664 index 0167d26..9acd8ed 100644
6665 --- a/arch/sparc/include/asm/uaccess.h
6666 +++ b/arch/sparc/include/asm/uaccess.h
6667 @@ -1,5 +1,13 @@
6668 #ifndef ___ASM_SPARC_UACCESS_H
6669 #define ___ASM_SPARC_UACCESS_H
6670 +
6671 +#ifdef __KERNEL__
6672 +#ifndef __ASSEMBLY__
6673 +#include <linux/types.h>
6674 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
6675 +#endif
6676 +#endif
6677 +
6678 #if defined(__sparc__) && defined(__arch64__)
6679 #include <asm/uaccess_64.h>
6680 #else
6681 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
6682 index 53a28dd..50c38c3 100644
6683 --- a/arch/sparc/include/asm/uaccess_32.h
6684 +++ b/arch/sparc/include/asm/uaccess_32.h
6685 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
6686
6687 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6688 {
6689 - if (n && __access_ok((unsigned long) to, n))
6690 + if ((long)n < 0)
6691 + return n;
6692 +
6693 + if (n && __access_ok((unsigned long) to, n)) {
6694 + if (!__builtin_constant_p(n))
6695 + check_object_size(from, n, true);
6696 return __copy_user(to, (__force void __user *) from, n);
6697 - else
6698 + } else
6699 return n;
6700 }
6701
6702 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
6703 {
6704 + if ((long)n < 0)
6705 + return n;
6706 +
6707 + if (!__builtin_constant_p(n))
6708 + check_object_size(from, n, true);
6709 +
6710 return __copy_user(to, (__force void __user *) from, n);
6711 }
6712
6713 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6714 {
6715 - if (n && __access_ok((unsigned long) from, n))
6716 + if ((long)n < 0)
6717 + return n;
6718 +
6719 + if (n && __access_ok((unsigned long) from, n)) {
6720 + if (!__builtin_constant_p(n))
6721 + check_object_size(to, n, false);
6722 return __copy_user((__force void __user *) to, from, n);
6723 - else
6724 + } else
6725 return n;
6726 }
6727
6728 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
6729 {
6730 + if ((long)n < 0)
6731 + return n;
6732 +
6733 return __copy_user((__force void __user *) to, from, n);
6734 }
6735
6736 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
6737 index 73083e1..2bc62a6 100644
6738 --- a/arch/sparc/include/asm/uaccess_64.h
6739 +++ b/arch/sparc/include/asm/uaccess_64.h
6740 @@ -10,6 +10,7 @@
6741 #include <linux/compiler.h>
6742 #include <linux/string.h>
6743 #include <linux/thread_info.h>
6744 +#include <linux/kernel.h>
6745 #include <asm/asi.h>
6746 #include <asm/spitfire.h>
6747 #include <asm-generic/uaccess-unaligned.h>
6748 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
6749 static inline unsigned long __must_check
6750 copy_from_user(void *to, const void __user *from, unsigned long size)
6751 {
6752 - unsigned long ret = ___copy_from_user(to, from, size);
6753 + unsigned long ret;
6754
6755 + if ((long)size < 0 || size > INT_MAX)
6756 + return size;
6757 +
6758 + if (!__builtin_constant_p(size))
6759 + check_object_size(to, size, false);
6760 +
6761 + ret = ___copy_from_user(to, from, size);
6762 if (unlikely(ret))
6763 ret = copy_from_user_fixup(to, from, size);
6764
6765 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
6766 static inline unsigned long __must_check
6767 copy_to_user(void __user *to, const void *from, unsigned long size)
6768 {
6769 - unsigned long ret = ___copy_to_user(to, from, size);
6770 + unsigned long ret;
6771
6772 + if ((long)size < 0 || size > INT_MAX)
6773 + return size;
6774 +
6775 + if (!__builtin_constant_p(size))
6776 + check_object_size(from, size, true);
6777 +
6778 + ret = ___copy_to_user(to, from, size);
6779 if (unlikely(ret))
6780 ret = copy_to_user_fixup(to, from, size);
6781 return ret;
6782 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
6783 index 6cf591b..b49e65a 100644
6784 --- a/arch/sparc/kernel/Makefile
6785 +++ b/arch/sparc/kernel/Makefile
6786 @@ -3,7 +3,7 @@
6787 #
6788
6789 asflags-y := -ansi
6790 -ccflags-y := -Werror
6791 +#ccflags-y := -Werror
6792
6793 extra-y := head_$(BITS).o
6794
6795 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
6796 index 487bffb..955a925 100644
6797 --- a/arch/sparc/kernel/process_32.c
6798 +++ b/arch/sparc/kernel/process_32.c
6799 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
6800
6801 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
6802 r->psr, r->pc, r->npc, r->y, print_tainted());
6803 - printk("PC: <%pS>\n", (void *) r->pc);
6804 + printk("PC: <%pA>\n", (void *) r->pc);
6805 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6806 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
6807 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
6808 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6809 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
6810 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
6811 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
6812 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
6813
6814 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6815 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
6816 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6817 rw = (struct reg_window32 *) fp;
6818 pc = rw->ins[7];
6819 printk("[%08lx : ", pc);
6820 - printk("%pS ] ", (void *) pc);
6821 + printk("%pA ] ", (void *) pc);
6822 fp = rw->ins[6];
6823 } while (++count < 16);
6824 printk("\n");
6825 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
6826 index c6e0c29..052832b 100644
6827 --- a/arch/sparc/kernel/process_64.c
6828 +++ b/arch/sparc/kernel/process_64.c
6829 @@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
6830 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
6831 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
6832 if (regs->tstate & TSTATE_PRIV)
6833 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
6834 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
6835 }
6836
6837 void show_regs(struct pt_regs *regs)
6838 {
6839 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
6840 regs->tpc, regs->tnpc, regs->y, print_tainted());
6841 - printk("TPC: <%pS>\n", (void *) regs->tpc);
6842 + printk("TPC: <%pA>\n", (void *) regs->tpc);
6843 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
6844 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
6845 regs->u_regs[3]);
6846 @@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
6847 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
6848 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
6849 regs->u_regs[15]);
6850 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
6851 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
6852 show_regwindow(regs);
6853 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
6854 }
6855 @@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
6856 ((tp && tp->task) ? tp->task->pid : -1));
6857
6858 if (gp->tstate & TSTATE_PRIV) {
6859 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
6860 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
6861 (void *) gp->tpc,
6862 (void *) gp->o7,
6863 (void *) gp->i7,
6864 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
6865 index 7ff45e4..a58f271 100644
6866 --- a/arch/sparc/kernel/ptrace_64.c
6867 +++ b/arch/sparc/kernel/ptrace_64.c
6868 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
6869 return ret;
6870 }
6871
6872 +#ifdef CONFIG_GRKERNSEC_SETXID
6873 +extern void gr_delayed_cred_worker(void);
6874 +#endif
6875 +
6876 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6877 {
6878 int ret = 0;
6879 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6880 /* do the secure computing check first */
6881 secure_computing_strict(regs->u_regs[UREG_G1]);
6882
6883 +#ifdef CONFIG_GRKERNSEC_SETXID
6884 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6885 + gr_delayed_cred_worker();
6886 +#endif
6887 +
6888 if (test_thread_flag(TIF_SYSCALL_TRACE))
6889 ret = tracehook_report_syscall_entry(regs);
6890
6891 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6892
6893 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
6894 {
6895 +#ifdef CONFIG_GRKERNSEC_SETXID
6896 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6897 + gr_delayed_cred_worker();
6898 +#endif
6899 +
6900 audit_syscall_exit(regs);
6901
6902 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6903 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
6904 index 0c9b31b..55a8ba6 100644
6905 --- a/arch/sparc/kernel/sys_sparc_32.c
6906 +++ b/arch/sparc/kernel/sys_sparc_32.c
6907 @@ -39,6 +39,7 @@ asmlinkage unsigned long sys_getpagesize(void)
6908 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
6909 {
6910 struct vm_area_struct * vmm;
6911 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
6912
6913 if (flags & MAP_FIXED) {
6914 /* We do not accept a shared mapping if it would violate
6915 @@ -54,7 +55,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6916 if (len > TASK_SIZE - PAGE_SIZE)
6917 return -ENOMEM;
6918 if (!addr)
6919 - addr = TASK_UNMAPPED_BASE;
6920 + addr = current->mm->mmap_base;
6921
6922 if (flags & MAP_SHARED)
6923 addr = COLOUR_ALIGN(addr);
6924 @@ -65,7 +66,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6925 /* At this point: (!vmm || addr < vmm->vm_end). */
6926 if (TASK_SIZE - PAGE_SIZE - len < addr)
6927 return -ENOMEM;
6928 - if (!vmm || addr + len <= vmm->vm_start)
6929 + if (check_heap_stack_gap(vmm, addr, len, offset))
6930 return addr;
6931 addr = vmm->vm_end;
6932 if (flags & MAP_SHARED)
6933 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
6934 index 878ef3d..f100719 100644
6935 --- a/arch/sparc/kernel/sys_sparc_64.c
6936 +++ b/arch/sparc/kernel/sys_sparc_64.c
6937 @@ -102,12 +102,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6938 unsigned long task_size = TASK_SIZE;
6939 unsigned long start_addr;
6940 int do_color_align;
6941 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6942
6943 if (flags & MAP_FIXED) {
6944 /* We do not accept a shared mapping if it would violate
6945 * cache aliasing constraints.
6946 */
6947 - if ((flags & MAP_SHARED) &&
6948 + if ((filp || (flags & MAP_SHARED)) &&
6949 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
6950 return -EINVAL;
6951 return addr;
6952 @@ -122,6 +123,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6953 if (filp || (flags & MAP_SHARED))
6954 do_color_align = 1;
6955
6956 +#ifdef CONFIG_PAX_RANDMMAP
6957 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6958 +#endif
6959 +
6960 if (addr) {
6961 if (do_color_align)
6962 addr = COLOUR_ALIGN(addr, pgoff);
6963 @@ -129,15 +134,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6964 addr = PAGE_ALIGN(addr);
6965
6966 vma = find_vma(mm, addr);
6967 - if (task_size - len >= addr &&
6968 - (!vma || addr + len <= vma->vm_start))
6969 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6970 return addr;
6971 }
6972
6973 if (len > mm->cached_hole_size) {
6974 - start_addr = addr = mm->free_area_cache;
6975 + start_addr = addr = mm->free_area_cache;
6976 } else {
6977 - start_addr = addr = TASK_UNMAPPED_BASE;
6978 + start_addr = addr = mm->mmap_base;
6979 mm->cached_hole_size = 0;
6980 }
6981
6982 @@ -157,14 +161,14 @@ full_search:
6983 vma = find_vma(mm, VA_EXCLUDE_END);
6984 }
6985 if (unlikely(task_size < addr)) {
6986 - if (start_addr != TASK_UNMAPPED_BASE) {
6987 - start_addr = addr = TASK_UNMAPPED_BASE;
6988 + if (start_addr != mm->mmap_base) {
6989 + start_addr = addr = mm->mmap_base;
6990 mm->cached_hole_size = 0;
6991 goto full_search;
6992 }
6993 return -ENOMEM;
6994 }
6995 - if (likely(!vma || addr + len <= vma->vm_start)) {
6996 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6997 /*
6998 * Remember the place where we stopped the search:
6999 */
7000 @@ -190,6 +194,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7001 unsigned long task_size = STACK_TOP32;
7002 unsigned long addr = addr0;
7003 int do_color_align;
7004 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7005
7006 /* This should only ever run for 32-bit processes. */
7007 BUG_ON(!test_thread_flag(TIF_32BIT));
7008 @@ -198,7 +203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7009 /* We do not accept a shared mapping if it would violate
7010 * cache aliasing constraints.
7011 */
7012 - if ((flags & MAP_SHARED) &&
7013 + if ((filp || (flags & MAP_SHARED)) &&
7014 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
7015 return -EINVAL;
7016 return addr;
7017 @@ -219,8 +224,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7018 addr = PAGE_ALIGN(addr);
7019
7020 vma = find_vma(mm, addr);
7021 - if (task_size - len >= addr &&
7022 - (!vma || addr + len <= vma->vm_start))
7023 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7024 return addr;
7025 }
7026
7027 @@ -241,7 +245,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7028 /* make sure it can fit in the remaining address space */
7029 if (likely(addr > len)) {
7030 vma = find_vma(mm, addr-len);
7031 - if (!vma || addr <= vma->vm_start) {
7032 + if (check_heap_stack_gap(vma, addr - len, len, offset)) {
7033 /* remember the address as a hint for next time */
7034 return (mm->free_area_cache = addr-len);
7035 }
7036 @@ -250,18 +254,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7037 if (unlikely(mm->mmap_base < len))
7038 goto bottomup;
7039
7040 - addr = mm->mmap_base-len;
7041 - if (do_color_align)
7042 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
7043 + addr = mm->mmap_base - len;
7044
7045 do {
7046 + if (do_color_align)
7047 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
7048 /*
7049 * Lookup failure means no vma is above this address,
7050 * else if new region fits below vma->vm_start,
7051 * return with success:
7052 */
7053 vma = find_vma(mm, addr);
7054 - if (likely(!vma || addr+len <= vma->vm_start)) {
7055 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
7056 /* remember the address as a hint for next time */
7057 return (mm->free_area_cache = addr);
7058 }
7059 @@ -271,10 +275,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7060 mm->cached_hole_size = vma->vm_start - addr;
7061
7062 /* try just below the current vma->vm_start */
7063 - addr = vma->vm_start-len;
7064 - if (do_color_align)
7065 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
7066 - } while (likely(len < vma->vm_start));
7067 + addr = skip_heap_stack_gap(vma, len, offset);
7068 + } while (!IS_ERR_VALUE(addr));
7069
7070 bottomup:
7071 /*
7072 @@ -348,6 +350,10 @@ static unsigned long mmap_rnd(void)
7073 {
7074 unsigned long rnd = 0UL;
7075
7076 +#ifdef CONFIG_PAX_RANDMMAP
7077 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7078 +#endif
7079 +
7080 if (current->flags & PF_RANDOMIZE) {
7081 unsigned long val = get_random_int();
7082 if (test_thread_flag(TIF_32BIT))
7083 @@ -373,6 +379,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7084 gap == RLIM_INFINITY ||
7085 sysctl_legacy_va_layout) {
7086 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7087 +
7088 +#ifdef CONFIG_PAX_RANDMMAP
7089 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7090 + mm->mmap_base += mm->delta_mmap;
7091 +#endif
7092 +
7093 mm->get_unmapped_area = arch_get_unmapped_area;
7094 mm->unmap_area = arch_unmap_area;
7095 } else {
7096 @@ -385,6 +397,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7097 gap = (task_size / 6 * 5);
7098
7099 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
7100 +
7101 +#ifdef CONFIG_PAX_RANDMMAP
7102 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7103 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7104 +#endif
7105 +
7106 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7107 mm->unmap_area = arch_unmap_area_topdown;
7108 }
7109 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
7110 index bf23477..b7425a6 100644
7111 --- a/arch/sparc/kernel/syscalls.S
7112 +++ b/arch/sparc/kernel/syscalls.S
7113 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
7114 #endif
7115 .align 32
7116 1: ldx [%g6 + TI_FLAGS], %l5
7117 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7118 + andcc %l5, _TIF_WORK_SYSCALL, %g0
7119 be,pt %icc, rtrap
7120 nop
7121 call syscall_trace_leave
7122 @@ -189,7 +189,7 @@ linux_sparc_syscall32:
7123
7124 srl %i5, 0, %o5 ! IEU1
7125 srl %i2, 0, %o2 ! IEU0 Group
7126 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7127 + andcc %l0, _TIF_WORK_SYSCALL, %g0
7128 bne,pn %icc, linux_syscall_trace32 ! CTI
7129 mov %i0, %l5 ! IEU1
7130 call %l7 ! CTI Group brk forced
7131 @@ -212,7 +212,7 @@ linux_sparc_syscall:
7132
7133 mov %i3, %o3 ! IEU1
7134 mov %i4, %o4 ! IEU0 Group
7135 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7136 + andcc %l0, _TIF_WORK_SYSCALL, %g0
7137 bne,pn %icc, linux_syscall_trace ! CTI Group
7138 mov %i0, %l5 ! IEU0
7139 2: call %l7 ! CTI Group brk forced
7140 @@ -228,7 +228,7 @@ ret_sys_call:
7141
7142 cmp %o0, -ERESTART_RESTARTBLOCK
7143 bgeu,pn %xcc, 1f
7144 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7145 + andcc %l0, _TIF_WORK_SYSCALL, %g0
7146 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
7147
7148 2:
7149 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
7150 index a5785ea..405c5f7 100644
7151 --- a/arch/sparc/kernel/traps_32.c
7152 +++ b/arch/sparc/kernel/traps_32.c
7153 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
7154 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
7155 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
7156
7157 +extern void gr_handle_kernel_exploit(void);
7158 +
7159 void die_if_kernel(char *str, struct pt_regs *regs)
7160 {
7161 static int die_counter;
7162 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7163 count++ < 30 &&
7164 (((unsigned long) rw) >= PAGE_OFFSET) &&
7165 !(((unsigned long) rw) & 0x7)) {
7166 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
7167 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
7168 (void *) rw->ins[7]);
7169 rw = (struct reg_window32 *)rw->ins[6];
7170 }
7171 }
7172 printk("Instruction DUMP:");
7173 instruction_dump ((unsigned long *) regs->pc);
7174 - if(regs->psr & PSR_PS)
7175 + if(regs->psr & PSR_PS) {
7176 + gr_handle_kernel_exploit();
7177 do_exit(SIGKILL);
7178 + }
7179 do_exit(SIGSEGV);
7180 }
7181
7182 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
7183 index b66a779..8e8d66c 100644
7184 --- a/arch/sparc/kernel/traps_64.c
7185 +++ b/arch/sparc/kernel/traps_64.c
7186 @@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
7187 i + 1,
7188 p->trapstack[i].tstate, p->trapstack[i].tpc,
7189 p->trapstack[i].tnpc, p->trapstack[i].tt);
7190 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
7191 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
7192 }
7193 }
7194
7195 @@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
7196
7197 lvl -= 0x100;
7198 if (regs->tstate & TSTATE_PRIV) {
7199 +
7200 +#ifdef CONFIG_PAX_REFCOUNT
7201 + if (lvl == 6)
7202 + pax_report_refcount_overflow(regs);
7203 +#endif
7204 +
7205 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
7206 die_if_kernel(buffer, regs);
7207 }
7208 @@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
7209 void bad_trap_tl1(struct pt_regs *regs, long lvl)
7210 {
7211 char buffer[32];
7212 -
7213 +
7214 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
7215 0, lvl, SIGTRAP) == NOTIFY_STOP)
7216 return;
7217
7218 +#ifdef CONFIG_PAX_REFCOUNT
7219 + if (lvl == 6)
7220 + pax_report_refcount_overflow(regs);
7221 +#endif
7222 +
7223 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
7224
7225 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
7226 @@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
7227 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
7228 printk("%s" "ERROR(%d): ",
7229 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
7230 - printk("TPC<%pS>\n", (void *) regs->tpc);
7231 + printk("TPC<%pA>\n", (void *) regs->tpc);
7232 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
7233 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
7234 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
7235 @@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
7236 smp_processor_id(),
7237 (type & 0x1) ? 'I' : 'D',
7238 regs->tpc);
7239 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
7240 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
7241 panic("Irrecoverable Cheetah+ parity error.");
7242 }
7243
7244 @@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
7245 smp_processor_id(),
7246 (type & 0x1) ? 'I' : 'D',
7247 regs->tpc);
7248 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
7249 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
7250 }
7251
7252 struct sun4v_error_entry {
7253 @@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
7254
7255 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
7256 regs->tpc, tl);
7257 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
7258 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
7259 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
7260 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
7261 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
7262 (void *) regs->u_regs[UREG_I7]);
7263 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
7264 "pte[%lx] error[%lx]\n",
7265 @@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
7266
7267 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
7268 regs->tpc, tl);
7269 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
7270 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
7271 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
7272 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
7273 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
7274 (void *) regs->u_regs[UREG_I7]);
7275 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
7276 "pte[%lx] error[%lx]\n",
7277 @@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
7278 fp = (unsigned long)sf->fp + STACK_BIAS;
7279 }
7280
7281 - printk(" [%016lx] %pS\n", pc, (void *) pc);
7282 + printk(" [%016lx] %pA\n", pc, (void *) pc);
7283 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
7284 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
7285 int index = tsk->curr_ret_stack;
7286 if (tsk->ret_stack && index >= graph) {
7287 pc = tsk->ret_stack[index - graph].ret;
7288 - printk(" [%016lx] %pS\n", pc, (void *) pc);
7289 + printk(" [%016lx] %pA\n", pc, (void *) pc);
7290 graph++;
7291 }
7292 }
7293 @@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
7294 return (struct reg_window *) (fp + STACK_BIAS);
7295 }
7296
7297 +extern void gr_handle_kernel_exploit(void);
7298 +
7299 void die_if_kernel(char *str, struct pt_regs *regs)
7300 {
7301 static int die_counter;
7302 @@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7303 while (rw &&
7304 count++ < 30 &&
7305 kstack_valid(tp, (unsigned long) rw)) {
7306 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
7307 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
7308 (void *) rw->ins[7]);
7309
7310 rw = kernel_stack_up(rw);
7311 @@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7312 }
7313 user_instruction_dump ((unsigned int __user *) regs->tpc);
7314 }
7315 - if (regs->tstate & TSTATE_PRIV)
7316 + if (regs->tstate & TSTATE_PRIV) {
7317 + gr_handle_kernel_exploit();
7318 do_exit(SIGKILL);
7319 + }
7320 do_exit(SIGSEGV);
7321 }
7322 EXPORT_SYMBOL(die_if_kernel);
7323 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
7324 index 8201c25e..072a2a7 100644
7325 --- a/arch/sparc/kernel/unaligned_64.c
7326 +++ b/arch/sparc/kernel/unaligned_64.c
7327 @@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
7328 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
7329
7330 if (__ratelimit(&ratelimit)) {
7331 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
7332 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
7333 regs->tpc, (void *) regs->tpc);
7334 }
7335 }
7336 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
7337 index 8410065f2..4fd4ca22 100644
7338 --- a/arch/sparc/lib/Makefile
7339 +++ b/arch/sparc/lib/Makefile
7340 @@ -2,7 +2,7 @@
7341 #
7342
7343 asflags-y := -ansi -DST_DIV0=0x02
7344 -ccflags-y := -Werror
7345 +#ccflags-y := -Werror
7346
7347 lib-$(CONFIG_SPARC32) += ashrdi3.o
7348 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
7349 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
7350 index 85c233d..68500e0 100644
7351 --- a/arch/sparc/lib/atomic_64.S
7352 +++ b/arch/sparc/lib/atomic_64.S
7353 @@ -17,7 +17,12 @@
7354 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7355 BACKOFF_SETUP(%o2)
7356 1: lduw [%o1], %g1
7357 - add %g1, %o0, %g7
7358 + addcc %g1, %o0, %g7
7359 +
7360 +#ifdef CONFIG_PAX_REFCOUNT
7361 + tvs %icc, 6
7362 +#endif
7363 +
7364 cas [%o1], %g1, %g7
7365 cmp %g1, %g7
7366 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7367 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7368 2: BACKOFF_SPIN(%o2, %o3, 1b)
7369 ENDPROC(atomic_add)
7370
7371 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7372 + BACKOFF_SETUP(%o2)
7373 +1: lduw [%o1], %g1
7374 + add %g1, %o0, %g7
7375 + cas [%o1], %g1, %g7
7376 + cmp %g1, %g7
7377 + bne,pn %icc, 2f
7378 + nop
7379 + retl
7380 + nop
7381 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7382 +ENDPROC(atomic_add_unchecked)
7383 +
7384 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7385 BACKOFF_SETUP(%o2)
7386 1: lduw [%o1], %g1
7387 - sub %g1, %o0, %g7
7388 + subcc %g1, %o0, %g7
7389 +
7390 +#ifdef CONFIG_PAX_REFCOUNT
7391 + tvs %icc, 6
7392 +#endif
7393 +
7394 cas [%o1], %g1, %g7
7395 cmp %g1, %g7
7396 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7397 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7398 2: BACKOFF_SPIN(%o2, %o3, 1b)
7399 ENDPROC(atomic_sub)
7400
7401 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7402 + BACKOFF_SETUP(%o2)
7403 +1: lduw [%o1], %g1
7404 + sub %g1, %o0, %g7
7405 + cas [%o1], %g1, %g7
7406 + cmp %g1, %g7
7407 + bne,pn %icc, 2f
7408 + nop
7409 + retl
7410 + nop
7411 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7412 +ENDPROC(atomic_sub_unchecked)
7413 +
7414 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7415 BACKOFF_SETUP(%o2)
7416 1: lduw [%o1], %g1
7417 - add %g1, %o0, %g7
7418 + addcc %g1, %o0, %g7
7419 +
7420 +#ifdef CONFIG_PAX_REFCOUNT
7421 + tvs %icc, 6
7422 +#endif
7423 +
7424 cas [%o1], %g1, %g7
7425 cmp %g1, %g7
7426 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7427 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7428 2: BACKOFF_SPIN(%o2, %o3, 1b)
7429 ENDPROC(atomic_add_ret)
7430
7431 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7432 + BACKOFF_SETUP(%o2)
7433 +1: lduw [%o1], %g1
7434 + addcc %g1, %o0, %g7
7435 + cas [%o1], %g1, %g7
7436 + cmp %g1, %g7
7437 + bne,pn %icc, 2f
7438 + add %g7, %o0, %g7
7439 + sra %g7, 0, %o0
7440 + retl
7441 + nop
7442 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7443 +ENDPROC(atomic_add_ret_unchecked)
7444 +
7445 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7446 BACKOFF_SETUP(%o2)
7447 1: lduw [%o1], %g1
7448 - sub %g1, %o0, %g7
7449 + subcc %g1, %o0, %g7
7450 +
7451 +#ifdef CONFIG_PAX_REFCOUNT
7452 + tvs %icc, 6
7453 +#endif
7454 +
7455 cas [%o1], %g1, %g7
7456 cmp %g1, %g7
7457 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7458 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
7459 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7460 BACKOFF_SETUP(%o2)
7461 1: ldx [%o1], %g1
7462 - add %g1, %o0, %g7
7463 + addcc %g1, %o0, %g7
7464 +
7465 +#ifdef CONFIG_PAX_REFCOUNT
7466 + tvs %xcc, 6
7467 +#endif
7468 +
7469 casx [%o1], %g1, %g7
7470 cmp %g1, %g7
7471 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7472 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7473 2: BACKOFF_SPIN(%o2, %o3, 1b)
7474 ENDPROC(atomic64_add)
7475
7476 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7477 + BACKOFF_SETUP(%o2)
7478 +1: ldx [%o1], %g1
7479 + addcc %g1, %o0, %g7
7480 + casx [%o1], %g1, %g7
7481 + cmp %g1, %g7
7482 + bne,pn %xcc, 2f
7483 + nop
7484 + retl
7485 + nop
7486 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7487 +ENDPROC(atomic64_add_unchecked)
7488 +
7489 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7490 BACKOFF_SETUP(%o2)
7491 1: ldx [%o1], %g1
7492 - sub %g1, %o0, %g7
7493 + subcc %g1, %o0, %g7
7494 +
7495 +#ifdef CONFIG_PAX_REFCOUNT
7496 + tvs %xcc, 6
7497 +#endif
7498 +
7499 casx [%o1], %g1, %g7
7500 cmp %g1, %g7
7501 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7502 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7503 2: BACKOFF_SPIN(%o2, %o3, 1b)
7504 ENDPROC(atomic64_sub)
7505
7506 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7507 + BACKOFF_SETUP(%o2)
7508 +1: ldx [%o1], %g1
7509 + subcc %g1, %o0, %g7
7510 + casx [%o1], %g1, %g7
7511 + cmp %g1, %g7
7512 + bne,pn %xcc, 2f
7513 + nop
7514 + retl
7515 + nop
7516 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7517 +ENDPROC(atomic64_sub_unchecked)
7518 +
7519 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7520 BACKOFF_SETUP(%o2)
7521 1: ldx [%o1], %g1
7522 - add %g1, %o0, %g7
7523 + addcc %g1, %o0, %g7
7524 +
7525 +#ifdef CONFIG_PAX_REFCOUNT
7526 + tvs %xcc, 6
7527 +#endif
7528 +
7529 casx [%o1], %g1, %g7
7530 cmp %g1, %g7
7531 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7532 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7533 2: BACKOFF_SPIN(%o2, %o3, 1b)
7534 ENDPROC(atomic64_add_ret)
7535
7536 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7537 + BACKOFF_SETUP(%o2)
7538 +1: ldx [%o1], %g1
7539 + addcc %g1, %o0, %g7
7540 + casx [%o1], %g1, %g7
7541 + cmp %g1, %g7
7542 + bne,pn %xcc, 2f
7543 + add %g7, %o0, %g7
7544 + mov %g7, %o0
7545 + retl
7546 + nop
7547 +2: BACKOFF_SPIN(%o2, %o3, 1b)
7548 +ENDPROC(atomic64_add_ret_unchecked)
7549 +
7550 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7551 BACKOFF_SETUP(%o2)
7552 1: ldx [%o1], %g1
7553 - sub %g1, %o0, %g7
7554 + subcc %g1, %o0, %g7
7555 +
7556 +#ifdef CONFIG_PAX_REFCOUNT
7557 + tvs %xcc, 6
7558 +#endif
7559 +
7560 casx [%o1], %g1, %g7
7561 cmp %g1, %g7
7562 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7563 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
7564 index 0c4e35e..745d3e4 100644
7565 --- a/arch/sparc/lib/ksyms.c
7566 +++ b/arch/sparc/lib/ksyms.c
7567 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
7568
7569 /* Atomic counter implementation. */
7570 EXPORT_SYMBOL(atomic_add);
7571 +EXPORT_SYMBOL(atomic_add_unchecked);
7572 EXPORT_SYMBOL(atomic_add_ret);
7573 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
7574 EXPORT_SYMBOL(atomic_sub);
7575 +EXPORT_SYMBOL(atomic_sub_unchecked);
7576 EXPORT_SYMBOL(atomic_sub_ret);
7577 EXPORT_SYMBOL(atomic64_add);
7578 +EXPORT_SYMBOL(atomic64_add_unchecked);
7579 EXPORT_SYMBOL(atomic64_add_ret);
7580 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
7581 EXPORT_SYMBOL(atomic64_sub);
7582 +EXPORT_SYMBOL(atomic64_sub_unchecked);
7583 EXPORT_SYMBOL(atomic64_sub_ret);
7584 EXPORT_SYMBOL(atomic64_dec_if_positive);
7585
7586 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
7587 index 30c3ecc..736f015 100644
7588 --- a/arch/sparc/mm/Makefile
7589 +++ b/arch/sparc/mm/Makefile
7590 @@ -2,7 +2,7 @@
7591 #
7592
7593 asflags-y := -ansi
7594 -ccflags-y := -Werror
7595 +#ccflags-y := -Werror
7596
7597 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
7598 obj-y += fault_$(BITS).o
7599 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
7600 index e98bfda..ea8d221 100644
7601 --- a/arch/sparc/mm/fault_32.c
7602 +++ b/arch/sparc/mm/fault_32.c
7603 @@ -21,6 +21,9 @@
7604 #include <linux/perf_event.h>
7605 #include <linux/interrupt.h>
7606 #include <linux/kdebug.h>
7607 +#include <linux/slab.h>
7608 +#include <linux/pagemap.h>
7609 +#include <linux/compiler.h>
7610
7611 #include <asm/page.h>
7612 #include <asm/pgtable.h>
7613 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
7614 return safe_compute_effective_address(regs, insn);
7615 }
7616
7617 +#ifdef CONFIG_PAX_PAGEEXEC
7618 +#ifdef CONFIG_PAX_DLRESOLVE
7619 +static void pax_emuplt_close(struct vm_area_struct *vma)
7620 +{
7621 + vma->vm_mm->call_dl_resolve = 0UL;
7622 +}
7623 +
7624 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7625 +{
7626 + unsigned int *kaddr;
7627 +
7628 + vmf->page = alloc_page(GFP_HIGHUSER);
7629 + if (!vmf->page)
7630 + return VM_FAULT_OOM;
7631 +
7632 + kaddr = kmap(vmf->page);
7633 + memset(kaddr, 0, PAGE_SIZE);
7634 + kaddr[0] = 0x9DE3BFA8U; /* save */
7635 + flush_dcache_page(vmf->page);
7636 + kunmap(vmf->page);
7637 + return VM_FAULT_MAJOR;
7638 +}
7639 +
7640 +static const struct vm_operations_struct pax_vm_ops = {
7641 + .close = pax_emuplt_close,
7642 + .fault = pax_emuplt_fault
7643 +};
7644 +
7645 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7646 +{
7647 + int ret;
7648 +
7649 + INIT_LIST_HEAD(&vma->anon_vma_chain);
7650 + vma->vm_mm = current->mm;
7651 + vma->vm_start = addr;
7652 + vma->vm_end = addr + PAGE_SIZE;
7653 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7654 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7655 + vma->vm_ops = &pax_vm_ops;
7656 +
7657 + ret = insert_vm_struct(current->mm, vma);
7658 + if (ret)
7659 + return ret;
7660 +
7661 + ++current->mm->total_vm;
7662 + return 0;
7663 +}
7664 +#endif
7665 +
7666 +/*
7667 + * PaX: decide what to do with offenders (regs->pc = fault address)
7668 + *
7669 + * returns 1 when task should be killed
7670 + * 2 when patched PLT trampoline was detected
7671 + * 3 when unpatched PLT trampoline was detected
7672 + */
7673 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7674 +{
7675 +
7676 +#ifdef CONFIG_PAX_EMUPLT
7677 + int err;
7678 +
7679 + do { /* PaX: patched PLT emulation #1 */
7680 + unsigned int sethi1, sethi2, jmpl;
7681 +
7682 + err = get_user(sethi1, (unsigned int *)regs->pc);
7683 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
7684 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
7685 +
7686 + if (err)
7687 + break;
7688 +
7689 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
7690 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
7691 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
7692 + {
7693 + unsigned int addr;
7694 +
7695 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
7696 + addr = regs->u_regs[UREG_G1];
7697 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7698 + regs->pc = addr;
7699 + regs->npc = addr+4;
7700 + return 2;
7701 + }
7702 + } while (0);
7703 +
7704 + do { /* PaX: patched PLT emulation #2 */
7705 + unsigned int ba;
7706 +
7707 + err = get_user(ba, (unsigned int *)regs->pc);
7708 +
7709 + if (err)
7710 + break;
7711 +
7712 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
7713 + unsigned int addr;
7714 +
7715 + if ((ba & 0xFFC00000U) == 0x30800000U)
7716 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7717 + else
7718 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7719 + regs->pc = addr;
7720 + regs->npc = addr+4;
7721 + return 2;
7722 + }
7723 + } while (0);
7724 +
7725 + do { /* PaX: patched PLT emulation #3 */
7726 + unsigned int sethi, bajmpl, nop;
7727 +
7728 + err = get_user(sethi, (unsigned int *)regs->pc);
7729 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
7730 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
7731 +
7732 + if (err)
7733 + break;
7734 +
7735 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7736 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
7737 + nop == 0x01000000U)
7738 + {
7739 + unsigned int addr;
7740 +
7741 + addr = (sethi & 0x003FFFFFU) << 10;
7742 + regs->u_regs[UREG_G1] = addr;
7743 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
7744 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7745 + else
7746 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7747 + regs->pc = addr;
7748 + regs->npc = addr+4;
7749 + return 2;
7750 + }
7751 + } while (0);
7752 +
7753 + do { /* PaX: unpatched PLT emulation step 1 */
7754 + unsigned int sethi, ba, nop;
7755 +
7756 + err = get_user(sethi, (unsigned int *)regs->pc);
7757 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
7758 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
7759 +
7760 + if (err)
7761 + break;
7762 +
7763 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7764 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7765 + nop == 0x01000000U)
7766 + {
7767 + unsigned int addr, save, call;
7768 +
7769 + if ((ba & 0xFFC00000U) == 0x30800000U)
7770 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7771 + else
7772 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7773 +
7774 + err = get_user(save, (unsigned int *)addr);
7775 + err |= get_user(call, (unsigned int *)(addr+4));
7776 + err |= get_user(nop, (unsigned int *)(addr+8));
7777 + if (err)
7778 + break;
7779 +
7780 +#ifdef CONFIG_PAX_DLRESOLVE
7781 + if (save == 0x9DE3BFA8U &&
7782 + (call & 0xC0000000U) == 0x40000000U &&
7783 + nop == 0x01000000U)
7784 + {
7785 + struct vm_area_struct *vma;
7786 + unsigned long call_dl_resolve;
7787 +
7788 + down_read(&current->mm->mmap_sem);
7789 + call_dl_resolve = current->mm->call_dl_resolve;
7790 + up_read(&current->mm->mmap_sem);
7791 + if (likely(call_dl_resolve))
7792 + goto emulate;
7793 +
7794 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7795 +
7796 + down_write(&current->mm->mmap_sem);
7797 + if (current->mm->call_dl_resolve) {
7798 + call_dl_resolve = current->mm->call_dl_resolve;
7799 + up_write(&current->mm->mmap_sem);
7800 + if (vma)
7801 + kmem_cache_free(vm_area_cachep, vma);
7802 + goto emulate;
7803 + }
7804 +
7805 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7806 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7807 + up_write(&current->mm->mmap_sem);
7808 + if (vma)
7809 + kmem_cache_free(vm_area_cachep, vma);
7810 + return 1;
7811 + }
7812 +
7813 + if (pax_insert_vma(vma, call_dl_resolve)) {
7814 + up_write(&current->mm->mmap_sem);
7815 + kmem_cache_free(vm_area_cachep, vma);
7816 + return 1;
7817 + }
7818 +
7819 + current->mm->call_dl_resolve = call_dl_resolve;
7820 + up_write(&current->mm->mmap_sem);
7821 +
7822 +emulate:
7823 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7824 + regs->pc = call_dl_resolve;
7825 + regs->npc = addr+4;
7826 + return 3;
7827 + }
7828 +#endif
7829 +
7830 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7831 + if ((save & 0xFFC00000U) == 0x05000000U &&
7832 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7833 + nop == 0x01000000U)
7834 + {
7835 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7836 + regs->u_regs[UREG_G2] = addr + 4;
7837 + addr = (save & 0x003FFFFFU) << 10;
7838 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7839 + regs->pc = addr;
7840 + regs->npc = addr+4;
7841 + return 3;
7842 + }
7843 + }
7844 + } while (0);
7845 +
7846 + do { /* PaX: unpatched PLT emulation step 2 */
7847 + unsigned int save, call, nop;
7848 +
7849 + err = get_user(save, (unsigned int *)(regs->pc-4));
7850 + err |= get_user(call, (unsigned int *)regs->pc);
7851 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
7852 + if (err)
7853 + break;
7854 +
7855 + if (save == 0x9DE3BFA8U &&
7856 + (call & 0xC0000000U) == 0x40000000U &&
7857 + nop == 0x01000000U)
7858 + {
7859 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
7860 +
7861 + regs->u_regs[UREG_RETPC] = regs->pc;
7862 + regs->pc = dl_resolve;
7863 + regs->npc = dl_resolve+4;
7864 + return 3;
7865 + }
7866 + } while (0);
7867 +#endif
7868 +
7869 + return 1;
7870 +}
7871 +
7872 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7873 +{
7874 + unsigned long i;
7875 +
7876 + printk(KERN_ERR "PAX: bytes at PC: ");
7877 + for (i = 0; i < 8; i++) {
7878 + unsigned int c;
7879 + if (get_user(c, (unsigned int *)pc+i))
7880 + printk(KERN_CONT "???????? ");
7881 + else
7882 + printk(KERN_CONT "%08x ", c);
7883 + }
7884 + printk("\n");
7885 +}
7886 +#endif
7887 +
7888 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
7889 int text_fault)
7890 {
7891 @@ -230,6 +504,24 @@ good_area:
7892 if (!(vma->vm_flags & VM_WRITE))
7893 goto bad_area;
7894 } else {
7895 +
7896 +#ifdef CONFIG_PAX_PAGEEXEC
7897 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
7898 + up_read(&mm->mmap_sem);
7899 + switch (pax_handle_fetch_fault(regs)) {
7900 +
7901 +#ifdef CONFIG_PAX_EMUPLT
7902 + case 2:
7903 + case 3:
7904 + return;
7905 +#endif
7906 +
7907 + }
7908 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
7909 + do_group_exit(SIGKILL);
7910 + }
7911 +#endif
7912 +
7913 /* Allow reads even for write-only mappings */
7914 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
7915 goto bad_area;
7916 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
7917 index 097aee7..5ca6697 100644
7918 --- a/arch/sparc/mm/fault_64.c
7919 +++ b/arch/sparc/mm/fault_64.c
7920 @@ -21,6 +21,9 @@
7921 #include <linux/kprobes.h>
7922 #include <linux/kdebug.h>
7923 #include <linux/percpu.h>
7924 +#include <linux/slab.h>
7925 +#include <linux/pagemap.h>
7926 +#include <linux/compiler.h>
7927
7928 #include <asm/page.h>
7929 #include <asm/pgtable.h>
7930 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
7931 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
7932 regs->tpc);
7933 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
7934 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
7935 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
7936 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
7937 dump_stack();
7938 unhandled_fault(regs->tpc, current, regs);
7939 @@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
7940 show_regs(regs);
7941 }
7942
7943 +#ifdef CONFIG_PAX_PAGEEXEC
7944 +#ifdef CONFIG_PAX_DLRESOLVE
7945 +static void pax_emuplt_close(struct vm_area_struct *vma)
7946 +{
7947 + vma->vm_mm->call_dl_resolve = 0UL;
7948 +}
7949 +
7950 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7951 +{
7952 + unsigned int *kaddr;
7953 +
7954 + vmf->page = alloc_page(GFP_HIGHUSER);
7955 + if (!vmf->page)
7956 + return VM_FAULT_OOM;
7957 +
7958 + kaddr = kmap(vmf->page);
7959 + memset(kaddr, 0, PAGE_SIZE);
7960 + kaddr[0] = 0x9DE3BFA8U; /* save */
7961 + flush_dcache_page(vmf->page);
7962 + kunmap(vmf->page);
7963 + return VM_FAULT_MAJOR;
7964 +}
7965 +
7966 +static const struct vm_operations_struct pax_vm_ops = {
7967 + .close = pax_emuplt_close,
7968 + .fault = pax_emuplt_fault
7969 +};
7970 +
7971 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7972 +{
7973 + int ret;
7974 +
7975 + INIT_LIST_HEAD(&vma->anon_vma_chain);
7976 + vma->vm_mm = current->mm;
7977 + vma->vm_start = addr;
7978 + vma->vm_end = addr + PAGE_SIZE;
7979 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7980 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7981 + vma->vm_ops = &pax_vm_ops;
7982 +
7983 + ret = insert_vm_struct(current->mm, vma);
7984 + if (ret)
7985 + return ret;
7986 +
7987 + ++current->mm->total_vm;
7988 + return 0;
7989 +}
7990 +#endif
7991 +
7992 +/*
7993 + * PaX: decide what to do with offenders (regs->tpc = fault address)
7994 + *
7995 + * returns 1 when task should be killed
7996 + * 2 when patched PLT trampoline was detected
7997 + * 3 when unpatched PLT trampoline was detected
7998 + */
7999 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8000 +{
8001 +
8002 +#ifdef CONFIG_PAX_EMUPLT
8003 + int err;
8004 +
8005 + do { /* PaX: patched PLT emulation #1 */
8006 + unsigned int sethi1, sethi2, jmpl;
8007 +
8008 + err = get_user(sethi1, (unsigned int *)regs->tpc);
8009 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
8010 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
8011 +
8012 + if (err)
8013 + break;
8014 +
8015 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
8016 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
8017 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
8018 + {
8019 + unsigned long addr;
8020 +
8021 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
8022 + addr = regs->u_regs[UREG_G1];
8023 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8024 +
8025 + if (test_thread_flag(TIF_32BIT))
8026 + addr &= 0xFFFFFFFFUL;
8027 +
8028 + regs->tpc = addr;
8029 + regs->tnpc = addr+4;
8030 + return 2;
8031 + }
8032 + } while (0);
8033 +
8034 + do { /* PaX: patched PLT emulation #2 */
8035 + unsigned int ba;
8036 +
8037 + err = get_user(ba, (unsigned int *)regs->tpc);
8038 +
8039 + if (err)
8040 + break;
8041 +
8042 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
8043 + unsigned long addr;
8044 +
8045 + if ((ba & 0xFFC00000U) == 0x30800000U)
8046 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
8047 + else
8048 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8049 +
8050 + if (test_thread_flag(TIF_32BIT))
8051 + addr &= 0xFFFFFFFFUL;
8052 +
8053 + regs->tpc = addr;
8054 + regs->tnpc = addr+4;
8055 + return 2;
8056 + }
8057 + } while (0);
8058 +
8059 + do { /* PaX: patched PLT emulation #3 */
8060 + unsigned int sethi, bajmpl, nop;
8061 +
8062 + err = get_user(sethi, (unsigned int *)regs->tpc);
8063 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
8064 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8065 +
8066 + if (err)
8067 + break;
8068 +
8069 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8070 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
8071 + nop == 0x01000000U)
8072 + {
8073 + unsigned long addr;
8074 +
8075 + addr = (sethi & 0x003FFFFFU) << 10;
8076 + regs->u_regs[UREG_G1] = addr;
8077 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
8078 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8079 + else
8080 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8081 +
8082 + if (test_thread_flag(TIF_32BIT))
8083 + addr &= 0xFFFFFFFFUL;
8084 +
8085 + regs->tpc = addr;
8086 + regs->tnpc = addr+4;
8087 + return 2;
8088 + }
8089 + } while (0);
8090 +
8091 + do { /* PaX: patched PLT emulation #4 */
8092 + unsigned int sethi, mov1, call, mov2;
8093 +
8094 + err = get_user(sethi, (unsigned int *)regs->tpc);
8095 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
8096 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
8097 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
8098 +
8099 + if (err)
8100 + break;
8101 +
8102 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8103 + mov1 == 0x8210000FU &&
8104 + (call & 0xC0000000U) == 0x40000000U &&
8105 + mov2 == 0x9E100001U)
8106 + {
8107 + unsigned long addr;
8108 +
8109 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
8110 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
8111 +
8112 + if (test_thread_flag(TIF_32BIT))
8113 + addr &= 0xFFFFFFFFUL;
8114 +
8115 + regs->tpc = addr;
8116 + regs->tnpc = addr+4;
8117 + return 2;
8118 + }
8119 + } while (0);
8120 +
8121 + do { /* PaX: patched PLT emulation #5 */
8122 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
8123 +
8124 + err = get_user(sethi, (unsigned int *)regs->tpc);
8125 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
8126 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
8127 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
8128 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
8129 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
8130 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
8131 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
8132 +
8133 + if (err)
8134 + break;
8135 +
8136 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8137 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
8138 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8139 + (or1 & 0xFFFFE000U) == 0x82106000U &&
8140 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
8141 + sllx == 0x83287020U &&
8142 + jmpl == 0x81C04005U &&
8143 + nop == 0x01000000U)
8144 + {
8145 + unsigned long addr;
8146 +
8147 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
8148 + regs->u_regs[UREG_G1] <<= 32;
8149 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
8150 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
8151 + regs->tpc = addr;
8152 + regs->tnpc = addr+4;
8153 + return 2;
8154 + }
8155 + } while (0);
8156 +
8157 + do { /* PaX: patched PLT emulation #6 */
8158 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
8159 +
8160 + err = get_user(sethi, (unsigned int *)regs->tpc);
8161 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
8162 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
8163 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
8164 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
8165 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
8166 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
8167 +
8168 + if (err)
8169 + break;
8170 +
8171 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8172 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
8173 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8174 + sllx == 0x83287020U &&
8175 + (or & 0xFFFFE000U) == 0x8A116000U &&
8176 + jmpl == 0x81C04005U &&
8177 + nop == 0x01000000U)
8178 + {
8179 + unsigned long addr;
8180 +
8181 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
8182 + regs->u_regs[UREG_G1] <<= 32;
8183 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
8184 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
8185 + regs->tpc = addr;
8186 + regs->tnpc = addr+4;
8187 + return 2;
8188 + }
8189 + } while (0);
8190 +
8191 + do { /* PaX: unpatched PLT emulation step 1 */
8192 + unsigned int sethi, ba, nop;
8193 +
8194 + err = get_user(sethi, (unsigned int *)regs->tpc);
8195 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8196 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8197 +
8198 + if (err)
8199 + break;
8200 +
8201 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8202 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
8203 + nop == 0x01000000U)
8204 + {
8205 + unsigned long addr;
8206 + unsigned int save, call;
8207 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
8208 +
8209 + if ((ba & 0xFFC00000U) == 0x30800000U)
8210 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
8211 + else
8212 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8213 +
8214 + if (test_thread_flag(TIF_32BIT))
8215 + addr &= 0xFFFFFFFFUL;
8216 +
8217 + err = get_user(save, (unsigned int *)addr);
8218 + err |= get_user(call, (unsigned int *)(addr+4));
8219 + err |= get_user(nop, (unsigned int *)(addr+8));
8220 + if (err)
8221 + break;
8222 +
8223 +#ifdef CONFIG_PAX_DLRESOLVE
8224 + if (save == 0x9DE3BFA8U &&
8225 + (call & 0xC0000000U) == 0x40000000U &&
8226 + nop == 0x01000000U)
8227 + {
8228 + struct vm_area_struct *vma;
8229 + unsigned long call_dl_resolve;
8230 +
8231 + down_read(&current->mm->mmap_sem);
8232 + call_dl_resolve = current->mm->call_dl_resolve;
8233 + up_read(&current->mm->mmap_sem);
8234 + if (likely(call_dl_resolve))
8235 + goto emulate;
8236 +
8237 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
8238 +
8239 + down_write(&current->mm->mmap_sem);
8240 + if (current->mm->call_dl_resolve) {
8241 + call_dl_resolve = current->mm->call_dl_resolve;
8242 + up_write(&current->mm->mmap_sem);
8243 + if (vma)
8244 + kmem_cache_free(vm_area_cachep, vma);
8245 + goto emulate;
8246 + }
8247 +
8248 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
8249 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
8250 + up_write(&current->mm->mmap_sem);
8251 + if (vma)
8252 + kmem_cache_free(vm_area_cachep, vma);
8253 + return 1;
8254 + }
8255 +
8256 + if (pax_insert_vma(vma, call_dl_resolve)) {
8257 + up_write(&current->mm->mmap_sem);
8258 + kmem_cache_free(vm_area_cachep, vma);
8259 + return 1;
8260 + }
8261 +
8262 + current->mm->call_dl_resolve = call_dl_resolve;
8263 + up_write(&current->mm->mmap_sem);
8264 +
8265 +emulate:
8266 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8267 + regs->tpc = call_dl_resolve;
8268 + regs->tnpc = addr+4;
8269 + return 3;
8270 + }
8271 +#endif
8272 +
8273 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
8274 + if ((save & 0xFFC00000U) == 0x05000000U &&
8275 + (call & 0xFFFFE000U) == 0x85C0A000U &&
8276 + nop == 0x01000000U)
8277 + {
8278 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8279 + regs->u_regs[UREG_G2] = addr + 4;
8280 + addr = (save & 0x003FFFFFU) << 10;
8281 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8282 +
8283 + if (test_thread_flag(TIF_32BIT))
8284 + addr &= 0xFFFFFFFFUL;
8285 +
8286 + regs->tpc = addr;
8287 + regs->tnpc = addr+4;
8288 + return 3;
8289 + }
8290 +
8291 + /* PaX: 64-bit PLT stub */
8292 + err = get_user(sethi1, (unsigned int *)addr);
8293 + err |= get_user(sethi2, (unsigned int *)(addr+4));
8294 + err |= get_user(or1, (unsigned int *)(addr+8));
8295 + err |= get_user(or2, (unsigned int *)(addr+12));
8296 + err |= get_user(sllx, (unsigned int *)(addr+16));
8297 + err |= get_user(add, (unsigned int *)(addr+20));
8298 + err |= get_user(jmpl, (unsigned int *)(addr+24));
8299 + err |= get_user(nop, (unsigned int *)(addr+28));
8300 + if (err)
8301 + break;
8302 +
8303 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
8304 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8305 + (or1 & 0xFFFFE000U) == 0x88112000U &&
8306 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
8307 + sllx == 0x89293020U &&
8308 + add == 0x8A010005U &&
8309 + jmpl == 0x89C14000U &&
8310 + nop == 0x01000000U)
8311 + {
8312 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8313 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
8314 + regs->u_regs[UREG_G4] <<= 32;
8315 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
8316 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
8317 + regs->u_regs[UREG_G4] = addr + 24;
8318 + addr = regs->u_regs[UREG_G5];
8319 + regs->tpc = addr;
8320 + regs->tnpc = addr+4;
8321 + return 3;
8322 + }
8323 + }
8324 + } while (0);
8325 +
8326 +#ifdef CONFIG_PAX_DLRESOLVE
8327 + do { /* PaX: unpatched PLT emulation step 2 */
8328 + unsigned int save, call, nop;
8329 +
8330 + err = get_user(save, (unsigned int *)(regs->tpc-4));
8331 + err |= get_user(call, (unsigned int *)regs->tpc);
8332 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
8333 + if (err)
8334 + break;
8335 +
8336 + if (save == 0x9DE3BFA8U &&
8337 + (call & 0xC0000000U) == 0x40000000U &&
8338 + nop == 0x01000000U)
8339 + {
8340 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
8341 +
8342 + if (test_thread_flag(TIF_32BIT))
8343 + dl_resolve &= 0xFFFFFFFFUL;
8344 +
8345 + regs->u_regs[UREG_RETPC] = regs->tpc;
8346 + regs->tpc = dl_resolve;
8347 + regs->tnpc = dl_resolve+4;
8348 + return 3;
8349 + }
8350 + } while (0);
8351 +#endif
8352 +
8353 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
8354 + unsigned int sethi, ba, nop;
8355 +
8356 + err = get_user(sethi, (unsigned int *)regs->tpc);
8357 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8358 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8359 +
8360 + if (err)
8361 + break;
8362 +
8363 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8364 + (ba & 0xFFF00000U) == 0x30600000U &&
8365 + nop == 0x01000000U)
8366 + {
8367 + unsigned long addr;
8368 +
8369 + addr = (sethi & 0x003FFFFFU) << 10;
8370 + regs->u_regs[UREG_G1] = addr;
8371 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8372 +
8373 + if (test_thread_flag(TIF_32BIT))
8374 + addr &= 0xFFFFFFFFUL;
8375 +
8376 + regs->tpc = addr;
8377 + regs->tnpc = addr+4;
8378 + return 2;
8379 + }
8380 + } while (0);
8381 +
8382 +#endif
8383 +
8384 + return 1;
8385 +}
8386 +
8387 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8388 +{
8389 + unsigned long i;
8390 +
8391 + printk(KERN_ERR "PAX: bytes at PC: ");
8392 + for (i = 0; i < 8; i++) {
8393 + unsigned int c;
8394 + if (get_user(c, (unsigned int *)pc+i))
8395 + printk(KERN_CONT "???????? ");
8396 + else
8397 + printk(KERN_CONT "%08x ", c);
8398 + }
8399 + printk("\n");
8400 +}
8401 +#endif
8402 +
8403 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
8404 {
8405 struct mm_struct *mm = current->mm;
8406 @@ -341,6 +804,29 @@ retry:
8407 if (!vma)
8408 goto bad_area;
8409
8410 +#ifdef CONFIG_PAX_PAGEEXEC
8411 + /* PaX: detect ITLB misses on non-exec pages */
8412 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
8413 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
8414 + {
8415 + if (address != regs->tpc)
8416 + goto good_area;
8417 +
8418 + up_read(&mm->mmap_sem);
8419 + switch (pax_handle_fetch_fault(regs)) {
8420 +
8421 +#ifdef CONFIG_PAX_EMUPLT
8422 + case 2:
8423 + case 3:
8424 + return;
8425 +#endif
8426 +
8427 + }
8428 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
8429 + do_group_exit(SIGKILL);
8430 + }
8431 +#endif
8432 +
8433 /* Pure DTLB misses do not tell us whether the fault causing
8434 * load/store/atomic was a write or not, it only says that there
8435 * was no match. So in such a case we (carefully) read the
8436 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
8437 index f76f83d..ee0d859 100644
8438 --- a/arch/sparc/mm/hugetlbpage.c
8439 +++ b/arch/sparc/mm/hugetlbpage.c
8440 @@ -34,6 +34,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
8441 struct vm_area_struct * vma;
8442 unsigned long task_size = TASK_SIZE;
8443 unsigned long start_addr;
8444 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8445
8446 if (test_thread_flag(TIF_32BIT))
8447 task_size = STACK_TOP32;
8448 @@ -67,7 +68,7 @@ full_search:
8449 }
8450 return -ENOMEM;
8451 }
8452 - if (likely(!vma || addr + len <= vma->vm_start)) {
8453 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
8454 /*
8455 * Remember the place where we stopped the search:
8456 */
8457 @@ -90,6 +91,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8458 struct vm_area_struct *vma;
8459 struct mm_struct *mm = current->mm;
8460 unsigned long addr = addr0;
8461 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8462
8463 /* This should only ever run for 32-bit processes. */
8464 BUG_ON(!test_thread_flag(TIF_32BIT));
8465 @@ -106,7 +108,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8466 /* make sure it can fit in the remaining address space */
8467 if (likely(addr > len)) {
8468 vma = find_vma(mm, addr-len);
8469 - if (!vma || addr <= vma->vm_start) {
8470 + if (check_heap_stack_gap(vma, addr - len, len, offset)) {
8471 /* remember the address as a hint for next time */
8472 return (mm->free_area_cache = addr-len);
8473 }
8474 @@ -115,16 +117,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8475 if (unlikely(mm->mmap_base < len))
8476 goto bottomup;
8477
8478 - addr = (mm->mmap_base-len) & HPAGE_MASK;
8479 + addr = mm->mmap_base - len;
8480
8481 do {
8482 + addr &= HPAGE_MASK;
8483 /*
8484 * Lookup failure means no vma is above this address,
8485 * else if new region fits below vma->vm_start,
8486 * return with success:
8487 */
8488 vma = find_vma(mm, addr);
8489 - if (likely(!vma || addr+len <= vma->vm_start)) {
8490 + if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
8491 /* remember the address as a hint for next time */
8492 return (mm->free_area_cache = addr);
8493 }
8494 @@ -134,8 +137,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8495 mm->cached_hole_size = vma->vm_start - addr;
8496
8497 /* try just below the current vma->vm_start */
8498 - addr = (vma->vm_start-len) & HPAGE_MASK;
8499 - } while (likely(len < vma->vm_start));
8500 + addr = skip_heap_stack_gap(vma, len, offset);
8501 + } while (!IS_ERR_VALUE(addr));
8502
8503 bottomup:
8504 /*
8505 @@ -163,6 +166,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8506 struct mm_struct *mm = current->mm;
8507 struct vm_area_struct *vma;
8508 unsigned long task_size = TASK_SIZE;
8509 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8510
8511 if (test_thread_flag(TIF_32BIT))
8512 task_size = STACK_TOP32;
8513 @@ -181,8 +185,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8514 if (addr) {
8515 addr = ALIGN(addr, HPAGE_SIZE);
8516 vma = find_vma(mm, addr);
8517 - if (task_size - len >= addr &&
8518 - (!vma || addr + len <= vma->vm_start))
8519 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8520 return addr;
8521 }
8522 if (mm->get_unmapped_area == arch_get_unmapped_area)
8523 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
8524 index f4500c6..889656c 100644
8525 --- a/arch/tile/include/asm/atomic_64.h
8526 +++ b/arch/tile/include/asm/atomic_64.h
8527 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8528
8529 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8530
8531 +#define atomic64_read_unchecked(v) atomic64_read(v)
8532 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8533 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8534 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8535 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8536 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8537 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8538 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8539 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8540 +
8541 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
8542 #define smp_mb__before_atomic_dec() smp_mb()
8543 #define smp_mb__after_atomic_dec() smp_mb()
8544 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
8545 index a9a5299..0fce79e 100644
8546 --- a/arch/tile/include/asm/cache.h
8547 +++ b/arch/tile/include/asm/cache.h
8548 @@ -15,11 +15,12 @@
8549 #ifndef _ASM_TILE_CACHE_H
8550 #define _ASM_TILE_CACHE_H
8551
8552 +#include <linux/const.h>
8553 #include <arch/chip.h>
8554
8555 /* bytes per L1 data cache line */
8556 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
8557 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8558 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8559
8560 /* bytes per L2 cache line */
8561 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
8562 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
8563 index 9ab078a..d6635c2 100644
8564 --- a/arch/tile/include/asm/uaccess.h
8565 +++ b/arch/tile/include/asm/uaccess.h
8566 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
8567 const void __user *from,
8568 unsigned long n)
8569 {
8570 - int sz = __compiletime_object_size(to);
8571 + size_t sz = __compiletime_object_size(to);
8572
8573 - if (likely(sz == -1 || sz >= n))
8574 + if (likely(sz == (size_t)-1 || sz >= n))
8575 n = _copy_from_user(to, from, n);
8576 else
8577 copy_from_user_overflow();
8578 diff --git a/arch/um/Makefile b/arch/um/Makefile
8579 index 133f7de..1d6f2f1 100644
8580 --- a/arch/um/Makefile
8581 +++ b/arch/um/Makefile
8582 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
8583 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
8584 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
8585
8586 +ifdef CONSTIFY_PLUGIN
8587 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8588 +endif
8589 +
8590 #This will adjust *FLAGS accordingly to the platform.
8591 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
8592
8593 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
8594 index 19e1bdd..3665b77 100644
8595 --- a/arch/um/include/asm/cache.h
8596 +++ b/arch/um/include/asm/cache.h
8597 @@ -1,6 +1,7 @@
8598 #ifndef __UM_CACHE_H
8599 #define __UM_CACHE_H
8600
8601 +#include <linux/const.h>
8602
8603 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
8604 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
8605 @@ -12,6 +13,6 @@
8606 # define L1_CACHE_SHIFT 5
8607 #endif
8608
8609 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8610 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8611
8612 #endif
8613 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
8614 index 2e0a6b1..a64d0f5 100644
8615 --- a/arch/um/include/asm/kmap_types.h
8616 +++ b/arch/um/include/asm/kmap_types.h
8617 @@ -8,6 +8,6 @@
8618
8619 /* No more #include "asm/arch/kmap_types.h" ! */
8620
8621 -#define KM_TYPE_NR 14
8622 +#define KM_TYPE_NR 15
8623
8624 #endif
8625 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
8626 index 5ff53d9..5850cdf 100644
8627 --- a/arch/um/include/asm/page.h
8628 +++ b/arch/um/include/asm/page.h
8629 @@ -14,6 +14,9 @@
8630 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
8631 #define PAGE_MASK (~(PAGE_SIZE-1))
8632
8633 +#define ktla_ktva(addr) (addr)
8634 +#define ktva_ktla(addr) (addr)
8635 +
8636 #ifndef __ASSEMBLY__
8637
8638 struct page;
8639 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
8640 index 0032f92..cd151e0 100644
8641 --- a/arch/um/include/asm/pgtable-3level.h
8642 +++ b/arch/um/include/asm/pgtable-3level.h
8643 @@ -58,6 +58,7 @@
8644 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
8645 #define pud_populate(mm, pud, pmd) \
8646 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
8647 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8648
8649 #ifdef CONFIG_64BIT
8650 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
8651 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
8652 index b6d699c..df7ac1d 100644
8653 --- a/arch/um/kernel/process.c
8654 +++ b/arch/um/kernel/process.c
8655 @@ -387,22 +387,6 @@ int singlestepping(void * t)
8656 return 2;
8657 }
8658
8659 -/*
8660 - * Only x86 and x86_64 have an arch_align_stack().
8661 - * All other arches have "#define arch_align_stack(x) (x)"
8662 - * in their asm/system.h
8663 - * As this is included in UML from asm-um/system-generic.h,
8664 - * we can use it to behave as the subarch does.
8665 - */
8666 -#ifndef arch_align_stack
8667 -unsigned long arch_align_stack(unsigned long sp)
8668 -{
8669 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8670 - sp -= get_random_int() % 8192;
8671 - return sp & ~0xf;
8672 -}
8673 -#endif
8674 -
8675 unsigned long get_wchan(struct task_struct *p)
8676 {
8677 unsigned long stack_page, sp, ip;
8678 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
8679 index ad8f795..2c7eec6 100644
8680 --- a/arch/unicore32/include/asm/cache.h
8681 +++ b/arch/unicore32/include/asm/cache.h
8682 @@ -12,8 +12,10 @@
8683 #ifndef __UNICORE_CACHE_H__
8684 #define __UNICORE_CACHE_H__
8685
8686 -#define L1_CACHE_SHIFT (5)
8687 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8688 +#include <linux/const.h>
8689 +
8690 +#define L1_CACHE_SHIFT 5
8691 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8692
8693 /*
8694 * Memory returned by kmalloc() may be used for DMA, so we must make
8695 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
8696 index 46c3bff..b82f26b 100644
8697 --- a/arch/x86/Kconfig
8698 +++ b/arch/x86/Kconfig
8699 @@ -241,7 +241,7 @@ config X86_HT
8700
8701 config X86_32_LAZY_GS
8702 def_bool y
8703 - depends on X86_32 && !CC_STACKPROTECTOR
8704 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
8705
8706 config ARCH_HWEIGHT_CFLAGS
8707 string
8708 @@ -1033,6 +1033,7 @@ config MICROCODE_OLD_INTERFACE
8709
8710 config X86_MSR
8711 tristate "/dev/cpu/*/msr - Model-specific register support"
8712 + depends on !GRKERNSEC_KMEM
8713 ---help---
8714 This device gives privileged processes access to the x86
8715 Model-Specific Registers (MSRs). It is a character device with
8716 @@ -1056,7 +1057,7 @@ choice
8717
8718 config NOHIGHMEM
8719 bool "off"
8720 - depends on !X86_NUMAQ
8721 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8722 ---help---
8723 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
8724 However, the address space of 32-bit x86 processors is only 4
8725 @@ -1093,7 +1094,7 @@ config NOHIGHMEM
8726
8727 config HIGHMEM4G
8728 bool "4GB"
8729 - depends on !X86_NUMAQ
8730 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8731 ---help---
8732 Select this if you have a 32-bit processor and between 1 and 4
8733 gigabytes of physical RAM.
8734 @@ -1147,7 +1148,7 @@ config PAGE_OFFSET
8735 hex
8736 default 0xB0000000 if VMSPLIT_3G_OPT
8737 default 0x80000000 if VMSPLIT_2G
8738 - default 0x78000000 if VMSPLIT_2G_OPT
8739 + default 0x70000000 if VMSPLIT_2G_OPT
8740 default 0x40000000 if VMSPLIT_1G
8741 default 0xC0000000
8742 depends on X86_32
8743 @@ -1548,6 +1549,7 @@ config SECCOMP
8744
8745 config CC_STACKPROTECTOR
8746 bool "Enable -fstack-protector buffer overflow detection"
8747 + depends on X86_64 || !PAX_MEMORY_UDEREF
8748 ---help---
8749 This option turns on the -fstack-protector GCC feature. This
8750 feature puts, at the beginning of functions, a canary value on
8751 @@ -1605,6 +1607,7 @@ config KEXEC_JUMP
8752 config PHYSICAL_START
8753 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
8754 default "0x1000000"
8755 + range 0x400000 0x40000000
8756 ---help---
8757 This gives the physical address where the kernel is loaded.
8758
8759 @@ -1668,6 +1671,7 @@ config X86_NEED_RELOCS
8760 config PHYSICAL_ALIGN
8761 hex "Alignment value to which kernel should be aligned" if X86_32
8762 default "0x1000000"
8763 + range 0x400000 0x1000000 if PAX_KERNEXEC
8764 range 0x2000 0x1000000
8765 ---help---
8766 This value puts the alignment restrictions on physical address
8767 @@ -1699,9 +1703,10 @@ config HOTPLUG_CPU
8768 Say N if you want to disable CPU hotplug.
8769
8770 config COMPAT_VDSO
8771 - def_bool y
8772 + def_bool n
8773 prompt "Compat VDSO support"
8774 depends on X86_32 || IA32_EMULATION
8775 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
8776 ---help---
8777 Map the 32-bit VDSO to the predictable old-style address too.
8778
8779 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
8780 index f3b86d0..17fd30f 100644
8781 --- a/arch/x86/Kconfig.cpu
8782 +++ b/arch/x86/Kconfig.cpu
8783 @@ -335,7 +335,7 @@ config X86_PPRO_FENCE
8784
8785 config X86_F00F_BUG
8786 def_bool y
8787 - depends on M586MMX || M586TSC || M586 || M486 || M386
8788 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
8789
8790 config X86_INVD_BUG
8791 def_bool y
8792 @@ -359,7 +359,7 @@ config X86_POPAD_OK
8793
8794 config X86_ALIGNMENT_16
8795 def_bool y
8796 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8797 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8798
8799 config X86_INTEL_USERCOPY
8800 def_bool y
8801 @@ -405,7 +405,7 @@ config X86_CMPXCHG64
8802 # generates cmov.
8803 config X86_CMOV
8804 def_bool y
8805 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8806 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8807
8808 config X86_MINIMUM_CPU_FAMILY
8809 int
8810 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
8811 index b322f12..652d0d9 100644
8812 --- a/arch/x86/Kconfig.debug
8813 +++ b/arch/x86/Kconfig.debug
8814 @@ -84,7 +84,7 @@ config X86_PTDUMP
8815 config DEBUG_RODATA
8816 bool "Write protect kernel read-only data structures"
8817 default y
8818 - depends on DEBUG_KERNEL
8819 + depends on DEBUG_KERNEL && BROKEN
8820 ---help---
8821 Mark the kernel read-only data as write-protected in the pagetables,
8822 in order to catch accidental (and incorrect) writes to such const
8823 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
8824
8825 config DEBUG_SET_MODULE_RONX
8826 bool "Set loadable kernel module data as NX and text as RO"
8827 - depends on MODULES
8828 + depends on MODULES && BROKEN
8829 ---help---
8830 This option helps catch unintended modifications to loadable
8831 kernel module's text and read-only data. It also prevents execution
8832 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
8833
8834 config DEBUG_STRICT_USER_COPY_CHECKS
8835 bool "Strict copy size checks"
8836 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
8837 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
8838 ---help---
8839 Enabling this option turns a certain set of sanity checks for user
8840 copy operations into compile time failures.
8841 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
8842 index 05afcca..b6ecb51 100644
8843 --- a/arch/x86/Makefile
8844 +++ b/arch/x86/Makefile
8845 @@ -50,6 +50,7 @@ else
8846 UTS_MACHINE := x86_64
8847 CHECKFLAGS += -D__x86_64__ -m64
8848
8849 + biarch := $(call cc-option,-m64)
8850 KBUILD_AFLAGS += -m64
8851 KBUILD_CFLAGS += -m64
8852
8853 @@ -229,3 +230,12 @@ define archhelp
8854 echo ' FDARGS="..." arguments for the booted kernel'
8855 echo ' FDINITRD=file initrd for the booted kernel'
8856 endef
8857 +
8858 +define OLD_LD
8859 +
8860 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
8861 +*** Please upgrade your binutils to 2.18 or newer
8862 +endef
8863 +
8864 +archprepare:
8865 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
8866 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
8867 index ccce0ed..fd9da25 100644
8868 --- a/arch/x86/boot/Makefile
8869 +++ b/arch/x86/boot/Makefile
8870 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
8871 $(call cc-option, -fno-stack-protector) \
8872 $(call cc-option, -mpreferred-stack-boundary=2)
8873 KBUILD_CFLAGS += $(call cc-option, -m32)
8874 +ifdef CONSTIFY_PLUGIN
8875 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8876 +endif
8877 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8878 GCOV_PROFILE := n
8879
8880 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
8881 index 878e4b9..20537ab 100644
8882 --- a/arch/x86/boot/bitops.h
8883 +++ b/arch/x86/boot/bitops.h
8884 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8885 u8 v;
8886 const u32 *p = (const u32 *)addr;
8887
8888 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8889 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8890 return v;
8891 }
8892
8893 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8894
8895 static inline void set_bit(int nr, void *addr)
8896 {
8897 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8898 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8899 }
8900
8901 #endif /* BOOT_BITOPS_H */
8902 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
8903 index 18997e5..83d9c67 100644
8904 --- a/arch/x86/boot/boot.h
8905 +++ b/arch/x86/boot/boot.h
8906 @@ -85,7 +85,7 @@ static inline void io_delay(void)
8907 static inline u16 ds(void)
8908 {
8909 u16 seg;
8910 - asm("movw %%ds,%0" : "=rm" (seg));
8911 + asm volatile("movw %%ds,%0" : "=rm" (seg));
8912 return seg;
8913 }
8914
8915 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
8916 static inline int memcmp(const void *s1, const void *s2, size_t len)
8917 {
8918 u8 diff;
8919 - asm("repe; cmpsb; setnz %0"
8920 + asm volatile("repe; cmpsb; setnz %0"
8921 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
8922 return diff;
8923 }
8924 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
8925 index 8a84501..b2d165f 100644
8926 --- a/arch/x86/boot/compressed/Makefile
8927 +++ b/arch/x86/boot/compressed/Makefile
8928 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
8929 KBUILD_CFLAGS += $(cflags-y)
8930 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
8931 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
8932 +ifdef CONSTIFY_PLUGIN
8933 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8934 +endif
8935
8936 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8937 GCOV_PROFILE := n
8938 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
8939 index ccae7e2..8ac70be 100644
8940 --- a/arch/x86/boot/compressed/eboot.c
8941 +++ b/arch/x86/boot/compressed/eboot.c
8942 @@ -144,7 +144,6 @@ again:
8943 *addr = max_addr;
8944 }
8945
8946 -free_pool:
8947 efi_call_phys1(sys_table->boottime->free_pool, map);
8948
8949 fail:
8950 @@ -208,7 +207,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
8951 if (i == map_size / desc_size)
8952 status = EFI_NOT_FOUND;
8953
8954 -free_pool:
8955 efi_call_phys1(sys_table->boottime->free_pool, map);
8956 fail:
8957 return status;
8958 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
8959 index ccb2f4a..e49b20e 100644
8960 --- a/arch/x86/boot/compressed/head_32.S
8961 +++ b/arch/x86/boot/compressed/head_32.S
8962 @@ -118,7 +118,7 @@ preferred_addr:
8963 notl %eax
8964 andl %eax, %ebx
8965 #else
8966 - movl $LOAD_PHYSICAL_ADDR, %ebx
8967 + movl $____LOAD_PHYSICAL_ADDR, %ebx
8968 #endif
8969
8970 /* Target address to relocate to for decompression */
8971 @@ -204,7 +204,7 @@ relocated:
8972 * and where it was actually loaded.
8973 */
8974 movl %ebp, %ebx
8975 - subl $LOAD_PHYSICAL_ADDR, %ebx
8976 + subl $____LOAD_PHYSICAL_ADDR, %ebx
8977 jz 2f /* Nothing to be done if loaded at compiled addr. */
8978 /*
8979 * Process relocations.
8980 @@ -212,8 +212,7 @@ relocated:
8981
8982 1: subl $4, %edi
8983 movl (%edi), %ecx
8984 - testl %ecx, %ecx
8985 - jz 2f
8986 + jecxz 2f
8987 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
8988 jmp 1b
8989 2:
8990 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
8991 index 2c4b171..e1fa5b1 100644
8992 --- a/arch/x86/boot/compressed/head_64.S
8993 +++ b/arch/x86/boot/compressed/head_64.S
8994 @@ -91,7 +91,7 @@ ENTRY(startup_32)
8995 notl %eax
8996 andl %eax, %ebx
8997 #else
8998 - movl $LOAD_PHYSICAL_ADDR, %ebx
8999 + movl $____LOAD_PHYSICAL_ADDR, %ebx
9000 #endif
9001
9002 /* Target address to relocate to for decompression */
9003 @@ -273,7 +273,7 @@ preferred_addr:
9004 notq %rax
9005 andq %rax, %rbp
9006 #else
9007 - movq $LOAD_PHYSICAL_ADDR, %rbp
9008 + movq $____LOAD_PHYSICAL_ADDR, %rbp
9009 #endif
9010
9011 /* Target address to relocate to for decompression */
9012 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
9013 index 88f7ff6..ed695dd 100644
9014 --- a/arch/x86/boot/compressed/misc.c
9015 +++ b/arch/x86/boot/compressed/misc.c
9016 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
9017 case PT_LOAD:
9018 #ifdef CONFIG_RELOCATABLE
9019 dest = output;
9020 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
9021 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
9022 #else
9023 dest = (void *)(phdr->p_paddr);
9024 #endif
9025 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
9026 error("Destination address too large");
9027 #endif
9028 #ifndef CONFIG_RELOCATABLE
9029 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
9030 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
9031 error("Wrong destination address");
9032 #endif
9033
9034 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
9035 index 4d3ff03..e4972ff 100644
9036 --- a/arch/x86/boot/cpucheck.c
9037 +++ b/arch/x86/boot/cpucheck.c
9038 @@ -74,7 +74,7 @@ static int has_fpu(void)
9039 u16 fcw = -1, fsw = -1;
9040 u32 cr0;
9041
9042 - asm("movl %%cr0,%0" : "=r" (cr0));
9043 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
9044 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
9045 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
9046 asm volatile("movl %0,%%cr0" : : "r" (cr0));
9047 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
9048 {
9049 u32 f0, f1;
9050
9051 - asm("pushfl ; "
9052 + asm volatile("pushfl ; "
9053 "pushfl ; "
9054 "popl %0 ; "
9055 "movl %0,%1 ; "
9056 @@ -115,7 +115,7 @@ static void get_flags(void)
9057 set_bit(X86_FEATURE_FPU, cpu.flags);
9058
9059 if (has_eflag(X86_EFLAGS_ID)) {
9060 - asm("cpuid"
9061 + asm volatile("cpuid"
9062 : "=a" (max_intel_level),
9063 "=b" (cpu_vendor[0]),
9064 "=d" (cpu_vendor[1]),
9065 @@ -124,7 +124,7 @@ static void get_flags(void)
9066
9067 if (max_intel_level >= 0x00000001 &&
9068 max_intel_level <= 0x0000ffff) {
9069 - asm("cpuid"
9070 + asm volatile("cpuid"
9071 : "=a" (tfms),
9072 "=c" (cpu.flags[4]),
9073 "=d" (cpu.flags[0])
9074 @@ -136,7 +136,7 @@ static void get_flags(void)
9075 cpu.model += ((tfms >> 16) & 0xf) << 4;
9076 }
9077
9078 - asm("cpuid"
9079 + asm volatile("cpuid"
9080 : "=a" (max_amd_level)
9081 : "a" (0x80000000)
9082 : "ebx", "ecx", "edx");
9083 @@ -144,7 +144,7 @@ static void get_flags(void)
9084 if (max_amd_level >= 0x80000001 &&
9085 max_amd_level <= 0x8000ffff) {
9086 u32 eax = 0x80000001;
9087 - asm("cpuid"
9088 + asm volatile("cpuid"
9089 : "+a" (eax),
9090 "=c" (cpu.flags[6]),
9091 "=d" (cpu.flags[1])
9092 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9093 u32 ecx = MSR_K7_HWCR;
9094 u32 eax, edx;
9095
9096 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9097 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9098 eax &= ~(1 << 15);
9099 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9100 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9101
9102 get_flags(); /* Make sure it really did something */
9103 err = check_flags();
9104 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9105 u32 ecx = MSR_VIA_FCR;
9106 u32 eax, edx;
9107
9108 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9109 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9110 eax |= (1<<1)|(1<<7);
9111 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9112 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9113
9114 set_bit(X86_FEATURE_CX8, cpu.flags);
9115 err = check_flags();
9116 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9117 u32 eax, edx;
9118 u32 level = 1;
9119
9120 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9121 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
9122 - asm("cpuid"
9123 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9124 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
9125 + asm volatile("cpuid"
9126 : "+a" (level), "=d" (cpu.flags[0])
9127 : : "ecx", "ebx");
9128 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9129 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9130
9131 err = check_flags();
9132 }
9133 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
9134 index 8c132a6..13e5c96 100644
9135 --- a/arch/x86/boot/header.S
9136 +++ b/arch/x86/boot/header.S
9137 @@ -387,10 +387,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
9138 # single linked list of
9139 # struct setup_data
9140
9141 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
9142 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
9143
9144 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
9145 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
9146 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
9147 +#else
9148 #define VO_INIT_SIZE (VO__end - VO__text)
9149 +#endif
9150 #if ZO_INIT_SIZE > VO_INIT_SIZE
9151 #define INIT_SIZE ZO_INIT_SIZE
9152 #else
9153 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
9154 index db75d07..8e6d0af 100644
9155 --- a/arch/x86/boot/memory.c
9156 +++ b/arch/x86/boot/memory.c
9157 @@ -19,7 +19,7 @@
9158
9159 static int detect_memory_e820(void)
9160 {
9161 - int count = 0;
9162 + unsigned int count = 0;
9163 struct biosregs ireg, oreg;
9164 struct e820entry *desc = boot_params.e820_map;
9165 static struct e820entry buf; /* static so it is zeroed */
9166 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
9167 index 11e8c6e..fdbb1ed 100644
9168 --- a/arch/x86/boot/video-vesa.c
9169 +++ b/arch/x86/boot/video-vesa.c
9170 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
9171
9172 boot_params.screen_info.vesapm_seg = oreg.es;
9173 boot_params.screen_info.vesapm_off = oreg.di;
9174 + boot_params.screen_info.vesapm_size = oreg.cx;
9175 }
9176
9177 /*
9178 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
9179 index 43eda28..5ab5fdb 100644
9180 --- a/arch/x86/boot/video.c
9181 +++ b/arch/x86/boot/video.c
9182 @@ -96,7 +96,7 @@ static void store_mode_params(void)
9183 static unsigned int get_entry(void)
9184 {
9185 char entry_buf[4];
9186 - int i, len = 0;
9187 + unsigned int i, len = 0;
9188 int key;
9189 unsigned int v;
9190
9191 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
9192 index 5b577d5..3c1fed4 100644
9193 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
9194 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
9195 @@ -8,6 +8,8 @@
9196 * including this sentence is retained in full.
9197 */
9198
9199 +#include <asm/alternative-asm.h>
9200 +
9201 .extern crypto_ft_tab
9202 .extern crypto_it_tab
9203 .extern crypto_fl_tab
9204 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
9205 je B192; \
9206 leaq 32(r9),r9;
9207
9208 +#define ret pax_force_retaddr 0, 1; ret
9209 +
9210 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
9211 movq r1,r2; \
9212 movq r3,r4; \
9213 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
9214 index 3470624..201259d 100644
9215 --- a/arch/x86/crypto/aesni-intel_asm.S
9216 +++ b/arch/x86/crypto/aesni-intel_asm.S
9217 @@ -31,6 +31,7 @@
9218
9219 #include <linux/linkage.h>
9220 #include <asm/inst.h>
9221 +#include <asm/alternative-asm.h>
9222
9223 #ifdef __x86_64__
9224 .data
9225 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
9226 pop %r14
9227 pop %r13
9228 pop %r12
9229 + pax_force_retaddr 0, 1
9230 ret
9231 +ENDPROC(aesni_gcm_dec)
9232
9233
9234 /*****************************************************************************
9235 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
9236 pop %r14
9237 pop %r13
9238 pop %r12
9239 + pax_force_retaddr 0, 1
9240 ret
9241 +ENDPROC(aesni_gcm_enc)
9242
9243 #endif
9244
9245 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
9246 pxor %xmm1, %xmm0
9247 movaps %xmm0, (TKEYP)
9248 add $0x10, TKEYP
9249 + pax_force_retaddr_bts
9250 ret
9251
9252 .align 4
9253 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
9254 shufps $0b01001110, %xmm2, %xmm1
9255 movaps %xmm1, 0x10(TKEYP)
9256 add $0x20, TKEYP
9257 + pax_force_retaddr_bts
9258 ret
9259
9260 .align 4
9261 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
9262
9263 movaps %xmm0, (TKEYP)
9264 add $0x10, TKEYP
9265 + pax_force_retaddr_bts
9266 ret
9267
9268 .align 4
9269 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
9270 pxor %xmm1, %xmm2
9271 movaps %xmm2, (TKEYP)
9272 add $0x10, TKEYP
9273 + pax_force_retaddr_bts
9274 ret
9275
9276 /*
9277 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
9278 #ifndef __x86_64__
9279 popl KEYP
9280 #endif
9281 + pax_force_retaddr 0, 1
9282 ret
9283 +ENDPROC(aesni_set_key)
9284
9285 /*
9286 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
9287 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
9288 popl KLEN
9289 popl KEYP
9290 #endif
9291 + pax_force_retaddr 0, 1
9292 ret
9293 +ENDPROC(aesni_enc)
9294
9295 /*
9296 * _aesni_enc1: internal ABI
9297 @@ -1959,6 +1972,7 @@ _aesni_enc1:
9298 AESENC KEY STATE
9299 movaps 0x70(TKEYP), KEY
9300 AESENCLAST KEY STATE
9301 + pax_force_retaddr_bts
9302 ret
9303
9304 /*
9305 @@ -2067,6 +2081,7 @@ _aesni_enc4:
9306 AESENCLAST KEY STATE2
9307 AESENCLAST KEY STATE3
9308 AESENCLAST KEY STATE4
9309 + pax_force_retaddr_bts
9310 ret
9311
9312 /*
9313 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
9314 popl KLEN
9315 popl KEYP
9316 #endif
9317 + pax_force_retaddr 0, 1
9318 ret
9319 +ENDPROC(aesni_dec)
9320
9321 /*
9322 * _aesni_dec1: internal ABI
9323 @@ -2146,6 +2163,7 @@ _aesni_dec1:
9324 AESDEC KEY STATE
9325 movaps 0x70(TKEYP), KEY
9326 AESDECLAST KEY STATE
9327 + pax_force_retaddr_bts
9328 ret
9329
9330 /*
9331 @@ -2254,6 +2272,7 @@ _aesni_dec4:
9332 AESDECLAST KEY STATE2
9333 AESDECLAST KEY STATE3
9334 AESDECLAST KEY STATE4
9335 + pax_force_retaddr_bts
9336 ret
9337
9338 /*
9339 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
9340 popl KEYP
9341 popl LEN
9342 #endif
9343 + pax_force_retaddr 0, 1
9344 ret
9345 +ENDPROC(aesni_ecb_enc)
9346
9347 /*
9348 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9349 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
9350 popl KEYP
9351 popl LEN
9352 #endif
9353 + pax_force_retaddr 0, 1
9354 ret
9355 +ENDPROC(aesni_ecb_dec)
9356
9357 /*
9358 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9359 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
9360 popl LEN
9361 popl IVP
9362 #endif
9363 + pax_force_retaddr 0, 1
9364 ret
9365 +ENDPROC(aesni_cbc_enc)
9366
9367 /*
9368 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9369 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
9370 popl LEN
9371 popl IVP
9372 #endif
9373 + pax_force_retaddr 0, 1
9374 ret
9375 +ENDPROC(aesni_cbc_dec)
9376
9377 #ifdef __x86_64__
9378 .align 16
9379 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
9380 mov $1, TCTR_LOW
9381 MOVQ_R64_XMM TCTR_LOW INC
9382 MOVQ_R64_XMM CTR TCTR_LOW
9383 + pax_force_retaddr_bts
9384 ret
9385
9386 /*
9387 @@ -2554,6 +2582,7 @@ _aesni_inc:
9388 .Linc_low:
9389 movaps CTR, IV
9390 PSHUFB_XMM BSWAP_MASK IV
9391 + pax_force_retaddr_bts
9392 ret
9393
9394 /*
9395 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
9396 .Lctr_enc_ret:
9397 movups IV, (IVP)
9398 .Lctr_enc_just_ret:
9399 + pax_force_retaddr 0, 1
9400 ret
9401 +ENDPROC(aesni_ctr_enc)
9402 #endif
9403 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9404 index 391d245..67f35c2 100644
9405 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
9406 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9407 @@ -20,6 +20,8 @@
9408 *
9409 */
9410
9411 +#include <asm/alternative-asm.h>
9412 +
9413 .file "blowfish-x86_64-asm.S"
9414 .text
9415
9416 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
9417 jnz __enc_xor;
9418
9419 write_block();
9420 + pax_force_retaddr 0, 1
9421 ret;
9422 __enc_xor:
9423 xor_block();
9424 + pax_force_retaddr 0, 1
9425 ret;
9426
9427 .align 8
9428 @@ -188,6 +192,7 @@ blowfish_dec_blk:
9429
9430 movq %r11, %rbp;
9431
9432 + pax_force_retaddr 0, 1
9433 ret;
9434
9435 /**********************************************************************
9436 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
9437
9438 popq %rbx;
9439 popq %rbp;
9440 + pax_force_retaddr 0, 1
9441 ret;
9442
9443 __enc_xor4:
9444 @@ -349,6 +355,7 @@ __enc_xor4:
9445
9446 popq %rbx;
9447 popq %rbp;
9448 + pax_force_retaddr 0, 1
9449 ret;
9450
9451 .align 8
9452 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
9453 popq %rbx;
9454 popq %rbp;
9455
9456 + pax_force_retaddr 0, 1
9457 ret;
9458
9459 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
9460 index 0b33743..7a56206 100644
9461 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
9462 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
9463 @@ -20,6 +20,8 @@
9464 *
9465 */
9466
9467 +#include <asm/alternative-asm.h>
9468 +
9469 .file "camellia-x86_64-asm_64.S"
9470 .text
9471
9472 @@ -229,12 +231,14 @@ __enc_done:
9473 enc_outunpack(mov, RT1);
9474
9475 movq RRBP, %rbp;
9476 + pax_force_retaddr 0, 1
9477 ret;
9478
9479 __enc_xor:
9480 enc_outunpack(xor, RT1);
9481
9482 movq RRBP, %rbp;
9483 + pax_force_retaddr 0, 1
9484 ret;
9485
9486 .global camellia_dec_blk;
9487 @@ -275,6 +279,7 @@ __dec_rounds16:
9488 dec_outunpack();
9489
9490 movq RRBP, %rbp;
9491 + pax_force_retaddr 0, 1
9492 ret;
9493
9494 /**********************************************************************
9495 @@ -468,6 +473,7 @@ __enc2_done:
9496
9497 movq RRBP, %rbp;
9498 popq %rbx;
9499 + pax_force_retaddr 0, 1
9500 ret;
9501
9502 __enc2_xor:
9503 @@ -475,6 +481,7 @@ __enc2_xor:
9504
9505 movq RRBP, %rbp;
9506 popq %rbx;
9507 + pax_force_retaddr 0, 1
9508 ret;
9509
9510 .global camellia_dec_blk_2way;
9511 @@ -517,4 +524,5 @@ __dec2_rounds16:
9512
9513 movq RRBP, %rbp;
9514 movq RXOR, %rbx;
9515 + pax_force_retaddr 0, 1
9516 ret;
9517 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9518 index a41a3aa..bdf5753 100644
9519 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9520 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9521 @@ -23,6 +23,8 @@
9522 *
9523 */
9524
9525 +#include <asm/alternative-asm.h>
9526 +
9527 .file "cast5-avx-x86_64-asm_64.S"
9528
9529 .extern cast5_s1
9530 @@ -293,6 +295,7 @@ __skip_enc:
9531 leaq 3*(2*4*4)(%r11), %rax;
9532 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9533
9534 + pax_force_retaddr 0, 1
9535 ret;
9536
9537 __enc_xor16:
9538 @@ -303,6 +306,7 @@ __enc_xor16:
9539 leaq 3*(2*4*4)(%r11), %rax;
9540 outunpack_xor_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9541
9542 + pax_force_retaddr 0, 1
9543 ret;
9544
9545 .align 16
9546 @@ -369,6 +373,7 @@ __dec_tail:
9547 leaq 3*(2*4*4)(%r11), %rax;
9548 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9549
9550 + pax_force_retaddr 0, 1
9551 ret;
9552
9553 __skip_dec:
9554 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9555 index 218d283..819e6da 100644
9556 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9557 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9558 @@ -23,6 +23,8 @@
9559 *
9560 */
9561
9562 +#include <asm/alternative-asm.h>
9563 +
9564 .file "cast6-avx-x86_64-asm_64.S"
9565
9566 .extern cast6_s1
9567 @@ -324,12 +326,14 @@ __cast6_enc_blk_8way:
9568 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9569 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9570
9571 + pax_force_retaddr 0, 1
9572 ret;
9573
9574 __enc_xor8:
9575 outunpack_xor_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9576 outunpack_xor_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9577
9578 + pax_force_retaddr 0, 1
9579 ret;
9580
9581 .align 16
9582 @@ -380,4 +384,5 @@ cast6_dec_blk_8way:
9583 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9584 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9585
9586 + pax_force_retaddr 0, 1
9587 ret;
9588 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9589 index 6214a9b..1f4fc9a 100644
9590 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
9591 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9592 @@ -1,3 +1,5 @@
9593 +#include <asm/alternative-asm.h>
9594 +
9595 # enter ECRYPT_encrypt_bytes
9596 .text
9597 .p2align 5
9598 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
9599 add %r11,%rsp
9600 mov %rdi,%rax
9601 mov %rsi,%rdx
9602 + pax_force_retaddr 0, 1
9603 ret
9604 # bytesatleast65:
9605 ._bytesatleast65:
9606 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
9607 add %r11,%rsp
9608 mov %rdi,%rax
9609 mov %rsi,%rdx
9610 + pax_force_retaddr
9611 ret
9612 # enter ECRYPT_ivsetup
9613 .text
9614 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
9615 add %r11,%rsp
9616 mov %rdi,%rax
9617 mov %rsi,%rdx
9618 + pax_force_retaddr
9619 ret
9620 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9621 index 504106b..4e50951 100644
9622 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9623 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9624 @@ -24,6 +24,8 @@
9625 *
9626 */
9627
9628 +#include <asm/alternative-asm.h>
9629 +
9630 .file "serpent-avx-x86_64-asm_64.S"
9631 .text
9632
9633 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
9634 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9635 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9636
9637 + pax_force_retaddr
9638 ret;
9639
9640 __enc_xor8:
9641 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9642 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9643
9644 + pax_force_retaddr
9645 ret;
9646
9647 .align 8
9648 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
9649 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9650 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9651
9652 + pax_force_retaddr
9653 ret;
9654 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9655 index 3ee1ff0..cbc568b 100644
9656 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9657 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9658 @@ -24,6 +24,8 @@
9659 *
9660 */
9661
9662 +#include <asm/alternative-asm.h>
9663 +
9664 .file "serpent-sse2-x86_64-asm_64.S"
9665 .text
9666
9667 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
9668 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9669 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9670
9671 + pax_force_retaddr
9672 ret;
9673
9674 __enc_xor8:
9675 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9676 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9677
9678 + pax_force_retaddr
9679 ret;
9680
9681 .align 8
9682 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
9683 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9684 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9685
9686 + pax_force_retaddr
9687 ret;
9688 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
9689 index 49d6987..df66bd4 100644
9690 --- a/arch/x86/crypto/sha1_ssse3_asm.S
9691 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
9692 @@ -28,6 +28,8 @@
9693 * (at your option) any later version.
9694 */
9695
9696 +#include <asm/alternative-asm.h>
9697 +
9698 #define CTX %rdi // arg1
9699 #define BUF %rsi // arg2
9700 #define CNT %rdx // arg3
9701 @@ -104,6 +106,7 @@
9702 pop %r12
9703 pop %rbp
9704 pop %rbx
9705 + pax_force_retaddr 0, 1
9706 ret
9707
9708 .size \name, .-\name
9709 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9710 index 1585abb..1ff9d9b 100644
9711 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9712 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9713 @@ -23,6 +23,8 @@
9714 *
9715 */
9716
9717 +#include <asm/alternative-asm.h>
9718 +
9719 .file "twofish-avx-x86_64-asm_64.S"
9720 .text
9721
9722 @@ -303,12 +305,14 @@ __twofish_enc_blk_8way:
9723 outunpack_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9724 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9725
9726 + pax_force_retaddr 0, 1
9727 ret;
9728
9729 __enc_xor8:
9730 outunpack_xor_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9731 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9732
9733 + pax_force_retaddr 0, 1
9734 ret;
9735
9736 .align 8
9737 @@ -354,4 +358,5 @@ twofish_dec_blk_8way:
9738 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
9739 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
9740
9741 + pax_force_retaddr 0, 1
9742 ret;
9743 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9744 index 5b012a2..36d5364 100644
9745 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9746 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9747 @@ -20,6 +20,8 @@
9748 *
9749 */
9750
9751 +#include <asm/alternative-asm.h>
9752 +
9753 .file "twofish-x86_64-asm-3way.S"
9754 .text
9755
9756 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
9757 popq %r13;
9758 popq %r14;
9759 popq %r15;
9760 + pax_force_retaddr 0, 1
9761 ret;
9762
9763 __enc_xor3:
9764 @@ -271,6 +274,7 @@ __enc_xor3:
9765 popq %r13;
9766 popq %r14;
9767 popq %r15;
9768 + pax_force_retaddr 0, 1
9769 ret;
9770
9771 .global twofish_dec_blk_3way
9772 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
9773 popq %r13;
9774 popq %r14;
9775 popq %r15;
9776 + pax_force_retaddr 0, 1
9777 ret;
9778
9779 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
9780 index 7bcf3fc..f53832f 100644
9781 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
9782 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
9783 @@ -21,6 +21,7 @@
9784 .text
9785
9786 #include <asm/asm-offsets.h>
9787 +#include <asm/alternative-asm.h>
9788
9789 #define a_offset 0
9790 #define b_offset 4
9791 @@ -268,6 +269,7 @@ twofish_enc_blk:
9792
9793 popq R1
9794 movq $1,%rax
9795 + pax_force_retaddr 0, 1
9796 ret
9797
9798 twofish_dec_blk:
9799 @@ -319,4 +321,5 @@ twofish_dec_blk:
9800
9801 popq R1
9802 movq $1,%rax
9803 + pax_force_retaddr 0, 1
9804 ret
9805 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
9806 index 07b3a68..bd2a388 100644
9807 --- a/arch/x86/ia32/ia32_aout.c
9808 +++ b/arch/x86/ia32/ia32_aout.c
9809 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
9810 unsigned long dump_start, dump_size;
9811 struct user32 dump;
9812
9813 + memset(&dump, 0, sizeof(dump));
9814 +
9815 fs = get_fs();
9816 set_fs(KERNEL_DS);
9817 has_dumped = 1;
9818 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
9819 index efc6a95..95abfe2 100644
9820 --- a/arch/x86/ia32/ia32_signal.c
9821 +++ b/arch/x86/ia32/ia32_signal.c
9822 @@ -163,8 +163,8 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
9823 }
9824 seg = get_fs();
9825 set_fs(KERNEL_DS);
9826 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
9827 - (stack_t __force __user *) &uoss, regs->sp);
9828 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
9829 + (stack_t __force_user *) &uoss, regs->sp);
9830 set_fs(seg);
9831 if (ret >= 0 && uoss_ptr) {
9832 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
9833 @@ -396,7 +396,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
9834 sp -= frame_size;
9835 /* Align the stack pointer according to the i386 ABI,
9836 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
9837 - sp = ((sp + 4) & -16ul) - 4;
9838 + sp = ((sp - 12) & -16ul) - 4;
9839 return (void __user *) sp;
9840 }
9841
9842 @@ -454,7 +454,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
9843 * These are actually not used anymore, but left because some
9844 * gdb versions depend on them as a marker.
9845 */
9846 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9847 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9848 } put_user_catch(err);
9849
9850 if (err)
9851 @@ -496,7 +496,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9852 0xb8,
9853 __NR_ia32_rt_sigreturn,
9854 0x80cd,
9855 - 0,
9856 + 0
9857 };
9858
9859 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
9860 @@ -522,16 +522,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9861
9862 if (ka->sa.sa_flags & SA_RESTORER)
9863 restorer = ka->sa.sa_restorer;
9864 + else if (current->mm->context.vdso)
9865 + /* Return stub is in 32bit vsyscall page */
9866 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
9867 else
9868 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
9869 - rt_sigreturn);
9870 + restorer = &frame->retcode;
9871 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
9872
9873 /*
9874 * Not actually used anymore, but left because some gdb
9875 * versions need it.
9876 */
9877 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9878 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9879 } put_user_catch(err);
9880
9881 err |= copy_siginfo_to_user32(&frame->info, info);
9882 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
9883 index e7fa545..9e6fe1a 100644
9884 --- a/arch/x86/ia32/ia32entry.S
9885 +++ b/arch/x86/ia32/ia32entry.S
9886 @@ -15,8 +15,10 @@
9887 #include <asm/irqflags.h>
9888 #include <asm/asm.h>
9889 #include <asm/smap.h>
9890 +#include <asm/pgtable.h>
9891 #include <linux/linkage.h>
9892 #include <linux/err.h>
9893 +#include <asm/alternative-asm.h>
9894
9895 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
9896 #include <linux/elf-em.h>
9897 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
9898 ENDPROC(native_irq_enable_sysexit)
9899 #endif
9900
9901 + .macro pax_enter_kernel_user
9902 + pax_set_fptr_mask
9903 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9904 + call pax_enter_kernel_user
9905 +#endif
9906 + .endm
9907 +
9908 + .macro pax_exit_kernel_user
9909 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9910 + call pax_exit_kernel_user
9911 +#endif
9912 +#ifdef CONFIG_PAX_RANDKSTACK
9913 + pushq %rax
9914 + pushq %r11
9915 + call pax_randomize_kstack
9916 + popq %r11
9917 + popq %rax
9918 +#endif
9919 + .endm
9920 +
9921 +.macro pax_erase_kstack
9922 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
9923 + call pax_erase_kstack
9924 +#endif
9925 +.endm
9926 +
9927 /*
9928 * 32bit SYSENTER instruction entry.
9929 *
9930 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
9931 CFI_REGISTER rsp,rbp
9932 SWAPGS_UNSAFE_STACK
9933 movq PER_CPU_VAR(kernel_stack), %rsp
9934 - addq $(KERNEL_STACK_OFFSET),%rsp
9935 - /*
9936 - * No need to follow this irqs on/off section: the syscall
9937 - * disabled irqs, here we enable it straight after entry:
9938 - */
9939 - ENABLE_INTERRUPTS(CLBR_NONE)
9940 movl %ebp,%ebp /* zero extension */
9941 pushq_cfi $__USER32_DS
9942 /*CFI_REL_OFFSET ss,0*/
9943 @@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
9944 CFI_REL_OFFSET rsp,0
9945 pushfq_cfi
9946 /*CFI_REL_OFFSET rflags,0*/
9947 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
9948 - CFI_REGISTER rip,r10
9949 + orl $X86_EFLAGS_IF,(%rsp)
9950 + GET_THREAD_INFO(%r11)
9951 + movl TI_sysenter_return(%r11), %r11d
9952 + CFI_REGISTER rip,r11
9953 pushq_cfi $__USER32_CS
9954 /*CFI_REL_OFFSET cs,0*/
9955 movl %eax, %eax
9956 - pushq_cfi %r10
9957 + pushq_cfi %r11
9958 CFI_REL_OFFSET rip,0
9959 pushq_cfi %rax
9960 cld
9961 SAVE_ARGS 0,1,0
9962 + pax_enter_kernel_user
9963 +
9964 +#ifdef CONFIG_PAX_RANDKSTACK
9965 + pax_erase_kstack
9966 +#endif
9967 +
9968 + /*
9969 + * No need to follow this irqs on/off section: the syscall
9970 + * disabled irqs, here we enable it straight after entry:
9971 + */
9972 + ENABLE_INTERRUPTS(CLBR_NONE)
9973 /* no need to do an access_ok check here because rbp has been
9974 32bit zero extended */
9975 +
9976 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9977 + mov $PAX_USER_SHADOW_BASE,%r11
9978 + add %r11,%rbp
9979 +#endif
9980 +
9981 ASM_STAC
9982 1: movl (%rbp),%ebp
9983 _ASM_EXTABLE(1b,ia32_badarg)
9984 ASM_CLAC
9985 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9986 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9987 + GET_THREAD_INFO(%r11)
9988 + orl $TS_COMPAT,TI_status(%r11)
9989 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9990 CFI_REMEMBER_STATE
9991 jnz sysenter_tracesys
9992 cmpq $(IA32_NR_syscalls-1),%rax
9993 @@ -162,12 +204,15 @@ sysenter_do_call:
9994 sysenter_dispatch:
9995 call *ia32_sys_call_table(,%rax,8)
9996 movq %rax,RAX-ARGOFFSET(%rsp)
9997 + GET_THREAD_INFO(%r11)
9998 DISABLE_INTERRUPTS(CLBR_NONE)
9999 TRACE_IRQS_OFF
10000 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10001 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
10002 jnz sysexit_audit
10003 sysexit_from_sys_call:
10004 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10005 + pax_exit_kernel_user
10006 + pax_erase_kstack
10007 + andl $~TS_COMPAT,TI_status(%r11)
10008 /* clear IF, that popfq doesn't enable interrupts early */
10009 andl $~0x200,EFLAGS-R11(%rsp)
10010 movl RIP-R11(%rsp),%edx /* User %eip */
10011 @@ -193,6 +238,9 @@ sysexit_from_sys_call:
10012 movl %eax,%esi /* 2nd arg: syscall number */
10013 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
10014 call __audit_syscall_entry
10015 +
10016 + pax_erase_kstack
10017 +
10018 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
10019 cmpq $(IA32_NR_syscalls-1),%rax
10020 ja ia32_badsys
10021 @@ -204,7 +252,7 @@ sysexit_from_sys_call:
10022 .endm
10023
10024 .macro auditsys_exit exit
10025 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10026 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10027 jnz ia32_ret_from_sys_call
10028 TRACE_IRQS_ON
10029 ENABLE_INTERRUPTS(CLBR_NONE)
10030 @@ -215,11 +263,12 @@ sysexit_from_sys_call:
10031 1: setbe %al /* 1 if error, 0 if not */
10032 movzbl %al,%edi /* zero-extend that into %edi */
10033 call __audit_syscall_exit
10034 + GET_THREAD_INFO(%r11)
10035 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
10036 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
10037 DISABLE_INTERRUPTS(CLBR_NONE)
10038 TRACE_IRQS_OFF
10039 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10040 + testl %edi,TI_flags(%r11)
10041 jz \exit
10042 CLEAR_RREGS -ARGOFFSET
10043 jmp int_with_check
10044 @@ -237,7 +286,7 @@ sysexit_audit:
10045
10046 sysenter_tracesys:
10047 #ifdef CONFIG_AUDITSYSCALL
10048 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10049 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10050 jz sysenter_auditsys
10051 #endif
10052 SAVE_REST
10053 @@ -249,6 +298,9 @@ sysenter_tracesys:
10054 RESTORE_REST
10055 cmpq $(IA32_NR_syscalls-1),%rax
10056 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
10057 +
10058 + pax_erase_kstack
10059 +
10060 jmp sysenter_do_call
10061 CFI_ENDPROC
10062 ENDPROC(ia32_sysenter_target)
10063 @@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
10064 ENTRY(ia32_cstar_target)
10065 CFI_STARTPROC32 simple
10066 CFI_SIGNAL_FRAME
10067 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
10068 + CFI_DEF_CFA rsp,0
10069 CFI_REGISTER rip,rcx
10070 /*CFI_REGISTER rflags,r11*/
10071 SWAPGS_UNSAFE_STACK
10072 movl %esp,%r8d
10073 CFI_REGISTER rsp,r8
10074 movq PER_CPU_VAR(kernel_stack),%rsp
10075 + SAVE_ARGS 8*6,0,0
10076 + pax_enter_kernel_user
10077 +
10078 +#ifdef CONFIG_PAX_RANDKSTACK
10079 + pax_erase_kstack
10080 +#endif
10081 +
10082 /*
10083 * No need to follow this irqs on/off section: the syscall
10084 * disabled irqs and here we enable it straight after entry:
10085 */
10086 ENABLE_INTERRUPTS(CLBR_NONE)
10087 - SAVE_ARGS 8,0,0
10088 movl %eax,%eax /* zero extension */
10089 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
10090 movq %rcx,RIP-ARGOFFSET(%rsp)
10091 @@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
10092 /* no need to do an access_ok check here because r8 has been
10093 32bit zero extended */
10094 /* hardware stack frame is complete now */
10095 +
10096 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10097 + mov $PAX_USER_SHADOW_BASE,%r11
10098 + add %r11,%r8
10099 +#endif
10100 +
10101 ASM_STAC
10102 1: movl (%r8),%r9d
10103 _ASM_EXTABLE(1b,ia32_badarg)
10104 ASM_CLAC
10105 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10106 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10107 + GET_THREAD_INFO(%r11)
10108 + orl $TS_COMPAT,TI_status(%r11)
10109 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
10110 CFI_REMEMBER_STATE
10111 jnz cstar_tracesys
10112 cmpq $IA32_NR_syscalls-1,%rax
10113 @@ -319,12 +384,15 @@ cstar_do_call:
10114 cstar_dispatch:
10115 call *ia32_sys_call_table(,%rax,8)
10116 movq %rax,RAX-ARGOFFSET(%rsp)
10117 + GET_THREAD_INFO(%r11)
10118 DISABLE_INTERRUPTS(CLBR_NONE)
10119 TRACE_IRQS_OFF
10120 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10121 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
10122 jnz sysretl_audit
10123 sysretl_from_sys_call:
10124 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10125 + pax_exit_kernel_user
10126 + pax_erase_kstack
10127 + andl $~TS_COMPAT,TI_status(%r11)
10128 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
10129 movl RIP-ARGOFFSET(%rsp),%ecx
10130 CFI_REGISTER rip,rcx
10131 @@ -352,7 +420,7 @@ sysretl_audit:
10132
10133 cstar_tracesys:
10134 #ifdef CONFIG_AUDITSYSCALL
10135 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10136 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10137 jz cstar_auditsys
10138 #endif
10139 xchgl %r9d,%ebp
10140 @@ -366,6 +434,9 @@ cstar_tracesys:
10141 xchgl %ebp,%r9d
10142 cmpq $(IA32_NR_syscalls-1),%rax
10143 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
10144 +
10145 + pax_erase_kstack
10146 +
10147 jmp cstar_do_call
10148 END(ia32_cstar_target)
10149
10150 @@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
10151 CFI_REL_OFFSET rip,RIP-RIP
10152 PARAVIRT_ADJUST_EXCEPTION_FRAME
10153 SWAPGS
10154 - /*
10155 - * No need to follow this irqs on/off section: the syscall
10156 - * disabled irqs and here we enable it straight after entry:
10157 - */
10158 - ENABLE_INTERRUPTS(CLBR_NONE)
10159 movl %eax,%eax
10160 pushq_cfi %rax
10161 cld
10162 /* note the registers are not zero extended to the sf.
10163 this could be a problem. */
10164 SAVE_ARGS 0,1,0
10165 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10166 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10167 + pax_enter_kernel_user
10168 +
10169 +#ifdef CONFIG_PAX_RANDKSTACK
10170 + pax_erase_kstack
10171 +#endif
10172 +
10173 + /*
10174 + * No need to follow this irqs on/off section: the syscall
10175 + * disabled irqs and here we enable it straight after entry:
10176 + */
10177 + ENABLE_INTERRUPTS(CLBR_NONE)
10178 + GET_THREAD_INFO(%r11)
10179 + orl $TS_COMPAT,TI_status(%r11)
10180 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
10181 jnz ia32_tracesys
10182 cmpq $(IA32_NR_syscalls-1),%rax
10183 ja ia32_badsys
10184 @@ -442,6 +520,9 @@ ia32_tracesys:
10185 RESTORE_REST
10186 cmpq $(IA32_NR_syscalls-1),%rax
10187 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
10188 +
10189 + pax_erase_kstack
10190 +
10191 jmp ia32_do_call
10192 END(ia32_syscall)
10193
10194 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
10195 index 86d68d1..f9960fe 100644
10196 --- a/arch/x86/ia32/sys_ia32.c
10197 +++ b/arch/x86/ia32/sys_ia32.c
10198 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
10199 */
10200 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
10201 {
10202 - typeof(ubuf->st_uid) uid = 0;
10203 - typeof(ubuf->st_gid) gid = 0;
10204 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
10205 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
10206 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
10207 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
10208 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
10209 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
10210 mm_segment_t old_fs = get_fs();
10211
10212 set_fs(KERNEL_DS);
10213 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
10214 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
10215 set_fs(old_fs);
10216 if (put_compat_timespec(&t, interval))
10217 return -EFAULT;
10218 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
10219 mm_segment_t old_fs = get_fs();
10220
10221 set_fs(KERNEL_DS);
10222 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
10223 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
10224 set_fs(old_fs);
10225 if (!ret) {
10226 switch (_NSIG_WORDS) {
10227 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
10228 if (copy_siginfo_from_user32(&info, uinfo))
10229 return -EFAULT;
10230 set_fs(KERNEL_DS);
10231 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
10232 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
10233 set_fs(old_fs);
10234 return ret;
10235 }
10236 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
10237 return -EFAULT;
10238
10239 set_fs(KERNEL_DS);
10240 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
10241 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
10242 count);
10243 set_fs(old_fs);
10244
10245 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
10246 index 372231c..a5aa1a1 100644
10247 --- a/arch/x86/include/asm/alternative-asm.h
10248 +++ b/arch/x86/include/asm/alternative-asm.h
10249 @@ -18,6 +18,45 @@
10250 .endm
10251 #endif
10252
10253 +#ifdef KERNEXEC_PLUGIN
10254 + .macro pax_force_retaddr_bts rip=0
10255 + btsq $63,\rip(%rsp)
10256 + .endm
10257 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10258 + .macro pax_force_retaddr rip=0, reload=0
10259 + btsq $63,\rip(%rsp)
10260 + .endm
10261 + .macro pax_force_fptr ptr
10262 + btsq $63,\ptr
10263 + .endm
10264 + .macro pax_set_fptr_mask
10265 + .endm
10266 +#endif
10267 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
10268 + .macro pax_force_retaddr rip=0, reload=0
10269 + .if \reload
10270 + pax_set_fptr_mask
10271 + .endif
10272 + orq %r10,\rip(%rsp)
10273 + .endm
10274 + .macro pax_force_fptr ptr
10275 + orq %r10,\ptr
10276 + .endm
10277 + .macro pax_set_fptr_mask
10278 + movabs $0x8000000000000000,%r10
10279 + .endm
10280 +#endif
10281 +#else
10282 + .macro pax_force_retaddr rip=0, reload=0
10283 + .endm
10284 + .macro pax_force_fptr ptr
10285 + .endm
10286 + .macro pax_force_retaddr_bts rip=0
10287 + .endm
10288 + .macro pax_set_fptr_mask
10289 + .endm
10290 +#endif
10291 +
10292 .macro altinstruction_entry orig alt feature orig_len alt_len
10293 .long \orig - .
10294 .long \alt - .
10295 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
10296 index 58ed6d9..f1cbe58 100644
10297 --- a/arch/x86/include/asm/alternative.h
10298 +++ b/arch/x86/include/asm/alternative.h
10299 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
10300 ".pushsection .discard,\"aw\",@progbits\n" \
10301 DISCARD_ENTRY(1) \
10302 ".popsection\n" \
10303 - ".pushsection .altinstr_replacement, \"ax\"\n" \
10304 + ".pushsection .altinstr_replacement, \"a\"\n" \
10305 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
10306 ".popsection"
10307
10308 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
10309 DISCARD_ENTRY(1) \
10310 DISCARD_ENTRY(2) \
10311 ".popsection\n" \
10312 - ".pushsection .altinstr_replacement, \"ax\"\n" \
10313 + ".pushsection .altinstr_replacement, \"a\"\n" \
10314 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
10315 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
10316 ".popsection"
10317 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
10318 index 3388034..ba52312 100644
10319 --- a/arch/x86/include/asm/apic.h
10320 +++ b/arch/x86/include/asm/apic.h
10321 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
10322
10323 #ifdef CONFIG_X86_LOCAL_APIC
10324
10325 -extern unsigned int apic_verbosity;
10326 +extern int apic_verbosity;
10327 extern int local_apic_timer_c2_ok;
10328
10329 extern int disable_apic;
10330 @@ -391,7 +391,7 @@ struct apic {
10331 */
10332 int (*x86_32_numa_cpu_node)(int cpu);
10333 #endif
10334 -};
10335 +} __do_const;
10336
10337 /*
10338 * Pointer to the local APIC driver in use on this system (there's
10339 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
10340 index 20370c6..a2eb9b0 100644
10341 --- a/arch/x86/include/asm/apm.h
10342 +++ b/arch/x86/include/asm/apm.h
10343 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
10344 __asm__ __volatile__(APM_DO_ZERO_SEGS
10345 "pushl %%edi\n\t"
10346 "pushl %%ebp\n\t"
10347 - "lcall *%%cs:apm_bios_entry\n\t"
10348 + "lcall *%%ss:apm_bios_entry\n\t"
10349 "setc %%al\n\t"
10350 "popl %%ebp\n\t"
10351 "popl %%edi\n\t"
10352 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
10353 __asm__ __volatile__(APM_DO_ZERO_SEGS
10354 "pushl %%edi\n\t"
10355 "pushl %%ebp\n\t"
10356 - "lcall *%%cs:apm_bios_entry\n\t"
10357 + "lcall *%%ss:apm_bios_entry\n\t"
10358 "setc %%bl\n\t"
10359 "popl %%ebp\n\t"
10360 "popl %%edi\n\t"
10361 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
10362 index b6c3b82..b4c077a 100644
10363 --- a/arch/x86/include/asm/atomic.h
10364 +++ b/arch/x86/include/asm/atomic.h
10365 @@ -22,7 +22,18 @@
10366 */
10367 static inline int atomic_read(const atomic_t *v)
10368 {
10369 - return (*(volatile int *)&(v)->counter);
10370 + return (*(volatile const int *)&(v)->counter);
10371 +}
10372 +
10373 +/**
10374 + * atomic_read_unchecked - read atomic variable
10375 + * @v: pointer of type atomic_unchecked_t
10376 + *
10377 + * Atomically reads the value of @v.
10378 + */
10379 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10380 +{
10381 + return (*(volatile const int *)&(v)->counter);
10382 }
10383
10384 /**
10385 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
10386 }
10387
10388 /**
10389 + * atomic_set_unchecked - set atomic variable
10390 + * @v: pointer of type atomic_unchecked_t
10391 + * @i: required value
10392 + *
10393 + * Atomically sets the value of @v to @i.
10394 + */
10395 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10396 +{
10397 + v->counter = i;
10398 +}
10399 +
10400 +/**
10401 * atomic_add - add integer to atomic variable
10402 * @i: integer value to add
10403 * @v: pointer of type atomic_t
10404 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
10405 */
10406 static inline void atomic_add(int i, atomic_t *v)
10407 {
10408 - asm volatile(LOCK_PREFIX "addl %1,%0"
10409 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
10410 +
10411 +#ifdef CONFIG_PAX_REFCOUNT
10412 + "jno 0f\n"
10413 + LOCK_PREFIX "subl %1,%0\n"
10414 + "int $4\n0:\n"
10415 + _ASM_EXTABLE(0b, 0b)
10416 +#endif
10417 +
10418 + : "+m" (v->counter)
10419 + : "ir" (i));
10420 +}
10421 +
10422 +/**
10423 + * atomic_add_unchecked - add integer to atomic variable
10424 + * @i: integer value to add
10425 + * @v: pointer of type atomic_unchecked_t
10426 + *
10427 + * Atomically adds @i to @v.
10428 + */
10429 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
10430 +{
10431 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
10432 : "+m" (v->counter)
10433 : "ir" (i));
10434 }
10435 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
10436 */
10437 static inline void atomic_sub(int i, atomic_t *v)
10438 {
10439 - asm volatile(LOCK_PREFIX "subl %1,%0"
10440 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
10441 +
10442 +#ifdef CONFIG_PAX_REFCOUNT
10443 + "jno 0f\n"
10444 + LOCK_PREFIX "addl %1,%0\n"
10445 + "int $4\n0:\n"
10446 + _ASM_EXTABLE(0b, 0b)
10447 +#endif
10448 +
10449 + : "+m" (v->counter)
10450 + : "ir" (i));
10451 +}
10452 +
10453 +/**
10454 + * atomic_sub_unchecked - subtract integer from atomic variable
10455 + * @i: integer value to subtract
10456 + * @v: pointer of type atomic_unchecked_t
10457 + *
10458 + * Atomically subtracts @i from @v.
10459 + */
10460 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
10461 +{
10462 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
10463 : "+m" (v->counter)
10464 : "ir" (i));
10465 }
10466 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10467 {
10468 unsigned char c;
10469
10470 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
10471 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
10472 +
10473 +#ifdef CONFIG_PAX_REFCOUNT
10474 + "jno 0f\n"
10475 + LOCK_PREFIX "addl %2,%0\n"
10476 + "int $4\n0:\n"
10477 + _ASM_EXTABLE(0b, 0b)
10478 +#endif
10479 +
10480 + "sete %1\n"
10481 : "+m" (v->counter), "=qm" (c)
10482 : "ir" (i) : "memory");
10483 return c;
10484 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10485 */
10486 static inline void atomic_inc(atomic_t *v)
10487 {
10488 - asm volatile(LOCK_PREFIX "incl %0"
10489 + asm volatile(LOCK_PREFIX "incl %0\n"
10490 +
10491 +#ifdef CONFIG_PAX_REFCOUNT
10492 + "jno 0f\n"
10493 + LOCK_PREFIX "decl %0\n"
10494 + "int $4\n0:\n"
10495 + _ASM_EXTABLE(0b, 0b)
10496 +#endif
10497 +
10498 + : "+m" (v->counter));
10499 +}
10500 +
10501 +/**
10502 + * atomic_inc_unchecked - increment atomic variable
10503 + * @v: pointer of type atomic_unchecked_t
10504 + *
10505 + * Atomically increments @v by 1.
10506 + */
10507 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10508 +{
10509 + asm volatile(LOCK_PREFIX "incl %0\n"
10510 : "+m" (v->counter));
10511 }
10512
10513 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
10514 */
10515 static inline void atomic_dec(atomic_t *v)
10516 {
10517 - asm volatile(LOCK_PREFIX "decl %0"
10518 + asm volatile(LOCK_PREFIX "decl %0\n"
10519 +
10520 +#ifdef CONFIG_PAX_REFCOUNT
10521 + "jno 0f\n"
10522 + LOCK_PREFIX "incl %0\n"
10523 + "int $4\n0:\n"
10524 + _ASM_EXTABLE(0b, 0b)
10525 +#endif
10526 +
10527 + : "+m" (v->counter));
10528 +}
10529 +
10530 +/**
10531 + * atomic_dec_unchecked - decrement atomic variable
10532 + * @v: pointer of type atomic_unchecked_t
10533 + *
10534 + * Atomically decrements @v by 1.
10535 + */
10536 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10537 +{
10538 + asm volatile(LOCK_PREFIX "decl %0\n"
10539 : "+m" (v->counter));
10540 }
10541
10542 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
10543 {
10544 unsigned char c;
10545
10546 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
10547 + asm volatile(LOCK_PREFIX "decl %0\n"
10548 +
10549 +#ifdef CONFIG_PAX_REFCOUNT
10550 + "jno 0f\n"
10551 + LOCK_PREFIX "incl %0\n"
10552 + "int $4\n0:\n"
10553 + _ASM_EXTABLE(0b, 0b)
10554 +#endif
10555 +
10556 + "sete %1\n"
10557 : "+m" (v->counter), "=qm" (c)
10558 : : "memory");
10559 return c != 0;
10560 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
10561 {
10562 unsigned char c;
10563
10564 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
10565 + asm volatile(LOCK_PREFIX "incl %0\n"
10566 +
10567 +#ifdef CONFIG_PAX_REFCOUNT
10568 + "jno 0f\n"
10569 + LOCK_PREFIX "decl %0\n"
10570 + "int $4\n0:\n"
10571 + _ASM_EXTABLE(0b, 0b)
10572 +#endif
10573 +
10574 + "sete %1\n"
10575 + : "+m" (v->counter), "=qm" (c)
10576 + : : "memory");
10577 + return c != 0;
10578 +}
10579 +
10580 +/**
10581 + * atomic_inc_and_test_unchecked - increment and test
10582 + * @v: pointer of type atomic_unchecked_t
10583 + *
10584 + * Atomically increments @v by 1
10585 + * and returns true if the result is zero, or false for all
10586 + * other cases.
10587 + */
10588 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10589 +{
10590 + unsigned char c;
10591 +
10592 + asm volatile(LOCK_PREFIX "incl %0\n"
10593 + "sete %1\n"
10594 : "+m" (v->counter), "=qm" (c)
10595 : : "memory");
10596 return c != 0;
10597 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
10598 {
10599 unsigned char c;
10600
10601 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
10602 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
10603 +
10604 +#ifdef CONFIG_PAX_REFCOUNT
10605 + "jno 0f\n"
10606 + LOCK_PREFIX "subl %2,%0\n"
10607 + "int $4\n0:\n"
10608 + _ASM_EXTABLE(0b, 0b)
10609 +#endif
10610 +
10611 + "sets %1\n"
10612 : "+m" (v->counter), "=qm" (c)
10613 : "ir" (i) : "memory");
10614 return c;
10615 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
10616 goto no_xadd;
10617 #endif
10618 /* Modern 486+ processor */
10619 - return i + xadd(&v->counter, i);
10620 + return i + xadd_check_overflow(&v->counter, i);
10621
10622 #ifdef CONFIG_M386
10623 no_xadd: /* Legacy 386 processor */
10624 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
10625 }
10626
10627 /**
10628 + * atomic_add_return_unchecked - add integer and return
10629 + * @i: integer value to add
10630 + * @v: pointer of type atomic_unchecked_t
10631 + *
10632 + * Atomically adds @i to @v and returns @i + @v
10633 + */
10634 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10635 +{
10636 +#ifdef CONFIG_M386
10637 + int __i;
10638 + unsigned long flags;
10639 + if (unlikely(boot_cpu_data.x86 <= 3))
10640 + goto no_xadd;
10641 +#endif
10642 + /* Modern 486+ processor */
10643 + return i + xadd(&v->counter, i);
10644 +
10645 +#ifdef CONFIG_M386
10646 +no_xadd: /* Legacy 386 processor */
10647 + raw_local_irq_save(flags);
10648 + __i = atomic_read_unchecked(v);
10649 + atomic_set_unchecked(v, i + __i);
10650 + raw_local_irq_restore(flags);
10651 + return i + __i;
10652 +#endif
10653 +}
10654 +
10655 +/**
10656 * atomic_sub_return - subtract integer and return
10657 * @v: pointer of type atomic_t
10658 * @i: integer value to subtract
10659 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
10660 }
10661
10662 #define atomic_inc_return(v) (atomic_add_return(1, v))
10663 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10664 +{
10665 + return atomic_add_return_unchecked(1, v);
10666 +}
10667 #define atomic_dec_return(v) (atomic_sub_return(1, v))
10668
10669 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10670 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10671 return cmpxchg(&v->counter, old, new);
10672 }
10673
10674 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10675 +{
10676 + return cmpxchg(&v->counter, old, new);
10677 +}
10678 +
10679 static inline int atomic_xchg(atomic_t *v, int new)
10680 {
10681 return xchg(&v->counter, new);
10682 }
10683
10684 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10685 +{
10686 + return xchg(&v->counter, new);
10687 +}
10688 +
10689 /**
10690 * __atomic_add_unless - add unless the number is already a given value
10691 * @v: pointer of type atomic_t
10692 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
10693 */
10694 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10695 {
10696 - int c, old;
10697 + int c, old, new;
10698 c = atomic_read(v);
10699 for (;;) {
10700 - if (unlikely(c == (u)))
10701 + if (unlikely(c == u))
10702 break;
10703 - old = atomic_cmpxchg((v), c, c + (a));
10704 +
10705 + asm volatile("addl %2,%0\n"
10706 +
10707 +#ifdef CONFIG_PAX_REFCOUNT
10708 + "jno 0f\n"
10709 + "subl %2,%0\n"
10710 + "int $4\n0:\n"
10711 + _ASM_EXTABLE(0b, 0b)
10712 +#endif
10713 +
10714 + : "=r" (new)
10715 + : "0" (c), "ir" (a));
10716 +
10717 + old = atomic_cmpxchg(v, c, new);
10718 if (likely(old == c))
10719 break;
10720 c = old;
10721 @@ -241,6 +458,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10722 }
10723
10724 /**
10725 + * atomic_inc_not_zero_hint - increment if not null
10726 + * @v: pointer of type atomic_t
10727 + * @hint: probable value of the atomic before the increment
10728 + *
10729 + * This version of atomic_inc_not_zero() gives a hint of probable
10730 + * value of the atomic. This helps processor to not read the memory
10731 + * before doing the atomic read/modify/write cycle, lowering
10732 + * number of bus transactions on some arches.
10733 + *
10734 + * Returns: 0 if increment was not done, 1 otherwise.
10735 + */
10736 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
10737 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
10738 +{
10739 + int val, c = hint, new;
10740 +
10741 + /* sanity test, should be removed by compiler if hint is a constant */
10742 + if (!hint)
10743 + return __atomic_add_unless(v, 1, 0);
10744 +
10745 + do {
10746 + asm volatile("incl %0\n"
10747 +
10748 +#ifdef CONFIG_PAX_REFCOUNT
10749 + "jno 0f\n"
10750 + "decl %0\n"
10751 + "int $4\n0:\n"
10752 + _ASM_EXTABLE(0b, 0b)
10753 +#endif
10754 +
10755 + : "=r" (new)
10756 + : "0" (c));
10757 +
10758 + val = atomic_cmpxchg(v, c, new);
10759 + if (val == c)
10760 + return 1;
10761 + c = val;
10762 + } while (c);
10763 +
10764 + return 0;
10765 +}
10766 +
10767 +/**
10768 * atomic_inc_short - increment of a short integer
10769 * @v: pointer to type int
10770 *
10771 @@ -269,14 +529,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
10772 #endif
10773
10774 /* These are x86-specific, used by some header files */
10775 -#define atomic_clear_mask(mask, addr) \
10776 - asm volatile(LOCK_PREFIX "andl %0,%1" \
10777 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
10778 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
10779 +{
10780 + asm volatile(LOCK_PREFIX "andl %1,%0"
10781 + : "+m" (v->counter)
10782 + : "r" (~(mask))
10783 + : "memory");
10784 +}
10785
10786 -#define atomic_set_mask(mask, addr) \
10787 - asm volatile(LOCK_PREFIX "orl %0,%1" \
10788 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
10789 - : "memory")
10790 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10791 +{
10792 + asm volatile(LOCK_PREFIX "andl %1,%0"
10793 + : "+m" (v->counter)
10794 + : "r" (~(mask))
10795 + : "memory");
10796 +}
10797 +
10798 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
10799 +{
10800 + asm volatile(LOCK_PREFIX "orl %1,%0"
10801 + : "+m" (v->counter)
10802 + : "r" (mask)
10803 + : "memory");
10804 +}
10805 +
10806 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10807 +{
10808 + asm volatile(LOCK_PREFIX "orl %1,%0"
10809 + : "+m" (v->counter)
10810 + : "r" (mask)
10811 + : "memory");
10812 +}
10813
10814 /* Atomic operations are already serializing on x86 */
10815 #define smp_mb__before_atomic_dec() barrier()
10816 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
10817 index b154de7..aadebd8 100644
10818 --- a/arch/x86/include/asm/atomic64_32.h
10819 +++ b/arch/x86/include/asm/atomic64_32.h
10820 @@ -12,6 +12,14 @@ typedef struct {
10821 u64 __aligned(8) counter;
10822 } atomic64_t;
10823
10824 +#ifdef CONFIG_PAX_REFCOUNT
10825 +typedef struct {
10826 + u64 __aligned(8) counter;
10827 +} atomic64_unchecked_t;
10828 +#else
10829 +typedef atomic64_t atomic64_unchecked_t;
10830 +#endif
10831 +
10832 #define ATOMIC64_INIT(val) { (val) }
10833
10834 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
10835 @@ -37,21 +45,31 @@ typedef struct {
10836 ATOMIC64_DECL_ONE(sym##_386)
10837
10838 ATOMIC64_DECL_ONE(add_386);
10839 +ATOMIC64_DECL_ONE(add_unchecked_386);
10840 ATOMIC64_DECL_ONE(sub_386);
10841 +ATOMIC64_DECL_ONE(sub_unchecked_386);
10842 ATOMIC64_DECL_ONE(inc_386);
10843 +ATOMIC64_DECL_ONE(inc_unchecked_386);
10844 ATOMIC64_DECL_ONE(dec_386);
10845 +ATOMIC64_DECL_ONE(dec_unchecked_386);
10846 #endif
10847
10848 #define alternative_atomic64(f, out, in...) \
10849 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
10850
10851 ATOMIC64_DECL(read);
10852 +ATOMIC64_DECL(read_unchecked);
10853 ATOMIC64_DECL(set);
10854 +ATOMIC64_DECL(set_unchecked);
10855 ATOMIC64_DECL(xchg);
10856 ATOMIC64_DECL(add_return);
10857 +ATOMIC64_DECL(add_return_unchecked);
10858 ATOMIC64_DECL(sub_return);
10859 +ATOMIC64_DECL(sub_return_unchecked);
10860 ATOMIC64_DECL(inc_return);
10861 +ATOMIC64_DECL(inc_return_unchecked);
10862 ATOMIC64_DECL(dec_return);
10863 +ATOMIC64_DECL(dec_return_unchecked);
10864 ATOMIC64_DECL(dec_if_positive);
10865 ATOMIC64_DECL(inc_not_zero);
10866 ATOMIC64_DECL(add_unless);
10867 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
10868 }
10869
10870 /**
10871 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
10872 + * @p: pointer to type atomic64_unchecked_t
10873 + * @o: expected value
10874 + * @n: new value
10875 + *
10876 + * Atomically sets @v to @n if it was equal to @o and returns
10877 + * the old value.
10878 + */
10879 +
10880 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
10881 +{
10882 + return cmpxchg64(&v->counter, o, n);
10883 +}
10884 +
10885 +/**
10886 * atomic64_xchg - xchg atomic64 variable
10887 * @v: pointer to type atomic64_t
10888 * @n: value to assign
10889 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
10890 }
10891
10892 /**
10893 + * atomic64_set_unchecked - set atomic64 variable
10894 + * @v: pointer to type atomic64_unchecked_t
10895 + * @n: value to assign
10896 + *
10897 + * Atomically sets the value of @v to @n.
10898 + */
10899 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
10900 +{
10901 + unsigned high = (unsigned)(i >> 32);
10902 + unsigned low = (unsigned)i;
10903 + alternative_atomic64(set, /* no output */,
10904 + "S" (v), "b" (low), "c" (high)
10905 + : "eax", "edx", "memory");
10906 +}
10907 +
10908 +/**
10909 * atomic64_read - read atomic64 variable
10910 * @v: pointer to type atomic64_t
10911 *
10912 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
10913 }
10914
10915 /**
10916 + * atomic64_read_unchecked - read atomic64 variable
10917 + * @v: pointer to type atomic64_unchecked_t
10918 + *
10919 + * Atomically reads the value of @v and returns it.
10920 + */
10921 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
10922 +{
10923 + long long r;
10924 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
10925 + return r;
10926 + }
10927 +
10928 +/**
10929 * atomic64_add_return - add and return
10930 * @i: integer value to add
10931 * @v: pointer to type atomic64_t
10932 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
10933 return i;
10934 }
10935
10936 +/**
10937 + * atomic64_add_return_unchecked - add and return
10938 + * @i: integer value to add
10939 + * @v: pointer to type atomic64_unchecked_t
10940 + *
10941 + * Atomically adds @i to @v and returns @i + *@v
10942 + */
10943 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
10944 +{
10945 + alternative_atomic64(add_return_unchecked,
10946 + ASM_OUTPUT2("+A" (i), "+c" (v)),
10947 + ASM_NO_INPUT_CLOBBER("memory"));
10948 + return i;
10949 +}
10950 +
10951 /*
10952 * Other variants with different arithmetic operators:
10953 */
10954 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
10955 return a;
10956 }
10957
10958 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10959 +{
10960 + long long a;
10961 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
10962 + "S" (v) : "memory", "ecx");
10963 + return a;
10964 +}
10965 +
10966 static inline long long atomic64_dec_return(atomic64_t *v)
10967 {
10968 long long a;
10969 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
10970 }
10971
10972 /**
10973 + * atomic64_add_unchecked - add integer to atomic64 variable
10974 + * @i: integer value to add
10975 + * @v: pointer to type atomic64_unchecked_t
10976 + *
10977 + * Atomically adds @i to @v.
10978 + */
10979 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
10980 +{
10981 + __alternative_atomic64(add_unchecked, add_return_unchecked,
10982 + ASM_OUTPUT2("+A" (i), "+c" (v)),
10983 + ASM_NO_INPUT_CLOBBER("memory"));
10984 + return i;
10985 +}
10986 +
10987 +/**
10988 * atomic64_sub - subtract the atomic64 variable
10989 * @i: integer value to subtract
10990 * @v: pointer to type atomic64_t
10991 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
10992 index 0e1cbfc..5623683 100644
10993 --- a/arch/x86/include/asm/atomic64_64.h
10994 +++ b/arch/x86/include/asm/atomic64_64.h
10995 @@ -18,7 +18,19 @@
10996 */
10997 static inline long atomic64_read(const atomic64_t *v)
10998 {
10999 - return (*(volatile long *)&(v)->counter);
11000 + return (*(volatile const long *)&(v)->counter);
11001 +}
11002 +
11003 +/**
11004 + * atomic64_read_unchecked - read atomic64 variable
11005 + * @v: pointer of type atomic64_unchecked_t
11006 + *
11007 + * Atomically reads the value of @v.
11008 + * Doesn't imply a read memory barrier.
11009 + */
11010 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
11011 +{
11012 + return (*(volatile const long *)&(v)->counter);
11013 }
11014
11015 /**
11016 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
11017 }
11018
11019 /**
11020 + * atomic64_set_unchecked - set atomic64 variable
11021 + * @v: pointer to type atomic64_unchecked_t
11022 + * @i: required value
11023 + *
11024 + * Atomically sets the value of @v to @i.
11025 + */
11026 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
11027 +{
11028 + v->counter = i;
11029 +}
11030 +
11031 +/**
11032 * atomic64_add - add integer to atomic64 variable
11033 * @i: integer value to add
11034 * @v: pointer to type atomic64_t
11035 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
11036 */
11037 static inline void atomic64_add(long i, atomic64_t *v)
11038 {
11039 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
11040 +
11041 +#ifdef CONFIG_PAX_REFCOUNT
11042 + "jno 0f\n"
11043 + LOCK_PREFIX "subq %1,%0\n"
11044 + "int $4\n0:\n"
11045 + _ASM_EXTABLE(0b, 0b)
11046 +#endif
11047 +
11048 + : "=m" (v->counter)
11049 + : "er" (i), "m" (v->counter));
11050 +}
11051 +
11052 +/**
11053 + * atomic64_add_unchecked - add integer to atomic64 variable
11054 + * @i: integer value to add
11055 + * @v: pointer to type atomic64_unchecked_t
11056 + *
11057 + * Atomically adds @i to @v.
11058 + */
11059 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
11060 +{
11061 asm volatile(LOCK_PREFIX "addq %1,%0"
11062 : "=m" (v->counter)
11063 : "er" (i), "m" (v->counter));
11064 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
11065 */
11066 static inline void atomic64_sub(long i, atomic64_t *v)
11067 {
11068 - asm volatile(LOCK_PREFIX "subq %1,%0"
11069 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
11070 +
11071 +#ifdef CONFIG_PAX_REFCOUNT
11072 + "jno 0f\n"
11073 + LOCK_PREFIX "addq %1,%0\n"
11074 + "int $4\n0:\n"
11075 + _ASM_EXTABLE(0b, 0b)
11076 +#endif
11077 +
11078 + : "=m" (v->counter)
11079 + : "er" (i), "m" (v->counter));
11080 +}
11081 +
11082 +/**
11083 + * atomic64_sub_unchecked - subtract the atomic64 variable
11084 + * @i: integer value to subtract
11085 + * @v: pointer to type atomic64_unchecked_t
11086 + *
11087 + * Atomically subtracts @i from @v.
11088 + */
11089 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
11090 +{
11091 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
11092 : "=m" (v->counter)
11093 : "er" (i), "m" (v->counter));
11094 }
11095 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
11096 {
11097 unsigned char c;
11098
11099 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
11100 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
11101 +
11102 +#ifdef CONFIG_PAX_REFCOUNT
11103 + "jno 0f\n"
11104 + LOCK_PREFIX "addq %2,%0\n"
11105 + "int $4\n0:\n"
11106 + _ASM_EXTABLE(0b, 0b)
11107 +#endif
11108 +
11109 + "sete %1\n"
11110 : "=m" (v->counter), "=qm" (c)
11111 : "er" (i), "m" (v->counter) : "memory");
11112 return c;
11113 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
11114 */
11115 static inline void atomic64_inc(atomic64_t *v)
11116 {
11117 + asm volatile(LOCK_PREFIX "incq %0\n"
11118 +
11119 +#ifdef CONFIG_PAX_REFCOUNT
11120 + "jno 0f\n"
11121 + LOCK_PREFIX "decq %0\n"
11122 + "int $4\n0:\n"
11123 + _ASM_EXTABLE(0b, 0b)
11124 +#endif
11125 +
11126 + : "=m" (v->counter)
11127 + : "m" (v->counter));
11128 +}
11129 +
11130 +/**
11131 + * atomic64_inc_unchecked - increment atomic64 variable
11132 + * @v: pointer to type atomic64_unchecked_t
11133 + *
11134 + * Atomically increments @v by 1.
11135 + */
11136 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
11137 +{
11138 asm volatile(LOCK_PREFIX "incq %0"
11139 : "=m" (v->counter)
11140 : "m" (v->counter));
11141 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
11142 */
11143 static inline void atomic64_dec(atomic64_t *v)
11144 {
11145 - asm volatile(LOCK_PREFIX "decq %0"
11146 + asm volatile(LOCK_PREFIX "decq %0\n"
11147 +
11148 +#ifdef CONFIG_PAX_REFCOUNT
11149 + "jno 0f\n"
11150 + LOCK_PREFIX "incq %0\n"
11151 + "int $4\n0:\n"
11152 + _ASM_EXTABLE(0b, 0b)
11153 +#endif
11154 +
11155 + : "=m" (v->counter)
11156 + : "m" (v->counter));
11157 +}
11158 +
11159 +/**
11160 + * atomic64_dec_unchecked - decrement atomic64 variable
11161 + * @v: pointer to type atomic64_t
11162 + *
11163 + * Atomically decrements @v by 1.
11164 + */
11165 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
11166 +{
11167 + asm volatile(LOCK_PREFIX "decq %0\n"
11168 : "=m" (v->counter)
11169 : "m" (v->counter));
11170 }
11171 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
11172 {
11173 unsigned char c;
11174
11175 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
11176 + asm volatile(LOCK_PREFIX "decq %0\n"
11177 +
11178 +#ifdef CONFIG_PAX_REFCOUNT
11179 + "jno 0f\n"
11180 + LOCK_PREFIX "incq %0\n"
11181 + "int $4\n0:\n"
11182 + _ASM_EXTABLE(0b, 0b)
11183 +#endif
11184 +
11185 + "sete %1\n"
11186 : "=m" (v->counter), "=qm" (c)
11187 : "m" (v->counter) : "memory");
11188 return c != 0;
11189 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
11190 {
11191 unsigned char c;
11192
11193 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
11194 + asm volatile(LOCK_PREFIX "incq %0\n"
11195 +
11196 +#ifdef CONFIG_PAX_REFCOUNT
11197 + "jno 0f\n"
11198 + LOCK_PREFIX "decq %0\n"
11199 + "int $4\n0:\n"
11200 + _ASM_EXTABLE(0b, 0b)
11201 +#endif
11202 +
11203 + "sete %1\n"
11204 : "=m" (v->counter), "=qm" (c)
11205 : "m" (v->counter) : "memory");
11206 return c != 0;
11207 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
11208 {
11209 unsigned char c;
11210
11211 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
11212 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
11213 +
11214 +#ifdef CONFIG_PAX_REFCOUNT
11215 + "jno 0f\n"
11216 + LOCK_PREFIX "subq %2,%0\n"
11217 + "int $4\n0:\n"
11218 + _ASM_EXTABLE(0b, 0b)
11219 +#endif
11220 +
11221 + "sets %1\n"
11222 : "=m" (v->counter), "=qm" (c)
11223 : "er" (i), "m" (v->counter) : "memory");
11224 return c;
11225 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
11226 */
11227 static inline long atomic64_add_return(long i, atomic64_t *v)
11228 {
11229 + return i + xadd_check_overflow(&v->counter, i);
11230 +}
11231 +
11232 +/**
11233 + * atomic64_add_return_unchecked - add and return
11234 + * @i: integer value to add
11235 + * @v: pointer to type atomic64_unchecked_t
11236 + *
11237 + * Atomically adds @i to @v and returns @i + @v
11238 + */
11239 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
11240 +{
11241 return i + xadd(&v->counter, i);
11242 }
11243
11244 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
11245 }
11246
11247 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
11248 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
11249 +{
11250 + return atomic64_add_return_unchecked(1, v);
11251 +}
11252 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
11253
11254 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
11255 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
11256 return cmpxchg(&v->counter, old, new);
11257 }
11258
11259 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
11260 +{
11261 + return cmpxchg(&v->counter, old, new);
11262 +}
11263 +
11264 static inline long atomic64_xchg(atomic64_t *v, long new)
11265 {
11266 return xchg(&v->counter, new);
11267 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
11268 */
11269 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
11270 {
11271 - long c, old;
11272 + long c, old, new;
11273 c = atomic64_read(v);
11274 for (;;) {
11275 - if (unlikely(c == (u)))
11276 + if (unlikely(c == u))
11277 break;
11278 - old = atomic64_cmpxchg((v), c, c + (a));
11279 +
11280 + asm volatile("add %2,%0\n"
11281 +
11282 +#ifdef CONFIG_PAX_REFCOUNT
11283 + "jno 0f\n"
11284 + "sub %2,%0\n"
11285 + "int $4\n0:\n"
11286 + _ASM_EXTABLE(0b, 0b)
11287 +#endif
11288 +
11289 + : "=r" (new)
11290 + : "0" (c), "ir" (a));
11291 +
11292 + old = atomic64_cmpxchg(v, c, new);
11293 if (likely(old == c))
11294 break;
11295 c = old;
11296 }
11297 - return c != (u);
11298 + return c != u;
11299 }
11300
11301 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11302 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
11303 index 6dfd019..0c6699f 100644
11304 --- a/arch/x86/include/asm/bitops.h
11305 +++ b/arch/x86/include/asm/bitops.h
11306 @@ -40,7 +40,7 @@
11307 * a mask operation on a byte.
11308 */
11309 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
11310 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
11311 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
11312 #define CONST_MASK(nr) (1 << ((nr) & 7))
11313
11314 /**
11315 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
11316 index b13fe63..0dab13a 100644
11317 --- a/arch/x86/include/asm/boot.h
11318 +++ b/arch/x86/include/asm/boot.h
11319 @@ -11,10 +11,15 @@
11320 #include <asm/pgtable_types.h>
11321
11322 /* Physical address where kernel should be loaded. */
11323 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11324 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11325 + (CONFIG_PHYSICAL_ALIGN - 1)) \
11326 & ~(CONFIG_PHYSICAL_ALIGN - 1))
11327
11328 +#ifndef __ASSEMBLY__
11329 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
11330 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
11331 +#endif
11332 +
11333 /* Minimum kernel alignment, as a power of two */
11334 #ifdef CONFIG_X86_64
11335 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
11336 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
11337 index 48f99f1..d78ebf9 100644
11338 --- a/arch/x86/include/asm/cache.h
11339 +++ b/arch/x86/include/asm/cache.h
11340 @@ -5,12 +5,13 @@
11341
11342 /* L1 cache line size */
11343 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11344 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11345 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11346
11347 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
11348 +#define __read_only __attribute__((__section__(".data..read_only")))
11349
11350 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
11351 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
11352 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
11353
11354 #ifdef CONFIG_X86_VSMP
11355 #ifdef CONFIG_SMP
11356 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
11357 index 9863ee3..4a1f8e1 100644
11358 --- a/arch/x86/include/asm/cacheflush.h
11359 +++ b/arch/x86/include/asm/cacheflush.h
11360 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
11361 unsigned long pg_flags = pg->flags & _PGMT_MASK;
11362
11363 if (pg_flags == _PGMT_DEFAULT)
11364 - return -1;
11365 + return ~0UL;
11366 else if (pg_flags == _PGMT_WC)
11367 return _PAGE_CACHE_WC;
11368 else if (pg_flags == _PGMT_UC_MINUS)
11369 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
11370 index 46fc474..b02b0f9 100644
11371 --- a/arch/x86/include/asm/checksum_32.h
11372 +++ b/arch/x86/include/asm/checksum_32.h
11373 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
11374 int len, __wsum sum,
11375 int *src_err_ptr, int *dst_err_ptr);
11376
11377 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
11378 + int len, __wsum sum,
11379 + int *src_err_ptr, int *dst_err_ptr);
11380 +
11381 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
11382 + int len, __wsum sum,
11383 + int *src_err_ptr, int *dst_err_ptr);
11384 +
11385 /*
11386 * Note: when you get a NULL pointer exception here this means someone
11387 * passed in an incorrect kernel address to one of these functions.
11388 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
11389 int *err_ptr)
11390 {
11391 might_sleep();
11392 - return csum_partial_copy_generic((__force void *)src, dst,
11393 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
11394 len, sum, err_ptr, NULL);
11395 }
11396
11397 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
11398 {
11399 might_sleep();
11400 if (access_ok(VERIFY_WRITE, dst, len))
11401 - return csum_partial_copy_generic(src, (__force void *)dst,
11402 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
11403 len, sum, NULL, err_ptr);
11404
11405 if (len)
11406 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
11407 index 8d871ea..c1a0dc9 100644
11408 --- a/arch/x86/include/asm/cmpxchg.h
11409 +++ b/arch/x86/include/asm/cmpxchg.h
11410 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
11411 __compiletime_error("Bad argument size for cmpxchg");
11412 extern void __xadd_wrong_size(void)
11413 __compiletime_error("Bad argument size for xadd");
11414 +extern void __xadd_check_overflow_wrong_size(void)
11415 + __compiletime_error("Bad argument size for xadd_check_overflow");
11416 extern void __add_wrong_size(void)
11417 __compiletime_error("Bad argument size for add");
11418 +extern void __add_check_overflow_wrong_size(void)
11419 + __compiletime_error("Bad argument size for add_check_overflow");
11420
11421 /*
11422 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
11423 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
11424 __ret; \
11425 })
11426
11427 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
11428 + ({ \
11429 + __typeof__ (*(ptr)) __ret = (arg); \
11430 + switch (sizeof(*(ptr))) { \
11431 + case __X86_CASE_L: \
11432 + asm volatile (lock #op "l %0, %1\n" \
11433 + "jno 0f\n" \
11434 + "mov %0,%1\n" \
11435 + "int $4\n0:\n" \
11436 + _ASM_EXTABLE(0b, 0b) \
11437 + : "+r" (__ret), "+m" (*(ptr)) \
11438 + : : "memory", "cc"); \
11439 + break; \
11440 + case __X86_CASE_Q: \
11441 + asm volatile (lock #op "q %q0, %1\n" \
11442 + "jno 0f\n" \
11443 + "mov %0,%1\n" \
11444 + "int $4\n0:\n" \
11445 + _ASM_EXTABLE(0b, 0b) \
11446 + : "+r" (__ret), "+m" (*(ptr)) \
11447 + : : "memory", "cc"); \
11448 + break; \
11449 + default: \
11450 + __ ## op ## _check_overflow_wrong_size(); \
11451 + } \
11452 + __ret; \
11453 + })
11454 +
11455 /*
11456 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
11457 * Since this is generally used to protect other memory information, we
11458 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
11459 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
11460 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
11461
11462 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
11463 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
11464 +
11465 #define __add(ptr, inc, lock) \
11466 ({ \
11467 __typeof__ (*(ptr)) __ret = (inc); \
11468 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
11469 index 8c297aa..7a90f03 100644
11470 --- a/arch/x86/include/asm/cpufeature.h
11471 +++ b/arch/x86/include/asm/cpufeature.h
11472 @@ -205,7 +205,7 @@
11473 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
11474 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
11475 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
11476 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
11477 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
11478 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
11479 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
11480 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
11481 @@ -379,7 +379,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
11482 ".section .discard,\"aw\",@progbits\n"
11483 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
11484 ".previous\n"
11485 - ".section .altinstr_replacement,\"ax\"\n"
11486 + ".section .altinstr_replacement,\"a\"\n"
11487 "3: movb $1,%0\n"
11488 "4:\n"
11489 ".previous\n"
11490 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
11491 index 8bf1c06..f723dfd 100644
11492 --- a/arch/x86/include/asm/desc.h
11493 +++ b/arch/x86/include/asm/desc.h
11494 @@ -4,6 +4,7 @@
11495 #include <asm/desc_defs.h>
11496 #include <asm/ldt.h>
11497 #include <asm/mmu.h>
11498 +#include <asm/pgtable.h>
11499
11500 #include <linux/smp.h>
11501 #include <linux/percpu.h>
11502 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11503
11504 desc->type = (info->read_exec_only ^ 1) << 1;
11505 desc->type |= info->contents << 2;
11506 + desc->type |= info->seg_not_present ^ 1;
11507
11508 desc->s = 1;
11509 desc->dpl = 0x3;
11510 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11511 }
11512
11513 extern struct desc_ptr idt_descr;
11514 -extern gate_desc idt_table[];
11515 extern struct desc_ptr nmi_idt_descr;
11516 -extern gate_desc nmi_idt_table[];
11517 -
11518 -struct gdt_page {
11519 - struct desc_struct gdt[GDT_ENTRIES];
11520 -} __attribute__((aligned(PAGE_SIZE)));
11521 -
11522 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
11523 +extern gate_desc idt_table[256];
11524 +extern gate_desc nmi_idt_table[256];
11525
11526 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
11527 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
11528 {
11529 - return per_cpu(gdt_page, cpu).gdt;
11530 + return cpu_gdt_table[cpu];
11531 }
11532
11533 #ifdef CONFIG_X86_64
11534 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
11535 unsigned long base, unsigned dpl, unsigned flags,
11536 unsigned short seg)
11537 {
11538 - gate->a = (seg << 16) | (base & 0xffff);
11539 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
11540 + gate->gate.offset_low = base;
11541 + gate->gate.seg = seg;
11542 + gate->gate.reserved = 0;
11543 + gate->gate.type = type;
11544 + gate->gate.s = 0;
11545 + gate->gate.dpl = dpl;
11546 + gate->gate.p = 1;
11547 + gate->gate.offset_high = base >> 16;
11548 }
11549
11550 #endif
11551 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
11552
11553 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
11554 {
11555 + pax_open_kernel();
11556 memcpy(&idt[entry], gate, sizeof(*gate));
11557 + pax_close_kernel();
11558 }
11559
11560 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
11561 {
11562 + pax_open_kernel();
11563 memcpy(&ldt[entry], desc, 8);
11564 + pax_close_kernel();
11565 }
11566
11567 static inline void
11568 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
11569 default: size = sizeof(*gdt); break;
11570 }
11571
11572 + pax_open_kernel();
11573 memcpy(&gdt[entry], desc, size);
11574 + pax_close_kernel();
11575 }
11576
11577 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
11578 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
11579
11580 static inline void native_load_tr_desc(void)
11581 {
11582 + pax_open_kernel();
11583 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
11584 + pax_close_kernel();
11585 }
11586
11587 static inline void native_load_gdt(const struct desc_ptr *dtr)
11588 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
11589 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
11590 unsigned int i;
11591
11592 + pax_open_kernel();
11593 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
11594 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
11595 + pax_close_kernel();
11596 }
11597
11598 #define _LDT_empty(info) \
11599 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
11600 }
11601
11602 #ifdef CONFIG_X86_64
11603 -static inline void set_nmi_gate(int gate, void *addr)
11604 +static inline void set_nmi_gate(int gate, const void *addr)
11605 {
11606 gate_desc s;
11607
11608 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
11609 }
11610 #endif
11611
11612 -static inline void _set_gate(int gate, unsigned type, void *addr,
11613 +static inline void _set_gate(int gate, unsigned type, const void *addr,
11614 unsigned dpl, unsigned ist, unsigned seg)
11615 {
11616 gate_desc s;
11617 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
11618 * Pentium F0 0F bugfix can have resulted in the mapped
11619 * IDT being write-protected.
11620 */
11621 -static inline void set_intr_gate(unsigned int n, void *addr)
11622 +static inline void set_intr_gate(unsigned int n, const void *addr)
11623 {
11624 BUG_ON((unsigned)n > 0xFF);
11625 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
11626 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
11627 /*
11628 * This routine sets up an interrupt gate at directory privilege level 3.
11629 */
11630 -static inline void set_system_intr_gate(unsigned int n, void *addr)
11631 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
11632 {
11633 BUG_ON((unsigned)n > 0xFF);
11634 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
11635 }
11636
11637 -static inline void set_system_trap_gate(unsigned int n, void *addr)
11638 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
11639 {
11640 BUG_ON((unsigned)n > 0xFF);
11641 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
11642 }
11643
11644 -static inline void set_trap_gate(unsigned int n, void *addr)
11645 +static inline void set_trap_gate(unsigned int n, const void *addr)
11646 {
11647 BUG_ON((unsigned)n > 0xFF);
11648 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
11649 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
11650 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
11651 {
11652 BUG_ON((unsigned)n > 0xFF);
11653 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
11654 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
11655 }
11656
11657 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
11658 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
11659 {
11660 BUG_ON((unsigned)n > 0xFF);
11661 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
11662 }
11663
11664 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
11665 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
11666 {
11667 BUG_ON((unsigned)n > 0xFF);
11668 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
11669 }
11670
11671 +#ifdef CONFIG_X86_32
11672 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
11673 +{
11674 + struct desc_struct d;
11675 +
11676 + if (likely(limit))
11677 + limit = (limit - 1UL) >> PAGE_SHIFT;
11678 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
11679 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
11680 +}
11681 +#endif
11682 +
11683 #endif /* _ASM_X86_DESC_H */
11684 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
11685 index 278441f..b95a174 100644
11686 --- a/arch/x86/include/asm/desc_defs.h
11687 +++ b/arch/x86/include/asm/desc_defs.h
11688 @@ -31,6 +31,12 @@ struct desc_struct {
11689 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
11690 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
11691 };
11692 + struct {
11693 + u16 offset_low;
11694 + u16 seg;
11695 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
11696 + unsigned offset_high: 16;
11697 + } gate;
11698 };
11699 } __attribute__((packed));
11700
11701 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
11702 index 3778256..c5d4fce 100644
11703 --- a/arch/x86/include/asm/e820.h
11704 +++ b/arch/x86/include/asm/e820.h
11705 @@ -69,7 +69,7 @@ struct e820map {
11706 #define ISA_START_ADDRESS 0xa0000
11707 #define ISA_END_ADDRESS 0x100000
11708
11709 -#define BIOS_BEGIN 0x000a0000
11710 +#define BIOS_BEGIN 0x000c0000
11711 #define BIOS_END 0x00100000
11712
11713 #define BIOS_ROM_BASE 0xffe00000
11714 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
11715 index 5939f44..f8845f6 100644
11716 --- a/arch/x86/include/asm/elf.h
11717 +++ b/arch/x86/include/asm/elf.h
11718 @@ -243,7 +243,25 @@ extern int force_personality32;
11719 the loader. We need to make sure that it is out of the way of the program
11720 that it will "exec", and that there is sufficient room for the brk. */
11721
11722 +#ifdef CONFIG_PAX_SEGMEXEC
11723 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
11724 +#else
11725 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
11726 +#endif
11727 +
11728 +#ifdef CONFIG_PAX_ASLR
11729 +#ifdef CONFIG_X86_32
11730 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
11731 +
11732 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11733 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11734 +#else
11735 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
11736 +
11737 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11738 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11739 +#endif
11740 +#endif
11741
11742 /* This yields a mask that user programs can use to figure out what
11743 instruction set this CPU supports. This could be done in user space,
11744 @@ -296,16 +314,12 @@ do { \
11745
11746 #define ARCH_DLINFO \
11747 do { \
11748 - if (vdso_enabled) \
11749 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11750 - (unsigned long)current->mm->context.vdso); \
11751 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11752 } while (0)
11753
11754 #define ARCH_DLINFO_X32 \
11755 do { \
11756 - if (vdso_enabled) \
11757 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11758 - (unsigned long)current->mm->context.vdso); \
11759 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11760 } while (0)
11761
11762 #define AT_SYSINFO 32
11763 @@ -320,7 +334,7 @@ else \
11764
11765 #endif /* !CONFIG_X86_32 */
11766
11767 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
11768 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
11769
11770 #define VDSO_ENTRY \
11771 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
11772 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
11773 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
11774 #define compat_arch_setup_additional_pages syscall32_setup_pages
11775
11776 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
11777 -#define arch_randomize_brk arch_randomize_brk
11778 -
11779 /*
11780 * True on X86_32 or when emulating IA32 on X86_64
11781 */
11782 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
11783 index 75ce3f4..882e801 100644
11784 --- a/arch/x86/include/asm/emergency-restart.h
11785 +++ b/arch/x86/include/asm/emergency-restart.h
11786 @@ -13,6 +13,6 @@ enum reboot_type {
11787
11788 extern enum reboot_type reboot_type;
11789
11790 -extern void machine_emergency_restart(void);
11791 +extern void machine_emergency_restart(void) __noreturn;
11792
11793 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
11794 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
11795 index 41ab26e..a88c9e6 100644
11796 --- a/arch/x86/include/asm/fpu-internal.h
11797 +++ b/arch/x86/include/asm/fpu-internal.h
11798 @@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
11799 ({ \
11800 int err; \
11801 asm volatile(ASM_STAC "\n" \
11802 - "1:" #insn "\n\t" \
11803 + "1:" \
11804 + __copyuser_seg \
11805 + #insn "\n\t" \
11806 "2: " ASM_CLAC "\n" \
11807 ".section .fixup,\"ax\"\n" \
11808 "3: movl $-1,%[err]\n" \
11809 @@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
11810 "emms\n\t" /* clear stack tags */
11811 "fildl %P[addr]", /* set F?P to defined value */
11812 X86_FEATURE_FXSAVE_LEAK,
11813 - [addr] "m" (tsk->thread.fpu.has_fpu));
11814 + [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
11815
11816 return fpu_restore_checking(&tsk->thread.fpu);
11817 }
11818 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
11819 index f373046..02653e2 100644
11820 --- a/arch/x86/include/asm/futex.h
11821 +++ b/arch/x86/include/asm/futex.h
11822 @@ -12,6 +12,7 @@
11823 #include <asm/smap.h>
11824
11825 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
11826 + typecheck(u32 __user *, uaddr); \
11827 asm volatile("\t" ASM_STAC "\n" \
11828 "1:\t" insn "\n" \
11829 "2:\t" ASM_CLAC "\n" \
11830 @@ -20,15 +21,16 @@
11831 "\tjmp\t2b\n" \
11832 "\t.previous\n" \
11833 _ASM_EXTABLE(1b, 3b) \
11834 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
11835 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
11836 : "i" (-EFAULT), "0" (oparg), "1" (0))
11837
11838 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
11839 + typecheck(u32 __user *, uaddr); \
11840 asm volatile("\t" ASM_STAC "\n" \
11841 "1:\tmovl %2, %0\n" \
11842 "\tmovl\t%0, %3\n" \
11843 "\t" insn "\n" \
11844 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
11845 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
11846 "\tjnz\t1b\n" \
11847 "3:\t" ASM_CLAC "\n" \
11848 "\t.section .fixup,\"ax\"\n" \
11849 @@ -38,7 +40,7 @@
11850 _ASM_EXTABLE(1b, 4b) \
11851 _ASM_EXTABLE(2b, 4b) \
11852 : "=&a" (oldval), "=&r" (ret), \
11853 - "+m" (*uaddr), "=&r" (tem) \
11854 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
11855 : "r" (oparg), "i" (-EFAULT), "1" (0))
11856
11857 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11858 @@ -65,10 +67,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11859
11860 switch (op) {
11861 case FUTEX_OP_SET:
11862 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
11863 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
11864 break;
11865 case FUTEX_OP_ADD:
11866 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
11867 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
11868 uaddr, oparg);
11869 break;
11870 case FUTEX_OP_OR:
11871 @@ -128,14 +130,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
11872 return -EFAULT;
11873
11874 asm volatile("\t" ASM_STAC "\n"
11875 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
11876 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
11877 "2:\t" ASM_CLAC "\n"
11878 "\t.section .fixup, \"ax\"\n"
11879 "3:\tmov %3, %0\n"
11880 "\tjmp 2b\n"
11881 "\t.previous\n"
11882 _ASM_EXTABLE(1b, 3b)
11883 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
11884 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
11885 : "i" (-EFAULT), "r" (newval), "1" (oldval)
11886 : "memory"
11887 );
11888 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
11889 index eb92a6e..b98b2f4 100644
11890 --- a/arch/x86/include/asm/hw_irq.h
11891 +++ b/arch/x86/include/asm/hw_irq.h
11892 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
11893 extern void enable_IO_APIC(void);
11894
11895 /* Statistics */
11896 -extern atomic_t irq_err_count;
11897 -extern atomic_t irq_mis_count;
11898 +extern atomic_unchecked_t irq_err_count;
11899 +extern atomic_unchecked_t irq_mis_count;
11900
11901 /* EISA */
11902 extern void eisa_set_level_irq(unsigned int irq);
11903 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
11904 index d8e8eef..15b1179 100644
11905 --- a/arch/x86/include/asm/io.h
11906 +++ b/arch/x86/include/asm/io.h
11907 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
11908 return ioremap_nocache(offset, size);
11909 }
11910
11911 -extern void iounmap(volatile void __iomem *addr);
11912 +extern void iounmap(const volatile void __iomem *addr);
11913
11914 extern void set_iounmap_nonlazy(void);
11915
11916 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
11917
11918 #include <linux/vmalloc.h>
11919
11920 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
11921 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
11922 +{
11923 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11924 +}
11925 +
11926 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
11927 +{
11928 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11929 +}
11930 +
11931 /*
11932 * Convert a virtual cached pointer to an uncached pointer
11933 */
11934 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
11935 index bba3cf8..06bc8da 100644
11936 --- a/arch/x86/include/asm/irqflags.h
11937 +++ b/arch/x86/include/asm/irqflags.h
11938 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
11939 sti; \
11940 sysexit
11941
11942 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
11943 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
11944 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
11945 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
11946 +
11947 #else
11948 #define INTERRUPT_RETURN iret
11949 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
11950 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
11951 index d3ddd17..c9fb0cc 100644
11952 --- a/arch/x86/include/asm/kprobes.h
11953 +++ b/arch/x86/include/asm/kprobes.h
11954 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
11955 #define RELATIVEJUMP_SIZE 5
11956 #define RELATIVECALL_OPCODE 0xe8
11957 #define RELATIVE_ADDR_SIZE 4
11958 -#define MAX_STACK_SIZE 64
11959 -#define MIN_STACK_SIZE(ADDR) \
11960 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
11961 - THREAD_SIZE - (unsigned long)(ADDR))) \
11962 - ? (MAX_STACK_SIZE) \
11963 - : (((unsigned long)current_thread_info()) + \
11964 - THREAD_SIZE - (unsigned long)(ADDR)))
11965 +#define MAX_STACK_SIZE 64UL
11966 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
11967
11968 #define flush_insn_slot(p) do { } while (0)
11969
11970 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
11971 index b2e11f4..f293e2e 100644
11972 --- a/arch/x86/include/asm/kvm_host.h
11973 +++ b/arch/x86/include/asm/kvm_host.h
11974 @@ -707,7 +707,7 @@ struct kvm_x86_ops {
11975 int (*check_intercept)(struct kvm_vcpu *vcpu,
11976 struct x86_instruction_info *info,
11977 enum x86_intercept_stage stage);
11978 -};
11979 +} __do_const;
11980
11981 struct kvm_arch_async_pf {
11982 u32 token;
11983 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
11984 index c8bed0d..85c03fd 100644
11985 --- a/arch/x86/include/asm/local.h
11986 +++ b/arch/x86/include/asm/local.h
11987 @@ -10,33 +10,97 @@ typedef struct {
11988 atomic_long_t a;
11989 } local_t;
11990
11991 +typedef struct {
11992 + atomic_long_unchecked_t a;
11993 +} local_unchecked_t;
11994 +
11995 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
11996
11997 #define local_read(l) atomic_long_read(&(l)->a)
11998 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
11999 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
12000 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
12001
12002 static inline void local_inc(local_t *l)
12003 {
12004 - asm volatile(_ASM_INC "%0"
12005 + asm volatile(_ASM_INC "%0\n"
12006 +
12007 +#ifdef CONFIG_PAX_REFCOUNT
12008 + "jno 0f\n"
12009 + _ASM_DEC "%0\n"
12010 + "int $4\n0:\n"
12011 + _ASM_EXTABLE(0b, 0b)
12012 +#endif
12013 +
12014 + : "+m" (l->a.counter));
12015 +}
12016 +
12017 +static inline void local_inc_unchecked(local_unchecked_t *l)
12018 +{
12019 + asm volatile(_ASM_INC "%0\n"
12020 : "+m" (l->a.counter));
12021 }
12022
12023 static inline void local_dec(local_t *l)
12024 {
12025 - asm volatile(_ASM_DEC "%0"
12026 + asm volatile(_ASM_DEC "%0\n"
12027 +
12028 +#ifdef CONFIG_PAX_REFCOUNT
12029 + "jno 0f\n"
12030 + _ASM_INC "%0\n"
12031 + "int $4\n0:\n"
12032 + _ASM_EXTABLE(0b, 0b)
12033 +#endif
12034 +
12035 + : "+m" (l->a.counter));
12036 +}
12037 +
12038 +static inline void local_dec_unchecked(local_unchecked_t *l)
12039 +{
12040 + asm volatile(_ASM_DEC "%0\n"
12041 : "+m" (l->a.counter));
12042 }
12043
12044 static inline void local_add(long i, local_t *l)
12045 {
12046 - asm volatile(_ASM_ADD "%1,%0"
12047 + asm volatile(_ASM_ADD "%1,%0\n"
12048 +
12049 +#ifdef CONFIG_PAX_REFCOUNT
12050 + "jno 0f\n"
12051 + _ASM_SUB "%1,%0\n"
12052 + "int $4\n0:\n"
12053 + _ASM_EXTABLE(0b, 0b)
12054 +#endif
12055 +
12056 + : "+m" (l->a.counter)
12057 + : "ir" (i));
12058 +}
12059 +
12060 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
12061 +{
12062 + asm volatile(_ASM_ADD "%1,%0\n"
12063 : "+m" (l->a.counter)
12064 : "ir" (i));
12065 }
12066
12067 static inline void local_sub(long i, local_t *l)
12068 {
12069 - asm volatile(_ASM_SUB "%1,%0"
12070 + asm volatile(_ASM_SUB "%1,%0\n"
12071 +
12072 +#ifdef CONFIG_PAX_REFCOUNT
12073 + "jno 0f\n"
12074 + _ASM_ADD "%1,%0\n"
12075 + "int $4\n0:\n"
12076 + _ASM_EXTABLE(0b, 0b)
12077 +#endif
12078 +
12079 + : "+m" (l->a.counter)
12080 + : "ir" (i));
12081 +}
12082 +
12083 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
12084 +{
12085 + asm volatile(_ASM_SUB "%1,%0\n"
12086 : "+m" (l->a.counter)
12087 : "ir" (i));
12088 }
12089 @@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
12090 {
12091 unsigned char c;
12092
12093 - asm volatile(_ASM_SUB "%2,%0; sete %1"
12094 + asm volatile(_ASM_SUB "%2,%0\n"
12095 +
12096 +#ifdef CONFIG_PAX_REFCOUNT
12097 + "jno 0f\n"
12098 + _ASM_ADD "%2,%0\n"
12099 + "int $4\n0:\n"
12100 + _ASM_EXTABLE(0b, 0b)
12101 +#endif
12102 +
12103 + "sete %1\n"
12104 : "+m" (l->a.counter), "=qm" (c)
12105 : "ir" (i) : "memory");
12106 return c;
12107 @@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
12108 {
12109 unsigned char c;
12110
12111 - asm volatile(_ASM_DEC "%0; sete %1"
12112 + asm volatile(_ASM_DEC "%0\n"
12113 +
12114 +#ifdef CONFIG_PAX_REFCOUNT
12115 + "jno 0f\n"
12116 + _ASM_INC "%0\n"
12117 + "int $4\n0:\n"
12118 + _ASM_EXTABLE(0b, 0b)
12119 +#endif
12120 +
12121 + "sete %1\n"
12122 : "+m" (l->a.counter), "=qm" (c)
12123 : : "memory");
12124 return c != 0;
12125 @@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
12126 {
12127 unsigned char c;
12128
12129 - asm volatile(_ASM_INC "%0; sete %1"
12130 + asm volatile(_ASM_INC "%0\n"
12131 +
12132 +#ifdef CONFIG_PAX_REFCOUNT
12133 + "jno 0f\n"
12134 + _ASM_DEC "%0\n"
12135 + "int $4\n0:\n"
12136 + _ASM_EXTABLE(0b, 0b)
12137 +#endif
12138 +
12139 + "sete %1\n"
12140 : "+m" (l->a.counter), "=qm" (c)
12141 : : "memory");
12142 return c != 0;
12143 @@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
12144 {
12145 unsigned char c;
12146
12147 - asm volatile(_ASM_ADD "%2,%0; sets %1"
12148 + asm volatile(_ASM_ADD "%2,%0\n"
12149 +
12150 +#ifdef CONFIG_PAX_REFCOUNT
12151 + "jno 0f\n"
12152 + _ASM_SUB "%2,%0\n"
12153 + "int $4\n0:\n"
12154 + _ASM_EXTABLE(0b, 0b)
12155 +#endif
12156 +
12157 + "sets %1\n"
12158 : "+m" (l->a.counter), "=qm" (c)
12159 : "ir" (i) : "memory");
12160 return c;
12161 @@ -132,7 +232,15 @@ static inline long local_add_return(long i, local_t *l)
12162 #endif
12163 /* Modern 486+ processor */
12164 __i = i;
12165 - asm volatile(_ASM_XADD "%0, %1;"
12166 + asm volatile(_ASM_XADD "%0, %1\n"
12167 +
12168 +#ifdef CONFIG_PAX_REFCOUNT
12169 + "jno 0f\n"
12170 + _ASM_MOV "%0,%1\n"
12171 + "int $4\n0:\n"
12172 + _ASM_EXTABLE(0b, 0b)
12173 +#endif
12174 +
12175 : "+r" (i), "+m" (l->a.counter)
12176 : : "memory");
12177 return i + __i;
12178 @@ -147,6 +255,38 @@ no_xadd: /* Legacy 386 processor */
12179 #endif
12180 }
12181
12182 +/**
12183 + * local_add_return_unchecked - add and return
12184 + * @i: integer value to add
12185 + * @l: pointer to type local_unchecked_t
12186 + *
12187 + * Atomically adds @i to @l and returns @i + @l
12188 + */
12189 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
12190 +{
12191 + long __i;
12192 +#ifdef CONFIG_M386
12193 + unsigned long flags;
12194 + if (unlikely(boot_cpu_data.x86 <= 3))
12195 + goto no_xadd;
12196 +#endif
12197 + /* Modern 486+ processor */
12198 + __i = i;
12199 + asm volatile(_ASM_XADD "%0, %1\n"
12200 + : "+r" (i), "+m" (l->a.counter)
12201 + : : "memory");
12202 + return i + __i;
12203 +
12204 +#ifdef CONFIG_M386
12205 +no_xadd: /* Legacy 386 processor */
12206 + local_irq_save(flags);
12207 + __i = local_read_unchecked(l);
12208 + local_set_unchecked(l, i + __i);
12209 + local_irq_restore(flags);
12210 + return i + __i;
12211 +#endif
12212 +}
12213 +
12214 static inline long local_sub_return(long i, local_t *l)
12215 {
12216 return local_add_return(-i, l);
12217 @@ -157,6 +297,8 @@ static inline long local_sub_return(long i, local_t *l)
12218
12219 #define local_cmpxchg(l, o, n) \
12220 (cmpxchg_local(&((l)->a.counter), (o), (n)))
12221 +#define local_cmpxchg_unchecked(l, o, n) \
12222 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
12223 /* Always has a lock prefix */
12224 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
12225
12226 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
12227 index 593e51d..fa69c9a 100644
12228 --- a/arch/x86/include/asm/mman.h
12229 +++ b/arch/x86/include/asm/mman.h
12230 @@ -5,4 +5,14 @@
12231
12232 #include <asm-generic/mman.h>
12233
12234 +#ifdef __KERNEL__
12235 +#ifndef __ASSEMBLY__
12236 +#ifdef CONFIG_X86_32
12237 +#define arch_mmap_check i386_mmap_check
12238 +int i386_mmap_check(unsigned long addr, unsigned long len,
12239 + unsigned long flags);
12240 +#endif
12241 +#endif
12242 +#endif
12243 +
12244 #endif /* _ASM_X86_MMAN_H */
12245 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
12246 index 5f55e69..e20bfb1 100644
12247 --- a/arch/x86/include/asm/mmu.h
12248 +++ b/arch/x86/include/asm/mmu.h
12249 @@ -9,7 +9,7 @@
12250 * we put the segment information here.
12251 */
12252 typedef struct {
12253 - void *ldt;
12254 + struct desc_struct *ldt;
12255 int size;
12256
12257 #ifdef CONFIG_X86_64
12258 @@ -18,7 +18,19 @@ typedef struct {
12259 #endif
12260
12261 struct mutex lock;
12262 - void *vdso;
12263 + unsigned long vdso;
12264 +
12265 +#ifdef CONFIG_X86_32
12266 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
12267 + unsigned long user_cs_base;
12268 + unsigned long user_cs_limit;
12269 +
12270 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
12271 + cpumask_t cpu_user_cs_mask;
12272 +#endif
12273 +
12274 +#endif
12275 +#endif
12276 } mm_context_t;
12277
12278 #ifdef CONFIG_SMP
12279 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
12280 index cdbf367..adb37ac 100644
12281 --- a/arch/x86/include/asm/mmu_context.h
12282 +++ b/arch/x86/include/asm/mmu_context.h
12283 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
12284
12285 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
12286 {
12287 +
12288 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12289 + unsigned int i;
12290 + pgd_t *pgd;
12291 +
12292 + pax_open_kernel();
12293 + pgd = get_cpu_pgd(smp_processor_id());
12294 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
12295 + set_pgd_batched(pgd+i, native_make_pgd(0));
12296 + pax_close_kernel();
12297 +#endif
12298 +
12299 #ifdef CONFIG_SMP
12300 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
12301 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
12302 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12303 struct task_struct *tsk)
12304 {
12305 unsigned cpu = smp_processor_id();
12306 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12307 + int tlbstate = TLBSTATE_OK;
12308 +#endif
12309
12310 if (likely(prev != next)) {
12311 #ifdef CONFIG_SMP
12312 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12313 + tlbstate = this_cpu_read(cpu_tlbstate.state);
12314 +#endif
12315 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12316 this_cpu_write(cpu_tlbstate.active_mm, next);
12317 #endif
12318 cpumask_set_cpu(cpu, mm_cpumask(next));
12319
12320 /* Re-load page tables */
12321 +#ifdef CONFIG_PAX_PER_CPU_PGD
12322 + pax_open_kernel();
12323 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12324 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12325 + pax_close_kernel();
12326 + load_cr3(get_cpu_pgd(cpu));
12327 +#else
12328 load_cr3(next->pgd);
12329 +#endif
12330
12331 /* stop flush ipis for the previous mm */
12332 cpumask_clear_cpu(cpu, mm_cpumask(prev));
12333 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12334 */
12335 if (unlikely(prev->context.ldt != next->context.ldt))
12336 load_LDT_nolock(&next->context);
12337 - }
12338 +
12339 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
12340 + if (!(__supported_pte_mask & _PAGE_NX)) {
12341 + smp_mb__before_clear_bit();
12342 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
12343 + smp_mb__after_clear_bit();
12344 + cpu_set(cpu, next->context.cpu_user_cs_mask);
12345 + }
12346 +#endif
12347 +
12348 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12349 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
12350 + prev->context.user_cs_limit != next->context.user_cs_limit))
12351 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12352 #ifdef CONFIG_SMP
12353 + else if (unlikely(tlbstate != TLBSTATE_OK))
12354 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12355 +#endif
12356 +#endif
12357 +
12358 + }
12359 else {
12360 +
12361 +#ifdef CONFIG_PAX_PER_CPU_PGD
12362 + pax_open_kernel();
12363 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12364 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12365 + pax_close_kernel();
12366 + load_cr3(get_cpu_pgd(cpu));
12367 +#endif
12368 +
12369 +#ifdef CONFIG_SMP
12370 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12371 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
12372
12373 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12374 * tlb flush IPI delivery. We must reload CR3
12375 * to make sure to use no freed page tables.
12376 */
12377 +
12378 +#ifndef CONFIG_PAX_PER_CPU_PGD
12379 load_cr3(next->pgd);
12380 +#endif
12381 +
12382 load_LDT_nolock(&next->context);
12383 +
12384 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
12385 + if (!(__supported_pte_mask & _PAGE_NX))
12386 + cpu_set(cpu, next->context.cpu_user_cs_mask);
12387 +#endif
12388 +
12389 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12390 +#ifdef CONFIG_PAX_PAGEEXEC
12391 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
12392 +#endif
12393 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12394 +#endif
12395 +
12396 }
12397 +#endif
12398 }
12399 -#endif
12400 }
12401
12402 #define activate_mm(prev, next) \
12403 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
12404 index 9eae775..c914fea 100644
12405 --- a/arch/x86/include/asm/module.h
12406 +++ b/arch/x86/include/asm/module.h
12407 @@ -5,6 +5,7 @@
12408
12409 #ifdef CONFIG_X86_64
12410 /* X86_64 does not define MODULE_PROC_FAMILY */
12411 +#define MODULE_PROC_FAMILY ""
12412 #elif defined CONFIG_M386
12413 #define MODULE_PROC_FAMILY "386 "
12414 #elif defined CONFIG_M486
12415 @@ -59,8 +60,20 @@
12416 #error unknown processor family
12417 #endif
12418
12419 -#ifdef CONFIG_X86_32
12420 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
12421 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
12422 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
12423 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
12424 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
12425 +#else
12426 +#define MODULE_PAX_KERNEXEC ""
12427 #endif
12428
12429 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12430 +#define MODULE_PAX_UDEREF "UDEREF "
12431 +#else
12432 +#define MODULE_PAX_UDEREF ""
12433 +#endif
12434 +
12435 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
12436 +
12437 #endif /* _ASM_X86_MODULE_H */
12438 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
12439 index 320f7bb..e89f8f8 100644
12440 --- a/arch/x86/include/asm/page_64_types.h
12441 +++ b/arch/x86/include/asm/page_64_types.h
12442 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
12443
12444 /* duplicated to the one in bootmem.h */
12445 extern unsigned long max_pfn;
12446 -extern unsigned long phys_base;
12447 +extern const unsigned long phys_base;
12448
12449 extern unsigned long __phys_addr(unsigned long);
12450 #define __phys_reloc_hide(x) (x)
12451 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
12452 index a0facf3..c017b15 100644
12453 --- a/arch/x86/include/asm/paravirt.h
12454 +++ b/arch/x86/include/asm/paravirt.h
12455 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
12456 val);
12457 }
12458
12459 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12460 +{
12461 + pgdval_t val = native_pgd_val(pgd);
12462 +
12463 + if (sizeof(pgdval_t) > sizeof(long))
12464 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
12465 + val, (u64)val >> 32);
12466 + else
12467 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
12468 + val);
12469 +}
12470 +
12471 static inline void pgd_clear(pgd_t *pgdp)
12472 {
12473 set_pgd(pgdp, __pgd(0));
12474 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
12475 pv_mmu_ops.set_fixmap(idx, phys, flags);
12476 }
12477
12478 +#ifdef CONFIG_PAX_KERNEXEC
12479 +static inline unsigned long pax_open_kernel(void)
12480 +{
12481 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
12482 +}
12483 +
12484 +static inline unsigned long pax_close_kernel(void)
12485 +{
12486 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
12487 +}
12488 +#else
12489 +static inline unsigned long pax_open_kernel(void) { return 0; }
12490 +static inline unsigned long pax_close_kernel(void) { return 0; }
12491 +#endif
12492 +
12493 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
12494
12495 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
12496 @@ -929,7 +956,7 @@ extern void default_banner(void);
12497
12498 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
12499 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
12500 -#define PARA_INDIRECT(addr) *%cs:addr
12501 +#define PARA_INDIRECT(addr) *%ss:addr
12502 #endif
12503
12504 #define INTERRUPT_RETURN \
12505 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
12506 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
12507 CLBR_NONE, \
12508 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
12509 +
12510 +#define GET_CR0_INTO_RDI \
12511 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
12512 + mov %rax,%rdi
12513 +
12514 +#define SET_RDI_INTO_CR0 \
12515 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
12516 +
12517 +#define GET_CR3_INTO_RDI \
12518 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
12519 + mov %rax,%rdi
12520 +
12521 +#define SET_RDI_INTO_CR3 \
12522 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
12523 +
12524 #endif /* CONFIG_X86_32 */
12525
12526 #endif /* __ASSEMBLY__ */
12527 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
12528 index 142236e..57cf5ea 100644
12529 --- a/arch/x86/include/asm/paravirt_types.h
12530 +++ b/arch/x86/include/asm/paravirt_types.h
12531 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
12532 struct paravirt_callee_save make_pud;
12533
12534 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
12535 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
12536 #endif /* PAGETABLE_LEVELS == 4 */
12537 #endif /* PAGETABLE_LEVELS >= 3 */
12538
12539 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
12540 an mfn. We can tell which is which from the index. */
12541 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
12542 phys_addr_t phys, pgprot_t flags);
12543 +
12544 +#ifdef CONFIG_PAX_KERNEXEC
12545 + unsigned long (*pax_open_kernel)(void);
12546 + unsigned long (*pax_close_kernel)(void);
12547 +#endif
12548 +
12549 };
12550
12551 struct arch_spinlock;
12552 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
12553 index b4389a4..7024269 100644
12554 --- a/arch/x86/include/asm/pgalloc.h
12555 +++ b/arch/x86/include/asm/pgalloc.h
12556 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
12557 pmd_t *pmd, pte_t *pte)
12558 {
12559 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12560 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
12561 +}
12562 +
12563 +static inline void pmd_populate_user(struct mm_struct *mm,
12564 + pmd_t *pmd, pte_t *pte)
12565 +{
12566 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12567 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
12568 }
12569
12570 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
12571
12572 #ifdef CONFIG_X86_PAE
12573 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
12574 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
12575 +{
12576 + pud_populate(mm, pudp, pmd);
12577 +}
12578 #else /* !CONFIG_X86_PAE */
12579 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12580 {
12581 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12582 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
12583 }
12584 +
12585 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12586 +{
12587 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12588 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
12589 +}
12590 #endif /* CONFIG_X86_PAE */
12591
12592 #if PAGETABLE_LEVELS > 3
12593 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12594 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
12595 }
12596
12597 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12598 +{
12599 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
12600 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
12601 +}
12602 +
12603 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
12604 {
12605 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
12606 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
12607 index f2b489c..4f7e2e5 100644
12608 --- a/arch/x86/include/asm/pgtable-2level.h
12609 +++ b/arch/x86/include/asm/pgtable-2level.h
12610 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
12611
12612 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12613 {
12614 + pax_open_kernel();
12615 *pmdp = pmd;
12616 + pax_close_kernel();
12617 }
12618
12619 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12620 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
12621 index 4cc9f2b..5fd9226 100644
12622 --- a/arch/x86/include/asm/pgtable-3level.h
12623 +++ b/arch/x86/include/asm/pgtable-3level.h
12624 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12625
12626 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12627 {
12628 + pax_open_kernel();
12629 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
12630 + pax_close_kernel();
12631 }
12632
12633 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12634 {
12635 + pax_open_kernel();
12636 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
12637 + pax_close_kernel();
12638 }
12639
12640 /*
12641 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
12642 index a1f780d..9f6c8dd 100644
12643 --- a/arch/x86/include/asm/pgtable.h
12644 +++ b/arch/x86/include/asm/pgtable.h
12645 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12646
12647 #ifndef __PAGETABLE_PUD_FOLDED
12648 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
12649 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
12650 #define pgd_clear(pgd) native_pgd_clear(pgd)
12651 #endif
12652
12653 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12654
12655 #define arch_end_context_switch(prev) do {} while(0)
12656
12657 +#define pax_open_kernel() native_pax_open_kernel()
12658 +#define pax_close_kernel() native_pax_close_kernel()
12659 #endif /* CONFIG_PARAVIRT */
12660
12661 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
12662 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
12663 +
12664 +#ifdef CONFIG_PAX_KERNEXEC
12665 +static inline unsigned long native_pax_open_kernel(void)
12666 +{
12667 + unsigned long cr0;
12668 +
12669 + preempt_disable();
12670 + barrier();
12671 + cr0 = read_cr0() ^ X86_CR0_WP;
12672 + BUG_ON(cr0 & X86_CR0_WP);
12673 + write_cr0(cr0);
12674 + return cr0 ^ X86_CR0_WP;
12675 +}
12676 +
12677 +static inline unsigned long native_pax_close_kernel(void)
12678 +{
12679 + unsigned long cr0;
12680 +
12681 + cr0 = read_cr0() ^ X86_CR0_WP;
12682 + BUG_ON(!(cr0 & X86_CR0_WP));
12683 + write_cr0(cr0);
12684 + barrier();
12685 + preempt_enable_no_resched();
12686 + return cr0 ^ X86_CR0_WP;
12687 +}
12688 +#else
12689 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
12690 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
12691 +#endif
12692 +
12693 /*
12694 * The following only work if pte_present() is true.
12695 * Undefined behaviour if not..
12696 */
12697 +static inline int pte_user(pte_t pte)
12698 +{
12699 + return pte_val(pte) & _PAGE_USER;
12700 +}
12701 +
12702 static inline int pte_dirty(pte_t pte)
12703 {
12704 return pte_flags(pte) & _PAGE_DIRTY;
12705 @@ -142,6 +182,11 @@ static inline unsigned long pmd_pfn(pmd_t pmd)
12706 return (pmd_val(pmd) & PTE_PFN_MASK) >> PAGE_SHIFT;
12707 }
12708
12709 +static inline unsigned long pud_pfn(pud_t pud)
12710 +{
12711 + return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
12712 +}
12713 +
12714 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
12715
12716 static inline int pmd_large(pmd_t pte)
12717 @@ -195,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
12718 return pte_clear_flags(pte, _PAGE_RW);
12719 }
12720
12721 +static inline pte_t pte_mkread(pte_t pte)
12722 +{
12723 + return __pte(pte_val(pte) | _PAGE_USER);
12724 +}
12725 +
12726 static inline pte_t pte_mkexec(pte_t pte)
12727 {
12728 - return pte_clear_flags(pte, _PAGE_NX);
12729 +#ifdef CONFIG_X86_PAE
12730 + if (__supported_pte_mask & _PAGE_NX)
12731 + return pte_clear_flags(pte, _PAGE_NX);
12732 + else
12733 +#endif
12734 + return pte_set_flags(pte, _PAGE_USER);
12735 +}
12736 +
12737 +static inline pte_t pte_exprotect(pte_t pte)
12738 +{
12739 +#ifdef CONFIG_X86_PAE
12740 + if (__supported_pte_mask & _PAGE_NX)
12741 + return pte_set_flags(pte, _PAGE_NX);
12742 + else
12743 +#endif
12744 + return pte_clear_flags(pte, _PAGE_USER);
12745 }
12746
12747 static inline pte_t pte_mkdirty(pte_t pte)
12748 @@ -389,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
12749 #endif
12750
12751 #ifndef __ASSEMBLY__
12752 +
12753 +#ifdef CONFIG_PAX_PER_CPU_PGD
12754 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
12755 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
12756 +{
12757 + return cpu_pgd[cpu];
12758 +}
12759 +#endif
12760 +
12761 #include <linux/mm_types.h>
12762
12763 static inline int pte_none(pte_t pte)
12764 @@ -565,7 +639,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
12765
12766 static inline int pgd_bad(pgd_t pgd)
12767 {
12768 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
12769 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
12770 }
12771
12772 static inline int pgd_none(pgd_t pgd)
12773 @@ -588,7 +662,12 @@ static inline int pgd_none(pgd_t pgd)
12774 * pgd_offset() returns a (pgd_t *)
12775 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
12776 */
12777 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
12778 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
12779 +
12780 +#ifdef CONFIG_PAX_PER_CPU_PGD
12781 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
12782 +#endif
12783 +
12784 /*
12785 * a shortcut which implies the use of the kernel's pgd, instead
12786 * of a process's
12787 @@ -599,6 +678,20 @@ static inline int pgd_none(pgd_t pgd)
12788 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
12789 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
12790
12791 +#ifdef CONFIG_X86_32
12792 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
12793 +#else
12794 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
12795 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
12796 +
12797 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12798 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
12799 +#else
12800 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
12801 +#endif
12802 +
12803 +#endif
12804 +
12805 #ifndef __ASSEMBLY__
12806
12807 extern int direct_gbpages;
12808 @@ -763,11 +856,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
12809 * dst and src can be on the same page, but the range must not overlap,
12810 * and must not cross a page boundary.
12811 */
12812 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
12813 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
12814 {
12815 - memcpy(dst, src, count * sizeof(pgd_t));
12816 + pax_open_kernel();
12817 + while (count--)
12818 + *dst++ = *src++;
12819 + pax_close_kernel();
12820 }
12821
12822 +#ifdef CONFIG_PAX_PER_CPU_PGD
12823 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
12824 +#endif
12825 +
12826 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12827 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
12828 +#else
12829 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
12830 +#endif
12831
12832 #include <asm-generic/pgtable.h>
12833 #endif /* __ASSEMBLY__ */
12834 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
12835 index 8faa215..a8a17ea 100644
12836 --- a/arch/x86/include/asm/pgtable_32.h
12837 +++ b/arch/x86/include/asm/pgtable_32.h
12838 @@ -25,9 +25,6 @@
12839 struct mm_struct;
12840 struct vm_area_struct;
12841
12842 -extern pgd_t swapper_pg_dir[1024];
12843 -extern pgd_t initial_page_table[1024];
12844 -
12845 static inline void pgtable_cache_init(void) { }
12846 static inline void check_pgt_cache(void) { }
12847 void paging_init(void);
12848 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12849 # include <asm/pgtable-2level.h>
12850 #endif
12851
12852 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
12853 +extern pgd_t initial_page_table[PTRS_PER_PGD];
12854 +#ifdef CONFIG_X86_PAE
12855 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
12856 +#endif
12857 +
12858 #if defined(CONFIG_HIGHPTE)
12859 #define pte_offset_map(dir, address) \
12860 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
12861 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12862 /* Clear a kernel PTE and flush it from the TLB */
12863 #define kpte_clear_flush(ptep, vaddr) \
12864 do { \
12865 + pax_open_kernel(); \
12866 pte_clear(&init_mm, (vaddr), (ptep)); \
12867 + pax_close_kernel(); \
12868 __flush_tlb_one((vaddr)); \
12869 } while (0)
12870
12871 @@ -75,6 +80,9 @@ do { \
12872
12873 #endif /* !__ASSEMBLY__ */
12874
12875 +#define HAVE_ARCH_UNMAPPED_AREA
12876 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
12877 +
12878 /*
12879 * kern_addr_valid() is (1) for FLATMEM and (0) for
12880 * SPARSEMEM and DISCONTIGMEM
12881 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
12882 index ed5903b..c7fe163 100644
12883 --- a/arch/x86/include/asm/pgtable_32_types.h
12884 +++ b/arch/x86/include/asm/pgtable_32_types.h
12885 @@ -8,7 +8,7 @@
12886 */
12887 #ifdef CONFIG_X86_PAE
12888 # include <asm/pgtable-3level_types.h>
12889 -# define PMD_SIZE (1UL << PMD_SHIFT)
12890 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
12891 # define PMD_MASK (~(PMD_SIZE - 1))
12892 #else
12893 # include <asm/pgtable-2level_types.h>
12894 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
12895 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
12896 #endif
12897
12898 +#ifdef CONFIG_PAX_KERNEXEC
12899 +#ifndef __ASSEMBLY__
12900 +extern unsigned char MODULES_EXEC_VADDR[];
12901 +extern unsigned char MODULES_EXEC_END[];
12902 +#endif
12903 +#include <asm/boot.h>
12904 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
12905 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
12906 +#else
12907 +#define ktla_ktva(addr) (addr)
12908 +#define ktva_ktla(addr) (addr)
12909 +#endif
12910 +
12911 #define MODULES_VADDR VMALLOC_START
12912 #define MODULES_END VMALLOC_END
12913 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
12914 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
12915 index 47356f9..deb94a2 100644
12916 --- a/arch/x86/include/asm/pgtable_64.h
12917 +++ b/arch/x86/include/asm/pgtable_64.h
12918 @@ -16,10 +16,14 @@
12919
12920 extern pud_t level3_kernel_pgt[512];
12921 extern pud_t level3_ident_pgt[512];
12922 +extern pud_t level3_vmalloc_start_pgt[512];
12923 +extern pud_t level3_vmalloc_end_pgt[512];
12924 +extern pud_t level3_vmemmap_pgt[512];
12925 +extern pud_t level2_vmemmap_pgt[512];
12926 extern pmd_t level2_kernel_pgt[512];
12927 extern pmd_t level2_fixmap_pgt[512];
12928 -extern pmd_t level2_ident_pgt[512];
12929 -extern pgd_t init_level4_pgt[];
12930 +extern pmd_t level2_ident_pgt[512*2];
12931 +extern pgd_t init_level4_pgt[512];
12932
12933 #define swapper_pg_dir init_level4_pgt
12934
12935 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12936
12937 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12938 {
12939 + pax_open_kernel();
12940 *pmdp = pmd;
12941 + pax_close_kernel();
12942 }
12943
12944 static inline void native_pmd_clear(pmd_t *pmd)
12945 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
12946
12947 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12948 {
12949 + pax_open_kernel();
12950 *pudp = pud;
12951 + pax_close_kernel();
12952 }
12953
12954 static inline void native_pud_clear(pud_t *pud)
12955 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
12956
12957 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
12958 {
12959 + pax_open_kernel();
12960 + *pgdp = pgd;
12961 + pax_close_kernel();
12962 +}
12963 +
12964 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12965 +{
12966 *pgdp = pgd;
12967 }
12968
12969 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
12970 index 766ea16..5b96cb3 100644
12971 --- a/arch/x86/include/asm/pgtable_64_types.h
12972 +++ b/arch/x86/include/asm/pgtable_64_types.h
12973 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
12974 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
12975 #define MODULES_END _AC(0xffffffffff000000, UL)
12976 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
12977 +#define MODULES_EXEC_VADDR MODULES_VADDR
12978 +#define MODULES_EXEC_END MODULES_END
12979 +
12980 +#define ktla_ktva(addr) (addr)
12981 +#define ktva_ktla(addr) (addr)
12982
12983 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
12984 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
12985 index ec8a1fc..7ccb593 100644
12986 --- a/arch/x86/include/asm/pgtable_types.h
12987 +++ b/arch/x86/include/asm/pgtable_types.h
12988 @@ -16,13 +16,12 @@
12989 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
12990 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
12991 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
12992 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
12993 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
12994 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
12995 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
12996 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
12997 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
12998 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
12999 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
13000 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
13001 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
13002 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
13003
13004 /* If _PAGE_BIT_PRESENT is clear, we use these: */
13005 @@ -40,7 +39,6 @@
13006 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
13007 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
13008 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
13009 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
13010 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
13011 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
13012 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
13013 @@ -57,8 +55,10 @@
13014
13015 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
13016 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
13017 -#else
13018 +#elif defined(CONFIG_KMEMCHECK)
13019 #define _PAGE_NX (_AT(pteval_t, 0))
13020 +#else
13021 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
13022 #endif
13023
13024 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
13025 @@ -96,6 +96,9 @@
13026 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
13027 _PAGE_ACCESSED)
13028
13029 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
13030 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
13031 +
13032 #define __PAGE_KERNEL_EXEC \
13033 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
13034 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
13035 @@ -106,7 +109,7 @@
13036 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
13037 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
13038 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
13039 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
13040 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
13041 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
13042 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
13043 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
13044 @@ -168,8 +171,8 @@
13045 * bits are combined, this will alow user to access the high address mapped
13046 * VDSO in the presence of CONFIG_COMPAT_VDSO
13047 */
13048 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
13049 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
13050 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
13051 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
13052 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
13053 #endif
13054
13055 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
13056 {
13057 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
13058 }
13059 +#endif
13060
13061 +#if PAGETABLE_LEVELS == 3
13062 +#include <asm-generic/pgtable-nopud.h>
13063 +#endif
13064 +
13065 +#if PAGETABLE_LEVELS == 2
13066 +#include <asm-generic/pgtable-nopmd.h>
13067 +#endif
13068 +
13069 +#ifndef __ASSEMBLY__
13070 #if PAGETABLE_LEVELS > 3
13071 typedef struct { pudval_t pud; } pud_t;
13072
13073 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
13074 return pud.pud;
13075 }
13076 #else
13077 -#include <asm-generic/pgtable-nopud.h>
13078 -
13079 static inline pudval_t native_pud_val(pud_t pud)
13080 {
13081 return native_pgd_val(pud.pgd);
13082 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
13083 return pmd.pmd;
13084 }
13085 #else
13086 -#include <asm-generic/pgtable-nopmd.h>
13087 -
13088 static inline pmdval_t native_pmd_val(pmd_t pmd)
13089 {
13090 return native_pgd_val(pmd.pud.pgd);
13091 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
13092
13093 extern pteval_t __supported_pte_mask;
13094 extern void set_nx(void);
13095 -extern int nx_enabled;
13096
13097 #define pgprot_writecombine pgprot_writecombine
13098 extern pgprot_t pgprot_writecombine(pgprot_t prot);
13099 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
13100 index ad1fc85..0b15fe1 100644
13101 --- a/arch/x86/include/asm/processor.h
13102 +++ b/arch/x86/include/asm/processor.h
13103 @@ -289,7 +289,7 @@ struct tss_struct {
13104
13105 } ____cacheline_aligned;
13106
13107 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
13108 +extern struct tss_struct init_tss[NR_CPUS];
13109
13110 /*
13111 * Save the original ist values for checking stack pointers during debugging
13112 @@ -818,11 +818,18 @@ static inline void spin_lock_prefetch(const void *x)
13113 */
13114 #define TASK_SIZE PAGE_OFFSET
13115 #define TASK_SIZE_MAX TASK_SIZE
13116 +
13117 +#ifdef CONFIG_PAX_SEGMEXEC
13118 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
13119 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
13120 +#else
13121 #define STACK_TOP TASK_SIZE
13122 -#define STACK_TOP_MAX STACK_TOP
13123 +#endif
13124 +
13125 +#define STACK_TOP_MAX TASK_SIZE
13126
13127 #define INIT_THREAD { \
13128 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
13129 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
13130 .vm86_info = NULL, \
13131 .sysenter_cs = __KERNEL_CS, \
13132 .io_bitmap_ptr = NULL, \
13133 @@ -836,7 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
13134 */
13135 #define INIT_TSS { \
13136 .x86_tss = { \
13137 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
13138 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
13139 .ss0 = __KERNEL_DS, \
13140 .ss1 = __KERNEL_CS, \
13141 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
13142 @@ -847,11 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
13143 extern unsigned long thread_saved_pc(struct task_struct *tsk);
13144
13145 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
13146 -#define KSTK_TOP(info) \
13147 -({ \
13148 - unsigned long *__ptr = (unsigned long *)(info); \
13149 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
13150 -})
13151 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
13152
13153 /*
13154 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
13155 @@ -866,7 +869,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13156 #define task_pt_regs(task) \
13157 ({ \
13158 struct pt_regs *__regs__; \
13159 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
13160 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
13161 __regs__ - 1; \
13162 })
13163
13164 @@ -876,13 +879,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13165 /*
13166 * User space process size. 47bits minus one guard page.
13167 */
13168 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
13169 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
13170
13171 /* This decides where the kernel will search for a free chunk of vm
13172 * space during mmap's.
13173 */
13174 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
13175 - 0xc0000000 : 0xFFFFe000)
13176 + 0xc0000000 : 0xFFFFf000)
13177
13178 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
13179 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
13180 @@ -893,11 +896,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13181 #define STACK_TOP_MAX TASK_SIZE_MAX
13182
13183 #define INIT_THREAD { \
13184 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
13185 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
13186 }
13187
13188 #define INIT_TSS { \
13189 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
13190 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
13191 }
13192
13193 /*
13194 @@ -925,6 +928,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
13195 */
13196 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
13197
13198 +#ifdef CONFIG_PAX_SEGMEXEC
13199 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
13200 +#endif
13201 +
13202 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
13203
13204 /* Get/set a process' ability to use the timestamp counter instruction */
13205 @@ -985,12 +992,12 @@ extern bool cpu_has_amd_erratum(const int *);
13206 #define cpu_has_amd_erratum(x) (false)
13207 #endif /* CONFIG_CPU_SUP_AMD */
13208
13209 -extern unsigned long arch_align_stack(unsigned long sp);
13210 +#define arch_align_stack(x) ((x) & ~0xfUL)
13211 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
13212
13213 void default_idle(void);
13214 bool set_pm_idle_to_default(void);
13215
13216 -void stop_this_cpu(void *dummy);
13217 +void stop_this_cpu(void *dummy) __noreturn;
13218
13219 #endif /* _ASM_X86_PROCESSOR_H */
13220 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
13221 index 19f16eb..b50624b 100644
13222 --- a/arch/x86/include/asm/ptrace.h
13223 +++ b/arch/x86/include/asm/ptrace.h
13224 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
13225 }
13226
13227 /*
13228 - * user_mode_vm(regs) determines whether a register set came from user mode.
13229 + * user_mode(regs) determines whether a register set came from user mode.
13230 * This is true if V8086 mode was enabled OR if the register set was from
13231 * protected mode with RPL-3 CS value. This tricky test checks that with
13232 * one comparison. Many places in the kernel can bypass this full check
13233 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
13234 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
13235 + * be used.
13236 */
13237 -static inline int user_mode(struct pt_regs *regs)
13238 +static inline int user_mode_novm(struct pt_regs *regs)
13239 {
13240 #ifdef CONFIG_X86_32
13241 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
13242 #else
13243 - return !!(regs->cs & 3);
13244 + return !!(regs->cs & SEGMENT_RPL_MASK);
13245 #endif
13246 }
13247
13248 -static inline int user_mode_vm(struct pt_regs *regs)
13249 +static inline int user_mode(struct pt_regs *regs)
13250 {
13251 #ifdef CONFIG_X86_32
13252 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
13253 USER_RPL;
13254 #else
13255 - return user_mode(regs);
13256 + return user_mode_novm(regs);
13257 #endif
13258 }
13259
13260 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
13261 #ifdef CONFIG_X86_64
13262 static inline bool user_64bit_mode(struct pt_regs *regs)
13263 {
13264 + unsigned long cs = regs->cs & 0xffff;
13265 #ifndef CONFIG_PARAVIRT
13266 /*
13267 * On non-paravirt systems, this is the only long mode CPL 3
13268 * selector. We do not allow long mode selectors in the LDT.
13269 */
13270 - return regs->cs == __USER_CS;
13271 + return cs == __USER_CS;
13272 #else
13273 /* Headers are too twisted for this to go in paravirt.h. */
13274 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
13275 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
13276 #endif
13277 }
13278 #endif
13279 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
13280 index fe1ec5b..dc5c3fe 100644
13281 --- a/arch/x86/include/asm/realmode.h
13282 +++ b/arch/x86/include/asm/realmode.h
13283 @@ -22,16 +22,14 @@ struct real_mode_header {
13284 #endif
13285 /* APM/BIOS reboot */
13286 u32 machine_real_restart_asm;
13287 -#ifdef CONFIG_X86_64
13288 u32 machine_real_restart_seg;
13289 -#endif
13290 };
13291
13292 /* This must match data at trampoline_32/64.S */
13293 struct trampoline_header {
13294 #ifdef CONFIG_X86_32
13295 u32 start;
13296 - u16 gdt_pad;
13297 + u16 boot_cs;
13298 u16 gdt_limit;
13299 u32 gdt_base;
13300 #else
13301 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
13302 index a82c4f1..f9c9696 100644
13303 --- a/arch/x86/include/asm/reboot.h
13304 +++ b/arch/x86/include/asm/reboot.h
13305 @@ -6,12 +6,12 @@
13306 struct pt_regs;
13307
13308 struct machine_ops {
13309 - void (*restart)(char *cmd);
13310 - void (*halt)(void);
13311 - void (*power_off)(void);
13312 + void (* __noreturn restart)(char *cmd);
13313 + void (* __noreturn halt)(void);
13314 + void (* __noreturn power_off)(void);
13315 void (*shutdown)(void);
13316 void (*crash_shutdown)(struct pt_regs *);
13317 - void (*emergency_restart)(void);
13318 + void (* __noreturn emergency_restart)(void);
13319 };
13320
13321 extern struct machine_ops machine_ops;
13322 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
13323 index 2dbe4a7..ce1db00 100644
13324 --- a/arch/x86/include/asm/rwsem.h
13325 +++ b/arch/x86/include/asm/rwsem.h
13326 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
13327 {
13328 asm volatile("# beginning down_read\n\t"
13329 LOCK_PREFIX _ASM_INC "(%1)\n\t"
13330 +
13331 +#ifdef CONFIG_PAX_REFCOUNT
13332 + "jno 0f\n"
13333 + LOCK_PREFIX _ASM_DEC "(%1)\n"
13334 + "int $4\n0:\n"
13335 + _ASM_EXTABLE(0b, 0b)
13336 +#endif
13337 +
13338 /* adds 0x00000001 */
13339 " jns 1f\n"
13340 " call call_rwsem_down_read_failed\n"
13341 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
13342 "1:\n\t"
13343 " mov %1,%2\n\t"
13344 " add %3,%2\n\t"
13345 +
13346 +#ifdef CONFIG_PAX_REFCOUNT
13347 + "jno 0f\n"
13348 + "sub %3,%2\n"
13349 + "int $4\n0:\n"
13350 + _ASM_EXTABLE(0b, 0b)
13351 +#endif
13352 +
13353 " jle 2f\n\t"
13354 LOCK_PREFIX " cmpxchg %2,%0\n\t"
13355 " jnz 1b\n\t"
13356 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
13357 long tmp;
13358 asm volatile("# beginning down_write\n\t"
13359 LOCK_PREFIX " xadd %1,(%2)\n\t"
13360 +
13361 +#ifdef CONFIG_PAX_REFCOUNT
13362 + "jno 0f\n"
13363 + "mov %1,(%2)\n"
13364 + "int $4\n0:\n"
13365 + _ASM_EXTABLE(0b, 0b)
13366 +#endif
13367 +
13368 /* adds 0xffff0001, returns the old value */
13369 " test %1,%1\n\t"
13370 /* was the count 0 before? */
13371 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
13372 long tmp;
13373 asm volatile("# beginning __up_read\n\t"
13374 LOCK_PREFIX " xadd %1,(%2)\n\t"
13375 +
13376 +#ifdef CONFIG_PAX_REFCOUNT
13377 + "jno 0f\n"
13378 + "mov %1,(%2)\n"
13379 + "int $4\n0:\n"
13380 + _ASM_EXTABLE(0b, 0b)
13381 +#endif
13382 +
13383 /* subtracts 1, returns the old value */
13384 " jns 1f\n\t"
13385 " call call_rwsem_wake\n" /* expects old value in %edx */
13386 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
13387 long tmp;
13388 asm volatile("# beginning __up_write\n\t"
13389 LOCK_PREFIX " xadd %1,(%2)\n\t"
13390 +
13391 +#ifdef CONFIG_PAX_REFCOUNT
13392 + "jno 0f\n"
13393 + "mov %1,(%2)\n"
13394 + "int $4\n0:\n"
13395 + _ASM_EXTABLE(0b, 0b)
13396 +#endif
13397 +
13398 /* subtracts 0xffff0001, returns the old value */
13399 " jns 1f\n\t"
13400 " call call_rwsem_wake\n" /* expects old value in %edx */
13401 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13402 {
13403 asm volatile("# beginning __downgrade_write\n\t"
13404 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
13405 +
13406 +#ifdef CONFIG_PAX_REFCOUNT
13407 + "jno 0f\n"
13408 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
13409 + "int $4\n0:\n"
13410 + _ASM_EXTABLE(0b, 0b)
13411 +#endif
13412 +
13413 /*
13414 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
13415 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
13416 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13417 */
13418 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13419 {
13420 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
13421 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
13422 +
13423 +#ifdef CONFIG_PAX_REFCOUNT
13424 + "jno 0f\n"
13425 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
13426 + "int $4\n0:\n"
13427 + _ASM_EXTABLE(0b, 0b)
13428 +#endif
13429 +
13430 : "+m" (sem->count)
13431 : "er" (delta));
13432 }
13433 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13434 */
13435 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
13436 {
13437 - return delta + xadd(&sem->count, delta);
13438 + return delta + xadd_check_overflow(&sem->count, delta);
13439 }
13440
13441 #endif /* __KERNEL__ */
13442 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
13443 index c48a950..c6d7468 100644
13444 --- a/arch/x86/include/asm/segment.h
13445 +++ b/arch/x86/include/asm/segment.h
13446 @@ -64,10 +64,15 @@
13447 * 26 - ESPFIX small SS
13448 * 27 - per-cpu [ offset to per-cpu data area ]
13449 * 28 - stack_canary-20 [ for stack protector ]
13450 - * 29 - unused
13451 - * 30 - unused
13452 + * 29 - PCI BIOS CS
13453 + * 30 - PCI BIOS DS
13454 * 31 - TSS for double fault handler
13455 */
13456 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
13457 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
13458 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
13459 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
13460 +
13461 #define GDT_ENTRY_TLS_MIN 6
13462 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
13463
13464 @@ -79,6 +84,8 @@
13465
13466 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
13467
13468 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
13469 +
13470 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
13471
13472 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
13473 @@ -104,6 +111,12 @@
13474 #define __KERNEL_STACK_CANARY 0
13475 #endif
13476
13477 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
13478 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
13479 +
13480 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
13481 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
13482 +
13483 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
13484
13485 /*
13486 @@ -141,7 +154,7 @@
13487 */
13488
13489 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
13490 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
13491 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
13492
13493
13494 #else
13495 @@ -165,6 +178,8 @@
13496 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
13497 #define __USER32_DS __USER_DS
13498
13499 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
13500 +
13501 #define GDT_ENTRY_TSS 8 /* needs two entries */
13502 #define GDT_ENTRY_LDT 10 /* needs two entries */
13503 #define GDT_ENTRY_TLS_MIN 12
13504 @@ -185,6 +200,7 @@
13505 #endif
13506
13507 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
13508 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
13509 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
13510 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
13511 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
13512 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
13513 {
13514 unsigned long __limit;
13515 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
13516 - return __limit + 1;
13517 + return __limit;
13518 }
13519
13520 #endif /* !__ASSEMBLY__ */
13521 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
13522 index 4f19a15..e04d86f 100644
13523 --- a/arch/x86/include/asm/smp.h
13524 +++ b/arch/x86/include/asm/smp.h
13525 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
13526 /* cpus sharing the last level cache: */
13527 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
13528 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
13529 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
13530 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
13531
13532 static inline struct cpumask *cpu_sibling_mask(int cpu)
13533 {
13534 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
13535 extern int safe_smp_processor_id(void);
13536
13537 #elif defined(CONFIG_X86_64_SMP)
13538 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13539 -
13540 -#define stack_smp_processor_id() \
13541 -({ \
13542 - struct thread_info *ti; \
13543 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
13544 - ti->cpu; \
13545 -})
13546 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13547 +#define stack_smp_processor_id() raw_smp_processor_id()
13548 #define safe_smp_processor_id() smp_processor_id()
13549
13550 #endif
13551 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
13552 index 33692ea..350a534 100644
13553 --- a/arch/x86/include/asm/spinlock.h
13554 +++ b/arch/x86/include/asm/spinlock.h
13555 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
13556 static inline void arch_read_lock(arch_rwlock_t *rw)
13557 {
13558 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
13559 +
13560 +#ifdef CONFIG_PAX_REFCOUNT
13561 + "jno 0f\n"
13562 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
13563 + "int $4\n0:\n"
13564 + _ASM_EXTABLE(0b, 0b)
13565 +#endif
13566 +
13567 "jns 1f\n"
13568 "call __read_lock_failed\n\t"
13569 "1:\n"
13570 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
13571 static inline void arch_write_lock(arch_rwlock_t *rw)
13572 {
13573 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
13574 +
13575 +#ifdef CONFIG_PAX_REFCOUNT
13576 + "jno 0f\n"
13577 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
13578 + "int $4\n0:\n"
13579 + _ASM_EXTABLE(0b, 0b)
13580 +#endif
13581 +
13582 "jz 1f\n"
13583 "call __write_lock_failed\n\t"
13584 "1:\n"
13585 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
13586
13587 static inline void arch_read_unlock(arch_rwlock_t *rw)
13588 {
13589 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
13590 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
13591 +
13592 +#ifdef CONFIG_PAX_REFCOUNT
13593 + "jno 0f\n"
13594 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
13595 + "int $4\n0:\n"
13596 + _ASM_EXTABLE(0b, 0b)
13597 +#endif
13598 +
13599 :"+m" (rw->lock) : : "memory");
13600 }
13601
13602 static inline void arch_write_unlock(arch_rwlock_t *rw)
13603 {
13604 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
13605 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
13606 +
13607 +#ifdef CONFIG_PAX_REFCOUNT
13608 + "jno 0f\n"
13609 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
13610 + "int $4\n0:\n"
13611 + _ASM_EXTABLE(0b, 0b)
13612 +#endif
13613 +
13614 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
13615 }
13616
13617 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
13618 index 6a99859..03cb807 100644
13619 --- a/arch/x86/include/asm/stackprotector.h
13620 +++ b/arch/x86/include/asm/stackprotector.h
13621 @@ -47,7 +47,7 @@
13622 * head_32 for boot CPU and setup_per_cpu_areas() for others.
13623 */
13624 #define GDT_STACK_CANARY_INIT \
13625 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
13626 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
13627
13628 /*
13629 * Initialize the stackprotector canary value.
13630 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
13631
13632 static inline void load_stack_canary_segment(void)
13633 {
13634 -#ifdef CONFIG_X86_32
13635 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
13636 asm volatile ("mov %0, %%gs" : : "r" (0));
13637 #endif
13638 }
13639 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
13640 index 70bbe39..4ae2bd4 100644
13641 --- a/arch/x86/include/asm/stacktrace.h
13642 +++ b/arch/x86/include/asm/stacktrace.h
13643 @@ -11,28 +11,20 @@
13644
13645 extern int kstack_depth_to_print;
13646
13647 -struct thread_info;
13648 +struct task_struct;
13649 struct stacktrace_ops;
13650
13651 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
13652 - unsigned long *stack,
13653 - unsigned long bp,
13654 - const struct stacktrace_ops *ops,
13655 - void *data,
13656 - unsigned long *end,
13657 - int *graph);
13658 +typedef unsigned long walk_stack_t(struct task_struct *task,
13659 + void *stack_start,
13660 + unsigned long *stack,
13661 + unsigned long bp,
13662 + const struct stacktrace_ops *ops,
13663 + void *data,
13664 + unsigned long *end,
13665 + int *graph);
13666
13667 -extern unsigned long
13668 -print_context_stack(struct thread_info *tinfo,
13669 - unsigned long *stack, unsigned long bp,
13670 - const struct stacktrace_ops *ops, void *data,
13671 - unsigned long *end, int *graph);
13672 -
13673 -extern unsigned long
13674 -print_context_stack_bp(struct thread_info *tinfo,
13675 - unsigned long *stack, unsigned long bp,
13676 - const struct stacktrace_ops *ops, void *data,
13677 - unsigned long *end, int *graph);
13678 +extern walk_stack_t print_context_stack;
13679 +extern walk_stack_t print_context_stack_bp;
13680
13681 /* Generic stack tracer with callbacks */
13682
13683 @@ -40,7 +32,7 @@ struct stacktrace_ops {
13684 void (*address)(void *data, unsigned long address, int reliable);
13685 /* On negative return stop dumping */
13686 int (*stack)(void *data, char *name);
13687 - walk_stack_t walk_stack;
13688 + walk_stack_t *walk_stack;
13689 };
13690
13691 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
13692 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
13693 index 4ec45b3..a4f0a8a 100644
13694 --- a/arch/x86/include/asm/switch_to.h
13695 +++ b/arch/x86/include/asm/switch_to.h
13696 @@ -108,7 +108,7 @@ do { \
13697 "call __switch_to\n\t" \
13698 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
13699 __switch_canary \
13700 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
13701 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
13702 "movq %%rax,%%rdi\n\t" \
13703 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
13704 "jnz ret_from_fork\n\t" \
13705 @@ -119,7 +119,7 @@ do { \
13706 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
13707 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
13708 [_tif_fork] "i" (_TIF_FORK), \
13709 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
13710 + [thread_info] "m" (current_tinfo), \
13711 [current_task] "m" (current_task) \
13712 __switch_canary_iparam \
13713 : "memory", "cc" __EXTRA_CLOBBER)
13714 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
13715 index 2d946e6..e453ec4 100644
13716 --- a/arch/x86/include/asm/thread_info.h
13717 +++ b/arch/x86/include/asm/thread_info.h
13718 @@ -10,6 +10,7 @@
13719 #include <linux/compiler.h>
13720 #include <asm/page.h>
13721 #include <asm/types.h>
13722 +#include <asm/percpu.h>
13723
13724 /*
13725 * low level task data that entry.S needs immediate access to
13726 @@ -24,7 +25,6 @@ struct exec_domain;
13727 #include <linux/atomic.h>
13728
13729 struct thread_info {
13730 - struct task_struct *task; /* main task structure */
13731 struct exec_domain *exec_domain; /* execution domain */
13732 __u32 flags; /* low level flags */
13733 __u32 status; /* thread synchronous flags */
13734 @@ -34,19 +34,13 @@ struct thread_info {
13735 mm_segment_t addr_limit;
13736 struct restart_block restart_block;
13737 void __user *sysenter_return;
13738 -#ifdef CONFIG_X86_32
13739 - unsigned long previous_esp; /* ESP of the previous stack in
13740 - case of nested (IRQ) stacks
13741 - */
13742 - __u8 supervisor_stack[0];
13743 -#endif
13744 + unsigned long lowest_stack;
13745 unsigned int sig_on_uaccess_error:1;
13746 unsigned int uaccess_err:1; /* uaccess failed */
13747 };
13748
13749 -#define INIT_THREAD_INFO(tsk) \
13750 +#define INIT_THREAD_INFO \
13751 { \
13752 - .task = &tsk, \
13753 .exec_domain = &default_exec_domain, \
13754 .flags = 0, \
13755 .cpu = 0, \
13756 @@ -57,7 +51,7 @@ struct thread_info {
13757 }, \
13758 }
13759
13760 -#define init_thread_info (init_thread_union.thread_info)
13761 +#define init_thread_info (init_thread_union.stack)
13762 #define init_stack (init_thread_union.stack)
13763
13764 #else /* !__ASSEMBLY__ */
13765 @@ -98,6 +92,7 @@ struct thread_info {
13766 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
13767 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
13768 #define TIF_X32 30 /* 32-bit native x86-64 binary */
13769 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
13770
13771 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
13772 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
13773 @@ -122,17 +117,18 @@ struct thread_info {
13774 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
13775 #define _TIF_ADDR32 (1 << TIF_ADDR32)
13776 #define _TIF_X32 (1 << TIF_X32)
13777 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
13778
13779 /* work to do in syscall_trace_enter() */
13780 #define _TIF_WORK_SYSCALL_ENTRY \
13781 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
13782 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
13783 - _TIF_NOHZ)
13784 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
13785
13786 /* work to do in syscall_trace_leave() */
13787 #define _TIF_WORK_SYSCALL_EXIT \
13788 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
13789 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
13790 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
13791
13792 /* work to do on interrupt/exception return */
13793 #define _TIF_WORK_MASK \
13794 @@ -143,7 +139,7 @@ struct thread_info {
13795 /* work to do on any return to user space */
13796 #define _TIF_ALLWORK_MASK \
13797 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
13798 - _TIF_NOHZ)
13799 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
13800
13801 /* Only used for 64 bit */
13802 #define _TIF_DO_NOTIFY_MASK \
13803 @@ -159,45 +155,40 @@ struct thread_info {
13804
13805 #define PREEMPT_ACTIVE 0x10000000
13806
13807 -#ifdef CONFIG_X86_32
13808 -
13809 -#define STACK_WARN (THREAD_SIZE/8)
13810 -/*
13811 - * macros/functions for gaining access to the thread information structure
13812 - *
13813 - * preempt_count needs to be 1 initially, until the scheduler is functional.
13814 - */
13815 -#ifndef __ASSEMBLY__
13816 -
13817 -
13818 -/* how to get the current stack pointer from C */
13819 -register unsigned long current_stack_pointer asm("esp") __used;
13820 -
13821 -/* how to get the thread information struct from C */
13822 -static inline struct thread_info *current_thread_info(void)
13823 -{
13824 - return (struct thread_info *)
13825 - (current_stack_pointer & ~(THREAD_SIZE - 1));
13826 -}
13827 -
13828 -#else /* !__ASSEMBLY__ */
13829 -
13830 +#ifdef __ASSEMBLY__
13831 /* how to get the thread information struct from ASM */
13832 #define GET_THREAD_INFO(reg) \
13833 - movl $-THREAD_SIZE, reg; \
13834 - andl %esp, reg
13835 + mov PER_CPU_VAR(current_tinfo), reg
13836
13837 /* use this one if reg already contains %esp */
13838 -#define GET_THREAD_INFO_WITH_ESP(reg) \
13839 - andl $-THREAD_SIZE, reg
13840 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
13841 +#else
13842 +/* how to get the thread information struct from C */
13843 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
13844 +
13845 +static __always_inline struct thread_info *current_thread_info(void)
13846 +{
13847 + return this_cpu_read_stable(current_tinfo);
13848 +}
13849 +#endif
13850 +
13851 +#ifdef CONFIG_X86_32
13852 +
13853 +#define STACK_WARN (THREAD_SIZE/8)
13854 +/*
13855 + * macros/functions for gaining access to the thread information structure
13856 + *
13857 + * preempt_count needs to be 1 initially, until the scheduler is functional.
13858 + */
13859 +#ifndef __ASSEMBLY__
13860 +
13861 +/* how to get the current stack pointer from C */
13862 +register unsigned long current_stack_pointer asm("esp") __used;
13863
13864 #endif
13865
13866 #else /* X86_32 */
13867
13868 -#include <asm/percpu.h>
13869 -#define KERNEL_STACK_OFFSET (5*8)
13870 -
13871 /*
13872 * macros/functions for gaining access to the thread information structure
13873 * preempt_count needs to be 1 initially, until the scheduler is functional.
13874 @@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
13875 #ifndef __ASSEMBLY__
13876 DECLARE_PER_CPU(unsigned long, kernel_stack);
13877
13878 -static inline struct thread_info *current_thread_info(void)
13879 -{
13880 - struct thread_info *ti;
13881 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
13882 - KERNEL_STACK_OFFSET - THREAD_SIZE);
13883 - return ti;
13884 -}
13885 -
13886 -#else /* !__ASSEMBLY__ */
13887 -
13888 -/* how to get the thread information struct from ASM */
13889 -#define GET_THREAD_INFO(reg) \
13890 - movq PER_CPU_VAR(kernel_stack),reg ; \
13891 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
13892 -
13893 -/*
13894 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
13895 - * a certain register (to be used in assembler memory operands).
13896 - */
13897 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
13898 -
13899 +/* how to get the current stack pointer from C */
13900 +register unsigned long current_stack_pointer asm("rsp") __used;
13901 #endif
13902
13903 #endif /* !X86_32 */
13904 @@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
13905 extern void arch_task_cache_init(void);
13906 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
13907 extern void arch_release_task_struct(struct task_struct *tsk);
13908 +
13909 +#define __HAVE_THREAD_FUNCTIONS
13910 +#define task_thread_info(task) (&(task)->tinfo)
13911 +#define task_stack_page(task) ((task)->stack)
13912 +#define setup_thread_stack(p, org) do {} while (0)
13913 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
13914 +
13915 #endif
13916 #endif /* _ASM_X86_THREAD_INFO_H */
13917 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
13918 index 7ccf8d1..9a18110 100644
13919 --- a/arch/x86/include/asm/uaccess.h
13920 +++ b/arch/x86/include/asm/uaccess.h
13921 @@ -7,6 +7,7 @@
13922 #include <linux/compiler.h>
13923 #include <linux/thread_info.h>
13924 #include <linux/string.h>
13925 +#include <linux/sched.h>
13926 #include <asm/asm.h>
13927 #include <asm/page.h>
13928 #include <asm/smap.h>
13929 @@ -29,7 +30,12 @@
13930
13931 #define get_ds() (KERNEL_DS)
13932 #define get_fs() (current_thread_info()->addr_limit)
13933 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13934 +void __set_fs(mm_segment_t x);
13935 +void set_fs(mm_segment_t x);
13936 +#else
13937 #define set_fs(x) (current_thread_info()->addr_limit = (x))
13938 +#endif
13939
13940 #define segment_eq(a, b) ((a).seg == (b).seg)
13941
13942 @@ -77,8 +83,33 @@
13943 * checks that the pointer is in the user space range - after calling
13944 * this function, memory access functions may still return -EFAULT.
13945 */
13946 -#define access_ok(type, addr, size) \
13947 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13948 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13949 +#define access_ok(type, addr, size) \
13950 +({ \
13951 + long __size = size; \
13952 + unsigned long __addr = (unsigned long)addr; \
13953 + unsigned long __addr_ao = __addr & PAGE_MASK; \
13954 + unsigned long __end_ao = __addr + __size - 1; \
13955 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
13956 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
13957 + while(__addr_ao <= __end_ao) { \
13958 + char __c_ao; \
13959 + __addr_ao += PAGE_SIZE; \
13960 + if (__size > PAGE_SIZE) \
13961 + cond_resched(); \
13962 + if (__get_user(__c_ao, (char __user *)__addr)) \
13963 + break; \
13964 + if (type != VERIFY_WRITE) { \
13965 + __addr = __addr_ao; \
13966 + continue; \
13967 + } \
13968 + if (__put_user(__c_ao, (char __user *)__addr)) \
13969 + break; \
13970 + __addr = __addr_ao; \
13971 + } \
13972 + } \
13973 + __ret_ao; \
13974 +})
13975
13976 /*
13977 * The exception table consists of pairs of addresses relative to the
13978 @@ -189,13 +220,21 @@ extern int __get_user_bad(void);
13979 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
13980 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
13981
13982 -
13983 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13984 +#define __copyuser_seg "gs;"
13985 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
13986 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
13987 +#else
13988 +#define __copyuser_seg
13989 +#define __COPYUSER_SET_ES
13990 +#define __COPYUSER_RESTORE_ES
13991 +#endif
13992
13993 #ifdef CONFIG_X86_32
13994 #define __put_user_asm_u64(x, addr, err, errret) \
13995 asm volatile(ASM_STAC "\n" \
13996 - "1: movl %%eax,0(%2)\n" \
13997 - "2: movl %%edx,4(%2)\n" \
13998 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
13999 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
14000 "3: " ASM_CLAC "\n" \
14001 ".section .fixup,\"ax\"\n" \
14002 "4: movl %3,%0\n" \
14003 @@ -208,8 +247,8 @@ extern int __get_user_bad(void);
14004
14005 #define __put_user_asm_ex_u64(x, addr) \
14006 asm volatile(ASM_STAC "\n" \
14007 - "1: movl %%eax,0(%1)\n" \
14008 - "2: movl %%edx,4(%1)\n" \
14009 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
14010 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
14011 "3: " ASM_CLAC "\n" \
14012 _ASM_EXTABLE_EX(1b, 2b) \
14013 _ASM_EXTABLE_EX(2b, 3b) \
14014 @@ -261,7 +300,7 @@ extern void __put_user_8(void);
14015 __typeof__(*(ptr)) __pu_val; \
14016 __chk_user_ptr(ptr); \
14017 might_fault(); \
14018 - __pu_val = x; \
14019 + __pu_val = (x); \
14020 switch (sizeof(*(ptr))) { \
14021 case 1: \
14022 __put_user_x(1, __pu_val, ptr, __ret_pu); \
14023 @@ -383,7 +422,7 @@ do { \
14024
14025 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
14026 asm volatile(ASM_STAC "\n" \
14027 - "1: mov"itype" %2,%"rtype"1\n" \
14028 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
14029 "2: " ASM_CLAC "\n" \
14030 ".section .fixup,\"ax\"\n" \
14031 "3: mov %3,%0\n" \
14032 @@ -391,7 +430,7 @@ do { \
14033 " jmp 2b\n" \
14034 ".previous\n" \
14035 _ASM_EXTABLE(1b, 3b) \
14036 - : "=r" (err), ltype(x) \
14037 + : "=r" (err), ltype (x) \
14038 : "m" (__m(addr)), "i" (errret), "0" (err))
14039
14040 #define __get_user_size_ex(x, ptr, size) \
14041 @@ -416,7 +455,7 @@ do { \
14042 } while (0)
14043
14044 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
14045 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
14046 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
14047 "2:\n" \
14048 _ASM_EXTABLE_EX(1b, 2b) \
14049 : ltype(x) : "m" (__m(addr)))
14050 @@ -433,13 +472,24 @@ do { \
14051 int __gu_err; \
14052 unsigned long __gu_val; \
14053 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
14054 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
14055 + (x) = (__typeof__(*(ptr)))__gu_val; \
14056 __gu_err; \
14057 })
14058
14059 /* FIXME: this hack is definitely wrong -AK */
14060 struct __large_struct { unsigned long buf[100]; };
14061 -#define __m(x) (*(struct __large_struct __user *)(x))
14062 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14063 +#define ____m(x) \
14064 +({ \
14065 + unsigned long ____x = (unsigned long)(x); \
14066 + if (____x < PAX_USER_SHADOW_BASE) \
14067 + ____x += PAX_USER_SHADOW_BASE; \
14068 + (void __user *)____x; \
14069 +})
14070 +#else
14071 +#define ____m(x) (x)
14072 +#endif
14073 +#define __m(x) (*(struct __large_struct __user *)____m(x))
14074
14075 /*
14076 * Tell gcc we read from memory instead of writing: this is because
14077 @@ -448,7 +498,7 @@ struct __large_struct { unsigned long buf[100]; };
14078 */
14079 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
14080 asm volatile(ASM_STAC "\n" \
14081 - "1: mov"itype" %"rtype"1,%2\n" \
14082 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
14083 "2: " ASM_CLAC "\n" \
14084 ".section .fixup,\"ax\"\n" \
14085 "3: mov %3,%0\n" \
14086 @@ -456,10 +506,10 @@ struct __large_struct { unsigned long buf[100]; };
14087 ".previous\n" \
14088 _ASM_EXTABLE(1b, 3b) \
14089 : "=r"(err) \
14090 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
14091 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
14092
14093 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
14094 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
14095 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
14096 "2:\n" \
14097 _ASM_EXTABLE_EX(1b, 2b) \
14098 : : ltype(x), "m" (__m(addr)))
14099 @@ -498,8 +548,12 @@ struct __large_struct { unsigned long buf[100]; };
14100 * On error, the variable @x is set to zero.
14101 */
14102
14103 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14104 +#define __get_user(x, ptr) get_user((x), (ptr))
14105 +#else
14106 #define __get_user(x, ptr) \
14107 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
14108 +#endif
14109
14110 /**
14111 * __put_user: - Write a simple value into user space, with less checking.
14112 @@ -521,8 +575,12 @@ struct __large_struct { unsigned long buf[100]; };
14113 * Returns zero on success, or -EFAULT on error.
14114 */
14115
14116 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14117 +#define __put_user(x, ptr) put_user((x), (ptr))
14118 +#else
14119 #define __put_user(x, ptr) \
14120 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
14121 +#endif
14122
14123 #define __get_user_unaligned __get_user
14124 #define __put_user_unaligned __put_user
14125 @@ -540,7 +598,7 @@ struct __large_struct { unsigned long buf[100]; };
14126 #define get_user_ex(x, ptr) do { \
14127 unsigned long __gue_val; \
14128 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
14129 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
14130 + (x) = (__typeof__(*(ptr)))__gue_val; \
14131 } while (0)
14132
14133 #ifdef CONFIG_X86_WP_WORKS_OK
14134 @@ -574,8 +632,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
14135 extern __must_check long strlen_user(const char __user *str);
14136 extern __must_check long strnlen_user(const char __user *str, long n);
14137
14138 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
14139 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
14140 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
14141 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
14142
14143 /*
14144 * movsl can be slow when source and dest are not both 8-byte aligned
14145 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
14146 index 7f760a9..04b1c65 100644
14147 --- a/arch/x86/include/asm/uaccess_32.h
14148 +++ b/arch/x86/include/asm/uaccess_32.h
14149 @@ -11,15 +11,15 @@
14150 #include <asm/page.h>
14151
14152 unsigned long __must_check __copy_to_user_ll
14153 - (void __user *to, const void *from, unsigned long n);
14154 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
14155 unsigned long __must_check __copy_from_user_ll
14156 - (void *to, const void __user *from, unsigned long n);
14157 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14158 unsigned long __must_check __copy_from_user_ll_nozero
14159 - (void *to, const void __user *from, unsigned long n);
14160 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14161 unsigned long __must_check __copy_from_user_ll_nocache
14162 - (void *to, const void __user *from, unsigned long n);
14163 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14164 unsigned long __must_check __copy_from_user_ll_nocache_nozero
14165 - (void *to, const void __user *from, unsigned long n);
14166 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14167
14168 /**
14169 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
14170 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
14171 static __always_inline unsigned long __must_check
14172 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
14173 {
14174 + if ((long)n < 0)
14175 + return n;
14176 +
14177 + check_object_size(from, n, true);
14178 +
14179 if (__builtin_constant_p(n)) {
14180 unsigned long ret;
14181
14182 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
14183 __copy_to_user(void __user *to, const void *from, unsigned long n)
14184 {
14185 might_fault();
14186 +
14187 return __copy_to_user_inatomic(to, from, n);
14188 }
14189
14190 static __always_inline unsigned long
14191 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
14192 {
14193 + if ((long)n < 0)
14194 + return n;
14195 +
14196 /* Avoid zeroing the tail if the copy fails..
14197 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
14198 * but as the zeroing behaviour is only significant when n is not
14199 @@ -137,6 +146,12 @@ static __always_inline unsigned long
14200 __copy_from_user(void *to, const void __user *from, unsigned long n)
14201 {
14202 might_fault();
14203 +
14204 + if ((long)n < 0)
14205 + return n;
14206 +
14207 + check_object_size(to, n, false);
14208 +
14209 if (__builtin_constant_p(n)) {
14210 unsigned long ret;
14211
14212 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
14213 const void __user *from, unsigned long n)
14214 {
14215 might_fault();
14216 +
14217 + if ((long)n < 0)
14218 + return n;
14219 +
14220 if (__builtin_constant_p(n)) {
14221 unsigned long ret;
14222
14223 @@ -181,15 +200,19 @@ static __always_inline unsigned long
14224 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
14225 unsigned long n)
14226 {
14227 - return __copy_from_user_ll_nocache_nozero(to, from, n);
14228 + if ((long)n < 0)
14229 + return n;
14230 +
14231 + return __copy_from_user_ll_nocache_nozero(to, from, n);
14232 }
14233
14234 -unsigned long __must_check copy_to_user(void __user *to,
14235 - const void *from, unsigned long n);
14236 -unsigned long __must_check _copy_from_user(void *to,
14237 - const void __user *from,
14238 - unsigned long n);
14239 -
14240 +extern void copy_to_user_overflow(void)
14241 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14242 + __compiletime_error("copy_to_user() buffer size is not provably correct")
14243 +#else
14244 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
14245 +#endif
14246 +;
14247
14248 extern void copy_from_user_overflow(void)
14249 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14250 @@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
14251 #endif
14252 ;
14253
14254 -static inline unsigned long __must_check copy_from_user(void *to,
14255 - const void __user *from,
14256 - unsigned long n)
14257 +/**
14258 + * copy_to_user: - Copy a block of data into user space.
14259 + * @to: Destination address, in user space.
14260 + * @from: Source address, in kernel space.
14261 + * @n: Number of bytes to copy.
14262 + *
14263 + * Context: User context only. This function may sleep.
14264 + *
14265 + * Copy data from kernel space to user space.
14266 + *
14267 + * Returns number of bytes that could not be copied.
14268 + * On success, this will be zero.
14269 + */
14270 +static inline unsigned long __must_check
14271 +copy_to_user(void __user *to, const void *from, unsigned long n)
14272 {
14273 - int sz = __compiletime_object_size(to);
14274 + size_t sz = __compiletime_object_size(from);
14275
14276 - if (likely(sz == -1 || sz >= n))
14277 - n = _copy_from_user(to, from, n);
14278 - else
14279 + if (unlikely(sz != (size_t)-1 && sz < n))
14280 + copy_to_user_overflow();
14281 + else if (access_ok(VERIFY_WRITE, to, n))
14282 + n = __copy_to_user(to, from, n);
14283 + return n;
14284 +}
14285 +
14286 +/**
14287 + * copy_from_user: - Copy a block of data from user space.
14288 + * @to: Destination address, in kernel space.
14289 + * @from: Source address, in user space.
14290 + * @n: Number of bytes to copy.
14291 + *
14292 + * Context: User context only. This function may sleep.
14293 + *
14294 + * Copy data from user space to kernel space.
14295 + *
14296 + * Returns number of bytes that could not be copied.
14297 + * On success, this will be zero.
14298 + *
14299 + * If some data could not be copied, this function will pad the copied
14300 + * data to the requested size using zero bytes.
14301 + */
14302 +static inline unsigned long __must_check
14303 +copy_from_user(void *to, const void __user *from, unsigned long n)
14304 +{
14305 + size_t sz = __compiletime_object_size(to);
14306 +
14307 + check_object_size(to, n, false);
14308 +
14309 + if (unlikely(sz != (size_t)-1 && sz < n))
14310 copy_from_user_overflow();
14311 -
14312 + else if (access_ok(VERIFY_READ, from, n))
14313 + n = __copy_from_user(to, from, n);
14314 + else if ((long)n > 0)
14315 + memset(to, 0, n);
14316 return n;
14317 }
14318
14319 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
14320 index 142810c..4b68a3e 100644
14321 --- a/arch/x86/include/asm/uaccess_64.h
14322 +++ b/arch/x86/include/asm/uaccess_64.h
14323 @@ -10,6 +10,9 @@
14324 #include <asm/alternative.h>
14325 #include <asm/cpufeature.h>
14326 #include <asm/page.h>
14327 +#include <asm/pgtable.h>
14328 +
14329 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
14330
14331 /*
14332 * Copy To/From Userspace
14333 @@ -17,13 +20,13 @@
14334
14335 /* Handles exceptions in both to and from, but doesn't do access_ok */
14336 __must_check unsigned long
14337 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
14338 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
14339 __must_check unsigned long
14340 -copy_user_generic_string(void *to, const void *from, unsigned len);
14341 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
14342 __must_check unsigned long
14343 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
14344 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
14345
14346 -static __always_inline __must_check unsigned long
14347 +static __always_inline __must_check __size_overflow(3) unsigned long
14348 copy_user_generic(void *to, const void *from, unsigned len)
14349 {
14350 unsigned ret;
14351 @@ -41,142 +44,203 @@ copy_user_generic(void *to, const void *from, unsigned len)
14352 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
14353 "=d" (len)),
14354 "1" (to), "2" (from), "3" (len)
14355 - : "memory", "rcx", "r8", "r9", "r10", "r11");
14356 + : "memory", "rcx", "r8", "r9", "r11");
14357 return ret;
14358 }
14359
14360 +static __always_inline __must_check unsigned long
14361 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
14362 +static __always_inline __must_check unsigned long
14363 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
14364 __must_check unsigned long
14365 -_copy_to_user(void __user *to, const void *from, unsigned len);
14366 -__must_check unsigned long
14367 -_copy_from_user(void *to, const void __user *from, unsigned len);
14368 -__must_check unsigned long
14369 -copy_in_user(void __user *to, const void __user *from, unsigned len);
14370 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
14371 +
14372 +extern void copy_to_user_overflow(void)
14373 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14374 + __compiletime_error("copy_to_user() buffer size is not provably correct")
14375 +#else
14376 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
14377 +#endif
14378 +;
14379 +
14380 +extern void copy_from_user_overflow(void)
14381 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14382 + __compiletime_error("copy_from_user() buffer size is not provably correct")
14383 +#else
14384 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
14385 +#endif
14386 +;
14387
14388 static inline unsigned long __must_check copy_from_user(void *to,
14389 const void __user *from,
14390 unsigned long n)
14391 {
14392 - int sz = __compiletime_object_size(to);
14393 -
14394 might_fault();
14395 - if (likely(sz == -1 || sz >= n))
14396 - n = _copy_from_user(to, from, n);
14397 -#ifdef CONFIG_DEBUG_VM
14398 - else
14399 - WARN(1, "Buffer overflow detected!\n");
14400 -#endif
14401 +
14402 + check_object_size(to, n, false);
14403 + if (access_ok(VERIFY_READ, from, n))
14404 + n = __copy_from_user(to, from, n);
14405 + else if (n < INT_MAX)
14406 + memset(to, 0, n);
14407 return n;
14408 }
14409
14410 static __always_inline __must_check
14411 -int copy_to_user(void __user *dst, const void *src, unsigned size)
14412 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
14413 {
14414 might_fault();
14415
14416 - return _copy_to_user(dst, src, size);
14417 + if (access_ok(VERIFY_WRITE, dst, size))
14418 + size = __copy_to_user(dst, src, size);
14419 + return size;
14420 }
14421
14422 static __always_inline __must_check
14423 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
14424 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
14425 {
14426 - int ret = 0;
14427 + size_t sz = __compiletime_object_size(dst);
14428 + unsigned ret = 0;
14429
14430 might_fault();
14431 +
14432 + if (size > INT_MAX)
14433 + return size;
14434 +
14435 + check_object_size(dst, size, false);
14436 +
14437 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14438 + if (!__access_ok(VERIFY_READ, src, size))
14439 + return size;
14440 +#endif
14441 +
14442 + if (unlikely(sz != (size_t)-1 && sz < size)) {
14443 + copy_from_user_overflow();
14444 + return size;
14445 + }
14446 +
14447 if (!__builtin_constant_p(size))
14448 - return copy_user_generic(dst, (__force void *)src, size);
14449 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14450 switch (size) {
14451 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
14452 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
14453 ret, "b", "b", "=q", 1);
14454 return ret;
14455 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
14456 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
14457 ret, "w", "w", "=r", 2);
14458 return ret;
14459 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
14460 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
14461 ret, "l", "k", "=r", 4);
14462 return ret;
14463 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
14464 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14465 ret, "q", "", "=r", 8);
14466 return ret;
14467 case 10:
14468 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14469 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14470 ret, "q", "", "=r", 10);
14471 if (unlikely(ret))
14472 return ret;
14473 __get_user_asm(*(u16 *)(8 + (char *)dst),
14474 - (u16 __user *)(8 + (char __user *)src),
14475 + (const u16 __user *)(8 + (const char __user *)src),
14476 ret, "w", "w", "=r", 2);
14477 return ret;
14478 case 16:
14479 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14480 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14481 ret, "q", "", "=r", 16);
14482 if (unlikely(ret))
14483 return ret;
14484 __get_user_asm(*(u64 *)(8 + (char *)dst),
14485 - (u64 __user *)(8 + (char __user *)src),
14486 + (const u64 __user *)(8 + (const char __user *)src),
14487 ret, "q", "", "=r", 8);
14488 return ret;
14489 default:
14490 - return copy_user_generic(dst, (__force void *)src, size);
14491 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14492 }
14493 }
14494
14495 static __always_inline __must_check
14496 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
14497 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
14498 {
14499 - int ret = 0;
14500 + size_t sz = __compiletime_object_size(src);
14501 + unsigned ret = 0;
14502
14503 might_fault();
14504 +
14505 + if (size > INT_MAX)
14506 + return size;
14507 +
14508 + check_object_size(src, size, true);
14509 +
14510 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14511 + if (!__access_ok(VERIFY_WRITE, dst, size))
14512 + return size;
14513 +#endif
14514 +
14515 + if (unlikely(sz != (size_t)-1 && sz < size)) {
14516 + copy_to_user_overflow();
14517 + return size;
14518 + }
14519 +
14520 if (!__builtin_constant_p(size))
14521 - return copy_user_generic((__force void *)dst, src, size);
14522 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14523 switch (size) {
14524 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
14525 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
14526 ret, "b", "b", "iq", 1);
14527 return ret;
14528 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
14529 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
14530 ret, "w", "w", "ir", 2);
14531 return ret;
14532 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
14533 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
14534 ret, "l", "k", "ir", 4);
14535 return ret;
14536 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
14537 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14538 ret, "q", "", "er", 8);
14539 return ret;
14540 case 10:
14541 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14542 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14543 ret, "q", "", "er", 10);
14544 if (unlikely(ret))
14545 return ret;
14546 asm("":::"memory");
14547 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
14548 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
14549 ret, "w", "w", "ir", 2);
14550 return ret;
14551 case 16:
14552 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14553 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14554 ret, "q", "", "er", 16);
14555 if (unlikely(ret))
14556 return ret;
14557 asm("":::"memory");
14558 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
14559 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
14560 ret, "q", "", "er", 8);
14561 return ret;
14562 default:
14563 - return copy_user_generic((__force void *)dst, src, size);
14564 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14565 }
14566 }
14567
14568 static __always_inline __must_check
14569 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14570 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
14571 {
14572 - int ret = 0;
14573 + unsigned ret = 0;
14574
14575 might_fault();
14576 +
14577 + if (size > INT_MAX)
14578 + return size;
14579 +
14580 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14581 + if (!__access_ok(VERIFY_READ, src, size))
14582 + return size;
14583 + if (!__access_ok(VERIFY_WRITE, dst, size))
14584 + return size;
14585 +#endif
14586 +
14587 if (!__builtin_constant_p(size))
14588 - return copy_user_generic((__force void *)dst,
14589 - (__force void *)src, size);
14590 + return copy_user_generic((__force_kernel void *)____m(dst),
14591 + (__force_kernel const void *)____m(src), size);
14592 switch (size) {
14593 case 1: {
14594 u8 tmp;
14595 - __get_user_asm(tmp, (u8 __user *)src,
14596 + __get_user_asm(tmp, (const u8 __user *)src,
14597 ret, "b", "b", "=q", 1);
14598 if (likely(!ret))
14599 __put_user_asm(tmp, (u8 __user *)dst,
14600 @@ -185,7 +249,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14601 }
14602 case 2: {
14603 u16 tmp;
14604 - __get_user_asm(tmp, (u16 __user *)src,
14605 + __get_user_asm(tmp, (const u16 __user *)src,
14606 ret, "w", "w", "=r", 2);
14607 if (likely(!ret))
14608 __put_user_asm(tmp, (u16 __user *)dst,
14609 @@ -195,7 +259,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14610
14611 case 4: {
14612 u32 tmp;
14613 - __get_user_asm(tmp, (u32 __user *)src,
14614 + __get_user_asm(tmp, (const u32 __user *)src,
14615 ret, "l", "k", "=r", 4);
14616 if (likely(!ret))
14617 __put_user_asm(tmp, (u32 __user *)dst,
14618 @@ -204,7 +268,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14619 }
14620 case 8: {
14621 u64 tmp;
14622 - __get_user_asm(tmp, (u64 __user *)src,
14623 + __get_user_asm(tmp, (const u64 __user *)src,
14624 ret, "q", "", "=r", 8);
14625 if (likely(!ret))
14626 __put_user_asm(tmp, (u64 __user *)dst,
14627 @@ -212,41 +276,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14628 return ret;
14629 }
14630 default:
14631 - return copy_user_generic((__force void *)dst,
14632 - (__force void *)src, size);
14633 + return copy_user_generic((__force_kernel void *)____m(dst),
14634 + (__force_kernel const void *)____m(src), size);
14635 }
14636 }
14637
14638 static __must_check __always_inline int
14639 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
14640 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
14641 {
14642 - return copy_user_generic(dst, (__force const void *)src, size);
14643 + if (size > INT_MAX)
14644 + return size;
14645 +
14646 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14647 + if (!__access_ok(VERIFY_READ, src, size))
14648 + return size;
14649 +#endif
14650 +
14651 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14652 }
14653
14654 -static __must_check __always_inline int
14655 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
14656 +static __must_check __always_inline unsigned long
14657 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
14658 {
14659 - return copy_user_generic((__force void *)dst, src, size);
14660 + if (size > INT_MAX)
14661 + return size;
14662 +
14663 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14664 + if (!__access_ok(VERIFY_WRITE, dst, size))
14665 + return size;
14666 +#endif
14667 +
14668 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14669 }
14670
14671 -extern long __copy_user_nocache(void *dst, const void __user *src,
14672 - unsigned size, int zerorest);
14673 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
14674 + unsigned long size, int zerorest) __size_overflow(3);
14675
14676 -static inline int
14677 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
14678 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
14679 {
14680 might_sleep();
14681 +
14682 + if (size > INT_MAX)
14683 + return size;
14684 +
14685 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14686 + if (!__access_ok(VERIFY_READ, src, size))
14687 + return size;
14688 +#endif
14689 +
14690 return __copy_user_nocache(dst, src, size, 1);
14691 }
14692
14693 -static inline int
14694 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14695 - unsigned size)
14696 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14697 + unsigned long size)
14698 {
14699 + if (size > INT_MAX)
14700 + return size;
14701 +
14702 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14703 + if (!__access_ok(VERIFY_READ, src, size))
14704 + return size;
14705 +#endif
14706 +
14707 return __copy_user_nocache(dst, src, size, 0);
14708 }
14709
14710 -unsigned long
14711 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
14712 +extern unsigned long
14713 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
14714
14715 #endif /* _ASM_X86_UACCESS_64_H */
14716 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
14717 index 5b238981..77fdd78 100644
14718 --- a/arch/x86/include/asm/word-at-a-time.h
14719 +++ b/arch/x86/include/asm/word-at-a-time.h
14720 @@ -11,7 +11,7 @@
14721 * and shift, for example.
14722 */
14723 struct word_at_a_time {
14724 - const unsigned long one_bits, high_bits;
14725 + unsigned long one_bits, high_bits;
14726 };
14727
14728 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
14729 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
14730 index 0415cda..b43d877 100644
14731 --- a/arch/x86/include/asm/xsave.h
14732 +++ b/arch/x86/include/asm/xsave.h
14733 @@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14734 return -EFAULT;
14735
14736 __asm__ __volatile__(ASM_STAC "\n"
14737 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
14738 + "1:"
14739 + __copyuser_seg
14740 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
14741 "2: " ASM_CLAC "\n"
14742 ".section .fixup,\"ax\"\n"
14743 "3: movl $-1,%[err]\n"
14744 @@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14745 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
14746 {
14747 int err;
14748 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
14749 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
14750 u32 lmask = mask;
14751 u32 hmask = mask >> 32;
14752
14753 __asm__ __volatile__(ASM_STAC "\n"
14754 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14755 + "1:"
14756 + __copyuser_seg
14757 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14758 "2: " ASM_CLAC "\n"
14759 ".section .fixup,\"ax\"\n"
14760 "3: movl $-1,%[err]\n"
14761 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
14762 index 91ce48f..a48ea05 100644
14763 --- a/arch/x86/kernel/Makefile
14764 +++ b/arch/x86/kernel/Makefile
14765 @@ -23,7 +23,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
14766 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
14767 obj-$(CONFIG_IRQ_WORK) += irq_work.o
14768 obj-y += probe_roms.o
14769 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
14770 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
14771 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
14772 obj-y += syscall_$(BITS).o
14773 obj-$(CONFIG_X86_64) += vsyscall_64.o
14774 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
14775 index e651f7a..c995dc4 100644
14776 --- a/arch/x86/kernel/acpi/boot.c
14777 +++ b/arch/x86/kernel/acpi/boot.c
14778 @@ -1576,7 +1576,7 @@ int __init acpi_boot_init(void)
14779 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
14780
14781 if (!acpi_noirq)
14782 - x86_init.pci.init = pci_acpi_init;
14783 + *(void **)&x86_init.pci.init = pci_acpi_init;
14784
14785 return 0;
14786 }
14787 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
14788 index 11676cf..a8cf3ec 100644
14789 --- a/arch/x86/kernel/acpi/sleep.c
14790 +++ b/arch/x86/kernel/acpi/sleep.c
14791 @@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
14792 #else /* CONFIG_64BIT */
14793 #ifdef CONFIG_SMP
14794 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
14795 +
14796 + pax_open_kernel();
14797 early_gdt_descr.address =
14798 (unsigned long)get_cpu_gdt_table(smp_processor_id());
14799 + pax_close_kernel();
14800 +
14801 initial_gs = per_cpu_offset(smp_processor_id());
14802 #endif
14803 initial_code = (unsigned long)wakeup_long64;
14804 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
14805 index 13ab720..95d5442 100644
14806 --- a/arch/x86/kernel/acpi/wakeup_32.S
14807 +++ b/arch/x86/kernel/acpi/wakeup_32.S
14808 @@ -30,13 +30,11 @@ wakeup_pmode_return:
14809 # and restore the stack ... but you need gdt for this to work
14810 movl saved_context_esp, %esp
14811
14812 - movl %cs:saved_magic, %eax
14813 - cmpl $0x12345678, %eax
14814 + cmpl $0x12345678, saved_magic
14815 jne bogus_magic
14816
14817 # jump to place where we left off
14818 - movl saved_eip, %eax
14819 - jmp *%eax
14820 + jmp *(saved_eip)
14821
14822 bogus_magic:
14823 jmp bogus_magic
14824 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
14825 index ef5ccca..bd83949 100644
14826 --- a/arch/x86/kernel/alternative.c
14827 +++ b/arch/x86/kernel/alternative.c
14828 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
14829 */
14830 for (a = start; a < end; a++) {
14831 instr = (u8 *)&a->instr_offset + a->instr_offset;
14832 +
14833 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14834 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14835 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
14836 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14837 +#endif
14838 +
14839 replacement = (u8 *)&a->repl_offset + a->repl_offset;
14840 BUG_ON(a->replacementlen > a->instrlen);
14841 BUG_ON(a->instrlen > sizeof(insnbuf));
14842 @@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
14843 for (poff = start; poff < end; poff++) {
14844 u8 *ptr = (u8 *)poff + *poff;
14845
14846 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14847 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14848 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14849 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14850 +#endif
14851 +
14852 if (!*poff || ptr < text || ptr >= text_end)
14853 continue;
14854 /* turn DS segment override prefix into lock prefix */
14855 - if (*ptr == 0x3e)
14856 + if (*ktla_ktva(ptr) == 0x3e)
14857 text_poke(ptr, ((unsigned char []){0xf0}), 1);
14858 }
14859 mutex_unlock(&text_mutex);
14860 @@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
14861 for (poff = start; poff < end; poff++) {
14862 u8 *ptr = (u8 *)poff + *poff;
14863
14864 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14865 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14866 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14867 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14868 +#endif
14869 +
14870 if (!*poff || ptr < text || ptr >= text_end)
14871 continue;
14872 /* turn lock prefix into DS segment override prefix */
14873 - if (*ptr == 0xf0)
14874 + if (*ktla_ktva(ptr) == 0xf0)
14875 text_poke(ptr, ((unsigned char []){0x3E}), 1);
14876 }
14877 mutex_unlock(&text_mutex);
14878 @@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
14879
14880 BUG_ON(p->len > MAX_PATCH_LEN);
14881 /* prep the buffer with the original instructions */
14882 - memcpy(insnbuf, p->instr, p->len);
14883 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
14884 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
14885 (unsigned long)p->instr, p->len);
14886
14887 @@ -515,7 +534,7 @@ void __init alternative_instructions(void)
14888 if (!uniproc_patched || num_possible_cpus() == 1)
14889 free_init_pages("SMP alternatives",
14890 (unsigned long)__smp_locks,
14891 - (unsigned long)__smp_locks_end);
14892 + PAGE_ALIGN((unsigned long)__smp_locks_end));
14893 #endif
14894
14895 apply_paravirt(__parainstructions, __parainstructions_end);
14896 @@ -535,13 +554,17 @@ void __init alternative_instructions(void)
14897 * instructions. And on the local CPU you need to be protected again NMI or MCE
14898 * handlers seeing an inconsistent instruction while you patch.
14899 */
14900 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
14901 +void *__kprobes text_poke_early(void *addr, const void *opcode,
14902 size_t len)
14903 {
14904 unsigned long flags;
14905 local_irq_save(flags);
14906 - memcpy(addr, opcode, len);
14907 +
14908 + pax_open_kernel();
14909 + memcpy(ktla_ktva(addr), opcode, len);
14910 sync_core();
14911 + pax_close_kernel();
14912 +
14913 local_irq_restore(flags);
14914 /* Could also do a CLFLUSH here to speed up CPU recovery; but
14915 that causes hangs on some VIA CPUs. */
14916 @@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
14917 */
14918 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
14919 {
14920 - unsigned long flags;
14921 - char *vaddr;
14922 + unsigned char *vaddr = ktla_ktva(addr);
14923 struct page *pages[2];
14924 - int i;
14925 + size_t i;
14926
14927 if (!core_kernel_text((unsigned long)addr)) {
14928 - pages[0] = vmalloc_to_page(addr);
14929 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
14930 + pages[0] = vmalloc_to_page(vaddr);
14931 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
14932 } else {
14933 - pages[0] = virt_to_page(addr);
14934 + pages[0] = virt_to_page(vaddr);
14935 WARN_ON(!PageReserved(pages[0]));
14936 - pages[1] = virt_to_page(addr + PAGE_SIZE);
14937 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
14938 }
14939 BUG_ON(!pages[0]);
14940 - local_irq_save(flags);
14941 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
14942 - if (pages[1])
14943 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
14944 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
14945 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
14946 - clear_fixmap(FIX_TEXT_POKE0);
14947 - if (pages[1])
14948 - clear_fixmap(FIX_TEXT_POKE1);
14949 - local_flush_tlb();
14950 - sync_core();
14951 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
14952 - that causes hangs on some VIA CPUs. */
14953 + text_poke_early(addr, opcode, len);
14954 for (i = 0; i < len; i++)
14955 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
14956 - local_irq_restore(flags);
14957 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
14958 return addr;
14959 }
14960
14961 diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
14962 index e663112..21938a3 100644
14963 --- a/arch/x86/kernel/amd_gart_64.c
14964 +++ b/arch/x86/kernel/amd_gart_64.c
14965 @@ -851,7 +851,7 @@ int __init gart_iommu_init(void)
14966
14967 flush_gart();
14968 dma_ops = &gart_dma_ops;
14969 - x86_platform.iommu_shutdown = gart_iommu_shutdown;
14970 + *(void **)&x86_platform.iommu_shutdown = gart_iommu_shutdown;
14971 swiotlb = 0;
14972
14973 return 0;
14974 diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
14975 index d5fd66f..6119b16 100644
14976 --- a/arch/x86/kernel/aperture_64.c
14977 +++ b/arch/x86/kernel/aperture_64.c
14978 @@ -390,7 +390,7 @@ int __init gart_iommu_hole_init(void)
14979
14980 iommu_detected = 1;
14981 gart_iommu_aperture = 1;
14982 - x86_init.iommu.iommu_init = gart_iommu_init;
14983 + *(void **)&x86_init.iommu.iommu_init = gart_iommu_init;
14984
14985 ctl = read_pci_config(bus, slot, 3,
14986 AMD64_GARTAPERTURECTL);
14987 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
14988 index b17416e..be6e5dc 100644
14989 --- a/arch/x86/kernel/apic/apic.c
14990 +++ b/arch/x86/kernel/apic/apic.c
14991 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
14992 /*
14993 * Debug level, exported for io_apic.c
14994 */
14995 -unsigned int apic_verbosity;
14996 +int apic_verbosity;
14997
14998 int pic_mode;
14999
15000 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
15001 apic_write(APIC_ESR, 0);
15002 v1 = apic_read(APIC_ESR);
15003 ack_APIC_irq();
15004 - atomic_inc(&irq_err_count);
15005 + atomic_inc_unchecked(&irq_err_count);
15006
15007 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
15008 smp_processor_id(), v0 , v1);
15009 @@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
15010 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
15011 /* Should happen once for each apic */
15012 WARN_ON((*drv)->eoi_write == eoi_write);
15013 - (*drv)->eoi_write = eoi_write;
15014 + pax_open_kernel();
15015 + *(void **)&(*drv)->eoi_write = eoi_write;
15016 + pax_close_kernel();
15017 }
15018 }
15019
15020 diff --git a/arch/x86/kernel/apic/apic_numachip.c b/arch/x86/kernel/apic/apic_numachip.c
15021 index a65829a..6ddc249 100644
15022 --- a/arch/x86/kernel/apic/apic_numachip.c
15023 +++ b/arch/x86/kernel/apic/apic_numachip.c
15024 @@ -178,7 +178,7 @@ static int __init numachip_system_init(void)
15025 if (!numachip_system)
15026 return 0;
15027
15028 - x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
15029 + *(void **)&x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
15030
15031 map_csrs();
15032
15033 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
15034 index 1817fa9..7bff097 100644
15035 --- a/arch/x86/kernel/apic/io_apic.c
15036 +++ b/arch/x86/kernel/apic/io_apic.c
15037 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
15038 }
15039 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
15040
15041 -void lock_vector_lock(void)
15042 +void lock_vector_lock(void) __acquires(vector_lock)
15043 {
15044 /* Used to the online set of cpus does not change
15045 * during assign_irq_vector.
15046 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
15047 raw_spin_lock(&vector_lock);
15048 }
15049
15050 -void unlock_vector_lock(void)
15051 +void unlock_vector_lock(void) __releases(vector_lock)
15052 {
15053 raw_spin_unlock(&vector_lock);
15054 }
15055 @@ -2411,7 +2411,7 @@ static void ack_apic_edge(struct irq_data *data)
15056 ack_APIC_irq();
15057 }
15058
15059 -atomic_t irq_mis_count;
15060 +atomic_unchecked_t irq_mis_count;
15061
15062 #ifdef CONFIG_GENERIC_PENDING_IRQ
15063 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
15064 @@ -2552,7 +2552,7 @@ static void ack_apic_level(struct irq_data *data)
15065 * at the cpu.
15066 */
15067 if (!(v & (1 << (i & 0x1f)))) {
15068 - atomic_inc(&irq_mis_count);
15069 + atomic_inc_unchecked(&irq_mis_count);
15070
15071 eoi_ioapic_irq(irq, cfg);
15072 }
15073 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
15074 index d661ee9..512c0a1 100644
15075 --- a/arch/x86/kernel/apic/numaq_32.c
15076 +++ b/arch/x86/kernel/apic/numaq_32.c
15077 @@ -257,14 +257,14 @@ static __init void early_check_numaq(void)
15078 early_get_smp_config();
15079
15080 if (found_numaq) {
15081 - x86_init.mpparse.mpc_record = numaq_mpc_record;
15082 - x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
15083 - x86_init.mpparse.mpc_apic_id = mpc_apic_id;
15084 - x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
15085 - x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
15086 - x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
15087 - x86_init.timers.tsc_pre_init = numaq_tsc_init;
15088 - x86_init.pci.init = pci_numaq_init;
15089 + *(void **)&x86_init.mpparse.mpc_record = numaq_mpc_record;
15090 + *(void **)&x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
15091 + *(void **)&x86_init.mpparse.mpc_apic_id = mpc_apic_id;
15092 + *(void **)&x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
15093 + *(void **)&x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
15094 + *(void **)&x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
15095 + *(void **)&x86_init.timers.tsc_pre_init = numaq_tsc_init;
15096 + *(void **)&x86_init.pci.init = pci_numaq_init;
15097 }
15098 }
15099
15100 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
15101 index 8cfade9..8ea7b51 100644
15102 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
15103 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
15104 @@ -139,8 +139,8 @@ static int __init uv_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
15105 is_uv1 ? UV1_HUB_REVISION_BASE : UV2_HUB_REVISION_BASE;
15106 pnodeid = early_get_pnodeid();
15107 early_get_apic_pnode_shift();
15108 - x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
15109 - x86_platform.nmi_init = uv_nmi_init;
15110 + *(void **)&x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
15111 + *(void **)&x86_platform.nmi_init = uv_nmi_init;
15112 if (!strcmp(oem_table_id, "UVL"))
15113 uv_system_type = UV_LEGACY_APIC;
15114 else if (!strcmp(oem_table_id, "UVX"))
15115 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
15116 index d65464e..1035d31 100644
15117 --- a/arch/x86/kernel/apm_32.c
15118 +++ b/arch/x86/kernel/apm_32.c
15119 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
15120 * This is for buggy BIOS's that refer to (real mode) segment 0x40
15121 * even though they are called in protected mode.
15122 */
15123 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
15124 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
15125 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
15126
15127 static const char driver_version[] = "1.16ac"; /* no spaces */
15128 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
15129 BUG_ON(cpu != 0);
15130 gdt = get_cpu_gdt_table(cpu);
15131 save_desc_40 = gdt[0x40 / 8];
15132 +
15133 + pax_open_kernel();
15134 gdt[0x40 / 8] = bad_bios_desc;
15135 + pax_close_kernel();
15136
15137 apm_irq_save(flags);
15138 APM_DO_SAVE_SEGS;
15139 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
15140 &call->esi);
15141 APM_DO_RESTORE_SEGS;
15142 apm_irq_restore(flags);
15143 +
15144 + pax_open_kernel();
15145 gdt[0x40 / 8] = save_desc_40;
15146 + pax_close_kernel();
15147 +
15148 put_cpu();
15149
15150 return call->eax & 0xff;
15151 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
15152 BUG_ON(cpu != 0);
15153 gdt = get_cpu_gdt_table(cpu);
15154 save_desc_40 = gdt[0x40 / 8];
15155 +
15156 + pax_open_kernel();
15157 gdt[0x40 / 8] = bad_bios_desc;
15158 + pax_close_kernel();
15159
15160 apm_irq_save(flags);
15161 APM_DO_SAVE_SEGS;
15162 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
15163 &call->eax);
15164 APM_DO_RESTORE_SEGS;
15165 apm_irq_restore(flags);
15166 +
15167 + pax_open_kernel();
15168 gdt[0x40 / 8] = save_desc_40;
15169 + pax_close_kernel();
15170 +
15171 put_cpu();
15172 return error;
15173 }
15174 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
15175 * code to that CPU.
15176 */
15177 gdt = get_cpu_gdt_table(0);
15178 +
15179 + pax_open_kernel();
15180 set_desc_base(&gdt[APM_CS >> 3],
15181 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
15182 set_desc_base(&gdt[APM_CS_16 >> 3],
15183 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
15184 set_desc_base(&gdt[APM_DS >> 3],
15185 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
15186 + pax_close_kernel();
15187
15188 proc_create("apm", 0, NULL, &apm_file_ops);
15189
15190 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
15191 index 2861082..6d4718e 100644
15192 --- a/arch/x86/kernel/asm-offsets.c
15193 +++ b/arch/x86/kernel/asm-offsets.c
15194 @@ -33,6 +33,8 @@ void common(void) {
15195 OFFSET(TI_status, thread_info, status);
15196 OFFSET(TI_addr_limit, thread_info, addr_limit);
15197 OFFSET(TI_preempt_count, thread_info, preempt_count);
15198 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
15199 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
15200
15201 BLANK();
15202 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
15203 @@ -53,8 +55,26 @@ void common(void) {
15204 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
15205 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
15206 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
15207 +
15208 +#ifdef CONFIG_PAX_KERNEXEC
15209 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
15210 #endif
15211
15212 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15213 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
15214 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
15215 +#ifdef CONFIG_X86_64
15216 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
15217 +#endif
15218 +#endif
15219 +
15220 +#endif
15221 +
15222 + BLANK();
15223 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
15224 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
15225 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
15226 +
15227 #ifdef CONFIG_XEN
15228 BLANK();
15229 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
15230 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
15231 index 1b4754f..fbb4227 100644
15232 --- a/arch/x86/kernel/asm-offsets_64.c
15233 +++ b/arch/x86/kernel/asm-offsets_64.c
15234 @@ -76,6 +76,7 @@ int main(void)
15235 BLANK();
15236 #undef ENTRY
15237
15238 + DEFINE(TSS_size, sizeof(struct tss_struct));
15239 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
15240 BLANK();
15241
15242 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
15243 index a0e067d..9c7db16 100644
15244 --- a/arch/x86/kernel/cpu/Makefile
15245 +++ b/arch/x86/kernel/cpu/Makefile
15246 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
15247 CFLAGS_REMOVE_perf_event.o = -pg
15248 endif
15249
15250 -# Make sure load_percpu_segment has no stackprotector
15251 -nostackp := $(call cc-option, -fno-stack-protector)
15252 -CFLAGS_common.o := $(nostackp)
15253 -
15254 obj-y := intel_cacheinfo.o scattered.o topology.o
15255 obj-y += proc.o capflags.o powerflags.o common.o
15256 obj-y += vmware.o hypervisor.o mshyperv.o
15257 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
15258 index 1b7d165..b9e2627 100644
15259 --- a/arch/x86/kernel/cpu/amd.c
15260 +++ b/arch/x86/kernel/cpu/amd.c
15261 @@ -738,7 +738,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
15262 unsigned int size)
15263 {
15264 /* AMD errata T13 (order #21922) */
15265 - if ((c->x86 == 6)) {
15266 + if (c->x86 == 6) {
15267 /* Duron Rev A0 */
15268 if (c->x86_model == 3 && c->x86_mask == 0)
15269 size = 64;
15270 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
15271 index 7505f7b..d59dac0 100644
15272 --- a/arch/x86/kernel/cpu/common.c
15273 +++ b/arch/x86/kernel/cpu/common.c
15274 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
15275
15276 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
15277
15278 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
15279 -#ifdef CONFIG_X86_64
15280 - /*
15281 - * We need valid kernel segments for data and code in long mode too
15282 - * IRET will check the segment types kkeil 2000/10/28
15283 - * Also sysret mandates a special GDT layout
15284 - *
15285 - * TLS descriptors are currently at a different place compared to i386.
15286 - * Hopefully nobody expects them at a fixed place (Wine?)
15287 - */
15288 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
15289 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
15290 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
15291 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
15292 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
15293 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
15294 -#else
15295 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
15296 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15297 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
15298 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
15299 - /*
15300 - * Segments used for calling PnP BIOS have byte granularity.
15301 - * They code segments and data segments have fixed 64k limits,
15302 - * the transfer segment sizes are set at run time.
15303 - */
15304 - /* 32-bit code */
15305 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15306 - /* 16-bit code */
15307 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15308 - /* 16-bit data */
15309 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
15310 - /* 16-bit data */
15311 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
15312 - /* 16-bit data */
15313 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
15314 - /*
15315 - * The APM segments have byte granularity and their bases
15316 - * are set at run time. All have 64k limits.
15317 - */
15318 - /* 32-bit code */
15319 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15320 - /* 16-bit code */
15321 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15322 - /* data */
15323 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
15324 -
15325 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15326 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15327 - GDT_STACK_CANARY_INIT
15328 -#endif
15329 -} };
15330 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
15331 -
15332 static int __init x86_xsave_setup(char *s)
15333 {
15334 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
15335 @@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
15336 {
15337 struct desc_ptr gdt_descr;
15338
15339 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
15340 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
15341 gdt_descr.size = GDT_SIZE - 1;
15342 load_gdt(&gdt_descr);
15343 /* Reload the per-cpu base */
15344 @@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
15345 /* Filter out anything that depends on CPUID levels we don't have */
15346 filter_cpuid_features(c, true);
15347
15348 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
15349 + setup_clear_cpu_cap(X86_FEATURE_SEP);
15350 +#endif
15351 +
15352 /* If the model name is still unset, do table lookup. */
15353 if (!c->x86_model_id[0]) {
15354 const char *p;
15355 @@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
15356 }
15357 __setup("clearcpuid=", setup_disablecpuid);
15358
15359 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
15360 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
15361 +
15362 #ifdef CONFIG_X86_64
15363 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
15364 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
15365 - (unsigned long) nmi_idt_table };
15366 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
15367
15368 DEFINE_PER_CPU_FIRST(union irq_stack_union,
15369 irq_stack_union) __aligned(PAGE_SIZE);
15370 @@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
15371 EXPORT_PER_CPU_SYMBOL(current_task);
15372
15373 DEFINE_PER_CPU(unsigned long, kernel_stack) =
15374 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
15375 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
15376 EXPORT_PER_CPU_SYMBOL(kernel_stack);
15377
15378 DEFINE_PER_CPU(char *, irq_stack_ptr) =
15379 @@ -1178,7 +1130,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
15380 {
15381 memset(regs, 0, sizeof(struct pt_regs));
15382 regs->fs = __KERNEL_PERCPU;
15383 - regs->gs = __KERNEL_STACK_CANARY;
15384 + savesegment(gs, regs->gs);
15385
15386 return regs;
15387 }
15388 @@ -1233,7 +1185,7 @@ void __cpuinit cpu_init(void)
15389 int i;
15390
15391 cpu = stack_smp_processor_id();
15392 - t = &per_cpu(init_tss, cpu);
15393 + t = init_tss + cpu;
15394 oist = &per_cpu(orig_ist, cpu);
15395
15396 #ifdef CONFIG_NUMA
15397 @@ -1259,7 +1211,7 @@ void __cpuinit cpu_init(void)
15398 switch_to_new_gdt(cpu);
15399 loadsegment(fs, 0);
15400
15401 - load_idt((const struct desc_ptr *)&idt_descr);
15402 + load_idt(&idt_descr);
15403
15404 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
15405 syscall_init();
15406 @@ -1268,7 +1220,6 @@ void __cpuinit cpu_init(void)
15407 wrmsrl(MSR_KERNEL_GS_BASE, 0);
15408 barrier();
15409
15410 - x86_configure_nx();
15411 if (cpu != 0)
15412 enable_x2apic();
15413
15414 @@ -1321,7 +1272,7 @@ void __cpuinit cpu_init(void)
15415 {
15416 int cpu = smp_processor_id();
15417 struct task_struct *curr = current;
15418 - struct tss_struct *t = &per_cpu(init_tss, cpu);
15419 + struct tss_struct *t = init_tss + cpu;
15420 struct thread_struct *thread = &curr->thread;
15421
15422 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
15423 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
15424 index 198e019..867575e 100644
15425 --- a/arch/x86/kernel/cpu/intel.c
15426 +++ b/arch/x86/kernel/cpu/intel.c
15427 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
15428 * Update the IDT descriptor and reload the IDT so that
15429 * it uses the read-only mapped virtual address.
15430 */
15431 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
15432 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
15433 load_idt(&idt_descr);
15434 }
15435 #endif
15436 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
15437 index 93c5451..3887433 100644
15438 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
15439 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
15440 @@ -983,6 +983,22 @@ static struct attribute *default_attrs[] = {
15441 };
15442
15443 #ifdef CONFIG_AMD_NB
15444 +static struct attribute *default_attrs_amd_nb[] = {
15445 + &type.attr,
15446 + &level.attr,
15447 + &coherency_line_size.attr,
15448 + &physical_line_partition.attr,
15449 + &ways_of_associativity.attr,
15450 + &number_of_sets.attr,
15451 + &size.attr,
15452 + &shared_cpu_map.attr,
15453 + &shared_cpu_list.attr,
15454 + NULL,
15455 + NULL,
15456 + NULL,
15457 + NULL
15458 +};
15459 +
15460 static struct attribute ** __cpuinit amd_l3_attrs(void)
15461 {
15462 static struct attribute **attrs;
15463 @@ -993,18 +1009,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
15464
15465 n = ARRAY_SIZE(default_attrs);
15466
15467 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
15468 - n += 2;
15469 -
15470 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
15471 - n += 1;
15472 -
15473 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
15474 - if (attrs == NULL)
15475 - return attrs = default_attrs;
15476 -
15477 - for (n = 0; default_attrs[n]; n++)
15478 - attrs[n] = default_attrs[n];
15479 + attrs = default_attrs_amd_nb;
15480
15481 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
15482 attrs[n++] = &cache_disable_0.attr;
15483 @@ -1055,6 +1060,13 @@ static struct kobj_type ktype_cache = {
15484 .default_attrs = default_attrs,
15485 };
15486
15487 +#ifdef CONFIG_AMD_NB
15488 +static struct kobj_type ktype_cache_amd_nb = {
15489 + .sysfs_ops = &sysfs_ops,
15490 + .default_attrs = default_attrs_amd_nb,
15491 +};
15492 +#endif
15493 +
15494 static struct kobj_type ktype_percpu_entry = {
15495 .sysfs_ops = &sysfs_ops,
15496 };
15497 @@ -1120,20 +1132,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
15498 return retval;
15499 }
15500
15501 +#ifdef CONFIG_AMD_NB
15502 + amd_l3_attrs();
15503 +#endif
15504 +
15505 for (i = 0; i < num_cache_leaves; i++) {
15506 + struct kobj_type *ktype;
15507 +
15508 this_object = INDEX_KOBJECT_PTR(cpu, i);
15509 this_object->cpu = cpu;
15510 this_object->index = i;
15511
15512 this_leaf = CPUID4_INFO_IDX(cpu, i);
15513
15514 - ktype_cache.default_attrs = default_attrs;
15515 + ktype = &ktype_cache;
15516 #ifdef CONFIG_AMD_NB
15517 if (this_leaf->base.nb)
15518 - ktype_cache.default_attrs = amd_l3_attrs();
15519 + ktype = &ktype_cache_amd_nb;
15520 #endif
15521 retval = kobject_init_and_add(&(this_object->kobj),
15522 - &ktype_cache,
15523 + ktype,
15524 per_cpu(ici_cache_kobject, cpu),
15525 "index%1lu", i);
15526 if (unlikely(retval)) {
15527 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
15528 index 46cbf86..55c7292 100644
15529 --- a/arch/x86/kernel/cpu/mcheck/mce.c
15530 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
15531 @@ -45,6 +45,7 @@
15532 #include <asm/processor.h>
15533 #include <asm/mce.h>
15534 #include <asm/msr.h>
15535 +#include <asm/local.h>
15536
15537 #include "mce-internal.h"
15538
15539 @@ -254,7 +255,7 @@ static void print_mce(struct mce *m)
15540 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
15541 m->cs, m->ip);
15542
15543 - if (m->cs == __KERNEL_CS)
15544 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
15545 print_symbol("{%s}", m->ip);
15546 pr_cont("\n");
15547 }
15548 @@ -287,10 +288,10 @@ static void print_mce(struct mce *m)
15549
15550 #define PANIC_TIMEOUT 5 /* 5 seconds */
15551
15552 -static atomic_t mce_paniced;
15553 +static atomic_unchecked_t mce_paniced;
15554
15555 static int fake_panic;
15556 -static atomic_t mce_fake_paniced;
15557 +static atomic_unchecked_t mce_fake_paniced;
15558
15559 /* Panic in progress. Enable interrupts and wait for final IPI */
15560 static void wait_for_panic(void)
15561 @@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15562 /*
15563 * Make sure only one CPU runs in machine check panic
15564 */
15565 - if (atomic_inc_return(&mce_paniced) > 1)
15566 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
15567 wait_for_panic();
15568 barrier();
15569
15570 @@ -322,7 +323,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15571 console_verbose();
15572 } else {
15573 /* Don't log too much for fake panic */
15574 - if (atomic_inc_return(&mce_fake_paniced) > 1)
15575 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
15576 return;
15577 }
15578 /* First print corrected ones that are still unlogged */
15579 @@ -694,7 +695,7 @@ static int mce_timed_out(u64 *t)
15580 * might have been modified by someone else.
15581 */
15582 rmb();
15583 - if (atomic_read(&mce_paniced))
15584 + if (atomic_read_unchecked(&mce_paniced))
15585 wait_for_panic();
15586 if (!monarch_timeout)
15587 goto out;
15588 @@ -1659,7 +1660,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
15589 }
15590
15591 /* Call the installed machine check handler for this CPU setup. */
15592 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
15593 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
15594 unexpected_machine_check;
15595
15596 /*
15597 @@ -1682,7 +1683,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15598 return;
15599 }
15600
15601 + pax_open_kernel();
15602 machine_check_vector = do_machine_check;
15603 + pax_close_kernel();
15604
15605 __mcheck_cpu_init_generic();
15606 __mcheck_cpu_init_vendor(c);
15607 @@ -1696,7 +1699,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15608 */
15609
15610 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
15611 -static int mce_chrdev_open_count; /* #times opened */
15612 +static local_t mce_chrdev_open_count; /* #times opened */
15613 static int mce_chrdev_open_exclu; /* already open exclusive? */
15614
15615 static int mce_chrdev_open(struct inode *inode, struct file *file)
15616 @@ -1704,7 +1707,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15617 spin_lock(&mce_chrdev_state_lock);
15618
15619 if (mce_chrdev_open_exclu ||
15620 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
15621 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
15622 spin_unlock(&mce_chrdev_state_lock);
15623
15624 return -EBUSY;
15625 @@ -1712,7 +1715,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15626
15627 if (file->f_flags & O_EXCL)
15628 mce_chrdev_open_exclu = 1;
15629 - mce_chrdev_open_count++;
15630 + local_inc(&mce_chrdev_open_count);
15631
15632 spin_unlock(&mce_chrdev_state_lock);
15633
15634 @@ -1723,7 +1726,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
15635 {
15636 spin_lock(&mce_chrdev_state_lock);
15637
15638 - mce_chrdev_open_count--;
15639 + local_dec(&mce_chrdev_open_count);
15640 mce_chrdev_open_exclu = 0;
15641
15642 spin_unlock(&mce_chrdev_state_lock);
15643 @@ -2367,7 +2370,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
15644 return NOTIFY_OK;
15645 }
15646
15647 -static struct notifier_block mce_cpu_notifier __cpuinitdata = {
15648 +static struct notifier_block mce_cpu_notifier __cpuinitconst = {
15649 .notifier_call = mce_cpu_callback,
15650 };
15651
15652 @@ -2445,7 +2448,7 @@ struct dentry *mce_get_debugfs_dir(void)
15653 static void mce_reset(void)
15654 {
15655 cpu_missing = 0;
15656 - atomic_set(&mce_fake_paniced, 0);
15657 + atomic_set_unchecked(&mce_fake_paniced, 0);
15658 atomic_set(&mce_executing, 0);
15659 atomic_set(&mce_callin, 0);
15660 atomic_set(&global_nwo, 0);
15661 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
15662 index 2d5454c..51987eb 100644
15663 --- a/arch/x86/kernel/cpu/mcheck/p5.c
15664 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
15665 @@ -11,6 +11,7 @@
15666 #include <asm/processor.h>
15667 #include <asm/mce.h>
15668 #include <asm/msr.h>
15669 +#include <asm/pgtable.h>
15670
15671 /* By default disabled */
15672 int mce_p5_enabled __read_mostly;
15673 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
15674 if (!cpu_has(c, X86_FEATURE_MCE))
15675 return;
15676
15677 + pax_open_kernel();
15678 machine_check_vector = pentium_machine_check;
15679 + pax_close_kernel();
15680 /* Make sure the vector pointer is visible before we enable MCEs: */
15681 wmb();
15682
15683 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
15684 index 2d7998f..17c9de1 100644
15685 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
15686 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
15687 @@ -10,6 +10,7 @@
15688 #include <asm/processor.h>
15689 #include <asm/mce.h>
15690 #include <asm/msr.h>
15691 +#include <asm/pgtable.h>
15692
15693 /* Machine check handler for WinChip C6: */
15694 static void winchip_machine_check(struct pt_regs *regs, long error_code)
15695 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
15696 {
15697 u32 lo, hi;
15698
15699 + pax_open_kernel();
15700 machine_check_vector = winchip_machine_check;
15701 + pax_close_kernel();
15702 /* Make sure the vector pointer is visible before we enable MCEs: */
15703 wmb();
15704
15705 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
15706 index 6b96110..0da73eb 100644
15707 --- a/arch/x86/kernel/cpu/mtrr/main.c
15708 +++ b/arch/x86/kernel/cpu/mtrr/main.c
15709 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
15710 u64 size_or_mask, size_and_mask;
15711 static bool mtrr_aps_delayed_init;
15712
15713 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
15714 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
15715
15716 const struct mtrr_ops *mtrr_if;
15717
15718 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
15719 index df5e41f..816c719 100644
15720 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
15721 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
15722 @@ -25,7 +25,7 @@ struct mtrr_ops {
15723 int (*validate_add_page)(unsigned long base, unsigned long size,
15724 unsigned int type);
15725 int (*have_wrcomb)(void);
15726 -};
15727 +} __do_const;
15728
15729 extern int generic_get_free_region(unsigned long base, unsigned long size,
15730 int replace_reg);
15731 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
15732 index d18b2b8..d3b834c 100644
15733 --- a/arch/x86/kernel/cpu/perf_event.c
15734 +++ b/arch/x86/kernel/cpu/perf_event.c
15735 @@ -1759,7 +1759,7 @@ static unsigned long get_segment_base(unsigned int segment)
15736 if (idx > GDT_ENTRIES)
15737 return 0;
15738
15739 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
15740 + desc = get_cpu_gdt_table(smp_processor_id());
15741 }
15742
15743 return get_desc_base(desc + idx);
15744 @@ -1849,7 +1849,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
15745 break;
15746
15747 perf_callchain_store(entry, frame.return_address);
15748 - fp = frame.next_frame;
15749 + fp = (const void __force_user *)frame.next_frame;
15750 }
15751 }
15752
15753 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
15754 index 324bb52..1a93d85 100644
15755 --- a/arch/x86/kernel/cpu/perf_event_intel.c
15756 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
15757 @@ -1949,10 +1949,10 @@ __init int intel_pmu_init(void)
15758 * v2 and above have a perf capabilities MSR
15759 */
15760 if (version > 1) {
15761 - u64 capabilities;
15762 + u64 capabilities = x86_pmu.intel_cap.capabilities;
15763
15764 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
15765 - x86_pmu.intel_cap.capabilities = capabilities;
15766 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
15767 + x86_pmu.intel_cap.capabilities = capabilities;
15768 }
15769
15770 intel_ds_init();
15771 diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
15772 index d22d0c4..088eb6f 100644
15773 --- a/arch/x86/kernel/cpu/vmware.c
15774 +++ b/arch/x86/kernel/cpu/vmware.c
15775 @@ -79,7 +79,7 @@ static void __init vmware_platform_setup(void)
15776 VMWARE_PORT(GETHZ, eax, ebx, ecx, edx);
15777
15778 if (ebx != UINT_MAX)
15779 - x86_platform.calibrate_tsc = vmware_get_tsc_khz;
15780 + *(void **)&x86_platform.calibrate_tsc = vmware_get_tsc_khz;
15781 else
15782 printk(KERN_WARNING
15783 "Failed to get TSC freq from the hypervisor\n");
15784 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
15785 index 13ad899..f642b9a 100644
15786 --- a/arch/x86/kernel/crash.c
15787 +++ b/arch/x86/kernel/crash.c
15788 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
15789 {
15790 #ifdef CONFIG_X86_32
15791 struct pt_regs fixed_regs;
15792 -#endif
15793
15794 -#ifdef CONFIG_X86_32
15795 - if (!user_mode_vm(regs)) {
15796 + if (!user_mode(regs)) {
15797 crash_fixup_ss_esp(&fixed_regs, regs);
15798 regs = &fixed_regs;
15799 }
15800 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
15801 index 37250fe..bf2ec74 100644
15802 --- a/arch/x86/kernel/doublefault_32.c
15803 +++ b/arch/x86/kernel/doublefault_32.c
15804 @@ -11,7 +11,7 @@
15805
15806 #define DOUBLEFAULT_STACKSIZE (1024)
15807 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
15808 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
15809 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
15810
15811 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
15812
15813 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
15814 unsigned long gdt, tss;
15815
15816 store_gdt(&gdt_desc);
15817 - gdt = gdt_desc.address;
15818 + gdt = (unsigned long)gdt_desc.address;
15819
15820 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
15821
15822 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
15823 /* 0x2 bit is always set */
15824 .flags = X86_EFLAGS_SF | 0x2,
15825 .sp = STACK_START,
15826 - .es = __USER_DS,
15827 + .es = __KERNEL_DS,
15828 .cs = __KERNEL_CS,
15829 .ss = __KERNEL_DS,
15830 - .ds = __USER_DS,
15831 + .ds = __KERNEL_DS,
15832 .fs = __KERNEL_PERCPU,
15833
15834 .__cr3 = __pa_nodebug(swapper_pg_dir),
15835 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
15836 index ae42418b..787c16b 100644
15837 --- a/arch/x86/kernel/dumpstack.c
15838 +++ b/arch/x86/kernel/dumpstack.c
15839 @@ -2,6 +2,9 @@
15840 * Copyright (C) 1991, 1992 Linus Torvalds
15841 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
15842 */
15843 +#ifdef CONFIG_GRKERNSEC_HIDESYM
15844 +#define __INCLUDED_BY_HIDESYM 1
15845 +#endif
15846 #include <linux/kallsyms.h>
15847 #include <linux/kprobes.h>
15848 #include <linux/uaccess.h>
15849 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
15850 static void
15851 print_ftrace_graph_addr(unsigned long addr, void *data,
15852 const struct stacktrace_ops *ops,
15853 - struct thread_info *tinfo, int *graph)
15854 + struct task_struct *task, int *graph)
15855 {
15856 - struct task_struct *task;
15857 unsigned long ret_addr;
15858 int index;
15859
15860 if (addr != (unsigned long)return_to_handler)
15861 return;
15862
15863 - task = tinfo->task;
15864 index = task->curr_ret_stack;
15865
15866 if (!task->ret_stack || index < *graph)
15867 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15868 static inline void
15869 print_ftrace_graph_addr(unsigned long addr, void *data,
15870 const struct stacktrace_ops *ops,
15871 - struct thread_info *tinfo, int *graph)
15872 + struct task_struct *task, int *graph)
15873 { }
15874 #endif
15875
15876 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15877 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
15878 */
15879
15880 -static inline int valid_stack_ptr(struct thread_info *tinfo,
15881 - void *p, unsigned int size, void *end)
15882 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
15883 {
15884 - void *t = tinfo;
15885 if (end) {
15886 if (p < end && p >= (end-THREAD_SIZE))
15887 return 1;
15888 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
15889 }
15890
15891 unsigned long
15892 -print_context_stack(struct thread_info *tinfo,
15893 +print_context_stack(struct task_struct *task, void *stack_start,
15894 unsigned long *stack, unsigned long bp,
15895 const struct stacktrace_ops *ops, void *data,
15896 unsigned long *end, int *graph)
15897 {
15898 struct stack_frame *frame = (struct stack_frame *)bp;
15899
15900 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
15901 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
15902 unsigned long addr;
15903
15904 addr = *stack;
15905 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
15906 } else {
15907 ops->address(data, addr, 0);
15908 }
15909 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15910 + print_ftrace_graph_addr(addr, data, ops, task, graph);
15911 }
15912 stack++;
15913 }
15914 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
15915 EXPORT_SYMBOL_GPL(print_context_stack);
15916
15917 unsigned long
15918 -print_context_stack_bp(struct thread_info *tinfo,
15919 +print_context_stack_bp(struct task_struct *task, void *stack_start,
15920 unsigned long *stack, unsigned long bp,
15921 const struct stacktrace_ops *ops, void *data,
15922 unsigned long *end, int *graph)
15923 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
15924 struct stack_frame *frame = (struct stack_frame *)bp;
15925 unsigned long *ret_addr = &frame->return_address;
15926
15927 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
15928 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
15929 unsigned long addr = *ret_addr;
15930
15931 if (!__kernel_text_address(addr))
15932 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
15933 ops->address(data, addr, 1);
15934 frame = frame->next_frame;
15935 ret_addr = &frame->return_address;
15936 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15937 + print_ftrace_graph_addr(addr, data, ops, task, graph);
15938 }
15939
15940 return (unsigned long)frame;
15941 @@ -189,7 +188,7 @@ void dump_stack(void)
15942
15943 bp = stack_frame(current, NULL);
15944 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
15945 - current->pid, current->comm, print_tainted(),
15946 + task_pid_nr(current), current->comm, print_tainted(),
15947 init_utsname()->release,
15948 (int)strcspn(init_utsname()->version, " "),
15949 init_utsname()->version);
15950 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
15951 }
15952 EXPORT_SYMBOL_GPL(oops_begin);
15953
15954 +extern void gr_handle_kernel_exploit(void);
15955 +
15956 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
15957 {
15958 if (regs && kexec_should_crash(current))
15959 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
15960 panic("Fatal exception in interrupt");
15961 if (panic_on_oops)
15962 panic("Fatal exception");
15963 - do_exit(signr);
15964 +
15965 + gr_handle_kernel_exploit();
15966 +
15967 + do_group_exit(signr);
15968 }
15969
15970 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
15971 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
15972 print_modules();
15973 show_regs(regs);
15974 #ifdef CONFIG_X86_32
15975 - if (user_mode_vm(regs)) {
15976 + if (user_mode(regs)) {
15977 sp = regs->sp;
15978 ss = regs->ss & 0xffff;
15979 } else {
15980 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
15981 unsigned long flags = oops_begin();
15982 int sig = SIGSEGV;
15983
15984 - if (!user_mode_vm(regs))
15985 + if (!user_mode(regs))
15986 report_bug(regs->ip, regs);
15987
15988 if (__die(str, regs, err))
15989 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
15990 index 1038a41..db2c12b 100644
15991 --- a/arch/x86/kernel/dumpstack_32.c
15992 +++ b/arch/x86/kernel/dumpstack_32.c
15993 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15994 bp = stack_frame(task, regs);
15995
15996 for (;;) {
15997 - struct thread_info *context;
15998 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
15999
16000 - context = (struct thread_info *)
16001 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
16002 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
16003 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
16004
16005 - stack = (unsigned long *)context->previous_esp;
16006 - if (!stack)
16007 + if (stack_start == task_stack_page(task))
16008 break;
16009 + stack = *(unsigned long **)stack_start;
16010 if (ops->stack(data, "IRQ") < 0)
16011 break;
16012 touch_nmi_watchdog();
16013 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
16014 {
16015 int i;
16016
16017 - __show_regs(regs, !user_mode_vm(regs));
16018 + __show_regs(regs, !user_mode(regs));
16019
16020 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
16021 TASK_COMM_LEN, current->comm, task_pid_nr(current),
16022 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
16023 * When in-kernel, we also print out the stack and code at the
16024 * time of the fault..
16025 */
16026 - if (!user_mode_vm(regs)) {
16027 + if (!user_mode(regs)) {
16028 unsigned int code_prologue = code_bytes * 43 / 64;
16029 unsigned int code_len = code_bytes;
16030 unsigned char c;
16031 u8 *ip;
16032 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
16033
16034 pr_emerg("Stack:\n");
16035 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
16036
16037 pr_emerg("Code:");
16038
16039 - ip = (u8 *)regs->ip - code_prologue;
16040 + ip = (u8 *)regs->ip - code_prologue + cs_base;
16041 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
16042 /* try starting at IP */
16043 - ip = (u8 *)regs->ip;
16044 + ip = (u8 *)regs->ip + cs_base;
16045 code_len = code_len - code_prologue + 1;
16046 }
16047 for (i = 0; i < code_len; i++, ip++) {
16048 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
16049 pr_cont(" Bad EIP value.");
16050 break;
16051 }
16052 - if (ip == (u8 *)regs->ip)
16053 + if (ip == (u8 *)regs->ip + cs_base)
16054 pr_cont(" <%02x>", c);
16055 else
16056 pr_cont(" %02x", c);
16057 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
16058 {
16059 unsigned short ud2;
16060
16061 + ip = ktla_ktva(ip);
16062 if (ip < PAGE_OFFSET)
16063 return 0;
16064 if (probe_kernel_address((unsigned short *)ip, ud2))
16065 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
16066
16067 return ud2 == 0x0b0f;
16068 }
16069 +
16070 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16071 +void pax_check_alloca(unsigned long size)
16072 +{
16073 + unsigned long sp = (unsigned long)&sp, stack_left;
16074 +
16075 + /* all kernel stacks are of the same size */
16076 + stack_left = sp & (THREAD_SIZE - 1);
16077 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16078 +}
16079 +EXPORT_SYMBOL(pax_check_alloca);
16080 +#endif
16081 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
16082 index b653675..51cc8c0 100644
16083 --- a/arch/x86/kernel/dumpstack_64.c
16084 +++ b/arch/x86/kernel/dumpstack_64.c
16085 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16086 unsigned long *irq_stack_end =
16087 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
16088 unsigned used = 0;
16089 - struct thread_info *tinfo;
16090 int graph = 0;
16091 unsigned long dummy;
16092 + void *stack_start;
16093
16094 if (!task)
16095 task = current;
16096 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16097 * current stack address. If the stacks consist of nested
16098 * exceptions
16099 */
16100 - tinfo = task_thread_info(task);
16101 for (;;) {
16102 char *id;
16103 unsigned long *estack_end;
16104 +
16105 estack_end = in_exception_stack(cpu, (unsigned long)stack,
16106 &used, &id);
16107
16108 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16109 if (ops->stack(data, id) < 0)
16110 break;
16111
16112 - bp = ops->walk_stack(tinfo, stack, bp, ops,
16113 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
16114 data, estack_end, &graph);
16115 ops->stack(data, "<EOE>");
16116 /*
16117 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16118 * second-to-last pointer (index -2 to end) in the
16119 * exception stack:
16120 */
16121 + if ((u16)estack_end[-1] != __KERNEL_DS)
16122 + goto out;
16123 stack = (unsigned long *) estack_end[-2];
16124 continue;
16125 }
16126 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16127 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
16128 if (ops->stack(data, "IRQ") < 0)
16129 break;
16130 - bp = ops->walk_stack(tinfo, stack, bp,
16131 + bp = ops->walk_stack(task, irq_stack, stack, bp,
16132 ops, data, irq_stack_end, &graph);
16133 /*
16134 * We link to the next stack (which would be
16135 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16136 /*
16137 * This handles the process stack:
16138 */
16139 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
16140 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
16141 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
16142 +out:
16143 put_cpu();
16144 }
16145 EXPORT_SYMBOL(dump_trace);
16146 @@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
16147 {
16148 int i;
16149 unsigned long sp;
16150 - const int cpu = smp_processor_id();
16151 + const int cpu = raw_smp_processor_id();
16152 struct task_struct *cur = current;
16153
16154 sp = regs->sp;
16155 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
16156
16157 return ud2 == 0x0b0f;
16158 }
16159 +
16160 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16161 +void pax_check_alloca(unsigned long size)
16162 +{
16163 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
16164 + unsigned cpu, used;
16165 + char *id;
16166 +
16167 + /* check the process stack first */
16168 + stack_start = (unsigned long)task_stack_page(current);
16169 + stack_end = stack_start + THREAD_SIZE;
16170 + if (likely(stack_start <= sp && sp < stack_end)) {
16171 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
16172 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16173 + return;
16174 + }
16175 +
16176 + cpu = get_cpu();
16177 +
16178 + /* check the irq stacks */
16179 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
16180 + stack_start = stack_end - IRQ_STACK_SIZE;
16181 + if (stack_start <= sp && sp < stack_end) {
16182 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
16183 + put_cpu();
16184 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16185 + return;
16186 + }
16187 +
16188 + /* check the exception stacks */
16189 + used = 0;
16190 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
16191 + stack_start = stack_end - EXCEPTION_STKSZ;
16192 + if (stack_end && stack_start <= sp && sp < stack_end) {
16193 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
16194 + put_cpu();
16195 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
16196 + return;
16197 + }
16198 +
16199 + put_cpu();
16200 +
16201 + /* unknown stack */
16202 + BUG();
16203 +}
16204 +EXPORT_SYMBOL(pax_check_alloca);
16205 +#endif
16206 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
16207 index 9b9f18b..9fcaa04 100644
16208 --- a/arch/x86/kernel/early_printk.c
16209 +++ b/arch/x86/kernel/early_printk.c
16210 @@ -7,6 +7,7 @@
16211 #include <linux/pci_regs.h>
16212 #include <linux/pci_ids.h>
16213 #include <linux/errno.h>
16214 +#include <linux/sched.h>
16215 #include <asm/io.h>
16216 #include <asm/processor.h>
16217 #include <asm/fcntl.h>
16218 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
16219 index cf8639b..6c6a674 100644
16220 --- a/arch/x86/kernel/entry_32.S
16221 +++ b/arch/x86/kernel/entry_32.S
16222 @@ -177,13 +177,153 @@
16223 /*CFI_REL_OFFSET gs, PT_GS*/
16224 .endm
16225 .macro SET_KERNEL_GS reg
16226 +
16227 +#ifdef CONFIG_CC_STACKPROTECTOR
16228 movl $(__KERNEL_STACK_CANARY), \reg
16229 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16230 + movl $(__USER_DS), \reg
16231 +#else
16232 + xorl \reg, \reg
16233 +#endif
16234 +
16235 movl \reg, %gs
16236 .endm
16237
16238 #endif /* CONFIG_X86_32_LAZY_GS */
16239
16240 -.macro SAVE_ALL
16241 +.macro pax_enter_kernel
16242 +#ifdef CONFIG_PAX_KERNEXEC
16243 + call pax_enter_kernel
16244 +#endif
16245 +.endm
16246 +
16247 +.macro pax_exit_kernel
16248 +#ifdef CONFIG_PAX_KERNEXEC
16249 + call pax_exit_kernel
16250 +#endif
16251 +.endm
16252 +
16253 +#ifdef CONFIG_PAX_KERNEXEC
16254 +ENTRY(pax_enter_kernel)
16255 +#ifdef CONFIG_PARAVIRT
16256 + pushl %eax
16257 + pushl %ecx
16258 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
16259 + mov %eax, %esi
16260 +#else
16261 + mov %cr0, %esi
16262 +#endif
16263 + bts $16, %esi
16264 + jnc 1f
16265 + mov %cs, %esi
16266 + cmp $__KERNEL_CS, %esi
16267 + jz 3f
16268 + ljmp $__KERNEL_CS, $3f
16269 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
16270 +2:
16271 +#ifdef CONFIG_PARAVIRT
16272 + mov %esi, %eax
16273 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16274 +#else
16275 + mov %esi, %cr0
16276 +#endif
16277 +3:
16278 +#ifdef CONFIG_PARAVIRT
16279 + popl %ecx
16280 + popl %eax
16281 +#endif
16282 + ret
16283 +ENDPROC(pax_enter_kernel)
16284 +
16285 +ENTRY(pax_exit_kernel)
16286 +#ifdef CONFIG_PARAVIRT
16287 + pushl %eax
16288 + pushl %ecx
16289 +#endif
16290 + mov %cs, %esi
16291 + cmp $__KERNEXEC_KERNEL_CS, %esi
16292 + jnz 2f
16293 +#ifdef CONFIG_PARAVIRT
16294 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
16295 + mov %eax, %esi
16296 +#else
16297 + mov %cr0, %esi
16298 +#endif
16299 + btr $16, %esi
16300 + ljmp $__KERNEL_CS, $1f
16301 +1:
16302 +#ifdef CONFIG_PARAVIRT
16303 + mov %esi, %eax
16304 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
16305 +#else
16306 + mov %esi, %cr0
16307 +#endif
16308 +2:
16309 +#ifdef CONFIG_PARAVIRT
16310 + popl %ecx
16311 + popl %eax
16312 +#endif
16313 + ret
16314 +ENDPROC(pax_exit_kernel)
16315 +#endif
16316 +
16317 +.macro pax_erase_kstack
16318 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16319 + call pax_erase_kstack
16320 +#endif
16321 +.endm
16322 +
16323 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16324 +/*
16325 + * ebp: thread_info
16326 + */
16327 +ENTRY(pax_erase_kstack)
16328 + pushl %edi
16329 + pushl %ecx
16330 + pushl %eax
16331 +
16332 + mov TI_lowest_stack(%ebp), %edi
16333 + mov $-0xBEEF, %eax
16334 + std
16335 +
16336 +1: mov %edi, %ecx
16337 + and $THREAD_SIZE_asm - 1, %ecx
16338 + shr $2, %ecx
16339 + repne scasl
16340 + jecxz 2f
16341 +
16342 + cmp $2*16, %ecx
16343 + jc 2f
16344 +
16345 + mov $2*16, %ecx
16346 + repe scasl
16347 + jecxz 2f
16348 + jne 1b
16349 +
16350 +2: cld
16351 + mov %esp, %ecx
16352 + sub %edi, %ecx
16353 +
16354 + cmp $THREAD_SIZE_asm, %ecx
16355 + jb 3f
16356 + ud2
16357 +3:
16358 +
16359 + shr $2, %ecx
16360 + rep stosl
16361 +
16362 + mov TI_task_thread_sp0(%ebp), %edi
16363 + sub $128, %edi
16364 + mov %edi, TI_lowest_stack(%ebp)
16365 +
16366 + popl %eax
16367 + popl %ecx
16368 + popl %edi
16369 + ret
16370 +ENDPROC(pax_erase_kstack)
16371 +#endif
16372 +
16373 +.macro __SAVE_ALL _DS
16374 cld
16375 PUSH_GS
16376 pushl_cfi %fs
16377 @@ -206,7 +346,7 @@
16378 CFI_REL_OFFSET ecx, 0
16379 pushl_cfi %ebx
16380 CFI_REL_OFFSET ebx, 0
16381 - movl $(__USER_DS), %edx
16382 + movl $\_DS, %edx
16383 movl %edx, %ds
16384 movl %edx, %es
16385 movl $(__KERNEL_PERCPU), %edx
16386 @@ -214,6 +354,15 @@
16387 SET_KERNEL_GS %edx
16388 .endm
16389
16390 +.macro SAVE_ALL
16391 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
16392 + __SAVE_ALL __KERNEL_DS
16393 + pax_enter_kernel
16394 +#else
16395 + __SAVE_ALL __USER_DS
16396 +#endif
16397 +.endm
16398 +
16399 .macro RESTORE_INT_REGS
16400 popl_cfi %ebx
16401 CFI_RESTORE ebx
16402 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
16403 popfl_cfi
16404 jmp syscall_exit
16405 CFI_ENDPROC
16406 -END(ret_from_fork)
16407 +ENDPROC(ret_from_fork)
16408
16409 ENTRY(ret_from_kernel_thread)
16410 CFI_STARTPROC
16411 @@ -344,7 +493,15 @@ ret_from_intr:
16412 andl $SEGMENT_RPL_MASK, %eax
16413 #endif
16414 cmpl $USER_RPL, %eax
16415 +
16416 +#ifdef CONFIG_PAX_KERNEXEC
16417 + jae resume_userspace
16418 +
16419 + pax_exit_kernel
16420 + jmp resume_kernel
16421 +#else
16422 jb resume_kernel # not returning to v8086 or userspace
16423 +#endif
16424
16425 ENTRY(resume_userspace)
16426 LOCKDEP_SYS_EXIT
16427 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
16428 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
16429 # int/exception return?
16430 jne work_pending
16431 - jmp restore_all
16432 -END(ret_from_exception)
16433 + jmp restore_all_pax
16434 +ENDPROC(ret_from_exception)
16435
16436 #ifdef CONFIG_PREEMPT
16437 ENTRY(resume_kernel)
16438 @@ -372,7 +529,7 @@ need_resched:
16439 jz restore_all
16440 call preempt_schedule_irq
16441 jmp need_resched
16442 -END(resume_kernel)
16443 +ENDPROC(resume_kernel)
16444 #endif
16445 CFI_ENDPROC
16446 /*
16447 @@ -406,30 +563,45 @@ sysenter_past_esp:
16448 /*CFI_REL_OFFSET cs, 0*/
16449 /*
16450 * Push current_thread_info()->sysenter_return to the stack.
16451 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
16452 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
16453 */
16454 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
16455 + pushl_cfi $0
16456 CFI_REL_OFFSET eip, 0
16457
16458 pushl_cfi %eax
16459 SAVE_ALL
16460 + GET_THREAD_INFO(%ebp)
16461 + movl TI_sysenter_return(%ebp),%ebp
16462 + movl %ebp,PT_EIP(%esp)
16463 ENABLE_INTERRUPTS(CLBR_NONE)
16464
16465 /*
16466 * Load the potential sixth argument from user stack.
16467 * Careful about security.
16468 */
16469 + movl PT_OLDESP(%esp),%ebp
16470 +
16471 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16472 + mov PT_OLDSS(%esp),%ds
16473 +1: movl %ds:(%ebp),%ebp
16474 + push %ss
16475 + pop %ds
16476 +#else
16477 cmpl $__PAGE_OFFSET-3,%ebp
16478 jae syscall_fault
16479 ASM_STAC
16480 1: movl (%ebp),%ebp
16481 ASM_CLAC
16482 +#endif
16483 +
16484 movl %ebp,PT_EBP(%esp)
16485 _ASM_EXTABLE(1b,syscall_fault)
16486
16487 GET_THREAD_INFO(%ebp)
16488
16489 +#ifdef CONFIG_PAX_RANDKSTACK
16490 + pax_erase_kstack
16491 +#endif
16492 +
16493 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16494 jnz sysenter_audit
16495 sysenter_do_call:
16496 @@ -444,12 +616,24 @@ sysenter_do_call:
16497 testl $_TIF_ALLWORK_MASK, %ecx
16498 jne sysexit_audit
16499 sysenter_exit:
16500 +
16501 +#ifdef CONFIG_PAX_RANDKSTACK
16502 + pushl_cfi %eax
16503 + movl %esp, %eax
16504 + call pax_randomize_kstack
16505 + popl_cfi %eax
16506 +#endif
16507 +
16508 + pax_erase_kstack
16509 +
16510 /* if something modifies registers it must also disable sysexit */
16511 movl PT_EIP(%esp), %edx
16512 movl PT_OLDESP(%esp), %ecx
16513 xorl %ebp,%ebp
16514 TRACE_IRQS_ON
16515 1: mov PT_FS(%esp), %fs
16516 +2: mov PT_DS(%esp), %ds
16517 +3: mov PT_ES(%esp), %es
16518 PTGS_TO_GS
16519 ENABLE_INTERRUPTS_SYSEXIT
16520
16521 @@ -466,6 +650,9 @@ sysenter_audit:
16522 movl %eax,%edx /* 2nd arg: syscall number */
16523 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
16524 call __audit_syscall_entry
16525 +
16526 + pax_erase_kstack
16527 +
16528 pushl_cfi %ebx
16529 movl PT_EAX(%esp),%eax /* reload syscall number */
16530 jmp sysenter_do_call
16531 @@ -491,10 +678,16 @@ sysexit_audit:
16532
16533 CFI_ENDPROC
16534 .pushsection .fixup,"ax"
16535 -2: movl $0,PT_FS(%esp)
16536 +4: movl $0,PT_FS(%esp)
16537 + jmp 1b
16538 +5: movl $0,PT_DS(%esp)
16539 + jmp 1b
16540 +6: movl $0,PT_ES(%esp)
16541 jmp 1b
16542 .popsection
16543 - _ASM_EXTABLE(1b,2b)
16544 + _ASM_EXTABLE(1b,4b)
16545 + _ASM_EXTABLE(2b,5b)
16546 + _ASM_EXTABLE(3b,6b)
16547 PTGS_TO_GS_EX
16548 ENDPROC(ia32_sysenter_target)
16549
16550 @@ -509,6 +702,11 @@ ENTRY(system_call)
16551 pushl_cfi %eax # save orig_eax
16552 SAVE_ALL
16553 GET_THREAD_INFO(%ebp)
16554 +
16555 +#ifdef CONFIG_PAX_RANDKSTACK
16556 + pax_erase_kstack
16557 +#endif
16558 +
16559 # system call tracing in operation / emulation
16560 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16561 jnz syscall_trace_entry
16562 @@ -527,6 +725,15 @@ syscall_exit:
16563 testl $_TIF_ALLWORK_MASK, %ecx # current->work
16564 jne syscall_exit_work
16565
16566 +restore_all_pax:
16567 +
16568 +#ifdef CONFIG_PAX_RANDKSTACK
16569 + movl %esp, %eax
16570 + call pax_randomize_kstack
16571 +#endif
16572 +
16573 + pax_erase_kstack
16574 +
16575 restore_all:
16576 TRACE_IRQS_IRET
16577 restore_all_notrace:
16578 @@ -583,14 +790,34 @@ ldt_ss:
16579 * compensating for the offset by changing to the ESPFIX segment with
16580 * a base address that matches for the difference.
16581 */
16582 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
16583 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
16584 mov %esp, %edx /* load kernel esp */
16585 mov PT_OLDESP(%esp), %eax /* load userspace esp */
16586 mov %dx, %ax /* eax: new kernel esp */
16587 sub %eax, %edx /* offset (low word is 0) */
16588 +#ifdef CONFIG_SMP
16589 + movl PER_CPU_VAR(cpu_number), %ebx
16590 + shll $PAGE_SHIFT_asm, %ebx
16591 + addl $cpu_gdt_table, %ebx
16592 +#else
16593 + movl $cpu_gdt_table, %ebx
16594 +#endif
16595 shr $16, %edx
16596 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
16597 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
16598 +
16599 +#ifdef CONFIG_PAX_KERNEXEC
16600 + mov %cr0, %esi
16601 + btr $16, %esi
16602 + mov %esi, %cr0
16603 +#endif
16604 +
16605 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
16606 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
16607 +
16608 +#ifdef CONFIG_PAX_KERNEXEC
16609 + bts $16, %esi
16610 + mov %esi, %cr0
16611 +#endif
16612 +
16613 pushl_cfi $__ESPFIX_SS
16614 pushl_cfi %eax /* new kernel esp */
16615 /* Disable interrupts, but do not irqtrace this section: we
16616 @@ -619,20 +846,18 @@ work_resched:
16617 movl TI_flags(%ebp), %ecx
16618 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
16619 # than syscall tracing?
16620 - jz restore_all
16621 + jz restore_all_pax
16622 testb $_TIF_NEED_RESCHED, %cl
16623 jnz work_resched
16624
16625 work_notifysig: # deal with pending signals and
16626 # notify-resume requests
16627 + movl %esp, %eax
16628 #ifdef CONFIG_VM86
16629 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
16630 - movl %esp, %eax
16631 jne work_notifysig_v86 # returning to kernel-space or
16632 # vm86-space
16633 1:
16634 -#else
16635 - movl %esp, %eax
16636 #endif
16637 TRACE_IRQS_ON
16638 ENABLE_INTERRUPTS(CLBR_NONE)
16639 @@ -653,7 +878,7 @@ work_notifysig_v86:
16640 movl %eax, %esp
16641 jmp 1b
16642 #endif
16643 -END(work_pending)
16644 +ENDPROC(work_pending)
16645
16646 # perform syscall exit tracing
16647 ALIGN
16648 @@ -661,11 +886,14 @@ syscall_trace_entry:
16649 movl $-ENOSYS,PT_EAX(%esp)
16650 movl %esp, %eax
16651 call syscall_trace_enter
16652 +
16653 + pax_erase_kstack
16654 +
16655 /* What it returned is what we'll actually use. */
16656 cmpl $(NR_syscalls), %eax
16657 jnae syscall_call
16658 jmp syscall_exit
16659 -END(syscall_trace_entry)
16660 +ENDPROC(syscall_trace_entry)
16661
16662 # perform syscall exit tracing
16663 ALIGN
16664 @@ -678,21 +906,25 @@ syscall_exit_work:
16665 movl %esp, %eax
16666 call syscall_trace_leave
16667 jmp resume_userspace
16668 -END(syscall_exit_work)
16669 +ENDPROC(syscall_exit_work)
16670 CFI_ENDPROC
16671
16672 RING0_INT_FRAME # can't unwind into user space anyway
16673 syscall_fault:
16674 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16675 + push %ss
16676 + pop %ds
16677 +#endif
16678 ASM_CLAC
16679 GET_THREAD_INFO(%ebp)
16680 movl $-EFAULT,PT_EAX(%esp)
16681 jmp resume_userspace
16682 -END(syscall_fault)
16683 +ENDPROC(syscall_fault)
16684
16685 syscall_badsys:
16686 movl $-ENOSYS,PT_EAX(%esp)
16687 jmp resume_userspace
16688 -END(syscall_badsys)
16689 +ENDPROC(syscall_badsys)
16690 CFI_ENDPROC
16691 /*
16692 * End of kprobes section
16693 @@ -772,8 +1004,15 @@ ENDPROC(ptregs_clone)
16694 * normal stack and adjusts ESP with the matching offset.
16695 */
16696 /* fixup the stack */
16697 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
16698 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
16699 +#ifdef CONFIG_SMP
16700 + movl PER_CPU_VAR(cpu_number), %ebx
16701 + shll $PAGE_SHIFT_asm, %ebx
16702 + addl $cpu_gdt_table, %ebx
16703 +#else
16704 + movl $cpu_gdt_table, %ebx
16705 +#endif
16706 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
16707 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
16708 shl $16, %eax
16709 addl %esp, %eax /* the adjusted stack pointer */
16710 pushl_cfi $__KERNEL_DS
16711 @@ -826,7 +1065,7 @@ vector=vector+1
16712 .endr
16713 2: jmp common_interrupt
16714 .endr
16715 -END(irq_entries_start)
16716 +ENDPROC(irq_entries_start)
16717
16718 .previous
16719 END(interrupt)
16720 @@ -877,7 +1116,7 @@ ENTRY(coprocessor_error)
16721 pushl_cfi $do_coprocessor_error
16722 jmp error_code
16723 CFI_ENDPROC
16724 -END(coprocessor_error)
16725 +ENDPROC(coprocessor_error)
16726
16727 ENTRY(simd_coprocessor_error)
16728 RING0_INT_FRAME
16729 @@ -899,7 +1138,7 @@ ENTRY(simd_coprocessor_error)
16730 #endif
16731 jmp error_code
16732 CFI_ENDPROC
16733 -END(simd_coprocessor_error)
16734 +ENDPROC(simd_coprocessor_error)
16735
16736 ENTRY(device_not_available)
16737 RING0_INT_FRAME
16738 @@ -908,18 +1147,18 @@ ENTRY(device_not_available)
16739 pushl_cfi $do_device_not_available
16740 jmp error_code
16741 CFI_ENDPROC
16742 -END(device_not_available)
16743 +ENDPROC(device_not_available)
16744
16745 #ifdef CONFIG_PARAVIRT
16746 ENTRY(native_iret)
16747 iret
16748 _ASM_EXTABLE(native_iret, iret_exc)
16749 -END(native_iret)
16750 +ENDPROC(native_iret)
16751
16752 ENTRY(native_irq_enable_sysexit)
16753 sti
16754 sysexit
16755 -END(native_irq_enable_sysexit)
16756 +ENDPROC(native_irq_enable_sysexit)
16757 #endif
16758
16759 ENTRY(overflow)
16760 @@ -929,7 +1168,7 @@ ENTRY(overflow)
16761 pushl_cfi $do_overflow
16762 jmp error_code
16763 CFI_ENDPROC
16764 -END(overflow)
16765 +ENDPROC(overflow)
16766
16767 ENTRY(bounds)
16768 RING0_INT_FRAME
16769 @@ -938,7 +1177,7 @@ ENTRY(bounds)
16770 pushl_cfi $do_bounds
16771 jmp error_code
16772 CFI_ENDPROC
16773 -END(bounds)
16774 +ENDPROC(bounds)
16775
16776 ENTRY(invalid_op)
16777 RING0_INT_FRAME
16778 @@ -947,7 +1186,7 @@ ENTRY(invalid_op)
16779 pushl_cfi $do_invalid_op
16780 jmp error_code
16781 CFI_ENDPROC
16782 -END(invalid_op)
16783 +ENDPROC(invalid_op)
16784
16785 ENTRY(coprocessor_segment_overrun)
16786 RING0_INT_FRAME
16787 @@ -956,7 +1195,7 @@ ENTRY(coprocessor_segment_overrun)
16788 pushl_cfi $do_coprocessor_segment_overrun
16789 jmp error_code
16790 CFI_ENDPROC
16791 -END(coprocessor_segment_overrun)
16792 +ENDPROC(coprocessor_segment_overrun)
16793
16794 ENTRY(invalid_TSS)
16795 RING0_EC_FRAME
16796 @@ -964,7 +1203,7 @@ ENTRY(invalid_TSS)
16797 pushl_cfi $do_invalid_TSS
16798 jmp error_code
16799 CFI_ENDPROC
16800 -END(invalid_TSS)
16801 +ENDPROC(invalid_TSS)
16802
16803 ENTRY(segment_not_present)
16804 RING0_EC_FRAME
16805 @@ -972,7 +1211,7 @@ ENTRY(segment_not_present)
16806 pushl_cfi $do_segment_not_present
16807 jmp error_code
16808 CFI_ENDPROC
16809 -END(segment_not_present)
16810 +ENDPROC(segment_not_present)
16811
16812 ENTRY(stack_segment)
16813 RING0_EC_FRAME
16814 @@ -980,7 +1219,7 @@ ENTRY(stack_segment)
16815 pushl_cfi $do_stack_segment
16816 jmp error_code
16817 CFI_ENDPROC
16818 -END(stack_segment)
16819 +ENDPROC(stack_segment)
16820
16821 ENTRY(alignment_check)
16822 RING0_EC_FRAME
16823 @@ -988,7 +1227,7 @@ ENTRY(alignment_check)
16824 pushl_cfi $do_alignment_check
16825 jmp error_code
16826 CFI_ENDPROC
16827 -END(alignment_check)
16828 +ENDPROC(alignment_check)
16829
16830 ENTRY(divide_error)
16831 RING0_INT_FRAME
16832 @@ -997,7 +1236,7 @@ ENTRY(divide_error)
16833 pushl_cfi $do_divide_error
16834 jmp error_code
16835 CFI_ENDPROC
16836 -END(divide_error)
16837 +ENDPROC(divide_error)
16838
16839 #ifdef CONFIG_X86_MCE
16840 ENTRY(machine_check)
16841 @@ -1007,7 +1246,7 @@ ENTRY(machine_check)
16842 pushl_cfi machine_check_vector
16843 jmp error_code
16844 CFI_ENDPROC
16845 -END(machine_check)
16846 +ENDPROC(machine_check)
16847 #endif
16848
16849 ENTRY(spurious_interrupt_bug)
16850 @@ -1017,7 +1256,7 @@ ENTRY(spurious_interrupt_bug)
16851 pushl_cfi $do_spurious_interrupt_bug
16852 jmp error_code
16853 CFI_ENDPROC
16854 -END(spurious_interrupt_bug)
16855 +ENDPROC(spurious_interrupt_bug)
16856 /*
16857 * End of kprobes section
16858 */
16859 @@ -1120,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
16860
16861 ENTRY(mcount)
16862 ret
16863 -END(mcount)
16864 +ENDPROC(mcount)
16865
16866 ENTRY(ftrace_caller)
16867 cmpl $0, function_trace_stop
16868 @@ -1153,7 +1392,7 @@ ftrace_graph_call:
16869 .globl ftrace_stub
16870 ftrace_stub:
16871 ret
16872 -END(ftrace_caller)
16873 +ENDPROC(ftrace_caller)
16874
16875 ENTRY(ftrace_regs_caller)
16876 pushf /* push flags before compare (in cs location) */
16877 @@ -1254,7 +1493,7 @@ trace:
16878 popl %ecx
16879 popl %eax
16880 jmp ftrace_stub
16881 -END(mcount)
16882 +ENDPROC(mcount)
16883 #endif /* CONFIG_DYNAMIC_FTRACE */
16884 #endif /* CONFIG_FUNCTION_TRACER */
16885
16886 @@ -1272,7 +1511,7 @@ ENTRY(ftrace_graph_caller)
16887 popl %ecx
16888 popl %eax
16889 ret
16890 -END(ftrace_graph_caller)
16891 +ENDPROC(ftrace_graph_caller)
16892
16893 .globl return_to_handler
16894 return_to_handler:
16895 @@ -1328,15 +1567,18 @@ error_code:
16896 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
16897 REG_TO_PTGS %ecx
16898 SET_KERNEL_GS %ecx
16899 - movl $(__USER_DS), %ecx
16900 + movl $(__KERNEL_DS), %ecx
16901 movl %ecx, %ds
16902 movl %ecx, %es
16903 +
16904 + pax_enter_kernel
16905 +
16906 TRACE_IRQS_OFF
16907 movl %esp,%eax # pt_regs pointer
16908 call *%edi
16909 jmp ret_from_exception
16910 CFI_ENDPROC
16911 -END(page_fault)
16912 +ENDPROC(page_fault)
16913
16914 /*
16915 * Debug traps and NMI can happen at the one SYSENTER instruction
16916 @@ -1379,7 +1621,7 @@ debug_stack_correct:
16917 call do_debug
16918 jmp ret_from_exception
16919 CFI_ENDPROC
16920 -END(debug)
16921 +ENDPROC(debug)
16922
16923 /*
16924 * NMI is doubly nasty. It can happen _while_ we're handling
16925 @@ -1417,6 +1659,9 @@ nmi_stack_correct:
16926 xorl %edx,%edx # zero error code
16927 movl %esp,%eax # pt_regs pointer
16928 call do_nmi
16929 +
16930 + pax_exit_kernel
16931 +
16932 jmp restore_all_notrace
16933 CFI_ENDPROC
16934
16935 @@ -1453,12 +1698,15 @@ nmi_espfix_stack:
16936 FIXUP_ESPFIX_STACK # %eax == %esp
16937 xorl %edx,%edx # zero error code
16938 call do_nmi
16939 +
16940 + pax_exit_kernel
16941 +
16942 RESTORE_REGS
16943 lss 12+4(%esp), %esp # back to espfix stack
16944 CFI_ADJUST_CFA_OFFSET -24
16945 jmp irq_return
16946 CFI_ENDPROC
16947 -END(nmi)
16948 +ENDPROC(nmi)
16949
16950 ENTRY(int3)
16951 RING0_INT_FRAME
16952 @@ -1471,14 +1719,14 @@ ENTRY(int3)
16953 call do_int3
16954 jmp ret_from_exception
16955 CFI_ENDPROC
16956 -END(int3)
16957 +ENDPROC(int3)
16958
16959 ENTRY(general_protection)
16960 RING0_EC_FRAME
16961 pushl_cfi $do_general_protection
16962 jmp error_code
16963 CFI_ENDPROC
16964 -END(general_protection)
16965 +ENDPROC(general_protection)
16966
16967 #ifdef CONFIG_KVM_GUEST
16968 ENTRY(async_page_fault)
16969 @@ -1487,7 +1735,7 @@ ENTRY(async_page_fault)
16970 pushl_cfi $do_async_page_fault
16971 jmp error_code
16972 CFI_ENDPROC
16973 -END(async_page_fault)
16974 +ENDPROC(async_page_fault)
16975 #endif
16976
16977 /*
16978 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
16979 index 1328fe4..cb03298 100644
16980 --- a/arch/x86/kernel/entry_64.S
16981 +++ b/arch/x86/kernel/entry_64.S
16982 @@ -59,6 +59,8 @@
16983 #include <asm/rcu.h>
16984 #include <asm/smap.h>
16985 #include <linux/err.h>
16986 +#include <asm/pgtable.h>
16987 +#include <asm/alternative-asm.h>
16988
16989 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
16990 #include <linux/elf-em.h>
16991 @@ -80,8 +82,9 @@
16992 #ifdef CONFIG_DYNAMIC_FTRACE
16993
16994 ENTRY(function_hook)
16995 + pax_force_retaddr
16996 retq
16997 -END(function_hook)
16998 +ENDPROC(function_hook)
16999
17000 /* skip is set if stack has been adjusted */
17001 .macro ftrace_caller_setup skip=0
17002 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
17003 #endif
17004
17005 GLOBAL(ftrace_stub)
17006 + pax_force_retaddr
17007 retq
17008 -END(ftrace_caller)
17009 +ENDPROC(ftrace_caller)
17010
17011 ENTRY(ftrace_regs_caller)
17012 /* Save the current flags before compare (in SS location)*/
17013 @@ -191,7 +195,7 @@ ftrace_restore_flags:
17014 popfq
17015 jmp ftrace_stub
17016
17017 -END(ftrace_regs_caller)
17018 +ENDPROC(ftrace_regs_caller)
17019
17020
17021 #else /* ! CONFIG_DYNAMIC_FTRACE */
17022 @@ -212,6 +216,7 @@ ENTRY(function_hook)
17023 #endif
17024
17025 GLOBAL(ftrace_stub)
17026 + pax_force_retaddr
17027 retq
17028
17029 trace:
17030 @@ -225,12 +230,13 @@ trace:
17031 #endif
17032 subq $MCOUNT_INSN_SIZE, %rdi
17033
17034 + pax_force_fptr ftrace_trace_function
17035 call *ftrace_trace_function
17036
17037 MCOUNT_RESTORE_FRAME
17038
17039 jmp ftrace_stub
17040 -END(function_hook)
17041 +ENDPROC(function_hook)
17042 #endif /* CONFIG_DYNAMIC_FTRACE */
17043 #endif /* CONFIG_FUNCTION_TRACER */
17044
17045 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
17046
17047 MCOUNT_RESTORE_FRAME
17048
17049 + pax_force_retaddr
17050 retq
17051 -END(ftrace_graph_caller)
17052 +ENDPROC(ftrace_graph_caller)
17053
17054 GLOBAL(return_to_handler)
17055 subq $24, %rsp
17056 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
17057 movq 8(%rsp), %rdx
17058 movq (%rsp), %rax
17059 addq $24, %rsp
17060 + pax_force_fptr %rdi
17061 jmp *%rdi
17062 +ENDPROC(return_to_handler)
17063 #endif
17064
17065
17066 @@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
17067 ENDPROC(native_usergs_sysret64)
17068 #endif /* CONFIG_PARAVIRT */
17069
17070 + .macro ljmpq sel, off
17071 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
17072 + .byte 0x48; ljmp *1234f(%rip)
17073 + .pushsection .rodata
17074 + .align 16
17075 + 1234: .quad \off; .word \sel
17076 + .popsection
17077 +#else
17078 + pushq $\sel
17079 + pushq $\off
17080 + lretq
17081 +#endif
17082 + .endm
17083 +
17084 + .macro pax_enter_kernel
17085 + pax_set_fptr_mask
17086 +#ifdef CONFIG_PAX_KERNEXEC
17087 + call pax_enter_kernel
17088 +#endif
17089 + .endm
17090 +
17091 + .macro pax_exit_kernel
17092 +#ifdef CONFIG_PAX_KERNEXEC
17093 + call pax_exit_kernel
17094 +#endif
17095 + .endm
17096 +
17097 +#ifdef CONFIG_PAX_KERNEXEC
17098 +ENTRY(pax_enter_kernel)
17099 + pushq %rdi
17100 +
17101 +#ifdef CONFIG_PARAVIRT
17102 + PV_SAVE_REGS(CLBR_RDI)
17103 +#endif
17104 +
17105 + GET_CR0_INTO_RDI
17106 + bts $16,%rdi
17107 + jnc 3f
17108 + mov %cs,%edi
17109 + cmp $__KERNEL_CS,%edi
17110 + jnz 2f
17111 +1:
17112 +
17113 +#ifdef CONFIG_PARAVIRT
17114 + PV_RESTORE_REGS(CLBR_RDI)
17115 +#endif
17116 +
17117 + popq %rdi
17118 + pax_force_retaddr
17119 + retq
17120 +
17121 +2: ljmpq __KERNEL_CS,1f
17122 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
17123 +4: SET_RDI_INTO_CR0
17124 + jmp 1b
17125 +ENDPROC(pax_enter_kernel)
17126 +
17127 +ENTRY(pax_exit_kernel)
17128 + pushq %rdi
17129 +
17130 +#ifdef CONFIG_PARAVIRT
17131 + PV_SAVE_REGS(CLBR_RDI)
17132 +#endif
17133 +
17134 + mov %cs,%rdi
17135 + cmp $__KERNEXEC_KERNEL_CS,%edi
17136 + jz 2f
17137 +1:
17138 +
17139 +#ifdef CONFIG_PARAVIRT
17140 + PV_RESTORE_REGS(CLBR_RDI);
17141 +#endif
17142 +
17143 + popq %rdi
17144 + pax_force_retaddr
17145 + retq
17146 +
17147 +2: GET_CR0_INTO_RDI
17148 + btr $16,%rdi
17149 + ljmpq __KERNEL_CS,3f
17150 +3: SET_RDI_INTO_CR0
17151 + jmp 1b
17152 +ENDPROC(pax_exit_kernel)
17153 +#endif
17154 +
17155 + .macro pax_enter_kernel_user
17156 + pax_set_fptr_mask
17157 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17158 + call pax_enter_kernel_user
17159 +#endif
17160 + .endm
17161 +
17162 + .macro pax_exit_kernel_user
17163 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17164 + call pax_exit_kernel_user
17165 +#endif
17166 +#ifdef CONFIG_PAX_RANDKSTACK
17167 + pushq %rax
17168 + call pax_randomize_kstack
17169 + popq %rax
17170 +#endif
17171 + .endm
17172 +
17173 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17174 +ENTRY(pax_enter_kernel_user)
17175 + pushq %rdi
17176 + pushq %rbx
17177 +
17178 +#ifdef CONFIG_PARAVIRT
17179 + PV_SAVE_REGS(CLBR_RDI)
17180 +#endif
17181 +
17182 + GET_CR3_INTO_RDI
17183 + mov %rdi,%rbx
17184 + add $__START_KERNEL_map,%rbx
17185 + sub phys_base(%rip),%rbx
17186 +
17187 +#ifdef CONFIG_PARAVIRT
17188 + pushq %rdi
17189 + cmpl $0, pv_info+PARAVIRT_enabled
17190 + jz 1f
17191 + i = 0
17192 + .rept USER_PGD_PTRS
17193 + mov i*8(%rbx),%rsi
17194 + mov $0,%sil
17195 + lea i*8(%rbx),%rdi
17196 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17197 + i = i + 1
17198 + .endr
17199 + jmp 2f
17200 +1:
17201 +#endif
17202 +
17203 + i = 0
17204 + .rept USER_PGD_PTRS
17205 + movb $0,i*8(%rbx)
17206 + i = i + 1
17207 + .endr
17208 +
17209 +#ifdef CONFIG_PARAVIRT
17210 +2: popq %rdi
17211 +#endif
17212 + SET_RDI_INTO_CR3
17213 +
17214 +#ifdef CONFIG_PAX_KERNEXEC
17215 + GET_CR0_INTO_RDI
17216 + bts $16,%rdi
17217 + SET_RDI_INTO_CR0
17218 +#endif
17219 +
17220 +#ifdef CONFIG_PARAVIRT
17221 + PV_RESTORE_REGS(CLBR_RDI)
17222 +#endif
17223 +
17224 + popq %rbx
17225 + popq %rdi
17226 + pax_force_retaddr
17227 + retq
17228 +ENDPROC(pax_enter_kernel_user)
17229 +
17230 +ENTRY(pax_exit_kernel_user)
17231 + push %rdi
17232 +
17233 +#ifdef CONFIG_PARAVIRT
17234 + pushq %rbx
17235 + PV_SAVE_REGS(CLBR_RDI)
17236 +#endif
17237 +
17238 +#ifdef CONFIG_PAX_KERNEXEC
17239 + GET_CR0_INTO_RDI
17240 + btr $16,%rdi
17241 + SET_RDI_INTO_CR0
17242 +#endif
17243 +
17244 + GET_CR3_INTO_RDI
17245 + add $__START_KERNEL_map,%rdi
17246 + sub phys_base(%rip),%rdi
17247 +
17248 +#ifdef CONFIG_PARAVIRT
17249 + cmpl $0, pv_info+PARAVIRT_enabled
17250 + jz 1f
17251 + mov %rdi,%rbx
17252 + i = 0
17253 + .rept USER_PGD_PTRS
17254 + mov i*8(%rbx),%rsi
17255 + mov $0x67,%sil
17256 + lea i*8(%rbx),%rdi
17257 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17258 + i = i + 1
17259 + .endr
17260 + jmp 2f
17261 +1:
17262 +#endif
17263 +
17264 + i = 0
17265 + .rept USER_PGD_PTRS
17266 + movb $0x67,i*8(%rdi)
17267 + i = i + 1
17268 + .endr
17269 +
17270 +#ifdef CONFIG_PARAVIRT
17271 +2: PV_RESTORE_REGS(CLBR_RDI)
17272 + popq %rbx
17273 +#endif
17274 +
17275 + popq %rdi
17276 + pax_force_retaddr
17277 + retq
17278 +ENDPROC(pax_exit_kernel_user)
17279 +#endif
17280 +
17281 +.macro pax_erase_kstack
17282 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17283 + call pax_erase_kstack
17284 +#endif
17285 +.endm
17286 +
17287 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17288 +ENTRY(pax_erase_kstack)
17289 + pushq %rdi
17290 + pushq %rcx
17291 + pushq %rax
17292 + pushq %r11
17293 +
17294 + GET_THREAD_INFO(%r11)
17295 + mov TI_lowest_stack(%r11), %rdi
17296 + mov $-0xBEEF, %rax
17297 + std
17298 +
17299 +1: mov %edi, %ecx
17300 + and $THREAD_SIZE_asm - 1, %ecx
17301 + shr $3, %ecx
17302 + repne scasq
17303 + jecxz 2f
17304 +
17305 + cmp $2*8, %ecx
17306 + jc 2f
17307 +
17308 + mov $2*8, %ecx
17309 + repe scasq
17310 + jecxz 2f
17311 + jne 1b
17312 +
17313 +2: cld
17314 + mov %esp, %ecx
17315 + sub %edi, %ecx
17316 +
17317 + cmp $THREAD_SIZE_asm, %rcx
17318 + jb 3f
17319 + ud2
17320 +3:
17321 +
17322 + shr $3, %ecx
17323 + rep stosq
17324 +
17325 + mov TI_task_thread_sp0(%r11), %rdi
17326 + sub $256, %rdi
17327 + mov %rdi, TI_lowest_stack(%r11)
17328 +
17329 + popq %r11
17330 + popq %rax
17331 + popq %rcx
17332 + popq %rdi
17333 + pax_force_retaddr
17334 + ret
17335 +ENDPROC(pax_erase_kstack)
17336 +#endif
17337
17338 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
17339 #ifdef CONFIG_TRACE_IRQFLAGS
17340 @@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
17341 .endm
17342
17343 .macro UNFAKE_STACK_FRAME
17344 - addq $8*6, %rsp
17345 - CFI_ADJUST_CFA_OFFSET -(6*8)
17346 + addq $8*6 + ARG_SKIP, %rsp
17347 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
17348 .endm
17349
17350 /*
17351 @@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
17352 movq %rsp, %rsi
17353
17354 leaq -RBP(%rsp),%rdi /* arg1 for handler */
17355 - testl $3, CS-RBP(%rsi)
17356 + testb $3, CS-RBP(%rsi)
17357 je 1f
17358 SWAPGS
17359 /*
17360 @@ -498,9 +774,10 @@ ENTRY(save_rest)
17361 movq_cfi r15, R15+16
17362 movq %r11, 8(%rsp) /* return address */
17363 FIXUP_TOP_OF_STACK %r11, 16
17364 + pax_force_retaddr
17365 ret
17366 CFI_ENDPROC
17367 -END(save_rest)
17368 +ENDPROC(save_rest)
17369
17370 /* save complete stack frame */
17371 .pushsection .kprobes.text, "ax"
17372 @@ -529,9 +806,10 @@ ENTRY(save_paranoid)
17373 js 1f /* negative -> in kernel */
17374 SWAPGS
17375 xorl %ebx,%ebx
17376 -1: ret
17377 +1: pax_force_retaddr_bts
17378 + ret
17379 CFI_ENDPROC
17380 -END(save_paranoid)
17381 +ENDPROC(save_paranoid)
17382 .popsection
17383
17384 /*
17385 @@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
17386
17387 RESTORE_REST
17388
17389 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17390 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17391 jz 1f
17392
17393 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
17394 @@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
17395 RESTORE_REST
17396 jmp int_ret_from_sys_call
17397 CFI_ENDPROC
17398 -END(ret_from_fork)
17399 +ENDPROC(ret_from_fork)
17400
17401 /*
17402 * System call entry. Up to 6 arguments in registers are supported.
17403 @@ -608,7 +886,7 @@ END(ret_from_fork)
17404 ENTRY(system_call)
17405 CFI_STARTPROC simple
17406 CFI_SIGNAL_FRAME
17407 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
17408 + CFI_DEF_CFA rsp,0
17409 CFI_REGISTER rip,rcx
17410 /*CFI_REGISTER rflags,r11*/
17411 SWAPGS_UNSAFE_STACK
17412 @@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
17413
17414 movq %rsp,PER_CPU_VAR(old_rsp)
17415 movq PER_CPU_VAR(kernel_stack),%rsp
17416 + SAVE_ARGS 8*6,0
17417 + pax_enter_kernel_user
17418 +
17419 +#ifdef CONFIG_PAX_RANDKSTACK
17420 + pax_erase_kstack
17421 +#endif
17422 +
17423 /*
17424 * No need to follow this irqs off/on section - it's straight
17425 * and short:
17426 */
17427 ENABLE_INTERRUPTS(CLBR_NONE)
17428 - SAVE_ARGS 8,0
17429 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
17430 movq %rcx,RIP-ARGOFFSET(%rsp)
17431 CFI_REL_OFFSET rip,RIP-ARGOFFSET
17432 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17433 + GET_THREAD_INFO(%rcx)
17434 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
17435 jnz tracesys
17436 system_call_fastpath:
17437 #if __SYSCALL_MASK == ~0
17438 @@ -640,7 +925,7 @@ system_call_fastpath:
17439 cmpl $__NR_syscall_max,%eax
17440 #endif
17441 ja badsys
17442 - movq %r10,%rcx
17443 + movq R10-ARGOFFSET(%rsp),%rcx
17444 call *sys_call_table(,%rax,8) # XXX: rip relative
17445 movq %rax,RAX-ARGOFFSET(%rsp)
17446 /*
17447 @@ -654,10 +939,13 @@ sysret_check:
17448 LOCKDEP_SYS_EXIT
17449 DISABLE_INTERRUPTS(CLBR_NONE)
17450 TRACE_IRQS_OFF
17451 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
17452 + GET_THREAD_INFO(%rcx)
17453 + movl TI_flags(%rcx),%edx
17454 andl %edi,%edx
17455 jnz sysret_careful
17456 CFI_REMEMBER_STATE
17457 + pax_exit_kernel_user
17458 + pax_erase_kstack
17459 /*
17460 * sysretq will re-enable interrupts:
17461 */
17462 @@ -709,14 +997,18 @@ badsys:
17463 * jump back to the normal fast path.
17464 */
17465 auditsys:
17466 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
17467 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
17468 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
17469 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
17470 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
17471 movq %rax,%rsi /* 2nd arg: syscall number */
17472 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
17473 call __audit_syscall_entry
17474 +
17475 + pax_erase_kstack
17476 +
17477 LOAD_ARGS 0 /* reload call-clobbered registers */
17478 + pax_set_fptr_mask
17479 jmp system_call_fastpath
17480
17481 /*
17482 @@ -737,7 +1029,7 @@ sysret_audit:
17483 /* Do syscall tracing */
17484 tracesys:
17485 #ifdef CONFIG_AUDITSYSCALL
17486 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17487 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
17488 jz auditsys
17489 #endif
17490 SAVE_REST
17491 @@ -745,12 +1037,16 @@ tracesys:
17492 FIXUP_TOP_OF_STACK %rdi
17493 movq %rsp,%rdi
17494 call syscall_trace_enter
17495 +
17496 + pax_erase_kstack
17497 +
17498 /*
17499 * Reload arg registers from stack in case ptrace changed them.
17500 * We don't reload %rax because syscall_trace_enter() returned
17501 * the value it wants us to use in the table lookup.
17502 */
17503 LOAD_ARGS ARGOFFSET, 1
17504 + pax_set_fptr_mask
17505 RESTORE_REST
17506 #if __SYSCALL_MASK == ~0
17507 cmpq $__NR_syscall_max,%rax
17508 @@ -759,7 +1055,7 @@ tracesys:
17509 cmpl $__NR_syscall_max,%eax
17510 #endif
17511 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
17512 - movq %r10,%rcx /* fixup for C */
17513 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
17514 call *sys_call_table(,%rax,8)
17515 movq %rax,RAX-ARGOFFSET(%rsp)
17516 /* Use IRET because user could have changed frame */
17517 @@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
17518 andl %edi,%edx
17519 jnz int_careful
17520 andl $~TS_COMPAT,TI_status(%rcx)
17521 - jmp retint_swapgs
17522 + pax_exit_kernel_user
17523 + pax_erase_kstack
17524 + jmp retint_swapgs_pax
17525
17526 /* Either reschedule or signal or syscall exit tracking needed. */
17527 /* First do a reschedule test. */
17528 @@ -826,7 +1124,7 @@ int_restore_rest:
17529 TRACE_IRQS_OFF
17530 jmp int_with_check
17531 CFI_ENDPROC
17532 -END(system_call)
17533 +ENDPROC(system_call)
17534
17535 /*
17536 * Certain special system calls that need to save a complete full stack frame.
17537 @@ -842,7 +1140,7 @@ ENTRY(\label)
17538 call \func
17539 jmp ptregscall_common
17540 CFI_ENDPROC
17541 -END(\label)
17542 +ENDPROC(\label)
17543 .endm
17544
17545 PTREGSCALL stub_clone, sys_clone, %r8
17546 @@ -860,9 +1158,10 @@ ENTRY(ptregscall_common)
17547 movq_cfi_restore R12+8, r12
17548 movq_cfi_restore RBP+8, rbp
17549 movq_cfi_restore RBX+8, rbx
17550 + pax_force_retaddr
17551 ret $REST_SKIP /* pop extended registers */
17552 CFI_ENDPROC
17553 -END(ptregscall_common)
17554 +ENDPROC(ptregscall_common)
17555
17556 ENTRY(stub_execve)
17557 CFI_STARTPROC
17558 @@ -876,7 +1175,7 @@ ENTRY(stub_execve)
17559 RESTORE_REST
17560 jmp int_ret_from_sys_call
17561 CFI_ENDPROC
17562 -END(stub_execve)
17563 +ENDPROC(stub_execve)
17564
17565 /*
17566 * sigreturn is special because it needs to restore all registers on return.
17567 @@ -894,7 +1193,7 @@ ENTRY(stub_rt_sigreturn)
17568 RESTORE_REST
17569 jmp int_ret_from_sys_call
17570 CFI_ENDPROC
17571 -END(stub_rt_sigreturn)
17572 +ENDPROC(stub_rt_sigreturn)
17573
17574 #ifdef CONFIG_X86_X32_ABI
17575 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
17576 @@ -962,7 +1261,7 @@ vector=vector+1
17577 2: jmp common_interrupt
17578 .endr
17579 CFI_ENDPROC
17580 -END(irq_entries_start)
17581 +ENDPROC(irq_entries_start)
17582
17583 .previous
17584 END(interrupt)
17585 @@ -982,6 +1281,16 @@ END(interrupt)
17586 subq $ORIG_RAX-RBP, %rsp
17587 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
17588 SAVE_ARGS_IRQ
17589 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17590 + testb $3, CS(%rdi)
17591 + jnz 1f
17592 + pax_enter_kernel
17593 + jmp 2f
17594 +1: pax_enter_kernel_user
17595 +2:
17596 +#else
17597 + pax_enter_kernel
17598 +#endif
17599 call \func
17600 .endm
17601
17602 @@ -1014,7 +1323,7 @@ ret_from_intr:
17603
17604 exit_intr:
17605 GET_THREAD_INFO(%rcx)
17606 - testl $3,CS-ARGOFFSET(%rsp)
17607 + testb $3,CS-ARGOFFSET(%rsp)
17608 je retint_kernel
17609
17610 /* Interrupt came from user space */
17611 @@ -1036,12 +1345,16 @@ retint_swapgs: /* return to user-space */
17612 * The iretq could re-enable interrupts:
17613 */
17614 DISABLE_INTERRUPTS(CLBR_ANY)
17615 + pax_exit_kernel_user
17616 +retint_swapgs_pax:
17617 TRACE_IRQS_IRETQ
17618 SWAPGS
17619 jmp restore_args
17620
17621 retint_restore_args: /* return to kernel space */
17622 DISABLE_INTERRUPTS(CLBR_ANY)
17623 + pax_exit_kernel
17624 + pax_force_retaddr (RIP-ARGOFFSET)
17625 /*
17626 * The iretq could re-enable interrupts:
17627 */
17628 @@ -1124,7 +1437,7 @@ ENTRY(retint_kernel)
17629 #endif
17630
17631 CFI_ENDPROC
17632 -END(common_interrupt)
17633 +ENDPROC(common_interrupt)
17634 /*
17635 * End of kprobes section
17636 */
17637 @@ -1142,7 +1455,7 @@ ENTRY(\sym)
17638 interrupt \do_sym
17639 jmp ret_from_intr
17640 CFI_ENDPROC
17641 -END(\sym)
17642 +ENDPROC(\sym)
17643 .endm
17644
17645 #ifdef CONFIG_SMP
17646 @@ -1198,12 +1511,22 @@ ENTRY(\sym)
17647 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17648 call error_entry
17649 DEFAULT_FRAME 0
17650 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17651 + testb $3, CS(%rsp)
17652 + jnz 1f
17653 + pax_enter_kernel
17654 + jmp 2f
17655 +1: pax_enter_kernel_user
17656 +2:
17657 +#else
17658 + pax_enter_kernel
17659 +#endif
17660 movq %rsp,%rdi /* pt_regs pointer */
17661 xorl %esi,%esi /* no error code */
17662 call \do_sym
17663 jmp error_exit /* %ebx: no swapgs flag */
17664 CFI_ENDPROC
17665 -END(\sym)
17666 +ENDPROC(\sym)
17667 .endm
17668
17669 .macro paranoidzeroentry sym do_sym
17670 @@ -1216,15 +1539,25 @@ ENTRY(\sym)
17671 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17672 call save_paranoid
17673 TRACE_IRQS_OFF
17674 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17675 + testb $3, CS(%rsp)
17676 + jnz 1f
17677 + pax_enter_kernel
17678 + jmp 2f
17679 +1: pax_enter_kernel_user
17680 +2:
17681 +#else
17682 + pax_enter_kernel
17683 +#endif
17684 movq %rsp,%rdi /* pt_regs pointer */
17685 xorl %esi,%esi /* no error code */
17686 call \do_sym
17687 jmp paranoid_exit /* %ebx: no swapgs flag */
17688 CFI_ENDPROC
17689 -END(\sym)
17690 +ENDPROC(\sym)
17691 .endm
17692
17693 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
17694 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
17695 .macro paranoidzeroentry_ist sym do_sym ist
17696 ENTRY(\sym)
17697 INTR_FRAME
17698 @@ -1235,14 +1568,30 @@ ENTRY(\sym)
17699 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17700 call save_paranoid
17701 TRACE_IRQS_OFF_DEBUG
17702 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17703 + testb $3, CS(%rsp)
17704 + jnz 1f
17705 + pax_enter_kernel
17706 + jmp 2f
17707 +1: pax_enter_kernel_user
17708 +2:
17709 +#else
17710 + pax_enter_kernel
17711 +#endif
17712 movq %rsp,%rdi /* pt_regs pointer */
17713 xorl %esi,%esi /* no error code */
17714 +#ifdef CONFIG_SMP
17715 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
17716 + lea init_tss(%r12), %r12
17717 +#else
17718 + lea init_tss(%rip), %r12
17719 +#endif
17720 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17721 call \do_sym
17722 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17723 jmp paranoid_exit /* %ebx: no swapgs flag */
17724 CFI_ENDPROC
17725 -END(\sym)
17726 +ENDPROC(\sym)
17727 .endm
17728
17729 .macro errorentry sym do_sym
17730 @@ -1254,13 +1603,23 @@ ENTRY(\sym)
17731 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17732 call error_entry
17733 DEFAULT_FRAME 0
17734 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17735 + testb $3, CS(%rsp)
17736 + jnz 1f
17737 + pax_enter_kernel
17738 + jmp 2f
17739 +1: pax_enter_kernel_user
17740 +2:
17741 +#else
17742 + pax_enter_kernel
17743 +#endif
17744 movq %rsp,%rdi /* pt_regs pointer */
17745 movq ORIG_RAX(%rsp),%rsi /* get error code */
17746 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17747 call \do_sym
17748 jmp error_exit /* %ebx: no swapgs flag */
17749 CFI_ENDPROC
17750 -END(\sym)
17751 +ENDPROC(\sym)
17752 .endm
17753
17754 /* error code is on the stack already */
17755 @@ -1274,13 +1633,23 @@ ENTRY(\sym)
17756 call save_paranoid
17757 DEFAULT_FRAME 0
17758 TRACE_IRQS_OFF
17759 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17760 + testb $3, CS(%rsp)
17761 + jnz 1f
17762 + pax_enter_kernel
17763 + jmp 2f
17764 +1: pax_enter_kernel_user
17765 +2:
17766 +#else
17767 + pax_enter_kernel
17768 +#endif
17769 movq %rsp,%rdi /* pt_regs pointer */
17770 movq ORIG_RAX(%rsp),%rsi /* get error code */
17771 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17772 call \do_sym
17773 jmp paranoid_exit /* %ebx: no swapgs flag */
17774 CFI_ENDPROC
17775 -END(\sym)
17776 +ENDPROC(\sym)
17777 .endm
17778
17779 zeroentry divide_error do_divide_error
17780 @@ -1310,9 +1679,10 @@ gs_change:
17781 2: mfence /* workaround */
17782 SWAPGS
17783 popfq_cfi
17784 + pax_force_retaddr
17785 ret
17786 CFI_ENDPROC
17787 -END(native_load_gs_index)
17788 +ENDPROC(native_load_gs_index)
17789
17790 _ASM_EXTABLE(gs_change,bad_gs)
17791 .section .fixup,"ax"
17792 @@ -1340,9 +1710,10 @@ ENTRY(call_softirq)
17793 CFI_DEF_CFA_REGISTER rsp
17794 CFI_ADJUST_CFA_OFFSET -8
17795 decl PER_CPU_VAR(irq_count)
17796 + pax_force_retaddr
17797 ret
17798 CFI_ENDPROC
17799 -END(call_softirq)
17800 +ENDPROC(call_softirq)
17801
17802 #ifdef CONFIG_XEN
17803 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
17804 @@ -1380,7 +1751,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
17805 decl PER_CPU_VAR(irq_count)
17806 jmp error_exit
17807 CFI_ENDPROC
17808 -END(xen_do_hypervisor_callback)
17809 +ENDPROC(xen_do_hypervisor_callback)
17810
17811 /*
17812 * Hypervisor uses this for application faults while it executes.
17813 @@ -1439,7 +1810,7 @@ ENTRY(xen_failsafe_callback)
17814 SAVE_ALL
17815 jmp error_exit
17816 CFI_ENDPROC
17817 -END(xen_failsafe_callback)
17818 +ENDPROC(xen_failsafe_callback)
17819
17820 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
17821 xen_hvm_callback_vector xen_evtchn_do_upcall
17822 @@ -1488,16 +1859,31 @@ ENTRY(paranoid_exit)
17823 TRACE_IRQS_OFF_DEBUG
17824 testl %ebx,%ebx /* swapgs needed? */
17825 jnz paranoid_restore
17826 - testl $3,CS(%rsp)
17827 + testb $3,CS(%rsp)
17828 jnz paranoid_userspace
17829 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17830 + pax_exit_kernel
17831 + TRACE_IRQS_IRETQ 0
17832 + SWAPGS_UNSAFE_STACK
17833 + RESTORE_ALL 8
17834 + pax_force_retaddr_bts
17835 + jmp irq_return
17836 +#endif
17837 paranoid_swapgs:
17838 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17839 + pax_exit_kernel_user
17840 +#else
17841 + pax_exit_kernel
17842 +#endif
17843 TRACE_IRQS_IRETQ 0
17844 SWAPGS_UNSAFE_STACK
17845 RESTORE_ALL 8
17846 jmp irq_return
17847 paranoid_restore:
17848 + pax_exit_kernel
17849 TRACE_IRQS_IRETQ_DEBUG 0
17850 RESTORE_ALL 8
17851 + pax_force_retaddr_bts
17852 jmp irq_return
17853 paranoid_userspace:
17854 GET_THREAD_INFO(%rcx)
17855 @@ -1526,7 +1912,7 @@ paranoid_schedule:
17856 TRACE_IRQS_OFF
17857 jmp paranoid_userspace
17858 CFI_ENDPROC
17859 -END(paranoid_exit)
17860 +ENDPROC(paranoid_exit)
17861
17862 /*
17863 * Exception entry point. This expects an error code/orig_rax on the stack.
17864 @@ -1553,12 +1939,13 @@ ENTRY(error_entry)
17865 movq_cfi r14, R14+8
17866 movq_cfi r15, R15+8
17867 xorl %ebx,%ebx
17868 - testl $3,CS+8(%rsp)
17869 + testb $3,CS+8(%rsp)
17870 je error_kernelspace
17871 error_swapgs:
17872 SWAPGS
17873 error_sti:
17874 TRACE_IRQS_OFF
17875 + pax_force_retaddr_bts
17876 ret
17877
17878 /*
17879 @@ -1585,7 +1972,7 @@ bstep_iret:
17880 movq %rcx,RIP+8(%rsp)
17881 jmp error_swapgs
17882 CFI_ENDPROC
17883 -END(error_entry)
17884 +ENDPROC(error_entry)
17885
17886
17887 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
17888 @@ -1605,7 +1992,7 @@ ENTRY(error_exit)
17889 jnz retint_careful
17890 jmp retint_swapgs
17891 CFI_ENDPROC
17892 -END(error_exit)
17893 +ENDPROC(error_exit)
17894
17895 /*
17896 * Test if a given stack is an NMI stack or not.
17897 @@ -1663,9 +2050,11 @@ ENTRY(nmi)
17898 * If %cs was not the kernel segment, then the NMI triggered in user
17899 * space, which means it is definitely not nested.
17900 */
17901 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
17902 + je 1f
17903 cmpl $__KERNEL_CS, 16(%rsp)
17904 jne first_nmi
17905 -
17906 +1:
17907 /*
17908 * Check the special variable on the stack to see if NMIs are
17909 * executing.
17910 @@ -1824,6 +2213,17 @@ end_repeat_nmi:
17911 */
17912 movq %cr2, %r12
17913
17914 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17915 + testb $3, CS(%rsp)
17916 + jnz 1f
17917 + pax_enter_kernel
17918 + jmp 2f
17919 +1: pax_enter_kernel_user
17920 +2:
17921 +#else
17922 + pax_enter_kernel
17923 +#endif
17924 +
17925 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
17926 movq %rsp,%rdi
17927 movq $-1,%rsi
17928 @@ -1839,21 +2239,32 @@ end_repeat_nmi:
17929 testl %ebx,%ebx /* swapgs needed? */
17930 jnz nmi_restore
17931 nmi_swapgs:
17932 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17933 + pax_exit_kernel_user
17934 +#else
17935 + pax_exit_kernel
17936 +#endif
17937 SWAPGS_UNSAFE_STACK
17938 + RESTORE_ALL 8
17939 + /* Clear the NMI executing stack variable */
17940 + movq $0, 10*8(%rsp)
17941 + jmp irq_return
17942 nmi_restore:
17943 + pax_exit_kernel
17944 RESTORE_ALL 8
17945 + pax_force_retaddr_bts
17946 /* Clear the NMI executing stack variable */
17947 movq $0, 10*8(%rsp)
17948 jmp irq_return
17949 CFI_ENDPROC
17950 -END(nmi)
17951 +ENDPROC(nmi)
17952
17953 ENTRY(ignore_sysret)
17954 CFI_STARTPROC
17955 mov $-ENOSYS,%eax
17956 sysret
17957 CFI_ENDPROC
17958 -END(ignore_sysret)
17959 +ENDPROC(ignore_sysret)
17960
17961 /*
17962 * End of kprobes section
17963 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
17964 index 1d41402..af9a46a 100644
17965 --- a/arch/x86/kernel/ftrace.c
17966 +++ b/arch/x86/kernel/ftrace.c
17967 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
17968 {
17969 unsigned char replaced[MCOUNT_INSN_SIZE];
17970
17971 + ip = ktla_ktva(ip);
17972 +
17973 /*
17974 * Note: Due to modules and __init, code can
17975 * disappear and change, we need to protect against faulting
17976 @@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
17977 unsigned char old[MCOUNT_INSN_SIZE], *new;
17978 int ret;
17979
17980 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
17981 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
17982 new = ftrace_call_replace(ip, (unsigned long)func);
17983
17984 /* See comment above by declaration of modifying_ftrace_code */
17985 @@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
17986 /* Also update the regs callback function */
17987 if (!ret) {
17988 ip = (unsigned long)(&ftrace_regs_call);
17989 - memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
17990 + memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
17991 new = ftrace_call_replace(ip, (unsigned long)func);
17992 ret = ftrace_modify_code(ip, old, new);
17993 }
17994 @@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
17995 * kernel identity mapping to modify code.
17996 */
17997 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
17998 - ip = (unsigned long)__va(__pa(ip));
17999 + ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
18000
18001 return probe_kernel_write((void *)ip, val, size);
18002 }
18003 @@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
18004 unsigned char replaced[MCOUNT_INSN_SIZE];
18005 unsigned char brk = BREAKPOINT_INSTRUCTION;
18006
18007 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
18008 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
18009 return -EFAULT;
18010
18011 /* Make sure it is what we expect it to be */
18012 @@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
18013 return ret;
18014
18015 fail_update:
18016 - probe_kernel_write((void *)ip, &old_code[0], 1);
18017 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
18018 goto out;
18019 }
18020
18021 @@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
18022 {
18023 unsigned char code[MCOUNT_INSN_SIZE];
18024
18025 + ip = ktla_ktva(ip);
18026 +
18027 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
18028 return -EFAULT;
18029
18030 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
18031 index c18f59d..69ddbc4 100644
18032 --- a/arch/x86/kernel/head32.c
18033 +++ b/arch/x86/kernel/head32.c
18034 @@ -18,20 +18,20 @@
18035 #include <asm/io_apic.h>
18036 #include <asm/bios_ebda.h>
18037 #include <asm/tlbflush.h>
18038 +#include <asm/boot.h>
18039
18040 static void __init i386_default_early_setup(void)
18041 {
18042 /* Initialize 32bit specific setup functions */
18043 - x86_init.resources.reserve_resources = i386_reserve_resources;
18044 - x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
18045 + *(void **)&x86_init.resources.reserve_resources = i386_reserve_resources;
18046 + *(void **)&x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
18047
18048 reserve_ebda_region();
18049 }
18050
18051 void __init i386_start_kernel(void)
18052 {
18053 - memblock_reserve(__pa_symbol(&_text),
18054 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
18055 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
18056
18057 #ifdef CONFIG_BLK_DEV_INITRD
18058 /* Reserve INITRD */
18059 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
18060 index 4dac2f6..bc6a335 100644
18061 --- a/arch/x86/kernel/head_32.S
18062 +++ b/arch/x86/kernel/head_32.S
18063 @@ -26,6 +26,12 @@
18064 /* Physical address */
18065 #define pa(X) ((X) - __PAGE_OFFSET)
18066
18067 +#ifdef CONFIG_PAX_KERNEXEC
18068 +#define ta(X) (X)
18069 +#else
18070 +#define ta(X) ((X) - __PAGE_OFFSET)
18071 +#endif
18072 +
18073 /*
18074 * References to members of the new_cpu_data structure.
18075 */
18076 @@ -55,11 +61,7 @@
18077 * and small than max_low_pfn, otherwise will waste some page table entries
18078 */
18079
18080 -#if PTRS_PER_PMD > 1
18081 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
18082 -#else
18083 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
18084 -#endif
18085 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
18086
18087 /* Number of possible pages in the lowmem region */
18088 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
18089 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
18090 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
18091
18092 /*
18093 + * Real beginning of normal "text" segment
18094 + */
18095 +ENTRY(stext)
18096 +ENTRY(_stext)
18097 +
18098 +/*
18099 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
18100 * %esi points to the real-mode code as a 32-bit pointer.
18101 * CS and DS must be 4 GB flat segments, but we don't depend on
18102 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
18103 * can.
18104 */
18105 __HEAD
18106 +
18107 +#ifdef CONFIG_PAX_KERNEXEC
18108 + jmp startup_32
18109 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
18110 +.fill PAGE_SIZE-5,1,0xcc
18111 +#endif
18112 +
18113 ENTRY(startup_32)
18114 movl pa(stack_start),%ecx
18115
18116 @@ -106,6 +121,59 @@ ENTRY(startup_32)
18117 2:
18118 leal -__PAGE_OFFSET(%ecx),%esp
18119
18120 +#ifdef CONFIG_SMP
18121 + movl $pa(cpu_gdt_table),%edi
18122 + movl $__per_cpu_load,%eax
18123 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
18124 + rorl $16,%eax
18125 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
18126 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
18127 + movl $__per_cpu_end - 1,%eax
18128 + subl $__per_cpu_start,%eax
18129 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
18130 +#endif
18131 +
18132 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18133 + movl $NR_CPUS,%ecx
18134 + movl $pa(cpu_gdt_table),%edi
18135 +1:
18136 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
18137 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
18138 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
18139 + addl $PAGE_SIZE_asm,%edi
18140 + loop 1b
18141 +#endif
18142 +
18143 +#ifdef CONFIG_PAX_KERNEXEC
18144 + movl $pa(boot_gdt),%edi
18145 + movl $__LOAD_PHYSICAL_ADDR,%eax
18146 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
18147 + rorl $16,%eax
18148 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
18149 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
18150 + rorl $16,%eax
18151 +
18152 + ljmp $(__BOOT_CS),$1f
18153 +1:
18154 +
18155 + movl $NR_CPUS,%ecx
18156 + movl $pa(cpu_gdt_table),%edi
18157 + addl $__PAGE_OFFSET,%eax
18158 +1:
18159 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
18160 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
18161 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
18162 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
18163 + rorl $16,%eax
18164 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
18165 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
18166 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
18167 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
18168 + rorl $16,%eax
18169 + addl $PAGE_SIZE_asm,%edi
18170 + loop 1b
18171 +#endif
18172 +
18173 /*
18174 * Clear BSS first so that there are no surprises...
18175 */
18176 @@ -196,8 +264,11 @@ ENTRY(startup_32)
18177 movl %eax, pa(max_pfn_mapped)
18178
18179 /* Do early initialization of the fixmap area */
18180 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
18181 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
18182 +#ifdef CONFIG_COMPAT_VDSO
18183 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
18184 +#else
18185 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
18186 +#endif
18187 #else /* Not PAE */
18188
18189 page_pde_offset = (__PAGE_OFFSET >> 20);
18190 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
18191 movl %eax, pa(max_pfn_mapped)
18192
18193 /* Do early initialization of the fixmap area */
18194 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
18195 - movl %eax,pa(initial_page_table+0xffc)
18196 +#ifdef CONFIG_COMPAT_VDSO
18197 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
18198 +#else
18199 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
18200 +#endif
18201 #endif
18202
18203 #ifdef CONFIG_PARAVIRT
18204 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
18205 cmpl $num_subarch_entries, %eax
18206 jae bad_subarch
18207
18208 - movl pa(subarch_entries)(,%eax,4), %eax
18209 - subl $__PAGE_OFFSET, %eax
18210 - jmp *%eax
18211 + jmp *pa(subarch_entries)(,%eax,4)
18212
18213 bad_subarch:
18214 WEAK(lguest_entry)
18215 @@ -256,10 +328,10 @@ WEAK(xen_entry)
18216 __INITDATA
18217
18218 subarch_entries:
18219 - .long default_entry /* normal x86/PC */
18220 - .long lguest_entry /* lguest hypervisor */
18221 - .long xen_entry /* Xen hypervisor */
18222 - .long default_entry /* Moorestown MID */
18223 + .long ta(default_entry) /* normal x86/PC */
18224 + .long ta(lguest_entry) /* lguest hypervisor */
18225 + .long ta(xen_entry) /* Xen hypervisor */
18226 + .long ta(default_entry) /* Moorestown MID */
18227 num_subarch_entries = (. - subarch_entries) / 4
18228 .previous
18229 #else
18230 @@ -316,6 +388,7 @@ default_entry:
18231 movl pa(mmu_cr4_features),%eax
18232 movl %eax,%cr4
18233
18234 +#ifdef CONFIG_X86_PAE
18235 testb $X86_CR4_PAE, %al # check if PAE is enabled
18236 jz 6f
18237
18238 @@ -344,6 +417,9 @@ default_entry:
18239 /* Make changes effective */
18240 wrmsr
18241
18242 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
18243 +#endif
18244 +
18245 6:
18246
18247 /*
18248 @@ -442,14 +518,20 @@ is386: movl $2,%ecx # set MP
18249 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
18250 movl %eax,%ss # after changing gdt.
18251
18252 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
18253 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
18254 movl %eax,%ds
18255 movl %eax,%es
18256
18257 movl $(__KERNEL_PERCPU), %eax
18258 movl %eax,%fs # set this cpu's percpu
18259
18260 +#ifdef CONFIG_CC_STACKPROTECTOR
18261 movl $(__KERNEL_STACK_CANARY),%eax
18262 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18263 + movl $(__USER_DS),%eax
18264 +#else
18265 + xorl %eax,%eax
18266 +#endif
18267 movl %eax,%gs
18268
18269 xorl %eax,%eax # Clear LDT
18270 @@ -526,8 +608,11 @@ setup_once:
18271 * relocation. Manually set base address in stack canary
18272 * segment descriptor.
18273 */
18274 - movl $gdt_page,%eax
18275 + movl $cpu_gdt_table,%eax
18276 movl $stack_canary,%ecx
18277 +#ifdef CONFIG_SMP
18278 + addl $__per_cpu_load,%ecx
18279 +#endif
18280 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
18281 shrl $16, %ecx
18282 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
18283 @@ -558,7 +643,7 @@ ENDPROC(early_idt_handlers)
18284 /* This is global to keep gas from relaxing the jumps */
18285 ENTRY(early_idt_handler)
18286 cld
18287 - cmpl $2,%ss:early_recursion_flag
18288 + cmpl $1,%ss:early_recursion_flag
18289 je hlt_loop
18290 incl %ss:early_recursion_flag
18291
18292 @@ -596,8 +681,8 @@ ENTRY(early_idt_handler)
18293 pushl (20+6*4)(%esp) /* trapno */
18294 pushl $fault_msg
18295 call printk
18296 -#endif
18297 call dump_stack
18298 +#endif
18299 hlt_loop:
18300 hlt
18301 jmp hlt_loop
18302 @@ -616,8 +701,11 @@ ENDPROC(early_idt_handler)
18303 /* This is the default interrupt "handler" :-) */
18304 ALIGN
18305 ignore_int:
18306 - cld
18307 #ifdef CONFIG_PRINTK
18308 + cmpl $2,%ss:early_recursion_flag
18309 + je hlt_loop
18310 + incl %ss:early_recursion_flag
18311 + cld
18312 pushl %eax
18313 pushl %ecx
18314 pushl %edx
18315 @@ -626,9 +714,6 @@ ignore_int:
18316 movl $(__KERNEL_DS),%eax
18317 movl %eax,%ds
18318 movl %eax,%es
18319 - cmpl $2,early_recursion_flag
18320 - je hlt_loop
18321 - incl early_recursion_flag
18322 pushl 16(%esp)
18323 pushl 24(%esp)
18324 pushl 32(%esp)
18325 @@ -662,29 +747,43 @@ ENTRY(setup_once_ref)
18326 /*
18327 * BSS section
18328 */
18329 -__PAGE_ALIGNED_BSS
18330 - .align PAGE_SIZE
18331 #ifdef CONFIG_X86_PAE
18332 +.section .initial_pg_pmd,"a",@progbits
18333 initial_pg_pmd:
18334 .fill 1024*KPMDS,4,0
18335 #else
18336 +.section .initial_page_table,"a",@progbits
18337 ENTRY(initial_page_table)
18338 .fill 1024,4,0
18339 #endif
18340 +.section .initial_pg_fixmap,"a",@progbits
18341 initial_pg_fixmap:
18342 .fill 1024,4,0
18343 +.section .empty_zero_page,"a",@progbits
18344 ENTRY(empty_zero_page)
18345 .fill 4096,1,0
18346 +.section .swapper_pg_dir,"a",@progbits
18347 ENTRY(swapper_pg_dir)
18348 +#ifdef CONFIG_X86_PAE
18349 + .fill 4,8,0
18350 +#else
18351 .fill 1024,4,0
18352 +#endif
18353 +
18354 +/*
18355 + * The IDT has to be page-aligned to simplify the Pentium
18356 + * F0 0F bug workaround.. We have a special link segment
18357 + * for this.
18358 + */
18359 +.section .idt,"a",@progbits
18360 +ENTRY(idt_table)
18361 + .fill 256,8,0
18362
18363 /*
18364 * This starts the data section.
18365 */
18366 #ifdef CONFIG_X86_PAE
18367 -__PAGE_ALIGNED_DATA
18368 - /* Page-aligned for the benefit of paravirt? */
18369 - .align PAGE_SIZE
18370 +.section .initial_page_table,"a",@progbits
18371 ENTRY(initial_page_table)
18372 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
18373 # if KPMDS == 3
18374 @@ -703,12 +802,20 @@ ENTRY(initial_page_table)
18375 # error "Kernel PMDs should be 1, 2 or 3"
18376 # endif
18377 .align PAGE_SIZE /* needs to be page-sized too */
18378 +
18379 +#ifdef CONFIG_PAX_PER_CPU_PGD
18380 +ENTRY(cpu_pgd)
18381 + .rept NR_CPUS
18382 + .fill 4,8,0
18383 + .endr
18384 +#endif
18385 +
18386 #endif
18387
18388 .data
18389 .balign 4
18390 ENTRY(stack_start)
18391 - .long init_thread_union+THREAD_SIZE
18392 + .long init_thread_union+THREAD_SIZE-8
18393
18394 __INITRODATA
18395 int_msg:
18396 @@ -736,7 +843,7 @@ fault_msg:
18397 * segment size, and 32-bit linear address value:
18398 */
18399
18400 - .data
18401 +.section .rodata,"a",@progbits
18402 .globl boot_gdt_descr
18403 .globl idt_descr
18404
18405 @@ -745,7 +852,7 @@ fault_msg:
18406 .word 0 # 32 bit align gdt_desc.address
18407 boot_gdt_descr:
18408 .word __BOOT_DS+7
18409 - .long boot_gdt - __PAGE_OFFSET
18410 + .long pa(boot_gdt)
18411
18412 .word 0 # 32-bit align idt_desc.address
18413 idt_descr:
18414 @@ -756,7 +863,7 @@ idt_descr:
18415 .word 0 # 32 bit align gdt_desc.address
18416 ENTRY(early_gdt_descr)
18417 .word GDT_ENTRIES*8-1
18418 - .long gdt_page /* Overwritten for secondary CPUs */
18419 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
18420
18421 /*
18422 * The boot_gdt must mirror the equivalent in setup.S and is
18423 @@ -765,5 +872,65 @@ ENTRY(early_gdt_descr)
18424 .align L1_CACHE_BYTES
18425 ENTRY(boot_gdt)
18426 .fill GDT_ENTRY_BOOT_CS,8,0
18427 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
18428 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
18429 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
18430 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
18431 +
18432 + .align PAGE_SIZE_asm
18433 +ENTRY(cpu_gdt_table)
18434 + .rept NR_CPUS
18435 + .quad 0x0000000000000000 /* NULL descriptor */
18436 + .quad 0x0000000000000000 /* 0x0b reserved */
18437 + .quad 0x0000000000000000 /* 0x13 reserved */
18438 + .quad 0x0000000000000000 /* 0x1b reserved */
18439 +
18440 +#ifdef CONFIG_PAX_KERNEXEC
18441 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
18442 +#else
18443 + .quad 0x0000000000000000 /* 0x20 unused */
18444 +#endif
18445 +
18446 + .quad 0x0000000000000000 /* 0x28 unused */
18447 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
18448 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
18449 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
18450 + .quad 0x0000000000000000 /* 0x4b reserved */
18451 + .quad 0x0000000000000000 /* 0x53 reserved */
18452 + .quad 0x0000000000000000 /* 0x5b reserved */
18453 +
18454 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
18455 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
18456 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
18457 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
18458 +
18459 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
18460 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
18461 +
18462 + /*
18463 + * Segments used for calling PnP BIOS have byte granularity.
18464 + * The code segments and data segments have fixed 64k limits,
18465 + * the transfer segment sizes are set at run time.
18466 + */
18467 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
18468 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
18469 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
18470 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
18471 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
18472 +
18473 + /*
18474 + * The APM segments have byte granularity and their bases
18475 + * are set at run time. All have 64k limits.
18476 + */
18477 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
18478 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
18479 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
18480 +
18481 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
18482 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
18483 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
18484 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
18485 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
18486 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
18487 +
18488 + /* Be sure this is zeroed to avoid false validations in Xen */
18489 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
18490 + .endr
18491 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
18492 index 94bf9cc..400455a 100644
18493 --- a/arch/x86/kernel/head_64.S
18494 +++ b/arch/x86/kernel/head_64.S
18495 @@ -20,6 +20,8 @@
18496 #include <asm/processor-flags.h>
18497 #include <asm/percpu.h>
18498 #include <asm/nops.h>
18499 +#include <asm/cpufeature.h>
18500 +#include <asm/alternative-asm.h>
18501
18502 #ifdef CONFIG_PARAVIRT
18503 #include <asm/asm-offsets.h>
18504 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
18505 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
18506 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
18507 L3_START_KERNEL = pud_index(__START_KERNEL_map)
18508 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
18509 +L3_VMALLOC_START = pud_index(VMALLOC_START)
18510 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
18511 +L3_VMALLOC_END = pud_index(VMALLOC_END)
18512 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
18513 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
18514
18515 .text
18516 __HEAD
18517 @@ -88,35 +96,23 @@ startup_64:
18518 */
18519 addq %rbp, init_level4_pgt + 0(%rip)
18520 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
18521 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
18522 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
18523 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
18524 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
18525
18526 addq %rbp, level3_ident_pgt + 0(%rip)
18527 +#ifndef CONFIG_XEN
18528 + addq %rbp, level3_ident_pgt + 8(%rip)
18529 +#endif
18530
18531 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
18532 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
18533 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
18534 +
18535 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
18536 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
18537
18538 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
18539 -
18540 - /* Add an Identity mapping if I am above 1G */
18541 - leaq _text(%rip), %rdi
18542 - andq $PMD_PAGE_MASK, %rdi
18543 -
18544 - movq %rdi, %rax
18545 - shrq $PUD_SHIFT, %rax
18546 - andq $(PTRS_PER_PUD - 1), %rax
18547 - jz ident_complete
18548 -
18549 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
18550 - leaq level3_ident_pgt(%rip), %rbx
18551 - movq %rdx, 0(%rbx, %rax, 8)
18552 -
18553 - movq %rdi, %rax
18554 - shrq $PMD_SHIFT, %rax
18555 - andq $(PTRS_PER_PMD - 1), %rax
18556 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
18557 - leaq level2_spare_pgt(%rip), %rbx
18558 - movq %rdx, 0(%rbx, %rax, 8)
18559 -ident_complete:
18560 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
18561
18562 /*
18563 * Fixup the kernel text+data virtual addresses. Note that
18564 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
18565 * after the boot processor executes this code.
18566 */
18567
18568 - /* Enable PAE mode and PGE */
18569 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
18570 + /* Enable PAE mode and PSE/PGE */
18571 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
18572 movq %rax, %cr4
18573
18574 /* Setup early boot stage 4 level pagetables. */
18575 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
18576 movl $MSR_EFER, %ecx
18577 rdmsr
18578 btsl $_EFER_SCE, %eax /* Enable System Call */
18579 - btl $20,%edi /* No Execute supported? */
18580 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
18581 jnc 1f
18582 btsl $_EFER_NX, %eax
18583 + leaq init_level4_pgt(%rip), %rdi
18584 +#ifndef CONFIG_EFI
18585 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
18586 +#endif
18587 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
18588 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
18589 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
18590 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
18591 1: wrmsr /* Make changes effective */
18592
18593 /* Setup cr0 */
18594 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
18595 * jump. In addition we need to ensure %cs is set so we make this
18596 * a far return.
18597 */
18598 + pax_set_fptr_mask
18599 movq initial_code(%rip),%rax
18600 pushq $0 # fake return address to stop unwinder
18601 pushq $__KERNEL_CS # set correct cs
18602 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
18603 bad_address:
18604 jmp bad_address
18605
18606 - .section ".init.text","ax"
18607 + __INIT
18608 .globl early_idt_handlers
18609 early_idt_handlers:
18610 # 104(%rsp) %rflags
18611 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
18612 addq $16,%rsp # drop vector number and error code
18613 decl early_recursion_flag(%rip)
18614 INTERRUPT_RETURN
18615 + .previous
18616
18617 + __INITDATA
18618 .balign 4
18619 early_recursion_flag:
18620 .long 0
18621 + .previous
18622
18623 + .section .rodata,"a",@progbits
18624 #ifdef CONFIG_EARLY_PRINTK
18625 early_idt_msg:
18626 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
18627 @@ -360,6 +369,7 @@ early_idt_ripmsg:
18628 #endif /* CONFIG_EARLY_PRINTK */
18629 .previous
18630
18631 + .section .rodata,"a",@progbits
18632 #define NEXT_PAGE(name) \
18633 .balign PAGE_SIZE; \
18634 ENTRY(name)
18635 @@ -372,7 +382,6 @@ ENTRY(name)
18636 i = i + 1 ; \
18637 .endr
18638
18639 - .data
18640 /*
18641 * This default setting generates an ident mapping at address 0x100000
18642 * and a mapping for the kernel that precisely maps virtual address
18643 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
18644 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18645 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
18646 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18647 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
18648 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
18649 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
18650 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
18651 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
18652 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18653 .org init_level4_pgt + L4_START_KERNEL*8, 0
18654 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
18655 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
18656
18657 +#ifdef CONFIG_PAX_PER_CPU_PGD
18658 +NEXT_PAGE(cpu_pgd)
18659 + .rept NR_CPUS
18660 + .fill 512,8,0
18661 + .endr
18662 +#endif
18663 +
18664 NEXT_PAGE(level3_ident_pgt)
18665 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18666 +#ifdef CONFIG_XEN
18667 .fill 511,8,0
18668 +#else
18669 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
18670 + .fill 510,8,0
18671 +#endif
18672 +
18673 +NEXT_PAGE(level3_vmalloc_start_pgt)
18674 + .fill 512,8,0
18675 +
18676 +NEXT_PAGE(level3_vmalloc_end_pgt)
18677 + .fill 512,8,0
18678 +
18679 +NEXT_PAGE(level3_vmemmap_pgt)
18680 + .fill L3_VMEMMAP_START,8,0
18681 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18682
18683 NEXT_PAGE(level3_kernel_pgt)
18684 .fill L3_START_KERNEL,8,0
18685 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
18686 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
18687 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18688
18689 +NEXT_PAGE(level2_vmemmap_pgt)
18690 + .fill 512,8,0
18691 +
18692 NEXT_PAGE(level2_fixmap_pgt)
18693 - .fill 506,8,0
18694 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18695 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
18696 - .fill 5,8,0
18697 + .fill 507,8,0
18698 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
18699 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
18700 + .fill 4,8,0
18701
18702 -NEXT_PAGE(level1_fixmap_pgt)
18703 +NEXT_PAGE(level1_vsyscall_pgt)
18704 .fill 512,8,0
18705
18706 -NEXT_PAGE(level2_ident_pgt)
18707 - /* Since I easily can, map the first 1G.
18708 + /* Since I easily can, map the first 2G.
18709 * Don't set NX because code runs from these pages.
18710 */
18711 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
18712 +NEXT_PAGE(level2_ident_pgt)
18713 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
18714
18715 NEXT_PAGE(level2_kernel_pgt)
18716 /*
18717 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
18718 * If you want to increase this then increase MODULES_VADDR
18719 * too.)
18720 */
18721 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
18722 - KERNEL_IMAGE_SIZE/PMD_SIZE)
18723 -
18724 -NEXT_PAGE(level2_spare_pgt)
18725 - .fill 512, 8, 0
18726 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
18727
18728 #undef PMDS
18729 #undef NEXT_PAGE
18730
18731 - .data
18732 + .align PAGE_SIZE
18733 +ENTRY(cpu_gdt_table)
18734 + .rept NR_CPUS
18735 + .quad 0x0000000000000000 /* NULL descriptor */
18736 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
18737 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
18738 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
18739 + .quad 0x00cffb000000ffff /* __USER32_CS */
18740 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
18741 + .quad 0x00affb000000ffff /* __USER_CS */
18742 +
18743 +#ifdef CONFIG_PAX_KERNEXEC
18744 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
18745 +#else
18746 + .quad 0x0 /* unused */
18747 +#endif
18748 +
18749 + .quad 0,0 /* TSS */
18750 + .quad 0,0 /* LDT */
18751 + .quad 0,0,0 /* three TLS descriptors */
18752 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
18753 + /* asm/segment.h:GDT_ENTRIES must match this */
18754 +
18755 + /* zero the remaining page */
18756 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
18757 + .endr
18758 +
18759 .align 16
18760 .globl early_gdt_descr
18761 early_gdt_descr:
18762 .word GDT_ENTRIES*8-1
18763 early_gdt_descr_base:
18764 - .quad INIT_PER_CPU_VAR(gdt_page)
18765 + .quad cpu_gdt_table
18766
18767 ENTRY(phys_base)
18768 /* This must match the first entry in level2_kernel_pgt */
18769 .quad 0x0000000000000000
18770
18771 #include "../../x86/xen/xen-head.S"
18772 -
18773 - .section .bss, "aw", @nobits
18774 +
18775 + .section .rodata,"a",@progbits
18776 .align L1_CACHE_BYTES
18777 ENTRY(idt_table)
18778 - .skip IDT_ENTRIES * 16
18779 + .fill 512,8,0
18780
18781 .align L1_CACHE_BYTES
18782 ENTRY(nmi_idt_table)
18783 - .skip IDT_ENTRIES * 16
18784 + .fill 512,8,0
18785
18786 __PAGE_ALIGNED_BSS
18787 .align PAGE_SIZE
18788 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
18789 index 9c3bd4a..e1d9b35 100644
18790 --- a/arch/x86/kernel/i386_ksyms_32.c
18791 +++ b/arch/x86/kernel/i386_ksyms_32.c
18792 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
18793 EXPORT_SYMBOL(cmpxchg8b_emu);
18794 #endif
18795
18796 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
18797 +
18798 /* Networking helper routines. */
18799 EXPORT_SYMBOL(csum_partial_copy_generic);
18800 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
18801 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
18802
18803 EXPORT_SYMBOL(__get_user_1);
18804 EXPORT_SYMBOL(__get_user_2);
18805 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
18806
18807 EXPORT_SYMBOL(csum_partial);
18808 EXPORT_SYMBOL(empty_zero_page);
18809 +
18810 +#ifdef CONFIG_PAX_KERNEXEC
18811 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
18812 +#endif
18813 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
18814 index 675a050..95febfd 100644
18815 --- a/arch/x86/kernel/i387.c
18816 +++ b/arch/x86/kernel/i387.c
18817 @@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
18818 static inline bool interrupted_user_mode(void)
18819 {
18820 struct pt_regs *regs = get_irq_regs();
18821 - return regs && user_mode_vm(regs);
18822 + return regs && user_mode(regs);
18823 }
18824
18825 /*
18826 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
18827 index 9a5c460..dc4374d 100644
18828 --- a/arch/x86/kernel/i8259.c
18829 +++ b/arch/x86/kernel/i8259.c
18830 @@ -209,7 +209,7 @@ spurious_8259A_irq:
18831 "spurious 8259A interrupt: IRQ%d.\n", irq);
18832 spurious_irq_mask |= irqmask;
18833 }
18834 - atomic_inc(&irq_err_count);
18835 + atomic_inc_unchecked(&irq_err_count);
18836 /*
18837 * Theoretically we do not have to handle this IRQ,
18838 * but in Linux this does not cause problems and is
18839 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
18840 index 8c96897..be66bfa 100644
18841 --- a/arch/x86/kernel/ioport.c
18842 +++ b/arch/x86/kernel/ioport.c
18843 @@ -6,6 +6,7 @@
18844 #include <linux/sched.h>
18845 #include <linux/kernel.h>
18846 #include <linux/capability.h>
18847 +#include <linux/security.h>
18848 #include <linux/errno.h>
18849 #include <linux/types.h>
18850 #include <linux/ioport.h>
18851 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18852
18853 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
18854 return -EINVAL;
18855 +#ifdef CONFIG_GRKERNSEC_IO
18856 + if (turn_on && grsec_disable_privio) {
18857 + gr_handle_ioperm();
18858 + return -EPERM;
18859 + }
18860 +#endif
18861 if (turn_on && !capable(CAP_SYS_RAWIO))
18862 return -EPERM;
18863
18864 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18865 * because the ->io_bitmap_max value must match the bitmap
18866 * contents:
18867 */
18868 - tss = &per_cpu(init_tss, get_cpu());
18869 + tss = init_tss + get_cpu();
18870
18871 if (turn_on)
18872 bitmap_clear(t->io_bitmap_ptr, from, num);
18873 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
18874 return -EINVAL;
18875 /* Trying to gain more privileges? */
18876 if (level > old) {
18877 +#ifdef CONFIG_GRKERNSEC_IO
18878 + if (grsec_disable_privio) {
18879 + gr_handle_iopl();
18880 + return -EPERM;
18881 + }
18882 +#endif
18883 if (!capable(CAP_SYS_RAWIO))
18884 return -EPERM;
18885 }
18886 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
18887 index e4595f1..ee3bfb8 100644
18888 --- a/arch/x86/kernel/irq.c
18889 +++ b/arch/x86/kernel/irq.c
18890 @@ -18,7 +18,7 @@
18891 #include <asm/mce.h>
18892 #include <asm/hw_irq.h>
18893
18894 -atomic_t irq_err_count;
18895 +atomic_unchecked_t irq_err_count;
18896
18897 /* Function pointer for generic interrupt vector handling */
18898 void (*x86_platform_ipi_callback)(void) = NULL;
18899 @@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
18900 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
18901 seq_printf(p, " Machine check polls\n");
18902 #endif
18903 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
18904 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
18905 #if defined(CONFIG_X86_IO_APIC)
18906 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
18907 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
18908 #endif
18909 return 0;
18910 }
18911 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
18912
18913 u64 arch_irq_stat(void)
18914 {
18915 - u64 sum = atomic_read(&irq_err_count);
18916 + u64 sum = atomic_read_unchecked(&irq_err_count);
18917
18918 #ifdef CONFIG_X86_IO_APIC
18919 - sum += atomic_read(&irq_mis_count);
18920 + sum += atomic_read_unchecked(&irq_mis_count);
18921 #endif
18922 return sum;
18923 }
18924 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
18925 index 344faf8..355f60d 100644
18926 --- a/arch/x86/kernel/irq_32.c
18927 +++ b/arch/x86/kernel/irq_32.c
18928 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
18929 __asm__ __volatile__("andl %%esp,%0" :
18930 "=r" (sp) : "0" (THREAD_SIZE - 1));
18931
18932 - return sp < (sizeof(struct thread_info) + STACK_WARN);
18933 + return sp < STACK_WARN;
18934 }
18935
18936 static void print_stack_overflow(void)
18937 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
18938 * per-CPU IRQ handling contexts (thread information and stack)
18939 */
18940 union irq_ctx {
18941 - struct thread_info tinfo;
18942 - u32 stack[THREAD_SIZE/sizeof(u32)];
18943 + unsigned long previous_esp;
18944 + u32 stack[THREAD_SIZE/sizeof(u32)];
18945 } __attribute__((aligned(THREAD_SIZE)));
18946
18947 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
18948 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
18949 static inline int
18950 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18951 {
18952 - union irq_ctx *curctx, *irqctx;
18953 + union irq_ctx *irqctx;
18954 u32 *isp, arg1, arg2;
18955
18956 - curctx = (union irq_ctx *) current_thread_info();
18957 irqctx = __this_cpu_read(hardirq_ctx);
18958
18959 /*
18960 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18961 * handler) we can't do that and just have to keep using the
18962 * current stack (which is the irq stack already after all)
18963 */
18964 - if (unlikely(curctx == irqctx))
18965 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
18966 return 0;
18967
18968 /* build the stack frame on the IRQ stack */
18969 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
18970 - irqctx->tinfo.task = curctx->tinfo.task;
18971 - irqctx->tinfo.previous_esp = current_stack_pointer;
18972 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
18973 + irqctx->previous_esp = current_stack_pointer;
18974
18975 - /* Copy the preempt_count so that the [soft]irq checks work. */
18976 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
18977 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18978 + __set_fs(MAKE_MM_SEG(0));
18979 +#endif
18980
18981 if (unlikely(overflow))
18982 call_on_stack(print_stack_overflow, isp);
18983 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18984 : "0" (irq), "1" (desc), "2" (isp),
18985 "D" (desc->handle_irq)
18986 : "memory", "cc", "ecx");
18987 +
18988 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18989 + __set_fs(current_thread_info()->addr_limit);
18990 +#endif
18991 +
18992 return 1;
18993 }
18994
18995 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18996 */
18997 void __cpuinit irq_ctx_init(int cpu)
18998 {
18999 - union irq_ctx *irqctx;
19000 -
19001 if (per_cpu(hardirq_ctx, cpu))
19002 return;
19003
19004 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
19005 - THREADINFO_GFP,
19006 - THREAD_SIZE_ORDER));
19007 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
19008 - irqctx->tinfo.cpu = cpu;
19009 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
19010 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
19011 -
19012 - per_cpu(hardirq_ctx, cpu) = irqctx;
19013 -
19014 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
19015 - THREADINFO_GFP,
19016 - THREAD_SIZE_ORDER));
19017 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
19018 - irqctx->tinfo.cpu = cpu;
19019 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
19020 -
19021 - per_cpu(softirq_ctx, cpu) = irqctx;
19022 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
19023 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
19024 +
19025 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
19026 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
19027
19028 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
19029 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
19030 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
19031 asmlinkage void do_softirq(void)
19032 {
19033 unsigned long flags;
19034 - struct thread_info *curctx;
19035 union irq_ctx *irqctx;
19036 u32 *isp;
19037
19038 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
19039 local_irq_save(flags);
19040
19041 if (local_softirq_pending()) {
19042 - curctx = current_thread_info();
19043 irqctx = __this_cpu_read(softirq_ctx);
19044 - irqctx->tinfo.task = curctx->task;
19045 - irqctx->tinfo.previous_esp = current_stack_pointer;
19046 + irqctx->previous_esp = current_stack_pointer;
19047
19048 /* build the stack frame on the softirq stack */
19049 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
19050 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
19051 +
19052 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19053 + __set_fs(MAKE_MM_SEG(0));
19054 +#endif
19055
19056 call_on_stack(__do_softirq, isp);
19057 +
19058 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19059 + __set_fs(current_thread_info()->addr_limit);
19060 +#endif
19061 +
19062 /*
19063 * Shouldn't happen, we returned above if in_interrupt():
19064 */
19065 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
19066 if (unlikely(!desc))
19067 return false;
19068
19069 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
19070 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
19071 if (unlikely(overflow))
19072 print_stack_overflow();
19073 desc->handle_irq(irq, desc);
19074 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
19075 index d04d3ec..ea4b374 100644
19076 --- a/arch/x86/kernel/irq_64.c
19077 +++ b/arch/x86/kernel/irq_64.c
19078 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
19079 u64 estack_top, estack_bottom;
19080 u64 curbase = (u64)task_stack_page(current);
19081
19082 - if (user_mode_vm(regs))
19083 + if (user_mode(regs))
19084 return;
19085
19086 if (regs->sp >= curbase + sizeof(struct thread_info) +
19087 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
19088 index dc1404b..bbc43e7 100644
19089 --- a/arch/x86/kernel/kdebugfs.c
19090 +++ b/arch/x86/kernel/kdebugfs.c
19091 @@ -27,7 +27,7 @@ struct setup_data_node {
19092 u32 len;
19093 };
19094
19095 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
19096 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
19097 size_t count, loff_t *ppos)
19098 {
19099 struct setup_data_node *node = file->private_data;
19100 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
19101 index 836f832..a8bda67 100644
19102 --- a/arch/x86/kernel/kgdb.c
19103 +++ b/arch/x86/kernel/kgdb.c
19104 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
19105 #ifdef CONFIG_X86_32
19106 switch (regno) {
19107 case GDB_SS:
19108 - if (!user_mode_vm(regs))
19109 + if (!user_mode(regs))
19110 *(unsigned long *)mem = __KERNEL_DS;
19111 break;
19112 case GDB_SP:
19113 - if (!user_mode_vm(regs))
19114 + if (!user_mode(regs))
19115 *(unsigned long *)mem = kernel_stack_pointer(regs);
19116 break;
19117 case GDB_GS:
19118 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
19119 bp->attr.bp_addr = breakinfo[breakno].addr;
19120 bp->attr.bp_len = breakinfo[breakno].len;
19121 bp->attr.bp_type = breakinfo[breakno].type;
19122 - info->address = breakinfo[breakno].addr;
19123 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
19124 + info->address = ktla_ktva(breakinfo[breakno].addr);
19125 + else
19126 + info->address = breakinfo[breakno].addr;
19127 info->len = breakinfo[breakno].len;
19128 info->type = breakinfo[breakno].type;
19129 val = arch_install_hw_breakpoint(bp);
19130 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
19131 case 'k':
19132 /* clear the trace bit */
19133 linux_regs->flags &= ~X86_EFLAGS_TF;
19134 - atomic_set(&kgdb_cpu_doing_single_step, -1);
19135 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
19136
19137 /* set the trace bit if we're stepping */
19138 if (remcomInBuffer[0] == 's') {
19139 linux_regs->flags |= X86_EFLAGS_TF;
19140 - atomic_set(&kgdb_cpu_doing_single_step,
19141 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
19142 raw_smp_processor_id());
19143 }
19144
19145 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
19146
19147 switch (cmd) {
19148 case DIE_DEBUG:
19149 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
19150 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
19151 if (user_mode(regs))
19152 return single_step_cont(regs, args);
19153 break;
19154 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
19155 #endif /* CONFIG_DEBUG_RODATA */
19156
19157 bpt->type = BP_BREAKPOINT;
19158 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
19159 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
19160 BREAK_INSTR_SIZE);
19161 if (err)
19162 return err;
19163 - err = probe_kernel_write((char *)bpt->bpt_addr,
19164 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
19165 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
19166 #ifdef CONFIG_DEBUG_RODATA
19167 if (!err)
19168 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
19169 return -EBUSY;
19170 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
19171 BREAK_INSTR_SIZE);
19172 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
19173 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
19174 if (err)
19175 return err;
19176 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
19177 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
19178 if (mutex_is_locked(&text_mutex))
19179 goto knl_write;
19180 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
19181 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
19182 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
19183 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
19184 goto knl_write;
19185 return err;
19186 knl_write:
19187 #endif /* CONFIG_DEBUG_RODATA */
19188 - return probe_kernel_write((char *)bpt->bpt_addr,
19189 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
19190 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
19191 }
19192
19193 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
19194 index c5e410e..ed5a7f0 100644
19195 --- a/arch/x86/kernel/kprobes-opt.c
19196 +++ b/arch/x86/kernel/kprobes-opt.c
19197 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
19198 * Verify if the address gap is in 2GB range, because this uses
19199 * a relative jump.
19200 */
19201 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
19202 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
19203 if (abs(rel) > 0x7fffffff)
19204 return -ERANGE;
19205
19206 @@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
19207 op->optinsn.size = ret;
19208
19209 /* Copy arch-dep-instance from template */
19210 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
19211 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
19212
19213 /* Set probe information */
19214 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
19215
19216 /* Set probe function call */
19217 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
19218 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
19219
19220 /* Set returning jmp instruction at the tail of out-of-line buffer */
19221 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
19222 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
19223 (u8 *)op->kp.addr + op->optinsn.size);
19224
19225 flush_icache_range((unsigned long) buf,
19226 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
19227 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
19228
19229 /* Backup instructions which will be replaced by jump address */
19230 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
19231 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
19232 RELATIVE_ADDR_SIZE);
19233
19234 insn_buf[0] = RELATIVEJUMP_OPCODE;
19235 @@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
19236 /* This kprobe is really able to run optimized path. */
19237 op = container_of(p, struct optimized_kprobe, kp);
19238 /* Detour through copied instructions */
19239 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
19240 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
19241 if (!reenter)
19242 reset_current_kprobe();
19243 preempt_enable_no_resched();
19244 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
19245 index 57916c0..9e0b9d0 100644
19246 --- a/arch/x86/kernel/kprobes.c
19247 +++ b/arch/x86/kernel/kprobes.c
19248 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
19249 s32 raddr;
19250 } __attribute__((packed)) *insn;
19251
19252 - insn = (struct __arch_relative_insn *)from;
19253 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
19254 +
19255 + pax_open_kernel();
19256 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
19257 insn->op = op;
19258 + pax_close_kernel();
19259 }
19260
19261 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
19262 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
19263 kprobe_opcode_t opcode;
19264 kprobe_opcode_t *orig_opcodes = opcodes;
19265
19266 - if (search_exception_tables((unsigned long)opcodes))
19267 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
19268 return 0; /* Page fault may occur on this address. */
19269
19270 retry:
19271 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
19272 * for the first byte, we can recover the original instruction
19273 * from it and kp->opcode.
19274 */
19275 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19276 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19277 buf[0] = kp->opcode;
19278 - return (unsigned long)buf;
19279 + return ktva_ktla((unsigned long)buf);
19280 }
19281
19282 /*
19283 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19284 /* Another subsystem puts a breakpoint, failed to recover */
19285 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
19286 return 0;
19287 + pax_open_kernel();
19288 memcpy(dest, insn.kaddr, insn.length);
19289 + pax_close_kernel();
19290
19291 #ifdef CONFIG_X86_64
19292 if (insn_rip_relative(&insn)) {
19293 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19294 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
19295 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
19296 disp = (u8 *) dest + insn_offset_displacement(&insn);
19297 + pax_open_kernel();
19298 *(s32 *) disp = (s32) newdisp;
19299 + pax_close_kernel();
19300 }
19301 #endif
19302 return insn.length;
19303 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19304 * nor set current_kprobe, because it doesn't use single
19305 * stepping.
19306 */
19307 - regs->ip = (unsigned long)p->ainsn.insn;
19308 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19309 preempt_enable_no_resched();
19310 return;
19311 }
19312 @@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19313 regs->flags &= ~X86_EFLAGS_IF;
19314 /* single step inline if the instruction is an int3 */
19315 if (p->opcode == BREAKPOINT_INSTRUCTION)
19316 - regs->ip = (unsigned long)p->addr;
19317 + regs->ip = ktla_ktva((unsigned long)p->addr);
19318 else
19319 - regs->ip = (unsigned long)p->ainsn.insn;
19320 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19321 }
19322
19323 /*
19324 @@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
19325 setup_singlestep(p, regs, kcb, 0);
19326 return 1;
19327 }
19328 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
19329 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
19330 /*
19331 * The breakpoint instruction was removed right
19332 * after we hit it. Another cpu has removed
19333 @@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
19334 " movq %rax, 152(%rsp)\n"
19335 RESTORE_REGS_STRING
19336 " popfq\n"
19337 +#ifdef KERNEXEC_PLUGIN
19338 + " btsq $63,(%rsp)\n"
19339 +#endif
19340 #else
19341 " pushf\n"
19342 SAVE_REGS_STRING
19343 @@ -788,7 +798,7 @@ static void __kprobes
19344 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
19345 {
19346 unsigned long *tos = stack_addr(regs);
19347 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
19348 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
19349 unsigned long orig_ip = (unsigned long)p->addr;
19350 kprobe_opcode_t *insn = p->ainsn.insn;
19351
19352 @@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
19353 struct die_args *args = data;
19354 int ret = NOTIFY_DONE;
19355
19356 - if (args->regs && user_mode_vm(args->regs))
19357 + if (args->regs && user_mode(args->regs))
19358 return ret;
19359
19360 switch (val) {
19361 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
19362 index 4180a87..4678e4f 100644
19363 --- a/arch/x86/kernel/kvm.c
19364 +++ b/arch/x86/kernel/kvm.c
19365 @@ -267,7 +267,7 @@ static void __init paravirt_ops_setup(void)
19366 pv_info.paravirt_enabled = 1;
19367
19368 if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY))
19369 - pv_cpu_ops.io_delay = kvm_io_delay;
19370 + *(void **)&pv_cpu_ops.io_delay = kvm_io_delay;
19371
19372 #ifdef CONFIG_X86_IO_APIC
19373 no_timer_check = 1;
19374 @@ -461,18 +461,18 @@ void __init kvm_guest_init(void)
19375 for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++)
19376 spin_lock_init(&async_pf_sleepers[i].lock);
19377 if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF))
19378 - x86_init.irqs.trap_init = kvm_apf_trap_init;
19379 + *(void **)&x86_init.irqs.trap_init = kvm_apf_trap_init;
19380
19381 if (kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) {
19382 has_steal_clock = 1;
19383 - pv_time_ops.steal_clock = kvm_steal_clock;
19384 + *(void **)&pv_time_ops.steal_clock = kvm_steal_clock;
19385 }
19386
19387 if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
19388 apic_set_eoi_write(kvm_guest_apic_eoi_write);
19389
19390 #ifdef CONFIG_SMP
19391 - smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
19392 + *(void **)&smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
19393 register_cpu_notifier(&kvm_cpu_notifier);
19394 #else
19395 kvm_guest_cpu_init();
19396 diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
19397 index f1b42b3..27ac4e7 100644
19398 --- a/arch/x86/kernel/kvmclock.c
19399 +++ b/arch/x86/kernel/kvmclock.c
19400 @@ -211,19 +211,19 @@ void __init kvmclock_init(void)
19401
19402 if (kvm_register_clock("boot clock"))
19403 return;
19404 - pv_time_ops.sched_clock = kvm_clock_read;
19405 - x86_platform.calibrate_tsc = kvm_get_tsc_khz;
19406 - x86_platform.get_wallclock = kvm_get_wallclock;
19407 - x86_platform.set_wallclock = kvm_set_wallclock;
19408 + *(void **)&pv_time_ops.sched_clock = kvm_clock_read;
19409 + *(void **)&x86_platform.calibrate_tsc = kvm_get_tsc_khz;
19410 + *(void **)&x86_platform.get_wallclock = kvm_get_wallclock;
19411 + *(void **)&x86_platform.set_wallclock = kvm_set_wallclock;
19412 #ifdef CONFIG_X86_LOCAL_APIC
19413 - x86_cpuinit.early_percpu_clock_init =
19414 + *(void **)&x86_cpuinit.early_percpu_clock_init =
19415 kvm_setup_secondary_clock;
19416 #endif
19417 - x86_platform.save_sched_clock_state = kvm_save_sched_clock_state;
19418 - x86_platform.restore_sched_clock_state = kvm_restore_sched_clock_state;
19419 - machine_ops.shutdown = kvm_shutdown;
19420 + *(void **)&x86_platform.save_sched_clock_state = kvm_save_sched_clock_state;
19421 + *(void **)&x86_platform.restore_sched_clock_state = kvm_restore_sched_clock_state;
19422 + *(void **)&machine_ops.shutdown = kvm_shutdown;
19423 #ifdef CONFIG_KEXEC
19424 - machine_ops.crash_shutdown = kvm_crash_shutdown;
19425 + *(void **)&machine_ops.crash_shutdown = kvm_crash_shutdown;
19426 #endif
19427 kvm_get_preset_lpj();
19428 clocksource_register_hz(&kvm_clock, NSEC_PER_SEC);
19429 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
19430 index ebc9873..1b9724b 100644
19431 --- a/arch/x86/kernel/ldt.c
19432 +++ b/arch/x86/kernel/ldt.c
19433 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
19434 if (reload) {
19435 #ifdef CONFIG_SMP
19436 preempt_disable();
19437 - load_LDT(pc);
19438 + load_LDT_nolock(pc);
19439 if (!cpumask_equal(mm_cpumask(current->mm),
19440 cpumask_of(smp_processor_id())))
19441 smp_call_function(flush_ldt, current->mm, 1);
19442 preempt_enable();
19443 #else
19444 - load_LDT(pc);
19445 + load_LDT_nolock(pc);
19446 #endif
19447 }
19448 if (oldsize) {
19449 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
19450 return err;
19451
19452 for (i = 0; i < old->size; i++)
19453 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
19454 + write_ldt_entry(new->ldt, i, old->ldt + i);
19455 return 0;
19456 }
19457
19458 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
19459 retval = copy_ldt(&mm->context, &old_mm->context);
19460 mutex_unlock(&old_mm->context.lock);
19461 }
19462 +
19463 + if (tsk == current) {
19464 + mm->context.vdso = 0;
19465 +
19466 +#ifdef CONFIG_X86_32
19467 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
19468 + mm->context.user_cs_base = 0UL;
19469 + mm->context.user_cs_limit = ~0UL;
19470 +
19471 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
19472 + cpus_clear(mm->context.cpu_user_cs_mask);
19473 +#endif
19474 +
19475 +#endif
19476 +#endif
19477 +
19478 + }
19479 +
19480 return retval;
19481 }
19482
19483 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
19484 }
19485 }
19486
19487 +#ifdef CONFIG_PAX_SEGMEXEC
19488 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
19489 + error = -EINVAL;
19490 + goto out_unlock;
19491 + }
19492 +#endif
19493 +
19494 fill_ldt(&ldt, &ldt_info);
19495 if (oldmode)
19496 ldt.avl = 0;
19497 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
19498 index 5b19e4d..6476a76 100644
19499 --- a/arch/x86/kernel/machine_kexec_32.c
19500 +++ b/arch/x86/kernel/machine_kexec_32.c
19501 @@ -26,7 +26,7 @@
19502 #include <asm/cacheflush.h>
19503 #include <asm/debugreg.h>
19504
19505 -static void set_idt(void *newidt, __u16 limit)
19506 +static void set_idt(struct desc_struct *newidt, __u16 limit)
19507 {
19508 struct desc_ptr curidt;
19509
19510 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
19511 }
19512
19513
19514 -static void set_gdt(void *newgdt, __u16 limit)
19515 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
19516 {
19517 struct desc_ptr curgdt;
19518
19519 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
19520 }
19521
19522 control_page = page_address(image->control_code_page);
19523 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
19524 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
19525
19526 relocate_kernel_ptr = control_page;
19527 page_list[PA_CONTROL_PAGE] = __pa(control_page);
19528 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
19529 index 3544aed..01ddc1c 100644
19530 --- a/arch/x86/kernel/microcode_intel.c
19531 +++ b/arch/x86/kernel/microcode_intel.c
19532 @@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
19533
19534 static int get_ucode_user(void *to, const void *from, size_t n)
19535 {
19536 - return copy_from_user(to, from, n);
19537 + return copy_from_user(to, (const void __force_user *)from, n);
19538 }
19539
19540 static enum ucode_state
19541 request_microcode_user(int cpu, const void __user *buf, size_t size)
19542 {
19543 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
19544 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
19545 }
19546
19547 static void microcode_fini_cpu(int cpu)
19548 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
19549 index 216a4d7..228255a 100644
19550 --- a/arch/x86/kernel/module.c
19551 +++ b/arch/x86/kernel/module.c
19552 @@ -43,15 +43,60 @@ do { \
19553 } while (0)
19554 #endif
19555
19556 -void *module_alloc(unsigned long size)
19557 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
19558 {
19559 - if (PAGE_ALIGN(size) > MODULES_LEN)
19560 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
19561 return NULL;
19562 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
19563 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
19564 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
19565 -1, __builtin_return_address(0));
19566 }
19567
19568 +void *module_alloc(unsigned long size)
19569 +{
19570 +
19571 +#ifdef CONFIG_PAX_KERNEXEC
19572 + return __module_alloc(size, PAGE_KERNEL);
19573 +#else
19574 + return __module_alloc(size, PAGE_KERNEL_EXEC);
19575 +#endif
19576 +
19577 +}
19578 +
19579 +#ifdef CONFIG_PAX_KERNEXEC
19580 +#ifdef CONFIG_X86_32
19581 +void *module_alloc_exec(unsigned long size)
19582 +{
19583 + struct vm_struct *area;
19584 +
19585 + if (size == 0)
19586 + return NULL;
19587 +
19588 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
19589 + return area ? area->addr : NULL;
19590 +}
19591 +EXPORT_SYMBOL(module_alloc_exec);
19592 +
19593 +void module_free_exec(struct module *mod, void *module_region)
19594 +{
19595 + vunmap(module_region);
19596 +}
19597 +EXPORT_SYMBOL(module_free_exec);
19598 +#else
19599 +void module_free_exec(struct module *mod, void *module_region)
19600 +{
19601 + module_free(mod, module_region);
19602 +}
19603 +EXPORT_SYMBOL(module_free_exec);
19604 +
19605 +void *module_alloc_exec(unsigned long size)
19606 +{
19607 + return __module_alloc(size, PAGE_KERNEL_RX);
19608 +}
19609 +EXPORT_SYMBOL(module_alloc_exec);
19610 +#endif
19611 +#endif
19612 +
19613 #ifdef CONFIG_X86_32
19614 int apply_relocate(Elf32_Shdr *sechdrs,
19615 const char *strtab,
19616 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19617 unsigned int i;
19618 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
19619 Elf32_Sym *sym;
19620 - uint32_t *location;
19621 + uint32_t *plocation, location;
19622
19623 DEBUGP("Applying relocate section %u to %u\n",
19624 relsec, sechdrs[relsec].sh_info);
19625 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
19626 /* This is where to make the change */
19627 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
19628 - + rel[i].r_offset;
19629 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
19630 + location = (uint32_t)plocation;
19631 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
19632 + plocation = ktla_ktva((void *)plocation);
19633 /* This is the symbol it is referring to. Note that all
19634 undefined symbols have been resolved. */
19635 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
19636 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19637 switch (ELF32_R_TYPE(rel[i].r_info)) {
19638 case R_386_32:
19639 /* We add the value into the location given */
19640 - *location += sym->st_value;
19641 + pax_open_kernel();
19642 + *plocation += sym->st_value;
19643 + pax_close_kernel();
19644 break;
19645 case R_386_PC32:
19646 /* Add the value, subtract its position */
19647 - *location += sym->st_value - (uint32_t)location;
19648 + pax_open_kernel();
19649 + *plocation += sym->st_value - location;
19650 + pax_close_kernel();
19651 break;
19652 default:
19653 pr_err("%s: Unknown relocation: %u\n",
19654 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
19655 case R_X86_64_NONE:
19656 break;
19657 case R_X86_64_64:
19658 + pax_open_kernel();
19659 *(u64 *)loc = val;
19660 + pax_close_kernel();
19661 break;
19662 case R_X86_64_32:
19663 + pax_open_kernel();
19664 *(u32 *)loc = val;
19665 + pax_close_kernel();
19666 if (val != *(u32 *)loc)
19667 goto overflow;
19668 break;
19669 case R_X86_64_32S:
19670 + pax_open_kernel();
19671 *(s32 *)loc = val;
19672 + pax_close_kernel();
19673 if ((s64)val != *(s32 *)loc)
19674 goto overflow;
19675 break;
19676 case R_X86_64_PC32:
19677 val -= (u64)loc;
19678 + pax_open_kernel();
19679 *(u32 *)loc = val;
19680 + pax_close_kernel();
19681 +
19682 #if 0
19683 if ((s64)val != *(s32 *)loc)
19684 goto overflow;
19685 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
19686 index f84f5c5..e27e54b 100644
19687 --- a/arch/x86/kernel/nmi.c
19688 +++ b/arch/x86/kernel/nmi.c
19689 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
19690 dotraplinkage notrace __kprobes void
19691 do_nmi(struct pt_regs *regs, long error_code)
19692 {
19693 +
19694 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19695 + if (!user_mode(regs)) {
19696 + unsigned long cs = regs->cs & 0xFFFF;
19697 + unsigned long ip = ktva_ktla(regs->ip);
19698 +
19699 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
19700 + regs->ip = ip;
19701 + }
19702 +#endif
19703 +
19704 nmi_nesting_preprocess(regs);
19705
19706 nmi_enter();
19707 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
19708 index 676b8c7..870ba04 100644
19709 --- a/arch/x86/kernel/paravirt-spinlocks.c
19710 +++ b/arch/x86/kernel/paravirt-spinlocks.c
19711 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
19712 arch_spin_lock(lock);
19713 }
19714
19715 -struct pv_lock_ops pv_lock_ops = {
19716 +struct pv_lock_ops pv_lock_ops __read_only = {
19717 #ifdef CONFIG_SMP
19718 .spin_is_locked = __ticket_spin_is_locked,
19719 .spin_is_contended = __ticket_spin_is_contended,
19720 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
19721 index 17fff18..0f5f957 100644
19722 --- a/arch/x86/kernel/paravirt.c
19723 +++ b/arch/x86/kernel/paravirt.c
19724 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
19725 {
19726 return x;
19727 }
19728 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19729 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
19730 +#endif
19731
19732 void __init default_banner(void)
19733 {
19734 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
19735 if (opfunc == NULL)
19736 /* If there's no function, patch it with a ud2a (BUG) */
19737 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
19738 - else if (opfunc == _paravirt_nop)
19739 + else if (opfunc == (void *)_paravirt_nop)
19740 /* If the operation is a nop, then nop the callsite */
19741 ret = paravirt_patch_nop();
19742
19743 /* identity functions just return their single argument */
19744 - else if (opfunc == _paravirt_ident_32)
19745 + else if (opfunc == (void *)_paravirt_ident_32)
19746 ret = paravirt_patch_ident_32(insnbuf, len);
19747 - else if (opfunc == _paravirt_ident_64)
19748 + else if (opfunc == (void *)_paravirt_ident_64)
19749 ret = paravirt_patch_ident_64(insnbuf, len);
19750 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19751 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
19752 + ret = paravirt_patch_ident_64(insnbuf, len);
19753 +#endif
19754
19755 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
19756 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
19757 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
19758 if (insn_len > len || start == NULL)
19759 insn_len = len;
19760 else
19761 - memcpy(insnbuf, start, insn_len);
19762 + memcpy(insnbuf, ktla_ktva(start), insn_len);
19763
19764 return insn_len;
19765 }
19766 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
19767 preempt_enable();
19768 }
19769
19770 -struct pv_info pv_info = {
19771 +struct pv_info pv_info __read_only = {
19772 .name = "bare hardware",
19773 .paravirt_enabled = 0,
19774 .kernel_rpl = 0,
19775 @@ -324,7 +331,7 @@ struct pv_time_ops pv_time_ops = {
19776 .steal_clock = native_steal_clock,
19777 };
19778
19779 -struct pv_irq_ops pv_irq_ops = {
19780 +struct pv_irq_ops pv_irq_ops __read_only = {
19781 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
19782 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
19783 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
19784 @@ -401,15 +408,20 @@ struct pv_apic_ops pv_apic_ops = {
19785 #endif
19786 };
19787
19788 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
19789 +#ifdef CONFIG_X86_32
19790 +#ifdef CONFIG_X86_PAE
19791 +/* 64-bit pagetable entries */
19792 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
19793 +#else
19794 /* 32-bit pagetable entries */
19795 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
19796 +#endif
19797 #else
19798 /* 64-bit pagetable entries */
19799 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
19800 #endif
19801
19802 -struct pv_mmu_ops pv_mmu_ops = {
19803 +struct pv_mmu_ops pv_mmu_ops __read_only = {
19804
19805 .read_cr2 = native_read_cr2,
19806 .write_cr2 = native_write_cr2,
19807 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
19808 .make_pud = PTE_IDENT,
19809
19810 .set_pgd = native_set_pgd,
19811 + .set_pgd_batched = native_set_pgd_batched,
19812 #endif
19813 #endif /* PAGETABLE_LEVELS >= 3 */
19814
19815 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
19816 },
19817
19818 .set_fixmap = native_set_fixmap,
19819 +
19820 +#ifdef CONFIG_PAX_KERNEXEC
19821 + .pax_open_kernel = native_pax_open_kernel,
19822 + .pax_close_kernel = native_pax_close_kernel,
19823 +#endif
19824 +
19825 };
19826
19827 EXPORT_SYMBOL_GPL(pv_time_ops);
19828 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
19829 index 299d493..79c13dd 100644
19830 --- a/arch/x86/kernel/pci-calgary_64.c
19831 +++ b/arch/x86/kernel/pci-calgary_64.c
19832 @@ -1461,7 +1461,7 @@ int __init detect_calgary(void)
19833 printk(KERN_INFO "PCI-DMA: Calgary TCE table spec is %d\n",
19834 specified_table_size);
19835
19836 - x86_init.iommu.iommu_init = calgary_iommu_init;
19837 + *(void **)&x86_init.iommu.iommu_init = calgary_iommu_init;
19838 }
19839 return calgary_found;
19840
19841 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
19842 index 35ccf75..7a15747 100644
19843 --- a/arch/x86/kernel/pci-iommu_table.c
19844 +++ b/arch/x86/kernel/pci-iommu_table.c
19845 @@ -2,7 +2,7 @@
19846 #include <asm/iommu_table.h>
19847 #include <linux/string.h>
19848 #include <linux/kallsyms.h>
19849 -
19850 +#include <linux/sched.h>
19851
19852 #define DEBUG 1
19853
19854 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
19855 index b644e1c..4a6d379 100644
19856 --- a/arch/x86/kernel/process.c
19857 +++ b/arch/x86/kernel/process.c
19858 @@ -36,7 +36,8 @@
19859 * section. Since TSS's are completely CPU-local, we want them
19860 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
19861 */
19862 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
19863 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
19864 +EXPORT_SYMBOL(init_tss);
19865
19866 #ifdef CONFIG_X86_64
19867 static DEFINE_PER_CPU(unsigned char, is_idle);
19868 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
19869 task_xstate_cachep =
19870 kmem_cache_create("task_xstate", xstate_size,
19871 __alignof__(union thread_xstate),
19872 - SLAB_PANIC | SLAB_NOTRACK, NULL);
19873 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
19874 }
19875
19876 /*
19877 @@ -105,7 +106,7 @@ void exit_thread(void)
19878 unsigned long *bp = t->io_bitmap_ptr;
19879
19880 if (bp) {
19881 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
19882 + struct tss_struct *tss = init_tss + get_cpu();
19883
19884 t->io_bitmap_ptr = NULL;
19885 clear_thread_flag(TIF_IO_BITMAP);
19886 @@ -136,7 +137,7 @@ void show_regs_common(void)
19887 board = dmi_get_system_info(DMI_BOARD_NAME);
19888
19889 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
19890 - current->pid, current->comm, print_tainted(),
19891 + task_pid_nr(current), current->comm, print_tainted(),
19892 init_utsname()->release,
19893 (int)strcspn(init_utsname()->version, " "),
19894 init_utsname()->version,
19895 @@ -149,6 +150,9 @@ void flush_thread(void)
19896 {
19897 struct task_struct *tsk = current;
19898
19899 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19900 + loadsegment(gs, 0);
19901 +#endif
19902 flush_ptrace_hw_breakpoint(tsk);
19903 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
19904 drop_init_fpu(tsk);
19905 @@ -336,7 +340,7 @@ static void __exit_idle(void)
19906 void exit_idle(void)
19907 {
19908 /* idle loop has pid 0 */
19909 - if (current->pid)
19910 + if (task_pid_nr(current))
19911 return;
19912 __exit_idle();
19913 }
19914 @@ -445,7 +449,7 @@ bool set_pm_idle_to_default(void)
19915
19916 return ret;
19917 }
19918 -void stop_this_cpu(void *dummy)
19919 +__noreturn void stop_this_cpu(void *dummy)
19920 {
19921 local_irq_disable();
19922 /*
19923 @@ -673,16 +677,37 @@ static int __init idle_setup(char *str)
19924 }
19925 early_param("idle", idle_setup);
19926
19927 -unsigned long arch_align_stack(unsigned long sp)
19928 +#ifdef CONFIG_PAX_RANDKSTACK
19929 +void pax_randomize_kstack(struct pt_regs *regs)
19930 {
19931 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
19932 - sp -= get_random_int() % 8192;
19933 - return sp & ~0xf;
19934 -}
19935 + struct thread_struct *thread = &current->thread;
19936 + unsigned long time;
19937
19938 -unsigned long arch_randomize_brk(struct mm_struct *mm)
19939 -{
19940 - unsigned long range_end = mm->brk + 0x02000000;
19941 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
19942 -}
19943 + if (!randomize_va_space)
19944 + return;
19945 +
19946 + if (v8086_mode(regs))
19947 + return;
19948
19949 + rdtscl(time);
19950 +
19951 + /* P4 seems to return a 0 LSB, ignore it */
19952 +#ifdef CONFIG_MPENTIUM4
19953 + time &= 0x3EUL;
19954 + time <<= 2;
19955 +#elif defined(CONFIG_X86_64)
19956 + time &= 0xFUL;
19957 + time <<= 4;
19958 +#else
19959 + time &= 0x1FUL;
19960 + time <<= 3;
19961 +#endif
19962 +
19963 + thread->sp0 ^= time;
19964 + load_sp0(init_tss + smp_processor_id(), thread);
19965 +
19966 +#ifdef CONFIG_X86_64
19967 + this_cpu_write(kernel_stack, thread->sp0);
19968 +#endif
19969 +}
19970 +#endif
19971 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
19972 index 44e0bff..5ceb99c 100644
19973 --- a/arch/x86/kernel/process_32.c
19974 +++ b/arch/x86/kernel/process_32.c
19975 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
19976 unsigned long thread_saved_pc(struct task_struct *tsk)
19977 {
19978 return ((unsigned long *)tsk->thread.sp)[3];
19979 +//XXX return tsk->thread.eip;
19980 }
19981
19982 void __show_regs(struct pt_regs *regs, int all)
19983 @@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
19984 unsigned long sp;
19985 unsigned short ss, gs;
19986
19987 - if (user_mode_vm(regs)) {
19988 + if (user_mode(regs)) {
19989 sp = regs->sp;
19990 ss = regs->ss & 0xffff;
19991 - gs = get_user_gs(regs);
19992 } else {
19993 sp = kernel_stack_pointer(regs);
19994 savesegment(ss, ss);
19995 - savesegment(gs, gs);
19996 }
19997 + gs = get_user_gs(regs);
19998
19999 show_regs_common();
20000
20001 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
20002 (u16)regs->cs, regs->ip, regs->flags,
20003 - smp_processor_id());
20004 + raw_smp_processor_id());
20005 print_symbol("EIP is at %s\n", regs->ip);
20006
20007 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
20008 @@ -131,20 +131,21 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
20009 unsigned long arg,
20010 struct task_struct *p, struct pt_regs *regs)
20011 {
20012 - struct pt_regs *childregs = task_pt_regs(p);
20013 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
20014 struct task_struct *tsk;
20015 int err;
20016
20017 p->thread.sp = (unsigned long) childregs;
20018 p->thread.sp0 = (unsigned long) (childregs+1);
20019 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
20020
20021 if (unlikely(!regs)) {
20022 /* kernel thread */
20023 memset(childregs, 0, sizeof(struct pt_regs));
20024 p->thread.ip = (unsigned long) ret_from_kernel_thread;
20025 - task_user_gs(p) = __KERNEL_STACK_CANARY;
20026 - childregs->ds = __USER_DS;
20027 - childregs->es = __USER_DS;
20028 + savesegment(gs, childregs->gs);
20029 + childregs->ds = __KERNEL_DS;
20030 + childregs->es = __KERNEL_DS;
20031 childregs->fs = __KERNEL_PERCPU;
20032 childregs->bx = sp; /* function */
20033 childregs->bp = arg;
20034 @@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20035 struct thread_struct *prev = &prev_p->thread,
20036 *next = &next_p->thread;
20037 int cpu = smp_processor_id();
20038 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
20039 + struct tss_struct *tss = init_tss + cpu;
20040 fpu_switch_t fpu;
20041
20042 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
20043 @@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20044 */
20045 lazy_save_gs(prev->gs);
20046
20047 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20048 + __set_fs(task_thread_info(next_p)->addr_limit);
20049 +#endif
20050 +
20051 /*
20052 * Load the per-thread Thread-Local Storage descriptor.
20053 */
20054 @@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20055 */
20056 arch_end_context_switch(next_p);
20057
20058 + this_cpu_write(current_task, next_p);
20059 + this_cpu_write(current_tinfo, &next_p->tinfo);
20060 +
20061 /*
20062 * Restore %gs if needed (which is common)
20063 */
20064 @@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20065
20066 switch_fpu_finish(next_p, fpu);
20067
20068 - this_cpu_write(current_task, next_p);
20069 -
20070 return prev_p;
20071 }
20072
20073 @@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
20074 } while (count++ < 16);
20075 return 0;
20076 }
20077 -
20078 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
20079 index 16c6365..5d32218 100644
20080 --- a/arch/x86/kernel/process_64.c
20081 +++ b/arch/x86/kernel/process_64.c
20082 @@ -153,10 +153,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
20083 struct pt_regs *childregs;
20084 struct task_struct *me = current;
20085
20086 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
20087 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
20088 childregs = task_pt_regs(p);
20089 p->thread.sp = (unsigned long) childregs;
20090 p->thread.usersp = me->thread.usersp;
20091 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
20092 set_tsk_thread_flag(p, TIF_FORK);
20093 p->fpu_counter = 0;
20094 p->thread.io_bitmap_ptr = NULL;
20095 @@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20096 struct thread_struct *prev = &prev_p->thread;
20097 struct thread_struct *next = &next_p->thread;
20098 int cpu = smp_processor_id();
20099 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
20100 + struct tss_struct *tss = init_tss + cpu;
20101 unsigned fsindex, gsindex;
20102 fpu_switch_t fpu;
20103
20104 @@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20105 prev->usersp = this_cpu_read(old_rsp);
20106 this_cpu_write(old_rsp, next->usersp);
20107 this_cpu_write(current_task, next_p);
20108 + this_cpu_write(current_tinfo, &next_p->tinfo);
20109
20110 - this_cpu_write(kernel_stack,
20111 - (unsigned long)task_stack_page(next_p) +
20112 - THREAD_SIZE - KERNEL_STACK_OFFSET);
20113 + this_cpu_write(kernel_stack, next->sp0);
20114
20115 /*
20116 * Now maybe reload the debug registers and handle I/O bitmaps
20117 @@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
20118 if (!p || p == current || p->state == TASK_RUNNING)
20119 return 0;
20120 stack = (unsigned long)task_stack_page(p);
20121 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
20122 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
20123 return 0;
20124 fp = *(u64 *)(p->thread.sp);
20125 do {
20126 - if (fp < (unsigned long)stack ||
20127 - fp >= (unsigned long)stack+THREAD_SIZE)
20128 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
20129 return 0;
20130 ip = *(u64 *)(fp+8);
20131 if (!in_sched_functions(ip))
20132 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
20133 index 974b67e..12cb2b5 100644
20134 --- a/arch/x86/kernel/ptrace.c
20135 +++ b/arch/x86/kernel/ptrace.c
20136 @@ -183,14 +183,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
20137 {
20138 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
20139 unsigned long sp = (unsigned long)&regs->sp;
20140 - struct thread_info *tinfo;
20141
20142 - if (context == (sp & ~(THREAD_SIZE - 1)))
20143 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
20144 return sp;
20145
20146 - tinfo = (struct thread_info *)context;
20147 - if (tinfo->previous_esp)
20148 - return tinfo->previous_esp;
20149 + sp = *(unsigned long *)context;
20150 + if (sp)
20151 + return sp;
20152
20153 return (unsigned long)regs;
20154 }
20155 @@ -587,7 +586,7 @@ static void ptrace_triggered(struct perf_event *bp,
20156 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
20157 {
20158 int i;
20159 - int dr7 = 0;
20160 + unsigned long dr7 = 0;
20161 struct arch_hw_breakpoint *info;
20162
20163 for (i = 0; i < HBP_NUM; i++) {
20164 @@ -855,7 +854,7 @@ long arch_ptrace(struct task_struct *child, long request,
20165 unsigned long addr, unsigned long data)
20166 {
20167 int ret;
20168 - unsigned long __user *datap = (unsigned long __user *)data;
20169 + unsigned long __user *datap = (__force unsigned long __user *)data;
20170
20171 switch (request) {
20172 /* read the word at location addr in the USER area. */
20173 @@ -940,14 +939,14 @@ long arch_ptrace(struct task_struct *child, long request,
20174 if ((int) addr < 0)
20175 return -EIO;
20176 ret = do_get_thread_area(child, addr,
20177 - (struct user_desc __user *)data);
20178 + (__force struct user_desc __user *) data);
20179 break;
20180
20181 case PTRACE_SET_THREAD_AREA:
20182 if ((int) addr < 0)
20183 return -EIO;
20184 ret = do_set_thread_area(child, addr,
20185 - (struct user_desc __user *)data, 0);
20186 + (__force struct user_desc __user *) data, 0);
20187 break;
20188 #endif
20189
20190 @@ -1325,7 +1324,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
20191
20192 #ifdef CONFIG_X86_64
20193
20194 -static struct user_regset x86_64_regsets[] __read_mostly = {
20195 +static struct user_regset x86_64_regsets[] = {
20196 [REGSET_GENERAL] = {
20197 .core_note_type = NT_PRSTATUS,
20198 .n = sizeof(struct user_regs_struct) / sizeof(long),
20199 @@ -1366,7 +1365,7 @@ static const struct user_regset_view user_x86_64_view = {
20200 #endif /* CONFIG_X86_64 */
20201
20202 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
20203 -static struct user_regset x86_32_regsets[] __read_mostly = {
20204 +static struct user_regset x86_32_regsets[] = {
20205 [REGSET_GENERAL] = {
20206 .core_note_type = NT_PRSTATUS,
20207 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
20208 @@ -1419,13 +1418,13 @@ static const struct user_regset_view user_x86_32_view = {
20209 */
20210 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
20211
20212 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
20213 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
20214 {
20215 #ifdef CONFIG_X86_64
20216 - x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20217 + *(unsigned int *)&x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20218 #endif
20219 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
20220 - x86_32_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20221 + *(unsigned int *)&x86_32_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20222 #endif
20223 xstate_fx_sw_bytes[USER_XSTATE_XCR0_WORD] = xstate_mask;
20224 }
20225 @@ -1454,7 +1453,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
20226 memset(info, 0, sizeof(*info));
20227 info->si_signo = SIGTRAP;
20228 info->si_code = si_code;
20229 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
20230 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
20231 }
20232
20233 void user_single_step_siginfo(struct task_struct *tsk,
20234 @@ -1483,6 +1482,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
20235 # define IS_IA32 0
20236 #endif
20237
20238 +#ifdef CONFIG_GRKERNSEC_SETXID
20239 +extern void gr_delayed_cred_worker(void);
20240 +#endif
20241 +
20242 /*
20243 * We must return the syscall number to actually look up in the table.
20244 * This can be -1L to skip running any syscall at all.
20245 @@ -1493,6 +1496,11 @@ long syscall_trace_enter(struct pt_regs *regs)
20246
20247 rcu_user_exit();
20248
20249 +#ifdef CONFIG_GRKERNSEC_SETXID
20250 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
20251 + gr_delayed_cred_worker();
20252 +#endif
20253 +
20254 /*
20255 * If we stepped into a sysenter/syscall insn, it trapped in
20256 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
20257 @@ -1548,6 +1556,11 @@ void syscall_trace_leave(struct pt_regs *regs)
20258 */
20259 rcu_user_exit();
20260
20261 +#ifdef CONFIG_GRKERNSEC_SETXID
20262 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
20263 + gr_delayed_cred_worker();
20264 +#endif
20265 +
20266 audit_syscall_exit(regs);
20267
20268 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
20269 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
20270 index 42eb330..139955c 100644
20271 --- a/arch/x86/kernel/pvclock.c
20272 +++ b/arch/x86/kernel/pvclock.c
20273 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
20274 return pv_tsc_khz;
20275 }
20276
20277 -static atomic64_t last_value = ATOMIC64_INIT(0);
20278 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
20279
20280 void pvclock_resume(void)
20281 {
20282 - atomic64_set(&last_value, 0);
20283 + atomic64_set_unchecked(&last_value, 0);
20284 }
20285
20286 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
20287 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
20288 * updating at the same time, and one of them could be slightly behind,
20289 * making the assumption that last_value always go forward fail to hold.
20290 */
20291 - last = atomic64_read(&last_value);
20292 + last = atomic64_read_unchecked(&last_value);
20293 do {
20294 if (ret < last)
20295 return last;
20296 - last = atomic64_cmpxchg(&last_value, last, ret);
20297 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
20298 } while (unlikely(last != ret));
20299
20300 return ret;
20301 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
20302 index 76fa1e9..a93c759 100644
20303 --- a/arch/x86/kernel/reboot.c
20304 +++ b/arch/x86/kernel/reboot.c
20305 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
20306 EXPORT_SYMBOL(pm_power_off);
20307
20308 static const struct desc_ptr no_idt = {};
20309 -static int reboot_mode;
20310 +static unsigned short reboot_mode;
20311 enum reboot_type reboot_type = BOOT_ACPI;
20312 int reboot_force;
20313
20314 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
20315
20316 void __noreturn machine_real_restart(unsigned int type)
20317 {
20318 +
20319 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20320 + struct desc_struct *gdt;
20321 +#endif
20322 +
20323 local_irq_disable();
20324
20325 /*
20326 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
20327
20328 /* Jump to the identity-mapped low memory code */
20329 #ifdef CONFIG_X86_32
20330 - asm volatile("jmpl *%0" : :
20331 +
20332 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20333 + gdt = get_cpu_gdt_table(smp_processor_id());
20334 + pax_open_kernel();
20335 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20336 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
20337 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
20338 + loadsegment(ds, __KERNEL_DS);
20339 + loadsegment(es, __KERNEL_DS);
20340 + loadsegment(ss, __KERNEL_DS);
20341 +#endif
20342 +#ifdef CONFIG_PAX_KERNEXEC
20343 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
20344 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
20345 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
20346 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
20347 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
20348 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
20349 +#endif
20350 + pax_close_kernel();
20351 +#endif
20352 +
20353 + asm volatile("ljmpl *%0" : :
20354 "rm" (real_mode_header->machine_real_restart_asm),
20355 "a" (type));
20356 #else
20357 @@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
20358 * try to force a triple fault and then cycle between hitting the keyboard
20359 * controller and doing that
20360 */
20361 -static void native_machine_emergency_restart(void)
20362 +static void __noreturn native_machine_emergency_restart(void)
20363 {
20364 int i;
20365 int attempt = 0;
20366 @@ -654,13 +681,13 @@ void native_machine_shutdown(void)
20367 #endif
20368 }
20369
20370 -static void __machine_emergency_restart(int emergency)
20371 +static void __noreturn __machine_emergency_restart(int emergency)
20372 {
20373 reboot_emergency = emergency;
20374 machine_ops.emergency_restart();
20375 }
20376
20377 -static void native_machine_restart(char *__unused)
20378 +static void __noreturn native_machine_restart(char *__unused)
20379 {
20380 pr_notice("machine restart\n");
20381
20382 @@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
20383 __machine_emergency_restart(0);
20384 }
20385
20386 -static void native_machine_halt(void)
20387 +static void __noreturn native_machine_halt(void)
20388 {
20389 /* Stop other cpus and apics */
20390 machine_shutdown();
20391 @@ -679,7 +706,7 @@ static void native_machine_halt(void)
20392 stop_this_cpu(NULL);
20393 }
20394
20395 -static void native_machine_power_off(void)
20396 +static void __noreturn native_machine_power_off(void)
20397 {
20398 if (pm_power_off) {
20399 if (!reboot_force)
20400 @@ -688,6 +715,7 @@ static void native_machine_power_off(void)
20401 }
20402 /* A fallback in case there is no PM info available */
20403 tboot_shutdown(TB_SHUTDOWN_HALT);
20404 + unreachable();
20405 }
20406
20407 struct machine_ops machine_ops = {
20408 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
20409 index 7a6f3b3..bed145d7 100644
20410 --- a/arch/x86/kernel/relocate_kernel_64.S
20411 +++ b/arch/x86/kernel/relocate_kernel_64.S
20412 @@ -11,6 +11,7 @@
20413 #include <asm/kexec.h>
20414 #include <asm/processor-flags.h>
20415 #include <asm/pgtable_types.h>
20416 +#include <asm/alternative-asm.h>
20417
20418 /*
20419 * Must be relocatable PIC code callable as a C function
20420 @@ -160,13 +161,14 @@ identity_mapped:
20421 xorq %rbp, %rbp
20422 xorq %r8, %r8
20423 xorq %r9, %r9
20424 - xorq %r10, %r9
20425 + xorq %r10, %r10
20426 xorq %r11, %r11
20427 xorq %r12, %r12
20428 xorq %r13, %r13
20429 xorq %r14, %r14
20430 xorq %r15, %r15
20431
20432 + pax_force_retaddr 0, 1
20433 ret
20434
20435 1:
20436 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
20437 index aeacb0e..f9d4c02 100644
20438 --- a/arch/x86/kernel/setup.c
20439 +++ b/arch/x86/kernel/setup.c
20440 @@ -441,7 +441,7 @@ static void __init parse_setup_data(void)
20441
20442 switch (data->type) {
20443 case SETUP_E820_EXT:
20444 - parse_e820_ext(data);
20445 + parse_e820_ext((struct setup_data __force_kernel *)data);
20446 break;
20447 case SETUP_DTB:
20448 add_dtb(pa_data);
20449 @@ -710,7 +710,7 @@ static void __init trim_bios_range(void)
20450 * area (640->1Mb) as ram even though it is not.
20451 * take them out.
20452 */
20453 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
20454 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
20455
20456 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
20457 }
20458 @@ -834,14 +834,14 @@ void __init setup_arch(char **cmdline_p)
20459
20460 if (!boot_params.hdr.root_flags)
20461 root_mountflags &= ~MS_RDONLY;
20462 - init_mm.start_code = (unsigned long) _text;
20463 - init_mm.end_code = (unsigned long) _etext;
20464 + init_mm.start_code = ktla_ktva((unsigned long) _text);
20465 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
20466 init_mm.end_data = (unsigned long) _edata;
20467 init_mm.brk = _brk_end;
20468
20469 - code_resource.start = virt_to_phys(_text);
20470 - code_resource.end = virt_to_phys(_etext)-1;
20471 - data_resource.start = virt_to_phys(_etext);
20472 + code_resource.start = virt_to_phys(ktla_ktva(_text));
20473 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
20474 + data_resource.start = virt_to_phys(_sdata);
20475 data_resource.end = virt_to_phys(_edata)-1;
20476 bss_resource.start = virt_to_phys(&__bss_start);
20477 bss_resource.end = virt_to_phys(&__bss_stop)-1;
20478 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
20479 index 5cdff03..5810740 100644
20480 --- a/arch/x86/kernel/setup_percpu.c
20481 +++ b/arch/x86/kernel/setup_percpu.c
20482 @@ -21,19 +21,17 @@
20483 #include <asm/cpu.h>
20484 #include <asm/stackprotector.h>
20485
20486 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
20487 +#ifdef CONFIG_SMP
20488 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
20489 EXPORT_PER_CPU_SYMBOL(cpu_number);
20490 +#endif
20491
20492 -#ifdef CONFIG_X86_64
20493 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
20494 -#else
20495 -#define BOOT_PERCPU_OFFSET 0
20496 -#endif
20497
20498 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
20499 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
20500
20501 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
20502 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
20503 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
20504 };
20505 EXPORT_SYMBOL(__per_cpu_offset);
20506 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
20507 {
20508 #ifdef CONFIG_X86_32
20509 struct desc_struct gdt;
20510 + unsigned long base = per_cpu_offset(cpu);
20511
20512 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
20513 - 0x2 | DESCTYPE_S, 0x8);
20514 - gdt.s = 1;
20515 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
20516 + 0x83 | DESCTYPE_S, 0xC);
20517 write_gdt_entry(get_cpu_gdt_table(cpu),
20518 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
20519 #endif
20520 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
20521 /* alrighty, percpu areas up and running */
20522 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
20523 for_each_possible_cpu(cpu) {
20524 +#ifdef CONFIG_CC_STACKPROTECTOR
20525 +#ifdef CONFIG_X86_32
20526 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
20527 +#endif
20528 +#endif
20529 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
20530 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
20531 per_cpu(cpu_number, cpu) = cpu;
20532 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
20533 */
20534 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
20535 #endif
20536 +#ifdef CONFIG_CC_STACKPROTECTOR
20537 +#ifdef CONFIG_X86_32
20538 + if (!cpu)
20539 + per_cpu(stack_canary.canary, cpu) = canary;
20540 +#endif
20541 +#endif
20542 /*
20543 * Up to this point, the boot CPU has been using .init.data
20544 * area. Reload any changed state for the boot CPU.
20545 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
20546 index 70b27ee..fcf827f 100644
20547 --- a/arch/x86/kernel/signal.c
20548 +++ b/arch/x86/kernel/signal.c
20549 @@ -195,7 +195,7 @@ static unsigned long align_sigframe(unsigned long sp)
20550 * Align the stack pointer according to the i386 ABI,
20551 * i.e. so that on function entry ((sp + 4) & 15) == 0.
20552 */
20553 - sp = ((sp + 4) & -16ul) - 4;
20554 + sp = ((sp - 12) & -16ul) - 4;
20555 #else /* !CONFIG_X86_32 */
20556 sp = round_down(sp, 16) - 8;
20557 #endif
20558 @@ -303,9 +303,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20559 }
20560
20561 if (current->mm->context.vdso)
20562 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20563 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20564 else
20565 - restorer = &frame->retcode;
20566 + restorer = (void __user *)&frame->retcode;
20567 if (ka->sa.sa_flags & SA_RESTORER)
20568 restorer = ka->sa.sa_restorer;
20569
20570 @@ -319,7 +319,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20571 * reasons and because gdb uses it as a signature to notice
20572 * signal handler stack frames.
20573 */
20574 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
20575 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
20576
20577 if (err)
20578 return -EFAULT;
20579 @@ -369,7 +369,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20580 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
20581
20582 /* Set up to return from userspace. */
20583 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20584 + if (current->mm->context.vdso)
20585 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20586 + else
20587 + restorer = (void __user *)&frame->retcode;
20588 if (ka->sa.sa_flags & SA_RESTORER)
20589 restorer = ka->sa.sa_restorer;
20590 put_user_ex(restorer, &frame->pretcode);
20591 @@ -381,7 +384,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20592 * reasons and because gdb uses it as a signature to notice
20593 * signal handler stack frames.
20594 */
20595 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
20596 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
20597 } put_user_catch(err);
20598
20599 err |= copy_siginfo_to_user(&frame->info, info);
20600 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
20601 index f3e2ec8..ad5287a 100644
20602 --- a/arch/x86/kernel/smpboot.c
20603 +++ b/arch/x86/kernel/smpboot.c
20604 @@ -673,6 +673,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20605 idle->thread.sp = (unsigned long) (((struct pt_regs *)
20606 (THREAD_SIZE + task_stack_page(idle))) - 1);
20607 per_cpu(current_task, cpu) = idle;
20608 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
20609
20610 #ifdef CONFIG_X86_32
20611 /* Stack for startup_32 can be just as for start_secondary onwards */
20612 @@ -680,11 +681,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20613 #else
20614 clear_tsk_thread_flag(idle, TIF_FORK);
20615 initial_gs = per_cpu_offset(cpu);
20616 - per_cpu(kernel_stack, cpu) =
20617 - (unsigned long)task_stack_page(idle) -
20618 - KERNEL_STACK_OFFSET + THREAD_SIZE;
20619 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
20620 #endif
20621 +
20622 + pax_open_kernel();
20623 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20624 + pax_close_kernel();
20625 +
20626 initial_code = (unsigned long)start_secondary;
20627 stack_start = idle->thread.sp;
20628
20629 @@ -823,6 +826,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
20630 /* the FPU context is blank, nobody can own it */
20631 __cpu_disable_lazy_restore(cpu);
20632
20633 +#ifdef CONFIG_PAX_PER_CPU_PGD
20634 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
20635 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
20636 + KERNEL_PGD_PTRS);
20637 +#endif
20638 +
20639 + /* the FPU context is blank, nobody can own it */
20640 + __cpu_disable_lazy_restore(cpu);
20641 +
20642 err = do_boot_cpu(apicid, cpu, tidle);
20643 if (err) {
20644 pr_debug("do_boot_cpu failed %d\n", err);
20645 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
20646 index 9b4d51d..5d28b58 100644
20647 --- a/arch/x86/kernel/step.c
20648 +++ b/arch/x86/kernel/step.c
20649 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20650 struct desc_struct *desc;
20651 unsigned long base;
20652
20653 - seg &= ~7UL;
20654 + seg >>= 3;
20655
20656 mutex_lock(&child->mm->context.lock);
20657 - if (unlikely((seg >> 3) >= child->mm->context.size))
20658 + if (unlikely(seg >= child->mm->context.size))
20659 addr = -1L; /* bogus selector, access would fault */
20660 else {
20661 desc = child->mm->context.ldt + seg;
20662 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20663 addr += base;
20664 }
20665 mutex_unlock(&child->mm->context.lock);
20666 - }
20667 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
20668 + addr = ktla_ktva(addr);
20669
20670 return addr;
20671 }
20672 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
20673 unsigned char opcode[15];
20674 unsigned long addr = convert_ip_to_linear(child, regs);
20675
20676 + if (addr == -EINVAL)
20677 + return 0;
20678 +
20679 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
20680 for (i = 0; i < copied; i++) {
20681 switch (opcode[i]) {
20682 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
20683 new file mode 100644
20684 index 0000000..26bb1af
20685 --- /dev/null
20686 +++ b/arch/x86/kernel/sys_i386_32.c
20687 @@ -0,0 +1,249 @@
20688 +/*
20689 + * This file contains various random system calls that
20690 + * have a non-standard calling sequence on the Linux/i386
20691 + * platform.
20692 + */
20693 +
20694 +#include <linux/errno.h>
20695 +#include <linux/sched.h>
20696 +#include <linux/mm.h>
20697 +#include <linux/fs.h>
20698 +#include <linux/smp.h>
20699 +#include <linux/sem.h>
20700 +#include <linux/msg.h>
20701 +#include <linux/shm.h>
20702 +#include <linux/stat.h>
20703 +#include <linux/syscalls.h>
20704 +#include <linux/mman.h>
20705 +#include <linux/file.h>
20706 +#include <linux/utsname.h>
20707 +#include <linux/ipc.h>
20708 +
20709 +#include <linux/uaccess.h>
20710 +#include <linux/unistd.h>
20711 +
20712 +#include <asm/syscalls.h>
20713 +
20714 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
20715 +{
20716 + unsigned long pax_task_size = TASK_SIZE;
20717 +
20718 +#ifdef CONFIG_PAX_SEGMEXEC
20719 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
20720 + pax_task_size = SEGMEXEC_TASK_SIZE;
20721 +#endif
20722 +
20723 + if (len > pax_task_size || addr > pax_task_size - len)
20724 + return -EINVAL;
20725 +
20726 + return 0;
20727 +}
20728 +
20729 +unsigned long
20730 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
20731 + unsigned long len, unsigned long pgoff, unsigned long flags)
20732 +{
20733 + struct mm_struct *mm = current->mm;
20734 + struct vm_area_struct *vma;
20735 + unsigned long start_addr, pax_task_size = TASK_SIZE;
20736 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20737 +
20738 +#ifdef CONFIG_PAX_SEGMEXEC
20739 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20740 + pax_task_size = SEGMEXEC_TASK_SIZE;
20741 +#endif
20742 +
20743 + pax_task_size -= PAGE_SIZE;
20744 +
20745 + if (len > pax_task_size)
20746 + return -ENOMEM;
20747 +
20748 + if (flags & MAP_FIXED)
20749 + return addr;
20750 +
20751 +#ifdef CONFIG_PAX_RANDMMAP
20752 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20753 +#endif
20754 +
20755 + if (addr) {
20756 + addr = PAGE_ALIGN(addr);
20757 + if (pax_task_size - len >= addr) {
20758 + vma = find_vma(mm, addr);
20759 + if (check_heap_stack_gap(vma, addr, len, offset))
20760 + return addr;
20761 + }
20762 + }
20763 + if (len > mm->cached_hole_size) {
20764 + start_addr = addr = mm->free_area_cache;
20765 + } else {
20766 + start_addr = addr = mm->mmap_base;
20767 + mm->cached_hole_size = 0;
20768 + }
20769 +
20770 +#ifdef CONFIG_PAX_PAGEEXEC
20771 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
20772 + start_addr = 0x00110000UL;
20773 +
20774 +#ifdef CONFIG_PAX_RANDMMAP
20775 + if (mm->pax_flags & MF_PAX_RANDMMAP)
20776 + start_addr += mm->delta_mmap & 0x03FFF000UL;
20777 +#endif
20778 +
20779 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
20780 + start_addr = addr = mm->mmap_base;
20781 + else
20782 + addr = start_addr;
20783 + }
20784 +#endif
20785 +
20786 +full_search:
20787 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
20788 + /* At this point: (!vma || addr < vma->vm_end). */
20789 + if (pax_task_size - len < addr) {
20790 + /*
20791 + * Start a new search - just in case we missed
20792 + * some holes.
20793 + */
20794 + if (start_addr != mm->mmap_base) {
20795 + start_addr = addr = mm->mmap_base;
20796 + mm->cached_hole_size = 0;
20797 + goto full_search;
20798 + }
20799 + return -ENOMEM;
20800 + }
20801 + if (check_heap_stack_gap(vma, addr, len, offset))
20802 + break;
20803 + if (addr + mm->cached_hole_size < vma->vm_start)
20804 + mm->cached_hole_size = vma->vm_start - addr;
20805 + addr = vma->vm_end;
20806 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
20807 + start_addr = addr = mm->mmap_base;
20808 + mm->cached_hole_size = 0;
20809 + goto full_search;
20810 + }
20811 + }
20812 +
20813 + /*
20814 + * Remember the place where we stopped the search:
20815 + */
20816 + mm->free_area_cache = addr + len;
20817 + return addr;
20818 +}
20819 +
20820 +unsigned long
20821 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20822 + const unsigned long len, const unsigned long pgoff,
20823 + const unsigned long flags)
20824 +{
20825 + struct vm_area_struct *vma;
20826 + struct mm_struct *mm = current->mm;
20827 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
20828 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20829 +
20830 +#ifdef CONFIG_PAX_SEGMEXEC
20831 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20832 + pax_task_size = SEGMEXEC_TASK_SIZE;
20833 +#endif
20834 +
20835 + pax_task_size -= PAGE_SIZE;
20836 +
20837 + /* requested length too big for entire address space */
20838 + if (len > pax_task_size)
20839 + return -ENOMEM;
20840 +
20841 + if (flags & MAP_FIXED)
20842 + return addr;
20843 +
20844 +#ifdef CONFIG_PAX_PAGEEXEC
20845 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
20846 + goto bottomup;
20847 +#endif
20848 +
20849 +#ifdef CONFIG_PAX_RANDMMAP
20850 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20851 +#endif
20852 +
20853 + /* requesting a specific address */
20854 + if (addr) {
20855 + addr = PAGE_ALIGN(addr);
20856 + if (pax_task_size - len >= addr) {
20857 + vma = find_vma(mm, addr);
20858 + if (check_heap_stack_gap(vma, addr, len, offset))
20859 + return addr;
20860 + }
20861 + }
20862 +
20863 + /* check if free_area_cache is useful for us */
20864 + if (len <= mm->cached_hole_size) {
20865 + mm->cached_hole_size = 0;
20866 + mm->free_area_cache = mm->mmap_base;
20867 + }
20868 +
20869 + /* either no address requested or can't fit in requested address hole */
20870 + addr = mm->free_area_cache;
20871 +
20872 + /* make sure it can fit in the remaining address space */
20873 + if (addr > len) {
20874 + vma = find_vma(mm, addr-len);
20875 + if (check_heap_stack_gap(vma, addr - len, len, offset))
20876 + /* remember the address as a hint for next time */
20877 + return (mm->free_area_cache = addr-len);
20878 + }
20879 +
20880 + if (mm->mmap_base < len)
20881 + goto bottomup;
20882 +
20883 + addr = mm->mmap_base-len;
20884 +
20885 + do {
20886 + /*
20887 + * Lookup failure means no vma is above this address,
20888 + * else if new region fits below vma->vm_start,
20889 + * return with success:
20890 + */
20891 + vma = find_vma(mm, addr);
20892 + if (check_heap_stack_gap(vma, addr, len, offset))
20893 + /* remember the address as a hint for next time */
20894 + return (mm->free_area_cache = addr);
20895 +
20896 + /* remember the largest hole we saw so far */
20897 + if (addr + mm->cached_hole_size < vma->vm_start)
20898 + mm->cached_hole_size = vma->vm_start - addr;
20899 +
20900 + /* try just below the current vma->vm_start */
20901 + addr = skip_heap_stack_gap(vma, len, offset);
20902 + } while (!IS_ERR_VALUE(addr));
20903 +
20904 +bottomup:
20905 + /*
20906 + * A failed mmap() very likely causes application failure,
20907 + * so fall back to the bottom-up function here. This scenario
20908 + * can happen with large stack limits and large mmap()
20909 + * allocations.
20910 + */
20911 +
20912 +#ifdef CONFIG_PAX_SEGMEXEC
20913 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
20914 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
20915 + else
20916 +#endif
20917 +
20918 + mm->mmap_base = TASK_UNMAPPED_BASE;
20919 +
20920 +#ifdef CONFIG_PAX_RANDMMAP
20921 + if (mm->pax_flags & MF_PAX_RANDMMAP)
20922 + mm->mmap_base += mm->delta_mmap;
20923 +#endif
20924 +
20925 + mm->free_area_cache = mm->mmap_base;
20926 + mm->cached_hole_size = ~0UL;
20927 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
20928 + /*
20929 + * Restore the topdown base:
20930 + */
20931 + mm->mmap_base = base;
20932 + mm->free_area_cache = base;
20933 + mm->cached_hole_size = ~0UL;
20934 +
20935 + return addr;
20936 +}
20937 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
20938 index b4d3c39..d699d77 100644
20939 --- a/arch/x86/kernel/sys_x86_64.c
20940 +++ b/arch/x86/kernel/sys_x86_64.c
20941 @@ -95,8 +95,8 @@ out:
20942 return error;
20943 }
20944
20945 -static void find_start_end(unsigned long flags, unsigned long *begin,
20946 - unsigned long *end)
20947 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
20948 + unsigned long *begin, unsigned long *end)
20949 {
20950 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
20951 unsigned long new_begin;
20952 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
20953 *begin = new_begin;
20954 }
20955 } else {
20956 - *begin = TASK_UNMAPPED_BASE;
20957 + *begin = mm->mmap_base;
20958 *end = TASK_SIZE;
20959 }
20960 }
20961 @@ -128,20 +128,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
20962 struct vm_area_struct *vma;
20963 unsigned long start_addr;
20964 unsigned long begin, end;
20965 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20966
20967 if (flags & MAP_FIXED)
20968 return addr;
20969
20970 - find_start_end(flags, &begin, &end);
20971 + find_start_end(mm, flags, &begin, &end);
20972
20973 if (len > end)
20974 return -ENOMEM;
20975
20976 +#ifdef CONFIG_PAX_RANDMMAP
20977 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20978 +#endif
20979 +
20980 if (addr) {
20981 addr = PAGE_ALIGN(addr);
20982 vma = find_vma(mm, addr);
20983 - if (end - len >= addr &&
20984 - (!vma || addr + len <= vma->vm_start))
20985 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
20986 return addr;
20987 }
20988 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
20989 @@ -172,7 +176,7 @@ full_search:
20990 }
20991 return -ENOMEM;
20992 }
20993 - if (!vma || addr + len <= vma->vm_start) {
20994 + if (check_heap_stack_gap(vma, addr, len, offset)) {
20995 /*
20996 * Remember the place where we stopped the search:
20997 */
20998 @@ -195,7 +199,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20999 {
21000 struct vm_area_struct *vma;
21001 struct mm_struct *mm = current->mm;
21002 - unsigned long addr = addr0, start_addr;
21003 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
21004 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
21005
21006 /* requested length too big for entire address space */
21007 if (len > TASK_SIZE)
21008 @@ -208,13 +213,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
21009 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
21010 goto bottomup;
21011
21012 +#ifdef CONFIG_PAX_RANDMMAP
21013 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
21014 +#endif
21015 +
21016 /* requesting a specific address */
21017 if (addr) {
21018 addr = PAGE_ALIGN(addr);
21019 - vma = find_vma(mm, addr);
21020 - if (TASK_SIZE - len >= addr &&
21021 - (!vma || addr + len <= vma->vm_start))
21022 - return addr;
21023 + if (TASK_SIZE - len >= addr) {
21024 + vma = find_vma(mm, addr);
21025 + if (check_heap_stack_gap(vma, addr, len, offset))
21026 + return addr;
21027 + }
21028 }
21029
21030 /* check if free_area_cache is useful for us */
21031 @@ -240,7 +250,7 @@ try_again:
21032 * return with success:
21033 */
21034 vma = find_vma(mm, addr);
21035 - if (!vma || addr+len <= vma->vm_start)
21036 + if (check_heap_stack_gap(vma, addr, len, offset))
21037 /* remember the address as a hint for next time */
21038 return mm->free_area_cache = addr;
21039
21040 @@ -249,8 +259,8 @@ try_again:
21041 mm->cached_hole_size = vma->vm_start - addr;
21042
21043 /* try just below the current vma->vm_start */
21044 - addr = vma->vm_start-len;
21045 - } while (len < vma->vm_start);
21046 + addr = skip_heap_stack_gap(vma, len, offset);
21047 + } while (!IS_ERR_VALUE(addr));
21048
21049 fail:
21050 /*
21051 @@ -270,13 +280,21 @@ bottomup:
21052 * can happen with large stack limits and large mmap()
21053 * allocations.
21054 */
21055 + mm->mmap_base = TASK_UNMAPPED_BASE;
21056 +
21057 +#ifdef CONFIG_PAX_RANDMMAP
21058 + if (mm->pax_flags & MF_PAX_RANDMMAP)
21059 + mm->mmap_base += mm->delta_mmap;
21060 +#endif
21061 +
21062 + mm->free_area_cache = mm->mmap_base;
21063 mm->cached_hole_size = ~0UL;
21064 - mm->free_area_cache = TASK_UNMAPPED_BASE;
21065 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
21066 /*
21067 * Restore the topdown base:
21068 */
21069 - mm->free_area_cache = mm->mmap_base;
21070 + mm->mmap_base = base;
21071 + mm->free_area_cache = base;
21072 mm->cached_hole_size = ~0UL;
21073
21074 return addr;
21075 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
21076 index f84fe00..93fe08f 100644
21077 --- a/arch/x86/kernel/tboot.c
21078 +++ b/arch/x86/kernel/tboot.c
21079 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
21080
21081 void tboot_shutdown(u32 shutdown_type)
21082 {
21083 - void (*shutdown)(void);
21084 + void (* __noreturn shutdown)(void);
21085
21086 if (!tboot_enabled())
21087 return;
21088 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
21089
21090 switch_to_tboot_pt();
21091
21092 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
21093 + shutdown = (void *)tboot->shutdown_entry;
21094 shutdown();
21095
21096 /* should not reach here */
21097 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
21098 return 0;
21099 }
21100
21101 -static atomic_t ap_wfs_count;
21102 +static atomic_unchecked_t ap_wfs_count;
21103
21104 static int tboot_wait_for_aps(int num_aps)
21105 {
21106 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
21107 {
21108 switch (action) {
21109 case CPU_DYING:
21110 - atomic_inc(&ap_wfs_count);
21111 + atomic_inc_unchecked(&ap_wfs_count);
21112 if (num_online_cpus() == 1)
21113 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
21114 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
21115 return NOTIFY_BAD;
21116 break;
21117 }
21118 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
21119
21120 tboot_create_trampoline();
21121
21122 - atomic_set(&ap_wfs_count, 0);
21123 + atomic_set_unchecked(&ap_wfs_count, 0);
21124 register_hotcpu_notifier(&tboot_cpu_notifier);
21125
21126 acpi_os_set_prepare_sleep(&tboot_sleep);
21127 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
21128 index 24d3c91..d06b473 100644
21129 --- a/arch/x86/kernel/time.c
21130 +++ b/arch/x86/kernel/time.c
21131 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
21132 {
21133 unsigned long pc = instruction_pointer(regs);
21134
21135 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
21136 + if (!user_mode(regs) && in_lock_functions(pc)) {
21137 #ifdef CONFIG_FRAME_POINTER
21138 - return *(unsigned long *)(regs->bp + sizeof(long));
21139 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
21140 #else
21141 unsigned long *sp =
21142 (unsigned long *)kernel_stack_pointer(regs);
21143 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
21144 * or above a saved flags. Eflags has bits 22-31 zero,
21145 * kernel addresses don't.
21146 */
21147 +
21148 +#ifdef CONFIG_PAX_KERNEXEC
21149 + return ktla_ktva(sp[0]);
21150 +#else
21151 if (sp[0] >> 22)
21152 return sp[0];
21153 if (sp[1] >> 22)
21154 return sp[1];
21155 #endif
21156 +
21157 +#endif
21158 }
21159 return pc;
21160 }
21161 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
21162 index 9d9d2f9..cad418a 100644
21163 --- a/arch/x86/kernel/tls.c
21164 +++ b/arch/x86/kernel/tls.c
21165 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
21166 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
21167 return -EINVAL;
21168
21169 +#ifdef CONFIG_PAX_SEGMEXEC
21170 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
21171 + return -EINVAL;
21172 +#endif
21173 +
21174 set_tls_desc(p, idx, &info, 1);
21175
21176 return 0;
21177 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
21178
21179 if (kbuf)
21180 info = kbuf;
21181 - else if (__copy_from_user(infobuf, ubuf, count))
21182 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
21183 return -EFAULT;
21184 else
21185 info = infobuf;
21186 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
21187 index 8276dc6..4ca48a2 100644
21188 --- a/arch/x86/kernel/traps.c
21189 +++ b/arch/x86/kernel/traps.c
21190 @@ -71,12 +71,6 @@ asmlinkage int system_call(void);
21191
21192 /* Do we ignore FPU interrupts ? */
21193 char ignore_fpu_irq;
21194 -
21195 -/*
21196 - * The IDT has to be page-aligned to simplify the Pentium
21197 - * F0 0F bug workaround.
21198 - */
21199 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
21200 #endif
21201
21202 DECLARE_BITMAP(used_vectors, NR_VECTORS);
21203 @@ -109,11 +103,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
21204 }
21205
21206 static int __kprobes
21207 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21208 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
21209 struct pt_regs *regs, long error_code)
21210 {
21211 #ifdef CONFIG_X86_32
21212 - if (regs->flags & X86_VM_MASK) {
21213 + if (v8086_mode(regs)) {
21214 /*
21215 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
21216 * On nmi (interrupt 2), do_trap should not be called.
21217 @@ -126,12 +120,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21218 return -1;
21219 }
21220 #endif
21221 - if (!user_mode(regs)) {
21222 + if (!user_mode_novm(regs)) {
21223 if (!fixup_exception(regs)) {
21224 tsk->thread.error_code = error_code;
21225 tsk->thread.trap_nr = trapnr;
21226 +
21227 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21228 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
21229 + str = "PAX: suspicious stack segment fault";
21230 +#endif
21231 +
21232 die(str, regs, error_code);
21233 }
21234 +
21235 +#ifdef CONFIG_PAX_REFCOUNT
21236 + if (trapnr == 4)
21237 + pax_report_refcount_overflow(regs);
21238 +#endif
21239 +
21240 return 0;
21241 }
21242
21243 @@ -139,7 +145,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21244 }
21245
21246 static void __kprobes
21247 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
21248 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
21249 long error_code, siginfo_t *info)
21250 {
21251 struct task_struct *tsk = current;
21252 @@ -163,7 +169,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
21253 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
21254 printk_ratelimit()) {
21255 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
21256 - tsk->comm, tsk->pid, str,
21257 + tsk->comm, task_pid_nr(tsk), str,
21258 regs->ip, regs->sp, error_code);
21259 print_vma_addr(" in ", regs->ip);
21260 pr_cont("\n");
21261 @@ -269,7 +275,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
21262 conditional_sti(regs);
21263
21264 #ifdef CONFIG_X86_32
21265 - if (regs->flags & X86_VM_MASK) {
21266 + if (v8086_mode(regs)) {
21267 local_irq_enable();
21268 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
21269 goto exit;
21270 @@ -277,18 +283,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
21271 #endif
21272
21273 tsk = current;
21274 - if (!user_mode(regs)) {
21275 + if (!user_mode_novm(regs)) {
21276 if (fixup_exception(regs))
21277 goto exit;
21278
21279 tsk->thread.error_code = error_code;
21280 tsk->thread.trap_nr = X86_TRAP_GP;
21281 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
21282 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
21283 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
21284 +
21285 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21286 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
21287 + die("PAX: suspicious general protection fault", regs, error_code);
21288 + else
21289 +#endif
21290 +
21291 die("general protection fault", regs, error_code);
21292 + }
21293 goto exit;
21294 }
21295
21296 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21297 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
21298 + struct mm_struct *mm = tsk->mm;
21299 + unsigned long limit;
21300 +
21301 + down_write(&mm->mmap_sem);
21302 + limit = mm->context.user_cs_limit;
21303 + if (limit < TASK_SIZE) {
21304 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
21305 + up_write(&mm->mmap_sem);
21306 + return;
21307 + }
21308 + up_write(&mm->mmap_sem);
21309 + }
21310 +#endif
21311 +
21312 tsk->thread.error_code = error_code;
21313 tsk->thread.trap_nr = X86_TRAP_GP;
21314
21315 @@ -443,7 +473,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21316 /* It's safe to allow irq's after DR6 has been saved */
21317 preempt_conditional_sti(regs);
21318
21319 - if (regs->flags & X86_VM_MASK) {
21320 + if (v8086_mode(regs)) {
21321 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
21322 X86_TRAP_DB);
21323 preempt_conditional_cli(regs);
21324 @@ -458,7 +488,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21325 * We already checked v86 mode above, so we can check for kernel mode
21326 * by just checking the CPL of CS.
21327 */
21328 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
21329 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
21330 tsk->thread.debugreg6 &= ~DR_STEP;
21331 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
21332 regs->flags &= ~X86_EFLAGS_TF;
21333 @@ -490,7 +520,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
21334 return;
21335 conditional_sti(regs);
21336
21337 - if (!user_mode_vm(regs))
21338 + if (!user_mode(regs))
21339 {
21340 if (!fixup_exception(regs)) {
21341 task->thread.error_code = error_code;
21342 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
21343 index aafa555..a04691a 100644
21344 --- a/arch/x86/kernel/uprobes.c
21345 +++ b/arch/x86/kernel/uprobes.c
21346 @@ -614,7 +614,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
21347 int ret = NOTIFY_DONE;
21348
21349 /* We are only interested in userspace traps */
21350 - if (regs && !user_mode_vm(regs))
21351 + if (regs && !user_mode(regs))
21352 return NOTIFY_DONE;
21353
21354 switch (val) {
21355 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
21356 index b9242ba..50c5edd 100644
21357 --- a/arch/x86/kernel/verify_cpu.S
21358 +++ b/arch/x86/kernel/verify_cpu.S
21359 @@ -20,6 +20,7 @@
21360 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
21361 * arch/x86/kernel/trampoline_64.S: secondary processor verification
21362 * arch/x86/kernel/head_32.S: processor startup
21363 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
21364 *
21365 * verify_cpu, returns the status of longmode and SSE in register %eax.
21366 * 0: Success 1: Failure
21367 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
21368 index 5c9687b..5f857d3 100644
21369 --- a/arch/x86/kernel/vm86_32.c
21370 +++ b/arch/x86/kernel/vm86_32.c
21371 @@ -43,6 +43,7 @@
21372 #include <linux/ptrace.h>
21373 #include <linux/audit.h>
21374 #include <linux/stddef.h>
21375 +#include <linux/grsecurity.h>
21376
21377 #include <asm/uaccess.h>
21378 #include <asm/io.h>
21379 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
21380 do_exit(SIGSEGV);
21381 }
21382
21383 - tss = &per_cpu(init_tss, get_cpu());
21384 + tss = init_tss + get_cpu();
21385 current->thread.sp0 = current->thread.saved_sp0;
21386 current->thread.sysenter_cs = __KERNEL_CS;
21387 load_sp0(tss, &current->thread);
21388 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
21389 struct task_struct *tsk;
21390 int tmp, ret = -EPERM;
21391
21392 +#ifdef CONFIG_GRKERNSEC_VM86
21393 + if (!capable(CAP_SYS_RAWIO)) {
21394 + gr_handle_vm86();
21395 + goto out;
21396 + }
21397 +#endif
21398 +
21399 tsk = current;
21400 if (tsk->thread.saved_sp0)
21401 goto out;
21402 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
21403 int tmp, ret;
21404 struct vm86plus_struct __user *v86;
21405
21406 +#ifdef CONFIG_GRKERNSEC_VM86
21407 + if (!capable(CAP_SYS_RAWIO)) {
21408 + gr_handle_vm86();
21409 + ret = -EPERM;
21410 + goto out;
21411 + }
21412 +#endif
21413 +
21414 tsk = current;
21415 switch (cmd) {
21416 case VM86_REQUEST_IRQ:
21417 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
21418 tsk->thread.saved_fs = info->regs32->fs;
21419 tsk->thread.saved_gs = get_user_gs(info->regs32);
21420
21421 - tss = &per_cpu(init_tss, get_cpu());
21422 + tss = init_tss + get_cpu();
21423 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
21424 if (cpu_has_sep)
21425 tsk->thread.sysenter_cs = 0;
21426 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
21427 goto cannot_handle;
21428 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
21429 goto cannot_handle;
21430 - intr_ptr = (unsigned long __user *) (i << 2);
21431 + intr_ptr = (__force unsigned long __user *) (i << 2);
21432 if (get_user(segoffs, intr_ptr))
21433 goto cannot_handle;
21434 if ((segoffs >> 16) == BIOSSEG)
21435 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
21436 index 22a1530..8fbaaad 100644
21437 --- a/arch/x86/kernel/vmlinux.lds.S
21438 +++ b/arch/x86/kernel/vmlinux.lds.S
21439 @@ -26,6 +26,13 @@
21440 #include <asm/page_types.h>
21441 #include <asm/cache.h>
21442 #include <asm/boot.h>
21443 +#include <asm/segment.h>
21444 +
21445 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21446 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
21447 +#else
21448 +#define __KERNEL_TEXT_OFFSET 0
21449 +#endif
21450
21451 #undef i386 /* in case the preprocessor is a 32bit one */
21452
21453 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
21454
21455 PHDRS {
21456 text PT_LOAD FLAGS(5); /* R_E */
21457 +#ifdef CONFIG_X86_32
21458 + module PT_LOAD FLAGS(5); /* R_E */
21459 +#endif
21460 +#ifdef CONFIG_XEN
21461 + rodata PT_LOAD FLAGS(5); /* R_E */
21462 +#else
21463 + rodata PT_LOAD FLAGS(4); /* R__ */
21464 +#endif
21465 data PT_LOAD FLAGS(6); /* RW_ */
21466 -#ifdef CONFIG_X86_64
21467 + init.begin PT_LOAD FLAGS(6); /* RW_ */
21468 #ifdef CONFIG_SMP
21469 percpu PT_LOAD FLAGS(6); /* RW_ */
21470 #endif
21471 + text.init PT_LOAD FLAGS(5); /* R_E */
21472 + text.exit PT_LOAD FLAGS(5); /* R_E */
21473 init PT_LOAD FLAGS(7); /* RWE */
21474 -#endif
21475 note PT_NOTE FLAGS(0); /* ___ */
21476 }
21477
21478 SECTIONS
21479 {
21480 #ifdef CONFIG_X86_32
21481 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
21482 - phys_startup_32 = startup_32 - LOAD_OFFSET;
21483 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
21484 #else
21485 - . = __START_KERNEL;
21486 - phys_startup_64 = startup_64 - LOAD_OFFSET;
21487 + . = __START_KERNEL;
21488 #endif
21489
21490 /* Text and read-only data */
21491 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
21492 - _text = .;
21493 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21494 /* bootstrapping code */
21495 +#ifdef CONFIG_X86_32
21496 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21497 +#else
21498 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21499 +#endif
21500 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21501 + _text = .;
21502 HEAD_TEXT
21503 #ifdef CONFIG_X86_32
21504 . = ALIGN(PAGE_SIZE);
21505 @@ -108,13 +128,48 @@ SECTIONS
21506 IRQENTRY_TEXT
21507 *(.fixup)
21508 *(.gnu.warning)
21509 - /* End of text section */
21510 - _etext = .;
21511 } :text = 0x9090
21512
21513 - NOTES :text :note
21514 + . += __KERNEL_TEXT_OFFSET;
21515
21516 - EXCEPTION_TABLE(16) :text = 0x9090
21517 +#ifdef CONFIG_X86_32
21518 + . = ALIGN(PAGE_SIZE);
21519 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
21520 +
21521 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
21522 + MODULES_EXEC_VADDR = .;
21523 + BYTE(0)
21524 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
21525 + . = ALIGN(HPAGE_SIZE) - 1;
21526 + MODULES_EXEC_END = .;
21527 +#endif
21528 +
21529 + } :module
21530 +#endif
21531 +
21532 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
21533 + /* End of text section */
21534 + BYTE(0)
21535 + _etext = . - __KERNEL_TEXT_OFFSET;
21536 + }
21537 +
21538 +#ifdef CONFIG_X86_32
21539 + . = ALIGN(PAGE_SIZE);
21540 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
21541 + *(.idt)
21542 + . = ALIGN(PAGE_SIZE);
21543 + *(.empty_zero_page)
21544 + *(.initial_pg_fixmap)
21545 + *(.initial_pg_pmd)
21546 + *(.initial_page_table)
21547 + *(.swapper_pg_dir)
21548 + } :rodata
21549 +#endif
21550 +
21551 + . = ALIGN(PAGE_SIZE);
21552 + NOTES :rodata :note
21553 +
21554 + EXCEPTION_TABLE(16) :rodata
21555
21556 #if defined(CONFIG_DEBUG_RODATA)
21557 /* .text should occupy whole number of pages */
21558 @@ -126,16 +181,20 @@ SECTIONS
21559
21560 /* Data */
21561 .data : AT(ADDR(.data) - LOAD_OFFSET) {
21562 +
21563 +#ifdef CONFIG_PAX_KERNEXEC
21564 + . = ALIGN(HPAGE_SIZE);
21565 +#else
21566 + . = ALIGN(PAGE_SIZE);
21567 +#endif
21568 +
21569 /* Start of data section */
21570 _sdata = .;
21571
21572 /* init_task */
21573 INIT_TASK_DATA(THREAD_SIZE)
21574
21575 -#ifdef CONFIG_X86_32
21576 - /* 32 bit has nosave before _edata */
21577 NOSAVE_DATA
21578 -#endif
21579
21580 PAGE_ALIGNED_DATA(PAGE_SIZE)
21581
21582 @@ -176,12 +235,19 @@ SECTIONS
21583 #endif /* CONFIG_X86_64 */
21584
21585 /* Init code and data - will be freed after init */
21586 - . = ALIGN(PAGE_SIZE);
21587 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
21588 + BYTE(0)
21589 +
21590 +#ifdef CONFIG_PAX_KERNEXEC
21591 + . = ALIGN(HPAGE_SIZE);
21592 +#else
21593 + . = ALIGN(PAGE_SIZE);
21594 +#endif
21595 +
21596 __init_begin = .; /* paired with __init_end */
21597 - }
21598 + } :init.begin
21599
21600 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
21601 +#ifdef CONFIG_SMP
21602 /*
21603 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
21604 * output PHDR, so the next output section - .init.text - should
21605 @@ -190,12 +256,27 @@ SECTIONS
21606 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
21607 #endif
21608
21609 - INIT_TEXT_SECTION(PAGE_SIZE)
21610 -#ifdef CONFIG_X86_64
21611 - :init
21612 -#endif
21613 + . = ALIGN(PAGE_SIZE);
21614 + init_begin = .;
21615 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
21616 + VMLINUX_SYMBOL(_sinittext) = .;
21617 + INIT_TEXT
21618 + VMLINUX_SYMBOL(_einittext) = .;
21619 + . = ALIGN(PAGE_SIZE);
21620 + } :text.init
21621
21622 - INIT_DATA_SECTION(16)
21623 + /*
21624 + * .exit.text is discard at runtime, not link time, to deal with
21625 + * references from .altinstructions and .eh_frame
21626 + */
21627 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21628 + EXIT_TEXT
21629 + . = ALIGN(16);
21630 + } :text.exit
21631 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
21632 +
21633 + . = ALIGN(PAGE_SIZE);
21634 + INIT_DATA_SECTION(16) :init
21635
21636 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
21637 __x86_cpu_dev_start = .;
21638 @@ -257,19 +338,12 @@ SECTIONS
21639 }
21640
21641 . = ALIGN(8);
21642 - /*
21643 - * .exit.text is discard at runtime, not link time, to deal with
21644 - * references from .altinstructions and .eh_frame
21645 - */
21646 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
21647 - EXIT_TEXT
21648 - }
21649
21650 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
21651 EXIT_DATA
21652 }
21653
21654 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
21655 +#ifndef CONFIG_SMP
21656 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
21657 #endif
21658
21659 @@ -288,16 +362,10 @@ SECTIONS
21660 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
21661 __smp_locks = .;
21662 *(.smp_locks)
21663 - . = ALIGN(PAGE_SIZE);
21664 __smp_locks_end = .;
21665 + . = ALIGN(PAGE_SIZE);
21666 }
21667
21668 -#ifdef CONFIG_X86_64
21669 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
21670 - NOSAVE_DATA
21671 - }
21672 -#endif
21673 -
21674 /* BSS */
21675 . = ALIGN(PAGE_SIZE);
21676 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
21677 @@ -313,6 +381,7 @@ SECTIONS
21678 __brk_base = .;
21679 . += 64 * 1024; /* 64k alignment slop space */
21680 *(.brk_reservation) /* areas brk users have reserved */
21681 + . = ALIGN(HPAGE_SIZE);
21682 __brk_limit = .;
21683 }
21684
21685 @@ -339,13 +408,12 @@ SECTIONS
21686 * for the boot processor.
21687 */
21688 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
21689 -INIT_PER_CPU(gdt_page);
21690 INIT_PER_CPU(irq_stack_union);
21691
21692 /*
21693 * Build-time check on the image size:
21694 */
21695 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
21696 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
21697 "kernel image bigger than KERNEL_IMAGE_SIZE");
21698
21699 #ifdef CONFIG_SMP
21700 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
21701 index 992f890..0ab1aae 100644
21702 --- a/arch/x86/kernel/vsmp_64.c
21703 +++ b/arch/x86/kernel/vsmp_64.c
21704 @@ -114,7 +114,7 @@ static void __init set_vsmp_pv_ops(void)
21705 pv_irq_ops.irq_enable = PV_CALLEE_SAVE(vsmp_irq_enable);
21706 pv_irq_ops.save_fl = PV_CALLEE_SAVE(vsmp_save_fl);
21707 pv_irq_ops.restore_fl = PV_CALLEE_SAVE(vsmp_restore_fl);
21708 - pv_init_ops.patch = vsmp_patch;
21709 + *(void **)&pv_init_ops.patch = vsmp_patch;
21710 ctl &= ~(1 << 4);
21711 }
21712 writel(ctl, address + 4);
21713 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
21714 static void vsmp_apic_post_init(void)
21715 {
21716 /* need to update phys_pkg_id */
21717 - apic->phys_pkg_id = apicid_phys_pkg_id;
21718 - apic->vector_allocation_domain = fill_vector_allocation_domain;
21719 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
21720 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
21721 }
21722
21723 void __init vsmp_init(void)
21724 @@ -227,7 +227,7 @@ void __init vsmp_init(void)
21725 if (!is_vsmp_box())
21726 return;
21727
21728 - x86_platform.apic_post_init = vsmp_apic_post_init;
21729 + *(void **)&x86_platform.apic_post_init = vsmp_apic_post_init;
21730
21731 vsmp_cap_cpus();
21732
21733 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
21734 index 3a3e8c9..1af9465 100644
21735 --- a/arch/x86/kernel/vsyscall_64.c
21736 +++ b/arch/x86/kernel/vsyscall_64.c
21737 @@ -56,15 +56,13 @@
21738 DEFINE_VVAR(int, vgetcpu_mode);
21739 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
21740
21741 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
21742 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
21743
21744 static int __init vsyscall_setup(char *str)
21745 {
21746 if (str) {
21747 if (!strcmp("emulate", str))
21748 vsyscall_mode = EMULATE;
21749 - else if (!strcmp("native", str))
21750 - vsyscall_mode = NATIVE;
21751 else if (!strcmp("none", str))
21752 vsyscall_mode = NONE;
21753 else
21754 @@ -315,8 +313,7 @@ done:
21755 return true;
21756
21757 sigsegv:
21758 - force_sig(SIGSEGV, current);
21759 - return true;
21760 + do_group_exit(SIGKILL);
21761 }
21762
21763 /*
21764 @@ -369,10 +366,7 @@ void __init map_vsyscall(void)
21765 extern char __vvar_page;
21766 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
21767
21768 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
21769 - vsyscall_mode == NATIVE
21770 - ? PAGE_KERNEL_VSYSCALL
21771 - : PAGE_KERNEL_VVAR);
21772 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
21773 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
21774 (unsigned long)VSYSCALL_START);
21775
21776 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
21777 index 1330dd1..d220b99 100644
21778 --- a/arch/x86/kernel/x8664_ksyms_64.c
21779 +++ b/arch/x86/kernel/x8664_ksyms_64.c
21780 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
21781 EXPORT_SYMBOL(copy_user_generic_unrolled);
21782 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
21783 EXPORT_SYMBOL(__copy_user_nocache);
21784 -EXPORT_SYMBOL(_copy_from_user);
21785 -EXPORT_SYMBOL(_copy_to_user);
21786
21787 EXPORT_SYMBOL(copy_page);
21788 EXPORT_SYMBOL(clear_page);
21789 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
21790 index ada87a3..afea76d 100644
21791 --- a/arch/x86/kernel/xsave.c
21792 +++ b/arch/x86/kernel/xsave.c
21793 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
21794 {
21795 int err;
21796
21797 + buf = (struct xsave_struct __user *)____m(buf);
21798 if (use_xsave())
21799 err = xsave_user(buf);
21800 else if (use_fxsr())
21801 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
21802 */
21803 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
21804 {
21805 + buf = (void __user *)____m(buf);
21806 if (use_xsave()) {
21807 if ((unsigned long)buf % 64 || fx_only) {
21808 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
21809 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
21810 index ec79e77..420f5cc 100644
21811 --- a/arch/x86/kvm/cpuid.c
21812 +++ b/arch/x86/kvm/cpuid.c
21813 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
21814 struct kvm_cpuid2 *cpuid,
21815 struct kvm_cpuid_entry2 __user *entries)
21816 {
21817 - int r;
21818 + int r, i;
21819
21820 r = -E2BIG;
21821 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
21822 goto out;
21823 r = -EFAULT;
21824 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
21825 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21826 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21827 goto out;
21828 + for (i = 0; i < cpuid->nent; ++i) {
21829 + struct kvm_cpuid_entry2 cpuid_entry;
21830 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
21831 + goto out;
21832 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
21833 + }
21834 vcpu->arch.cpuid_nent = cpuid->nent;
21835 kvm_apic_set_version(vcpu);
21836 kvm_x86_ops->cpuid_update(vcpu);
21837 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
21838 struct kvm_cpuid2 *cpuid,
21839 struct kvm_cpuid_entry2 __user *entries)
21840 {
21841 - int r;
21842 + int r, i;
21843
21844 r = -E2BIG;
21845 if (cpuid->nent < vcpu->arch.cpuid_nent)
21846 goto out;
21847 r = -EFAULT;
21848 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
21849 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21850 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21851 goto out;
21852 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
21853 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
21854 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
21855 + goto out;
21856 + }
21857 return 0;
21858
21859 out:
21860 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
21861 index bba39bf..296540a 100644
21862 --- a/arch/x86/kvm/emulate.c
21863 +++ b/arch/x86/kvm/emulate.c
21864 @@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21865
21866 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
21867 do { \
21868 + unsigned long _tmp; \
21869 __asm__ __volatile__ ( \
21870 _PRE_EFLAGS("0", "4", "2") \
21871 _op _suffix " %"_x"3,%1; " \
21872 @@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21873 /* Raw emulation: instruction has two explicit operands. */
21874 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
21875 do { \
21876 - unsigned long _tmp; \
21877 - \
21878 switch ((ctxt)->dst.bytes) { \
21879 case 2: \
21880 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
21881 @@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21882
21883 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
21884 do { \
21885 - unsigned long _tmp; \
21886 switch ((ctxt)->dst.bytes) { \
21887 case 1: \
21888 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
21889 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
21890 index 43e9fad..3b7c059 100644
21891 --- a/arch/x86/kvm/lapic.c
21892 +++ b/arch/x86/kvm/lapic.c
21893 @@ -55,7 +55,7 @@
21894 #define APIC_BUS_CYCLE_NS 1
21895
21896 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
21897 -#define apic_debug(fmt, arg...)
21898 +#define apic_debug(fmt, arg...) do {} while (0)
21899
21900 #define APIC_LVT_NUM 6
21901 /* 14 is the version for Xeon and Pentium 8.4.8*/
21902 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
21903 index 714e2c0..3f7a086 100644
21904 --- a/arch/x86/kvm/paging_tmpl.h
21905 +++ b/arch/x86/kvm/paging_tmpl.h
21906 @@ -208,7 +208,7 @@ retry_walk:
21907 if (unlikely(kvm_is_error_hva(host_addr)))
21908 goto error;
21909
21910 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
21911 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
21912 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
21913 goto error;
21914 walker->ptep_user[walker->level - 1] = ptep_user;
21915 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
21916 index d017df3..61ae42e 100644
21917 --- a/arch/x86/kvm/svm.c
21918 +++ b/arch/x86/kvm/svm.c
21919 @@ -3500,7 +3500,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
21920 int cpu = raw_smp_processor_id();
21921
21922 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
21923 +
21924 + pax_open_kernel();
21925 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
21926 + pax_close_kernel();
21927 +
21928 load_TR_desc();
21929 }
21930
21931 @@ -3874,6 +3878,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
21932 #endif
21933 #endif
21934
21935 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21936 + __set_fs(current_thread_info()->addr_limit);
21937 +#endif
21938 +
21939 reload_tss(vcpu);
21940
21941 local_irq_disable();
21942 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
21943 index f858159..4ab7dba 100644
21944 --- a/arch/x86/kvm/vmx.c
21945 +++ b/arch/x86/kvm/vmx.c
21946 @@ -1332,7 +1332,11 @@ static void reload_tss(void)
21947 struct desc_struct *descs;
21948
21949 descs = (void *)gdt->address;
21950 +
21951 + pax_open_kernel();
21952 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
21953 + pax_close_kernel();
21954 +
21955 load_TR_desc();
21956 }
21957
21958 @@ -1546,6 +1550,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
21959 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
21960 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
21961
21962 +#ifdef CONFIG_PAX_PER_CPU_PGD
21963 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
21964 +#endif
21965 +
21966 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
21967 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
21968 vmx->loaded_vmcs->cpu = cpu;
21969 @@ -2669,8 +2677,11 @@ static __init int hardware_setup(void)
21970 if (!cpu_has_vmx_flexpriority())
21971 flexpriority_enabled = 0;
21972
21973 - if (!cpu_has_vmx_tpr_shadow())
21974 - kvm_x86_ops->update_cr8_intercept = NULL;
21975 + if (!cpu_has_vmx_tpr_shadow()) {
21976 + pax_open_kernel();
21977 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
21978 + pax_close_kernel();
21979 + }
21980
21981 if (enable_ept && !cpu_has_vmx_ept_2m_page())
21982 kvm_disable_largepages();
21983 @@ -3712,7 +3723,10 @@ static void vmx_set_constant_host_state(void)
21984
21985 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
21986 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
21987 +
21988 +#ifndef CONFIG_PAX_PER_CPU_PGD
21989 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
21990 +#endif
21991
21992 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
21993 #ifdef CONFIG_X86_64
21994 @@ -3733,7 +3747,7 @@ static void vmx_set_constant_host_state(void)
21995 native_store_idt(&dt);
21996 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
21997
21998 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
21999 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
22000
22001 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
22002 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
22003 @@ -6279,6 +6293,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22004 "jmp 2f \n\t"
22005 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
22006 "2: "
22007 +
22008 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22009 + "ljmp %[cs],$3f\n\t"
22010 + "3: "
22011 +#endif
22012 +
22013 /* Save guest registers, load host registers, keep flags */
22014 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
22015 "pop %0 \n\t"
22016 @@ -6331,6 +6351,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22017 #endif
22018 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
22019 [wordsize]"i"(sizeof(ulong))
22020 +
22021 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22022 + ,[cs]"i"(__KERNEL_CS)
22023 +#endif
22024 +
22025 : "cc", "memory"
22026 #ifdef CONFIG_X86_64
22027 , "rax", "rbx", "rdi", "rsi"
22028 @@ -6344,7 +6369,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22029 if (debugctlmsr)
22030 update_debugctlmsr(debugctlmsr);
22031
22032 -#ifndef CONFIG_X86_64
22033 +#ifdef CONFIG_X86_32
22034 /*
22035 * The sysexit path does not restore ds/es, so we must set them to
22036 * a reasonable value ourselves.
22037 @@ -6353,8 +6378,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22038 * may be executed in interrupt context, which saves and restore segments
22039 * around it, nullifying its effect.
22040 */
22041 - loadsegment(ds, __USER_DS);
22042 - loadsegment(es, __USER_DS);
22043 + loadsegment(ds, __KERNEL_DS);
22044 + loadsegment(es, __KERNEL_DS);
22045 + loadsegment(ss, __KERNEL_DS);
22046 +
22047 +#ifdef CONFIG_PAX_KERNEXEC
22048 + loadsegment(fs, __KERNEL_PERCPU);
22049 +#endif
22050 +
22051 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22052 + __set_fs(current_thread_info()->addr_limit);
22053 +#endif
22054 +
22055 #endif
22056
22057 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
22058 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
22059 index 4f76417..93429b5 100644
22060 --- a/arch/x86/kvm/x86.c
22061 +++ b/arch/x86/kvm/x86.c
22062 @@ -1390,8 +1390,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
22063 {
22064 struct kvm *kvm = vcpu->kvm;
22065 int lm = is_long_mode(vcpu);
22066 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
22067 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
22068 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
22069 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
22070 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
22071 : kvm->arch.xen_hvm_config.blob_size_32;
22072 u32 page_num = data & ~PAGE_MASK;
22073 @@ -2255,6 +2255,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
22074 if (n < msr_list.nmsrs)
22075 goto out;
22076 r = -EFAULT;
22077 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
22078 + goto out;
22079 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
22080 num_msrs_to_save * sizeof(u32)))
22081 goto out;
22082 @@ -2379,7 +2381,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
22083 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
22084 struct kvm_interrupt *irq)
22085 {
22086 - if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
22087 + if (irq->irq >= KVM_NR_INTERRUPTS)
22088 return -EINVAL;
22089 if (irqchip_in_kernel(vcpu->kvm))
22090 return -ENXIO;
22091 @@ -4881,7 +4883,7 @@ static void kvm_set_mmio_spte_mask(void)
22092 kvm_mmu_set_mmio_spte_mask(mask);
22093 }
22094
22095 -int kvm_arch_init(void *opaque)
22096 +int kvm_arch_init(const void *opaque)
22097 {
22098 int r;
22099 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
22100 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
22101 index 642d880..5dd034e 100644
22102 --- a/arch/x86/lguest/boot.c
22103 +++ b/arch/x86/lguest/boot.c
22104 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
22105
22106 static void set_lguest_basic_apic_ops(void)
22107 {
22108 - apic->read = lguest_apic_read;
22109 - apic->write = lguest_apic_write;
22110 - apic->icr_read = lguest_apic_icr_read;
22111 - apic->icr_write = lguest_apic_icr_write;
22112 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
22113 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
22114 + *(void **)&apic->read = lguest_apic_read;
22115 + *(void **)&apic->write = lguest_apic_write;
22116 + *(void **)&apic->icr_read = lguest_apic_icr_read;
22117 + *(void **)&apic->icr_write = lguest_apic_icr_write;
22118 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
22119 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
22120 };
22121 #endif
22122
22123 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
22124 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
22125 * Launcher to reboot us.
22126 */
22127 -static void lguest_restart(char *reason)
22128 +static __noreturn void lguest_restart(char *reason)
22129 {
22130 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
22131 + BUG();
22132 }
22133
22134 /*G:050
22135 @@ -1292,28 +1293,28 @@ __init void lguest_init(void)
22136 pv_irq_ops.safe_halt = lguest_safe_halt;
22137
22138 /* Setup operations */
22139 - pv_init_ops.patch = lguest_patch;
22140 + *(void **)&pv_init_ops.patch = lguest_patch;
22141
22142 /* Intercepts of various CPU instructions */
22143 - pv_cpu_ops.load_gdt = lguest_load_gdt;
22144 - pv_cpu_ops.cpuid = lguest_cpuid;
22145 - pv_cpu_ops.load_idt = lguest_load_idt;
22146 - pv_cpu_ops.iret = lguest_iret;
22147 - pv_cpu_ops.load_sp0 = lguest_load_sp0;
22148 - pv_cpu_ops.load_tr_desc = lguest_load_tr_desc;
22149 - pv_cpu_ops.set_ldt = lguest_set_ldt;
22150 - pv_cpu_ops.load_tls = lguest_load_tls;
22151 - pv_cpu_ops.set_debugreg = lguest_set_debugreg;
22152 - pv_cpu_ops.clts = lguest_clts;
22153 - pv_cpu_ops.read_cr0 = lguest_read_cr0;
22154 - pv_cpu_ops.write_cr0 = lguest_write_cr0;
22155 - pv_cpu_ops.read_cr4 = lguest_read_cr4;
22156 - pv_cpu_ops.write_cr4 = lguest_write_cr4;
22157 - pv_cpu_ops.write_gdt_entry = lguest_write_gdt_entry;
22158 - pv_cpu_ops.write_idt_entry = lguest_write_idt_entry;
22159 - pv_cpu_ops.wbinvd = lguest_wbinvd;
22160 - pv_cpu_ops.start_context_switch = paravirt_start_context_switch;
22161 - pv_cpu_ops.end_context_switch = lguest_end_context_switch;
22162 + *(void **)&pv_cpu_ops.load_gdt = lguest_load_gdt;
22163 + *(void **)&pv_cpu_ops.cpuid = lguest_cpuid;
22164 + *(void **)&pv_cpu_ops.load_idt = lguest_load_idt;
22165 + *(void **)&pv_cpu_ops.iret = lguest_iret;
22166 + *(void **)&pv_cpu_ops.load_sp0 = lguest_load_sp0;
22167 + *(void **)&pv_cpu_ops.load_tr_desc = lguest_load_tr_desc;
22168 + *(void **)&pv_cpu_ops.set_ldt = lguest_set_ldt;
22169 + *(void **)&pv_cpu_ops.load_tls = lguest_load_tls;
22170 + *(void **)&pv_cpu_ops.set_debugreg = lguest_set_debugreg;
22171 + *(void **)&pv_cpu_ops.clts = lguest_clts;
22172 + *(void **)&pv_cpu_ops.read_cr0 = lguest_read_cr0;
22173 + *(void **)&pv_cpu_ops.write_cr0 = lguest_write_cr0;
22174 + *(void **)&pv_cpu_ops.read_cr4 = lguest_read_cr4;
22175 + *(void **)&pv_cpu_ops.write_cr4 = lguest_write_cr4;
22176 + *(void **)&pv_cpu_ops.write_gdt_entry = lguest_write_gdt_entry;
22177 + *(void **)&pv_cpu_ops.write_idt_entry = lguest_write_idt_entry;
22178 + *(void **)&pv_cpu_ops.wbinvd = lguest_wbinvd;
22179 + *(void **)&pv_cpu_ops.start_context_switch = paravirt_start_context_switch;
22180 + *(void **)&pv_cpu_ops.end_context_switch = lguest_end_context_switch;
22181
22182 /* Pagetable management */
22183 pv_mmu_ops.write_cr3 = lguest_write_cr3;
22184 @@ -1341,11 +1342,11 @@ __init void lguest_init(void)
22185 set_lguest_basic_apic_ops();
22186 #endif
22187
22188 - x86_init.resources.memory_setup = lguest_memory_setup;
22189 - x86_init.irqs.intr_init = lguest_init_IRQ;
22190 - x86_init.timers.timer_init = lguest_time_init;
22191 - x86_platform.calibrate_tsc = lguest_tsc_khz;
22192 - x86_platform.get_wallclock = lguest_get_wallclock;
22193 + *(void **)&x86_init.resources.memory_setup = lguest_memory_setup;
22194 + *(void **)&x86_init.irqs.intr_init = lguest_init_IRQ;
22195 + *(void **)&x86_init.timers.timer_init = lguest_time_init;
22196 + *(void **)&x86_platform.calibrate_tsc = lguest_tsc_khz;
22197 + *(void **)&x86_platform.get_wallclock = lguest_get_wallclock;
22198
22199 /*
22200 * Now is a good time to look at the implementations of these functions
22201 @@ -1434,7 +1435,7 @@ __init void lguest_init(void)
22202 * routine.
22203 */
22204 pm_power_off = lguest_power_off;
22205 - machine_ops.restart = lguest_restart;
22206 + *(void **)&machine_ops.restart = lguest_restart;
22207
22208 /*
22209 * Now we're set up, call i386_start_kernel() in head32.c and we proceed
22210 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
22211 index 00933d5..3a64af9 100644
22212 --- a/arch/x86/lib/atomic64_386_32.S
22213 +++ b/arch/x86/lib/atomic64_386_32.S
22214 @@ -48,6 +48,10 @@ BEGIN(read)
22215 movl (v), %eax
22216 movl 4(v), %edx
22217 RET_ENDP
22218 +BEGIN(read_unchecked)
22219 + movl (v), %eax
22220 + movl 4(v), %edx
22221 +RET_ENDP
22222 #undef v
22223
22224 #define v %esi
22225 @@ -55,6 +59,10 @@ BEGIN(set)
22226 movl %ebx, (v)
22227 movl %ecx, 4(v)
22228 RET_ENDP
22229 +BEGIN(set_unchecked)
22230 + movl %ebx, (v)
22231 + movl %ecx, 4(v)
22232 +RET_ENDP
22233 #undef v
22234
22235 #define v %esi
22236 @@ -70,6 +78,20 @@ RET_ENDP
22237 BEGIN(add)
22238 addl %eax, (v)
22239 adcl %edx, 4(v)
22240 +
22241 +#ifdef CONFIG_PAX_REFCOUNT
22242 + jno 0f
22243 + subl %eax, (v)
22244 + sbbl %edx, 4(v)
22245 + int $4
22246 +0:
22247 + _ASM_EXTABLE(0b, 0b)
22248 +#endif
22249 +
22250 +RET_ENDP
22251 +BEGIN(add_unchecked)
22252 + addl %eax, (v)
22253 + adcl %edx, 4(v)
22254 RET_ENDP
22255 #undef v
22256
22257 @@ -77,6 +99,24 @@ RET_ENDP
22258 BEGIN(add_return)
22259 addl (v), %eax
22260 adcl 4(v), %edx
22261 +
22262 +#ifdef CONFIG_PAX_REFCOUNT
22263 + into
22264 +1234:
22265 + _ASM_EXTABLE(1234b, 2f)
22266 +#endif
22267 +
22268 + movl %eax, (v)
22269 + movl %edx, 4(v)
22270 +
22271 +#ifdef CONFIG_PAX_REFCOUNT
22272 +2:
22273 +#endif
22274 +
22275 +RET_ENDP
22276 +BEGIN(add_return_unchecked)
22277 + addl (v), %eax
22278 + adcl 4(v), %edx
22279 movl %eax, (v)
22280 movl %edx, 4(v)
22281 RET_ENDP
22282 @@ -86,6 +126,20 @@ RET_ENDP
22283 BEGIN(sub)
22284 subl %eax, (v)
22285 sbbl %edx, 4(v)
22286 +
22287 +#ifdef CONFIG_PAX_REFCOUNT
22288 + jno 0f
22289 + addl %eax, (v)
22290 + adcl %edx, 4(v)
22291 + int $4
22292 +0:
22293 + _ASM_EXTABLE(0b, 0b)
22294 +#endif
22295 +
22296 +RET_ENDP
22297 +BEGIN(sub_unchecked)
22298 + subl %eax, (v)
22299 + sbbl %edx, 4(v)
22300 RET_ENDP
22301 #undef v
22302
22303 @@ -96,6 +150,27 @@ BEGIN(sub_return)
22304 sbbl $0, %edx
22305 addl (v), %eax
22306 adcl 4(v), %edx
22307 +
22308 +#ifdef CONFIG_PAX_REFCOUNT
22309 + into
22310 +1234:
22311 + _ASM_EXTABLE(1234b, 2f)
22312 +#endif
22313 +
22314 + movl %eax, (v)
22315 + movl %edx, 4(v)
22316 +
22317 +#ifdef CONFIG_PAX_REFCOUNT
22318 +2:
22319 +#endif
22320 +
22321 +RET_ENDP
22322 +BEGIN(sub_return_unchecked)
22323 + negl %edx
22324 + negl %eax
22325 + sbbl $0, %edx
22326 + addl (v), %eax
22327 + adcl 4(v), %edx
22328 movl %eax, (v)
22329 movl %edx, 4(v)
22330 RET_ENDP
22331 @@ -105,6 +180,20 @@ RET_ENDP
22332 BEGIN(inc)
22333 addl $1, (v)
22334 adcl $0, 4(v)
22335 +
22336 +#ifdef CONFIG_PAX_REFCOUNT
22337 + jno 0f
22338 + subl $1, (v)
22339 + sbbl $0, 4(v)
22340 + int $4
22341 +0:
22342 + _ASM_EXTABLE(0b, 0b)
22343 +#endif
22344 +
22345 +RET_ENDP
22346 +BEGIN(inc_unchecked)
22347 + addl $1, (v)
22348 + adcl $0, 4(v)
22349 RET_ENDP
22350 #undef v
22351
22352 @@ -114,6 +203,26 @@ BEGIN(inc_return)
22353 movl 4(v), %edx
22354 addl $1, %eax
22355 adcl $0, %edx
22356 +
22357 +#ifdef CONFIG_PAX_REFCOUNT
22358 + into
22359 +1234:
22360 + _ASM_EXTABLE(1234b, 2f)
22361 +#endif
22362 +
22363 + movl %eax, (v)
22364 + movl %edx, 4(v)
22365 +
22366 +#ifdef CONFIG_PAX_REFCOUNT
22367 +2:
22368 +#endif
22369 +
22370 +RET_ENDP
22371 +BEGIN(inc_return_unchecked)
22372 + movl (v), %eax
22373 + movl 4(v), %edx
22374 + addl $1, %eax
22375 + adcl $0, %edx
22376 movl %eax, (v)
22377 movl %edx, 4(v)
22378 RET_ENDP
22379 @@ -123,6 +232,20 @@ RET_ENDP
22380 BEGIN(dec)
22381 subl $1, (v)
22382 sbbl $0, 4(v)
22383 +
22384 +#ifdef CONFIG_PAX_REFCOUNT
22385 + jno 0f
22386 + addl $1, (v)
22387 + adcl $0, 4(v)
22388 + int $4
22389 +0:
22390 + _ASM_EXTABLE(0b, 0b)
22391 +#endif
22392 +
22393 +RET_ENDP
22394 +BEGIN(dec_unchecked)
22395 + subl $1, (v)
22396 + sbbl $0, 4(v)
22397 RET_ENDP
22398 #undef v
22399
22400 @@ -132,6 +255,26 @@ BEGIN(dec_return)
22401 movl 4(v), %edx
22402 subl $1, %eax
22403 sbbl $0, %edx
22404 +
22405 +#ifdef CONFIG_PAX_REFCOUNT
22406 + into
22407 +1234:
22408 + _ASM_EXTABLE(1234b, 2f)
22409 +#endif
22410 +
22411 + movl %eax, (v)
22412 + movl %edx, 4(v)
22413 +
22414 +#ifdef CONFIG_PAX_REFCOUNT
22415 +2:
22416 +#endif
22417 +
22418 +RET_ENDP
22419 +BEGIN(dec_return_unchecked)
22420 + movl (v), %eax
22421 + movl 4(v), %edx
22422 + subl $1, %eax
22423 + sbbl $0, %edx
22424 movl %eax, (v)
22425 movl %edx, 4(v)
22426 RET_ENDP
22427 @@ -143,6 +286,13 @@ BEGIN(add_unless)
22428 adcl %edx, %edi
22429 addl (v), %eax
22430 adcl 4(v), %edx
22431 +
22432 +#ifdef CONFIG_PAX_REFCOUNT
22433 + into
22434 +1234:
22435 + _ASM_EXTABLE(1234b, 2f)
22436 +#endif
22437 +
22438 cmpl %eax, %ecx
22439 je 3f
22440 1:
22441 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
22442 1:
22443 addl $1, %eax
22444 adcl $0, %edx
22445 +
22446 +#ifdef CONFIG_PAX_REFCOUNT
22447 + into
22448 +1234:
22449 + _ASM_EXTABLE(1234b, 2f)
22450 +#endif
22451 +
22452 movl %eax, (v)
22453 movl %edx, 4(v)
22454 movl $1, %eax
22455 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
22456 movl 4(v), %edx
22457 subl $1, %eax
22458 sbbl $0, %edx
22459 +
22460 +#ifdef CONFIG_PAX_REFCOUNT
22461 + into
22462 +1234:
22463 + _ASM_EXTABLE(1234b, 1f)
22464 +#endif
22465 +
22466 js 1f
22467 movl %eax, (v)
22468 movl %edx, 4(v)
22469 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
22470 index f5cc9eb..51fa319 100644
22471 --- a/arch/x86/lib/atomic64_cx8_32.S
22472 +++ b/arch/x86/lib/atomic64_cx8_32.S
22473 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
22474 CFI_STARTPROC
22475
22476 read64 %ecx
22477 + pax_force_retaddr
22478 ret
22479 CFI_ENDPROC
22480 ENDPROC(atomic64_read_cx8)
22481
22482 +ENTRY(atomic64_read_unchecked_cx8)
22483 + CFI_STARTPROC
22484 +
22485 + read64 %ecx
22486 + pax_force_retaddr
22487 + ret
22488 + CFI_ENDPROC
22489 +ENDPROC(atomic64_read_unchecked_cx8)
22490 +
22491 ENTRY(atomic64_set_cx8)
22492 CFI_STARTPROC
22493
22494 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
22495 cmpxchg8b (%esi)
22496 jne 1b
22497
22498 + pax_force_retaddr
22499 ret
22500 CFI_ENDPROC
22501 ENDPROC(atomic64_set_cx8)
22502
22503 +ENTRY(atomic64_set_unchecked_cx8)
22504 + CFI_STARTPROC
22505 +
22506 +1:
22507 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
22508 + * are atomic on 586 and newer */
22509 + cmpxchg8b (%esi)
22510 + jne 1b
22511 +
22512 + pax_force_retaddr
22513 + ret
22514 + CFI_ENDPROC
22515 +ENDPROC(atomic64_set_unchecked_cx8)
22516 +
22517 ENTRY(atomic64_xchg_cx8)
22518 CFI_STARTPROC
22519
22520 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
22521 cmpxchg8b (%esi)
22522 jne 1b
22523
22524 + pax_force_retaddr
22525 ret
22526 CFI_ENDPROC
22527 ENDPROC(atomic64_xchg_cx8)
22528
22529 -.macro addsub_return func ins insc
22530 -ENTRY(atomic64_\func\()_return_cx8)
22531 +.macro addsub_return func ins insc unchecked=""
22532 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22533 CFI_STARTPROC
22534 SAVE ebp
22535 SAVE ebx
22536 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
22537 movl %edx, %ecx
22538 \ins\()l %esi, %ebx
22539 \insc\()l %edi, %ecx
22540 +
22541 +.ifb \unchecked
22542 +#ifdef CONFIG_PAX_REFCOUNT
22543 + into
22544 +2:
22545 + _ASM_EXTABLE(2b, 3f)
22546 +#endif
22547 +.endif
22548 +
22549 LOCK_PREFIX
22550 cmpxchg8b (%ebp)
22551 jne 1b
22552 -
22553 -10:
22554 movl %ebx, %eax
22555 movl %ecx, %edx
22556 +
22557 +.ifb \unchecked
22558 +#ifdef CONFIG_PAX_REFCOUNT
22559 +3:
22560 +#endif
22561 +.endif
22562 +
22563 RESTORE edi
22564 RESTORE esi
22565 RESTORE ebx
22566 RESTORE ebp
22567 + pax_force_retaddr
22568 ret
22569 CFI_ENDPROC
22570 -ENDPROC(atomic64_\func\()_return_cx8)
22571 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22572 .endm
22573
22574 addsub_return add add adc
22575 addsub_return sub sub sbb
22576 +addsub_return add add adc _unchecked
22577 +addsub_return sub sub sbb _unchecked
22578
22579 -.macro incdec_return func ins insc
22580 -ENTRY(atomic64_\func\()_return_cx8)
22581 +.macro incdec_return func ins insc unchecked=""
22582 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22583 CFI_STARTPROC
22584 SAVE ebx
22585
22586 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
22587 movl %edx, %ecx
22588 \ins\()l $1, %ebx
22589 \insc\()l $0, %ecx
22590 +
22591 +.ifb \unchecked
22592 +#ifdef CONFIG_PAX_REFCOUNT
22593 + into
22594 +2:
22595 + _ASM_EXTABLE(2b, 3f)
22596 +#endif
22597 +.endif
22598 +
22599 LOCK_PREFIX
22600 cmpxchg8b (%esi)
22601 jne 1b
22602
22603 -10:
22604 movl %ebx, %eax
22605 movl %ecx, %edx
22606 +
22607 +.ifb \unchecked
22608 +#ifdef CONFIG_PAX_REFCOUNT
22609 +3:
22610 +#endif
22611 +.endif
22612 +
22613 RESTORE ebx
22614 + pax_force_retaddr
22615 ret
22616 CFI_ENDPROC
22617 -ENDPROC(atomic64_\func\()_return_cx8)
22618 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22619 .endm
22620
22621 incdec_return inc add adc
22622 incdec_return dec sub sbb
22623 +incdec_return inc add adc _unchecked
22624 +incdec_return dec sub sbb _unchecked
22625
22626 ENTRY(atomic64_dec_if_positive_cx8)
22627 CFI_STARTPROC
22628 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
22629 movl %edx, %ecx
22630 subl $1, %ebx
22631 sbb $0, %ecx
22632 +
22633 +#ifdef CONFIG_PAX_REFCOUNT
22634 + into
22635 +1234:
22636 + _ASM_EXTABLE(1234b, 2f)
22637 +#endif
22638 +
22639 js 2f
22640 LOCK_PREFIX
22641 cmpxchg8b (%esi)
22642 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
22643 movl %ebx, %eax
22644 movl %ecx, %edx
22645 RESTORE ebx
22646 + pax_force_retaddr
22647 ret
22648 CFI_ENDPROC
22649 ENDPROC(atomic64_dec_if_positive_cx8)
22650 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
22651 movl %edx, %ecx
22652 addl %ebp, %ebx
22653 adcl %edi, %ecx
22654 +
22655 +#ifdef CONFIG_PAX_REFCOUNT
22656 + into
22657 +1234:
22658 + _ASM_EXTABLE(1234b, 3f)
22659 +#endif
22660 +
22661 LOCK_PREFIX
22662 cmpxchg8b (%esi)
22663 jne 1b
22664 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
22665 CFI_ADJUST_CFA_OFFSET -8
22666 RESTORE ebx
22667 RESTORE ebp
22668 + pax_force_retaddr
22669 ret
22670 4:
22671 cmpl %edx, 4(%esp)
22672 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
22673 xorl %ecx, %ecx
22674 addl $1, %ebx
22675 adcl %edx, %ecx
22676 +
22677 +#ifdef CONFIG_PAX_REFCOUNT
22678 + into
22679 +1234:
22680 + _ASM_EXTABLE(1234b, 3f)
22681 +#endif
22682 +
22683 LOCK_PREFIX
22684 cmpxchg8b (%esi)
22685 jne 1b
22686 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
22687 movl $1, %eax
22688 3:
22689 RESTORE ebx
22690 + pax_force_retaddr
22691 ret
22692 CFI_ENDPROC
22693 ENDPROC(atomic64_inc_not_zero_cx8)
22694 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
22695 index 2af5df3..62b1a5a 100644
22696 --- a/arch/x86/lib/checksum_32.S
22697 +++ b/arch/x86/lib/checksum_32.S
22698 @@ -29,7 +29,8 @@
22699 #include <asm/dwarf2.h>
22700 #include <asm/errno.h>
22701 #include <asm/asm.h>
22702 -
22703 +#include <asm/segment.h>
22704 +
22705 /*
22706 * computes a partial checksum, e.g. for TCP/UDP fragments
22707 */
22708 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
22709
22710 #define ARGBASE 16
22711 #define FP 12
22712 -
22713 -ENTRY(csum_partial_copy_generic)
22714 +
22715 +ENTRY(csum_partial_copy_generic_to_user)
22716 CFI_STARTPROC
22717 +
22718 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22719 + pushl_cfi %gs
22720 + popl_cfi %es
22721 + jmp csum_partial_copy_generic
22722 +#endif
22723 +
22724 +ENTRY(csum_partial_copy_generic_from_user)
22725 +
22726 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22727 + pushl_cfi %gs
22728 + popl_cfi %ds
22729 +#endif
22730 +
22731 +ENTRY(csum_partial_copy_generic)
22732 subl $4,%esp
22733 CFI_ADJUST_CFA_OFFSET 4
22734 pushl_cfi %edi
22735 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
22736 jmp 4f
22737 SRC(1: movw (%esi), %bx )
22738 addl $2, %esi
22739 -DST( movw %bx, (%edi) )
22740 +DST( movw %bx, %es:(%edi) )
22741 addl $2, %edi
22742 addw %bx, %ax
22743 adcl $0, %eax
22744 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
22745 SRC(1: movl (%esi), %ebx )
22746 SRC( movl 4(%esi), %edx )
22747 adcl %ebx, %eax
22748 -DST( movl %ebx, (%edi) )
22749 +DST( movl %ebx, %es:(%edi) )
22750 adcl %edx, %eax
22751 -DST( movl %edx, 4(%edi) )
22752 +DST( movl %edx, %es:4(%edi) )
22753
22754 SRC( movl 8(%esi), %ebx )
22755 SRC( movl 12(%esi), %edx )
22756 adcl %ebx, %eax
22757 -DST( movl %ebx, 8(%edi) )
22758 +DST( movl %ebx, %es:8(%edi) )
22759 adcl %edx, %eax
22760 -DST( movl %edx, 12(%edi) )
22761 +DST( movl %edx, %es:12(%edi) )
22762
22763 SRC( movl 16(%esi), %ebx )
22764 SRC( movl 20(%esi), %edx )
22765 adcl %ebx, %eax
22766 -DST( movl %ebx, 16(%edi) )
22767 +DST( movl %ebx, %es:16(%edi) )
22768 adcl %edx, %eax
22769 -DST( movl %edx, 20(%edi) )
22770 +DST( movl %edx, %es:20(%edi) )
22771
22772 SRC( movl 24(%esi), %ebx )
22773 SRC( movl 28(%esi), %edx )
22774 adcl %ebx, %eax
22775 -DST( movl %ebx, 24(%edi) )
22776 +DST( movl %ebx, %es:24(%edi) )
22777 adcl %edx, %eax
22778 -DST( movl %edx, 28(%edi) )
22779 +DST( movl %edx, %es:28(%edi) )
22780
22781 lea 32(%esi), %esi
22782 lea 32(%edi), %edi
22783 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
22784 shrl $2, %edx # This clears CF
22785 SRC(3: movl (%esi), %ebx )
22786 adcl %ebx, %eax
22787 -DST( movl %ebx, (%edi) )
22788 +DST( movl %ebx, %es:(%edi) )
22789 lea 4(%esi), %esi
22790 lea 4(%edi), %edi
22791 dec %edx
22792 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
22793 jb 5f
22794 SRC( movw (%esi), %cx )
22795 leal 2(%esi), %esi
22796 -DST( movw %cx, (%edi) )
22797 +DST( movw %cx, %es:(%edi) )
22798 leal 2(%edi), %edi
22799 je 6f
22800 shll $16,%ecx
22801 SRC(5: movb (%esi), %cl )
22802 -DST( movb %cl, (%edi) )
22803 +DST( movb %cl, %es:(%edi) )
22804 6: addl %ecx, %eax
22805 adcl $0, %eax
22806 7:
22807 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
22808
22809 6001:
22810 movl ARGBASE+20(%esp), %ebx # src_err_ptr
22811 - movl $-EFAULT, (%ebx)
22812 + movl $-EFAULT, %ss:(%ebx)
22813
22814 # zero the complete destination - computing the rest
22815 # is too much work
22816 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
22817
22818 6002:
22819 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22820 - movl $-EFAULT,(%ebx)
22821 + movl $-EFAULT,%ss:(%ebx)
22822 jmp 5000b
22823
22824 .previous
22825
22826 + pushl_cfi %ss
22827 + popl_cfi %ds
22828 + pushl_cfi %ss
22829 + popl_cfi %es
22830 popl_cfi %ebx
22831 CFI_RESTORE ebx
22832 popl_cfi %esi
22833 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
22834 popl_cfi %ecx # equivalent to addl $4,%esp
22835 ret
22836 CFI_ENDPROC
22837 -ENDPROC(csum_partial_copy_generic)
22838 +ENDPROC(csum_partial_copy_generic_to_user)
22839
22840 #else
22841
22842 /* Version for PentiumII/PPro */
22843
22844 #define ROUND1(x) \
22845 + nop; nop; nop; \
22846 SRC(movl x(%esi), %ebx ) ; \
22847 addl %ebx, %eax ; \
22848 - DST(movl %ebx, x(%edi) ) ;
22849 + DST(movl %ebx, %es:x(%edi)) ;
22850
22851 #define ROUND(x) \
22852 + nop; nop; nop; \
22853 SRC(movl x(%esi), %ebx ) ; \
22854 adcl %ebx, %eax ; \
22855 - DST(movl %ebx, x(%edi) ) ;
22856 + DST(movl %ebx, %es:x(%edi)) ;
22857
22858 #define ARGBASE 12
22859 -
22860 -ENTRY(csum_partial_copy_generic)
22861 +
22862 +ENTRY(csum_partial_copy_generic_to_user)
22863 CFI_STARTPROC
22864 +
22865 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22866 + pushl_cfi %gs
22867 + popl_cfi %es
22868 + jmp csum_partial_copy_generic
22869 +#endif
22870 +
22871 +ENTRY(csum_partial_copy_generic_from_user)
22872 +
22873 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22874 + pushl_cfi %gs
22875 + popl_cfi %ds
22876 +#endif
22877 +
22878 +ENTRY(csum_partial_copy_generic)
22879 pushl_cfi %ebx
22880 CFI_REL_OFFSET ebx, 0
22881 pushl_cfi %edi
22882 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
22883 subl %ebx, %edi
22884 lea -1(%esi),%edx
22885 andl $-32,%edx
22886 - lea 3f(%ebx,%ebx), %ebx
22887 + lea 3f(%ebx,%ebx,2), %ebx
22888 testl %esi, %esi
22889 jmp *%ebx
22890 1: addl $64,%esi
22891 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
22892 jb 5f
22893 SRC( movw (%esi), %dx )
22894 leal 2(%esi), %esi
22895 -DST( movw %dx, (%edi) )
22896 +DST( movw %dx, %es:(%edi) )
22897 leal 2(%edi), %edi
22898 je 6f
22899 shll $16,%edx
22900 5:
22901 SRC( movb (%esi), %dl )
22902 -DST( movb %dl, (%edi) )
22903 +DST( movb %dl, %es:(%edi) )
22904 6: addl %edx, %eax
22905 adcl $0, %eax
22906 7:
22907 .section .fixup, "ax"
22908 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
22909 - movl $-EFAULT, (%ebx)
22910 + movl $-EFAULT, %ss:(%ebx)
22911 # zero the complete destination (computing the rest is too much work)
22912 movl ARGBASE+8(%esp),%edi # dst
22913 movl ARGBASE+12(%esp),%ecx # len
22914 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
22915 rep; stosb
22916 jmp 7b
22917 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22918 - movl $-EFAULT, (%ebx)
22919 + movl $-EFAULT, %ss:(%ebx)
22920 jmp 7b
22921 .previous
22922
22923 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22924 + pushl_cfi %ss
22925 + popl_cfi %ds
22926 + pushl_cfi %ss
22927 + popl_cfi %es
22928 +#endif
22929 +
22930 popl_cfi %esi
22931 CFI_RESTORE esi
22932 popl_cfi %edi
22933 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
22934 CFI_RESTORE ebx
22935 ret
22936 CFI_ENDPROC
22937 -ENDPROC(csum_partial_copy_generic)
22938 +ENDPROC(csum_partial_copy_generic_to_user)
22939
22940 #undef ROUND
22941 #undef ROUND1
22942 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
22943 index f2145cf..cea889d 100644
22944 --- a/arch/x86/lib/clear_page_64.S
22945 +++ b/arch/x86/lib/clear_page_64.S
22946 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
22947 movl $4096/8,%ecx
22948 xorl %eax,%eax
22949 rep stosq
22950 + pax_force_retaddr
22951 ret
22952 CFI_ENDPROC
22953 ENDPROC(clear_page_c)
22954 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
22955 movl $4096,%ecx
22956 xorl %eax,%eax
22957 rep stosb
22958 + pax_force_retaddr
22959 ret
22960 CFI_ENDPROC
22961 ENDPROC(clear_page_c_e)
22962 @@ -43,6 +45,7 @@ ENTRY(clear_page)
22963 leaq 64(%rdi),%rdi
22964 jnz .Lloop
22965 nop
22966 + pax_force_retaddr
22967 ret
22968 CFI_ENDPROC
22969 .Lclear_page_end:
22970 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
22971
22972 #include <asm/cpufeature.h>
22973
22974 - .section .altinstr_replacement,"ax"
22975 + .section .altinstr_replacement,"a"
22976 1: .byte 0xeb /* jmp <disp8> */
22977 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
22978 2: .byte 0xeb /* jmp <disp8> */
22979 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
22980 index 1e572c5..2a162cd 100644
22981 --- a/arch/x86/lib/cmpxchg16b_emu.S
22982 +++ b/arch/x86/lib/cmpxchg16b_emu.S
22983 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
22984
22985 popf
22986 mov $1, %al
22987 + pax_force_retaddr
22988 ret
22989
22990 not_same:
22991 popf
22992 xor %al,%al
22993 + pax_force_retaddr
22994 ret
22995
22996 CFI_ENDPROC
22997 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
22998 index 6b34d04..dccb07f 100644
22999 --- a/arch/x86/lib/copy_page_64.S
23000 +++ b/arch/x86/lib/copy_page_64.S
23001 @@ -9,6 +9,7 @@ copy_page_c:
23002 CFI_STARTPROC
23003 movl $4096/8,%ecx
23004 rep movsq
23005 + pax_force_retaddr
23006 ret
23007 CFI_ENDPROC
23008 ENDPROC(copy_page_c)
23009 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
23010
23011 ENTRY(copy_page)
23012 CFI_STARTPROC
23013 - subq $2*8,%rsp
23014 - CFI_ADJUST_CFA_OFFSET 2*8
23015 + subq $3*8,%rsp
23016 + CFI_ADJUST_CFA_OFFSET 3*8
23017 movq %rbx,(%rsp)
23018 CFI_REL_OFFSET rbx, 0
23019 movq %r12,1*8(%rsp)
23020 CFI_REL_OFFSET r12, 1*8
23021 + movq %r13,2*8(%rsp)
23022 + CFI_REL_OFFSET r13, 2*8
23023
23024 movl $(4096/64)-5,%ecx
23025 .p2align 4
23026 @@ -37,7 +40,7 @@ ENTRY(copy_page)
23027 movq 16 (%rsi), %rdx
23028 movq 24 (%rsi), %r8
23029 movq 32 (%rsi), %r9
23030 - movq 40 (%rsi), %r10
23031 + movq 40 (%rsi), %r13
23032 movq 48 (%rsi), %r11
23033 movq 56 (%rsi), %r12
23034
23035 @@ -48,7 +51,7 @@ ENTRY(copy_page)
23036 movq %rdx, 16 (%rdi)
23037 movq %r8, 24 (%rdi)
23038 movq %r9, 32 (%rdi)
23039 - movq %r10, 40 (%rdi)
23040 + movq %r13, 40 (%rdi)
23041 movq %r11, 48 (%rdi)
23042 movq %r12, 56 (%rdi)
23043
23044 @@ -67,7 +70,7 @@ ENTRY(copy_page)
23045 movq 16 (%rsi), %rdx
23046 movq 24 (%rsi), %r8
23047 movq 32 (%rsi), %r9
23048 - movq 40 (%rsi), %r10
23049 + movq 40 (%rsi), %r13
23050 movq 48 (%rsi), %r11
23051 movq 56 (%rsi), %r12
23052
23053 @@ -76,7 +79,7 @@ ENTRY(copy_page)
23054 movq %rdx, 16 (%rdi)
23055 movq %r8, 24 (%rdi)
23056 movq %r9, 32 (%rdi)
23057 - movq %r10, 40 (%rdi)
23058 + movq %r13, 40 (%rdi)
23059 movq %r11, 48 (%rdi)
23060 movq %r12, 56 (%rdi)
23061
23062 @@ -89,8 +92,11 @@ ENTRY(copy_page)
23063 CFI_RESTORE rbx
23064 movq 1*8(%rsp),%r12
23065 CFI_RESTORE r12
23066 - addq $2*8,%rsp
23067 - CFI_ADJUST_CFA_OFFSET -2*8
23068 + movq 2*8(%rsp),%r13
23069 + CFI_RESTORE r13
23070 + addq $3*8,%rsp
23071 + CFI_ADJUST_CFA_OFFSET -3*8
23072 + pax_force_retaddr
23073 ret
23074 .Lcopy_page_end:
23075 CFI_ENDPROC
23076 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
23077
23078 #include <asm/cpufeature.h>
23079
23080 - .section .altinstr_replacement,"ax"
23081 + .section .altinstr_replacement,"a"
23082 1: .byte 0xeb /* jmp <disp8> */
23083 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
23084 2:
23085 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
23086 index a30ca15..d25fab6 100644
23087 --- a/arch/x86/lib/copy_user_64.S
23088 +++ b/arch/x86/lib/copy_user_64.S
23089 @@ -18,6 +18,7 @@
23090 #include <asm/alternative-asm.h>
23091 #include <asm/asm.h>
23092 #include <asm/smap.h>
23093 +#include <asm/pgtable.h>
23094
23095 /*
23096 * By placing feature2 after feature1 in altinstructions section, we logically
23097 @@ -31,7 +32,7 @@
23098 .byte 0xe9 /* 32bit jump */
23099 .long \orig-1f /* by default jump to orig */
23100 1:
23101 - .section .altinstr_replacement,"ax"
23102 + .section .altinstr_replacement,"a"
23103 2: .byte 0xe9 /* near jump with 32bit immediate */
23104 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
23105 3: .byte 0xe9 /* near jump with 32bit immediate */
23106 @@ -70,47 +71,20 @@
23107 #endif
23108 .endm
23109
23110 -/* Standard copy_to_user with segment limit checking */
23111 -ENTRY(_copy_to_user)
23112 - CFI_STARTPROC
23113 - GET_THREAD_INFO(%rax)
23114 - movq %rdi,%rcx
23115 - addq %rdx,%rcx
23116 - jc bad_to_user
23117 - cmpq TI_addr_limit(%rax),%rcx
23118 - ja bad_to_user
23119 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
23120 - copy_user_generic_unrolled,copy_user_generic_string, \
23121 - copy_user_enhanced_fast_string
23122 - CFI_ENDPROC
23123 -ENDPROC(_copy_to_user)
23124 -
23125 -/* Standard copy_from_user with segment limit checking */
23126 -ENTRY(_copy_from_user)
23127 - CFI_STARTPROC
23128 - GET_THREAD_INFO(%rax)
23129 - movq %rsi,%rcx
23130 - addq %rdx,%rcx
23131 - jc bad_from_user
23132 - cmpq TI_addr_limit(%rax),%rcx
23133 - ja bad_from_user
23134 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
23135 - copy_user_generic_unrolled,copy_user_generic_string, \
23136 - copy_user_enhanced_fast_string
23137 - CFI_ENDPROC
23138 -ENDPROC(_copy_from_user)
23139 -
23140 .section .fixup,"ax"
23141 /* must zero dest */
23142 ENTRY(bad_from_user)
23143 bad_from_user:
23144 CFI_STARTPROC
23145 + testl %edx,%edx
23146 + js bad_to_user
23147 movl %edx,%ecx
23148 xorl %eax,%eax
23149 rep
23150 stosb
23151 bad_to_user:
23152 movl %edx,%eax
23153 + pax_force_retaddr
23154 ret
23155 CFI_ENDPROC
23156 ENDPROC(bad_from_user)
23157 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
23158 jz 17f
23159 1: movq (%rsi),%r8
23160 2: movq 1*8(%rsi),%r9
23161 -3: movq 2*8(%rsi),%r10
23162 +3: movq 2*8(%rsi),%rax
23163 4: movq 3*8(%rsi),%r11
23164 5: movq %r8,(%rdi)
23165 6: movq %r9,1*8(%rdi)
23166 -7: movq %r10,2*8(%rdi)
23167 +7: movq %rax,2*8(%rdi)
23168 8: movq %r11,3*8(%rdi)
23169 9: movq 4*8(%rsi),%r8
23170 10: movq 5*8(%rsi),%r9
23171 -11: movq 6*8(%rsi),%r10
23172 +11: movq 6*8(%rsi),%rax
23173 12: movq 7*8(%rsi),%r11
23174 13: movq %r8,4*8(%rdi)
23175 14: movq %r9,5*8(%rdi)
23176 -15: movq %r10,6*8(%rdi)
23177 +15: movq %rax,6*8(%rdi)
23178 16: movq %r11,7*8(%rdi)
23179 leaq 64(%rsi),%rsi
23180 leaq 64(%rdi),%rdi
23181 @@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
23182 jnz 21b
23183 23: xor %eax,%eax
23184 ASM_CLAC
23185 + pax_force_retaddr
23186 ret
23187
23188 .section .fixup,"ax"
23189 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
23190 movsb
23191 4: xorl %eax,%eax
23192 ASM_CLAC
23193 + pax_force_retaddr
23194 ret
23195
23196 .section .fixup,"ax"
23197 @@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
23198 movsb
23199 2: xorl %eax,%eax
23200 ASM_CLAC
23201 + pax_force_retaddr
23202 ret
23203
23204 .section .fixup,"ax"
23205 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
23206 index 6a4f43c..f5f9e26 100644
23207 --- a/arch/x86/lib/copy_user_nocache_64.S
23208 +++ b/arch/x86/lib/copy_user_nocache_64.S
23209 @@ -8,6 +8,7 @@
23210
23211 #include <linux/linkage.h>
23212 #include <asm/dwarf2.h>
23213 +#include <asm/alternative-asm.h>
23214
23215 #define FIX_ALIGNMENT 1
23216
23217 @@ -16,6 +17,7 @@
23218 #include <asm/thread_info.h>
23219 #include <asm/asm.h>
23220 #include <asm/smap.h>
23221 +#include <asm/pgtable.h>
23222
23223 .macro ALIGN_DESTINATION
23224 #ifdef FIX_ALIGNMENT
23225 @@ -49,6 +51,15 @@
23226 */
23227 ENTRY(__copy_user_nocache)
23228 CFI_STARTPROC
23229 +
23230 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23231 + mov $PAX_USER_SHADOW_BASE,%rcx
23232 + cmp %rcx,%rsi
23233 + jae 1f
23234 + add %rcx,%rsi
23235 +1:
23236 +#endif
23237 +
23238 ASM_STAC
23239 cmpl $8,%edx
23240 jb 20f /* less then 8 bytes, go to byte copy loop */
23241 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
23242 jz 17f
23243 1: movq (%rsi),%r8
23244 2: movq 1*8(%rsi),%r9
23245 -3: movq 2*8(%rsi),%r10
23246 +3: movq 2*8(%rsi),%rax
23247 4: movq 3*8(%rsi),%r11
23248 5: movnti %r8,(%rdi)
23249 6: movnti %r9,1*8(%rdi)
23250 -7: movnti %r10,2*8(%rdi)
23251 +7: movnti %rax,2*8(%rdi)
23252 8: movnti %r11,3*8(%rdi)
23253 9: movq 4*8(%rsi),%r8
23254 10: movq 5*8(%rsi),%r9
23255 -11: movq 6*8(%rsi),%r10
23256 +11: movq 6*8(%rsi),%rax
23257 12: movq 7*8(%rsi),%r11
23258 13: movnti %r8,4*8(%rdi)
23259 14: movnti %r9,5*8(%rdi)
23260 -15: movnti %r10,6*8(%rdi)
23261 +15: movnti %rax,6*8(%rdi)
23262 16: movnti %r11,7*8(%rdi)
23263 leaq 64(%rsi),%rsi
23264 leaq 64(%rdi),%rdi
23265 @@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
23266 23: xorl %eax,%eax
23267 ASM_CLAC
23268 sfence
23269 + pax_force_retaddr
23270 ret
23271
23272 .section .fixup,"ax"
23273 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
23274 index 2419d5f..953ee51 100644
23275 --- a/arch/x86/lib/csum-copy_64.S
23276 +++ b/arch/x86/lib/csum-copy_64.S
23277 @@ -9,6 +9,7 @@
23278 #include <asm/dwarf2.h>
23279 #include <asm/errno.h>
23280 #include <asm/asm.h>
23281 +#include <asm/alternative-asm.h>
23282
23283 /*
23284 * Checksum copy with exception handling.
23285 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
23286 CFI_RESTORE rbp
23287 addq $7*8, %rsp
23288 CFI_ADJUST_CFA_OFFSET -7*8
23289 + pax_force_retaddr 0, 1
23290 ret
23291 CFI_RESTORE_STATE
23292
23293 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
23294 index 25b7ae8..169fafc 100644
23295 --- a/arch/x86/lib/csum-wrappers_64.c
23296 +++ b/arch/x86/lib/csum-wrappers_64.c
23297 @@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
23298 len -= 2;
23299 }
23300 }
23301 - isum = csum_partial_copy_generic((__force const void *)src,
23302 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
23303 dst, len, isum, errp, NULL);
23304 if (unlikely(*errp))
23305 goto out_err;
23306 @@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
23307 }
23308
23309 *errp = 0;
23310 - return csum_partial_copy_generic(src, (void __force *)dst,
23311 + return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
23312 len, isum, NULL, errp);
23313 }
23314 EXPORT_SYMBOL(csum_partial_copy_to_user);
23315 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
23316 index 156b9c8..b144132 100644
23317 --- a/arch/x86/lib/getuser.S
23318 +++ b/arch/x86/lib/getuser.S
23319 @@ -34,17 +34,40 @@
23320 #include <asm/thread_info.h>
23321 #include <asm/asm.h>
23322 #include <asm/smap.h>
23323 +#include <asm/segment.h>
23324 +#include <asm/pgtable.h>
23325 +#include <asm/alternative-asm.h>
23326 +
23327 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23328 +#define __copyuser_seg gs;
23329 +#else
23330 +#define __copyuser_seg
23331 +#endif
23332
23333 .text
23334 ENTRY(__get_user_1)
23335 CFI_STARTPROC
23336 +
23337 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23338 GET_THREAD_INFO(%_ASM_DX)
23339 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23340 jae bad_get_user
23341 ASM_STAC
23342 -1: movzb (%_ASM_AX),%edx
23343 +
23344 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23345 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23346 + cmp %_ASM_DX,%_ASM_AX
23347 + jae 1234f
23348 + add %_ASM_DX,%_ASM_AX
23349 +1234:
23350 +#endif
23351 +
23352 +#endif
23353 +
23354 +1: __copyuser_seg movzb (%_ASM_AX),%edx
23355 xor %eax,%eax
23356 ASM_CLAC
23357 + pax_force_retaddr
23358 ret
23359 CFI_ENDPROC
23360 ENDPROC(__get_user_1)
23361 @@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
23362 ENTRY(__get_user_2)
23363 CFI_STARTPROC
23364 add $1,%_ASM_AX
23365 +
23366 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23367 jc bad_get_user
23368 GET_THREAD_INFO(%_ASM_DX)
23369 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23370 jae bad_get_user
23371 ASM_STAC
23372 -2: movzwl -1(%_ASM_AX),%edx
23373 +
23374 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23375 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23376 + cmp %_ASM_DX,%_ASM_AX
23377 + jae 1234f
23378 + add %_ASM_DX,%_ASM_AX
23379 +1234:
23380 +#endif
23381 +
23382 +#endif
23383 +
23384 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
23385 xor %eax,%eax
23386 ASM_CLAC
23387 + pax_force_retaddr
23388 ret
23389 CFI_ENDPROC
23390 ENDPROC(__get_user_2)
23391 @@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
23392 ENTRY(__get_user_4)
23393 CFI_STARTPROC
23394 add $3,%_ASM_AX
23395 +
23396 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23397 jc bad_get_user
23398 GET_THREAD_INFO(%_ASM_DX)
23399 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23400 jae bad_get_user
23401 ASM_STAC
23402 -3: mov -3(%_ASM_AX),%edx
23403 +
23404 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23405 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23406 + cmp %_ASM_DX,%_ASM_AX
23407 + jae 1234f
23408 + add %_ASM_DX,%_ASM_AX
23409 +1234:
23410 +#endif
23411 +
23412 +#endif
23413 +
23414 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
23415 xor %eax,%eax
23416 ASM_CLAC
23417 + pax_force_retaddr
23418 ret
23419 CFI_ENDPROC
23420 ENDPROC(__get_user_4)
23421 @@ -87,10 +138,20 @@ ENTRY(__get_user_8)
23422 GET_THREAD_INFO(%_ASM_DX)
23423 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23424 jae bad_get_user
23425 +
23426 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23427 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23428 + cmp %_ASM_DX,%_ASM_AX
23429 + jae 1234f
23430 + add %_ASM_DX,%_ASM_AX
23431 +1234:
23432 +#endif
23433 +
23434 ASM_STAC
23435 4: movq -7(%_ASM_AX),%_ASM_DX
23436 xor %eax,%eax
23437 ASM_CLAC
23438 + pax_force_retaddr
23439 ret
23440 CFI_ENDPROC
23441 ENDPROC(__get_user_8)
23442 @@ -101,6 +162,7 @@ bad_get_user:
23443 xor %edx,%edx
23444 mov $(-EFAULT),%_ASM_AX
23445 ASM_CLAC
23446 + pax_force_retaddr
23447 ret
23448 CFI_ENDPROC
23449 END(bad_get_user)
23450 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
23451 index 54fcffe..7be149e 100644
23452 --- a/arch/x86/lib/insn.c
23453 +++ b/arch/x86/lib/insn.c
23454 @@ -20,8 +20,10 @@
23455
23456 #ifdef __KERNEL__
23457 #include <linux/string.h>
23458 +#include <asm/pgtable_types.h>
23459 #else
23460 #include <string.h>
23461 +#define ktla_ktva(addr) addr
23462 #endif
23463 #include <asm/inat.h>
23464 #include <asm/insn.h>
23465 @@ -53,8 +55,8 @@
23466 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
23467 {
23468 memset(insn, 0, sizeof(*insn));
23469 - insn->kaddr = kaddr;
23470 - insn->next_byte = kaddr;
23471 + insn->kaddr = ktla_ktva(kaddr);
23472 + insn->next_byte = ktla_ktva(kaddr);
23473 insn->x86_64 = x86_64 ? 1 : 0;
23474 insn->opnd_bytes = 4;
23475 if (x86_64)
23476 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
23477 index 05a95e7..326f2fa 100644
23478 --- a/arch/x86/lib/iomap_copy_64.S
23479 +++ b/arch/x86/lib/iomap_copy_64.S
23480 @@ -17,6 +17,7 @@
23481
23482 #include <linux/linkage.h>
23483 #include <asm/dwarf2.h>
23484 +#include <asm/alternative-asm.h>
23485
23486 /*
23487 * override generic version in lib/iomap_copy.c
23488 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
23489 CFI_STARTPROC
23490 movl %edx,%ecx
23491 rep movsd
23492 + pax_force_retaddr
23493 ret
23494 CFI_ENDPROC
23495 ENDPROC(__iowrite32_copy)
23496 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
23497 index 1c273be..da9cc0e 100644
23498 --- a/arch/x86/lib/memcpy_64.S
23499 +++ b/arch/x86/lib/memcpy_64.S
23500 @@ -33,6 +33,7 @@
23501 rep movsq
23502 movl %edx, %ecx
23503 rep movsb
23504 + pax_force_retaddr
23505 ret
23506 .Lmemcpy_e:
23507 .previous
23508 @@ -49,6 +50,7 @@
23509 movq %rdi, %rax
23510 movq %rdx, %rcx
23511 rep movsb
23512 + pax_force_retaddr
23513 ret
23514 .Lmemcpy_e_e:
23515 .previous
23516 @@ -76,13 +78,13 @@ ENTRY(memcpy)
23517 */
23518 movq 0*8(%rsi), %r8
23519 movq 1*8(%rsi), %r9
23520 - movq 2*8(%rsi), %r10
23521 + movq 2*8(%rsi), %rcx
23522 movq 3*8(%rsi), %r11
23523 leaq 4*8(%rsi), %rsi
23524
23525 movq %r8, 0*8(%rdi)
23526 movq %r9, 1*8(%rdi)
23527 - movq %r10, 2*8(%rdi)
23528 + movq %rcx, 2*8(%rdi)
23529 movq %r11, 3*8(%rdi)
23530 leaq 4*8(%rdi), %rdi
23531 jae .Lcopy_forward_loop
23532 @@ -105,12 +107,12 @@ ENTRY(memcpy)
23533 subq $0x20, %rdx
23534 movq -1*8(%rsi), %r8
23535 movq -2*8(%rsi), %r9
23536 - movq -3*8(%rsi), %r10
23537 + movq -3*8(%rsi), %rcx
23538 movq -4*8(%rsi), %r11
23539 leaq -4*8(%rsi), %rsi
23540 movq %r8, -1*8(%rdi)
23541 movq %r9, -2*8(%rdi)
23542 - movq %r10, -3*8(%rdi)
23543 + movq %rcx, -3*8(%rdi)
23544 movq %r11, -4*8(%rdi)
23545 leaq -4*8(%rdi), %rdi
23546 jae .Lcopy_backward_loop
23547 @@ -130,12 +132,13 @@ ENTRY(memcpy)
23548 */
23549 movq 0*8(%rsi), %r8
23550 movq 1*8(%rsi), %r9
23551 - movq -2*8(%rsi, %rdx), %r10
23552 + movq -2*8(%rsi, %rdx), %rcx
23553 movq -1*8(%rsi, %rdx), %r11
23554 movq %r8, 0*8(%rdi)
23555 movq %r9, 1*8(%rdi)
23556 - movq %r10, -2*8(%rdi, %rdx)
23557 + movq %rcx, -2*8(%rdi, %rdx)
23558 movq %r11, -1*8(%rdi, %rdx)
23559 + pax_force_retaddr
23560 retq
23561 .p2align 4
23562 .Lless_16bytes:
23563 @@ -148,6 +151,7 @@ ENTRY(memcpy)
23564 movq -1*8(%rsi, %rdx), %r9
23565 movq %r8, 0*8(%rdi)
23566 movq %r9, -1*8(%rdi, %rdx)
23567 + pax_force_retaddr
23568 retq
23569 .p2align 4
23570 .Lless_8bytes:
23571 @@ -161,6 +165,7 @@ ENTRY(memcpy)
23572 movl -4(%rsi, %rdx), %r8d
23573 movl %ecx, (%rdi)
23574 movl %r8d, -4(%rdi, %rdx)
23575 + pax_force_retaddr
23576 retq
23577 .p2align 4
23578 .Lless_3bytes:
23579 @@ -179,6 +184,7 @@ ENTRY(memcpy)
23580 movb %cl, (%rdi)
23581
23582 .Lend:
23583 + pax_force_retaddr
23584 retq
23585 CFI_ENDPROC
23586 ENDPROC(memcpy)
23587 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
23588 index ee16461..c39c199 100644
23589 --- a/arch/x86/lib/memmove_64.S
23590 +++ b/arch/x86/lib/memmove_64.S
23591 @@ -61,13 +61,13 @@ ENTRY(memmove)
23592 5:
23593 sub $0x20, %rdx
23594 movq 0*8(%rsi), %r11
23595 - movq 1*8(%rsi), %r10
23596 + movq 1*8(%rsi), %rcx
23597 movq 2*8(%rsi), %r9
23598 movq 3*8(%rsi), %r8
23599 leaq 4*8(%rsi), %rsi
23600
23601 movq %r11, 0*8(%rdi)
23602 - movq %r10, 1*8(%rdi)
23603 + movq %rcx, 1*8(%rdi)
23604 movq %r9, 2*8(%rdi)
23605 movq %r8, 3*8(%rdi)
23606 leaq 4*8(%rdi), %rdi
23607 @@ -81,10 +81,10 @@ ENTRY(memmove)
23608 4:
23609 movq %rdx, %rcx
23610 movq -8(%rsi, %rdx), %r11
23611 - lea -8(%rdi, %rdx), %r10
23612 + lea -8(%rdi, %rdx), %r9
23613 shrq $3, %rcx
23614 rep movsq
23615 - movq %r11, (%r10)
23616 + movq %r11, (%r9)
23617 jmp 13f
23618 .Lmemmove_end_forward:
23619
23620 @@ -95,14 +95,14 @@ ENTRY(memmove)
23621 7:
23622 movq %rdx, %rcx
23623 movq (%rsi), %r11
23624 - movq %rdi, %r10
23625 + movq %rdi, %r9
23626 leaq -8(%rsi, %rdx), %rsi
23627 leaq -8(%rdi, %rdx), %rdi
23628 shrq $3, %rcx
23629 std
23630 rep movsq
23631 cld
23632 - movq %r11, (%r10)
23633 + movq %r11, (%r9)
23634 jmp 13f
23635
23636 /*
23637 @@ -127,13 +127,13 @@ ENTRY(memmove)
23638 8:
23639 subq $0x20, %rdx
23640 movq -1*8(%rsi), %r11
23641 - movq -2*8(%rsi), %r10
23642 + movq -2*8(%rsi), %rcx
23643 movq -3*8(%rsi), %r9
23644 movq -4*8(%rsi), %r8
23645 leaq -4*8(%rsi), %rsi
23646
23647 movq %r11, -1*8(%rdi)
23648 - movq %r10, -2*8(%rdi)
23649 + movq %rcx, -2*8(%rdi)
23650 movq %r9, -3*8(%rdi)
23651 movq %r8, -4*8(%rdi)
23652 leaq -4*8(%rdi), %rdi
23653 @@ -151,11 +151,11 @@ ENTRY(memmove)
23654 * Move data from 16 bytes to 31 bytes.
23655 */
23656 movq 0*8(%rsi), %r11
23657 - movq 1*8(%rsi), %r10
23658 + movq 1*8(%rsi), %rcx
23659 movq -2*8(%rsi, %rdx), %r9
23660 movq -1*8(%rsi, %rdx), %r8
23661 movq %r11, 0*8(%rdi)
23662 - movq %r10, 1*8(%rdi)
23663 + movq %rcx, 1*8(%rdi)
23664 movq %r9, -2*8(%rdi, %rdx)
23665 movq %r8, -1*8(%rdi, %rdx)
23666 jmp 13f
23667 @@ -167,9 +167,9 @@ ENTRY(memmove)
23668 * Move data from 8 bytes to 15 bytes.
23669 */
23670 movq 0*8(%rsi), %r11
23671 - movq -1*8(%rsi, %rdx), %r10
23672 + movq -1*8(%rsi, %rdx), %r9
23673 movq %r11, 0*8(%rdi)
23674 - movq %r10, -1*8(%rdi, %rdx)
23675 + movq %r9, -1*8(%rdi, %rdx)
23676 jmp 13f
23677 10:
23678 cmpq $4, %rdx
23679 @@ -178,9 +178,9 @@ ENTRY(memmove)
23680 * Move data from 4 bytes to 7 bytes.
23681 */
23682 movl (%rsi), %r11d
23683 - movl -4(%rsi, %rdx), %r10d
23684 + movl -4(%rsi, %rdx), %r9d
23685 movl %r11d, (%rdi)
23686 - movl %r10d, -4(%rdi, %rdx)
23687 + movl %r9d, -4(%rdi, %rdx)
23688 jmp 13f
23689 11:
23690 cmp $2, %rdx
23691 @@ -189,9 +189,9 @@ ENTRY(memmove)
23692 * Move data from 2 bytes to 3 bytes.
23693 */
23694 movw (%rsi), %r11w
23695 - movw -2(%rsi, %rdx), %r10w
23696 + movw -2(%rsi, %rdx), %r9w
23697 movw %r11w, (%rdi)
23698 - movw %r10w, -2(%rdi, %rdx)
23699 + movw %r9w, -2(%rdi, %rdx)
23700 jmp 13f
23701 12:
23702 cmp $1, %rdx
23703 @@ -202,6 +202,7 @@ ENTRY(memmove)
23704 movb (%rsi), %r11b
23705 movb %r11b, (%rdi)
23706 13:
23707 + pax_force_retaddr
23708 retq
23709 CFI_ENDPROC
23710
23711 @@ -210,6 +211,7 @@ ENTRY(memmove)
23712 /* Forward moving data. */
23713 movq %rdx, %rcx
23714 rep movsb
23715 + pax_force_retaddr
23716 retq
23717 .Lmemmove_end_forward_efs:
23718 .previous
23719 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
23720 index 2dcb380..963660a 100644
23721 --- a/arch/x86/lib/memset_64.S
23722 +++ b/arch/x86/lib/memset_64.S
23723 @@ -30,6 +30,7 @@
23724 movl %edx,%ecx
23725 rep stosb
23726 movq %r9,%rax
23727 + pax_force_retaddr
23728 ret
23729 .Lmemset_e:
23730 .previous
23731 @@ -52,6 +53,7 @@
23732 movq %rdx,%rcx
23733 rep stosb
23734 movq %r9,%rax
23735 + pax_force_retaddr
23736 ret
23737 .Lmemset_e_e:
23738 .previous
23739 @@ -59,7 +61,7 @@
23740 ENTRY(memset)
23741 ENTRY(__memset)
23742 CFI_STARTPROC
23743 - movq %rdi,%r10
23744 + movq %rdi,%r11
23745
23746 /* expand byte value */
23747 movzbl %sil,%ecx
23748 @@ -117,7 +119,8 @@ ENTRY(__memset)
23749 jnz .Lloop_1
23750
23751 .Lende:
23752 - movq %r10,%rax
23753 + movq %r11,%rax
23754 + pax_force_retaddr
23755 ret
23756
23757 CFI_RESTORE_STATE
23758 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
23759 index c9f2d9b..e7fd2c0 100644
23760 --- a/arch/x86/lib/mmx_32.c
23761 +++ b/arch/x86/lib/mmx_32.c
23762 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23763 {
23764 void *p;
23765 int i;
23766 + unsigned long cr0;
23767
23768 if (unlikely(in_interrupt()))
23769 return __memcpy(to, from, len);
23770 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23771 kernel_fpu_begin();
23772
23773 __asm__ __volatile__ (
23774 - "1: prefetch (%0)\n" /* This set is 28 bytes */
23775 - " prefetch 64(%0)\n"
23776 - " prefetch 128(%0)\n"
23777 - " prefetch 192(%0)\n"
23778 - " prefetch 256(%0)\n"
23779 + "1: prefetch (%1)\n" /* This set is 28 bytes */
23780 + " prefetch 64(%1)\n"
23781 + " prefetch 128(%1)\n"
23782 + " prefetch 192(%1)\n"
23783 + " prefetch 256(%1)\n"
23784 "2: \n"
23785 ".section .fixup, \"ax\"\n"
23786 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23787 + "3: \n"
23788 +
23789 +#ifdef CONFIG_PAX_KERNEXEC
23790 + " movl %%cr0, %0\n"
23791 + " movl %0, %%eax\n"
23792 + " andl $0xFFFEFFFF, %%eax\n"
23793 + " movl %%eax, %%cr0\n"
23794 +#endif
23795 +
23796 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23797 +
23798 +#ifdef CONFIG_PAX_KERNEXEC
23799 + " movl %0, %%cr0\n"
23800 +#endif
23801 +
23802 " jmp 2b\n"
23803 ".previous\n"
23804 _ASM_EXTABLE(1b, 3b)
23805 - : : "r" (from));
23806 + : "=&r" (cr0) : "r" (from) : "ax");
23807
23808 for ( ; i > 5; i--) {
23809 __asm__ __volatile__ (
23810 - "1: prefetch 320(%0)\n"
23811 - "2: movq (%0), %%mm0\n"
23812 - " movq 8(%0), %%mm1\n"
23813 - " movq 16(%0), %%mm2\n"
23814 - " movq 24(%0), %%mm3\n"
23815 - " movq %%mm0, (%1)\n"
23816 - " movq %%mm1, 8(%1)\n"
23817 - " movq %%mm2, 16(%1)\n"
23818 - " movq %%mm3, 24(%1)\n"
23819 - " movq 32(%0), %%mm0\n"
23820 - " movq 40(%0), %%mm1\n"
23821 - " movq 48(%0), %%mm2\n"
23822 - " movq 56(%0), %%mm3\n"
23823 - " movq %%mm0, 32(%1)\n"
23824 - " movq %%mm1, 40(%1)\n"
23825 - " movq %%mm2, 48(%1)\n"
23826 - " movq %%mm3, 56(%1)\n"
23827 + "1: prefetch 320(%1)\n"
23828 + "2: movq (%1), %%mm0\n"
23829 + " movq 8(%1), %%mm1\n"
23830 + " movq 16(%1), %%mm2\n"
23831 + " movq 24(%1), %%mm3\n"
23832 + " movq %%mm0, (%2)\n"
23833 + " movq %%mm1, 8(%2)\n"
23834 + " movq %%mm2, 16(%2)\n"
23835 + " movq %%mm3, 24(%2)\n"
23836 + " movq 32(%1), %%mm0\n"
23837 + " movq 40(%1), %%mm1\n"
23838 + " movq 48(%1), %%mm2\n"
23839 + " movq 56(%1), %%mm3\n"
23840 + " movq %%mm0, 32(%2)\n"
23841 + " movq %%mm1, 40(%2)\n"
23842 + " movq %%mm2, 48(%2)\n"
23843 + " movq %%mm3, 56(%2)\n"
23844 ".section .fixup, \"ax\"\n"
23845 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23846 + "3:\n"
23847 +
23848 +#ifdef CONFIG_PAX_KERNEXEC
23849 + " movl %%cr0, %0\n"
23850 + " movl %0, %%eax\n"
23851 + " andl $0xFFFEFFFF, %%eax\n"
23852 + " movl %%eax, %%cr0\n"
23853 +#endif
23854 +
23855 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23856 +
23857 +#ifdef CONFIG_PAX_KERNEXEC
23858 + " movl %0, %%cr0\n"
23859 +#endif
23860 +
23861 " jmp 2b\n"
23862 ".previous\n"
23863 _ASM_EXTABLE(1b, 3b)
23864 - : : "r" (from), "r" (to) : "memory");
23865 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23866
23867 from += 64;
23868 to += 64;
23869 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
23870 static void fast_copy_page(void *to, void *from)
23871 {
23872 int i;
23873 + unsigned long cr0;
23874
23875 kernel_fpu_begin();
23876
23877 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
23878 * but that is for later. -AV
23879 */
23880 __asm__ __volatile__(
23881 - "1: prefetch (%0)\n"
23882 - " prefetch 64(%0)\n"
23883 - " prefetch 128(%0)\n"
23884 - " prefetch 192(%0)\n"
23885 - " prefetch 256(%0)\n"
23886 + "1: prefetch (%1)\n"
23887 + " prefetch 64(%1)\n"
23888 + " prefetch 128(%1)\n"
23889 + " prefetch 192(%1)\n"
23890 + " prefetch 256(%1)\n"
23891 "2: \n"
23892 ".section .fixup, \"ax\"\n"
23893 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23894 + "3: \n"
23895 +
23896 +#ifdef CONFIG_PAX_KERNEXEC
23897 + " movl %%cr0, %0\n"
23898 + " movl %0, %%eax\n"
23899 + " andl $0xFFFEFFFF, %%eax\n"
23900 + " movl %%eax, %%cr0\n"
23901 +#endif
23902 +
23903 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23904 +
23905 +#ifdef CONFIG_PAX_KERNEXEC
23906 + " movl %0, %%cr0\n"
23907 +#endif
23908 +
23909 " jmp 2b\n"
23910 ".previous\n"
23911 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
23912 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
23913
23914 for (i = 0; i < (4096-320)/64; i++) {
23915 __asm__ __volatile__ (
23916 - "1: prefetch 320(%0)\n"
23917 - "2: movq (%0), %%mm0\n"
23918 - " movntq %%mm0, (%1)\n"
23919 - " movq 8(%0), %%mm1\n"
23920 - " movntq %%mm1, 8(%1)\n"
23921 - " movq 16(%0), %%mm2\n"
23922 - " movntq %%mm2, 16(%1)\n"
23923 - " movq 24(%0), %%mm3\n"
23924 - " movntq %%mm3, 24(%1)\n"
23925 - " movq 32(%0), %%mm4\n"
23926 - " movntq %%mm4, 32(%1)\n"
23927 - " movq 40(%0), %%mm5\n"
23928 - " movntq %%mm5, 40(%1)\n"
23929 - " movq 48(%0), %%mm6\n"
23930 - " movntq %%mm6, 48(%1)\n"
23931 - " movq 56(%0), %%mm7\n"
23932 - " movntq %%mm7, 56(%1)\n"
23933 + "1: prefetch 320(%1)\n"
23934 + "2: movq (%1), %%mm0\n"
23935 + " movntq %%mm0, (%2)\n"
23936 + " movq 8(%1), %%mm1\n"
23937 + " movntq %%mm1, 8(%2)\n"
23938 + " movq 16(%1), %%mm2\n"
23939 + " movntq %%mm2, 16(%2)\n"
23940 + " movq 24(%1), %%mm3\n"
23941 + " movntq %%mm3, 24(%2)\n"
23942 + " movq 32(%1), %%mm4\n"
23943 + " movntq %%mm4, 32(%2)\n"
23944 + " movq 40(%1), %%mm5\n"
23945 + " movntq %%mm5, 40(%2)\n"
23946 + " movq 48(%1), %%mm6\n"
23947 + " movntq %%mm6, 48(%2)\n"
23948 + " movq 56(%1), %%mm7\n"
23949 + " movntq %%mm7, 56(%2)\n"
23950 ".section .fixup, \"ax\"\n"
23951 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23952 + "3:\n"
23953 +
23954 +#ifdef CONFIG_PAX_KERNEXEC
23955 + " movl %%cr0, %0\n"
23956 + " movl %0, %%eax\n"
23957 + " andl $0xFFFEFFFF, %%eax\n"
23958 + " movl %%eax, %%cr0\n"
23959 +#endif
23960 +
23961 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23962 +
23963 +#ifdef CONFIG_PAX_KERNEXEC
23964 + " movl %0, %%cr0\n"
23965 +#endif
23966 +
23967 " jmp 2b\n"
23968 ".previous\n"
23969 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
23970 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23971
23972 from += 64;
23973 to += 64;
23974 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
23975 static void fast_copy_page(void *to, void *from)
23976 {
23977 int i;
23978 + unsigned long cr0;
23979
23980 kernel_fpu_begin();
23981
23982 __asm__ __volatile__ (
23983 - "1: prefetch (%0)\n"
23984 - " prefetch 64(%0)\n"
23985 - " prefetch 128(%0)\n"
23986 - " prefetch 192(%0)\n"
23987 - " prefetch 256(%0)\n"
23988 + "1: prefetch (%1)\n"
23989 + " prefetch 64(%1)\n"
23990 + " prefetch 128(%1)\n"
23991 + " prefetch 192(%1)\n"
23992 + " prefetch 256(%1)\n"
23993 "2: \n"
23994 ".section .fixup, \"ax\"\n"
23995 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23996 + "3: \n"
23997 +
23998 +#ifdef CONFIG_PAX_KERNEXEC
23999 + " movl %%cr0, %0\n"
24000 + " movl %0, %%eax\n"
24001 + " andl $0xFFFEFFFF, %%eax\n"
24002 + " movl %%eax, %%cr0\n"
24003 +#endif
24004 +
24005 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
24006 +
24007 +#ifdef CONFIG_PAX_KERNEXEC
24008 + " movl %0, %%cr0\n"
24009 +#endif
24010 +
24011 " jmp 2b\n"
24012 ".previous\n"
24013 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
24014 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
24015
24016 for (i = 0; i < 4096/64; i++) {
24017 __asm__ __volatile__ (
24018 - "1: prefetch 320(%0)\n"
24019 - "2: movq (%0), %%mm0\n"
24020 - " movq 8(%0), %%mm1\n"
24021 - " movq 16(%0), %%mm2\n"
24022 - " movq 24(%0), %%mm3\n"
24023 - " movq %%mm0, (%1)\n"
24024 - " movq %%mm1, 8(%1)\n"
24025 - " movq %%mm2, 16(%1)\n"
24026 - " movq %%mm3, 24(%1)\n"
24027 - " movq 32(%0), %%mm0\n"
24028 - " movq 40(%0), %%mm1\n"
24029 - " movq 48(%0), %%mm2\n"
24030 - " movq 56(%0), %%mm3\n"
24031 - " movq %%mm0, 32(%1)\n"
24032 - " movq %%mm1, 40(%1)\n"
24033 - " movq %%mm2, 48(%1)\n"
24034 - " movq %%mm3, 56(%1)\n"
24035 + "1: prefetch 320(%1)\n"
24036 + "2: movq (%1), %%mm0\n"
24037 + " movq 8(%1), %%mm1\n"
24038 + " movq 16(%1), %%mm2\n"
24039 + " movq 24(%1), %%mm3\n"
24040 + " movq %%mm0, (%2)\n"
24041 + " movq %%mm1, 8(%2)\n"
24042 + " movq %%mm2, 16(%2)\n"
24043 + " movq %%mm3, 24(%2)\n"
24044 + " movq 32(%1), %%mm0\n"
24045 + " movq 40(%1), %%mm1\n"
24046 + " movq 48(%1), %%mm2\n"
24047 + " movq 56(%1), %%mm3\n"
24048 + " movq %%mm0, 32(%2)\n"
24049 + " movq %%mm1, 40(%2)\n"
24050 + " movq %%mm2, 48(%2)\n"
24051 + " movq %%mm3, 56(%2)\n"
24052 ".section .fixup, \"ax\"\n"
24053 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
24054 + "3:\n"
24055 +
24056 +#ifdef CONFIG_PAX_KERNEXEC
24057 + " movl %%cr0, %0\n"
24058 + " movl %0, %%eax\n"
24059 + " andl $0xFFFEFFFF, %%eax\n"
24060 + " movl %%eax, %%cr0\n"
24061 +#endif
24062 +
24063 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
24064 +
24065 +#ifdef CONFIG_PAX_KERNEXEC
24066 + " movl %0, %%cr0\n"
24067 +#endif
24068 +
24069 " jmp 2b\n"
24070 ".previous\n"
24071 _ASM_EXTABLE(1b, 3b)
24072 - : : "r" (from), "r" (to) : "memory");
24073 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
24074
24075 from += 64;
24076 to += 64;
24077 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
24078 index f6d13ee..aca5f0b 100644
24079 --- a/arch/x86/lib/msr-reg.S
24080 +++ b/arch/x86/lib/msr-reg.S
24081 @@ -3,6 +3,7 @@
24082 #include <asm/dwarf2.h>
24083 #include <asm/asm.h>
24084 #include <asm/msr.h>
24085 +#include <asm/alternative-asm.h>
24086
24087 #ifdef CONFIG_X86_64
24088 /*
24089 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
24090 CFI_STARTPROC
24091 pushq_cfi %rbx
24092 pushq_cfi %rbp
24093 - movq %rdi, %r10 /* Save pointer */
24094 + movq %rdi, %r9 /* Save pointer */
24095 xorl %r11d, %r11d /* Return value */
24096 movl (%rdi), %eax
24097 movl 4(%rdi), %ecx
24098 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
24099 movl 28(%rdi), %edi
24100 CFI_REMEMBER_STATE
24101 1: \op
24102 -2: movl %eax, (%r10)
24103 +2: movl %eax, (%r9)
24104 movl %r11d, %eax /* Return value */
24105 - movl %ecx, 4(%r10)
24106 - movl %edx, 8(%r10)
24107 - movl %ebx, 12(%r10)
24108 - movl %ebp, 20(%r10)
24109 - movl %esi, 24(%r10)
24110 - movl %edi, 28(%r10)
24111 + movl %ecx, 4(%r9)
24112 + movl %edx, 8(%r9)
24113 + movl %ebx, 12(%r9)
24114 + movl %ebp, 20(%r9)
24115 + movl %esi, 24(%r9)
24116 + movl %edi, 28(%r9)
24117 popq_cfi %rbp
24118 popq_cfi %rbx
24119 + pax_force_retaddr
24120 ret
24121 3:
24122 CFI_RESTORE_STATE
24123 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
24124 index fc6ba17..04471c5 100644
24125 --- a/arch/x86/lib/putuser.S
24126 +++ b/arch/x86/lib/putuser.S
24127 @@ -16,7 +16,9 @@
24128 #include <asm/errno.h>
24129 #include <asm/asm.h>
24130 #include <asm/smap.h>
24131 -
24132 +#include <asm/segment.h>
24133 +#include <asm/pgtable.h>
24134 +#include <asm/alternative-asm.h>
24135
24136 /*
24137 * __put_user_X
24138 @@ -30,57 +32,125 @@
24139 * as they get called from within inline assembly.
24140 */
24141
24142 -#define ENTER CFI_STARTPROC ; \
24143 - GET_THREAD_INFO(%_ASM_BX)
24144 -#define EXIT ASM_CLAC ; \
24145 - ret ; \
24146 +#define ENTER CFI_STARTPROC
24147 +#define EXIT ASM_CLAC ; \
24148 + pax_force_retaddr ; \
24149 + ret ; \
24150 CFI_ENDPROC
24151
24152 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24153 +#define _DEST %_ASM_CX,%_ASM_BX
24154 +#else
24155 +#define _DEST %_ASM_CX
24156 +#endif
24157 +
24158 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24159 +#define __copyuser_seg gs;
24160 +#else
24161 +#define __copyuser_seg
24162 +#endif
24163 +
24164 .text
24165 ENTRY(__put_user_1)
24166 ENTER
24167 +
24168 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24169 + GET_THREAD_INFO(%_ASM_BX)
24170 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
24171 jae bad_put_user
24172 ASM_STAC
24173 -1: movb %al,(%_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 +1: __copyuser_seg movb %al,(_DEST)
24186 xor %eax,%eax
24187 EXIT
24188 ENDPROC(__put_user_1)
24189
24190 ENTRY(__put_user_2)
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 $1,%_ASM_BX
24197 cmp %_ASM_BX,%_ASM_CX
24198 jae bad_put_user
24199 ASM_STAC
24200 -2: movw %ax,(%_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 +2: __copyuser_seg movw %ax,(_DEST)
24213 xor %eax,%eax
24214 EXIT
24215 ENDPROC(__put_user_2)
24216
24217 ENTRY(__put_user_4)
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 $3,%_ASM_BX
24224 cmp %_ASM_BX,%_ASM_CX
24225 jae bad_put_user
24226 ASM_STAC
24227 -3: movl %eax,(%_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 +3: __copyuser_seg movl %eax,(_DEST)
24240 xor %eax,%eax
24241 EXIT
24242 ENDPROC(__put_user_4)
24243
24244 ENTRY(__put_user_8)
24245 ENTER
24246 +
24247 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24248 + GET_THREAD_INFO(%_ASM_BX)
24249 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24250 sub $7,%_ASM_BX
24251 cmp %_ASM_BX,%_ASM_CX
24252 jae bad_put_user
24253 ASM_STAC
24254 -4: mov %_ASM_AX,(%_ASM_CX)
24255 +
24256 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24257 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24258 + cmp %_ASM_BX,%_ASM_CX
24259 + jb 1234f
24260 + xor %ebx,%ebx
24261 +1234:
24262 +#endif
24263 +
24264 +#endif
24265 +
24266 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
24267 #ifdef CONFIG_X86_32
24268 -5: movl %edx,4(%_ASM_CX)
24269 +5: __copyuser_seg movl %edx,4(_DEST)
24270 #endif
24271 xor %eax,%eax
24272 EXIT
24273 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
24274 index 1cad221..de671ee 100644
24275 --- a/arch/x86/lib/rwlock.S
24276 +++ b/arch/x86/lib/rwlock.S
24277 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
24278 FRAME
24279 0: LOCK_PREFIX
24280 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
24281 +
24282 +#ifdef CONFIG_PAX_REFCOUNT
24283 + jno 1234f
24284 + LOCK_PREFIX
24285 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
24286 + int $4
24287 +1234:
24288 + _ASM_EXTABLE(1234b, 1234b)
24289 +#endif
24290 +
24291 1: rep; nop
24292 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
24293 jne 1b
24294 LOCK_PREFIX
24295 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
24296 +
24297 +#ifdef CONFIG_PAX_REFCOUNT
24298 + jno 1234f
24299 + LOCK_PREFIX
24300 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
24301 + int $4
24302 +1234:
24303 + _ASM_EXTABLE(1234b, 1234b)
24304 +#endif
24305 +
24306 jnz 0b
24307 ENDFRAME
24308 + pax_force_retaddr
24309 ret
24310 CFI_ENDPROC
24311 END(__write_lock_failed)
24312 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
24313 FRAME
24314 0: LOCK_PREFIX
24315 READ_LOCK_SIZE(inc) (%__lock_ptr)
24316 +
24317 +#ifdef CONFIG_PAX_REFCOUNT
24318 + jno 1234f
24319 + LOCK_PREFIX
24320 + READ_LOCK_SIZE(dec) (%__lock_ptr)
24321 + int $4
24322 +1234:
24323 + _ASM_EXTABLE(1234b, 1234b)
24324 +#endif
24325 +
24326 1: rep; nop
24327 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
24328 js 1b
24329 LOCK_PREFIX
24330 READ_LOCK_SIZE(dec) (%__lock_ptr)
24331 +
24332 +#ifdef CONFIG_PAX_REFCOUNT
24333 + jno 1234f
24334 + LOCK_PREFIX
24335 + READ_LOCK_SIZE(inc) (%__lock_ptr)
24336 + int $4
24337 +1234:
24338 + _ASM_EXTABLE(1234b, 1234b)
24339 +#endif
24340 +
24341 js 0b
24342 ENDFRAME
24343 + pax_force_retaddr
24344 ret
24345 CFI_ENDPROC
24346 END(__read_lock_failed)
24347 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
24348 index 5dff5f0..cadebf4 100644
24349 --- a/arch/x86/lib/rwsem.S
24350 +++ b/arch/x86/lib/rwsem.S
24351 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
24352 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24353 CFI_RESTORE __ASM_REG(dx)
24354 restore_common_regs
24355 + pax_force_retaddr
24356 ret
24357 CFI_ENDPROC
24358 ENDPROC(call_rwsem_down_read_failed)
24359 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
24360 movq %rax,%rdi
24361 call rwsem_down_write_failed
24362 restore_common_regs
24363 + pax_force_retaddr
24364 ret
24365 CFI_ENDPROC
24366 ENDPROC(call_rwsem_down_write_failed)
24367 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
24368 movq %rax,%rdi
24369 call rwsem_wake
24370 restore_common_regs
24371 -1: ret
24372 +1: pax_force_retaddr
24373 + ret
24374 CFI_ENDPROC
24375 ENDPROC(call_rwsem_wake)
24376
24377 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
24378 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24379 CFI_RESTORE __ASM_REG(dx)
24380 restore_common_regs
24381 + pax_force_retaddr
24382 ret
24383 CFI_ENDPROC
24384 ENDPROC(call_rwsem_downgrade_wake)
24385 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
24386 index a63efd6..ccecad8 100644
24387 --- a/arch/x86/lib/thunk_64.S
24388 +++ b/arch/x86/lib/thunk_64.S
24389 @@ -8,6 +8,7 @@
24390 #include <linux/linkage.h>
24391 #include <asm/dwarf2.h>
24392 #include <asm/calling.h>
24393 +#include <asm/alternative-asm.h>
24394
24395 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
24396 .macro THUNK name, func, put_ret_addr_in_rdi=0
24397 @@ -41,5 +42,6 @@
24398 SAVE_ARGS
24399 restore:
24400 RESTORE_ARGS
24401 + pax_force_retaddr
24402 ret
24403 CFI_ENDPROC
24404 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
24405 index 98f6d6b6..d27f045 100644
24406 --- a/arch/x86/lib/usercopy_32.c
24407 +++ b/arch/x86/lib/usercopy_32.c
24408 @@ -42,11 +42,13 @@ do { \
24409 int __d0; \
24410 might_fault(); \
24411 __asm__ __volatile__( \
24412 + __COPYUSER_SET_ES \
24413 ASM_STAC "\n" \
24414 "0: rep; stosl\n" \
24415 " movl %2,%0\n" \
24416 "1: rep; stosb\n" \
24417 "2: " ASM_CLAC "\n" \
24418 + __COPYUSER_RESTORE_ES \
24419 ".section .fixup,\"ax\"\n" \
24420 "3: lea 0(%2,%0,4),%0\n" \
24421 " jmp 2b\n" \
24422 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
24423
24424 #ifdef CONFIG_X86_INTEL_USERCOPY
24425 static unsigned long
24426 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
24427 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
24428 {
24429 int d0, d1;
24430 __asm__ __volatile__(
24431 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24432 " .align 2,0x90\n"
24433 "3: movl 0(%4), %%eax\n"
24434 "4: movl 4(%4), %%edx\n"
24435 - "5: movl %%eax, 0(%3)\n"
24436 - "6: movl %%edx, 4(%3)\n"
24437 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
24438 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
24439 "7: movl 8(%4), %%eax\n"
24440 "8: movl 12(%4),%%edx\n"
24441 - "9: movl %%eax, 8(%3)\n"
24442 - "10: movl %%edx, 12(%3)\n"
24443 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
24444 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
24445 "11: movl 16(%4), %%eax\n"
24446 "12: movl 20(%4), %%edx\n"
24447 - "13: movl %%eax, 16(%3)\n"
24448 - "14: movl %%edx, 20(%3)\n"
24449 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
24450 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
24451 "15: movl 24(%4), %%eax\n"
24452 "16: movl 28(%4), %%edx\n"
24453 - "17: movl %%eax, 24(%3)\n"
24454 - "18: movl %%edx, 28(%3)\n"
24455 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
24456 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
24457 "19: movl 32(%4), %%eax\n"
24458 "20: movl 36(%4), %%edx\n"
24459 - "21: movl %%eax, 32(%3)\n"
24460 - "22: movl %%edx, 36(%3)\n"
24461 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
24462 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
24463 "23: movl 40(%4), %%eax\n"
24464 "24: movl 44(%4), %%edx\n"
24465 - "25: movl %%eax, 40(%3)\n"
24466 - "26: movl %%edx, 44(%3)\n"
24467 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
24468 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
24469 "27: movl 48(%4), %%eax\n"
24470 "28: movl 52(%4), %%edx\n"
24471 - "29: movl %%eax, 48(%3)\n"
24472 - "30: movl %%edx, 52(%3)\n"
24473 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
24474 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
24475 "31: movl 56(%4), %%eax\n"
24476 "32: movl 60(%4), %%edx\n"
24477 - "33: movl %%eax, 56(%3)\n"
24478 - "34: movl %%edx, 60(%3)\n"
24479 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
24480 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
24481 " addl $-64, %0\n"
24482 " addl $64, %4\n"
24483 " addl $64, %3\n"
24484 @@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24485 " shrl $2, %0\n"
24486 " andl $3, %%eax\n"
24487 " cld\n"
24488 + __COPYUSER_SET_ES
24489 "99: rep; movsl\n"
24490 "36: movl %%eax, %0\n"
24491 "37: rep; movsb\n"
24492 "100:\n"
24493 + __COPYUSER_RESTORE_ES
24494 ".section .fixup,\"ax\"\n"
24495 "101: lea 0(%%eax,%0,4),%0\n"
24496 " jmp 100b\n"
24497 @@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24498 }
24499
24500 static unsigned long
24501 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
24502 +{
24503 + int d0, d1;
24504 + __asm__ __volatile__(
24505 + " .align 2,0x90\n"
24506 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
24507 + " cmpl $67, %0\n"
24508 + " jbe 3f\n"
24509 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
24510 + " .align 2,0x90\n"
24511 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
24512 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
24513 + "5: movl %%eax, 0(%3)\n"
24514 + "6: movl %%edx, 4(%3)\n"
24515 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
24516 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
24517 + "9: movl %%eax, 8(%3)\n"
24518 + "10: movl %%edx, 12(%3)\n"
24519 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
24520 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
24521 + "13: movl %%eax, 16(%3)\n"
24522 + "14: movl %%edx, 20(%3)\n"
24523 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
24524 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
24525 + "17: movl %%eax, 24(%3)\n"
24526 + "18: movl %%edx, 28(%3)\n"
24527 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
24528 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
24529 + "21: movl %%eax, 32(%3)\n"
24530 + "22: movl %%edx, 36(%3)\n"
24531 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
24532 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
24533 + "25: movl %%eax, 40(%3)\n"
24534 + "26: movl %%edx, 44(%3)\n"
24535 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
24536 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
24537 + "29: movl %%eax, 48(%3)\n"
24538 + "30: movl %%edx, 52(%3)\n"
24539 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
24540 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
24541 + "33: movl %%eax, 56(%3)\n"
24542 + "34: movl %%edx, 60(%3)\n"
24543 + " addl $-64, %0\n"
24544 + " addl $64, %4\n"
24545 + " addl $64, %3\n"
24546 + " cmpl $63, %0\n"
24547 + " ja 1b\n"
24548 + "35: movl %0, %%eax\n"
24549 + " shrl $2, %0\n"
24550 + " andl $3, %%eax\n"
24551 + " cld\n"
24552 + "99: rep; "__copyuser_seg" movsl\n"
24553 + "36: movl %%eax, %0\n"
24554 + "37: rep; "__copyuser_seg" movsb\n"
24555 + "100:\n"
24556 + ".section .fixup,\"ax\"\n"
24557 + "101: lea 0(%%eax,%0,4),%0\n"
24558 + " jmp 100b\n"
24559 + ".previous\n"
24560 + _ASM_EXTABLE(1b,100b)
24561 + _ASM_EXTABLE(2b,100b)
24562 + _ASM_EXTABLE(3b,100b)
24563 + _ASM_EXTABLE(4b,100b)
24564 + _ASM_EXTABLE(5b,100b)
24565 + _ASM_EXTABLE(6b,100b)
24566 + _ASM_EXTABLE(7b,100b)
24567 + _ASM_EXTABLE(8b,100b)
24568 + _ASM_EXTABLE(9b,100b)
24569 + _ASM_EXTABLE(10b,100b)
24570 + _ASM_EXTABLE(11b,100b)
24571 + _ASM_EXTABLE(12b,100b)
24572 + _ASM_EXTABLE(13b,100b)
24573 + _ASM_EXTABLE(14b,100b)
24574 + _ASM_EXTABLE(15b,100b)
24575 + _ASM_EXTABLE(16b,100b)
24576 + _ASM_EXTABLE(17b,100b)
24577 + _ASM_EXTABLE(18b,100b)
24578 + _ASM_EXTABLE(19b,100b)
24579 + _ASM_EXTABLE(20b,100b)
24580 + _ASM_EXTABLE(21b,100b)
24581 + _ASM_EXTABLE(22b,100b)
24582 + _ASM_EXTABLE(23b,100b)
24583 + _ASM_EXTABLE(24b,100b)
24584 + _ASM_EXTABLE(25b,100b)
24585 + _ASM_EXTABLE(26b,100b)
24586 + _ASM_EXTABLE(27b,100b)
24587 + _ASM_EXTABLE(28b,100b)
24588 + _ASM_EXTABLE(29b,100b)
24589 + _ASM_EXTABLE(30b,100b)
24590 + _ASM_EXTABLE(31b,100b)
24591 + _ASM_EXTABLE(32b,100b)
24592 + _ASM_EXTABLE(33b,100b)
24593 + _ASM_EXTABLE(34b,100b)
24594 + _ASM_EXTABLE(35b,100b)
24595 + _ASM_EXTABLE(36b,100b)
24596 + _ASM_EXTABLE(37b,100b)
24597 + _ASM_EXTABLE(99b,101b)
24598 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
24599 + : "1"(to), "2"(from), "0"(size)
24600 + : "eax", "edx", "memory");
24601 + return size;
24602 +}
24603 +
24604 +static unsigned long __size_overflow(3)
24605 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24606 {
24607 int d0, d1;
24608 __asm__ __volatile__(
24609 " .align 2,0x90\n"
24610 - "0: movl 32(%4), %%eax\n"
24611 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24612 " cmpl $67, %0\n"
24613 " jbe 2f\n"
24614 - "1: movl 64(%4), %%eax\n"
24615 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24616 " .align 2,0x90\n"
24617 - "2: movl 0(%4), %%eax\n"
24618 - "21: movl 4(%4), %%edx\n"
24619 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24620 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24621 " movl %%eax, 0(%3)\n"
24622 " movl %%edx, 4(%3)\n"
24623 - "3: movl 8(%4), %%eax\n"
24624 - "31: movl 12(%4),%%edx\n"
24625 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24626 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24627 " movl %%eax, 8(%3)\n"
24628 " movl %%edx, 12(%3)\n"
24629 - "4: movl 16(%4), %%eax\n"
24630 - "41: movl 20(%4), %%edx\n"
24631 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24632 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24633 " movl %%eax, 16(%3)\n"
24634 " movl %%edx, 20(%3)\n"
24635 - "10: movl 24(%4), %%eax\n"
24636 - "51: movl 28(%4), %%edx\n"
24637 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24638 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24639 " movl %%eax, 24(%3)\n"
24640 " movl %%edx, 28(%3)\n"
24641 - "11: movl 32(%4), %%eax\n"
24642 - "61: movl 36(%4), %%edx\n"
24643 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24644 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24645 " movl %%eax, 32(%3)\n"
24646 " movl %%edx, 36(%3)\n"
24647 - "12: movl 40(%4), %%eax\n"
24648 - "71: movl 44(%4), %%edx\n"
24649 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24650 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24651 " movl %%eax, 40(%3)\n"
24652 " movl %%edx, 44(%3)\n"
24653 - "13: movl 48(%4), %%eax\n"
24654 - "81: movl 52(%4), %%edx\n"
24655 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24656 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24657 " movl %%eax, 48(%3)\n"
24658 " movl %%edx, 52(%3)\n"
24659 - "14: movl 56(%4), %%eax\n"
24660 - "91: movl 60(%4), %%edx\n"
24661 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24662 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24663 " movl %%eax, 56(%3)\n"
24664 " movl %%edx, 60(%3)\n"
24665 " addl $-64, %0\n"
24666 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24667 " shrl $2, %0\n"
24668 " andl $3, %%eax\n"
24669 " cld\n"
24670 - "6: rep; movsl\n"
24671 + "6: rep; "__copyuser_seg" movsl\n"
24672 " movl %%eax,%0\n"
24673 - "7: rep; movsb\n"
24674 + "7: rep; "__copyuser_seg" movsb\n"
24675 "8:\n"
24676 ".section .fixup,\"ax\"\n"
24677 "9: lea 0(%%eax,%0,4),%0\n"
24678 @@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24679 * hyoshiok@miraclelinux.com
24680 */
24681
24682 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24683 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
24684 const void __user *from, unsigned long size)
24685 {
24686 int d0, d1;
24687
24688 __asm__ __volatile__(
24689 " .align 2,0x90\n"
24690 - "0: movl 32(%4), %%eax\n"
24691 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24692 " cmpl $67, %0\n"
24693 " jbe 2f\n"
24694 - "1: movl 64(%4), %%eax\n"
24695 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24696 " .align 2,0x90\n"
24697 - "2: movl 0(%4), %%eax\n"
24698 - "21: movl 4(%4), %%edx\n"
24699 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24700 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24701 " movnti %%eax, 0(%3)\n"
24702 " movnti %%edx, 4(%3)\n"
24703 - "3: movl 8(%4), %%eax\n"
24704 - "31: movl 12(%4),%%edx\n"
24705 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24706 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24707 " movnti %%eax, 8(%3)\n"
24708 " movnti %%edx, 12(%3)\n"
24709 - "4: movl 16(%4), %%eax\n"
24710 - "41: movl 20(%4), %%edx\n"
24711 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24712 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24713 " movnti %%eax, 16(%3)\n"
24714 " movnti %%edx, 20(%3)\n"
24715 - "10: movl 24(%4), %%eax\n"
24716 - "51: movl 28(%4), %%edx\n"
24717 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24718 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24719 " movnti %%eax, 24(%3)\n"
24720 " movnti %%edx, 28(%3)\n"
24721 - "11: movl 32(%4), %%eax\n"
24722 - "61: movl 36(%4), %%edx\n"
24723 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24724 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24725 " movnti %%eax, 32(%3)\n"
24726 " movnti %%edx, 36(%3)\n"
24727 - "12: movl 40(%4), %%eax\n"
24728 - "71: movl 44(%4), %%edx\n"
24729 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24730 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24731 " movnti %%eax, 40(%3)\n"
24732 " movnti %%edx, 44(%3)\n"
24733 - "13: movl 48(%4), %%eax\n"
24734 - "81: movl 52(%4), %%edx\n"
24735 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24736 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24737 " movnti %%eax, 48(%3)\n"
24738 " movnti %%edx, 52(%3)\n"
24739 - "14: movl 56(%4), %%eax\n"
24740 - "91: movl 60(%4), %%edx\n"
24741 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24742 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24743 " movnti %%eax, 56(%3)\n"
24744 " movnti %%edx, 60(%3)\n"
24745 " addl $-64, %0\n"
24746 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24747 " shrl $2, %0\n"
24748 " andl $3, %%eax\n"
24749 " cld\n"
24750 - "6: rep; movsl\n"
24751 + "6: rep; "__copyuser_seg" movsl\n"
24752 " movl %%eax,%0\n"
24753 - "7: rep; movsb\n"
24754 + "7: rep; "__copyuser_seg" movsb\n"
24755 "8:\n"
24756 ".section .fixup,\"ax\"\n"
24757 "9: lea 0(%%eax,%0,4),%0\n"
24758 @@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24759 return size;
24760 }
24761
24762 -static unsigned long __copy_user_intel_nocache(void *to,
24763 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
24764 const void __user *from, unsigned long size)
24765 {
24766 int d0, d1;
24767
24768 __asm__ __volatile__(
24769 " .align 2,0x90\n"
24770 - "0: movl 32(%4), %%eax\n"
24771 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24772 " cmpl $67, %0\n"
24773 " jbe 2f\n"
24774 - "1: movl 64(%4), %%eax\n"
24775 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24776 " .align 2,0x90\n"
24777 - "2: movl 0(%4), %%eax\n"
24778 - "21: movl 4(%4), %%edx\n"
24779 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24780 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24781 " movnti %%eax, 0(%3)\n"
24782 " movnti %%edx, 4(%3)\n"
24783 - "3: movl 8(%4), %%eax\n"
24784 - "31: movl 12(%4),%%edx\n"
24785 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24786 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24787 " movnti %%eax, 8(%3)\n"
24788 " movnti %%edx, 12(%3)\n"
24789 - "4: movl 16(%4), %%eax\n"
24790 - "41: movl 20(%4), %%edx\n"
24791 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24792 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24793 " movnti %%eax, 16(%3)\n"
24794 " movnti %%edx, 20(%3)\n"
24795 - "10: movl 24(%4), %%eax\n"
24796 - "51: movl 28(%4), %%edx\n"
24797 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24798 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24799 " movnti %%eax, 24(%3)\n"
24800 " movnti %%edx, 28(%3)\n"
24801 - "11: movl 32(%4), %%eax\n"
24802 - "61: movl 36(%4), %%edx\n"
24803 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24804 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24805 " movnti %%eax, 32(%3)\n"
24806 " movnti %%edx, 36(%3)\n"
24807 - "12: movl 40(%4), %%eax\n"
24808 - "71: movl 44(%4), %%edx\n"
24809 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24810 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24811 " movnti %%eax, 40(%3)\n"
24812 " movnti %%edx, 44(%3)\n"
24813 - "13: movl 48(%4), %%eax\n"
24814 - "81: movl 52(%4), %%edx\n"
24815 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24816 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24817 " movnti %%eax, 48(%3)\n"
24818 " movnti %%edx, 52(%3)\n"
24819 - "14: movl 56(%4), %%eax\n"
24820 - "91: movl 60(%4), %%edx\n"
24821 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24822 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24823 " movnti %%eax, 56(%3)\n"
24824 " movnti %%edx, 60(%3)\n"
24825 " addl $-64, %0\n"
24826 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
24827 " shrl $2, %0\n"
24828 " andl $3, %%eax\n"
24829 " cld\n"
24830 - "6: rep; movsl\n"
24831 + "6: rep; "__copyuser_seg" movsl\n"
24832 " movl %%eax,%0\n"
24833 - "7: rep; movsb\n"
24834 + "7: rep; "__copyuser_seg" movsb\n"
24835 "8:\n"
24836 ".section .fixup,\"ax\"\n"
24837 "9: lea 0(%%eax,%0,4),%0\n"
24838 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
24839 */
24840 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
24841 unsigned long size);
24842 -unsigned long __copy_user_intel(void __user *to, const void *from,
24843 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
24844 + unsigned long size);
24845 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
24846 unsigned long size);
24847 unsigned long __copy_user_zeroing_intel_nocache(void *to,
24848 const void __user *from, unsigned long size);
24849 #endif /* CONFIG_X86_INTEL_USERCOPY */
24850
24851 /* Generic arbitrary sized copy. */
24852 -#define __copy_user(to, from, size) \
24853 +#define __copy_user(to, from, size, prefix, set, restore) \
24854 do { \
24855 int __d0, __d1, __d2; \
24856 __asm__ __volatile__( \
24857 + set \
24858 " cmp $7,%0\n" \
24859 " jbe 1f\n" \
24860 " movl %1,%0\n" \
24861 " negl %0\n" \
24862 " andl $7,%0\n" \
24863 " subl %0,%3\n" \
24864 - "4: rep; movsb\n" \
24865 + "4: rep; "prefix"movsb\n" \
24866 " movl %3,%0\n" \
24867 " shrl $2,%0\n" \
24868 " andl $3,%3\n" \
24869 " .align 2,0x90\n" \
24870 - "0: rep; movsl\n" \
24871 + "0: rep; "prefix"movsl\n" \
24872 " movl %3,%0\n" \
24873 - "1: rep; movsb\n" \
24874 + "1: rep; "prefix"movsb\n" \
24875 "2:\n" \
24876 + restore \
24877 ".section .fixup,\"ax\"\n" \
24878 "5: addl %3,%0\n" \
24879 " jmp 2b\n" \
24880 @@ -538,14 +650,14 @@ do { \
24881 " negl %0\n" \
24882 " andl $7,%0\n" \
24883 " subl %0,%3\n" \
24884 - "4: rep; movsb\n" \
24885 + "4: rep; "__copyuser_seg"movsb\n" \
24886 " movl %3,%0\n" \
24887 " shrl $2,%0\n" \
24888 " andl $3,%3\n" \
24889 " .align 2,0x90\n" \
24890 - "0: rep; movsl\n" \
24891 + "0: rep; "__copyuser_seg"movsl\n" \
24892 " movl %3,%0\n" \
24893 - "1: rep; movsb\n" \
24894 + "1: rep; "__copyuser_seg"movsb\n" \
24895 "2:\n" \
24896 ".section .fixup,\"ax\"\n" \
24897 "5: addl %3,%0\n" \
24898 @@ -629,9 +741,9 @@ survive:
24899 #endif
24900 stac();
24901 if (movsl_is_ok(to, from, n))
24902 - __copy_user(to, from, n);
24903 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
24904 else
24905 - n = __copy_user_intel(to, from, n);
24906 + n = __generic_copy_to_user_intel(to, from, n);
24907 clac();
24908 return n;
24909 }
24910 @@ -655,10 +767,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
24911 {
24912 stac();
24913 if (movsl_is_ok(to, from, n))
24914 - __copy_user(to, from, n);
24915 + __copy_user(to, from, n, __copyuser_seg, "", "");
24916 else
24917 - n = __copy_user_intel((void __user *)to,
24918 - (const void *)from, n);
24919 + n = __generic_copy_from_user_intel(to, from, n);
24920 clac();
24921 return n;
24922 }
24923 @@ -689,66 +800,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
24924 if (n > 64 && cpu_has_xmm2)
24925 n = __copy_user_intel_nocache(to, from, n);
24926 else
24927 - __copy_user(to, from, n);
24928 + __copy_user(to, from, n, __copyuser_seg, "", "");
24929 #else
24930 - __copy_user(to, from, n);
24931 + __copy_user(to, from, n, __copyuser_seg, "", "");
24932 #endif
24933 clac();
24934 return n;
24935 }
24936 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
24937
24938 -/**
24939 - * copy_to_user: - Copy a block of data into user space.
24940 - * @to: Destination address, in user space.
24941 - * @from: Source address, in kernel space.
24942 - * @n: Number of bytes to copy.
24943 - *
24944 - * Context: User context only. This function may sleep.
24945 - *
24946 - * Copy data from kernel space to user space.
24947 - *
24948 - * Returns number of bytes that could not be copied.
24949 - * On success, this will be zero.
24950 - */
24951 -unsigned long
24952 -copy_to_user(void __user *to, const void *from, unsigned long n)
24953 -{
24954 - if (access_ok(VERIFY_WRITE, to, n))
24955 - n = __copy_to_user(to, from, n);
24956 - return n;
24957 -}
24958 -EXPORT_SYMBOL(copy_to_user);
24959 -
24960 -/**
24961 - * copy_from_user: - Copy a block of data from user space.
24962 - * @to: Destination address, in kernel space.
24963 - * @from: Source address, in user space.
24964 - * @n: Number of bytes to copy.
24965 - *
24966 - * Context: User context only. This function may sleep.
24967 - *
24968 - * Copy data from user space to kernel space.
24969 - *
24970 - * Returns number of bytes that could not be copied.
24971 - * On success, this will be zero.
24972 - *
24973 - * If some data could not be copied, this function will pad the copied
24974 - * data to the requested size using zero bytes.
24975 - */
24976 -unsigned long
24977 -_copy_from_user(void *to, const void __user *from, unsigned long n)
24978 -{
24979 - if (access_ok(VERIFY_READ, from, n))
24980 - n = __copy_from_user(to, from, n);
24981 - else
24982 - memset(to, 0, n);
24983 - return n;
24984 -}
24985 -EXPORT_SYMBOL(_copy_from_user);
24986 -
24987 void copy_from_user_overflow(void)
24988 {
24989 WARN(1, "Buffer overflow detected!\n");
24990 }
24991 EXPORT_SYMBOL(copy_from_user_overflow);
24992 +
24993 +void copy_to_user_overflow(void)
24994 +{
24995 + WARN(1, "Buffer overflow detected!\n");
24996 +}
24997 +EXPORT_SYMBOL(copy_to_user_overflow);
24998 +
24999 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25000 +void __set_fs(mm_segment_t x)
25001 +{
25002 + switch (x.seg) {
25003 + case 0:
25004 + loadsegment(gs, 0);
25005 + break;
25006 + case TASK_SIZE_MAX:
25007 + loadsegment(gs, __USER_DS);
25008 + break;
25009 + case -1UL:
25010 + loadsegment(gs, __KERNEL_DS);
25011 + break;
25012 + default:
25013 + BUG();
25014 + }
25015 + return;
25016 +}
25017 +EXPORT_SYMBOL(__set_fs);
25018 +
25019 +void set_fs(mm_segment_t x)
25020 +{
25021 + current_thread_info()->addr_limit = x;
25022 + __set_fs(x);
25023 +}
25024 +EXPORT_SYMBOL(set_fs);
25025 +#endif
25026 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
25027 index 05928aa..b33dea1 100644
25028 --- a/arch/x86/lib/usercopy_64.c
25029 +++ b/arch/x86/lib/usercopy_64.c
25030 @@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
25031 _ASM_EXTABLE(0b,3b)
25032 _ASM_EXTABLE(1b,2b)
25033 : [size8] "=&c"(size), [dst] "=&D" (__d0)
25034 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
25035 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
25036 [zero] "r" (0UL), [eight] "r" (8UL));
25037 clac();
25038 return size;
25039 @@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
25040 }
25041 EXPORT_SYMBOL(clear_user);
25042
25043 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
25044 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
25045 {
25046 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
25047 - return copy_user_generic((__force void *)to, (__force void *)from, len);
25048 - }
25049 - return len;
25050 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
25051 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
25052 + return len;
25053 }
25054 EXPORT_SYMBOL(copy_in_user);
25055
25056 @@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
25057 * it is not necessary to optimize tail handling.
25058 */
25059 unsigned long
25060 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
25061 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
25062 {
25063 char c;
25064 unsigned zero_len;
25065 @@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
25066 clac();
25067 return len;
25068 }
25069 +
25070 +void copy_from_user_overflow(void)
25071 +{
25072 + WARN(1, "Buffer overflow detected!\n");
25073 +}
25074 +EXPORT_SYMBOL(copy_from_user_overflow);
25075 +
25076 +void copy_to_user_overflow(void)
25077 +{
25078 + WARN(1, "Buffer overflow detected!\n");
25079 +}
25080 +EXPORT_SYMBOL(copy_to_user_overflow);
25081 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
25082 index 903ec1e..c4166b2 100644
25083 --- a/arch/x86/mm/extable.c
25084 +++ b/arch/x86/mm/extable.c
25085 @@ -6,12 +6,24 @@
25086 static inline unsigned long
25087 ex_insn_addr(const struct exception_table_entry *x)
25088 {
25089 - return (unsigned long)&x->insn + x->insn;
25090 + unsigned long reloc = 0;
25091 +
25092 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25093 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25094 +#endif
25095 +
25096 + return (unsigned long)&x->insn + x->insn + reloc;
25097 }
25098 static inline unsigned long
25099 ex_fixup_addr(const struct exception_table_entry *x)
25100 {
25101 - return (unsigned long)&x->fixup + x->fixup;
25102 + unsigned long reloc = 0;
25103 +
25104 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25105 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25106 +#endif
25107 +
25108 + return (unsigned long)&x->fixup + x->fixup + reloc;
25109 }
25110
25111 int fixup_exception(struct pt_regs *regs)
25112 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
25113 unsigned long new_ip;
25114
25115 #ifdef CONFIG_PNPBIOS
25116 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
25117 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
25118 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
25119 extern u32 pnp_bios_is_utter_crap;
25120 pnp_bios_is_utter_crap = 1;
25121 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
25122 i += 4;
25123 p->fixup -= i;
25124 i += 4;
25125 +
25126 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25127 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
25128 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25129 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25130 +#endif
25131 +
25132 }
25133 }
25134
25135 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
25136 index 8e13ecb..60bf506 100644
25137 --- a/arch/x86/mm/fault.c
25138 +++ b/arch/x86/mm/fault.c
25139 @@ -13,12 +13,19 @@
25140 #include <linux/perf_event.h> /* perf_sw_event */
25141 #include <linux/hugetlb.h> /* hstate_index_to_shift */
25142 #include <linux/prefetch.h> /* prefetchw */
25143 +#include <linux/unistd.h>
25144 +#include <linux/compiler.h>
25145
25146 #include <asm/traps.h> /* dotraplinkage, ... */
25147 #include <asm/pgalloc.h> /* pgd_*(), ... */
25148 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
25149 #include <asm/fixmap.h> /* VSYSCALL_START */
25150 #include <asm/rcu.h> /* exception_enter(), ... */
25151 +#include <asm/tlbflush.h>
25152 +
25153 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25154 +#include <asm/stacktrace.h>
25155 +#endif
25156
25157 /*
25158 * Page fault error code bits:
25159 @@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
25160 int ret = 0;
25161
25162 /* kprobe_running() needs smp_processor_id() */
25163 - if (kprobes_built_in() && !user_mode_vm(regs)) {
25164 + if (kprobes_built_in() && !user_mode(regs)) {
25165 preempt_disable();
25166 if (kprobe_running() && kprobe_fault_handler(regs, 14))
25167 ret = 1;
25168 @@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
25169 return !instr_lo || (instr_lo>>1) == 1;
25170 case 0x00:
25171 /* Prefetch instruction is 0x0F0D or 0x0F18 */
25172 - if (probe_kernel_address(instr, opcode))
25173 + if (user_mode(regs)) {
25174 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
25175 + return 0;
25176 + } else if (probe_kernel_address(instr, opcode))
25177 return 0;
25178
25179 *prefetch = (instr_lo == 0xF) &&
25180 @@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
25181 while (instr < max_instr) {
25182 unsigned char opcode;
25183
25184 - if (probe_kernel_address(instr, opcode))
25185 + if (user_mode(regs)) {
25186 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
25187 + break;
25188 + } else if (probe_kernel_address(instr, opcode))
25189 break;
25190
25191 instr++;
25192 @@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
25193 force_sig_info(si_signo, &info, tsk);
25194 }
25195
25196 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25197 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
25198 +#endif
25199 +
25200 +#ifdef CONFIG_PAX_EMUTRAMP
25201 +static int pax_handle_fetch_fault(struct pt_regs *regs);
25202 +#endif
25203 +
25204 +#ifdef CONFIG_PAX_PAGEEXEC
25205 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
25206 +{
25207 + pgd_t *pgd;
25208 + pud_t *pud;
25209 + pmd_t *pmd;
25210 +
25211 + pgd = pgd_offset(mm, address);
25212 + if (!pgd_present(*pgd))
25213 + return NULL;
25214 + pud = pud_offset(pgd, address);
25215 + if (!pud_present(*pud))
25216 + return NULL;
25217 + pmd = pmd_offset(pud, address);
25218 + if (!pmd_present(*pmd))
25219 + return NULL;
25220 + return pmd;
25221 +}
25222 +#endif
25223 +
25224 DEFINE_SPINLOCK(pgd_lock);
25225 LIST_HEAD(pgd_list);
25226
25227 @@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
25228 for (address = VMALLOC_START & PMD_MASK;
25229 address >= TASK_SIZE && address < FIXADDR_TOP;
25230 address += PMD_SIZE) {
25231 +
25232 +#ifdef CONFIG_PAX_PER_CPU_PGD
25233 + unsigned long cpu;
25234 +#else
25235 struct page *page;
25236 +#endif
25237
25238 spin_lock(&pgd_lock);
25239 +
25240 +#ifdef CONFIG_PAX_PER_CPU_PGD
25241 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25242 + pgd_t *pgd = get_cpu_pgd(cpu);
25243 + pmd_t *ret;
25244 +#else
25245 list_for_each_entry(page, &pgd_list, lru) {
25246 + pgd_t *pgd = page_address(page);
25247 spinlock_t *pgt_lock;
25248 pmd_t *ret;
25249
25250 @@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
25251 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25252
25253 spin_lock(pgt_lock);
25254 - ret = vmalloc_sync_one(page_address(page), address);
25255 +#endif
25256 +
25257 + ret = vmalloc_sync_one(pgd, address);
25258 +
25259 +#ifndef CONFIG_PAX_PER_CPU_PGD
25260 spin_unlock(pgt_lock);
25261 +#endif
25262
25263 if (!ret)
25264 break;
25265 @@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
25266 * an interrupt in the middle of a task switch..
25267 */
25268 pgd_paddr = read_cr3();
25269 +
25270 +#ifdef CONFIG_PAX_PER_CPU_PGD
25271 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
25272 +#endif
25273 +
25274 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
25275 if (!pmd_k)
25276 return -1;
25277 @@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
25278 * happen within a race in page table update. In the later
25279 * case just flush:
25280 */
25281 +
25282 +#ifdef CONFIG_PAX_PER_CPU_PGD
25283 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
25284 + pgd = pgd_offset_cpu(smp_processor_id(), address);
25285 +#else
25286 pgd = pgd_offset(current->active_mm, address);
25287 +#endif
25288 +
25289 pgd_ref = pgd_offset_k(address);
25290 if (pgd_none(*pgd_ref))
25291 return -1;
25292 @@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
25293 static int is_errata100(struct pt_regs *regs, unsigned long address)
25294 {
25295 #ifdef CONFIG_X86_64
25296 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
25297 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
25298 return 1;
25299 #endif
25300 return 0;
25301 @@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
25302 }
25303
25304 static const char nx_warning[] = KERN_CRIT
25305 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
25306 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
25307
25308 static void
25309 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
25310 @@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
25311 if (!oops_may_print())
25312 return;
25313
25314 - if (error_code & PF_INSTR) {
25315 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
25316 unsigned int level;
25317
25318 pte_t *pte = lookup_address(address, &level);
25319
25320 if (pte && pte_present(*pte) && !pte_exec(*pte))
25321 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
25322 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
25323 }
25324
25325 +#ifdef CONFIG_PAX_KERNEXEC
25326 + if (init_mm.start_code <= address && address < init_mm.end_code) {
25327 + if (current->signal->curr_ip)
25328 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
25329 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
25330 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
25331 + else
25332 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
25333 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
25334 + }
25335 +#endif
25336 +
25337 printk(KERN_ALERT "BUG: unable to handle kernel ");
25338 if (address < PAGE_SIZE)
25339 printk(KERN_CONT "NULL pointer dereference");
25340 @@ -749,12 +831,30 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
25341 }
25342 #endif
25343
25344 - if (unlikely(show_unhandled_signals))
25345 - show_signal_msg(regs, error_code, address, tsk);
25346 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25347 + if (pax_is_fetch_fault(regs, error_code, address)) {
25348 +
25349 +#ifdef CONFIG_PAX_EMUTRAMP
25350 + switch (pax_handle_fetch_fault(regs)) {
25351 + case 2:
25352 + return;
25353 + }
25354 +#endif
25355 +
25356 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25357 + do_group_exit(SIGKILL);
25358 + }
25359 +#endif
25360
25361 /* Kernel addresses are always protection faults: */
25362 + if (address >= TASK_SIZE)
25363 + error_code |= PF_PROT;
25364 +
25365 + if (show_unhandled_signals)
25366 + show_signal_msg(regs, error_code, address, tsk);
25367 +
25368 tsk->thread.cr2 = address;
25369 - tsk->thread.error_code = error_code | (address >= TASK_SIZE);
25370 + tsk->thread.error_code = error_code;
25371 tsk->thread.trap_nr = X86_TRAP_PF;
25372
25373 force_sig_info_fault(SIGSEGV, si_code, address, tsk, 0);
25374 @@ -845,7 +945,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
25375 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
25376 printk(KERN_ERR
25377 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
25378 - tsk->comm, tsk->pid, address);
25379 + tsk->comm, task_pid_nr(tsk), address);
25380 code = BUS_MCEERR_AR;
25381 }
25382 #endif
25383 @@ -901,6 +1001,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
25384 return 1;
25385 }
25386
25387 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25388 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
25389 +{
25390 + pte_t *pte;
25391 + pmd_t *pmd;
25392 + spinlock_t *ptl;
25393 + unsigned char pte_mask;
25394 +
25395 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
25396 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
25397 + return 0;
25398 +
25399 + /* PaX: it's our fault, let's handle it if we can */
25400 +
25401 + /* PaX: take a look at read faults before acquiring any locks */
25402 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
25403 + /* instruction fetch attempt from a protected page in user mode */
25404 + up_read(&mm->mmap_sem);
25405 +
25406 +#ifdef CONFIG_PAX_EMUTRAMP
25407 + switch (pax_handle_fetch_fault(regs)) {
25408 + case 2:
25409 + return 1;
25410 + }
25411 +#endif
25412 +
25413 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25414 + do_group_exit(SIGKILL);
25415 + }
25416 +
25417 + pmd = pax_get_pmd(mm, address);
25418 + if (unlikely(!pmd))
25419 + return 0;
25420 +
25421 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
25422 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
25423 + pte_unmap_unlock(pte, ptl);
25424 + return 0;
25425 + }
25426 +
25427 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
25428 + /* write attempt to a protected page in user mode */
25429 + pte_unmap_unlock(pte, ptl);
25430 + return 0;
25431 + }
25432 +
25433 +#ifdef CONFIG_SMP
25434 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
25435 +#else
25436 + if (likely(address > get_limit(regs->cs)))
25437 +#endif
25438 + {
25439 + set_pte(pte, pte_mkread(*pte));
25440 + __flush_tlb_one(address);
25441 + pte_unmap_unlock(pte, ptl);
25442 + up_read(&mm->mmap_sem);
25443 + return 1;
25444 + }
25445 +
25446 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
25447 +
25448 + /*
25449 + * PaX: fill DTLB with user rights and retry
25450 + */
25451 + __asm__ __volatile__ (
25452 + "orb %2,(%1)\n"
25453 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
25454 +/*
25455 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
25456 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
25457 + * page fault when examined during a TLB load attempt. this is true not only
25458 + * for PTEs holding a non-present entry but also present entries that will
25459 + * raise a page fault (such as those set up by PaX, or the copy-on-write
25460 + * mechanism). in effect it means that we do *not* need to flush the TLBs
25461 + * for our target pages since their PTEs are simply not in the TLBs at all.
25462 +
25463 + * the best thing in omitting it is that we gain around 15-20% speed in the
25464 + * fast path of the page fault handler and can get rid of tracing since we
25465 + * can no longer flush unintended entries.
25466 + */
25467 + "invlpg (%0)\n"
25468 +#endif
25469 + __copyuser_seg"testb $0,(%0)\n"
25470 + "xorb %3,(%1)\n"
25471 + :
25472 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
25473 + : "memory", "cc");
25474 + pte_unmap_unlock(pte, ptl);
25475 + up_read(&mm->mmap_sem);
25476 + return 1;
25477 +}
25478 +#endif
25479 +
25480 /*
25481 * Handle a spurious fault caused by a stale TLB entry.
25482 *
25483 @@ -973,6 +1166,9 @@ int show_unhandled_signals = 1;
25484 static inline int
25485 access_error(unsigned long error_code, struct vm_area_struct *vma)
25486 {
25487 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
25488 + return 1;
25489 +
25490 if (error_code & PF_WRITE) {
25491 /* write, present and write, not present: */
25492 if (unlikely(!(vma->vm_flags & VM_WRITE)))
25493 @@ -1001,7 +1197,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
25494 if (error_code & PF_USER)
25495 return false;
25496
25497 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
25498 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
25499 return false;
25500
25501 return true;
25502 @@ -1017,18 +1213,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25503 {
25504 struct vm_area_struct *vma;
25505 struct task_struct *tsk;
25506 - unsigned long address;
25507 struct mm_struct *mm;
25508 int fault;
25509 int write = error_code & PF_WRITE;
25510 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
25511 (write ? FAULT_FLAG_WRITE : 0);
25512
25513 - tsk = current;
25514 - mm = tsk->mm;
25515 -
25516 /* Get the faulting address: */
25517 - address = read_cr2();
25518 + unsigned long address = read_cr2();
25519 +
25520 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25521 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
25522 + if (!search_exception_tables(regs->ip)) {
25523 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25524 + bad_area_nosemaphore(regs, error_code, address);
25525 + return;
25526 + }
25527 + if (address < PAX_USER_SHADOW_BASE) {
25528 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25529 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
25530 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
25531 + } else
25532 + address -= PAX_USER_SHADOW_BASE;
25533 + }
25534 +#endif
25535 +
25536 + tsk = current;
25537 + mm = tsk->mm;
25538
25539 /*
25540 * Detect and handle instructions that would cause a page fault for
25541 @@ -1089,7 +1300,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25542 * User-mode registers count as a user access even for any
25543 * potential system fault or CPU buglet:
25544 */
25545 - if (user_mode_vm(regs)) {
25546 + if (user_mode(regs)) {
25547 local_irq_enable();
25548 error_code |= PF_USER;
25549 } else {
25550 @@ -1151,6 +1362,11 @@ retry:
25551 might_sleep();
25552 }
25553
25554 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25555 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
25556 + return;
25557 +#endif
25558 +
25559 vma = find_vma(mm, address);
25560 if (unlikely(!vma)) {
25561 bad_area(regs, error_code, address);
25562 @@ -1162,18 +1378,24 @@ retry:
25563 bad_area(regs, error_code, address);
25564 return;
25565 }
25566 - if (error_code & PF_USER) {
25567 - /*
25568 - * Accessing the stack below %sp is always a bug.
25569 - * The large cushion allows instructions like enter
25570 - * and pusha to work. ("enter $65535, $31" pushes
25571 - * 32 pointers and then decrements %sp by 65535.)
25572 - */
25573 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
25574 - bad_area(regs, error_code, address);
25575 - return;
25576 - }
25577 + /*
25578 + * Accessing the stack below %sp is always a bug.
25579 + * The large cushion allows instructions like enter
25580 + * and pusha to work. ("enter $65535, $31" pushes
25581 + * 32 pointers and then decrements %sp by 65535.)
25582 + */
25583 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
25584 + bad_area(regs, error_code, address);
25585 + return;
25586 }
25587 +
25588 +#ifdef CONFIG_PAX_SEGMEXEC
25589 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
25590 + bad_area(regs, error_code, address);
25591 + return;
25592 + }
25593 +#endif
25594 +
25595 if (unlikely(expand_stack(vma, address))) {
25596 bad_area(regs, error_code, address);
25597 return;
25598 @@ -1237,3 +1459,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
25599 __do_page_fault(regs, error_code);
25600 exception_exit(regs);
25601 }
25602 +
25603 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25604 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
25605 +{
25606 + struct mm_struct *mm = current->mm;
25607 + unsigned long ip = regs->ip;
25608 +
25609 + if (v8086_mode(regs))
25610 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
25611 +
25612 +#ifdef CONFIG_PAX_PAGEEXEC
25613 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
25614 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
25615 + return true;
25616 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
25617 + return true;
25618 + return false;
25619 + }
25620 +#endif
25621 +
25622 +#ifdef CONFIG_PAX_SEGMEXEC
25623 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
25624 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
25625 + return true;
25626 + return false;
25627 + }
25628 +#endif
25629 +
25630 + return false;
25631 +}
25632 +#endif
25633 +
25634 +#ifdef CONFIG_PAX_EMUTRAMP
25635 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
25636 +{
25637 + int err;
25638 +
25639 + do { /* PaX: libffi trampoline emulation */
25640 + unsigned char mov, jmp;
25641 + unsigned int addr1, addr2;
25642 +
25643 +#ifdef CONFIG_X86_64
25644 + if ((regs->ip + 9) >> 32)
25645 + break;
25646 +#endif
25647 +
25648 + err = get_user(mov, (unsigned char __user *)regs->ip);
25649 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25650 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25651 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25652 +
25653 + if (err)
25654 + break;
25655 +
25656 + if (mov == 0xB8 && jmp == 0xE9) {
25657 + regs->ax = addr1;
25658 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25659 + return 2;
25660 + }
25661 + } while (0);
25662 +
25663 + do { /* PaX: gcc trampoline emulation #1 */
25664 + unsigned char mov1, mov2;
25665 + unsigned short jmp;
25666 + unsigned int addr1, addr2;
25667 +
25668 +#ifdef CONFIG_X86_64
25669 + if ((regs->ip + 11) >> 32)
25670 + break;
25671 +#endif
25672 +
25673 + err = get_user(mov1, (unsigned char __user *)regs->ip);
25674 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25675 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
25676 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25677 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
25678 +
25679 + if (err)
25680 + break;
25681 +
25682 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
25683 + regs->cx = addr1;
25684 + regs->ax = addr2;
25685 + regs->ip = addr2;
25686 + return 2;
25687 + }
25688 + } while (0);
25689 +
25690 + do { /* PaX: gcc trampoline emulation #2 */
25691 + unsigned char mov, jmp;
25692 + unsigned int addr1, addr2;
25693 +
25694 +#ifdef CONFIG_X86_64
25695 + if ((regs->ip + 9) >> 32)
25696 + break;
25697 +#endif
25698 +
25699 + err = get_user(mov, (unsigned char __user *)regs->ip);
25700 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25701 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25702 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25703 +
25704 + if (err)
25705 + break;
25706 +
25707 + if (mov == 0xB9 && jmp == 0xE9) {
25708 + regs->cx = addr1;
25709 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25710 + return 2;
25711 + }
25712 + } while (0);
25713 +
25714 + return 1; /* PaX in action */
25715 +}
25716 +
25717 +#ifdef CONFIG_X86_64
25718 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
25719 +{
25720 + int err;
25721 +
25722 + do { /* PaX: libffi trampoline emulation */
25723 + unsigned short mov1, mov2, jmp1;
25724 + unsigned char stcclc, jmp2;
25725 + unsigned long addr1, addr2;
25726 +
25727 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25728 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25729 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25730 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25731 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
25732 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
25733 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
25734 +
25735 + if (err)
25736 + break;
25737 +
25738 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25739 + regs->r11 = addr1;
25740 + regs->r10 = addr2;
25741 + if (stcclc == 0xF8)
25742 + regs->flags &= ~X86_EFLAGS_CF;
25743 + else
25744 + regs->flags |= X86_EFLAGS_CF;
25745 + regs->ip = addr1;
25746 + return 2;
25747 + }
25748 + } while (0);
25749 +
25750 + do { /* PaX: gcc trampoline emulation #1 */
25751 + unsigned short mov1, mov2, jmp1;
25752 + unsigned char jmp2;
25753 + unsigned int addr1;
25754 + unsigned long addr2;
25755 +
25756 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25757 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
25758 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
25759 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
25760 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
25761 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
25762 +
25763 + if (err)
25764 + break;
25765 +
25766 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25767 + regs->r11 = addr1;
25768 + regs->r10 = addr2;
25769 + regs->ip = addr1;
25770 + return 2;
25771 + }
25772 + } while (0);
25773 +
25774 + do { /* PaX: gcc trampoline emulation #2 */
25775 + unsigned short mov1, mov2, jmp1;
25776 + unsigned char jmp2;
25777 + unsigned long addr1, addr2;
25778 +
25779 + err = get_user(mov1, (unsigned short __user *)regs->ip);
25780 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25781 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25782 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25783 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
25784 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
25785 +
25786 + if (err)
25787 + break;
25788 +
25789 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25790 + regs->r11 = addr1;
25791 + regs->r10 = addr2;
25792 + regs->ip = addr1;
25793 + return 2;
25794 + }
25795 + } while (0);
25796 +
25797 + return 1; /* PaX in action */
25798 +}
25799 +#endif
25800 +
25801 +/*
25802 + * PaX: decide what to do with offenders (regs->ip = fault address)
25803 + *
25804 + * returns 1 when task should be killed
25805 + * 2 when gcc trampoline was detected
25806 + */
25807 +static int pax_handle_fetch_fault(struct pt_regs *regs)
25808 +{
25809 + if (v8086_mode(regs))
25810 + return 1;
25811 +
25812 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
25813 + return 1;
25814 +
25815 +#ifdef CONFIG_X86_32
25816 + return pax_handle_fetch_fault_32(regs);
25817 +#else
25818 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
25819 + return pax_handle_fetch_fault_32(regs);
25820 + else
25821 + return pax_handle_fetch_fault_64(regs);
25822 +#endif
25823 +}
25824 +#endif
25825 +
25826 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25827 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
25828 +{
25829 + long i;
25830 +
25831 + printk(KERN_ERR "PAX: bytes at PC: ");
25832 + for (i = 0; i < 20; i++) {
25833 + unsigned char c;
25834 + if (get_user(c, (unsigned char __force_user *)pc+i))
25835 + printk(KERN_CONT "?? ");
25836 + else
25837 + printk(KERN_CONT "%02x ", c);
25838 + }
25839 + printk("\n");
25840 +
25841 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
25842 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
25843 + unsigned long c;
25844 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
25845 +#ifdef CONFIG_X86_32
25846 + printk(KERN_CONT "???????? ");
25847 +#else
25848 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
25849 + printk(KERN_CONT "???????? ???????? ");
25850 + else
25851 + printk(KERN_CONT "???????????????? ");
25852 +#endif
25853 + } else {
25854 +#ifdef CONFIG_X86_64
25855 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
25856 + printk(KERN_CONT "%08x ", (unsigned int)c);
25857 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
25858 + } else
25859 +#endif
25860 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
25861 + }
25862 + }
25863 + printk("\n");
25864 +}
25865 +#endif
25866 +
25867 +/**
25868 + * probe_kernel_write(): safely attempt to write to a location
25869 + * @dst: address to write to
25870 + * @src: pointer to the data that shall be written
25871 + * @size: size of the data chunk
25872 + *
25873 + * Safely write to address @dst from the buffer at @src. If a kernel fault
25874 + * happens, handle that and return -EFAULT.
25875 + */
25876 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
25877 +{
25878 + long ret;
25879 + mm_segment_t old_fs = get_fs();
25880 +
25881 + set_fs(KERNEL_DS);
25882 + pagefault_disable();
25883 + pax_open_kernel();
25884 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
25885 + pax_close_kernel();
25886 + pagefault_enable();
25887 + set_fs(old_fs);
25888 +
25889 + return ret ? -EFAULT : 0;
25890 +}
25891 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
25892 index dd74e46..7d26398 100644
25893 --- a/arch/x86/mm/gup.c
25894 +++ b/arch/x86/mm/gup.c
25895 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
25896 addr = start;
25897 len = (unsigned long) nr_pages << PAGE_SHIFT;
25898 end = start + len;
25899 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25900 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25901 (void __user *)start, len)))
25902 return 0;
25903
25904 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
25905 index 6f31ee5..8ee4164 100644
25906 --- a/arch/x86/mm/highmem_32.c
25907 +++ b/arch/x86/mm/highmem_32.c
25908 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
25909 idx = type + KM_TYPE_NR*smp_processor_id();
25910 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25911 BUG_ON(!pte_none(*(kmap_pte-idx)));
25912 +
25913 + pax_open_kernel();
25914 set_pte(kmap_pte-idx, mk_pte(page, prot));
25915 + pax_close_kernel();
25916 +
25917 arch_flush_lazy_mmu_mode();
25918
25919 return (void *)vaddr;
25920 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
25921 index 937bff5..dce75ff 100644
25922 --- a/arch/x86/mm/hugetlbpage.c
25923 +++ b/arch/x86/mm/hugetlbpage.c
25924 @@ -276,13 +276,21 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
25925 struct hstate *h = hstate_file(file);
25926 struct mm_struct *mm = current->mm;
25927 struct vm_area_struct *vma;
25928 - unsigned long start_addr;
25929 + unsigned long start_addr, pax_task_size = TASK_SIZE;
25930 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25931 +
25932 +#ifdef CONFIG_PAX_SEGMEXEC
25933 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25934 + pax_task_size = SEGMEXEC_TASK_SIZE;
25935 +#endif
25936 +
25937 + pax_task_size -= PAGE_SIZE;
25938
25939 if (len > mm->cached_hole_size) {
25940 - start_addr = mm->free_area_cache;
25941 + start_addr = mm->free_area_cache;
25942 } else {
25943 - start_addr = TASK_UNMAPPED_BASE;
25944 - mm->cached_hole_size = 0;
25945 + start_addr = mm->mmap_base;
25946 + mm->cached_hole_size = 0;
25947 }
25948
25949 full_search:
25950 @@ -290,26 +298,27 @@ full_search:
25951
25952 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
25953 /* At this point: (!vma || addr < vma->vm_end). */
25954 - if (TASK_SIZE - len < addr) {
25955 + if (pax_task_size - len < addr) {
25956 /*
25957 * Start a new search - just in case we missed
25958 * some holes.
25959 */
25960 - if (start_addr != TASK_UNMAPPED_BASE) {
25961 - start_addr = TASK_UNMAPPED_BASE;
25962 + if (start_addr != mm->mmap_base) {
25963 + start_addr = mm->mmap_base;
25964 mm->cached_hole_size = 0;
25965 goto full_search;
25966 }
25967 return -ENOMEM;
25968 }
25969 - if (!vma || addr + len <= vma->vm_start) {
25970 - mm->free_area_cache = addr + len;
25971 - return addr;
25972 - }
25973 + if (check_heap_stack_gap(vma, addr, len, offset))
25974 + break;
25975 if (addr + mm->cached_hole_size < vma->vm_start)
25976 mm->cached_hole_size = vma->vm_start - addr;
25977 addr = ALIGN(vma->vm_end, huge_page_size(h));
25978 }
25979 +
25980 + mm->free_area_cache = addr + len;
25981 + return addr;
25982 }
25983
25984 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25985 @@ -320,9 +329,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25986 struct mm_struct *mm = current->mm;
25987 struct vm_area_struct *vma;
25988 unsigned long base = mm->mmap_base;
25989 - unsigned long addr = addr0;
25990 + unsigned long addr;
25991 unsigned long largest_hole = mm->cached_hole_size;
25992 - unsigned long start_addr;
25993 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25994
25995 /* don't allow allocations above current base */
25996 if (mm->free_area_cache > base)
25997 @@ -332,16 +341,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25998 largest_hole = 0;
25999 mm->free_area_cache = base;
26000 }
26001 -try_again:
26002 - start_addr = mm->free_area_cache;
26003
26004 /* make sure it can fit in the remaining address space */
26005 if (mm->free_area_cache < len)
26006 goto fail;
26007
26008 /* either no address requested or can't fit in requested address hole */
26009 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
26010 + addr = mm->free_area_cache - len;
26011 do {
26012 + addr &= huge_page_mask(h);
26013 /*
26014 * Lookup failure means no vma is above this address,
26015 * i.e. return with success:
26016 @@ -350,10 +358,10 @@ try_again:
26017 if (!vma)
26018 return addr;
26019
26020 - if (addr + len <= vma->vm_start) {
26021 + if (check_heap_stack_gap(vma, addr, len, offset)) {
26022 /* remember the address as a hint for next time */
26023 - mm->cached_hole_size = largest_hole;
26024 - return (mm->free_area_cache = addr);
26025 + mm->cached_hole_size = largest_hole;
26026 + return (mm->free_area_cache = addr);
26027 } else if (mm->free_area_cache == vma->vm_end) {
26028 /* pull free_area_cache down to the first hole */
26029 mm->free_area_cache = vma->vm_start;
26030 @@ -362,29 +370,34 @@ try_again:
26031
26032 /* remember the largest hole we saw so far */
26033 if (addr + largest_hole < vma->vm_start)
26034 - largest_hole = vma->vm_start - addr;
26035 + largest_hole = vma->vm_start - addr;
26036
26037 /* try just below the current vma->vm_start */
26038 - addr = (vma->vm_start - len) & huge_page_mask(h);
26039 - } while (len <= vma->vm_start);
26040 + addr = skip_heap_stack_gap(vma, len, offset);
26041 + } while (!IS_ERR_VALUE(addr));
26042
26043 fail:
26044 /*
26045 - * if hint left us with no space for the requested
26046 - * mapping then try again:
26047 - */
26048 - if (start_addr != base) {
26049 - mm->free_area_cache = base;
26050 - largest_hole = 0;
26051 - goto try_again;
26052 - }
26053 - /*
26054 * A failed mmap() very likely causes application failure,
26055 * so fall back to the bottom-up function here. This scenario
26056 * can happen with large stack limits and large mmap()
26057 * allocations.
26058 */
26059 - mm->free_area_cache = TASK_UNMAPPED_BASE;
26060 +
26061 +#ifdef CONFIG_PAX_SEGMEXEC
26062 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26063 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
26064 + else
26065 +#endif
26066 +
26067 + mm->mmap_base = TASK_UNMAPPED_BASE;
26068 +
26069 +#ifdef CONFIG_PAX_RANDMMAP
26070 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26071 + mm->mmap_base += mm->delta_mmap;
26072 +#endif
26073 +
26074 + mm->free_area_cache = mm->mmap_base;
26075 mm->cached_hole_size = ~0UL;
26076 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
26077 len, pgoff, flags);
26078 @@ -392,6 +405,7 @@ fail:
26079 /*
26080 * Restore the topdown base:
26081 */
26082 + mm->mmap_base = base;
26083 mm->free_area_cache = base;
26084 mm->cached_hole_size = ~0UL;
26085
26086 @@ -405,10 +419,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
26087 struct hstate *h = hstate_file(file);
26088 struct mm_struct *mm = current->mm;
26089 struct vm_area_struct *vma;
26090 + unsigned long pax_task_size = TASK_SIZE;
26091 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
26092
26093 if (len & ~huge_page_mask(h))
26094 return -EINVAL;
26095 - if (len > TASK_SIZE)
26096 +
26097 +#ifdef CONFIG_PAX_SEGMEXEC
26098 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26099 + pax_task_size = SEGMEXEC_TASK_SIZE;
26100 +#endif
26101 +
26102 + pax_task_size -= PAGE_SIZE;
26103 +
26104 + if (len > pax_task_size)
26105 return -ENOMEM;
26106
26107 if (flags & MAP_FIXED) {
26108 @@ -417,11 +441,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
26109 return addr;
26110 }
26111
26112 +#ifdef CONFIG_PAX_RANDMMAP
26113 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26114 +#endif
26115 +
26116 if (addr) {
26117 addr = ALIGN(addr, huge_page_size(h));
26118 vma = find_vma(mm, addr);
26119 - if (TASK_SIZE - len >= addr &&
26120 - (!vma || addr + len <= vma->vm_start))
26121 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26122 return addr;
26123 }
26124 if (mm->get_unmapped_area == arch_get_unmapped_area)
26125 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
26126 index d7aea41..0fc945b 100644
26127 --- a/arch/x86/mm/init.c
26128 +++ b/arch/x86/mm/init.c
26129 @@ -4,6 +4,7 @@
26130 #include <linux/swap.h>
26131 #include <linux/memblock.h>
26132 #include <linux/bootmem.h> /* for max_low_pfn */
26133 +#include <linux/tboot.h>
26134
26135 #include <asm/cacheflush.h>
26136 #include <asm/e820.h>
26137 @@ -16,6 +17,8 @@
26138 #include <asm/tlb.h>
26139 #include <asm/proto.h>
26140 #include <asm/dma.h> /* for MAX_DMA_PFN */
26141 +#include <asm/desc.h>
26142 +#include <asm/bios_ebda.h>
26143
26144 unsigned long __initdata pgt_buf_start;
26145 unsigned long __meminitdata pgt_buf_end;
26146 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
26147 {
26148 int i;
26149 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
26150 - unsigned long start = 0, good_end;
26151 + unsigned long start = 0x100000, good_end;
26152 phys_addr_t base;
26153
26154 for (i = 0; i < nr_range; i++) {
26155 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
26156 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
26157 * mmio resources as well as potential bios/acpi data regions.
26158 */
26159 +
26160 +#ifdef CONFIG_GRKERNSEC_KMEM
26161 +static unsigned int ebda_start __read_only;
26162 +static unsigned int ebda_end __read_only;
26163 +#endif
26164 +
26165 int devmem_is_allowed(unsigned long pagenr)
26166 {
26167 - if (pagenr < 256)
26168 +#ifdef CONFIG_GRKERNSEC_KMEM
26169 + /* allow BDA */
26170 + if (!pagenr)
26171 return 1;
26172 + /* allow EBDA */
26173 + if (pagenr >= ebda_start && pagenr < ebda_end)
26174 + return 1;
26175 + /* if tboot is in use, allow access to its hardcoded serial log range */
26176 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
26177 + return 1;
26178 +#else
26179 + if (!pagenr)
26180 + return 1;
26181 +#ifdef CONFIG_VM86
26182 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
26183 + return 1;
26184 +#endif
26185 +#endif
26186 +
26187 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
26188 + return 1;
26189 +#ifdef CONFIG_GRKERNSEC_KMEM
26190 + /* throw out everything else below 1MB */
26191 + if (pagenr <= 256)
26192 + return 0;
26193 +#endif
26194 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
26195 return 0;
26196 if (!page_is_ram(pagenr))
26197 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
26198 #endif
26199 }
26200
26201 +#ifdef CONFIG_GRKERNSEC_KMEM
26202 +static inline void gr_init_ebda(void)
26203 +{
26204 + unsigned int ebda_addr;
26205 + unsigned int ebda_size = 0;
26206 +
26207 + ebda_addr = get_bios_ebda();
26208 + if (ebda_addr) {
26209 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
26210 + ebda_size <<= 10;
26211 + }
26212 + if (ebda_addr && ebda_size) {
26213 + ebda_start = ebda_addr >> PAGE_SHIFT;
26214 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
26215 + } else {
26216 + ebda_start = 0x9f000 >> PAGE_SHIFT;
26217 + ebda_end = 0xa0000 >> PAGE_SHIFT;
26218 + }
26219 +}
26220 +#else
26221 +static inline void gr_init_ebda(void) { }
26222 +#endif
26223 +
26224 void free_initmem(void)
26225 {
26226 +#ifdef CONFIG_PAX_KERNEXEC
26227 +#ifdef CONFIG_X86_32
26228 + /* PaX: limit KERNEL_CS to actual size */
26229 + unsigned long addr, limit;
26230 + struct desc_struct d;
26231 + int cpu;
26232 +#else
26233 + pgd_t *pgd;
26234 + pud_t *pud;
26235 + pmd_t *pmd;
26236 + unsigned long addr, end;
26237 +#endif
26238 +#endif
26239 +
26240 + gr_init_ebda();
26241 +
26242 +#ifdef CONFIG_PAX_KERNEXEC
26243 +#ifdef CONFIG_X86_32
26244 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
26245 + limit = (limit - 1UL) >> PAGE_SHIFT;
26246 +
26247 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
26248 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26249 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
26250 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
26251 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
26252 + }
26253 +
26254 + /* PaX: make KERNEL_CS read-only */
26255 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
26256 + if (!paravirt_enabled())
26257 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
26258 +/*
26259 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
26260 + pgd = pgd_offset_k(addr);
26261 + pud = pud_offset(pgd, addr);
26262 + pmd = pmd_offset(pud, addr);
26263 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26264 + }
26265 +*/
26266 +#ifdef CONFIG_X86_PAE
26267 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
26268 +/*
26269 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
26270 + pgd = pgd_offset_k(addr);
26271 + pud = pud_offset(pgd, addr);
26272 + pmd = pmd_offset(pud, addr);
26273 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
26274 + }
26275 +*/
26276 +#endif
26277 +
26278 +#ifdef CONFIG_MODULES
26279 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
26280 +#endif
26281 +
26282 +#else
26283 + /* PaX: make kernel code/rodata read-only, rest non-executable */
26284 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
26285 + pgd = pgd_offset_k(addr);
26286 + pud = pud_offset(pgd, addr);
26287 + pmd = pmd_offset(pud, addr);
26288 + if (!pmd_present(*pmd))
26289 + continue;
26290 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
26291 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26292 + else
26293 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
26294 + }
26295 +
26296 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
26297 + end = addr + KERNEL_IMAGE_SIZE;
26298 + for (; addr < end; addr += PMD_SIZE) {
26299 + pgd = pgd_offset_k(addr);
26300 + pud = pud_offset(pgd, addr);
26301 + pmd = pmd_offset(pud, addr);
26302 + if (!pmd_present(*pmd))
26303 + continue;
26304 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
26305 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26306 + }
26307 +#endif
26308 +
26309 + flush_tlb_all();
26310 +#endif
26311 +
26312 free_init_pages("unused kernel memory",
26313 (unsigned long)(&__init_begin),
26314 (unsigned long)(&__init_end));
26315 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
26316 index 11a5800..4bd9977 100644
26317 --- a/arch/x86/mm/init_32.c
26318 +++ b/arch/x86/mm/init_32.c
26319 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
26320 }
26321
26322 /*
26323 - * Creates a middle page table and puts a pointer to it in the
26324 - * given global directory entry. This only returns the gd entry
26325 - * in non-PAE compilation mode, since the middle layer is folded.
26326 - */
26327 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
26328 -{
26329 - pud_t *pud;
26330 - pmd_t *pmd_table;
26331 -
26332 -#ifdef CONFIG_X86_PAE
26333 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
26334 - if (after_bootmem)
26335 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
26336 - else
26337 - pmd_table = (pmd_t *)alloc_low_page();
26338 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
26339 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
26340 - pud = pud_offset(pgd, 0);
26341 - BUG_ON(pmd_table != pmd_offset(pud, 0));
26342 -
26343 - return pmd_table;
26344 - }
26345 -#endif
26346 - pud = pud_offset(pgd, 0);
26347 - pmd_table = pmd_offset(pud, 0);
26348 -
26349 - return pmd_table;
26350 -}
26351 -
26352 -/*
26353 * Create a page table and place a pointer to it in a middle page
26354 * directory entry:
26355 */
26356 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
26357 page_table = (pte_t *)alloc_low_page();
26358
26359 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
26360 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26361 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
26362 +#else
26363 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
26364 +#endif
26365 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
26366 }
26367
26368 return pte_offset_kernel(pmd, 0);
26369 }
26370
26371 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
26372 +{
26373 + pud_t *pud;
26374 + pmd_t *pmd_table;
26375 +
26376 + pud = pud_offset(pgd, 0);
26377 + pmd_table = pmd_offset(pud, 0);
26378 +
26379 + return pmd_table;
26380 +}
26381 +
26382 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
26383 {
26384 int pgd_idx = pgd_index(vaddr);
26385 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26386 int pgd_idx, pmd_idx;
26387 unsigned long vaddr;
26388 pgd_t *pgd;
26389 + pud_t *pud;
26390 pmd_t *pmd;
26391 pte_t *pte = NULL;
26392
26393 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26394 pgd = pgd_base + pgd_idx;
26395
26396 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
26397 - pmd = one_md_table_init(pgd);
26398 - pmd = pmd + pmd_index(vaddr);
26399 + pud = pud_offset(pgd, vaddr);
26400 + pmd = pmd_offset(pud, vaddr);
26401 +
26402 +#ifdef CONFIG_X86_PAE
26403 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26404 +#endif
26405 +
26406 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
26407 pmd++, pmd_idx++) {
26408 pte = page_table_kmap_check(one_page_table_init(pmd),
26409 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26410 }
26411 }
26412
26413 -static inline int is_kernel_text(unsigned long addr)
26414 +static inline int is_kernel_text(unsigned long start, unsigned long end)
26415 {
26416 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
26417 - return 1;
26418 - return 0;
26419 + if ((start > ktla_ktva((unsigned long)_etext) ||
26420 + end <= ktla_ktva((unsigned long)_stext)) &&
26421 + (start > ktla_ktva((unsigned long)_einittext) ||
26422 + end <= ktla_ktva((unsigned long)_sinittext)) &&
26423 +
26424 +#ifdef CONFIG_ACPI_SLEEP
26425 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
26426 +#endif
26427 +
26428 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
26429 + return 0;
26430 + return 1;
26431 }
26432
26433 /*
26434 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
26435 unsigned long last_map_addr = end;
26436 unsigned long start_pfn, end_pfn;
26437 pgd_t *pgd_base = swapper_pg_dir;
26438 - int pgd_idx, pmd_idx, pte_ofs;
26439 + unsigned int pgd_idx, pmd_idx, pte_ofs;
26440 unsigned long pfn;
26441 pgd_t *pgd;
26442 + pud_t *pud;
26443 pmd_t *pmd;
26444 pte_t *pte;
26445 unsigned pages_2m, pages_4k;
26446 @@ -280,8 +281,13 @@ repeat:
26447 pfn = start_pfn;
26448 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26449 pgd = pgd_base + pgd_idx;
26450 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
26451 - pmd = one_md_table_init(pgd);
26452 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
26453 + pud = pud_offset(pgd, 0);
26454 + pmd = pmd_offset(pud, 0);
26455 +
26456 +#ifdef CONFIG_X86_PAE
26457 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26458 +#endif
26459
26460 if (pfn >= end_pfn)
26461 continue;
26462 @@ -293,14 +299,13 @@ repeat:
26463 #endif
26464 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
26465 pmd++, pmd_idx++) {
26466 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
26467 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
26468
26469 /*
26470 * Map with big pages if possible, otherwise
26471 * create normal page tables:
26472 */
26473 if (use_pse) {
26474 - unsigned int addr2;
26475 pgprot_t prot = PAGE_KERNEL_LARGE;
26476 /*
26477 * first pass will use the same initial
26478 @@ -310,11 +315,7 @@ repeat:
26479 __pgprot(PTE_IDENT_ATTR |
26480 _PAGE_PSE);
26481
26482 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
26483 - PAGE_OFFSET + PAGE_SIZE-1;
26484 -
26485 - if (is_kernel_text(addr) ||
26486 - is_kernel_text(addr2))
26487 + if (is_kernel_text(address, address + PMD_SIZE))
26488 prot = PAGE_KERNEL_LARGE_EXEC;
26489
26490 pages_2m++;
26491 @@ -331,7 +332,7 @@ repeat:
26492 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26493 pte += pte_ofs;
26494 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
26495 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
26496 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
26497 pgprot_t prot = PAGE_KERNEL;
26498 /*
26499 * first pass will use the same initial
26500 @@ -339,7 +340,7 @@ repeat:
26501 */
26502 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
26503
26504 - if (is_kernel_text(addr))
26505 + if (is_kernel_text(address, address + PAGE_SIZE))
26506 prot = PAGE_KERNEL_EXEC;
26507
26508 pages_4k++;
26509 @@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
26510
26511 pud = pud_offset(pgd, va);
26512 pmd = pmd_offset(pud, va);
26513 - if (!pmd_present(*pmd))
26514 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
26515 break;
26516
26517 pte = pte_offset_kernel(pmd, va);
26518 @@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
26519
26520 static void __init pagetable_init(void)
26521 {
26522 - pgd_t *pgd_base = swapper_pg_dir;
26523 -
26524 - permanent_kmaps_init(pgd_base);
26525 + permanent_kmaps_init(swapper_pg_dir);
26526 }
26527
26528 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26529 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26530 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26531
26532 /* user-defined highmem size */
26533 @@ -731,6 +730,12 @@ void __init mem_init(void)
26534
26535 pci_iommu_alloc();
26536
26537 +#ifdef CONFIG_PAX_PER_CPU_PGD
26538 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26539 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26540 + KERNEL_PGD_PTRS);
26541 +#endif
26542 +
26543 #ifdef CONFIG_FLATMEM
26544 BUG_ON(!mem_map);
26545 #endif
26546 @@ -757,7 +762,7 @@ void __init mem_init(void)
26547 reservedpages++;
26548
26549 codesize = (unsigned long) &_etext - (unsigned long) &_text;
26550 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
26551 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
26552 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
26553
26554 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
26555 @@ -798,10 +803,10 @@ void __init mem_init(void)
26556 ((unsigned long)&__init_end -
26557 (unsigned long)&__init_begin) >> 10,
26558
26559 - (unsigned long)&_etext, (unsigned long)&_edata,
26560 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
26561 + (unsigned long)&_sdata, (unsigned long)&_edata,
26562 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
26563
26564 - (unsigned long)&_text, (unsigned long)&_etext,
26565 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
26566 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
26567
26568 /*
26569 @@ -879,6 +884,7 @@ void set_kernel_text_rw(void)
26570 if (!kernel_set_to_readonly)
26571 return;
26572
26573 + start = ktla_ktva(start);
26574 pr_debug("Set kernel text: %lx - %lx for read write\n",
26575 start, start+size);
26576
26577 @@ -893,6 +899,7 @@ void set_kernel_text_ro(void)
26578 if (!kernel_set_to_readonly)
26579 return;
26580
26581 + start = ktla_ktva(start);
26582 pr_debug("Set kernel text: %lx - %lx for read only\n",
26583 start, start+size);
26584
26585 @@ -921,6 +928,7 @@ void mark_rodata_ro(void)
26586 unsigned long start = PFN_ALIGN(_text);
26587 unsigned long size = PFN_ALIGN(_etext) - start;
26588
26589 + start = ktla_ktva(start);
26590 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
26591 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
26592 size >> 10);
26593 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
26594 index 3baff25..678a54e 100644
26595 --- a/arch/x86/mm/init_64.c
26596 +++ b/arch/x86/mm/init_64.c
26597 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
26598 * around without checking the pgd every time.
26599 */
26600
26601 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
26602 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
26603 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26604
26605 int force_personality32;
26606 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26607
26608 for (address = start; address <= end; address += PGDIR_SIZE) {
26609 const pgd_t *pgd_ref = pgd_offset_k(address);
26610 +
26611 +#ifdef CONFIG_PAX_PER_CPU_PGD
26612 + unsigned long cpu;
26613 +#else
26614 struct page *page;
26615 +#endif
26616
26617 if (pgd_none(*pgd_ref))
26618 continue;
26619
26620 spin_lock(&pgd_lock);
26621 +
26622 +#ifdef CONFIG_PAX_PER_CPU_PGD
26623 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26624 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
26625 +#else
26626 list_for_each_entry(page, &pgd_list, lru) {
26627 pgd_t *pgd;
26628 spinlock_t *pgt_lock;
26629 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26630 /* the pgt_lock only for Xen */
26631 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26632 spin_lock(pgt_lock);
26633 +#endif
26634
26635 if (pgd_none(*pgd))
26636 set_pgd(pgd, *pgd_ref);
26637 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26638 BUG_ON(pgd_page_vaddr(*pgd)
26639 != pgd_page_vaddr(*pgd_ref));
26640
26641 +#ifndef CONFIG_PAX_PER_CPU_PGD
26642 spin_unlock(pgt_lock);
26643 +#endif
26644 +
26645 }
26646 spin_unlock(&pgd_lock);
26647 }
26648 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
26649 {
26650 if (pgd_none(*pgd)) {
26651 pud_t *pud = (pud_t *)spp_getpage();
26652 - pgd_populate(&init_mm, pgd, pud);
26653 + pgd_populate_kernel(&init_mm, pgd, pud);
26654 if (pud != pud_offset(pgd, 0))
26655 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
26656 pud, pud_offset(pgd, 0));
26657 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
26658 {
26659 if (pud_none(*pud)) {
26660 pmd_t *pmd = (pmd_t *) spp_getpage();
26661 - pud_populate(&init_mm, pud, pmd);
26662 + pud_populate_kernel(&init_mm, pud, pmd);
26663 if (pmd != pmd_offset(pud, 0))
26664 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
26665 pmd, pmd_offset(pud, 0));
26666 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
26667 pmd = fill_pmd(pud, vaddr);
26668 pte = fill_pte(pmd, vaddr);
26669
26670 + pax_open_kernel();
26671 set_pte(pte, new_pte);
26672 + pax_close_kernel();
26673
26674 /*
26675 * It's enough to flush this one mapping.
26676 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
26677 pgd = pgd_offset_k((unsigned long)__va(phys));
26678 if (pgd_none(*pgd)) {
26679 pud = (pud_t *) spp_getpage();
26680 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
26681 - _PAGE_USER));
26682 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
26683 }
26684 pud = pud_offset(pgd, (unsigned long)__va(phys));
26685 if (pud_none(*pud)) {
26686 pmd = (pmd_t *) spp_getpage();
26687 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
26688 - _PAGE_USER));
26689 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
26690 }
26691 pmd = pmd_offset(pud, phys);
26692 BUG_ON(!pmd_none(*pmd));
26693 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
26694 if (pfn >= pgt_buf_top)
26695 panic("alloc_low_page: ran out of memory");
26696
26697 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26698 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26699 clear_page(adr);
26700 *phys = pfn * PAGE_SIZE;
26701 return adr;
26702 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
26703
26704 phys = __pa(virt);
26705 left = phys & (PAGE_SIZE - 1);
26706 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26707 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26708 adr = (void *)(((unsigned long)adr) | left);
26709
26710 return adr;
26711 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
26712 unmap_low_page(pmd);
26713
26714 spin_lock(&init_mm.page_table_lock);
26715 - pud_populate(&init_mm, pud, __va(pmd_phys));
26716 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
26717 spin_unlock(&init_mm.page_table_lock);
26718 }
26719 __flush_tlb_all();
26720 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
26721 unmap_low_page(pud);
26722
26723 spin_lock(&init_mm.page_table_lock);
26724 - pgd_populate(&init_mm, pgd, __va(pud_phys));
26725 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
26726 spin_unlock(&init_mm.page_table_lock);
26727 pgd_changed = true;
26728 }
26729 @@ -691,6 +705,12 @@ void __init mem_init(void)
26730
26731 pci_iommu_alloc();
26732
26733 +#ifdef CONFIG_PAX_PER_CPU_PGD
26734 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26735 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26736 + KERNEL_PGD_PTRS);
26737 +#endif
26738 +
26739 /* clear_bss() already clear the empty_zero_page */
26740
26741 reservedpages = 0;
26742 @@ -829,6 +849,9 @@ int kern_addr_valid(unsigned long addr)
26743 if (pud_none(*pud))
26744 return 0;
26745
26746 + if (pud_large(*pud))
26747 + return pfn_valid(pud_pfn(*pud));
26748 +
26749 pmd = pmd_offset(pud, addr);
26750 if (pmd_none(*pmd))
26751 return 0;
26752 @@ -851,8 +874,8 @@ int kern_addr_valid(unsigned long addr)
26753 static struct vm_area_struct gate_vma = {
26754 .vm_start = VSYSCALL_START,
26755 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
26756 - .vm_page_prot = PAGE_READONLY_EXEC,
26757 - .vm_flags = VM_READ | VM_EXEC
26758 + .vm_page_prot = PAGE_READONLY,
26759 + .vm_flags = VM_READ
26760 };
26761
26762 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26763 @@ -886,7 +909,7 @@ int in_gate_area_no_mm(unsigned long addr)
26764
26765 const char *arch_vma_name(struct vm_area_struct *vma)
26766 {
26767 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26768 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26769 return "[vdso]";
26770 if (vma == &gate_vma)
26771 return "[vsyscall]";
26772 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
26773 index 7b179b4..6bd1777 100644
26774 --- a/arch/x86/mm/iomap_32.c
26775 +++ b/arch/x86/mm/iomap_32.c
26776 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
26777 type = kmap_atomic_idx_push();
26778 idx = type + KM_TYPE_NR * smp_processor_id();
26779 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
26780 +
26781 + pax_open_kernel();
26782 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
26783 + pax_close_kernel();
26784 +
26785 arch_flush_lazy_mmu_mode();
26786
26787 return (void *)vaddr;
26788 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
26789 index 78fe3f1..2f9433c 100644
26790 --- a/arch/x86/mm/ioremap.c
26791 +++ b/arch/x86/mm/ioremap.c
26792 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
26793 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
26794 int is_ram = page_is_ram(pfn);
26795
26796 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
26797 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
26798 return NULL;
26799 WARN_ON_ONCE(is_ram);
26800 }
26801 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
26802 *
26803 * Caller must ensure there is only one unmapping for the same pointer.
26804 */
26805 -void iounmap(volatile void __iomem *addr)
26806 +void iounmap(const volatile void __iomem *addr)
26807 {
26808 struct vm_struct *p, *o;
26809
26810 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
26811
26812 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
26813 if (page_is_ram(start >> PAGE_SHIFT))
26814 +#ifdef CONFIG_HIGHMEM
26815 + if ((start >> PAGE_SHIFT) < max_low_pfn)
26816 +#endif
26817 return __va(phys);
26818
26819 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
26820 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
26821 early_param("early_ioremap_debug", early_ioremap_debug_setup);
26822
26823 static __initdata int after_paging_init;
26824 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
26825 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
26826
26827 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
26828 {
26829 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
26830 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
26831
26832 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
26833 - memset(bm_pte, 0, sizeof(bm_pte));
26834 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
26835 + pmd_populate_user(&init_mm, pmd, bm_pte);
26836
26837 /*
26838 * The boot-ioremap range spans multiple pmds, for which
26839 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
26840 index d87dd6d..bf3fa66 100644
26841 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
26842 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
26843 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
26844 * memory (e.g. tracked pages)? For now, we need this to avoid
26845 * invoking kmemcheck for PnP BIOS calls.
26846 */
26847 - if (regs->flags & X86_VM_MASK)
26848 + if (v8086_mode(regs))
26849 return false;
26850 - if (regs->cs != __KERNEL_CS)
26851 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
26852 return false;
26853
26854 pte = kmemcheck_pte_lookup(address);
26855 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
26856 index 845df68..1d8d29f 100644
26857 --- a/arch/x86/mm/mmap.c
26858 +++ b/arch/x86/mm/mmap.c
26859 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
26860 * Leave an at least ~128 MB hole with possible stack randomization.
26861 */
26862 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
26863 -#define MAX_GAP (TASK_SIZE/6*5)
26864 +#define MAX_GAP (pax_task_size/6*5)
26865
26866 static int mmap_is_legacy(void)
26867 {
26868 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
26869 return rnd << PAGE_SHIFT;
26870 }
26871
26872 -static unsigned long mmap_base(void)
26873 +static unsigned long mmap_base(struct mm_struct *mm)
26874 {
26875 unsigned long gap = rlimit(RLIMIT_STACK);
26876 + unsigned long pax_task_size = TASK_SIZE;
26877 +
26878 +#ifdef CONFIG_PAX_SEGMEXEC
26879 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26880 + pax_task_size = SEGMEXEC_TASK_SIZE;
26881 +#endif
26882
26883 if (gap < MIN_GAP)
26884 gap = MIN_GAP;
26885 else if (gap > MAX_GAP)
26886 gap = MAX_GAP;
26887
26888 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
26889 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
26890 }
26891
26892 /*
26893 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
26894 * does, but not when emulating X86_32
26895 */
26896 -static unsigned long mmap_legacy_base(void)
26897 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
26898 {
26899 - if (mmap_is_ia32())
26900 + if (mmap_is_ia32()) {
26901 +
26902 +#ifdef CONFIG_PAX_SEGMEXEC
26903 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26904 + return SEGMEXEC_TASK_UNMAPPED_BASE;
26905 + else
26906 +#endif
26907 +
26908 return TASK_UNMAPPED_BASE;
26909 - else
26910 + } else
26911 return TASK_UNMAPPED_BASE + mmap_rnd();
26912 }
26913
26914 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
26915 void arch_pick_mmap_layout(struct mm_struct *mm)
26916 {
26917 if (mmap_is_legacy()) {
26918 - mm->mmap_base = mmap_legacy_base();
26919 + mm->mmap_base = mmap_legacy_base(mm);
26920 +
26921 +#ifdef CONFIG_PAX_RANDMMAP
26922 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26923 + mm->mmap_base += mm->delta_mmap;
26924 +#endif
26925 +
26926 mm->get_unmapped_area = arch_get_unmapped_area;
26927 mm->unmap_area = arch_unmap_area;
26928 } else {
26929 - mm->mmap_base = mmap_base();
26930 + mm->mmap_base = mmap_base(mm);
26931 +
26932 +#ifdef CONFIG_PAX_RANDMMAP
26933 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26934 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
26935 +#endif
26936 +
26937 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
26938 mm->unmap_area = arch_unmap_area_topdown;
26939 }
26940 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
26941 index dc0b727..f612039 100644
26942 --- a/arch/x86/mm/mmio-mod.c
26943 +++ b/arch/x86/mm/mmio-mod.c
26944 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
26945 break;
26946 default:
26947 {
26948 - unsigned char *ip = (unsigned char *)instptr;
26949 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
26950 my_trace->opcode = MMIO_UNKNOWN_OP;
26951 my_trace->width = 0;
26952 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
26953 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
26954 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26955 void __iomem *addr)
26956 {
26957 - static atomic_t next_id;
26958 + static atomic_unchecked_t next_id;
26959 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
26960 /* These are page-unaligned. */
26961 struct mmiotrace_map map = {
26962 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26963 .private = trace
26964 },
26965 .phys = offset,
26966 - .id = atomic_inc_return(&next_id)
26967 + .id = atomic_inc_return_unchecked(&next_id)
26968 };
26969 map.map_id = trace->id;
26970
26971 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
26972 ioremap_trace_core(offset, size, addr);
26973 }
26974
26975 -static void iounmap_trace_core(volatile void __iomem *addr)
26976 +static void iounmap_trace_core(const volatile void __iomem *addr)
26977 {
26978 struct mmiotrace_map map = {
26979 .phys = 0,
26980 @@ -328,7 +328,7 @@ not_enabled:
26981 }
26982 }
26983
26984 -void mmiotrace_iounmap(volatile void __iomem *addr)
26985 +void mmiotrace_iounmap(const volatile void __iomem *addr)
26986 {
26987 might_sleep();
26988 if (is_enabled()) /* recheck and proper locking in *_core() */
26989 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
26990 index b008656..773eac2 100644
26991 --- a/arch/x86/mm/pageattr-test.c
26992 +++ b/arch/x86/mm/pageattr-test.c
26993 @@ -36,7 +36,7 @@ enum {
26994
26995 static int pte_testbit(pte_t pte)
26996 {
26997 - return pte_flags(pte) & _PAGE_UNUSED1;
26998 + return pte_flags(pte) & _PAGE_CPA_TEST;
26999 }
27000
27001 struct split_state {
27002 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
27003 index a718e0d..77419bc 100644
27004 --- a/arch/x86/mm/pageattr.c
27005 +++ b/arch/x86/mm/pageattr.c
27006 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
27007 */
27008 #ifdef CONFIG_PCI_BIOS
27009 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
27010 - pgprot_val(forbidden) |= _PAGE_NX;
27011 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
27012 #endif
27013
27014 /*
27015 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
27016 * Does not cover __inittext since that is gone later on. On
27017 * 64bit we do not enforce !NX on the low mapping
27018 */
27019 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
27020 - pgprot_val(forbidden) |= _PAGE_NX;
27021 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
27022 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
27023
27024 +#ifdef CONFIG_DEBUG_RODATA
27025 /*
27026 * The .rodata section needs to be read-only. Using the pfn
27027 * catches all aliases.
27028 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
27029 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
27030 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
27031 pgprot_val(forbidden) |= _PAGE_RW;
27032 +#endif
27033
27034 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
27035 /*
27036 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
27037 }
27038 #endif
27039
27040 +#ifdef CONFIG_PAX_KERNEXEC
27041 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
27042 + pgprot_val(forbidden) |= _PAGE_RW;
27043 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
27044 + }
27045 +#endif
27046 +
27047 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
27048
27049 return prot;
27050 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
27051 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
27052 {
27053 /* change init_mm */
27054 + pax_open_kernel();
27055 set_pte_atomic(kpte, pte);
27056 +
27057 #ifdef CONFIG_X86_32
27058 if (!SHARED_KERNEL_PMD) {
27059 +
27060 +#ifdef CONFIG_PAX_PER_CPU_PGD
27061 + unsigned long cpu;
27062 +#else
27063 struct page *page;
27064 +#endif
27065
27066 +#ifdef CONFIG_PAX_PER_CPU_PGD
27067 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27068 + pgd_t *pgd = get_cpu_pgd(cpu);
27069 +#else
27070 list_for_each_entry(page, &pgd_list, lru) {
27071 - pgd_t *pgd;
27072 + pgd_t *pgd = (pgd_t *)page_address(page);
27073 +#endif
27074 +
27075 pud_t *pud;
27076 pmd_t *pmd;
27077
27078 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
27079 + pgd += pgd_index(address);
27080 pud = pud_offset(pgd, address);
27081 pmd = pmd_offset(pud, address);
27082 set_pte_atomic((pte_t *)pmd, pte);
27083 }
27084 }
27085 #endif
27086 + pax_close_kernel();
27087 }
27088
27089 static int
27090 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
27091 index 0eb572e..92f5c1e 100644
27092 --- a/arch/x86/mm/pat.c
27093 +++ b/arch/x86/mm/pat.c
27094 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
27095
27096 if (!entry) {
27097 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
27098 - current->comm, current->pid, start, end - 1);
27099 + current->comm, task_pid_nr(current), start, end - 1);
27100 return -EINVAL;
27101 }
27102
27103 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27104
27105 while (cursor < to) {
27106 if (!devmem_is_allowed(pfn)) {
27107 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
27108 - current->comm, from, to - 1);
27109 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
27110 + current->comm, from, to - 1, cursor);
27111 return 0;
27112 }
27113 cursor += PAGE_SIZE;
27114 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
27115 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
27116 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
27117 "for [mem %#010Lx-%#010Lx]\n",
27118 - current->comm, current->pid,
27119 + current->comm, task_pid_nr(current),
27120 cattr_name(flags),
27121 base, (unsigned long long)(base + size-1));
27122 return -EINVAL;
27123 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
27124 flags = lookup_memtype(paddr);
27125 if (want_flags != flags) {
27126 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
27127 - current->comm, current->pid,
27128 + current->comm, task_pid_nr(current),
27129 cattr_name(want_flags),
27130 (unsigned long long)paddr,
27131 (unsigned long long)(paddr + size - 1),
27132 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
27133 free_memtype(paddr, paddr + size);
27134 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
27135 " for [mem %#010Lx-%#010Lx], got %s\n",
27136 - current->comm, current->pid,
27137 + current->comm, task_pid_nr(current),
27138 cattr_name(want_flags),
27139 (unsigned long long)paddr,
27140 (unsigned long long)(paddr + size - 1),
27141 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
27142 index 9f0614d..92ae64a 100644
27143 --- a/arch/x86/mm/pf_in.c
27144 +++ b/arch/x86/mm/pf_in.c
27145 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
27146 int i;
27147 enum reason_type rv = OTHERS;
27148
27149 - p = (unsigned char *)ins_addr;
27150 + p = (unsigned char *)ktla_ktva(ins_addr);
27151 p += skip_prefix(p, &prf);
27152 p += get_opcode(p, &opcode);
27153
27154 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
27155 struct prefix_bits prf;
27156 int i;
27157
27158 - p = (unsigned char *)ins_addr;
27159 + p = (unsigned char *)ktla_ktva(ins_addr);
27160 p += skip_prefix(p, &prf);
27161 p += get_opcode(p, &opcode);
27162
27163 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
27164 struct prefix_bits prf;
27165 int i;
27166
27167 - p = (unsigned char *)ins_addr;
27168 + p = (unsigned char *)ktla_ktva(ins_addr);
27169 p += skip_prefix(p, &prf);
27170 p += get_opcode(p, &opcode);
27171
27172 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
27173 struct prefix_bits prf;
27174 int i;
27175
27176 - p = (unsigned char *)ins_addr;
27177 + p = (unsigned char *)ktla_ktva(ins_addr);
27178 p += skip_prefix(p, &prf);
27179 p += get_opcode(p, &opcode);
27180 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
27181 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
27182 struct prefix_bits prf;
27183 int i;
27184
27185 - p = (unsigned char *)ins_addr;
27186 + p = (unsigned char *)ktla_ktva(ins_addr);
27187 p += skip_prefix(p, &prf);
27188 p += get_opcode(p, &opcode);
27189 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
27190 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
27191 index 8573b83..4f3ed7e 100644
27192 --- a/arch/x86/mm/pgtable.c
27193 +++ b/arch/x86/mm/pgtable.c
27194 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
27195 list_del(&page->lru);
27196 }
27197
27198 -#define UNSHARED_PTRS_PER_PGD \
27199 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
27200 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27201 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
27202
27203 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
27204 +{
27205 + unsigned int count = USER_PGD_PTRS;
27206
27207 + while (count--)
27208 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
27209 +}
27210 +#endif
27211 +
27212 +#ifdef CONFIG_PAX_PER_CPU_PGD
27213 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
27214 +{
27215 + unsigned int count = USER_PGD_PTRS;
27216 +
27217 + while (count--) {
27218 + pgd_t pgd;
27219 +
27220 +#ifdef CONFIG_X86_64
27221 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
27222 +#else
27223 + pgd = *src++;
27224 +#endif
27225 +
27226 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27227 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
27228 +#endif
27229 +
27230 + *dst++ = pgd;
27231 + }
27232 +
27233 +}
27234 +#endif
27235 +
27236 +#ifdef CONFIG_X86_64
27237 +#define pxd_t pud_t
27238 +#define pyd_t pgd_t
27239 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
27240 +#define pxd_free(mm, pud) pud_free((mm), (pud))
27241 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
27242 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
27243 +#define PYD_SIZE PGDIR_SIZE
27244 +#else
27245 +#define pxd_t pmd_t
27246 +#define pyd_t pud_t
27247 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
27248 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
27249 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
27250 +#define pyd_offset(mm, address) pud_offset((mm), (address))
27251 +#define PYD_SIZE PUD_SIZE
27252 +#endif
27253 +
27254 +#ifdef CONFIG_PAX_PER_CPU_PGD
27255 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
27256 +static inline void pgd_dtor(pgd_t *pgd) {}
27257 +#else
27258 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
27259 {
27260 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
27261 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
27262 pgd_list_del(pgd);
27263 spin_unlock(&pgd_lock);
27264 }
27265 +#endif
27266
27267 /*
27268 * List of all pgd's needed for non-PAE so it can invalidate entries
27269 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
27270 * -- wli
27271 */
27272
27273 -#ifdef CONFIG_X86_PAE
27274 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
27275 /*
27276 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
27277 * updating the top-level pagetable entries to guarantee the
27278 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
27279 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
27280 * and initialize the kernel pmds here.
27281 */
27282 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
27283 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
27284
27285 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
27286 {
27287 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
27288 */
27289 flush_tlb_mm(mm);
27290 }
27291 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
27292 +#define PREALLOCATED_PXDS USER_PGD_PTRS
27293 #else /* !CONFIG_X86_PAE */
27294
27295 /* No need to prepopulate any pagetable entries in non-PAE modes. */
27296 -#define PREALLOCATED_PMDS 0
27297 +#define PREALLOCATED_PXDS 0
27298
27299 #endif /* CONFIG_X86_PAE */
27300
27301 -static void free_pmds(pmd_t *pmds[])
27302 +static void free_pxds(pxd_t *pxds[])
27303 {
27304 int i;
27305
27306 - for(i = 0; i < PREALLOCATED_PMDS; i++)
27307 - if (pmds[i])
27308 - free_page((unsigned long)pmds[i]);
27309 + for(i = 0; i < PREALLOCATED_PXDS; i++)
27310 + if (pxds[i])
27311 + free_page((unsigned long)pxds[i]);
27312 }
27313
27314 -static int preallocate_pmds(pmd_t *pmds[])
27315 +static int preallocate_pxds(pxd_t *pxds[])
27316 {
27317 int i;
27318 bool failed = false;
27319
27320 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
27321 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
27322 - if (pmd == NULL)
27323 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
27324 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
27325 + if (pxd == NULL)
27326 failed = true;
27327 - pmds[i] = pmd;
27328 + pxds[i] = pxd;
27329 }
27330
27331 if (failed) {
27332 - free_pmds(pmds);
27333 + free_pxds(pxds);
27334 return -ENOMEM;
27335 }
27336
27337 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
27338 * preallocate which never got a corresponding vma will need to be
27339 * freed manually.
27340 */
27341 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
27342 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
27343 {
27344 int i;
27345
27346 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
27347 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
27348 pgd_t pgd = pgdp[i];
27349
27350 if (pgd_val(pgd) != 0) {
27351 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
27352 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
27353
27354 - pgdp[i] = native_make_pgd(0);
27355 + set_pgd(pgdp + i, native_make_pgd(0));
27356
27357 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
27358 - pmd_free(mm, pmd);
27359 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
27360 + pxd_free(mm, pxd);
27361 }
27362 }
27363 }
27364
27365 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
27366 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
27367 {
27368 - pud_t *pud;
27369 + pyd_t *pyd;
27370 unsigned long addr;
27371 int i;
27372
27373 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
27374 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
27375 return;
27376
27377 - pud = pud_offset(pgd, 0);
27378 +#ifdef CONFIG_X86_64
27379 + pyd = pyd_offset(mm, 0L);
27380 +#else
27381 + pyd = pyd_offset(pgd, 0L);
27382 +#endif
27383
27384 - for (addr = i = 0; i < PREALLOCATED_PMDS;
27385 - i++, pud++, addr += PUD_SIZE) {
27386 - pmd_t *pmd = pmds[i];
27387 + for (addr = i = 0; i < PREALLOCATED_PXDS;
27388 + i++, pyd++, addr += PYD_SIZE) {
27389 + pxd_t *pxd = pxds[i];
27390
27391 if (i >= KERNEL_PGD_BOUNDARY)
27392 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27393 - sizeof(pmd_t) * PTRS_PER_PMD);
27394 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27395 + sizeof(pxd_t) * PTRS_PER_PMD);
27396
27397 - pud_populate(mm, pud, pmd);
27398 + pyd_populate(mm, pyd, pxd);
27399 }
27400 }
27401
27402 pgd_t *pgd_alloc(struct mm_struct *mm)
27403 {
27404 pgd_t *pgd;
27405 - pmd_t *pmds[PREALLOCATED_PMDS];
27406 + pxd_t *pxds[PREALLOCATED_PXDS];
27407
27408 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
27409
27410 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27411
27412 mm->pgd = pgd;
27413
27414 - if (preallocate_pmds(pmds) != 0)
27415 + if (preallocate_pxds(pxds) != 0)
27416 goto out_free_pgd;
27417
27418 if (paravirt_pgd_alloc(mm) != 0)
27419 - goto out_free_pmds;
27420 + goto out_free_pxds;
27421
27422 /*
27423 * Make sure that pre-populating the pmds is atomic with
27424 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27425 spin_lock(&pgd_lock);
27426
27427 pgd_ctor(mm, pgd);
27428 - pgd_prepopulate_pmd(mm, pgd, pmds);
27429 + pgd_prepopulate_pxd(mm, pgd, pxds);
27430
27431 spin_unlock(&pgd_lock);
27432
27433 return pgd;
27434
27435 -out_free_pmds:
27436 - free_pmds(pmds);
27437 +out_free_pxds:
27438 + free_pxds(pxds);
27439 out_free_pgd:
27440 free_page((unsigned long)pgd);
27441 out:
27442 @@ -295,7 +356,7 @@ out:
27443
27444 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
27445 {
27446 - pgd_mop_up_pmds(mm, pgd);
27447 + pgd_mop_up_pxds(mm, pgd);
27448 pgd_dtor(pgd);
27449 paravirt_pgd_free(mm, pgd);
27450 free_page((unsigned long)pgd);
27451 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
27452 index a69bcb8..19068ab 100644
27453 --- a/arch/x86/mm/pgtable_32.c
27454 +++ b/arch/x86/mm/pgtable_32.c
27455 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
27456 return;
27457 }
27458 pte = pte_offset_kernel(pmd, vaddr);
27459 +
27460 + pax_open_kernel();
27461 if (pte_val(pteval))
27462 set_pte_at(&init_mm, vaddr, pte, pteval);
27463 else
27464 pte_clear(&init_mm, vaddr, pte);
27465 + pax_close_kernel();
27466
27467 /*
27468 * It's enough to flush this one mapping.
27469 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
27470 index 410531d..0f16030 100644
27471 --- a/arch/x86/mm/setup_nx.c
27472 +++ b/arch/x86/mm/setup_nx.c
27473 @@ -5,8 +5,10 @@
27474 #include <asm/pgtable.h>
27475 #include <asm/proto.h>
27476
27477 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27478 static int disable_nx __cpuinitdata;
27479
27480 +#ifndef CONFIG_PAX_PAGEEXEC
27481 /*
27482 * noexec = on|off
27483 *
27484 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
27485 return 0;
27486 }
27487 early_param("noexec", noexec_setup);
27488 +#endif
27489 +
27490 +#endif
27491
27492 void __cpuinit x86_configure_nx(void)
27493 {
27494 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27495 if (cpu_has_nx && !disable_nx)
27496 __supported_pte_mask |= _PAGE_NX;
27497 else
27498 +#endif
27499 __supported_pte_mask &= ~_PAGE_NX;
27500 }
27501
27502 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
27503 index 60f926c..a710970 100644
27504 --- a/arch/x86/mm/tlb.c
27505 +++ b/arch/x86/mm/tlb.c
27506 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
27507 BUG();
27508 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
27509 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
27510 +
27511 +#ifndef CONFIG_PAX_PER_CPU_PGD
27512 load_cr3(swapper_pg_dir);
27513 +#endif
27514 +
27515 }
27516 }
27517 EXPORT_SYMBOL_GPL(leave_mm);
27518 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
27519 index 877b9a1..a8ecf42 100644
27520 --- a/arch/x86/net/bpf_jit.S
27521 +++ b/arch/x86/net/bpf_jit.S
27522 @@ -9,6 +9,7 @@
27523 */
27524 #include <linux/linkage.h>
27525 #include <asm/dwarf2.h>
27526 +#include <asm/alternative-asm.h>
27527
27528 /*
27529 * Calling convention :
27530 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
27531 jle bpf_slow_path_word
27532 mov (SKBDATA,%rsi),%eax
27533 bswap %eax /* ntohl() */
27534 + pax_force_retaddr
27535 ret
27536
27537 sk_load_half:
27538 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
27539 jle bpf_slow_path_half
27540 movzwl (SKBDATA,%rsi),%eax
27541 rol $8,%ax # ntohs()
27542 + pax_force_retaddr
27543 ret
27544
27545 sk_load_byte:
27546 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
27547 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
27548 jle bpf_slow_path_byte
27549 movzbl (SKBDATA,%rsi),%eax
27550 + pax_force_retaddr
27551 ret
27552
27553 /**
27554 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
27555 movzbl (SKBDATA,%rsi),%ebx
27556 and $15,%bl
27557 shl $2,%bl
27558 + pax_force_retaddr
27559 ret
27560
27561 /* rsi contains offset and can be scratched */
27562 @@ -109,6 +114,7 @@ bpf_slow_path_word:
27563 js bpf_error
27564 mov -12(%rbp),%eax
27565 bswap %eax
27566 + pax_force_retaddr
27567 ret
27568
27569 bpf_slow_path_half:
27570 @@ -117,12 +123,14 @@ bpf_slow_path_half:
27571 mov -12(%rbp),%ax
27572 rol $8,%ax
27573 movzwl %ax,%eax
27574 + pax_force_retaddr
27575 ret
27576
27577 bpf_slow_path_byte:
27578 bpf_slow_path_common(1)
27579 js bpf_error
27580 movzbl -12(%rbp),%eax
27581 + pax_force_retaddr
27582 ret
27583
27584 bpf_slow_path_byte_msh:
27585 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
27586 and $15,%al
27587 shl $2,%al
27588 xchg %eax,%ebx
27589 + pax_force_retaddr
27590 ret
27591
27592 #define sk_negative_common(SIZE) \
27593 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
27594 sk_negative_common(4)
27595 mov (%rax), %eax
27596 bswap %eax
27597 + pax_force_retaddr
27598 ret
27599
27600 bpf_slow_path_half_neg:
27601 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
27602 mov (%rax),%ax
27603 rol $8,%ax
27604 movzwl %ax,%eax
27605 + pax_force_retaddr
27606 ret
27607
27608 bpf_slow_path_byte_neg:
27609 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
27610 .globl sk_load_byte_negative_offset
27611 sk_negative_common(1)
27612 movzbl (%rax), %eax
27613 + pax_force_retaddr
27614 ret
27615
27616 bpf_slow_path_byte_msh_neg:
27617 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
27618 and $15,%al
27619 shl $2,%al
27620 xchg %eax,%ebx
27621 + pax_force_retaddr
27622 ret
27623
27624 bpf_error:
27625 @@ -197,4 +210,5 @@ bpf_error:
27626 xor %eax,%eax
27627 mov -8(%rbp),%rbx
27628 leaveq
27629 + pax_force_retaddr
27630 ret
27631 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
27632 index 520d2bd..b895ef4 100644
27633 --- a/arch/x86/net/bpf_jit_comp.c
27634 +++ b/arch/x86/net/bpf_jit_comp.c
27635 @@ -11,6 +11,7 @@
27636 #include <asm/cacheflush.h>
27637 #include <linux/netdevice.h>
27638 #include <linux/filter.h>
27639 +#include <linux/random.h>
27640
27641 /*
27642 * Conventions :
27643 @@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
27644 return ptr + len;
27645 }
27646
27647 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27648 +#define MAX_INSTR_CODE_SIZE 96
27649 +#else
27650 +#define MAX_INSTR_CODE_SIZE 64
27651 +#endif
27652 +
27653 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
27654
27655 #define EMIT1(b1) EMIT(b1, 1)
27656 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
27657 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
27658 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
27659 +
27660 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27661 +/* original constant will appear in ecx */
27662 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
27663 +do { \
27664 + /* mov ecx, randkey */ \
27665 + EMIT1(0xb9); \
27666 + EMIT(_key, 4); \
27667 + /* xor ecx, randkey ^ off */ \
27668 + EMIT2(0x81, 0xf1); \
27669 + EMIT((_key) ^ (_off), 4); \
27670 +} while (0)
27671 +
27672 +#define EMIT1_off32(b1, _off) \
27673 +do { \
27674 + switch (b1) { \
27675 + case 0x05: /* add eax, imm32 */ \
27676 + case 0x2d: /* sub eax, imm32 */ \
27677 + case 0x25: /* and eax, imm32 */ \
27678 + case 0x0d: /* or eax, imm32 */ \
27679 + case 0xb8: /* mov eax, imm32 */ \
27680 + case 0x3d: /* cmp eax, imm32 */ \
27681 + case 0xa9: /* test eax, imm32 */ \
27682 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27683 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
27684 + break; \
27685 + case 0xbb: /* mov ebx, imm32 */ \
27686 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27687 + /* mov ebx, ecx */ \
27688 + EMIT2(0x89, 0xcb); \
27689 + break; \
27690 + case 0xbe: /* mov esi, imm32 */ \
27691 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27692 + /* mov esi, ecx */ \
27693 + EMIT2(0x89, 0xce); \
27694 + break; \
27695 + case 0xe9: /* jmp rel imm32 */ \
27696 + EMIT1(b1); \
27697 + EMIT(_off, 4); \
27698 + /* prevent fall-through, we're not called if off = 0 */ \
27699 + EMIT(0xcccccccc, 4); \
27700 + EMIT(0xcccccccc, 4); \
27701 + break; \
27702 + default: \
27703 + EMIT1(b1); \
27704 + EMIT(_off, 4); \
27705 + } \
27706 +} while (0)
27707 +
27708 +#define EMIT2_off32(b1, b2, _off) \
27709 +do { \
27710 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
27711 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
27712 + EMIT(randkey, 4); \
27713 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
27714 + EMIT((_off) - randkey, 4); \
27715 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
27716 + DILUTE_CONST_SEQUENCE(_off, randkey); \
27717 + /* imul eax, ecx */ \
27718 + EMIT3(0x0f, 0xaf, 0xc1); \
27719 + } else { \
27720 + EMIT2(b1, b2); \
27721 + EMIT(_off, 4); \
27722 + } \
27723 +} while (0)
27724 +#else
27725 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
27726 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
27727 +#endif
27728
27729 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
27730 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
27731 @@ -89,6 +164,24 @@ do { \
27732 #define X86_JBE 0x76
27733 #define X86_JA 0x77
27734
27735 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27736 +#define APPEND_FLOW_VERIFY() \
27737 +do { \
27738 + /* mov ecx, randkey */ \
27739 + EMIT1(0xb9); \
27740 + EMIT(randkey, 4); \
27741 + /* cmp ecx, randkey */ \
27742 + EMIT2(0x81, 0xf9); \
27743 + EMIT(randkey, 4); \
27744 + /* jz after 8 int 3s */ \
27745 + EMIT2(0x74, 0x08); \
27746 + EMIT(0xcccccccc, 4); \
27747 + EMIT(0xcccccccc, 4); \
27748 +} while (0)
27749 +#else
27750 +#define APPEND_FLOW_VERIFY() do { } while (0)
27751 +#endif
27752 +
27753 #define EMIT_COND_JMP(op, offset) \
27754 do { \
27755 if (is_near(offset)) \
27756 @@ -96,6 +189,7 @@ do { \
27757 else { \
27758 EMIT2(0x0f, op + 0x10); \
27759 EMIT(offset, 4); /* jxx .+off32 */ \
27760 + APPEND_FLOW_VERIFY(); \
27761 } \
27762 } while (0)
27763
27764 @@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
27765 set_fs(old_fs);
27766 }
27767
27768 +struct bpf_jit_work {
27769 + struct work_struct work;
27770 + void *image;
27771 +};
27772 +
27773 #define CHOOSE_LOAD_FUNC(K, func) \
27774 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
27775
27776 void bpf_jit_compile(struct sk_filter *fp)
27777 {
27778 - u8 temp[64];
27779 + u8 temp[MAX_INSTR_CODE_SIZE];
27780 u8 *prog;
27781 unsigned int proglen, oldproglen = 0;
27782 int ilen, i;
27783 @@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
27784 unsigned int *addrs;
27785 const struct sock_filter *filter = fp->insns;
27786 int flen = fp->len;
27787 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27788 + unsigned int randkey;
27789 +#endif
27790
27791 if (!bpf_jit_enable)
27792 return;
27793 @@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
27794 if (addrs == NULL)
27795 return;
27796
27797 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
27798 + if (!fp->work)
27799 + goto out;
27800 +
27801 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27802 + randkey = get_random_int();
27803 +#endif
27804 +
27805 /* Before first pass, make a rough estimation of addrs[]
27806 - * each bpf instruction is translated to less than 64 bytes
27807 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
27808 */
27809 for (proglen = 0, i = 0; i < flen; i++) {
27810 - proglen += 64;
27811 + proglen += MAX_INSTR_CODE_SIZE;
27812 addrs[i] = proglen;
27813 }
27814 cleanup_addr = proglen; /* epilogue address */
27815 @@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
27816 case BPF_S_ALU_MUL_K: /* A *= K */
27817 if (is_imm8(K))
27818 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
27819 - else {
27820 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
27821 - EMIT(K, 4);
27822 - }
27823 + else
27824 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
27825 break;
27826 case BPF_S_ALU_DIV_X: /* A /= X; */
27827 seen |= SEEN_XREG;
27828 @@ -301,13 +409,23 @@ void bpf_jit_compile(struct sk_filter *fp)
27829 break;
27830 case BPF_S_ALU_MOD_K: /* A %= K; */
27831 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
27832 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27833 + DILUTE_CONST_SEQUENCE(K, randkey);
27834 +#else
27835 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
27836 +#endif
27837 EMIT2(0xf7, 0xf1); /* div %ecx */
27838 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
27839 break;
27840 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
27841 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27842 + DILUTE_CONST_SEQUENCE(K, randkey);
27843 + // imul rax, rcx
27844 + EMIT4(0x48, 0x0f, 0xaf, 0xc1);
27845 +#else
27846 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
27847 EMIT(K, 4);
27848 +#endif
27849 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
27850 break;
27851 case BPF_S_ALU_AND_X:
27852 @@ -543,8 +661,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
27853 if (is_imm8(K)) {
27854 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
27855 } else {
27856 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
27857 - EMIT(K, 4);
27858 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
27859 }
27860 } else {
27861 EMIT2(0x89,0xde); /* mov %ebx,%esi */
27862 @@ -627,17 +744,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27863 break;
27864 default:
27865 /* hmm, too complex filter, give up with jit compiler */
27866 - goto out;
27867 + goto error;
27868 }
27869 ilen = prog - temp;
27870 if (image) {
27871 if (unlikely(proglen + ilen > oldproglen)) {
27872 pr_err("bpb_jit_compile fatal error\n");
27873 - kfree(addrs);
27874 - module_free(NULL, image);
27875 - return;
27876 + module_free_exec(NULL, image);
27877 + goto error;
27878 }
27879 + pax_open_kernel();
27880 memcpy(image + proglen, temp, ilen);
27881 + pax_close_kernel();
27882 }
27883 proglen += ilen;
27884 addrs[i] = proglen;
27885 @@ -658,11 +776,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27886 break;
27887 }
27888 if (proglen == oldproglen) {
27889 - image = module_alloc(max_t(unsigned int,
27890 - proglen,
27891 - sizeof(struct work_struct)));
27892 + image = module_alloc_exec(proglen);
27893 if (!image)
27894 - goto out;
27895 + goto error;
27896 }
27897 oldproglen = proglen;
27898 }
27899 @@ -678,7 +794,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27900 bpf_flush_icache(image, image + proglen);
27901
27902 fp->bpf_func = (void *)image;
27903 - }
27904 + } else
27905 +error:
27906 + kfree(fp->work);
27907 +
27908 out:
27909 kfree(addrs);
27910 return;
27911 @@ -686,18 +805,20 @@ out:
27912
27913 static void jit_free_defer(struct work_struct *arg)
27914 {
27915 - module_free(NULL, arg);
27916 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
27917 + kfree(arg);
27918 }
27919
27920 /* run from softirq, we must use a work_struct to call
27921 - * module_free() from process context
27922 + * module_free_exec() from process context
27923 */
27924 void bpf_jit_free(struct sk_filter *fp)
27925 {
27926 if (fp->bpf_func != sk_run_filter) {
27927 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
27928 + struct work_struct *work = &fp->work->work;
27929
27930 INIT_WORK(work, jit_free_defer);
27931 + fp->work->image = fp->bpf_func;
27932 schedule_work(work);
27933 }
27934 }
27935 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
27936 index d6aa6e8..266395a 100644
27937 --- a/arch/x86/oprofile/backtrace.c
27938 +++ b/arch/x86/oprofile/backtrace.c
27939 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
27940 struct stack_frame_ia32 *fp;
27941 unsigned long bytes;
27942
27943 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27944 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27945 if (bytes != sizeof(bufhead))
27946 return NULL;
27947
27948 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
27949 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
27950
27951 oprofile_add_trace(bufhead[0].return_address);
27952
27953 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
27954 struct stack_frame bufhead[2];
27955 unsigned long bytes;
27956
27957 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27958 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27959 if (bytes != sizeof(bufhead))
27960 return NULL;
27961
27962 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
27963 {
27964 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
27965
27966 - if (!user_mode_vm(regs)) {
27967 + if (!user_mode(regs)) {
27968 unsigned long stack = kernel_stack_pointer(regs);
27969 if (depth)
27970 dump_trace(NULL, regs, (unsigned long *)stack, 0,
27971 diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
27972 index 192397c..5ba6f9e 100644
27973 --- a/arch/x86/pci/acpi.c
27974 +++ b/arch/x86/pci/acpi.c
27975 @@ -568,7 +568,7 @@ int __init pci_acpi_init(void)
27976 acpi_irq_penalty_init();
27977 pcibios_enable_irq = acpi_pci_irq_enable;
27978 pcibios_disable_irq = acpi_pci_irq_disable;
27979 - x86_init.pci.init_irq = x86_init_noop;
27980 + *(void **)&x86_init.pci.init_irq = x86_init_noop;
27981
27982 if (pci_routeirq) {
27983 /*
27984 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
27985 index e14a2ff..3fd6b58 100644
27986 --- a/arch/x86/pci/mrst.c
27987 +++ b/arch/x86/pci/mrst.c
27988 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
27989 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
27990 pci_mmcfg_late_init();
27991 pcibios_enable_irq = mrst_pci_irq_enable;
27992 - pci_root_ops = pci_mrst_ops;
27993 + pax_open_kernel();
27994 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
27995 + pax_close_kernel();
27996 pci_soc_mode = 1;
27997 /* Continue with standard init */
27998 return 1;
27999 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
28000 index da8fe05..7ee6704 100644
28001 --- a/arch/x86/pci/pcbios.c
28002 +++ b/arch/x86/pci/pcbios.c
28003 @@ -79,50 +79,93 @@ union bios32 {
28004 static struct {
28005 unsigned long address;
28006 unsigned short segment;
28007 -} bios32_indirect = { 0, __KERNEL_CS };
28008 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
28009
28010 /*
28011 * Returns the entry point for the given service, NULL on error
28012 */
28013
28014 -static unsigned long bios32_service(unsigned long service)
28015 +static unsigned long __devinit bios32_service(unsigned long service)
28016 {
28017 unsigned char return_code; /* %al */
28018 unsigned long address; /* %ebx */
28019 unsigned long length; /* %ecx */
28020 unsigned long entry; /* %edx */
28021 unsigned long flags;
28022 + struct desc_struct d, *gdt;
28023
28024 local_irq_save(flags);
28025 - __asm__("lcall *(%%edi); cld"
28026 +
28027 + gdt = get_cpu_gdt_table(smp_processor_id());
28028 +
28029 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
28030 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
28031 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
28032 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
28033 +
28034 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
28035 : "=a" (return_code),
28036 "=b" (address),
28037 "=c" (length),
28038 "=d" (entry)
28039 : "0" (service),
28040 "1" (0),
28041 - "D" (&bios32_indirect));
28042 + "D" (&bios32_indirect),
28043 + "r"(__PCIBIOS_DS)
28044 + : "memory");
28045 +
28046 + pax_open_kernel();
28047 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
28048 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
28049 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
28050 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
28051 + pax_close_kernel();
28052 +
28053 local_irq_restore(flags);
28054
28055 switch (return_code) {
28056 - case 0:
28057 - return address + entry;
28058 - case 0x80: /* Not present */
28059 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
28060 - return 0;
28061 - default: /* Shouldn't happen */
28062 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
28063 - service, return_code);
28064 + case 0: {
28065 + int cpu;
28066 + unsigned char flags;
28067 +
28068 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
28069 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
28070 + printk(KERN_WARNING "bios32_service: not valid\n");
28071 return 0;
28072 + }
28073 + address = address + PAGE_OFFSET;
28074 + length += 16UL; /* some BIOSs underreport this... */
28075 + flags = 4;
28076 + if (length >= 64*1024*1024) {
28077 + length >>= PAGE_SHIFT;
28078 + flags |= 8;
28079 + }
28080 +
28081 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28082 + gdt = get_cpu_gdt_table(cpu);
28083 + pack_descriptor(&d, address, length, 0x9b, flags);
28084 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
28085 + pack_descriptor(&d, address, length, 0x93, flags);
28086 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
28087 + }
28088 + return entry;
28089 + }
28090 + case 0x80: /* Not present */
28091 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
28092 + return 0;
28093 + default: /* Shouldn't happen */
28094 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
28095 + service, return_code);
28096 + return 0;
28097 }
28098 }
28099
28100 static struct {
28101 unsigned long address;
28102 unsigned short segment;
28103 -} pci_indirect = { 0, __KERNEL_CS };
28104 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
28105
28106 -static int pci_bios_present;
28107 +static int pci_bios_present __read_only;
28108
28109 static int __devinit check_pcibios(void)
28110 {
28111 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
28112 unsigned long flags, pcibios_entry;
28113
28114 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
28115 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
28116 + pci_indirect.address = pcibios_entry;
28117
28118 local_irq_save(flags);
28119 - __asm__(
28120 - "lcall *(%%edi); cld\n\t"
28121 + __asm__("movw %w6, %%ds\n\t"
28122 + "lcall *%%ss:(%%edi); cld\n\t"
28123 + "push %%ss\n\t"
28124 + "pop %%ds\n\t"
28125 "jc 1f\n\t"
28126 "xor %%ah, %%ah\n"
28127 "1:"
28128 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
28129 "=b" (ebx),
28130 "=c" (ecx)
28131 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
28132 - "D" (&pci_indirect)
28133 + "D" (&pci_indirect),
28134 + "r" (__PCIBIOS_DS)
28135 : "memory");
28136 local_irq_restore(flags);
28137
28138 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28139
28140 switch (len) {
28141 case 1:
28142 - __asm__("lcall *(%%esi); cld\n\t"
28143 + __asm__("movw %w6, %%ds\n\t"
28144 + "lcall *%%ss:(%%esi); cld\n\t"
28145 + "push %%ss\n\t"
28146 + "pop %%ds\n\t"
28147 "jc 1f\n\t"
28148 "xor %%ah, %%ah\n"
28149 "1:"
28150 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28151 : "1" (PCIBIOS_READ_CONFIG_BYTE),
28152 "b" (bx),
28153 "D" ((long)reg),
28154 - "S" (&pci_indirect));
28155 + "S" (&pci_indirect),
28156 + "r" (__PCIBIOS_DS));
28157 /*
28158 * Zero-extend the result beyond 8 bits, do not trust the
28159 * BIOS having done it:
28160 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28161 *value &= 0xff;
28162 break;
28163 case 2:
28164 - __asm__("lcall *(%%esi); cld\n\t"
28165 + __asm__("movw %w6, %%ds\n\t"
28166 + "lcall *%%ss:(%%esi); cld\n\t"
28167 + "push %%ss\n\t"
28168 + "pop %%ds\n\t"
28169 "jc 1f\n\t"
28170 "xor %%ah, %%ah\n"
28171 "1:"
28172 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28173 : "1" (PCIBIOS_READ_CONFIG_WORD),
28174 "b" (bx),
28175 "D" ((long)reg),
28176 - "S" (&pci_indirect));
28177 + "S" (&pci_indirect),
28178 + "r" (__PCIBIOS_DS));
28179 /*
28180 * Zero-extend the result beyond 16 bits, do not trust the
28181 * BIOS having done it:
28182 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28183 *value &= 0xffff;
28184 break;
28185 case 4:
28186 - __asm__("lcall *(%%esi); cld\n\t"
28187 + __asm__("movw %w6, %%ds\n\t"
28188 + "lcall *%%ss:(%%esi); cld\n\t"
28189 + "push %%ss\n\t"
28190 + "pop %%ds\n\t"
28191 "jc 1f\n\t"
28192 "xor %%ah, %%ah\n"
28193 "1:"
28194 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28195 : "1" (PCIBIOS_READ_CONFIG_DWORD),
28196 "b" (bx),
28197 "D" ((long)reg),
28198 - "S" (&pci_indirect));
28199 + "S" (&pci_indirect),
28200 + "r" (__PCIBIOS_DS));
28201 break;
28202 }
28203
28204 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28205
28206 switch (len) {
28207 case 1:
28208 - __asm__("lcall *(%%esi); cld\n\t"
28209 + __asm__("movw %w6, %%ds\n\t"
28210 + "lcall *%%ss:(%%esi); cld\n\t"
28211 + "push %%ss\n\t"
28212 + "pop %%ds\n\t"
28213 "jc 1f\n\t"
28214 "xor %%ah, %%ah\n"
28215 "1:"
28216 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28217 "c" (value),
28218 "b" (bx),
28219 "D" ((long)reg),
28220 - "S" (&pci_indirect));
28221 + "S" (&pci_indirect),
28222 + "r" (__PCIBIOS_DS));
28223 break;
28224 case 2:
28225 - __asm__("lcall *(%%esi); cld\n\t"
28226 + __asm__("movw %w6, %%ds\n\t"
28227 + "lcall *%%ss:(%%esi); cld\n\t"
28228 + "push %%ss\n\t"
28229 + "pop %%ds\n\t"
28230 "jc 1f\n\t"
28231 "xor %%ah, %%ah\n"
28232 "1:"
28233 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28234 "c" (value),
28235 "b" (bx),
28236 "D" ((long)reg),
28237 - "S" (&pci_indirect));
28238 + "S" (&pci_indirect),
28239 + "r" (__PCIBIOS_DS));
28240 break;
28241 case 4:
28242 - __asm__("lcall *(%%esi); cld\n\t"
28243 + __asm__("movw %w6, %%ds\n\t"
28244 + "lcall *%%ss:(%%esi); cld\n\t"
28245 + "push %%ss\n\t"
28246 + "pop %%ds\n\t"
28247 "jc 1f\n\t"
28248 "xor %%ah, %%ah\n"
28249 "1:"
28250 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28251 "c" (value),
28252 "b" (bx),
28253 "D" ((long)reg),
28254 - "S" (&pci_indirect));
28255 + "S" (&pci_indirect),
28256 + "r" (__PCIBIOS_DS));
28257 break;
28258 }
28259
28260 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
28261
28262 DBG("PCI: Fetching IRQ routing table... ");
28263 __asm__("push %%es\n\t"
28264 + "movw %w8, %%ds\n\t"
28265 "push %%ds\n\t"
28266 "pop %%es\n\t"
28267 - "lcall *(%%esi); cld\n\t"
28268 + "lcall *%%ss:(%%esi); cld\n\t"
28269 "pop %%es\n\t"
28270 + "push %%ss\n\t"
28271 + "pop %%ds\n"
28272 "jc 1f\n\t"
28273 "xor %%ah, %%ah\n"
28274 "1:"
28275 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
28276 "1" (0),
28277 "D" ((long) &opt),
28278 "S" (&pci_indirect),
28279 - "m" (opt)
28280 + "m" (opt),
28281 + "r" (__PCIBIOS_DS)
28282 : "memory");
28283 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
28284 if (ret & 0xff00)
28285 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
28286 {
28287 int ret;
28288
28289 - __asm__("lcall *(%%esi); cld\n\t"
28290 + __asm__("movw %w5, %%ds\n\t"
28291 + "lcall *%%ss:(%%esi); cld\n\t"
28292 + "push %%ss\n\t"
28293 + "pop %%ds\n"
28294 "jc 1f\n\t"
28295 "xor %%ah, %%ah\n"
28296 "1:"
28297 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
28298 : "0" (PCIBIOS_SET_PCI_HW_INT),
28299 "b" ((dev->bus->number << 8) | dev->devfn),
28300 "c" ((irq << 8) | (pin + 10)),
28301 - "S" (&pci_indirect));
28302 + "S" (&pci_indirect),
28303 + "r" (__PCIBIOS_DS));
28304 return !(ret & 0xff00);
28305 }
28306 EXPORT_SYMBOL(pcibios_set_irq_routing);
28307 diff --git a/arch/x86/pci/xen.c b/arch/x86/pci/xen.c
28308 index 56ab749..3cb792a 100644
28309 --- a/arch/x86/pci/xen.c
28310 +++ b/arch/x86/pci/xen.c
28311 @@ -395,9 +395,9 @@ int __init pci_xen_init(void)
28312 #endif
28313
28314 #ifdef CONFIG_PCI_MSI
28315 - x86_msi.setup_msi_irqs = xen_setup_msi_irqs;
28316 - x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28317 - x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
28318 + *(void **)&x86_msi.setup_msi_irqs = xen_setup_msi_irqs;
28319 + *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28320 + *(void **)&x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
28321 #endif
28322 return 0;
28323 }
28324 @@ -416,8 +416,8 @@ int __init pci_xen_hvm_init(void)
28325 #endif
28326
28327 #ifdef CONFIG_PCI_MSI
28328 - x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs;
28329 - x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28330 + *(void **)&x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs;
28331 + *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28332 #endif
28333 return 0;
28334 }
28335 @@ -474,9 +474,9 @@ int __init pci_xen_initial_domain(void)
28336 int irq;
28337
28338 #ifdef CONFIG_PCI_MSI
28339 - x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs;
28340 - x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28341 - x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs;
28342 + *(void **)&x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs;
28343 + *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28344 + *(void **)&x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs;
28345 #endif
28346 xen_setup_acpi_sci();
28347 __acpi_register_gsi = acpi_register_gsi_xen;
28348 diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
28349 index 77cf009..7fe44c8 100644
28350 --- a/arch/x86/platform/efi/efi.c
28351 +++ b/arch/x86/platform/efi/efi.c
28352 @@ -746,8 +746,8 @@ void __init efi_init(void)
28353
28354 #ifdef CONFIG_X86_32
28355 if (efi_is_native()) {
28356 - x86_platform.get_wallclock = efi_get_time;
28357 - x86_platform.set_wallclock = efi_set_rtc_mmss;
28358 + *(void **)&x86_platform.get_wallclock = efi_get_time;
28359 + *(void **)&x86_platform.set_wallclock = efi_set_rtc_mmss;
28360 }
28361 #endif
28362
28363 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
28364 index 40e4469..1ab536e 100644
28365 --- a/arch/x86/platform/efi/efi_32.c
28366 +++ b/arch/x86/platform/efi/efi_32.c
28367 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
28368 {
28369 struct desc_ptr gdt_descr;
28370
28371 +#ifdef CONFIG_PAX_KERNEXEC
28372 + struct desc_struct d;
28373 +#endif
28374 +
28375 local_irq_save(efi_rt_eflags);
28376
28377 load_cr3(initial_page_table);
28378 __flush_tlb_all();
28379
28380 +#ifdef CONFIG_PAX_KERNEXEC
28381 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
28382 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28383 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
28384 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28385 +#endif
28386 +
28387 gdt_descr.address = __pa(get_cpu_gdt_table(0));
28388 gdt_descr.size = GDT_SIZE - 1;
28389 load_gdt(&gdt_descr);
28390 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
28391 {
28392 struct desc_ptr gdt_descr;
28393
28394 +#ifdef CONFIG_PAX_KERNEXEC
28395 + struct desc_struct d;
28396 +
28397 + memset(&d, 0, sizeof d);
28398 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28399 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28400 +#endif
28401 +
28402 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
28403 gdt_descr.size = GDT_SIZE - 1;
28404 load_gdt(&gdt_descr);
28405 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
28406 index fbe66e6..eae5e38 100644
28407 --- a/arch/x86/platform/efi/efi_stub_32.S
28408 +++ b/arch/x86/platform/efi/efi_stub_32.S
28409 @@ -6,7 +6,9 @@
28410 */
28411
28412 #include <linux/linkage.h>
28413 +#include <linux/init.h>
28414 #include <asm/page_types.h>
28415 +#include <asm/segment.h>
28416
28417 /*
28418 * efi_call_phys(void *, ...) is a function with variable parameters.
28419 @@ -20,7 +22,7 @@
28420 * service functions will comply with gcc calling convention, too.
28421 */
28422
28423 -.text
28424 +__INIT
28425 ENTRY(efi_call_phys)
28426 /*
28427 * 0. The function can only be called in Linux kernel. So CS has been
28428 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
28429 * The mapping of lower virtual memory has been created in prelog and
28430 * epilog.
28431 */
28432 - movl $1f, %edx
28433 - subl $__PAGE_OFFSET, %edx
28434 - jmp *%edx
28435 +#ifdef CONFIG_PAX_KERNEXEC
28436 + movl $(__KERNEXEC_EFI_DS), %edx
28437 + mov %edx, %ds
28438 + mov %edx, %es
28439 + mov %edx, %ss
28440 + addl $2f,(1f)
28441 + ljmp *(1f)
28442 +
28443 +__INITDATA
28444 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
28445 +.previous
28446 +
28447 +2:
28448 + subl $2b,(1b)
28449 +#else
28450 + jmp 1f-__PAGE_OFFSET
28451 1:
28452 +#endif
28453
28454 /*
28455 * 2. Now on the top of stack is the return
28456 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
28457 * parameter 2, ..., param n. To make things easy, we save the return
28458 * address of efi_call_phys in a global variable.
28459 */
28460 - popl %edx
28461 - movl %edx, saved_return_addr
28462 - /* get the function pointer into ECX*/
28463 - popl %ecx
28464 - movl %ecx, efi_rt_function_ptr
28465 - movl $2f, %edx
28466 - subl $__PAGE_OFFSET, %edx
28467 - pushl %edx
28468 + popl (saved_return_addr)
28469 + popl (efi_rt_function_ptr)
28470
28471 /*
28472 * 3. Clear PG bit in %CR0.
28473 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
28474 /*
28475 * 5. Call the physical function.
28476 */
28477 - jmp *%ecx
28478 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
28479
28480 -2:
28481 /*
28482 * 6. After EFI runtime service returns, control will return to
28483 * following instruction. We'd better readjust stack pointer first.
28484 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
28485 movl %cr0, %edx
28486 orl $0x80000000, %edx
28487 movl %edx, %cr0
28488 - jmp 1f
28489 -1:
28490 +
28491 /*
28492 * 8. Now restore the virtual mode from flat mode by
28493 * adding EIP with PAGE_OFFSET.
28494 */
28495 - movl $1f, %edx
28496 - jmp *%edx
28497 +#ifdef CONFIG_PAX_KERNEXEC
28498 + movl $(__KERNEL_DS), %edx
28499 + mov %edx, %ds
28500 + mov %edx, %es
28501 + mov %edx, %ss
28502 + ljmp $(__KERNEL_CS),$1f
28503 +#else
28504 + jmp 1f+__PAGE_OFFSET
28505 +#endif
28506 1:
28507
28508 /*
28509 * 9. Balance the stack. And because EAX contain the return value,
28510 * we'd better not clobber it.
28511 */
28512 - leal efi_rt_function_ptr, %edx
28513 - movl (%edx), %ecx
28514 - pushl %ecx
28515 + pushl (efi_rt_function_ptr)
28516
28517 /*
28518 - * 10. Push the saved return address onto the stack and return.
28519 + * 10. Return to the saved return address.
28520 */
28521 - leal saved_return_addr, %edx
28522 - movl (%edx), %ecx
28523 - pushl %ecx
28524 - ret
28525 + jmpl *(saved_return_addr)
28526 ENDPROC(efi_call_phys)
28527 .previous
28528
28529 -.data
28530 +__INITDATA
28531 saved_return_addr:
28532 .long 0
28533 efi_rt_function_ptr:
28534 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
28535 index 4c07cca..2c8427d 100644
28536 --- a/arch/x86/platform/efi/efi_stub_64.S
28537 +++ b/arch/x86/platform/efi/efi_stub_64.S
28538 @@ -7,6 +7,7 @@
28539 */
28540
28541 #include <linux/linkage.h>
28542 +#include <asm/alternative-asm.h>
28543
28544 #define SAVE_XMM \
28545 mov %rsp, %rax; \
28546 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
28547 call *%rdi
28548 addq $32, %rsp
28549 RESTORE_XMM
28550 + pax_force_retaddr 0, 1
28551 ret
28552 ENDPROC(efi_call0)
28553
28554 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
28555 call *%rdi
28556 addq $32, %rsp
28557 RESTORE_XMM
28558 + pax_force_retaddr 0, 1
28559 ret
28560 ENDPROC(efi_call1)
28561
28562 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
28563 call *%rdi
28564 addq $32, %rsp
28565 RESTORE_XMM
28566 + pax_force_retaddr 0, 1
28567 ret
28568 ENDPROC(efi_call2)
28569
28570 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
28571 call *%rdi
28572 addq $32, %rsp
28573 RESTORE_XMM
28574 + pax_force_retaddr 0, 1
28575 ret
28576 ENDPROC(efi_call3)
28577
28578 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
28579 call *%rdi
28580 addq $32, %rsp
28581 RESTORE_XMM
28582 + pax_force_retaddr 0, 1
28583 ret
28584 ENDPROC(efi_call4)
28585
28586 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
28587 call *%rdi
28588 addq $48, %rsp
28589 RESTORE_XMM
28590 + pax_force_retaddr 0, 1
28591 ret
28592 ENDPROC(efi_call5)
28593
28594 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
28595 call *%rdi
28596 addq $48, %rsp
28597 RESTORE_XMM
28598 + pax_force_retaddr 0, 1
28599 ret
28600 ENDPROC(efi_call6)
28601 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
28602 index fd41a92..bc8091d 100644
28603 --- a/arch/x86/platform/mrst/mrst.c
28604 +++ b/arch/x86/platform/mrst/mrst.c
28605 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
28606 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
28607 int sfi_mrtc_num;
28608
28609 -static void mrst_power_off(void)
28610 +static __noreturn void mrst_power_off(void)
28611 {
28612 + BUG();
28613 }
28614
28615 -static void mrst_reboot(void)
28616 +static __noreturn void mrst_reboot(void)
28617 {
28618 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
28619 + BUG();
28620 }
28621
28622 /* parse all the mtimer info to a static mtimer array */
28623 @@ -233,14 +235,14 @@ static void __init mrst_time_init(void)
28624 case MRST_TIMER_APBT_ONLY:
28625 break;
28626 case MRST_TIMER_LAPIC_APBT:
28627 - x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28628 - x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28629 + *(void **)&x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28630 + *(void **)&x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28631 break;
28632 default:
28633 if (!boot_cpu_has(X86_FEATURE_ARAT))
28634 break;
28635 - x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28636 - x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28637 + *(void **)&x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28638 + *(void **)&x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28639 return;
28640 }
28641 /* we need at least one APB timer */
28642 @@ -282,35 +284,35 @@ static unsigned char mrst_get_nmi_reason(void)
28643 */
28644 void __init x86_mrst_early_setup(void)
28645 {
28646 - x86_init.resources.probe_roms = x86_init_noop;
28647 - x86_init.resources.reserve_resources = x86_init_noop;
28648 + *(void **)&x86_init.resources.probe_roms = x86_init_noop;
28649 + *(void **)&x86_init.resources.reserve_resources = x86_init_noop;
28650
28651 - x86_init.timers.timer_init = mrst_time_init;
28652 - x86_init.timers.setup_percpu_clockev = x86_init_noop;
28653 + *(void **)&x86_init.timers.timer_init = mrst_time_init;
28654 + *(void **)&x86_init.timers.setup_percpu_clockev = x86_init_noop;
28655
28656 - x86_init.irqs.pre_vector_init = x86_init_noop;
28657 + *(void **)&x86_init.irqs.pre_vector_init = x86_init_noop;
28658
28659 - x86_init.oem.arch_setup = mrst_arch_setup;
28660 + *(void **)&x86_init.oem.arch_setup = mrst_arch_setup;
28661
28662 - x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
28663 + *(void **)&x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
28664
28665 - x86_platform.calibrate_tsc = mrst_calibrate_tsc;
28666 - x86_platform.i8042_detect = mrst_i8042_detect;
28667 - x86_init.timers.wallclock_init = mrst_rtc_init;
28668 - x86_platform.get_nmi_reason = mrst_get_nmi_reason;
28669 + *(void **)&x86_platform.calibrate_tsc = mrst_calibrate_tsc;
28670 + *(void **)&x86_platform.i8042_detect = mrst_i8042_detect;
28671 + *(void **)&x86_init.timers.wallclock_init = mrst_rtc_init;
28672 + *(void **)&x86_platform.get_nmi_reason = mrst_get_nmi_reason;
28673
28674 - x86_init.pci.init = pci_mrst_init;
28675 - x86_init.pci.fixup_irqs = x86_init_noop;
28676 + *(void **)&x86_init.pci.init = pci_mrst_init;
28677 + *(void **)&x86_init.pci.fixup_irqs = x86_init_noop;
28678
28679 legacy_pic = &null_legacy_pic;
28680
28681 /* Moorestown specific power_off/restart method */
28682 pm_power_off = mrst_power_off;
28683 - machine_ops.emergency_restart = mrst_reboot;
28684 + *(void **)&machine_ops.emergency_restart = mrst_reboot;
28685
28686 /* Avoid searching for BIOS MP tables */
28687 - x86_init.mpparse.find_smp_config = x86_init_noop;
28688 - x86_init.mpparse.get_smp_config = x86_init_uint_noop;
28689 + *(void **)&x86_init.mpparse.find_smp_config = x86_init_noop;
28690 + *(void **)&x86_init.mpparse.get_smp_config = x86_init_uint_noop;
28691 set_bit(MP_BUS_ISA, mp_bus_not_pci);
28692 }
28693
28694 diff --git a/arch/x86/platform/mrst/vrtc.c b/arch/x86/platform/mrst/vrtc.c
28695 index 225bd0f..22e8086 100644
28696 --- a/arch/x86/platform/mrst/vrtc.c
28697 +++ b/arch/x86/platform/mrst/vrtc.c
28698 @@ -120,8 +120,8 @@ void __init mrst_rtc_init(void)
28699
28700 vrtc_virt_base = (void __iomem *)set_fixmap_offset_nocache(FIX_LNW_VRTC,
28701 vrtc_paddr);
28702 - x86_platform.get_wallclock = vrtc_get_time;
28703 - x86_platform.set_wallclock = vrtc_set_mmss;
28704 + *(void **)&x86_platform.get_wallclock = vrtc_get_time;
28705 + *(void **)&x86_platform.set_wallclock = vrtc_set_mmss;
28706 }
28707
28708 /*
28709 diff --git a/arch/x86/platform/olpc/olpc.c b/arch/x86/platform/olpc/olpc.c
28710 index 2737608..0d62cc2 100644
28711 --- a/arch/x86/platform/olpc/olpc.c
28712 +++ b/arch/x86/platform/olpc/olpc.c
28713 @@ -395,7 +395,7 @@ static int __init olpc_init(void)
28714 * XO-1 only. */
28715 if (olpc_platform_info.boardrev < olpc_board_pre(0xd0) &&
28716 !cs5535_has_vsa2())
28717 - x86_init.pci.arch_init = pci_olpc_init;
28718 + *(void **)&x86_init.pci.arch_init = pci_olpc_init;
28719 #endif
28720
28721 if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) { /* XO-1 */
28722 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
28723 index d6ee929..3637cb5 100644
28724 --- a/arch/x86/platform/olpc/olpc_dt.c
28725 +++ b/arch/x86/platform/olpc/olpc_dt.c
28726 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
28727 return res;
28728 }
28729
28730 -static struct of_pdt_ops prom_olpc_ops __initdata = {
28731 +static struct of_pdt_ops prom_olpc_ops __initconst = {
28732 .nextprop = olpc_dt_nextprop,
28733 .getproplen = olpc_dt_getproplen,
28734 .getproperty = olpc_dt_getproperty,
28735 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
28736 index 218cdb1..c1178eb 100644
28737 --- a/arch/x86/power/cpu.c
28738 +++ b/arch/x86/power/cpu.c
28739 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
28740 static void fix_processor_context(void)
28741 {
28742 int cpu = smp_processor_id();
28743 - struct tss_struct *t = &per_cpu(init_tss, cpu);
28744 + struct tss_struct *t = init_tss + cpu;
28745
28746 set_tss_desc(cpu, t); /*
28747 * This just modifies memory; should not be
28748 @@ -142,8 +142,6 @@ static void fix_processor_context(void)
28749 */
28750
28751 #ifdef CONFIG_X86_64
28752 - get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
28753 -
28754 syscall_init(); /* This sets MSR_*STAR and related */
28755 #endif
28756 load_TR_desc(); /* This does ltr */
28757 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
28758 index cbca565..bae7133 100644
28759 --- a/arch/x86/realmode/init.c
28760 +++ b/arch/x86/realmode/init.c
28761 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
28762 __va(real_mode_header->trampoline_header);
28763
28764 #ifdef CONFIG_X86_32
28765 - trampoline_header->start = __pa(startup_32_smp);
28766 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
28767 +
28768 +#ifdef CONFIG_PAX_KERNEXEC
28769 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
28770 +#endif
28771 +
28772 + trampoline_header->boot_cs = __BOOT_CS;
28773 trampoline_header->gdt_limit = __BOOT_DS + 7;
28774 trampoline_header->gdt_base = __pa(boot_gdt);
28775 #else
28776 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
28777 index 8869287..d577672 100644
28778 --- a/arch/x86/realmode/rm/Makefile
28779 +++ b/arch/x86/realmode/rm/Makefile
28780 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
28781 $(call cc-option, -fno-unit-at-a-time)) \
28782 $(call cc-option, -fno-stack-protector) \
28783 $(call cc-option, -mpreferred-stack-boundary=2)
28784 +ifdef CONSTIFY_PLUGIN
28785 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
28786 +endif
28787 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
28788 GCOV_PROFILE := n
28789 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
28790 index a28221d..93c40f1 100644
28791 --- a/arch/x86/realmode/rm/header.S
28792 +++ b/arch/x86/realmode/rm/header.S
28793 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
28794 #endif
28795 /* APM/BIOS reboot */
28796 .long pa_machine_real_restart_asm
28797 -#ifdef CONFIG_X86_64
28798 +#ifdef CONFIG_X86_32
28799 + .long __KERNEL_CS
28800 +#else
28801 .long __KERNEL32_CS
28802 #endif
28803 END(real_mode_header)
28804 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
28805 index c1b2791..f9e31c7 100644
28806 --- a/arch/x86/realmode/rm/trampoline_32.S
28807 +++ b/arch/x86/realmode/rm/trampoline_32.S
28808 @@ -25,6 +25,12 @@
28809 #include <asm/page_types.h>
28810 #include "realmode.h"
28811
28812 +#ifdef CONFIG_PAX_KERNEXEC
28813 +#define ta(X) (X)
28814 +#else
28815 +#define ta(X) (pa_ ## X)
28816 +#endif
28817 +
28818 .text
28819 .code16
28820
28821 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
28822
28823 cli # We should be safe anyway
28824
28825 - movl tr_start, %eax # where we need to go
28826 -
28827 movl $0xA5A5A5A5, trampoline_status
28828 # write marker for master knows we're running
28829
28830 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
28831 movw $1, %dx # protected mode (PE) bit
28832 lmsw %dx # into protected mode
28833
28834 - ljmpl $__BOOT_CS, $pa_startup_32
28835 + ljmpl *(trampoline_header)
28836
28837 .section ".text32","ax"
28838 .code32
28839 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
28840 .balign 8
28841 GLOBAL(trampoline_header)
28842 tr_start: .space 4
28843 - tr_gdt_pad: .space 2
28844 + tr_boot_cs: .space 2
28845 tr_gdt: .space 6
28846 END(trampoline_header)
28847
28848 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
28849 index bb360dc..3e5945f 100644
28850 --- a/arch/x86/realmode/rm/trampoline_64.S
28851 +++ b/arch/x86/realmode/rm/trampoline_64.S
28852 @@ -107,7 +107,7 @@ ENTRY(startup_32)
28853 wrmsr
28854
28855 # Enable paging and in turn activate Long Mode
28856 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
28857 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
28858 movl %eax, %cr0
28859
28860 /*
28861 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
28862 index 5a1847d..deccb30 100644
28863 --- a/arch/x86/tools/relocs.c
28864 +++ b/arch/x86/tools/relocs.c
28865 @@ -12,10 +12,13 @@
28866 #include <regex.h>
28867 #include <tools/le_byteshift.h>
28868
28869 +#include "../../../include/generated/autoconf.h"
28870 +
28871 static void die(char *fmt, ...);
28872
28873 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
28874 static Elf32_Ehdr ehdr;
28875 +static Elf32_Phdr *phdr;
28876 static unsigned long reloc_count, reloc_idx;
28877 static unsigned long *relocs;
28878 static unsigned long reloc16_count, reloc16_idx;
28879 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
28880 }
28881 }
28882
28883 +static void read_phdrs(FILE *fp)
28884 +{
28885 + unsigned int i;
28886 +
28887 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
28888 + if (!phdr) {
28889 + die("Unable to allocate %d program headers\n",
28890 + ehdr.e_phnum);
28891 + }
28892 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
28893 + die("Seek to %d failed: %s\n",
28894 + ehdr.e_phoff, strerror(errno));
28895 + }
28896 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
28897 + die("Cannot read ELF program headers: %s\n",
28898 + strerror(errno));
28899 + }
28900 + for(i = 0; i < ehdr.e_phnum; i++) {
28901 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
28902 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
28903 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
28904 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
28905 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
28906 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
28907 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
28908 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
28909 + }
28910 +
28911 +}
28912 +
28913 static void read_shdrs(FILE *fp)
28914 {
28915 - int i;
28916 + unsigned int i;
28917 Elf32_Shdr shdr;
28918
28919 secs = calloc(ehdr.e_shnum, sizeof(struct section));
28920 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
28921
28922 static void read_strtabs(FILE *fp)
28923 {
28924 - int i;
28925 + unsigned int i;
28926 for (i = 0; i < ehdr.e_shnum; i++) {
28927 struct section *sec = &secs[i];
28928 if (sec->shdr.sh_type != SHT_STRTAB) {
28929 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
28930
28931 static void read_symtabs(FILE *fp)
28932 {
28933 - int i,j;
28934 + unsigned int i,j;
28935 for (i = 0; i < ehdr.e_shnum; i++) {
28936 struct section *sec = &secs[i];
28937 if (sec->shdr.sh_type != SHT_SYMTAB) {
28938 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
28939 }
28940
28941
28942 -static void read_relocs(FILE *fp)
28943 +static void read_relocs(FILE *fp, int use_real_mode)
28944 {
28945 - int i,j;
28946 + unsigned int i,j;
28947 + uint32_t base;
28948 +
28949 for (i = 0; i < ehdr.e_shnum; i++) {
28950 struct section *sec = &secs[i];
28951 if (sec->shdr.sh_type != SHT_REL) {
28952 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
28953 die("Cannot read symbol table: %s\n",
28954 strerror(errno));
28955 }
28956 + base = 0;
28957 +
28958 +#ifdef CONFIG_X86_32
28959 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
28960 + if (phdr[j].p_type != PT_LOAD )
28961 + continue;
28962 + 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)
28963 + continue;
28964 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
28965 + break;
28966 + }
28967 +#endif
28968 +
28969 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
28970 Elf32_Rel *rel = &sec->reltab[j];
28971 - rel->r_offset = elf32_to_cpu(rel->r_offset);
28972 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
28973 rel->r_info = elf32_to_cpu(rel->r_info);
28974 }
28975 }
28976 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
28977
28978 static void print_absolute_symbols(void)
28979 {
28980 - int i;
28981 + unsigned int i;
28982 printf("Absolute symbols\n");
28983 printf(" Num: Value Size Type Bind Visibility Name\n");
28984 for (i = 0; i < ehdr.e_shnum; i++) {
28985 struct section *sec = &secs[i];
28986 char *sym_strtab;
28987 - int j;
28988 + unsigned int j;
28989
28990 if (sec->shdr.sh_type != SHT_SYMTAB) {
28991 continue;
28992 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
28993
28994 static void print_absolute_relocs(void)
28995 {
28996 - int i, printed = 0;
28997 + unsigned int i, printed = 0;
28998
28999 for (i = 0; i < ehdr.e_shnum; i++) {
29000 struct section *sec = &secs[i];
29001 struct section *sec_applies, *sec_symtab;
29002 char *sym_strtab;
29003 Elf32_Sym *sh_symtab;
29004 - int j;
29005 + unsigned int j;
29006 if (sec->shdr.sh_type != SHT_REL) {
29007 continue;
29008 }
29009 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
29010 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
29011 int use_real_mode)
29012 {
29013 - int i;
29014 + unsigned int i;
29015 /* Walk through the relocations */
29016 for (i = 0; i < ehdr.e_shnum; i++) {
29017 char *sym_strtab;
29018 Elf32_Sym *sh_symtab;
29019 struct section *sec_applies, *sec_symtab;
29020 - int j;
29021 + unsigned int j;
29022 struct section *sec = &secs[i];
29023
29024 if (sec->shdr.sh_type != SHT_REL) {
29025 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
29026 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
29027 r_type = ELF32_R_TYPE(rel->r_info);
29028
29029 + if (!use_real_mode) {
29030 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
29031 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
29032 + continue;
29033 +
29034 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
29035 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
29036 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
29037 + continue;
29038 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
29039 + continue;
29040 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
29041 + continue;
29042 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
29043 + continue;
29044 +#endif
29045 + }
29046 +
29047 shn_abs = sym->st_shndx == SHN_ABS;
29048
29049 switch (r_type) {
29050 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
29051
29052 static void emit_relocs(int as_text, int use_real_mode)
29053 {
29054 - int i;
29055 + unsigned int i;
29056 /* Count how many relocations I have and allocate space for them. */
29057 reloc_count = 0;
29058 walk_relocs(count_reloc, use_real_mode);
29059 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
29060 fname, strerror(errno));
29061 }
29062 read_ehdr(fp);
29063 + read_phdrs(fp);
29064 read_shdrs(fp);
29065 read_strtabs(fp);
29066 read_symtabs(fp);
29067 - read_relocs(fp);
29068 + read_relocs(fp, use_real_mode);
29069 if (show_absolute_syms) {
29070 print_absolute_symbols();
29071 return 0;
29072 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
29073 index fd14be1..e3c79c0 100644
29074 --- a/arch/x86/vdso/Makefile
29075 +++ b/arch/x86/vdso/Makefile
29076 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
29077 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
29078 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
29079
29080 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
29081 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
29082 GCOV_PROFILE := n
29083
29084 #
29085 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
29086 index 0faad64..39ef157 100644
29087 --- a/arch/x86/vdso/vdso32-setup.c
29088 +++ b/arch/x86/vdso/vdso32-setup.c
29089 @@ -25,6 +25,7 @@
29090 #include <asm/tlbflush.h>
29091 #include <asm/vdso.h>
29092 #include <asm/proto.h>
29093 +#include <asm/mman.h>
29094
29095 enum {
29096 VDSO_DISABLED = 0,
29097 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
29098 void enable_sep_cpu(void)
29099 {
29100 int cpu = get_cpu();
29101 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
29102 + struct tss_struct *tss = init_tss + cpu;
29103
29104 if (!boot_cpu_has(X86_FEATURE_SEP)) {
29105 put_cpu();
29106 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
29107 gate_vma.vm_start = FIXADDR_USER_START;
29108 gate_vma.vm_end = FIXADDR_USER_END;
29109 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
29110 - gate_vma.vm_page_prot = __P101;
29111 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
29112
29113 return 0;
29114 }
29115 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29116 if (compat)
29117 addr = VDSO_HIGH_BASE;
29118 else {
29119 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
29120 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
29121 if (IS_ERR_VALUE(addr)) {
29122 ret = addr;
29123 goto up_fail;
29124 }
29125 }
29126
29127 - current->mm->context.vdso = (void *)addr;
29128 + current->mm->context.vdso = addr;
29129
29130 if (compat_uses_vma || !compat) {
29131 /*
29132 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29133 }
29134
29135 current_thread_info()->sysenter_return =
29136 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
29137 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
29138
29139 up_fail:
29140 if (ret)
29141 - current->mm->context.vdso = NULL;
29142 + current->mm->context.vdso = 0;
29143
29144 up_write(&mm->mmap_sem);
29145
29146 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
29147
29148 const char *arch_vma_name(struct vm_area_struct *vma)
29149 {
29150 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
29151 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
29152 return "[vdso]";
29153 +
29154 +#ifdef CONFIG_PAX_SEGMEXEC
29155 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
29156 + return "[vdso]";
29157 +#endif
29158 +
29159 return NULL;
29160 }
29161
29162 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
29163 * Check to see if the corresponding task was created in compat vdso
29164 * mode.
29165 */
29166 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
29167 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
29168 return &gate_vma;
29169 return NULL;
29170 }
29171 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
29172 index 00aaf04..4a26505 100644
29173 --- a/arch/x86/vdso/vma.c
29174 +++ b/arch/x86/vdso/vma.c
29175 @@ -16,8 +16,6 @@
29176 #include <asm/vdso.h>
29177 #include <asm/page.h>
29178
29179 -unsigned int __read_mostly vdso_enabled = 1;
29180 -
29181 extern char vdso_start[], vdso_end[];
29182 extern unsigned short vdso_sync_cpuid;
29183
29184 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
29185 * unaligned here as a result of stack start randomization.
29186 */
29187 addr = PAGE_ALIGN(addr);
29188 - addr = align_addr(addr, NULL, ALIGN_VDSO);
29189
29190 return addr;
29191 }
29192 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
29193 unsigned size)
29194 {
29195 struct mm_struct *mm = current->mm;
29196 - unsigned long addr;
29197 + unsigned long addr = 0;
29198 int ret;
29199
29200 - if (!vdso_enabled)
29201 - return 0;
29202 -
29203 down_write(&mm->mmap_sem);
29204 +
29205 +#ifdef CONFIG_PAX_RANDMMAP
29206 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
29207 +#endif
29208 +
29209 addr = vdso_addr(mm->start_stack, size);
29210 + addr = align_addr(addr, NULL, ALIGN_VDSO);
29211 addr = get_unmapped_area(NULL, addr, size, 0, 0);
29212 if (IS_ERR_VALUE(addr)) {
29213 ret = addr;
29214 goto up_fail;
29215 }
29216
29217 - current->mm->context.vdso = (void *)addr;
29218 + mm->context.vdso = addr;
29219
29220 ret = install_special_mapping(mm, addr, size,
29221 VM_READ|VM_EXEC|
29222 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
29223 pages);
29224 - if (ret) {
29225 - current->mm->context.vdso = NULL;
29226 - goto up_fail;
29227 - }
29228 + if (ret)
29229 + mm->context.vdso = 0;
29230
29231 up_fail:
29232 up_write(&mm->mmap_sem);
29233 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29234 vdsox32_size);
29235 }
29236 #endif
29237 -
29238 -static __init int vdso_setup(char *s)
29239 -{
29240 - vdso_enabled = simple_strtoul(s, NULL, 0);
29241 - return 0;
29242 -}
29243 -__setup("vdso=", vdso_setup);
29244 diff --git a/arch/x86/xen/apic.c b/arch/x86/xen/apic.c
29245 index 7005ced..530d6eb 100644
29246 --- a/arch/x86/xen/apic.c
29247 +++ b/arch/x86/xen/apic.c
29248 @@ -30,5 +30,5 @@ static unsigned int xen_io_apic_read(unsigned apic, unsigned reg)
29249
29250 void __init xen_init_apic(void)
29251 {
29252 - x86_io_apic_ops.read = xen_io_apic_read;
29253 + *(void **)&x86_io_apic_ops.read = xen_io_apic_read;
29254 }
29255 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
29256 index 586d838..9181904 100644
29257 --- a/arch/x86/xen/enlighten.c
29258 +++ b/arch/x86/xen/enlighten.c
29259 @@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
29260
29261 struct shared_info xen_dummy_shared_info;
29262
29263 -void *xen_initial_gdt;
29264 -
29265 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
29266 __read_mostly int xen_have_vector_callback;
29267 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
29268 @@ -473,8 +471,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
29269 {
29270 unsigned long va = dtr->address;
29271 unsigned int size = dtr->size + 1;
29272 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
29273 - unsigned long frames[pages];
29274 + unsigned long frames[65536 / PAGE_SIZE];
29275 int f;
29276
29277 /*
29278 @@ -522,8 +519,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
29279 {
29280 unsigned long va = dtr->address;
29281 unsigned int size = dtr->size + 1;
29282 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
29283 - unsigned long frames[pages];
29284 + unsigned long frames[65536 / PAGE_SIZE];
29285 int f;
29286
29287 /*
29288 @@ -918,21 +914,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
29289
29290 static void set_xen_basic_apic_ops(void)
29291 {
29292 - apic->read = xen_apic_read;
29293 - apic->write = xen_apic_write;
29294 - apic->icr_read = xen_apic_icr_read;
29295 - apic->icr_write = xen_apic_icr_write;
29296 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
29297 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
29298 - apic->set_apic_id = xen_set_apic_id;
29299 - apic->get_apic_id = xen_get_apic_id;
29300 + *(void **)&apic->read = xen_apic_read;
29301 + *(void **)&apic->write = xen_apic_write;
29302 + *(void **)&apic->icr_read = xen_apic_icr_read;
29303 + *(void **)&apic->icr_write = xen_apic_icr_write;
29304 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
29305 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
29306 + *(void **)&apic->set_apic_id = xen_set_apic_id;
29307 + *(void **)&apic->get_apic_id = xen_get_apic_id;
29308
29309 #ifdef CONFIG_SMP
29310 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
29311 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
29312 - apic->send_IPI_mask = xen_send_IPI_mask;
29313 - apic->send_IPI_all = xen_send_IPI_all;
29314 - apic->send_IPI_self = xen_send_IPI_self;
29315 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
29316 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
29317 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
29318 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
29319 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
29320 #endif
29321 }
29322
29323 @@ -1222,30 +1218,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
29324 #endif
29325 };
29326
29327 -static void xen_reboot(int reason)
29328 +static __noreturn void xen_reboot(int reason)
29329 {
29330 struct sched_shutdown r = { .reason = reason };
29331
29332 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
29333 - BUG();
29334 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
29335 + BUG();
29336 }
29337
29338 -static void xen_restart(char *msg)
29339 +static __noreturn void xen_restart(char *msg)
29340 {
29341 xen_reboot(SHUTDOWN_reboot);
29342 }
29343
29344 -static void xen_emergency_restart(void)
29345 +static __noreturn void xen_emergency_restart(void)
29346 {
29347 xen_reboot(SHUTDOWN_reboot);
29348 }
29349
29350 -static void xen_machine_halt(void)
29351 +static __noreturn void xen_machine_halt(void)
29352 {
29353 xen_reboot(SHUTDOWN_poweroff);
29354 }
29355
29356 -static void xen_machine_power_off(void)
29357 +static __noreturn void xen_machine_power_off(void)
29358 {
29359 if (pm_power_off)
29360 pm_power_off();
29361 @@ -1290,14 +1286,14 @@ static const struct machine_ops xen_machine_ops __initconst = {
29362 */
29363 static void __init xen_setup_stackprotector(void)
29364 {
29365 - pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
29366 - pv_cpu_ops.load_gdt = xen_load_gdt_boot;
29367 + *(void **)&pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
29368 + *(void **)&pv_cpu_ops.load_gdt = xen_load_gdt_boot;
29369
29370 setup_stack_canary_segment(0);
29371 switch_to_new_gdt(0);
29372
29373 - pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
29374 - pv_cpu_ops.load_gdt = xen_load_gdt;
29375 + *(void **)&pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
29376 + *(void **)&pv_cpu_ops.load_gdt = xen_load_gdt;
29377 }
29378
29379 /* First C function to be called on Xen boot */
29380 @@ -1315,13 +1311,13 @@ asmlinkage void __init xen_start_kernel(void)
29381
29382 /* Install Xen paravirt ops */
29383 pv_info = xen_info;
29384 - pv_init_ops = xen_init_ops;
29385 - pv_cpu_ops = xen_cpu_ops;
29386 - pv_apic_ops = xen_apic_ops;
29387 + memcpy((void *)&pv_init_ops, &xen_init_ops, sizeof pv_init_ops);
29388 + memcpy((void *)&pv_cpu_ops, &xen_cpu_ops, sizeof pv_cpu_ops);
29389 + memcpy((void *)&pv_apic_ops, &xen_apic_ops, sizeof pv_apic_ops);
29390
29391 - x86_init.resources.memory_setup = xen_memory_setup;
29392 - x86_init.oem.arch_setup = xen_arch_setup;
29393 - x86_init.oem.banner = xen_banner;
29394 + *(void **)&x86_init.resources.memory_setup = xen_memory_setup;
29395 + *(void **)&x86_init.oem.arch_setup = xen_arch_setup;
29396 + *(void **)&x86_init.oem.banner = xen_banner;
29397
29398 xen_init_time_ops();
29399
29400 @@ -1347,7 +1343,17 @@ asmlinkage void __init xen_start_kernel(void)
29401 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
29402
29403 /* Work out if we support NX */
29404 - x86_configure_nx();
29405 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29406 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
29407 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
29408 + unsigned l, h;
29409 +
29410 + __supported_pte_mask |= _PAGE_NX;
29411 + rdmsr(MSR_EFER, l, h);
29412 + l |= EFER_NX;
29413 + wrmsr(MSR_EFER, l, h);
29414 + }
29415 +#endif
29416
29417 xen_setup_features();
29418
29419 @@ -1376,14 +1382,7 @@ asmlinkage void __init xen_start_kernel(void)
29420 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
29421 }
29422
29423 - machine_ops = xen_machine_ops;
29424 -
29425 - /*
29426 - * The only reliable way to retain the initial address of the
29427 - * percpu gdt_page is to remember it here, so we can go and
29428 - * mark it RW later, when the initial percpu area is freed.
29429 - */
29430 - xen_initial_gdt = &per_cpu(gdt_page, 0);
29431 + memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
29432
29433 xen_smp_init();
29434
29435 @@ -1450,7 +1449,7 @@ asmlinkage void __init xen_start_kernel(void)
29436 add_preferred_console("tty", 0, NULL);
29437 add_preferred_console("hvc", 0, NULL);
29438 if (pci_xen)
29439 - x86_init.pci.arch_init = pci_xen_init;
29440 + *(void **)&x86_init.pci.arch_init = pci_xen_init;
29441 } else {
29442 const struct dom0_vga_console_info *info =
29443 (void *)((char *)xen_start_info +
29444 @@ -1476,8 +1475,8 @@ asmlinkage void __init xen_start_kernel(void)
29445 xen_acpi_sleep_register();
29446
29447 /* Avoid searching for BIOS MP tables */
29448 - x86_init.mpparse.find_smp_config = x86_init_noop;
29449 - x86_init.mpparse.get_smp_config = x86_init_uint_noop;
29450 + *(void **)&x86_init.mpparse.find_smp_config = x86_init_noop;
29451 + *(void **)&x86_init.mpparse.get_smp_config = x86_init_uint_noop;
29452 }
29453 #ifdef CONFIG_PCI
29454 /* PCI BIOS service won't work from a PV guest. */
29455 @@ -1583,7 +1582,7 @@ static void __init xen_hvm_guest_init(void)
29456 xen_hvm_smp_init();
29457 register_cpu_notifier(&xen_hvm_cpu_notifier);
29458 xen_unplug_emulated_devices();
29459 - x86_init.irqs.intr_init = xen_init_IRQ;
29460 + *(void **)&x86_init.irqs.intr_init = xen_init_IRQ;
29461 xen_hvm_init_time_ops();
29462 xen_hvm_init_mmu_ops();
29463 }
29464 diff --git a/arch/x86/xen/irq.c b/arch/x86/xen/irq.c
29465 index 01a4dc0..3ca0cc9 100644
29466 --- a/arch/x86/xen/irq.c
29467 +++ b/arch/x86/xen/irq.c
29468 @@ -130,5 +130,5 @@ static const struct pv_irq_ops xen_irq_ops __initconst = {
29469 void __init xen_init_irq_ops(void)
29470 {
29471 pv_irq_ops = xen_irq_ops;
29472 - x86_init.irqs.intr_init = xen_init_IRQ;
29473 + *(void **)&x86_init.irqs.intr_init = xen_init_IRQ;
29474 }
29475 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
29476 index dcf5f2d..5f72fe7 100644
29477 --- a/arch/x86/xen/mmu.c
29478 +++ b/arch/x86/xen/mmu.c
29479 @@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29480 /* L3_k[510] -> level2_kernel_pgt
29481 * L3_i[511] -> level2_fixmap_pgt */
29482 convert_pfn_mfn(level3_kernel_pgt);
29483 + convert_pfn_mfn(level3_vmalloc_start_pgt);
29484 + convert_pfn_mfn(level3_vmalloc_end_pgt);
29485 + convert_pfn_mfn(level3_vmemmap_pgt);
29486
29487 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
29488 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
29489 @@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29490 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
29491 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
29492 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
29493 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
29494 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
29495 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
29496 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
29497 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
29498 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
29499 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
29500 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
29501
29502 @@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
29503 pv_mmu_ops.set_pud = xen_set_pud;
29504 #if PAGETABLE_LEVELS == 4
29505 pv_mmu_ops.set_pgd = xen_set_pgd;
29506 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
29507 #endif
29508
29509 /* This will work as long as patching hasn't happened yet
29510 @@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
29511 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
29512 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
29513 .set_pgd = xen_set_pgd_hyper,
29514 + .set_pgd_batched = xen_set_pgd_hyper,
29515
29516 .alloc_pud = xen_alloc_pmd_init,
29517 .release_pud = xen_release_pmd_init,
29518 @@ -2197,8 +2206,8 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
29519
29520 void __init xen_init_mmu_ops(void)
29521 {
29522 - x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve;
29523 - x86_init.paging.pagetable_init = xen_pagetable_init;
29524 + *(void **)&x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve;
29525 + *(void **)&x86_init.paging.pagetable_init = xen_pagetable_init;
29526 pv_mmu_ops = xen_mmu_ops;
29527
29528 memset(dummy_mapping, 0xff, PAGE_SIZE);
29529 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
29530 index 353c50f..a0b9b0d 100644
29531 --- a/arch/x86/xen/smp.c
29532 +++ b/arch/x86/xen/smp.c
29533 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
29534 {
29535 BUG_ON(smp_processor_id() != 0);
29536 native_smp_prepare_boot_cpu();
29537 -
29538 - /* We've switched to the "real" per-cpu gdt, so make sure the
29539 - old memory can be recycled */
29540 - make_lowmem_page_readwrite(xen_initial_gdt);
29541 -
29542 xen_filter_cpu_maps();
29543 xen_setup_vcpu_info_placement();
29544 }
29545 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
29546 gdt = get_cpu_gdt_table(cpu);
29547
29548 ctxt->flags = VGCF_IN_KERNEL;
29549 - ctxt->user_regs.ds = __USER_DS;
29550 - ctxt->user_regs.es = __USER_DS;
29551 + ctxt->user_regs.ds = __KERNEL_DS;
29552 + ctxt->user_regs.es = __KERNEL_DS;
29553 ctxt->user_regs.ss = __KERNEL_DS;
29554 #ifdef CONFIG_X86_32
29555 ctxt->user_regs.fs = __KERNEL_PERCPU;
29556 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
29557 + savesegment(gs, ctxt->user_regs.gs);
29558 #else
29559 ctxt->gs_base_kernel = per_cpu_offset(cpu);
29560 #endif
29561 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
29562 int rc;
29563
29564 per_cpu(current_task, cpu) = idle;
29565 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
29566 #ifdef CONFIG_X86_32
29567 irq_ctx_init(cpu);
29568 #else
29569 clear_tsk_thread_flag(idle, TIF_FORK);
29570 - per_cpu(kernel_stack, cpu) =
29571 - (unsigned long)task_stack_page(idle) -
29572 - KERNEL_STACK_OFFSET + THREAD_SIZE;
29573 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
29574 #endif
29575 xen_setup_runstate_info(cpu);
29576 xen_setup_timer(cpu);
29577 @@ -637,7 +631,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
29578
29579 void __init xen_smp_init(void)
29580 {
29581 - smp_ops = xen_smp_ops;
29582 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
29583 xen_fill_possible_map();
29584 xen_init_spinlocks();
29585 }
29586 @@ -672,10 +666,10 @@ void __init xen_hvm_smp_init(void)
29587 {
29588 if (!xen_have_vector_callback)
29589 return;
29590 - smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
29591 - smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
29592 - smp_ops.cpu_up = xen_hvm_cpu_up;
29593 - smp_ops.cpu_die = xen_hvm_cpu_die;
29594 - smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
29595 - smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
29596 + *(void **)&smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
29597 + *(void **)&smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
29598 + *(void **)&smp_ops.cpu_up = xen_hvm_cpu_up;
29599 + *(void **)&smp_ops.cpu_die = xen_hvm_cpu_die;
29600 + *(void **)&smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
29601 + *(void **)&smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
29602 }
29603 diff --git a/arch/x86/xen/spinlock.c b/arch/x86/xen/spinlock.c
29604 index 83e866d..ef60385 100644
29605 --- a/arch/x86/xen/spinlock.c
29606 +++ b/arch/x86/xen/spinlock.c
29607 @@ -390,12 +390,12 @@ void __init xen_init_spinlocks(void)
29608 {
29609 BUILD_BUG_ON(sizeof(struct xen_spinlock) > sizeof(arch_spinlock_t));
29610
29611 - pv_lock_ops.spin_is_locked = xen_spin_is_locked;
29612 - pv_lock_ops.spin_is_contended = xen_spin_is_contended;
29613 - pv_lock_ops.spin_lock = xen_spin_lock;
29614 - pv_lock_ops.spin_lock_flags = xen_spin_lock_flags;
29615 - pv_lock_ops.spin_trylock = xen_spin_trylock;
29616 - pv_lock_ops.spin_unlock = xen_spin_unlock;
29617 + *(void **)&pv_lock_ops.spin_is_locked = xen_spin_is_locked;
29618 + *(void **)&pv_lock_ops.spin_is_contended = xen_spin_is_contended;
29619 + *(void **)&pv_lock_ops.spin_lock = xen_spin_lock;
29620 + *(void **)&pv_lock_ops.spin_lock_flags = xen_spin_lock_flags;
29621 + *(void **)&pv_lock_ops.spin_trylock = xen_spin_trylock;
29622 + *(void **)&pv_lock_ops.spin_unlock = xen_spin_unlock;
29623 }
29624
29625 #ifdef CONFIG_XEN_DEBUG_FS
29626 diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
29627 index 0296a95..3c51a2d 100644
29628 --- a/arch/x86/xen/time.c
29629 +++ b/arch/x86/xen/time.c
29630 @@ -481,15 +481,15 @@ static void __init xen_time_init(void)
29631
29632 void __init xen_init_time_ops(void)
29633 {
29634 - pv_time_ops = xen_time_ops;
29635 + memcpy((void *)&pv_time_ops, &xen_time_ops, sizeof pv_time_ops);
29636
29637 - x86_init.timers.timer_init = xen_time_init;
29638 - x86_init.timers.setup_percpu_clockev = x86_init_noop;
29639 - x86_cpuinit.setup_percpu_clockev = x86_init_noop;
29640 + *(void **)&x86_init.timers.timer_init = xen_time_init;
29641 + *(void **)&x86_init.timers.setup_percpu_clockev = x86_init_noop;
29642 + *(void **)&x86_cpuinit.setup_percpu_clockev = x86_init_noop;
29643
29644 - x86_platform.calibrate_tsc = xen_tsc_khz;
29645 - x86_platform.get_wallclock = xen_get_wallclock;
29646 - x86_platform.set_wallclock = xen_set_wallclock;
29647 + *(void **)&x86_platform.calibrate_tsc = xen_tsc_khz;
29648 + *(void **)&x86_platform.get_wallclock = xen_get_wallclock;
29649 + *(void **)&x86_platform.set_wallclock = xen_set_wallclock;
29650 }
29651
29652 #ifdef CONFIG_XEN_PVHVM
29653 @@ -514,12 +514,12 @@ void __init xen_hvm_init_time_ops(void)
29654 return;
29655 }
29656
29657 - pv_time_ops = xen_time_ops;
29658 - x86_init.timers.setup_percpu_clockev = xen_time_init;
29659 - x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;
29660 + memcpy((void *)&pv_time_ops, &xen_time_ops, sizeof pv_time_ops);
29661 + *(void **)&x86_init.timers.setup_percpu_clockev = xen_time_init;
29662 + *(void **)&x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;
29663
29664 - x86_platform.calibrate_tsc = xen_tsc_khz;
29665 - x86_platform.get_wallclock = xen_get_wallclock;
29666 - x86_platform.set_wallclock = xen_set_wallclock;
29667 + *(void **)&x86_platform.calibrate_tsc = xen_tsc_khz;
29668 + *(void **)&x86_platform.get_wallclock = xen_get_wallclock;
29669 + *(void **)&x86_platform.set_wallclock = xen_set_wallclock;
29670 }
29671 #endif
29672 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
29673 index f9643fc..602e8af 100644
29674 --- a/arch/x86/xen/xen-asm_32.S
29675 +++ b/arch/x86/xen/xen-asm_32.S
29676 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
29677 ESP_OFFSET=4 # bytes pushed onto stack
29678
29679 /*
29680 - * Store vcpu_info pointer for easy access. Do it this way to
29681 - * avoid having to reload %fs
29682 + * Store vcpu_info pointer for easy access.
29683 */
29684 #ifdef CONFIG_SMP
29685 - GET_THREAD_INFO(%eax)
29686 - movl TI_cpu(%eax), %eax
29687 - movl __per_cpu_offset(,%eax,4), %eax
29688 - mov xen_vcpu(%eax), %eax
29689 + push %fs
29690 + mov $(__KERNEL_PERCPU), %eax
29691 + mov %eax, %fs
29692 + mov PER_CPU_VAR(xen_vcpu), %eax
29693 + pop %fs
29694 #else
29695 movl xen_vcpu, %eax
29696 #endif
29697 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
29698 index 7faed58..ba4427c 100644
29699 --- a/arch/x86/xen/xen-head.S
29700 +++ b/arch/x86/xen/xen-head.S
29701 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
29702 #ifdef CONFIG_X86_32
29703 mov %esi,xen_start_info
29704 mov $init_thread_union+THREAD_SIZE,%esp
29705 +#ifdef CONFIG_SMP
29706 + movl $cpu_gdt_table,%edi
29707 + movl $__per_cpu_load,%eax
29708 + movw %ax,__KERNEL_PERCPU + 2(%edi)
29709 + rorl $16,%eax
29710 + movb %al,__KERNEL_PERCPU + 4(%edi)
29711 + movb %ah,__KERNEL_PERCPU + 7(%edi)
29712 + movl $__per_cpu_end - 1,%eax
29713 + subl $__per_cpu_start,%eax
29714 + movw %ax,__KERNEL_PERCPU + 0(%edi)
29715 +#endif
29716 #else
29717 mov %rsi,xen_start_info
29718 mov $init_thread_union+THREAD_SIZE,%rsp
29719 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
29720 index a95b417..b6dbd0b 100644
29721 --- a/arch/x86/xen/xen-ops.h
29722 +++ b/arch/x86/xen/xen-ops.h
29723 @@ -10,8 +10,6 @@
29724 extern const char xen_hypervisor_callback[];
29725 extern const char xen_failsafe_callback[];
29726
29727 -extern void *xen_initial_gdt;
29728 -
29729 struct trap_info;
29730 void xen_copy_trap_info(struct trap_info *traps);
29731
29732 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
29733 index 525bd3d..ef888b1 100644
29734 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
29735 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
29736 @@ -119,9 +119,9 @@
29737 ----------------------------------------------------------------------*/
29738
29739 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
29740 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
29741 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
29742 #define XCHAL_DCACHE_LINEWIDTH 5 /* 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 16384 /* I-cache size in bytes or 0 */
29746 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
29747 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
29748 index 2f33760..835e50a 100644
29749 --- a/arch/xtensa/variants/fsf/include/variant/core.h
29750 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
29751 @@ -11,6 +11,7 @@
29752 #ifndef _XTENSA_CORE_H
29753 #define _XTENSA_CORE_H
29754
29755 +#include <linux/const.h>
29756
29757 /****************************************************************************
29758 Parameters Useful for Any Code, USER or PRIVILEGED
29759 @@ -112,9 +113,9 @@
29760 ----------------------------------------------------------------------*/
29761
29762 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29763 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29764 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29765 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29766 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29767
29768 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
29769 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
29770 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
29771 index af00795..2bb8105 100644
29772 --- a/arch/xtensa/variants/s6000/include/variant/core.h
29773 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
29774 @@ -11,6 +11,7 @@
29775 #ifndef _XTENSA_CORE_CONFIGURATION_H
29776 #define _XTENSA_CORE_CONFIGURATION_H
29777
29778 +#include <linux/const.h>
29779
29780 /****************************************************************************
29781 Parameters Useful for Any Code, USER or PRIVILEGED
29782 @@ -118,9 +119,9 @@
29783 ----------------------------------------------------------------------*/
29784
29785 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29786 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29787 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29788 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29789 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29790
29791 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
29792 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
29793 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
29794 index 58916af..9cb880b 100644
29795 --- a/block/blk-iopoll.c
29796 +++ b/block/blk-iopoll.c
29797 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
29798 }
29799 EXPORT_SYMBOL(blk_iopoll_complete);
29800
29801 -static void blk_iopoll_softirq(struct softirq_action *h)
29802 +static void blk_iopoll_softirq(void)
29803 {
29804 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
29805 int rearm = 0, budget = blk_iopoll_budget;
29806 diff --git a/block/blk-map.c b/block/blk-map.c
29807 index 623e1cd..ca1e109 100644
29808 --- a/block/blk-map.c
29809 +++ b/block/blk-map.c
29810 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
29811 if (!len || !kbuf)
29812 return -EINVAL;
29813
29814 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
29815 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
29816 if (do_copy)
29817 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
29818 else
29819 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
29820 index 467c8de..4bddc6d 100644
29821 --- a/block/blk-softirq.c
29822 +++ b/block/blk-softirq.c
29823 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
29824 * Softirq action handler - move entries to local list and loop over them
29825 * while passing them to the queue registered handler.
29826 */
29827 -static void blk_done_softirq(struct softirq_action *h)
29828 +static void blk_done_softirq(void)
29829 {
29830 struct list_head *cpu_list, local_list;
29831
29832 diff --git a/block/bsg.c b/block/bsg.c
29833 index ff64ae3..593560c 100644
29834 --- a/block/bsg.c
29835 +++ b/block/bsg.c
29836 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
29837 struct sg_io_v4 *hdr, struct bsg_device *bd,
29838 fmode_t has_write_perm)
29839 {
29840 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29841 + unsigned char *cmdptr;
29842 +
29843 if (hdr->request_len > BLK_MAX_CDB) {
29844 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
29845 if (!rq->cmd)
29846 return -ENOMEM;
29847 - }
29848 + cmdptr = rq->cmd;
29849 + } else
29850 + cmdptr = tmpcmd;
29851
29852 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
29853 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
29854 hdr->request_len))
29855 return -EFAULT;
29856
29857 + if (cmdptr != rq->cmd)
29858 + memcpy(rq->cmd, cmdptr, hdr->request_len);
29859 +
29860 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
29861 if (blk_verify_command(rq->cmd, has_write_perm))
29862 return -EPERM;
29863 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
29864 index 7c668c8..db3521c 100644
29865 --- a/block/compat_ioctl.c
29866 +++ b/block/compat_ioctl.c
29867 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
29868 err |= __get_user(f->spec1, &uf->spec1);
29869 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
29870 err |= __get_user(name, &uf->name);
29871 - f->name = compat_ptr(name);
29872 + f->name = (void __force_kernel *)compat_ptr(name);
29873 if (err) {
29874 err = -EFAULT;
29875 goto out;
29876 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
29877 index 6296b40..417c00f 100644
29878 --- a/block/partitions/efi.c
29879 +++ b/block/partitions/efi.c
29880 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
29881 if (!gpt)
29882 return NULL;
29883
29884 + if (!le32_to_cpu(gpt->num_partition_entries))
29885 + return NULL;
29886 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
29887 + if (!pte)
29888 + return NULL;
29889 +
29890 count = le32_to_cpu(gpt->num_partition_entries) *
29891 le32_to_cpu(gpt->sizeof_partition_entry);
29892 - if (!count)
29893 - return NULL;
29894 - pte = kzalloc(count, GFP_KERNEL);
29895 - if (!pte)
29896 - return NULL;
29897 -
29898 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
29899 (u8 *) pte,
29900 count) < count) {
29901 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
29902 index 9a87daa..fb17486 100644
29903 --- a/block/scsi_ioctl.c
29904 +++ b/block/scsi_ioctl.c
29905 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
29906 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
29907 struct sg_io_hdr *hdr, fmode_t mode)
29908 {
29909 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
29910 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29911 + unsigned char *cmdptr;
29912 +
29913 + if (rq->cmd != rq->__cmd)
29914 + cmdptr = rq->cmd;
29915 + else
29916 + cmdptr = tmpcmd;
29917 +
29918 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
29919 return -EFAULT;
29920 +
29921 + if (cmdptr != rq->cmd)
29922 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
29923 +
29924 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
29925 return -EPERM;
29926
29927 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29928 int err;
29929 unsigned int in_len, out_len, bytes, opcode, cmdlen;
29930 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
29931 + unsigned char tmpcmd[sizeof(rq->__cmd)];
29932 + unsigned char *cmdptr;
29933
29934 if (!sic)
29935 return -EINVAL;
29936 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29937 */
29938 err = -EFAULT;
29939 rq->cmd_len = cmdlen;
29940 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
29941 +
29942 + if (rq->cmd != rq->__cmd)
29943 + cmdptr = rq->cmd;
29944 + else
29945 + cmdptr = tmpcmd;
29946 +
29947 + if (copy_from_user(cmdptr, sic->data, cmdlen))
29948 goto error;
29949
29950 + if (rq->cmd != cmdptr)
29951 + memcpy(rq->cmd, cmdptr, cmdlen);
29952 +
29953 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
29954 goto error;
29955
29956 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
29957 index 7bdd61b..afec999 100644
29958 --- a/crypto/cryptd.c
29959 +++ b/crypto/cryptd.c
29960 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
29961
29962 struct cryptd_blkcipher_request_ctx {
29963 crypto_completion_t complete;
29964 -};
29965 +} __no_const;
29966
29967 struct cryptd_hash_ctx {
29968 struct crypto_shash *child;
29969 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
29970
29971 struct cryptd_aead_request_ctx {
29972 crypto_completion_t complete;
29973 -};
29974 +} __no_const;
29975
29976 static void cryptd_queue_worker(struct work_struct *work);
29977
29978 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
29979 index e6defd8..c26a225 100644
29980 --- a/drivers/acpi/apei/cper.c
29981 +++ b/drivers/acpi/apei/cper.c
29982 @@ -38,12 +38,12 @@
29983 */
29984 u64 cper_next_record_id(void)
29985 {
29986 - static atomic64_t seq;
29987 + static atomic64_unchecked_t seq;
29988
29989 - if (!atomic64_read(&seq))
29990 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
29991 + if (!atomic64_read_unchecked(&seq))
29992 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
29993
29994 - return atomic64_inc_return(&seq);
29995 + return atomic64_inc_return_unchecked(&seq);
29996 }
29997 EXPORT_SYMBOL_GPL(cper_next_record_id);
29998
29999 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
30000 index 7586544..636a2f0 100644
30001 --- a/drivers/acpi/ec_sys.c
30002 +++ b/drivers/acpi/ec_sys.c
30003 @@ -12,6 +12,7 @@
30004 #include <linux/acpi.h>
30005 #include <linux/debugfs.h>
30006 #include <linux/module.h>
30007 +#include <linux/uaccess.h>
30008 #include "internal.h"
30009
30010 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
30011 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
30012 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
30013 */
30014 unsigned int size = EC_SPACE_SIZE;
30015 - u8 *data = (u8 *) buf;
30016 + u8 data;
30017 loff_t init_off = *off;
30018 int err = 0;
30019
30020 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
30021 size = count;
30022
30023 while (size) {
30024 - err = ec_read(*off, &data[*off - init_off]);
30025 + err = ec_read(*off, &data);
30026 if (err)
30027 return err;
30028 + if (put_user(data, &buf[*off - init_off]))
30029 + return -EFAULT;
30030 *off += 1;
30031 size--;
30032 }
30033 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
30034
30035 unsigned int size = count;
30036 loff_t init_off = *off;
30037 - u8 *data = (u8 *) buf;
30038 int err = 0;
30039
30040 if (*off >= EC_SPACE_SIZE)
30041 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
30042 }
30043
30044 while (size) {
30045 - u8 byte_write = data[*off - init_off];
30046 + u8 byte_write;
30047 + if (get_user(byte_write, &buf[*off - init_off]))
30048 + return -EFAULT;
30049 err = ec_write(*off, byte_write);
30050 if (err)
30051 return err;
30052 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
30053 index 27adb09..ef98796b 100644
30054 --- a/drivers/acpi/proc.c
30055 +++ b/drivers/acpi/proc.c
30056 @@ -362,16 +362,13 @@ acpi_system_write_wakeup_device(struct file *file,
30057 struct list_head *node, *next;
30058 char strbuf[5];
30059 char str[5] = "";
30060 - unsigned int len = count;
30061
30062 - if (len > 4)
30063 - len = 4;
30064 - if (len < 0)
30065 - return -EFAULT;
30066 + if (count > 4)
30067 + count = 4;
30068
30069 - if (copy_from_user(strbuf, buffer, len))
30070 + if (copy_from_user(strbuf, buffer, count))
30071 return -EFAULT;
30072 - strbuf[len] = '\0';
30073 + strbuf[count] = '\0';
30074 sscanf(strbuf, "%s", str);
30075
30076 mutex_lock(&acpi_device_lock);
30077 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
30078 index bd4e5dc..0497b66 100644
30079 --- a/drivers/acpi/processor_driver.c
30080 +++ b/drivers/acpi/processor_driver.c
30081 @@ -552,7 +552,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
30082 return 0;
30083 #endif
30084
30085 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
30086 + BUG_ON(pr->id >= nr_cpu_ids);
30087
30088 /*
30089 * Buggy BIOS check
30090 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
30091 index c8ac4fe..631818e 100644
30092 --- a/drivers/ata/libata-core.c
30093 +++ b/drivers/ata/libata-core.c
30094 @@ -4779,7 +4779,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
30095 struct ata_port *ap;
30096 unsigned int tag;
30097
30098 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30099 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30100 ap = qc->ap;
30101
30102 qc->flags = 0;
30103 @@ -4795,7 +4795,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
30104 struct ata_port *ap;
30105 struct ata_link *link;
30106
30107 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30108 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30109 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
30110 ap = qc->ap;
30111 link = qc->dev->link;
30112 @@ -5891,6 +5891,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
30113 return;
30114
30115 spin_lock(&lock);
30116 + pax_open_kernel();
30117
30118 for (cur = ops->inherits; cur; cur = cur->inherits) {
30119 void **inherit = (void **)cur;
30120 @@ -5904,8 +5905,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
30121 if (IS_ERR(*pp))
30122 *pp = NULL;
30123
30124 - ops->inherits = NULL;
30125 + *(struct ata_port_operations **)&ops->inherits = NULL;
30126
30127 + pax_close_kernel();
30128 spin_unlock(&lock);
30129 }
30130
30131 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
30132 index 371fd2c..0836c78 100644
30133 --- a/drivers/ata/pata_arasan_cf.c
30134 +++ b/drivers/ata/pata_arasan_cf.c
30135 @@ -861,7 +861,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
30136 /* Handle platform specific quirks */
30137 if (pdata->quirk) {
30138 if (pdata->quirk & CF_BROKEN_PIO) {
30139 - ap->ops->set_piomode = NULL;
30140 + pax_open_kernel();
30141 + *(void **)&ap->ops->set_piomode = NULL;
30142 + pax_close_kernel();
30143 ap->pio_mask = 0;
30144 }
30145 if (pdata->quirk & CF_BROKEN_MWDMA)
30146 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
30147 index f9b983a..887b9d8 100644
30148 --- a/drivers/atm/adummy.c
30149 +++ b/drivers/atm/adummy.c
30150 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
30151 vcc->pop(vcc, skb);
30152 else
30153 dev_kfree_skb_any(skb);
30154 - atomic_inc(&vcc->stats->tx);
30155 + atomic_inc_unchecked(&vcc->stats->tx);
30156
30157 return 0;
30158 }
30159 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
30160 index ff7bb8a..568fc0b 100644
30161 --- a/drivers/atm/ambassador.c
30162 +++ b/drivers/atm/ambassador.c
30163 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
30164 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
30165
30166 // VC layer stats
30167 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30168 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30169
30170 // free the descriptor
30171 kfree (tx_descr);
30172 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
30173 dump_skb ("<<<", vc, skb);
30174
30175 // VC layer stats
30176 - atomic_inc(&atm_vcc->stats->rx);
30177 + atomic_inc_unchecked(&atm_vcc->stats->rx);
30178 __net_timestamp(skb);
30179 // end of our responsibility
30180 atm_vcc->push (atm_vcc, skb);
30181 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
30182 } else {
30183 PRINTK (KERN_INFO, "dropped over-size frame");
30184 // should we count this?
30185 - atomic_inc(&atm_vcc->stats->rx_drop);
30186 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30187 }
30188
30189 } else {
30190 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
30191 }
30192
30193 if (check_area (skb->data, skb->len)) {
30194 - atomic_inc(&atm_vcc->stats->tx_err);
30195 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
30196 return -ENOMEM; // ?
30197 }
30198
30199 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
30200 index b22d71c..d6e1049 100644
30201 --- a/drivers/atm/atmtcp.c
30202 +++ b/drivers/atm/atmtcp.c
30203 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30204 if (vcc->pop) vcc->pop(vcc,skb);
30205 else dev_kfree_skb(skb);
30206 if (dev_data) return 0;
30207 - atomic_inc(&vcc->stats->tx_err);
30208 + atomic_inc_unchecked(&vcc->stats->tx_err);
30209 return -ENOLINK;
30210 }
30211 size = skb->len+sizeof(struct atmtcp_hdr);
30212 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30213 if (!new_skb) {
30214 if (vcc->pop) vcc->pop(vcc,skb);
30215 else dev_kfree_skb(skb);
30216 - atomic_inc(&vcc->stats->tx_err);
30217 + atomic_inc_unchecked(&vcc->stats->tx_err);
30218 return -ENOBUFS;
30219 }
30220 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
30221 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30222 if (vcc->pop) vcc->pop(vcc,skb);
30223 else dev_kfree_skb(skb);
30224 out_vcc->push(out_vcc,new_skb);
30225 - atomic_inc(&vcc->stats->tx);
30226 - atomic_inc(&out_vcc->stats->rx);
30227 + atomic_inc_unchecked(&vcc->stats->tx);
30228 + atomic_inc_unchecked(&out_vcc->stats->rx);
30229 return 0;
30230 }
30231
30232 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
30233 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
30234 read_unlock(&vcc_sklist_lock);
30235 if (!out_vcc) {
30236 - atomic_inc(&vcc->stats->tx_err);
30237 + atomic_inc_unchecked(&vcc->stats->tx_err);
30238 goto done;
30239 }
30240 skb_pull(skb,sizeof(struct atmtcp_hdr));
30241 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
30242 __net_timestamp(new_skb);
30243 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
30244 out_vcc->push(out_vcc,new_skb);
30245 - atomic_inc(&vcc->stats->tx);
30246 - atomic_inc(&out_vcc->stats->rx);
30247 + atomic_inc_unchecked(&vcc->stats->tx);
30248 + atomic_inc_unchecked(&out_vcc->stats->rx);
30249 done:
30250 if (vcc->pop) vcc->pop(vcc,skb);
30251 else dev_kfree_skb(skb);
30252 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
30253 index 81e44f7..498ea36 100644
30254 --- a/drivers/atm/eni.c
30255 +++ b/drivers/atm/eni.c
30256 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
30257 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
30258 vcc->dev->number);
30259 length = 0;
30260 - atomic_inc(&vcc->stats->rx_err);
30261 + atomic_inc_unchecked(&vcc->stats->rx_err);
30262 }
30263 else {
30264 length = ATM_CELL_SIZE-1; /* no HEC */
30265 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
30266 size);
30267 }
30268 eff = length = 0;
30269 - atomic_inc(&vcc->stats->rx_err);
30270 + atomic_inc_unchecked(&vcc->stats->rx_err);
30271 }
30272 else {
30273 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
30274 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
30275 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
30276 vcc->dev->number,vcc->vci,length,size << 2,descr);
30277 length = eff = 0;
30278 - atomic_inc(&vcc->stats->rx_err);
30279 + atomic_inc_unchecked(&vcc->stats->rx_err);
30280 }
30281 }
30282 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
30283 @@ -767,7 +767,7 @@ rx_dequeued++;
30284 vcc->push(vcc,skb);
30285 pushed++;
30286 }
30287 - atomic_inc(&vcc->stats->rx);
30288 + atomic_inc_unchecked(&vcc->stats->rx);
30289 }
30290 wake_up(&eni_dev->rx_wait);
30291 }
30292 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
30293 PCI_DMA_TODEVICE);
30294 if (vcc->pop) vcc->pop(vcc,skb);
30295 else dev_kfree_skb_irq(skb);
30296 - atomic_inc(&vcc->stats->tx);
30297 + atomic_inc_unchecked(&vcc->stats->tx);
30298 wake_up(&eni_dev->tx_wait);
30299 dma_complete++;
30300 }
30301 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
30302 index 86fed1b..6dc4721 100644
30303 --- a/drivers/atm/firestream.c
30304 +++ b/drivers/atm/firestream.c
30305 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
30306 }
30307 }
30308
30309 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30310 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30311
30312 fs_dprintk (FS_DEBUG_TXMEM, "i");
30313 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
30314 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
30315 #endif
30316 skb_put (skb, qe->p1 & 0xffff);
30317 ATM_SKB(skb)->vcc = atm_vcc;
30318 - atomic_inc(&atm_vcc->stats->rx);
30319 + atomic_inc_unchecked(&atm_vcc->stats->rx);
30320 __net_timestamp(skb);
30321 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
30322 atm_vcc->push (atm_vcc, skb);
30323 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
30324 kfree (pe);
30325 }
30326 if (atm_vcc)
30327 - atomic_inc(&atm_vcc->stats->rx_drop);
30328 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30329 break;
30330 case 0x1f: /* Reassembly abort: no buffers. */
30331 /* Silently increment error counter. */
30332 if (atm_vcc)
30333 - atomic_inc(&atm_vcc->stats->rx_drop);
30334 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30335 break;
30336 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
30337 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
30338 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
30339 index 361f5ae..7fc552d 100644
30340 --- a/drivers/atm/fore200e.c
30341 +++ b/drivers/atm/fore200e.c
30342 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
30343 #endif
30344 /* check error condition */
30345 if (*entry->status & STATUS_ERROR)
30346 - atomic_inc(&vcc->stats->tx_err);
30347 + atomic_inc_unchecked(&vcc->stats->tx_err);
30348 else
30349 - atomic_inc(&vcc->stats->tx);
30350 + atomic_inc_unchecked(&vcc->stats->tx);
30351 }
30352 }
30353
30354 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
30355 if (skb == NULL) {
30356 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
30357
30358 - atomic_inc(&vcc->stats->rx_drop);
30359 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30360 return -ENOMEM;
30361 }
30362
30363 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
30364
30365 dev_kfree_skb_any(skb);
30366
30367 - atomic_inc(&vcc->stats->rx_drop);
30368 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30369 return -ENOMEM;
30370 }
30371
30372 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
30373
30374 vcc->push(vcc, skb);
30375 - atomic_inc(&vcc->stats->rx);
30376 + atomic_inc_unchecked(&vcc->stats->rx);
30377
30378 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
30379
30380 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
30381 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
30382 fore200e->atm_dev->number,
30383 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
30384 - atomic_inc(&vcc->stats->rx_err);
30385 + atomic_inc_unchecked(&vcc->stats->rx_err);
30386 }
30387 }
30388
30389 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
30390 goto retry_here;
30391 }
30392
30393 - atomic_inc(&vcc->stats->tx_err);
30394 + atomic_inc_unchecked(&vcc->stats->tx_err);
30395
30396 fore200e->tx_sat++;
30397 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
30398 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
30399 index b182c2f..1c6fa8a 100644
30400 --- a/drivers/atm/he.c
30401 +++ b/drivers/atm/he.c
30402 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30403
30404 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
30405 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
30406 - atomic_inc(&vcc->stats->rx_drop);
30407 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30408 goto return_host_buffers;
30409 }
30410
30411 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30412 RBRQ_LEN_ERR(he_dev->rbrq_head)
30413 ? "LEN_ERR" : "",
30414 vcc->vpi, vcc->vci);
30415 - atomic_inc(&vcc->stats->rx_err);
30416 + atomic_inc_unchecked(&vcc->stats->rx_err);
30417 goto return_host_buffers;
30418 }
30419
30420 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30421 vcc->push(vcc, skb);
30422 spin_lock(&he_dev->global_lock);
30423
30424 - atomic_inc(&vcc->stats->rx);
30425 + atomic_inc_unchecked(&vcc->stats->rx);
30426
30427 return_host_buffers:
30428 ++pdus_assembled;
30429 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
30430 tpd->vcc->pop(tpd->vcc, tpd->skb);
30431 else
30432 dev_kfree_skb_any(tpd->skb);
30433 - atomic_inc(&tpd->vcc->stats->tx_err);
30434 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
30435 }
30436 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
30437 return;
30438 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30439 vcc->pop(vcc, skb);
30440 else
30441 dev_kfree_skb_any(skb);
30442 - atomic_inc(&vcc->stats->tx_err);
30443 + atomic_inc_unchecked(&vcc->stats->tx_err);
30444 return -EINVAL;
30445 }
30446
30447 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30448 vcc->pop(vcc, skb);
30449 else
30450 dev_kfree_skb_any(skb);
30451 - atomic_inc(&vcc->stats->tx_err);
30452 + atomic_inc_unchecked(&vcc->stats->tx_err);
30453 return -EINVAL;
30454 }
30455 #endif
30456 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30457 vcc->pop(vcc, skb);
30458 else
30459 dev_kfree_skb_any(skb);
30460 - atomic_inc(&vcc->stats->tx_err);
30461 + atomic_inc_unchecked(&vcc->stats->tx_err);
30462 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30463 return -ENOMEM;
30464 }
30465 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30466 vcc->pop(vcc, skb);
30467 else
30468 dev_kfree_skb_any(skb);
30469 - atomic_inc(&vcc->stats->tx_err);
30470 + atomic_inc_unchecked(&vcc->stats->tx_err);
30471 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30472 return -ENOMEM;
30473 }
30474 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30475 __enqueue_tpd(he_dev, tpd, cid);
30476 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30477
30478 - atomic_inc(&vcc->stats->tx);
30479 + atomic_inc_unchecked(&vcc->stats->tx);
30480
30481 return 0;
30482 }
30483 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
30484 index 7d01c2a..4e3ac01 100644
30485 --- a/drivers/atm/horizon.c
30486 +++ b/drivers/atm/horizon.c
30487 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
30488 {
30489 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
30490 // VC layer stats
30491 - atomic_inc(&vcc->stats->rx);
30492 + atomic_inc_unchecked(&vcc->stats->rx);
30493 __net_timestamp(skb);
30494 // end of our responsibility
30495 vcc->push (vcc, skb);
30496 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
30497 dev->tx_iovec = NULL;
30498
30499 // VC layer stats
30500 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30501 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30502
30503 // free the skb
30504 hrz_kfree_skb (skb);
30505 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
30506 index 8974bd2..b856f85 100644
30507 --- a/drivers/atm/idt77252.c
30508 +++ b/drivers/atm/idt77252.c
30509 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
30510 else
30511 dev_kfree_skb(skb);
30512
30513 - atomic_inc(&vcc->stats->tx);
30514 + atomic_inc_unchecked(&vcc->stats->tx);
30515 }
30516
30517 atomic_dec(&scq->used);
30518 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30519 if ((sb = dev_alloc_skb(64)) == NULL) {
30520 printk("%s: Can't allocate buffers for aal0.\n",
30521 card->name);
30522 - atomic_add(i, &vcc->stats->rx_drop);
30523 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
30524 break;
30525 }
30526 if (!atm_charge(vcc, sb->truesize)) {
30527 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
30528 card->name);
30529 - atomic_add(i - 1, &vcc->stats->rx_drop);
30530 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
30531 dev_kfree_skb(sb);
30532 break;
30533 }
30534 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30535 ATM_SKB(sb)->vcc = vcc;
30536 __net_timestamp(sb);
30537 vcc->push(vcc, sb);
30538 - atomic_inc(&vcc->stats->rx);
30539 + atomic_inc_unchecked(&vcc->stats->rx);
30540
30541 cell += ATM_CELL_PAYLOAD;
30542 }
30543 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30544 "(CDC: %08x)\n",
30545 card->name, len, rpp->len, readl(SAR_REG_CDC));
30546 recycle_rx_pool_skb(card, rpp);
30547 - atomic_inc(&vcc->stats->rx_err);
30548 + atomic_inc_unchecked(&vcc->stats->rx_err);
30549 return;
30550 }
30551 if (stat & SAR_RSQE_CRC) {
30552 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
30553 recycle_rx_pool_skb(card, rpp);
30554 - atomic_inc(&vcc->stats->rx_err);
30555 + atomic_inc_unchecked(&vcc->stats->rx_err);
30556 return;
30557 }
30558 if (skb_queue_len(&rpp->queue) > 1) {
30559 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30560 RXPRINTK("%s: Can't alloc RX skb.\n",
30561 card->name);
30562 recycle_rx_pool_skb(card, rpp);
30563 - atomic_inc(&vcc->stats->rx_err);
30564 + atomic_inc_unchecked(&vcc->stats->rx_err);
30565 return;
30566 }
30567 if (!atm_charge(vcc, skb->truesize)) {
30568 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30569 __net_timestamp(skb);
30570
30571 vcc->push(vcc, skb);
30572 - atomic_inc(&vcc->stats->rx);
30573 + atomic_inc_unchecked(&vcc->stats->rx);
30574
30575 return;
30576 }
30577 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30578 __net_timestamp(skb);
30579
30580 vcc->push(vcc, skb);
30581 - atomic_inc(&vcc->stats->rx);
30582 + atomic_inc_unchecked(&vcc->stats->rx);
30583
30584 if (skb->truesize > SAR_FB_SIZE_3)
30585 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
30586 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
30587 if (vcc->qos.aal != ATM_AAL0) {
30588 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
30589 card->name, vpi, vci);
30590 - atomic_inc(&vcc->stats->rx_drop);
30591 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30592 goto drop;
30593 }
30594
30595 if ((sb = dev_alloc_skb(64)) == NULL) {
30596 printk("%s: Can't allocate buffers for AAL0.\n",
30597 card->name);
30598 - atomic_inc(&vcc->stats->rx_err);
30599 + atomic_inc_unchecked(&vcc->stats->rx_err);
30600 goto drop;
30601 }
30602
30603 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
30604 ATM_SKB(sb)->vcc = vcc;
30605 __net_timestamp(sb);
30606 vcc->push(vcc, sb);
30607 - atomic_inc(&vcc->stats->rx);
30608 + atomic_inc_unchecked(&vcc->stats->rx);
30609
30610 drop:
30611 skb_pull(queue, 64);
30612 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30613
30614 if (vc == NULL) {
30615 printk("%s: NULL connection in send().\n", card->name);
30616 - atomic_inc(&vcc->stats->tx_err);
30617 + atomic_inc_unchecked(&vcc->stats->tx_err);
30618 dev_kfree_skb(skb);
30619 return -EINVAL;
30620 }
30621 if (!test_bit(VCF_TX, &vc->flags)) {
30622 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
30623 - atomic_inc(&vcc->stats->tx_err);
30624 + atomic_inc_unchecked(&vcc->stats->tx_err);
30625 dev_kfree_skb(skb);
30626 return -EINVAL;
30627 }
30628 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30629 break;
30630 default:
30631 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
30632 - atomic_inc(&vcc->stats->tx_err);
30633 + atomic_inc_unchecked(&vcc->stats->tx_err);
30634 dev_kfree_skb(skb);
30635 return -EINVAL;
30636 }
30637
30638 if (skb_shinfo(skb)->nr_frags != 0) {
30639 printk("%s: No scatter-gather yet.\n", card->name);
30640 - atomic_inc(&vcc->stats->tx_err);
30641 + atomic_inc_unchecked(&vcc->stats->tx_err);
30642 dev_kfree_skb(skb);
30643 return -EINVAL;
30644 }
30645 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30646
30647 err = queue_skb(card, vc, skb, oam);
30648 if (err) {
30649 - atomic_inc(&vcc->stats->tx_err);
30650 + atomic_inc_unchecked(&vcc->stats->tx_err);
30651 dev_kfree_skb(skb);
30652 return err;
30653 }
30654 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
30655 skb = dev_alloc_skb(64);
30656 if (!skb) {
30657 printk("%s: Out of memory in send_oam().\n", card->name);
30658 - atomic_inc(&vcc->stats->tx_err);
30659 + atomic_inc_unchecked(&vcc->stats->tx_err);
30660 return -ENOMEM;
30661 }
30662 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
30663 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
30664 index 96cce6d..62c3ec5 100644
30665 --- a/drivers/atm/iphase.c
30666 +++ b/drivers/atm/iphase.c
30667 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
30668 status = (u_short) (buf_desc_ptr->desc_mode);
30669 if (status & (RX_CER | RX_PTE | RX_OFL))
30670 {
30671 - atomic_inc(&vcc->stats->rx_err);
30672 + atomic_inc_unchecked(&vcc->stats->rx_err);
30673 IF_ERR(printk("IA: bad packet, dropping it");)
30674 if (status & RX_CER) {
30675 IF_ERR(printk(" cause: packet CRC error\n");)
30676 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
30677 len = dma_addr - buf_addr;
30678 if (len > iadev->rx_buf_sz) {
30679 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
30680 - atomic_inc(&vcc->stats->rx_err);
30681 + atomic_inc_unchecked(&vcc->stats->rx_err);
30682 goto out_free_desc;
30683 }
30684
30685 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30686 ia_vcc = INPH_IA_VCC(vcc);
30687 if (ia_vcc == NULL)
30688 {
30689 - atomic_inc(&vcc->stats->rx_err);
30690 + atomic_inc_unchecked(&vcc->stats->rx_err);
30691 atm_return(vcc, skb->truesize);
30692 dev_kfree_skb_any(skb);
30693 goto INCR_DLE;
30694 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30695 if ((length > iadev->rx_buf_sz) || (length >
30696 (skb->len - sizeof(struct cpcs_trailer))))
30697 {
30698 - atomic_inc(&vcc->stats->rx_err);
30699 + atomic_inc_unchecked(&vcc->stats->rx_err);
30700 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
30701 length, skb->len);)
30702 atm_return(vcc, skb->truesize);
30703 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30704
30705 IF_RX(printk("rx_dle_intr: skb push");)
30706 vcc->push(vcc,skb);
30707 - atomic_inc(&vcc->stats->rx);
30708 + atomic_inc_unchecked(&vcc->stats->rx);
30709 iadev->rx_pkt_cnt++;
30710 }
30711 INCR_DLE:
30712 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
30713 {
30714 struct k_sonet_stats *stats;
30715 stats = &PRIV(_ia_dev[board])->sonet_stats;
30716 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
30717 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
30718 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
30719 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
30720 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
30721 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
30722 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
30723 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
30724 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
30725 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
30726 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
30727 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
30728 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
30729 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
30730 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
30731 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
30732 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
30733 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
30734 }
30735 ia_cmds.status = 0;
30736 break;
30737 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30738 if ((desc == 0) || (desc > iadev->num_tx_desc))
30739 {
30740 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
30741 - atomic_inc(&vcc->stats->tx);
30742 + atomic_inc_unchecked(&vcc->stats->tx);
30743 if (vcc->pop)
30744 vcc->pop(vcc, skb);
30745 else
30746 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30747 ATM_DESC(skb) = vcc->vci;
30748 skb_queue_tail(&iadev->tx_dma_q, skb);
30749
30750 - atomic_inc(&vcc->stats->tx);
30751 + atomic_inc_unchecked(&vcc->stats->tx);
30752 iadev->tx_pkt_cnt++;
30753 /* Increment transaction counter */
30754 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
30755
30756 #if 0
30757 /* add flow control logic */
30758 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
30759 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
30760 if (iavcc->vc_desc_cnt > 10) {
30761 vcc->tx_quota = vcc->tx_quota * 3 / 4;
30762 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
30763 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
30764 index 68c7588..7036683 100644
30765 --- a/drivers/atm/lanai.c
30766 +++ b/drivers/atm/lanai.c
30767 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
30768 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
30769 lanai_endtx(lanai, lvcc);
30770 lanai_free_skb(lvcc->tx.atmvcc, skb);
30771 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
30772 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
30773 }
30774
30775 /* Try to fill the buffer - don't call unless there is backlog */
30776 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
30777 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
30778 __net_timestamp(skb);
30779 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
30780 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
30781 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
30782 out:
30783 lvcc->rx.buf.ptr = end;
30784 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
30785 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30786 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
30787 "vcc %d\n", lanai->number, (unsigned int) s, vci);
30788 lanai->stats.service_rxnotaal5++;
30789 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30790 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30791 return 0;
30792 }
30793 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
30794 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30795 int bytes;
30796 read_unlock(&vcc_sklist_lock);
30797 DPRINTK("got trashed rx pdu on vci %d\n", vci);
30798 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30799 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30800 lvcc->stats.x.aal5.service_trash++;
30801 bytes = (SERVICE_GET_END(s) * 16) -
30802 (((unsigned long) lvcc->rx.buf.ptr) -
30803 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30804 }
30805 if (s & SERVICE_STREAM) {
30806 read_unlock(&vcc_sklist_lock);
30807 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30808 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30809 lvcc->stats.x.aal5.service_stream++;
30810 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
30811 "PDU on VCI %d!\n", lanai->number, vci);
30812 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30813 return 0;
30814 }
30815 DPRINTK("got rx crc error on vci %d\n", vci);
30816 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30817 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30818 lvcc->stats.x.aal5.service_rxcrc++;
30819 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
30820 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
30821 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
30822 index 1c70c45..300718d 100644
30823 --- a/drivers/atm/nicstar.c
30824 +++ b/drivers/atm/nicstar.c
30825 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30826 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
30827 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
30828 card->index);
30829 - atomic_inc(&vcc->stats->tx_err);
30830 + atomic_inc_unchecked(&vcc->stats->tx_err);
30831 dev_kfree_skb_any(skb);
30832 return -EINVAL;
30833 }
30834 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30835 if (!vc->tx) {
30836 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
30837 card->index);
30838 - atomic_inc(&vcc->stats->tx_err);
30839 + atomic_inc_unchecked(&vcc->stats->tx_err);
30840 dev_kfree_skb_any(skb);
30841 return -EINVAL;
30842 }
30843 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30844 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
30845 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
30846 card->index);
30847 - atomic_inc(&vcc->stats->tx_err);
30848 + atomic_inc_unchecked(&vcc->stats->tx_err);
30849 dev_kfree_skb_any(skb);
30850 return -EINVAL;
30851 }
30852
30853 if (skb_shinfo(skb)->nr_frags != 0) {
30854 printk("nicstar%d: No scatter-gather yet.\n", card->index);
30855 - atomic_inc(&vcc->stats->tx_err);
30856 + atomic_inc_unchecked(&vcc->stats->tx_err);
30857 dev_kfree_skb_any(skb);
30858 return -EINVAL;
30859 }
30860 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30861 }
30862
30863 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
30864 - atomic_inc(&vcc->stats->tx_err);
30865 + atomic_inc_unchecked(&vcc->stats->tx_err);
30866 dev_kfree_skb_any(skb);
30867 return -EIO;
30868 }
30869 - atomic_inc(&vcc->stats->tx);
30870 + atomic_inc_unchecked(&vcc->stats->tx);
30871
30872 return 0;
30873 }
30874 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30875 printk
30876 ("nicstar%d: Can't allocate buffers for aal0.\n",
30877 card->index);
30878 - atomic_add(i, &vcc->stats->rx_drop);
30879 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
30880 break;
30881 }
30882 if (!atm_charge(vcc, sb->truesize)) {
30883 RXPRINTK
30884 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
30885 card->index);
30886 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30887 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30888 dev_kfree_skb_any(sb);
30889 break;
30890 }
30891 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30892 ATM_SKB(sb)->vcc = vcc;
30893 __net_timestamp(sb);
30894 vcc->push(vcc, sb);
30895 - atomic_inc(&vcc->stats->rx);
30896 + atomic_inc_unchecked(&vcc->stats->rx);
30897 cell += ATM_CELL_PAYLOAD;
30898 }
30899
30900 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30901 if (iovb == NULL) {
30902 printk("nicstar%d: Out of iovec buffers.\n",
30903 card->index);
30904 - atomic_inc(&vcc->stats->rx_drop);
30905 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30906 recycle_rx_buf(card, skb);
30907 return;
30908 }
30909 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30910 small or large buffer itself. */
30911 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
30912 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
30913 - atomic_inc(&vcc->stats->rx_err);
30914 + atomic_inc_unchecked(&vcc->stats->rx_err);
30915 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30916 NS_MAX_IOVECS);
30917 NS_PRV_IOVCNT(iovb) = 0;
30918 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30919 ("nicstar%d: Expected a small buffer, and this is not one.\n",
30920 card->index);
30921 which_list(card, skb);
30922 - atomic_inc(&vcc->stats->rx_err);
30923 + atomic_inc_unchecked(&vcc->stats->rx_err);
30924 recycle_rx_buf(card, skb);
30925 vc->rx_iov = NULL;
30926 recycle_iov_buf(card, iovb);
30927 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30928 ("nicstar%d: Expected a large buffer, and this is not one.\n",
30929 card->index);
30930 which_list(card, skb);
30931 - atomic_inc(&vcc->stats->rx_err);
30932 + atomic_inc_unchecked(&vcc->stats->rx_err);
30933 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30934 NS_PRV_IOVCNT(iovb));
30935 vc->rx_iov = NULL;
30936 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30937 printk(" - PDU size mismatch.\n");
30938 else
30939 printk(".\n");
30940 - atomic_inc(&vcc->stats->rx_err);
30941 + atomic_inc_unchecked(&vcc->stats->rx_err);
30942 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30943 NS_PRV_IOVCNT(iovb));
30944 vc->rx_iov = NULL;
30945 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30946 /* skb points to a small buffer */
30947 if (!atm_charge(vcc, skb->truesize)) {
30948 push_rxbufs(card, skb);
30949 - atomic_inc(&vcc->stats->rx_drop);
30950 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30951 } else {
30952 skb_put(skb, len);
30953 dequeue_sm_buf(card, skb);
30954 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30955 ATM_SKB(skb)->vcc = vcc;
30956 __net_timestamp(skb);
30957 vcc->push(vcc, skb);
30958 - atomic_inc(&vcc->stats->rx);
30959 + atomic_inc_unchecked(&vcc->stats->rx);
30960 }
30961 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
30962 struct sk_buff *sb;
30963 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30964 if (len <= NS_SMBUFSIZE) {
30965 if (!atm_charge(vcc, sb->truesize)) {
30966 push_rxbufs(card, sb);
30967 - atomic_inc(&vcc->stats->rx_drop);
30968 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30969 } else {
30970 skb_put(sb, len);
30971 dequeue_sm_buf(card, sb);
30972 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30973 ATM_SKB(sb)->vcc = vcc;
30974 __net_timestamp(sb);
30975 vcc->push(vcc, sb);
30976 - atomic_inc(&vcc->stats->rx);
30977 + atomic_inc_unchecked(&vcc->stats->rx);
30978 }
30979
30980 push_rxbufs(card, skb);
30981 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30982
30983 if (!atm_charge(vcc, skb->truesize)) {
30984 push_rxbufs(card, skb);
30985 - atomic_inc(&vcc->stats->rx_drop);
30986 + atomic_inc_unchecked(&vcc->stats->rx_drop);
30987 } else {
30988 dequeue_lg_buf(card, skb);
30989 #ifdef NS_USE_DESTRUCTORS
30990 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30991 ATM_SKB(skb)->vcc = vcc;
30992 __net_timestamp(skb);
30993 vcc->push(vcc, skb);
30994 - atomic_inc(&vcc->stats->rx);
30995 + atomic_inc_unchecked(&vcc->stats->rx);
30996 }
30997
30998 push_rxbufs(card, sb);
30999 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31000 printk
31001 ("nicstar%d: Out of huge buffers.\n",
31002 card->index);
31003 - atomic_inc(&vcc->stats->rx_drop);
31004 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31005 recycle_iovec_rx_bufs(card,
31006 (struct iovec *)
31007 iovb->data,
31008 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31009 card->hbpool.count++;
31010 } else
31011 dev_kfree_skb_any(hb);
31012 - atomic_inc(&vcc->stats->rx_drop);
31013 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31014 } else {
31015 /* Copy the small buffer to the huge buffer */
31016 sb = (struct sk_buff *)iov->iov_base;
31017 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31018 #endif /* NS_USE_DESTRUCTORS */
31019 __net_timestamp(hb);
31020 vcc->push(vcc, hb);
31021 - atomic_inc(&vcc->stats->rx);
31022 + atomic_inc_unchecked(&vcc->stats->rx);
31023 }
31024 }
31025
31026 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
31027 index 1853a45..cf2426d 100644
31028 --- a/drivers/atm/solos-pci.c
31029 +++ b/drivers/atm/solos-pci.c
31030 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
31031 }
31032 atm_charge(vcc, skb->truesize);
31033 vcc->push(vcc, skb);
31034 - atomic_inc(&vcc->stats->rx);
31035 + atomic_inc_unchecked(&vcc->stats->rx);
31036 break;
31037
31038 case PKT_STATUS:
31039 @@ -1010,7 +1010,7 @@ static uint32_t fpga_tx(struct solos_card *card)
31040 vcc = SKB_CB(oldskb)->vcc;
31041
31042 if (vcc) {
31043 - atomic_inc(&vcc->stats->tx);
31044 + atomic_inc_unchecked(&vcc->stats->tx);
31045 solos_pop(vcc, oldskb);
31046 } else
31047 dev_kfree_skb_irq(oldskb);
31048 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
31049 index 0215934..ce9f5b1 100644
31050 --- a/drivers/atm/suni.c
31051 +++ b/drivers/atm/suni.c
31052 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
31053
31054
31055 #define ADD_LIMITED(s,v) \
31056 - atomic_add((v),&stats->s); \
31057 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
31058 + atomic_add_unchecked((v),&stats->s); \
31059 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
31060
31061
31062 static void suni_hz(unsigned long from_timer)
31063 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
31064 index 5120a96..e2572bd 100644
31065 --- a/drivers/atm/uPD98402.c
31066 +++ b/drivers/atm/uPD98402.c
31067 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
31068 struct sonet_stats tmp;
31069 int error = 0;
31070
31071 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
31072 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
31073 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
31074 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
31075 if (zero && !error) {
31076 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
31077
31078
31079 #define ADD_LIMITED(s,v) \
31080 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
31081 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
31082 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31083 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
31084 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
31085 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31086
31087
31088 static void stat_event(struct atm_dev *dev)
31089 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
31090 if (reason & uPD98402_INT_PFM) stat_event(dev);
31091 if (reason & uPD98402_INT_PCO) {
31092 (void) GET(PCOCR); /* clear interrupt cause */
31093 - atomic_add(GET(HECCT),
31094 + atomic_add_unchecked(GET(HECCT),
31095 &PRIV(dev)->sonet_stats.uncorr_hcs);
31096 }
31097 if ((reason & uPD98402_INT_RFO) &&
31098 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
31099 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
31100 uPD98402_INT_LOS),PIMR); /* enable them */
31101 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
31102 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31103 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
31104 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
31105 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31106 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
31107 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
31108 return 0;
31109 }
31110
31111 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
31112 index abe4e20..83c4727 100644
31113 --- a/drivers/atm/zatm.c
31114 +++ b/drivers/atm/zatm.c
31115 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
31116 }
31117 if (!size) {
31118 dev_kfree_skb_irq(skb);
31119 - if (vcc) atomic_inc(&vcc->stats->rx_err);
31120 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
31121 continue;
31122 }
31123 if (!atm_charge(vcc,skb->truesize)) {
31124 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
31125 skb->len = size;
31126 ATM_SKB(skb)->vcc = vcc;
31127 vcc->push(vcc,skb);
31128 - atomic_inc(&vcc->stats->rx);
31129 + atomic_inc_unchecked(&vcc->stats->rx);
31130 }
31131 zout(pos & 0xffff,MTA(mbx));
31132 #if 0 /* probably a stupid idea */
31133 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
31134 skb_queue_head(&zatm_vcc->backlog,skb);
31135 break;
31136 }
31137 - atomic_inc(&vcc->stats->tx);
31138 + atomic_inc_unchecked(&vcc->stats->tx);
31139 wake_up(&zatm_vcc->tx_wait);
31140 }
31141
31142 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
31143 index 147d1a4..d0fd4b0 100644
31144 --- a/drivers/base/devtmpfs.c
31145 +++ b/drivers/base/devtmpfs.c
31146 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
31147 if (!thread)
31148 return 0;
31149
31150 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
31151 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
31152 if (err)
31153 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
31154 else
31155 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
31156 index e6ee5e8..98ad7fc 100644
31157 --- a/drivers/base/power/wakeup.c
31158 +++ b/drivers/base/power/wakeup.c
31159 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
31160 * They need to be modified together atomically, so it's better to use one
31161 * atomic variable to hold them both.
31162 */
31163 -static atomic_t combined_event_count = ATOMIC_INIT(0);
31164 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
31165
31166 #define IN_PROGRESS_BITS (sizeof(int) * 4)
31167 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
31168
31169 static void split_counters(unsigned int *cnt, unsigned int *inpr)
31170 {
31171 - unsigned int comb = atomic_read(&combined_event_count);
31172 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
31173
31174 *cnt = (comb >> IN_PROGRESS_BITS);
31175 *inpr = comb & MAX_IN_PROGRESS;
31176 @@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
31177 ws->start_prevent_time = ws->last_time;
31178
31179 /* Increment the counter of events in progress. */
31180 - cec = atomic_inc_return(&combined_event_count);
31181 + cec = atomic_inc_return_unchecked(&combined_event_count);
31182
31183 trace_wakeup_source_activate(ws->name, cec);
31184 }
31185 @@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
31186 * Increment the counter of registered wakeup events and decrement the
31187 * couter of wakeup events in progress simultaneously.
31188 */
31189 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
31190 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
31191 trace_wakeup_source_deactivate(ws->name, cec);
31192
31193 split_counters(&cnt, &inpr);
31194 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
31195 index ca83f96..69d4ea9 100644
31196 --- a/drivers/block/cciss.c
31197 +++ b/drivers/block/cciss.c
31198 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
31199 int err;
31200 u32 cp;
31201
31202 + memset(&arg64, 0, sizeof(arg64));
31203 +
31204 err = 0;
31205 err |=
31206 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
31207 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
31208 while (!list_empty(&h->reqQ)) {
31209 c = list_entry(h->reqQ.next, CommandList_struct, list);
31210 /* can't do anything if fifo is full */
31211 - if ((h->access.fifo_full(h))) {
31212 + if ((h->access->fifo_full(h))) {
31213 dev_warn(&h->pdev->dev, "fifo full\n");
31214 break;
31215 }
31216 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
31217 h->Qdepth--;
31218
31219 /* Tell the controller execute command */
31220 - h->access.submit_command(h, c);
31221 + h->access->submit_command(h, c);
31222
31223 /* Put job onto the completed Q */
31224 addQ(&h->cmpQ, c);
31225 @@ -3443,17 +3445,17 @@ startio:
31226
31227 static inline unsigned long get_next_completion(ctlr_info_t *h)
31228 {
31229 - return h->access.command_completed(h);
31230 + return h->access->command_completed(h);
31231 }
31232
31233 static inline int interrupt_pending(ctlr_info_t *h)
31234 {
31235 - return h->access.intr_pending(h);
31236 + return h->access->intr_pending(h);
31237 }
31238
31239 static inline long interrupt_not_for_us(ctlr_info_t *h)
31240 {
31241 - return ((h->access.intr_pending(h) == 0) ||
31242 + return ((h->access->intr_pending(h) == 0) ||
31243 (h->interrupts_enabled == 0));
31244 }
31245
31246 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
31247 u32 a;
31248
31249 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
31250 - return h->access.command_completed(h);
31251 + return h->access->command_completed(h);
31252
31253 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
31254 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
31255 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
31256 trans_support & CFGTBL_Trans_use_short_tags);
31257
31258 /* Change the access methods to the performant access methods */
31259 - h->access = SA5_performant_access;
31260 + h->access = &SA5_performant_access;
31261 h->transMethod = CFGTBL_Trans_Performant;
31262
31263 return;
31264 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
31265 if (prod_index < 0)
31266 return -ENODEV;
31267 h->product_name = products[prod_index].product_name;
31268 - h->access = *(products[prod_index].access);
31269 + h->access = products[prod_index].access;
31270
31271 if (cciss_board_disabled(h)) {
31272 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
31273 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
31274 }
31275
31276 /* make sure the board interrupts are off */
31277 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31278 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31279 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
31280 if (rc)
31281 goto clean2;
31282 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
31283 * fake ones to scoop up any residual completions.
31284 */
31285 spin_lock_irqsave(&h->lock, flags);
31286 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31287 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31288 spin_unlock_irqrestore(&h->lock, flags);
31289 free_irq(h->intr[h->intr_mode], h);
31290 rc = cciss_request_irq(h, cciss_msix_discard_completions,
31291 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
31292 dev_info(&h->pdev->dev, "Board READY.\n");
31293 dev_info(&h->pdev->dev,
31294 "Waiting for stale completions to drain.\n");
31295 - h->access.set_intr_mask(h, CCISS_INTR_ON);
31296 + h->access->set_intr_mask(h, CCISS_INTR_ON);
31297 msleep(10000);
31298 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31299 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31300
31301 rc = controller_reset_failed(h->cfgtable);
31302 if (rc)
31303 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
31304 cciss_scsi_setup(h);
31305
31306 /* Turn the interrupts on so we can service requests */
31307 - h->access.set_intr_mask(h, CCISS_INTR_ON);
31308 + h->access->set_intr_mask(h, CCISS_INTR_ON);
31309
31310 /* Get the firmware version */
31311 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
31312 @@ -5210,7 +5212,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
31313 kfree(flush_buf);
31314 if (return_code != IO_OK)
31315 dev_warn(&h->pdev->dev, "Error flushing cache\n");
31316 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
31317 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
31318 free_irq(h->intr[h->intr_mode], h);
31319 }
31320
31321 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
31322 index 7fda30e..eb5dfe0 100644
31323 --- a/drivers/block/cciss.h
31324 +++ b/drivers/block/cciss.h
31325 @@ -101,7 +101,7 @@ struct ctlr_info
31326 /* information about each logical volume */
31327 drive_info_struct *drv[CISS_MAX_LUN];
31328
31329 - struct access_method access;
31330 + struct access_method *access;
31331
31332 /* queue and queue Info */
31333 struct list_head reqQ;
31334 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
31335 index 9125bbe..eede5c8 100644
31336 --- a/drivers/block/cpqarray.c
31337 +++ b/drivers/block/cpqarray.c
31338 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
31339 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
31340 goto Enomem4;
31341 }
31342 - hba[i]->access.set_intr_mask(hba[i], 0);
31343 + hba[i]->access->set_intr_mask(hba[i], 0);
31344 if (request_irq(hba[i]->intr, do_ida_intr,
31345 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
31346 {
31347 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
31348 add_timer(&hba[i]->timer);
31349
31350 /* Enable IRQ now that spinlock and rate limit timer are set up */
31351 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
31352 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
31353
31354 for(j=0; j<NWD; j++) {
31355 struct gendisk *disk = ida_gendisk[i][j];
31356 @@ -694,7 +694,7 @@ DBGINFO(
31357 for(i=0; i<NR_PRODUCTS; i++) {
31358 if (board_id == products[i].board_id) {
31359 c->product_name = products[i].product_name;
31360 - c->access = *(products[i].access);
31361 + c->access = products[i].access;
31362 break;
31363 }
31364 }
31365 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
31366 hba[ctlr]->intr = intr;
31367 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
31368 hba[ctlr]->product_name = products[j].product_name;
31369 - hba[ctlr]->access = *(products[j].access);
31370 + hba[ctlr]->access = products[j].access;
31371 hba[ctlr]->ctlr = ctlr;
31372 hba[ctlr]->board_id = board_id;
31373 hba[ctlr]->pci_dev = NULL; /* not PCI */
31374 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
31375
31376 while((c = h->reqQ) != NULL) {
31377 /* Can't do anything if we're busy */
31378 - if (h->access.fifo_full(h) == 0)
31379 + if (h->access->fifo_full(h) == 0)
31380 return;
31381
31382 /* Get the first entry from the request Q */
31383 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
31384 h->Qdepth--;
31385
31386 /* Tell the controller to do our bidding */
31387 - h->access.submit_command(h, c);
31388 + h->access->submit_command(h, c);
31389
31390 /* Get onto the completion Q */
31391 addQ(&h->cmpQ, c);
31392 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
31393 unsigned long flags;
31394 __u32 a,a1;
31395
31396 - istat = h->access.intr_pending(h);
31397 + istat = h->access->intr_pending(h);
31398 /* Is this interrupt for us? */
31399 if (istat == 0)
31400 return IRQ_NONE;
31401 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
31402 */
31403 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
31404 if (istat & FIFO_NOT_EMPTY) {
31405 - while((a = h->access.command_completed(h))) {
31406 + while((a = h->access->command_completed(h))) {
31407 a1 = a; a &= ~3;
31408 if ((c = h->cmpQ) == NULL)
31409 {
31410 @@ -1449,11 +1449,11 @@ static int sendcmd(
31411 /*
31412 * Disable interrupt
31413 */
31414 - info_p->access.set_intr_mask(info_p, 0);
31415 + info_p->access->set_intr_mask(info_p, 0);
31416 /* Make sure there is room in the command FIFO */
31417 /* Actually it should be completely empty at this time. */
31418 for (i = 200000; i > 0; i--) {
31419 - temp = info_p->access.fifo_full(info_p);
31420 + temp = info_p->access->fifo_full(info_p);
31421 if (temp != 0) {
31422 break;
31423 }
31424 @@ -1466,7 +1466,7 @@ DBG(
31425 /*
31426 * Send the cmd
31427 */
31428 - info_p->access.submit_command(info_p, c);
31429 + info_p->access->submit_command(info_p, c);
31430 complete = pollcomplete(ctlr);
31431
31432 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
31433 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
31434 * we check the new geometry. Then turn interrupts back on when
31435 * we're done.
31436 */
31437 - host->access.set_intr_mask(host, 0);
31438 + host->access->set_intr_mask(host, 0);
31439 getgeometry(ctlr);
31440 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
31441 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
31442
31443 for(i=0; i<NWD; i++) {
31444 struct gendisk *disk = ida_gendisk[ctlr][i];
31445 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
31446 /* Wait (up to 2 seconds) for a command to complete */
31447
31448 for (i = 200000; i > 0; i--) {
31449 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
31450 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
31451 if (done == 0) {
31452 udelay(10); /* a short fixed delay */
31453 } else
31454 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
31455 index be73e9d..7fbf140 100644
31456 --- a/drivers/block/cpqarray.h
31457 +++ b/drivers/block/cpqarray.h
31458 @@ -99,7 +99,7 @@ struct ctlr_info {
31459 drv_info_t drv[NWD];
31460 struct proc_dir_entry *proc;
31461
31462 - struct access_method access;
31463 + struct access_method *access;
31464
31465 cmdlist_t *reqQ;
31466 cmdlist_t *cmpQ;
31467 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
31468 index b953cc7..e3dc580 100644
31469 --- a/drivers/block/drbd/drbd_int.h
31470 +++ b/drivers/block/drbd/drbd_int.h
31471 @@ -735,7 +735,7 @@ struct drbd_request;
31472 struct drbd_epoch {
31473 struct list_head list;
31474 unsigned int barrier_nr;
31475 - atomic_t epoch_size; /* increased on every request added. */
31476 + atomic_unchecked_t epoch_size; /* increased on every request added. */
31477 atomic_t active; /* increased on every req. added, and dec on every finished. */
31478 unsigned long flags;
31479 };
31480 @@ -1116,7 +1116,7 @@ struct drbd_conf {
31481 void *int_dig_in;
31482 void *int_dig_vv;
31483 wait_queue_head_t seq_wait;
31484 - atomic_t packet_seq;
31485 + atomic_unchecked_t packet_seq;
31486 unsigned int peer_seq;
31487 spinlock_t peer_seq_lock;
31488 unsigned int minor;
31489 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
31490
31491 static inline void drbd_tcp_cork(struct socket *sock)
31492 {
31493 - int __user val = 1;
31494 + int val = 1;
31495 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31496 - (char __user *)&val, sizeof(val));
31497 + (char __force_user *)&val, sizeof(val));
31498 }
31499
31500 static inline void drbd_tcp_uncork(struct socket *sock)
31501 {
31502 - int __user val = 0;
31503 + int val = 0;
31504 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31505 - (char __user *)&val, sizeof(val));
31506 + (char __force_user *)&val, sizeof(val));
31507 }
31508
31509 static inline void drbd_tcp_nodelay(struct socket *sock)
31510 {
31511 - int __user val = 1;
31512 + int val = 1;
31513 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
31514 - (char __user *)&val, sizeof(val));
31515 + (char __force_user *)&val, sizeof(val));
31516 }
31517
31518 static inline void drbd_tcp_quickack(struct socket *sock)
31519 {
31520 - int __user val = 2;
31521 + int val = 2;
31522 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
31523 - (char __user *)&val, sizeof(val));
31524 + (char __force_user *)&val, sizeof(val));
31525 }
31526
31527 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
31528 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
31529 index f55683a..2101b96 100644
31530 --- a/drivers/block/drbd/drbd_main.c
31531 +++ b/drivers/block/drbd/drbd_main.c
31532 @@ -2556,7 +2556,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
31533 p.sector = sector;
31534 p.block_id = block_id;
31535 p.blksize = blksize;
31536 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31537 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31538
31539 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
31540 return false;
31541 @@ -2854,7 +2854,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
31542
31543 p.sector = cpu_to_be64(req->sector);
31544 p.block_id = (unsigned long)req;
31545 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31546 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31547
31548 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
31549
31550 @@ -3139,7 +3139,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
31551 atomic_set(&mdev->unacked_cnt, 0);
31552 atomic_set(&mdev->local_cnt, 0);
31553 atomic_set(&mdev->net_cnt, 0);
31554 - atomic_set(&mdev->packet_seq, 0);
31555 + atomic_set_unchecked(&mdev->packet_seq, 0);
31556 atomic_set(&mdev->pp_in_use, 0);
31557 atomic_set(&mdev->pp_in_use_by_net, 0);
31558 atomic_set(&mdev->rs_sect_in, 0);
31559 @@ -3221,8 +3221,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
31560 mdev->receiver.t_state);
31561
31562 /* no need to lock it, I'm the only thread alive */
31563 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
31564 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
31565 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
31566 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
31567 mdev->al_writ_cnt =
31568 mdev->bm_writ_cnt =
31569 mdev->read_cnt =
31570 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
31571 index edb490a..ecd69da 100644
31572 --- a/drivers/block/drbd/drbd_nl.c
31573 +++ b/drivers/block/drbd/drbd_nl.c
31574 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
31575 module_put(THIS_MODULE);
31576 }
31577
31578 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31579 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31580
31581 static unsigned short *
31582 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
31583 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
31584 cn_reply->id.idx = CN_IDX_DRBD;
31585 cn_reply->id.val = CN_VAL_DRBD;
31586
31587 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31588 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31589 cn_reply->ack = 0; /* not used here. */
31590 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31591 (int)((char *)tl - (char *)reply->tag_list);
31592 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
31593 cn_reply->id.idx = CN_IDX_DRBD;
31594 cn_reply->id.val = CN_VAL_DRBD;
31595
31596 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31597 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31598 cn_reply->ack = 0; /* not used here. */
31599 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31600 (int)((char *)tl - (char *)reply->tag_list);
31601 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
31602 cn_reply->id.idx = CN_IDX_DRBD;
31603 cn_reply->id.val = CN_VAL_DRBD;
31604
31605 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
31606 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
31607 cn_reply->ack = 0; // not used here.
31608 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31609 (int)((char*)tl - (char*)reply->tag_list);
31610 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
31611 cn_reply->id.idx = CN_IDX_DRBD;
31612 cn_reply->id.val = CN_VAL_DRBD;
31613
31614 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31615 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31616 cn_reply->ack = 0; /* not used here. */
31617 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31618 (int)((char *)tl - (char *)reply->tag_list);
31619 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
31620 index c74ca2d..860c819 100644
31621 --- a/drivers/block/drbd/drbd_receiver.c
31622 +++ b/drivers/block/drbd/drbd_receiver.c
31623 @@ -898,7 +898,7 @@ retry:
31624 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
31625 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
31626
31627 - atomic_set(&mdev->packet_seq, 0);
31628 + atomic_set_unchecked(&mdev->packet_seq, 0);
31629 mdev->peer_seq = 0;
31630
31631 if (drbd_send_protocol(mdev) == -1)
31632 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31633 do {
31634 next_epoch = NULL;
31635
31636 - epoch_size = atomic_read(&epoch->epoch_size);
31637 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
31638
31639 switch (ev & ~EV_CLEANUP) {
31640 case EV_PUT:
31641 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31642 rv = FE_DESTROYED;
31643 } else {
31644 epoch->flags = 0;
31645 - atomic_set(&epoch->epoch_size, 0);
31646 + atomic_set_unchecked(&epoch->epoch_size, 0);
31647 /* atomic_set(&epoch->active, 0); is already zero */
31648 if (rv == FE_STILL_LIVE)
31649 rv = FE_RECYCLED;
31650 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31651 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
31652 drbd_flush(mdev);
31653
31654 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
31655 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31656 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
31657 if (epoch)
31658 break;
31659 }
31660
31661 epoch = mdev->current_epoch;
31662 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
31663 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
31664
31665 D_ASSERT(atomic_read(&epoch->active) == 0);
31666 D_ASSERT(epoch->flags == 0);
31667 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31668 }
31669
31670 epoch->flags = 0;
31671 - atomic_set(&epoch->epoch_size, 0);
31672 + atomic_set_unchecked(&epoch->epoch_size, 0);
31673 atomic_set(&epoch->active, 0);
31674
31675 spin_lock(&mdev->epoch_lock);
31676 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
31677 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31678 list_add(&epoch->list, &mdev->current_epoch->list);
31679 mdev->current_epoch = epoch;
31680 mdev->epochs++;
31681 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31682 spin_unlock(&mdev->peer_seq_lock);
31683
31684 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
31685 - atomic_inc(&mdev->current_epoch->epoch_size);
31686 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
31687 return drbd_drain_block(mdev, data_size);
31688 }
31689
31690 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31691
31692 spin_lock(&mdev->epoch_lock);
31693 e->epoch = mdev->current_epoch;
31694 - atomic_inc(&e->epoch->epoch_size);
31695 + atomic_inc_unchecked(&e->epoch->epoch_size);
31696 atomic_inc(&e->epoch->active);
31697 spin_unlock(&mdev->epoch_lock);
31698
31699 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
31700 D_ASSERT(list_empty(&mdev->done_ee));
31701
31702 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
31703 - atomic_set(&mdev->current_epoch->epoch_size, 0);
31704 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
31705 D_ASSERT(list_empty(&mdev->current_epoch->list));
31706 }
31707
31708 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
31709 index 54046e5..7759c55 100644
31710 --- a/drivers/block/loop.c
31711 +++ b/drivers/block/loop.c
31712 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
31713 mm_segment_t old_fs = get_fs();
31714
31715 set_fs(get_ds());
31716 - bw = file->f_op->write(file, buf, len, &pos);
31717 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
31718 set_fs(old_fs);
31719 if (likely(bw == len))
31720 return 0;
31721 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
31722 index d620b44..587561e 100644
31723 --- a/drivers/cdrom/cdrom.c
31724 +++ b/drivers/cdrom/cdrom.c
31725 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
31726 ENSURE(reset, CDC_RESET);
31727 ENSURE(generic_packet, CDC_GENERIC_PACKET);
31728 cdi->mc_flags = 0;
31729 - cdo->n_minors = 0;
31730 cdi->options = CDO_USE_FFLAGS;
31731
31732 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
31733 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
31734 else
31735 cdi->cdda_method = CDDA_OLD;
31736
31737 - if (!cdo->generic_packet)
31738 - cdo->generic_packet = cdrom_dummy_generic_packet;
31739 + if (!cdo->generic_packet) {
31740 + pax_open_kernel();
31741 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
31742 + pax_close_kernel();
31743 + }
31744
31745 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
31746 mutex_lock(&cdrom_mutex);
31747 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
31748 if (cdi->exit)
31749 cdi->exit(cdi);
31750
31751 - cdi->ops->n_minors--;
31752 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
31753 }
31754
31755 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
31756 index 75d485a..2809958 100644
31757 --- a/drivers/cdrom/gdrom.c
31758 +++ b/drivers/cdrom/gdrom.c
31759 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
31760 .audio_ioctl = gdrom_audio_ioctl,
31761 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
31762 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
31763 - .n_minors = 1,
31764 };
31765
31766 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
31767 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
31768 index 72bedad..8181ce1 100644
31769 --- a/drivers/char/Kconfig
31770 +++ b/drivers/char/Kconfig
31771 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
31772
31773 config DEVKMEM
31774 bool "/dev/kmem virtual device support"
31775 - default y
31776 + default n
31777 + depends on !GRKERNSEC_KMEM
31778 help
31779 Say Y here if you want to support the /dev/kmem device. The
31780 /dev/kmem device is rarely used, but can be used for certain
31781 @@ -581,6 +582,7 @@ config DEVPORT
31782 bool
31783 depends on !M68K
31784 depends on ISA || PCI
31785 + depends on !GRKERNSEC_KMEM
31786 default y
31787
31788 source "drivers/s390/char/Kconfig"
31789 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
31790 index 2e04433..22afc64 100644
31791 --- a/drivers/char/agp/frontend.c
31792 +++ b/drivers/char/agp/frontend.c
31793 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
31794 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
31795 return -EFAULT;
31796
31797 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
31798 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
31799 return -EFAULT;
31800
31801 client = agp_find_client_by_pid(reserve.pid);
31802 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
31803 index 21cb980..f15107c 100644
31804 --- a/drivers/char/genrtc.c
31805 +++ b/drivers/char/genrtc.c
31806 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
31807 switch (cmd) {
31808
31809 case RTC_PLL_GET:
31810 + memset(&pll, 0, sizeof(pll));
31811 if (get_rtc_pll(&pll))
31812 return -EINVAL;
31813 else
31814 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
31815 index dfd7876..c0b0885 100644
31816 --- a/drivers/char/hpet.c
31817 +++ b/drivers/char/hpet.c
31818 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
31819 }
31820
31821 static int
31822 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
31823 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
31824 struct hpet_info *info)
31825 {
31826 struct hpet_timer __iomem *timer;
31827 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
31828 index a0c84bb..9edcf60 100644
31829 --- a/drivers/char/ipmi/ipmi_msghandler.c
31830 +++ b/drivers/char/ipmi/ipmi_msghandler.c
31831 @@ -420,7 +420,7 @@ struct ipmi_smi {
31832 struct proc_dir_entry *proc_dir;
31833 char proc_dir_name[10];
31834
31835 - atomic_t stats[IPMI_NUM_STATS];
31836 + atomic_unchecked_t stats[IPMI_NUM_STATS];
31837
31838 /*
31839 * run_to_completion duplicate of smb_info, smi_info
31840 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
31841
31842
31843 #define ipmi_inc_stat(intf, stat) \
31844 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
31845 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
31846 #define ipmi_get_stat(intf, stat) \
31847 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
31848 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
31849
31850 static int is_lan_addr(struct ipmi_addr *addr)
31851 {
31852 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
31853 INIT_LIST_HEAD(&intf->cmd_rcvrs);
31854 init_waitqueue_head(&intf->waitq);
31855 for (i = 0; i < IPMI_NUM_STATS; i++)
31856 - atomic_set(&intf->stats[i], 0);
31857 + atomic_set_unchecked(&intf->stats[i], 0);
31858
31859 intf->proc_dir = NULL;
31860
31861 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
31862 index 32a6c7e..f6966a9 100644
31863 --- a/drivers/char/ipmi/ipmi_si_intf.c
31864 +++ b/drivers/char/ipmi/ipmi_si_intf.c
31865 @@ -275,7 +275,7 @@ struct smi_info {
31866 unsigned char slave_addr;
31867
31868 /* Counters and things for the proc filesystem. */
31869 - atomic_t stats[SI_NUM_STATS];
31870 + atomic_unchecked_t stats[SI_NUM_STATS];
31871
31872 struct task_struct *thread;
31873
31874 @@ -284,9 +284,9 @@ struct smi_info {
31875 };
31876
31877 #define smi_inc_stat(smi, stat) \
31878 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
31879 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
31880 #define smi_get_stat(smi, stat) \
31881 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
31882 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
31883
31884 #define SI_MAX_PARMS 4
31885
31886 @@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
31887 atomic_set(&new_smi->req_events, 0);
31888 new_smi->run_to_completion = 0;
31889 for (i = 0; i < SI_NUM_STATS; i++)
31890 - atomic_set(&new_smi->stats[i], 0);
31891 + atomic_set_unchecked(&new_smi->stats[i], 0);
31892
31893 new_smi->interrupt_disabled = 1;
31894 atomic_set(&new_smi->stop_operation, 0);
31895 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
31896 index 0537903..121c699 100644
31897 --- a/drivers/char/mem.c
31898 +++ b/drivers/char/mem.c
31899 @@ -18,6 +18,7 @@
31900 #include <linux/raw.h>
31901 #include <linux/tty.h>
31902 #include <linux/capability.h>
31903 +#include <linux/security.h>
31904 #include <linux/ptrace.h>
31905 #include <linux/device.h>
31906 #include <linux/highmem.h>
31907 @@ -37,6 +38,10 @@
31908
31909 #define DEVPORT_MINOR 4
31910
31911 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31912 +extern const struct file_operations grsec_fops;
31913 +#endif
31914 +
31915 static inline unsigned long size_inside_page(unsigned long start,
31916 unsigned long size)
31917 {
31918 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31919
31920 while (cursor < to) {
31921 if (!devmem_is_allowed(pfn)) {
31922 +#ifdef CONFIG_GRKERNSEC_KMEM
31923 + gr_handle_mem_readwrite(from, to);
31924 +#else
31925 printk(KERN_INFO
31926 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
31927 current->comm, from, to);
31928 +#endif
31929 return 0;
31930 }
31931 cursor += PAGE_SIZE;
31932 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31933 }
31934 return 1;
31935 }
31936 +#elif defined(CONFIG_GRKERNSEC_KMEM)
31937 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31938 +{
31939 + return 0;
31940 +}
31941 #else
31942 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31943 {
31944 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31945
31946 while (count > 0) {
31947 unsigned long remaining;
31948 + char *temp;
31949
31950 sz = size_inside_page(p, count);
31951
31952 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31953 if (!ptr)
31954 return -EFAULT;
31955
31956 - remaining = copy_to_user(buf, ptr, sz);
31957 +#ifdef CONFIG_PAX_USERCOPY
31958 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31959 + if (!temp) {
31960 + unxlate_dev_mem_ptr(p, ptr);
31961 + return -ENOMEM;
31962 + }
31963 + memcpy(temp, ptr, sz);
31964 +#else
31965 + temp = ptr;
31966 +#endif
31967 +
31968 + remaining = copy_to_user(buf, temp, sz);
31969 +
31970 +#ifdef CONFIG_PAX_USERCOPY
31971 + kfree(temp);
31972 +#endif
31973 +
31974 unxlate_dev_mem_ptr(p, ptr);
31975 if (remaining)
31976 return -EFAULT;
31977 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31978 size_t count, loff_t *ppos)
31979 {
31980 unsigned long p = *ppos;
31981 - ssize_t low_count, read, sz;
31982 + ssize_t low_count, read, sz, err = 0;
31983 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
31984 - int err = 0;
31985
31986 read = 0;
31987 if (p < (unsigned long) high_memory) {
31988 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31989 }
31990 #endif
31991 while (low_count > 0) {
31992 + char *temp;
31993 +
31994 sz = size_inside_page(p, low_count);
31995
31996 /*
31997 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31998 */
31999 kbuf = xlate_dev_kmem_ptr((char *)p);
32000
32001 - if (copy_to_user(buf, kbuf, sz))
32002 +#ifdef CONFIG_PAX_USERCOPY
32003 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
32004 + if (!temp)
32005 + return -ENOMEM;
32006 + memcpy(temp, kbuf, sz);
32007 +#else
32008 + temp = kbuf;
32009 +#endif
32010 +
32011 + err = copy_to_user(buf, temp, sz);
32012 +
32013 +#ifdef CONFIG_PAX_USERCOPY
32014 + kfree(temp);
32015 +#endif
32016 +
32017 + if (err)
32018 return -EFAULT;
32019 buf += sz;
32020 p += sz;
32021 @@ -833,6 +880,9 @@ static const struct memdev {
32022 #ifdef CONFIG_CRASH_DUMP
32023 [12] = { "oldmem", 0, &oldmem_fops, NULL },
32024 #endif
32025 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
32026 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
32027 +#endif
32028 };
32029
32030 static int memory_open(struct inode *inode, struct file *filp)
32031 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
32032 index 9df78e2..01ba9ae 100644
32033 --- a/drivers/char/nvram.c
32034 +++ b/drivers/char/nvram.c
32035 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
32036
32037 spin_unlock_irq(&rtc_lock);
32038
32039 - if (copy_to_user(buf, contents, tmp - contents))
32040 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
32041 return -EFAULT;
32042
32043 *ppos = i;
32044 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
32045 index 21721d2..4e98777 100644
32046 --- a/drivers/char/pcmcia/synclink_cs.c
32047 +++ b/drivers/char/pcmcia/synclink_cs.c
32048 @@ -2346,9 +2346,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32049
32050 if (debug_level >= DEBUG_LEVEL_INFO)
32051 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
32052 - __FILE__,__LINE__, info->device_name, port->count);
32053 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
32054
32055 - WARN_ON(!port->count);
32056 + WARN_ON(!atomic_read(&port->count));
32057
32058 if (tty_port_close_start(port, tty, filp) == 0)
32059 goto cleanup;
32060 @@ -2366,7 +2366,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32061 cleanup:
32062 if (debug_level >= DEBUG_LEVEL_INFO)
32063 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
32064 - tty->driver->name, port->count);
32065 + tty->driver->name, atomic_read(&port->count));
32066 }
32067
32068 /* Wait until the transmitter is empty.
32069 @@ -2508,7 +2508,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32070
32071 if (debug_level >= DEBUG_LEVEL_INFO)
32072 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
32073 - __FILE__,__LINE__,tty->driver->name, port->count);
32074 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
32075
32076 /* If port is closing, signal caller to try again */
32077 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
32078 @@ -2528,11 +2528,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32079 goto cleanup;
32080 }
32081 spin_lock(&port->lock);
32082 - port->count++;
32083 + atomic_inc(&port->count);
32084 spin_unlock(&port->lock);
32085 spin_unlock_irqrestore(&info->netlock, flags);
32086
32087 - if (port->count == 1) {
32088 + if (atomic_read(&port->count) == 1) {
32089 /* 1st open on this device, init hardware */
32090 retval = startup(info, tty);
32091 if (retval < 0)
32092 @@ -3886,7 +3886,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
32093 unsigned short new_crctype;
32094
32095 /* return error if TTY interface open */
32096 - if (info->port.count)
32097 + if (atomic_read(&info->port.count))
32098 return -EBUSY;
32099
32100 switch (encoding)
32101 @@ -3989,7 +3989,7 @@ static int hdlcdev_open(struct net_device *dev)
32102
32103 /* arbitrate between network and tty opens */
32104 spin_lock_irqsave(&info->netlock, flags);
32105 - if (info->port.count != 0 || info->netcount != 0) {
32106 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
32107 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
32108 spin_unlock_irqrestore(&info->netlock, flags);
32109 return -EBUSY;
32110 @@ -4078,7 +4078,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
32111 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
32112
32113 /* return error if TTY interface open */
32114 - if (info->port.count)
32115 + if (atomic_read(&info->port.count))
32116 return -EBUSY;
32117
32118 if (cmd != SIOCWANDEV)
32119 diff --git a/drivers/char/random.c b/drivers/char/random.c
32120 index b86eae9..b9c2ed7 100644
32121 --- a/drivers/char/random.c
32122 +++ b/drivers/char/random.c
32123 @@ -272,8 +272,13 @@
32124 /*
32125 * Configuration information
32126 */
32127 +#ifdef CONFIG_GRKERNSEC_RANDNET
32128 +#define INPUT_POOL_WORDS 512
32129 +#define OUTPUT_POOL_WORDS 128
32130 +#else
32131 #define INPUT_POOL_WORDS 128
32132 #define OUTPUT_POOL_WORDS 32
32133 +#endif
32134 #define SEC_XFER_SIZE 512
32135 #define EXTRACT_SIZE 10
32136
32137 @@ -313,10 +318,17 @@ static struct poolinfo {
32138 int poolwords;
32139 int tap1, tap2, tap3, tap4, tap5;
32140 } poolinfo_table[] = {
32141 +#ifdef CONFIG_GRKERNSEC_RANDNET
32142 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
32143 + { 512, 411, 308, 208, 104, 1 },
32144 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
32145 + { 128, 103, 76, 51, 25, 1 },
32146 +#else
32147 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
32148 { 128, 103, 76, 51, 25, 1 },
32149 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
32150 { 32, 26, 20, 14, 7, 1 },
32151 +#endif
32152 #if 0
32153 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
32154 { 2048, 1638, 1231, 819, 411, 1 },
32155 @@ -437,6 +449,7 @@ struct entropy_store {
32156 int entropy_count;
32157 int entropy_total;
32158 unsigned int initialized:1;
32159 + bool last_data_init;
32160 __u8 last_data[EXTRACT_SIZE];
32161 };
32162
32163 @@ -527,8 +540,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
32164 input_rotate += i ? 7 : 14;
32165 }
32166
32167 - ACCESS_ONCE(r->input_rotate) = input_rotate;
32168 - ACCESS_ONCE(r->add_ptr) = i;
32169 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
32170 + ACCESS_ONCE_RW(r->add_ptr) = i;
32171 smp_wmb();
32172
32173 if (out)
32174 @@ -957,6 +970,10 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
32175 ssize_t ret = 0, i;
32176 __u8 tmp[EXTRACT_SIZE];
32177
32178 + /* if last_data isn't primed, we need EXTRACT_SIZE extra bytes */
32179 + if (fips_enabled && !r->last_data_init)
32180 + nbytes += EXTRACT_SIZE;
32181 +
32182 trace_extract_entropy(r->name, nbytes, r->entropy_count, _RET_IP_);
32183 xfer_secondary_pool(r, nbytes);
32184 nbytes = account(r, nbytes, min, reserved);
32185 @@ -967,6 +984,17 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
32186 if (fips_enabled) {
32187 unsigned long flags;
32188
32189 +
32190 + /* prime last_data value if need be, per fips 140-2 */
32191 + if (!r->last_data_init) {
32192 + spin_lock_irqsave(&r->lock, flags);
32193 + memcpy(r->last_data, tmp, EXTRACT_SIZE);
32194 + r->last_data_init = true;
32195 + nbytes -= EXTRACT_SIZE;
32196 + spin_unlock_irqrestore(&r->lock, flags);
32197 + extract_buf(r, tmp);
32198 + }
32199 +
32200 spin_lock_irqsave(&r->lock, flags);
32201 if (!memcmp(tmp, r->last_data, EXTRACT_SIZE))
32202 panic("Hardware RNG duplicated output!\n");
32203 @@ -1008,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
32204
32205 extract_buf(r, tmp);
32206 i = min_t(int, nbytes, EXTRACT_SIZE);
32207 - if (copy_to_user(buf, tmp, i)) {
32208 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
32209 ret = -EFAULT;
32210 break;
32211 }
32212 @@ -1086,6 +1114,7 @@ static void init_std_data(struct entropy_store *r)
32213
32214 r->entropy_count = 0;
32215 r->entropy_total = 0;
32216 + r->last_data_init = false;
32217 mix_pool_bytes(r, &now, sizeof(now), NULL);
32218 for (i = r->poolinfo->POOLBYTES; i > 0; i -= sizeof(rv)) {
32219 if (!arch_get_random_long(&rv))
32220 @@ -1342,7 +1371,7 @@ EXPORT_SYMBOL(generate_random_uuid);
32221 #include <linux/sysctl.h>
32222
32223 static int min_read_thresh = 8, min_write_thresh;
32224 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
32225 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
32226 static int max_write_thresh = INPUT_POOL_WORDS * 32;
32227 static char sysctl_bootid[16];
32228
32229 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
32230 index 9b4f011..b7e0a1a 100644
32231 --- a/drivers/char/sonypi.c
32232 +++ b/drivers/char/sonypi.c
32233 @@ -54,6 +54,7 @@
32234
32235 #include <asm/uaccess.h>
32236 #include <asm/io.h>
32237 +#include <asm/local.h>
32238
32239 #include <linux/sonypi.h>
32240
32241 @@ -490,7 +491,7 @@ static struct sonypi_device {
32242 spinlock_t fifo_lock;
32243 wait_queue_head_t fifo_proc_list;
32244 struct fasync_struct *fifo_async;
32245 - int open_count;
32246 + local_t open_count;
32247 int model;
32248 struct input_dev *input_jog_dev;
32249 struct input_dev *input_key_dev;
32250 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
32251 static int sonypi_misc_release(struct inode *inode, struct file *file)
32252 {
32253 mutex_lock(&sonypi_device.lock);
32254 - sonypi_device.open_count--;
32255 + local_dec(&sonypi_device.open_count);
32256 mutex_unlock(&sonypi_device.lock);
32257 return 0;
32258 }
32259 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
32260 {
32261 mutex_lock(&sonypi_device.lock);
32262 /* Flush input queue on first open */
32263 - if (!sonypi_device.open_count)
32264 + if (!local_read(&sonypi_device.open_count))
32265 kfifo_reset(&sonypi_device.fifo);
32266 - sonypi_device.open_count++;
32267 + local_inc(&sonypi_device.open_count);
32268 mutex_unlock(&sonypi_device.lock);
32269
32270 return 0;
32271 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
32272 index 93211df..c7805f7 100644
32273 --- a/drivers/char/tpm/tpm.c
32274 +++ b/drivers/char/tpm/tpm.c
32275 @@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
32276 chip->vendor.req_complete_val)
32277 goto out_recv;
32278
32279 - if ((status == chip->vendor.req_canceled)) {
32280 + if (status == chip->vendor.req_canceled) {
32281 dev_err(chip->dev, "Operation Canceled\n");
32282 rc = -ECANCELED;
32283 goto out;
32284 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
32285 index 56051d0..11cf3b7 100644
32286 --- a/drivers/char/tpm/tpm_acpi.c
32287 +++ b/drivers/char/tpm/tpm_acpi.c
32288 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
32289 virt = acpi_os_map_memory(start, len);
32290 if (!virt) {
32291 kfree(log->bios_event_log);
32292 + log->bios_event_log = NULL;
32293 printk("%s: ERROR - Unable to map memory\n", __func__);
32294 return -EIO;
32295 }
32296
32297 - memcpy_fromio(log->bios_event_log, virt, len);
32298 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
32299
32300 acpi_os_unmap_memory(virt, len);
32301 return 0;
32302 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
32303 index 84ddc55..1d32f1e 100644
32304 --- a/drivers/char/tpm/tpm_eventlog.c
32305 +++ b/drivers/char/tpm/tpm_eventlog.c
32306 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
32307 event = addr;
32308
32309 if ((event->event_type == 0 && event->event_size == 0) ||
32310 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
32311 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
32312 return NULL;
32313
32314 return addr;
32315 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
32316 return NULL;
32317
32318 if ((event->event_type == 0 && event->event_size == 0) ||
32319 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
32320 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
32321 return NULL;
32322
32323 (*pos)++;
32324 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
32325 int i;
32326
32327 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
32328 - seq_putc(m, data[i]);
32329 + if (!seq_putc(m, data[i]))
32330 + return -EFAULT;
32331
32332 return 0;
32333 }
32334 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
32335 index 088c8fd..774c5a5 100644
32336 --- a/drivers/char/virtio_console.c
32337 +++ b/drivers/char/virtio_console.c
32338 @@ -622,7 +622,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
32339 if (to_user) {
32340 ssize_t ret;
32341
32342 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
32343 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
32344 if (ret)
32345 return -EFAULT;
32346 } else {
32347 @@ -721,7 +721,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
32348 if (!port_has_data(port) && !port->host_connected)
32349 return 0;
32350
32351 - return fill_readbuf(port, ubuf, count, true);
32352 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
32353 }
32354
32355 static int wait_port_writable(struct port *port, bool nonblock)
32356 diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
32357 index 75c0a1a..96ba8f6 100644
32358 --- a/drivers/edac/edac_mc.c
32359 +++ b/drivers/edac/edac_mc.c
32360 @@ -340,7 +340,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
32361 /*
32362 * Alocate and fill the csrow/channels structs
32363 */
32364 - mci->csrows = kcalloc(sizeof(*mci->csrows), tot_csrows, GFP_KERNEL);
32365 + mci->csrows = kcalloc(tot_csrows, sizeof(*mci->csrows), GFP_KERNEL);
32366 if (!mci->csrows)
32367 goto error;
32368 for (row = 0; row < tot_csrows; row++) {
32369 @@ -351,7 +351,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
32370 csr->csrow_idx = row;
32371 csr->mci = mci;
32372 csr->nr_channels = tot_channels;
32373 - csr->channels = kcalloc(sizeof(*csr->channels), tot_channels,
32374 + csr->channels = kcalloc(tot_channels, sizeof(*csr->channels),
32375 GFP_KERNEL);
32376 if (!csr->channels)
32377 goto error;
32378 @@ -369,7 +369,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
32379 /*
32380 * Allocate and fill the dimm structs
32381 */
32382 - mci->dimms = kcalloc(sizeof(*mci->dimms), tot_dimms, GFP_KERNEL);
32383 + mci->dimms = kcalloc(tot_dimms, sizeof(*mci->dimms), GFP_KERNEL);
32384 if (!mci->dimms)
32385 goto error;
32386
32387 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
32388 index 1bfb207..0d059c2 100644
32389 --- a/drivers/edac/edac_pci_sysfs.c
32390 +++ b/drivers/edac/edac_pci_sysfs.c
32391 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
32392 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
32393 static int edac_pci_poll_msec = 1000; /* one second workq period */
32394
32395 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
32396 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
32397 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
32398 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
32399
32400 static struct kobject *edac_pci_top_main_kobj;
32401 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
32402 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32403 edac_printk(KERN_CRIT, EDAC_PCI,
32404 "Signaled System Error on %s\n",
32405 pci_name(dev));
32406 - atomic_inc(&pci_nonparity_count);
32407 + atomic_inc_unchecked(&pci_nonparity_count);
32408 }
32409
32410 if (status & (PCI_STATUS_PARITY)) {
32411 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32412 "Master Data Parity Error on %s\n",
32413 pci_name(dev));
32414
32415 - atomic_inc(&pci_parity_count);
32416 + atomic_inc_unchecked(&pci_parity_count);
32417 }
32418
32419 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32420 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32421 "Detected Parity Error on %s\n",
32422 pci_name(dev));
32423
32424 - atomic_inc(&pci_parity_count);
32425 + atomic_inc_unchecked(&pci_parity_count);
32426 }
32427 }
32428
32429 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32430 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
32431 "Signaled System Error on %s\n",
32432 pci_name(dev));
32433 - atomic_inc(&pci_nonparity_count);
32434 + atomic_inc_unchecked(&pci_nonparity_count);
32435 }
32436
32437 if (status & (PCI_STATUS_PARITY)) {
32438 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32439 "Master Data Parity Error on "
32440 "%s\n", pci_name(dev));
32441
32442 - atomic_inc(&pci_parity_count);
32443 + atomic_inc_unchecked(&pci_parity_count);
32444 }
32445
32446 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32447 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32448 "Detected Parity Error on %s\n",
32449 pci_name(dev));
32450
32451 - atomic_inc(&pci_parity_count);
32452 + atomic_inc_unchecked(&pci_parity_count);
32453 }
32454 }
32455 }
32456 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
32457 if (!check_pci_errors)
32458 return;
32459
32460 - before_count = atomic_read(&pci_parity_count);
32461 + before_count = atomic_read_unchecked(&pci_parity_count);
32462
32463 /* scan all PCI devices looking for a Parity Error on devices and
32464 * bridges.
32465 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
32466 /* Only if operator has selected panic on PCI Error */
32467 if (edac_pci_get_panic_on_pe()) {
32468 /* If the count is different 'after' from 'before' */
32469 - if (before_count != atomic_read(&pci_parity_count))
32470 + if (before_count != atomic_read_unchecked(&pci_parity_count))
32471 panic("EDAC: PCI Parity Error");
32472 }
32473 }
32474 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
32475 index 8c87a5e..a19cbd7 100644
32476 --- a/drivers/edac/mce_amd.h
32477 +++ b/drivers/edac/mce_amd.h
32478 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
32479 struct amd_decoder_ops {
32480 bool (*dc_mce)(u16, u8);
32481 bool (*ic_mce)(u16, u8);
32482 -};
32483 +} __no_const;
32484
32485 void amd_report_gart_errors(bool);
32486 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
32487 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
32488 index 57ea7f4..789e3c3 100644
32489 --- a/drivers/firewire/core-card.c
32490 +++ b/drivers/firewire/core-card.c
32491 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
32492
32493 void fw_core_remove_card(struct fw_card *card)
32494 {
32495 - struct fw_card_driver dummy_driver = dummy_driver_template;
32496 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
32497
32498 card->driver->update_phy_reg(card, 4,
32499 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
32500 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
32501 index f8d2287..5aaf4db 100644
32502 --- a/drivers/firewire/core-cdev.c
32503 +++ b/drivers/firewire/core-cdev.c
32504 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
32505 int ret;
32506
32507 if ((request->channels == 0 && request->bandwidth == 0) ||
32508 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
32509 - request->bandwidth < 0)
32510 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
32511 return -EINVAL;
32512
32513 r = kmalloc(sizeof(*r), GFP_KERNEL);
32514 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
32515 index 28a94c7..58da63a 100644
32516 --- a/drivers/firewire/core-transaction.c
32517 +++ b/drivers/firewire/core-transaction.c
32518 @@ -38,6 +38,7 @@
32519 #include <linux/timer.h>
32520 #include <linux/types.h>
32521 #include <linux/workqueue.h>
32522 +#include <linux/sched.h>
32523
32524 #include <asm/byteorder.h>
32525
32526 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
32527 index 515a42c..5ecf3ba 100644
32528 --- a/drivers/firewire/core.h
32529 +++ b/drivers/firewire/core.h
32530 @@ -111,6 +111,7 @@ struct fw_card_driver {
32531
32532 int (*stop_iso)(struct fw_iso_context *ctx);
32533 };
32534 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
32535
32536 void fw_card_initialize(struct fw_card *card,
32537 const struct fw_card_driver *driver, struct device *device);
32538 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
32539 index 982f1f5..d21e5da 100644
32540 --- a/drivers/firmware/dmi_scan.c
32541 +++ b/drivers/firmware/dmi_scan.c
32542 @@ -491,11 +491,6 @@ void __init dmi_scan_machine(void)
32543 }
32544 }
32545 else {
32546 - /*
32547 - * no iounmap() for that ioremap(); it would be a no-op, but
32548 - * it's so early in setup that sucker gets confused into doing
32549 - * what it shouldn't if we actually call it.
32550 - */
32551 p = dmi_ioremap(0xF0000, 0x10000);
32552 if (p == NULL)
32553 goto error;
32554 @@ -770,7 +765,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
32555 if (buf == NULL)
32556 return -1;
32557
32558 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
32559 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
32560
32561 iounmap(buf);
32562 return 0;
32563 diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
32564 index bfd8f43..133189c 100644
32565 --- a/drivers/firmware/efivars.c
32566 +++ b/drivers/firmware/efivars.c
32567 @@ -1234,9 +1234,9 @@ efivars_init(void)
32568 return -ENOMEM;
32569 }
32570
32571 - ops.get_variable = efi.get_variable;
32572 - ops.set_variable = efi.set_variable;
32573 - ops.get_next_variable = efi.get_next_variable;
32574 + *(void **)&ops.get_variable = efi.get_variable;
32575 + *(void **)&ops.set_variable = efi.set_variable;
32576 + *(void **)&ops.get_next_variable = efi.get_next_variable;
32577 error = register_efivars(&__efivars, &ops, efi_kobj);
32578 if (error)
32579 goto err_put;
32580 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
32581 index 82d5c20..44a7177 100644
32582 --- a/drivers/gpio/gpio-vr41xx.c
32583 +++ b/drivers/gpio/gpio-vr41xx.c
32584 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
32585 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
32586 maskl, pendl, maskh, pendh);
32587
32588 - atomic_inc(&irq_err_count);
32589 + atomic_inc_unchecked(&irq_err_count);
32590
32591 return -EINVAL;
32592 }
32593 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
32594 index 1227adf..f2301c2 100644
32595 --- a/drivers/gpu/drm/drm_crtc_helper.c
32596 +++ b/drivers/gpu/drm/drm_crtc_helper.c
32597 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
32598 struct drm_crtc *tmp;
32599 int crtc_mask = 1;
32600
32601 - WARN(!crtc, "checking null crtc?\n");
32602 + BUG_ON(!crtc);
32603
32604 dev = crtc->dev;
32605
32606 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
32607 index be174ca..0bcbb71 100644
32608 --- a/drivers/gpu/drm/drm_drv.c
32609 +++ b/drivers/gpu/drm/drm_drv.c
32610 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
32611 /**
32612 * Copy and IOCTL return string to user space
32613 */
32614 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
32615 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
32616 {
32617 int len;
32618
32619 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
32620 return -ENODEV;
32621
32622 atomic_inc(&dev->ioctl_count);
32623 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
32624 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
32625 ++file_priv->ioctl_count;
32626
32627 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
32628 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
32629 index 133b413..fd68225 100644
32630 --- a/drivers/gpu/drm/drm_fops.c
32631 +++ b/drivers/gpu/drm/drm_fops.c
32632 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
32633 }
32634
32635 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
32636 - atomic_set(&dev->counts[i], 0);
32637 + atomic_set_unchecked(&dev->counts[i], 0);
32638
32639 dev->sigdata.lock = NULL;
32640
32641 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
32642 if (drm_device_is_unplugged(dev))
32643 return -ENODEV;
32644
32645 - if (!dev->open_count++)
32646 + if (local_inc_return(&dev->open_count) == 1)
32647 need_setup = 1;
32648 mutex_lock(&dev->struct_mutex);
32649 old_mapping = dev->dev_mapping;
32650 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
32651 retcode = drm_open_helper(inode, filp, dev);
32652 if (retcode)
32653 goto err_undo;
32654 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
32655 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
32656 if (need_setup) {
32657 retcode = drm_setup(dev);
32658 if (retcode)
32659 @@ -164,7 +164,7 @@ err_undo:
32660 iput(container_of(dev->dev_mapping, struct inode, i_data));
32661 dev->dev_mapping = old_mapping;
32662 mutex_unlock(&dev->struct_mutex);
32663 - dev->open_count--;
32664 + local_dec(&dev->open_count);
32665 return retcode;
32666 }
32667 EXPORT_SYMBOL(drm_open);
32668 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
32669
32670 mutex_lock(&drm_global_mutex);
32671
32672 - DRM_DEBUG("open_count = %d\n", dev->open_count);
32673 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
32674
32675 if (dev->driver->preclose)
32676 dev->driver->preclose(dev, file_priv);
32677 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
32678 * Begin inline drm_release
32679 */
32680
32681 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
32682 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
32683 task_pid_nr(current),
32684 (long)old_encode_dev(file_priv->minor->device),
32685 - dev->open_count);
32686 + local_read(&dev->open_count));
32687
32688 /* Release any auth tokens that might point to this file_priv,
32689 (do that under the drm_global_mutex) */
32690 @@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
32691 * End inline drm_release
32692 */
32693
32694 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
32695 - if (!--dev->open_count) {
32696 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
32697 + if (local_dec_and_test(&dev->open_count)) {
32698 if (atomic_read(&dev->ioctl_count)) {
32699 DRM_ERROR("Device busy: %d\n",
32700 atomic_read(&dev->ioctl_count));
32701 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
32702 index f731116..629842c 100644
32703 --- a/drivers/gpu/drm/drm_global.c
32704 +++ b/drivers/gpu/drm/drm_global.c
32705 @@ -36,7 +36,7 @@
32706 struct drm_global_item {
32707 struct mutex mutex;
32708 void *object;
32709 - int refcount;
32710 + atomic_t refcount;
32711 };
32712
32713 static struct drm_global_item glob[DRM_GLOBAL_NUM];
32714 @@ -49,7 +49,7 @@ void drm_global_init(void)
32715 struct drm_global_item *item = &glob[i];
32716 mutex_init(&item->mutex);
32717 item->object = NULL;
32718 - item->refcount = 0;
32719 + atomic_set(&item->refcount, 0);
32720 }
32721 }
32722
32723 @@ -59,7 +59,7 @@ void drm_global_release(void)
32724 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
32725 struct drm_global_item *item = &glob[i];
32726 BUG_ON(item->object != NULL);
32727 - BUG_ON(item->refcount != 0);
32728 + BUG_ON(atomic_read(&item->refcount) != 0);
32729 }
32730 }
32731
32732 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32733 void *object;
32734
32735 mutex_lock(&item->mutex);
32736 - if (item->refcount == 0) {
32737 + if (atomic_read(&item->refcount) == 0) {
32738 item->object = kzalloc(ref->size, GFP_KERNEL);
32739 if (unlikely(item->object == NULL)) {
32740 ret = -ENOMEM;
32741 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32742 goto out_err;
32743
32744 }
32745 - ++item->refcount;
32746 + atomic_inc(&item->refcount);
32747 ref->object = item->object;
32748 object = item->object;
32749 mutex_unlock(&item->mutex);
32750 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
32751 struct drm_global_item *item = &glob[ref->global_type];
32752
32753 mutex_lock(&item->mutex);
32754 - BUG_ON(item->refcount == 0);
32755 + BUG_ON(atomic_read(&item->refcount) == 0);
32756 BUG_ON(ref->object != item->object);
32757 - if (--item->refcount == 0) {
32758 + if (atomic_dec_and_test(&item->refcount)) {
32759 ref->release(ref);
32760 item->object = NULL;
32761 }
32762 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
32763 index d4b20ce..77a8d41 100644
32764 --- a/drivers/gpu/drm/drm_info.c
32765 +++ b/drivers/gpu/drm/drm_info.c
32766 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
32767 struct drm_local_map *map;
32768 struct drm_map_list *r_list;
32769
32770 - /* Hardcoded from _DRM_FRAME_BUFFER,
32771 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
32772 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
32773 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
32774 + static const char * const types[] = {
32775 + [_DRM_FRAME_BUFFER] = "FB",
32776 + [_DRM_REGISTERS] = "REG",
32777 + [_DRM_SHM] = "SHM",
32778 + [_DRM_AGP] = "AGP",
32779 + [_DRM_SCATTER_GATHER] = "SG",
32780 + [_DRM_CONSISTENT] = "PCI",
32781 + [_DRM_GEM] = "GEM" };
32782 const char *type;
32783 int i;
32784
32785 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
32786 map = r_list->map;
32787 if (!map)
32788 continue;
32789 - if (map->type < 0 || map->type > 5)
32790 + if (map->type >= ARRAY_SIZE(types))
32791 type = "??";
32792 else
32793 type = types[map->type];
32794 @@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
32795 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
32796 vma->vm_flags & VM_LOCKED ? 'l' : '-',
32797 vma->vm_flags & VM_IO ? 'i' : '-',
32798 +#ifdef CONFIG_GRKERNSEC_HIDESYM
32799 + 0);
32800 +#else
32801 vma->vm_pgoff);
32802 +#endif
32803
32804 #if defined(__i386__)
32805 pgprot = pgprot_val(vma->vm_page_prot);
32806 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
32807 index 2f4c434..764794b 100644
32808 --- a/drivers/gpu/drm/drm_ioc32.c
32809 +++ b/drivers/gpu/drm/drm_ioc32.c
32810 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
32811 request = compat_alloc_user_space(nbytes);
32812 if (!access_ok(VERIFY_WRITE, request, nbytes))
32813 return -EFAULT;
32814 - list = (struct drm_buf_desc *) (request + 1);
32815 + list = (struct drm_buf_desc __user *) (request + 1);
32816
32817 if (__put_user(count, &request->count)
32818 || __put_user(list, &request->list))
32819 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
32820 request = compat_alloc_user_space(nbytes);
32821 if (!access_ok(VERIFY_WRITE, request, nbytes))
32822 return -EFAULT;
32823 - list = (struct drm_buf_pub *) (request + 1);
32824 + list = (struct drm_buf_pub __user *) (request + 1);
32825
32826 if (__put_user(count, &request->count)
32827 || __put_user(list, &request->list))
32828 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
32829 index 23dd975..63e9801 100644
32830 --- a/drivers/gpu/drm/drm_ioctl.c
32831 +++ b/drivers/gpu/drm/drm_ioctl.c
32832 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
32833 stats->data[i].value =
32834 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
32835 else
32836 - stats->data[i].value = atomic_read(&dev->counts[i]);
32837 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
32838 stats->data[i].type = dev->types[i];
32839 }
32840
32841 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
32842 index d752c96..fe08455 100644
32843 --- a/drivers/gpu/drm/drm_lock.c
32844 +++ b/drivers/gpu/drm/drm_lock.c
32845 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32846 if (drm_lock_take(&master->lock, lock->context)) {
32847 master->lock.file_priv = file_priv;
32848 master->lock.lock_time = jiffies;
32849 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
32850 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
32851 break; /* Got lock */
32852 }
32853
32854 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32855 return -EINVAL;
32856 }
32857
32858 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
32859 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
32860
32861 if (drm_lock_free(&master->lock, lock->context)) {
32862 /* FIXME: Should really bail out here. */
32863 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
32864 index c236fd2..6b5f2e7 100644
32865 --- a/drivers/gpu/drm/drm_stub.c
32866 +++ b/drivers/gpu/drm/drm_stub.c
32867 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
32868
32869 drm_device_set_unplugged(dev);
32870
32871 - if (dev->open_count == 0) {
32872 + if (local_read(&dev->open_count) == 0) {
32873 drm_put_dev(dev);
32874 }
32875 mutex_unlock(&drm_global_mutex);
32876 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
32877 index 004ecdf..db1f6e0 100644
32878 --- a/drivers/gpu/drm/i810/i810_dma.c
32879 +++ b/drivers/gpu/drm/i810/i810_dma.c
32880 @@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
32881 dma->buflist[vertex->idx],
32882 vertex->discard, vertex->used);
32883
32884 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32885 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32886 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32887 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32888 sarea_priv->last_enqueue = dev_priv->counter - 1;
32889 sarea_priv->last_dispatch = (int)hw_status[5];
32890
32891 @@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
32892 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
32893 mc->last_render);
32894
32895 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32896 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32897 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32898 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32899 sarea_priv->last_enqueue = dev_priv->counter - 1;
32900 sarea_priv->last_dispatch = (int)hw_status[5];
32901
32902 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
32903 index 6e0acad..93c8289 100644
32904 --- a/drivers/gpu/drm/i810/i810_drv.h
32905 +++ b/drivers/gpu/drm/i810/i810_drv.h
32906 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
32907 int page_flipping;
32908
32909 wait_queue_head_t irq_queue;
32910 - atomic_t irq_received;
32911 - atomic_t irq_emitted;
32912 + atomic_unchecked_t irq_received;
32913 + atomic_unchecked_t irq_emitted;
32914
32915 int front_offset;
32916 } drm_i810_private_t;
32917 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
32918 index 3a1a495..995c093 100644
32919 --- a/drivers/gpu/drm/i915/i915_debugfs.c
32920 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
32921 @@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
32922 I915_READ(GTIMR));
32923 }
32924 seq_printf(m, "Interrupts received: %d\n",
32925 - atomic_read(&dev_priv->irq_received));
32926 + atomic_read_unchecked(&dev_priv->irq_received));
32927 for_each_ring(ring, dev_priv, i) {
32928 if (IS_GEN6(dev) || IS_GEN7(dev)) {
32929 seq_printf(m,
32930 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
32931 index 61ae104..f8a4bc1 100644
32932 --- a/drivers/gpu/drm/i915/i915_dma.c
32933 +++ b/drivers/gpu/drm/i915/i915_dma.c
32934 @@ -1274,7 +1274,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
32935 bool can_switch;
32936
32937 spin_lock(&dev->count_lock);
32938 - can_switch = (dev->open_count == 0);
32939 + can_switch = (local_read(&dev->open_count) == 0);
32940 spin_unlock(&dev->count_lock);
32941 return can_switch;
32942 }
32943 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
32944 index 92f1750..3beba74 100644
32945 --- a/drivers/gpu/drm/i915/i915_drv.h
32946 +++ b/drivers/gpu/drm/i915/i915_drv.h
32947 @@ -430,7 +430,7 @@ typedef struct drm_i915_private {
32948
32949 struct resource mch_res;
32950
32951 - atomic_t irq_received;
32952 + atomic_unchecked_t irq_received;
32953
32954 /* protects the irq masks */
32955 spinlock_t irq_lock;
32956 @@ -1055,7 +1055,7 @@ struct drm_i915_gem_object {
32957 * will be page flipped away on the next vblank. When it
32958 * reaches 0, dev_priv->pending_flip_queue will be woken up.
32959 */
32960 - atomic_t pending_flip;
32961 + atomic_unchecked_t pending_flip;
32962 };
32963
32964 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
32965 @@ -1558,7 +1558,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
32966 struct drm_i915_private *dev_priv, unsigned port);
32967 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
32968 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
32969 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32970 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32971 {
32972 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
32973 }
32974 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32975 index 67036e9..b9f1357 100644
32976 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32977 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32978 @@ -681,7 +681,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
32979 i915_gem_clflush_object(obj);
32980
32981 if (obj->base.pending_write_domain)
32982 - flips |= atomic_read(&obj->pending_flip);
32983 + flips |= atomic_read_unchecked(&obj->pending_flip);
32984
32985 flush_domains |= obj->base.write_domain;
32986 }
32987 @@ -712,9 +712,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
32988
32989 static int
32990 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
32991 - int count)
32992 + unsigned int count)
32993 {
32994 - int i;
32995 + unsigned int i;
32996
32997 for (i = 0; i < count; i++) {
32998 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
32999 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
33000 index dc29ace..137d83a 100644
33001 --- a/drivers/gpu/drm/i915/i915_irq.c
33002 +++ b/drivers/gpu/drm/i915/i915_irq.c
33003 @@ -531,7 +531,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
33004 u32 pipe_stats[I915_MAX_PIPES];
33005 bool blc_event;
33006
33007 - atomic_inc(&dev_priv->irq_received);
33008 + atomic_inc_unchecked(&dev_priv->irq_received);
33009
33010 while (true) {
33011 iir = I915_READ(VLV_IIR);
33012 @@ -678,7 +678,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
33013 irqreturn_t ret = IRQ_NONE;
33014 int i;
33015
33016 - atomic_inc(&dev_priv->irq_received);
33017 + atomic_inc_unchecked(&dev_priv->irq_received);
33018
33019 /* disable master interrupt before clearing iir */
33020 de_ier = I915_READ(DEIER);
33021 @@ -753,7 +753,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
33022 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
33023 u32 hotplug_mask;
33024
33025 - atomic_inc(&dev_priv->irq_received);
33026 + atomic_inc_unchecked(&dev_priv->irq_received);
33027
33028 /* disable master interrupt before clearing iir */
33029 de_ier = I915_READ(DEIER);
33030 @@ -1762,7 +1762,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
33031 {
33032 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33033
33034 - atomic_set(&dev_priv->irq_received, 0);
33035 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33036
33037 I915_WRITE(HWSTAM, 0xeffe);
33038
33039 @@ -1788,7 +1788,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
33040 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33041 int pipe;
33042
33043 - atomic_set(&dev_priv->irq_received, 0);
33044 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33045
33046 /* VLV magic */
33047 I915_WRITE(VLV_IMR, 0);
33048 @@ -2093,7 +2093,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
33049 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33050 int pipe;
33051
33052 - atomic_set(&dev_priv->irq_received, 0);
33053 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33054
33055 for_each_pipe(pipe)
33056 I915_WRITE(PIPESTAT(pipe), 0);
33057 @@ -2144,7 +2144,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
33058 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
33059 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
33060
33061 - atomic_inc(&dev_priv->irq_received);
33062 + atomic_inc_unchecked(&dev_priv->irq_received);
33063
33064 iir = I915_READ16(IIR);
33065 if (iir == 0)
33066 @@ -2229,7 +2229,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
33067 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33068 int pipe;
33069
33070 - atomic_set(&dev_priv->irq_received, 0);
33071 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33072
33073 if (I915_HAS_HOTPLUG(dev)) {
33074 I915_WRITE(PORT_HOTPLUG_EN, 0);
33075 @@ -2324,7 +2324,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
33076 };
33077 int pipe, ret = IRQ_NONE;
33078
33079 - atomic_inc(&dev_priv->irq_received);
33080 + atomic_inc_unchecked(&dev_priv->irq_received);
33081
33082 iir = I915_READ(IIR);
33083 do {
33084 @@ -2450,7 +2450,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
33085 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33086 int pipe;
33087
33088 - atomic_set(&dev_priv->irq_received, 0);
33089 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33090
33091 I915_WRITE(PORT_HOTPLUG_EN, 0);
33092 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
33093 @@ -2557,7 +2557,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
33094 int irq_received;
33095 int ret = IRQ_NONE, pipe;
33096
33097 - atomic_inc(&dev_priv->irq_received);
33098 + atomic_inc_unchecked(&dev_priv->irq_received);
33099
33100 iir = I915_READ(IIR);
33101
33102 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
33103 index 4d3c7c6..eaac87b 100644
33104 --- a/drivers/gpu/drm/i915/intel_display.c
33105 +++ b/drivers/gpu/drm/i915/intel_display.c
33106 @@ -2131,7 +2131,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
33107
33108 wait_event(dev_priv->pending_flip_queue,
33109 atomic_read(&dev_priv->mm.wedged) ||
33110 - atomic_read(&obj->pending_flip) == 0);
33111 + atomic_read_unchecked(&obj->pending_flip) == 0);
33112
33113 /* Big Hammer, we also need to ensure that any pending
33114 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
33115 @@ -6221,8 +6221,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
33116
33117 obj = work->old_fb_obj;
33118
33119 - atomic_clear_mask(1 << intel_crtc->plane,
33120 - &obj->pending_flip.counter);
33121 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
33122 wake_up(&dev_priv->pending_flip_queue);
33123
33124 queue_work(dev_priv->wq, &work->work);
33125 @@ -6589,7 +6588,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33126 /* Block clients from rendering to the new back buffer until
33127 * the flip occurs and the object is no longer visible.
33128 */
33129 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33130 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33131 atomic_inc(&intel_crtc->unpin_work_count);
33132
33133 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
33134 @@ -6606,7 +6605,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33135
33136 cleanup_pending:
33137 atomic_dec(&intel_crtc->unpin_work_count);
33138 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33139 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33140 drm_gem_object_unreference(&work->old_fb_obj->base);
33141 drm_gem_object_unreference(&obj->base);
33142 mutex_unlock(&dev->struct_mutex);
33143 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
33144 index 54558a0..2d97005 100644
33145 --- a/drivers/gpu/drm/mga/mga_drv.h
33146 +++ b/drivers/gpu/drm/mga/mga_drv.h
33147 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
33148 u32 clear_cmd;
33149 u32 maccess;
33150
33151 - atomic_t vbl_received; /**< Number of vblanks received. */
33152 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
33153 wait_queue_head_t fence_queue;
33154 - atomic_t last_fence_retired;
33155 + atomic_unchecked_t last_fence_retired;
33156 u32 next_fence_to_post;
33157
33158 unsigned int fb_cpp;
33159 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
33160 index 598c281..60d590e 100644
33161 --- a/drivers/gpu/drm/mga/mga_irq.c
33162 +++ b/drivers/gpu/drm/mga/mga_irq.c
33163 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
33164 if (crtc != 0)
33165 return 0;
33166
33167 - return atomic_read(&dev_priv->vbl_received);
33168 + return atomic_read_unchecked(&dev_priv->vbl_received);
33169 }
33170
33171
33172 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33173 /* VBLANK interrupt */
33174 if (status & MGA_VLINEPEN) {
33175 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
33176 - atomic_inc(&dev_priv->vbl_received);
33177 + atomic_inc_unchecked(&dev_priv->vbl_received);
33178 drm_handle_vblank(dev, 0);
33179 handled = 1;
33180 }
33181 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33182 if ((prim_start & ~0x03) != (prim_end & ~0x03))
33183 MGA_WRITE(MGA_PRIMEND, prim_end);
33184
33185 - atomic_inc(&dev_priv->last_fence_retired);
33186 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
33187 DRM_WAKEUP(&dev_priv->fence_queue);
33188 handled = 1;
33189 }
33190 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
33191 * using fences.
33192 */
33193 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
33194 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
33195 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
33196 - *sequence) <= (1 << 23)));
33197
33198 *sequence = cur_fence;
33199 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
33200 index 09fdef2..57f5c3b 100644
33201 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
33202 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
33203 @@ -1240,7 +1240,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
33204 struct bit_table {
33205 const char id;
33206 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
33207 -};
33208 +} __no_const;
33209
33210 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
33211
33212 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
33213 index a101699..a163f0a 100644
33214 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
33215 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
33216 @@ -80,7 +80,7 @@ struct nouveau_drm {
33217 struct drm_global_reference mem_global_ref;
33218 struct ttm_bo_global_ref bo_global_ref;
33219 struct ttm_bo_device bdev;
33220 - atomic_t validate_sequence;
33221 + atomic_unchecked_t validate_sequence;
33222 int (*move)(struct nouveau_channel *,
33223 struct ttm_buffer_object *,
33224 struct ttm_mem_reg *, struct ttm_mem_reg *);
33225 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
33226 index cdb83ac..27f0a16 100644
33227 --- a/drivers/gpu/drm/nouveau/nouveau_fence.h
33228 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
33229 @@ -43,7 +43,7 @@ struct nouveau_fence_priv {
33230 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
33231 struct nouveau_channel *);
33232 u32 (*read)(struct nouveau_channel *);
33233 -};
33234 +} __no_const;
33235
33236 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
33237
33238 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
33239 index 5e2f521..0d21436 100644
33240 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
33241 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
33242 @@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
33243 int trycnt = 0;
33244 int ret, i;
33245
33246 - sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
33247 + sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
33248 retry:
33249 if (++trycnt > 100000) {
33250 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
33251 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
33252 index 6f0ac64..9c2dfb4 100644
33253 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
33254 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
33255 @@ -63,7 +63,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
33256 bool can_switch;
33257
33258 spin_lock(&dev->count_lock);
33259 - can_switch = (dev->open_count == 0);
33260 + can_switch = (local_read(&dev->open_count) == 0);
33261 spin_unlock(&dev->count_lock);
33262 return can_switch;
33263 }
33264 diff --git a/drivers/gpu/drm/nouveau/nv50_evo.c b/drivers/gpu/drm/nouveau/nv50_evo.c
33265 index 9f6f55c..30e3a29 100644
33266 --- a/drivers/gpu/drm/nouveau/nv50_evo.c
33267 +++ b/drivers/gpu/drm/nouveau/nv50_evo.c
33268 @@ -152,9 +152,9 @@ nv50_evo_channel_new(struct drm_device *dev, int chid,
33269 kzalloc(sizeof(*evo->object->oclass), GFP_KERNEL);
33270 evo->object->oclass->ofuncs =
33271 kzalloc(sizeof(*evo->object->oclass->ofuncs), GFP_KERNEL);
33272 - evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
33273 - evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
33274 - evo->object->oclass->ofuncs->rd08 =
33275 + *(void**)&evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
33276 + *(void**)&evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
33277 + *(void**)&evo->object->oclass->ofuncs->rd08 =
33278 ioremap(pci_resource_start(dev->pdev, 0) +
33279 NV50_PDISPLAY_USER(evo->handle), PAGE_SIZE);
33280 return 0;
33281 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
33282 index b562b59..9d725a8 100644
33283 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
33284 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
33285 @@ -317,7 +317,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
33286 }
33287
33288 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
33289 - struct dp_train_func func = {
33290 + static struct dp_train_func func = {
33291 .link_set = nv50_sor_dp_link_set,
33292 .train_set = nv50_sor_dp_train_set,
33293 .train_adj = nv50_sor_dp_train_adj
33294 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
33295 index c402fca..f1d694b 100644
33296 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
33297 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
33298 @@ -1389,7 +1389,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
33299 nv_wait(device, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
33300
33301 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
33302 - struct dp_train_func func = {
33303 + static struct dp_train_func func = {
33304 .link_set = nvd0_sor_dp_link_set,
33305 .train_set = nvd0_sor_dp_train_set,
33306 .train_adj = nvd0_sor_dp_train_adj
33307 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
33308 index d4660cf..70dbe65 100644
33309 --- a/drivers/gpu/drm/r128/r128_cce.c
33310 +++ b/drivers/gpu/drm/r128/r128_cce.c
33311 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
33312
33313 /* GH: Simple idle check.
33314 */
33315 - atomic_set(&dev_priv->idle_count, 0);
33316 + atomic_set_unchecked(&dev_priv->idle_count, 0);
33317
33318 /* We don't support anything other than bus-mastering ring mode,
33319 * but the ring can be in either AGP or PCI space for the ring
33320 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
33321 index 930c71b..499aded 100644
33322 --- a/drivers/gpu/drm/r128/r128_drv.h
33323 +++ b/drivers/gpu/drm/r128/r128_drv.h
33324 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
33325 int is_pci;
33326 unsigned long cce_buffers_offset;
33327
33328 - atomic_t idle_count;
33329 + atomic_unchecked_t idle_count;
33330
33331 int page_flipping;
33332 int current_page;
33333 u32 crtc_offset;
33334 u32 crtc_offset_cntl;
33335
33336 - atomic_t vbl_received;
33337 + atomic_unchecked_t vbl_received;
33338
33339 u32 color_fmt;
33340 unsigned int front_offset;
33341 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
33342 index 2ea4f09..d391371 100644
33343 --- a/drivers/gpu/drm/r128/r128_irq.c
33344 +++ b/drivers/gpu/drm/r128/r128_irq.c
33345 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
33346 if (crtc != 0)
33347 return 0;
33348
33349 - return atomic_read(&dev_priv->vbl_received);
33350 + return atomic_read_unchecked(&dev_priv->vbl_received);
33351 }
33352
33353 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33354 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33355 /* VBLANK interrupt */
33356 if (status & R128_CRTC_VBLANK_INT) {
33357 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
33358 - atomic_inc(&dev_priv->vbl_received);
33359 + atomic_inc_unchecked(&dev_priv->vbl_received);
33360 drm_handle_vblank(dev, 0);
33361 return IRQ_HANDLED;
33362 }
33363 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
33364 index 19bb7e6..de7e2a2 100644
33365 --- a/drivers/gpu/drm/r128/r128_state.c
33366 +++ b/drivers/gpu/drm/r128/r128_state.c
33367 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
33368
33369 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
33370 {
33371 - if (atomic_read(&dev_priv->idle_count) == 0)
33372 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
33373 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
33374 else
33375 - atomic_set(&dev_priv->idle_count, 0);
33376 + atomic_set_unchecked(&dev_priv->idle_count, 0);
33377 }
33378
33379 #endif
33380 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
33381 index 5a82b6b..9e69c73 100644
33382 --- a/drivers/gpu/drm/radeon/mkregtable.c
33383 +++ b/drivers/gpu/drm/radeon/mkregtable.c
33384 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
33385 regex_t mask_rex;
33386 regmatch_t match[4];
33387 char buf[1024];
33388 - size_t end;
33389 + long end;
33390 int len;
33391 int done = 0;
33392 int r;
33393 unsigned o;
33394 struct offset *offset;
33395 char last_reg_s[10];
33396 - int last_reg;
33397 + unsigned long last_reg;
33398
33399 if (regcomp
33400 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
33401 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
33402 index 008d645..de03849 100644
33403 --- a/drivers/gpu/drm/radeon/radeon_device.c
33404 +++ b/drivers/gpu/drm/radeon/radeon_device.c
33405 @@ -941,7 +941,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
33406 bool can_switch;
33407
33408 spin_lock(&dev->count_lock);
33409 - can_switch = (dev->open_count == 0);
33410 + can_switch = (local_read(&dev->open_count) == 0);
33411 spin_unlock(&dev->count_lock);
33412 return can_switch;
33413 }
33414 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
33415 index a1b59ca..86f2d44 100644
33416 --- a/drivers/gpu/drm/radeon/radeon_drv.h
33417 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
33418 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
33419
33420 /* SW interrupt */
33421 wait_queue_head_t swi_queue;
33422 - atomic_t swi_emitted;
33423 + atomic_unchecked_t swi_emitted;
33424 int vblank_crtc;
33425 uint32_t irq_enable_reg;
33426 uint32_t r500_disp_irq_reg;
33427 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
33428 index c180df8..cd80dd2d 100644
33429 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
33430 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
33431 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
33432 request = compat_alloc_user_space(sizeof(*request));
33433 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
33434 || __put_user(req32.param, &request->param)
33435 - || __put_user((void __user *)(unsigned long)req32.value,
33436 + || __put_user((unsigned long)req32.value,
33437 &request->value))
33438 return -EFAULT;
33439
33440 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
33441 index e771033..a0bc6b3 100644
33442 --- a/drivers/gpu/drm/radeon/radeon_irq.c
33443 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
33444 @@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
33445 unsigned int ret;
33446 RING_LOCALS;
33447
33448 - atomic_inc(&dev_priv->swi_emitted);
33449 - ret = atomic_read(&dev_priv->swi_emitted);
33450 + atomic_inc_unchecked(&dev_priv->swi_emitted);
33451 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
33452
33453 BEGIN_RING(4);
33454 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
33455 @@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
33456 drm_radeon_private_t *dev_priv =
33457 (drm_radeon_private_t *) dev->dev_private;
33458
33459 - atomic_set(&dev_priv->swi_emitted, 0);
33460 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
33461 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
33462
33463 dev->max_vblank_count = 0x001fffff;
33464 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
33465 index 8e9057b..af6dacb 100644
33466 --- a/drivers/gpu/drm/radeon/radeon_state.c
33467 +++ b/drivers/gpu/drm/radeon/radeon_state.c
33468 @@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
33469 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
33470 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
33471
33472 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33473 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33474 sarea_priv->nbox * sizeof(depth_boxes[0])))
33475 return -EFAULT;
33476
33477 @@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
33478 {
33479 drm_radeon_private_t *dev_priv = dev->dev_private;
33480 drm_radeon_getparam_t *param = data;
33481 - int value;
33482 + int value = 0;
33483
33484 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
33485
33486 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
33487 index 5ebe1b3..1ed9426 100644
33488 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
33489 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
33490 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33491 }
33492 if (unlikely(ttm_vm_ops == NULL)) {
33493 ttm_vm_ops = vma->vm_ops;
33494 - radeon_ttm_vm_ops = *ttm_vm_ops;
33495 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33496 + pax_open_kernel();
33497 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
33498 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33499 + pax_close_kernel();
33500 }
33501 vma->vm_ops = &radeon_ttm_vm_ops;
33502 return 0;
33503 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
33504 index 5706d2a..17aedaa 100644
33505 --- a/drivers/gpu/drm/radeon/rs690.c
33506 +++ b/drivers/gpu/drm/radeon/rs690.c
33507 @@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
33508 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
33509 rdev->pm.sideport_bandwidth.full)
33510 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
33511 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
33512 + read_delay_latency.full = dfixed_const(800 * 1000);
33513 read_delay_latency.full = dfixed_div(read_delay_latency,
33514 rdev->pm.igp_sideport_mclk);
33515 + a.full = dfixed_const(370);
33516 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
33517 } else {
33518 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
33519 rdev->pm.k8_bandwidth.full)
33520 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33521 index bd2a3b4..122d9ad 100644
33522 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
33523 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33524 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
33525 static int ttm_pool_mm_shrink(struct shrinker *shrink,
33526 struct shrink_control *sc)
33527 {
33528 - static atomic_t start_pool = ATOMIC_INIT(0);
33529 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
33530 unsigned i;
33531 - unsigned pool_offset = atomic_add_return(1, &start_pool);
33532 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
33533 struct ttm_page_pool *pool;
33534 int shrink_pages = sc->nr_to_scan;
33535
33536 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
33537 index 893a650..6190d3b 100644
33538 --- a/drivers/gpu/drm/via/via_drv.h
33539 +++ b/drivers/gpu/drm/via/via_drv.h
33540 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
33541 typedef uint32_t maskarray_t[5];
33542
33543 typedef struct drm_via_irq {
33544 - atomic_t irq_received;
33545 + atomic_unchecked_t irq_received;
33546 uint32_t pending_mask;
33547 uint32_t enable_mask;
33548 wait_queue_head_t irq_queue;
33549 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
33550 struct timeval last_vblank;
33551 int last_vblank_valid;
33552 unsigned usec_per_vblank;
33553 - atomic_t vbl_received;
33554 + atomic_unchecked_t vbl_received;
33555 drm_via_state_t hc_state;
33556 char pci_buf[VIA_PCI_BUF_SIZE];
33557 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
33558 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
33559 index ac98964..5dbf512 100644
33560 --- a/drivers/gpu/drm/via/via_irq.c
33561 +++ b/drivers/gpu/drm/via/via_irq.c
33562 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
33563 if (crtc != 0)
33564 return 0;
33565
33566 - return atomic_read(&dev_priv->vbl_received);
33567 + return atomic_read_unchecked(&dev_priv->vbl_received);
33568 }
33569
33570 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33571 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33572
33573 status = VIA_READ(VIA_REG_INTERRUPT);
33574 if (status & VIA_IRQ_VBLANK_PENDING) {
33575 - atomic_inc(&dev_priv->vbl_received);
33576 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
33577 + atomic_inc_unchecked(&dev_priv->vbl_received);
33578 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
33579 do_gettimeofday(&cur_vblank);
33580 if (dev_priv->last_vblank_valid) {
33581 dev_priv->usec_per_vblank =
33582 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33583 dev_priv->last_vblank = cur_vblank;
33584 dev_priv->last_vblank_valid = 1;
33585 }
33586 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
33587 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
33588 DRM_DEBUG("US per vblank is: %u\n",
33589 dev_priv->usec_per_vblank);
33590 }
33591 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33592
33593 for (i = 0; i < dev_priv->num_irqs; ++i) {
33594 if (status & cur_irq->pending_mask) {
33595 - atomic_inc(&cur_irq->irq_received);
33596 + atomic_inc_unchecked(&cur_irq->irq_received);
33597 DRM_WAKEUP(&cur_irq->irq_queue);
33598 handled = 1;
33599 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
33600 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
33601 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33602 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
33603 masks[irq][4]));
33604 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
33605 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
33606 } else {
33607 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33608 (((cur_irq_sequence =
33609 - atomic_read(&cur_irq->irq_received)) -
33610 + atomic_read_unchecked(&cur_irq->irq_received)) -
33611 *sequence) <= (1 << 23)));
33612 }
33613 *sequence = cur_irq_sequence;
33614 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
33615 }
33616
33617 for (i = 0; i < dev_priv->num_irqs; ++i) {
33618 - atomic_set(&cur_irq->irq_received, 0);
33619 + atomic_set_unchecked(&cur_irq->irq_received, 0);
33620 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
33621 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
33622 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
33623 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
33624 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
33625 case VIA_IRQ_RELATIVE:
33626 irqwait->request.sequence +=
33627 - atomic_read(&cur_irq->irq_received);
33628 + atomic_read_unchecked(&cur_irq->irq_received);
33629 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
33630 case VIA_IRQ_ABSOLUTE:
33631 break;
33632 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33633 index 88a179e..57fe50481c 100644
33634 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33635 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33636 @@ -263,7 +263,7 @@ struct vmw_private {
33637 * Fencing and IRQs.
33638 */
33639
33640 - atomic_t marker_seq;
33641 + atomic_unchecked_t marker_seq;
33642 wait_queue_head_t fence_queue;
33643 wait_queue_head_t fifo_queue;
33644 int fence_queue_waiters; /* Protected by hw_mutex */
33645 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33646 index 3eb1486..0a47ee9 100644
33647 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33648 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33649 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
33650 (unsigned int) min,
33651 (unsigned int) fifo->capabilities);
33652
33653 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33654 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33655 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
33656 vmw_marker_queue_init(&fifo->marker_queue);
33657 return vmw_fifo_send_fence(dev_priv, &dummy);
33658 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
33659 if (reserveable)
33660 iowrite32(bytes, fifo_mem +
33661 SVGA_FIFO_RESERVED);
33662 - return fifo_mem + (next_cmd >> 2);
33663 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
33664 } else {
33665 need_bounce = true;
33666 }
33667 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33668
33669 fm = vmw_fifo_reserve(dev_priv, bytes);
33670 if (unlikely(fm == NULL)) {
33671 - *seqno = atomic_read(&dev_priv->marker_seq);
33672 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33673 ret = -ENOMEM;
33674 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
33675 false, 3*HZ);
33676 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33677 }
33678
33679 do {
33680 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
33681 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
33682 } while (*seqno == 0);
33683
33684 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
33685 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33686 index 4640adb..e1384ed 100644
33687 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33688 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33689 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
33690 * emitted. Then the fence is stale and signaled.
33691 */
33692
33693 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
33694 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
33695 > VMW_FENCE_WRAP);
33696
33697 return ret;
33698 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
33699
33700 if (fifo_idle)
33701 down_read(&fifo_state->rwsem);
33702 - signal_seq = atomic_read(&dev_priv->marker_seq);
33703 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
33704 ret = 0;
33705
33706 for (;;) {
33707 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33708 index 8a8725c..afed796 100644
33709 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33710 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33711 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
33712 while (!vmw_lag_lt(queue, us)) {
33713 spin_lock(&queue->lock);
33714 if (list_empty(&queue->head))
33715 - seqno = atomic_read(&dev_priv->marker_seq);
33716 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33717 else {
33718 marker = list_first_entry(&queue->head,
33719 struct vmw_marker, head);
33720 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
33721 index 52146db..ae33762 100644
33722 --- a/drivers/hid/hid-core.c
33723 +++ b/drivers/hid/hid-core.c
33724 @@ -2201,7 +2201,7 @@ static bool hid_ignore(struct hid_device *hdev)
33725
33726 int hid_add_device(struct hid_device *hdev)
33727 {
33728 - static atomic_t id = ATOMIC_INIT(0);
33729 + static atomic_unchecked_t id = ATOMIC_INIT(0);
33730 int ret;
33731
33732 if (WARN_ON(hdev->status & HID_STAT_ADDED))
33733 @@ -2236,7 +2236,7 @@ int hid_add_device(struct hid_device *hdev)
33734 /* XXX hack, any other cleaner solution after the driver core
33735 * is converted to allow more than 20 bytes as the device name? */
33736 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
33737 - hdev->vendor, hdev->product, atomic_inc_return(&id));
33738 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
33739
33740 hid_debug_register(hdev, dev_name(&hdev->dev));
33741 ret = device_add(&hdev->dev);
33742 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
33743 index eec3291..8ed706b 100644
33744 --- a/drivers/hid/hid-wiimote-debug.c
33745 +++ b/drivers/hid/hid-wiimote-debug.c
33746 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
33747 else if (size == 0)
33748 return -EIO;
33749
33750 - if (copy_to_user(u, buf, size))
33751 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
33752 return -EFAULT;
33753
33754 *off += size;
33755 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
33756 index 14599e2..711c965 100644
33757 --- a/drivers/hid/usbhid/hiddev.c
33758 +++ b/drivers/hid/usbhid/hiddev.c
33759 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
33760 break;
33761
33762 case HIDIOCAPPLICATION:
33763 - if (arg < 0 || arg >= hid->maxapplication)
33764 + if (arg >= hid->maxapplication)
33765 break;
33766
33767 for (i = 0; i < hid->maxcollection; i++)
33768 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
33769 index f4c3d28..82f45a9 100644
33770 --- a/drivers/hv/channel.c
33771 +++ b/drivers/hv/channel.c
33772 @@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
33773 int ret = 0;
33774 int t;
33775
33776 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
33777 - atomic_inc(&vmbus_connection.next_gpadl_handle);
33778 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
33779 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
33780
33781 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
33782 if (ret)
33783 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
33784 index 3648f8f..30ef30d 100644
33785 --- a/drivers/hv/hv.c
33786 +++ b/drivers/hv/hv.c
33787 @@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
33788 u64 output_address = (output) ? virt_to_phys(output) : 0;
33789 u32 output_address_hi = output_address >> 32;
33790 u32 output_address_lo = output_address & 0xFFFFFFFF;
33791 - void *hypercall_page = hv_context.hypercall_page;
33792 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
33793
33794 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
33795 "=a"(hv_status_lo) : "d" (control_hi),
33796 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
33797 index d8d1fad..b91caf7 100644
33798 --- a/drivers/hv/hyperv_vmbus.h
33799 +++ b/drivers/hv/hyperv_vmbus.h
33800 @@ -594,7 +594,7 @@ enum vmbus_connect_state {
33801 struct vmbus_connection {
33802 enum vmbus_connect_state conn_state;
33803
33804 - atomic_t next_gpadl_handle;
33805 + atomic_unchecked_t next_gpadl_handle;
33806
33807 /*
33808 * Represents channel interrupts. Each bit position represents a
33809 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
33810 index 8e1a9ec..4687821 100644
33811 --- a/drivers/hv/vmbus_drv.c
33812 +++ b/drivers/hv/vmbus_drv.c
33813 @@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
33814 {
33815 int ret = 0;
33816
33817 - static atomic_t device_num = ATOMIC_INIT(0);
33818 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
33819
33820 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
33821 - atomic_inc_return(&device_num));
33822 + atomic_inc_return_unchecked(&device_num));
33823
33824 child_device_obj->device.bus = &hv_bus;
33825 child_device_obj->device.parent = &hv_acpi_dev->dev;
33826 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
33827 index 07a0c1a..0cac334 100644
33828 --- a/drivers/hwmon/sht15.c
33829 +++ b/drivers/hwmon/sht15.c
33830 @@ -169,7 +169,7 @@ struct sht15_data {
33831 int supply_uV;
33832 bool supply_uV_valid;
33833 struct work_struct update_supply_work;
33834 - atomic_t interrupt_handled;
33835 + atomic_unchecked_t interrupt_handled;
33836 };
33837
33838 /**
33839 @@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
33840 return ret;
33841
33842 gpio_direction_input(data->pdata->gpio_data);
33843 - atomic_set(&data->interrupt_handled, 0);
33844 + atomic_set_unchecked(&data->interrupt_handled, 0);
33845
33846 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33847 if (gpio_get_value(data->pdata->gpio_data) == 0) {
33848 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
33849 /* Only relevant if the interrupt hasn't occurred. */
33850 - if (!atomic_read(&data->interrupt_handled))
33851 + if (!atomic_read_unchecked(&data->interrupt_handled))
33852 schedule_work(&data->read_work);
33853 }
33854 ret = wait_event_timeout(data->wait_queue,
33855 @@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
33856
33857 /* First disable the interrupt */
33858 disable_irq_nosync(irq);
33859 - atomic_inc(&data->interrupt_handled);
33860 + atomic_inc_unchecked(&data->interrupt_handled);
33861 /* Then schedule a reading work struct */
33862 if (data->state != SHT15_READING_NOTHING)
33863 schedule_work(&data->read_work);
33864 @@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
33865 * If not, then start the interrupt again - care here as could
33866 * have gone low in meantime so verify it hasn't!
33867 */
33868 - atomic_set(&data->interrupt_handled, 0);
33869 + atomic_set_unchecked(&data->interrupt_handled, 0);
33870 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33871 /* If still not occurred or another handler was scheduled */
33872 if (gpio_get_value(data->pdata->gpio_data)
33873 - || atomic_read(&data->interrupt_handled))
33874 + || atomic_read_unchecked(&data->interrupt_handled))
33875 return;
33876 }
33877
33878 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
33879 index 378fcb5..5e91fa8 100644
33880 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
33881 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
33882 @@ -43,7 +43,7 @@
33883 extern struct i2c_adapter amd756_smbus;
33884
33885 static struct i2c_adapter *s4882_adapter;
33886 -static struct i2c_algorithm *s4882_algo;
33887 +static i2c_algorithm_no_const *s4882_algo;
33888
33889 /* Wrapper access functions for multiplexed SMBus */
33890 static DEFINE_MUTEX(amd756_lock);
33891 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
33892 index 29015eb..af2d8e9 100644
33893 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
33894 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
33895 @@ -41,7 +41,7 @@
33896 extern struct i2c_adapter *nforce2_smbus;
33897
33898 static struct i2c_adapter *s4985_adapter;
33899 -static struct i2c_algorithm *s4985_algo;
33900 +static i2c_algorithm_no_const *s4985_algo;
33901
33902 /* Wrapper access functions for multiplexed SMBus */
33903 static DEFINE_MUTEX(nforce2_lock);
33904 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
33905 index 8126824..55a2798 100644
33906 --- a/drivers/ide/ide-cd.c
33907 +++ b/drivers/ide/ide-cd.c
33908 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
33909 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
33910 if ((unsigned long)buf & alignment
33911 || blk_rq_bytes(rq) & q->dma_pad_mask
33912 - || object_is_on_stack(buf))
33913 + || object_starts_on_stack(buf))
33914 drive->dma = 0;
33915 }
33916 }
33917 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
33918 index 394fea2..c833880 100644
33919 --- a/drivers/infiniband/core/cm.c
33920 +++ b/drivers/infiniband/core/cm.c
33921 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
33922
33923 struct cm_counter_group {
33924 struct kobject obj;
33925 - atomic_long_t counter[CM_ATTR_COUNT];
33926 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
33927 };
33928
33929 struct cm_counter_attribute {
33930 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
33931 struct ib_mad_send_buf *msg = NULL;
33932 int ret;
33933
33934 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33935 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33936 counter[CM_REQ_COUNTER]);
33937
33938 /* Quick state check to discard duplicate REQs. */
33939 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
33940 if (!cm_id_priv)
33941 return;
33942
33943 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33944 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33945 counter[CM_REP_COUNTER]);
33946 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
33947 if (ret)
33948 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
33949 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
33950 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
33951 spin_unlock_irq(&cm_id_priv->lock);
33952 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33953 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33954 counter[CM_RTU_COUNTER]);
33955 goto out;
33956 }
33957 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
33958 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
33959 dreq_msg->local_comm_id);
33960 if (!cm_id_priv) {
33961 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33962 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33963 counter[CM_DREQ_COUNTER]);
33964 cm_issue_drep(work->port, work->mad_recv_wc);
33965 return -EINVAL;
33966 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
33967 case IB_CM_MRA_REP_RCVD:
33968 break;
33969 case IB_CM_TIMEWAIT:
33970 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33971 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33972 counter[CM_DREQ_COUNTER]);
33973 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33974 goto unlock;
33975 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
33976 cm_free_msg(msg);
33977 goto deref;
33978 case IB_CM_DREQ_RCVD:
33979 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33980 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33981 counter[CM_DREQ_COUNTER]);
33982 goto unlock;
33983 default:
33984 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
33985 ib_modify_mad(cm_id_priv->av.port->mad_agent,
33986 cm_id_priv->msg, timeout)) {
33987 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
33988 - atomic_long_inc(&work->port->
33989 + atomic_long_inc_unchecked(&work->port->
33990 counter_group[CM_RECV_DUPLICATES].
33991 counter[CM_MRA_COUNTER]);
33992 goto out;
33993 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
33994 break;
33995 case IB_CM_MRA_REQ_RCVD:
33996 case IB_CM_MRA_REP_RCVD:
33997 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33998 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33999 counter[CM_MRA_COUNTER]);
34000 /* fall through */
34001 default:
34002 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
34003 case IB_CM_LAP_IDLE:
34004 break;
34005 case IB_CM_MRA_LAP_SENT:
34006 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34007 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34008 counter[CM_LAP_COUNTER]);
34009 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34010 goto unlock;
34011 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
34012 cm_free_msg(msg);
34013 goto deref;
34014 case IB_CM_LAP_RCVD:
34015 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34016 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34017 counter[CM_LAP_COUNTER]);
34018 goto unlock;
34019 default:
34020 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
34021 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
34022 if (cur_cm_id_priv) {
34023 spin_unlock_irq(&cm.lock);
34024 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34025 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34026 counter[CM_SIDR_REQ_COUNTER]);
34027 goto out; /* Duplicate message. */
34028 }
34029 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
34030 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
34031 msg->retries = 1;
34032
34033 - atomic_long_add(1 + msg->retries,
34034 + atomic_long_add_unchecked(1 + msg->retries,
34035 &port->counter_group[CM_XMIT].counter[attr_index]);
34036 if (msg->retries)
34037 - atomic_long_add(msg->retries,
34038 + atomic_long_add_unchecked(msg->retries,
34039 &port->counter_group[CM_XMIT_RETRIES].
34040 counter[attr_index]);
34041
34042 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
34043 }
34044
34045 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
34046 - atomic_long_inc(&port->counter_group[CM_RECV].
34047 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
34048 counter[attr_id - CM_ATTR_ID_OFFSET]);
34049
34050 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
34051 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
34052 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
34053
34054 return sprintf(buf, "%ld\n",
34055 - atomic_long_read(&group->counter[cm_attr->index]));
34056 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
34057 }
34058
34059 static const struct sysfs_ops cm_counter_ops = {
34060 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
34061 index 176c8f9..2627b62 100644
34062 --- a/drivers/infiniband/core/fmr_pool.c
34063 +++ b/drivers/infiniband/core/fmr_pool.c
34064 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
34065
34066 struct task_struct *thread;
34067
34068 - atomic_t req_ser;
34069 - atomic_t flush_ser;
34070 + atomic_unchecked_t req_ser;
34071 + atomic_unchecked_t flush_ser;
34072
34073 wait_queue_head_t force_wait;
34074 };
34075 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34076 struct ib_fmr_pool *pool = pool_ptr;
34077
34078 do {
34079 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
34080 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
34081 ib_fmr_batch_release(pool);
34082
34083 - atomic_inc(&pool->flush_ser);
34084 + atomic_inc_unchecked(&pool->flush_ser);
34085 wake_up_interruptible(&pool->force_wait);
34086
34087 if (pool->flush_function)
34088 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34089 }
34090
34091 set_current_state(TASK_INTERRUPTIBLE);
34092 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
34093 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
34094 !kthread_should_stop())
34095 schedule();
34096 __set_current_state(TASK_RUNNING);
34097 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
34098 pool->dirty_watermark = params->dirty_watermark;
34099 pool->dirty_len = 0;
34100 spin_lock_init(&pool->pool_lock);
34101 - atomic_set(&pool->req_ser, 0);
34102 - atomic_set(&pool->flush_ser, 0);
34103 + atomic_set_unchecked(&pool->req_ser, 0);
34104 + atomic_set_unchecked(&pool->flush_ser, 0);
34105 init_waitqueue_head(&pool->force_wait);
34106
34107 pool->thread = kthread_run(ib_fmr_cleanup_thread,
34108 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
34109 }
34110 spin_unlock_irq(&pool->pool_lock);
34111
34112 - serial = atomic_inc_return(&pool->req_ser);
34113 + serial = atomic_inc_return_unchecked(&pool->req_ser);
34114 wake_up_process(pool->thread);
34115
34116 if (wait_event_interruptible(pool->force_wait,
34117 - atomic_read(&pool->flush_ser) - serial >= 0))
34118 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
34119 return -EINTR;
34120
34121 return 0;
34122 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
34123 } else {
34124 list_add_tail(&fmr->list, &pool->dirty_list);
34125 if (++pool->dirty_len >= pool->dirty_watermark) {
34126 - atomic_inc(&pool->req_ser);
34127 + atomic_inc_unchecked(&pool->req_ser);
34128 wake_up_process(pool->thread);
34129 }
34130 }
34131 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
34132 index afd8179..598063f 100644
34133 --- a/drivers/infiniband/hw/cxgb4/mem.c
34134 +++ b/drivers/infiniband/hw/cxgb4/mem.c
34135 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34136 int err;
34137 struct fw_ri_tpte tpt;
34138 u32 stag_idx;
34139 - static atomic_t key;
34140 + static atomic_unchecked_t key;
34141
34142 if (c4iw_fatal_error(rdev))
34143 return -EIO;
34144 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34145 if (rdev->stats.stag.cur > rdev->stats.stag.max)
34146 rdev->stats.stag.max = rdev->stats.stag.cur;
34147 mutex_unlock(&rdev->stats.lock);
34148 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
34149 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
34150 }
34151 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
34152 __func__, stag_state, type, pdid, stag_idx);
34153 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
34154 index 79b3dbc..96e5fcc 100644
34155 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
34156 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
34157 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34158 struct ib_atomic_eth *ateth;
34159 struct ipath_ack_entry *e;
34160 u64 vaddr;
34161 - atomic64_t *maddr;
34162 + atomic64_unchecked_t *maddr;
34163 u64 sdata;
34164 u32 rkey;
34165 u8 next;
34166 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34167 IB_ACCESS_REMOTE_ATOMIC)))
34168 goto nack_acc_unlck;
34169 /* Perform atomic OP and save result. */
34170 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34171 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34172 sdata = be64_to_cpu(ateth->swap_data);
34173 e = &qp->s_ack_queue[qp->r_head_ack_queue];
34174 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
34175 - (u64) atomic64_add_return(sdata, maddr) - sdata :
34176 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34177 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34178 be64_to_cpu(ateth->compare_data),
34179 sdata);
34180 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
34181 index 1f95bba..9530f87 100644
34182 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
34183 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
34184 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
34185 unsigned long flags;
34186 struct ib_wc wc;
34187 u64 sdata;
34188 - atomic64_t *maddr;
34189 + atomic64_unchecked_t *maddr;
34190 enum ib_wc_status send_status;
34191
34192 /*
34193 @@ -382,11 +382,11 @@ again:
34194 IB_ACCESS_REMOTE_ATOMIC)))
34195 goto acc_err;
34196 /* Perform atomic OP and save result. */
34197 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34198 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34199 sdata = wqe->wr.wr.atomic.compare_add;
34200 *(u64 *) sqp->s_sge.sge.vaddr =
34201 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
34202 - (u64) atomic64_add_return(sdata, maddr) - sdata :
34203 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34204 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34205 sdata, wqe->wr.wr.atomic.swap);
34206 goto send_comp;
34207 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
34208 index 748db2d..5f75cc3 100644
34209 --- a/drivers/infiniband/hw/nes/nes.c
34210 +++ b/drivers/infiniband/hw/nes/nes.c
34211 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
34212 LIST_HEAD(nes_adapter_list);
34213 static LIST_HEAD(nes_dev_list);
34214
34215 -atomic_t qps_destroyed;
34216 +atomic_unchecked_t qps_destroyed;
34217
34218 static unsigned int ee_flsh_adapter;
34219 static unsigned int sysfs_nonidx_addr;
34220 @@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
34221 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
34222 struct nes_adapter *nesadapter = nesdev->nesadapter;
34223
34224 - atomic_inc(&qps_destroyed);
34225 + atomic_inc_unchecked(&qps_destroyed);
34226
34227 /* Free the control structures */
34228
34229 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
34230 index 33cc589..3bd6538 100644
34231 --- a/drivers/infiniband/hw/nes/nes.h
34232 +++ b/drivers/infiniband/hw/nes/nes.h
34233 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
34234 extern unsigned int wqm_quanta;
34235 extern struct list_head nes_adapter_list;
34236
34237 -extern atomic_t cm_connects;
34238 -extern atomic_t cm_accepts;
34239 -extern atomic_t cm_disconnects;
34240 -extern atomic_t cm_closes;
34241 -extern atomic_t cm_connecteds;
34242 -extern atomic_t cm_connect_reqs;
34243 -extern atomic_t cm_rejects;
34244 -extern atomic_t mod_qp_timouts;
34245 -extern atomic_t qps_created;
34246 -extern atomic_t qps_destroyed;
34247 -extern atomic_t sw_qps_destroyed;
34248 +extern atomic_unchecked_t cm_connects;
34249 +extern atomic_unchecked_t cm_accepts;
34250 +extern atomic_unchecked_t cm_disconnects;
34251 +extern atomic_unchecked_t cm_closes;
34252 +extern atomic_unchecked_t cm_connecteds;
34253 +extern atomic_unchecked_t cm_connect_reqs;
34254 +extern atomic_unchecked_t cm_rejects;
34255 +extern atomic_unchecked_t mod_qp_timouts;
34256 +extern atomic_unchecked_t qps_created;
34257 +extern atomic_unchecked_t qps_destroyed;
34258 +extern atomic_unchecked_t sw_qps_destroyed;
34259 extern u32 mh_detected;
34260 extern u32 mh_pauses_sent;
34261 extern u32 cm_packets_sent;
34262 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
34263 extern u32 cm_packets_received;
34264 extern u32 cm_packets_dropped;
34265 extern u32 cm_packets_retrans;
34266 -extern atomic_t cm_listens_created;
34267 -extern atomic_t cm_listens_destroyed;
34268 +extern atomic_unchecked_t cm_listens_created;
34269 +extern atomic_unchecked_t cm_listens_destroyed;
34270 extern u32 cm_backlog_drops;
34271 -extern atomic_t cm_loopbacks;
34272 -extern atomic_t cm_nodes_created;
34273 -extern atomic_t cm_nodes_destroyed;
34274 -extern atomic_t cm_accel_dropped_pkts;
34275 -extern atomic_t cm_resets_recvd;
34276 -extern atomic_t pau_qps_created;
34277 -extern atomic_t pau_qps_destroyed;
34278 +extern atomic_unchecked_t cm_loopbacks;
34279 +extern atomic_unchecked_t cm_nodes_created;
34280 +extern atomic_unchecked_t cm_nodes_destroyed;
34281 +extern atomic_unchecked_t cm_accel_dropped_pkts;
34282 +extern atomic_unchecked_t cm_resets_recvd;
34283 +extern atomic_unchecked_t pau_qps_created;
34284 +extern atomic_unchecked_t pau_qps_destroyed;
34285
34286 extern u32 int_mod_timer_init;
34287 extern u32 int_mod_cq_depth_256;
34288 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
34289 index cfaacaf..fa0722e 100644
34290 --- a/drivers/infiniband/hw/nes/nes_cm.c
34291 +++ b/drivers/infiniband/hw/nes/nes_cm.c
34292 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
34293 u32 cm_packets_retrans;
34294 u32 cm_packets_created;
34295 u32 cm_packets_received;
34296 -atomic_t cm_listens_created;
34297 -atomic_t cm_listens_destroyed;
34298 +atomic_unchecked_t cm_listens_created;
34299 +atomic_unchecked_t cm_listens_destroyed;
34300 u32 cm_backlog_drops;
34301 -atomic_t cm_loopbacks;
34302 -atomic_t cm_nodes_created;
34303 -atomic_t cm_nodes_destroyed;
34304 -atomic_t cm_accel_dropped_pkts;
34305 -atomic_t cm_resets_recvd;
34306 +atomic_unchecked_t cm_loopbacks;
34307 +atomic_unchecked_t cm_nodes_created;
34308 +atomic_unchecked_t cm_nodes_destroyed;
34309 +atomic_unchecked_t cm_accel_dropped_pkts;
34310 +atomic_unchecked_t cm_resets_recvd;
34311
34312 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
34313 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
34314 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
34315
34316 static struct nes_cm_core *g_cm_core;
34317
34318 -atomic_t cm_connects;
34319 -atomic_t cm_accepts;
34320 -atomic_t cm_disconnects;
34321 -atomic_t cm_closes;
34322 -atomic_t cm_connecteds;
34323 -atomic_t cm_connect_reqs;
34324 -atomic_t cm_rejects;
34325 +atomic_unchecked_t cm_connects;
34326 +atomic_unchecked_t cm_accepts;
34327 +atomic_unchecked_t cm_disconnects;
34328 +atomic_unchecked_t cm_closes;
34329 +atomic_unchecked_t cm_connecteds;
34330 +atomic_unchecked_t cm_connect_reqs;
34331 +atomic_unchecked_t cm_rejects;
34332
34333 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
34334 {
34335 @@ -1281,7 +1281,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
34336 kfree(listener);
34337 listener = NULL;
34338 ret = 0;
34339 - atomic_inc(&cm_listens_destroyed);
34340 + atomic_inc_unchecked(&cm_listens_destroyed);
34341 } else {
34342 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
34343 }
34344 @@ -1480,7 +1480,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
34345 cm_node->rem_mac);
34346
34347 add_hte_node(cm_core, cm_node);
34348 - atomic_inc(&cm_nodes_created);
34349 + atomic_inc_unchecked(&cm_nodes_created);
34350
34351 return cm_node;
34352 }
34353 @@ -1538,7 +1538,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
34354 }
34355
34356 atomic_dec(&cm_core->node_cnt);
34357 - atomic_inc(&cm_nodes_destroyed);
34358 + atomic_inc_unchecked(&cm_nodes_destroyed);
34359 nesqp = cm_node->nesqp;
34360 if (nesqp) {
34361 nesqp->cm_node = NULL;
34362 @@ -1602,7 +1602,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
34363
34364 static void drop_packet(struct sk_buff *skb)
34365 {
34366 - atomic_inc(&cm_accel_dropped_pkts);
34367 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
34368 dev_kfree_skb_any(skb);
34369 }
34370
34371 @@ -1665,7 +1665,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
34372 {
34373
34374 int reset = 0; /* whether to send reset in case of err.. */
34375 - atomic_inc(&cm_resets_recvd);
34376 + atomic_inc_unchecked(&cm_resets_recvd);
34377 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
34378 " refcnt=%d\n", cm_node, cm_node->state,
34379 atomic_read(&cm_node->ref_count));
34380 @@ -2306,7 +2306,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
34381 rem_ref_cm_node(cm_node->cm_core, cm_node);
34382 return NULL;
34383 }
34384 - atomic_inc(&cm_loopbacks);
34385 + atomic_inc_unchecked(&cm_loopbacks);
34386 loopbackremotenode->loopbackpartner = cm_node;
34387 loopbackremotenode->tcp_cntxt.rcv_wscale =
34388 NES_CM_DEFAULT_RCV_WND_SCALE;
34389 @@ -2581,7 +2581,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
34390 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
34391 else {
34392 rem_ref_cm_node(cm_core, cm_node);
34393 - atomic_inc(&cm_accel_dropped_pkts);
34394 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
34395 dev_kfree_skb_any(skb);
34396 }
34397 break;
34398 @@ -2889,7 +2889,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
34399
34400 if ((cm_id) && (cm_id->event_handler)) {
34401 if (issue_disconn) {
34402 - atomic_inc(&cm_disconnects);
34403 + atomic_inc_unchecked(&cm_disconnects);
34404 cm_event.event = IW_CM_EVENT_DISCONNECT;
34405 cm_event.status = disconn_status;
34406 cm_event.local_addr = cm_id->local_addr;
34407 @@ -2911,7 +2911,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
34408 }
34409
34410 if (issue_close) {
34411 - atomic_inc(&cm_closes);
34412 + atomic_inc_unchecked(&cm_closes);
34413 nes_disconnect(nesqp, 1);
34414
34415 cm_id->provider_data = nesqp;
34416 @@ -3047,7 +3047,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34417
34418 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
34419 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
34420 - atomic_inc(&cm_accepts);
34421 + atomic_inc_unchecked(&cm_accepts);
34422
34423 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
34424 netdev_refcnt_read(nesvnic->netdev));
34425 @@ -3242,7 +3242,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
34426 struct nes_cm_core *cm_core;
34427 u8 *start_buff;
34428
34429 - atomic_inc(&cm_rejects);
34430 + atomic_inc_unchecked(&cm_rejects);
34431 cm_node = (struct nes_cm_node *)cm_id->provider_data;
34432 loopback = cm_node->loopbackpartner;
34433 cm_core = cm_node->cm_core;
34434 @@ -3302,7 +3302,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34435 ntohl(cm_id->local_addr.sin_addr.s_addr),
34436 ntohs(cm_id->local_addr.sin_port));
34437
34438 - atomic_inc(&cm_connects);
34439 + atomic_inc_unchecked(&cm_connects);
34440 nesqp->active_conn = 1;
34441
34442 /* cache the cm_id in the qp */
34443 @@ -3412,7 +3412,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
34444 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
34445 return err;
34446 }
34447 - atomic_inc(&cm_listens_created);
34448 + atomic_inc_unchecked(&cm_listens_created);
34449 }
34450
34451 cm_id->add_ref(cm_id);
34452 @@ -3513,7 +3513,7 @@ static void cm_event_connected(struct nes_cm_event *event)
34453
34454 if (nesqp->destroyed)
34455 return;
34456 - atomic_inc(&cm_connecteds);
34457 + atomic_inc_unchecked(&cm_connecteds);
34458 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
34459 " local port 0x%04X. jiffies = %lu.\n",
34460 nesqp->hwqp.qp_id,
34461 @@ -3693,7 +3693,7 @@ static void cm_event_reset(struct nes_cm_event *event)
34462
34463 cm_id->add_ref(cm_id);
34464 ret = cm_id->event_handler(cm_id, &cm_event);
34465 - atomic_inc(&cm_closes);
34466 + atomic_inc_unchecked(&cm_closes);
34467 cm_event.event = IW_CM_EVENT_CLOSE;
34468 cm_event.status = 0;
34469 cm_event.provider_data = cm_id->provider_data;
34470 @@ -3729,7 +3729,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
34471 return;
34472 cm_id = cm_node->cm_id;
34473
34474 - atomic_inc(&cm_connect_reqs);
34475 + atomic_inc_unchecked(&cm_connect_reqs);
34476 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34477 cm_node, cm_id, jiffies);
34478
34479 @@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
34480 return;
34481 cm_id = cm_node->cm_id;
34482
34483 - atomic_inc(&cm_connect_reqs);
34484 + atomic_inc_unchecked(&cm_connect_reqs);
34485 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34486 cm_node, cm_id, jiffies);
34487
34488 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
34489 index 3ba7be3..c81f6ff 100644
34490 --- a/drivers/infiniband/hw/nes/nes_mgt.c
34491 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
34492 @@ -40,8 +40,8 @@
34493 #include "nes.h"
34494 #include "nes_mgt.h"
34495
34496 -atomic_t pau_qps_created;
34497 -atomic_t pau_qps_destroyed;
34498 +atomic_unchecked_t pau_qps_created;
34499 +atomic_unchecked_t pau_qps_destroyed;
34500
34501 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
34502 {
34503 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
34504 {
34505 struct sk_buff *skb;
34506 unsigned long flags;
34507 - atomic_inc(&pau_qps_destroyed);
34508 + atomic_inc_unchecked(&pau_qps_destroyed);
34509
34510 /* Free packets that have not yet been forwarded */
34511 /* Lock is acquired by skb_dequeue when removing the skb */
34512 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
34513 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
34514 skb_queue_head_init(&nesqp->pau_list);
34515 spin_lock_init(&nesqp->pau_lock);
34516 - atomic_inc(&pau_qps_created);
34517 + atomic_inc_unchecked(&pau_qps_created);
34518 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
34519 }
34520
34521 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
34522 index 0564be7..f68b0f1 100644
34523 --- a/drivers/infiniband/hw/nes/nes_nic.c
34524 +++ b/drivers/infiniband/hw/nes/nes_nic.c
34525 @@ -1272,39 +1272,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
34526 target_stat_values[++index] = mh_detected;
34527 target_stat_values[++index] = mh_pauses_sent;
34528 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
34529 - target_stat_values[++index] = atomic_read(&cm_connects);
34530 - target_stat_values[++index] = atomic_read(&cm_accepts);
34531 - target_stat_values[++index] = atomic_read(&cm_disconnects);
34532 - target_stat_values[++index] = atomic_read(&cm_connecteds);
34533 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
34534 - target_stat_values[++index] = atomic_read(&cm_rejects);
34535 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
34536 - target_stat_values[++index] = atomic_read(&qps_created);
34537 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
34538 - target_stat_values[++index] = atomic_read(&qps_destroyed);
34539 - target_stat_values[++index] = atomic_read(&cm_closes);
34540 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
34541 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
34542 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
34543 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
34544 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
34545 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
34546 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
34547 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
34548 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
34549 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
34550 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
34551 target_stat_values[++index] = cm_packets_sent;
34552 target_stat_values[++index] = cm_packets_bounced;
34553 target_stat_values[++index] = cm_packets_created;
34554 target_stat_values[++index] = cm_packets_received;
34555 target_stat_values[++index] = cm_packets_dropped;
34556 target_stat_values[++index] = cm_packets_retrans;
34557 - target_stat_values[++index] = atomic_read(&cm_listens_created);
34558 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
34559 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
34560 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
34561 target_stat_values[++index] = cm_backlog_drops;
34562 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
34563 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
34564 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
34565 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
34566 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
34567 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
34568 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
34569 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
34570 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
34571 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
34572 target_stat_values[++index] = nesadapter->free_4kpbl;
34573 target_stat_values[++index] = nesadapter->free_256pbl;
34574 target_stat_values[++index] = int_mod_timer_init;
34575 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
34576 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
34577 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
34578 - target_stat_values[++index] = atomic_read(&pau_qps_created);
34579 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
34580 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
34581 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
34582 }
34583
34584 /**
34585 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
34586 index 07e4fba..685f041 100644
34587 --- a/drivers/infiniband/hw/nes/nes_verbs.c
34588 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
34589 @@ -46,9 +46,9 @@
34590
34591 #include <rdma/ib_umem.h>
34592
34593 -atomic_t mod_qp_timouts;
34594 -atomic_t qps_created;
34595 -atomic_t sw_qps_destroyed;
34596 +atomic_unchecked_t mod_qp_timouts;
34597 +atomic_unchecked_t qps_created;
34598 +atomic_unchecked_t sw_qps_destroyed;
34599
34600 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
34601
34602 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
34603 if (init_attr->create_flags)
34604 return ERR_PTR(-EINVAL);
34605
34606 - atomic_inc(&qps_created);
34607 + atomic_inc_unchecked(&qps_created);
34608 switch (init_attr->qp_type) {
34609 case IB_QPT_RC:
34610 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
34611 @@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
34612 struct iw_cm_event cm_event;
34613 int ret = 0;
34614
34615 - atomic_inc(&sw_qps_destroyed);
34616 + atomic_inc_unchecked(&sw_qps_destroyed);
34617 nesqp->destroyed = 1;
34618
34619 /* Blow away the connection if it exists. */
34620 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
34621 index 4d11575..3e890e5 100644
34622 --- a/drivers/infiniband/hw/qib/qib.h
34623 +++ b/drivers/infiniband/hw/qib/qib.h
34624 @@ -51,6 +51,7 @@
34625 #include <linux/completion.h>
34626 #include <linux/kref.h>
34627 #include <linux/sched.h>
34628 +#include <linux/slab.h>
34629
34630 #include "qib_common.h"
34631 #include "qib_verbs.h"
34632 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
34633 index da739d9..da1c7f4 100644
34634 --- a/drivers/input/gameport/gameport.c
34635 +++ b/drivers/input/gameport/gameport.c
34636 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
34637 */
34638 static void gameport_init_port(struct gameport *gameport)
34639 {
34640 - static atomic_t gameport_no = ATOMIC_INIT(0);
34641 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
34642
34643 __module_get(THIS_MODULE);
34644
34645 mutex_init(&gameport->drv_mutex);
34646 device_initialize(&gameport->dev);
34647 dev_set_name(&gameport->dev, "gameport%lu",
34648 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
34649 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
34650 gameport->dev.bus = &gameport_bus;
34651 gameport->dev.release = gameport_release_port;
34652 if (gameport->parent)
34653 diff --git a/drivers/input/input.c b/drivers/input/input.c
34654 index 53a0dde..abffda7 100644
34655 --- a/drivers/input/input.c
34656 +++ b/drivers/input/input.c
34657 @@ -1902,7 +1902,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
34658 */
34659 int input_register_device(struct input_dev *dev)
34660 {
34661 - static atomic_t input_no = ATOMIC_INIT(0);
34662 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
34663 struct input_handler *handler;
34664 unsigned int packet_size;
34665 const char *path;
34666 @@ -1945,7 +1945,7 @@ int input_register_device(struct input_dev *dev)
34667 dev->setkeycode = input_default_setkeycode;
34668
34669 dev_set_name(&dev->dev, "input%ld",
34670 - (unsigned long) atomic_inc_return(&input_no) - 1);
34671 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
34672
34673 error = device_add(&dev->dev);
34674 if (error)
34675 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
34676 index 04c69af..5f92d00 100644
34677 --- a/drivers/input/joystick/sidewinder.c
34678 +++ b/drivers/input/joystick/sidewinder.c
34679 @@ -30,6 +30,7 @@
34680 #include <linux/kernel.h>
34681 #include <linux/module.h>
34682 #include <linux/slab.h>
34683 +#include <linux/sched.h>
34684 #include <linux/init.h>
34685 #include <linux/input.h>
34686 #include <linux/gameport.h>
34687 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
34688 index 83811e4..0822b90 100644
34689 --- a/drivers/input/joystick/xpad.c
34690 +++ b/drivers/input/joystick/xpad.c
34691 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
34692
34693 static int xpad_led_probe(struct usb_xpad *xpad)
34694 {
34695 - static atomic_t led_seq = ATOMIC_INIT(0);
34696 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
34697 long led_no;
34698 struct xpad_led *led;
34699 struct led_classdev *led_cdev;
34700 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
34701 if (!led)
34702 return -ENOMEM;
34703
34704 - led_no = (long)atomic_inc_return(&led_seq) - 1;
34705 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
34706
34707 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
34708 led->xpad = xpad;
34709 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
34710 index 4c842c3..590b0bf 100644
34711 --- a/drivers/input/mousedev.c
34712 +++ b/drivers/input/mousedev.c
34713 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
34714
34715 spin_unlock_irq(&client->packet_lock);
34716
34717 - if (copy_to_user(buffer, data, count))
34718 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
34719 return -EFAULT;
34720
34721 return count;
34722 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
34723 index d0f7533..fb8215b 100644
34724 --- a/drivers/input/serio/serio.c
34725 +++ b/drivers/input/serio/serio.c
34726 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
34727 */
34728 static void serio_init_port(struct serio *serio)
34729 {
34730 - static atomic_t serio_no = ATOMIC_INIT(0);
34731 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
34732
34733 __module_get(THIS_MODULE);
34734
34735 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
34736 mutex_init(&serio->drv_mutex);
34737 device_initialize(&serio->dev);
34738 dev_set_name(&serio->dev, "serio%ld",
34739 - (long)atomic_inc_return(&serio_no) - 1);
34740 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
34741 serio->dev.bus = &serio_bus;
34742 serio->dev.release = serio_release_port;
34743 serio->dev.groups = serio_device_attr_groups;
34744 diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
34745 index faf10ba..7cfaba9 100644
34746 --- a/drivers/iommu/amd_iommu_init.c
34747 +++ b/drivers/iommu/amd_iommu_init.c
34748 @@ -1922,7 +1922,7 @@ static int __init state_next(void)
34749 case IOMMU_ACPI_FINISHED:
34750 early_enable_iommus();
34751 register_syscore_ops(&amd_iommu_syscore_ops);
34752 - x86_platform.iommu_shutdown = disable_iommus;
34753 + *(void **)&x86_platform.iommu_shutdown = disable_iommus;
34754 init_state = IOMMU_ENABLED;
34755 break;
34756 case IOMMU_ENABLED:
34757 @@ -2064,7 +2064,7 @@ int __init amd_iommu_detect(void)
34758
34759 amd_iommu_detected = true;
34760 iommu_detected = 1;
34761 - x86_init.iommu.iommu_init = amd_iommu_init;
34762 + *(void **)&x86_init.iommu.iommu_init = amd_iommu_init;
34763
34764 return 0;
34765 }
34766 diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
34767 index 86e2f4a..d1cec5d 100644
34768 --- a/drivers/iommu/dmar.c
34769 +++ b/drivers/iommu/dmar.c
34770 @@ -555,7 +555,7 @@ int __init detect_intel_iommu(void)
34771
34772 #ifdef CONFIG_X86
34773 if (ret)
34774 - x86_init.iommu.iommu_init = intel_iommu_init;
34775 + *(void **)&x86_init.iommu.iommu_init = intel_iommu_init;
34776 #endif
34777 }
34778 early_acpi_os_unmap_memory(dmar_tbl, dmar_tbl_size);
34779 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
34780 index c679867..6e2e34d 100644
34781 --- a/drivers/isdn/capi/capi.c
34782 +++ b/drivers/isdn/capi/capi.c
34783 @@ -83,8 +83,8 @@ struct capiminor {
34784
34785 struct capi20_appl *ap;
34786 u32 ncci;
34787 - atomic_t datahandle;
34788 - atomic_t msgid;
34789 + atomic_unchecked_t datahandle;
34790 + atomic_unchecked_t msgid;
34791
34792 struct tty_port port;
34793 int ttyinstop;
34794 @@ -393,7 +393,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
34795 capimsg_setu16(s, 2, mp->ap->applid);
34796 capimsg_setu8 (s, 4, CAPI_DATA_B3);
34797 capimsg_setu8 (s, 5, CAPI_RESP);
34798 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
34799 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
34800 capimsg_setu32(s, 8, mp->ncci);
34801 capimsg_setu16(s, 12, datahandle);
34802 }
34803 @@ -514,14 +514,14 @@ static void handle_minor_send(struct capiminor *mp)
34804 mp->outbytes -= len;
34805 spin_unlock_bh(&mp->outlock);
34806
34807 - datahandle = atomic_inc_return(&mp->datahandle);
34808 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
34809 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
34810 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34811 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34812 capimsg_setu16(skb->data, 2, mp->ap->applid);
34813 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
34814 capimsg_setu8 (skb->data, 5, CAPI_REQ);
34815 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
34816 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
34817 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
34818 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
34819 capimsg_setu16(skb->data, 16, len); /* Data length */
34820 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
34821 index 67abf3f..076b3a6 100644
34822 --- a/drivers/isdn/gigaset/interface.c
34823 +++ b/drivers/isdn/gigaset/interface.c
34824 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
34825 }
34826 tty->driver_data = cs;
34827
34828 - ++cs->port.count;
34829 + atomic_inc(&cs->port.count);
34830
34831 - if (cs->port.count == 1) {
34832 + if (atomic_read(&cs->port.count) == 1) {
34833 tty_port_tty_set(&cs->port, tty);
34834 tty->low_latency = 1;
34835 }
34836 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
34837
34838 if (!cs->connected)
34839 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
34840 - else if (!cs->port.count)
34841 + else if (!atomic_read(&cs->port.count))
34842 dev_warn(cs->dev, "%s: device not opened\n", __func__);
34843 - else if (!--cs->port.count)
34844 + else if (!atomic_dec_return(&cs->port.count))
34845 tty_port_tty_set(&cs->port, NULL);
34846
34847 mutex_unlock(&cs->mutex);
34848 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
34849 index 821f7ac..28d4030 100644
34850 --- a/drivers/isdn/hardware/avm/b1.c
34851 +++ b/drivers/isdn/hardware/avm/b1.c
34852 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
34853 }
34854 if (left) {
34855 if (t4file->user) {
34856 - if (copy_from_user(buf, dp, left))
34857 + if (left > sizeof buf || copy_from_user(buf, dp, left))
34858 return -EFAULT;
34859 } else {
34860 memcpy(buf, dp, left);
34861 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
34862 }
34863 if (left) {
34864 if (config->user) {
34865 - if (copy_from_user(buf, dp, left))
34866 + if (left > sizeof buf || copy_from_user(buf, dp, left))
34867 return -EFAULT;
34868 } else {
34869 memcpy(buf, dp, left);
34870 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
34871 index b817809..409caff 100644
34872 --- a/drivers/isdn/i4l/isdn_tty.c
34873 +++ b/drivers/isdn/i4l/isdn_tty.c
34874 @@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
34875
34876 #ifdef ISDN_DEBUG_MODEM_OPEN
34877 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
34878 - port->count);
34879 + atomic_read(&port->count));
34880 #endif
34881 - port->count++;
34882 + atomic_inc(&port->count);
34883 port->tty = tty;
34884 /*
34885 * Start up serial port
34886 @@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34887 #endif
34888 return;
34889 }
34890 - if ((tty->count == 1) && (port->count != 1)) {
34891 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
34892 /*
34893 * Uh, oh. tty->count is 1, which means that the tty
34894 * structure will be freed. Info->count should always
34895 @@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34896 * serial port won't be shutdown.
34897 */
34898 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
34899 - "info->count is %d\n", port->count);
34900 - port->count = 1;
34901 + "info->count is %d\n", atomic_read(&port->count));
34902 + atomic_set(&port->count, 1);
34903 }
34904 - if (--port->count < 0) {
34905 + if (atomic_dec_return(&port->count) < 0) {
34906 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
34907 - info->line, port->count);
34908 - port->count = 0;
34909 + info->line, atomic_read(&port->count));
34910 + atomic_set(&port->count, 0);
34911 }
34912 - if (port->count) {
34913 + if (atomic_read(&port->count)) {
34914 #ifdef ISDN_DEBUG_MODEM_OPEN
34915 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
34916 #endif
34917 @@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
34918 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
34919 return;
34920 isdn_tty_shutdown(info);
34921 - port->count = 0;
34922 + atomic_set(&port->count, 0);
34923 port->flags &= ~ASYNC_NORMAL_ACTIVE;
34924 port->tty = NULL;
34925 wake_up_interruptible(&port->open_wait);
34926 @@ -1971,7 +1971,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
34927 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
34928 modem_info *info = &dev->mdm.info[i];
34929
34930 - if (info->port.count == 0)
34931 + if (atomic_read(&info->port.count) == 0)
34932 continue;
34933 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
34934 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
34935 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
34936 index e74df7c..03a03ba 100644
34937 --- a/drivers/isdn/icn/icn.c
34938 +++ b/drivers/isdn/icn/icn.c
34939 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
34940 if (count > len)
34941 count = len;
34942 if (user) {
34943 - if (copy_from_user(msg, buf, count))
34944 + if (count > sizeof msg || copy_from_user(msg, buf, count))
34945 return -EFAULT;
34946 } else
34947 memcpy(msg, buf, count);
34948 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
34949 index b5fdcb7..5b6c59f 100644
34950 --- a/drivers/lguest/core.c
34951 +++ b/drivers/lguest/core.c
34952 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
34953 * it's worked so far. The end address needs +1 because __get_vm_area
34954 * allocates an extra guard page, so we need space for that.
34955 */
34956 +
34957 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
34958 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34959 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
34960 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34961 +#else
34962 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34963 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
34964 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34965 +#endif
34966 +
34967 if (!switcher_vma) {
34968 err = -ENOMEM;
34969 printk("lguest: could not map switcher pages high\n");
34970 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
34971 * Now the Switcher is mapped at the right address, we can't fail!
34972 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
34973 */
34974 - memcpy(switcher_vma->addr, start_switcher_text,
34975 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
34976 end_switcher_text - start_switcher_text);
34977
34978 printk(KERN_INFO "lguest: mapped switcher at %p\n",
34979 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
34980 index 4af12e1..0e89afe 100644
34981 --- a/drivers/lguest/x86/core.c
34982 +++ b/drivers/lguest/x86/core.c
34983 @@ -59,7 +59,7 @@ static struct {
34984 /* Offset from where switcher.S was compiled to where we've copied it */
34985 static unsigned long switcher_offset(void)
34986 {
34987 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
34988 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
34989 }
34990
34991 /* This cpu's struct lguest_pages. */
34992 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
34993 * These copies are pretty cheap, so we do them unconditionally: */
34994 /* Save the current Host top-level page directory.
34995 */
34996 +
34997 +#ifdef CONFIG_PAX_PER_CPU_PGD
34998 + pages->state.host_cr3 = read_cr3();
34999 +#else
35000 pages->state.host_cr3 = __pa(current->mm->pgd);
35001 +#endif
35002 +
35003 /*
35004 * Set up the Guest's page tables to see this CPU's pages (and no
35005 * other CPU's pages).
35006 @@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
35007 * compiled-in switcher code and the high-mapped copy we just made.
35008 */
35009 for (i = 0; i < IDT_ENTRIES; i++)
35010 - default_idt_entries[i] += switcher_offset();
35011 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
35012
35013 /*
35014 * Set up the Switcher's per-cpu areas.
35015 @@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
35016 * it will be undisturbed when we switch. To change %cs and jump we
35017 * need this structure to feed to Intel's "lcall" instruction.
35018 */
35019 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
35020 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
35021 lguest_entry.segment = LGUEST_CS;
35022
35023 /*
35024 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
35025 index 40634b0..4f5855e 100644
35026 --- a/drivers/lguest/x86/switcher_32.S
35027 +++ b/drivers/lguest/x86/switcher_32.S
35028 @@ -87,6 +87,7 @@
35029 #include <asm/page.h>
35030 #include <asm/segment.h>
35031 #include <asm/lguest.h>
35032 +#include <asm/processor-flags.h>
35033
35034 // We mark the start of the code to copy
35035 // It's placed in .text tho it's never run here
35036 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
35037 // Changes type when we load it: damn Intel!
35038 // For after we switch over our page tables
35039 // That entry will be read-only: we'd crash.
35040 +
35041 +#ifdef CONFIG_PAX_KERNEXEC
35042 + mov %cr0, %edx
35043 + xor $X86_CR0_WP, %edx
35044 + mov %edx, %cr0
35045 +#endif
35046 +
35047 movl $(GDT_ENTRY_TSS*8), %edx
35048 ltr %dx
35049
35050 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
35051 // Let's clear it again for our return.
35052 // The GDT descriptor of the Host
35053 // Points to the table after two "size" bytes
35054 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
35055 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
35056 // Clear "used" from type field (byte 5, bit 2)
35057 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
35058 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
35059 +
35060 +#ifdef CONFIG_PAX_KERNEXEC
35061 + mov %cr0, %eax
35062 + xor $X86_CR0_WP, %eax
35063 + mov %eax, %cr0
35064 +#endif
35065
35066 // Once our page table's switched, the Guest is live!
35067 // The Host fades as we run this final step.
35068 @@ -295,13 +309,12 @@ deliver_to_host:
35069 // I consulted gcc, and it gave
35070 // These instructions, which I gladly credit:
35071 leal (%edx,%ebx,8), %eax
35072 - movzwl (%eax),%edx
35073 - movl 4(%eax), %eax
35074 - xorw %ax, %ax
35075 - orl %eax, %edx
35076 + movl 4(%eax), %edx
35077 + movw (%eax), %dx
35078 // Now the address of the handler's in %edx
35079 // We call it now: its "iret" drops us home.
35080 - jmp *%edx
35081 + ljmp $__KERNEL_CS, $1f
35082 +1: jmp *%edx
35083
35084 // Every interrupt can come to us here
35085 // But we must truly tell each apart.
35086 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
35087 index 7155945..4bcc562 100644
35088 --- a/drivers/md/bitmap.c
35089 +++ b/drivers/md/bitmap.c
35090 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
35091 chunk_kb ? "KB" : "B");
35092 if (bitmap->storage.file) {
35093 seq_printf(seq, ", file: ");
35094 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
35095 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
35096 }
35097
35098 seq_printf(seq, "\n");
35099 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
35100 index a651d52..82f8a95 100644
35101 --- a/drivers/md/dm-ioctl.c
35102 +++ b/drivers/md/dm-ioctl.c
35103 @@ -1601,7 +1601,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
35104 cmd == DM_LIST_VERSIONS_CMD)
35105 return 0;
35106
35107 - if ((cmd == DM_DEV_CREATE_CMD)) {
35108 + if (cmd == DM_DEV_CREATE_CMD) {
35109 if (!*param->name) {
35110 DMWARN("name not supplied when creating device");
35111 return -EINVAL;
35112 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
35113 index fd61f98..8050783 100644
35114 --- a/drivers/md/dm-raid1.c
35115 +++ b/drivers/md/dm-raid1.c
35116 @@ -40,7 +40,7 @@ enum dm_raid1_error {
35117
35118 struct mirror {
35119 struct mirror_set *ms;
35120 - atomic_t error_count;
35121 + atomic_unchecked_t error_count;
35122 unsigned long error_type;
35123 struct dm_dev *dev;
35124 sector_t offset;
35125 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
35126 struct mirror *m;
35127
35128 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
35129 - if (!atomic_read(&m->error_count))
35130 + if (!atomic_read_unchecked(&m->error_count))
35131 return m;
35132
35133 return NULL;
35134 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35135 * simple way to tell if a device has encountered
35136 * errors.
35137 */
35138 - atomic_inc(&m->error_count);
35139 + atomic_inc_unchecked(&m->error_count);
35140
35141 if (test_and_set_bit(error_type, &m->error_type))
35142 return;
35143 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
35144 struct mirror *m = get_default_mirror(ms);
35145
35146 do {
35147 - if (likely(!atomic_read(&m->error_count)))
35148 + if (likely(!atomic_read_unchecked(&m->error_count)))
35149 return m;
35150
35151 if (m-- == ms->mirror)
35152 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
35153 {
35154 struct mirror *default_mirror = get_default_mirror(m->ms);
35155
35156 - return !atomic_read(&default_mirror->error_count);
35157 + return !atomic_read_unchecked(&default_mirror->error_count);
35158 }
35159
35160 static int mirror_available(struct mirror_set *ms, struct bio *bio)
35161 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
35162 */
35163 if (likely(region_in_sync(ms, region, 1)))
35164 m = choose_mirror(ms, bio->bi_sector);
35165 - else if (m && atomic_read(&m->error_count))
35166 + else if (m && atomic_read_unchecked(&m->error_count))
35167 m = NULL;
35168
35169 if (likely(m))
35170 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
35171 }
35172
35173 ms->mirror[mirror].ms = ms;
35174 - atomic_set(&(ms->mirror[mirror].error_count), 0);
35175 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
35176 ms->mirror[mirror].error_type = 0;
35177 ms->mirror[mirror].offset = offset;
35178
35179 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
35180 */
35181 static char device_status_char(struct mirror *m)
35182 {
35183 - if (!atomic_read(&(m->error_count)))
35184 + if (!atomic_read_unchecked(&(m->error_count)))
35185 return 'A';
35186
35187 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
35188 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
35189 index e2f87653..f279abe 100644
35190 --- a/drivers/md/dm-stripe.c
35191 +++ b/drivers/md/dm-stripe.c
35192 @@ -20,7 +20,7 @@ struct stripe {
35193 struct dm_dev *dev;
35194 sector_t physical_start;
35195
35196 - atomic_t error_count;
35197 + atomic_unchecked_t error_count;
35198 };
35199
35200 struct stripe_c {
35201 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
35202 kfree(sc);
35203 return r;
35204 }
35205 - atomic_set(&(sc->stripe[i].error_count), 0);
35206 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
35207 }
35208
35209 ti->private = sc;
35210 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
35211 DMEMIT("%d ", sc->stripes);
35212 for (i = 0; i < sc->stripes; i++) {
35213 DMEMIT("%s ", sc->stripe[i].dev->name);
35214 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
35215 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
35216 'D' : 'A';
35217 }
35218 buffer[i] = '\0';
35219 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
35220 */
35221 for (i = 0; i < sc->stripes; i++)
35222 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
35223 - atomic_inc(&(sc->stripe[i].error_count));
35224 - if (atomic_read(&(sc->stripe[i].error_count)) <
35225 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
35226 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
35227 DM_IO_ERROR_THRESHOLD)
35228 schedule_work(&sc->trigger_event);
35229 }
35230 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
35231 index fa29557..d24a5b7 100644
35232 --- a/drivers/md/dm-table.c
35233 +++ b/drivers/md/dm-table.c
35234 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
35235 if (!dev_size)
35236 return 0;
35237
35238 - if ((start >= dev_size) || (start + len > dev_size)) {
35239 + if ((start >= dev_size) || (len > dev_size - start)) {
35240 DMWARN("%s: %s too small for target: "
35241 "start=%llu, len=%llu, dev_size=%llu",
35242 dm_device_name(ti->table->md), bdevname(bdev, b),
35243 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
35244 index 693e149..b7e0fde 100644
35245 --- a/drivers/md/dm-thin-metadata.c
35246 +++ b/drivers/md/dm-thin-metadata.c
35247 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35248 {
35249 pmd->info.tm = pmd->tm;
35250 pmd->info.levels = 2;
35251 - pmd->info.value_type.context = pmd->data_sm;
35252 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35253 pmd->info.value_type.size = sizeof(__le64);
35254 pmd->info.value_type.inc = data_block_inc;
35255 pmd->info.value_type.dec = data_block_dec;
35256 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35257
35258 pmd->bl_info.tm = pmd->tm;
35259 pmd->bl_info.levels = 1;
35260 - pmd->bl_info.value_type.context = pmd->data_sm;
35261 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35262 pmd->bl_info.value_type.size = sizeof(__le64);
35263 pmd->bl_info.value_type.inc = data_block_inc;
35264 pmd->bl_info.value_type.dec = data_block_dec;
35265 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
35266 index 77e6eff..913d695 100644
35267 --- a/drivers/md/dm.c
35268 +++ b/drivers/md/dm.c
35269 @@ -182,9 +182,9 @@ struct mapped_device {
35270 /*
35271 * Event handling.
35272 */
35273 - atomic_t event_nr;
35274 + atomic_unchecked_t event_nr;
35275 wait_queue_head_t eventq;
35276 - atomic_t uevent_seq;
35277 + atomic_unchecked_t uevent_seq;
35278 struct list_head uevent_list;
35279 spinlock_t uevent_lock; /* Protect access to uevent_list */
35280
35281 @@ -1847,8 +1847,8 @@ static struct mapped_device *alloc_dev(int minor)
35282 rwlock_init(&md->map_lock);
35283 atomic_set(&md->holders, 1);
35284 atomic_set(&md->open_count, 0);
35285 - atomic_set(&md->event_nr, 0);
35286 - atomic_set(&md->uevent_seq, 0);
35287 + atomic_set_unchecked(&md->event_nr, 0);
35288 + atomic_set_unchecked(&md->uevent_seq, 0);
35289 INIT_LIST_HEAD(&md->uevent_list);
35290 spin_lock_init(&md->uevent_lock);
35291
35292 @@ -1982,7 +1982,7 @@ static void event_callback(void *context)
35293
35294 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
35295
35296 - atomic_inc(&md->event_nr);
35297 + atomic_inc_unchecked(&md->event_nr);
35298 wake_up(&md->eventq);
35299 }
35300
35301 @@ -2637,18 +2637,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
35302
35303 uint32_t dm_next_uevent_seq(struct mapped_device *md)
35304 {
35305 - return atomic_add_return(1, &md->uevent_seq);
35306 + return atomic_add_return_unchecked(1, &md->uevent_seq);
35307 }
35308
35309 uint32_t dm_get_event_nr(struct mapped_device *md)
35310 {
35311 - return atomic_read(&md->event_nr);
35312 + return atomic_read_unchecked(&md->event_nr);
35313 }
35314
35315 int dm_wait_event(struct mapped_device *md, int event_nr)
35316 {
35317 return wait_event_interruptible(md->eventq,
35318 - (event_nr != atomic_read(&md->event_nr)));
35319 + (event_nr != atomic_read_unchecked(&md->event_nr)));
35320 }
35321
35322 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
35323 diff --git a/drivers/md/md.c b/drivers/md/md.c
35324 index 6120071..31d9be2 100644
35325 --- a/drivers/md/md.c
35326 +++ b/drivers/md/md.c
35327 @@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
35328 * start build, activate spare
35329 */
35330 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
35331 -static atomic_t md_event_count;
35332 +static atomic_unchecked_t md_event_count;
35333 void md_new_event(struct mddev *mddev)
35334 {
35335 - atomic_inc(&md_event_count);
35336 + atomic_inc_unchecked(&md_event_count);
35337 wake_up(&md_event_waiters);
35338 }
35339 EXPORT_SYMBOL_GPL(md_new_event);
35340 @@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
35341 */
35342 static void md_new_event_inintr(struct mddev *mddev)
35343 {
35344 - atomic_inc(&md_event_count);
35345 + atomic_inc_unchecked(&md_event_count);
35346 wake_up(&md_event_waiters);
35347 }
35348
35349 @@ -1504,7 +1504,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
35350 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
35351 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
35352 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
35353 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
35354 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
35355
35356 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
35357 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
35358 @@ -1748,7 +1748,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
35359 else
35360 sb->resync_offset = cpu_to_le64(0);
35361
35362 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
35363 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
35364
35365 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
35366 sb->size = cpu_to_le64(mddev->dev_sectors);
35367 @@ -2748,7 +2748,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
35368 static ssize_t
35369 errors_show(struct md_rdev *rdev, char *page)
35370 {
35371 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
35372 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
35373 }
35374
35375 static ssize_t
35376 @@ -2757,7 +2757,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
35377 char *e;
35378 unsigned long n = simple_strtoul(buf, &e, 10);
35379 if (*buf && (*e == 0 || *e == '\n')) {
35380 - atomic_set(&rdev->corrected_errors, n);
35381 + atomic_set_unchecked(&rdev->corrected_errors, n);
35382 return len;
35383 }
35384 return -EINVAL;
35385 @@ -3204,8 +3204,8 @@ int md_rdev_init(struct md_rdev *rdev)
35386 rdev->sb_loaded = 0;
35387 rdev->bb_page = NULL;
35388 atomic_set(&rdev->nr_pending, 0);
35389 - atomic_set(&rdev->read_errors, 0);
35390 - atomic_set(&rdev->corrected_errors, 0);
35391 + atomic_set_unchecked(&rdev->read_errors, 0);
35392 + atomic_set_unchecked(&rdev->corrected_errors, 0);
35393
35394 INIT_LIST_HEAD(&rdev->same_set);
35395 init_waitqueue_head(&rdev->blocked_wait);
35396 @@ -6984,7 +6984,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
35397
35398 spin_unlock(&pers_lock);
35399 seq_printf(seq, "\n");
35400 - seq->poll_event = atomic_read(&md_event_count);
35401 + seq->poll_event = atomic_read_unchecked(&md_event_count);
35402 return 0;
35403 }
35404 if (v == (void*)2) {
35405 @@ -7087,7 +7087,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
35406 return error;
35407
35408 seq = file->private_data;
35409 - seq->poll_event = atomic_read(&md_event_count);
35410 + seq->poll_event = atomic_read_unchecked(&md_event_count);
35411 return error;
35412 }
35413
35414 @@ -7101,7 +7101,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
35415 /* always allow read */
35416 mask = POLLIN | POLLRDNORM;
35417
35418 - if (seq->poll_event != atomic_read(&md_event_count))
35419 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
35420 mask |= POLLERR | POLLPRI;
35421 return mask;
35422 }
35423 @@ -7145,7 +7145,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
35424 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
35425 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
35426 (int)part_stat_read(&disk->part0, sectors[1]) -
35427 - atomic_read(&disk->sync_io);
35428 + atomic_read_unchecked(&disk->sync_io);
35429 /* sync IO will cause sync_io to increase before the disk_stats
35430 * as sync_io is counted when a request starts, and
35431 * disk_stats is counted when it completes.
35432 diff --git a/drivers/md/md.h b/drivers/md/md.h
35433 index af443ab..0f93be3 100644
35434 --- a/drivers/md/md.h
35435 +++ b/drivers/md/md.h
35436 @@ -94,13 +94,13 @@ struct md_rdev {
35437 * only maintained for arrays that
35438 * support hot removal
35439 */
35440 - atomic_t read_errors; /* number of consecutive read errors that
35441 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
35442 * we have tried to ignore.
35443 */
35444 struct timespec last_read_error; /* monotonic time since our
35445 * last read error
35446 */
35447 - atomic_t corrected_errors; /* number of corrected read errors,
35448 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
35449 * for reporting to userspace and storing
35450 * in superblock.
35451 */
35452 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
35453
35454 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
35455 {
35456 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
35457 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
35458 }
35459
35460 struct md_personality
35461 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
35462 index 1cbfc6b..56e1dbb 100644
35463 --- a/drivers/md/persistent-data/dm-space-map.h
35464 +++ b/drivers/md/persistent-data/dm-space-map.h
35465 @@ -60,6 +60,7 @@ struct dm_space_map {
35466 int (*root_size)(struct dm_space_map *sm, size_t *result);
35467 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
35468 };
35469 +typedef struct dm_space_map __no_const dm_space_map_no_const;
35470
35471 /*----------------------------------------------------------------*/
35472
35473 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
35474 index a0f7309..5599dbc 100644
35475 --- a/drivers/md/raid1.c
35476 +++ b/drivers/md/raid1.c
35477 @@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
35478 if (r1_sync_page_io(rdev, sect, s,
35479 bio->bi_io_vec[idx].bv_page,
35480 READ) != 0)
35481 - atomic_add(s, &rdev->corrected_errors);
35482 + atomic_add_unchecked(s, &rdev->corrected_errors);
35483 }
35484 sectors -= s;
35485 sect += s;
35486 @@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
35487 test_bit(In_sync, &rdev->flags)) {
35488 if (r1_sync_page_io(rdev, sect, s,
35489 conf->tmppage, READ)) {
35490 - atomic_add(s, &rdev->corrected_errors);
35491 + atomic_add_unchecked(s, &rdev->corrected_errors);
35492 printk(KERN_INFO
35493 "md/raid1:%s: read error corrected "
35494 "(%d sectors at %llu on %s)\n",
35495 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
35496 index c9acbd7..386cd3e 100644
35497 --- a/drivers/md/raid10.c
35498 +++ b/drivers/md/raid10.c
35499 @@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
35500 /* The write handler will notice the lack of
35501 * R10BIO_Uptodate and record any errors etc
35502 */
35503 - atomic_add(r10_bio->sectors,
35504 + atomic_add_unchecked(r10_bio->sectors,
35505 &conf->mirrors[d].rdev->corrected_errors);
35506
35507 /* for reconstruct, we always reschedule after a read.
35508 @@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35509 {
35510 struct timespec cur_time_mon;
35511 unsigned long hours_since_last;
35512 - unsigned int read_errors = atomic_read(&rdev->read_errors);
35513 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
35514
35515 ktime_get_ts(&cur_time_mon);
35516
35517 @@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35518 * overflowing the shift of read_errors by hours_since_last.
35519 */
35520 if (hours_since_last >= 8 * sizeof(read_errors))
35521 - atomic_set(&rdev->read_errors, 0);
35522 + atomic_set_unchecked(&rdev->read_errors, 0);
35523 else
35524 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
35525 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
35526 }
35527
35528 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
35529 @@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35530 return;
35531
35532 check_decay_read_errors(mddev, rdev);
35533 - atomic_inc(&rdev->read_errors);
35534 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
35535 + atomic_inc_unchecked(&rdev->read_errors);
35536 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
35537 char b[BDEVNAME_SIZE];
35538 bdevname(rdev->bdev, b);
35539
35540 @@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35541 "md/raid10:%s: %s: Raid device exceeded "
35542 "read_error threshold [cur %d:max %d]\n",
35543 mdname(mddev), b,
35544 - atomic_read(&rdev->read_errors), max_read_errors);
35545 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
35546 printk(KERN_NOTICE
35547 "md/raid10:%s: %s: Failing raid device\n",
35548 mdname(mddev), b);
35549 @@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35550 sect +
35551 choose_data_offset(r10_bio, rdev)),
35552 bdevname(rdev->bdev, b));
35553 - atomic_add(s, &rdev->corrected_errors);
35554 + atomic_add_unchecked(s, &rdev->corrected_errors);
35555 }
35556
35557 rdev_dec_pending(rdev, mddev);
35558 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
35559 index a450268..c4168a9 100644
35560 --- a/drivers/md/raid5.c
35561 +++ b/drivers/md/raid5.c
35562 @@ -1789,21 +1789,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
35563 mdname(conf->mddev), STRIPE_SECTORS,
35564 (unsigned long long)s,
35565 bdevname(rdev->bdev, b));
35566 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
35567 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
35568 clear_bit(R5_ReadError, &sh->dev[i].flags);
35569 clear_bit(R5_ReWrite, &sh->dev[i].flags);
35570 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
35571 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
35572
35573 - if (atomic_read(&rdev->read_errors))
35574 - atomic_set(&rdev->read_errors, 0);
35575 + if (atomic_read_unchecked(&rdev->read_errors))
35576 + atomic_set_unchecked(&rdev->read_errors, 0);
35577 } else {
35578 const char *bdn = bdevname(rdev->bdev, b);
35579 int retry = 0;
35580 int set_bad = 0;
35581
35582 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
35583 - atomic_inc(&rdev->read_errors);
35584 + atomic_inc_unchecked(&rdev->read_errors);
35585 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
35586 printk_ratelimited(
35587 KERN_WARNING
35588 @@ -1831,7 +1831,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
35589 mdname(conf->mddev),
35590 (unsigned long long)s,
35591 bdn);
35592 - } else if (atomic_read(&rdev->read_errors)
35593 + } else if (atomic_read_unchecked(&rdev->read_errors)
35594 > conf->max_nr_stripes)
35595 printk(KERN_WARNING
35596 "md/raid:%s: Too many read errors, failing device %s.\n",
35597 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
35598 index d33101a..6b13069 100644
35599 --- a/drivers/media/dvb-core/dvbdev.c
35600 +++ b/drivers/media/dvb-core/dvbdev.c
35601 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
35602 const struct dvb_device *template, void *priv, int type)
35603 {
35604 struct dvb_device *dvbdev;
35605 - struct file_operations *dvbdevfops;
35606 + file_operations_no_const *dvbdevfops;
35607 struct device *clsdev;
35608 int minor;
35609 int id;
35610 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
35611 index 404f63a..4796533 100644
35612 --- a/drivers/media/dvb-frontends/dib3000.h
35613 +++ b/drivers/media/dvb-frontends/dib3000.h
35614 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
35615 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
35616 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
35617 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
35618 -};
35619 +} __no_const;
35620
35621 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
35622 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
35623 diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c
35624 index 3aa6856..435ad25 100644
35625 --- a/drivers/media/pci/cx88/cx88-alsa.c
35626 +++ b/drivers/media/pci/cx88/cx88-alsa.c
35627 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
35628 * Only boards with eeprom and byte 1 at eeprom=1 have it
35629 */
35630
35631 -static const struct pci_device_id cx88_audio_pci_tbl[] __devinitdata = {
35632 +static const struct pci_device_id cx88_audio_pci_tbl[] __devinitconst = {
35633 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35634 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35635 {0, }
35636 diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
35637 index feff57e..66a2c67 100644
35638 --- a/drivers/media/pci/ddbridge/ddbridge-core.c
35639 +++ b/drivers/media/pci/ddbridge/ddbridge-core.c
35640 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
35641 .subvendor = _subvend, .subdevice = _subdev, \
35642 .driver_data = (unsigned long)&_driverdata }
35643
35644 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
35645 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
35646 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
35647 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
35648 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
35649 diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c
35650 index 96a13ed..6df45b4 100644
35651 --- a/drivers/media/pci/ngene/ngene-cards.c
35652 +++ b/drivers/media/pci/ngene/ngene-cards.c
35653 @@ -741,7 +741,7 @@ static struct ngene_info ngene_info_terratec = {
35654
35655 /****************************************************************************/
35656
35657 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
35658 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
35659 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
35660 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
35661 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
35662 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
35663 index a3b1a34..71ce0e3 100644
35664 --- a/drivers/media/platform/omap/omap_vout.c
35665 +++ b/drivers/media/platform/omap/omap_vout.c
35666 @@ -65,7 +65,6 @@ enum omap_vout_channels {
35667 OMAP_VIDEO2,
35668 };
35669
35670 -static struct videobuf_queue_ops video_vbq_ops;
35671 /* Variables configurable through module params*/
35672 static u32 video1_numbuffers = 3;
35673 static u32 video2_numbuffers = 3;
35674 @@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
35675 {
35676 struct videobuf_queue *q;
35677 struct omap_vout_device *vout = NULL;
35678 + static struct videobuf_queue_ops video_vbq_ops = {
35679 + .buf_setup = omap_vout_buffer_setup,
35680 + .buf_prepare = omap_vout_buffer_prepare,
35681 + .buf_release = omap_vout_buffer_release,
35682 + .buf_queue = omap_vout_buffer_queue,
35683 + };
35684
35685 vout = video_drvdata(file);
35686 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
35687 @@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
35688 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
35689
35690 q = &vout->vbq;
35691 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
35692 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
35693 - video_vbq_ops.buf_release = omap_vout_buffer_release;
35694 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
35695 spin_lock_init(&vout->vbq_lock);
35696
35697 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
35698 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
35699 index ddb422e..8cf008e 100644
35700 --- a/drivers/media/platform/s5p-tv/mixer.h
35701 +++ b/drivers/media/platform/s5p-tv/mixer.h
35702 @@ -155,7 +155,7 @@ struct mxr_layer {
35703 /** layer index (unique identifier) */
35704 int idx;
35705 /** callbacks for layer methods */
35706 - struct mxr_layer_ops ops;
35707 + struct mxr_layer_ops *ops;
35708 /** format array */
35709 const struct mxr_format **fmt_array;
35710 /** size of format array */
35711 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35712 index b93a21f..2535195 100644
35713 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35714 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35715 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
35716 {
35717 struct mxr_layer *layer;
35718 int ret;
35719 - struct mxr_layer_ops ops = {
35720 + static struct mxr_layer_ops ops = {
35721 .release = mxr_graph_layer_release,
35722 .buffer_set = mxr_graph_buffer_set,
35723 .stream_set = mxr_graph_stream_set,
35724 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
35725 index 3b1670a..595c939 100644
35726 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
35727 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
35728 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
35729 layer->update_buf = next;
35730 }
35731
35732 - layer->ops.buffer_set(layer, layer->update_buf);
35733 + layer->ops->buffer_set(layer, layer->update_buf);
35734
35735 if (done && done != layer->shadow_buf)
35736 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
35737 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
35738 index 0c1cd89..6574647 100644
35739 --- a/drivers/media/platform/s5p-tv/mixer_video.c
35740 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
35741 @@ -209,7 +209,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
35742 layer->geo.src.height = layer->geo.src.full_height;
35743
35744 mxr_geometry_dump(mdev, &layer->geo);
35745 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35746 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35747 mxr_geometry_dump(mdev, &layer->geo);
35748 }
35749
35750 @@ -227,7 +227,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
35751 layer->geo.dst.full_width = mbus_fmt.width;
35752 layer->geo.dst.full_height = mbus_fmt.height;
35753 layer->geo.dst.field = mbus_fmt.field;
35754 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35755 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35756
35757 mxr_geometry_dump(mdev, &layer->geo);
35758 }
35759 @@ -333,7 +333,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
35760 /* set source size to highest accepted value */
35761 geo->src.full_width = max(geo->dst.full_width, pix->width);
35762 geo->src.full_height = max(geo->dst.full_height, pix->height);
35763 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35764 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35765 mxr_geometry_dump(mdev, &layer->geo);
35766 /* set cropping to total visible screen */
35767 geo->src.width = pix->width;
35768 @@ -341,12 +341,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
35769 geo->src.x_offset = 0;
35770 geo->src.y_offset = 0;
35771 /* assure consistency of geometry */
35772 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
35773 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
35774 mxr_geometry_dump(mdev, &layer->geo);
35775 /* set full size to lowest possible value */
35776 geo->src.full_width = 0;
35777 geo->src.full_height = 0;
35778 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35779 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35780 mxr_geometry_dump(mdev, &layer->geo);
35781
35782 /* returning results */
35783 @@ -473,7 +473,7 @@ static int mxr_s_selection(struct file *file, void *fh,
35784 target->width = s->r.width;
35785 target->height = s->r.height;
35786
35787 - layer->ops.fix_geometry(layer, stage, s->flags);
35788 + layer->ops->fix_geometry(layer, stage, s->flags);
35789
35790 /* retrieve update selection rectangle */
35791 res.left = target->x_offset;
35792 @@ -928,13 +928,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
35793 mxr_output_get(mdev);
35794
35795 mxr_layer_update_output(layer);
35796 - layer->ops.format_set(layer);
35797 + layer->ops->format_set(layer);
35798 /* enabling layer in hardware */
35799 spin_lock_irqsave(&layer->enq_slock, flags);
35800 layer->state = MXR_LAYER_STREAMING;
35801 spin_unlock_irqrestore(&layer->enq_slock, flags);
35802
35803 - layer->ops.stream_set(layer, MXR_ENABLE);
35804 + layer->ops->stream_set(layer, MXR_ENABLE);
35805 mxr_streamer_get(mdev);
35806
35807 return 0;
35808 @@ -1004,7 +1004,7 @@ static int stop_streaming(struct vb2_queue *vq)
35809 spin_unlock_irqrestore(&layer->enq_slock, flags);
35810
35811 /* disabling layer in hardware */
35812 - layer->ops.stream_set(layer, MXR_DISABLE);
35813 + layer->ops->stream_set(layer, MXR_DISABLE);
35814 /* remove one streamer */
35815 mxr_streamer_put(mdev);
35816 /* allow changes in output configuration */
35817 @@ -1043,8 +1043,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
35818
35819 void mxr_layer_release(struct mxr_layer *layer)
35820 {
35821 - if (layer->ops.release)
35822 - layer->ops.release(layer);
35823 + if (layer->ops->release)
35824 + layer->ops->release(layer);
35825 }
35826
35827 void mxr_base_layer_release(struct mxr_layer *layer)
35828 @@ -1070,7 +1070,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
35829
35830 layer->mdev = mdev;
35831 layer->idx = idx;
35832 - layer->ops = *ops;
35833 + layer->ops = ops;
35834
35835 spin_lock_init(&layer->enq_slock);
35836 INIT_LIST_HEAD(&layer->enq_list);
35837 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35838 index 3d13a63..da31bf1 100644
35839 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35840 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35841 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
35842 {
35843 struct mxr_layer *layer;
35844 int ret;
35845 - struct mxr_layer_ops ops = {
35846 + static struct mxr_layer_ops ops = {
35847 .release = mxr_vp_layer_release,
35848 .buffer_set = mxr_vp_buffer_set,
35849 .stream_set = mxr_vp_stream_set,
35850 diff --git a/drivers/media/platform/timblogiw.c b/drivers/media/platform/timblogiw.c
35851 index 02194c0..36d69c1 100644
35852 --- a/drivers/media/platform/timblogiw.c
35853 +++ b/drivers/media/platform/timblogiw.c
35854 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
35855
35856 /* Platform device functions */
35857
35858 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35859 +static struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35860 .vidioc_querycap = timblogiw_querycap,
35861 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
35862 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
35863 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35864 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
35865 };
35866
35867 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
35868 +static struct v4l2_file_operations timblogiw_fops = {
35869 .owner = THIS_MODULE,
35870 .open = timblogiw_open,
35871 .release = timblogiw_close,
35872 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
35873 index 697a421..16c5a5f 100644
35874 --- a/drivers/media/radio/radio-cadet.c
35875 +++ b/drivers/media/radio/radio-cadet.c
35876 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35877 unsigned char readbuf[RDS_BUFFER];
35878 int i = 0;
35879
35880 + if (count > RDS_BUFFER)
35881 + return -EFAULT;
35882 mutex_lock(&dev->lock);
35883 if (dev->rdsstat == 0)
35884 cadet_start_rds(dev);
35885 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35886 while (i < count && dev->rdsin != dev->rdsout)
35887 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
35888
35889 - if (i && copy_to_user(data, readbuf, i))
35890 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
35891 i = -EFAULT;
35892 unlock:
35893 mutex_unlock(&dev->lock);
35894 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
35895 index 3940bb0..fb3952a 100644
35896 --- a/drivers/media/usb/dvb-usb/cxusb.c
35897 +++ b/drivers/media/usb/dvb-usb/cxusb.c
35898 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
35899
35900 struct dib0700_adapter_state {
35901 int (*set_param_save) (struct dvb_frontend *);
35902 -};
35903 +} __no_const;
35904
35905 static int dib7070_set_param_override(struct dvb_frontend *fe)
35906 {
35907 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
35908 index 9382895..ac8093c 100644
35909 --- a/drivers/media/usb/dvb-usb/dw2102.c
35910 +++ b/drivers/media/usb/dvb-usb/dw2102.c
35911 @@ -95,7 +95,7 @@ struct su3000_state {
35912
35913 struct s6x0_state {
35914 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
35915 -};
35916 +} __no_const;
35917
35918 /* debug */
35919 static int dvb_usb_dw2102_debug;
35920 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
35921 index fb69baa..cf7ad22 100644
35922 --- a/drivers/message/fusion/mptbase.c
35923 +++ b/drivers/message/fusion/mptbase.c
35924 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
35925 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
35926 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
35927
35928 +#ifdef CONFIG_GRKERNSEC_HIDESYM
35929 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
35930 +#else
35931 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
35932 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
35933 +#endif
35934 +
35935 /*
35936 * Rounding UP to nearest 4-kB boundary here...
35937 */
35938 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
35939 index 551262e..7551198 100644
35940 --- a/drivers/message/fusion/mptsas.c
35941 +++ b/drivers/message/fusion/mptsas.c
35942 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
35943 return 0;
35944 }
35945
35946 +static inline void
35947 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35948 +{
35949 + if (phy_info->port_details) {
35950 + phy_info->port_details->rphy = rphy;
35951 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35952 + ioc->name, rphy));
35953 + }
35954 +
35955 + if (rphy) {
35956 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35957 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35958 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35959 + ioc->name, rphy, rphy->dev.release));
35960 + }
35961 +}
35962 +
35963 /* no mutex */
35964 static void
35965 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
35966 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
35967 return NULL;
35968 }
35969
35970 -static inline void
35971 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35972 -{
35973 - if (phy_info->port_details) {
35974 - phy_info->port_details->rphy = rphy;
35975 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35976 - ioc->name, rphy));
35977 - }
35978 -
35979 - if (rphy) {
35980 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35981 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35982 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35983 - ioc->name, rphy, rphy->dev.release));
35984 - }
35985 -}
35986 -
35987 static inline struct sas_port *
35988 mptsas_get_port(struct mptsas_phyinfo *phy_info)
35989 {
35990 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
35991 index 0c3ced7..1fe34ec 100644
35992 --- a/drivers/message/fusion/mptscsih.c
35993 +++ b/drivers/message/fusion/mptscsih.c
35994 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
35995
35996 h = shost_priv(SChost);
35997
35998 - if (h) {
35999 - if (h->info_kbuf == NULL)
36000 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36001 - return h->info_kbuf;
36002 - h->info_kbuf[0] = '\0';
36003 + if (!h)
36004 + return NULL;
36005
36006 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36007 - h->info_kbuf[size-1] = '\0';
36008 - }
36009 + if (h->info_kbuf == NULL)
36010 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36011 + return h->info_kbuf;
36012 + h->info_kbuf[0] = '\0';
36013 +
36014 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36015 + h->info_kbuf[size-1] = '\0';
36016
36017 return h->info_kbuf;
36018 }
36019 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
36020 index 8001aa6..b137580 100644
36021 --- a/drivers/message/i2o/i2o_proc.c
36022 +++ b/drivers/message/i2o/i2o_proc.c
36023 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
36024 "Array Controller Device"
36025 };
36026
36027 -static char *chtostr(char *tmp, u8 *chars, int n)
36028 -{
36029 - tmp[0] = 0;
36030 - return strncat(tmp, (char *)chars, n);
36031 -}
36032 -
36033 static int i2o_report_query_status(struct seq_file *seq, int block_status,
36034 char *group)
36035 {
36036 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36037 } *result;
36038
36039 i2o_exec_execute_ddm_table ddm_table;
36040 - char tmp[28 + 1];
36041
36042 result = kmalloc(sizeof(*result), GFP_KERNEL);
36043 if (!result)
36044 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36045
36046 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
36047 seq_printf(seq, "%-#8x", ddm_table.module_id);
36048 - seq_printf(seq, "%-29s",
36049 - chtostr(tmp, ddm_table.module_name_version, 28));
36050 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
36051 seq_printf(seq, "%9d ", ddm_table.data_size);
36052 seq_printf(seq, "%8d", ddm_table.code_size);
36053
36054 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36055
36056 i2o_driver_result_table *result;
36057 i2o_driver_store_table *dst;
36058 - char tmp[28 + 1];
36059
36060 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
36061 if (result == NULL)
36062 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36063
36064 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
36065 seq_printf(seq, "%-#8x", dst->module_id);
36066 - seq_printf(seq, "%-29s",
36067 - chtostr(tmp, dst->module_name_version, 28));
36068 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
36069 + seq_printf(seq, "%-.28s", dst->module_name_version);
36070 + seq_printf(seq, "%-.8s", dst->date);
36071 seq_printf(seq, "%8d ", dst->module_size);
36072 seq_printf(seq, "%8d ", dst->mpb_size);
36073 seq_printf(seq, "0x%04x", dst->module_flags);
36074 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36075 // == (allow) 512d bytes (max)
36076 static u16 *work16 = (u16 *) work32;
36077 int token;
36078 - char tmp[16 + 1];
36079
36080 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
36081
36082 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36083 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
36084 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
36085 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
36086 - seq_printf(seq, "Vendor info : %s\n",
36087 - chtostr(tmp, (u8 *) (work32 + 2), 16));
36088 - seq_printf(seq, "Product info : %s\n",
36089 - chtostr(tmp, (u8 *) (work32 + 6), 16));
36090 - seq_printf(seq, "Description : %s\n",
36091 - chtostr(tmp, (u8 *) (work32 + 10), 16));
36092 - seq_printf(seq, "Product rev. : %s\n",
36093 - chtostr(tmp, (u8 *) (work32 + 14), 8));
36094 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
36095 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
36096 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
36097 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
36098
36099 seq_printf(seq, "Serial number : ");
36100 print_serial_number(seq, (u8 *) (work32 + 16),
36101 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36102 u8 pad[256]; // allow up to 256 byte (max) serial number
36103 } result;
36104
36105 - char tmp[24 + 1];
36106 -
36107 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
36108
36109 if (token < 0) {
36110 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36111 }
36112
36113 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
36114 - seq_printf(seq, "Module name : %s\n",
36115 - chtostr(tmp, result.module_name, 24));
36116 - seq_printf(seq, "Module revision : %s\n",
36117 - chtostr(tmp, result.module_rev, 8));
36118 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
36119 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
36120
36121 seq_printf(seq, "Serial number : ");
36122 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
36123 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36124 u8 instance_number[4];
36125 } result;
36126
36127 - char tmp[64 + 1];
36128 -
36129 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
36130
36131 if (token < 0) {
36132 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36133 return 0;
36134 }
36135
36136 - seq_printf(seq, "Device name : %s\n",
36137 - chtostr(tmp, result.device_name, 64));
36138 - seq_printf(seq, "Service name : %s\n",
36139 - chtostr(tmp, result.service_name, 64));
36140 - seq_printf(seq, "Physical name : %s\n",
36141 - chtostr(tmp, result.physical_location, 64));
36142 - seq_printf(seq, "Instance number : %s\n",
36143 - chtostr(tmp, result.instance_number, 4));
36144 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
36145 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
36146 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
36147 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
36148
36149 return 0;
36150 }
36151 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
36152 index a8c08f3..155fe3d 100644
36153 --- a/drivers/message/i2o/iop.c
36154 +++ b/drivers/message/i2o/iop.c
36155 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
36156
36157 spin_lock_irqsave(&c->context_list_lock, flags);
36158
36159 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
36160 - atomic_inc(&c->context_list_counter);
36161 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
36162 + atomic_inc_unchecked(&c->context_list_counter);
36163
36164 - entry->context = atomic_read(&c->context_list_counter);
36165 + entry->context = atomic_read_unchecked(&c->context_list_counter);
36166
36167 list_add(&entry->list, &c->context_list);
36168
36169 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
36170
36171 #if BITS_PER_LONG == 64
36172 spin_lock_init(&c->context_list_lock);
36173 - atomic_set(&c->context_list_counter, 0);
36174 + atomic_set_unchecked(&c->context_list_counter, 0);
36175 INIT_LIST_HEAD(&c->context_list);
36176 #endif
36177
36178 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
36179 index 965c480..71f2db9 100644
36180 --- a/drivers/mfd/janz-cmodio.c
36181 +++ b/drivers/mfd/janz-cmodio.c
36182 @@ -13,6 +13,7 @@
36183
36184 #include <linux/kernel.h>
36185 #include <linux/module.h>
36186 +#include <linux/slab.h>
36187 #include <linux/init.h>
36188 #include <linux/pci.h>
36189 #include <linux/interrupt.h>
36190 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
36191 index 3aa9a96..59cf685 100644
36192 --- a/drivers/misc/kgdbts.c
36193 +++ b/drivers/misc/kgdbts.c
36194 @@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
36195 char before[BREAK_INSTR_SIZE];
36196 char after[BREAK_INSTR_SIZE];
36197
36198 - probe_kernel_read(before, (char *)kgdbts_break_test,
36199 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
36200 BREAK_INSTR_SIZE);
36201 init_simple_test();
36202 ts.tst = plant_and_detach_test;
36203 @@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
36204 /* Activate test with initial breakpoint */
36205 if (!is_early)
36206 kgdb_breakpoint();
36207 - probe_kernel_read(after, (char *)kgdbts_break_test,
36208 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
36209 BREAK_INSTR_SIZE);
36210 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
36211 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
36212 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
36213 index 4a87e5c..76bdf5c 100644
36214 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
36215 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
36216 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
36217 * the lid is closed. This leads to interrupts as soon as a little move
36218 * is done.
36219 */
36220 - atomic_inc(&lis3->count);
36221 + atomic_inc_unchecked(&lis3->count);
36222
36223 wake_up_interruptible(&lis3->misc_wait);
36224 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
36225 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
36226 if (lis3->pm_dev)
36227 pm_runtime_get_sync(lis3->pm_dev);
36228
36229 - atomic_set(&lis3->count, 0);
36230 + atomic_set_unchecked(&lis3->count, 0);
36231 return 0;
36232 }
36233
36234 @@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
36235 add_wait_queue(&lis3->misc_wait, &wait);
36236 while (true) {
36237 set_current_state(TASK_INTERRUPTIBLE);
36238 - data = atomic_xchg(&lis3->count, 0);
36239 + data = atomic_xchg_unchecked(&lis3->count, 0);
36240 if (data)
36241 break;
36242
36243 @@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
36244 struct lis3lv02d, miscdev);
36245
36246 poll_wait(file, &lis3->misc_wait, wait);
36247 - if (atomic_read(&lis3->count))
36248 + if (atomic_read_unchecked(&lis3->count))
36249 return POLLIN | POLLRDNORM;
36250 return 0;
36251 }
36252 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
36253 index c439c82..1f20f57 100644
36254 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
36255 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
36256 @@ -297,7 +297,7 @@ struct lis3lv02d {
36257 struct input_polled_dev *idev; /* input device */
36258 struct platform_device *pdev; /* platform device */
36259 struct regulator_bulk_data regulators[2];
36260 - atomic_t count; /* interrupt count after last read */
36261 + atomic_unchecked_t count; /* interrupt count after last read */
36262 union axis_conversion ac; /* hw -> logical axis */
36263 int mapped_btns[3];
36264
36265 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
36266 index 2f30bad..c4c13d0 100644
36267 --- a/drivers/misc/sgi-gru/gruhandles.c
36268 +++ b/drivers/misc/sgi-gru/gruhandles.c
36269 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
36270 unsigned long nsec;
36271
36272 nsec = CLKS2NSEC(clks);
36273 - atomic_long_inc(&mcs_op_statistics[op].count);
36274 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
36275 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
36276 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
36277 if (mcs_op_statistics[op].max < nsec)
36278 mcs_op_statistics[op].max = nsec;
36279 }
36280 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
36281 index 950dbe9..eeef0f8 100644
36282 --- a/drivers/misc/sgi-gru/gruprocfs.c
36283 +++ b/drivers/misc/sgi-gru/gruprocfs.c
36284 @@ -32,9 +32,9 @@
36285
36286 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
36287
36288 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
36289 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
36290 {
36291 - unsigned long val = atomic_long_read(v);
36292 + unsigned long val = atomic_long_read_unchecked(v);
36293
36294 seq_printf(s, "%16lu %s\n", val, id);
36295 }
36296 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
36297
36298 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
36299 for (op = 0; op < mcsop_last; op++) {
36300 - count = atomic_long_read(&mcs_op_statistics[op].count);
36301 - total = atomic_long_read(&mcs_op_statistics[op].total);
36302 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
36303 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
36304 max = mcs_op_statistics[op].max;
36305 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
36306 count ? total / count : 0, max);
36307 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
36308 index 5c3ce24..4915ccb 100644
36309 --- a/drivers/misc/sgi-gru/grutables.h
36310 +++ b/drivers/misc/sgi-gru/grutables.h
36311 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
36312 * GRU statistics.
36313 */
36314 struct gru_stats_s {
36315 - atomic_long_t vdata_alloc;
36316 - atomic_long_t vdata_free;
36317 - atomic_long_t gts_alloc;
36318 - atomic_long_t gts_free;
36319 - atomic_long_t gms_alloc;
36320 - atomic_long_t gms_free;
36321 - atomic_long_t gts_double_allocate;
36322 - atomic_long_t assign_context;
36323 - atomic_long_t assign_context_failed;
36324 - atomic_long_t free_context;
36325 - atomic_long_t load_user_context;
36326 - atomic_long_t load_kernel_context;
36327 - atomic_long_t lock_kernel_context;
36328 - atomic_long_t unlock_kernel_context;
36329 - atomic_long_t steal_user_context;
36330 - atomic_long_t steal_kernel_context;
36331 - atomic_long_t steal_context_failed;
36332 - atomic_long_t nopfn;
36333 - atomic_long_t asid_new;
36334 - atomic_long_t asid_next;
36335 - atomic_long_t asid_wrap;
36336 - atomic_long_t asid_reuse;
36337 - atomic_long_t intr;
36338 - atomic_long_t intr_cbr;
36339 - atomic_long_t intr_tfh;
36340 - atomic_long_t intr_spurious;
36341 - atomic_long_t intr_mm_lock_failed;
36342 - atomic_long_t call_os;
36343 - atomic_long_t call_os_wait_queue;
36344 - atomic_long_t user_flush_tlb;
36345 - atomic_long_t user_unload_context;
36346 - atomic_long_t user_exception;
36347 - atomic_long_t set_context_option;
36348 - atomic_long_t check_context_retarget_intr;
36349 - atomic_long_t check_context_unload;
36350 - atomic_long_t tlb_dropin;
36351 - atomic_long_t tlb_preload_page;
36352 - atomic_long_t tlb_dropin_fail_no_asid;
36353 - atomic_long_t tlb_dropin_fail_upm;
36354 - atomic_long_t tlb_dropin_fail_invalid;
36355 - atomic_long_t tlb_dropin_fail_range_active;
36356 - atomic_long_t tlb_dropin_fail_idle;
36357 - atomic_long_t tlb_dropin_fail_fmm;
36358 - atomic_long_t tlb_dropin_fail_no_exception;
36359 - atomic_long_t tfh_stale_on_fault;
36360 - atomic_long_t mmu_invalidate_range;
36361 - atomic_long_t mmu_invalidate_page;
36362 - atomic_long_t flush_tlb;
36363 - atomic_long_t flush_tlb_gru;
36364 - atomic_long_t flush_tlb_gru_tgh;
36365 - atomic_long_t flush_tlb_gru_zero_asid;
36366 + atomic_long_unchecked_t vdata_alloc;
36367 + atomic_long_unchecked_t vdata_free;
36368 + atomic_long_unchecked_t gts_alloc;
36369 + atomic_long_unchecked_t gts_free;
36370 + atomic_long_unchecked_t gms_alloc;
36371 + atomic_long_unchecked_t gms_free;
36372 + atomic_long_unchecked_t gts_double_allocate;
36373 + atomic_long_unchecked_t assign_context;
36374 + atomic_long_unchecked_t assign_context_failed;
36375 + atomic_long_unchecked_t free_context;
36376 + atomic_long_unchecked_t load_user_context;
36377 + atomic_long_unchecked_t load_kernel_context;
36378 + atomic_long_unchecked_t lock_kernel_context;
36379 + atomic_long_unchecked_t unlock_kernel_context;
36380 + atomic_long_unchecked_t steal_user_context;
36381 + atomic_long_unchecked_t steal_kernel_context;
36382 + atomic_long_unchecked_t steal_context_failed;
36383 + atomic_long_unchecked_t nopfn;
36384 + atomic_long_unchecked_t asid_new;
36385 + atomic_long_unchecked_t asid_next;
36386 + atomic_long_unchecked_t asid_wrap;
36387 + atomic_long_unchecked_t asid_reuse;
36388 + atomic_long_unchecked_t intr;
36389 + atomic_long_unchecked_t intr_cbr;
36390 + atomic_long_unchecked_t intr_tfh;
36391 + atomic_long_unchecked_t intr_spurious;
36392 + atomic_long_unchecked_t intr_mm_lock_failed;
36393 + atomic_long_unchecked_t call_os;
36394 + atomic_long_unchecked_t call_os_wait_queue;
36395 + atomic_long_unchecked_t user_flush_tlb;
36396 + atomic_long_unchecked_t user_unload_context;
36397 + atomic_long_unchecked_t user_exception;
36398 + atomic_long_unchecked_t set_context_option;
36399 + atomic_long_unchecked_t check_context_retarget_intr;
36400 + atomic_long_unchecked_t check_context_unload;
36401 + atomic_long_unchecked_t tlb_dropin;
36402 + atomic_long_unchecked_t tlb_preload_page;
36403 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
36404 + atomic_long_unchecked_t tlb_dropin_fail_upm;
36405 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
36406 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
36407 + atomic_long_unchecked_t tlb_dropin_fail_idle;
36408 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
36409 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
36410 + atomic_long_unchecked_t tfh_stale_on_fault;
36411 + atomic_long_unchecked_t mmu_invalidate_range;
36412 + atomic_long_unchecked_t mmu_invalidate_page;
36413 + atomic_long_unchecked_t flush_tlb;
36414 + atomic_long_unchecked_t flush_tlb_gru;
36415 + atomic_long_unchecked_t flush_tlb_gru_tgh;
36416 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
36417
36418 - atomic_long_t copy_gpa;
36419 - atomic_long_t read_gpa;
36420 + atomic_long_unchecked_t copy_gpa;
36421 + atomic_long_unchecked_t read_gpa;
36422
36423 - atomic_long_t mesq_receive;
36424 - atomic_long_t mesq_receive_none;
36425 - atomic_long_t mesq_send;
36426 - atomic_long_t mesq_send_failed;
36427 - atomic_long_t mesq_noop;
36428 - atomic_long_t mesq_send_unexpected_error;
36429 - atomic_long_t mesq_send_lb_overflow;
36430 - atomic_long_t mesq_send_qlimit_reached;
36431 - atomic_long_t mesq_send_amo_nacked;
36432 - atomic_long_t mesq_send_put_nacked;
36433 - atomic_long_t mesq_page_overflow;
36434 - atomic_long_t mesq_qf_locked;
36435 - atomic_long_t mesq_qf_noop_not_full;
36436 - atomic_long_t mesq_qf_switch_head_failed;
36437 - atomic_long_t mesq_qf_unexpected_error;
36438 - atomic_long_t mesq_noop_unexpected_error;
36439 - atomic_long_t mesq_noop_lb_overflow;
36440 - atomic_long_t mesq_noop_qlimit_reached;
36441 - atomic_long_t mesq_noop_amo_nacked;
36442 - atomic_long_t mesq_noop_put_nacked;
36443 - atomic_long_t mesq_noop_page_overflow;
36444 + atomic_long_unchecked_t mesq_receive;
36445 + atomic_long_unchecked_t mesq_receive_none;
36446 + atomic_long_unchecked_t mesq_send;
36447 + atomic_long_unchecked_t mesq_send_failed;
36448 + atomic_long_unchecked_t mesq_noop;
36449 + atomic_long_unchecked_t mesq_send_unexpected_error;
36450 + atomic_long_unchecked_t mesq_send_lb_overflow;
36451 + atomic_long_unchecked_t mesq_send_qlimit_reached;
36452 + atomic_long_unchecked_t mesq_send_amo_nacked;
36453 + atomic_long_unchecked_t mesq_send_put_nacked;
36454 + atomic_long_unchecked_t mesq_page_overflow;
36455 + atomic_long_unchecked_t mesq_qf_locked;
36456 + atomic_long_unchecked_t mesq_qf_noop_not_full;
36457 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
36458 + atomic_long_unchecked_t mesq_qf_unexpected_error;
36459 + atomic_long_unchecked_t mesq_noop_unexpected_error;
36460 + atomic_long_unchecked_t mesq_noop_lb_overflow;
36461 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
36462 + atomic_long_unchecked_t mesq_noop_amo_nacked;
36463 + atomic_long_unchecked_t mesq_noop_put_nacked;
36464 + atomic_long_unchecked_t mesq_noop_page_overflow;
36465
36466 };
36467
36468 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
36469 tghop_invalidate, mcsop_last};
36470
36471 struct mcs_op_statistic {
36472 - atomic_long_t count;
36473 - atomic_long_t total;
36474 + atomic_long_unchecked_t count;
36475 + atomic_long_unchecked_t total;
36476 unsigned long max;
36477 };
36478
36479 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
36480
36481 #define STAT(id) do { \
36482 if (gru_options & OPT_STATS) \
36483 - atomic_long_inc(&gru_stats.id); \
36484 + atomic_long_inc_unchecked(&gru_stats.id); \
36485 } while (0)
36486
36487 #ifdef CONFIG_SGI_GRU_DEBUG
36488 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
36489 index c862cd4..0d176fe 100644
36490 --- a/drivers/misc/sgi-xp/xp.h
36491 +++ b/drivers/misc/sgi-xp/xp.h
36492 @@ -288,7 +288,7 @@ struct xpc_interface {
36493 xpc_notify_func, void *);
36494 void (*received) (short, int, void *);
36495 enum xp_retval (*partid_to_nasids) (short, void *);
36496 -};
36497 +} __no_const;
36498
36499 extern struct xpc_interface xpc_interface;
36500
36501 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
36502 index b94d5f7..7f494c5 100644
36503 --- a/drivers/misc/sgi-xp/xpc.h
36504 +++ b/drivers/misc/sgi-xp/xpc.h
36505 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
36506 void (*received_payload) (struct xpc_channel *, void *);
36507 void (*notify_senders_of_disconnect) (struct xpc_channel *);
36508 };
36509 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
36510
36511 /* struct xpc_partition act_state values (for XPC HB) */
36512
36513 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
36514 /* found in xpc_main.c */
36515 extern struct device *xpc_part;
36516 extern struct device *xpc_chan;
36517 -extern struct xpc_arch_operations xpc_arch_ops;
36518 +extern xpc_arch_operations_no_const xpc_arch_ops;
36519 extern int xpc_disengage_timelimit;
36520 extern int xpc_disengage_timedout;
36521 extern int xpc_activate_IRQ_rcvd;
36522 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
36523 index d971817..33bdca5 100644
36524 --- a/drivers/misc/sgi-xp/xpc_main.c
36525 +++ b/drivers/misc/sgi-xp/xpc_main.c
36526 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
36527 .notifier_call = xpc_system_die,
36528 };
36529
36530 -struct xpc_arch_operations xpc_arch_ops;
36531 +xpc_arch_operations_no_const xpc_arch_ops;
36532
36533 /*
36534 * Timer function to enforce the timelimit on the partition disengage.
36535 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
36536
36537 if (((die_args->trapnr == X86_TRAP_MF) ||
36538 (die_args->trapnr == X86_TRAP_XF)) &&
36539 - !user_mode_vm(die_args->regs))
36540 + !user_mode(die_args->regs))
36541 xpc_die_deactivate();
36542
36543 break;
36544 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
36545 index a0e1720..ee63d0b 100644
36546 --- a/drivers/mmc/core/mmc_ops.c
36547 +++ b/drivers/mmc/core/mmc_ops.c
36548 @@ -245,7 +245,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
36549 void *data_buf;
36550 int is_on_stack;
36551
36552 - is_on_stack = object_is_on_stack(buf);
36553 + is_on_stack = object_starts_on_stack(buf);
36554 if (is_on_stack) {
36555 /*
36556 * dma onto stack is unsafe/nonportable, but callers to this
36557 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
36558 index 53b8fd9..615b462 100644
36559 --- a/drivers/mmc/host/dw_mmc.h
36560 +++ b/drivers/mmc/host/dw_mmc.h
36561 @@ -205,5 +205,5 @@ struct dw_mci_drv_data {
36562 int (*parse_dt)(struct dw_mci *host);
36563 int (*setup_bus)(struct dw_mci *host,
36564 struct device_node *slot_np, u8 bus_width);
36565 -};
36566 +} __do_const;
36567 #endif /* _DW_MMC_H_ */
36568 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
36569 index c9ec725..178e79a 100644
36570 --- a/drivers/mmc/host/sdhci-s3c.c
36571 +++ b/drivers/mmc/host/sdhci-s3c.c
36572 @@ -719,9 +719,11 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
36573 * we can use overriding functions instead of default.
36574 */
36575 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
36576 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
36577 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
36578 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
36579 + pax_open_kernel();
36580 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
36581 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
36582 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
36583 + pax_close_kernel();
36584 }
36585
36586 /* It supports additional host capabilities if needed */
36587 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
36588 index a4eb8b5..8c0628f 100644
36589 --- a/drivers/mtd/devices/doc2000.c
36590 +++ b/drivers/mtd/devices/doc2000.c
36591 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
36592
36593 /* The ECC will not be calculated correctly if less than 512 is written */
36594 /* DBB-
36595 - if (len != 0x200 && eccbuf)
36596 + if (len != 0x200)
36597 printk(KERN_WARNING
36598 "ECC needs a full sector write (adr: %lx size %lx)\n",
36599 (long) to, (long) len);
36600 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
36601 index e706a23..b3d262f 100644
36602 --- a/drivers/mtd/nand/denali.c
36603 +++ b/drivers/mtd/nand/denali.c
36604 @@ -26,6 +26,7 @@
36605 #include <linux/pci.h>
36606 #include <linux/mtd/mtd.h>
36607 #include <linux/module.h>
36608 +#include <linux/slab.h>
36609
36610 #include "denali.h"
36611
36612 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
36613 index 51b9d6a..52af9a7 100644
36614 --- a/drivers/mtd/nftlmount.c
36615 +++ b/drivers/mtd/nftlmount.c
36616 @@ -24,6 +24,7 @@
36617 #include <asm/errno.h>
36618 #include <linux/delay.h>
36619 #include <linux/slab.h>
36620 +#include <linux/sched.h>
36621 #include <linux/mtd/mtd.h>
36622 #include <linux/mtd/nand.h>
36623 #include <linux/mtd/nftl.h>
36624 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
36625 index 203ff9d..0968ca8 100644
36626 --- a/drivers/net/ethernet/8390/ax88796.c
36627 +++ b/drivers/net/ethernet/8390/ax88796.c
36628 @@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
36629 if (ax->plat->reg_offsets)
36630 ei_local->reg_offset = ax->plat->reg_offsets;
36631 else {
36632 + resource_size_t _mem_size = mem_size;
36633 + do_div(_mem_size, 0x18);
36634 ei_local->reg_offset = ax->reg_offsets;
36635 for (ret = 0; ret < 0x18; ret++)
36636 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
36637 + ax->reg_offsets[ret] = _mem_size * ret;
36638 }
36639
36640 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
36641 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36642 index 9c5ea6c..eaad276 100644
36643 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36644 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36645 @@ -1046,7 +1046,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
36646 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
36647 {
36648 /* RX_MODE controlling object */
36649 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
36650 + bnx2x_init_rx_mode_obj(bp);
36651
36652 /* multicast configuration controlling object */
36653 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
36654 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36655 index 614981c..11216c7 100644
36656 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36657 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36658 @@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
36659 return rc;
36660 }
36661
36662 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36663 - struct bnx2x_rx_mode_obj *o)
36664 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
36665 {
36666 if (CHIP_IS_E1x(bp)) {
36667 - o->wait_comp = bnx2x_empty_rx_mode_wait;
36668 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
36669 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
36670 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
36671 } else {
36672 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
36673 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
36674 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
36675 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
36676 }
36677 }
36678
36679 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36680 index acf2fe4..efb96df 100644
36681 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36682 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36683 @@ -1281,8 +1281,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
36684
36685 /********************* RX MODE ****************/
36686
36687 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36688 - struct bnx2x_rx_mode_obj *o);
36689 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
36690
36691 /**
36692 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
36693 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
36694 index d9308c32..d87b824 100644
36695 --- a/drivers/net/ethernet/broadcom/tg3.h
36696 +++ b/drivers/net/ethernet/broadcom/tg3.h
36697 @@ -140,6 +140,7 @@
36698 #define CHIPREV_ID_5750_A0 0x4000
36699 #define CHIPREV_ID_5750_A1 0x4001
36700 #define CHIPREV_ID_5750_A3 0x4003
36701 +#define CHIPREV_ID_5750_C1 0x4201
36702 #define CHIPREV_ID_5750_C2 0x4202
36703 #define CHIPREV_ID_5752_A0_HW 0x5000
36704 #define CHIPREV_ID_5752_A0 0x6000
36705 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36706 index 8cffcdf..aadf043 100644
36707 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36708 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36709 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
36710 */
36711 struct l2t_skb_cb {
36712 arp_failure_handler_func arp_failure_handler;
36713 -};
36714 +} __no_const;
36715
36716 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
36717
36718 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
36719 index f879e92..726f20f 100644
36720 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
36721 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
36722 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36723 for (i=0; i<ETH_ALEN; i++) {
36724 tmp.addr[i] = dev->dev_addr[i];
36725 }
36726 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36727 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36728 break;
36729
36730 case DE4X5_SET_HWADDR: /* Set the hardware address */
36731 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36732 spin_lock_irqsave(&lp->lock, flags);
36733 memcpy(&statbuf, &lp->pktStats, ioc->len);
36734 spin_unlock_irqrestore(&lp->lock, flags);
36735 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
36736 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
36737 return -EFAULT;
36738 break;
36739 }
36740 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
36741 index d1b6cc5..cde0d97 100644
36742 --- a/drivers/net/ethernet/emulex/benet/be_main.c
36743 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
36744 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
36745
36746 if (wrapped)
36747 newacc += 65536;
36748 - ACCESS_ONCE(*acc) = newacc;
36749 + ACCESS_ONCE_RW(*acc) = newacc;
36750 }
36751
36752 void be_parse_stats(struct be_adapter *adapter)
36753 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
36754 index 74d749e..eefb1bd 100644
36755 --- a/drivers/net/ethernet/faraday/ftgmac100.c
36756 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
36757 @@ -31,6 +31,8 @@
36758 #include <linux/netdevice.h>
36759 #include <linux/phy.h>
36760 #include <linux/platform_device.h>
36761 +#include <linux/interrupt.h>
36762 +#include <linux/irqreturn.h>
36763 #include <net/ip.h>
36764
36765 #include "ftgmac100.h"
36766 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
36767 index b901a01..1ff32ee 100644
36768 --- a/drivers/net/ethernet/faraday/ftmac100.c
36769 +++ b/drivers/net/ethernet/faraday/ftmac100.c
36770 @@ -31,6 +31,8 @@
36771 #include <linux/module.h>
36772 #include <linux/netdevice.h>
36773 #include <linux/platform_device.h>
36774 +#include <linux/interrupt.h>
36775 +#include <linux/irqreturn.h>
36776
36777 #include "ftmac100.h"
36778
36779 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36780 index d929131..aed108f 100644
36781 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36782 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36783 @@ -865,7 +865,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
36784 /* store the new cycle speed */
36785 adapter->cycle_speed = cycle_speed;
36786
36787 - ACCESS_ONCE(adapter->base_incval) = incval;
36788 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
36789 smp_mb();
36790
36791 /* grab the ptp lock */
36792 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36793 index c2e420a..26a75e0 100644
36794 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
36795 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36796 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36797 struct __vxge_hw_fifo *fifo;
36798 struct vxge_hw_fifo_config *config;
36799 u32 txdl_size, txdl_per_memblock;
36800 - struct vxge_hw_mempool_cbs fifo_mp_callback;
36801 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
36802 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
36803 + };
36804 +
36805 struct __vxge_hw_virtualpath *vpath;
36806
36807 if ((vp == NULL) || (attr == NULL)) {
36808 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36809 goto exit;
36810 }
36811
36812 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
36813 -
36814 fifo->mempool =
36815 __vxge_hw_mempool_create(vpath->hldev,
36816 fifo->config->memblock_size,
36817 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
36818 index 6afe74e..2e2950f 100644
36819 --- a/drivers/net/ethernet/realtek/r8169.c
36820 +++ b/drivers/net/ethernet/realtek/r8169.c
36821 @@ -747,22 +747,22 @@ struct rtl8169_private {
36822 struct mdio_ops {
36823 void (*write)(struct rtl8169_private *, int, int);
36824 int (*read)(struct rtl8169_private *, int);
36825 - } mdio_ops;
36826 + } __no_const mdio_ops;
36827
36828 struct pll_power_ops {
36829 void (*down)(struct rtl8169_private *);
36830 void (*up)(struct rtl8169_private *);
36831 - } pll_power_ops;
36832 + } __no_const pll_power_ops;
36833
36834 struct jumbo_ops {
36835 void (*enable)(struct rtl8169_private *);
36836 void (*disable)(struct rtl8169_private *);
36837 - } jumbo_ops;
36838 + } __no_const jumbo_ops;
36839
36840 struct csi_ops {
36841 void (*write)(struct rtl8169_private *, int, int);
36842 u32 (*read)(struct rtl8169_private *, int);
36843 - } csi_ops;
36844 + } __no_const csi_ops;
36845
36846 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
36847 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
36848 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
36849 index 0767043f..08c2553 100644
36850 --- a/drivers/net/ethernet/sfc/ptp.c
36851 +++ b/drivers/net/ethernet/sfc/ptp.c
36852 @@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
36853 (u32)((u64)ptp->start.dma_addr >> 32));
36854
36855 /* Clear flag that signals MC ready */
36856 - ACCESS_ONCE(*start) = 0;
36857 + ACCESS_ONCE_RW(*start) = 0;
36858 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
36859 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
36860
36861 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36862 index 0c74a70..3bc6f68 100644
36863 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36864 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36865 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
36866
36867 writel(value, ioaddr + MMC_CNTRL);
36868
36869 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36870 - MMC_CNTRL, value);
36871 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36872 +// MMC_CNTRL, value);
36873 }
36874
36875 /* To mask all all interrupts.*/
36876 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
36877 index 5fd6f46..ee1f265 100644
36878 --- a/drivers/net/hyperv/hyperv_net.h
36879 +++ b/drivers/net/hyperv/hyperv_net.h
36880 @@ -101,7 +101,7 @@ struct rndis_device {
36881
36882 enum rndis_device_state state;
36883 bool link_state;
36884 - atomic_t new_req_id;
36885 + atomic_unchecked_t new_req_id;
36886
36887 spinlock_t request_lock;
36888 struct list_head req_list;
36889 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
36890 index 928148c..d83298e 100644
36891 --- a/drivers/net/hyperv/rndis_filter.c
36892 +++ b/drivers/net/hyperv/rndis_filter.c
36893 @@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
36894 * template
36895 */
36896 set = &rndis_msg->msg.set_req;
36897 - set->req_id = atomic_inc_return(&dev->new_req_id);
36898 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36899
36900 /* Add to the request list */
36901 spin_lock_irqsave(&dev->request_lock, flags);
36902 @@ -760,7 +760,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
36903
36904 /* Setup the rndis set */
36905 halt = &request->request_msg.msg.halt_req;
36906 - halt->req_id = atomic_inc_return(&dev->new_req_id);
36907 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36908
36909 /* Ignore return since this msg is optional. */
36910 rndis_filter_send_request(dev, request);
36911 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
36912 index 7d39add..037e1da 100644
36913 --- a/drivers/net/ieee802154/fakehard.c
36914 +++ b/drivers/net/ieee802154/fakehard.c
36915 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
36916 phy->transmit_power = 0xbf;
36917
36918 dev->netdev_ops = &fake_ops;
36919 - dev->ml_priv = &fake_mlme;
36920 + dev->ml_priv = (void *)&fake_mlme;
36921
36922 priv = netdev_priv(dev);
36923 priv->phy = phy;
36924 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
36925 index 0f0f9ce..0ca5819 100644
36926 --- a/drivers/net/macvtap.c
36927 +++ b/drivers/net/macvtap.c
36928 @@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
36929 return NOTIFY_DONE;
36930 }
36931
36932 -static struct notifier_block macvtap_notifier_block __read_mostly = {
36933 +static struct notifier_block macvtap_notifier_block = {
36934 .notifier_call = macvtap_device_event,
36935 };
36936
36937 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
36938 index daec9b0..6428fcb 100644
36939 --- a/drivers/net/phy/mdio-bitbang.c
36940 +++ b/drivers/net/phy/mdio-bitbang.c
36941 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
36942 struct mdiobb_ctrl *ctrl = bus->priv;
36943
36944 module_put(ctrl->ops->owner);
36945 + mdiobus_unregister(bus);
36946 mdiobus_free(bus);
36947 }
36948 EXPORT_SYMBOL(free_mdio_bitbang);
36949 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
36950 index eb3f5ce..d773730 100644
36951 --- a/drivers/net/ppp/ppp_generic.c
36952 +++ b/drivers/net/ppp/ppp_generic.c
36953 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36954 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
36955 struct ppp_stats stats;
36956 struct ppp_comp_stats cstats;
36957 - char *vers;
36958
36959 switch (cmd) {
36960 case SIOCGPPPSTATS:
36961 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36962 break;
36963
36964 case SIOCGPPPVER:
36965 - vers = PPP_VERSION;
36966 - if (copy_to_user(addr, vers, strlen(vers) + 1))
36967 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
36968 break;
36969 err = 0;
36970 break;
36971 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
36972 index ad86660..9fd0884 100644
36973 --- a/drivers/net/team/team.c
36974 +++ b/drivers/net/team/team.c
36975 @@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
36976 return NOTIFY_DONE;
36977 }
36978
36979 -static struct notifier_block team_notifier_block __read_mostly = {
36980 +static struct notifier_block team_notifier_block = {
36981 .notifier_call = team_device_event,
36982 };
36983
36984 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
36985 index 0873cdc..ddb178e 100644
36986 --- a/drivers/net/tun.c
36987 +++ b/drivers/net/tun.c
36988 @@ -1374,7 +1374,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
36989 }
36990
36991 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36992 - unsigned long arg, int ifreq_len)
36993 + unsigned long arg, size_t ifreq_len)
36994 {
36995 struct tun_file *tfile = file->private_data;
36996 struct tun_struct *tun;
36997 @@ -1387,6 +1387,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36998 int vnet_hdr_sz;
36999 int ret;
37000
37001 + if (ifreq_len > sizeof ifr)
37002 + return -EFAULT;
37003 +
37004 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
37005 if (copy_from_user(&ifr, argp, ifreq_len))
37006 return -EFAULT;
37007 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
37008 index 605a4ba..a883dd1 100644
37009 --- a/drivers/net/usb/hso.c
37010 +++ b/drivers/net/usb/hso.c
37011 @@ -71,7 +71,7 @@
37012 #include <asm/byteorder.h>
37013 #include <linux/serial_core.h>
37014 #include <linux/serial.h>
37015 -
37016 +#include <asm/local.h>
37017
37018 #define MOD_AUTHOR "Option Wireless"
37019 #define MOD_DESCRIPTION "USB High Speed Option driver"
37020 @@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
37021 struct urb *urb;
37022
37023 urb = serial->rx_urb[0];
37024 - if (serial->port.count > 0) {
37025 + if (atomic_read(&serial->port.count) > 0) {
37026 count = put_rxbuf_data(urb, serial);
37027 if (count == -1)
37028 return;
37029 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
37030 DUMP1(urb->transfer_buffer, urb->actual_length);
37031
37032 /* Anyone listening? */
37033 - if (serial->port.count == 0)
37034 + if (atomic_read(&serial->port.count) == 0)
37035 return;
37036
37037 if (status == 0) {
37038 @@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37039 tty_port_tty_set(&serial->port, tty);
37040
37041 /* check for port already opened, if not set the termios */
37042 - serial->port.count++;
37043 - if (serial->port.count == 1) {
37044 + if (atomic_inc_return(&serial->port.count) == 1) {
37045 serial->rx_state = RX_IDLE;
37046 /* Force default termio settings */
37047 _hso_serial_set_termios(tty, NULL);
37048 @@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37049 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
37050 if (result) {
37051 hso_stop_serial_device(serial->parent);
37052 - serial->port.count--;
37053 + atomic_dec(&serial->port.count);
37054 kref_put(&serial->parent->ref, hso_serial_ref_free);
37055 }
37056 } else {
37057 @@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
37058
37059 /* reset the rts and dtr */
37060 /* do the actual close */
37061 - serial->port.count--;
37062 + atomic_dec(&serial->port.count);
37063
37064 - if (serial->port.count <= 0) {
37065 - serial->port.count = 0;
37066 + if (atomic_read(&serial->port.count) <= 0) {
37067 + atomic_set(&serial->port.count, 0);
37068 tty_port_tty_set(&serial->port, NULL);
37069 if (!usb_gone)
37070 hso_stop_serial_device(serial->parent);
37071 @@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
37072
37073 /* the actual setup */
37074 spin_lock_irqsave(&serial->serial_lock, flags);
37075 - if (serial->port.count)
37076 + if (atomic_read(&serial->port.count))
37077 _hso_serial_set_termios(tty, old);
37078 else
37079 tty->termios = *old;
37080 @@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
37081 D1("Pending read interrupt on port %d\n", i);
37082 spin_lock(&serial->serial_lock);
37083 if (serial->rx_state == RX_IDLE &&
37084 - serial->port.count > 0) {
37085 + atomic_read(&serial->port.count) > 0) {
37086 /* Setup and send a ctrl req read on
37087 * port i */
37088 if (!serial->rx_urb_filled[0]) {
37089 @@ -3078,7 +3077,7 @@ static int hso_resume(struct usb_interface *iface)
37090 /* Start all serial ports */
37091 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
37092 if (serial_table[i] && (serial_table[i]->interface == iface)) {
37093 - if (dev2ser(serial_table[i])->port.count) {
37094 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
37095 result =
37096 hso_start_serial_device(serial_table[i], GFP_NOIO);
37097 hso_kick_transmit(dev2ser(serial_table[i]));
37098 diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
37099 index edb81ed..ab8931c 100644
37100 --- a/drivers/net/usb/usbnet.c
37101 +++ b/drivers/net/usb/usbnet.c
37102 @@ -380,6 +380,12 @@ static int rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
37103 unsigned long lockflags;
37104 size_t size = dev->rx_urb_size;
37105
37106 + /* prevent rx skb allocation when error ratio is high */
37107 + if (test_bit(EVENT_RX_KILL, &dev->flags)) {
37108 + usb_free_urb(urb);
37109 + return -ENOLINK;
37110 + }
37111 +
37112 skb = __netdev_alloc_skb_ip_align(dev->net, size, flags);
37113 if (!skb) {
37114 netif_dbg(dev, rx_err, dev->net, "no rx skb\n");
37115 @@ -539,6 +545,17 @@ block:
37116 break;
37117 }
37118
37119 + /* stop rx if packet error rate is high */
37120 + if (++dev->pkt_cnt > 30) {
37121 + dev->pkt_cnt = 0;
37122 + dev->pkt_err = 0;
37123 + } else {
37124 + if (state == rx_cleanup)
37125 + dev->pkt_err++;
37126 + if (dev->pkt_err > 20)
37127 + set_bit(EVENT_RX_KILL, &dev->flags);
37128 + }
37129 +
37130 state = defer_bh(dev, skb, &dev->rxq, state);
37131
37132 if (urb) {
37133 @@ -790,6 +807,11 @@ int usbnet_open (struct net_device *net)
37134 (dev->driver_info->flags & FLAG_FRAMING_AX) ? "ASIX" :
37135 "simple");
37136
37137 + /* reset rx error state */
37138 + dev->pkt_cnt = 0;
37139 + dev->pkt_err = 0;
37140 + clear_bit(EVENT_RX_KILL, &dev->flags);
37141 +
37142 // delay posting reads until we're fully open
37143 tasklet_schedule (&dev->bh);
37144 if (info->manage_power) {
37145 @@ -1253,6 +1275,9 @@ static void usbnet_bh (unsigned long param)
37146 }
37147 }
37148
37149 + /* restart RX again after disabling due to high error rate */
37150 + clear_bit(EVENT_RX_KILL, &dev->flags);
37151 +
37152 // waiting for all pending urbs to complete?
37153 if (dev->wait) {
37154 if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
37155 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37156 index 8d78253..bebbb68 100644
37157 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37158 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37159 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37160 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
37161 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
37162
37163 - ACCESS_ONCE(ads->ds_link) = i->link;
37164 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
37165 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
37166 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
37167
37168 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
37169 ctl6 = SM(i->keytype, AR_EncrType);
37170 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37171
37172 if ((i->is_first || i->is_last) &&
37173 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
37174 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
37175 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
37176 | set11nTries(i->rates, 1)
37177 | set11nTries(i->rates, 2)
37178 | set11nTries(i->rates, 3)
37179 | (i->dur_update ? AR_DurUpdateEna : 0)
37180 | SM(0, AR_BurstDur);
37181
37182 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
37183 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
37184 | set11nRate(i->rates, 1)
37185 | set11nRate(i->rates, 2)
37186 | set11nRate(i->rates, 3);
37187 } else {
37188 - ACCESS_ONCE(ads->ds_ctl2) = 0;
37189 - ACCESS_ONCE(ads->ds_ctl3) = 0;
37190 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
37191 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
37192 }
37193
37194 if (!i->is_first) {
37195 - ACCESS_ONCE(ads->ds_ctl0) = 0;
37196 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37197 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37198 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
37199 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37200 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37201 return;
37202 }
37203
37204 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37205 break;
37206 }
37207
37208 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37209 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37210 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37211 | SM(i->txpower, AR_XmitPower)
37212 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37213 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37214 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
37215 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
37216
37217 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37218 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37219 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37220 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37221
37222 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
37223 return;
37224
37225 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37226 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37227 | set11nPktDurRTSCTS(i->rates, 1);
37228
37229 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37230 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37231 | set11nPktDurRTSCTS(i->rates, 3);
37232
37233 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37234 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37235 | set11nRateFlags(i->rates, 1)
37236 | set11nRateFlags(i->rates, 2)
37237 | set11nRateFlags(i->rates, 3)
37238 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37239 index 301bf72..3f5654f 100644
37240 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37241 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37242 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37243 (i->qcu << AR_TxQcuNum_S) | desc_len;
37244
37245 checksum += val;
37246 - ACCESS_ONCE(ads->info) = val;
37247 + ACCESS_ONCE_RW(ads->info) = val;
37248
37249 checksum += i->link;
37250 - ACCESS_ONCE(ads->link) = i->link;
37251 + ACCESS_ONCE_RW(ads->link) = i->link;
37252
37253 checksum += i->buf_addr[0];
37254 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
37255 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
37256 checksum += i->buf_addr[1];
37257 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
37258 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
37259 checksum += i->buf_addr[2];
37260 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
37261 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
37262 checksum += i->buf_addr[3];
37263 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
37264 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
37265
37266 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
37267 - ACCESS_ONCE(ads->ctl3) = val;
37268 + ACCESS_ONCE_RW(ads->ctl3) = val;
37269 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
37270 - ACCESS_ONCE(ads->ctl5) = val;
37271 + ACCESS_ONCE_RW(ads->ctl5) = val;
37272 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
37273 - ACCESS_ONCE(ads->ctl7) = val;
37274 + ACCESS_ONCE_RW(ads->ctl7) = val;
37275 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
37276 - ACCESS_ONCE(ads->ctl9) = val;
37277 + ACCESS_ONCE_RW(ads->ctl9) = val;
37278
37279 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
37280 - ACCESS_ONCE(ads->ctl10) = checksum;
37281 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
37282
37283 if (i->is_first || i->is_last) {
37284 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
37285 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
37286 | set11nTries(i->rates, 1)
37287 | set11nTries(i->rates, 2)
37288 | set11nTries(i->rates, 3)
37289 | (i->dur_update ? AR_DurUpdateEna : 0)
37290 | SM(0, AR_BurstDur);
37291
37292 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
37293 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
37294 | set11nRate(i->rates, 1)
37295 | set11nRate(i->rates, 2)
37296 | set11nRate(i->rates, 3);
37297 } else {
37298 - ACCESS_ONCE(ads->ctl13) = 0;
37299 - ACCESS_ONCE(ads->ctl14) = 0;
37300 + ACCESS_ONCE_RW(ads->ctl13) = 0;
37301 + ACCESS_ONCE_RW(ads->ctl14) = 0;
37302 }
37303
37304 ads->ctl20 = 0;
37305 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37306
37307 ctl17 = SM(i->keytype, AR_EncrType);
37308 if (!i->is_first) {
37309 - ACCESS_ONCE(ads->ctl11) = 0;
37310 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37311 - ACCESS_ONCE(ads->ctl15) = 0;
37312 - ACCESS_ONCE(ads->ctl16) = 0;
37313 - ACCESS_ONCE(ads->ctl17) = ctl17;
37314 - ACCESS_ONCE(ads->ctl18) = 0;
37315 - ACCESS_ONCE(ads->ctl19) = 0;
37316 + ACCESS_ONCE_RW(ads->ctl11) = 0;
37317 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37318 + ACCESS_ONCE_RW(ads->ctl15) = 0;
37319 + ACCESS_ONCE_RW(ads->ctl16) = 0;
37320 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37321 + ACCESS_ONCE_RW(ads->ctl18) = 0;
37322 + ACCESS_ONCE_RW(ads->ctl19) = 0;
37323 return;
37324 }
37325
37326 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37327 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37328 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37329 | SM(i->txpower, AR_XmitPower)
37330 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37331 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37332 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
37333 ctl12 |= SM(val, AR_PAPRDChainMask);
37334
37335 - ACCESS_ONCE(ads->ctl12) = ctl12;
37336 - ACCESS_ONCE(ads->ctl17) = ctl17;
37337 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
37338 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37339
37340 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37341 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37342 | set11nPktDurRTSCTS(i->rates, 1);
37343
37344 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37345 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37346 | set11nPktDurRTSCTS(i->rates, 3);
37347
37348 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
37349 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
37350 | set11nRateFlags(i->rates, 1)
37351 | set11nRateFlags(i->rates, 2)
37352 | set11nRateFlags(i->rates, 3)
37353 | SM(i->rtscts_rate, AR_RTSCTSRate);
37354
37355 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
37356 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
37357 }
37358
37359 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
37360 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
37361 index b68aaf5..fb20845 100644
37362 --- a/drivers/net/wireless/ath/ath9k/hw.h
37363 +++ b/drivers/net/wireless/ath/ath9k/hw.h
37364 @@ -657,7 +657,7 @@ struct ath_hw_private_ops {
37365
37366 /* ANI */
37367 void (*ani_cache_ini_regs)(struct ath_hw *ah);
37368 -};
37369 +} __no_const;
37370
37371 /**
37372 * struct ath_hw_ops - callbacks used by hardware code and driver code
37373 @@ -687,7 +687,7 @@ struct ath_hw_ops {
37374 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
37375 struct ath_hw_antcomb_conf *antconf);
37376 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
37377 -};
37378 +} __no_const;
37379
37380 struct ath_nf_limits {
37381 s16 max;
37382 diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37383 index 71ced17..cd82b12 100644
37384 --- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37385 +++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37386 @@ -184,7 +184,7 @@ struct brcmf_cfg80211_event_loop {
37387 struct net_device *ndev,
37388 const struct brcmf_event_msg *e,
37389 void *data);
37390 -};
37391 +} __no_const;
37392
37393 /* basic structure of scan request */
37394 struct brcmf_cfg80211_scan_req {
37395 @@ -239,7 +239,7 @@ struct brcmf_cfg80211_profile {
37396 struct brcmf_cfg80211_iscan_eloop {
37397 s32 (*handler[WL_SCAN_ERSULTS_LAST])
37398 (struct brcmf_cfg80211_info *cfg);
37399 -};
37400 +} __no_const;
37401
37402 /* dongle iscan controller */
37403 struct brcmf_cfg80211_iscan_ctrl {
37404 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
37405 index e252acb..6ad1e65 100644
37406 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
37407 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
37408 @@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
37409 */
37410 if (il3945_mod_params.disable_hw_scan) {
37411 D_INFO("Disabling hw_scan\n");
37412 - il3945_mac_ops.hw_scan = NULL;
37413 + pax_open_kernel();
37414 + *(void **)&il3945_mac_ops.hw_scan = NULL;
37415 + pax_close_kernel();
37416 }
37417
37418 D_INFO("*** LOAD DRIVER ***\n");
37419 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37420 index 1a98fa3..51e6661 100644
37421 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37422 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37423 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
37424 {
37425 struct iwl_priv *priv = file->private_data;
37426 char buf[64];
37427 - int buf_size;
37428 + size_t buf_size;
37429 u32 offset, len;
37430
37431 memset(buf, 0, sizeof(buf));
37432 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
37433 struct iwl_priv *priv = file->private_data;
37434
37435 char buf[8];
37436 - int buf_size;
37437 + size_t buf_size;
37438 u32 reset_flag;
37439
37440 memset(buf, 0, sizeof(buf));
37441 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
37442 {
37443 struct iwl_priv *priv = file->private_data;
37444 char buf[8];
37445 - int buf_size;
37446 + size_t buf_size;
37447 int ht40;
37448
37449 memset(buf, 0, sizeof(buf));
37450 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
37451 {
37452 struct iwl_priv *priv = file->private_data;
37453 char buf[8];
37454 - int buf_size;
37455 + size_t buf_size;
37456 int value;
37457
37458 memset(buf, 0, sizeof(buf));
37459 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
37460 {
37461 struct iwl_priv *priv = file->private_data;
37462 char buf[8];
37463 - int buf_size;
37464 + size_t buf_size;
37465 int clear;
37466
37467 memset(buf, 0, sizeof(buf));
37468 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
37469 {
37470 struct iwl_priv *priv = file->private_data;
37471 char buf[8];
37472 - int buf_size;
37473 + size_t buf_size;
37474 int trace;
37475
37476 memset(buf, 0, sizeof(buf));
37477 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
37478 {
37479 struct iwl_priv *priv = file->private_data;
37480 char buf[8];
37481 - int buf_size;
37482 + size_t buf_size;
37483 int missed;
37484
37485 memset(buf, 0, sizeof(buf));
37486 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
37487
37488 struct iwl_priv *priv = file->private_data;
37489 char buf[8];
37490 - int buf_size;
37491 + size_t buf_size;
37492 int plcp;
37493
37494 memset(buf, 0, sizeof(buf));
37495 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
37496
37497 struct iwl_priv *priv = file->private_data;
37498 char buf[8];
37499 - int buf_size;
37500 + size_t buf_size;
37501 int flush;
37502
37503 memset(buf, 0, sizeof(buf));
37504 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
37505
37506 struct iwl_priv *priv = file->private_data;
37507 char buf[8];
37508 - int buf_size;
37509 + size_t buf_size;
37510 int rts;
37511
37512 if (!priv->cfg->ht_params)
37513 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
37514 {
37515 struct iwl_priv *priv = file->private_data;
37516 char buf[8];
37517 - int buf_size;
37518 + size_t buf_size;
37519
37520 memset(buf, 0, sizeof(buf));
37521 buf_size = min(count, sizeof(buf) - 1);
37522 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
37523 struct iwl_priv *priv = file->private_data;
37524 u32 event_log_flag;
37525 char buf[8];
37526 - int buf_size;
37527 + size_t buf_size;
37528
37529 /* check that the interface is up */
37530 if (!iwl_is_ready(priv))
37531 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
37532 struct iwl_priv *priv = file->private_data;
37533 char buf[8];
37534 u32 calib_disabled;
37535 - int buf_size;
37536 + size_t buf_size;
37537
37538 memset(buf, 0, sizeof(buf));
37539 buf_size = min(count, sizeof(buf) - 1);
37540 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
37541 index fe0fffd..b4c5724 100644
37542 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
37543 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
37544 @@ -1967,7 +1967,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
37545 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
37546
37547 char buf[8];
37548 - int buf_size;
37549 + size_t buf_size;
37550 u32 reset_flag;
37551
37552 memset(buf, 0, sizeof(buf));
37553 @@ -1988,7 +1988,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
37554 {
37555 struct iwl_trans *trans = file->private_data;
37556 char buf[8];
37557 - int buf_size;
37558 + size_t buf_size;
37559 int csr;
37560
37561 memset(buf, 0, sizeof(buf));
37562 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
37563 index 429ca32..f86236b 100644
37564 --- a/drivers/net/wireless/mac80211_hwsim.c
37565 +++ b/drivers/net/wireless/mac80211_hwsim.c
37566 @@ -1751,9 +1751,11 @@ static int __init init_mac80211_hwsim(void)
37567 return -EINVAL;
37568
37569 if (fake_hw_scan) {
37570 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
37571 - mac80211_hwsim_ops.sw_scan_start = NULL;
37572 - mac80211_hwsim_ops.sw_scan_complete = NULL;
37573 + pax_open_kernel();
37574 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
37575 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
37576 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
37577 + pax_close_kernel();
37578 }
37579
37580 spin_lock_init(&hwsim_radio_lock);
37581 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
37582 index bd1f0cb..db85ab0 100644
37583 --- a/drivers/net/wireless/rndis_wlan.c
37584 +++ b/drivers/net/wireless/rndis_wlan.c
37585 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
37586
37587 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
37588
37589 - if (rts_threshold < 0 || rts_threshold > 2347)
37590 + if (rts_threshold > 2347)
37591 rts_threshold = 2347;
37592
37593 tmp = cpu_to_le32(rts_threshold);
37594 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
37595 index 0751b35..246ba3e 100644
37596 --- a/drivers/net/wireless/rt2x00/rt2x00.h
37597 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
37598 @@ -398,7 +398,7 @@ struct rt2x00_intf {
37599 * for hardware which doesn't support hardware
37600 * sequence counting.
37601 */
37602 - atomic_t seqno;
37603 + atomic_unchecked_t seqno;
37604 };
37605
37606 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
37607 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
37608 index e488b94..14b6a0c 100644
37609 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
37610 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
37611 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
37612 * sequence counter given by mac80211.
37613 */
37614 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
37615 - seqno = atomic_add_return(0x10, &intf->seqno);
37616 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
37617 else
37618 - seqno = atomic_read(&intf->seqno);
37619 + seqno = atomic_read_unchecked(&intf->seqno);
37620
37621 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
37622 hdr->seq_ctrl |= cpu_to_le16(seqno);
37623 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
37624 index e2750a1..797e179 100644
37625 --- a/drivers/net/wireless/ti/wl1251/sdio.c
37626 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
37627 @@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
37628
37629 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
37630
37631 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37632 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37633 + pax_open_kernel();
37634 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37635 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37636 + pax_close_kernel();
37637
37638 wl1251_info("using dedicated interrupt line");
37639 } else {
37640 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37641 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37642 + pax_open_kernel();
37643 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37644 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37645 + pax_close_kernel();
37646
37647 wl1251_info("using SDIO interrupt");
37648 }
37649 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
37650 index dadf1db..d9db7a7 100644
37651 --- a/drivers/net/wireless/ti/wl12xx/main.c
37652 +++ b/drivers/net/wireless/ti/wl12xx/main.c
37653 @@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37654 sizeof(wl->conf.mem));
37655
37656 /* read data preparation is only needed by wl127x */
37657 - wl->ops->prepare_read = wl127x_prepare_read;
37658 + pax_open_kernel();
37659 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37660 + pax_close_kernel();
37661
37662 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37663 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37664 @@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37665 sizeof(wl->conf.mem));
37666
37667 /* read data preparation is only needed by wl127x */
37668 - wl->ops->prepare_read = wl127x_prepare_read;
37669 + pax_open_kernel();
37670 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37671 + pax_close_kernel();
37672
37673 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37674 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37675 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
37676 index a39682a..1e8220c 100644
37677 --- a/drivers/net/wireless/ti/wl18xx/main.c
37678 +++ b/drivers/net/wireless/ti/wl18xx/main.c
37679 @@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
37680 }
37681
37682 if (!checksum_param) {
37683 - wl18xx_ops.set_rx_csum = NULL;
37684 - wl18xx_ops.init_vif = NULL;
37685 + pax_open_kernel();
37686 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
37687 + *(void **)&wl18xx_ops.init_vif = NULL;
37688 + pax_close_kernel();
37689 }
37690
37691 /* Enable 11a Band only if we have 5G antennas */
37692 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
37693 index d93b2b6..ae50401 100644
37694 --- a/drivers/oprofile/buffer_sync.c
37695 +++ b/drivers/oprofile/buffer_sync.c
37696 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
37697 if (cookie == NO_COOKIE)
37698 offset = pc;
37699 if (cookie == INVALID_COOKIE) {
37700 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37701 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37702 offset = pc;
37703 }
37704 if (cookie != last_cookie) {
37705 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
37706 /* add userspace sample */
37707
37708 if (!mm) {
37709 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
37710 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
37711 return 0;
37712 }
37713
37714 cookie = lookup_dcookie(mm, s->eip, &offset);
37715
37716 if (cookie == INVALID_COOKIE) {
37717 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37718 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37719 return 0;
37720 }
37721
37722 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
37723 /* ignore backtraces if failed to add a sample */
37724 if (state == sb_bt_start) {
37725 state = sb_bt_ignore;
37726 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
37727 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
37728 }
37729 }
37730 release_mm(mm);
37731 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
37732 index c0cc4e7..44d4e54 100644
37733 --- a/drivers/oprofile/event_buffer.c
37734 +++ b/drivers/oprofile/event_buffer.c
37735 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
37736 }
37737
37738 if (buffer_pos == buffer_size) {
37739 - atomic_inc(&oprofile_stats.event_lost_overflow);
37740 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
37741 return;
37742 }
37743
37744 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
37745 index ed2c3ec..deda85a 100644
37746 --- a/drivers/oprofile/oprof.c
37747 +++ b/drivers/oprofile/oprof.c
37748 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
37749 if (oprofile_ops.switch_events())
37750 return;
37751
37752 - atomic_inc(&oprofile_stats.multiplex_counter);
37753 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
37754 start_switch_worker();
37755 }
37756
37757 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
37758 index 917d28e..d62d981 100644
37759 --- a/drivers/oprofile/oprofile_stats.c
37760 +++ b/drivers/oprofile/oprofile_stats.c
37761 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
37762 cpu_buf->sample_invalid_eip = 0;
37763 }
37764
37765 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
37766 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
37767 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
37768 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
37769 - atomic_set(&oprofile_stats.multiplex_counter, 0);
37770 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
37771 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
37772 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
37773 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
37774 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
37775 }
37776
37777
37778 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
37779 index 38b6fc0..b5cbfce 100644
37780 --- a/drivers/oprofile/oprofile_stats.h
37781 +++ b/drivers/oprofile/oprofile_stats.h
37782 @@ -13,11 +13,11 @@
37783 #include <linux/atomic.h>
37784
37785 struct oprofile_stat_struct {
37786 - atomic_t sample_lost_no_mm;
37787 - atomic_t sample_lost_no_mapping;
37788 - atomic_t bt_lost_no_mapping;
37789 - atomic_t event_lost_overflow;
37790 - atomic_t multiplex_counter;
37791 + atomic_unchecked_t sample_lost_no_mm;
37792 + atomic_unchecked_t sample_lost_no_mapping;
37793 + atomic_unchecked_t bt_lost_no_mapping;
37794 + atomic_unchecked_t event_lost_overflow;
37795 + atomic_unchecked_t multiplex_counter;
37796 };
37797
37798 extern struct oprofile_stat_struct oprofile_stats;
37799 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
37800 index 849357c..b83c1e0 100644
37801 --- a/drivers/oprofile/oprofilefs.c
37802 +++ b/drivers/oprofile/oprofilefs.c
37803 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
37804
37805
37806 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
37807 - char const *name, atomic_t *val)
37808 + char const *name, atomic_unchecked_t *val)
37809 {
37810 return __oprofilefs_create_file(sb, root, name,
37811 &atomic_ro_fops, 0444, val);
37812 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
37813 index 3f56bc0..707d642 100644
37814 --- a/drivers/parport/procfs.c
37815 +++ b/drivers/parport/procfs.c
37816 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
37817
37818 *ppos += len;
37819
37820 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
37821 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
37822 }
37823
37824 #ifdef CONFIG_PARPORT_1284
37825 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
37826
37827 *ppos += len;
37828
37829 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
37830 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
37831 }
37832 #endif /* IEEE1284.3 support. */
37833
37834 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
37835 index a6a71c4..c91097b 100644
37836 --- a/drivers/pci/hotplug/cpcihp_generic.c
37837 +++ b/drivers/pci/hotplug/cpcihp_generic.c
37838 @@ -73,7 +73,6 @@ static u16 port;
37839 static unsigned int enum_bit;
37840 static u8 enum_mask;
37841
37842 -static struct cpci_hp_controller_ops generic_hpc_ops;
37843 static struct cpci_hp_controller generic_hpc;
37844
37845 static int __init validate_parameters(void)
37846 @@ -139,6 +138,10 @@ static int query_enum(void)
37847 return ((value & enum_mask) == enum_mask);
37848 }
37849
37850 +static struct cpci_hp_controller_ops generic_hpc_ops = {
37851 + .query_enum = query_enum,
37852 +};
37853 +
37854 static int __init cpcihp_generic_init(void)
37855 {
37856 int status;
37857 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
37858 pci_dev_put(dev);
37859
37860 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
37861 - generic_hpc_ops.query_enum = query_enum;
37862 generic_hpc.ops = &generic_hpc_ops;
37863
37864 status = cpci_hp_register_controller(&generic_hpc);
37865 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
37866 index 6bf8d2a..9711ce0 100644
37867 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
37868 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
37869 @@ -59,7 +59,6 @@
37870 /* local variables */
37871 static bool debug;
37872 static bool poll;
37873 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
37874 static struct cpci_hp_controller zt5550_hpc;
37875
37876 /* Primary cPCI bus bridge device */
37877 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
37878 return 0;
37879 }
37880
37881 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
37882 + .query_enum = zt5550_hc_query_enum,
37883 +};
37884 +
37885 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
37886 {
37887 int status;
37888 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
37889 dbg("returned from zt5550_hc_config");
37890
37891 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
37892 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
37893 zt5550_hpc.ops = &zt5550_hpc_ops;
37894 if(!poll) {
37895 zt5550_hpc.irq = hc_dev->irq;
37896 zt5550_hpc.irq_flags = IRQF_SHARED;
37897 zt5550_hpc.dev_id = hc_dev;
37898
37899 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37900 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37901 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37902 + pax_open_kernel();
37903 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37904 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37905 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37906 + pax_open_kernel();
37907 } else {
37908 info("using ENUM# polling mode");
37909 }
37910 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
37911 index 76ba8a1..20ca857 100644
37912 --- a/drivers/pci/hotplug/cpqphp_nvram.c
37913 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
37914 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
37915
37916 void compaq_nvram_init (void __iomem *rom_start)
37917 {
37918 +
37919 +#ifndef CONFIG_PAX_KERNEXEC
37920 if (rom_start) {
37921 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
37922 }
37923 +#endif
37924 +
37925 dbg("int15 entry = %p\n", compaq_int15_entry_point);
37926
37927 /* initialize our int15 lock */
37928 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
37929 index 449f257..0731e96 100644
37930 --- a/drivers/pci/pcie/aspm.c
37931 +++ b/drivers/pci/pcie/aspm.c
37932 @@ -27,9 +27,9 @@
37933 #define MODULE_PARAM_PREFIX "pcie_aspm."
37934
37935 /* Note: those are not register definitions */
37936 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
37937 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
37938 -#define ASPM_STATE_L1 (4) /* L1 state */
37939 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
37940 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
37941 +#define ASPM_STATE_L1 (4U) /* L1 state */
37942 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
37943 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
37944
37945 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
37946 index ec909af..e7517f3 100644
37947 --- a/drivers/pci/probe.c
37948 +++ b/drivers/pci/probe.c
37949 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
37950 struct pci_bus_region region;
37951 bool bar_too_big = false, bar_disabled = false;
37952
37953 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
37954 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
37955
37956 /* No printks while decoding is disabled! */
37957 if (!dev->mmio_always_on) {
37958 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
37959 index 9b8505c..f00870a 100644
37960 --- a/drivers/pci/proc.c
37961 +++ b/drivers/pci/proc.c
37962 @@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
37963 static int __init pci_proc_init(void)
37964 {
37965 struct pci_dev *dev = NULL;
37966 +
37967 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
37968 +#ifdef CONFIG_GRKERNSEC_PROC_USER
37969 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
37970 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
37971 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
37972 +#endif
37973 +#else
37974 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
37975 +#endif
37976 proc_create("devices", 0, proc_bus_pci_dir,
37977 &proc_bus_pci_dev_operations);
37978 proc_initialized = 1;
37979 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
37980 index 75dd651..2af4c9a 100644
37981 --- a/drivers/platform/x86/thinkpad_acpi.c
37982 +++ b/drivers/platform/x86/thinkpad_acpi.c
37983 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
37984 return 0;
37985 }
37986
37987 -void static hotkey_mask_warn_incomplete_mask(void)
37988 +static void hotkey_mask_warn_incomplete_mask(void)
37989 {
37990 /* log only what the user can fix... */
37991 const u32 wantedmask = hotkey_driver_mask &
37992 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
37993 }
37994 }
37995
37996 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37997 - struct tp_nvram_state *newn,
37998 - const u32 event_mask)
37999 -{
38000 -
38001 #define TPACPI_COMPARE_KEY(__scancode, __member) \
38002 do { \
38003 if ((event_mask & (1 << __scancode)) && \
38004 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38005 tpacpi_hotkey_send_key(__scancode); \
38006 } while (0)
38007
38008 - void issue_volchange(const unsigned int oldvol,
38009 - const unsigned int newvol)
38010 - {
38011 - unsigned int i = oldvol;
38012 +static void issue_volchange(const unsigned int oldvol,
38013 + const unsigned int newvol,
38014 + const u32 event_mask)
38015 +{
38016 + unsigned int i = oldvol;
38017
38018 - while (i > newvol) {
38019 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
38020 - i--;
38021 - }
38022 - while (i < newvol) {
38023 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38024 - i++;
38025 - }
38026 + while (i > newvol) {
38027 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
38028 + i--;
38029 }
38030 + while (i < newvol) {
38031 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38032 + i++;
38033 + }
38034 +}
38035
38036 - void issue_brightnesschange(const unsigned int oldbrt,
38037 - const unsigned int newbrt)
38038 - {
38039 - unsigned int i = oldbrt;
38040 +static void issue_brightnesschange(const unsigned int oldbrt,
38041 + const unsigned int newbrt,
38042 + const u32 event_mask)
38043 +{
38044 + unsigned int i = oldbrt;
38045
38046 - while (i > newbrt) {
38047 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
38048 - i--;
38049 - }
38050 - while (i < newbrt) {
38051 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38052 - i++;
38053 - }
38054 + while (i > newbrt) {
38055 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
38056 + i--;
38057 + }
38058 + while (i < newbrt) {
38059 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38060 + i++;
38061 }
38062 +}
38063
38064 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38065 + struct tp_nvram_state *newn,
38066 + const u32 event_mask)
38067 +{
38068 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
38069 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
38070 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
38071 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38072 oldn->volume_level != newn->volume_level) {
38073 /* recently muted, or repeated mute keypress, or
38074 * multiple presses ending in mute */
38075 - issue_volchange(oldn->volume_level, newn->volume_level);
38076 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
38077 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
38078 }
38079 } else {
38080 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38081 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38082 }
38083 if (oldn->volume_level != newn->volume_level) {
38084 - issue_volchange(oldn->volume_level, newn->volume_level);
38085 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
38086 } else if (oldn->volume_toggle != newn->volume_toggle) {
38087 /* repeated vol up/down keypress at end of scale ? */
38088 if (newn->volume_level == 0)
38089 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38090 /* handle brightness */
38091 if (oldn->brightness_level != newn->brightness_level) {
38092 issue_brightnesschange(oldn->brightness_level,
38093 - newn->brightness_level);
38094 + newn->brightness_level,
38095 + event_mask);
38096 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
38097 /* repeated key presses that didn't change state */
38098 if (newn->brightness_level == 0)
38099 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38100 && !tp_features.bright_unkfw)
38101 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38102 }
38103 +}
38104
38105 #undef TPACPI_COMPARE_KEY
38106 #undef TPACPI_MAY_SEND_KEY
38107 -}
38108
38109 /*
38110 * Polling driver
38111 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
38112 index 769d265..a3a05ca 100644
38113 --- a/drivers/pnp/pnpbios/bioscalls.c
38114 +++ b/drivers/pnp/pnpbios/bioscalls.c
38115 @@ -58,7 +58,7 @@ do { \
38116 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
38117 } while(0)
38118
38119 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
38120 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
38121 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
38122
38123 /*
38124 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38125
38126 cpu = get_cpu();
38127 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
38128 +
38129 + pax_open_kernel();
38130 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
38131 + pax_close_kernel();
38132
38133 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
38134 spin_lock_irqsave(&pnp_bios_lock, flags);
38135 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38136 :"memory");
38137 spin_unlock_irqrestore(&pnp_bios_lock, flags);
38138
38139 + pax_open_kernel();
38140 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
38141 + pax_close_kernel();
38142 +
38143 put_cpu();
38144
38145 /* If we get here and this is set then the PnP BIOS faulted on us. */
38146 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
38147 return status;
38148 }
38149
38150 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
38151 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
38152 {
38153 int i;
38154
38155 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38156 pnp_bios_callpoint.offset = header->fields.pm16offset;
38157 pnp_bios_callpoint.segment = PNP_CS16;
38158
38159 + pax_open_kernel();
38160 +
38161 for_each_possible_cpu(i) {
38162 struct desc_struct *gdt = get_cpu_gdt_table(i);
38163 if (!gdt)
38164 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38165 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
38166 (unsigned long)__va(header->fields.pm16dseg));
38167 }
38168 +
38169 + pax_close_kernel();
38170 }
38171 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
38172 index b0ecacb..7c9da2e 100644
38173 --- a/drivers/pnp/resource.c
38174 +++ b/drivers/pnp/resource.c
38175 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
38176 return 1;
38177
38178 /* check if the resource is valid */
38179 - if (*irq < 0 || *irq > 15)
38180 + if (*irq > 15)
38181 return 0;
38182
38183 /* check if the resource is reserved */
38184 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
38185 return 1;
38186
38187 /* check if the resource is valid */
38188 - if (*dma < 0 || *dma == 4 || *dma > 7)
38189 + if (*dma == 4 || *dma > 7)
38190 return 0;
38191
38192 /* check if the resource is reserved */
38193 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
38194 index 7df7c5f..bd48c47 100644
38195 --- a/drivers/power/pda_power.c
38196 +++ b/drivers/power/pda_power.c
38197 @@ -37,7 +37,11 @@ static int polling;
38198
38199 #ifdef CONFIG_USB_OTG_UTILS
38200 static struct usb_phy *transceiver;
38201 -static struct notifier_block otg_nb;
38202 +static int otg_handle_notification(struct notifier_block *nb,
38203 + unsigned long event, void *unused);
38204 +static struct notifier_block otg_nb = {
38205 + .notifier_call = otg_handle_notification
38206 +};
38207 #endif
38208
38209 static struct regulator *ac_draw;
38210 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
38211
38212 #ifdef CONFIG_USB_OTG_UTILS
38213 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
38214 - otg_nb.notifier_call = otg_handle_notification;
38215 ret = usb_register_notifier(transceiver, &otg_nb);
38216 if (ret) {
38217 dev_err(dev, "failure to register otg notifier\n");
38218 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
38219 index 8d53174..04c65de 100644
38220 --- a/drivers/regulator/max8660.c
38221 +++ b/drivers/regulator/max8660.c
38222 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
38223 max8660->shadow_regs[MAX8660_OVER1] = 5;
38224 } else {
38225 /* Otherwise devices can be toggled via software */
38226 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
38227 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
38228 + pax_open_kernel();
38229 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
38230 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
38231 + pax_close_kernel();
38232 }
38233
38234 /*
38235 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
38236 index 1fa6381..f58834e 100644
38237 --- a/drivers/regulator/mc13892-regulator.c
38238 +++ b/drivers/regulator/mc13892-regulator.c
38239 @@ -540,10 +540,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
38240 }
38241 mc13xxx_unlock(mc13892);
38242
38243 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38244 + pax_open_kernel();
38245 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38246 = mc13892_vcam_set_mode;
38247 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38248 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38249 = mc13892_vcam_get_mode;
38250 + pax_close_kernel();
38251
38252 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
38253 ARRAY_SIZE(mc13892_regulators));
38254 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
38255 index cace6d3..f623fda 100644
38256 --- a/drivers/rtc/rtc-dev.c
38257 +++ b/drivers/rtc/rtc-dev.c
38258 @@ -14,6 +14,7 @@
38259 #include <linux/module.h>
38260 #include <linux/rtc.h>
38261 #include <linux/sched.h>
38262 +#include <linux/grsecurity.h>
38263 #include "rtc-core.h"
38264
38265 static dev_t rtc_devt;
38266 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
38267 if (copy_from_user(&tm, uarg, sizeof(tm)))
38268 return -EFAULT;
38269
38270 + gr_log_timechange();
38271 +
38272 return rtc_set_time(rtc, &tm);
38273
38274 case RTC_PIE_ON:
38275 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
38276 index 4ad7e36..d004679 100644
38277 --- a/drivers/scsi/bfa/bfa.h
38278 +++ b/drivers/scsi/bfa/bfa.h
38279 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
38280 u32 *end);
38281 int cpe_vec_q0;
38282 int rme_vec_q0;
38283 -};
38284 +} __no_const;
38285 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
38286
38287 struct bfa_faa_cbfn_s {
38288 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
38289 index e693af6..2e525b6 100644
38290 --- a/drivers/scsi/bfa/bfa_fcpim.h
38291 +++ b/drivers/scsi/bfa/bfa_fcpim.h
38292 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
38293
38294 struct bfa_itn_s {
38295 bfa_isr_func_t isr;
38296 -};
38297 +} __no_const;
38298
38299 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
38300 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
38301 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
38302 index 23a90e7..9cf04ee 100644
38303 --- a/drivers/scsi/bfa/bfa_ioc.h
38304 +++ b/drivers/scsi/bfa/bfa_ioc.h
38305 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
38306 bfa_ioc_disable_cbfn_t disable_cbfn;
38307 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
38308 bfa_ioc_reset_cbfn_t reset_cbfn;
38309 -};
38310 +} __no_const;
38311
38312 /*
38313 * IOC event notification mechanism.
38314 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
38315 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
38316 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
38317 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
38318 -};
38319 +} __no_const;
38320
38321 /*
38322 * Queue element to wait for room in request queue. FIFO order is
38323 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
38324 index 593085a..47aa999 100644
38325 --- a/drivers/scsi/hosts.c
38326 +++ b/drivers/scsi/hosts.c
38327 @@ -42,7 +42,7 @@
38328 #include "scsi_logging.h"
38329
38330
38331 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38332 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38333
38334
38335 static void scsi_host_cls_release(struct device *dev)
38336 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
38337 * subtract one because we increment first then return, but we need to
38338 * know what the next host number was before increment
38339 */
38340 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
38341 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
38342 shost->dma_channel = 0xff;
38343
38344 /* These three are default values which can be overridden */
38345 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
38346 index 4217e49..9c77e3e 100644
38347 --- a/drivers/scsi/hpsa.c
38348 +++ b/drivers/scsi/hpsa.c
38349 @@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
38350 unsigned long flags;
38351
38352 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38353 - return h->access.command_completed(h, q);
38354 + return h->access->command_completed(h, q);
38355
38356 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
38357 a = rq->head[rq->current_entry];
38358 @@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
38359 while (!list_empty(&h->reqQ)) {
38360 c = list_entry(h->reqQ.next, struct CommandList, list);
38361 /* can't do anything if fifo is full */
38362 - if ((h->access.fifo_full(h))) {
38363 + if ((h->access->fifo_full(h))) {
38364 dev_warn(&h->pdev->dev, "fifo full\n");
38365 break;
38366 }
38367 @@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
38368
38369 /* Tell the controller execute command */
38370 spin_unlock_irqrestore(&h->lock, flags);
38371 - h->access.submit_command(h, c);
38372 + h->access->submit_command(h, c);
38373 spin_lock_irqsave(&h->lock, flags);
38374 }
38375 spin_unlock_irqrestore(&h->lock, flags);
38376 @@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
38377
38378 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
38379 {
38380 - return h->access.command_completed(h, q);
38381 + return h->access->command_completed(h, q);
38382 }
38383
38384 static inline bool interrupt_pending(struct ctlr_info *h)
38385 {
38386 - return h->access.intr_pending(h);
38387 + return h->access->intr_pending(h);
38388 }
38389
38390 static inline long interrupt_not_for_us(struct ctlr_info *h)
38391 {
38392 - return (h->access.intr_pending(h) == 0) ||
38393 + return (h->access->intr_pending(h) == 0) ||
38394 (h->interrupts_enabled == 0);
38395 }
38396
38397 @@ -4318,7 +4318,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
38398 if (prod_index < 0)
38399 return -ENODEV;
38400 h->product_name = products[prod_index].product_name;
38401 - h->access = *(products[prod_index].access);
38402 + h->access = products[prod_index].access;
38403
38404 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
38405 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
38406 @@ -4600,7 +4600,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
38407
38408 assert_spin_locked(&lockup_detector_lock);
38409 remove_ctlr_from_lockup_detector_list(h);
38410 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38411 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38412 spin_lock_irqsave(&h->lock, flags);
38413 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
38414 spin_unlock_irqrestore(&h->lock, flags);
38415 @@ -4778,7 +4778,7 @@ reinit_after_soft_reset:
38416 }
38417
38418 /* make sure the board interrupts are off */
38419 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38420 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38421
38422 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
38423 goto clean2;
38424 @@ -4812,7 +4812,7 @@ reinit_after_soft_reset:
38425 * fake ones to scoop up any residual completions.
38426 */
38427 spin_lock_irqsave(&h->lock, flags);
38428 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38429 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38430 spin_unlock_irqrestore(&h->lock, flags);
38431 free_irqs(h);
38432 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
38433 @@ -4831,9 +4831,9 @@ reinit_after_soft_reset:
38434 dev_info(&h->pdev->dev, "Board READY.\n");
38435 dev_info(&h->pdev->dev,
38436 "Waiting for stale completions to drain.\n");
38437 - h->access.set_intr_mask(h, HPSA_INTR_ON);
38438 + h->access->set_intr_mask(h, HPSA_INTR_ON);
38439 msleep(10000);
38440 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38441 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38442
38443 rc = controller_reset_failed(h->cfgtable);
38444 if (rc)
38445 @@ -4854,7 +4854,7 @@ reinit_after_soft_reset:
38446 }
38447
38448 /* Turn the interrupts on so we can service requests */
38449 - h->access.set_intr_mask(h, HPSA_INTR_ON);
38450 + h->access->set_intr_mask(h, HPSA_INTR_ON);
38451
38452 hpsa_hba_inquiry(h);
38453 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
38454 @@ -4906,7 +4906,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
38455 * To write all data in the battery backed cache to disks
38456 */
38457 hpsa_flush_cache(h);
38458 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
38459 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
38460 hpsa_free_irqs_and_disable_msix(h);
38461 }
38462
38463 @@ -5075,7 +5075,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
38464 return;
38465 }
38466 /* Change the access methods to the performant access methods */
38467 - h->access = SA5_performant_access;
38468 + h->access = &SA5_performant_access;
38469 h->transMethod = CFGTBL_Trans_Performant;
38470 }
38471
38472 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
38473 index 9816479..c5d4e97 100644
38474 --- a/drivers/scsi/hpsa.h
38475 +++ b/drivers/scsi/hpsa.h
38476 @@ -79,7 +79,7 @@ struct ctlr_info {
38477 unsigned int msix_vector;
38478 unsigned int msi_vector;
38479 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
38480 - struct access_method access;
38481 + struct access_method *access;
38482
38483 /* queue and queue Info */
38484 struct list_head reqQ;
38485 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
38486 index c772d8d..35c362c 100644
38487 --- a/drivers/scsi/libfc/fc_exch.c
38488 +++ b/drivers/scsi/libfc/fc_exch.c
38489 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
38490 u16 pool_max_index;
38491
38492 struct {
38493 - atomic_t no_free_exch;
38494 - atomic_t no_free_exch_xid;
38495 - atomic_t xid_not_found;
38496 - atomic_t xid_busy;
38497 - atomic_t seq_not_found;
38498 - atomic_t non_bls_resp;
38499 + atomic_unchecked_t no_free_exch;
38500 + atomic_unchecked_t no_free_exch_xid;
38501 + atomic_unchecked_t xid_not_found;
38502 + atomic_unchecked_t xid_busy;
38503 + atomic_unchecked_t seq_not_found;
38504 + atomic_unchecked_t non_bls_resp;
38505 } stats;
38506 };
38507
38508 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
38509 /* allocate memory for exchange */
38510 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
38511 if (!ep) {
38512 - atomic_inc(&mp->stats.no_free_exch);
38513 + atomic_inc_unchecked(&mp->stats.no_free_exch);
38514 goto out;
38515 }
38516 memset(ep, 0, sizeof(*ep));
38517 @@ -786,7 +786,7 @@ out:
38518 return ep;
38519 err:
38520 spin_unlock_bh(&pool->lock);
38521 - atomic_inc(&mp->stats.no_free_exch_xid);
38522 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
38523 mempool_free(ep, mp->ep_pool);
38524 return NULL;
38525 }
38526 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38527 xid = ntohs(fh->fh_ox_id); /* we originated exch */
38528 ep = fc_exch_find(mp, xid);
38529 if (!ep) {
38530 - atomic_inc(&mp->stats.xid_not_found);
38531 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38532 reject = FC_RJT_OX_ID;
38533 goto out;
38534 }
38535 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38536 ep = fc_exch_find(mp, xid);
38537 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
38538 if (ep) {
38539 - atomic_inc(&mp->stats.xid_busy);
38540 + atomic_inc_unchecked(&mp->stats.xid_busy);
38541 reject = FC_RJT_RX_ID;
38542 goto rel;
38543 }
38544 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38545 }
38546 xid = ep->xid; /* get our XID */
38547 } else if (!ep) {
38548 - atomic_inc(&mp->stats.xid_not_found);
38549 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38550 reject = FC_RJT_RX_ID; /* XID not found */
38551 goto out;
38552 }
38553 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38554 } else {
38555 sp = &ep->seq;
38556 if (sp->id != fh->fh_seq_id) {
38557 - atomic_inc(&mp->stats.seq_not_found);
38558 + atomic_inc_unchecked(&mp->stats.seq_not_found);
38559 if (f_ctl & FC_FC_END_SEQ) {
38560 /*
38561 * Update sequence_id based on incoming last
38562 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38563
38564 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
38565 if (!ep) {
38566 - atomic_inc(&mp->stats.xid_not_found);
38567 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38568 goto out;
38569 }
38570 if (ep->esb_stat & ESB_ST_COMPLETE) {
38571 - atomic_inc(&mp->stats.xid_not_found);
38572 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38573 goto rel;
38574 }
38575 if (ep->rxid == FC_XID_UNKNOWN)
38576 ep->rxid = ntohs(fh->fh_rx_id);
38577 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
38578 - atomic_inc(&mp->stats.xid_not_found);
38579 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38580 goto rel;
38581 }
38582 if (ep->did != ntoh24(fh->fh_s_id) &&
38583 ep->did != FC_FID_FLOGI) {
38584 - atomic_inc(&mp->stats.xid_not_found);
38585 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38586 goto rel;
38587 }
38588 sof = fr_sof(fp);
38589 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38590 sp->ssb_stat |= SSB_ST_RESP;
38591 sp->id = fh->fh_seq_id;
38592 } else if (sp->id != fh->fh_seq_id) {
38593 - atomic_inc(&mp->stats.seq_not_found);
38594 + atomic_inc_unchecked(&mp->stats.seq_not_found);
38595 goto rel;
38596 }
38597
38598 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38599 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
38600
38601 if (!sp)
38602 - atomic_inc(&mp->stats.xid_not_found);
38603 + atomic_inc_unchecked(&mp->stats.xid_not_found);
38604 else
38605 - atomic_inc(&mp->stats.non_bls_resp);
38606 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
38607
38608 fc_frame_free(fp);
38609 }
38610 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
38611
38612 list_for_each_entry(ema, &lport->ema_list, ema_list) {
38613 mp = ema->mp;
38614 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
38615 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
38616 st->fc_no_free_exch_xid +=
38617 - atomic_read(&mp->stats.no_free_exch_xid);
38618 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
38619 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
38620 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
38621 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
38622 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
38623 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
38624 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
38625 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
38626 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
38627 }
38628 }
38629 EXPORT_SYMBOL(fc_exch_update_stats);
38630 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
38631 index bdb81cd..d3c7c2c 100644
38632 --- a/drivers/scsi/libsas/sas_ata.c
38633 +++ b/drivers/scsi/libsas/sas_ata.c
38634 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
38635 .postreset = ata_std_postreset,
38636 .error_handler = ata_std_error_handler,
38637 .post_internal_cmd = sas_ata_post_internal,
38638 - .qc_defer = ata_std_qc_defer,
38639 + .qc_defer = ata_std_qc_defer,
38640 .qc_prep = ata_noop_qc_prep,
38641 .qc_issue = sas_ata_qc_issue,
38642 .qc_fill_rtf = sas_ata_qc_fill_rtf,
38643 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
38644 index 69b5993..1ac9dce 100644
38645 --- a/drivers/scsi/lpfc/lpfc.h
38646 +++ b/drivers/scsi/lpfc/lpfc.h
38647 @@ -424,7 +424,7 @@ struct lpfc_vport {
38648 struct dentry *debug_nodelist;
38649 struct dentry *vport_debugfs_root;
38650 struct lpfc_debugfs_trc *disc_trc;
38651 - atomic_t disc_trc_cnt;
38652 + atomic_unchecked_t disc_trc_cnt;
38653 #endif
38654 uint8_t stat_data_enabled;
38655 uint8_t stat_data_blocked;
38656 @@ -840,8 +840,8 @@ struct lpfc_hba {
38657 struct timer_list fabric_block_timer;
38658 unsigned long bit_flags;
38659 #define FABRIC_COMANDS_BLOCKED 0
38660 - atomic_t num_rsrc_err;
38661 - atomic_t num_cmd_success;
38662 + atomic_unchecked_t num_rsrc_err;
38663 + atomic_unchecked_t num_cmd_success;
38664 unsigned long last_rsrc_error_time;
38665 unsigned long last_ramp_down_time;
38666 unsigned long last_ramp_up_time;
38667 @@ -877,7 +877,7 @@ struct lpfc_hba {
38668
38669 struct dentry *debug_slow_ring_trc;
38670 struct lpfc_debugfs_trc *slow_ring_trc;
38671 - atomic_t slow_ring_trc_cnt;
38672 + atomic_unchecked_t slow_ring_trc_cnt;
38673 /* iDiag debugfs sub-directory */
38674 struct dentry *idiag_root;
38675 struct dentry *idiag_pci_cfg;
38676 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
38677 index f63f5ff..de29189 100644
38678 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
38679 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
38680 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
38681
38682 #include <linux/debugfs.h>
38683
38684 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38685 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38686 static unsigned long lpfc_debugfs_start_time = 0L;
38687
38688 /* iDiag */
38689 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
38690 lpfc_debugfs_enable = 0;
38691
38692 len = 0;
38693 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
38694 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
38695 (lpfc_debugfs_max_disc_trc - 1);
38696 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
38697 dtp = vport->disc_trc + i;
38698 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
38699 lpfc_debugfs_enable = 0;
38700
38701 len = 0;
38702 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
38703 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
38704 (lpfc_debugfs_max_slow_ring_trc - 1);
38705 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
38706 dtp = phba->slow_ring_trc + i;
38707 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
38708 !vport || !vport->disc_trc)
38709 return;
38710
38711 - index = atomic_inc_return(&vport->disc_trc_cnt) &
38712 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
38713 (lpfc_debugfs_max_disc_trc - 1);
38714 dtp = vport->disc_trc + index;
38715 dtp->fmt = fmt;
38716 dtp->data1 = data1;
38717 dtp->data2 = data2;
38718 dtp->data3 = data3;
38719 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38720 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38721 dtp->jif = jiffies;
38722 #endif
38723 return;
38724 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
38725 !phba || !phba->slow_ring_trc)
38726 return;
38727
38728 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
38729 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
38730 (lpfc_debugfs_max_slow_ring_trc - 1);
38731 dtp = phba->slow_ring_trc + index;
38732 dtp->fmt = fmt;
38733 dtp->data1 = data1;
38734 dtp->data2 = data2;
38735 dtp->data3 = data3;
38736 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38737 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38738 dtp->jif = jiffies;
38739 #endif
38740 return;
38741 @@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38742 "slow_ring buffer\n");
38743 goto debug_failed;
38744 }
38745 - atomic_set(&phba->slow_ring_trc_cnt, 0);
38746 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
38747 memset(phba->slow_ring_trc, 0,
38748 (sizeof(struct lpfc_debugfs_trc) *
38749 lpfc_debugfs_max_slow_ring_trc));
38750 @@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38751 "buffer\n");
38752 goto debug_failed;
38753 }
38754 - atomic_set(&vport->disc_trc_cnt, 0);
38755 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
38756
38757 snprintf(name, sizeof(name), "discovery_trace");
38758 vport->debug_disc_trc =
38759 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
38760 index 7dc4218..3436f08 100644
38761 --- a/drivers/scsi/lpfc/lpfc_init.c
38762 +++ b/drivers/scsi/lpfc/lpfc_init.c
38763 @@ -10589,8 +10589,10 @@ lpfc_init(void)
38764 "misc_register returned with status %d", error);
38765
38766 if (lpfc_enable_npiv) {
38767 - lpfc_transport_functions.vport_create = lpfc_vport_create;
38768 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38769 + pax_open_kernel();
38770 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
38771 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38772 + pax_close_kernel();
38773 }
38774 lpfc_transport_template =
38775 fc_attach_transport(&lpfc_transport_functions);
38776 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
38777 index 7f45ac9..cf62eda 100644
38778 --- a/drivers/scsi/lpfc/lpfc_scsi.c
38779 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
38780 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
38781 uint32_t evt_posted;
38782
38783 spin_lock_irqsave(&phba->hbalock, flags);
38784 - atomic_inc(&phba->num_rsrc_err);
38785 + atomic_inc_unchecked(&phba->num_rsrc_err);
38786 phba->last_rsrc_error_time = jiffies;
38787
38788 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
38789 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
38790 unsigned long flags;
38791 struct lpfc_hba *phba = vport->phba;
38792 uint32_t evt_posted;
38793 - atomic_inc(&phba->num_cmd_success);
38794 + atomic_inc_unchecked(&phba->num_cmd_success);
38795
38796 if (vport->cfg_lun_queue_depth <= queue_depth)
38797 return;
38798 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38799 unsigned long num_rsrc_err, num_cmd_success;
38800 int i;
38801
38802 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
38803 - num_cmd_success = atomic_read(&phba->num_cmd_success);
38804 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
38805 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
38806
38807 /*
38808 * The error and success command counters are global per
38809 @@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38810 }
38811 }
38812 lpfc_destroy_vport_work_array(phba, vports);
38813 - atomic_set(&phba->num_rsrc_err, 0);
38814 - atomic_set(&phba->num_cmd_success, 0);
38815 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38816 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38817 }
38818
38819 /**
38820 @@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
38821 }
38822 }
38823 lpfc_destroy_vport_work_array(phba, vports);
38824 - atomic_set(&phba->num_rsrc_err, 0);
38825 - atomic_set(&phba->num_cmd_success, 0);
38826 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
38827 + atomic_set_unchecked(&phba->num_cmd_success, 0);
38828 }
38829
38830 /**
38831 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
38832 index af763ea..41904f7 100644
38833 --- a/drivers/scsi/pmcraid.c
38834 +++ b/drivers/scsi/pmcraid.c
38835 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
38836 res->scsi_dev = scsi_dev;
38837 scsi_dev->hostdata = res;
38838 res->change_detected = 0;
38839 - atomic_set(&res->read_failures, 0);
38840 - atomic_set(&res->write_failures, 0);
38841 + atomic_set_unchecked(&res->read_failures, 0);
38842 + atomic_set_unchecked(&res->write_failures, 0);
38843 rc = 0;
38844 }
38845 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
38846 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
38847
38848 /* If this was a SCSI read/write command keep count of errors */
38849 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
38850 - atomic_inc(&res->read_failures);
38851 + atomic_inc_unchecked(&res->read_failures);
38852 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
38853 - atomic_inc(&res->write_failures);
38854 + atomic_inc_unchecked(&res->write_failures);
38855
38856 if (!RES_IS_GSCSI(res->cfg_entry) &&
38857 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
38858 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
38859 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38860 * hrrq_id assigned here in queuecommand
38861 */
38862 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38863 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38864 pinstance->num_hrrq;
38865 cmd->cmd_done = pmcraid_io_done;
38866
38867 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
38868 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38869 * hrrq_id assigned here in queuecommand
38870 */
38871 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38872 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38873 pinstance->num_hrrq;
38874
38875 if (request_size) {
38876 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
38877
38878 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
38879 /* add resources only after host is added into system */
38880 - if (!atomic_read(&pinstance->expose_resources))
38881 + if (!atomic_read_unchecked(&pinstance->expose_resources))
38882 return;
38883
38884 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
38885 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
38886 init_waitqueue_head(&pinstance->reset_wait_q);
38887
38888 atomic_set(&pinstance->outstanding_cmds, 0);
38889 - atomic_set(&pinstance->last_message_id, 0);
38890 - atomic_set(&pinstance->expose_resources, 0);
38891 + atomic_set_unchecked(&pinstance->last_message_id, 0);
38892 + atomic_set_unchecked(&pinstance->expose_resources, 0);
38893
38894 INIT_LIST_HEAD(&pinstance->free_res_q);
38895 INIT_LIST_HEAD(&pinstance->used_res_q);
38896 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
38897 /* Schedule worker thread to handle CCN and take care of adding and
38898 * removing devices to OS
38899 */
38900 - atomic_set(&pinstance->expose_resources, 1);
38901 + atomic_set_unchecked(&pinstance->expose_resources, 1);
38902 schedule_work(&pinstance->worker_q);
38903 return rc;
38904
38905 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
38906 index e1d150f..6c6df44 100644
38907 --- a/drivers/scsi/pmcraid.h
38908 +++ b/drivers/scsi/pmcraid.h
38909 @@ -748,7 +748,7 @@ struct pmcraid_instance {
38910 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
38911
38912 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
38913 - atomic_t last_message_id;
38914 + atomic_unchecked_t last_message_id;
38915
38916 /* configuration table */
38917 struct pmcraid_config_table *cfg_table;
38918 @@ -777,7 +777,7 @@ struct pmcraid_instance {
38919 atomic_t outstanding_cmds;
38920
38921 /* should add/delete resources to mid-layer now ?*/
38922 - atomic_t expose_resources;
38923 + atomic_unchecked_t expose_resources;
38924
38925
38926
38927 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
38928 struct pmcraid_config_table_entry_ext cfg_entry_ext;
38929 };
38930 struct scsi_device *scsi_dev; /* Link scsi_device structure */
38931 - atomic_t read_failures; /* count of failed READ commands */
38932 - atomic_t write_failures; /* count of failed WRITE commands */
38933 + atomic_unchecked_t read_failures; /* count of failed READ commands */
38934 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
38935
38936 /* To indicate add/delete/modify during CCN */
38937 u8 change_detected;
38938 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
38939 index 83d7984..a27d947 100644
38940 --- a/drivers/scsi/qla2xxx/qla_attr.c
38941 +++ b/drivers/scsi/qla2xxx/qla_attr.c
38942 @@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
38943 return 0;
38944 }
38945
38946 -struct fc_function_template qla2xxx_transport_functions = {
38947 +fc_function_template_no_const qla2xxx_transport_functions = {
38948
38949 .show_host_node_name = 1,
38950 .show_host_port_name = 1,
38951 @@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
38952 .bsg_timeout = qla24xx_bsg_timeout,
38953 };
38954
38955 -struct fc_function_template qla2xxx_transport_vport_functions = {
38956 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
38957
38958 .show_host_node_name = 1,
38959 .show_host_port_name = 1,
38960 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
38961 index 6acb397..d86e3e0 100644
38962 --- a/drivers/scsi/qla2xxx/qla_gbl.h
38963 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
38964 @@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
38965 struct device_attribute;
38966 extern struct device_attribute *qla2x00_host_attrs[];
38967 struct fc_function_template;
38968 -extern struct fc_function_template qla2xxx_transport_functions;
38969 -extern struct fc_function_template qla2xxx_transport_vport_functions;
38970 +extern fc_function_template_no_const qla2xxx_transport_functions;
38971 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
38972 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
38973 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
38974 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
38975 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
38976 index f4b1fc8..a1ce4dd 100644
38977 --- a/drivers/scsi/qla2xxx/qla_os.c
38978 +++ b/drivers/scsi/qla2xxx/qla_os.c
38979 @@ -1462,8 +1462,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
38980 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
38981 /* Ok, a 64bit DMA mask is applicable. */
38982 ha->flags.enable_64bit_addressing = 1;
38983 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38984 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38985 + pax_open_kernel();
38986 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38987 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38988 + pax_close_kernel();
38989 return;
38990 }
38991 }
38992 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
38993 index 329d553..f20d31d 100644
38994 --- a/drivers/scsi/qla4xxx/ql4_def.h
38995 +++ b/drivers/scsi/qla4xxx/ql4_def.h
38996 @@ -273,7 +273,7 @@ struct ddb_entry {
38997 * (4000 only) */
38998 atomic_t relogin_timer; /* Max Time to wait for
38999 * relogin to complete */
39000 - atomic_t relogin_retry_count; /* Num of times relogin has been
39001 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
39002 * retried */
39003 uint32_t default_time2wait; /* Default Min time between
39004 * relogins (+aens) */
39005 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
39006 index fbc546e..c7d1b48 100644
39007 --- a/drivers/scsi/qla4xxx/ql4_os.c
39008 +++ b/drivers/scsi/qla4xxx/ql4_os.c
39009 @@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
39010 */
39011 if (!iscsi_is_session_online(cls_sess)) {
39012 /* Reset retry relogin timer */
39013 - atomic_inc(&ddb_entry->relogin_retry_count);
39014 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
39015 DEBUG2(ql4_printk(KERN_INFO, ha,
39016 "%s: index[%d] relogin timed out-retrying"
39017 " relogin (%d), retry (%d)\n", __func__,
39018 ddb_entry->fw_ddb_index,
39019 - atomic_read(&ddb_entry->relogin_retry_count),
39020 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
39021 ddb_entry->default_time2wait + 4));
39022 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
39023 atomic_set(&ddb_entry->retry_relogin_timer,
39024 @@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
39025
39026 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
39027 atomic_set(&ddb_entry->relogin_timer, 0);
39028 - atomic_set(&ddb_entry->relogin_retry_count, 0);
39029 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
39030 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
39031 ddb_entry->default_relogin_timeout =
39032 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
39033 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
39034 index 2c0d0ec..4e8681a 100644
39035 --- a/drivers/scsi/scsi.c
39036 +++ b/drivers/scsi/scsi.c
39037 @@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
39038 unsigned long timeout;
39039 int rtn = 0;
39040
39041 - atomic_inc(&cmd->device->iorequest_cnt);
39042 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
39043
39044 /* check if the device is still usable */
39045 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
39046 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
39047 index 9032e91..7a805d0 100644
39048 --- a/drivers/scsi/scsi_lib.c
39049 +++ b/drivers/scsi/scsi_lib.c
39050 @@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
39051 shost = sdev->host;
39052 scsi_init_cmd_errh(cmd);
39053 cmd->result = DID_NO_CONNECT << 16;
39054 - atomic_inc(&cmd->device->iorequest_cnt);
39055 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
39056
39057 /*
39058 * SCSI request completion path will do scsi_device_unbusy(),
39059 @@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
39060
39061 INIT_LIST_HEAD(&cmd->eh_entry);
39062
39063 - atomic_inc(&cmd->device->iodone_cnt);
39064 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
39065 if (cmd->result)
39066 - atomic_inc(&cmd->device->ioerr_cnt);
39067 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
39068
39069 disposition = scsi_decide_disposition(cmd);
39070 if (disposition != SUCCESS &&
39071 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
39072 index 931a7d9..0c2a754 100644
39073 --- a/drivers/scsi/scsi_sysfs.c
39074 +++ b/drivers/scsi/scsi_sysfs.c
39075 @@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
39076 char *buf) \
39077 { \
39078 struct scsi_device *sdev = to_scsi_device(dev); \
39079 - unsigned long long count = atomic_read(&sdev->field); \
39080 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
39081 return snprintf(buf, 20, "0x%llx\n", count); \
39082 } \
39083 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
39084 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
39085 index 84a1fdf..693b0d6 100644
39086 --- a/drivers/scsi/scsi_tgt_lib.c
39087 +++ b/drivers/scsi/scsi_tgt_lib.c
39088 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
39089 int err;
39090
39091 dprintk("%lx %u\n", uaddr, len);
39092 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
39093 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
39094 if (err) {
39095 /*
39096 * TODO: need to fixup sg_tablesize, max_segment_size,
39097 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
39098 index e894ca7..de9d7660 100644
39099 --- a/drivers/scsi/scsi_transport_fc.c
39100 +++ b/drivers/scsi/scsi_transport_fc.c
39101 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
39102 * Netlink Infrastructure
39103 */
39104
39105 -static atomic_t fc_event_seq;
39106 +static atomic_unchecked_t fc_event_seq;
39107
39108 /**
39109 * fc_get_event_number - Obtain the next sequential FC event number
39110 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
39111 u32
39112 fc_get_event_number(void)
39113 {
39114 - return atomic_add_return(1, &fc_event_seq);
39115 + return atomic_add_return_unchecked(1, &fc_event_seq);
39116 }
39117 EXPORT_SYMBOL(fc_get_event_number);
39118
39119 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
39120 {
39121 int error;
39122
39123 - atomic_set(&fc_event_seq, 0);
39124 + atomic_set_unchecked(&fc_event_seq, 0);
39125
39126 error = transport_class_register(&fc_host_class);
39127 if (error)
39128 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
39129 char *cp;
39130
39131 *val = simple_strtoul(buf, &cp, 0);
39132 - if ((*cp && (*cp != '\n')) || (*val < 0))
39133 + if (*cp && (*cp != '\n'))
39134 return -EINVAL;
39135 /*
39136 * Check for overflow; dev_loss_tmo is u32
39137 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
39138 index 31969f2..2b348f0 100644
39139 --- a/drivers/scsi/scsi_transport_iscsi.c
39140 +++ b/drivers/scsi/scsi_transport_iscsi.c
39141 @@ -79,7 +79,7 @@ struct iscsi_internal {
39142 struct transport_container session_cont;
39143 };
39144
39145 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
39146 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
39147 static struct workqueue_struct *iscsi_eh_timer_workq;
39148
39149 static DEFINE_IDA(iscsi_sess_ida);
39150 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
39151 int err;
39152
39153 ihost = shost->shost_data;
39154 - session->sid = atomic_add_return(1, &iscsi_session_nr);
39155 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
39156
39157 if (target_id == ISCSI_MAX_TARGET) {
39158 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
39159 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
39160 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
39161 ISCSI_TRANSPORT_VERSION);
39162
39163 - atomic_set(&iscsi_session_nr, 0);
39164 + atomic_set_unchecked(&iscsi_session_nr, 0);
39165
39166 err = class_register(&iscsi_transport_class);
39167 if (err)
39168 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
39169 index 21a045e..ec89e03 100644
39170 --- a/drivers/scsi/scsi_transport_srp.c
39171 +++ b/drivers/scsi/scsi_transport_srp.c
39172 @@ -33,7 +33,7 @@
39173 #include "scsi_transport_srp_internal.h"
39174
39175 struct srp_host_attrs {
39176 - atomic_t next_port_id;
39177 + atomic_unchecked_t next_port_id;
39178 };
39179 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
39180
39181 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
39182 struct Scsi_Host *shost = dev_to_shost(dev);
39183 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
39184
39185 - atomic_set(&srp_host->next_port_id, 0);
39186 + atomic_set_unchecked(&srp_host->next_port_id, 0);
39187 return 0;
39188 }
39189
39190 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
39191 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
39192 rport->roles = ids->roles;
39193
39194 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
39195 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
39196 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
39197
39198 transport_setup_device(&rport->dev);
39199 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
39200 index a45e12a..d9120cb 100644
39201 --- a/drivers/scsi/sd.c
39202 +++ b/drivers/scsi/sd.c
39203 @@ -2899,7 +2899,7 @@ static int sd_probe(struct device *dev)
39204 sdkp->disk = gd;
39205 sdkp->index = index;
39206 atomic_set(&sdkp->openers, 0);
39207 - atomic_set(&sdkp->device->ioerr_cnt, 0);
39208 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
39209
39210 if (!sdp->request_queue->rq_timeout) {
39211 if (sdp->type != TYPE_MOD)
39212 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
39213 index be2c9a6..275525c 100644
39214 --- a/drivers/scsi/sg.c
39215 +++ b/drivers/scsi/sg.c
39216 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
39217 sdp->disk->disk_name,
39218 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
39219 NULL,
39220 - (char *)arg);
39221 + (char __user *)arg);
39222 case BLKTRACESTART:
39223 return blk_trace_startstop(sdp->device->request_queue, 1);
39224 case BLKTRACESTOP:
39225 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
39226 index 84c2861..ece0a31 100644
39227 --- a/drivers/spi/spi.c
39228 +++ b/drivers/spi/spi.c
39229 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
39230 EXPORT_SYMBOL_GPL(spi_bus_unlock);
39231
39232 /* portable code must never pass more than 32 bytes */
39233 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
39234 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
39235
39236 static u8 *buf;
39237
39238 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
39239 index 34afc16..ffe44dd 100644
39240 --- a/drivers/staging/octeon/ethernet-rx.c
39241 +++ b/drivers/staging/octeon/ethernet-rx.c
39242 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39243 /* Increment RX stats for virtual ports */
39244 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
39245 #ifdef CONFIG_64BIT
39246 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
39247 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
39248 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
39249 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
39250 #else
39251 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
39252 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
39253 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
39254 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
39255 #endif
39256 }
39257 netif_receive_skb(skb);
39258 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39259 dev->name);
39260 */
39261 #ifdef CONFIG_64BIT
39262 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
39263 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39264 #else
39265 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
39266 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
39267 #endif
39268 dev_kfree_skb_irq(skb);
39269 }
39270 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
39271 index 683bedc..86dba9a 100644
39272 --- a/drivers/staging/octeon/ethernet.c
39273 +++ b/drivers/staging/octeon/ethernet.c
39274 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
39275 * since the RX tasklet also increments it.
39276 */
39277 #ifdef CONFIG_64BIT
39278 - atomic64_add(rx_status.dropped_packets,
39279 - (atomic64_t *)&priv->stats.rx_dropped);
39280 + atomic64_add_unchecked(rx_status.dropped_packets,
39281 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39282 #else
39283 - atomic_add(rx_status.dropped_packets,
39284 - (atomic_t *)&priv->stats.rx_dropped);
39285 + atomic_add_unchecked(rx_status.dropped_packets,
39286 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
39287 #endif
39288 }
39289
39290 diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
39291 index a2b7e03..aaf3630 100644
39292 --- a/drivers/staging/ramster/tmem.c
39293 +++ b/drivers/staging/ramster/tmem.c
39294 @@ -50,25 +50,25 @@
39295 * A tmem host implementation must use this function to register callbacks
39296 * for memory allocation.
39297 */
39298 -static struct tmem_hostops tmem_hostops;
39299 +static struct tmem_hostops *tmem_hostops;
39300
39301 static void tmem_objnode_tree_init(void);
39302
39303 void tmem_register_hostops(struct tmem_hostops *m)
39304 {
39305 tmem_objnode_tree_init();
39306 - tmem_hostops = *m;
39307 + tmem_hostops = m;
39308 }
39309
39310 /*
39311 * A tmem host implementation must use this function to register
39312 * callbacks for a page-accessible memory (PAM) implementation.
39313 */
39314 -static struct tmem_pamops tmem_pamops;
39315 +static struct tmem_pamops *tmem_pamops;
39316
39317 void tmem_register_pamops(struct tmem_pamops *m)
39318 {
39319 - tmem_pamops = *m;
39320 + tmem_pamops = m;
39321 }
39322
39323 /*
39324 @@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
39325 obj->pampd_count = 0;
39326 #ifdef CONFIG_RAMSTER
39327 if (tmem_pamops.new_obj != NULL)
39328 - (*tmem_pamops.new_obj)(obj);
39329 + (tmem_pamops->new_obj)(obj);
39330 #endif
39331 SET_SENTINEL(obj, OBJ);
39332
39333 @@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
39334 rbnode = rb_next(rbnode);
39335 tmem_pampd_destroy_all_in_obj(obj, true);
39336 tmem_obj_free(obj, hb);
39337 - (*tmem_hostops.obj_free)(obj, pool);
39338 + (tmem_hostops->obj_free)(obj, pool);
39339 }
39340 spin_unlock(&hb->lock);
39341 }
39342 @@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
39343 ASSERT_SENTINEL(obj, OBJ);
39344 BUG_ON(obj->pool == NULL);
39345 ASSERT_SENTINEL(obj->pool, POOL);
39346 - objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
39347 + objnode = (tmem_hostops->objnode_alloc)(obj->pool);
39348 if (unlikely(objnode == NULL))
39349 goto out;
39350 objnode->obj = obj;
39351 @@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
39352 ASSERT_SENTINEL(pool, POOL);
39353 objnode->obj->objnode_count--;
39354 objnode->obj = NULL;
39355 - (*tmem_hostops.objnode_free)(objnode, pool);
39356 + (tmem_hostops->objnode_free)(objnode, pool);
39357 }
39358
39359 /*
39360 @@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
39361 void *old_pampd = *(void **)slot;
39362 *(void **)slot = new_pampd;
39363 if (!no_free)
39364 - (*tmem_pamops.free)(old_pampd, obj->pool,
39365 + (tmem_pamops->free)(old_pampd, obj->pool,
39366 NULL, 0, false);
39367 ret = new_pampd;
39368 }
39369 @@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
39370 if (objnode->slots[i]) {
39371 if (ht == 1) {
39372 obj->pampd_count--;
39373 - (*tmem_pamops.free)(objnode->slots[i],
39374 + (tmem_pamops->free)(objnode->slots[i],
39375 obj->pool, NULL, 0, true);
39376 objnode->slots[i] = NULL;
39377 continue;
39378 @@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
39379 return;
39380 if (obj->objnode_tree_height == 0) {
39381 obj->pampd_count--;
39382 - (*tmem_pamops.free)(obj->objnode_tree_root,
39383 + (tmem_pamops->free)(obj->objnode_tree_root,
39384 obj->pool, NULL, 0, true);
39385 } else {
39386 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
39387 @@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
39388 obj->objnode_tree_root = NULL;
39389 #ifdef CONFIG_RAMSTER
39390 if (tmem_pamops.free_obj != NULL)
39391 - (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
39392 + (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
39393 #endif
39394 }
39395
39396 @@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39397 /* if found, is a dup put, flush the old one */
39398 pampd_del = tmem_pampd_delete_from_obj(obj, index);
39399 BUG_ON(pampd_del != pampd);
39400 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
39401 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
39402 if (obj->pampd_count == 0) {
39403 objnew = obj;
39404 objfound = NULL;
39405 @@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39406 pampd = NULL;
39407 }
39408 } else {
39409 - obj = objnew = (*tmem_hostops.obj_alloc)(pool);
39410 + obj = objnew = (tmem_hostops->obj_alloc)(pool);
39411 if (unlikely(obj == NULL)) {
39412 ret = -ENOMEM;
39413 goto out;
39414 @@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39415 if (unlikely(ret == -ENOMEM))
39416 /* may have partially built objnode tree ("stump") */
39417 goto delete_and_free;
39418 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
39419 + (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
39420 goto out;
39421
39422 delete_and_free:
39423 (void)tmem_pampd_delete_from_obj(obj, index);
39424 if (pampd)
39425 - (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
39426 + (tmem_pamops->free)(pampd, pool, NULL, 0, true);
39427 if (objnew) {
39428 tmem_obj_free(objnew, hb);
39429 - (*tmem_hostops.obj_free)(objnew, pool);
39430 + (tmem_hostops->obj_free)(objnew, pool);
39431 }
39432 out:
39433 spin_unlock(&hb->lock);
39434 @@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
39435 if (pampd != NULL) {
39436 BUG_ON(obj == NULL);
39437 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
39438 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
39439 + (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
39440 } else if (delete) {
39441 BUG_ON(obj == NULL);
39442 (void)tmem_pampd_delete_from_obj(obj, index);
39443 @@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
39444 int ret = 0;
39445
39446 if (!is_ephemeral(pool))
39447 - new_pampd = (*tmem_pamops.repatriate_preload)(
39448 + new_pampd = (tmem_pamops->repatriate_preload)(
39449 old_pampd, pool, oidp, index, &intransit);
39450 if (intransit)
39451 ret = -EAGAIN;
39452 @@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
39453 /* must release the hb->lock else repatriate can't sleep */
39454 spin_unlock(&hb->lock);
39455 if (!intransit)
39456 - ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
39457 + ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
39458 oidp, index, free, data);
39459 if (ret == -EAGAIN) {
39460 /* rare I think, but should cond_resched()??? */
39461 @@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
39462 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
39463 /* if we bug here, pamops wasn't properly set up for ramster */
39464 BUG_ON(tmem_pamops.replace_in_obj == NULL);
39465 - ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
39466 + ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
39467 out:
39468 spin_unlock(&hb->lock);
39469 return ret;
39470 @@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39471 if (free) {
39472 if (obj->pampd_count == 0) {
39473 tmem_obj_free(obj, hb);
39474 - (*tmem_hostops.obj_free)(obj, pool);
39475 + (tmem_hostops->obj_free)(obj, pool);
39476 obj = NULL;
39477 }
39478 }
39479 if (free)
39480 - ret = (*tmem_pamops.get_data_and_free)(
39481 + ret = (tmem_pamops->get_data_and_free)(
39482 data, sizep, raw, pampd, pool, oidp, index);
39483 else
39484 - ret = (*tmem_pamops.get_data)(
39485 + ret = (tmem_pamops->get_data)(
39486 data, sizep, raw, pampd, pool, oidp, index);
39487 if (ret < 0)
39488 goto out;
39489 @@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
39490 pampd = tmem_pampd_delete_from_obj(obj, index);
39491 if (pampd == NULL)
39492 goto out;
39493 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
39494 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
39495 if (obj->pampd_count == 0) {
39496 tmem_obj_free(obj, hb);
39497 - (*tmem_hostops.obj_free)(obj, pool);
39498 + (tmem_hostops->obj_free)(obj, pool);
39499 }
39500 ret = 0;
39501
39502 @@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
39503 goto out;
39504 tmem_pampd_destroy_all_in_obj(obj, false);
39505 tmem_obj_free(obj, hb);
39506 - (*tmem_hostops.obj_free)(obj, pool);
39507 + (tmem_hostops->obj_free)(obj, pool);
39508 ret = 0;
39509
39510 out:
39511 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
39512 index dc23395..cf7e9b1 100644
39513 --- a/drivers/staging/rtl8712/rtl871x_io.h
39514 +++ b/drivers/staging/rtl8712/rtl871x_io.h
39515 @@ -108,7 +108,7 @@ struct _io_ops {
39516 u8 *pmem);
39517 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
39518 u8 *pmem);
39519 -};
39520 +} __no_const;
39521
39522 struct io_req {
39523 struct list_head list;
39524 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
39525 index 180c963..1f18377 100644
39526 --- a/drivers/staging/sbe-2t3e3/netdev.c
39527 +++ b/drivers/staging/sbe-2t3e3/netdev.c
39528 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39529 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
39530
39531 if (rlen)
39532 - if (copy_to_user(data, &resp, rlen))
39533 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
39534 return -EFAULT;
39535
39536 return 0;
39537 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
39538 index c66b8b3..a4a035b 100644
39539 --- a/drivers/staging/usbip/vhci.h
39540 +++ b/drivers/staging/usbip/vhci.h
39541 @@ -83,7 +83,7 @@ struct vhci_hcd {
39542 unsigned resuming:1;
39543 unsigned long re_timeout;
39544
39545 - atomic_t seqnum;
39546 + atomic_unchecked_t seqnum;
39547
39548 /*
39549 * NOTE:
39550 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
39551 index 620d1be..1cd6711 100644
39552 --- a/drivers/staging/usbip/vhci_hcd.c
39553 +++ b/drivers/staging/usbip/vhci_hcd.c
39554 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
39555 return;
39556 }
39557
39558 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
39559 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39560 if (priv->seqnum == 0xffff)
39561 dev_info(&urb->dev->dev, "seqnum max\n");
39562
39563 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
39564 return -ENOMEM;
39565 }
39566
39567 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
39568 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39569 if (unlink->seqnum == 0xffff)
39570 pr_info("seqnum max\n");
39571
39572 @@ -924,7 +924,7 @@ static int vhci_start(struct usb_hcd *hcd)
39573 vdev->rhport = rhport;
39574 }
39575
39576 - atomic_set(&vhci->seqnum, 0);
39577 + atomic_set_unchecked(&vhci->seqnum, 0);
39578 spin_lock_init(&vhci->lock);
39579
39580 hcd->power_budget = 0; /* no limit */
39581 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
39582 index f0eaf04..5a82e06 100644
39583 --- a/drivers/staging/usbip/vhci_rx.c
39584 +++ b/drivers/staging/usbip/vhci_rx.c
39585 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
39586 if (!urb) {
39587 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
39588 pr_info("max seqnum %d\n",
39589 - atomic_read(&the_controller->seqnum));
39590 + atomic_read_unchecked(&the_controller->seqnum));
39591 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
39592 return;
39593 }
39594 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
39595 index 67b1b88..6392fe9 100644
39596 --- a/drivers/staging/vt6655/hostap.c
39597 +++ b/drivers/staging/vt6655/hostap.c
39598 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
39599 *
39600 */
39601
39602 +static net_device_ops_no_const apdev_netdev_ops;
39603 +
39604 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39605 {
39606 PSDevice apdev_priv;
39607 struct net_device *dev = pDevice->dev;
39608 int ret;
39609 - const struct net_device_ops apdev_netdev_ops = {
39610 - .ndo_start_xmit = pDevice->tx_80211,
39611 - };
39612
39613 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39614
39615 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39616 *apdev_priv = *pDevice;
39617 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39618
39619 + /* only half broken now */
39620 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39621 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39622
39623 pDevice->apdev->type = ARPHRD_IEEE80211;
39624 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
39625 index 0a73d40..6fda560 100644
39626 --- a/drivers/staging/vt6656/hostap.c
39627 +++ b/drivers/staging/vt6656/hostap.c
39628 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
39629 *
39630 */
39631
39632 +static net_device_ops_no_const apdev_netdev_ops;
39633 +
39634 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39635 {
39636 PSDevice apdev_priv;
39637 struct net_device *dev = pDevice->dev;
39638 int ret;
39639 - const struct net_device_ops apdev_netdev_ops = {
39640 - .ndo_start_xmit = pDevice->tx_80211,
39641 - };
39642
39643 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39644
39645 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39646 *apdev_priv = *pDevice;
39647 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39648
39649 + /* only half broken now */
39650 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39651 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39652
39653 pDevice->apdev->type = ARPHRD_IEEE80211;
39654 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
39655 index 56c8e60..1920c63 100644
39656 --- a/drivers/staging/zcache/tmem.c
39657 +++ b/drivers/staging/zcache/tmem.c
39658 @@ -39,7 +39,7 @@
39659 * A tmem host implementation must use this function to register callbacks
39660 * for memory allocation.
39661 */
39662 -static struct tmem_hostops tmem_hostops;
39663 +static tmem_hostops_no_const tmem_hostops;
39664
39665 static void tmem_objnode_tree_init(void);
39666
39667 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
39668 * A tmem host implementation must use this function to register
39669 * callbacks for a page-accessible memory (PAM) implementation
39670 */
39671 -static struct tmem_pamops tmem_pamops;
39672 +static tmem_pamops_no_const tmem_pamops;
39673
39674 void tmem_register_pamops(struct tmem_pamops *m)
39675 {
39676 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
39677 index 0d4aa82..f7832d4 100644
39678 --- a/drivers/staging/zcache/tmem.h
39679 +++ b/drivers/staging/zcache/tmem.h
39680 @@ -180,6 +180,7 @@ struct tmem_pamops {
39681 void (*new_obj)(struct tmem_obj *);
39682 int (*replace_in_obj)(void *, struct tmem_obj *);
39683 };
39684 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
39685 extern void tmem_register_pamops(struct tmem_pamops *m);
39686
39687 /* memory allocation methods provided by the host implementation */
39688 @@ -189,6 +190,7 @@ struct tmem_hostops {
39689 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
39690 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
39691 };
39692 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
39693 extern void tmem_register_hostops(struct tmem_hostops *m);
39694
39695 /* core tmem accessor functions */
39696 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
39697 index 13fe16c..cbdc39a 100644
39698 --- a/drivers/target/target_core_transport.c
39699 +++ b/drivers/target/target_core_transport.c
39700 @@ -1085,7 +1085,7 @@ struct se_device *transport_add_device_to_core_hba(
39701 spin_lock_init(&dev->se_port_lock);
39702 spin_lock_init(&dev->se_tmr_lock);
39703 spin_lock_init(&dev->qf_cmd_lock);
39704 - atomic_set(&dev->dev_ordered_id, 0);
39705 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
39706
39707 se_dev_set_default_attribs(dev, dev_limits);
39708
39709 @@ -1275,7 +1275,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
39710 * Used to determine when ORDERED commands should go from
39711 * Dormant to Active status.
39712 */
39713 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
39714 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
39715 smp_mb__after_atomic_inc();
39716 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
39717 cmd->se_ordered_id, cmd->sam_task_attr,
39718 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
39719 index 0a6a0bc..5501b06 100644
39720 --- a/drivers/tty/cyclades.c
39721 +++ b/drivers/tty/cyclades.c
39722 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
39723 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
39724 info->port.count);
39725 #endif
39726 - info->port.count++;
39727 + atomic_inc(&info->port.count);
39728 #ifdef CY_DEBUG_COUNT
39729 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
39730 - current->pid, info->port.count);
39731 + current->pid, atomic_read(&info->port.count));
39732 #endif
39733
39734 /*
39735 @@ -3989,7 +3989,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
39736 for (j = 0; j < cy_card[i].nports; j++) {
39737 info = &cy_card[i].ports[j];
39738
39739 - if (info->port.count) {
39740 + if (atomic_read(&info->port.count)) {
39741 /* XXX is the ldisc num worth this? */
39742 struct tty_struct *tty;
39743 struct tty_ldisc *ld;
39744 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
39745 index 13ee53b..418d164 100644
39746 --- a/drivers/tty/hvc/hvc_console.c
39747 +++ b/drivers/tty/hvc/hvc_console.c
39748 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
39749
39750 spin_lock_irqsave(&hp->port.lock, flags);
39751 /* Check and then increment for fast path open. */
39752 - if (hp->port.count++ > 0) {
39753 + if (atomic_inc_return(&hp->port.count) > 1) {
39754 spin_unlock_irqrestore(&hp->port.lock, flags);
39755 hvc_kick();
39756 return 0;
39757 @@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39758
39759 spin_lock_irqsave(&hp->port.lock, flags);
39760
39761 - if (--hp->port.count == 0) {
39762 + if (atomic_dec_return(&hp->port.count) == 0) {
39763 spin_unlock_irqrestore(&hp->port.lock, flags);
39764 /* We are done with the tty pointer now. */
39765 tty_port_tty_set(&hp->port, NULL);
39766 @@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39767 */
39768 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
39769 } else {
39770 - if (hp->port.count < 0)
39771 + if (atomic_read(&hp->port.count) < 0)
39772 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
39773 - hp->vtermno, hp->port.count);
39774 + hp->vtermno, atomic_read(&hp->port.count));
39775 spin_unlock_irqrestore(&hp->port.lock, flags);
39776 }
39777 }
39778 @@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
39779 * open->hangup case this can be called after the final close so prevent
39780 * that from happening for now.
39781 */
39782 - if (hp->port.count <= 0) {
39783 + if (atomic_read(&hp->port.count) <= 0) {
39784 spin_unlock_irqrestore(&hp->port.lock, flags);
39785 return;
39786 }
39787
39788 - hp->port.count = 0;
39789 + atomic_set(&hp->port.count, 0);
39790 spin_unlock_irqrestore(&hp->port.lock, flags);
39791 tty_port_tty_set(&hp->port, NULL);
39792
39793 @@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
39794 return -EPIPE;
39795
39796 /* FIXME what's this (unprotected) check for? */
39797 - if (hp->port.count <= 0)
39798 + if (atomic_read(&hp->port.count) <= 0)
39799 return -EIO;
39800
39801 spin_lock_irqsave(&hp->lock, flags);
39802 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
39803 index cab5c7a..4cc66ea 100644
39804 --- a/drivers/tty/hvc/hvcs.c
39805 +++ b/drivers/tty/hvc/hvcs.c
39806 @@ -83,6 +83,7 @@
39807 #include <asm/hvcserver.h>
39808 #include <asm/uaccess.h>
39809 #include <asm/vio.h>
39810 +#include <asm/local.h>
39811
39812 /*
39813 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
39814 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
39815
39816 spin_lock_irqsave(&hvcsd->lock, flags);
39817
39818 - if (hvcsd->port.count > 0) {
39819 + if (atomic_read(&hvcsd->port.count) > 0) {
39820 spin_unlock_irqrestore(&hvcsd->lock, flags);
39821 printk(KERN_INFO "HVCS: vterm state unchanged. "
39822 "The hvcs device node is still in use.\n");
39823 @@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
39824 }
39825 }
39826
39827 - hvcsd->port.count = 0;
39828 + atomic_set(&hvcsd->port.count, 0);
39829 hvcsd->port.tty = tty;
39830 tty->driver_data = hvcsd;
39831
39832 @@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
39833 unsigned long flags;
39834
39835 spin_lock_irqsave(&hvcsd->lock, flags);
39836 - hvcsd->port.count++;
39837 + atomic_inc(&hvcsd->port.count);
39838 hvcsd->todo_mask |= HVCS_SCHED_READ;
39839 spin_unlock_irqrestore(&hvcsd->lock, flags);
39840
39841 @@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39842 hvcsd = tty->driver_data;
39843
39844 spin_lock_irqsave(&hvcsd->lock, flags);
39845 - if (--hvcsd->port.count == 0) {
39846 + if (atomic_dec_and_test(&hvcsd->port.count)) {
39847
39848 vio_disable_interrupts(hvcsd->vdev);
39849
39850 @@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39851
39852 free_irq(irq, hvcsd);
39853 return;
39854 - } else if (hvcsd->port.count < 0) {
39855 + } else if (atomic_read(&hvcsd->port.count) < 0) {
39856 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
39857 " is missmanaged.\n",
39858 - hvcsd->vdev->unit_address, hvcsd->port.count);
39859 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
39860 }
39861
39862 spin_unlock_irqrestore(&hvcsd->lock, flags);
39863 @@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39864
39865 spin_lock_irqsave(&hvcsd->lock, flags);
39866 /* Preserve this so that we know how many kref refs to put */
39867 - temp_open_count = hvcsd->port.count;
39868 + temp_open_count = atomic_read(&hvcsd->port.count);
39869
39870 /*
39871 * Don't kref put inside the spinlock because the destruction
39872 @@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39873 tty->driver_data = NULL;
39874 hvcsd->port.tty = NULL;
39875
39876 - hvcsd->port.count = 0;
39877 + atomic_set(&hvcsd->port.count, 0);
39878
39879 /* This will drop any buffered data on the floor which is OK in a hangup
39880 * scenario. */
39881 @@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
39882 * the middle of a write operation? This is a crummy place to do this
39883 * but we want to keep it all in the spinlock.
39884 */
39885 - if (hvcsd->port.count <= 0) {
39886 + if (atomic_read(&hvcsd->port.count) <= 0) {
39887 spin_unlock_irqrestore(&hvcsd->lock, flags);
39888 return -ENODEV;
39889 }
39890 @@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
39891 {
39892 struct hvcs_struct *hvcsd = tty->driver_data;
39893
39894 - if (!hvcsd || hvcsd->port.count <= 0)
39895 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
39896 return 0;
39897
39898 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
39899 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
39900 index 160f0ad..588b853 100644
39901 --- a/drivers/tty/ipwireless/tty.c
39902 +++ b/drivers/tty/ipwireless/tty.c
39903 @@ -29,6 +29,7 @@
39904 #include <linux/tty_driver.h>
39905 #include <linux/tty_flip.h>
39906 #include <linux/uaccess.h>
39907 +#include <asm/local.h>
39908
39909 #include "tty.h"
39910 #include "network.h"
39911 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39912 mutex_unlock(&tty->ipw_tty_mutex);
39913 return -ENODEV;
39914 }
39915 - if (tty->port.count == 0)
39916 + if (atomic_read(&tty->port.count) == 0)
39917 tty->tx_bytes_queued = 0;
39918
39919 - tty->port.count++;
39920 + atomic_inc(&tty->port.count);
39921
39922 tty->port.tty = linux_tty;
39923 linux_tty->driver_data = tty;
39924 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39925
39926 static void do_ipw_close(struct ipw_tty *tty)
39927 {
39928 - tty->port.count--;
39929 -
39930 - if (tty->port.count == 0) {
39931 + if (atomic_dec_return(&tty->port.count) == 0) {
39932 struct tty_struct *linux_tty = tty->port.tty;
39933
39934 if (linux_tty != NULL) {
39935 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
39936 return;
39937
39938 mutex_lock(&tty->ipw_tty_mutex);
39939 - if (tty->port.count == 0) {
39940 + if (atomic_read(&tty->port.count) == 0) {
39941 mutex_unlock(&tty->ipw_tty_mutex);
39942 return;
39943 }
39944 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
39945 return;
39946 }
39947
39948 - if (!tty->port.count) {
39949 + if (!atomic_read(&tty->port.count)) {
39950 mutex_unlock(&tty->ipw_tty_mutex);
39951 return;
39952 }
39953 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
39954 return -ENODEV;
39955
39956 mutex_lock(&tty->ipw_tty_mutex);
39957 - if (!tty->port.count) {
39958 + if (!atomic_read(&tty->port.count)) {
39959 mutex_unlock(&tty->ipw_tty_mutex);
39960 return -EINVAL;
39961 }
39962 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
39963 if (!tty)
39964 return -ENODEV;
39965
39966 - if (!tty->port.count)
39967 + if (!atomic_read(&tty->port.count))
39968 return -EINVAL;
39969
39970 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
39971 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
39972 if (!tty)
39973 return 0;
39974
39975 - if (!tty->port.count)
39976 + if (!atomic_read(&tty->port.count))
39977 return 0;
39978
39979 return tty->tx_bytes_queued;
39980 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
39981 if (!tty)
39982 return -ENODEV;
39983
39984 - if (!tty->port.count)
39985 + if (!atomic_read(&tty->port.count))
39986 return -EINVAL;
39987
39988 return get_control_lines(tty);
39989 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
39990 if (!tty)
39991 return -ENODEV;
39992
39993 - if (!tty->port.count)
39994 + if (!atomic_read(&tty->port.count))
39995 return -EINVAL;
39996
39997 return set_control_lines(tty, set, clear);
39998 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
39999 if (!tty)
40000 return -ENODEV;
40001
40002 - if (!tty->port.count)
40003 + if (!atomic_read(&tty->port.count))
40004 return -EINVAL;
40005
40006 /* FIXME: Exactly how is the tty object locked here .. */
40007 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
40008 * are gone */
40009 mutex_lock(&ttyj->ipw_tty_mutex);
40010 }
40011 - while (ttyj->port.count)
40012 + while (atomic_read(&ttyj->port.count))
40013 do_ipw_close(ttyj);
40014 ipwireless_disassociate_network_ttys(network,
40015 ttyj->channel_idx);
40016 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
40017 index 56e616b..9d9f10a 100644
40018 --- a/drivers/tty/moxa.c
40019 +++ b/drivers/tty/moxa.c
40020 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
40021 }
40022
40023 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
40024 - ch->port.count++;
40025 + atomic_inc(&ch->port.count);
40026 tty->driver_data = ch;
40027 tty_port_tty_set(&ch->port, tty);
40028 mutex_lock(&ch->port.mutex);
40029 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
40030 index 1e8e8ce..a9efc93 100644
40031 --- a/drivers/tty/n_gsm.c
40032 +++ b/drivers/tty/n_gsm.c
40033 @@ -1638,7 +1638,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
40034 kref_init(&dlci->ref);
40035 mutex_init(&dlci->mutex);
40036 dlci->fifo = &dlci->_fifo;
40037 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
40038 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
40039 kfree(dlci);
40040 return NULL;
40041 }
40042 @@ -2925,7 +2925,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
40043 struct gsm_dlci *dlci = tty->driver_data;
40044 struct tty_port *port = &dlci->port;
40045
40046 - port->count++;
40047 + atomic_inc(&port->count);
40048 dlci_get(dlci);
40049 dlci_get(dlci->gsm->dlci[0]);
40050 mux_get(dlci->gsm);
40051 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
40052 index 8c0b7b4..e88f052 100644
40053 --- a/drivers/tty/n_tty.c
40054 +++ b/drivers/tty/n_tty.c
40055 @@ -2142,6 +2142,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
40056 {
40057 *ops = tty_ldisc_N_TTY;
40058 ops->owner = NULL;
40059 - ops->refcount = ops->flags = 0;
40060 + atomic_set(&ops->refcount, 0);
40061 + ops->flags = 0;
40062 }
40063 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
40064 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
40065 index 8cf8d0a..4ef9ed0 100644
40066 --- a/drivers/tty/pty.c
40067 +++ b/drivers/tty/pty.c
40068 @@ -730,8 +730,10 @@ static void __init unix98_pty_init(void)
40069 panic("Couldn't register Unix98 pts driver");
40070
40071 /* Now create the /dev/ptmx special device */
40072 + pax_open_kernel();
40073 tty_default_fops(&ptmx_fops);
40074 - ptmx_fops.open = ptmx_open;
40075 + *(void **)&ptmx_fops.open = ptmx_open;
40076 + pax_close_kernel();
40077
40078 cdev_init(&ptmx_cdev, &ptmx_fops);
40079 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
40080 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
40081 index 9700d34..df7520c 100644
40082 --- a/drivers/tty/rocket.c
40083 +++ b/drivers/tty/rocket.c
40084 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40085 tty->driver_data = info;
40086 tty_port_tty_set(port, tty);
40087
40088 - if (port->count++ == 0) {
40089 + if (atomic_inc_return(&port->count) == 1) {
40090 atomic_inc(&rp_num_ports_open);
40091
40092 #ifdef ROCKET_DEBUG_OPEN
40093 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40094 #endif
40095 }
40096 #ifdef ROCKET_DEBUG_OPEN
40097 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
40098 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
40099 #endif
40100
40101 /*
40102 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
40103 spin_unlock_irqrestore(&info->port.lock, flags);
40104 return;
40105 }
40106 - if (info->port.count)
40107 + if (atomic_read(&info->port.count))
40108 atomic_dec(&rp_num_ports_open);
40109 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
40110 spin_unlock_irqrestore(&info->port.lock, flags);
40111 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
40112 index 1002054..dd644a8 100644
40113 --- a/drivers/tty/serial/kgdboc.c
40114 +++ b/drivers/tty/serial/kgdboc.c
40115 @@ -24,8 +24,9 @@
40116 #define MAX_CONFIG_LEN 40
40117
40118 static struct kgdb_io kgdboc_io_ops;
40119 +static struct kgdb_io kgdboc_io_ops_console;
40120
40121 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
40122 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
40123 static int configured = -1;
40124
40125 static char config[MAX_CONFIG_LEN];
40126 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
40127 kgdboc_unregister_kbd();
40128 if (configured == 1)
40129 kgdb_unregister_io_module(&kgdboc_io_ops);
40130 + else if (configured == 2)
40131 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
40132 }
40133
40134 static int configure_kgdboc(void)
40135 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
40136 int err;
40137 char *cptr = config;
40138 struct console *cons;
40139 + int is_console = 0;
40140
40141 err = kgdboc_option_setup(config);
40142 if (err || !strlen(config) || isspace(config[0]))
40143 goto noconfig;
40144
40145 err = -ENODEV;
40146 - kgdboc_io_ops.is_console = 0;
40147 kgdb_tty_driver = NULL;
40148
40149 kgdboc_use_kms = 0;
40150 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
40151 int idx;
40152 if (cons->device && cons->device(cons, &idx) == p &&
40153 idx == tty_line) {
40154 - kgdboc_io_ops.is_console = 1;
40155 + is_console = 1;
40156 break;
40157 }
40158 cons = cons->next;
40159 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
40160 kgdb_tty_line = tty_line;
40161
40162 do_register:
40163 - err = kgdb_register_io_module(&kgdboc_io_ops);
40164 + if (is_console) {
40165 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
40166 + configured = 2;
40167 + } else {
40168 + err = kgdb_register_io_module(&kgdboc_io_ops);
40169 + configured = 1;
40170 + }
40171 if (err)
40172 goto noconfig;
40173
40174 @@ -205,8 +214,6 @@ do_register:
40175 if (err)
40176 goto nmi_con_failed;
40177
40178 - configured = 1;
40179 -
40180 return 0;
40181
40182 nmi_con_failed:
40183 @@ -223,7 +230,7 @@ noconfig:
40184 static int __init init_kgdboc(void)
40185 {
40186 /* Already configured? */
40187 - if (configured == 1)
40188 + if (configured >= 1)
40189 return 0;
40190
40191 return configure_kgdboc();
40192 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
40193 if (config[len - 1] == '\n')
40194 config[len - 1] = '\0';
40195
40196 - if (configured == 1)
40197 + if (configured >= 1)
40198 cleanup_kgdboc();
40199
40200 /* Go and configure with the new params. */
40201 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
40202 .post_exception = kgdboc_post_exp_handler,
40203 };
40204
40205 +static struct kgdb_io kgdboc_io_ops_console = {
40206 + .name = "kgdboc",
40207 + .read_char = kgdboc_get_char,
40208 + .write_char = kgdboc_put_char,
40209 + .pre_exception = kgdboc_pre_exp_handler,
40210 + .post_exception = kgdboc_post_exp_handler,
40211 + .is_console = 1
40212 +};
40213 +
40214 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
40215 /* This is only available if kgdboc is a built in for early debugging */
40216 static int __init kgdboc_early_init(char *opt)
40217 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
40218 index 7f04717..0f3794f 100644
40219 --- a/drivers/tty/serial/samsung.c
40220 +++ b/drivers/tty/serial/samsung.c
40221 @@ -445,11 +445,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
40222 }
40223 }
40224
40225 +static int s3c64xx_serial_startup(struct uart_port *port);
40226 static int s3c24xx_serial_startup(struct uart_port *port)
40227 {
40228 struct s3c24xx_uart_port *ourport = to_ourport(port);
40229 int ret;
40230
40231 + /* Startup sequence is different for s3c64xx and higher SoC's */
40232 + if (s3c24xx_serial_has_interrupt_mask(port))
40233 + return s3c64xx_serial_startup(port);
40234 +
40235 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
40236 port->mapbase, port->membase);
40237
40238 @@ -1115,10 +1120,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
40239 /* setup info for port */
40240 port->dev = &platdev->dev;
40241
40242 - /* Startup sequence is different for s3c64xx and higher SoC's */
40243 - if (s3c24xx_serial_has_interrupt_mask(port))
40244 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
40245 -
40246 port->uartclk = 1;
40247
40248 if (cfg->uart_flags & UPF_CONS_FLOW) {
40249 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
40250 index 0fcfd98..8244fce 100644
40251 --- a/drivers/tty/serial/serial_core.c
40252 +++ b/drivers/tty/serial/serial_core.c
40253 @@ -1408,7 +1408,7 @@ static void uart_hangup(struct tty_struct *tty)
40254 uart_flush_buffer(tty);
40255 uart_shutdown(tty, state);
40256 spin_lock_irqsave(&port->lock, flags);
40257 - port->count = 0;
40258 + atomic_set(&port->count, 0);
40259 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
40260 spin_unlock_irqrestore(&port->lock, flags);
40261 tty_port_tty_set(port, NULL);
40262 @@ -1504,7 +1504,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40263 goto end;
40264 }
40265
40266 - port->count++;
40267 + atomic_inc(&port->count);
40268 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
40269 retval = -ENXIO;
40270 goto err_dec_count;
40271 @@ -1531,7 +1531,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40272 /*
40273 * Make sure the device is in D0 state.
40274 */
40275 - if (port->count == 1)
40276 + if (atomic_read(&port->count) == 1)
40277 uart_change_pm(state, 0);
40278
40279 /*
40280 @@ -1549,7 +1549,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40281 end:
40282 return retval;
40283 err_dec_count:
40284 - port->count--;
40285 + atomic_inc(&port->count);
40286 mutex_unlock(&port->mutex);
40287 goto end;
40288 }
40289 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
40290 index 70e3a52..5742052 100644
40291 --- a/drivers/tty/synclink.c
40292 +++ b/drivers/tty/synclink.c
40293 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40294
40295 if (debug_level >= DEBUG_LEVEL_INFO)
40296 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
40297 - __FILE__,__LINE__, info->device_name, info->port.count);
40298 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40299
40300 if (tty_port_close_start(&info->port, tty, filp) == 0)
40301 goto cleanup;
40302 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40303 cleanup:
40304 if (debug_level >= DEBUG_LEVEL_INFO)
40305 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
40306 - tty->driver->name, info->port.count);
40307 + tty->driver->name, atomic_read(&info->port.count));
40308
40309 } /* end of mgsl_close() */
40310
40311 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
40312
40313 mgsl_flush_buffer(tty);
40314 shutdown(info);
40315 -
40316 - info->port.count = 0;
40317 +
40318 + atomic_set(&info->port.count, 0);
40319 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40320 info->port.tty = NULL;
40321
40322 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40323
40324 if (debug_level >= DEBUG_LEVEL_INFO)
40325 printk("%s(%d):block_til_ready before block on %s count=%d\n",
40326 - __FILE__,__LINE__, tty->driver->name, port->count );
40327 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40328
40329 spin_lock_irqsave(&info->irq_spinlock, flags);
40330 if (!tty_hung_up_p(filp)) {
40331 extra_count = true;
40332 - port->count--;
40333 + atomic_dec(&port->count);
40334 }
40335 spin_unlock_irqrestore(&info->irq_spinlock, flags);
40336 port->blocked_open++;
40337 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40338
40339 if (debug_level >= DEBUG_LEVEL_INFO)
40340 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
40341 - __FILE__,__LINE__, tty->driver->name, port->count );
40342 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40343
40344 tty_unlock(tty);
40345 schedule();
40346 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40347
40348 /* FIXME: Racy on hangup during close wait */
40349 if (extra_count)
40350 - port->count++;
40351 + atomic_inc(&port->count);
40352 port->blocked_open--;
40353
40354 if (debug_level >= DEBUG_LEVEL_INFO)
40355 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
40356 - __FILE__,__LINE__, tty->driver->name, port->count );
40357 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40358
40359 if (!retval)
40360 port->flags |= ASYNC_NORMAL_ACTIVE;
40361 @@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
40362
40363 if (debug_level >= DEBUG_LEVEL_INFO)
40364 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
40365 - __FILE__,__LINE__,tty->driver->name, info->port.count);
40366 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
40367
40368 /* If port is closing, signal caller to try again */
40369 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40370 @@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
40371 spin_unlock_irqrestore(&info->netlock, flags);
40372 goto cleanup;
40373 }
40374 - info->port.count++;
40375 + atomic_inc(&info->port.count);
40376 spin_unlock_irqrestore(&info->netlock, flags);
40377
40378 - if (info->port.count == 1) {
40379 + if (atomic_read(&info->port.count) == 1) {
40380 /* 1st open on this device, init hardware */
40381 retval = startup(info);
40382 if (retval < 0)
40383 @@ -3451,8 +3451,8 @@ cleanup:
40384 if (retval) {
40385 if (tty->count == 1)
40386 info->port.tty = NULL; /* tty layer will release tty struct */
40387 - if(info->port.count)
40388 - info->port.count--;
40389 + if (atomic_read(&info->port.count))
40390 + atomic_dec(&info->port.count);
40391 }
40392
40393 return retval;
40394 @@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40395 unsigned short new_crctype;
40396
40397 /* return error if TTY interface open */
40398 - if (info->port.count)
40399 + if (atomic_read(&info->port.count))
40400 return -EBUSY;
40401
40402 switch (encoding)
40403 @@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
40404
40405 /* arbitrate between network and tty opens */
40406 spin_lock_irqsave(&info->netlock, flags);
40407 - if (info->port.count != 0 || info->netcount != 0) {
40408 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40409 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40410 spin_unlock_irqrestore(&info->netlock, flags);
40411 return -EBUSY;
40412 @@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40413 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
40414
40415 /* return error if TTY interface open */
40416 - if (info->port.count)
40417 + if (atomic_read(&info->port.count))
40418 return -EBUSY;
40419
40420 if (cmd != SIOCWANDEV)
40421 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
40422 index b38e954..ce45b38 100644
40423 --- a/drivers/tty/synclink_gt.c
40424 +++ b/drivers/tty/synclink_gt.c
40425 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
40426 tty->driver_data = info;
40427 info->port.tty = tty;
40428
40429 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
40430 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
40431
40432 /* If port is closing, signal caller to try again */
40433 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40434 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
40435 mutex_unlock(&info->port.mutex);
40436 goto cleanup;
40437 }
40438 - info->port.count++;
40439 + atomic_inc(&info->port.count);
40440 spin_unlock_irqrestore(&info->netlock, flags);
40441
40442 - if (info->port.count == 1) {
40443 + if (atomic_read(&info->port.count) == 1) {
40444 /* 1st open on this device, init hardware */
40445 retval = startup(info);
40446 if (retval < 0) {
40447 @@ -716,8 +716,8 @@ cleanup:
40448 if (retval) {
40449 if (tty->count == 1)
40450 info->port.tty = NULL; /* tty layer will release tty struct */
40451 - if(info->port.count)
40452 - info->port.count--;
40453 + if(atomic_read(&info->port.count))
40454 + atomic_dec(&info->port.count);
40455 }
40456
40457 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
40458 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40459
40460 if (sanity_check(info, tty->name, "close"))
40461 return;
40462 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
40463 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
40464
40465 if (tty_port_close_start(&info->port, tty, filp) == 0)
40466 goto cleanup;
40467 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40468 tty_port_close_end(&info->port, tty);
40469 info->port.tty = NULL;
40470 cleanup:
40471 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
40472 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
40473 }
40474
40475 static void hangup(struct tty_struct *tty)
40476 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
40477 shutdown(info);
40478
40479 spin_lock_irqsave(&info->port.lock, flags);
40480 - info->port.count = 0;
40481 + atomic_set(&info->port.count, 0);
40482 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40483 info->port.tty = NULL;
40484 spin_unlock_irqrestore(&info->port.lock, flags);
40485 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40486 unsigned short new_crctype;
40487
40488 /* return error if TTY interface open */
40489 - if (info->port.count)
40490 + if (atomic_read(&info->port.count))
40491 return -EBUSY;
40492
40493 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
40494 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
40495
40496 /* arbitrate between network and tty opens */
40497 spin_lock_irqsave(&info->netlock, flags);
40498 - if (info->port.count != 0 || info->netcount != 0) {
40499 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40500 DBGINFO(("%s hdlc_open busy\n", dev->name));
40501 spin_unlock_irqrestore(&info->netlock, flags);
40502 return -EBUSY;
40503 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40504 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
40505
40506 /* return error if TTY interface open */
40507 - if (info->port.count)
40508 + if (atomic_read(&info->port.count))
40509 return -EBUSY;
40510
40511 if (cmd != SIOCWANDEV)
40512 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
40513 if (port == NULL)
40514 continue;
40515 spin_lock(&port->lock);
40516 - if ((port->port.count || port->netcount) &&
40517 + if ((atomic_read(&port->port.count) || port->netcount) &&
40518 port->pending_bh && !port->bh_running &&
40519 !port->bh_requested) {
40520 DBGISR(("%s bh queued\n", port->device_name));
40521 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40522 spin_lock_irqsave(&info->lock, flags);
40523 if (!tty_hung_up_p(filp)) {
40524 extra_count = true;
40525 - port->count--;
40526 + atomic_dec(&port->count);
40527 }
40528 spin_unlock_irqrestore(&info->lock, flags);
40529 port->blocked_open++;
40530 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40531 remove_wait_queue(&port->open_wait, &wait);
40532
40533 if (extra_count)
40534 - port->count++;
40535 + atomic_inc(&port->count);
40536 port->blocked_open--;
40537
40538 if (!retval)
40539 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
40540 index f17d9f3..27a041b 100644
40541 --- a/drivers/tty/synclinkmp.c
40542 +++ b/drivers/tty/synclinkmp.c
40543 @@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
40544
40545 if (debug_level >= DEBUG_LEVEL_INFO)
40546 printk("%s(%d):%s open(), old ref count = %d\n",
40547 - __FILE__,__LINE__,tty->driver->name, info->port.count);
40548 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
40549
40550 /* If port is closing, signal caller to try again */
40551 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40552 @@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
40553 spin_unlock_irqrestore(&info->netlock, flags);
40554 goto cleanup;
40555 }
40556 - info->port.count++;
40557 + atomic_inc(&info->port.count);
40558 spin_unlock_irqrestore(&info->netlock, flags);
40559
40560 - if (info->port.count == 1) {
40561 + if (atomic_read(&info->port.count) == 1) {
40562 /* 1st open on this device, init hardware */
40563 retval = startup(info);
40564 if (retval < 0)
40565 @@ -797,8 +797,8 @@ cleanup:
40566 if (retval) {
40567 if (tty->count == 1)
40568 info->port.tty = NULL; /* tty layer will release tty struct */
40569 - if(info->port.count)
40570 - info->port.count--;
40571 + if(atomic_read(&info->port.count))
40572 + atomic_dec(&info->port.count);
40573 }
40574
40575 return retval;
40576 @@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40577
40578 if (debug_level >= DEBUG_LEVEL_INFO)
40579 printk("%s(%d):%s close() entry, count=%d\n",
40580 - __FILE__,__LINE__, info->device_name, info->port.count);
40581 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40582
40583 if (tty_port_close_start(&info->port, tty, filp) == 0)
40584 goto cleanup;
40585 @@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40586 cleanup:
40587 if (debug_level >= DEBUG_LEVEL_INFO)
40588 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
40589 - tty->driver->name, info->port.count);
40590 + tty->driver->name, atomic_read(&info->port.count));
40591 }
40592
40593 /* Called by tty_hangup() when a hangup is signaled.
40594 @@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
40595 shutdown(info);
40596
40597 spin_lock_irqsave(&info->port.lock, flags);
40598 - info->port.count = 0;
40599 + atomic_set(&info->port.count, 0);
40600 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40601 info->port.tty = NULL;
40602 spin_unlock_irqrestore(&info->port.lock, flags);
40603 @@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40604 unsigned short new_crctype;
40605
40606 /* return error if TTY interface open */
40607 - if (info->port.count)
40608 + if (atomic_read(&info->port.count))
40609 return -EBUSY;
40610
40611 switch (encoding)
40612 @@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
40613
40614 /* arbitrate between network and tty opens */
40615 spin_lock_irqsave(&info->netlock, flags);
40616 - if (info->port.count != 0 || info->netcount != 0) {
40617 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40618 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40619 spin_unlock_irqrestore(&info->netlock, flags);
40620 return -EBUSY;
40621 @@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40622 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
40623
40624 /* return error if TTY interface open */
40625 - if (info->port.count)
40626 + if (atomic_read(&info->port.count))
40627 return -EBUSY;
40628
40629 if (cmd != SIOCWANDEV)
40630 @@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
40631 * do not request bottom half processing if the
40632 * device is not open in a normal mode.
40633 */
40634 - if ( port && (port->port.count || port->netcount) &&
40635 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
40636 port->pending_bh && !port->bh_running &&
40637 !port->bh_requested ) {
40638 if ( debug_level >= DEBUG_LEVEL_ISR )
40639 @@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40640
40641 if (debug_level >= DEBUG_LEVEL_INFO)
40642 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
40643 - __FILE__,__LINE__, tty->driver->name, port->count );
40644 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40645
40646 spin_lock_irqsave(&info->lock, flags);
40647 if (!tty_hung_up_p(filp)) {
40648 extra_count = true;
40649 - port->count--;
40650 + atomic_dec(&port->count);
40651 }
40652 spin_unlock_irqrestore(&info->lock, flags);
40653 port->blocked_open++;
40654 @@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40655
40656 if (debug_level >= DEBUG_LEVEL_INFO)
40657 printk("%s(%d):%s block_til_ready() count=%d\n",
40658 - __FILE__,__LINE__, tty->driver->name, port->count );
40659 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40660
40661 tty_unlock(tty);
40662 schedule();
40663 @@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40664 remove_wait_queue(&port->open_wait, &wait);
40665
40666 if (extra_count)
40667 - port->count++;
40668 + atomic_inc(&port->count);
40669 port->blocked_open--;
40670
40671 if (debug_level >= DEBUG_LEVEL_INFO)
40672 printk("%s(%d):%s block_til_ready() after, count=%d\n",
40673 - __FILE__,__LINE__, tty->driver->name, port->count );
40674 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40675
40676 if (!retval)
40677 port->flags |= ASYNC_NORMAL_ACTIVE;
40678 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
40679 index 16ee6ce..bfcac57 100644
40680 --- a/drivers/tty/sysrq.c
40681 +++ b/drivers/tty/sysrq.c
40682 @@ -866,7 +866,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
40683 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
40684 size_t count, loff_t *ppos)
40685 {
40686 - if (count) {
40687 + if (count && capable(CAP_SYS_ADMIN)) {
40688 char c;
40689
40690 if (get_user(c, buf))
40691 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
40692 index 2ea176b..2877bc8 100644
40693 --- a/drivers/tty/tty_io.c
40694 +++ b/drivers/tty/tty_io.c
40695 @@ -3395,7 +3395,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
40696
40697 void tty_default_fops(struct file_operations *fops)
40698 {
40699 - *fops = tty_fops;
40700 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
40701 }
40702
40703 /*
40704 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
40705 index 0f2a2c5..471e228 100644
40706 --- a/drivers/tty/tty_ldisc.c
40707 +++ b/drivers/tty/tty_ldisc.c
40708 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
40709 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
40710 struct tty_ldisc_ops *ldo = ld->ops;
40711
40712 - ldo->refcount--;
40713 + atomic_dec(&ldo->refcount);
40714 module_put(ldo->owner);
40715 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40716
40717 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
40718 spin_lock_irqsave(&tty_ldisc_lock, flags);
40719 tty_ldiscs[disc] = new_ldisc;
40720 new_ldisc->num = disc;
40721 - new_ldisc->refcount = 0;
40722 + atomic_set(&new_ldisc->refcount, 0);
40723 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40724
40725 return ret;
40726 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
40727 return -EINVAL;
40728
40729 spin_lock_irqsave(&tty_ldisc_lock, flags);
40730 - if (tty_ldiscs[disc]->refcount)
40731 + if (atomic_read(&tty_ldiscs[disc]->refcount))
40732 ret = -EBUSY;
40733 else
40734 tty_ldiscs[disc] = NULL;
40735 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
40736 if (ldops) {
40737 ret = ERR_PTR(-EAGAIN);
40738 if (try_module_get(ldops->owner)) {
40739 - ldops->refcount++;
40740 + atomic_inc(&ldops->refcount);
40741 ret = ldops;
40742 }
40743 }
40744 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
40745 unsigned long flags;
40746
40747 spin_lock_irqsave(&tty_ldisc_lock, flags);
40748 - ldops->refcount--;
40749 + atomic_dec(&ldops->refcount);
40750 module_put(ldops->owner);
40751 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40752 }
40753 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
40754 index d7bdd8d..feaef30 100644
40755 --- a/drivers/tty/tty_port.c
40756 +++ b/drivers/tty/tty_port.c
40757 @@ -202,7 +202,7 @@ void tty_port_hangup(struct tty_port *port)
40758 unsigned long flags;
40759
40760 spin_lock_irqsave(&port->lock, flags);
40761 - port->count = 0;
40762 + atomic_set(&port->count, 0);
40763 port->flags &= ~ASYNC_NORMAL_ACTIVE;
40764 if (port->tty) {
40765 set_bit(TTY_IO_ERROR, &port->tty->flags);
40766 @@ -328,7 +328,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40767 /* The port lock protects the port counts */
40768 spin_lock_irqsave(&port->lock, flags);
40769 if (!tty_hung_up_p(filp))
40770 - port->count--;
40771 + atomic_dec(&port->count);
40772 port->blocked_open++;
40773 spin_unlock_irqrestore(&port->lock, flags);
40774
40775 @@ -370,7 +370,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40776 we must not mess that up further */
40777 spin_lock_irqsave(&port->lock, flags);
40778 if (!tty_hung_up_p(filp))
40779 - port->count++;
40780 + atomic_inc(&port->count);
40781 port->blocked_open--;
40782 if (retval == 0)
40783 port->flags |= ASYNC_NORMAL_ACTIVE;
40784 @@ -390,19 +390,19 @@ int tty_port_close_start(struct tty_port *port,
40785 return 0;
40786 }
40787
40788 - if (tty->count == 1 && port->count != 1) {
40789 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
40790 printk(KERN_WARNING
40791 "tty_port_close_start: tty->count = 1 port count = %d.\n",
40792 - port->count);
40793 - port->count = 1;
40794 + atomic_read(&port->count));
40795 + atomic_set(&port->count, 1);
40796 }
40797 - if (--port->count < 0) {
40798 + if (atomic_dec_return(&port->count) < 0) {
40799 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
40800 - port->count);
40801 - port->count = 0;
40802 + atomic_read(&port->count));
40803 + atomic_set(&port->count, 0);
40804 }
40805
40806 - if (port->count) {
40807 + if (atomic_read(&port->count)) {
40808 spin_unlock_irqrestore(&port->lock, flags);
40809 if (port->ops->drop)
40810 port->ops->drop(port);
40811 @@ -500,7 +500,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
40812 {
40813 spin_lock_irq(&port->lock);
40814 if (!tty_hung_up_p(filp))
40815 - ++port->count;
40816 + atomic_inc(&port->count);
40817 spin_unlock_irq(&port->lock);
40818 tty_port_tty_set(port, tty);
40819
40820 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
40821 index 681765b..d3ccdf2 100644
40822 --- a/drivers/tty/vt/keyboard.c
40823 +++ b/drivers/tty/vt/keyboard.c
40824 @@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
40825 kbd->kbdmode == VC_OFF) &&
40826 value != KVAL(K_SAK))
40827 return; /* SAK is allowed even in raw mode */
40828 +
40829 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
40830 + {
40831 + void *func = fn_handler[value];
40832 + if (func == fn_show_state || func == fn_show_ptregs ||
40833 + func == fn_show_mem)
40834 + return;
40835 + }
40836 +#endif
40837 +
40838 fn_handler[value](vc);
40839 }
40840
40841 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40842 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
40843 return -EFAULT;
40844
40845 - if (!capable(CAP_SYS_TTY_CONFIG))
40846 - perm = 0;
40847 -
40848 switch (cmd) {
40849 case KDGKBENT:
40850 /* Ensure another thread doesn't free it under us */
40851 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40852 spin_unlock_irqrestore(&kbd_event_lock, flags);
40853 return put_user(val, &user_kbe->kb_value);
40854 case KDSKBENT:
40855 + if (!capable(CAP_SYS_TTY_CONFIG))
40856 + perm = 0;
40857 +
40858 if (!perm)
40859 return -EPERM;
40860 if (!i && v == K_NOSUCHMAP) {
40861 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40862 int i, j, k;
40863 int ret;
40864
40865 - if (!capable(CAP_SYS_TTY_CONFIG))
40866 - perm = 0;
40867 -
40868 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
40869 if (!kbs) {
40870 ret = -ENOMEM;
40871 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40872 kfree(kbs);
40873 return ((p && *p) ? -EOVERFLOW : 0);
40874 case KDSKBSENT:
40875 + if (!capable(CAP_SYS_TTY_CONFIG))
40876 + perm = 0;
40877 +
40878 if (!perm) {
40879 ret = -EPERM;
40880 goto reterr;
40881 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
40882 index 5110f36..8dc0a74 100644
40883 --- a/drivers/uio/uio.c
40884 +++ b/drivers/uio/uio.c
40885 @@ -25,6 +25,7 @@
40886 #include <linux/kobject.h>
40887 #include <linux/cdev.h>
40888 #include <linux/uio_driver.h>
40889 +#include <asm/local.h>
40890
40891 #define UIO_MAX_DEVICES (1U << MINORBITS)
40892
40893 @@ -32,10 +33,10 @@ struct uio_device {
40894 struct module *owner;
40895 struct device *dev;
40896 int minor;
40897 - atomic_t event;
40898 + atomic_unchecked_t event;
40899 struct fasync_struct *async_queue;
40900 wait_queue_head_t wait;
40901 - int vma_count;
40902 + local_t vma_count;
40903 struct uio_info *info;
40904 struct kobject *map_dir;
40905 struct kobject *portio_dir;
40906 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
40907 struct device_attribute *attr, char *buf)
40908 {
40909 struct uio_device *idev = dev_get_drvdata(dev);
40910 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
40911 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
40912 }
40913
40914 static struct device_attribute uio_class_attributes[] = {
40915 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
40916 {
40917 struct uio_device *idev = info->uio_dev;
40918
40919 - atomic_inc(&idev->event);
40920 + atomic_inc_unchecked(&idev->event);
40921 wake_up_interruptible(&idev->wait);
40922 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
40923 }
40924 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
40925 }
40926
40927 listener->dev = idev;
40928 - listener->event_count = atomic_read(&idev->event);
40929 + listener->event_count = atomic_read_unchecked(&idev->event);
40930 filep->private_data = listener;
40931
40932 if (idev->info->open) {
40933 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
40934 return -EIO;
40935
40936 poll_wait(filep, &idev->wait, wait);
40937 - if (listener->event_count != atomic_read(&idev->event))
40938 + if (listener->event_count != atomic_read_unchecked(&idev->event))
40939 return POLLIN | POLLRDNORM;
40940 return 0;
40941 }
40942 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
40943 do {
40944 set_current_state(TASK_INTERRUPTIBLE);
40945
40946 - event_count = atomic_read(&idev->event);
40947 + event_count = atomic_read_unchecked(&idev->event);
40948 if (event_count != listener->event_count) {
40949 if (copy_to_user(buf, &event_count, count))
40950 retval = -EFAULT;
40951 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
40952 static void uio_vma_open(struct vm_area_struct *vma)
40953 {
40954 struct uio_device *idev = vma->vm_private_data;
40955 - idev->vma_count++;
40956 + local_inc(&idev->vma_count);
40957 }
40958
40959 static void uio_vma_close(struct vm_area_struct *vma)
40960 {
40961 struct uio_device *idev = vma->vm_private_data;
40962 - idev->vma_count--;
40963 + local_dec(&idev->vma_count);
40964 }
40965
40966 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40967 @@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
40968 idev->owner = owner;
40969 idev->info = info;
40970 init_waitqueue_head(&idev->wait);
40971 - atomic_set(&idev->event, 0);
40972 + atomic_set_unchecked(&idev->event, 0);
40973
40974 ret = uio_get_minor(idev);
40975 if (ret)
40976 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
40977 index b7eb86a..36d28af 100644
40978 --- a/drivers/usb/atm/cxacru.c
40979 +++ b/drivers/usb/atm/cxacru.c
40980 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
40981 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
40982 if (ret < 2)
40983 return -EINVAL;
40984 - if (index < 0 || index > 0x7f)
40985 + if (index > 0x7f)
40986 return -EINVAL;
40987 pos += tmp;
40988
40989 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
40990 index 35f10bf..6a38a0b 100644
40991 --- a/drivers/usb/atm/usbatm.c
40992 +++ b/drivers/usb/atm/usbatm.c
40993 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40994 if (printk_ratelimit())
40995 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
40996 __func__, vpi, vci);
40997 - atomic_inc(&vcc->stats->rx_err);
40998 + atomic_inc_unchecked(&vcc->stats->rx_err);
40999 return;
41000 }
41001
41002 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41003 if (length > ATM_MAX_AAL5_PDU) {
41004 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
41005 __func__, length, vcc);
41006 - atomic_inc(&vcc->stats->rx_err);
41007 + atomic_inc_unchecked(&vcc->stats->rx_err);
41008 goto out;
41009 }
41010
41011 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41012 if (sarb->len < pdu_length) {
41013 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
41014 __func__, pdu_length, sarb->len, vcc);
41015 - atomic_inc(&vcc->stats->rx_err);
41016 + atomic_inc_unchecked(&vcc->stats->rx_err);
41017 goto out;
41018 }
41019
41020 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
41021 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
41022 __func__, vcc);
41023 - atomic_inc(&vcc->stats->rx_err);
41024 + atomic_inc_unchecked(&vcc->stats->rx_err);
41025 goto out;
41026 }
41027
41028 @@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41029 if (printk_ratelimit())
41030 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
41031 __func__, length);
41032 - atomic_inc(&vcc->stats->rx_drop);
41033 + atomic_inc_unchecked(&vcc->stats->rx_drop);
41034 goto out;
41035 }
41036
41037 @@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41038
41039 vcc->push(vcc, skb);
41040
41041 - atomic_inc(&vcc->stats->rx);
41042 + atomic_inc_unchecked(&vcc->stats->rx);
41043 out:
41044 skb_trim(sarb, 0);
41045 }
41046 @@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
41047 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
41048
41049 usbatm_pop(vcc, skb);
41050 - atomic_inc(&vcc->stats->tx);
41051 + atomic_inc_unchecked(&vcc->stats->tx);
41052
41053 skb = skb_dequeue(&instance->sndqueue);
41054 }
41055 @@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
41056 if (!left--)
41057 return sprintf(page,
41058 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
41059 - atomic_read(&atm_dev->stats.aal5.tx),
41060 - atomic_read(&atm_dev->stats.aal5.tx_err),
41061 - atomic_read(&atm_dev->stats.aal5.rx),
41062 - atomic_read(&atm_dev->stats.aal5.rx_err),
41063 - atomic_read(&atm_dev->stats.aal5.rx_drop));
41064 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
41065 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
41066 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
41067 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
41068 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
41069
41070 if (!left--) {
41071 if (instance->disconnected)
41072 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
41073 index f460de3..95ba1f6 100644
41074 --- a/drivers/usb/core/devices.c
41075 +++ b/drivers/usb/core/devices.c
41076 @@ -126,7 +126,7 @@ static const char format_endpt[] =
41077 * time it gets called.
41078 */
41079 static struct device_connect_event {
41080 - atomic_t count;
41081 + atomic_unchecked_t count;
41082 wait_queue_head_t wait;
41083 } device_event = {
41084 .count = ATOMIC_INIT(1),
41085 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
41086
41087 void usbfs_conn_disc_event(void)
41088 {
41089 - atomic_add(2, &device_event.count);
41090 + atomic_add_unchecked(2, &device_event.count);
41091 wake_up(&device_event.wait);
41092 }
41093
41094 @@ -647,7 +647,7 @@ static unsigned int usb_device_poll(struct file *file,
41095
41096 poll_wait(file, &device_event.wait, wait);
41097
41098 - event_count = atomic_read(&device_event.count);
41099 + event_count = atomic_read_unchecked(&device_event.count);
41100 if (file->f_version != event_count) {
41101 file->f_version = event_count;
41102 return POLLIN | POLLRDNORM;
41103 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
41104 index f034716..aed0368 100644
41105 --- a/drivers/usb/core/hcd.c
41106 +++ b/drivers/usb/core/hcd.c
41107 @@ -1478,7 +1478,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41108 */
41109 usb_get_urb(urb);
41110 atomic_inc(&urb->use_count);
41111 - atomic_inc(&urb->dev->urbnum);
41112 + atomic_inc_unchecked(&urb->dev->urbnum);
41113 usbmon_urb_submit(&hcd->self, urb);
41114
41115 /* NOTE requirements on root-hub callers (usbfs and the hub
41116 @@ -1505,7 +1505,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41117 urb->hcpriv = NULL;
41118 INIT_LIST_HEAD(&urb->urb_list);
41119 atomic_dec(&urb->use_count);
41120 - atomic_dec(&urb->dev->urbnum);
41121 + atomic_dec_unchecked(&urb->dev->urbnum);
41122 if (atomic_read(&urb->reject))
41123 wake_up(&usb_kill_urb_queue);
41124 usb_put_urb(urb);
41125 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
41126 index 818e4a0..0fc9589 100644
41127 --- a/drivers/usb/core/sysfs.c
41128 +++ b/drivers/usb/core/sysfs.c
41129 @@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
41130 struct usb_device *udev;
41131
41132 udev = to_usb_device(dev);
41133 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
41134 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
41135 }
41136 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
41137
41138 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
41139 index cd8fb44..17fbe0c 100644
41140 --- a/drivers/usb/core/usb.c
41141 +++ b/drivers/usb/core/usb.c
41142 @@ -397,7 +397,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
41143 set_dev_node(&dev->dev, dev_to_node(bus->controller));
41144 dev->state = USB_STATE_ATTACHED;
41145 dev->lpm_disable_count = 1;
41146 - atomic_set(&dev->urbnum, 0);
41147 + atomic_set_unchecked(&dev->urbnum, 0);
41148
41149 INIT_LIST_HEAD(&dev->ep0.urb_list);
41150 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
41151 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
41152 index 4bfa78a..902bfbd 100644
41153 --- a/drivers/usb/early/ehci-dbgp.c
41154 +++ b/drivers/usb/early/ehci-dbgp.c
41155 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
41156
41157 #ifdef CONFIG_KGDB
41158 static struct kgdb_io kgdbdbgp_io_ops;
41159 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
41160 +static struct kgdb_io kgdbdbgp_io_ops_console;
41161 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
41162 #else
41163 #define dbgp_kgdb_mode (0)
41164 #endif
41165 @@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
41166 .write_char = kgdbdbgp_write_char,
41167 };
41168
41169 +static struct kgdb_io kgdbdbgp_io_ops_console = {
41170 + .name = "kgdbdbgp",
41171 + .read_char = kgdbdbgp_read_char,
41172 + .write_char = kgdbdbgp_write_char,
41173 + .is_console = 1
41174 +};
41175 +
41176 static int kgdbdbgp_wait_time;
41177
41178 static int __init kgdbdbgp_parse_config(char *str)
41179 @@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
41180 ptr++;
41181 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
41182 }
41183 - kgdb_register_io_module(&kgdbdbgp_io_ops);
41184 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
41185 + if (early_dbgp_console.index != -1)
41186 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
41187 + else
41188 + kgdb_register_io_module(&kgdbdbgp_io_ops);
41189
41190 return 0;
41191 }
41192 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
41193 index f173952..83d6ec0 100644
41194 --- a/drivers/usb/gadget/u_serial.c
41195 +++ b/drivers/usb/gadget/u_serial.c
41196 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41197 spin_lock_irq(&port->port_lock);
41198
41199 /* already open? Great. */
41200 - if (port->port.count) {
41201 + if (atomic_read(&port->port.count)) {
41202 status = 0;
41203 - port->port.count++;
41204 + atomic_inc(&port->port.count);
41205
41206 /* currently opening/closing? wait ... */
41207 } else if (port->openclose) {
41208 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41209 tty->driver_data = port;
41210 port->port.tty = tty;
41211
41212 - port->port.count = 1;
41213 + atomic_set(&port->port.count, 1);
41214 port->openclose = false;
41215
41216 /* if connected, start the I/O stream */
41217 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41218
41219 spin_lock_irq(&port->port_lock);
41220
41221 - if (port->port.count != 1) {
41222 - if (port->port.count == 0)
41223 + if (atomic_read(&port->port.count) != 1) {
41224 + if (atomic_read(&port->port.count) == 0)
41225 WARN_ON(1);
41226 else
41227 - --port->port.count;
41228 + atomic_dec(&port->port.count);
41229 goto exit;
41230 }
41231
41232 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41233 * and sleep if necessary
41234 */
41235 port->openclose = true;
41236 - port->port.count = 0;
41237 + atomic_set(&port->port.count, 0);
41238
41239 gser = port->port_usb;
41240 if (gser && gser->disconnect)
41241 @@ -1157,7 +1157,7 @@ static int gs_closed(struct gs_port *port)
41242 int cond;
41243
41244 spin_lock_irq(&port->port_lock);
41245 - cond = (port->port.count == 0) && !port->openclose;
41246 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
41247 spin_unlock_irq(&port->port_lock);
41248 return cond;
41249 }
41250 @@ -1270,7 +1270,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
41251 /* if it's already open, start I/O ... and notify the serial
41252 * protocol about open/close status (connect/disconnect).
41253 */
41254 - if (port->port.count) {
41255 + if (atomic_read(&port->port.count)) {
41256 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
41257 gs_start_io(port);
41258 if (gser->connect)
41259 @@ -1317,7 +1317,7 @@ void gserial_disconnect(struct gserial *gser)
41260
41261 port->port_usb = NULL;
41262 gser->ioport = NULL;
41263 - if (port->port.count > 0 || port->openclose) {
41264 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
41265 wake_up_interruptible(&port->drain_wait);
41266 if (port->port.tty)
41267 tty_hangup(port->port.tty);
41268 @@ -1333,7 +1333,7 @@ void gserial_disconnect(struct gserial *gser)
41269
41270 /* finally, free any unused/unusable I/O buffers */
41271 spin_lock_irqsave(&port->port_lock, flags);
41272 - if (port->port.count == 0 && !port->openclose)
41273 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
41274 gs_buf_free(&port->port_write_buf);
41275 gs_free_requests(gser->out, &port->read_pool, NULL);
41276 gs_free_requests(gser->out, &port->read_queue, NULL);
41277 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
41278 index 5f3bcd3..bfca43f 100644
41279 --- a/drivers/usb/serial/console.c
41280 +++ b/drivers/usb/serial/console.c
41281 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
41282
41283 info->port = port;
41284
41285 - ++port->port.count;
41286 + atomic_inc(&port->port.count);
41287 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
41288 if (serial->type->set_termios) {
41289 /*
41290 @@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
41291 }
41292 /* Now that any required fake tty operations are completed restore
41293 * the tty port count */
41294 - --port->port.count;
41295 + atomic_dec(&port->port.count);
41296 /* The console is special in terms of closing the device so
41297 * indicate this port is now acting as a system console. */
41298 port->port.console = 1;
41299 @@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
41300 free_tty:
41301 kfree(tty);
41302 reset_open_count:
41303 - port->port.count = 0;
41304 + atomic_set(&port->port.count, 0);
41305 usb_autopm_put_interface(serial->interface);
41306 error_get_interface:
41307 usb_serial_put(serial);
41308 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
41309 index d6bea3e..60b250e 100644
41310 --- a/drivers/usb/wusbcore/wa-hc.h
41311 +++ b/drivers/usb/wusbcore/wa-hc.h
41312 @@ -192,7 +192,7 @@ struct wahc {
41313 struct list_head xfer_delayed_list;
41314 spinlock_t xfer_list_lock;
41315 struct work_struct xfer_work;
41316 - atomic_t xfer_id_count;
41317 + atomic_unchecked_t xfer_id_count;
41318 };
41319
41320
41321 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
41322 INIT_LIST_HEAD(&wa->xfer_delayed_list);
41323 spin_lock_init(&wa->xfer_list_lock);
41324 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
41325 - atomic_set(&wa->xfer_id_count, 1);
41326 + atomic_set_unchecked(&wa->xfer_id_count, 1);
41327 }
41328
41329 /**
41330 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
41331 index 57c01ab..8a05959 100644
41332 --- a/drivers/usb/wusbcore/wa-xfer.c
41333 +++ b/drivers/usb/wusbcore/wa-xfer.c
41334 @@ -296,7 +296,7 @@ out:
41335 */
41336 static void wa_xfer_id_init(struct wa_xfer *xfer)
41337 {
41338 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
41339 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
41340 }
41341
41342 /*
41343 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
41344 index dedaf81..b0f11ab 100644
41345 --- a/drivers/vhost/vhost.c
41346 +++ b/drivers/vhost/vhost.c
41347 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
41348 return 0;
41349 }
41350
41351 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
41352 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
41353 {
41354 struct file *eventfp, *filep = NULL;
41355 bool pollstart = false, pollstop = false;
41356 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
41357 index 0fefa84..7a9d581 100644
41358 --- a/drivers/video/aty/aty128fb.c
41359 +++ b/drivers/video/aty/aty128fb.c
41360 @@ -149,7 +149,7 @@ enum {
41361 };
41362
41363 /* Must match above enum */
41364 -static char * const r128_family[] __devinitconst = {
41365 +static const char * const r128_family[] __devinitconst = {
41366 "AGP",
41367 "PCI",
41368 "PRO AGP",
41369 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
41370 index 5c3960d..15cf8fc 100644
41371 --- a/drivers/video/fbcmap.c
41372 +++ b/drivers/video/fbcmap.c
41373 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
41374 rc = -ENODEV;
41375 goto out;
41376 }
41377 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
41378 - !info->fbops->fb_setcmap)) {
41379 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
41380 rc = -EINVAL;
41381 goto out1;
41382 }
41383 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
41384 index 3ff0105..7589d98 100644
41385 --- a/drivers/video/fbmem.c
41386 +++ b/drivers/video/fbmem.c
41387 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
41388 image->dx += image->width + 8;
41389 }
41390 } else if (rotate == FB_ROTATE_UD) {
41391 - for (x = 0; x < num && image->dx >= 0; x++) {
41392 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
41393 info->fbops->fb_imageblit(info, image);
41394 image->dx -= image->width + 8;
41395 }
41396 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
41397 image->dy += image->height + 8;
41398 }
41399 } else if (rotate == FB_ROTATE_CCW) {
41400 - for (x = 0; x < num && image->dy >= 0; x++) {
41401 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
41402 info->fbops->fb_imageblit(info, image);
41403 image->dy -= image->height + 8;
41404 }
41405 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
41406 return -EFAULT;
41407 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
41408 return -EINVAL;
41409 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
41410 + if (con2fb.framebuffer >= FB_MAX)
41411 return -EINVAL;
41412 if (!registered_fb[con2fb.framebuffer])
41413 request_module("fb%d", con2fb.framebuffer);
41414 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
41415 index 7672d2e..b56437f 100644
41416 --- a/drivers/video/i810/i810_accel.c
41417 +++ b/drivers/video/i810/i810_accel.c
41418 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
41419 }
41420 }
41421 printk("ringbuffer lockup!!!\n");
41422 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
41423 i810_report_error(mmio);
41424 par->dev_flags |= LOCKUP;
41425 info->pixmap.scan_align = 1;
41426 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
41427 index 3c14e43..eafa544 100644
41428 --- a/drivers/video/logo/logo_linux_clut224.ppm
41429 +++ b/drivers/video/logo/logo_linux_clut224.ppm
41430 @@ -1,1604 +1,1123 @@
41431 P3
41432 -# Standard 224-color Linux logo
41433 80 80
41434 255
41435 - 0 0 0 0 0 0 0 0 0 0 0 0
41436 - 0 0 0 0 0 0 0 0 0 0 0 0
41437 - 0 0 0 0 0 0 0 0 0 0 0 0
41438 - 0 0 0 0 0 0 0 0 0 0 0 0
41439 - 0 0 0 0 0 0 0 0 0 0 0 0
41440 - 0 0 0 0 0 0 0 0 0 0 0 0
41441 - 0 0 0 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 - 6 6 6 6 6 6 10 10 10 10 10 10
41445 - 10 10 10 6 6 6 6 6 6 6 6 6
41446 - 0 0 0 0 0 0 0 0 0 0 0 0
41447 - 0 0 0 0 0 0 0 0 0 0 0 0
41448 - 0 0 0 0 0 0 0 0 0 0 0 0
41449 - 0 0 0 0 0 0 0 0 0 0 0 0
41450 - 0 0 0 0 0 0 0 0 0 0 0 0
41451 - 0 0 0 0 0 0 0 0 0 0 0 0
41452 - 0 0 0 0 0 0 0 0 0 0 0 0
41453 - 0 0 0 0 0 0 0 0 0 0 0 0
41454 - 0 0 0 0 0 0 0 0 0 0 0 0
41455 - 0 0 0 0 0 0 0 0 0 0 0 0
41456 - 0 0 0 0 0 0 0 0 0 0 0 0
41457 - 0 0 0 0 0 0 0 0 0 0 0 0
41458 - 0 0 0 0 0 0 0 0 0 0 0 0
41459 - 0 0 0 0 0 0 0 0 0 0 0 0
41460 - 0 0 0 0 0 0 0 0 0 0 0 0
41461 - 0 0 0 0 0 0 0 0 0 0 0 0
41462 - 0 0 0 0 0 0 0 0 0 0 0 0
41463 - 0 0 0 6 6 6 10 10 10 14 14 14
41464 - 22 22 22 26 26 26 30 30 30 34 34 34
41465 - 30 30 30 30 30 30 26 26 26 18 18 18
41466 - 14 14 14 10 10 10 6 6 6 0 0 0
41467 - 0 0 0 0 0 0 0 0 0 0 0 0
41468 - 0 0 0 0 0 0 0 0 0 0 0 0
41469 - 0 0 0 0 0 0 0 0 0 0 0 0
41470 - 0 0 0 0 0 0 0 0 0 0 0 0
41471 - 0 0 0 0 0 0 0 0 0 0 0 0
41472 - 0 0 0 0 0 0 0 0 0 0 0 0
41473 - 0 0 0 0 0 0 0 0 0 0 0 0
41474 - 0 0 0 0 0 0 0 0 0 0 0 0
41475 - 0 0 0 0 0 0 0 0 0 0 0 0
41476 - 0 0 0 0 0 1 0 0 1 0 0 0
41477 - 0 0 0 0 0 0 0 0 0 0 0 0
41478 - 0 0 0 0 0 0 0 0 0 0 0 0
41479 - 0 0 0 0 0 0 0 0 0 0 0 0
41480 - 0 0 0 0 0 0 0 0 0 0 0 0
41481 - 0 0 0 0 0 0 0 0 0 0 0 0
41482 - 0 0 0 0 0 0 0 0 0 0 0 0
41483 - 6 6 6 14 14 14 26 26 26 42 42 42
41484 - 54 54 54 66 66 66 78 78 78 78 78 78
41485 - 78 78 78 74 74 74 66 66 66 54 54 54
41486 - 42 42 42 26 26 26 18 18 18 10 10 10
41487 - 6 6 6 0 0 0 0 0 0 0 0 0
41488 - 0 0 0 0 0 0 0 0 0 0 0 0
41489 - 0 0 0 0 0 0 0 0 0 0 0 0
41490 - 0 0 0 0 0 0 0 0 0 0 0 0
41491 - 0 0 0 0 0 0 0 0 0 0 0 0
41492 - 0 0 0 0 0 0 0 0 0 0 0 0
41493 - 0 0 0 0 0 0 0 0 0 0 0 0
41494 - 0 0 0 0 0 0 0 0 0 0 0 0
41495 - 0 0 0 0 0 0 0 0 0 0 0 0
41496 - 0 0 1 0 0 0 0 0 0 0 0 0
41497 - 0 0 0 0 0 0 0 0 0 0 0 0
41498 - 0 0 0 0 0 0 0 0 0 0 0 0
41499 - 0 0 0 0 0 0 0 0 0 0 0 0
41500 - 0 0 0 0 0 0 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 10 10 10
41503 - 22 22 22 42 42 42 66 66 66 86 86 86
41504 - 66 66 66 38 38 38 38 38 38 22 22 22
41505 - 26 26 26 34 34 34 54 54 54 66 66 66
41506 - 86 86 86 70 70 70 46 46 46 26 26 26
41507 - 14 14 14 6 6 6 0 0 0 0 0 0
41508 - 0 0 0 0 0 0 0 0 0 0 0 0
41509 - 0 0 0 0 0 0 0 0 0 0 0 0
41510 - 0 0 0 0 0 0 0 0 0 0 0 0
41511 - 0 0 0 0 0 0 0 0 0 0 0 0
41512 - 0 0 0 0 0 0 0 0 0 0 0 0
41513 - 0 0 0 0 0 0 0 0 0 0 0 0
41514 - 0 0 0 0 0 0 0 0 0 0 0 0
41515 - 0 0 0 0 0 0 0 0 0 0 0 0
41516 - 0 0 1 0 0 1 0 0 1 0 0 0
41517 - 0 0 0 0 0 0 0 0 0 0 0 0
41518 - 0 0 0 0 0 0 0 0 0 0 0 0
41519 - 0 0 0 0 0 0 0 0 0 0 0 0
41520 - 0 0 0 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 10 10 10 26 26 26
41523 - 50 50 50 82 82 82 58 58 58 6 6 6
41524 - 2 2 6 2 2 6 2 2 6 2 2 6
41525 - 2 2 6 2 2 6 2 2 6 2 2 6
41526 - 6 6 6 54 54 54 86 86 86 66 66 66
41527 - 38 38 38 18 18 18 6 6 6 0 0 0
41528 - 0 0 0 0 0 0 0 0 0 0 0 0
41529 - 0 0 0 0 0 0 0 0 0 0 0 0
41530 - 0 0 0 0 0 0 0 0 0 0 0 0
41531 - 0 0 0 0 0 0 0 0 0 0 0 0
41532 - 0 0 0 0 0 0 0 0 0 0 0 0
41533 - 0 0 0 0 0 0 0 0 0 0 0 0
41534 - 0 0 0 0 0 0 0 0 0 0 0 0
41535 - 0 0 0 0 0 0 0 0 0 0 0 0
41536 - 0 0 0 0 0 0 0 0 0 0 0 0
41537 - 0 0 0 0 0 0 0 0 0 0 0 0
41538 - 0 0 0 0 0 0 0 0 0 0 0 0
41539 - 0 0 0 0 0 0 0 0 0 0 0 0
41540 - 0 0 0 0 0 0 0 0 0 0 0 0
41541 - 0 0 0 0 0 0 0 0 0 0 0 0
41542 - 0 0 0 6 6 6 22 22 22 50 50 50
41543 - 78 78 78 34 34 34 2 2 6 2 2 6
41544 - 2 2 6 2 2 6 2 2 6 2 2 6
41545 - 2 2 6 2 2 6 2 2 6 2 2 6
41546 - 2 2 6 2 2 6 6 6 6 70 70 70
41547 - 78 78 78 46 46 46 22 22 22 6 6 6
41548 - 0 0 0 0 0 0 0 0 0 0 0 0
41549 - 0 0 0 0 0 0 0 0 0 0 0 0
41550 - 0 0 0 0 0 0 0 0 0 0 0 0
41551 - 0 0 0 0 0 0 0 0 0 0 0 0
41552 - 0 0 0 0 0 0 0 0 0 0 0 0
41553 - 0 0 0 0 0 0 0 0 0 0 0 0
41554 - 0 0 0 0 0 0 0 0 0 0 0 0
41555 - 0 0 0 0 0 0 0 0 0 0 0 0
41556 - 0 0 1 0 0 1 0 0 1 0 0 0
41557 - 0 0 0 0 0 0 0 0 0 0 0 0
41558 - 0 0 0 0 0 0 0 0 0 0 0 0
41559 - 0 0 0 0 0 0 0 0 0 0 0 0
41560 - 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 - 6 6 6 18 18 18 42 42 42 82 82 82
41563 - 26 26 26 2 2 6 2 2 6 2 2 6
41564 - 2 2 6 2 2 6 2 2 6 2 2 6
41565 - 2 2 6 2 2 6 2 2 6 14 14 14
41566 - 46 46 46 34 34 34 6 6 6 2 2 6
41567 - 42 42 42 78 78 78 42 42 42 18 18 18
41568 - 6 6 6 0 0 0 0 0 0 0 0 0
41569 - 0 0 0 0 0 0 0 0 0 0 0 0
41570 - 0 0 0 0 0 0 0 0 0 0 0 0
41571 - 0 0 0 0 0 0 0 0 0 0 0 0
41572 - 0 0 0 0 0 0 0 0 0 0 0 0
41573 - 0 0 0 0 0 0 0 0 0 0 0 0
41574 - 0 0 0 0 0 0 0 0 0 0 0 0
41575 - 0 0 0 0 0 0 0 0 0 0 0 0
41576 - 0 0 1 0 0 0 0 0 1 0 0 0
41577 - 0 0 0 0 0 0 0 0 0 0 0 0
41578 - 0 0 0 0 0 0 0 0 0 0 0 0
41579 - 0 0 0 0 0 0 0 0 0 0 0 0
41580 - 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 - 10 10 10 30 30 30 66 66 66 58 58 58
41583 - 2 2 6 2 2 6 2 2 6 2 2 6
41584 - 2 2 6 2 2 6 2 2 6 2 2 6
41585 - 2 2 6 2 2 6 2 2 6 26 26 26
41586 - 86 86 86 101 101 101 46 46 46 10 10 10
41587 - 2 2 6 58 58 58 70 70 70 34 34 34
41588 - 10 10 10 0 0 0 0 0 0 0 0 0
41589 - 0 0 0 0 0 0 0 0 0 0 0 0
41590 - 0 0 0 0 0 0 0 0 0 0 0 0
41591 - 0 0 0 0 0 0 0 0 0 0 0 0
41592 - 0 0 0 0 0 0 0 0 0 0 0 0
41593 - 0 0 0 0 0 0 0 0 0 0 0 0
41594 - 0 0 0 0 0 0 0 0 0 0 0 0
41595 - 0 0 0 0 0 0 0 0 0 0 0 0
41596 - 0 0 1 0 0 1 0 0 1 0 0 0
41597 - 0 0 0 0 0 0 0 0 0 0 0 0
41598 - 0 0 0 0 0 0 0 0 0 0 0 0
41599 - 0 0 0 0 0 0 0 0 0 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 - 14 14 14 42 42 42 86 86 86 10 10 10
41603 - 2 2 6 2 2 6 2 2 6 2 2 6
41604 - 2 2 6 2 2 6 2 2 6 2 2 6
41605 - 2 2 6 2 2 6 2 2 6 30 30 30
41606 - 94 94 94 94 94 94 58 58 58 26 26 26
41607 - 2 2 6 6 6 6 78 78 78 54 54 54
41608 - 22 22 22 6 6 6 0 0 0 0 0 0
41609 - 0 0 0 0 0 0 0 0 0 0 0 0
41610 - 0 0 0 0 0 0 0 0 0 0 0 0
41611 - 0 0 0 0 0 0 0 0 0 0 0 0
41612 - 0 0 0 0 0 0 0 0 0 0 0 0
41613 - 0 0 0 0 0 0 0 0 0 0 0 0
41614 - 0 0 0 0 0 0 0 0 0 0 0 0
41615 - 0 0 0 0 0 0 0 0 0 0 0 0
41616 - 0 0 0 0 0 0 0 0 0 0 0 0
41617 - 0 0 0 0 0 0 0 0 0 0 0 0
41618 - 0 0 0 0 0 0 0 0 0 0 0 0
41619 - 0 0 0 0 0 0 0 0 0 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 6 6 6
41622 - 22 22 22 62 62 62 62 62 62 2 2 6
41623 - 2 2 6 2 2 6 2 2 6 2 2 6
41624 - 2 2 6 2 2 6 2 2 6 2 2 6
41625 - 2 2 6 2 2 6 2 2 6 26 26 26
41626 - 54 54 54 38 38 38 18 18 18 10 10 10
41627 - 2 2 6 2 2 6 34 34 34 82 82 82
41628 - 38 38 38 14 14 14 0 0 0 0 0 0
41629 - 0 0 0 0 0 0 0 0 0 0 0 0
41630 - 0 0 0 0 0 0 0 0 0 0 0 0
41631 - 0 0 0 0 0 0 0 0 0 0 0 0
41632 - 0 0 0 0 0 0 0 0 0 0 0 0
41633 - 0 0 0 0 0 0 0 0 0 0 0 0
41634 - 0 0 0 0 0 0 0 0 0 0 0 0
41635 - 0 0 0 0 0 0 0 0 0 0 0 0
41636 - 0 0 0 0 0 1 0 0 1 0 0 0
41637 - 0 0 0 0 0 0 0 0 0 0 0 0
41638 - 0 0 0 0 0 0 0 0 0 0 0 0
41639 - 0 0 0 0 0 0 0 0 0 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 6 6 6
41642 - 30 30 30 78 78 78 30 30 30 2 2 6
41643 - 2 2 6 2 2 6 2 2 6 2 2 6
41644 - 2 2 6 2 2 6 2 2 6 2 2 6
41645 - 2 2 6 2 2 6 2 2 6 10 10 10
41646 - 10 10 10 2 2 6 2 2 6 2 2 6
41647 - 2 2 6 2 2 6 2 2 6 78 78 78
41648 - 50 50 50 18 18 18 6 6 6 0 0 0
41649 - 0 0 0 0 0 0 0 0 0 0 0 0
41650 - 0 0 0 0 0 0 0 0 0 0 0 0
41651 - 0 0 0 0 0 0 0 0 0 0 0 0
41652 - 0 0 0 0 0 0 0 0 0 0 0 0
41653 - 0 0 0 0 0 0 0 0 0 0 0 0
41654 - 0 0 0 0 0 0 0 0 0 0 0 0
41655 - 0 0 0 0 0 0 0 0 0 0 0 0
41656 - 0 0 1 0 0 0 0 0 0 0 0 0
41657 - 0 0 0 0 0 0 0 0 0 0 0 0
41658 - 0 0 0 0 0 0 0 0 0 0 0 0
41659 - 0 0 0 0 0 0 0 0 0 0 0 0
41660 - 0 0 0 0 0 0 0 0 0 0 0 0
41661 - 0 0 0 0 0 0 0 0 0 10 10 10
41662 - 38 38 38 86 86 86 14 14 14 2 2 6
41663 - 2 2 6 2 2 6 2 2 6 2 2 6
41664 - 2 2 6 2 2 6 2 2 6 2 2 6
41665 - 2 2 6 2 2 6 2 2 6 2 2 6
41666 - 2 2 6 2 2 6 2 2 6 2 2 6
41667 - 2 2 6 2 2 6 2 2 6 54 54 54
41668 - 66 66 66 26 26 26 6 6 6 0 0 0
41669 - 0 0 0 0 0 0 0 0 0 0 0 0
41670 - 0 0 0 0 0 0 0 0 0 0 0 0
41671 - 0 0 0 0 0 0 0 0 0 0 0 0
41672 - 0 0 0 0 0 0 0 0 0 0 0 0
41673 - 0 0 0 0 0 0 0 0 0 0 0 0
41674 - 0 0 0 0 0 0 0 0 0 0 0 0
41675 - 0 0 0 0 0 0 0 0 0 0 0 0
41676 - 0 0 0 0 0 1 0 0 1 0 0 0
41677 - 0 0 0 0 0 0 0 0 0 0 0 0
41678 - 0 0 0 0 0 0 0 0 0 0 0 0
41679 - 0 0 0 0 0 0 0 0 0 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 14 14 14
41682 - 42 42 42 82 82 82 2 2 6 2 2 6
41683 - 2 2 6 6 6 6 10 10 10 2 2 6
41684 - 2 2 6 2 2 6 2 2 6 2 2 6
41685 - 2 2 6 2 2 6 2 2 6 6 6 6
41686 - 14 14 14 10 10 10 2 2 6 2 2 6
41687 - 2 2 6 2 2 6 2 2 6 18 18 18
41688 - 82 82 82 34 34 34 10 10 10 0 0 0
41689 - 0 0 0 0 0 0 0 0 0 0 0 0
41690 - 0 0 0 0 0 0 0 0 0 0 0 0
41691 - 0 0 0 0 0 0 0 0 0 0 0 0
41692 - 0 0 0 0 0 0 0 0 0 0 0 0
41693 - 0 0 0 0 0 0 0 0 0 0 0 0
41694 - 0 0 0 0 0 0 0 0 0 0 0 0
41695 - 0 0 0 0 0 0 0 0 0 0 0 0
41696 - 0 0 1 0 0 0 0 0 0 0 0 0
41697 - 0 0 0 0 0 0 0 0 0 0 0 0
41698 - 0 0 0 0 0 0 0 0 0 0 0 0
41699 - 0 0 0 0 0 0 0 0 0 0 0 0
41700 - 0 0 0 0 0 0 0 0 0 0 0 0
41701 - 0 0 0 0 0 0 0 0 0 14 14 14
41702 - 46 46 46 86 86 86 2 2 6 2 2 6
41703 - 6 6 6 6 6 6 22 22 22 34 34 34
41704 - 6 6 6 2 2 6 2 2 6 2 2 6
41705 - 2 2 6 2 2 6 18 18 18 34 34 34
41706 - 10 10 10 50 50 50 22 22 22 2 2 6
41707 - 2 2 6 2 2 6 2 2 6 10 10 10
41708 - 86 86 86 42 42 42 14 14 14 0 0 0
41709 - 0 0 0 0 0 0 0 0 0 0 0 0
41710 - 0 0 0 0 0 0 0 0 0 0 0 0
41711 - 0 0 0 0 0 0 0 0 0 0 0 0
41712 - 0 0 0 0 0 0 0 0 0 0 0 0
41713 - 0 0 0 0 0 0 0 0 0 0 0 0
41714 - 0 0 0 0 0 0 0 0 0 0 0 0
41715 - 0 0 0 0 0 0 0 0 0 0 0 0
41716 - 0 0 1 0 0 1 0 0 1 0 0 0
41717 - 0 0 0 0 0 0 0 0 0 0 0 0
41718 - 0 0 0 0 0 0 0 0 0 0 0 0
41719 - 0 0 0 0 0 0 0 0 0 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 14 14 14
41722 - 46 46 46 86 86 86 2 2 6 2 2 6
41723 - 38 38 38 116 116 116 94 94 94 22 22 22
41724 - 22 22 22 2 2 6 2 2 6 2 2 6
41725 - 14 14 14 86 86 86 138 138 138 162 162 162
41726 -154 154 154 38 38 38 26 26 26 6 6 6
41727 - 2 2 6 2 2 6 2 2 6 2 2 6
41728 - 86 86 86 46 46 46 14 14 14 0 0 0
41729 - 0 0 0 0 0 0 0 0 0 0 0 0
41730 - 0 0 0 0 0 0 0 0 0 0 0 0
41731 - 0 0 0 0 0 0 0 0 0 0 0 0
41732 - 0 0 0 0 0 0 0 0 0 0 0 0
41733 - 0 0 0 0 0 0 0 0 0 0 0 0
41734 - 0 0 0 0 0 0 0 0 0 0 0 0
41735 - 0 0 0 0 0 0 0 0 0 0 0 0
41736 - 0 0 0 0 0 0 0 0 0 0 0 0
41737 - 0 0 0 0 0 0 0 0 0 0 0 0
41738 - 0 0 0 0 0 0 0 0 0 0 0 0
41739 - 0 0 0 0 0 0 0 0 0 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 14 14 14
41742 - 46 46 46 86 86 86 2 2 6 14 14 14
41743 -134 134 134 198 198 198 195 195 195 116 116 116
41744 - 10 10 10 2 2 6 2 2 6 6 6 6
41745 -101 98 89 187 187 187 210 210 210 218 218 218
41746 -214 214 214 134 134 134 14 14 14 6 6 6
41747 - 2 2 6 2 2 6 2 2 6 2 2 6
41748 - 86 86 86 50 50 50 18 18 18 6 6 6
41749 - 0 0 0 0 0 0 0 0 0 0 0 0
41750 - 0 0 0 0 0 0 0 0 0 0 0 0
41751 - 0 0 0 0 0 0 0 0 0 0 0 0
41752 - 0 0 0 0 0 0 0 0 0 0 0 0
41753 - 0 0 0 0 0 0 0 0 0 0 0 0
41754 - 0 0 0 0 0 0 0 0 0 0 0 0
41755 - 0 0 0 0 0 0 0 0 1 0 0 0
41756 - 0 0 1 0 0 1 0 0 1 0 0 0
41757 - 0 0 0 0 0 0 0 0 0 0 0 0
41758 - 0 0 0 0 0 0 0 0 0 0 0 0
41759 - 0 0 0 0 0 0 0 0 0 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 14 14 14
41762 - 46 46 46 86 86 86 2 2 6 54 54 54
41763 -218 218 218 195 195 195 226 226 226 246 246 246
41764 - 58 58 58 2 2 6 2 2 6 30 30 30
41765 -210 210 210 253 253 253 174 174 174 123 123 123
41766 -221 221 221 234 234 234 74 74 74 2 2 6
41767 - 2 2 6 2 2 6 2 2 6 2 2 6
41768 - 70 70 70 58 58 58 22 22 22 6 6 6
41769 - 0 0 0 0 0 0 0 0 0 0 0 0
41770 - 0 0 0 0 0 0 0 0 0 0 0 0
41771 - 0 0 0 0 0 0 0 0 0 0 0 0
41772 - 0 0 0 0 0 0 0 0 0 0 0 0
41773 - 0 0 0 0 0 0 0 0 0 0 0 0
41774 - 0 0 0 0 0 0 0 0 0 0 0 0
41775 - 0 0 0 0 0 0 0 0 0 0 0 0
41776 - 0 0 0 0 0 0 0 0 0 0 0 0
41777 - 0 0 0 0 0 0 0 0 0 0 0 0
41778 - 0 0 0 0 0 0 0 0 0 0 0 0
41779 - 0 0 0 0 0 0 0 0 0 0 0 0
41780 - 0 0 0 0 0 0 0 0 0 0 0 0
41781 - 0 0 0 0 0 0 0 0 0 14 14 14
41782 - 46 46 46 82 82 82 2 2 6 106 106 106
41783 -170 170 170 26 26 26 86 86 86 226 226 226
41784 -123 123 123 10 10 10 14 14 14 46 46 46
41785 -231 231 231 190 190 190 6 6 6 70 70 70
41786 - 90 90 90 238 238 238 158 158 158 2 2 6
41787 - 2 2 6 2 2 6 2 2 6 2 2 6
41788 - 70 70 70 58 58 58 22 22 22 6 6 6
41789 - 0 0 0 0 0 0 0 0 0 0 0 0
41790 - 0 0 0 0 0 0 0 0 0 0 0 0
41791 - 0 0 0 0 0 0 0 0 0 0 0 0
41792 - 0 0 0 0 0 0 0 0 0 0 0 0
41793 - 0 0 0 0 0 0 0 0 0 0 0 0
41794 - 0 0 0 0 0 0 0 0 0 0 0 0
41795 - 0 0 0 0 0 0 0 0 1 0 0 0
41796 - 0 0 1 0 0 1 0 0 1 0 0 0
41797 - 0 0 0 0 0 0 0 0 0 0 0 0
41798 - 0 0 0 0 0 0 0 0 0 0 0 0
41799 - 0 0 0 0 0 0 0 0 0 0 0 0
41800 - 0 0 0 0 0 0 0 0 0 0 0 0
41801 - 0 0 0 0 0 0 0 0 0 14 14 14
41802 - 42 42 42 86 86 86 6 6 6 116 116 116
41803 -106 106 106 6 6 6 70 70 70 149 149 149
41804 -128 128 128 18 18 18 38 38 38 54 54 54
41805 -221 221 221 106 106 106 2 2 6 14 14 14
41806 - 46 46 46 190 190 190 198 198 198 2 2 6
41807 - 2 2 6 2 2 6 2 2 6 2 2 6
41808 - 74 74 74 62 62 62 22 22 22 6 6 6
41809 - 0 0 0 0 0 0 0 0 0 0 0 0
41810 - 0 0 0 0 0 0 0 0 0 0 0 0
41811 - 0 0 0 0 0 0 0 0 0 0 0 0
41812 - 0 0 0 0 0 0 0 0 0 0 0 0
41813 - 0 0 0 0 0 0 0 0 0 0 0 0
41814 - 0 0 0 0 0 0 0 0 0 0 0 0
41815 - 0 0 0 0 0 0 0 0 1 0 0 0
41816 - 0 0 1 0 0 0 0 0 1 0 0 0
41817 - 0 0 0 0 0 0 0 0 0 0 0 0
41818 - 0 0 0 0 0 0 0 0 0 0 0 0
41819 - 0 0 0 0 0 0 0 0 0 0 0 0
41820 - 0 0 0 0 0 0 0 0 0 0 0 0
41821 - 0 0 0 0 0 0 0 0 0 14 14 14
41822 - 42 42 42 94 94 94 14 14 14 101 101 101
41823 -128 128 128 2 2 6 18 18 18 116 116 116
41824 -118 98 46 121 92 8 121 92 8 98 78 10
41825 -162 162 162 106 106 106 2 2 6 2 2 6
41826 - 2 2 6 195 195 195 195 195 195 6 6 6
41827 - 2 2 6 2 2 6 2 2 6 2 2 6
41828 - 74 74 74 62 62 62 22 22 22 6 6 6
41829 - 0 0 0 0 0 0 0 0 0 0 0 0
41830 - 0 0 0 0 0 0 0 0 0 0 0 0
41831 - 0 0 0 0 0 0 0 0 0 0 0 0
41832 - 0 0 0 0 0 0 0 0 0 0 0 0
41833 - 0 0 0 0 0 0 0 0 0 0 0 0
41834 - 0 0 0 0 0 0 0 0 0 0 0 0
41835 - 0 0 0 0 0 0 0 0 1 0 0 1
41836 - 0 0 1 0 0 0 0 0 1 0 0 0
41837 - 0 0 0 0 0 0 0 0 0 0 0 0
41838 - 0 0 0 0 0 0 0 0 0 0 0 0
41839 - 0 0 0 0 0 0 0 0 0 0 0 0
41840 - 0 0 0 0 0 0 0 0 0 0 0 0
41841 - 0 0 0 0 0 0 0 0 0 10 10 10
41842 - 38 38 38 90 90 90 14 14 14 58 58 58
41843 -210 210 210 26 26 26 54 38 6 154 114 10
41844 -226 170 11 236 186 11 225 175 15 184 144 12
41845 -215 174 15 175 146 61 37 26 9 2 2 6
41846 - 70 70 70 246 246 246 138 138 138 2 2 6
41847 - 2 2 6 2 2 6 2 2 6 2 2 6
41848 - 70 70 70 66 66 66 26 26 26 6 6 6
41849 - 0 0 0 0 0 0 0 0 0 0 0 0
41850 - 0 0 0 0 0 0 0 0 0 0 0 0
41851 - 0 0 0 0 0 0 0 0 0 0 0 0
41852 - 0 0 0 0 0 0 0 0 0 0 0 0
41853 - 0 0 0 0 0 0 0 0 0 0 0 0
41854 - 0 0 0 0 0 0 0 0 0 0 0 0
41855 - 0 0 0 0 0 0 0 0 0 0 0 0
41856 - 0 0 0 0 0 0 0 0 0 0 0 0
41857 - 0 0 0 0 0 0 0 0 0 0 0 0
41858 - 0 0 0 0 0 0 0 0 0 0 0 0
41859 - 0 0 0 0 0 0 0 0 0 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 10 10 10
41862 - 38 38 38 86 86 86 14 14 14 10 10 10
41863 -195 195 195 188 164 115 192 133 9 225 175 15
41864 -239 182 13 234 190 10 232 195 16 232 200 30
41865 -245 207 45 241 208 19 232 195 16 184 144 12
41866 -218 194 134 211 206 186 42 42 42 2 2 6
41867 - 2 2 6 2 2 6 2 2 6 2 2 6
41868 - 50 50 50 74 74 74 30 30 30 6 6 6
41869 - 0 0 0 0 0 0 0 0 0 0 0 0
41870 - 0 0 0 0 0 0 0 0 0 0 0 0
41871 - 0 0 0 0 0 0 0 0 0 0 0 0
41872 - 0 0 0 0 0 0 0 0 0 0 0 0
41873 - 0 0 0 0 0 0 0 0 0 0 0 0
41874 - 0 0 0 0 0 0 0 0 0 0 0 0
41875 - 0 0 0 0 0 0 0 0 0 0 0 0
41876 - 0 0 0 0 0 0 0 0 0 0 0 0
41877 - 0 0 0 0 0 0 0 0 0 0 0 0
41878 - 0 0 0 0 0 0 0 0 0 0 0 0
41879 - 0 0 0 0 0 0 0 0 0 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 10 10 10
41882 - 34 34 34 86 86 86 14 14 14 2 2 6
41883 -121 87 25 192 133 9 219 162 10 239 182 13
41884 -236 186 11 232 195 16 241 208 19 244 214 54
41885 -246 218 60 246 218 38 246 215 20 241 208 19
41886 -241 208 19 226 184 13 121 87 25 2 2 6
41887 - 2 2 6 2 2 6 2 2 6 2 2 6
41888 - 50 50 50 82 82 82 34 34 34 10 10 10
41889 - 0 0 0 0 0 0 0 0 0 0 0 0
41890 - 0 0 0 0 0 0 0 0 0 0 0 0
41891 - 0 0 0 0 0 0 0 0 0 0 0 0
41892 - 0 0 0 0 0 0 0 0 0 0 0 0
41893 - 0 0 0 0 0 0 0 0 0 0 0 0
41894 - 0 0 0 0 0 0 0 0 0 0 0 0
41895 - 0 0 0 0 0 0 0 0 0 0 0 0
41896 - 0 0 0 0 0 0 0 0 0 0 0 0
41897 - 0 0 0 0 0 0 0 0 0 0 0 0
41898 - 0 0 0 0 0 0 0 0 0 0 0 0
41899 - 0 0 0 0 0 0 0 0 0 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 10 10 10
41902 - 34 34 34 82 82 82 30 30 30 61 42 6
41903 -180 123 7 206 145 10 230 174 11 239 182 13
41904 -234 190 10 238 202 15 241 208 19 246 218 74
41905 -246 218 38 246 215 20 246 215 20 246 215 20
41906 -226 184 13 215 174 15 184 144 12 6 6 6
41907 - 2 2 6 2 2 6 2 2 6 2 2 6
41908 - 26 26 26 94 94 94 42 42 42 14 14 14
41909 - 0 0 0 0 0 0 0 0 0 0 0 0
41910 - 0 0 0 0 0 0 0 0 0 0 0 0
41911 - 0 0 0 0 0 0 0 0 0 0 0 0
41912 - 0 0 0 0 0 0 0 0 0 0 0 0
41913 - 0 0 0 0 0 0 0 0 0 0 0 0
41914 - 0 0 0 0 0 0 0 0 0 0 0 0
41915 - 0 0 0 0 0 0 0 0 0 0 0 0
41916 - 0 0 0 0 0 0 0 0 0 0 0 0
41917 - 0 0 0 0 0 0 0 0 0 0 0 0
41918 - 0 0 0 0 0 0 0 0 0 0 0 0
41919 - 0 0 0 0 0 0 0 0 0 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 10 10 10
41922 - 30 30 30 78 78 78 50 50 50 104 69 6
41923 -192 133 9 216 158 10 236 178 12 236 186 11
41924 -232 195 16 241 208 19 244 214 54 245 215 43
41925 -246 215 20 246 215 20 241 208 19 198 155 10
41926 -200 144 11 216 158 10 156 118 10 2 2 6
41927 - 2 2 6 2 2 6 2 2 6 2 2 6
41928 - 6 6 6 90 90 90 54 54 54 18 18 18
41929 - 6 6 6 0 0 0 0 0 0 0 0 0
41930 - 0 0 0 0 0 0 0 0 0 0 0 0
41931 - 0 0 0 0 0 0 0 0 0 0 0 0
41932 - 0 0 0 0 0 0 0 0 0 0 0 0
41933 - 0 0 0 0 0 0 0 0 0 0 0 0
41934 - 0 0 0 0 0 0 0 0 0 0 0 0
41935 - 0 0 0 0 0 0 0 0 0 0 0 0
41936 - 0 0 0 0 0 0 0 0 0 0 0 0
41937 - 0 0 0 0 0 0 0 0 0 0 0 0
41938 - 0 0 0 0 0 0 0 0 0 0 0 0
41939 - 0 0 0 0 0 0 0 0 0 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 10 10 10
41942 - 30 30 30 78 78 78 46 46 46 22 22 22
41943 -137 92 6 210 162 10 239 182 13 238 190 10
41944 -238 202 15 241 208 19 246 215 20 246 215 20
41945 -241 208 19 203 166 17 185 133 11 210 150 10
41946 -216 158 10 210 150 10 102 78 10 2 2 6
41947 - 6 6 6 54 54 54 14 14 14 2 2 6
41948 - 2 2 6 62 62 62 74 74 74 30 30 30
41949 - 10 10 10 0 0 0 0 0 0 0 0 0
41950 - 0 0 0 0 0 0 0 0 0 0 0 0
41951 - 0 0 0 0 0 0 0 0 0 0 0 0
41952 - 0 0 0 0 0 0 0 0 0 0 0 0
41953 - 0 0 0 0 0 0 0 0 0 0 0 0
41954 - 0 0 0 0 0 0 0 0 0 0 0 0
41955 - 0 0 0 0 0 0 0 0 0 0 0 0
41956 - 0 0 0 0 0 0 0 0 0 0 0 0
41957 - 0 0 0 0 0 0 0 0 0 0 0 0
41958 - 0 0 0 0 0 0 0 0 0 0 0 0
41959 - 0 0 0 0 0 0 0 0 0 0 0 0
41960 - 0 0 0 0 0 0 0 0 0 0 0 0
41961 - 0 0 0 0 0 0 0 0 0 10 10 10
41962 - 34 34 34 78 78 78 50 50 50 6 6 6
41963 - 94 70 30 139 102 15 190 146 13 226 184 13
41964 -232 200 30 232 195 16 215 174 15 190 146 13
41965 -168 122 10 192 133 9 210 150 10 213 154 11
41966 -202 150 34 182 157 106 101 98 89 2 2 6
41967 - 2 2 6 78 78 78 116 116 116 58 58 58
41968 - 2 2 6 22 22 22 90 90 90 46 46 46
41969 - 18 18 18 6 6 6 0 0 0 0 0 0
41970 - 0 0 0 0 0 0 0 0 0 0 0 0
41971 - 0 0 0 0 0 0 0 0 0 0 0 0
41972 - 0 0 0 0 0 0 0 0 0 0 0 0
41973 - 0 0 0 0 0 0 0 0 0 0 0 0
41974 - 0 0 0 0 0 0 0 0 0 0 0 0
41975 - 0 0 0 0 0 0 0 0 0 0 0 0
41976 - 0 0 0 0 0 0 0 0 0 0 0 0
41977 - 0 0 0 0 0 0 0 0 0 0 0 0
41978 - 0 0 0 0 0 0 0 0 0 0 0 0
41979 - 0 0 0 0 0 0 0 0 0 0 0 0
41980 - 0 0 0 0 0 0 0 0 0 0 0 0
41981 - 0 0 0 0 0 0 0 0 0 10 10 10
41982 - 38 38 38 86 86 86 50 50 50 6 6 6
41983 -128 128 128 174 154 114 156 107 11 168 122 10
41984 -198 155 10 184 144 12 197 138 11 200 144 11
41985 -206 145 10 206 145 10 197 138 11 188 164 115
41986 -195 195 195 198 198 198 174 174 174 14 14 14
41987 - 2 2 6 22 22 22 116 116 116 116 116 116
41988 - 22 22 22 2 2 6 74 74 74 70 70 70
41989 - 30 30 30 10 10 10 0 0 0 0 0 0
41990 - 0 0 0 0 0 0 0 0 0 0 0 0
41991 - 0 0 0 0 0 0 0 0 0 0 0 0
41992 - 0 0 0 0 0 0 0 0 0 0 0 0
41993 - 0 0 0 0 0 0 0 0 0 0 0 0
41994 - 0 0 0 0 0 0 0 0 0 0 0 0
41995 - 0 0 0 0 0 0 0 0 0 0 0 0
41996 - 0 0 0 0 0 0 0 0 0 0 0 0
41997 - 0 0 0 0 0 0 0 0 0 0 0 0
41998 - 0 0 0 0 0 0 0 0 0 0 0 0
41999 - 0 0 0 0 0 0 0 0 0 0 0 0
42000 - 0 0 0 0 0 0 0 0 0 0 0 0
42001 - 0 0 0 0 0 0 6 6 6 18 18 18
42002 - 50 50 50 101 101 101 26 26 26 10 10 10
42003 -138 138 138 190 190 190 174 154 114 156 107 11
42004 -197 138 11 200 144 11 197 138 11 192 133 9
42005 -180 123 7 190 142 34 190 178 144 187 187 187
42006 -202 202 202 221 221 221 214 214 214 66 66 66
42007 - 2 2 6 2 2 6 50 50 50 62 62 62
42008 - 6 6 6 2 2 6 10 10 10 90 90 90
42009 - 50 50 50 18 18 18 6 6 6 0 0 0
42010 - 0 0 0 0 0 0 0 0 0 0 0 0
42011 - 0 0 0 0 0 0 0 0 0 0 0 0
42012 - 0 0 0 0 0 0 0 0 0 0 0 0
42013 - 0 0 0 0 0 0 0 0 0 0 0 0
42014 - 0 0 0 0 0 0 0 0 0 0 0 0
42015 - 0 0 0 0 0 0 0 0 0 0 0 0
42016 - 0 0 0 0 0 0 0 0 0 0 0 0
42017 - 0 0 0 0 0 0 0 0 0 0 0 0
42018 - 0 0 0 0 0 0 0 0 0 0 0 0
42019 - 0 0 0 0 0 0 0 0 0 0 0 0
42020 - 0 0 0 0 0 0 0 0 0 0 0 0
42021 - 0 0 0 0 0 0 10 10 10 34 34 34
42022 - 74 74 74 74 74 74 2 2 6 6 6 6
42023 -144 144 144 198 198 198 190 190 190 178 166 146
42024 -154 121 60 156 107 11 156 107 11 168 124 44
42025 -174 154 114 187 187 187 190 190 190 210 210 210
42026 -246 246 246 253 253 253 253 253 253 182 182 182
42027 - 6 6 6 2 2 6 2 2 6 2 2 6
42028 - 2 2 6 2 2 6 2 2 6 62 62 62
42029 - 74 74 74 34 34 34 14 14 14 0 0 0
42030 - 0 0 0 0 0 0 0 0 0 0 0 0
42031 - 0 0 0 0 0 0 0 0 0 0 0 0
42032 - 0 0 0 0 0 0 0 0 0 0 0 0
42033 - 0 0 0 0 0 0 0 0 0 0 0 0
42034 - 0 0 0 0 0 0 0 0 0 0 0 0
42035 - 0 0 0 0 0 0 0 0 0 0 0 0
42036 - 0 0 0 0 0 0 0 0 0 0 0 0
42037 - 0 0 0 0 0 0 0 0 0 0 0 0
42038 - 0 0 0 0 0 0 0 0 0 0 0 0
42039 - 0 0 0 0 0 0 0 0 0 0 0 0
42040 - 0 0 0 0 0 0 0 0 0 0 0 0
42041 - 0 0 0 10 10 10 22 22 22 54 54 54
42042 - 94 94 94 18 18 18 2 2 6 46 46 46
42043 -234 234 234 221 221 221 190 190 190 190 190 190
42044 -190 190 190 187 187 187 187 187 187 190 190 190
42045 -190 190 190 195 195 195 214 214 214 242 242 242
42046 -253 253 253 253 253 253 253 253 253 253 253 253
42047 - 82 82 82 2 2 6 2 2 6 2 2 6
42048 - 2 2 6 2 2 6 2 2 6 14 14 14
42049 - 86 86 86 54 54 54 22 22 22 6 6 6
42050 - 0 0 0 0 0 0 0 0 0 0 0 0
42051 - 0 0 0 0 0 0 0 0 0 0 0 0
42052 - 0 0 0 0 0 0 0 0 0 0 0 0
42053 - 0 0 0 0 0 0 0 0 0 0 0 0
42054 - 0 0 0 0 0 0 0 0 0 0 0 0
42055 - 0 0 0 0 0 0 0 0 0 0 0 0
42056 - 0 0 0 0 0 0 0 0 0 0 0 0
42057 - 0 0 0 0 0 0 0 0 0 0 0 0
42058 - 0 0 0 0 0 0 0 0 0 0 0 0
42059 - 0 0 0 0 0 0 0 0 0 0 0 0
42060 - 0 0 0 0 0 0 0 0 0 0 0 0
42061 - 6 6 6 18 18 18 46 46 46 90 90 90
42062 - 46 46 46 18 18 18 6 6 6 182 182 182
42063 -253 253 253 246 246 246 206 206 206 190 190 190
42064 -190 190 190 190 190 190 190 190 190 190 190 190
42065 -206 206 206 231 231 231 250 250 250 253 253 253
42066 -253 253 253 253 253 253 253 253 253 253 253 253
42067 -202 202 202 14 14 14 2 2 6 2 2 6
42068 - 2 2 6 2 2 6 2 2 6 2 2 6
42069 - 42 42 42 86 86 86 42 42 42 18 18 18
42070 - 6 6 6 0 0 0 0 0 0 0 0 0
42071 - 0 0 0 0 0 0 0 0 0 0 0 0
42072 - 0 0 0 0 0 0 0 0 0 0 0 0
42073 - 0 0 0 0 0 0 0 0 0 0 0 0
42074 - 0 0 0 0 0 0 0 0 0 0 0 0
42075 - 0 0 0 0 0 0 0 0 0 0 0 0
42076 - 0 0 0 0 0 0 0 0 0 0 0 0
42077 - 0 0 0 0 0 0 0 0 0 0 0 0
42078 - 0 0 0 0 0 0 0 0 0 0 0 0
42079 - 0 0 0 0 0 0 0 0 0 0 0 0
42080 - 0 0 0 0 0 0 0 0 0 6 6 6
42081 - 14 14 14 38 38 38 74 74 74 66 66 66
42082 - 2 2 6 6 6 6 90 90 90 250 250 250
42083 -253 253 253 253 253 253 238 238 238 198 198 198
42084 -190 190 190 190 190 190 195 195 195 221 221 221
42085 -246 246 246 253 253 253 253 253 253 253 253 253
42086 -253 253 253 253 253 253 253 253 253 253 253 253
42087 -253 253 253 82 82 82 2 2 6 2 2 6
42088 - 2 2 6 2 2 6 2 2 6 2 2 6
42089 - 2 2 6 78 78 78 70 70 70 34 34 34
42090 - 14 14 14 6 6 6 0 0 0 0 0 0
42091 - 0 0 0 0 0 0 0 0 0 0 0 0
42092 - 0 0 0 0 0 0 0 0 0 0 0 0
42093 - 0 0 0 0 0 0 0 0 0 0 0 0
42094 - 0 0 0 0 0 0 0 0 0 0 0 0
42095 - 0 0 0 0 0 0 0 0 0 0 0 0
42096 - 0 0 0 0 0 0 0 0 0 0 0 0
42097 - 0 0 0 0 0 0 0 0 0 0 0 0
42098 - 0 0 0 0 0 0 0 0 0 0 0 0
42099 - 0 0 0 0 0 0 0 0 0 0 0 0
42100 - 0 0 0 0 0 0 0 0 0 14 14 14
42101 - 34 34 34 66 66 66 78 78 78 6 6 6
42102 - 2 2 6 18 18 18 218 218 218 253 253 253
42103 -253 253 253 253 253 253 253 253 253 246 246 246
42104 -226 226 226 231 231 231 246 246 246 253 253 253
42105 -253 253 253 253 253 253 253 253 253 253 253 253
42106 -253 253 253 253 253 253 253 253 253 253 253 253
42107 -253 253 253 178 178 178 2 2 6 2 2 6
42108 - 2 2 6 2 2 6 2 2 6 2 2 6
42109 - 2 2 6 18 18 18 90 90 90 62 62 62
42110 - 30 30 30 10 10 10 0 0 0 0 0 0
42111 - 0 0 0 0 0 0 0 0 0 0 0 0
42112 - 0 0 0 0 0 0 0 0 0 0 0 0
42113 - 0 0 0 0 0 0 0 0 0 0 0 0
42114 - 0 0 0 0 0 0 0 0 0 0 0 0
42115 - 0 0 0 0 0 0 0 0 0 0 0 0
42116 - 0 0 0 0 0 0 0 0 0 0 0 0
42117 - 0 0 0 0 0 0 0 0 0 0 0 0
42118 - 0 0 0 0 0 0 0 0 0 0 0 0
42119 - 0 0 0 0 0 0 0 0 0 0 0 0
42120 - 0 0 0 0 0 0 10 10 10 26 26 26
42121 - 58 58 58 90 90 90 18 18 18 2 2 6
42122 - 2 2 6 110 110 110 253 253 253 253 253 253
42123 -253 253 253 253 253 253 253 253 253 253 253 253
42124 -250 250 250 253 253 253 253 253 253 253 253 253
42125 -253 253 253 253 253 253 253 253 253 253 253 253
42126 -253 253 253 253 253 253 253 253 253 253 253 253
42127 -253 253 253 231 231 231 18 18 18 2 2 6
42128 - 2 2 6 2 2 6 2 2 6 2 2 6
42129 - 2 2 6 2 2 6 18 18 18 94 94 94
42130 - 54 54 54 26 26 26 10 10 10 0 0 0
42131 - 0 0 0 0 0 0 0 0 0 0 0 0
42132 - 0 0 0 0 0 0 0 0 0 0 0 0
42133 - 0 0 0 0 0 0 0 0 0 0 0 0
42134 - 0 0 0 0 0 0 0 0 0 0 0 0
42135 - 0 0 0 0 0 0 0 0 0 0 0 0
42136 - 0 0 0 0 0 0 0 0 0 0 0 0
42137 - 0 0 0 0 0 0 0 0 0 0 0 0
42138 - 0 0 0 0 0 0 0 0 0 0 0 0
42139 - 0 0 0 0 0 0 0 0 0 0 0 0
42140 - 0 0 0 6 6 6 22 22 22 50 50 50
42141 - 90 90 90 26 26 26 2 2 6 2 2 6
42142 - 14 14 14 195 195 195 250 250 250 253 253 253
42143 -253 253 253 253 253 253 253 253 253 253 253 253
42144 -253 253 253 253 253 253 253 253 253 253 253 253
42145 -253 253 253 253 253 253 253 253 253 253 253 253
42146 -253 253 253 253 253 253 253 253 253 253 253 253
42147 -250 250 250 242 242 242 54 54 54 2 2 6
42148 - 2 2 6 2 2 6 2 2 6 2 2 6
42149 - 2 2 6 2 2 6 2 2 6 38 38 38
42150 - 86 86 86 50 50 50 22 22 22 6 6 6
42151 - 0 0 0 0 0 0 0 0 0 0 0 0
42152 - 0 0 0 0 0 0 0 0 0 0 0 0
42153 - 0 0 0 0 0 0 0 0 0 0 0 0
42154 - 0 0 0 0 0 0 0 0 0 0 0 0
42155 - 0 0 0 0 0 0 0 0 0 0 0 0
42156 - 0 0 0 0 0 0 0 0 0 0 0 0
42157 - 0 0 0 0 0 0 0 0 0 0 0 0
42158 - 0 0 0 0 0 0 0 0 0 0 0 0
42159 - 0 0 0 0 0 0 0 0 0 0 0 0
42160 - 6 6 6 14 14 14 38 38 38 82 82 82
42161 - 34 34 34 2 2 6 2 2 6 2 2 6
42162 - 42 42 42 195 195 195 246 246 246 253 253 253
42163 -253 253 253 253 253 253 253 253 253 250 250 250
42164 -242 242 242 242 242 242 250 250 250 253 253 253
42165 -253 253 253 253 253 253 253 253 253 253 253 253
42166 -253 253 253 250 250 250 246 246 246 238 238 238
42167 -226 226 226 231 231 231 101 101 101 6 6 6
42168 - 2 2 6 2 2 6 2 2 6 2 2 6
42169 - 2 2 6 2 2 6 2 2 6 2 2 6
42170 - 38 38 38 82 82 82 42 42 42 14 14 14
42171 - 6 6 6 0 0 0 0 0 0 0 0 0
42172 - 0 0 0 0 0 0 0 0 0 0 0 0
42173 - 0 0 0 0 0 0 0 0 0 0 0 0
42174 - 0 0 0 0 0 0 0 0 0 0 0 0
42175 - 0 0 0 0 0 0 0 0 0 0 0 0
42176 - 0 0 0 0 0 0 0 0 0 0 0 0
42177 - 0 0 0 0 0 0 0 0 0 0 0 0
42178 - 0 0 0 0 0 0 0 0 0 0 0 0
42179 - 0 0 0 0 0 0 0 0 0 0 0 0
42180 - 10 10 10 26 26 26 62 62 62 66 66 66
42181 - 2 2 6 2 2 6 2 2 6 6 6 6
42182 - 70 70 70 170 170 170 206 206 206 234 234 234
42183 -246 246 246 250 250 250 250 250 250 238 238 238
42184 -226 226 226 231 231 231 238 238 238 250 250 250
42185 -250 250 250 250 250 250 246 246 246 231 231 231
42186 -214 214 214 206 206 206 202 202 202 202 202 202
42187 -198 198 198 202 202 202 182 182 182 18 18 18
42188 - 2 2 6 2 2 6 2 2 6 2 2 6
42189 - 2 2 6 2 2 6 2 2 6 2 2 6
42190 - 2 2 6 62 62 62 66 66 66 30 30 30
42191 - 10 10 10 0 0 0 0 0 0 0 0 0
42192 - 0 0 0 0 0 0 0 0 0 0 0 0
42193 - 0 0 0 0 0 0 0 0 0 0 0 0
42194 - 0 0 0 0 0 0 0 0 0 0 0 0
42195 - 0 0 0 0 0 0 0 0 0 0 0 0
42196 - 0 0 0 0 0 0 0 0 0 0 0 0
42197 - 0 0 0 0 0 0 0 0 0 0 0 0
42198 - 0 0 0 0 0 0 0 0 0 0 0 0
42199 - 0 0 0 0 0 0 0 0 0 0 0 0
42200 - 14 14 14 42 42 42 82 82 82 18 18 18
42201 - 2 2 6 2 2 6 2 2 6 10 10 10
42202 - 94 94 94 182 182 182 218 218 218 242 242 242
42203 -250 250 250 253 253 253 253 253 253 250 250 250
42204 -234 234 234 253 253 253 253 253 253 253 253 253
42205 -253 253 253 253 253 253 253 253 253 246 246 246
42206 -238 238 238 226 226 226 210 210 210 202 202 202
42207 -195 195 195 195 195 195 210 210 210 158 158 158
42208 - 6 6 6 14 14 14 50 50 50 14 14 14
42209 - 2 2 6 2 2 6 2 2 6 2 2 6
42210 - 2 2 6 6 6 6 86 86 86 46 46 46
42211 - 18 18 18 6 6 6 0 0 0 0 0 0
42212 - 0 0 0 0 0 0 0 0 0 0 0 0
42213 - 0 0 0 0 0 0 0 0 0 0 0 0
42214 - 0 0 0 0 0 0 0 0 0 0 0 0
42215 - 0 0 0 0 0 0 0 0 0 0 0 0
42216 - 0 0 0 0 0 0 0 0 0 0 0 0
42217 - 0 0 0 0 0 0 0 0 0 0 0 0
42218 - 0 0 0 0 0 0 0 0 0 0 0 0
42219 - 0 0 0 0 0 0 0 0 0 6 6 6
42220 - 22 22 22 54 54 54 70 70 70 2 2 6
42221 - 2 2 6 10 10 10 2 2 6 22 22 22
42222 -166 166 166 231 231 231 250 250 250 253 253 253
42223 -253 253 253 253 253 253 253 253 253 250 250 250
42224 -242 242 242 253 253 253 253 253 253 253 253 253
42225 -253 253 253 253 253 253 253 253 253 253 253 253
42226 -253 253 253 253 253 253 253 253 253 246 246 246
42227 -231 231 231 206 206 206 198 198 198 226 226 226
42228 - 94 94 94 2 2 6 6 6 6 38 38 38
42229 - 30 30 30 2 2 6 2 2 6 2 2 6
42230 - 2 2 6 2 2 6 62 62 62 66 66 66
42231 - 26 26 26 10 10 10 0 0 0 0 0 0
42232 - 0 0 0 0 0 0 0 0 0 0 0 0
42233 - 0 0 0 0 0 0 0 0 0 0 0 0
42234 - 0 0 0 0 0 0 0 0 0 0 0 0
42235 - 0 0 0 0 0 0 0 0 0 0 0 0
42236 - 0 0 0 0 0 0 0 0 0 0 0 0
42237 - 0 0 0 0 0 0 0 0 0 0 0 0
42238 - 0 0 0 0 0 0 0 0 0 0 0 0
42239 - 0 0 0 0 0 0 0 0 0 10 10 10
42240 - 30 30 30 74 74 74 50 50 50 2 2 6
42241 - 26 26 26 26 26 26 2 2 6 106 106 106
42242 -238 238 238 253 253 253 253 253 253 253 253 253
42243 -253 253 253 253 253 253 253 253 253 253 253 253
42244 -253 253 253 253 253 253 253 253 253 253 253 253
42245 -253 253 253 253 253 253 253 253 253 253 253 253
42246 -253 253 253 253 253 253 253 253 253 253 253 253
42247 -253 253 253 246 246 246 218 218 218 202 202 202
42248 -210 210 210 14 14 14 2 2 6 2 2 6
42249 - 30 30 30 22 22 22 2 2 6 2 2 6
42250 - 2 2 6 2 2 6 18 18 18 86 86 86
42251 - 42 42 42 14 14 14 0 0 0 0 0 0
42252 - 0 0 0 0 0 0 0 0 0 0 0 0
42253 - 0 0 0 0 0 0 0 0 0 0 0 0
42254 - 0 0 0 0 0 0 0 0 0 0 0 0
42255 - 0 0 0 0 0 0 0 0 0 0 0 0
42256 - 0 0 0 0 0 0 0 0 0 0 0 0
42257 - 0 0 0 0 0 0 0 0 0 0 0 0
42258 - 0 0 0 0 0 0 0 0 0 0 0 0
42259 - 0 0 0 0 0 0 0 0 0 14 14 14
42260 - 42 42 42 90 90 90 22 22 22 2 2 6
42261 - 42 42 42 2 2 6 18 18 18 218 218 218
42262 -253 253 253 253 253 253 253 253 253 253 253 253
42263 -253 253 253 253 253 253 253 253 253 253 253 253
42264 -253 253 253 253 253 253 253 253 253 253 253 253
42265 -253 253 253 253 253 253 253 253 253 253 253 253
42266 -253 253 253 253 253 253 253 253 253 253 253 253
42267 -253 253 253 253 253 253 250 250 250 221 221 221
42268 -218 218 218 101 101 101 2 2 6 14 14 14
42269 - 18 18 18 38 38 38 10 10 10 2 2 6
42270 - 2 2 6 2 2 6 2 2 6 78 78 78
42271 - 58 58 58 22 22 22 6 6 6 0 0 0
42272 - 0 0 0 0 0 0 0 0 0 0 0 0
42273 - 0 0 0 0 0 0 0 0 0 0 0 0
42274 - 0 0 0 0 0 0 0 0 0 0 0 0
42275 - 0 0 0 0 0 0 0 0 0 0 0 0
42276 - 0 0 0 0 0 0 0 0 0 0 0 0
42277 - 0 0 0 0 0 0 0 0 0 0 0 0
42278 - 0 0 0 0 0 0 0 0 0 0 0 0
42279 - 0 0 0 0 0 0 6 6 6 18 18 18
42280 - 54 54 54 82 82 82 2 2 6 26 26 26
42281 - 22 22 22 2 2 6 123 123 123 253 253 253
42282 -253 253 253 253 253 253 253 253 253 253 253 253
42283 -253 253 253 253 253 253 253 253 253 253 253 253
42284 -253 253 253 253 253 253 253 253 253 253 253 253
42285 -253 253 253 253 253 253 253 253 253 253 253 253
42286 -253 253 253 253 253 253 253 253 253 253 253 253
42287 -253 253 253 253 253 253 253 253 253 250 250 250
42288 -238 238 238 198 198 198 6 6 6 38 38 38
42289 - 58 58 58 26 26 26 38 38 38 2 2 6
42290 - 2 2 6 2 2 6 2 2 6 46 46 46
42291 - 78 78 78 30 30 30 10 10 10 0 0 0
42292 - 0 0 0 0 0 0 0 0 0 0 0 0
42293 - 0 0 0 0 0 0 0 0 0 0 0 0
42294 - 0 0 0 0 0 0 0 0 0 0 0 0
42295 - 0 0 0 0 0 0 0 0 0 0 0 0
42296 - 0 0 0 0 0 0 0 0 0 0 0 0
42297 - 0 0 0 0 0 0 0 0 0 0 0 0
42298 - 0 0 0 0 0 0 0 0 0 0 0 0
42299 - 0 0 0 0 0 0 10 10 10 30 30 30
42300 - 74 74 74 58 58 58 2 2 6 42 42 42
42301 - 2 2 6 22 22 22 231 231 231 253 253 253
42302 -253 253 253 253 253 253 253 253 253 253 253 253
42303 -253 253 253 253 253 253 253 253 253 250 250 250
42304 -253 253 253 253 253 253 253 253 253 253 253 253
42305 -253 253 253 253 253 253 253 253 253 253 253 253
42306 -253 253 253 253 253 253 253 253 253 253 253 253
42307 -253 253 253 253 253 253 253 253 253 253 253 253
42308 -253 253 253 246 246 246 46 46 46 38 38 38
42309 - 42 42 42 14 14 14 38 38 38 14 14 14
42310 - 2 2 6 2 2 6 2 2 6 6 6 6
42311 - 86 86 86 46 46 46 14 14 14 0 0 0
42312 - 0 0 0 0 0 0 0 0 0 0 0 0
42313 - 0 0 0 0 0 0 0 0 0 0 0 0
42314 - 0 0 0 0 0 0 0 0 0 0 0 0
42315 - 0 0 0 0 0 0 0 0 0 0 0 0
42316 - 0 0 0 0 0 0 0 0 0 0 0 0
42317 - 0 0 0 0 0 0 0 0 0 0 0 0
42318 - 0 0 0 0 0 0 0 0 0 0 0 0
42319 - 0 0 0 6 6 6 14 14 14 42 42 42
42320 - 90 90 90 18 18 18 18 18 18 26 26 26
42321 - 2 2 6 116 116 116 253 253 253 253 253 253
42322 -253 253 253 253 253 253 253 253 253 253 253 253
42323 -253 253 253 253 253 253 250 250 250 238 238 238
42324 -253 253 253 253 253 253 253 253 253 253 253 253
42325 -253 253 253 253 253 253 253 253 253 253 253 253
42326 -253 253 253 253 253 253 253 253 253 253 253 253
42327 -253 253 253 253 253 253 253 253 253 253 253 253
42328 -253 253 253 253 253 253 94 94 94 6 6 6
42329 - 2 2 6 2 2 6 10 10 10 34 34 34
42330 - 2 2 6 2 2 6 2 2 6 2 2 6
42331 - 74 74 74 58 58 58 22 22 22 6 6 6
42332 - 0 0 0 0 0 0 0 0 0 0 0 0
42333 - 0 0 0 0 0 0 0 0 0 0 0 0
42334 - 0 0 0 0 0 0 0 0 0 0 0 0
42335 - 0 0 0 0 0 0 0 0 0 0 0 0
42336 - 0 0 0 0 0 0 0 0 0 0 0 0
42337 - 0 0 0 0 0 0 0 0 0 0 0 0
42338 - 0 0 0 0 0 0 0 0 0 0 0 0
42339 - 0 0 0 10 10 10 26 26 26 66 66 66
42340 - 82 82 82 2 2 6 38 38 38 6 6 6
42341 - 14 14 14 210 210 210 253 253 253 253 253 253
42342 -253 253 253 253 253 253 253 253 253 253 253 253
42343 -253 253 253 253 253 253 246 246 246 242 242 242
42344 -253 253 253 253 253 253 253 253 253 253 253 253
42345 -253 253 253 253 253 253 253 253 253 253 253 253
42346 -253 253 253 253 253 253 253 253 253 253 253 253
42347 -253 253 253 253 253 253 253 253 253 253 253 253
42348 -253 253 253 253 253 253 144 144 144 2 2 6
42349 - 2 2 6 2 2 6 2 2 6 46 46 46
42350 - 2 2 6 2 2 6 2 2 6 2 2 6
42351 - 42 42 42 74 74 74 30 30 30 10 10 10
42352 - 0 0 0 0 0 0 0 0 0 0 0 0
42353 - 0 0 0 0 0 0 0 0 0 0 0 0
42354 - 0 0 0 0 0 0 0 0 0 0 0 0
42355 - 0 0 0 0 0 0 0 0 0 0 0 0
42356 - 0 0 0 0 0 0 0 0 0 0 0 0
42357 - 0 0 0 0 0 0 0 0 0 0 0 0
42358 - 0 0 0 0 0 0 0 0 0 0 0 0
42359 - 6 6 6 14 14 14 42 42 42 90 90 90
42360 - 26 26 26 6 6 6 42 42 42 2 2 6
42361 - 74 74 74 250 250 250 253 253 253 253 253 253
42362 -253 253 253 253 253 253 253 253 253 253 253 253
42363 -253 253 253 253 253 253 242 242 242 242 242 242
42364 -253 253 253 253 253 253 253 253 253 253 253 253
42365 -253 253 253 253 253 253 253 253 253 253 253 253
42366 -253 253 253 253 253 253 253 253 253 253 253 253
42367 -253 253 253 253 253 253 253 253 253 253 253 253
42368 -253 253 253 253 253 253 182 182 182 2 2 6
42369 - 2 2 6 2 2 6 2 2 6 46 46 46
42370 - 2 2 6 2 2 6 2 2 6 2 2 6
42371 - 10 10 10 86 86 86 38 38 38 10 10 10
42372 - 0 0 0 0 0 0 0 0 0 0 0 0
42373 - 0 0 0 0 0 0 0 0 0 0 0 0
42374 - 0 0 0 0 0 0 0 0 0 0 0 0
42375 - 0 0 0 0 0 0 0 0 0 0 0 0
42376 - 0 0 0 0 0 0 0 0 0 0 0 0
42377 - 0 0 0 0 0 0 0 0 0 0 0 0
42378 - 0 0 0 0 0 0 0 0 0 0 0 0
42379 - 10 10 10 26 26 26 66 66 66 82 82 82
42380 - 2 2 6 22 22 22 18 18 18 2 2 6
42381 -149 149 149 253 253 253 253 253 253 253 253 253
42382 -253 253 253 253 253 253 253 253 253 253 253 253
42383 -253 253 253 253 253 253 234 234 234 242 242 242
42384 -253 253 253 253 253 253 253 253 253 253 253 253
42385 -253 253 253 253 253 253 253 253 253 253 253 253
42386 -253 253 253 253 253 253 253 253 253 253 253 253
42387 -253 253 253 253 253 253 253 253 253 253 253 253
42388 -253 253 253 253 253 253 206 206 206 2 2 6
42389 - 2 2 6 2 2 6 2 2 6 38 38 38
42390 - 2 2 6 2 2 6 2 2 6 2 2 6
42391 - 6 6 6 86 86 86 46 46 46 14 14 14
42392 - 0 0 0 0 0 0 0 0 0 0 0 0
42393 - 0 0 0 0 0 0 0 0 0 0 0 0
42394 - 0 0 0 0 0 0 0 0 0 0 0 0
42395 - 0 0 0 0 0 0 0 0 0 0 0 0
42396 - 0 0 0 0 0 0 0 0 0 0 0 0
42397 - 0 0 0 0 0 0 0 0 0 0 0 0
42398 - 0 0 0 0 0 0 0 0 0 6 6 6
42399 - 18 18 18 46 46 46 86 86 86 18 18 18
42400 - 2 2 6 34 34 34 10 10 10 6 6 6
42401 -210 210 210 253 253 253 253 253 253 253 253 253
42402 -253 253 253 253 253 253 253 253 253 253 253 253
42403 -253 253 253 253 253 253 234 234 234 242 242 242
42404 -253 253 253 253 253 253 253 253 253 253 253 253
42405 -253 253 253 253 253 253 253 253 253 253 253 253
42406 -253 253 253 253 253 253 253 253 253 253 253 253
42407 -253 253 253 253 253 253 253 253 253 253 253 253
42408 -253 253 253 253 253 253 221 221 221 6 6 6
42409 - 2 2 6 2 2 6 6 6 6 30 30 30
42410 - 2 2 6 2 2 6 2 2 6 2 2 6
42411 - 2 2 6 82 82 82 54 54 54 18 18 18
42412 - 6 6 6 0 0 0 0 0 0 0 0 0
42413 - 0 0 0 0 0 0 0 0 0 0 0 0
42414 - 0 0 0 0 0 0 0 0 0 0 0 0
42415 - 0 0 0 0 0 0 0 0 0 0 0 0
42416 - 0 0 0 0 0 0 0 0 0 0 0 0
42417 - 0 0 0 0 0 0 0 0 0 0 0 0
42418 - 0 0 0 0 0 0 0 0 0 10 10 10
42419 - 26 26 26 66 66 66 62 62 62 2 2 6
42420 - 2 2 6 38 38 38 10 10 10 26 26 26
42421 -238 238 238 253 253 253 253 253 253 253 253 253
42422 -253 253 253 253 253 253 253 253 253 253 253 253
42423 -253 253 253 253 253 253 231 231 231 238 238 238
42424 -253 253 253 253 253 253 253 253 253 253 253 253
42425 -253 253 253 253 253 253 253 253 253 253 253 253
42426 -253 253 253 253 253 253 253 253 253 253 253 253
42427 -253 253 253 253 253 253 253 253 253 253 253 253
42428 -253 253 253 253 253 253 231 231 231 6 6 6
42429 - 2 2 6 2 2 6 10 10 10 30 30 30
42430 - 2 2 6 2 2 6 2 2 6 2 2 6
42431 - 2 2 6 66 66 66 58 58 58 22 22 22
42432 - 6 6 6 0 0 0 0 0 0 0 0 0
42433 - 0 0 0 0 0 0 0 0 0 0 0 0
42434 - 0 0 0 0 0 0 0 0 0 0 0 0
42435 - 0 0 0 0 0 0 0 0 0 0 0 0
42436 - 0 0 0 0 0 0 0 0 0 0 0 0
42437 - 0 0 0 0 0 0 0 0 0 0 0 0
42438 - 0 0 0 0 0 0 0 0 0 10 10 10
42439 - 38 38 38 78 78 78 6 6 6 2 2 6
42440 - 2 2 6 46 46 46 14 14 14 42 42 42
42441 -246 246 246 253 253 253 253 253 253 253 253 253
42442 -253 253 253 253 253 253 253 253 253 253 253 253
42443 -253 253 253 253 253 253 231 231 231 242 242 242
42444 -253 253 253 253 253 253 253 253 253 253 253 253
42445 -253 253 253 253 253 253 253 253 253 253 253 253
42446 -253 253 253 253 253 253 253 253 253 253 253 253
42447 -253 253 253 253 253 253 253 253 253 253 253 253
42448 -253 253 253 253 253 253 234 234 234 10 10 10
42449 - 2 2 6 2 2 6 22 22 22 14 14 14
42450 - 2 2 6 2 2 6 2 2 6 2 2 6
42451 - 2 2 6 66 66 66 62 62 62 22 22 22
42452 - 6 6 6 0 0 0 0 0 0 0 0 0
42453 - 0 0 0 0 0 0 0 0 0 0 0 0
42454 - 0 0 0 0 0 0 0 0 0 0 0 0
42455 - 0 0 0 0 0 0 0 0 0 0 0 0
42456 - 0 0 0 0 0 0 0 0 0 0 0 0
42457 - 0 0 0 0 0 0 0 0 0 0 0 0
42458 - 0 0 0 0 0 0 6 6 6 18 18 18
42459 - 50 50 50 74 74 74 2 2 6 2 2 6
42460 - 14 14 14 70 70 70 34 34 34 62 62 62
42461 -250 250 250 253 253 253 253 253 253 253 253 253
42462 -253 253 253 253 253 253 253 253 253 253 253 253
42463 -253 253 253 253 253 253 231 231 231 246 246 246
42464 -253 253 253 253 253 253 253 253 253 253 253 253
42465 -253 253 253 253 253 253 253 253 253 253 253 253
42466 -253 253 253 253 253 253 253 253 253 253 253 253
42467 -253 253 253 253 253 253 253 253 253 253 253 253
42468 -253 253 253 253 253 253 234 234 234 14 14 14
42469 - 2 2 6 2 2 6 30 30 30 2 2 6
42470 - 2 2 6 2 2 6 2 2 6 2 2 6
42471 - 2 2 6 66 66 66 62 62 62 22 22 22
42472 - 6 6 6 0 0 0 0 0 0 0 0 0
42473 - 0 0 0 0 0 0 0 0 0 0 0 0
42474 - 0 0 0 0 0 0 0 0 0 0 0 0
42475 - 0 0 0 0 0 0 0 0 0 0 0 0
42476 - 0 0 0 0 0 0 0 0 0 0 0 0
42477 - 0 0 0 0 0 0 0 0 0 0 0 0
42478 - 0 0 0 0 0 0 6 6 6 18 18 18
42479 - 54 54 54 62 62 62 2 2 6 2 2 6
42480 - 2 2 6 30 30 30 46 46 46 70 70 70
42481 -250 250 250 253 253 253 253 253 253 253 253 253
42482 -253 253 253 253 253 253 253 253 253 253 253 253
42483 -253 253 253 253 253 253 231 231 231 246 246 246
42484 -253 253 253 253 253 253 253 253 253 253 253 253
42485 -253 253 253 253 253 253 253 253 253 253 253 253
42486 -253 253 253 253 253 253 253 253 253 253 253 253
42487 -253 253 253 253 253 253 253 253 253 253 253 253
42488 -253 253 253 253 253 253 226 226 226 10 10 10
42489 - 2 2 6 6 6 6 30 30 30 2 2 6
42490 - 2 2 6 2 2 6 2 2 6 2 2 6
42491 - 2 2 6 66 66 66 58 58 58 22 22 22
42492 - 6 6 6 0 0 0 0 0 0 0 0 0
42493 - 0 0 0 0 0 0 0 0 0 0 0 0
42494 - 0 0 0 0 0 0 0 0 0 0 0 0
42495 - 0 0 0 0 0 0 0 0 0 0 0 0
42496 - 0 0 0 0 0 0 0 0 0 0 0 0
42497 - 0 0 0 0 0 0 0 0 0 0 0 0
42498 - 0 0 0 0 0 0 6 6 6 22 22 22
42499 - 58 58 58 62 62 62 2 2 6 2 2 6
42500 - 2 2 6 2 2 6 30 30 30 78 78 78
42501 -250 250 250 253 253 253 253 253 253 253 253 253
42502 -253 253 253 253 253 253 253 253 253 253 253 253
42503 -253 253 253 253 253 253 231 231 231 246 246 246
42504 -253 253 253 253 253 253 253 253 253 253 253 253
42505 -253 253 253 253 253 253 253 253 253 253 253 253
42506 -253 253 253 253 253 253 253 253 253 253 253 253
42507 -253 253 253 253 253 253 253 253 253 253 253 253
42508 -253 253 253 253 253 253 206 206 206 2 2 6
42509 - 22 22 22 34 34 34 18 14 6 22 22 22
42510 - 26 26 26 18 18 18 6 6 6 2 2 6
42511 - 2 2 6 82 82 82 54 54 54 18 18 18
42512 - 6 6 6 0 0 0 0 0 0 0 0 0
42513 - 0 0 0 0 0 0 0 0 0 0 0 0
42514 - 0 0 0 0 0 0 0 0 0 0 0 0
42515 - 0 0 0 0 0 0 0 0 0 0 0 0
42516 - 0 0 0 0 0 0 0 0 0 0 0 0
42517 - 0 0 0 0 0 0 0 0 0 0 0 0
42518 - 0 0 0 0 0 0 6 6 6 26 26 26
42519 - 62 62 62 106 106 106 74 54 14 185 133 11
42520 -210 162 10 121 92 8 6 6 6 62 62 62
42521 -238 238 238 253 253 253 253 253 253 253 253 253
42522 -253 253 253 253 253 253 253 253 253 253 253 253
42523 -253 253 253 253 253 253 231 231 231 246 246 246
42524 -253 253 253 253 253 253 253 253 253 253 253 253
42525 -253 253 253 253 253 253 253 253 253 253 253 253
42526 -253 253 253 253 253 253 253 253 253 253 253 253
42527 -253 253 253 253 253 253 253 253 253 253 253 253
42528 -253 253 253 253 253 253 158 158 158 18 18 18
42529 - 14 14 14 2 2 6 2 2 6 2 2 6
42530 - 6 6 6 18 18 18 66 66 66 38 38 38
42531 - 6 6 6 94 94 94 50 50 50 18 18 18
42532 - 6 6 6 0 0 0 0 0 0 0 0 0
42533 - 0 0 0 0 0 0 0 0 0 0 0 0
42534 - 0 0 0 0 0 0 0 0 0 0 0 0
42535 - 0 0 0 0 0 0 0 0 0 0 0 0
42536 - 0 0 0 0 0 0 0 0 0 0 0 0
42537 - 0 0 0 0 0 0 0 0 0 6 6 6
42538 - 10 10 10 10 10 10 18 18 18 38 38 38
42539 - 78 78 78 142 134 106 216 158 10 242 186 14
42540 -246 190 14 246 190 14 156 118 10 10 10 10
42541 - 90 90 90 238 238 238 253 253 253 253 253 253
42542 -253 253 253 253 253 253 253 253 253 253 253 253
42543 -253 253 253 253 253 253 231 231 231 250 250 250
42544 -253 253 253 253 253 253 253 253 253 253 253 253
42545 -253 253 253 253 253 253 253 253 253 253 253 253
42546 -253 253 253 253 253 253 253 253 253 253 253 253
42547 -253 253 253 253 253 253 253 253 253 246 230 190
42548 -238 204 91 238 204 91 181 142 44 37 26 9
42549 - 2 2 6 2 2 6 2 2 6 2 2 6
42550 - 2 2 6 2 2 6 38 38 38 46 46 46
42551 - 26 26 26 106 106 106 54 54 54 18 18 18
42552 - 6 6 6 0 0 0 0 0 0 0 0 0
42553 - 0 0 0 0 0 0 0 0 0 0 0 0
42554 - 0 0 0 0 0 0 0 0 0 0 0 0
42555 - 0 0 0 0 0 0 0 0 0 0 0 0
42556 - 0 0 0 0 0 0 0 0 0 0 0 0
42557 - 0 0 0 6 6 6 14 14 14 22 22 22
42558 - 30 30 30 38 38 38 50 50 50 70 70 70
42559 -106 106 106 190 142 34 226 170 11 242 186 14
42560 -246 190 14 246 190 14 246 190 14 154 114 10
42561 - 6 6 6 74 74 74 226 226 226 253 253 253
42562 -253 253 253 253 253 253 253 253 253 253 253 253
42563 -253 253 253 253 253 253 231 231 231 250 250 250
42564 -253 253 253 253 253 253 253 253 253 253 253 253
42565 -253 253 253 253 253 253 253 253 253 253 253 253
42566 -253 253 253 253 253 253 253 253 253 253 253 253
42567 -253 253 253 253 253 253 253 253 253 228 184 62
42568 -241 196 14 241 208 19 232 195 16 38 30 10
42569 - 2 2 6 2 2 6 2 2 6 2 2 6
42570 - 2 2 6 6 6 6 30 30 30 26 26 26
42571 -203 166 17 154 142 90 66 66 66 26 26 26
42572 - 6 6 6 0 0 0 0 0 0 0 0 0
42573 - 0 0 0 0 0 0 0 0 0 0 0 0
42574 - 0 0 0 0 0 0 0 0 0 0 0 0
42575 - 0 0 0 0 0 0 0 0 0 0 0 0
42576 - 0 0 0 0 0 0 0 0 0 0 0 0
42577 - 6 6 6 18 18 18 38 38 38 58 58 58
42578 - 78 78 78 86 86 86 101 101 101 123 123 123
42579 -175 146 61 210 150 10 234 174 13 246 186 14
42580 -246 190 14 246 190 14 246 190 14 238 190 10
42581 -102 78 10 2 2 6 46 46 46 198 198 198
42582 -253 253 253 253 253 253 253 253 253 253 253 253
42583 -253 253 253 253 253 253 234 234 234 242 242 242
42584 -253 253 253 253 253 253 253 253 253 253 253 253
42585 -253 253 253 253 253 253 253 253 253 253 253 253
42586 -253 253 253 253 253 253 253 253 253 253 253 253
42587 -253 253 253 253 253 253 253 253 253 224 178 62
42588 -242 186 14 241 196 14 210 166 10 22 18 6
42589 - 2 2 6 2 2 6 2 2 6 2 2 6
42590 - 2 2 6 2 2 6 6 6 6 121 92 8
42591 -238 202 15 232 195 16 82 82 82 34 34 34
42592 - 10 10 10 0 0 0 0 0 0 0 0 0
42593 - 0 0 0 0 0 0 0 0 0 0 0 0
42594 - 0 0 0 0 0 0 0 0 0 0 0 0
42595 - 0 0 0 0 0 0 0 0 0 0 0 0
42596 - 0 0 0 0 0 0 0 0 0 0 0 0
42597 - 14 14 14 38 38 38 70 70 70 154 122 46
42598 -190 142 34 200 144 11 197 138 11 197 138 11
42599 -213 154 11 226 170 11 242 186 14 246 190 14
42600 -246 190 14 246 190 14 246 190 14 246 190 14
42601 -225 175 15 46 32 6 2 2 6 22 22 22
42602 -158 158 158 250 250 250 253 253 253 253 253 253
42603 -253 253 253 253 253 253 253 253 253 253 253 253
42604 -253 253 253 253 253 253 253 253 253 253 253 253
42605 -253 253 253 253 253 253 253 253 253 253 253 253
42606 -253 253 253 253 253 253 253 253 253 253 253 253
42607 -253 253 253 250 250 250 242 242 242 224 178 62
42608 -239 182 13 236 186 11 213 154 11 46 32 6
42609 - 2 2 6 2 2 6 2 2 6 2 2 6
42610 - 2 2 6 2 2 6 61 42 6 225 175 15
42611 -238 190 10 236 186 11 112 100 78 42 42 42
42612 - 14 14 14 0 0 0 0 0 0 0 0 0
42613 - 0 0 0 0 0 0 0 0 0 0 0 0
42614 - 0 0 0 0 0 0 0 0 0 0 0 0
42615 - 0 0 0 0 0 0 0 0 0 0 0 0
42616 - 0 0 0 0 0 0 0 0 0 6 6 6
42617 - 22 22 22 54 54 54 154 122 46 213 154 11
42618 -226 170 11 230 174 11 226 170 11 226 170 11
42619 -236 178 12 242 186 14 246 190 14 246 190 14
42620 -246 190 14 246 190 14 246 190 14 246 190 14
42621 -241 196 14 184 144 12 10 10 10 2 2 6
42622 - 6 6 6 116 116 116 242 242 242 253 253 253
42623 -253 253 253 253 253 253 253 253 253 253 253 253
42624 -253 253 253 253 253 253 253 253 253 253 253 253
42625 -253 253 253 253 253 253 253 253 253 253 253 253
42626 -253 253 253 253 253 253 253 253 253 253 253 253
42627 -253 253 253 231 231 231 198 198 198 214 170 54
42628 -236 178 12 236 178 12 210 150 10 137 92 6
42629 - 18 14 6 2 2 6 2 2 6 2 2 6
42630 - 6 6 6 70 47 6 200 144 11 236 178 12
42631 -239 182 13 239 182 13 124 112 88 58 58 58
42632 - 22 22 22 6 6 6 0 0 0 0 0 0
42633 - 0 0 0 0 0 0 0 0 0 0 0 0
42634 - 0 0 0 0 0 0 0 0 0 0 0 0
42635 - 0 0 0 0 0 0 0 0 0 0 0 0
42636 - 0 0 0 0 0 0 0 0 0 10 10 10
42637 - 30 30 30 70 70 70 180 133 36 226 170 11
42638 -239 182 13 242 186 14 242 186 14 246 186 14
42639 -246 190 14 246 190 14 246 190 14 246 190 14
42640 -246 190 14 246 190 14 246 190 14 246 190 14
42641 -246 190 14 232 195 16 98 70 6 2 2 6
42642 - 2 2 6 2 2 6 66 66 66 221 221 221
42643 -253 253 253 253 253 253 253 253 253 253 253 253
42644 -253 253 253 253 253 253 253 253 253 253 253 253
42645 -253 253 253 253 253 253 253 253 253 253 253 253
42646 -253 253 253 253 253 253 253 253 253 253 253 253
42647 -253 253 253 206 206 206 198 198 198 214 166 58
42648 -230 174 11 230 174 11 216 158 10 192 133 9
42649 -163 110 8 116 81 8 102 78 10 116 81 8
42650 -167 114 7 197 138 11 226 170 11 239 182 13
42651 -242 186 14 242 186 14 162 146 94 78 78 78
42652 - 34 34 34 14 14 14 6 6 6 0 0 0
42653 - 0 0 0 0 0 0 0 0 0 0 0 0
42654 - 0 0 0 0 0 0 0 0 0 0 0 0
42655 - 0 0 0 0 0 0 0 0 0 0 0 0
42656 - 0 0 0 0 0 0 0 0 0 6 6 6
42657 - 30 30 30 78 78 78 190 142 34 226 170 11
42658 -239 182 13 246 190 14 246 190 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 241 196 14 203 166 17 22 18 6
42662 - 2 2 6 2 2 6 2 2 6 38 38 38
42663 -218 218 218 253 253 253 253 253 253 253 253 253
42664 -253 253 253 253 253 253 253 253 253 253 253 253
42665 -253 253 253 253 253 253 253 253 253 253 253 253
42666 -253 253 253 253 253 253 253 253 253 253 253 253
42667 -250 250 250 206 206 206 198 198 198 202 162 69
42668 -226 170 11 236 178 12 224 166 10 210 150 10
42669 -200 144 11 197 138 11 192 133 9 197 138 11
42670 -210 150 10 226 170 11 242 186 14 246 190 14
42671 -246 190 14 246 186 14 225 175 15 124 112 88
42672 - 62 62 62 30 30 30 14 14 14 6 6 6
42673 - 0 0 0 0 0 0 0 0 0 0 0 0
42674 - 0 0 0 0 0 0 0 0 0 0 0 0
42675 - 0 0 0 0 0 0 0 0 0 0 0 0
42676 - 0 0 0 0 0 0 0 0 0 10 10 10
42677 - 30 30 30 78 78 78 174 135 50 224 166 10
42678 -239 182 13 246 190 14 246 190 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 241 196 14 139 102 15
42682 - 2 2 6 2 2 6 2 2 6 2 2 6
42683 - 78 78 78 250 250 250 253 253 253 253 253 253
42684 -253 253 253 253 253 253 253 253 253 253 253 253
42685 -253 253 253 253 253 253 253 253 253 253 253 253
42686 -253 253 253 253 253 253 253 253 253 253 253 253
42687 -250 250 250 214 214 214 198 198 198 190 150 46
42688 -219 162 10 236 178 12 234 174 13 224 166 10
42689 -216 158 10 213 154 11 213 154 11 216 158 10
42690 -226 170 11 239 182 13 246 190 14 246 190 14
42691 -246 190 14 246 190 14 242 186 14 206 162 42
42692 -101 101 101 58 58 58 30 30 30 14 14 14
42693 - 6 6 6 0 0 0 0 0 0 0 0 0
42694 - 0 0 0 0 0 0 0 0 0 0 0 0
42695 - 0 0 0 0 0 0 0 0 0 0 0 0
42696 - 0 0 0 0 0 0 0 0 0 10 10 10
42697 - 30 30 30 74 74 74 174 135 50 216 158 10
42698 -236 178 12 246 190 14 246 190 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 241 196 14 226 184 13
42702 - 61 42 6 2 2 6 2 2 6 2 2 6
42703 - 22 22 22 238 238 238 253 253 253 253 253 253
42704 -253 253 253 253 253 253 253 253 253 253 253 253
42705 -253 253 253 253 253 253 253 253 253 253 253 253
42706 -253 253 253 253 253 253 253 253 253 253 253 253
42707 -253 253 253 226 226 226 187 187 187 180 133 36
42708 -216 158 10 236 178 12 239 182 13 236 178 12
42709 -230 174 11 226 170 11 226 170 11 230 174 11
42710 -236 178 12 242 186 14 246 190 14 246 190 14
42711 -246 190 14 246 190 14 246 186 14 239 182 13
42712 -206 162 42 106 106 106 66 66 66 34 34 34
42713 - 14 14 14 6 6 6 0 0 0 0 0 0
42714 - 0 0 0 0 0 0 0 0 0 0 0 0
42715 - 0 0 0 0 0 0 0 0 0 0 0 0
42716 - 0 0 0 0 0 0 0 0 0 6 6 6
42717 - 26 26 26 70 70 70 163 133 67 213 154 11
42718 -236 178 12 246 190 14 246 190 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 241 196 14
42722 -190 146 13 18 14 6 2 2 6 2 2 6
42723 - 46 46 46 246 246 246 253 253 253 253 253 253
42724 -253 253 253 253 253 253 253 253 253 253 253 253
42725 -253 253 253 253 253 253 253 253 253 253 253 253
42726 -253 253 253 253 253 253 253 253 253 253 253 253
42727 -253 253 253 221 221 221 86 86 86 156 107 11
42728 -216 158 10 236 178 12 242 186 14 246 186 14
42729 -242 186 14 239 182 13 239 182 13 242 186 14
42730 -242 186 14 246 186 14 246 190 14 246 190 14
42731 -246 190 14 246 190 14 246 190 14 246 190 14
42732 -242 186 14 225 175 15 142 122 72 66 66 66
42733 - 30 30 30 10 10 10 0 0 0 0 0 0
42734 - 0 0 0 0 0 0 0 0 0 0 0 0
42735 - 0 0 0 0 0 0 0 0 0 0 0 0
42736 - 0 0 0 0 0 0 0 0 0 6 6 6
42737 - 26 26 26 70 70 70 163 133 67 210 150 10
42738 -236 178 12 246 190 14 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 246 190 14 246 190 14 246 190 14
42742 -232 195 16 121 92 8 34 34 34 106 106 106
42743 -221 221 221 253 253 253 253 253 253 253 253 253
42744 -253 253 253 253 253 253 253 253 253 253 253 253
42745 -253 253 253 253 253 253 253 253 253 253 253 253
42746 -253 253 253 253 253 253 253 253 253 253 253 253
42747 -242 242 242 82 82 82 18 14 6 163 110 8
42748 -216 158 10 236 178 12 242 186 14 246 190 14
42749 -246 190 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 246 190 14 242 186 14 163 133 67
42753 - 46 46 46 18 18 18 6 6 6 0 0 0
42754 - 0 0 0 0 0 0 0 0 0 0 0 0
42755 - 0 0 0 0 0 0 0 0 0 0 0 0
42756 - 0 0 0 0 0 0 0 0 0 10 10 10
42757 - 30 30 30 78 78 78 163 133 67 210 150 10
42758 -236 178 12 246 186 14 246 190 14 246 190 14
42759 -246 190 14 246 190 14 246 190 14 246 190 14
42760 -246 190 14 246 190 14 246 190 14 246 190 14
42761 -246 190 14 246 190 14 246 190 14 246 190 14
42762 -241 196 14 215 174 15 190 178 144 253 253 253
42763 -253 253 253 253 253 253 253 253 253 253 253 253
42764 -253 253 253 253 253 253 253 253 253 253 253 253
42765 -253 253 253 253 253 253 253 253 253 253 253 253
42766 -253 253 253 253 253 253 253 253 253 218 218 218
42767 - 58 58 58 2 2 6 22 18 6 167 114 7
42768 -216 158 10 236 178 12 246 186 14 246 190 14
42769 -246 190 14 246 190 14 246 190 14 246 190 14
42770 -246 190 14 246 190 14 246 190 14 246 190 14
42771 -246 190 14 246 190 14 246 190 14 246 190 14
42772 -246 190 14 246 186 14 242 186 14 190 150 46
42773 - 54 54 54 22 22 22 6 6 6 0 0 0
42774 - 0 0 0 0 0 0 0 0 0 0 0 0
42775 - 0 0 0 0 0 0 0 0 0 0 0 0
42776 - 0 0 0 0 0 0 0 0 0 14 14 14
42777 - 38 38 38 86 86 86 180 133 36 213 154 11
42778 -236 178 12 246 186 14 246 190 14 246 190 14
42779 -246 190 14 246 190 14 246 190 14 246 190 14
42780 -246 190 14 246 190 14 246 190 14 246 190 14
42781 -246 190 14 246 190 14 246 190 14 246 190 14
42782 -246 190 14 232 195 16 190 146 13 214 214 214
42783 -253 253 253 253 253 253 253 253 253 253 253 253
42784 -253 253 253 253 253 253 253 253 253 253 253 253
42785 -253 253 253 253 253 253 253 253 253 253 253 253
42786 -253 253 253 250 250 250 170 170 170 26 26 26
42787 - 2 2 6 2 2 6 37 26 9 163 110 8
42788 -219 162 10 239 182 13 246 186 14 246 190 14
42789 -246 190 14 246 190 14 246 190 14 246 190 14
42790 -246 190 14 246 190 14 246 190 14 246 190 14
42791 -246 190 14 246 190 14 246 190 14 246 190 14
42792 -246 186 14 236 178 12 224 166 10 142 122 72
42793 - 46 46 46 18 18 18 6 6 6 0 0 0
42794 - 0 0 0 0 0 0 0 0 0 0 0 0
42795 - 0 0 0 0 0 0 0 0 0 0 0 0
42796 - 0 0 0 0 0 0 6 6 6 18 18 18
42797 - 50 50 50 109 106 95 192 133 9 224 166 10
42798 -242 186 14 246 190 14 246 190 14 246 190 14
42799 -246 190 14 246 190 14 246 190 14 246 190 14
42800 -246 190 14 246 190 14 246 190 14 246 190 14
42801 -246 190 14 246 190 14 246 190 14 246 190 14
42802 -242 186 14 226 184 13 210 162 10 142 110 46
42803 -226 226 226 253 253 253 253 253 253 253 253 253
42804 -253 253 253 253 253 253 253 253 253 253 253 253
42805 -253 253 253 253 253 253 253 253 253 253 253 253
42806 -198 198 198 66 66 66 2 2 6 2 2 6
42807 - 2 2 6 2 2 6 50 34 6 156 107 11
42808 -219 162 10 239 182 13 246 186 14 246 190 14
42809 -246 190 14 246 190 14 246 190 14 246 190 14
42810 -246 190 14 246 190 14 246 190 14 246 190 14
42811 -246 190 14 246 190 14 246 190 14 242 186 14
42812 -234 174 13 213 154 11 154 122 46 66 66 66
42813 - 30 30 30 10 10 10 0 0 0 0 0 0
42814 - 0 0 0 0 0 0 0 0 0 0 0 0
42815 - 0 0 0 0 0 0 0 0 0 0 0 0
42816 - 0 0 0 0 0 0 6 6 6 22 22 22
42817 - 58 58 58 154 121 60 206 145 10 234 174 13
42818 -242 186 14 246 186 14 246 190 14 246 190 14
42819 -246 190 14 246 190 14 246 190 14 246 190 14
42820 -246 190 14 246 190 14 246 190 14 246 190 14
42821 -246 190 14 246 190 14 246 190 14 246 190 14
42822 -246 186 14 236 178 12 210 162 10 163 110 8
42823 - 61 42 6 138 138 138 218 218 218 250 250 250
42824 -253 253 253 253 253 253 253 253 253 250 250 250
42825 -242 242 242 210 210 210 144 144 144 66 66 66
42826 - 6 6 6 2 2 6 2 2 6 2 2 6
42827 - 2 2 6 2 2 6 61 42 6 163 110 8
42828 -216 158 10 236 178 12 246 190 14 246 190 14
42829 -246 190 14 246 190 14 246 190 14 246 190 14
42830 -246 190 14 246 190 14 246 190 14 246 190 14
42831 -246 190 14 239 182 13 230 174 11 216 158 10
42832 -190 142 34 124 112 88 70 70 70 38 38 38
42833 - 18 18 18 6 6 6 0 0 0 0 0 0
42834 - 0 0 0 0 0 0 0 0 0 0 0 0
42835 - 0 0 0 0 0 0 0 0 0 0 0 0
42836 - 0 0 0 0 0 0 6 6 6 22 22 22
42837 - 62 62 62 168 124 44 206 145 10 224 166 10
42838 -236 178 12 239 182 13 242 186 14 242 186 14
42839 -246 186 14 246 190 14 246 190 14 246 190 14
42840 -246 190 14 246 190 14 246 190 14 246 190 14
42841 -246 190 14 246 190 14 246 190 14 246 190 14
42842 -246 190 14 236 178 12 216 158 10 175 118 6
42843 - 80 54 7 2 2 6 6 6 6 30 30 30
42844 - 54 54 54 62 62 62 50 50 50 38 38 38
42845 - 14 14 14 2 2 6 2 2 6 2 2 6
42846 - 2 2 6 2 2 6 2 2 6 2 2 6
42847 - 2 2 6 6 6 6 80 54 7 167 114 7
42848 -213 154 11 236 178 12 246 190 14 246 190 14
42849 -246 190 14 246 190 14 246 190 14 246 190 14
42850 -246 190 14 242 186 14 239 182 13 239 182 13
42851 -230 174 11 210 150 10 174 135 50 124 112 88
42852 - 82 82 82 54 54 54 34 34 34 18 18 18
42853 - 6 6 6 0 0 0 0 0 0 0 0 0
42854 - 0 0 0 0 0 0 0 0 0 0 0 0
42855 - 0 0 0 0 0 0 0 0 0 0 0 0
42856 - 0 0 0 0 0 0 6 6 6 18 18 18
42857 - 50 50 50 158 118 36 192 133 9 200 144 11
42858 -216 158 10 219 162 10 224 166 10 226 170 11
42859 -230 174 11 236 178 12 239 182 13 239 182 13
42860 -242 186 14 246 186 14 246 190 14 246 190 14
42861 -246 190 14 246 190 14 246 190 14 246 190 14
42862 -246 186 14 230 174 11 210 150 10 163 110 8
42863 -104 69 6 10 10 10 2 2 6 2 2 6
42864 - 2 2 6 2 2 6 2 2 6 2 2 6
42865 - 2 2 6 2 2 6 2 2 6 2 2 6
42866 - 2 2 6 2 2 6 2 2 6 2 2 6
42867 - 2 2 6 6 6 6 91 60 6 167 114 7
42868 -206 145 10 230 174 11 242 186 14 246 190 14
42869 -246 190 14 246 190 14 246 186 14 242 186 14
42870 -239 182 13 230 174 11 224 166 10 213 154 11
42871 -180 133 36 124 112 88 86 86 86 58 58 58
42872 - 38 38 38 22 22 22 10 10 10 6 6 6
42873 - 0 0 0 0 0 0 0 0 0 0 0 0
42874 - 0 0 0 0 0 0 0 0 0 0 0 0
42875 - 0 0 0 0 0 0 0 0 0 0 0 0
42876 - 0 0 0 0 0 0 0 0 0 14 14 14
42877 - 34 34 34 70 70 70 138 110 50 158 118 36
42878 -167 114 7 180 123 7 192 133 9 197 138 11
42879 -200 144 11 206 145 10 213 154 11 219 162 10
42880 -224 166 10 230 174 11 239 182 13 242 186 14
42881 -246 186 14 246 186 14 246 186 14 246 186 14
42882 -239 182 13 216 158 10 185 133 11 152 99 6
42883 -104 69 6 18 14 6 2 2 6 2 2 6
42884 - 2 2 6 2 2 6 2 2 6 2 2 6
42885 - 2 2 6 2 2 6 2 2 6 2 2 6
42886 - 2 2 6 2 2 6 2 2 6 2 2 6
42887 - 2 2 6 6 6 6 80 54 7 152 99 6
42888 -192 133 9 219 162 10 236 178 12 239 182 13
42889 -246 186 14 242 186 14 239 182 13 236 178 12
42890 -224 166 10 206 145 10 192 133 9 154 121 60
42891 - 94 94 94 62 62 62 42 42 42 22 22 22
42892 - 14 14 14 6 6 6 0 0 0 0 0 0
42893 - 0 0 0 0 0 0 0 0 0 0 0 0
42894 - 0 0 0 0 0 0 0 0 0 0 0 0
42895 - 0 0 0 0 0 0 0 0 0 0 0 0
42896 - 0 0 0 0 0 0 0 0 0 6 6 6
42897 - 18 18 18 34 34 34 58 58 58 78 78 78
42898 -101 98 89 124 112 88 142 110 46 156 107 11
42899 -163 110 8 167 114 7 175 118 6 180 123 7
42900 -185 133 11 197 138 11 210 150 10 219 162 10
42901 -226 170 11 236 178 12 236 178 12 234 174 13
42902 -219 162 10 197 138 11 163 110 8 130 83 6
42903 - 91 60 6 10 10 10 2 2 6 2 2 6
42904 - 18 18 18 38 38 38 38 38 38 38 38 38
42905 - 38 38 38 38 38 38 38 38 38 38 38 38
42906 - 38 38 38 38 38 38 26 26 26 2 2 6
42907 - 2 2 6 6 6 6 70 47 6 137 92 6
42908 -175 118 6 200 144 11 219 162 10 230 174 11
42909 -234 174 13 230 174 11 219 162 10 210 150 10
42910 -192 133 9 163 110 8 124 112 88 82 82 82
42911 - 50 50 50 30 30 30 14 14 14 6 6 6
42912 - 0 0 0 0 0 0 0 0 0 0 0 0
42913 - 0 0 0 0 0 0 0 0 0 0 0 0
42914 - 0 0 0 0 0 0 0 0 0 0 0 0
42915 - 0 0 0 0 0 0 0 0 0 0 0 0
42916 - 0 0 0 0 0 0 0 0 0 0 0 0
42917 - 6 6 6 14 14 14 22 22 22 34 34 34
42918 - 42 42 42 58 58 58 74 74 74 86 86 86
42919 -101 98 89 122 102 70 130 98 46 121 87 25
42920 -137 92 6 152 99 6 163 110 8 180 123 7
42921 -185 133 11 197 138 11 206 145 10 200 144 11
42922 -180 123 7 156 107 11 130 83 6 104 69 6
42923 - 50 34 6 54 54 54 110 110 110 101 98 89
42924 - 86 86 86 82 82 82 78 78 78 78 78 78
42925 - 78 78 78 78 78 78 78 78 78 78 78 78
42926 - 78 78 78 82 82 82 86 86 86 94 94 94
42927 -106 106 106 101 101 101 86 66 34 124 80 6
42928 -156 107 11 180 123 7 192 133 9 200 144 11
42929 -206 145 10 200 144 11 192 133 9 175 118 6
42930 -139 102 15 109 106 95 70 70 70 42 42 42
42931 - 22 22 22 10 10 10 0 0 0 0 0 0
42932 - 0 0 0 0 0 0 0 0 0 0 0 0
42933 - 0 0 0 0 0 0 0 0 0 0 0 0
42934 - 0 0 0 0 0 0 0 0 0 0 0 0
42935 - 0 0 0 0 0 0 0 0 0 0 0 0
42936 - 0 0 0 0 0 0 0 0 0 0 0 0
42937 - 0 0 0 0 0 0 6 6 6 10 10 10
42938 - 14 14 14 22 22 22 30 30 30 38 38 38
42939 - 50 50 50 62 62 62 74 74 74 90 90 90
42940 -101 98 89 112 100 78 121 87 25 124 80 6
42941 -137 92 6 152 99 6 152 99 6 152 99 6
42942 -138 86 6 124 80 6 98 70 6 86 66 30
42943 -101 98 89 82 82 82 58 58 58 46 46 46
42944 - 38 38 38 34 34 34 34 34 34 34 34 34
42945 - 34 34 34 34 34 34 34 34 34 34 34 34
42946 - 34 34 34 34 34 34 38 38 38 42 42 42
42947 - 54 54 54 82 82 82 94 86 76 91 60 6
42948 -134 86 6 156 107 11 167 114 7 175 118 6
42949 -175 118 6 167 114 7 152 99 6 121 87 25
42950 -101 98 89 62 62 62 34 34 34 18 18 18
42951 - 6 6 6 0 0 0 0 0 0 0 0 0
42952 - 0 0 0 0 0 0 0 0 0 0 0 0
42953 - 0 0 0 0 0 0 0 0 0 0 0 0
42954 - 0 0 0 0 0 0 0 0 0 0 0 0
42955 - 0 0 0 0 0 0 0 0 0 0 0 0
42956 - 0 0 0 0 0 0 0 0 0 0 0 0
42957 - 0 0 0 0 0 0 0 0 0 0 0 0
42958 - 0 0 0 6 6 6 6 6 6 10 10 10
42959 - 18 18 18 22 22 22 30 30 30 42 42 42
42960 - 50 50 50 66 66 66 86 86 86 101 98 89
42961 -106 86 58 98 70 6 104 69 6 104 69 6
42962 -104 69 6 91 60 6 82 62 34 90 90 90
42963 - 62 62 62 38 38 38 22 22 22 14 14 14
42964 - 10 10 10 10 10 10 10 10 10 10 10 10
42965 - 10 10 10 10 10 10 6 6 6 10 10 10
42966 - 10 10 10 10 10 10 10 10 10 14 14 14
42967 - 22 22 22 42 42 42 70 70 70 89 81 66
42968 - 80 54 7 104 69 6 124 80 6 137 92 6
42969 -134 86 6 116 81 8 100 82 52 86 86 86
42970 - 58 58 58 30 30 30 14 14 14 6 6 6
42971 - 0 0 0 0 0 0 0 0 0 0 0 0
42972 - 0 0 0 0 0 0 0 0 0 0 0 0
42973 - 0 0 0 0 0 0 0 0 0 0 0 0
42974 - 0 0 0 0 0 0 0 0 0 0 0 0
42975 - 0 0 0 0 0 0 0 0 0 0 0 0
42976 - 0 0 0 0 0 0 0 0 0 0 0 0
42977 - 0 0 0 0 0 0 0 0 0 0 0 0
42978 - 0 0 0 0 0 0 0 0 0 0 0 0
42979 - 0 0 0 6 6 6 10 10 10 14 14 14
42980 - 18 18 18 26 26 26 38 38 38 54 54 54
42981 - 70 70 70 86 86 86 94 86 76 89 81 66
42982 - 89 81 66 86 86 86 74 74 74 50 50 50
42983 - 30 30 30 14 14 14 6 6 6 0 0 0
42984 - 0 0 0 0 0 0 0 0 0 0 0 0
42985 - 0 0 0 0 0 0 0 0 0 0 0 0
42986 - 0 0 0 0 0 0 0 0 0 0 0 0
42987 - 6 6 6 18 18 18 34 34 34 58 58 58
42988 - 82 82 82 89 81 66 89 81 66 89 81 66
42989 - 94 86 66 94 86 76 74 74 74 50 50 50
42990 - 26 26 26 14 14 14 6 6 6 0 0 0
42991 - 0 0 0 0 0 0 0 0 0 0 0 0
42992 - 0 0 0 0 0 0 0 0 0 0 0 0
42993 - 0 0 0 0 0 0 0 0 0 0 0 0
42994 - 0 0 0 0 0 0 0 0 0 0 0 0
42995 - 0 0 0 0 0 0 0 0 0 0 0 0
42996 - 0 0 0 0 0 0 0 0 0 0 0 0
42997 - 0 0 0 0 0 0 0 0 0 0 0 0
42998 - 0 0 0 0 0 0 0 0 0 0 0 0
42999 - 0 0 0 0 0 0 0 0 0 0 0 0
43000 - 6 6 6 6 6 6 14 14 14 18 18 18
43001 - 30 30 30 38 38 38 46 46 46 54 54 54
43002 - 50 50 50 42 42 42 30 30 30 18 18 18
43003 - 10 10 10 0 0 0 0 0 0 0 0 0
43004 - 0 0 0 0 0 0 0 0 0 0 0 0
43005 - 0 0 0 0 0 0 0 0 0 0 0 0
43006 - 0 0 0 0 0 0 0 0 0 0 0 0
43007 - 0 0 0 6 6 6 14 14 14 26 26 26
43008 - 38 38 38 50 50 50 58 58 58 58 58 58
43009 - 54 54 54 42 42 42 30 30 30 18 18 18
43010 - 10 10 10 0 0 0 0 0 0 0 0 0
43011 - 0 0 0 0 0 0 0 0 0 0 0 0
43012 - 0 0 0 0 0 0 0 0 0 0 0 0
43013 - 0 0 0 0 0 0 0 0 0 0 0 0
43014 - 0 0 0 0 0 0 0 0 0 0 0 0
43015 - 0 0 0 0 0 0 0 0 0 0 0 0
43016 - 0 0 0 0 0 0 0 0 0 0 0 0
43017 - 0 0 0 0 0 0 0 0 0 0 0 0
43018 - 0 0 0 0 0 0 0 0 0 0 0 0
43019 - 0 0 0 0 0 0 0 0 0 0 0 0
43020 - 0 0 0 0 0 0 0 0 0 6 6 6
43021 - 6 6 6 10 10 10 14 14 14 18 18 18
43022 - 18 18 18 14 14 14 10 10 10 6 6 6
43023 - 0 0 0 0 0 0 0 0 0 0 0 0
43024 - 0 0 0 0 0 0 0 0 0 0 0 0
43025 - 0 0 0 0 0 0 0 0 0 0 0 0
43026 - 0 0 0 0 0 0 0 0 0 0 0 0
43027 - 0 0 0 0 0 0 0 0 0 6 6 6
43028 - 14 14 14 18 18 18 22 22 22 22 22 22
43029 - 18 18 18 14 14 14 10 10 10 6 6 6
43030 - 0 0 0 0 0 0 0 0 0 0 0 0
43031 - 0 0 0 0 0 0 0 0 0 0 0 0
43032 - 0 0 0 0 0 0 0 0 0 0 0 0
43033 - 0 0 0 0 0 0 0 0 0 0 0 0
43034 - 0 0 0 0 0 0 0 0 0 0 0 0
43035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43041 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43043 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43048 +4 4 4 4 4 4
43049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43055 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43056 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43057 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43058 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43062 +4 4 4 4 4 4
43063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43076 +4 4 4 4 4 4
43077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43085 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43090 +4 4 4 4 4 4
43091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43099 +4 4 4 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 4 4 4
43102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43104 +4 4 4 4 4 4
43105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
43116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43118 +4 4 4 4 4 4
43119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43123 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
43124 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
43125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43128 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
43129 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43130 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
43131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43132 +4 4 4 4 4 4
43133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43137 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
43138 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
43139 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43142 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
43143 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
43144 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
43145 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43146 +4 4 4 4 4 4
43147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43151 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
43152 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
43153 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43156 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
43157 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
43158 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
43159 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
43160 +4 4 4 4 4 4
43161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43164 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
43165 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
43166 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
43167 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
43168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43169 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43170 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
43171 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
43172 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
43173 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
43174 +4 4 4 4 4 4
43175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43178 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
43179 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
43180 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
43181 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
43182 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43183 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
43184 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
43185 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
43186 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
43187 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
43188 +4 4 4 4 4 4
43189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43192 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
43193 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
43194 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
43195 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
43196 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
43197 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
43198 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
43199 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
43200 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
43201 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
43202 +4 4 4 4 4 4
43203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43205 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
43206 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
43207 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
43208 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
43209 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
43210 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
43211 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
43212 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
43213 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
43214 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
43215 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
43216 +4 4 4 4 4 4
43217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43219 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
43220 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
43221 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
43222 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
43223 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
43224 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
43225 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
43226 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
43227 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
43228 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
43229 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
43230 +4 4 4 4 4 4
43231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43233 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
43234 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
43235 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
43236 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
43237 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
43238 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
43239 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
43240 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
43241 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
43242 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
43243 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43244 +4 4 4 4 4 4
43245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43247 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
43248 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
43249 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
43250 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
43251 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
43252 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
43253 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
43254 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
43255 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
43256 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
43257 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
43258 +4 4 4 4 4 4
43259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43260 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
43261 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
43262 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
43263 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
43264 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
43265 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
43266 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
43267 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
43268 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
43269 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
43270 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
43271 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
43272 +4 4 4 4 4 4
43273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43274 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
43275 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
43276 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
43277 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43278 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
43279 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
43280 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
43281 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
43282 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
43283 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
43284 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
43285 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
43286 +0 0 0 4 4 4
43287 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43288 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
43289 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
43290 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
43291 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
43292 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
43293 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
43294 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
43295 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
43296 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
43297 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
43298 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
43299 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
43300 +2 0 0 0 0 0
43301 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
43302 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
43303 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
43304 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
43305 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
43306 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
43307 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
43308 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
43309 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
43310 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
43311 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
43312 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
43313 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
43314 +37 38 37 0 0 0
43315 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43316 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
43317 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
43318 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
43319 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
43320 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
43321 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
43322 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
43323 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
43324 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
43325 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
43326 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
43327 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
43328 +85 115 134 4 0 0
43329 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
43330 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
43331 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
43332 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
43333 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
43334 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
43335 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
43336 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
43337 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
43338 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
43339 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
43340 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
43341 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
43342 +60 73 81 4 0 0
43343 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
43344 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
43345 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
43346 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
43347 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
43348 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
43349 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
43350 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
43351 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
43352 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
43353 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
43354 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
43355 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
43356 +16 19 21 4 0 0
43357 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
43358 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
43359 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
43360 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
43361 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
43362 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
43363 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
43364 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
43365 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
43366 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
43367 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
43368 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
43369 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
43370 +4 0 0 4 3 3
43371 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
43372 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
43373 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
43374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
43375 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
43376 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
43377 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
43378 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
43379 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
43380 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
43381 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
43382 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
43383 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
43384 +3 2 2 4 4 4
43385 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
43386 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
43387 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
43388 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43389 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
43390 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
43391 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
43392 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
43393 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
43394 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
43395 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
43396 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
43397 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
43398 +4 4 4 4 4 4
43399 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
43400 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
43401 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
43402 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
43403 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
43404 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
43405 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
43406 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
43407 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
43408 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
43409 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
43410 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
43411 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
43412 +4 4 4 4 4 4
43413 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
43414 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
43415 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
43416 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
43417 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
43418 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
43419 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
43420 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
43421 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
43422 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
43423 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
43424 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
43425 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
43426 +5 5 5 5 5 5
43427 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
43428 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
43429 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
43430 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
43431 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
43432 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43433 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
43434 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
43435 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
43436 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
43437 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
43438 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
43439 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
43440 +5 5 5 4 4 4
43441 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
43442 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
43443 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
43444 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
43445 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43446 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
43447 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
43448 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
43449 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
43450 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
43451 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
43452 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
43453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43454 +4 4 4 4 4 4
43455 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
43456 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
43457 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
43458 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
43459 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
43460 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43461 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43462 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
43463 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
43464 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
43465 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
43466 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
43467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43468 +4 4 4 4 4 4
43469 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
43470 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
43471 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
43472 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
43473 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43474 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
43475 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
43476 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
43477 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
43478 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
43479 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
43480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43482 +4 4 4 4 4 4
43483 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
43484 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
43485 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
43486 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
43487 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43488 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43489 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43490 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
43491 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
43492 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
43493 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
43494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43496 +4 4 4 4 4 4
43497 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
43498 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
43499 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
43500 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
43501 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43502 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
43503 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
43504 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
43505 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
43506 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
43507 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43510 +4 4 4 4 4 4
43511 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
43512 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
43513 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
43514 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
43515 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43516 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
43517 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
43518 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
43519 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
43520 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
43521 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
43522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43523 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43524 +4 4 4 4 4 4
43525 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
43526 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
43527 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
43528 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
43529 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43530 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
43531 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
43532 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
43533 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
43534 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
43535 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
43536 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43537 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43538 +4 4 4 4 4 4
43539 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
43540 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
43541 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
43542 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43543 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
43544 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
43545 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
43546 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
43547 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
43548 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
43549 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43551 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43552 +4 4 4 4 4 4
43553 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
43554 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
43555 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
43556 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43557 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43558 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
43559 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
43560 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
43561 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
43562 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
43563 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43564 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43565 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43566 +4 4 4 4 4 4
43567 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
43568 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
43569 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43570 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43571 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43572 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
43573 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
43574 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
43575 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
43576 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
43577 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43578 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43579 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43580 +4 4 4 4 4 4
43581 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
43582 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
43583 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43584 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43585 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43586 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
43587 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
43588 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
43589 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43590 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43591 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43592 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43593 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43594 +4 4 4 4 4 4
43595 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43596 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
43597 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43598 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
43599 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
43600 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
43601 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
43602 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
43603 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43604 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43605 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43606 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43607 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43608 +4 4 4 4 4 4
43609 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43610 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
43611 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43612 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
43613 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43614 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
43615 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
43616 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
43617 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43618 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43619 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43620 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43621 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43622 +4 4 4 4 4 4
43623 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
43624 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
43625 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43626 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
43627 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
43628 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
43629 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
43630 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
43631 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43632 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43633 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43634 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43635 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43636 +4 4 4 4 4 4
43637 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
43638 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
43639 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43640 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
43641 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
43642 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
43643 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
43644 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
43645 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43646 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43647 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43648 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43649 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43650 +4 4 4 4 4 4
43651 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43652 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
43653 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43654 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
43655 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
43656 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
43657 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
43658 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
43659 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43660 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43661 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43662 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43663 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43664 +4 4 4 4 4 4
43665 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
43666 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
43667 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43668 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
43669 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
43670 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
43671 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
43672 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
43673 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
43674 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43675 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43677 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43678 +4 4 4 4 4 4
43679 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43680 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
43681 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
43682 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
43683 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
43684 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
43685 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
43686 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
43687 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43688 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43689 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43691 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43692 +4 4 4 4 4 4
43693 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43694 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
43695 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43696 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
43697 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
43698 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
43699 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
43700 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
43701 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43702 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43703 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43705 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43706 +4 4 4 4 4 4
43707 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43708 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
43709 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
43710 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
43711 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
43712 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
43713 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43714 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
43715 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43716 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43717 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43719 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43720 +4 4 4 4 4 4
43721 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43722 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
43723 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
43724 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43725 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
43726 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
43727 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43728 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
43729 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43730 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43731 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43733 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43734 +4 4 4 4 4 4
43735 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43736 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
43737 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
43738 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
43739 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
43740 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
43741 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
43742 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
43743 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
43744 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43745 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43747 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43748 +4 4 4 4 4 4
43749 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43750 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
43751 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
43752 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
43753 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
43754 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
43755 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
43756 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
43757 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
43758 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43759 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43761 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43762 +4 4 4 4 4 4
43763 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
43764 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
43765 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
43766 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
43767 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43768 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
43769 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
43770 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
43771 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
43772 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43773 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43775 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43776 +4 4 4 4 4 4
43777 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43778 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
43779 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
43780 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
43781 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
43782 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
43783 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
43784 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
43785 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
43786 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43787 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43789 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43790 +4 4 4 4 4 4
43791 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
43792 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
43793 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
43794 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
43795 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
43796 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
43797 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
43798 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
43799 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
43800 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
43801 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43803 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43804 +4 4 4 4 4 4
43805 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
43806 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43807 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
43808 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
43809 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
43810 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
43811 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
43812 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
43813 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
43814 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
43815 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43816 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43817 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43818 +4 4 4 4 4 4
43819 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
43820 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43821 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
43822 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
43823 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
43824 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
43825 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43826 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
43827 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
43828 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
43829 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43830 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43831 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43832 +4 4 4 4 4 4
43833 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
43834 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
43835 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
43836 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
43837 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
43838 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
43839 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
43840 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
43841 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
43842 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
43843 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43844 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43845 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43846 +4 4 4 4 4 4
43847 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
43848 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
43849 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43850 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
43851 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
43852 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
43853 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
43854 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
43855 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
43856 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
43857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43858 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43859 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43860 +4 4 4 4 4 4
43861 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43862 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
43863 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
43864 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
43865 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
43866 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
43867 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
43868 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
43869 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
43870 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
43871 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43872 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43873 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43874 +4 4 4 4 4 4
43875 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
43876 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
43877 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
43878 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
43879 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
43880 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
43881 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
43882 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
43883 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
43884 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
43885 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43886 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43887 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43888 +4 4 4 4 4 4
43889 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
43890 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
43891 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
43892 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
43893 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
43894 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
43895 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
43896 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
43897 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43898 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43899 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43900 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43901 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43902 +4 4 4 4 4 4
43903 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
43904 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43905 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
43906 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43907 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
43908 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
43909 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
43910 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
43911 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
43912 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43913 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43914 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43915 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43916 +4 4 4 4 4 4
43917 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
43918 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
43919 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
43920 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
43921 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
43922 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
43923 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
43924 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
43925 +4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43928 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43929 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43930 +4 4 4 4 4 4
43931 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43932 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
43933 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
43934 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
43935 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
43936 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
43937 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
43938 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
43939 +4 0 0 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 4 4 4
43942 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43943 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43944 +4 4 4 4 4 4
43945 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
43946 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
43947 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43948 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
43949 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
43950 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
43951 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
43952 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43958 +4 4 4 4 4 4
43959 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
43960 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
43961 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
43962 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
43963 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
43964 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
43965 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
43966 +6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
43971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43972 +4 4 4 4 4 4
43973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43974 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
43975 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43976 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
43977 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
43978 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
43979 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
43980 +4 0 0 4 3 3 6 6 6 4 4 4 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 4 4 4 4 4 4 4 4 4
43985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43986 +4 4 4 4 4 4
43987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43988 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
43989 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
43990 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
43991 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
43992 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
43993 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
43994 +6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4
43999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44000 +4 4 4 4 4 4
44001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44002 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
44003 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
44004 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
44005 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
44006 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
44007 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
44008 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44014 +4 4 4 4 4 4
44015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44017 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
44018 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
44019 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
44020 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
44021 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
44022 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44024 +4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44028 +4 4 4 4 4 4
44029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44032 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44033 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
44034 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
44035 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
44036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44038 +4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
44042 +4 4 4 4 4 4
44043 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44046 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
44047 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
44048 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
44049 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
44050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44052 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
44056 +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 5 5 5 4 3 3 5 5 5 6 6 6
44061 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44062 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
44063 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
44064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44069 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44070 +4 4 4 4 4 4
44071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44074 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
44075 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
44076 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
44077 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
44078 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44083 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44084 +4 4 4 4 4 4
44085 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44089 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
44090 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44091 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44092 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44098 +4 4 4 4 4 4
44099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44100 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44103 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
44104 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
44105 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
44106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44112 +4 4 4 4 4 4
44113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44117 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
44118 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
44119 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44126 +4 4 4 4 4 4
44127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44131 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
44132 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
44133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44140 +4 4 4 4 4 4
44141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44145 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
44146 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
44147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44154 +4 4 4 4 4 4
44155 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
44156 index 86d449e..af6a7f7 100644
44157 --- a/drivers/video/udlfb.c
44158 +++ b/drivers/video/udlfb.c
44159 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
44160 dlfb_urb_completion(urb);
44161
44162 error:
44163 - atomic_add(bytes_sent, &dev->bytes_sent);
44164 - atomic_add(bytes_identical, &dev->bytes_identical);
44165 - atomic_add(width*height*2, &dev->bytes_rendered);
44166 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44167 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44168 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
44169 end_cycles = get_cycles();
44170 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
44171 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44172 >> 10)), /* Kcycles */
44173 &dev->cpu_kcycles_used);
44174
44175 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
44176 dlfb_urb_completion(urb);
44177
44178 error:
44179 - atomic_add(bytes_sent, &dev->bytes_sent);
44180 - atomic_add(bytes_identical, &dev->bytes_identical);
44181 - atomic_add(bytes_rendered, &dev->bytes_rendered);
44182 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44183 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44184 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
44185 end_cycles = get_cycles();
44186 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
44187 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44188 >> 10)), /* Kcycles */
44189 &dev->cpu_kcycles_used);
44190 }
44191 @@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
44192 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44193 struct dlfb_data *dev = fb_info->par;
44194 return snprintf(buf, PAGE_SIZE, "%u\n",
44195 - atomic_read(&dev->bytes_rendered));
44196 + atomic_read_unchecked(&dev->bytes_rendered));
44197 }
44198
44199 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44200 @@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44201 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44202 struct dlfb_data *dev = fb_info->par;
44203 return snprintf(buf, PAGE_SIZE, "%u\n",
44204 - atomic_read(&dev->bytes_identical));
44205 + atomic_read_unchecked(&dev->bytes_identical));
44206 }
44207
44208 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44209 @@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44210 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44211 struct dlfb_data *dev = fb_info->par;
44212 return snprintf(buf, PAGE_SIZE, "%u\n",
44213 - atomic_read(&dev->bytes_sent));
44214 + atomic_read_unchecked(&dev->bytes_sent));
44215 }
44216
44217 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44218 @@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44219 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44220 struct dlfb_data *dev = fb_info->par;
44221 return snprintf(buf, PAGE_SIZE, "%u\n",
44222 - atomic_read(&dev->cpu_kcycles_used));
44223 + atomic_read_unchecked(&dev->cpu_kcycles_used));
44224 }
44225
44226 static ssize_t edid_show(
44227 @@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
44228 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44229 struct dlfb_data *dev = fb_info->par;
44230
44231 - atomic_set(&dev->bytes_rendered, 0);
44232 - atomic_set(&dev->bytes_identical, 0);
44233 - atomic_set(&dev->bytes_sent, 0);
44234 - atomic_set(&dev->cpu_kcycles_used, 0);
44235 + atomic_set_unchecked(&dev->bytes_rendered, 0);
44236 + atomic_set_unchecked(&dev->bytes_identical, 0);
44237 + atomic_set_unchecked(&dev->bytes_sent, 0);
44238 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
44239
44240 return count;
44241 }
44242 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
44243 index 2f8f82d..191de37 100644
44244 --- a/drivers/video/uvesafb.c
44245 +++ b/drivers/video/uvesafb.c
44246 @@ -19,6 +19,7 @@
44247 #include <linux/io.h>
44248 #include <linux/mutex.h>
44249 #include <linux/slab.h>
44250 +#include <linux/moduleloader.h>
44251 #include <video/edid.h>
44252 #include <video/uvesafb.h>
44253 #ifdef CONFIG_X86
44254 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
44255 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
44256 par->pmi_setpal = par->ypan = 0;
44257 } else {
44258 +
44259 +#ifdef CONFIG_PAX_KERNEXEC
44260 +#ifdef CONFIG_MODULES
44261 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
44262 +#endif
44263 + if (!par->pmi_code) {
44264 + par->pmi_setpal = par->ypan = 0;
44265 + return 0;
44266 + }
44267 +#endif
44268 +
44269 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
44270 + task->t.regs.edi);
44271 +
44272 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44273 + pax_open_kernel();
44274 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
44275 + pax_close_kernel();
44276 +
44277 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
44278 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
44279 +#else
44280 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
44281 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
44282 +#endif
44283 +
44284 printk(KERN_INFO "uvesafb: protected mode interface info at "
44285 "%04x:%04x\n",
44286 (u16)task->t.regs.es, (u16)task->t.regs.edi);
44287 @@ -818,13 +841,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
44288 par->ypan = ypan;
44289
44290 if (par->pmi_setpal || par->ypan) {
44291 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
44292 if (__supported_pte_mask & _PAGE_NX) {
44293 par->pmi_setpal = par->ypan = 0;
44294 printk(KERN_WARNING "uvesafb: NX protection is actively."
44295 "We have better not to use the PMI.\n");
44296 - } else {
44297 + } else
44298 +#endif
44299 uvesafb_vbe_getpmi(task, par);
44300 - }
44301 }
44302 #else
44303 /* The protected mode interface is not available on non-x86. */
44304 @@ -1838,6 +1862,11 @@ out:
44305 if (par->vbe_modes)
44306 kfree(par->vbe_modes);
44307
44308 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44309 + if (par->pmi_code)
44310 + module_free_exec(NULL, par->pmi_code);
44311 +#endif
44312 +
44313 framebuffer_release(info);
44314 return err;
44315 }
44316 @@ -1864,6 +1893,12 @@ static int uvesafb_remove(struct platform_device *dev)
44317 kfree(par->vbe_state_orig);
44318 if (par->vbe_state_saved)
44319 kfree(par->vbe_state_saved);
44320 +
44321 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44322 + if (par->pmi_code)
44323 + module_free_exec(NULL, par->pmi_code);
44324 +#endif
44325 +
44326 }
44327
44328 framebuffer_release(info);
44329 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
44330 index 501b340..86bd4cf 100644
44331 --- a/drivers/video/vesafb.c
44332 +++ b/drivers/video/vesafb.c
44333 @@ -9,6 +9,7 @@
44334 */
44335
44336 #include <linux/module.h>
44337 +#include <linux/moduleloader.h>
44338 #include <linux/kernel.h>
44339 #include <linux/errno.h>
44340 #include <linux/string.h>
44341 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
44342 static int vram_total __initdata; /* Set total amount of memory */
44343 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
44344 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
44345 -static void (*pmi_start)(void) __read_mostly;
44346 -static void (*pmi_pal) (void) __read_mostly;
44347 +static void (*pmi_start)(void) __read_only;
44348 +static void (*pmi_pal) (void) __read_only;
44349 static int depth __read_mostly;
44350 static int vga_compat __read_mostly;
44351 /* --------------------------------------------------------------------- */
44352 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
44353 unsigned int size_vmode;
44354 unsigned int size_remap;
44355 unsigned int size_total;
44356 + void *pmi_code = NULL;
44357
44358 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
44359 return -ENODEV;
44360 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
44361 size_remap = size_total;
44362 vesafb_fix.smem_len = size_remap;
44363
44364 -#ifndef __i386__
44365 - screen_info.vesapm_seg = 0;
44366 -#endif
44367 -
44368 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
44369 printk(KERN_WARNING
44370 "vesafb: cannot reserve video memory at 0x%lx\n",
44371 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
44372 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
44373 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
44374
44375 +#ifdef __i386__
44376 +
44377 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44378 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
44379 + if (!pmi_code)
44380 +#elif !defined(CONFIG_PAX_KERNEXEC)
44381 + if (0)
44382 +#endif
44383 +
44384 +#endif
44385 + screen_info.vesapm_seg = 0;
44386 +
44387 if (screen_info.vesapm_seg) {
44388 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
44389 - screen_info.vesapm_seg,screen_info.vesapm_off);
44390 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
44391 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
44392 }
44393
44394 if (screen_info.vesapm_seg < 0xc000)
44395 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
44396
44397 if (ypan || pmi_setpal) {
44398 unsigned short *pmi_base;
44399 +
44400 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
44401 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
44402 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
44403 +
44404 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44405 + pax_open_kernel();
44406 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
44407 +#else
44408 + pmi_code = pmi_base;
44409 +#endif
44410 +
44411 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
44412 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
44413 +
44414 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44415 + pmi_start = ktva_ktla(pmi_start);
44416 + pmi_pal = ktva_ktla(pmi_pal);
44417 + pax_close_kernel();
44418 +#endif
44419 +
44420 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
44421 if (pmi_base[3]) {
44422 printk(KERN_INFO "vesafb: pmi: ports = ");
44423 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
44424 info->node, info->fix.id);
44425 return 0;
44426 err:
44427 +
44428 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44429 + module_free_exec(NULL, pmi_code);
44430 +#endif
44431 +
44432 if (info->screen_base)
44433 iounmap(info->screen_base);
44434 framebuffer_release(info);
44435 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
44436 index 88714ae..16c2e11 100644
44437 --- a/drivers/video/via/via_clock.h
44438 +++ b/drivers/video/via/via_clock.h
44439 @@ -56,7 +56,7 @@ struct via_clock {
44440
44441 void (*set_engine_pll_state)(u8 state);
44442 void (*set_engine_pll)(struct via_pll_config config);
44443 -};
44444 +} __no_const;
44445
44446
44447 static inline u32 get_pll_internal_frequency(u32 ref_freq,
44448 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
44449 index 6b1b7e1..b2fa4d5 100644
44450 --- a/drivers/virtio/virtio_mmio.c
44451 +++ b/drivers/virtio/virtio_mmio.c
44452 @@ -530,7 +530,7 @@ static int vm_cmdline_set(const char *device,
44453
44454 resources[0].end = memparse(device, &str) - 1;
44455
44456 - processed = sscanf(str, "@%lli:%u%n:%d%n",
44457 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
44458 &base, &resources[1].start, &consumed,
44459 &vm_cmdline_id, &consumed);
44460
44461 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
44462 index fef20db..d28b1ab 100644
44463 --- a/drivers/xen/xenfs/xenstored.c
44464 +++ b/drivers/xen/xenfs/xenstored.c
44465 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
44466 static int xsd_kva_open(struct inode *inode, struct file *file)
44467 {
44468 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
44469 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44470 + NULL);
44471 +#else
44472 xen_store_interface);
44473 +#endif
44474 +
44475 if (!file->private_data)
44476 return -ENOMEM;
44477 return 0;
44478 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
44479 index 890bed5..17ae73e 100644
44480 --- a/fs/9p/vfs_inode.c
44481 +++ b/fs/9p/vfs_inode.c
44482 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
44483 void
44484 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44485 {
44486 - char *s = nd_get_link(nd);
44487 + const char *s = nd_get_link(nd);
44488
44489 p9_debug(P9_DEBUG_VFS, " %s %s\n",
44490 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
44491 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
44492 index 0efd152..b5802ad 100644
44493 --- a/fs/Kconfig.binfmt
44494 +++ b/fs/Kconfig.binfmt
44495 @@ -89,7 +89,7 @@ config HAVE_AOUT
44496
44497 config BINFMT_AOUT
44498 tristate "Kernel support for a.out and ECOFF binaries"
44499 - depends on HAVE_AOUT
44500 + depends on HAVE_AOUT && BROKEN
44501 ---help---
44502 A.out (Assembler.OUTput) is a set of formats for libraries and
44503 executables used in the earliest versions of UNIX. Linux used
44504 diff --git a/fs/aio.c b/fs/aio.c
44505 index 71f613c..9d01f1f 100644
44506 --- a/fs/aio.c
44507 +++ b/fs/aio.c
44508 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
44509 size += sizeof(struct io_event) * nr_events;
44510 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
44511
44512 - if (nr_pages < 0)
44513 + if (nr_pages <= 0)
44514 return -EINVAL;
44515
44516 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
44517 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
44518 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44519 {
44520 ssize_t ret;
44521 + struct iovec iovstack;
44522
44523 #ifdef CONFIG_COMPAT
44524 if (compat)
44525 ret = compat_rw_copy_check_uvector(type,
44526 (struct compat_iovec __user *)kiocb->ki_buf,
44527 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44528 + kiocb->ki_nbytes, 1, &iovstack,
44529 &kiocb->ki_iovec);
44530 else
44531 #endif
44532 ret = rw_copy_check_uvector(type,
44533 (struct iovec __user *)kiocb->ki_buf,
44534 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44535 + kiocb->ki_nbytes, 1, &iovstack,
44536 &kiocb->ki_iovec);
44537 if (ret < 0)
44538 goto out;
44539 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44540 if (ret < 0)
44541 goto out;
44542
44543 + if (kiocb->ki_iovec == &iovstack) {
44544 + kiocb->ki_inline_vec = iovstack;
44545 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
44546 + }
44547 kiocb->ki_nr_segs = kiocb->ki_nbytes;
44548 kiocb->ki_cur_seg = 0;
44549 /* ki_nbytes/left now reflect bytes instead of segs */
44550 diff --git a/fs/attr.c b/fs/attr.c
44551 index cce7df5..eaa2731 100644
44552 --- a/fs/attr.c
44553 +++ b/fs/attr.c
44554 @@ -100,6 +100,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
44555 unsigned long limit;
44556
44557 limit = rlimit(RLIMIT_FSIZE);
44558 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
44559 if (limit != RLIM_INFINITY && offset > limit)
44560 goto out_sig;
44561 if (offset > inode->i_sb->s_maxbytes)
44562 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
44563 index dce436e..55e670d 100644
44564 --- a/fs/autofs4/waitq.c
44565 +++ b/fs/autofs4/waitq.c
44566 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
44567 {
44568 unsigned long sigpipe, flags;
44569 mm_segment_t fs;
44570 - const char *data = (const char *)addr;
44571 + const char __user *data = (const char __force_user *)addr;
44572 ssize_t wr = 0;
44573
44574 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
44575 @@ -347,6 +347,10 @@ static int validate_request(struct autofs_wait_queue **wait,
44576 return 1;
44577 }
44578
44579 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44580 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
44581 +#endif
44582 +
44583 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44584 enum autofs_notify notify)
44585 {
44586 @@ -380,7 +384,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44587
44588 /* If this is a direct mount request create a dummy name */
44589 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
44590 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44591 + /* this name does get written to userland via autofs4_write() */
44592 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
44593 +#else
44594 qstr.len = sprintf(name, "%p", dentry);
44595 +#endif
44596 else {
44597 qstr.len = autofs4_getpath(sbi, dentry, &name);
44598 if (!qstr.len) {
44599 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
44600 index 2b3bda8..6a2d4be 100644
44601 --- a/fs/befs/linuxvfs.c
44602 +++ b/fs/befs/linuxvfs.c
44603 @@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44604 {
44605 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
44606 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
44607 - char *link = nd_get_link(nd);
44608 + const char *link = nd_get_link(nd);
44609 if (!IS_ERR(link))
44610 kfree(link);
44611 }
44612 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
44613 index 0e7a6f8..332b1ca 100644
44614 --- a/fs/binfmt_aout.c
44615 +++ b/fs/binfmt_aout.c
44616 @@ -16,6 +16,7 @@
44617 #include <linux/string.h>
44618 #include <linux/fs.h>
44619 #include <linux/file.h>
44620 +#include <linux/security.h>
44621 #include <linux/stat.h>
44622 #include <linux/fcntl.h>
44623 #include <linux/ptrace.h>
44624 @@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
44625 #endif
44626 # define START_STACK(u) ((void __user *)u.start_stack)
44627
44628 + memset(&dump, 0, sizeof(dump));
44629 +
44630 fs = get_fs();
44631 set_fs(KERNEL_DS);
44632 has_dumped = 1;
44633 @@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
44634
44635 /* If the size of the dump file exceeds the rlimit, then see what would happen
44636 if we wrote the stack, but not the data area. */
44637 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
44638 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
44639 dump.u_dsize = 0;
44640
44641 /* Make sure we have enough room to write the stack and data areas. */
44642 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
44643 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
44644 dump.u_ssize = 0;
44645
44646 @@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44647 rlim = rlimit(RLIMIT_DATA);
44648 if (rlim >= RLIM_INFINITY)
44649 rlim = ~0;
44650 +
44651 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
44652 if (ex.a_data + ex.a_bss > rlim)
44653 return -ENOMEM;
44654
44655 @@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44656
44657 install_exec_creds(bprm);
44658
44659 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44660 + current->mm->pax_flags = 0UL;
44661 +#endif
44662 +
44663 +#ifdef CONFIG_PAX_PAGEEXEC
44664 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
44665 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
44666 +
44667 +#ifdef CONFIG_PAX_EMUTRAMP
44668 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
44669 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
44670 +#endif
44671 +
44672 +#ifdef CONFIG_PAX_MPROTECT
44673 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
44674 + current->mm->pax_flags |= MF_PAX_MPROTECT;
44675 +#endif
44676 +
44677 + }
44678 +#endif
44679 +
44680 if (N_MAGIC(ex) == OMAGIC) {
44681 unsigned long text_addr, map_size;
44682 loff_t pos;
44683 @@ -332,7 +360,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44684 }
44685
44686 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
44687 - PROT_READ | PROT_WRITE | PROT_EXEC,
44688 + PROT_READ | PROT_WRITE,
44689 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
44690 fd_offset + ex.a_text);
44691 if (error != N_DATADDR(ex)) {
44692 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
44693 index fbd9f60..0b845dd 100644
44694 --- a/fs/binfmt_elf.c
44695 +++ b/fs/binfmt_elf.c
44696 @@ -33,6 +33,7 @@
44697 #include <linux/elf.h>
44698 #include <linux/utsname.h>
44699 #include <linux/coredump.h>
44700 +#include <linux/xattr.h>
44701 #include <asm/uaccess.h>
44702 #include <asm/param.h>
44703 #include <asm/page.h>
44704 @@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
44705 #define elf_core_dump NULL
44706 #endif
44707
44708 +#ifdef CONFIG_PAX_MPROTECT
44709 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
44710 +#endif
44711 +
44712 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
44713 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
44714 #else
44715 @@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
44716 .load_binary = load_elf_binary,
44717 .load_shlib = load_elf_library,
44718 .core_dump = elf_core_dump,
44719 +
44720 +#ifdef CONFIG_PAX_MPROTECT
44721 + .handle_mprotect= elf_handle_mprotect,
44722 +#endif
44723 +
44724 .min_coredump = ELF_EXEC_PAGESIZE,
44725 };
44726
44727 @@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
44728
44729 static int set_brk(unsigned long start, unsigned long end)
44730 {
44731 + unsigned long e = end;
44732 +
44733 start = ELF_PAGEALIGN(start);
44734 end = ELF_PAGEALIGN(end);
44735 if (end > start) {
44736 @@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
44737 if (BAD_ADDR(addr))
44738 return addr;
44739 }
44740 - current->mm->start_brk = current->mm->brk = end;
44741 + current->mm->start_brk = current->mm->brk = e;
44742 return 0;
44743 }
44744
44745 @@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44746 elf_addr_t __user *u_rand_bytes;
44747 const char *k_platform = ELF_PLATFORM;
44748 const char *k_base_platform = ELF_BASE_PLATFORM;
44749 - unsigned char k_rand_bytes[16];
44750 + u32 k_rand_bytes[4];
44751 int items;
44752 elf_addr_t *elf_info;
44753 int ei_index = 0;
44754 const struct cred *cred = current_cred();
44755 struct vm_area_struct *vma;
44756 + unsigned long saved_auxv[AT_VECTOR_SIZE];
44757
44758 /*
44759 * In some cases (e.g. Hyper-Threading), we want to avoid L1
44760 @@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44761 * Generate 16 random bytes for userspace PRNG seeding.
44762 */
44763 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
44764 - u_rand_bytes = (elf_addr_t __user *)
44765 - STACK_ALLOC(p, sizeof(k_rand_bytes));
44766 + srandom32(k_rand_bytes[0] ^ random32());
44767 + srandom32(k_rand_bytes[1] ^ random32());
44768 + srandom32(k_rand_bytes[2] ^ random32());
44769 + srandom32(k_rand_bytes[3] ^ random32());
44770 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
44771 + u_rand_bytes = (elf_addr_t __user *) p;
44772 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
44773 return -EFAULT;
44774
44775 @@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44776 return -EFAULT;
44777 current->mm->env_end = p;
44778
44779 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
44780 +
44781 /* Put the elf_info on the stack in the right place. */
44782 sp = (elf_addr_t __user *)envp + 1;
44783 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
44784 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
44785 return -EFAULT;
44786 return 0;
44787 }
44788 @@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
44789 an ELF header */
44790
44791 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44792 - struct file *interpreter, unsigned long *interp_map_addr,
44793 - unsigned long no_base)
44794 + struct file *interpreter, unsigned long no_base)
44795 {
44796 struct elf_phdr *elf_phdata;
44797 struct elf_phdr *eppnt;
44798 - unsigned long load_addr = 0;
44799 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
44800 int load_addr_set = 0;
44801 unsigned long last_bss = 0, elf_bss = 0;
44802 - unsigned long error = ~0UL;
44803 + unsigned long error = -EINVAL;
44804 unsigned long total_size;
44805 int retval, i, size;
44806
44807 @@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44808 goto out_close;
44809 }
44810
44811 +#ifdef CONFIG_PAX_SEGMEXEC
44812 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
44813 + pax_task_size = SEGMEXEC_TASK_SIZE;
44814 +#endif
44815 +
44816 eppnt = elf_phdata;
44817 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
44818 if (eppnt->p_type == PT_LOAD) {
44819 @@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44820 map_addr = elf_map(interpreter, load_addr + vaddr,
44821 eppnt, elf_prot, elf_type, total_size);
44822 total_size = 0;
44823 - if (!*interp_map_addr)
44824 - *interp_map_addr = map_addr;
44825 error = map_addr;
44826 if (BAD_ADDR(map_addr))
44827 goto out_close;
44828 @@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44829 k = load_addr + eppnt->p_vaddr;
44830 if (BAD_ADDR(k) ||
44831 eppnt->p_filesz > eppnt->p_memsz ||
44832 - eppnt->p_memsz > TASK_SIZE ||
44833 - TASK_SIZE - eppnt->p_memsz < k) {
44834 + eppnt->p_memsz > pax_task_size ||
44835 + pax_task_size - eppnt->p_memsz < k) {
44836 error = -ENOMEM;
44837 goto out_close;
44838 }
44839 @@ -530,6 +551,315 @@ out:
44840 return error;
44841 }
44842
44843 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
44844 +#ifdef CONFIG_PAX_SOFTMODE
44845 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
44846 +{
44847 + unsigned long pax_flags = 0UL;
44848 +
44849 +#ifdef CONFIG_PAX_PAGEEXEC
44850 + if (elf_phdata->p_flags & PF_PAGEEXEC)
44851 + pax_flags |= MF_PAX_PAGEEXEC;
44852 +#endif
44853 +
44854 +#ifdef CONFIG_PAX_SEGMEXEC
44855 + if (elf_phdata->p_flags & PF_SEGMEXEC)
44856 + pax_flags |= MF_PAX_SEGMEXEC;
44857 +#endif
44858 +
44859 +#ifdef CONFIG_PAX_EMUTRAMP
44860 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
44861 + pax_flags |= MF_PAX_EMUTRAMP;
44862 +#endif
44863 +
44864 +#ifdef CONFIG_PAX_MPROTECT
44865 + if (elf_phdata->p_flags & PF_MPROTECT)
44866 + pax_flags |= MF_PAX_MPROTECT;
44867 +#endif
44868 +
44869 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44870 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
44871 + pax_flags |= MF_PAX_RANDMMAP;
44872 +#endif
44873 +
44874 + return pax_flags;
44875 +}
44876 +#endif
44877 +
44878 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
44879 +{
44880 + unsigned long pax_flags = 0UL;
44881 +
44882 +#ifdef CONFIG_PAX_PAGEEXEC
44883 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
44884 + pax_flags |= MF_PAX_PAGEEXEC;
44885 +#endif
44886 +
44887 +#ifdef CONFIG_PAX_SEGMEXEC
44888 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
44889 + pax_flags |= MF_PAX_SEGMEXEC;
44890 +#endif
44891 +
44892 +#ifdef CONFIG_PAX_EMUTRAMP
44893 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
44894 + pax_flags |= MF_PAX_EMUTRAMP;
44895 +#endif
44896 +
44897 +#ifdef CONFIG_PAX_MPROTECT
44898 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
44899 + pax_flags |= MF_PAX_MPROTECT;
44900 +#endif
44901 +
44902 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44903 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
44904 + pax_flags |= MF_PAX_RANDMMAP;
44905 +#endif
44906 +
44907 + return pax_flags;
44908 +}
44909 +#endif
44910 +
44911 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44912 +#ifdef CONFIG_PAX_SOFTMODE
44913 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
44914 +{
44915 + unsigned long pax_flags = 0UL;
44916 +
44917 +#ifdef CONFIG_PAX_PAGEEXEC
44918 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
44919 + pax_flags |= MF_PAX_PAGEEXEC;
44920 +#endif
44921 +
44922 +#ifdef CONFIG_PAX_SEGMEXEC
44923 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
44924 + pax_flags |= MF_PAX_SEGMEXEC;
44925 +#endif
44926 +
44927 +#ifdef CONFIG_PAX_EMUTRAMP
44928 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
44929 + pax_flags |= MF_PAX_EMUTRAMP;
44930 +#endif
44931 +
44932 +#ifdef CONFIG_PAX_MPROTECT
44933 + if (pax_flags_softmode & MF_PAX_MPROTECT)
44934 + pax_flags |= MF_PAX_MPROTECT;
44935 +#endif
44936 +
44937 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44938 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
44939 + pax_flags |= MF_PAX_RANDMMAP;
44940 +#endif
44941 +
44942 + return pax_flags;
44943 +}
44944 +#endif
44945 +
44946 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
44947 +{
44948 + unsigned long pax_flags = 0UL;
44949 +
44950 +#ifdef CONFIG_PAX_PAGEEXEC
44951 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
44952 + pax_flags |= MF_PAX_PAGEEXEC;
44953 +#endif
44954 +
44955 +#ifdef CONFIG_PAX_SEGMEXEC
44956 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
44957 + pax_flags |= MF_PAX_SEGMEXEC;
44958 +#endif
44959 +
44960 +#ifdef CONFIG_PAX_EMUTRAMP
44961 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
44962 + pax_flags |= MF_PAX_EMUTRAMP;
44963 +#endif
44964 +
44965 +#ifdef CONFIG_PAX_MPROTECT
44966 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
44967 + pax_flags |= MF_PAX_MPROTECT;
44968 +#endif
44969 +
44970 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44971 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
44972 + pax_flags |= MF_PAX_RANDMMAP;
44973 +#endif
44974 +
44975 + return pax_flags;
44976 +}
44977 +#endif
44978 +
44979 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44980 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
44981 +{
44982 + unsigned long pax_flags = 0UL;
44983 +
44984 +#ifdef CONFIG_PAX_EI_PAX
44985 +
44986 +#ifdef CONFIG_PAX_PAGEEXEC
44987 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
44988 + pax_flags |= MF_PAX_PAGEEXEC;
44989 +#endif
44990 +
44991 +#ifdef CONFIG_PAX_SEGMEXEC
44992 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
44993 + pax_flags |= MF_PAX_SEGMEXEC;
44994 +#endif
44995 +
44996 +#ifdef CONFIG_PAX_EMUTRAMP
44997 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
44998 + pax_flags |= MF_PAX_EMUTRAMP;
44999 +#endif
45000 +
45001 +#ifdef CONFIG_PAX_MPROTECT
45002 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
45003 + pax_flags |= MF_PAX_MPROTECT;
45004 +#endif
45005 +
45006 +#ifdef CONFIG_PAX_ASLR
45007 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
45008 + pax_flags |= MF_PAX_RANDMMAP;
45009 +#endif
45010 +
45011 +#else
45012 +
45013 +#ifdef CONFIG_PAX_PAGEEXEC
45014 + pax_flags |= MF_PAX_PAGEEXEC;
45015 +#endif
45016 +
45017 +#ifdef CONFIG_PAX_SEGMEXEC
45018 + pax_flags |= MF_PAX_SEGMEXEC;
45019 +#endif
45020 +
45021 +#ifdef CONFIG_PAX_MPROTECT
45022 + pax_flags |= MF_PAX_MPROTECT;
45023 +#endif
45024 +
45025 +#ifdef CONFIG_PAX_RANDMMAP
45026 + if (randomize_va_space)
45027 + pax_flags |= MF_PAX_RANDMMAP;
45028 +#endif
45029 +
45030 +#endif
45031 +
45032 + return pax_flags;
45033 +}
45034 +
45035 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
45036 +{
45037 +
45038 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
45039 + unsigned long i;
45040 +
45041 + for (i = 0UL; i < elf_ex->e_phnum; i++)
45042 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
45043 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
45044 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
45045 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
45046 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
45047 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
45048 + return ~0UL;
45049 +
45050 +#ifdef CONFIG_PAX_SOFTMODE
45051 + if (pax_softmode)
45052 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
45053 + else
45054 +#endif
45055 +
45056 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
45057 + break;
45058 + }
45059 +#endif
45060 +
45061 + return ~0UL;
45062 +}
45063 +
45064 +static unsigned long pax_parse_xattr_pax(struct file * const file)
45065 +{
45066 +
45067 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
45068 + ssize_t xattr_size, i;
45069 + unsigned char xattr_value[5];
45070 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
45071 +
45072 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
45073 + if (xattr_size <= 0 || xattr_size > 5)
45074 + return ~0UL;
45075 +
45076 + for (i = 0; i < xattr_size; i++)
45077 + switch (xattr_value[i]) {
45078 + default:
45079 + return ~0UL;
45080 +
45081 +#define parse_flag(option1, option2, flag) \
45082 + case option1: \
45083 + if (pax_flags_hardmode & MF_PAX_##flag) \
45084 + return ~0UL; \
45085 + pax_flags_hardmode |= MF_PAX_##flag; \
45086 + break; \
45087 + case option2: \
45088 + if (pax_flags_softmode & MF_PAX_##flag) \
45089 + return ~0UL; \
45090 + pax_flags_softmode |= MF_PAX_##flag; \
45091 + break;
45092 +
45093 + parse_flag('p', 'P', PAGEEXEC);
45094 + parse_flag('e', 'E', EMUTRAMP);
45095 + parse_flag('m', 'M', MPROTECT);
45096 + parse_flag('r', 'R', RANDMMAP);
45097 + parse_flag('s', 'S', SEGMEXEC);
45098 +
45099 +#undef parse_flag
45100 + }
45101 +
45102 + if (pax_flags_hardmode & pax_flags_softmode)
45103 + return ~0UL;
45104 +
45105 +#ifdef CONFIG_PAX_SOFTMODE
45106 + if (pax_softmode)
45107 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
45108 + else
45109 +#endif
45110 +
45111 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
45112 +#else
45113 + return ~0UL;
45114 +#endif
45115 +
45116 +}
45117 +
45118 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
45119 +{
45120 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
45121 +
45122 + pax_flags = pax_parse_ei_pax(elf_ex);
45123 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
45124 + xattr_pax_flags = pax_parse_xattr_pax(file);
45125 +
45126 + if (pt_pax_flags == ~0UL)
45127 + pt_pax_flags = xattr_pax_flags;
45128 + else if (xattr_pax_flags == ~0UL)
45129 + xattr_pax_flags = pt_pax_flags;
45130 + if (pt_pax_flags != xattr_pax_flags)
45131 + return -EINVAL;
45132 + if (pt_pax_flags != ~0UL)
45133 + pax_flags = pt_pax_flags;
45134 +
45135 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
45136 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45137 + if ((__supported_pte_mask & _PAGE_NX))
45138 + pax_flags &= ~MF_PAX_SEGMEXEC;
45139 + else
45140 + pax_flags &= ~MF_PAX_PAGEEXEC;
45141 + }
45142 +#endif
45143 +
45144 + if (0 > pax_check_flags(&pax_flags))
45145 + return -EINVAL;
45146 +
45147 + current->mm->pax_flags = pax_flags;
45148 + return 0;
45149 +}
45150 +#endif
45151 +
45152 /*
45153 * These are the functions used to load ELF style executables and shared
45154 * libraries. There is no binary dependent code anywhere else.
45155 @@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
45156 {
45157 unsigned int random_variable = 0;
45158
45159 +#ifdef CONFIG_PAX_RANDUSTACK
45160 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
45161 + return stack_top - current->mm->delta_stack;
45162 +#endif
45163 +
45164 if ((current->flags & PF_RANDOMIZE) &&
45165 !(current->personality & ADDR_NO_RANDOMIZE)) {
45166 random_variable = get_random_int() & STACK_RND_MASK;
45167 @@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45168 unsigned long load_addr = 0, load_bias = 0;
45169 int load_addr_set = 0;
45170 char * elf_interpreter = NULL;
45171 - unsigned long error;
45172 + unsigned long error = 0;
45173 struct elf_phdr *elf_ppnt, *elf_phdata;
45174 unsigned long elf_bss, elf_brk;
45175 int retval, i;
45176 @@ -574,11 +909,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45177 unsigned long start_code, end_code, start_data, end_data;
45178 unsigned long reloc_func_desc __maybe_unused = 0;
45179 int executable_stack = EXSTACK_DEFAULT;
45180 - unsigned long def_flags = 0;
45181 struct {
45182 struct elfhdr elf_ex;
45183 struct elfhdr interp_elf_ex;
45184 } *loc;
45185 + unsigned long pax_task_size = TASK_SIZE;
45186
45187 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
45188 if (!loc) {
45189 @@ -714,11 +1049,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45190 goto out_free_dentry;
45191
45192 /* OK, This is the point of no return */
45193 - current->mm->def_flags = def_flags;
45194 +
45195 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45196 + current->mm->pax_flags = 0UL;
45197 +#endif
45198 +
45199 +#ifdef CONFIG_PAX_DLRESOLVE
45200 + current->mm->call_dl_resolve = 0UL;
45201 +#endif
45202 +
45203 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
45204 + current->mm->call_syscall = 0UL;
45205 +#endif
45206 +
45207 +#ifdef CONFIG_PAX_ASLR
45208 + current->mm->delta_mmap = 0UL;
45209 + current->mm->delta_stack = 0UL;
45210 +#endif
45211 +
45212 + current->mm->def_flags = 0;
45213 +
45214 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45215 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
45216 + send_sig(SIGKILL, current, 0);
45217 + goto out_free_dentry;
45218 + }
45219 +#endif
45220 +
45221 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45222 + pax_set_initial_flags(bprm);
45223 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
45224 + if (pax_set_initial_flags_func)
45225 + (pax_set_initial_flags_func)(bprm);
45226 +#endif
45227 +
45228 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
45229 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
45230 + current->mm->context.user_cs_limit = PAGE_SIZE;
45231 + current->mm->def_flags |= VM_PAGEEXEC;
45232 + }
45233 +#endif
45234 +
45235 +#ifdef CONFIG_PAX_SEGMEXEC
45236 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
45237 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
45238 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
45239 + pax_task_size = SEGMEXEC_TASK_SIZE;
45240 + current->mm->def_flags |= VM_NOHUGEPAGE;
45241 + }
45242 +#endif
45243 +
45244 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
45245 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45246 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
45247 + put_cpu();
45248 + }
45249 +#endif
45250
45251 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
45252 may depend on the personality. */
45253 SET_PERSONALITY(loc->elf_ex);
45254 +
45255 +#ifdef CONFIG_PAX_ASLR
45256 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45257 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
45258 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
45259 + }
45260 +#endif
45261 +
45262 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45263 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45264 + executable_stack = EXSTACK_DISABLE_X;
45265 + current->personality &= ~READ_IMPLIES_EXEC;
45266 + } else
45267 +#endif
45268 +
45269 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
45270 current->personality |= READ_IMPLIES_EXEC;
45271
45272 @@ -809,6 +1214,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45273 #else
45274 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
45275 #endif
45276 +
45277 +#ifdef CONFIG_PAX_RANDMMAP
45278 + /* PaX: randomize base address at the default exe base if requested */
45279 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
45280 +#ifdef CONFIG_SPARC64
45281 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
45282 +#else
45283 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
45284 +#endif
45285 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
45286 + elf_flags |= MAP_FIXED;
45287 + }
45288 +#endif
45289 +
45290 }
45291
45292 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
45293 @@ -841,9 +1260,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45294 * allowed task size. Note that p_filesz must always be
45295 * <= p_memsz so it is only necessary to check p_memsz.
45296 */
45297 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45298 - elf_ppnt->p_memsz > TASK_SIZE ||
45299 - TASK_SIZE - elf_ppnt->p_memsz < k) {
45300 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45301 + elf_ppnt->p_memsz > pax_task_size ||
45302 + pax_task_size - elf_ppnt->p_memsz < k) {
45303 /* set_brk can never work. Avoid overflows. */
45304 send_sig(SIGKILL, current, 0);
45305 retval = -EINVAL;
45306 @@ -882,17 +1301,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
45307 goto out_free_dentry;
45308 }
45309 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
45310 - send_sig(SIGSEGV, current, 0);
45311 - retval = -EFAULT; /* Nobody gets to see this, but.. */
45312 - goto out_free_dentry;
45313 + /*
45314 + * This bss-zeroing can fail if the ELF
45315 + * file specifies odd protections. So
45316 + * we don't check the return value
45317 + */
45318 }
45319
45320 +#ifdef CONFIG_PAX_RANDMMAP
45321 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45322 + unsigned long start, size;
45323 +
45324 + start = ELF_PAGEALIGN(elf_brk);
45325 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
45326 + down_read(&current->mm->mmap_sem);
45327 + retval = -ENOMEM;
45328 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
45329 + unsigned long prot = PROT_NONE;
45330 +
45331 + up_read(&current->mm->mmap_sem);
45332 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
45333 +// if (current->personality & ADDR_NO_RANDOMIZE)
45334 +// prot = PROT_READ;
45335 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
45336 + retval = IS_ERR_VALUE(start) ? start : 0;
45337 + } else
45338 + up_read(&current->mm->mmap_sem);
45339 + if (retval == 0)
45340 + retval = set_brk(start + size, start + size + PAGE_SIZE);
45341 + if (retval < 0) {
45342 + send_sig(SIGKILL, current, 0);
45343 + goto out_free_dentry;
45344 + }
45345 + }
45346 +#endif
45347 +
45348 if (elf_interpreter) {
45349 - unsigned long interp_map_addr = 0;
45350 -
45351 elf_entry = load_elf_interp(&loc->interp_elf_ex,
45352 interpreter,
45353 - &interp_map_addr,
45354 load_bias);
45355 if (!IS_ERR((void *)elf_entry)) {
45356 /*
45357 @@ -1114,7 +1560,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
45358 * Decide what to dump of a segment, part, all or none.
45359 */
45360 static unsigned long vma_dump_size(struct vm_area_struct *vma,
45361 - unsigned long mm_flags)
45362 + unsigned long mm_flags, long signr)
45363 {
45364 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
45365
45366 @@ -1151,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
45367 if (vma->vm_file == NULL)
45368 return 0;
45369
45370 - if (FILTER(MAPPED_PRIVATE))
45371 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
45372 goto whole;
45373
45374 /*
45375 @@ -1373,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
45376 {
45377 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
45378 int i = 0;
45379 - do
45380 + do {
45381 i += 2;
45382 - while (auxv[i - 2] != AT_NULL);
45383 + } while (auxv[i - 2] != AT_NULL);
45384 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
45385 }
45386
45387 @@ -2003,14 +2449,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
45388 }
45389
45390 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
45391 - unsigned long mm_flags)
45392 + struct coredump_params *cprm)
45393 {
45394 struct vm_area_struct *vma;
45395 size_t size = 0;
45396
45397 for (vma = first_vma(current, gate_vma); vma != NULL;
45398 vma = next_vma(vma, gate_vma))
45399 - size += vma_dump_size(vma, mm_flags);
45400 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45401 return size;
45402 }
45403
45404 @@ -2104,7 +2550,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45405
45406 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
45407
45408 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
45409 + offset += elf_core_vma_data_size(gate_vma, cprm);
45410 offset += elf_core_extra_data_size();
45411 e_shoff = offset;
45412
45413 @@ -2118,10 +2564,12 @@ static int elf_core_dump(struct coredump_params *cprm)
45414 offset = dataoff;
45415
45416 size += sizeof(*elf);
45417 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45418 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
45419 goto end_coredump;
45420
45421 size += sizeof(*phdr4note);
45422 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45423 if (size > cprm->limit
45424 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
45425 goto end_coredump;
45426 @@ -2135,7 +2583,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45427 phdr.p_offset = offset;
45428 phdr.p_vaddr = vma->vm_start;
45429 phdr.p_paddr = 0;
45430 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
45431 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45432 phdr.p_memsz = vma->vm_end - vma->vm_start;
45433 offset += phdr.p_filesz;
45434 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
45435 @@ -2146,6 +2594,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45436 phdr.p_align = ELF_EXEC_PAGESIZE;
45437
45438 size += sizeof(phdr);
45439 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45440 if (size > cprm->limit
45441 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
45442 goto end_coredump;
45443 @@ -2170,7 +2619,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45444 unsigned long addr;
45445 unsigned long end;
45446
45447 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
45448 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45449
45450 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
45451 struct page *page;
45452 @@ -2179,6 +2628,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45453 page = get_dump_page(addr);
45454 if (page) {
45455 void *kaddr = kmap(page);
45456 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
45457 stop = ((size += PAGE_SIZE) > cprm->limit) ||
45458 !dump_write(cprm->file, kaddr,
45459 PAGE_SIZE);
45460 @@ -2196,6 +2646,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45461
45462 if (e_phnum == PN_XNUM) {
45463 size += sizeof(*shdr4extnum);
45464 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
45465 if (size > cprm->limit
45466 || !dump_write(cprm->file, shdr4extnum,
45467 sizeof(*shdr4extnum)))
45468 @@ -2216,6 +2667,97 @@ out:
45469
45470 #endif /* CONFIG_ELF_CORE */
45471
45472 +#ifdef CONFIG_PAX_MPROTECT
45473 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
45474 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
45475 + * we'll remove VM_MAYWRITE for good on RELRO segments.
45476 + *
45477 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
45478 + * basis because we want to allow the common case and not the special ones.
45479 + */
45480 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
45481 +{
45482 + struct elfhdr elf_h;
45483 + struct elf_phdr elf_p;
45484 + unsigned long i;
45485 + unsigned long oldflags;
45486 + bool is_textrel_rw, is_textrel_rx, is_relro;
45487 +
45488 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
45489 + return;
45490 +
45491 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
45492 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
45493 +
45494 +#ifdef CONFIG_PAX_ELFRELOCS
45495 + /* possible TEXTREL */
45496 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
45497 + 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);
45498 +#else
45499 + is_textrel_rw = false;
45500 + is_textrel_rx = false;
45501 +#endif
45502 +
45503 + /* possible RELRO */
45504 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
45505 +
45506 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
45507 + return;
45508 +
45509 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
45510 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
45511 +
45512 +#ifdef CONFIG_PAX_ETEXECRELOCS
45513 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45514 +#else
45515 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
45516 +#endif
45517 +
45518 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45519 + !elf_check_arch(&elf_h) ||
45520 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
45521 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
45522 + return;
45523 +
45524 + for (i = 0UL; i < elf_h.e_phnum; i++) {
45525 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
45526 + return;
45527 + switch (elf_p.p_type) {
45528 + case PT_DYNAMIC:
45529 + if (!is_textrel_rw && !is_textrel_rx)
45530 + continue;
45531 + i = 0UL;
45532 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
45533 + elf_dyn dyn;
45534 +
45535 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
45536 + return;
45537 + if (dyn.d_tag == DT_NULL)
45538 + return;
45539 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
45540 + gr_log_textrel(vma);
45541 + if (is_textrel_rw)
45542 + vma->vm_flags |= VM_MAYWRITE;
45543 + else
45544 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
45545 + vma->vm_flags &= ~VM_MAYWRITE;
45546 + return;
45547 + }
45548 + i++;
45549 + }
45550 + return;
45551 +
45552 + case PT_GNU_RELRO:
45553 + if (!is_relro)
45554 + continue;
45555 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
45556 + vma->vm_flags &= ~VM_MAYWRITE;
45557 + return;
45558 + }
45559 + }
45560 +}
45561 +#endif
45562 +
45563 static int __init init_elf_binfmt(void)
45564 {
45565 register_binfmt(&elf_format);
45566 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
45567 index e280352..7b2f231 100644
45568 --- a/fs/binfmt_flat.c
45569 +++ b/fs/binfmt_flat.c
45570 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
45571 realdatastart = (unsigned long) -ENOMEM;
45572 printk("Unable to allocate RAM for process data, errno %d\n",
45573 (int)-realdatastart);
45574 + down_write(&current->mm->mmap_sem);
45575 vm_munmap(textpos, text_len);
45576 + up_write(&current->mm->mmap_sem);
45577 ret = realdatastart;
45578 goto err;
45579 }
45580 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45581 }
45582 if (IS_ERR_VALUE(result)) {
45583 printk("Unable to read data+bss, errno %d\n", (int)-result);
45584 + down_write(&current->mm->mmap_sem);
45585 vm_munmap(textpos, text_len);
45586 vm_munmap(realdatastart, len);
45587 + up_write(&current->mm->mmap_sem);
45588 ret = result;
45589 goto err;
45590 }
45591 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45592 }
45593 if (IS_ERR_VALUE(result)) {
45594 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
45595 + down_write(&current->mm->mmap_sem);
45596 vm_munmap(textpos, text_len + data_len + extra +
45597 MAX_SHARED_LIBS * sizeof(unsigned long));
45598 + up_write(&current->mm->mmap_sem);
45599 ret = result;
45600 goto err;
45601 }
45602 diff --git a/fs/bio.c b/fs/bio.c
45603 index b96fc6c..431d628 100644
45604 --- a/fs/bio.c
45605 +++ b/fs/bio.c
45606 @@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
45607 /*
45608 * Overflow, abort
45609 */
45610 - if (end < start)
45611 + if (end < start || end - start > INT_MAX - nr_pages)
45612 return ERR_PTR(-EINVAL);
45613
45614 nr_pages += end - start;
45615 @@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
45616 /*
45617 * Overflow, abort
45618 */
45619 - if (end < start)
45620 + if (end < start || end - start > INT_MAX - nr_pages)
45621 return ERR_PTR(-EINVAL);
45622
45623 nr_pages += end - start;
45624 @@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
45625 const int read = bio_data_dir(bio) == READ;
45626 struct bio_map_data *bmd = bio->bi_private;
45627 int i;
45628 - char *p = bmd->sgvecs[0].iov_base;
45629 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
45630
45631 __bio_for_each_segment(bvec, bio, i, 0) {
45632 char *addr = page_address(bvec->bv_page);
45633 diff --git a/fs/block_dev.c b/fs/block_dev.c
45634 index ab3a456..7da538b 100644
45635 --- a/fs/block_dev.c
45636 +++ b/fs/block_dev.c
45637 @@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
45638 else if (bdev->bd_contains == bdev)
45639 return true; /* is a whole device which isn't held */
45640
45641 - else if (whole->bd_holder == bd_may_claim)
45642 + else if (whole->bd_holder == (void *)bd_may_claim)
45643 return true; /* is a partition of a device that is being partitioned */
45644 else if (whole->bd_holder != NULL)
45645 return false; /* is a partition of a held device */
45646 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
45647 index cdfb4c4..da736d4 100644
45648 --- a/fs/btrfs/ctree.c
45649 +++ b/fs/btrfs/ctree.c
45650 @@ -1035,9 +1035,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
45651 free_extent_buffer(buf);
45652 add_root_to_dirty_list(root);
45653 } else {
45654 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
45655 - parent_start = parent->start;
45656 - else
45657 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
45658 + if (parent)
45659 + parent_start = parent->start;
45660 + else
45661 + parent_start = 0;
45662 + } else
45663 parent_start = 0;
45664
45665 WARN_ON(trans->transid != btrfs_header_generation(parent));
45666 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
45667 index 95542a1..95a8727 100644
45668 --- a/fs/btrfs/inode.c
45669 +++ b/fs/btrfs/inode.c
45670 @@ -7243,7 +7243,7 @@ fail:
45671 return -ENOMEM;
45672 }
45673
45674 -static int btrfs_getattr(struct vfsmount *mnt,
45675 +int btrfs_getattr(struct vfsmount *mnt,
45676 struct dentry *dentry, struct kstat *stat)
45677 {
45678 struct inode *inode = dentry->d_inode;
45679 @@ -7257,6 +7257,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
45680 return 0;
45681 }
45682
45683 +EXPORT_SYMBOL(btrfs_getattr);
45684 +
45685 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
45686 +{
45687 + return BTRFS_I(inode)->root->anon_dev;
45688 +}
45689 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
45690 +
45691 /*
45692 * If a file is moved, it will inherit the cow and compression flags of the new
45693 * directory.
45694 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
45695 index 8fcf9a5..a200000 100644
45696 --- a/fs/btrfs/ioctl.c
45697 +++ b/fs/btrfs/ioctl.c
45698 @@ -2965,9 +2965,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45699 for (i = 0; i < num_types; i++) {
45700 struct btrfs_space_info *tmp;
45701
45702 + /* Don't copy in more than we allocated */
45703 if (!slot_count)
45704 break;
45705
45706 + slot_count--;
45707 +
45708 info = NULL;
45709 rcu_read_lock();
45710 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
45711 @@ -2989,10 +2992,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45712 memcpy(dest, &space, sizeof(space));
45713 dest++;
45714 space_args.total_spaces++;
45715 - slot_count--;
45716 }
45717 - if (!slot_count)
45718 - break;
45719 }
45720 up_read(&info->groups_sem);
45721 }
45722 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
45723 index 776f0aa..3aad281 100644
45724 --- a/fs/btrfs/relocation.c
45725 +++ b/fs/btrfs/relocation.c
45726 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
45727 }
45728 spin_unlock(&rc->reloc_root_tree.lock);
45729
45730 - BUG_ON((struct btrfs_root *)node->data != root);
45731 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
45732
45733 if (!del) {
45734 spin_lock(&rc->reloc_root_tree.lock);
45735 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
45736 index 622f469..e8d2d55 100644
45737 --- a/fs/cachefiles/bind.c
45738 +++ b/fs/cachefiles/bind.c
45739 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
45740 args);
45741
45742 /* start by checking things over */
45743 - ASSERT(cache->fstop_percent >= 0 &&
45744 - cache->fstop_percent < cache->fcull_percent &&
45745 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
45746 cache->fcull_percent < cache->frun_percent &&
45747 cache->frun_percent < 100);
45748
45749 - ASSERT(cache->bstop_percent >= 0 &&
45750 - cache->bstop_percent < cache->bcull_percent &&
45751 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
45752 cache->bcull_percent < cache->brun_percent &&
45753 cache->brun_percent < 100);
45754
45755 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
45756 index 0a1467b..6a53245 100644
45757 --- a/fs/cachefiles/daemon.c
45758 +++ b/fs/cachefiles/daemon.c
45759 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
45760 if (n > buflen)
45761 return -EMSGSIZE;
45762
45763 - if (copy_to_user(_buffer, buffer, n) != 0)
45764 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
45765 return -EFAULT;
45766
45767 return n;
45768 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
45769 if (test_bit(CACHEFILES_DEAD, &cache->flags))
45770 return -EIO;
45771
45772 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
45773 + if (datalen > PAGE_SIZE - 1)
45774 return -EOPNOTSUPP;
45775
45776 /* drag the command string into the kernel so we can parse it */
45777 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
45778 if (args[0] != '%' || args[1] != '\0')
45779 return -EINVAL;
45780
45781 - if (fstop < 0 || fstop >= cache->fcull_percent)
45782 + if (fstop >= cache->fcull_percent)
45783 return cachefiles_daemon_range_error(cache, args);
45784
45785 cache->fstop_percent = fstop;
45786 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
45787 if (args[0] != '%' || args[1] != '\0')
45788 return -EINVAL;
45789
45790 - if (bstop < 0 || bstop >= cache->bcull_percent)
45791 + if (bstop >= cache->bcull_percent)
45792 return cachefiles_daemon_range_error(cache, args);
45793
45794 cache->bstop_percent = bstop;
45795 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
45796 index bd6bc1b..b627b53 100644
45797 --- a/fs/cachefiles/internal.h
45798 +++ b/fs/cachefiles/internal.h
45799 @@ -57,7 +57,7 @@ struct cachefiles_cache {
45800 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
45801 struct rb_root active_nodes; /* active nodes (can't be culled) */
45802 rwlock_t active_lock; /* lock for active_nodes */
45803 - atomic_t gravecounter; /* graveyard uniquifier */
45804 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
45805 unsigned frun_percent; /* when to stop culling (% files) */
45806 unsigned fcull_percent; /* when to start culling (% files) */
45807 unsigned fstop_percent; /* when to stop allocating (% files) */
45808 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
45809 * proc.c
45810 */
45811 #ifdef CONFIG_CACHEFILES_HISTOGRAM
45812 -extern atomic_t cachefiles_lookup_histogram[HZ];
45813 -extern atomic_t cachefiles_mkdir_histogram[HZ];
45814 -extern atomic_t cachefiles_create_histogram[HZ];
45815 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45816 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45817 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
45818
45819 extern int __init cachefiles_proc_init(void);
45820 extern void cachefiles_proc_cleanup(void);
45821 static inline
45822 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
45823 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
45824 {
45825 unsigned long jif = jiffies - start_jif;
45826 if (jif >= HZ)
45827 jif = HZ - 1;
45828 - atomic_inc(&histogram[jif]);
45829 + atomic_inc_unchecked(&histogram[jif]);
45830 }
45831
45832 #else
45833 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
45834 index b0b5f7c..039bb26 100644
45835 --- a/fs/cachefiles/namei.c
45836 +++ b/fs/cachefiles/namei.c
45837 @@ -318,7 +318,7 @@ try_again:
45838 /* first step is to make up a grave dentry in the graveyard */
45839 sprintf(nbuffer, "%08x%08x",
45840 (uint32_t) get_seconds(),
45841 - (uint32_t) atomic_inc_return(&cache->gravecounter));
45842 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
45843
45844 /* do the multiway lock magic */
45845 trap = lock_rename(cache->graveyard, dir);
45846 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
45847 index eccd339..4c1d995 100644
45848 --- a/fs/cachefiles/proc.c
45849 +++ b/fs/cachefiles/proc.c
45850 @@ -14,9 +14,9 @@
45851 #include <linux/seq_file.h>
45852 #include "internal.h"
45853
45854 -atomic_t cachefiles_lookup_histogram[HZ];
45855 -atomic_t cachefiles_mkdir_histogram[HZ];
45856 -atomic_t cachefiles_create_histogram[HZ];
45857 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45858 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45859 +atomic_unchecked_t cachefiles_create_histogram[HZ];
45860
45861 /*
45862 * display the latency histogram
45863 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
45864 return 0;
45865 default:
45866 index = (unsigned long) v - 3;
45867 - x = atomic_read(&cachefiles_lookup_histogram[index]);
45868 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
45869 - z = atomic_read(&cachefiles_create_histogram[index]);
45870 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
45871 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
45872 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
45873 if (x == 0 && y == 0 && z == 0)
45874 return 0;
45875
45876 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
45877 index c994691..2a1537f 100644
45878 --- a/fs/cachefiles/rdwr.c
45879 +++ b/fs/cachefiles/rdwr.c
45880 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
45881 old_fs = get_fs();
45882 set_fs(KERNEL_DS);
45883 ret = file->f_op->write(
45884 - file, (const void __user *) data, len, &pos);
45885 + file, (const void __force_user *) data, len, &pos);
45886 set_fs(old_fs);
45887 kunmap(page);
45888 if (ret != len)
45889 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
45890 index e5b7731..b9c59fb 100644
45891 --- a/fs/ceph/dir.c
45892 +++ b/fs/ceph/dir.c
45893 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
45894 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
45895 struct ceph_mds_client *mdsc = fsc->mdsc;
45896 unsigned frag = fpos_frag(filp->f_pos);
45897 - int off = fpos_off(filp->f_pos);
45898 + unsigned int off = fpos_off(filp->f_pos);
45899 int err;
45900 u32 ftype;
45901 struct ceph_mds_reply_info_parsed *rinfo;
45902 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
45903 index d9ea6ed..1e6c8ac 100644
45904 --- a/fs/cifs/cifs_debug.c
45905 +++ b/fs/cifs/cifs_debug.c
45906 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45907
45908 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
45909 #ifdef CONFIG_CIFS_STATS2
45910 - atomic_set(&totBufAllocCount, 0);
45911 - atomic_set(&totSmBufAllocCount, 0);
45912 + atomic_set_unchecked(&totBufAllocCount, 0);
45913 + atomic_set_unchecked(&totSmBufAllocCount, 0);
45914 #endif /* CONFIG_CIFS_STATS2 */
45915 spin_lock(&cifs_tcp_ses_lock);
45916 list_for_each(tmp1, &cifs_tcp_ses_list) {
45917 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45918 tcon = list_entry(tmp3,
45919 struct cifs_tcon,
45920 tcon_list);
45921 - atomic_set(&tcon->num_smbs_sent, 0);
45922 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
45923 if (server->ops->clear_stats)
45924 server->ops->clear_stats(tcon);
45925 }
45926 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45927 smBufAllocCount.counter, cifs_min_small);
45928 #ifdef CONFIG_CIFS_STATS2
45929 seq_printf(m, "Total Large %d Small %d Allocations\n",
45930 - atomic_read(&totBufAllocCount),
45931 - atomic_read(&totSmBufAllocCount));
45932 + atomic_read_unchecked(&totBufAllocCount),
45933 + atomic_read_unchecked(&totSmBufAllocCount));
45934 #endif /* CONFIG_CIFS_STATS2 */
45935
45936 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
45937 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45938 if (tcon->need_reconnect)
45939 seq_puts(m, "\tDISCONNECTED ");
45940 seq_printf(m, "\nSMBs: %d",
45941 - atomic_read(&tcon->num_smbs_sent));
45942 + atomic_read_unchecked(&tcon->num_smbs_sent));
45943 if (server->ops->print_stats)
45944 server->ops->print_stats(m, tcon);
45945 }
45946 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
45947 index e7931cc..76a1ab9 100644
45948 --- a/fs/cifs/cifsfs.c
45949 +++ b/fs/cifs/cifsfs.c
45950 @@ -999,7 +999,7 @@ cifs_init_request_bufs(void)
45951 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
45952 cifs_req_cachep = kmem_cache_create("cifs_request",
45953 CIFSMaxBufSize + max_hdr_size, 0,
45954 - SLAB_HWCACHE_ALIGN, NULL);
45955 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
45956 if (cifs_req_cachep == NULL)
45957 return -ENOMEM;
45958
45959 @@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
45960 efficient to alloc 1 per page off the slab compared to 17K (5page)
45961 alloc of large cifs buffers even when page debugging is on */
45962 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
45963 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
45964 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
45965 NULL);
45966 if (cifs_sm_req_cachep == NULL) {
45967 mempool_destroy(cifs_req_poolp);
45968 @@ -1111,8 +1111,8 @@ init_cifs(void)
45969 atomic_set(&bufAllocCount, 0);
45970 atomic_set(&smBufAllocCount, 0);
45971 #ifdef CONFIG_CIFS_STATS2
45972 - atomic_set(&totBufAllocCount, 0);
45973 - atomic_set(&totSmBufAllocCount, 0);
45974 + atomic_set_unchecked(&totBufAllocCount, 0);
45975 + atomic_set_unchecked(&totSmBufAllocCount, 0);
45976 #endif /* CONFIG_CIFS_STATS2 */
45977
45978 atomic_set(&midCount, 0);
45979 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
45980 index f5af252..489b5f2 100644
45981 --- a/fs/cifs/cifsglob.h
45982 +++ b/fs/cifs/cifsglob.h
45983 @@ -751,35 +751,35 @@ struct cifs_tcon {
45984 __u16 Flags; /* optional support bits */
45985 enum statusEnum tidStatus;
45986 #ifdef CONFIG_CIFS_STATS
45987 - atomic_t num_smbs_sent;
45988 + atomic_unchecked_t num_smbs_sent;
45989 union {
45990 struct {
45991 - atomic_t num_writes;
45992 - atomic_t num_reads;
45993 - atomic_t num_flushes;
45994 - atomic_t num_oplock_brks;
45995 - atomic_t num_opens;
45996 - atomic_t num_closes;
45997 - atomic_t num_deletes;
45998 - atomic_t num_mkdirs;
45999 - atomic_t num_posixopens;
46000 - atomic_t num_posixmkdirs;
46001 - atomic_t num_rmdirs;
46002 - atomic_t num_renames;
46003 - atomic_t num_t2renames;
46004 - atomic_t num_ffirst;
46005 - atomic_t num_fnext;
46006 - atomic_t num_fclose;
46007 - atomic_t num_hardlinks;
46008 - atomic_t num_symlinks;
46009 - atomic_t num_locks;
46010 - atomic_t num_acl_get;
46011 - atomic_t num_acl_set;
46012 + atomic_unchecked_t num_writes;
46013 + atomic_unchecked_t num_reads;
46014 + atomic_unchecked_t num_flushes;
46015 + atomic_unchecked_t num_oplock_brks;
46016 + atomic_unchecked_t num_opens;
46017 + atomic_unchecked_t num_closes;
46018 + atomic_unchecked_t num_deletes;
46019 + atomic_unchecked_t num_mkdirs;
46020 + atomic_unchecked_t num_posixopens;
46021 + atomic_unchecked_t num_posixmkdirs;
46022 + atomic_unchecked_t num_rmdirs;
46023 + atomic_unchecked_t num_renames;
46024 + atomic_unchecked_t num_t2renames;
46025 + atomic_unchecked_t num_ffirst;
46026 + atomic_unchecked_t num_fnext;
46027 + atomic_unchecked_t num_fclose;
46028 + atomic_unchecked_t num_hardlinks;
46029 + atomic_unchecked_t num_symlinks;
46030 + atomic_unchecked_t num_locks;
46031 + atomic_unchecked_t num_acl_get;
46032 + atomic_unchecked_t num_acl_set;
46033 } cifs_stats;
46034 #ifdef CONFIG_CIFS_SMB2
46035 struct {
46036 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
46037 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
46038 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
46039 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
46040 } smb2_stats;
46041 #endif /* CONFIG_CIFS_SMB2 */
46042 } stats;
46043 @@ -1094,7 +1094,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
46044 }
46045
46046 #ifdef CONFIG_CIFS_STATS
46047 -#define cifs_stats_inc atomic_inc
46048 +#define cifs_stats_inc atomic_inc_unchecked
46049
46050 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
46051 unsigned int bytes)
46052 @@ -1459,8 +1459,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
46053 /* Various Debug counters */
46054 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
46055 #ifdef CONFIG_CIFS_STATS2
46056 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
46057 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
46058 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
46059 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
46060 #endif
46061 GLOBAL_EXTERN atomic_t smBufAllocCount;
46062 GLOBAL_EXTERN atomic_t midCount;
46063 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
46064 index 51dc2fb..1e12a33 100644
46065 --- a/fs/cifs/link.c
46066 +++ b/fs/cifs/link.c
46067 @@ -616,7 +616,7 @@ symlink_exit:
46068
46069 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
46070 {
46071 - char *p = nd_get_link(nd);
46072 + const char *p = nd_get_link(nd);
46073 if (!IS_ERR(p))
46074 kfree(p);
46075 }
46076 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
46077 index 3a00c0d..42d901c 100644
46078 --- a/fs/cifs/misc.c
46079 +++ b/fs/cifs/misc.c
46080 @@ -169,7 +169,7 @@ cifs_buf_get(void)
46081 memset(ret_buf, 0, buf_size + 3);
46082 atomic_inc(&bufAllocCount);
46083 #ifdef CONFIG_CIFS_STATS2
46084 - atomic_inc(&totBufAllocCount);
46085 + atomic_inc_unchecked(&totBufAllocCount);
46086 #endif /* CONFIG_CIFS_STATS2 */
46087 }
46088
46089 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
46090 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
46091 atomic_inc(&smBufAllocCount);
46092 #ifdef CONFIG_CIFS_STATS2
46093 - atomic_inc(&totSmBufAllocCount);
46094 + atomic_inc_unchecked(&totSmBufAllocCount);
46095 #endif /* CONFIG_CIFS_STATS2 */
46096
46097 }
46098 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
46099 index 591bf19..690d600 100644
46100 --- a/fs/cifs/smb1ops.c
46101 +++ b/fs/cifs/smb1ops.c
46102 @@ -617,27 +617,27 @@ static void
46103 cifs_clear_stats(struct cifs_tcon *tcon)
46104 {
46105 #ifdef CONFIG_CIFS_STATS
46106 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
46107 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
46108 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
46109 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46110 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
46111 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
46112 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46113 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
46114 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
46115 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
46116 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
46117 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
46118 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
46119 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
46120 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
46121 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
46122 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
46123 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
46124 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
46125 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
46126 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
46127 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
46128 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
46129 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
46130 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46131 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
46132 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
46133 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46134 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
46135 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
46136 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
46137 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
46138 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
46139 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
46140 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
46141 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
46142 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
46143 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
46144 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
46145 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
46146 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
46147 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
46148 #endif
46149 }
46150
46151 @@ -646,36 +646,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46152 {
46153 #ifdef CONFIG_CIFS_STATS
46154 seq_printf(m, " Oplocks breaks: %d",
46155 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
46156 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
46157 seq_printf(m, "\nReads: %d Bytes: %llu",
46158 - atomic_read(&tcon->stats.cifs_stats.num_reads),
46159 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
46160 (long long)(tcon->bytes_read));
46161 seq_printf(m, "\nWrites: %d Bytes: %llu",
46162 - atomic_read(&tcon->stats.cifs_stats.num_writes),
46163 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
46164 (long long)(tcon->bytes_written));
46165 seq_printf(m, "\nFlushes: %d",
46166 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
46167 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
46168 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
46169 - atomic_read(&tcon->stats.cifs_stats.num_locks),
46170 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
46171 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
46172 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
46173 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
46174 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
46175 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
46176 - atomic_read(&tcon->stats.cifs_stats.num_opens),
46177 - atomic_read(&tcon->stats.cifs_stats.num_closes),
46178 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
46179 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
46180 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
46181 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
46182 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
46183 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
46184 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
46185 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
46186 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
46187 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
46188 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
46189 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
46190 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
46191 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
46192 seq_printf(m, "\nRenames: %d T2 Renames %d",
46193 - atomic_read(&tcon->stats.cifs_stats.num_renames),
46194 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
46195 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
46196 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
46197 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
46198 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
46199 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
46200 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
46201 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
46202 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
46203 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
46204 #endif
46205 }
46206
46207 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
46208 index 4d9dbe0..0af4601 100644
46209 --- a/fs/cifs/smb2ops.c
46210 +++ b/fs/cifs/smb2ops.c
46211 @@ -291,8 +291,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
46212 #ifdef CONFIG_CIFS_STATS
46213 int i;
46214 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
46215 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46216 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46217 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46218 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46219 }
46220 #endif
46221 }
46222 @@ -301,66 +301,66 @@ static void
46223 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46224 {
46225 #ifdef CONFIG_CIFS_STATS
46226 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46227 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46228 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46229 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46230 seq_printf(m, "\nNegotiates: %d sent %d failed",
46231 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
46232 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
46233 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
46234 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
46235 seq_printf(m, "\nSessionSetups: %d sent %d failed",
46236 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
46237 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
46238 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
46239 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
46240 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
46241 seq_printf(m, "\nLogoffs: %d sent %d failed",
46242 - atomic_read(&sent[SMB2_LOGOFF_HE]),
46243 - atomic_read(&failed[SMB2_LOGOFF_HE]));
46244 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
46245 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
46246 seq_printf(m, "\nTreeConnects: %d sent %d failed",
46247 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
46248 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
46249 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
46250 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
46251 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
46252 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
46253 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
46254 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
46255 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
46256 seq_printf(m, "\nCreates: %d sent %d failed",
46257 - atomic_read(&sent[SMB2_CREATE_HE]),
46258 - atomic_read(&failed[SMB2_CREATE_HE]));
46259 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
46260 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
46261 seq_printf(m, "\nCloses: %d sent %d failed",
46262 - atomic_read(&sent[SMB2_CLOSE_HE]),
46263 - atomic_read(&failed[SMB2_CLOSE_HE]));
46264 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
46265 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
46266 seq_printf(m, "\nFlushes: %d sent %d failed",
46267 - atomic_read(&sent[SMB2_FLUSH_HE]),
46268 - atomic_read(&failed[SMB2_FLUSH_HE]));
46269 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
46270 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
46271 seq_printf(m, "\nReads: %d sent %d failed",
46272 - atomic_read(&sent[SMB2_READ_HE]),
46273 - atomic_read(&failed[SMB2_READ_HE]));
46274 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
46275 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
46276 seq_printf(m, "\nWrites: %d sent %d failed",
46277 - atomic_read(&sent[SMB2_WRITE_HE]),
46278 - atomic_read(&failed[SMB2_WRITE_HE]));
46279 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
46280 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
46281 seq_printf(m, "\nLocks: %d sent %d failed",
46282 - atomic_read(&sent[SMB2_LOCK_HE]),
46283 - atomic_read(&failed[SMB2_LOCK_HE]));
46284 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
46285 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
46286 seq_printf(m, "\nIOCTLs: %d sent %d failed",
46287 - atomic_read(&sent[SMB2_IOCTL_HE]),
46288 - atomic_read(&failed[SMB2_IOCTL_HE]));
46289 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
46290 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
46291 seq_printf(m, "\nCancels: %d sent %d failed",
46292 - atomic_read(&sent[SMB2_CANCEL_HE]),
46293 - atomic_read(&failed[SMB2_CANCEL_HE]));
46294 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
46295 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
46296 seq_printf(m, "\nEchos: %d sent %d failed",
46297 - atomic_read(&sent[SMB2_ECHO_HE]),
46298 - atomic_read(&failed[SMB2_ECHO_HE]));
46299 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
46300 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
46301 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
46302 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
46303 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
46304 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
46305 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
46306 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
46307 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
46308 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
46309 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
46310 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
46311 seq_printf(m, "\nQueryInfos: %d sent %d failed",
46312 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
46313 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
46314 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
46315 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
46316 seq_printf(m, "\nSetInfos: %d sent %d failed",
46317 - atomic_read(&sent[SMB2_SET_INFO_HE]),
46318 - atomic_read(&failed[SMB2_SET_INFO_HE]));
46319 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
46320 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
46321 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
46322 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
46323 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
46324 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
46325 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
46326 #endif
46327 }
46328
46329 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
46330 index 958ae0e..505c9d0 100644
46331 --- a/fs/coda/cache.c
46332 +++ b/fs/coda/cache.c
46333 @@ -24,7 +24,7 @@
46334 #include "coda_linux.h"
46335 #include "coda_cache.h"
46336
46337 -static atomic_t permission_epoch = ATOMIC_INIT(0);
46338 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
46339
46340 /* replace or extend an acl cache hit */
46341 void coda_cache_enter(struct inode *inode, int mask)
46342 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
46343 struct coda_inode_info *cii = ITOC(inode);
46344
46345 spin_lock(&cii->c_lock);
46346 - cii->c_cached_epoch = atomic_read(&permission_epoch);
46347 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
46348 if (cii->c_uid != current_fsuid()) {
46349 cii->c_uid = current_fsuid();
46350 cii->c_cached_perm = mask;
46351 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
46352 {
46353 struct coda_inode_info *cii = ITOC(inode);
46354 spin_lock(&cii->c_lock);
46355 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
46356 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
46357 spin_unlock(&cii->c_lock);
46358 }
46359
46360 /* remove all acl caches */
46361 void coda_cache_clear_all(struct super_block *sb)
46362 {
46363 - atomic_inc(&permission_epoch);
46364 + atomic_inc_unchecked(&permission_epoch);
46365 }
46366
46367
46368 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
46369 spin_lock(&cii->c_lock);
46370 hit = (mask & cii->c_cached_perm) == mask &&
46371 cii->c_uid == current_fsuid() &&
46372 - cii->c_cached_epoch == atomic_read(&permission_epoch);
46373 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
46374 spin_unlock(&cii->c_lock);
46375
46376 return hit;
46377 diff --git a/fs/compat.c b/fs/compat.c
46378 index 015e1e1..5ce8e54 100644
46379 --- a/fs/compat.c
46380 +++ b/fs/compat.c
46381 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
46382
46383 set_fs(KERNEL_DS);
46384 /* The __user pointer cast is valid because of the set_fs() */
46385 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
46386 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
46387 set_fs(oldfs);
46388 /* truncating is ok because it's a user address */
46389 if (!ret)
46390 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
46391 goto out;
46392
46393 ret = -EINVAL;
46394 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
46395 + if (nr_segs > UIO_MAXIOV)
46396 goto out;
46397 if (nr_segs > fast_segs) {
46398 ret = -ENOMEM;
46399 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
46400
46401 struct compat_readdir_callback {
46402 struct compat_old_linux_dirent __user *dirent;
46403 + struct file * file;
46404 int result;
46405 };
46406
46407 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
46408 buf->result = -EOVERFLOW;
46409 return -EOVERFLOW;
46410 }
46411 +
46412 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46413 + return 0;
46414 +
46415 buf->result++;
46416 dirent = buf->dirent;
46417 if (!access_ok(VERIFY_WRITE, dirent,
46418 @@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
46419
46420 buf.result = 0;
46421 buf.dirent = dirent;
46422 + buf.file = f.file;
46423
46424 error = vfs_readdir(f.file, compat_fillonedir, &buf);
46425 if (buf.result)
46426 @@ -897,6 +903,7 @@ struct compat_linux_dirent {
46427 struct compat_getdents_callback {
46428 struct compat_linux_dirent __user *current_dir;
46429 struct compat_linux_dirent __user *previous;
46430 + struct file * file;
46431 int count;
46432 int error;
46433 };
46434 @@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
46435 buf->error = -EOVERFLOW;
46436 return -EOVERFLOW;
46437 }
46438 +
46439 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46440 + return 0;
46441 +
46442 dirent = buf->previous;
46443 if (dirent) {
46444 if (__put_user(offset, &dirent->d_off))
46445 @@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
46446 buf.previous = NULL;
46447 buf.count = count;
46448 buf.error = 0;
46449 + buf.file = f.file;
46450
46451 error = vfs_readdir(f.file, compat_filldir, &buf);
46452 if (error >= 0)
46453 @@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
46454 struct compat_getdents_callback64 {
46455 struct linux_dirent64 __user *current_dir;
46456 struct linux_dirent64 __user *previous;
46457 + struct file * file;
46458 int count;
46459 int error;
46460 };
46461 @@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
46462 buf->error = -EINVAL; /* only used if we fail.. */
46463 if (reclen > buf->count)
46464 return -EINVAL;
46465 +
46466 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46467 + return 0;
46468 +
46469 dirent = buf->previous;
46470
46471 if (dirent) {
46472 @@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
46473 buf.previous = NULL;
46474 buf.count = count;
46475 buf.error = 0;
46476 + buf.file = f.file;
46477
46478 error = vfs_readdir(f.file, compat_filldir64, &buf);
46479 if (error >= 0)
46480 error = buf.error;
46481 lastdirent = buf.previous;
46482 if (lastdirent) {
46483 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
46484 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
46485 if (__put_user_unaligned(d_off, &lastdirent->d_off))
46486 error = -EFAULT;
46487 else
46488 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
46489 index a81147e..20bf2b5 100644
46490 --- a/fs/compat_binfmt_elf.c
46491 +++ b/fs/compat_binfmt_elf.c
46492 @@ -30,11 +30,13 @@
46493 #undef elf_phdr
46494 #undef elf_shdr
46495 #undef elf_note
46496 +#undef elf_dyn
46497 #undef elf_addr_t
46498 #define elfhdr elf32_hdr
46499 #define elf_phdr elf32_phdr
46500 #define elf_shdr elf32_shdr
46501 #define elf_note elf32_note
46502 +#define elf_dyn Elf32_Dyn
46503 #define elf_addr_t Elf32_Addr
46504
46505 /*
46506 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
46507 index 4c6285f..b7a2411 100644
46508 --- a/fs/compat_ioctl.c
46509 +++ b/fs/compat_ioctl.c
46510 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
46511 return -EFAULT;
46512 if (__get_user(udata, &ss32->iomem_base))
46513 return -EFAULT;
46514 - ss.iomem_base = compat_ptr(udata);
46515 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
46516 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
46517 __get_user(ss.port_high, &ss32->port_high))
46518 return -EFAULT;
46519 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
46520 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
46521 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
46522 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
46523 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46524 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46525 return -EFAULT;
46526
46527 return ioctl_preallocate(file, p);
46528 @@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
46529 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
46530 {
46531 unsigned int a, b;
46532 - a = *(unsigned int *)p;
46533 - b = *(unsigned int *)q;
46534 + a = *(const unsigned int *)p;
46535 + b = *(const unsigned int *)q;
46536 if (a > b)
46537 return 1;
46538 if (a < b)
46539 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
46540 index 7414ae2..d98ad6d 100644
46541 --- a/fs/configfs/dir.c
46542 +++ b/fs/configfs/dir.c
46543 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46544 }
46545 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
46546 struct configfs_dirent *next;
46547 - const char * name;
46548 + const unsigned char * name;
46549 + char d_name[sizeof(next->s_dentry->d_iname)];
46550 int len;
46551 struct inode *inode = NULL;
46552
46553 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46554 continue;
46555
46556 name = configfs_get_name(next);
46557 - len = strlen(name);
46558 + if (next->s_dentry && name == next->s_dentry->d_iname) {
46559 + len = next->s_dentry->d_name.len;
46560 + memcpy(d_name, name, len);
46561 + name = d_name;
46562 + } else
46563 + len = strlen(name);
46564
46565 /*
46566 * We'll have a dentry and an inode for
46567 diff --git a/fs/coredump.c b/fs/coredump.c
46568 index ce47379..68c8e43 100644
46569 --- a/fs/coredump.c
46570 +++ b/fs/coredump.c
46571 @@ -52,7 +52,7 @@ struct core_name {
46572 char *corename;
46573 int used, size;
46574 };
46575 -static atomic_t call_count = ATOMIC_INIT(1);
46576 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
46577
46578 /* The maximal length of core_pattern is also specified in sysctl.c */
46579
46580 @@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
46581 {
46582 char *old_corename = cn->corename;
46583
46584 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
46585 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
46586 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
46587
46588 if (!cn->corename) {
46589 @@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
46590 int pid_in_pattern = 0;
46591 int err = 0;
46592
46593 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
46594 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
46595 cn->corename = kmalloc(cn->size, GFP_KERNEL);
46596 cn->used = 0;
46597
46598 @@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
46599 pipe = file->f_path.dentry->d_inode->i_pipe;
46600
46601 pipe_lock(pipe);
46602 - pipe->readers++;
46603 - pipe->writers--;
46604 + atomic_inc(&pipe->readers);
46605 + atomic_dec(&pipe->writers);
46606
46607 - while ((pipe->readers > 1) && (!signal_pending(current))) {
46608 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
46609 wake_up_interruptible_sync(&pipe->wait);
46610 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
46611 pipe_wait(pipe);
46612 }
46613
46614 - pipe->readers--;
46615 - pipe->writers++;
46616 + atomic_dec(&pipe->readers);
46617 + atomic_inc(&pipe->writers);
46618 pipe_unlock(pipe);
46619
46620 }
46621 @@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46622 int ispipe;
46623 struct files_struct *displaced;
46624 bool need_nonrelative = false;
46625 - static atomic_t core_dump_count = ATOMIC_INIT(0);
46626 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
46627 + long signr = siginfo->si_signo;
46628 struct coredump_params cprm = {
46629 .siginfo = siginfo,
46630 .regs = regs,
46631 @@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46632 .mm_flags = mm->flags,
46633 };
46634
46635 - audit_core_dumps(siginfo->si_signo);
46636 + audit_core_dumps(signr);
46637 +
46638 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
46639 + gr_handle_brute_attach(cprm.mm_flags);
46640
46641 binfmt = mm->binfmt;
46642 if (!binfmt || !binfmt->core_dump)
46643 @@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46644 need_nonrelative = true;
46645 }
46646
46647 - retval = coredump_wait(siginfo->si_signo, &core_state);
46648 + retval = coredump_wait(signr, &core_state);
46649 if (retval < 0)
46650 goto fail_creds;
46651
46652 @@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46653 }
46654 cprm.limit = RLIM_INFINITY;
46655
46656 - dump_count = atomic_inc_return(&core_dump_count);
46657 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
46658 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
46659 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
46660 task_tgid_vnr(current), current->comm);
46661 @@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46662 } else {
46663 struct inode *inode;
46664
46665 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
46666 +
46667 if (cprm.limit < binfmt->min_coredump)
46668 goto fail_unlock;
46669
46670 @@ -640,7 +646,7 @@ close_fail:
46671 filp_close(cprm.file, NULL);
46672 fail_dropcount:
46673 if (ispipe)
46674 - atomic_dec(&core_dump_count);
46675 + atomic_dec_unchecked(&core_dump_count);
46676 fail_unlock:
46677 kfree(cn.corename);
46678 fail_corename:
46679 @@ -659,7 +665,7 @@ fail:
46680 */
46681 int dump_write(struct file *file, const void *addr, int nr)
46682 {
46683 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
46684 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
46685 }
46686 EXPORT_SYMBOL(dump_write);
46687
46688 diff --git a/fs/dcache.c b/fs/dcache.c
46689 index 0d0adb6..f4646e9 100644
46690 --- a/fs/dcache.c
46691 +++ b/fs/dcache.c
46692 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
46693 mempages -= reserve;
46694
46695 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
46696 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
46697 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
46698
46699 dcache_init();
46700 inode_init();
46701 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
46702 index b607d92..41fda09 100644
46703 --- a/fs/debugfs/inode.c
46704 +++ b/fs/debugfs/inode.c
46705 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
46706 */
46707 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
46708 {
46709 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
46710 + return __create_file(name, S_IFDIR | S_IRWXU,
46711 +#else
46712 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
46713 +#endif
46714 parent, NULL, NULL);
46715 }
46716 EXPORT_SYMBOL_GPL(debugfs_create_dir);
46717 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
46718 index cc7709e..7e7211f 100644
46719 --- a/fs/ecryptfs/inode.c
46720 +++ b/fs/ecryptfs/inode.c
46721 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
46722 old_fs = get_fs();
46723 set_fs(get_ds());
46724 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
46725 - (char __user *)lower_buf,
46726 + (char __force_user *)lower_buf,
46727 PATH_MAX);
46728 set_fs(old_fs);
46729 if (rc < 0)
46730 @@ -706,7 +706,7 @@ out:
46731 static void
46732 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
46733 {
46734 - char *buf = nd_get_link(nd);
46735 + const char *buf = nd_get_link(nd);
46736 if (!IS_ERR(buf)) {
46737 /* Free the char* */
46738 kfree(buf);
46739 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
46740 index 412e6ed..4292d22 100644
46741 --- a/fs/ecryptfs/miscdev.c
46742 +++ b/fs/ecryptfs/miscdev.c
46743 @@ -315,7 +315,7 @@ check_list:
46744 goto out_unlock_msg_ctx;
46745 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
46746 if (msg_ctx->msg) {
46747 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
46748 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
46749 goto out_unlock_msg_ctx;
46750 i += packet_length_size;
46751 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
46752 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
46753 index b2a34a1..162fa69 100644
46754 --- a/fs/ecryptfs/read_write.c
46755 +++ b/fs/ecryptfs/read_write.c
46756 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
46757 return -EIO;
46758 fs_save = get_fs();
46759 set_fs(get_ds());
46760 - rc = vfs_write(lower_file, data, size, &offset);
46761 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
46762 set_fs(fs_save);
46763 mark_inode_dirty_sync(ecryptfs_inode);
46764 return rc;
46765 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
46766 return -EIO;
46767 fs_save = get_fs();
46768 set_fs(get_ds());
46769 - rc = vfs_read(lower_file, data, size, &offset);
46770 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
46771 set_fs(fs_save);
46772 return rc;
46773 }
46774 diff --git a/fs/exec.c b/fs/exec.c
46775 index c6e6de4..45e71ad 100644
46776 --- a/fs/exec.c
46777 +++ b/fs/exec.c
46778 @@ -55,6 +55,17 @@
46779 #include <linux/pipe_fs_i.h>
46780 #include <linux/oom.h>
46781 #include <linux/compat.h>
46782 +#include <linux/random.h>
46783 +#include <linux/seq_file.h>
46784 +#include <linux/coredump.h>
46785 +#include <linux/mman.h>
46786 +
46787 +#ifdef CONFIG_PAX_REFCOUNT
46788 +#include <linux/kallsyms.h>
46789 +#include <linux/kdebug.h>
46790 +#endif
46791 +
46792 +#include <trace/events/fs.h>
46793
46794 #include <asm/uaccess.h>
46795 #include <asm/mmu_context.h>
46796 @@ -66,6 +77,18 @@
46797
46798 #include <trace/events/sched.h>
46799
46800 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
46801 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
46802 +{
46803 + 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");
46804 +}
46805 +#endif
46806 +
46807 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
46808 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
46809 +EXPORT_SYMBOL(pax_set_initial_flags_func);
46810 +#endif
46811 +
46812 int suid_dumpable = 0;
46813
46814 static LIST_HEAD(formats);
46815 @@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46816 int write)
46817 {
46818 struct page *page;
46819 - int ret;
46820
46821 -#ifdef CONFIG_STACK_GROWSUP
46822 - if (write) {
46823 - ret = expand_downwards(bprm->vma, pos);
46824 - if (ret < 0)
46825 - return NULL;
46826 - }
46827 -#endif
46828 - ret = get_user_pages(current, bprm->mm, pos,
46829 - 1, write, 1, &page, NULL);
46830 - if (ret <= 0)
46831 + if (0 > expand_downwards(bprm->vma, pos))
46832 + return NULL;
46833 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
46834 return NULL;
46835
46836 if (write) {
46837 @@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46838 if (size <= ARG_MAX)
46839 return page;
46840
46841 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46842 + // only allow 512KB for argv+env on suid/sgid binaries
46843 + // to prevent easy ASLR exhaustion
46844 + if (((bprm->cred->euid != current_euid()) ||
46845 + (bprm->cred->egid != current_egid())) &&
46846 + (size > (512 * 1024))) {
46847 + put_page(page);
46848 + return NULL;
46849 + }
46850 +#endif
46851 +
46852 /*
46853 * Limit to 1/4-th the stack size for the argv+env strings.
46854 * This ensures that:
46855 @@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46856 vma->vm_end = STACK_TOP_MAX;
46857 vma->vm_start = vma->vm_end - PAGE_SIZE;
46858 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
46859 +
46860 +#ifdef CONFIG_PAX_SEGMEXEC
46861 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
46862 +#endif
46863 +
46864 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
46865 INIT_LIST_HEAD(&vma->anon_vma_chain);
46866
46867 @@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46868 mm->stack_vm = mm->total_vm = 1;
46869 up_write(&mm->mmap_sem);
46870 bprm->p = vma->vm_end - sizeof(void *);
46871 +
46872 +#ifdef CONFIG_PAX_RANDUSTACK
46873 + if (randomize_va_space)
46874 + bprm->p ^= random32() & ~PAGE_MASK;
46875 +#endif
46876 +
46877 return 0;
46878 err:
46879 up_write(&mm->mmap_sem);
46880 @@ -384,19 +421,7 @@ err:
46881 return err;
46882 }
46883
46884 -struct user_arg_ptr {
46885 -#ifdef CONFIG_COMPAT
46886 - bool is_compat;
46887 -#endif
46888 - union {
46889 - const char __user *const __user *native;
46890 -#ifdef CONFIG_COMPAT
46891 - const compat_uptr_t __user *compat;
46892 -#endif
46893 - } ptr;
46894 -};
46895 -
46896 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46897 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46898 {
46899 const char __user *native;
46900
46901 @@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46902 compat_uptr_t compat;
46903
46904 if (get_user(compat, argv.ptr.compat + nr))
46905 - return ERR_PTR(-EFAULT);
46906 + return (const char __force_user *)ERR_PTR(-EFAULT);
46907
46908 return compat_ptr(compat);
46909 }
46910 #endif
46911
46912 if (get_user(native, argv.ptr.native + nr))
46913 - return ERR_PTR(-EFAULT);
46914 + return (const char __force_user *)ERR_PTR(-EFAULT);
46915
46916 return native;
46917 }
46918 @@ -431,11 +456,12 @@ static int count(struct user_arg_ptr argv, int max)
46919 if (!p)
46920 break;
46921
46922 - if (IS_ERR(p))
46923 + if (IS_ERR((const char __force_kernel *)p))
46924 return -EFAULT;
46925
46926 - if (i++ >= max)
46927 + if (i >= max)
46928 return -E2BIG;
46929 + ++i;
46930
46931 if (fatal_signal_pending(current))
46932 return -ERESTARTNOHAND;
46933 @@ -465,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
46934
46935 ret = -EFAULT;
46936 str = get_user_arg_ptr(argv, argc);
46937 - if (IS_ERR(str))
46938 + if (IS_ERR((const char __force_kernel *)str))
46939 goto out;
46940
46941 len = strnlen_user(str, MAX_ARG_STRLEN);
46942 @@ -547,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
46943 int r;
46944 mm_segment_t oldfs = get_fs();
46945 struct user_arg_ptr argv = {
46946 - .ptr.native = (const char __user *const __user *)__argv,
46947 + .ptr.native = (const char __force_user *const __force_user *)__argv,
46948 };
46949
46950 set_fs(KERNEL_DS);
46951 @@ -582,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46952 unsigned long new_end = old_end - shift;
46953 struct mmu_gather tlb;
46954
46955 - BUG_ON(new_start > new_end);
46956 + if (new_start >= new_end || new_start < mmap_min_addr)
46957 + return -ENOMEM;
46958
46959 /*
46960 * ensure there are no vmas between where we want to go
46961 @@ -591,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46962 if (vma != find_vma(mm, new_start))
46963 return -EFAULT;
46964
46965 +#ifdef CONFIG_PAX_SEGMEXEC
46966 + BUG_ON(pax_find_mirror_vma(vma));
46967 +#endif
46968 +
46969 /*
46970 * cover the whole range: [new_start, old_end)
46971 */
46972 @@ -671,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46973 stack_top = arch_align_stack(stack_top);
46974 stack_top = PAGE_ALIGN(stack_top);
46975
46976 - if (unlikely(stack_top < mmap_min_addr) ||
46977 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
46978 - return -ENOMEM;
46979 -
46980 stack_shift = vma->vm_end - stack_top;
46981
46982 bprm->p -= stack_shift;
46983 @@ -686,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
46984 bprm->exec -= stack_shift;
46985
46986 down_write(&mm->mmap_sem);
46987 +
46988 + /* Move stack pages down in memory. */
46989 + if (stack_shift) {
46990 + ret = shift_arg_pages(vma, stack_shift);
46991 + if (ret)
46992 + goto out_unlock;
46993 + }
46994 +
46995 vm_flags = VM_STACK_FLAGS;
46996
46997 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46998 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46999 + vm_flags &= ~VM_EXEC;
47000 +
47001 +#ifdef CONFIG_PAX_MPROTECT
47002 + if (mm->pax_flags & MF_PAX_MPROTECT)
47003 + vm_flags &= ~VM_MAYEXEC;
47004 +#endif
47005 +
47006 + }
47007 +#endif
47008 +
47009 /*
47010 * Adjust stack execute permissions; explicitly enable for
47011 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
47012 @@ -706,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
47013 goto out_unlock;
47014 BUG_ON(prev != vma);
47015
47016 - /* Move stack pages down in memory. */
47017 - if (stack_shift) {
47018 - ret = shift_arg_pages(vma, stack_shift);
47019 - if (ret)
47020 - goto out_unlock;
47021 - }
47022 -
47023 /* mprotect_fixup is overkill to remove the temporary stack flags */
47024 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
47025
47026 @@ -736,6 +776,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
47027 #endif
47028 current->mm->start_stack = bprm->p;
47029 ret = expand_stack(vma, stack_base);
47030 +
47031 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
47032 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
47033 + unsigned long size, flags, vm_flags;
47034 +
47035 + size = STACK_TOP - vma->vm_end;
47036 + flags = MAP_FIXED | MAP_PRIVATE;
47037 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
47038 +
47039 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
47040 +
47041 +#ifdef CONFIG_X86
47042 + if (!ret) {
47043 + size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
47044 + ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
47045 + }
47046 +#endif
47047 +
47048 + }
47049 +#endif
47050 +
47051 if (ret)
47052 ret = -EFAULT;
47053
47054 @@ -771,6 +832,8 @@ struct file *open_exec(const char *name)
47055
47056 fsnotify_open(file);
47057
47058 + trace_open_exec(name);
47059 +
47060 err = deny_write_access(file);
47061 if (err)
47062 goto exit;
47063 @@ -794,7 +857,7 @@ int kernel_read(struct file *file, loff_t offset,
47064 old_fs = get_fs();
47065 set_fs(get_ds());
47066 /* The cast to a user pointer is valid due to the set_fs() */
47067 - result = vfs_read(file, (void __user *)addr, count, &pos);
47068 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
47069 set_fs(old_fs);
47070 return result;
47071 }
47072 @@ -1246,7 +1309,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
47073 }
47074 rcu_read_unlock();
47075
47076 - if (p->fs->users > n_fs) {
47077 + if (atomic_read(&p->fs->users) > n_fs) {
47078 bprm->unsafe |= LSM_UNSAFE_SHARE;
47079 } else {
47080 res = -EAGAIN;
47081 @@ -1449,6 +1512,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
47082
47083 EXPORT_SYMBOL(search_binary_handler);
47084
47085 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47086 +static DEFINE_PER_CPU(u64, exec_counter);
47087 +static int __init init_exec_counters(void)
47088 +{
47089 + unsigned int cpu;
47090 +
47091 + for_each_possible_cpu(cpu) {
47092 + per_cpu(exec_counter, cpu) = (u64)cpu;
47093 + }
47094 +
47095 + return 0;
47096 +}
47097 +early_initcall(init_exec_counters);
47098 +static inline void increment_exec_counter(void)
47099 +{
47100 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
47101 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
47102 +}
47103 +#else
47104 +static inline void increment_exec_counter(void) {}
47105 +#endif
47106 +
47107 /*
47108 * sys_execve() executes a new program.
47109 */
47110 @@ -1457,6 +1542,11 @@ static int do_execve_common(const char *filename,
47111 struct user_arg_ptr envp,
47112 struct pt_regs *regs)
47113 {
47114 +#ifdef CONFIG_GRKERNSEC
47115 + struct file *old_exec_file;
47116 + struct acl_subject_label *old_acl;
47117 + struct rlimit old_rlim[RLIM_NLIMITS];
47118 +#endif
47119 struct linux_binprm *bprm;
47120 struct file *file;
47121 struct files_struct *displaced;
47122 @@ -1464,6 +1554,8 @@ static int do_execve_common(const char *filename,
47123 int retval;
47124 const struct cred *cred = current_cred();
47125
47126 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
47127 +
47128 /*
47129 * We move the actual failure in case of RLIMIT_NPROC excess from
47130 * set*uid() to execve() because too many poorly written programs
47131 @@ -1504,12 +1596,27 @@ static int do_execve_common(const char *filename,
47132 if (IS_ERR(file))
47133 goto out_unmark;
47134
47135 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
47136 + retval = -EPERM;
47137 + goto out_file;
47138 + }
47139 +
47140 sched_exec();
47141
47142 bprm->file = file;
47143 bprm->filename = filename;
47144 bprm->interp = filename;
47145
47146 + if (gr_process_user_ban()) {
47147 + retval = -EPERM;
47148 + goto out_file;
47149 + }
47150 +
47151 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
47152 + retval = -EACCES;
47153 + goto out_file;
47154 + }
47155 +
47156 retval = bprm_mm_init(bprm);
47157 if (retval)
47158 goto out_file;
47159 @@ -1526,24 +1633,65 @@ static int do_execve_common(const char *filename,
47160 if (retval < 0)
47161 goto out;
47162
47163 +#ifdef CONFIG_GRKERNSEC
47164 + old_acl = current->acl;
47165 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
47166 + old_exec_file = current->exec_file;
47167 + get_file(file);
47168 + current->exec_file = file;
47169 +#endif
47170 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47171 + /* limit suid stack to 8MB
47172 + we saved the old limits above and will restore them if this exec fails
47173 + */
47174 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
47175 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
47176 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
47177 +#endif
47178 +
47179 + if (!gr_tpe_allow(file)) {
47180 + retval = -EACCES;
47181 + goto out_fail;
47182 + }
47183 +
47184 + if (gr_check_crash_exec(file)) {
47185 + retval = -EACCES;
47186 + goto out_fail;
47187 + }
47188 +
47189 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
47190 + bprm->unsafe);
47191 + if (retval < 0)
47192 + goto out_fail;
47193 +
47194 retval = copy_strings_kernel(1, &bprm->filename, bprm);
47195 if (retval < 0)
47196 - goto out;
47197 + goto out_fail;
47198
47199 bprm->exec = bprm->p;
47200 retval = copy_strings(bprm->envc, envp, bprm);
47201 if (retval < 0)
47202 - goto out;
47203 + goto out_fail;
47204
47205 retval = copy_strings(bprm->argc, argv, bprm);
47206 if (retval < 0)
47207 - goto out;
47208 + goto out_fail;
47209 +
47210 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
47211 +
47212 + gr_handle_exec_args(bprm, argv);
47213
47214 retval = search_binary_handler(bprm,regs);
47215 if (retval < 0)
47216 - goto out;
47217 + goto out_fail;
47218 +#ifdef CONFIG_GRKERNSEC
47219 + if (old_exec_file)
47220 + fput(old_exec_file);
47221 +#endif
47222
47223 /* execve succeeded */
47224 +
47225 + increment_exec_counter();
47226 current->fs->in_exec = 0;
47227 current->in_execve = 0;
47228 acct_update_integrals(current);
47229 @@ -1552,6 +1700,14 @@ static int do_execve_common(const char *filename,
47230 put_files_struct(displaced);
47231 return retval;
47232
47233 +out_fail:
47234 +#ifdef CONFIG_GRKERNSEC
47235 + current->acl = old_acl;
47236 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
47237 + fput(current->exec_file);
47238 + current->exec_file = old_exec_file;
47239 +#endif
47240 +
47241 out:
47242 if (bprm->mm) {
47243 acct_arg_size(bprm, 0);
47244 @@ -1727,3 +1883,253 @@ int kernel_execve(const char *filename,
47245 ret_from_kernel_execve(p);
47246 }
47247 #endif
47248 +
47249 +int pax_check_flags(unsigned long *flags)
47250 +{
47251 + int retval = 0;
47252 +
47253 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
47254 + if (*flags & MF_PAX_SEGMEXEC)
47255 + {
47256 + *flags &= ~MF_PAX_SEGMEXEC;
47257 + retval = -EINVAL;
47258 + }
47259 +#endif
47260 +
47261 + if ((*flags & MF_PAX_PAGEEXEC)
47262 +
47263 +#ifdef CONFIG_PAX_PAGEEXEC
47264 + && (*flags & MF_PAX_SEGMEXEC)
47265 +#endif
47266 +
47267 + )
47268 + {
47269 + *flags &= ~MF_PAX_PAGEEXEC;
47270 + retval = -EINVAL;
47271 + }
47272 +
47273 + if ((*flags & MF_PAX_MPROTECT)
47274 +
47275 +#ifdef CONFIG_PAX_MPROTECT
47276 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47277 +#endif
47278 +
47279 + )
47280 + {
47281 + *flags &= ~MF_PAX_MPROTECT;
47282 + retval = -EINVAL;
47283 + }
47284 +
47285 + if ((*flags & MF_PAX_EMUTRAMP)
47286 +
47287 +#ifdef CONFIG_PAX_EMUTRAMP
47288 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47289 +#endif
47290 +
47291 + )
47292 + {
47293 + *flags &= ~MF_PAX_EMUTRAMP;
47294 + retval = -EINVAL;
47295 + }
47296 +
47297 + return retval;
47298 +}
47299 +
47300 +EXPORT_SYMBOL(pax_check_flags);
47301 +
47302 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47303 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
47304 +{
47305 + struct task_struct *tsk = current;
47306 + struct mm_struct *mm = current->mm;
47307 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
47308 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
47309 + char *path_exec = NULL;
47310 + char *path_fault = NULL;
47311 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
47312 + siginfo_t info = { };
47313 +
47314 + if (buffer_exec && buffer_fault) {
47315 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
47316 +
47317 + down_read(&mm->mmap_sem);
47318 + vma = mm->mmap;
47319 + while (vma && (!vma_exec || !vma_fault)) {
47320 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
47321 + vma_exec = vma;
47322 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
47323 + vma_fault = vma;
47324 + vma = vma->vm_next;
47325 + }
47326 + if (vma_exec) {
47327 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
47328 + if (IS_ERR(path_exec))
47329 + path_exec = "<path too long>";
47330 + else {
47331 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
47332 + if (path_exec) {
47333 + *path_exec = 0;
47334 + path_exec = buffer_exec;
47335 + } else
47336 + path_exec = "<path too long>";
47337 + }
47338 + }
47339 + if (vma_fault) {
47340 + start = vma_fault->vm_start;
47341 + end = vma_fault->vm_end;
47342 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
47343 + if (vma_fault->vm_file) {
47344 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
47345 + if (IS_ERR(path_fault))
47346 + path_fault = "<path too long>";
47347 + else {
47348 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
47349 + if (path_fault) {
47350 + *path_fault = 0;
47351 + path_fault = buffer_fault;
47352 + } else
47353 + path_fault = "<path too long>";
47354 + }
47355 + } else
47356 + path_fault = "<anonymous mapping>";
47357 + }
47358 + up_read(&mm->mmap_sem);
47359 + }
47360 + if (tsk->signal->curr_ip)
47361 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
47362 + else
47363 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
47364 + 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),
47365 + from_kuid(&init_user_ns, task_uid(tsk)), from_kuid(&init_user_ns, task_euid(tsk)), pc, sp);
47366 + free_page((unsigned long)buffer_exec);
47367 + free_page((unsigned long)buffer_fault);
47368 + pax_report_insns(regs, pc, sp);
47369 + info.si_signo = SIGKILL;
47370 + info.si_errno = 0;
47371 + info.si_code = SI_KERNEL;
47372 + info.si_pid = 0;
47373 + info.si_uid = 0;
47374 + do_coredump(&info, regs);
47375 +}
47376 +#endif
47377 +
47378 +#ifdef CONFIG_PAX_REFCOUNT
47379 +void pax_report_refcount_overflow(struct pt_regs *regs)
47380 +{
47381 + if (current->signal->curr_ip)
47382 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
47383 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
47384 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
47385 + else
47386 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
47387 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
47388 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
47389 + show_regs(regs);
47390 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
47391 +}
47392 +#endif
47393 +
47394 +#ifdef CONFIG_PAX_USERCOPY
47395 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
47396 +static noinline int check_stack_object(const void *obj, unsigned long len)
47397 +{
47398 + const void * const stack = task_stack_page(current);
47399 + const void * const stackend = stack + THREAD_SIZE;
47400 +
47401 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
47402 + const void *frame = NULL;
47403 + const void *oldframe;
47404 +#endif
47405 +
47406 + if (obj + len < obj)
47407 + return -1;
47408 +
47409 + if (obj + len <= stack || stackend <= obj)
47410 + return 0;
47411 +
47412 + if (obj < stack || stackend < obj + len)
47413 + return -1;
47414 +
47415 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
47416 + oldframe = __builtin_frame_address(1);
47417 + if (oldframe)
47418 + frame = __builtin_frame_address(2);
47419 + /*
47420 + low ----------------------------------------------> high
47421 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
47422 + ^----------------^
47423 + allow copies only within here
47424 + */
47425 + while (stack <= frame && frame < stackend) {
47426 + /* if obj + len extends past the last frame, this
47427 + check won't pass and the next frame will be 0,
47428 + causing us to bail out and correctly report
47429 + the copy as invalid
47430 + */
47431 + if (obj + len <= frame)
47432 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
47433 + oldframe = frame;
47434 + frame = *(const void * const *)frame;
47435 + }
47436 + return -1;
47437 +#else
47438 + return 1;
47439 +#endif
47440 +}
47441 +
47442 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
47443 +{
47444 + if (current->signal->curr_ip)
47445 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
47446 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
47447 + else
47448 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
47449 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
47450 + dump_stack();
47451 + gr_handle_kernel_exploit();
47452 + do_group_exit(SIGKILL);
47453 +}
47454 +#endif
47455 +
47456 +void __check_object_size(const void *ptr, unsigned long n, bool to)
47457 +{
47458 +
47459 +#ifdef CONFIG_PAX_USERCOPY
47460 + const char *type;
47461 +
47462 + if (!n)
47463 + return;
47464 +
47465 + type = check_heap_object(ptr, n);
47466 + if (!type) {
47467 + if (check_stack_object(ptr, n) != -1)
47468 + return;
47469 + type = "<process stack>";
47470 + }
47471 +
47472 + pax_report_usercopy(ptr, n, to, type);
47473 +#endif
47474 +
47475 +}
47476 +EXPORT_SYMBOL(__check_object_size);
47477 +
47478 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
47479 +void pax_track_stack(void)
47480 +{
47481 + unsigned long sp = (unsigned long)&sp;
47482 + if (sp < current_thread_info()->lowest_stack &&
47483 + sp > (unsigned long)task_stack_page(current))
47484 + current_thread_info()->lowest_stack = sp;
47485 +}
47486 +EXPORT_SYMBOL(pax_track_stack);
47487 +#endif
47488 +
47489 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
47490 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
47491 +{
47492 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
47493 + dump_stack();
47494 + do_group_exit(SIGKILL);
47495 +}
47496 +EXPORT_SYMBOL(report_size_overflow);
47497 +#endif
47498 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
47499 index 2616d0e..2ffdec9 100644
47500 --- a/fs/ext2/balloc.c
47501 +++ b/fs/ext2/balloc.c
47502 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
47503
47504 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47505 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47506 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47507 + if (free_blocks < root_blocks + 1 &&
47508 !uid_eq(sbi->s_resuid, current_fsuid()) &&
47509 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47510 - !in_group_p (sbi->s_resgid))) {
47511 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47512 return 0;
47513 }
47514 return 1;
47515 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
47516 index 22548f5..41521d8 100644
47517 --- a/fs/ext3/balloc.c
47518 +++ b/fs/ext3/balloc.c
47519 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
47520
47521 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47522 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47523 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47524 + if (free_blocks < root_blocks + 1 &&
47525 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
47526 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47527 - !in_group_p (sbi->s_resgid))) {
47528 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47529 return 0;
47530 }
47531 return 1;
47532 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
47533 index cf18217..8f6b9c3 100644
47534 --- a/fs/ext4/balloc.c
47535 +++ b/fs/ext4/balloc.c
47536 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
47537 /* Hm, nope. Are (enough) root reserved clusters available? */
47538 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
47539 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
47540 - capable(CAP_SYS_RESOURCE) ||
47541 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
47542 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
47543 + capable_nolog(CAP_SYS_RESOURCE)) {
47544
47545 if (free_clusters >= (nclusters + dirty_clusters))
47546 return 1;
47547 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
47548 index 3c20de1..6ff2460 100644
47549 --- a/fs/ext4/ext4.h
47550 +++ b/fs/ext4/ext4.h
47551 @@ -1247,19 +1247,19 @@ struct ext4_sb_info {
47552 unsigned long s_mb_last_start;
47553
47554 /* stats for buddy allocator */
47555 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
47556 - atomic_t s_bal_success; /* we found long enough chunks */
47557 - atomic_t s_bal_allocated; /* in blocks */
47558 - atomic_t s_bal_ex_scanned; /* total extents scanned */
47559 - atomic_t s_bal_goals; /* goal hits */
47560 - atomic_t s_bal_breaks; /* too long searches */
47561 - atomic_t s_bal_2orders; /* 2^order hits */
47562 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
47563 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
47564 + atomic_unchecked_t s_bal_allocated; /* in blocks */
47565 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
47566 + atomic_unchecked_t s_bal_goals; /* goal hits */
47567 + atomic_unchecked_t s_bal_breaks; /* too long searches */
47568 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
47569 spinlock_t s_bal_lock;
47570 unsigned long s_mb_buddies_generated;
47571 unsigned long long s_mb_generation_time;
47572 - atomic_t s_mb_lost_chunks;
47573 - atomic_t s_mb_preallocated;
47574 - atomic_t s_mb_discarded;
47575 + atomic_unchecked_t s_mb_lost_chunks;
47576 + atomic_unchecked_t s_mb_preallocated;
47577 + atomic_unchecked_t s_mb_discarded;
47578 atomic_t s_lock_busy;
47579
47580 /* locality groups */
47581 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
47582 index 526e553..3f2de85 100644
47583 --- a/fs/ext4/mballoc.c
47584 +++ b/fs/ext4/mballoc.c
47585 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
47586 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
47587
47588 if (EXT4_SB(sb)->s_mb_stats)
47589 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
47590 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
47591
47592 break;
47593 }
47594 @@ -2044,7 +2044,7 @@ repeat:
47595 ac->ac_status = AC_STATUS_CONTINUE;
47596 ac->ac_flags |= EXT4_MB_HINT_FIRST;
47597 cr = 3;
47598 - atomic_inc(&sbi->s_mb_lost_chunks);
47599 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
47600 goto repeat;
47601 }
47602 }
47603 @@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
47604 if (sbi->s_mb_stats) {
47605 ext4_msg(sb, KERN_INFO,
47606 "mballoc: %u blocks %u reqs (%u success)",
47607 - atomic_read(&sbi->s_bal_allocated),
47608 - atomic_read(&sbi->s_bal_reqs),
47609 - atomic_read(&sbi->s_bal_success));
47610 + atomic_read_unchecked(&sbi->s_bal_allocated),
47611 + atomic_read_unchecked(&sbi->s_bal_reqs),
47612 + atomic_read_unchecked(&sbi->s_bal_success));
47613 ext4_msg(sb, KERN_INFO,
47614 "mballoc: %u extents scanned, %u goal hits, "
47615 "%u 2^N hits, %u breaks, %u lost",
47616 - atomic_read(&sbi->s_bal_ex_scanned),
47617 - atomic_read(&sbi->s_bal_goals),
47618 - atomic_read(&sbi->s_bal_2orders),
47619 - atomic_read(&sbi->s_bal_breaks),
47620 - atomic_read(&sbi->s_mb_lost_chunks));
47621 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
47622 + atomic_read_unchecked(&sbi->s_bal_goals),
47623 + atomic_read_unchecked(&sbi->s_bal_2orders),
47624 + atomic_read_unchecked(&sbi->s_bal_breaks),
47625 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
47626 ext4_msg(sb, KERN_INFO,
47627 "mballoc: %lu generated and it took %Lu",
47628 sbi->s_mb_buddies_generated,
47629 sbi->s_mb_generation_time);
47630 ext4_msg(sb, KERN_INFO,
47631 "mballoc: %u preallocated, %u discarded",
47632 - atomic_read(&sbi->s_mb_preallocated),
47633 - atomic_read(&sbi->s_mb_discarded));
47634 + atomic_read_unchecked(&sbi->s_mb_preallocated),
47635 + atomic_read_unchecked(&sbi->s_mb_discarded));
47636 }
47637
47638 free_percpu(sbi->s_locality_groups);
47639 @@ -3052,16 +3052,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
47640 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
47641
47642 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
47643 - atomic_inc(&sbi->s_bal_reqs);
47644 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47645 + atomic_inc_unchecked(&sbi->s_bal_reqs);
47646 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47647 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
47648 - atomic_inc(&sbi->s_bal_success);
47649 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
47650 + atomic_inc_unchecked(&sbi->s_bal_success);
47651 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
47652 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
47653 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
47654 - atomic_inc(&sbi->s_bal_goals);
47655 + atomic_inc_unchecked(&sbi->s_bal_goals);
47656 if (ac->ac_found > sbi->s_mb_max_to_scan)
47657 - atomic_inc(&sbi->s_bal_breaks);
47658 + atomic_inc_unchecked(&sbi->s_bal_breaks);
47659 }
47660
47661 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
47662 @@ -3461,7 +3461,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
47663 trace_ext4_mb_new_inode_pa(ac, pa);
47664
47665 ext4_mb_use_inode_pa(ac, pa);
47666 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
47667 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
47668
47669 ei = EXT4_I(ac->ac_inode);
47670 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47671 @@ -3521,7 +3521,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
47672 trace_ext4_mb_new_group_pa(ac, pa);
47673
47674 ext4_mb_use_group_pa(ac, pa);
47675 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47676 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47677
47678 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47679 lg = ac->ac_lg;
47680 @@ -3610,7 +3610,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
47681 * from the bitmap and continue.
47682 */
47683 }
47684 - atomic_add(free, &sbi->s_mb_discarded);
47685 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
47686
47687 return err;
47688 }
47689 @@ -3628,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
47690 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
47691 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
47692 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
47693 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47694 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47695 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
47696
47697 return 0;
47698 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
47699 index d59b351..775f8c8 100644
47700 --- a/fs/ext4/super.c
47701 +++ b/fs/ext4/super.c
47702 @@ -3212,7 +3212,6 @@ int ext4_calculate_overhead(struct super_block *sb)
47703 ext4_fsblk_t overhead = 0;
47704 char *buf = (char *) get_zeroed_page(GFP_KERNEL);
47705
47706 - memset(buf, 0, PAGE_SIZE);
47707 if (!buf)
47708 return -ENOMEM;
47709
47710 diff --git a/fs/fcntl.c b/fs/fcntl.c
47711 index 71a600a..20d87b1 100644
47712 --- a/fs/fcntl.c
47713 +++ b/fs/fcntl.c
47714 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
47715 if (err)
47716 return err;
47717
47718 + if (gr_handle_chroot_fowner(pid, type))
47719 + return -ENOENT;
47720 + if (gr_check_protected_task_fowner(pid, type))
47721 + return -EACCES;
47722 +
47723 f_modown(filp, pid, type, force);
47724 return 0;
47725 }
47726 diff --git a/fs/fhandle.c b/fs/fhandle.c
47727 index f775bfd..629bd4c 100644
47728 --- a/fs/fhandle.c
47729 +++ b/fs/fhandle.c
47730 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
47731 } else
47732 retval = 0;
47733 /* copy the mount id */
47734 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
47735 - sizeof(*mnt_id)) ||
47736 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
47737 copy_to_user(ufh, handle,
47738 sizeof(struct file_handle) + handle_bytes))
47739 retval = -EFAULT;
47740 diff --git a/fs/fifo.c b/fs/fifo.c
47741 index cf6f434..3d7942c 100644
47742 --- a/fs/fifo.c
47743 +++ b/fs/fifo.c
47744 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
47745 */
47746 filp->f_op = &read_pipefifo_fops;
47747 pipe->r_counter++;
47748 - if (pipe->readers++ == 0)
47749 + if (atomic_inc_return(&pipe->readers) == 1)
47750 wake_up_partner(inode);
47751
47752 - if (!pipe->writers) {
47753 + if (!atomic_read(&pipe->writers)) {
47754 if ((filp->f_flags & O_NONBLOCK)) {
47755 /* suppress POLLHUP until we have
47756 * seen a writer */
47757 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
47758 * errno=ENXIO when there is no process reading the FIFO.
47759 */
47760 ret = -ENXIO;
47761 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
47762 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
47763 goto err;
47764
47765 filp->f_op = &write_pipefifo_fops;
47766 pipe->w_counter++;
47767 - if (!pipe->writers++)
47768 + if (atomic_inc_return(&pipe->writers) == 1)
47769 wake_up_partner(inode);
47770
47771 - if (!pipe->readers) {
47772 + if (!atomic_read(&pipe->readers)) {
47773 if (wait_for_partner(inode, &pipe->r_counter))
47774 goto err_wr;
47775 }
47776 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
47777 */
47778 filp->f_op = &rdwr_pipefifo_fops;
47779
47780 - pipe->readers++;
47781 - pipe->writers++;
47782 + atomic_inc(&pipe->readers);
47783 + atomic_inc(&pipe->writers);
47784 pipe->r_counter++;
47785 pipe->w_counter++;
47786 - if (pipe->readers == 1 || pipe->writers == 1)
47787 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
47788 wake_up_partner(inode);
47789 break;
47790
47791 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
47792 return 0;
47793
47794 err_rd:
47795 - if (!--pipe->readers)
47796 + if (atomic_dec_and_test(&pipe->readers))
47797 wake_up_interruptible(&pipe->wait);
47798 ret = -ERESTARTSYS;
47799 goto err;
47800
47801 err_wr:
47802 - if (!--pipe->writers)
47803 + if (atomic_dec_and_test(&pipe->writers))
47804 wake_up_interruptible(&pipe->wait);
47805 ret = -ERESTARTSYS;
47806 goto err;
47807
47808 err:
47809 - if (!pipe->readers && !pipe->writers)
47810 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
47811 free_pipe_info(inode);
47812
47813 err_nocleanup:
47814 diff --git a/fs/file.c b/fs/file.c
47815 index eff2316..8c8930c 100644
47816 --- a/fs/file.c
47817 +++ b/fs/file.c
47818 @@ -16,6 +16,7 @@
47819 #include <linux/slab.h>
47820 #include <linux/vmalloc.h>
47821 #include <linux/file.h>
47822 +#include <linux/security.h>
47823 #include <linux/fdtable.h>
47824 #include <linux/bitops.h>
47825 #include <linux/interrupt.h>
47826 @@ -898,6 +899,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
47827 if (!file)
47828 return __close_fd(files, fd);
47829
47830 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
47831 if (fd >= rlimit(RLIMIT_NOFILE))
47832 return -EBADF;
47833
47834 @@ -924,6 +926,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
47835 if (unlikely(oldfd == newfd))
47836 return -EINVAL;
47837
47838 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
47839 if (newfd >= rlimit(RLIMIT_NOFILE))
47840 return -EBADF;
47841
47842 @@ -979,6 +982,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
47843 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
47844 {
47845 int err;
47846 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
47847 if (from >= rlimit(RLIMIT_NOFILE))
47848 return -EINVAL;
47849 err = alloc_fd(from, flags);
47850 diff --git a/fs/filesystems.c b/fs/filesystems.c
47851 index da165f6..3671bdb 100644
47852 --- a/fs/filesystems.c
47853 +++ b/fs/filesystems.c
47854 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
47855 int len = dot ? dot - name : strlen(name);
47856
47857 fs = __get_fs_type(name, len);
47858 +
47859 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
47860 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
47861 +#else
47862 if (!fs && (request_module("%.*s", len, name) == 0))
47863 +#endif
47864 fs = __get_fs_type(name, len);
47865
47866 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
47867 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
47868 index 5df4775..9d9336f 100644
47869 --- a/fs/fs_struct.c
47870 +++ b/fs/fs_struct.c
47871 @@ -4,6 +4,7 @@
47872 #include <linux/path.h>
47873 #include <linux/slab.h>
47874 #include <linux/fs_struct.h>
47875 +#include <linux/grsecurity.h>
47876 #include "internal.h"
47877
47878 /*
47879 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
47880 write_seqcount_begin(&fs->seq);
47881 old_root = fs->root;
47882 fs->root = *path;
47883 + gr_set_chroot_entries(current, path);
47884 write_seqcount_end(&fs->seq);
47885 spin_unlock(&fs->lock);
47886 if (old_root.dentry)
47887 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
47888 return 1;
47889 }
47890
47891 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
47892 +{
47893 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
47894 + return 0;
47895 + *p = *new;
47896 +
47897 + /* This function is only called from pivot_root(). Leave our
47898 + gr_chroot_dentry and is_chrooted flags as-is, so that a
47899 + pivoted root isn't treated as a chroot
47900 + */
47901 + //gr_set_chroot_entries(task, new);
47902 +
47903 + return 1;
47904 +}
47905 +
47906 void chroot_fs_refs(struct path *old_root, struct path *new_root)
47907 {
47908 struct task_struct *g, *p;
47909 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
47910 int hits = 0;
47911 spin_lock(&fs->lock);
47912 write_seqcount_begin(&fs->seq);
47913 - hits += replace_path(&fs->root, old_root, new_root);
47914 + hits += replace_root_path(p, &fs->root, old_root, new_root);
47915 hits += replace_path(&fs->pwd, old_root, new_root);
47916 write_seqcount_end(&fs->seq);
47917 while (hits--) {
47918 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
47919 task_lock(tsk);
47920 spin_lock(&fs->lock);
47921 tsk->fs = NULL;
47922 - kill = !--fs->users;
47923 + gr_clear_chroot_entries(tsk);
47924 + kill = !atomic_dec_return(&fs->users);
47925 spin_unlock(&fs->lock);
47926 task_unlock(tsk);
47927 if (kill)
47928 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47929 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
47930 /* We don't need to lock fs - think why ;-) */
47931 if (fs) {
47932 - fs->users = 1;
47933 + atomic_set(&fs->users, 1);
47934 fs->in_exec = 0;
47935 spin_lock_init(&fs->lock);
47936 seqcount_init(&fs->seq);
47937 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47938 spin_lock(&old->lock);
47939 fs->root = old->root;
47940 path_get(&fs->root);
47941 + /* instead of calling gr_set_chroot_entries here,
47942 + we call it from every caller of this function
47943 + */
47944 fs->pwd = old->pwd;
47945 path_get(&fs->pwd);
47946 spin_unlock(&old->lock);
47947 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
47948
47949 task_lock(current);
47950 spin_lock(&fs->lock);
47951 - kill = !--fs->users;
47952 + kill = !atomic_dec_return(&fs->users);
47953 current->fs = new_fs;
47954 + gr_set_chroot_entries(current, &new_fs->root);
47955 spin_unlock(&fs->lock);
47956 task_unlock(current);
47957
47958 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
47959
47960 int current_umask(void)
47961 {
47962 - return current->fs->umask;
47963 + return current->fs->umask | gr_acl_umask();
47964 }
47965 EXPORT_SYMBOL(current_umask);
47966
47967 /* to be mentioned only in INIT_TASK */
47968 struct fs_struct init_fs = {
47969 - .users = 1,
47970 + .users = ATOMIC_INIT(1),
47971 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
47972 .seq = SEQCNT_ZERO,
47973 .umask = 0022,
47974 @@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
47975 task_lock(current);
47976
47977 spin_lock(&init_fs.lock);
47978 - init_fs.users++;
47979 + atomic_inc(&init_fs.users);
47980 spin_unlock(&init_fs.lock);
47981
47982 spin_lock(&fs->lock);
47983 current->fs = &init_fs;
47984 - kill = !--fs->users;
47985 + gr_set_chroot_entries(current, &current->fs->root);
47986 + kill = !atomic_dec_return(&fs->users);
47987 spin_unlock(&fs->lock);
47988
47989 task_unlock(current);
47990 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
47991 index 9905350..02eaec4 100644
47992 --- a/fs/fscache/cookie.c
47993 +++ b/fs/fscache/cookie.c
47994 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
47995 parent ? (char *) parent->def->name : "<no-parent>",
47996 def->name, netfs_data);
47997
47998 - fscache_stat(&fscache_n_acquires);
47999 + fscache_stat_unchecked(&fscache_n_acquires);
48000
48001 /* if there's no parent cookie, then we don't create one here either */
48002 if (!parent) {
48003 - fscache_stat(&fscache_n_acquires_null);
48004 + fscache_stat_unchecked(&fscache_n_acquires_null);
48005 _leave(" [no parent]");
48006 return NULL;
48007 }
48008 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
48009 /* allocate and initialise a cookie */
48010 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
48011 if (!cookie) {
48012 - fscache_stat(&fscache_n_acquires_oom);
48013 + fscache_stat_unchecked(&fscache_n_acquires_oom);
48014 _leave(" [ENOMEM]");
48015 return NULL;
48016 }
48017 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
48018
48019 switch (cookie->def->type) {
48020 case FSCACHE_COOKIE_TYPE_INDEX:
48021 - fscache_stat(&fscache_n_cookie_index);
48022 + fscache_stat_unchecked(&fscache_n_cookie_index);
48023 break;
48024 case FSCACHE_COOKIE_TYPE_DATAFILE:
48025 - fscache_stat(&fscache_n_cookie_data);
48026 + fscache_stat_unchecked(&fscache_n_cookie_data);
48027 break;
48028 default:
48029 - fscache_stat(&fscache_n_cookie_special);
48030 + fscache_stat_unchecked(&fscache_n_cookie_special);
48031 break;
48032 }
48033
48034 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
48035 if (fscache_acquire_non_index_cookie(cookie) < 0) {
48036 atomic_dec(&parent->n_children);
48037 __fscache_cookie_put(cookie);
48038 - fscache_stat(&fscache_n_acquires_nobufs);
48039 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
48040 _leave(" = NULL");
48041 return NULL;
48042 }
48043 }
48044
48045 - fscache_stat(&fscache_n_acquires_ok);
48046 + fscache_stat_unchecked(&fscache_n_acquires_ok);
48047 _leave(" = %p", cookie);
48048 return cookie;
48049 }
48050 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
48051 cache = fscache_select_cache_for_object(cookie->parent);
48052 if (!cache) {
48053 up_read(&fscache_addremove_sem);
48054 - fscache_stat(&fscache_n_acquires_no_cache);
48055 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
48056 _leave(" = -ENOMEDIUM [no cache]");
48057 return -ENOMEDIUM;
48058 }
48059 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
48060 object = cache->ops->alloc_object(cache, cookie);
48061 fscache_stat_d(&fscache_n_cop_alloc_object);
48062 if (IS_ERR(object)) {
48063 - fscache_stat(&fscache_n_object_no_alloc);
48064 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
48065 ret = PTR_ERR(object);
48066 goto error;
48067 }
48068
48069 - fscache_stat(&fscache_n_object_alloc);
48070 + fscache_stat_unchecked(&fscache_n_object_alloc);
48071
48072 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
48073
48074 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
48075 struct fscache_object *object;
48076 struct hlist_node *_p;
48077
48078 - fscache_stat(&fscache_n_updates);
48079 + fscache_stat_unchecked(&fscache_n_updates);
48080
48081 if (!cookie) {
48082 - fscache_stat(&fscache_n_updates_null);
48083 + fscache_stat_unchecked(&fscache_n_updates_null);
48084 _leave(" [no cookie]");
48085 return;
48086 }
48087 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48088 struct fscache_object *object;
48089 unsigned long event;
48090
48091 - fscache_stat(&fscache_n_relinquishes);
48092 + fscache_stat_unchecked(&fscache_n_relinquishes);
48093 if (retire)
48094 - fscache_stat(&fscache_n_relinquishes_retire);
48095 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
48096
48097 if (!cookie) {
48098 - fscache_stat(&fscache_n_relinquishes_null);
48099 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
48100 _leave(" [no cookie]");
48101 return;
48102 }
48103 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48104
48105 /* wait for the cookie to finish being instantiated (or to fail) */
48106 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
48107 - fscache_stat(&fscache_n_relinquishes_waitcrt);
48108 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
48109 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
48110 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
48111 }
48112 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
48113 index f6aad48..88dcf26 100644
48114 --- a/fs/fscache/internal.h
48115 +++ b/fs/fscache/internal.h
48116 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
48117 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
48118 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
48119
48120 -extern atomic_t fscache_n_op_pend;
48121 -extern atomic_t fscache_n_op_run;
48122 -extern atomic_t fscache_n_op_enqueue;
48123 -extern atomic_t fscache_n_op_deferred_release;
48124 -extern atomic_t fscache_n_op_release;
48125 -extern atomic_t fscache_n_op_gc;
48126 -extern atomic_t fscache_n_op_cancelled;
48127 -extern atomic_t fscache_n_op_rejected;
48128 +extern atomic_unchecked_t fscache_n_op_pend;
48129 +extern atomic_unchecked_t fscache_n_op_run;
48130 +extern atomic_unchecked_t fscache_n_op_enqueue;
48131 +extern atomic_unchecked_t fscache_n_op_deferred_release;
48132 +extern atomic_unchecked_t fscache_n_op_release;
48133 +extern atomic_unchecked_t fscache_n_op_gc;
48134 +extern atomic_unchecked_t fscache_n_op_cancelled;
48135 +extern atomic_unchecked_t fscache_n_op_rejected;
48136
48137 -extern atomic_t fscache_n_attr_changed;
48138 -extern atomic_t fscache_n_attr_changed_ok;
48139 -extern atomic_t fscache_n_attr_changed_nobufs;
48140 -extern atomic_t fscache_n_attr_changed_nomem;
48141 -extern atomic_t fscache_n_attr_changed_calls;
48142 +extern atomic_unchecked_t fscache_n_attr_changed;
48143 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
48144 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
48145 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
48146 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
48147
48148 -extern atomic_t fscache_n_allocs;
48149 -extern atomic_t fscache_n_allocs_ok;
48150 -extern atomic_t fscache_n_allocs_wait;
48151 -extern atomic_t fscache_n_allocs_nobufs;
48152 -extern atomic_t fscache_n_allocs_intr;
48153 -extern atomic_t fscache_n_allocs_object_dead;
48154 -extern atomic_t fscache_n_alloc_ops;
48155 -extern atomic_t fscache_n_alloc_op_waits;
48156 +extern atomic_unchecked_t fscache_n_allocs;
48157 +extern atomic_unchecked_t fscache_n_allocs_ok;
48158 +extern atomic_unchecked_t fscache_n_allocs_wait;
48159 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
48160 +extern atomic_unchecked_t fscache_n_allocs_intr;
48161 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
48162 +extern atomic_unchecked_t fscache_n_alloc_ops;
48163 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
48164
48165 -extern atomic_t fscache_n_retrievals;
48166 -extern atomic_t fscache_n_retrievals_ok;
48167 -extern atomic_t fscache_n_retrievals_wait;
48168 -extern atomic_t fscache_n_retrievals_nodata;
48169 -extern atomic_t fscache_n_retrievals_nobufs;
48170 -extern atomic_t fscache_n_retrievals_intr;
48171 -extern atomic_t fscache_n_retrievals_nomem;
48172 -extern atomic_t fscache_n_retrievals_object_dead;
48173 -extern atomic_t fscache_n_retrieval_ops;
48174 -extern atomic_t fscache_n_retrieval_op_waits;
48175 +extern atomic_unchecked_t fscache_n_retrievals;
48176 +extern atomic_unchecked_t fscache_n_retrievals_ok;
48177 +extern atomic_unchecked_t fscache_n_retrievals_wait;
48178 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
48179 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
48180 +extern atomic_unchecked_t fscache_n_retrievals_intr;
48181 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
48182 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
48183 +extern atomic_unchecked_t fscache_n_retrieval_ops;
48184 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
48185
48186 -extern atomic_t fscache_n_stores;
48187 -extern atomic_t fscache_n_stores_ok;
48188 -extern atomic_t fscache_n_stores_again;
48189 -extern atomic_t fscache_n_stores_nobufs;
48190 -extern atomic_t fscache_n_stores_oom;
48191 -extern atomic_t fscache_n_store_ops;
48192 -extern atomic_t fscache_n_store_calls;
48193 -extern atomic_t fscache_n_store_pages;
48194 -extern atomic_t fscache_n_store_radix_deletes;
48195 -extern atomic_t fscache_n_store_pages_over_limit;
48196 +extern atomic_unchecked_t fscache_n_stores;
48197 +extern atomic_unchecked_t fscache_n_stores_ok;
48198 +extern atomic_unchecked_t fscache_n_stores_again;
48199 +extern atomic_unchecked_t fscache_n_stores_nobufs;
48200 +extern atomic_unchecked_t fscache_n_stores_oom;
48201 +extern atomic_unchecked_t fscache_n_store_ops;
48202 +extern atomic_unchecked_t fscache_n_store_calls;
48203 +extern atomic_unchecked_t fscache_n_store_pages;
48204 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
48205 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
48206
48207 -extern atomic_t fscache_n_store_vmscan_not_storing;
48208 -extern atomic_t fscache_n_store_vmscan_gone;
48209 -extern atomic_t fscache_n_store_vmscan_busy;
48210 -extern atomic_t fscache_n_store_vmscan_cancelled;
48211 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48212 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
48213 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
48214 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48215
48216 -extern atomic_t fscache_n_marks;
48217 -extern atomic_t fscache_n_uncaches;
48218 +extern atomic_unchecked_t fscache_n_marks;
48219 +extern atomic_unchecked_t fscache_n_uncaches;
48220
48221 -extern atomic_t fscache_n_acquires;
48222 -extern atomic_t fscache_n_acquires_null;
48223 -extern atomic_t fscache_n_acquires_no_cache;
48224 -extern atomic_t fscache_n_acquires_ok;
48225 -extern atomic_t fscache_n_acquires_nobufs;
48226 -extern atomic_t fscache_n_acquires_oom;
48227 +extern atomic_unchecked_t fscache_n_acquires;
48228 +extern atomic_unchecked_t fscache_n_acquires_null;
48229 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
48230 +extern atomic_unchecked_t fscache_n_acquires_ok;
48231 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
48232 +extern atomic_unchecked_t fscache_n_acquires_oom;
48233
48234 -extern atomic_t fscache_n_updates;
48235 -extern atomic_t fscache_n_updates_null;
48236 -extern atomic_t fscache_n_updates_run;
48237 +extern atomic_unchecked_t fscache_n_updates;
48238 +extern atomic_unchecked_t fscache_n_updates_null;
48239 +extern atomic_unchecked_t fscache_n_updates_run;
48240
48241 -extern atomic_t fscache_n_relinquishes;
48242 -extern atomic_t fscache_n_relinquishes_null;
48243 -extern atomic_t fscache_n_relinquishes_waitcrt;
48244 -extern atomic_t fscache_n_relinquishes_retire;
48245 +extern atomic_unchecked_t fscache_n_relinquishes;
48246 +extern atomic_unchecked_t fscache_n_relinquishes_null;
48247 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48248 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
48249
48250 -extern atomic_t fscache_n_cookie_index;
48251 -extern atomic_t fscache_n_cookie_data;
48252 -extern atomic_t fscache_n_cookie_special;
48253 +extern atomic_unchecked_t fscache_n_cookie_index;
48254 +extern atomic_unchecked_t fscache_n_cookie_data;
48255 +extern atomic_unchecked_t fscache_n_cookie_special;
48256
48257 -extern atomic_t fscache_n_object_alloc;
48258 -extern atomic_t fscache_n_object_no_alloc;
48259 -extern atomic_t fscache_n_object_lookups;
48260 -extern atomic_t fscache_n_object_lookups_negative;
48261 -extern atomic_t fscache_n_object_lookups_positive;
48262 -extern atomic_t fscache_n_object_lookups_timed_out;
48263 -extern atomic_t fscache_n_object_created;
48264 -extern atomic_t fscache_n_object_avail;
48265 -extern atomic_t fscache_n_object_dead;
48266 +extern atomic_unchecked_t fscache_n_object_alloc;
48267 +extern atomic_unchecked_t fscache_n_object_no_alloc;
48268 +extern atomic_unchecked_t fscache_n_object_lookups;
48269 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
48270 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
48271 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
48272 +extern atomic_unchecked_t fscache_n_object_created;
48273 +extern atomic_unchecked_t fscache_n_object_avail;
48274 +extern atomic_unchecked_t fscache_n_object_dead;
48275
48276 -extern atomic_t fscache_n_checkaux_none;
48277 -extern atomic_t fscache_n_checkaux_okay;
48278 -extern atomic_t fscache_n_checkaux_update;
48279 -extern atomic_t fscache_n_checkaux_obsolete;
48280 +extern atomic_unchecked_t fscache_n_checkaux_none;
48281 +extern atomic_unchecked_t fscache_n_checkaux_okay;
48282 +extern atomic_unchecked_t fscache_n_checkaux_update;
48283 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
48284
48285 extern atomic_t fscache_n_cop_alloc_object;
48286 extern atomic_t fscache_n_cop_lookup_object;
48287 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
48288 atomic_inc(stat);
48289 }
48290
48291 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
48292 +{
48293 + atomic_inc_unchecked(stat);
48294 +}
48295 +
48296 static inline void fscache_stat_d(atomic_t *stat)
48297 {
48298 atomic_dec(stat);
48299 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
48300
48301 #define __fscache_stat(stat) (NULL)
48302 #define fscache_stat(stat) do {} while (0)
48303 +#define fscache_stat_unchecked(stat) do {} while (0)
48304 #define fscache_stat_d(stat) do {} while (0)
48305 #endif
48306
48307 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
48308 index b6b897c..0ffff9c 100644
48309 --- a/fs/fscache/object.c
48310 +++ b/fs/fscache/object.c
48311 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48312 /* update the object metadata on disk */
48313 case FSCACHE_OBJECT_UPDATING:
48314 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
48315 - fscache_stat(&fscache_n_updates_run);
48316 + fscache_stat_unchecked(&fscache_n_updates_run);
48317 fscache_stat(&fscache_n_cop_update_object);
48318 object->cache->ops->update_object(object);
48319 fscache_stat_d(&fscache_n_cop_update_object);
48320 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48321 spin_lock(&object->lock);
48322 object->state = FSCACHE_OBJECT_DEAD;
48323 spin_unlock(&object->lock);
48324 - fscache_stat(&fscache_n_object_dead);
48325 + fscache_stat_unchecked(&fscache_n_object_dead);
48326 goto terminal_transit;
48327
48328 /* handle the parent cache of this object being withdrawn from
48329 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48330 spin_lock(&object->lock);
48331 object->state = FSCACHE_OBJECT_DEAD;
48332 spin_unlock(&object->lock);
48333 - fscache_stat(&fscache_n_object_dead);
48334 + fscache_stat_unchecked(&fscache_n_object_dead);
48335 goto terminal_transit;
48336
48337 /* complain about the object being woken up once it is
48338 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48339 parent->cookie->def->name, cookie->def->name,
48340 object->cache->tag->name);
48341
48342 - fscache_stat(&fscache_n_object_lookups);
48343 + fscache_stat_unchecked(&fscache_n_object_lookups);
48344 fscache_stat(&fscache_n_cop_lookup_object);
48345 ret = object->cache->ops->lookup_object(object);
48346 fscache_stat_d(&fscache_n_cop_lookup_object);
48347 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
48348 if (ret == -ETIMEDOUT) {
48349 /* probably stuck behind another object, so move this one to
48350 * the back of the queue */
48351 - fscache_stat(&fscache_n_object_lookups_timed_out);
48352 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
48353 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
48354 }
48355
48356 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
48357
48358 spin_lock(&object->lock);
48359 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
48360 - fscache_stat(&fscache_n_object_lookups_negative);
48361 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
48362
48363 /* transit here to allow write requests to begin stacking up
48364 * and read requests to begin returning ENODATA */
48365 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
48366 * result, in which case there may be data available */
48367 spin_lock(&object->lock);
48368 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
48369 - fscache_stat(&fscache_n_object_lookups_positive);
48370 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
48371
48372 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
48373
48374 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
48375 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
48376 } else {
48377 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
48378 - fscache_stat(&fscache_n_object_created);
48379 + fscache_stat_unchecked(&fscache_n_object_created);
48380
48381 object->state = FSCACHE_OBJECT_AVAILABLE;
48382 spin_unlock(&object->lock);
48383 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
48384 fscache_enqueue_dependents(object);
48385
48386 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
48387 - fscache_stat(&fscache_n_object_avail);
48388 + fscache_stat_unchecked(&fscache_n_object_avail);
48389
48390 _leave("");
48391 }
48392 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
48393 enum fscache_checkaux result;
48394
48395 if (!object->cookie->def->check_aux) {
48396 - fscache_stat(&fscache_n_checkaux_none);
48397 + fscache_stat_unchecked(&fscache_n_checkaux_none);
48398 return FSCACHE_CHECKAUX_OKAY;
48399 }
48400
48401 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
48402 switch (result) {
48403 /* entry okay as is */
48404 case FSCACHE_CHECKAUX_OKAY:
48405 - fscache_stat(&fscache_n_checkaux_okay);
48406 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
48407 break;
48408
48409 /* entry requires update */
48410 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
48411 - fscache_stat(&fscache_n_checkaux_update);
48412 + fscache_stat_unchecked(&fscache_n_checkaux_update);
48413 break;
48414
48415 /* entry requires deletion */
48416 case FSCACHE_CHECKAUX_OBSOLETE:
48417 - fscache_stat(&fscache_n_checkaux_obsolete);
48418 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
48419 break;
48420
48421 default:
48422 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
48423 index 30afdfa..2256596 100644
48424 --- a/fs/fscache/operation.c
48425 +++ b/fs/fscache/operation.c
48426 @@ -17,7 +17,7 @@
48427 #include <linux/slab.h>
48428 #include "internal.h"
48429
48430 -atomic_t fscache_op_debug_id;
48431 +atomic_unchecked_t fscache_op_debug_id;
48432 EXPORT_SYMBOL(fscache_op_debug_id);
48433
48434 /**
48435 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
48436 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
48437 ASSERTCMP(atomic_read(&op->usage), >, 0);
48438
48439 - fscache_stat(&fscache_n_op_enqueue);
48440 + fscache_stat_unchecked(&fscache_n_op_enqueue);
48441 switch (op->flags & FSCACHE_OP_TYPE) {
48442 case FSCACHE_OP_ASYNC:
48443 _debug("queue async");
48444 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
48445 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
48446 if (op->processor)
48447 fscache_enqueue_operation(op);
48448 - fscache_stat(&fscache_n_op_run);
48449 + fscache_stat_unchecked(&fscache_n_op_run);
48450 }
48451
48452 /*
48453 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48454 if (object->n_ops > 1) {
48455 atomic_inc(&op->usage);
48456 list_add_tail(&op->pend_link, &object->pending_ops);
48457 - fscache_stat(&fscache_n_op_pend);
48458 + fscache_stat_unchecked(&fscache_n_op_pend);
48459 } else if (!list_empty(&object->pending_ops)) {
48460 atomic_inc(&op->usage);
48461 list_add_tail(&op->pend_link, &object->pending_ops);
48462 - fscache_stat(&fscache_n_op_pend);
48463 + fscache_stat_unchecked(&fscache_n_op_pend);
48464 fscache_start_operations(object);
48465 } else {
48466 ASSERTCMP(object->n_in_progress, ==, 0);
48467 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48468 object->n_exclusive++; /* reads and writes must wait */
48469 atomic_inc(&op->usage);
48470 list_add_tail(&op->pend_link, &object->pending_ops);
48471 - fscache_stat(&fscache_n_op_pend);
48472 + fscache_stat_unchecked(&fscache_n_op_pend);
48473 ret = 0;
48474 } else {
48475 /* not allowed to submit ops in any other state */
48476 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
48477 if (object->n_exclusive > 0) {
48478 atomic_inc(&op->usage);
48479 list_add_tail(&op->pend_link, &object->pending_ops);
48480 - fscache_stat(&fscache_n_op_pend);
48481 + fscache_stat_unchecked(&fscache_n_op_pend);
48482 } else if (!list_empty(&object->pending_ops)) {
48483 atomic_inc(&op->usage);
48484 list_add_tail(&op->pend_link, &object->pending_ops);
48485 - fscache_stat(&fscache_n_op_pend);
48486 + fscache_stat_unchecked(&fscache_n_op_pend);
48487 fscache_start_operations(object);
48488 } else {
48489 ASSERTCMP(object->n_exclusive, ==, 0);
48490 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
48491 object->n_ops++;
48492 atomic_inc(&op->usage);
48493 list_add_tail(&op->pend_link, &object->pending_ops);
48494 - fscache_stat(&fscache_n_op_pend);
48495 + fscache_stat_unchecked(&fscache_n_op_pend);
48496 ret = 0;
48497 } else if (object->state == FSCACHE_OBJECT_DYING ||
48498 object->state == FSCACHE_OBJECT_LC_DYING ||
48499 object->state == FSCACHE_OBJECT_WITHDRAWING) {
48500 - fscache_stat(&fscache_n_op_rejected);
48501 + fscache_stat_unchecked(&fscache_n_op_rejected);
48502 ret = -ENOBUFS;
48503 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
48504 fscache_report_unexpected_submission(object, op, ostate);
48505 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
48506
48507 ret = -EBUSY;
48508 if (!list_empty(&op->pend_link)) {
48509 - fscache_stat(&fscache_n_op_cancelled);
48510 + fscache_stat_unchecked(&fscache_n_op_cancelled);
48511 list_del_init(&op->pend_link);
48512 object->n_ops--;
48513 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
48514 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
48515 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
48516 BUG();
48517
48518 - fscache_stat(&fscache_n_op_release);
48519 + fscache_stat_unchecked(&fscache_n_op_release);
48520
48521 if (op->release) {
48522 op->release(op);
48523 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
48524 * lock, and defer it otherwise */
48525 if (!spin_trylock(&object->lock)) {
48526 _debug("defer put");
48527 - fscache_stat(&fscache_n_op_deferred_release);
48528 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
48529
48530 cache = object->cache;
48531 spin_lock(&cache->op_gc_list_lock);
48532 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
48533
48534 _debug("GC DEFERRED REL OBJ%x OP%x",
48535 object->debug_id, op->debug_id);
48536 - fscache_stat(&fscache_n_op_gc);
48537 + fscache_stat_unchecked(&fscache_n_op_gc);
48538
48539 ASSERTCMP(atomic_read(&op->usage), ==, 0);
48540
48541 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
48542 index 3f7a59b..cf196cc 100644
48543 --- a/fs/fscache/page.c
48544 +++ b/fs/fscache/page.c
48545 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48546 val = radix_tree_lookup(&cookie->stores, page->index);
48547 if (!val) {
48548 rcu_read_unlock();
48549 - fscache_stat(&fscache_n_store_vmscan_not_storing);
48550 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
48551 __fscache_uncache_page(cookie, page);
48552 return true;
48553 }
48554 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48555 spin_unlock(&cookie->stores_lock);
48556
48557 if (xpage) {
48558 - fscache_stat(&fscache_n_store_vmscan_cancelled);
48559 - fscache_stat(&fscache_n_store_radix_deletes);
48560 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
48561 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48562 ASSERTCMP(xpage, ==, page);
48563 } else {
48564 - fscache_stat(&fscache_n_store_vmscan_gone);
48565 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
48566 }
48567
48568 wake_up_bit(&cookie->flags, 0);
48569 @@ -107,7 +107,7 @@ page_busy:
48570 /* we might want to wait here, but that could deadlock the allocator as
48571 * the work threads writing to the cache may all end up sleeping
48572 * on memory allocation */
48573 - fscache_stat(&fscache_n_store_vmscan_busy);
48574 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
48575 return false;
48576 }
48577 EXPORT_SYMBOL(__fscache_maybe_release_page);
48578 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
48579 FSCACHE_COOKIE_STORING_TAG);
48580 if (!radix_tree_tag_get(&cookie->stores, page->index,
48581 FSCACHE_COOKIE_PENDING_TAG)) {
48582 - fscache_stat(&fscache_n_store_radix_deletes);
48583 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48584 xpage = radix_tree_delete(&cookie->stores, page->index);
48585 }
48586 spin_unlock(&cookie->stores_lock);
48587 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
48588
48589 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
48590
48591 - fscache_stat(&fscache_n_attr_changed_calls);
48592 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
48593
48594 if (fscache_object_is_active(object)) {
48595 fscache_stat(&fscache_n_cop_attr_changed);
48596 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48597
48598 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48599
48600 - fscache_stat(&fscache_n_attr_changed);
48601 + fscache_stat_unchecked(&fscache_n_attr_changed);
48602
48603 op = kzalloc(sizeof(*op), GFP_KERNEL);
48604 if (!op) {
48605 - fscache_stat(&fscache_n_attr_changed_nomem);
48606 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
48607 _leave(" = -ENOMEM");
48608 return -ENOMEM;
48609 }
48610 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48611 if (fscache_submit_exclusive_op(object, op) < 0)
48612 goto nobufs;
48613 spin_unlock(&cookie->lock);
48614 - fscache_stat(&fscache_n_attr_changed_ok);
48615 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
48616 fscache_put_operation(op);
48617 _leave(" = 0");
48618 return 0;
48619 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48620 nobufs:
48621 spin_unlock(&cookie->lock);
48622 kfree(op);
48623 - fscache_stat(&fscache_n_attr_changed_nobufs);
48624 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
48625 _leave(" = %d", -ENOBUFS);
48626 return -ENOBUFS;
48627 }
48628 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
48629 /* allocate a retrieval operation and attempt to submit it */
48630 op = kzalloc(sizeof(*op), GFP_NOIO);
48631 if (!op) {
48632 - fscache_stat(&fscache_n_retrievals_nomem);
48633 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48634 return NULL;
48635 }
48636
48637 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48638 return 0;
48639 }
48640
48641 - fscache_stat(&fscache_n_retrievals_wait);
48642 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
48643
48644 jif = jiffies;
48645 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
48646 fscache_wait_bit_interruptible,
48647 TASK_INTERRUPTIBLE) != 0) {
48648 - fscache_stat(&fscache_n_retrievals_intr);
48649 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48650 _leave(" = -ERESTARTSYS");
48651 return -ERESTARTSYS;
48652 }
48653 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48654 */
48655 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48656 struct fscache_retrieval *op,
48657 - atomic_t *stat_op_waits,
48658 - atomic_t *stat_object_dead)
48659 + atomic_unchecked_t *stat_op_waits,
48660 + atomic_unchecked_t *stat_object_dead)
48661 {
48662 int ret;
48663
48664 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48665 goto check_if_dead;
48666
48667 _debug(">>> WT");
48668 - fscache_stat(stat_op_waits);
48669 + fscache_stat_unchecked(stat_op_waits);
48670 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
48671 fscache_wait_bit_interruptible,
48672 TASK_INTERRUPTIBLE) < 0) {
48673 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48674
48675 check_if_dead:
48676 if (unlikely(fscache_object_is_dead(object))) {
48677 - fscache_stat(stat_object_dead);
48678 + fscache_stat_unchecked(stat_object_dead);
48679 return -ENOBUFS;
48680 }
48681 return 0;
48682 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48683
48684 _enter("%p,%p,,,", cookie, page);
48685
48686 - fscache_stat(&fscache_n_retrievals);
48687 + fscache_stat_unchecked(&fscache_n_retrievals);
48688
48689 if (hlist_empty(&cookie->backing_objects))
48690 goto nobufs;
48691 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48692 goto nobufs_unlock;
48693 spin_unlock(&cookie->lock);
48694
48695 - fscache_stat(&fscache_n_retrieval_ops);
48696 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
48697
48698 /* pin the netfs read context in case we need to do the actual netfs
48699 * read because we've encountered a cache read failure */
48700 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48701
48702 error:
48703 if (ret == -ENOMEM)
48704 - fscache_stat(&fscache_n_retrievals_nomem);
48705 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48706 else if (ret == -ERESTARTSYS)
48707 - fscache_stat(&fscache_n_retrievals_intr);
48708 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48709 else if (ret == -ENODATA)
48710 - fscache_stat(&fscache_n_retrievals_nodata);
48711 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48712 else if (ret < 0)
48713 - fscache_stat(&fscache_n_retrievals_nobufs);
48714 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48715 else
48716 - fscache_stat(&fscache_n_retrievals_ok);
48717 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
48718
48719 fscache_put_retrieval(op);
48720 _leave(" = %d", ret);
48721 @@ -429,7 +429,7 @@ nobufs_unlock:
48722 spin_unlock(&cookie->lock);
48723 kfree(op);
48724 nobufs:
48725 - fscache_stat(&fscache_n_retrievals_nobufs);
48726 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48727 _leave(" = -ENOBUFS");
48728 return -ENOBUFS;
48729 }
48730 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48731
48732 _enter("%p,,%d,,,", cookie, *nr_pages);
48733
48734 - fscache_stat(&fscache_n_retrievals);
48735 + fscache_stat_unchecked(&fscache_n_retrievals);
48736
48737 if (hlist_empty(&cookie->backing_objects))
48738 goto nobufs;
48739 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48740 goto nobufs_unlock;
48741 spin_unlock(&cookie->lock);
48742
48743 - fscache_stat(&fscache_n_retrieval_ops);
48744 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
48745
48746 /* pin the netfs read context in case we need to do the actual netfs
48747 * read because we've encountered a cache read failure */
48748 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48749
48750 error:
48751 if (ret == -ENOMEM)
48752 - fscache_stat(&fscache_n_retrievals_nomem);
48753 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48754 else if (ret == -ERESTARTSYS)
48755 - fscache_stat(&fscache_n_retrievals_intr);
48756 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
48757 else if (ret == -ENODATA)
48758 - fscache_stat(&fscache_n_retrievals_nodata);
48759 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48760 else if (ret < 0)
48761 - fscache_stat(&fscache_n_retrievals_nobufs);
48762 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48763 else
48764 - fscache_stat(&fscache_n_retrievals_ok);
48765 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
48766
48767 fscache_put_retrieval(op);
48768 _leave(" = %d", ret);
48769 @@ -545,7 +545,7 @@ nobufs_unlock:
48770 spin_unlock(&cookie->lock);
48771 kfree(op);
48772 nobufs:
48773 - fscache_stat(&fscache_n_retrievals_nobufs);
48774 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48775 _leave(" = -ENOBUFS");
48776 return -ENOBUFS;
48777 }
48778 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48779
48780 _enter("%p,%p,,,", cookie, page);
48781
48782 - fscache_stat(&fscache_n_allocs);
48783 + fscache_stat_unchecked(&fscache_n_allocs);
48784
48785 if (hlist_empty(&cookie->backing_objects))
48786 goto nobufs;
48787 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48788 goto nobufs_unlock;
48789 spin_unlock(&cookie->lock);
48790
48791 - fscache_stat(&fscache_n_alloc_ops);
48792 + fscache_stat_unchecked(&fscache_n_alloc_ops);
48793
48794 ret = fscache_wait_for_retrieval_activation(
48795 object, op,
48796 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48797
48798 error:
48799 if (ret == -ERESTARTSYS)
48800 - fscache_stat(&fscache_n_allocs_intr);
48801 + fscache_stat_unchecked(&fscache_n_allocs_intr);
48802 else if (ret < 0)
48803 - fscache_stat(&fscache_n_allocs_nobufs);
48804 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48805 else
48806 - fscache_stat(&fscache_n_allocs_ok);
48807 + fscache_stat_unchecked(&fscache_n_allocs_ok);
48808
48809 fscache_put_retrieval(op);
48810 _leave(" = %d", ret);
48811 @@ -625,7 +625,7 @@ nobufs_unlock:
48812 spin_unlock(&cookie->lock);
48813 kfree(op);
48814 nobufs:
48815 - fscache_stat(&fscache_n_allocs_nobufs);
48816 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48817 _leave(" = -ENOBUFS");
48818 return -ENOBUFS;
48819 }
48820 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48821
48822 spin_lock(&cookie->stores_lock);
48823
48824 - fscache_stat(&fscache_n_store_calls);
48825 + fscache_stat_unchecked(&fscache_n_store_calls);
48826
48827 /* find a page to store */
48828 page = NULL;
48829 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48830 page = results[0];
48831 _debug("gang %d [%lx]", n, page->index);
48832 if (page->index > op->store_limit) {
48833 - fscache_stat(&fscache_n_store_pages_over_limit);
48834 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
48835 goto superseded;
48836 }
48837
48838 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48839 spin_unlock(&cookie->stores_lock);
48840 spin_unlock(&object->lock);
48841
48842 - fscache_stat(&fscache_n_store_pages);
48843 + fscache_stat_unchecked(&fscache_n_store_pages);
48844 fscache_stat(&fscache_n_cop_write_page);
48845 ret = object->cache->ops->write_page(op, page);
48846 fscache_stat_d(&fscache_n_cop_write_page);
48847 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48848 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48849 ASSERT(PageFsCache(page));
48850
48851 - fscache_stat(&fscache_n_stores);
48852 + fscache_stat_unchecked(&fscache_n_stores);
48853
48854 op = kzalloc(sizeof(*op), GFP_NOIO);
48855 if (!op)
48856 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48857 spin_unlock(&cookie->stores_lock);
48858 spin_unlock(&object->lock);
48859
48860 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
48861 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
48862 op->store_limit = object->store_limit;
48863
48864 if (fscache_submit_op(object, &op->op) < 0)
48865 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48866
48867 spin_unlock(&cookie->lock);
48868 radix_tree_preload_end();
48869 - fscache_stat(&fscache_n_store_ops);
48870 - fscache_stat(&fscache_n_stores_ok);
48871 + fscache_stat_unchecked(&fscache_n_store_ops);
48872 + fscache_stat_unchecked(&fscache_n_stores_ok);
48873
48874 /* the work queue now carries its own ref on the object */
48875 fscache_put_operation(&op->op);
48876 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48877 return 0;
48878
48879 already_queued:
48880 - fscache_stat(&fscache_n_stores_again);
48881 + fscache_stat_unchecked(&fscache_n_stores_again);
48882 already_pending:
48883 spin_unlock(&cookie->stores_lock);
48884 spin_unlock(&object->lock);
48885 spin_unlock(&cookie->lock);
48886 radix_tree_preload_end();
48887 kfree(op);
48888 - fscache_stat(&fscache_n_stores_ok);
48889 + fscache_stat_unchecked(&fscache_n_stores_ok);
48890 _leave(" = 0");
48891 return 0;
48892
48893 @@ -851,14 +851,14 @@ nobufs:
48894 spin_unlock(&cookie->lock);
48895 radix_tree_preload_end();
48896 kfree(op);
48897 - fscache_stat(&fscache_n_stores_nobufs);
48898 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
48899 _leave(" = -ENOBUFS");
48900 return -ENOBUFS;
48901
48902 nomem_free:
48903 kfree(op);
48904 nomem:
48905 - fscache_stat(&fscache_n_stores_oom);
48906 + fscache_stat_unchecked(&fscache_n_stores_oom);
48907 _leave(" = -ENOMEM");
48908 return -ENOMEM;
48909 }
48910 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
48911 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48912 ASSERTCMP(page, !=, NULL);
48913
48914 - fscache_stat(&fscache_n_uncaches);
48915 + fscache_stat_unchecked(&fscache_n_uncaches);
48916
48917 /* cache withdrawal may beat us to it */
48918 if (!PageFsCache(page))
48919 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
48920 unsigned long loop;
48921
48922 #ifdef CONFIG_FSCACHE_STATS
48923 - atomic_add(pagevec->nr, &fscache_n_marks);
48924 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
48925 #endif
48926
48927 for (loop = 0; loop < pagevec->nr; loop++) {
48928 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
48929 index 4765190..2a067f2 100644
48930 --- a/fs/fscache/stats.c
48931 +++ b/fs/fscache/stats.c
48932 @@ -18,95 +18,95 @@
48933 /*
48934 * operation counters
48935 */
48936 -atomic_t fscache_n_op_pend;
48937 -atomic_t fscache_n_op_run;
48938 -atomic_t fscache_n_op_enqueue;
48939 -atomic_t fscache_n_op_requeue;
48940 -atomic_t fscache_n_op_deferred_release;
48941 -atomic_t fscache_n_op_release;
48942 -atomic_t fscache_n_op_gc;
48943 -atomic_t fscache_n_op_cancelled;
48944 -atomic_t fscache_n_op_rejected;
48945 +atomic_unchecked_t fscache_n_op_pend;
48946 +atomic_unchecked_t fscache_n_op_run;
48947 +atomic_unchecked_t fscache_n_op_enqueue;
48948 +atomic_unchecked_t fscache_n_op_requeue;
48949 +atomic_unchecked_t fscache_n_op_deferred_release;
48950 +atomic_unchecked_t fscache_n_op_release;
48951 +atomic_unchecked_t fscache_n_op_gc;
48952 +atomic_unchecked_t fscache_n_op_cancelled;
48953 +atomic_unchecked_t fscache_n_op_rejected;
48954
48955 -atomic_t fscache_n_attr_changed;
48956 -atomic_t fscache_n_attr_changed_ok;
48957 -atomic_t fscache_n_attr_changed_nobufs;
48958 -atomic_t fscache_n_attr_changed_nomem;
48959 -atomic_t fscache_n_attr_changed_calls;
48960 +atomic_unchecked_t fscache_n_attr_changed;
48961 +atomic_unchecked_t fscache_n_attr_changed_ok;
48962 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
48963 +atomic_unchecked_t fscache_n_attr_changed_nomem;
48964 +atomic_unchecked_t fscache_n_attr_changed_calls;
48965
48966 -atomic_t fscache_n_allocs;
48967 -atomic_t fscache_n_allocs_ok;
48968 -atomic_t fscache_n_allocs_wait;
48969 -atomic_t fscache_n_allocs_nobufs;
48970 -atomic_t fscache_n_allocs_intr;
48971 -atomic_t fscache_n_allocs_object_dead;
48972 -atomic_t fscache_n_alloc_ops;
48973 -atomic_t fscache_n_alloc_op_waits;
48974 +atomic_unchecked_t fscache_n_allocs;
48975 +atomic_unchecked_t fscache_n_allocs_ok;
48976 +atomic_unchecked_t fscache_n_allocs_wait;
48977 +atomic_unchecked_t fscache_n_allocs_nobufs;
48978 +atomic_unchecked_t fscache_n_allocs_intr;
48979 +atomic_unchecked_t fscache_n_allocs_object_dead;
48980 +atomic_unchecked_t fscache_n_alloc_ops;
48981 +atomic_unchecked_t fscache_n_alloc_op_waits;
48982
48983 -atomic_t fscache_n_retrievals;
48984 -atomic_t fscache_n_retrievals_ok;
48985 -atomic_t fscache_n_retrievals_wait;
48986 -atomic_t fscache_n_retrievals_nodata;
48987 -atomic_t fscache_n_retrievals_nobufs;
48988 -atomic_t fscache_n_retrievals_intr;
48989 -atomic_t fscache_n_retrievals_nomem;
48990 -atomic_t fscache_n_retrievals_object_dead;
48991 -atomic_t fscache_n_retrieval_ops;
48992 -atomic_t fscache_n_retrieval_op_waits;
48993 +atomic_unchecked_t fscache_n_retrievals;
48994 +atomic_unchecked_t fscache_n_retrievals_ok;
48995 +atomic_unchecked_t fscache_n_retrievals_wait;
48996 +atomic_unchecked_t fscache_n_retrievals_nodata;
48997 +atomic_unchecked_t fscache_n_retrievals_nobufs;
48998 +atomic_unchecked_t fscache_n_retrievals_intr;
48999 +atomic_unchecked_t fscache_n_retrievals_nomem;
49000 +atomic_unchecked_t fscache_n_retrievals_object_dead;
49001 +atomic_unchecked_t fscache_n_retrieval_ops;
49002 +atomic_unchecked_t fscache_n_retrieval_op_waits;
49003
49004 -atomic_t fscache_n_stores;
49005 -atomic_t fscache_n_stores_ok;
49006 -atomic_t fscache_n_stores_again;
49007 -atomic_t fscache_n_stores_nobufs;
49008 -atomic_t fscache_n_stores_oom;
49009 -atomic_t fscache_n_store_ops;
49010 -atomic_t fscache_n_store_calls;
49011 -atomic_t fscache_n_store_pages;
49012 -atomic_t fscache_n_store_radix_deletes;
49013 -atomic_t fscache_n_store_pages_over_limit;
49014 +atomic_unchecked_t fscache_n_stores;
49015 +atomic_unchecked_t fscache_n_stores_ok;
49016 +atomic_unchecked_t fscache_n_stores_again;
49017 +atomic_unchecked_t fscache_n_stores_nobufs;
49018 +atomic_unchecked_t fscache_n_stores_oom;
49019 +atomic_unchecked_t fscache_n_store_ops;
49020 +atomic_unchecked_t fscache_n_store_calls;
49021 +atomic_unchecked_t fscache_n_store_pages;
49022 +atomic_unchecked_t fscache_n_store_radix_deletes;
49023 +atomic_unchecked_t fscache_n_store_pages_over_limit;
49024
49025 -atomic_t fscache_n_store_vmscan_not_storing;
49026 -atomic_t fscache_n_store_vmscan_gone;
49027 -atomic_t fscache_n_store_vmscan_busy;
49028 -atomic_t fscache_n_store_vmscan_cancelled;
49029 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
49030 +atomic_unchecked_t fscache_n_store_vmscan_gone;
49031 +atomic_unchecked_t fscache_n_store_vmscan_busy;
49032 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
49033
49034 -atomic_t fscache_n_marks;
49035 -atomic_t fscache_n_uncaches;
49036 +atomic_unchecked_t fscache_n_marks;
49037 +atomic_unchecked_t fscache_n_uncaches;
49038
49039 -atomic_t fscache_n_acquires;
49040 -atomic_t fscache_n_acquires_null;
49041 -atomic_t fscache_n_acquires_no_cache;
49042 -atomic_t fscache_n_acquires_ok;
49043 -atomic_t fscache_n_acquires_nobufs;
49044 -atomic_t fscache_n_acquires_oom;
49045 +atomic_unchecked_t fscache_n_acquires;
49046 +atomic_unchecked_t fscache_n_acquires_null;
49047 +atomic_unchecked_t fscache_n_acquires_no_cache;
49048 +atomic_unchecked_t fscache_n_acquires_ok;
49049 +atomic_unchecked_t fscache_n_acquires_nobufs;
49050 +atomic_unchecked_t fscache_n_acquires_oom;
49051
49052 -atomic_t fscache_n_updates;
49053 -atomic_t fscache_n_updates_null;
49054 -atomic_t fscache_n_updates_run;
49055 +atomic_unchecked_t fscache_n_updates;
49056 +atomic_unchecked_t fscache_n_updates_null;
49057 +atomic_unchecked_t fscache_n_updates_run;
49058
49059 -atomic_t fscache_n_relinquishes;
49060 -atomic_t fscache_n_relinquishes_null;
49061 -atomic_t fscache_n_relinquishes_waitcrt;
49062 -atomic_t fscache_n_relinquishes_retire;
49063 +atomic_unchecked_t fscache_n_relinquishes;
49064 +atomic_unchecked_t fscache_n_relinquishes_null;
49065 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
49066 +atomic_unchecked_t fscache_n_relinquishes_retire;
49067
49068 -atomic_t fscache_n_cookie_index;
49069 -atomic_t fscache_n_cookie_data;
49070 -atomic_t fscache_n_cookie_special;
49071 +atomic_unchecked_t fscache_n_cookie_index;
49072 +atomic_unchecked_t fscache_n_cookie_data;
49073 +atomic_unchecked_t fscache_n_cookie_special;
49074
49075 -atomic_t fscache_n_object_alloc;
49076 -atomic_t fscache_n_object_no_alloc;
49077 -atomic_t fscache_n_object_lookups;
49078 -atomic_t fscache_n_object_lookups_negative;
49079 -atomic_t fscache_n_object_lookups_positive;
49080 -atomic_t fscache_n_object_lookups_timed_out;
49081 -atomic_t fscache_n_object_created;
49082 -atomic_t fscache_n_object_avail;
49083 -atomic_t fscache_n_object_dead;
49084 +atomic_unchecked_t fscache_n_object_alloc;
49085 +atomic_unchecked_t fscache_n_object_no_alloc;
49086 +atomic_unchecked_t fscache_n_object_lookups;
49087 +atomic_unchecked_t fscache_n_object_lookups_negative;
49088 +atomic_unchecked_t fscache_n_object_lookups_positive;
49089 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
49090 +atomic_unchecked_t fscache_n_object_created;
49091 +atomic_unchecked_t fscache_n_object_avail;
49092 +atomic_unchecked_t fscache_n_object_dead;
49093
49094 -atomic_t fscache_n_checkaux_none;
49095 -atomic_t fscache_n_checkaux_okay;
49096 -atomic_t fscache_n_checkaux_update;
49097 -atomic_t fscache_n_checkaux_obsolete;
49098 +atomic_unchecked_t fscache_n_checkaux_none;
49099 +atomic_unchecked_t fscache_n_checkaux_okay;
49100 +atomic_unchecked_t fscache_n_checkaux_update;
49101 +atomic_unchecked_t fscache_n_checkaux_obsolete;
49102
49103 atomic_t fscache_n_cop_alloc_object;
49104 atomic_t fscache_n_cop_lookup_object;
49105 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
49106 seq_puts(m, "FS-Cache statistics\n");
49107
49108 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
49109 - atomic_read(&fscache_n_cookie_index),
49110 - atomic_read(&fscache_n_cookie_data),
49111 - atomic_read(&fscache_n_cookie_special));
49112 + atomic_read_unchecked(&fscache_n_cookie_index),
49113 + atomic_read_unchecked(&fscache_n_cookie_data),
49114 + atomic_read_unchecked(&fscache_n_cookie_special));
49115
49116 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
49117 - atomic_read(&fscache_n_object_alloc),
49118 - atomic_read(&fscache_n_object_no_alloc),
49119 - atomic_read(&fscache_n_object_avail),
49120 - atomic_read(&fscache_n_object_dead));
49121 + atomic_read_unchecked(&fscache_n_object_alloc),
49122 + atomic_read_unchecked(&fscache_n_object_no_alloc),
49123 + atomic_read_unchecked(&fscache_n_object_avail),
49124 + atomic_read_unchecked(&fscache_n_object_dead));
49125 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
49126 - atomic_read(&fscache_n_checkaux_none),
49127 - atomic_read(&fscache_n_checkaux_okay),
49128 - atomic_read(&fscache_n_checkaux_update),
49129 - atomic_read(&fscache_n_checkaux_obsolete));
49130 + atomic_read_unchecked(&fscache_n_checkaux_none),
49131 + atomic_read_unchecked(&fscache_n_checkaux_okay),
49132 + atomic_read_unchecked(&fscache_n_checkaux_update),
49133 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
49134
49135 seq_printf(m, "Pages : mrk=%u unc=%u\n",
49136 - atomic_read(&fscache_n_marks),
49137 - atomic_read(&fscache_n_uncaches));
49138 + atomic_read_unchecked(&fscache_n_marks),
49139 + atomic_read_unchecked(&fscache_n_uncaches));
49140
49141 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
49142 " oom=%u\n",
49143 - atomic_read(&fscache_n_acquires),
49144 - atomic_read(&fscache_n_acquires_null),
49145 - atomic_read(&fscache_n_acquires_no_cache),
49146 - atomic_read(&fscache_n_acquires_ok),
49147 - atomic_read(&fscache_n_acquires_nobufs),
49148 - atomic_read(&fscache_n_acquires_oom));
49149 + atomic_read_unchecked(&fscache_n_acquires),
49150 + atomic_read_unchecked(&fscache_n_acquires_null),
49151 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
49152 + atomic_read_unchecked(&fscache_n_acquires_ok),
49153 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
49154 + atomic_read_unchecked(&fscache_n_acquires_oom));
49155
49156 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
49157 - atomic_read(&fscache_n_object_lookups),
49158 - atomic_read(&fscache_n_object_lookups_negative),
49159 - atomic_read(&fscache_n_object_lookups_positive),
49160 - atomic_read(&fscache_n_object_created),
49161 - atomic_read(&fscache_n_object_lookups_timed_out));
49162 + atomic_read_unchecked(&fscache_n_object_lookups),
49163 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
49164 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
49165 + atomic_read_unchecked(&fscache_n_object_created),
49166 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
49167
49168 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
49169 - atomic_read(&fscache_n_updates),
49170 - atomic_read(&fscache_n_updates_null),
49171 - atomic_read(&fscache_n_updates_run));
49172 + atomic_read_unchecked(&fscache_n_updates),
49173 + atomic_read_unchecked(&fscache_n_updates_null),
49174 + atomic_read_unchecked(&fscache_n_updates_run));
49175
49176 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
49177 - atomic_read(&fscache_n_relinquishes),
49178 - atomic_read(&fscache_n_relinquishes_null),
49179 - atomic_read(&fscache_n_relinquishes_waitcrt),
49180 - atomic_read(&fscache_n_relinquishes_retire));
49181 + atomic_read_unchecked(&fscache_n_relinquishes),
49182 + atomic_read_unchecked(&fscache_n_relinquishes_null),
49183 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
49184 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
49185
49186 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
49187 - atomic_read(&fscache_n_attr_changed),
49188 - atomic_read(&fscache_n_attr_changed_ok),
49189 - atomic_read(&fscache_n_attr_changed_nobufs),
49190 - atomic_read(&fscache_n_attr_changed_nomem),
49191 - atomic_read(&fscache_n_attr_changed_calls));
49192 + atomic_read_unchecked(&fscache_n_attr_changed),
49193 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
49194 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
49195 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
49196 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
49197
49198 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
49199 - atomic_read(&fscache_n_allocs),
49200 - atomic_read(&fscache_n_allocs_ok),
49201 - atomic_read(&fscache_n_allocs_wait),
49202 - atomic_read(&fscache_n_allocs_nobufs),
49203 - atomic_read(&fscache_n_allocs_intr));
49204 + atomic_read_unchecked(&fscache_n_allocs),
49205 + atomic_read_unchecked(&fscache_n_allocs_ok),
49206 + atomic_read_unchecked(&fscache_n_allocs_wait),
49207 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
49208 + atomic_read_unchecked(&fscache_n_allocs_intr));
49209 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
49210 - atomic_read(&fscache_n_alloc_ops),
49211 - atomic_read(&fscache_n_alloc_op_waits),
49212 - atomic_read(&fscache_n_allocs_object_dead));
49213 + atomic_read_unchecked(&fscache_n_alloc_ops),
49214 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
49215 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
49216
49217 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
49218 " int=%u oom=%u\n",
49219 - atomic_read(&fscache_n_retrievals),
49220 - atomic_read(&fscache_n_retrievals_ok),
49221 - atomic_read(&fscache_n_retrievals_wait),
49222 - atomic_read(&fscache_n_retrievals_nodata),
49223 - atomic_read(&fscache_n_retrievals_nobufs),
49224 - atomic_read(&fscache_n_retrievals_intr),
49225 - atomic_read(&fscache_n_retrievals_nomem));
49226 + atomic_read_unchecked(&fscache_n_retrievals),
49227 + atomic_read_unchecked(&fscache_n_retrievals_ok),
49228 + atomic_read_unchecked(&fscache_n_retrievals_wait),
49229 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
49230 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
49231 + atomic_read_unchecked(&fscache_n_retrievals_intr),
49232 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
49233 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
49234 - atomic_read(&fscache_n_retrieval_ops),
49235 - atomic_read(&fscache_n_retrieval_op_waits),
49236 - atomic_read(&fscache_n_retrievals_object_dead));
49237 + atomic_read_unchecked(&fscache_n_retrieval_ops),
49238 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
49239 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
49240
49241 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
49242 - atomic_read(&fscache_n_stores),
49243 - atomic_read(&fscache_n_stores_ok),
49244 - atomic_read(&fscache_n_stores_again),
49245 - atomic_read(&fscache_n_stores_nobufs),
49246 - atomic_read(&fscache_n_stores_oom));
49247 + atomic_read_unchecked(&fscache_n_stores),
49248 + atomic_read_unchecked(&fscache_n_stores_ok),
49249 + atomic_read_unchecked(&fscache_n_stores_again),
49250 + atomic_read_unchecked(&fscache_n_stores_nobufs),
49251 + atomic_read_unchecked(&fscache_n_stores_oom));
49252 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
49253 - atomic_read(&fscache_n_store_ops),
49254 - atomic_read(&fscache_n_store_calls),
49255 - atomic_read(&fscache_n_store_pages),
49256 - atomic_read(&fscache_n_store_radix_deletes),
49257 - atomic_read(&fscache_n_store_pages_over_limit));
49258 + atomic_read_unchecked(&fscache_n_store_ops),
49259 + atomic_read_unchecked(&fscache_n_store_calls),
49260 + atomic_read_unchecked(&fscache_n_store_pages),
49261 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
49262 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
49263
49264 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
49265 - atomic_read(&fscache_n_store_vmscan_not_storing),
49266 - atomic_read(&fscache_n_store_vmscan_gone),
49267 - atomic_read(&fscache_n_store_vmscan_busy),
49268 - atomic_read(&fscache_n_store_vmscan_cancelled));
49269 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
49270 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
49271 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
49272 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
49273
49274 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
49275 - atomic_read(&fscache_n_op_pend),
49276 - atomic_read(&fscache_n_op_run),
49277 - atomic_read(&fscache_n_op_enqueue),
49278 - atomic_read(&fscache_n_op_cancelled),
49279 - atomic_read(&fscache_n_op_rejected));
49280 + atomic_read_unchecked(&fscache_n_op_pend),
49281 + atomic_read_unchecked(&fscache_n_op_run),
49282 + atomic_read_unchecked(&fscache_n_op_enqueue),
49283 + atomic_read_unchecked(&fscache_n_op_cancelled),
49284 + atomic_read_unchecked(&fscache_n_op_rejected));
49285 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
49286 - atomic_read(&fscache_n_op_deferred_release),
49287 - atomic_read(&fscache_n_op_release),
49288 - atomic_read(&fscache_n_op_gc));
49289 + atomic_read_unchecked(&fscache_n_op_deferred_release),
49290 + atomic_read_unchecked(&fscache_n_op_release),
49291 + atomic_read_unchecked(&fscache_n_op_gc));
49292
49293 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
49294 atomic_read(&fscache_n_cop_alloc_object),
49295 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
49296 index ee8d550..7189d8c 100644
49297 --- a/fs/fuse/cuse.c
49298 +++ b/fs/fuse/cuse.c
49299 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
49300 INIT_LIST_HEAD(&cuse_conntbl[i]);
49301
49302 /* inherit and extend fuse_dev_operations */
49303 - cuse_channel_fops = fuse_dev_operations;
49304 - cuse_channel_fops.owner = THIS_MODULE;
49305 - cuse_channel_fops.open = cuse_channel_open;
49306 - cuse_channel_fops.release = cuse_channel_release;
49307 + pax_open_kernel();
49308 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
49309 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
49310 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
49311 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
49312 + pax_close_kernel();
49313
49314 cuse_class = class_create(THIS_MODULE, "cuse");
49315 if (IS_ERR(cuse_class))
49316 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
49317 index 8c23fa7..0e3aac7 100644
49318 --- a/fs/fuse/dev.c
49319 +++ b/fs/fuse/dev.c
49320 @@ -1241,7 +1241,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
49321 ret = 0;
49322 pipe_lock(pipe);
49323
49324 - if (!pipe->readers) {
49325 + if (!atomic_read(&pipe->readers)) {
49326 send_sig(SIGPIPE, current, 0);
49327 if (!ret)
49328 ret = -EPIPE;
49329 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
49330 index 324bc08..4fdd56e 100644
49331 --- a/fs/fuse/dir.c
49332 +++ b/fs/fuse/dir.c
49333 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
49334 return link;
49335 }
49336
49337 -static void free_link(char *link)
49338 +static void free_link(const char *link)
49339 {
49340 if (!IS_ERR(link))
49341 free_page((unsigned long) link);
49342 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
49343 index 381893c..3793318 100644
49344 --- a/fs/gfs2/inode.c
49345 +++ b/fs/gfs2/inode.c
49346 @@ -1490,7 +1490,7 @@ out:
49347
49348 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
49349 {
49350 - char *s = nd_get_link(nd);
49351 + const char *s = nd_get_link(nd);
49352 if (!IS_ERR(s))
49353 kfree(s);
49354 }
49355 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
49356 index c5bc355..163a13e 100644
49357 --- a/fs/hugetlbfs/inode.c
49358 +++ b/fs/hugetlbfs/inode.c
49359 @@ -153,6 +153,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
49360 struct vm_area_struct *vma;
49361 unsigned long start_addr;
49362 struct hstate *h = hstate_file(file);
49363 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
49364
49365 if (len & ~huge_page_mask(h))
49366 return -EINVAL;
49367 @@ -165,18 +166,21 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
49368 return addr;
49369 }
49370
49371 +#ifdef CONFIG_PAX_RANDMMAP
49372 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
49373 +#endif
49374 +
49375 if (addr) {
49376 addr = ALIGN(addr, huge_page_size(h));
49377 vma = find_vma(mm, addr);
49378 - if (TASK_SIZE - len >= addr &&
49379 - (!vma || addr + len <= vma->vm_start))
49380 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
49381 return addr;
49382 }
49383
49384 if (len > mm->cached_hole_size)
49385 start_addr = mm->free_area_cache;
49386 else {
49387 - start_addr = TASK_UNMAPPED_BASE;
49388 + start_addr = mm->mmap_base;
49389 mm->cached_hole_size = 0;
49390 }
49391
49392 @@ -190,15 +194,15 @@ full_search:
49393 * Start a new search - just in case we missed
49394 * some holes.
49395 */
49396 - if (start_addr != TASK_UNMAPPED_BASE) {
49397 - start_addr = TASK_UNMAPPED_BASE;
49398 + if (start_addr != mm->mmap_base) {
49399 + start_addr = mm->mmap_base;
49400 mm->cached_hole_size = 0;
49401 goto full_search;
49402 }
49403 return -ENOMEM;
49404 }
49405
49406 - if (!vma || addr + len <= vma->vm_start) {
49407 + if (check_heap_stack_gap(vma, addr, len, offset)) {
49408 mm->free_area_cache = addr + len;
49409 return addr;
49410 }
49411 @@ -923,7 +927,7 @@ static struct file_system_type hugetlbfs_fs_type = {
49412 .kill_sb = kill_litter_super,
49413 };
49414
49415 -static struct vfsmount *hugetlbfs_vfsmount;
49416 +struct vfsmount *hugetlbfs_vfsmount;
49417
49418 static int can_do_hugetlb_shm(void)
49419 {
49420 diff --git a/fs/inode.c b/fs/inode.c
49421 index 64999f1..8fad608 100644
49422 --- a/fs/inode.c
49423 +++ b/fs/inode.c
49424 @@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
49425
49426 #ifdef CONFIG_SMP
49427 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
49428 - static atomic_t shared_last_ino;
49429 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
49430 + static atomic_unchecked_t shared_last_ino;
49431 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
49432
49433 res = next - LAST_INO_BATCH;
49434 }
49435 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
49436 index 4a6cf28..d3a29d3 100644
49437 --- a/fs/jffs2/erase.c
49438 +++ b/fs/jffs2/erase.c
49439 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
49440 struct jffs2_unknown_node marker = {
49441 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
49442 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
49443 - .totlen = cpu_to_je32(c->cleanmarker_size)
49444 + .totlen = cpu_to_je32(c->cleanmarker_size),
49445 + .hdr_crc = cpu_to_je32(0)
49446 };
49447
49448 jffs2_prealloc_raw_node_refs(c, jeb, 1);
49449 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
49450 index a6597d6..41b30ec 100644
49451 --- a/fs/jffs2/wbuf.c
49452 +++ b/fs/jffs2/wbuf.c
49453 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
49454 {
49455 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
49456 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
49457 - .totlen = constant_cpu_to_je32(8)
49458 + .totlen = constant_cpu_to_je32(8),
49459 + .hdr_crc = constant_cpu_to_je32(0)
49460 };
49461
49462 /*
49463 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
49464 index 1a543be..d803c40 100644
49465 --- a/fs/jfs/super.c
49466 +++ b/fs/jfs/super.c
49467 @@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
49468
49469 jfs_inode_cachep =
49470 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
49471 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
49472 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
49473 init_once);
49474 if (jfs_inode_cachep == NULL)
49475 return -ENOMEM;
49476 diff --git a/fs/libfs.c b/fs/libfs.c
49477 index 7cc37ca..b3e3eec 100644
49478 --- a/fs/libfs.c
49479 +++ b/fs/libfs.c
49480 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49481
49482 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
49483 struct dentry *next;
49484 + char d_name[sizeof(next->d_iname)];
49485 + const unsigned char *name;
49486 +
49487 next = list_entry(p, struct dentry, d_u.d_child);
49488 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
49489 if (!simple_positive(next)) {
49490 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49491
49492 spin_unlock(&next->d_lock);
49493 spin_unlock(&dentry->d_lock);
49494 - if (filldir(dirent, next->d_name.name,
49495 + name = next->d_name.name;
49496 + if (name == next->d_iname) {
49497 + memcpy(d_name, name, next->d_name.len);
49498 + name = d_name;
49499 + }
49500 + if (filldir(dirent, name,
49501 next->d_name.len, filp->f_pos,
49502 next->d_inode->i_ino,
49503 dt_type(next->d_inode)) < 0)
49504 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
49505 index 05d2912..760abfa 100644
49506 --- a/fs/lockd/clntproc.c
49507 +++ b/fs/lockd/clntproc.c
49508 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
49509 /*
49510 * Cookie counter for NLM requests
49511 */
49512 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
49513 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
49514
49515 void nlmclnt_next_cookie(struct nlm_cookie *c)
49516 {
49517 - u32 cookie = atomic_inc_return(&nlm_cookie);
49518 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
49519
49520 memcpy(c->data, &cookie, 4);
49521 c->len=4;
49522 diff --git a/fs/locks.c b/fs/locks.c
49523 index a94e331..060bce3 100644
49524 --- a/fs/locks.c
49525 +++ b/fs/locks.c
49526 @@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
49527 return;
49528
49529 if (filp->f_op && filp->f_op->flock) {
49530 - struct file_lock fl = {
49531 + struct file_lock flock = {
49532 .fl_pid = current->tgid,
49533 .fl_file = filp,
49534 .fl_flags = FL_FLOCK,
49535 .fl_type = F_UNLCK,
49536 .fl_end = OFFSET_MAX,
49537 };
49538 - filp->f_op->flock(filp, F_SETLKW, &fl);
49539 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
49540 - fl.fl_ops->fl_release_private(&fl);
49541 + filp->f_op->flock(filp, F_SETLKW, &flock);
49542 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
49543 + flock.fl_ops->fl_release_private(&flock);
49544 }
49545
49546 lock_flocks();
49547 diff --git a/fs/namei.c b/fs/namei.c
49548 index 5f4cdf3..959a013 100644
49549 --- a/fs/namei.c
49550 +++ b/fs/namei.c
49551 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
49552 if (ret != -EACCES)
49553 return ret;
49554
49555 +#ifdef CONFIG_GRKERNSEC
49556 + /* we'll block if we have to log due to a denied capability use */
49557 + if (mask & MAY_NOT_BLOCK)
49558 + return -ECHILD;
49559 +#endif
49560 +
49561 if (S_ISDIR(inode->i_mode)) {
49562 /* DACs are overridable for directories */
49563 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
49564 - return 0;
49565 if (!(mask & MAY_WRITE))
49566 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49567 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49568 + inode_capable(inode, CAP_DAC_READ_SEARCH))
49569 return 0;
49570 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
49571 + return 0;
49572 return -EACCES;
49573 }
49574 /*
49575 + * Searching includes executable on directories, else just read.
49576 + */
49577 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49578 + if (mask == MAY_READ)
49579 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49580 + inode_capable(inode, CAP_DAC_READ_SEARCH))
49581 + return 0;
49582 +
49583 + /*
49584 * Read/write DACs are always overridable.
49585 * Executable DACs are overridable when there is
49586 * at least one exec bit set.
49587 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
49588 if (inode_capable(inode, CAP_DAC_OVERRIDE))
49589 return 0;
49590
49591 - /*
49592 - * Searching includes executable on directories, else just read.
49593 - */
49594 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49595 - if (mask == MAY_READ)
49596 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49597 - return 0;
49598 -
49599 return -EACCES;
49600 }
49601
49602 @@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49603 {
49604 struct dentry *dentry = link->dentry;
49605 int error;
49606 - char *s;
49607 + const char *s;
49608
49609 BUG_ON(nd->flags & LOOKUP_RCU);
49610
49611 @@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49612 if (error)
49613 goto out_put_nd_path;
49614
49615 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
49616 + dentry->d_inode, dentry, nd->path.mnt)) {
49617 + error = -EACCES;
49618 + goto out_put_nd_path;
49619 + }
49620 +
49621 nd->last_type = LAST_BIND;
49622 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
49623 error = PTR_ERR(*p);
49624 @@ -1605,6 +1619,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
49625 break;
49626 res = walk_component(nd, path, &nd->last,
49627 nd->last_type, LOOKUP_FOLLOW);
49628 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
49629 + res = -EACCES;
49630 put_link(nd, &link, cookie);
49631 } while (res > 0);
49632
49633 @@ -1703,7 +1719,7 @@ EXPORT_SYMBOL(full_name_hash);
49634 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
49635 {
49636 unsigned long a, b, adata, bdata, mask, hash, len;
49637 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49638 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49639
49640 hash = a = 0;
49641 len = -sizeof(unsigned long);
49642 @@ -1993,6 +2009,8 @@ static int path_lookupat(int dfd, const char *name,
49643 if (err)
49644 break;
49645 err = lookup_last(nd, &path);
49646 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
49647 + err = -EACCES;
49648 put_link(nd, &link, cookie);
49649 }
49650 }
49651 @@ -2000,6 +2018,21 @@ static int path_lookupat(int dfd, const char *name,
49652 if (!err)
49653 err = complete_walk(nd);
49654
49655 + if (!(nd->flags & LOOKUP_PARENT)) {
49656 +#ifdef CONFIG_GRKERNSEC
49657 + if (flags & LOOKUP_RCU) {
49658 + if (!err)
49659 + path_put(&nd->path);
49660 + err = -ECHILD;
49661 + } else
49662 +#endif
49663 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49664 + if (!err)
49665 + path_put(&nd->path);
49666 + err = -ENOENT;
49667 + }
49668 + }
49669 +
49670 if (!err && nd->flags & LOOKUP_DIRECTORY) {
49671 if (!nd->inode->i_op->lookup) {
49672 path_put(&nd->path);
49673 @@ -2027,8 +2060,17 @@ static int filename_lookup(int dfd, struct filename *name,
49674 retval = path_lookupat(dfd, name->name,
49675 flags | LOOKUP_REVAL, nd);
49676
49677 - if (likely(!retval))
49678 + if (likely(!retval)) {
49679 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
49680 +#ifdef CONFIG_GRKERNSEC
49681 + if (flags & LOOKUP_RCU)
49682 + return -ECHILD;
49683 +#endif
49684 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
49685 + return -ENOENT;
49686 + }
49687 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
49688 + }
49689 return retval;
49690 }
49691
49692 @@ -2402,6 +2444,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
49693 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
49694 return -EPERM;
49695
49696 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
49697 + return -EPERM;
49698 + if (gr_handle_rawio(inode))
49699 + return -EPERM;
49700 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
49701 + return -EACCES;
49702 +
49703 return 0;
49704 }
49705
49706 @@ -2623,7 +2672,7 @@ looked_up:
49707 * cleared otherwise prior to returning.
49708 */
49709 static int lookup_open(struct nameidata *nd, struct path *path,
49710 - struct file *file,
49711 + struct path *link, struct file *file,
49712 const struct open_flags *op,
49713 bool got_write, int *opened)
49714 {
49715 @@ -2658,6 +2707,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49716 /* Negative dentry, just create the file */
49717 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
49718 umode_t mode = op->mode;
49719 +
49720 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
49721 + error = -EACCES;
49722 + goto out_dput;
49723 + }
49724 +
49725 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
49726 + error = -EACCES;
49727 + goto out_dput;
49728 + }
49729 +
49730 if (!IS_POSIXACL(dir->d_inode))
49731 mode &= ~current_umask();
49732 /*
49733 @@ -2679,6 +2739,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49734 nd->flags & LOOKUP_EXCL);
49735 if (error)
49736 goto out_dput;
49737 + else
49738 + gr_handle_create(dentry, nd->path.mnt);
49739 }
49740 out_no_open:
49741 path->dentry = dentry;
49742 @@ -2693,7 +2755,7 @@ out_dput:
49743 /*
49744 * Handle the last step of open()
49745 */
49746 -static int do_last(struct nameidata *nd, struct path *path,
49747 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
49748 struct file *file, const struct open_flags *op,
49749 int *opened, struct filename *name)
49750 {
49751 @@ -2722,16 +2784,44 @@ static int do_last(struct nameidata *nd, struct path *path,
49752 error = complete_walk(nd);
49753 if (error)
49754 return error;
49755 +#ifdef CONFIG_GRKERNSEC
49756 + if (nd->flags & LOOKUP_RCU) {
49757 + error = -ECHILD;
49758 + goto out;
49759 + }
49760 +#endif
49761 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49762 + error = -ENOENT;
49763 + goto out;
49764 + }
49765 audit_inode(name, nd->path.dentry, 0);
49766 if (open_flag & O_CREAT) {
49767 error = -EISDIR;
49768 goto out;
49769 }
49770 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49771 + error = -EACCES;
49772 + goto out;
49773 + }
49774 goto finish_open;
49775 case LAST_BIND:
49776 error = complete_walk(nd);
49777 if (error)
49778 return error;
49779 +#ifdef CONFIG_GRKERNSEC
49780 + if (nd->flags & LOOKUP_RCU) {
49781 + error = -ECHILD;
49782 + goto out;
49783 + }
49784 +#endif
49785 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
49786 + error = -ENOENT;
49787 + goto out;
49788 + }
49789 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49790 + error = -EACCES;
49791 + goto out;
49792 + }
49793 audit_inode(name, dir, 0);
49794 goto finish_open;
49795 }
49796 @@ -2780,7 +2870,7 @@ retry_lookup:
49797 */
49798 }
49799 mutex_lock(&dir->d_inode->i_mutex);
49800 - error = lookup_open(nd, path, file, op, got_write, opened);
49801 + error = lookup_open(nd, path, link, file, op, got_write, opened);
49802 mutex_unlock(&dir->d_inode->i_mutex);
49803
49804 if (error <= 0) {
49805 @@ -2804,11 +2894,28 @@ retry_lookup:
49806 goto finish_open_created;
49807 }
49808
49809 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
49810 + error = -ENOENT;
49811 + goto exit_dput;
49812 + }
49813 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
49814 + error = -EACCES;
49815 + goto exit_dput;
49816 + }
49817 +
49818 /*
49819 * create/update audit record if it already exists.
49820 */
49821 - if (path->dentry->d_inode)
49822 + if (path->dentry->d_inode) {
49823 + /* only check if O_CREAT is specified, all other checks need to go
49824 + into may_open */
49825 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
49826 + error = -EACCES;
49827 + goto exit_dput;
49828 + }
49829 +
49830 audit_inode(name, path->dentry, 0);
49831 + }
49832
49833 /*
49834 * If atomic_open() acquired write access it is dropped now due to
49835 @@ -2849,6 +2956,11 @@ finish_lookup:
49836 }
49837 }
49838 BUG_ON(inode != path->dentry->d_inode);
49839 + /* if we're resolving a symlink to another symlink */
49840 + if (link && gr_handle_symlink_owner(link, inode)) {
49841 + error = -EACCES;
49842 + goto out;
49843 + }
49844 return 1;
49845 }
49846
49847 @@ -2858,7 +2970,6 @@ finish_lookup:
49848 save_parent.dentry = nd->path.dentry;
49849 save_parent.mnt = mntget(path->mnt);
49850 nd->path.dentry = path->dentry;
49851 -
49852 }
49853 nd->inode = inode;
49854 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
49855 @@ -2867,6 +2978,22 @@ finish_lookup:
49856 path_put(&save_parent);
49857 return error;
49858 }
49859 +
49860 +#ifdef CONFIG_GRKERNSEC
49861 + if (nd->flags & LOOKUP_RCU) {
49862 + error = -ECHILD;
49863 + goto out;
49864 + }
49865 +#endif
49866 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49867 + error = -ENOENT;
49868 + goto out;
49869 + }
49870 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
49871 + error = -EACCES;
49872 + goto out;
49873 + }
49874 +
49875 error = -EISDIR;
49876 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
49877 goto out;
49878 @@ -2965,7 +3092,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49879 if (unlikely(error))
49880 goto out;
49881
49882 - error = do_last(nd, &path, file, op, &opened, pathname);
49883 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
49884 while (unlikely(error > 0)) { /* trailing symlink */
49885 struct path link = path;
49886 void *cookie;
49887 @@ -2983,7 +3110,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49888 error = follow_link(&link, nd, &cookie);
49889 if (unlikely(error))
49890 break;
49891 - error = do_last(nd, &path, file, op, &opened, pathname);
49892 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
49893 put_link(nd, &link, cookie);
49894 }
49895 out:
49896 @@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
49897 goto unlock;
49898
49899 error = -EEXIST;
49900 - if (dentry->d_inode)
49901 + if (dentry->d_inode) {
49902 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
49903 + error = -ENOENT;
49904 + }
49905 goto fail;
49906 + }
49907 /*
49908 * Special case - lookup gave negative, but... we had foo/bar/
49909 * From the vfs_mknod() POV we just have a negative dentry -
49910 @@ -3125,6 +3256,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
49911 }
49912 EXPORT_SYMBOL(user_path_create);
49913
49914 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, int is_dir)
49915 +{
49916 + struct filename *tmp = getname(pathname);
49917 + struct dentry *res;
49918 + if (IS_ERR(tmp))
49919 + return ERR_CAST(tmp);
49920 + res = kern_path_create(dfd, tmp->name, path, is_dir);
49921 + if (IS_ERR(res))
49922 + putname(tmp);
49923 + else
49924 + *to = tmp;
49925 + return res;
49926 +}
49927 +
49928 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
49929 {
49930 int error = may_create(dir, dentry);
49931 @@ -3186,6 +3331,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49932
49933 if (!IS_POSIXACL(path.dentry->d_inode))
49934 mode &= ~current_umask();
49935 +
49936 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
49937 + error = -EPERM;
49938 + goto out;
49939 + }
49940 +
49941 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
49942 + error = -EACCES;
49943 + goto out;
49944 + }
49945 +
49946 error = security_path_mknod(&path, dentry, mode, dev);
49947 if (error)
49948 goto out;
49949 @@ -3202,6 +3358,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49950 break;
49951 }
49952 out:
49953 + if (!error)
49954 + gr_handle_create(dentry, path.mnt);
49955 done_path_create(&path, dentry);
49956 return error;
49957 }
49958 @@ -3248,9 +3406,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
49959
49960 if (!IS_POSIXACL(path.dentry->d_inode))
49961 mode &= ~current_umask();
49962 +
49963 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
49964 + error = -EACCES;
49965 + goto out;
49966 + }
49967 +
49968 error = security_path_mkdir(&path, dentry, mode);
49969 if (!error)
49970 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
49971 + if (!error)
49972 + gr_handle_create(dentry, path.mnt);
49973 +out:
49974 done_path_create(&path, dentry);
49975 return error;
49976 }
49977 @@ -3327,6 +3494,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
49978 struct filename *name;
49979 struct dentry *dentry;
49980 struct nameidata nd;
49981 + ino_t saved_ino = 0;
49982 + dev_t saved_dev = 0;
49983
49984 name = user_path_parent(dfd, pathname, &nd);
49985 if (IS_ERR(name))
49986 @@ -3358,10 +3527,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
49987 error = -ENOENT;
49988 goto exit3;
49989 }
49990 +
49991 + saved_ino = dentry->d_inode->i_ino;
49992 + saved_dev = gr_get_dev_from_dentry(dentry);
49993 +
49994 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
49995 + error = -EACCES;
49996 + goto exit3;
49997 + }
49998 +
49999 error = security_path_rmdir(&nd.path, dentry);
50000 if (error)
50001 goto exit3;
50002 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
50003 + if (!error && (saved_dev || saved_ino))
50004 + gr_handle_delete(saved_ino, saved_dev);
50005 exit3:
50006 dput(dentry);
50007 exit2:
50008 @@ -3423,6 +3603,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
50009 struct dentry *dentry;
50010 struct nameidata nd;
50011 struct inode *inode = NULL;
50012 + ino_t saved_ino = 0;
50013 + dev_t saved_dev = 0;
50014
50015 name = user_path_parent(dfd, pathname, &nd);
50016 if (IS_ERR(name))
50017 @@ -3448,10 +3630,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
50018 if (!inode)
50019 goto slashes;
50020 ihold(inode);
50021 +
50022 + if (inode->i_nlink <= 1) {
50023 + saved_ino = inode->i_ino;
50024 + saved_dev = gr_get_dev_from_dentry(dentry);
50025 + }
50026 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
50027 + error = -EACCES;
50028 + goto exit2;
50029 + }
50030 +
50031 error = security_path_unlink(&nd.path, dentry);
50032 if (error)
50033 goto exit2;
50034 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
50035 + if (!error && (saved_ino || saved_dev))
50036 + gr_handle_delete(saved_ino, saved_dev);
50037 exit2:
50038 dput(dentry);
50039 }
50040 @@ -3523,9 +3717,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
50041 if (IS_ERR(dentry))
50042 goto out_putname;
50043
50044 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
50045 + error = -EACCES;
50046 + goto out;
50047 + }
50048 +
50049 error = security_path_symlink(&path, dentry, from->name);
50050 if (!error)
50051 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
50052 + if (!error)
50053 + gr_handle_create(dentry, path.mnt);
50054 +out:
50055 done_path_create(&path, dentry);
50056 out_putname:
50057 putname(from);
50058 @@ -3595,6 +3797,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
50059 {
50060 struct dentry *new_dentry;
50061 struct path old_path, new_path;
50062 + struct filename *to = NULL;
50063 int how = 0;
50064 int error;
50065
50066 @@ -3618,7 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
50067 if (error)
50068 return error;
50069
50070 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
50071 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
50072 error = PTR_ERR(new_dentry);
50073 if (IS_ERR(new_dentry))
50074 goto out;
50075 @@ -3629,11 +3832,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
50076 error = may_linkat(&old_path);
50077 if (unlikely(error))
50078 goto out_dput;
50079 +
50080 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
50081 + old_path.dentry->d_inode,
50082 + old_path.dentry->d_inode->i_mode, to)) {
50083 + error = -EACCES;
50084 + goto out_dput;
50085 + }
50086 +
50087 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
50088 + old_path.dentry, old_path.mnt, to)) {
50089 + error = -EACCES;
50090 + goto out_dput;
50091 + }
50092 +
50093 error = security_path_link(old_path.dentry, &new_path, new_dentry);
50094 if (error)
50095 goto out_dput;
50096 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
50097 + if (!error)
50098 + gr_handle_create(new_dentry, new_path.mnt);
50099 out_dput:
50100 + putname(to);
50101 done_path_create(&new_path, new_dentry);
50102 out:
50103 path_put(&old_path);
50104 @@ -3873,12 +4093,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
50105 if (new_dentry == trap)
50106 goto exit5;
50107
50108 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
50109 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
50110 + to);
50111 + if (error)
50112 + goto exit5;
50113 +
50114 error = security_path_rename(&oldnd.path, old_dentry,
50115 &newnd.path, new_dentry);
50116 if (error)
50117 goto exit5;
50118 error = vfs_rename(old_dir->d_inode, old_dentry,
50119 new_dir->d_inode, new_dentry);
50120 + if (!error)
50121 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
50122 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
50123 exit5:
50124 dput(new_dentry);
50125 exit4:
50126 @@ -3903,6 +4132,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
50127
50128 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
50129 {
50130 + char tmpbuf[64];
50131 + const char *newlink;
50132 int len;
50133
50134 len = PTR_ERR(link);
50135 @@ -3912,7 +4143,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
50136 len = strlen(link);
50137 if (len > (unsigned) buflen)
50138 len = buflen;
50139 - if (copy_to_user(buffer, link, len))
50140 +
50141 + if (len < sizeof(tmpbuf)) {
50142 + memcpy(tmpbuf, link, len);
50143 + newlink = tmpbuf;
50144 + } else
50145 + newlink = link;
50146 +
50147 + if (copy_to_user(buffer, newlink, len))
50148 len = -EFAULT;
50149 out:
50150 return len;
50151 diff --git a/fs/namespace.c b/fs/namespace.c
50152 index 2496062..e26f6d6 100644
50153 --- a/fs/namespace.c
50154 +++ b/fs/namespace.c
50155 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
50156 if (!(sb->s_flags & MS_RDONLY))
50157 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
50158 up_write(&sb->s_umount);
50159 +
50160 + gr_log_remount(mnt->mnt_devname, retval);
50161 +
50162 return retval;
50163 }
50164
50165 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
50166 br_write_unlock(&vfsmount_lock);
50167 up_write(&namespace_sem);
50168 release_mounts(&umount_list);
50169 +
50170 + gr_log_unmount(mnt->mnt_devname, retval);
50171 +
50172 return retval;
50173 }
50174
50175 @@ -2244,6 +2250,16 @@ long do_mount(const char *dev_name, const char *dir_name,
50176 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
50177 MS_STRICTATIME);
50178
50179 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
50180 + retval = -EPERM;
50181 + goto dput_out;
50182 + }
50183 +
50184 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
50185 + retval = -EPERM;
50186 + goto dput_out;
50187 + }
50188 +
50189 if (flags & MS_REMOUNT)
50190 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
50191 data_page);
50192 @@ -2258,6 +2274,9 @@ long do_mount(const char *dev_name, const char *dir_name,
50193 dev_name, data_page);
50194 dput_out:
50195 path_put(&path);
50196 +
50197 + gr_log_mount(dev_name, dir_name, retval);
50198 +
50199 return retval;
50200 }
50201
50202 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
50203 if (error)
50204 goto out2;
50205
50206 + if (gr_handle_chroot_pivot()) {
50207 + error = -EPERM;
50208 + goto out2;
50209 + }
50210 +
50211 get_fs_root(current->fs, &root);
50212 error = lock_mount(&old);
50213 if (error)
50214 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
50215 index 6fa01ae..2790820 100644
50216 --- a/fs/nfs/inode.c
50217 +++ b/fs/nfs/inode.c
50218 @@ -1029,16 +1029,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
50219 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
50220 }
50221
50222 -static atomic_long_t nfs_attr_generation_counter;
50223 +static atomic_long_unchecked_t nfs_attr_generation_counter;
50224
50225 static unsigned long nfs_read_attr_generation_counter(void)
50226 {
50227 - return atomic_long_read(&nfs_attr_generation_counter);
50228 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
50229 }
50230
50231 unsigned long nfs_inc_attr_generation_counter(void)
50232 {
50233 - return atomic_long_inc_return(&nfs_attr_generation_counter);
50234 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
50235 }
50236
50237 void nfs_fattr_init(struct nfs_fattr *fattr)
50238 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
50239 index f59169e..fd7d359 100644
50240 --- a/fs/nfsd/vfs.c
50241 +++ b/fs/nfsd/vfs.c
50242 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
50243 } else {
50244 oldfs = get_fs();
50245 set_fs(KERNEL_DS);
50246 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
50247 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
50248 set_fs(oldfs);
50249 }
50250
50251 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
50252
50253 /* Write the data. */
50254 oldfs = get_fs(); set_fs(KERNEL_DS);
50255 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
50256 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
50257 set_fs(oldfs);
50258 if (host_err < 0)
50259 goto out_nfserr;
50260 @@ -1587,7 +1587,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
50261 */
50262
50263 oldfs = get_fs(); set_fs(KERNEL_DS);
50264 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
50265 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
50266 set_fs(oldfs);
50267
50268 if (host_err < 0)
50269 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
50270 index 6fcaeb8..9d16d04 100644
50271 --- a/fs/notify/fanotify/fanotify_user.c
50272 +++ b/fs/notify/fanotify/fanotify_user.c
50273 @@ -250,8 +250,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
50274
50275 fd = fanotify_event_metadata.fd;
50276 ret = -EFAULT;
50277 - if (copy_to_user(buf, &fanotify_event_metadata,
50278 - fanotify_event_metadata.event_len))
50279 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
50280 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
50281 goto out_close_fd;
50282
50283 ret = prepare_for_access_response(group, event, fd);
50284 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
50285 index c887b13..0fdf472 100644
50286 --- a/fs/notify/notification.c
50287 +++ b/fs/notify/notification.c
50288 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
50289 * get set to 0 so it will never get 'freed'
50290 */
50291 static struct fsnotify_event *q_overflow_event;
50292 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50293 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50294
50295 /**
50296 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
50297 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
50298 */
50299 u32 fsnotify_get_cookie(void)
50300 {
50301 - return atomic_inc_return(&fsnotify_sync_cookie);
50302 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
50303 }
50304 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
50305
50306 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
50307 index 99e3610..02c1068 100644
50308 --- a/fs/ntfs/dir.c
50309 +++ b/fs/ntfs/dir.c
50310 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
50311 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
50312 ~(s64)(ndir->itype.index.block_size - 1)));
50313 /* Bounds checks. */
50314 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
50315 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
50316 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
50317 "inode 0x%lx or driver bug.", vdir->i_ino);
50318 goto err_out;
50319 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
50320 index 1ecf464..e1ff8bf 100644
50321 --- a/fs/ntfs/file.c
50322 +++ b/fs/ntfs/file.c
50323 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
50324 #endif /* NTFS_RW */
50325 };
50326
50327 -const struct file_operations ntfs_empty_file_ops = {};
50328 +const struct file_operations ntfs_empty_file_ops __read_only;
50329
50330 -const struct inode_operations ntfs_empty_inode_ops = {};
50331 +const struct inode_operations ntfs_empty_inode_ops __read_only;
50332 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
50333 index a9f78c7..ed8a381 100644
50334 --- a/fs/ocfs2/localalloc.c
50335 +++ b/fs/ocfs2/localalloc.c
50336 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
50337 goto bail;
50338 }
50339
50340 - atomic_inc(&osb->alloc_stats.moves);
50341 + atomic_inc_unchecked(&osb->alloc_stats.moves);
50342
50343 bail:
50344 if (handle)
50345 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
50346 index d355e6e..578d905 100644
50347 --- a/fs/ocfs2/ocfs2.h
50348 +++ b/fs/ocfs2/ocfs2.h
50349 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
50350
50351 struct ocfs2_alloc_stats
50352 {
50353 - atomic_t moves;
50354 - atomic_t local_data;
50355 - atomic_t bitmap_data;
50356 - atomic_t bg_allocs;
50357 - atomic_t bg_extends;
50358 + atomic_unchecked_t moves;
50359 + atomic_unchecked_t local_data;
50360 + atomic_unchecked_t bitmap_data;
50361 + atomic_unchecked_t bg_allocs;
50362 + atomic_unchecked_t bg_extends;
50363 };
50364
50365 enum ocfs2_local_alloc_state
50366 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
50367 index f169da4..9112253 100644
50368 --- a/fs/ocfs2/suballoc.c
50369 +++ b/fs/ocfs2/suballoc.c
50370 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
50371 mlog_errno(status);
50372 goto bail;
50373 }
50374 - atomic_inc(&osb->alloc_stats.bg_extends);
50375 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
50376
50377 /* You should never ask for this much metadata */
50378 BUG_ON(bits_wanted >
50379 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
50380 mlog_errno(status);
50381 goto bail;
50382 }
50383 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50384 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50385
50386 *suballoc_loc = res.sr_bg_blkno;
50387 *suballoc_bit_start = res.sr_bit_offset;
50388 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
50389 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
50390 res->sr_bits);
50391
50392 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50393 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50394
50395 BUG_ON(res->sr_bits != 1);
50396
50397 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
50398 mlog_errno(status);
50399 goto bail;
50400 }
50401 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50402 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
50403
50404 BUG_ON(res.sr_bits != 1);
50405
50406 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
50407 cluster_start,
50408 num_clusters);
50409 if (!status)
50410 - atomic_inc(&osb->alloc_stats.local_data);
50411 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
50412 } else {
50413 if (min_clusters > (osb->bitmap_cpg - 1)) {
50414 /* The only paths asking for contiguousness
50415 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
50416 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
50417 res.sr_bg_blkno,
50418 res.sr_bit_offset);
50419 - atomic_inc(&osb->alloc_stats.bitmap_data);
50420 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
50421 *num_clusters = res.sr_bits;
50422 }
50423 }
50424 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
50425 index 0e91ec2..f4b3fc6 100644
50426 --- a/fs/ocfs2/super.c
50427 +++ b/fs/ocfs2/super.c
50428 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
50429 "%10s => GlobalAllocs: %d LocalAllocs: %d "
50430 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
50431 "Stats",
50432 - atomic_read(&osb->alloc_stats.bitmap_data),
50433 - atomic_read(&osb->alloc_stats.local_data),
50434 - atomic_read(&osb->alloc_stats.bg_allocs),
50435 - atomic_read(&osb->alloc_stats.moves),
50436 - atomic_read(&osb->alloc_stats.bg_extends));
50437 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
50438 + atomic_read_unchecked(&osb->alloc_stats.local_data),
50439 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
50440 + atomic_read_unchecked(&osb->alloc_stats.moves),
50441 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
50442
50443 out += snprintf(buf + out, len - out,
50444 "%10s => State: %u Descriptor: %llu Size: %u bits "
50445 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
50446 spin_lock_init(&osb->osb_xattr_lock);
50447 ocfs2_init_steal_slots(osb);
50448
50449 - atomic_set(&osb->alloc_stats.moves, 0);
50450 - atomic_set(&osb->alloc_stats.local_data, 0);
50451 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
50452 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
50453 - atomic_set(&osb->alloc_stats.bg_extends, 0);
50454 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
50455 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
50456 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
50457 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
50458 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
50459
50460 /* Copy the blockcheck stats from the superblock probe */
50461 osb->osb_ecc_stats = *stats;
50462 diff --git a/fs/open.c b/fs/open.c
50463 index 59071f5..c6229a0 100644
50464 --- a/fs/open.c
50465 +++ b/fs/open.c
50466 @@ -31,6 +31,8 @@
50467 #include <linux/ima.h>
50468 #include <linux/dnotify.h>
50469
50470 +#define CREATE_TRACE_POINTS
50471 +#include <trace/events/fs.h>
50472 #include "internal.h"
50473
50474 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
50475 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
50476 error = locks_verify_truncate(inode, NULL, length);
50477 if (!error)
50478 error = security_path_truncate(&path);
50479 +
50480 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
50481 + error = -EACCES;
50482 +
50483 if (!error)
50484 error = do_truncate(path.dentry, length, 0, NULL);
50485
50486 @@ -362,6 +368,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
50487 if (__mnt_is_readonly(path.mnt))
50488 res = -EROFS;
50489
50490 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
50491 + res = -EACCES;
50492 +
50493 out_path_release:
50494 path_put(&path);
50495 out:
50496 @@ -388,6 +397,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
50497 if (error)
50498 goto dput_and_out;
50499
50500 + gr_log_chdir(path.dentry, path.mnt);
50501 +
50502 set_fs_pwd(current->fs, &path);
50503
50504 dput_and_out:
50505 @@ -413,6 +424,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
50506 goto out_putf;
50507
50508 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
50509 +
50510 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
50511 + error = -EPERM;
50512 +
50513 + if (!error)
50514 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
50515 +
50516 if (!error)
50517 set_fs_pwd(current->fs, &f.file->f_path);
50518 out_putf:
50519 @@ -441,7 +459,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
50520 if (error)
50521 goto dput_and_out;
50522
50523 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
50524 + goto dput_and_out;
50525 +
50526 set_fs_root(current->fs, &path);
50527 +
50528 + gr_handle_chroot_chdir(&path);
50529 +
50530 error = 0;
50531 dput_and_out:
50532 path_put(&path);
50533 @@ -459,6 +483,16 @@ static int chmod_common(struct path *path, umode_t mode)
50534 if (error)
50535 return error;
50536 mutex_lock(&inode->i_mutex);
50537 +
50538 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
50539 + error = -EACCES;
50540 + goto out_unlock;
50541 + }
50542 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
50543 + error = -EACCES;
50544 + goto out_unlock;
50545 + }
50546 +
50547 error = security_path_chmod(path, mode);
50548 if (error)
50549 goto out_unlock;
50550 @@ -514,6 +548,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
50551 uid = make_kuid(current_user_ns(), user);
50552 gid = make_kgid(current_user_ns(), group);
50553
50554 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
50555 + return -EACCES;
50556 +
50557 newattrs.ia_valid = ATTR_CTIME;
50558 if (user != (uid_t) -1) {
50559 if (!uid_valid(uid))
50560 @@ -925,6 +962,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
50561 } else {
50562 fsnotify_open(f);
50563 fd_install(fd, f);
50564 + trace_do_sys_open(tmp->name, flags, mode);
50565 }
50566 }
50567 putname(tmp);
50568 diff --git a/fs/pipe.c b/fs/pipe.c
50569 index bd3479d..fb92c4d 100644
50570 --- a/fs/pipe.c
50571 +++ b/fs/pipe.c
50572 @@ -438,9 +438,9 @@ redo:
50573 }
50574 if (bufs) /* More to do? */
50575 continue;
50576 - if (!pipe->writers)
50577 + if (!atomic_read(&pipe->writers))
50578 break;
50579 - if (!pipe->waiting_writers) {
50580 + if (!atomic_read(&pipe->waiting_writers)) {
50581 /* syscall merging: Usually we must not sleep
50582 * if O_NONBLOCK is set, or if we got some data.
50583 * But if a writer sleeps in kernel space, then
50584 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
50585 mutex_lock(&inode->i_mutex);
50586 pipe = inode->i_pipe;
50587
50588 - if (!pipe->readers) {
50589 + if (!atomic_read(&pipe->readers)) {
50590 send_sig(SIGPIPE, current, 0);
50591 ret = -EPIPE;
50592 goto out;
50593 @@ -553,7 +553,7 @@ redo1:
50594 for (;;) {
50595 int bufs;
50596
50597 - if (!pipe->readers) {
50598 + if (!atomic_read(&pipe->readers)) {
50599 send_sig(SIGPIPE, current, 0);
50600 if (!ret)
50601 ret = -EPIPE;
50602 @@ -644,9 +644,9 @@ redo2:
50603 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50604 do_wakeup = 0;
50605 }
50606 - pipe->waiting_writers++;
50607 + atomic_inc(&pipe->waiting_writers);
50608 pipe_wait(pipe);
50609 - pipe->waiting_writers--;
50610 + atomic_dec(&pipe->waiting_writers);
50611 }
50612 out:
50613 mutex_unlock(&inode->i_mutex);
50614 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50615 mask = 0;
50616 if (filp->f_mode & FMODE_READ) {
50617 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
50618 - if (!pipe->writers && filp->f_version != pipe->w_counter)
50619 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
50620 mask |= POLLHUP;
50621 }
50622
50623 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50624 * Most Unices do not set POLLERR for FIFOs but on Linux they
50625 * behave exactly like pipes for poll().
50626 */
50627 - if (!pipe->readers)
50628 + if (!atomic_read(&pipe->readers))
50629 mask |= POLLERR;
50630 }
50631
50632 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
50633
50634 mutex_lock(&inode->i_mutex);
50635 pipe = inode->i_pipe;
50636 - pipe->readers -= decr;
50637 - pipe->writers -= decw;
50638 + atomic_sub(decr, &pipe->readers);
50639 + atomic_sub(decw, &pipe->writers);
50640
50641 - if (!pipe->readers && !pipe->writers) {
50642 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
50643 free_pipe_info(inode);
50644 } else {
50645 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
50646 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
50647
50648 if (inode->i_pipe) {
50649 ret = 0;
50650 - inode->i_pipe->readers++;
50651 + atomic_inc(&inode->i_pipe->readers);
50652 }
50653
50654 mutex_unlock(&inode->i_mutex);
50655 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
50656
50657 if (inode->i_pipe) {
50658 ret = 0;
50659 - inode->i_pipe->writers++;
50660 + atomic_inc(&inode->i_pipe->writers);
50661 }
50662
50663 mutex_unlock(&inode->i_mutex);
50664 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
50665 if (inode->i_pipe) {
50666 ret = 0;
50667 if (filp->f_mode & FMODE_READ)
50668 - inode->i_pipe->readers++;
50669 + atomic_inc(&inode->i_pipe->readers);
50670 if (filp->f_mode & FMODE_WRITE)
50671 - inode->i_pipe->writers++;
50672 + atomic_inc(&inode->i_pipe->writers);
50673 }
50674
50675 mutex_unlock(&inode->i_mutex);
50676 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
50677 inode->i_pipe = NULL;
50678 }
50679
50680 -static struct vfsmount *pipe_mnt __read_mostly;
50681 +struct vfsmount *pipe_mnt __read_mostly;
50682
50683 /*
50684 * pipefs_dname() is called from d_path().
50685 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
50686 goto fail_iput;
50687 inode->i_pipe = pipe;
50688
50689 - pipe->readers = pipe->writers = 1;
50690 + atomic_set(&pipe->readers, 1);
50691 + atomic_set(&pipe->writers, 1);
50692 inode->i_fop = &rdwr_pipefifo_fops;
50693
50694 /*
50695 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
50696 index 15af622..0e9f4467 100644
50697 --- a/fs/proc/Kconfig
50698 +++ b/fs/proc/Kconfig
50699 @@ -30,12 +30,12 @@ config PROC_FS
50700
50701 config PROC_KCORE
50702 bool "/proc/kcore support" if !ARM
50703 - depends on PROC_FS && MMU
50704 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
50705
50706 config PROC_VMCORE
50707 bool "/proc/vmcore support"
50708 - depends on PROC_FS && CRASH_DUMP
50709 - default y
50710 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
50711 + default n
50712 help
50713 Exports the dump image of crashed kernel in ELF format.
50714
50715 @@ -59,8 +59,8 @@ config PROC_SYSCTL
50716 limited in memory.
50717
50718 config PROC_PAGE_MONITOR
50719 - default y
50720 - depends on PROC_FS && MMU
50721 + default n
50722 + depends on PROC_FS && MMU && !GRKERNSEC
50723 bool "Enable /proc page monitoring" if EXPERT
50724 help
50725 Various /proc files exist to monitor process memory utilization:
50726 diff --git a/fs/proc/array.c b/fs/proc/array.c
50727 index bd31e02..15cae71 100644
50728 --- a/fs/proc/array.c
50729 +++ b/fs/proc/array.c
50730 @@ -60,6 +60,7 @@
50731 #include <linux/tty.h>
50732 #include <linux/string.h>
50733 #include <linux/mman.h>
50734 +#include <linux/grsecurity.h>
50735 #include <linux/proc_fs.h>
50736 #include <linux/ioport.h>
50737 #include <linux/uaccess.h>
50738 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
50739 seq_putc(m, '\n');
50740 }
50741
50742 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50743 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
50744 +{
50745 + if (p->mm)
50746 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
50747 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
50748 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
50749 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
50750 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
50751 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
50752 + else
50753 + seq_printf(m, "PaX:\t-----\n");
50754 +}
50755 +#endif
50756 +
50757 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50758 struct pid *pid, struct task_struct *task)
50759 {
50760 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50761 task_cpus_allowed(m, task);
50762 cpuset_task_status_allowed(m, task);
50763 task_context_switch_counts(m, task);
50764 +
50765 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50766 + task_pax(m, task);
50767 +#endif
50768 +
50769 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
50770 + task_grsec_rbac(m, task);
50771 +#endif
50772 +
50773 return 0;
50774 }
50775
50776 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50777 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50778 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50779 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50780 +#endif
50781 +
50782 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50783 struct pid *pid, struct task_struct *task, int whole)
50784 {
50785 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50786 char tcomm[sizeof(task->comm)];
50787 unsigned long flags;
50788
50789 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50790 + if (current->exec_id != m->exec_id) {
50791 + gr_log_badprocpid("stat");
50792 + return 0;
50793 + }
50794 +#endif
50795 +
50796 state = *get_task_state(task);
50797 vsize = eip = esp = 0;
50798 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50799 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50800 gtime = task->gtime;
50801 }
50802
50803 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50804 + if (PAX_RAND_FLAGS(mm)) {
50805 + eip = 0;
50806 + esp = 0;
50807 + wchan = 0;
50808 + }
50809 +#endif
50810 +#ifdef CONFIG_GRKERNSEC_HIDESYM
50811 + wchan = 0;
50812 + eip =0;
50813 + esp =0;
50814 +#endif
50815 +
50816 /* scale priority and nice values from timeslices to -20..20 */
50817 /* to make it look like a "normal" Unix priority/nice value */
50818 priority = task_prio(task);
50819 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50820 seq_put_decimal_ull(m, ' ', vsize);
50821 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
50822 seq_put_decimal_ull(m, ' ', rsslim);
50823 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50824 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
50825 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
50826 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
50827 +#else
50828 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
50829 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
50830 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
50831 +#endif
50832 seq_put_decimal_ull(m, ' ', esp);
50833 seq_put_decimal_ull(m, ' ', eip);
50834 /* The signal information here is obsolete.
50835 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50836 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
50837 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
50838
50839 - if (mm && permitted) {
50840 + if (mm && permitted
50841 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50842 + && !PAX_RAND_FLAGS(mm)
50843 +#endif
50844 + ) {
50845 seq_put_decimal_ull(m, ' ', mm->start_data);
50846 seq_put_decimal_ull(m, ' ', mm->end_data);
50847 seq_put_decimal_ull(m, ' ', mm->start_brk);
50848 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50849 struct pid *pid, struct task_struct *task)
50850 {
50851 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
50852 - struct mm_struct *mm = get_task_mm(task);
50853 + struct mm_struct *mm;
50854
50855 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50856 + if (current->exec_id != m->exec_id) {
50857 + gr_log_badprocpid("statm");
50858 + return 0;
50859 + }
50860 +#endif
50861 + mm = get_task_mm(task);
50862 if (mm) {
50863 size = task_statm(mm, &shared, &text, &data, &resident);
50864 mmput(mm);
50865 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50866 return 0;
50867 }
50868
50869 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50870 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
50871 +{
50872 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
50873 +}
50874 +#endif
50875 +
50876 #ifdef CONFIG_CHECKPOINT_RESTORE
50877 static struct pid *
50878 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
50879 diff --git a/fs/proc/base.c b/fs/proc/base.c
50880 index 9e28356..c485b3c 100644
50881 --- a/fs/proc/base.c
50882 +++ b/fs/proc/base.c
50883 @@ -111,6 +111,14 @@ struct pid_entry {
50884 union proc_op op;
50885 };
50886
50887 +struct getdents_callback {
50888 + struct linux_dirent __user * current_dir;
50889 + struct linux_dirent __user * previous;
50890 + struct file * file;
50891 + int count;
50892 + int error;
50893 +};
50894 +
50895 #define NOD(NAME, MODE, IOP, FOP, OP) { \
50896 .name = (NAME), \
50897 .len = sizeof(NAME) - 1, \
50898 @@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
50899 if (!mm->arg_end)
50900 goto out_mm; /* Shh! No looking before we're done */
50901
50902 + if (gr_acl_handle_procpidmem(task))
50903 + goto out_mm;
50904 +
50905 len = mm->arg_end - mm->arg_start;
50906
50907 if (len > PAGE_SIZE)
50908 @@ -235,12 +246,28 @@ out:
50909 return res;
50910 }
50911
50912 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50913 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50914 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
50915 + _mm->pax_flags & MF_PAX_SEGMEXEC))
50916 +#endif
50917 +
50918 static int proc_pid_auxv(struct task_struct *task, char *buffer)
50919 {
50920 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
50921 int res = PTR_ERR(mm);
50922 if (mm && !IS_ERR(mm)) {
50923 unsigned int nwords = 0;
50924 +
50925 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50926 + /* allow if we're currently ptracing this task */
50927 + if (PAX_RAND_FLAGS(mm) &&
50928 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
50929 + mmput(mm);
50930 + return 0;
50931 + }
50932 +#endif
50933 +
50934 do {
50935 nwords += 2;
50936 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
50937 @@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
50938 }
50939
50940
50941 -#ifdef CONFIG_KALLSYMS
50942 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50943 /*
50944 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
50945 * Returns the resolved symbol. If that fails, simply return the address.
50946 @@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
50947 mutex_unlock(&task->signal->cred_guard_mutex);
50948 }
50949
50950 -#ifdef CONFIG_STACKTRACE
50951 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50952
50953 #define MAX_STACK_TRACE_DEPTH 64
50954
50955 @@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
50956 return count;
50957 }
50958
50959 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50960 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50961 static int proc_pid_syscall(struct task_struct *task, char *buffer)
50962 {
50963 long nr;
50964 @@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
50965 /************************************************************************/
50966
50967 /* permission checks */
50968 -static int proc_fd_access_allowed(struct inode *inode)
50969 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
50970 {
50971 struct task_struct *task;
50972 int allowed = 0;
50973 @@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
50974 */
50975 task = get_proc_task(inode);
50976 if (task) {
50977 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50978 + if (log)
50979 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50980 + else
50981 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50982 put_task_struct(task);
50983 }
50984 return allowed;
50985 @@ -562,10 +592,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
50986 struct task_struct *task,
50987 int hide_pid_min)
50988 {
50989 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50990 + return false;
50991 +
50992 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50993 + rcu_read_lock();
50994 + {
50995 + const struct cred *tmpcred = current_cred();
50996 + const struct cred *cred = __task_cred(task);
50997 +
50998 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
50999 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51000 + || in_group_p(grsec_proc_gid)
51001 +#endif
51002 + ) {
51003 + rcu_read_unlock();
51004 + return true;
51005 + }
51006 + }
51007 + rcu_read_unlock();
51008 +
51009 + if (!pid->hide_pid)
51010 + return false;
51011 +#endif
51012 +
51013 if (pid->hide_pid < hide_pid_min)
51014 return true;
51015 if (in_group_p(pid->pid_gid))
51016 return true;
51017 +
51018 return ptrace_may_access(task, PTRACE_MODE_READ);
51019 }
51020
51021 @@ -583,7 +638,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
51022 put_task_struct(task);
51023
51024 if (!has_perms) {
51025 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51026 + {
51027 +#else
51028 if (pid->hide_pid == 2) {
51029 +#endif
51030 /*
51031 * Let's make getdents(), stat(), and open()
51032 * consistent with each other. If a process
51033 @@ -681,6 +740,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
51034 if (!task)
51035 return -ESRCH;
51036
51037 + if (gr_acl_handle_procpidmem(task)) {
51038 + put_task_struct(task);
51039 + return -EPERM;
51040 + }
51041 +
51042 mm = mm_access(task, mode);
51043 put_task_struct(task);
51044
51045 @@ -696,6 +760,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
51046
51047 file->private_data = mm;
51048
51049 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51050 + file->f_version = current->exec_id;
51051 +#endif
51052 +
51053 return 0;
51054 }
51055
51056 @@ -717,6 +785,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
51057 ssize_t copied;
51058 char *page;
51059
51060 +#ifdef CONFIG_GRKERNSEC
51061 + if (write)
51062 + return -EPERM;
51063 +#endif
51064 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51065 + if (file->f_version != current->exec_id) {
51066 + gr_log_badprocpid("mem");
51067 + return 0;
51068 + }
51069 +#endif
51070 +
51071 if (!mm)
51072 return 0;
51073
51074 @@ -821,6 +900,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
51075 if (!mm)
51076 return 0;
51077
51078 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51079 + if (file->f_version != current->exec_id) {
51080 + gr_log_badprocpid("environ");
51081 + return 0;
51082 + }
51083 +#endif
51084 +
51085 page = (char *)__get_free_page(GFP_TEMPORARY);
51086 if (!page)
51087 return -ENOMEM;
51088 @@ -1436,7 +1522,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
51089 int error = -EACCES;
51090
51091 /* Are we allowed to snoop on the tasks file descriptors? */
51092 - if (!proc_fd_access_allowed(inode))
51093 + if (!proc_fd_access_allowed(inode, 0))
51094 goto out;
51095
51096 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51097 @@ -1480,8 +1566,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
51098 struct path path;
51099
51100 /* Are we allowed to snoop on the tasks file descriptors? */
51101 - if (!proc_fd_access_allowed(inode))
51102 - goto out;
51103 + /* logging this is needed for learning on chromium to work properly,
51104 + but we don't want to flood the logs from 'ps' which does a readlink
51105 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
51106 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
51107 + */
51108 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
51109 + if (!proc_fd_access_allowed(inode,0))
51110 + goto out;
51111 + } else {
51112 + if (!proc_fd_access_allowed(inode,1))
51113 + goto out;
51114 + }
51115
51116 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51117 if (error)
51118 @@ -1531,7 +1627,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
51119 rcu_read_lock();
51120 cred = __task_cred(task);
51121 inode->i_uid = cred->euid;
51122 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51123 + inode->i_gid = grsec_proc_gid;
51124 +#else
51125 inode->i_gid = cred->egid;
51126 +#endif
51127 rcu_read_unlock();
51128 }
51129 security_task_to_inode(task, inode);
51130 @@ -1567,10 +1667,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
51131 return -ENOENT;
51132 }
51133 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51134 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51135 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51136 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51137 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51138 +#endif
51139 task_dumpable(task)) {
51140 cred = __task_cred(task);
51141 stat->uid = cred->euid;
51142 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51143 + stat->gid = grsec_proc_gid;
51144 +#else
51145 stat->gid = cred->egid;
51146 +#endif
51147 }
51148 }
51149 rcu_read_unlock();
51150 @@ -1608,11 +1717,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
51151
51152 if (task) {
51153 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51154 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51155 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51156 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51157 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51158 +#endif
51159 task_dumpable(task)) {
51160 rcu_read_lock();
51161 cred = __task_cred(task);
51162 inode->i_uid = cred->euid;
51163 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51164 + inode->i_gid = grsec_proc_gid;
51165 +#else
51166 inode->i_gid = cred->egid;
51167 +#endif
51168 rcu_read_unlock();
51169 } else {
51170 inode->i_uid = GLOBAL_ROOT_UID;
51171 @@ -2065,6 +2183,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
51172 if (!task)
51173 goto out_no_task;
51174
51175 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51176 + goto out;
51177 +
51178 /*
51179 * Yes, it does not scale. And it should not. Don't add
51180 * new entries into /proc/<tgid>/ without very good reasons.
51181 @@ -2109,6 +2230,9 @@ static int proc_pident_readdir(struct file *filp,
51182 if (!task)
51183 goto out_no_task;
51184
51185 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51186 + goto out;
51187 +
51188 ret = 0;
51189 i = filp->f_pos;
51190 switch (i) {
51191 @@ -2380,7 +2504,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
51192 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
51193 void *cookie)
51194 {
51195 - char *s = nd_get_link(nd);
51196 + const char *s = nd_get_link(nd);
51197 if (!IS_ERR(s))
51198 kfree(s);
51199 }
51200 @@ -2662,7 +2786,7 @@ static const struct pid_entry tgid_base_stuff[] = {
51201 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
51202 #endif
51203 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51204 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51205 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51206 INF("syscall", S_IRUGO, proc_pid_syscall),
51207 #endif
51208 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51209 @@ -2687,10 +2811,10 @@ static const struct pid_entry tgid_base_stuff[] = {
51210 #ifdef CONFIG_SECURITY
51211 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51212 #endif
51213 -#ifdef CONFIG_KALLSYMS
51214 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51215 INF("wchan", S_IRUGO, proc_pid_wchan),
51216 #endif
51217 -#ifdef CONFIG_STACKTRACE
51218 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51219 ONE("stack", S_IRUGO, proc_pid_stack),
51220 #endif
51221 #ifdef CONFIG_SCHEDSTATS
51222 @@ -2724,6 +2848,9 @@ static const struct pid_entry tgid_base_stuff[] = {
51223 #ifdef CONFIG_HARDWALL
51224 INF("hardwall", S_IRUGO, proc_pid_hardwall),
51225 #endif
51226 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51227 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
51228 +#endif
51229 #ifdef CONFIG_USER_NS
51230 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
51231 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
51232 @@ -2856,7 +2983,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
51233 if (!inode)
51234 goto out;
51235
51236 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51237 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
51238 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51239 + inode->i_gid = grsec_proc_gid;
51240 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
51241 +#else
51242 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
51243 +#endif
51244 inode->i_op = &proc_tgid_base_inode_operations;
51245 inode->i_fop = &proc_tgid_base_operations;
51246 inode->i_flags|=S_IMMUTABLE;
51247 @@ -2898,7 +3032,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
51248 if (!task)
51249 goto out;
51250
51251 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51252 + goto out_put_task;
51253 +
51254 result = proc_pid_instantiate(dir, dentry, task, NULL);
51255 +out_put_task:
51256 put_task_struct(task);
51257 out:
51258 return result;
51259 @@ -2961,6 +3099,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
51260 static int fake_filldir(void *buf, const char *name, int namelen,
51261 loff_t offset, u64 ino, unsigned d_type)
51262 {
51263 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
51264 + __buf->error = -EINVAL;
51265 return 0;
51266 }
51267
51268 @@ -3027,7 +3167,7 @@ static const struct pid_entry tid_base_stuff[] = {
51269 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
51270 #endif
51271 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51272 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51273 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51274 INF("syscall", S_IRUGO, proc_pid_syscall),
51275 #endif
51276 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51277 @@ -3054,10 +3194,10 @@ static const struct pid_entry tid_base_stuff[] = {
51278 #ifdef CONFIG_SECURITY
51279 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51280 #endif
51281 -#ifdef CONFIG_KALLSYMS
51282 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51283 INF("wchan", S_IRUGO, proc_pid_wchan),
51284 #endif
51285 -#ifdef CONFIG_STACKTRACE
51286 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51287 ONE("stack", S_IRUGO, proc_pid_stack),
51288 #endif
51289 #ifdef CONFIG_SCHEDSTATS
51290 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
51291 index 82676e3..5f8518a 100644
51292 --- a/fs/proc/cmdline.c
51293 +++ b/fs/proc/cmdline.c
51294 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
51295
51296 static int __init proc_cmdline_init(void)
51297 {
51298 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51299 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
51300 +#else
51301 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
51302 +#endif
51303 return 0;
51304 }
51305 module_init(proc_cmdline_init);
51306 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
51307 index b143471..bb105e5 100644
51308 --- a/fs/proc/devices.c
51309 +++ b/fs/proc/devices.c
51310 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
51311
51312 static int __init proc_devices_init(void)
51313 {
51314 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51315 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
51316 +#else
51317 proc_create("devices", 0, NULL, &proc_devinfo_operations);
51318 +#endif
51319 return 0;
51320 }
51321 module_init(proc_devices_init);
51322 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
51323 index f28a875..c467953 100644
51324 --- a/fs/proc/fd.c
51325 +++ b/fs/proc/fd.c
51326 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
51327 if (!task)
51328 return -ENOENT;
51329
51330 - files = get_files_struct(task);
51331 + if (!gr_acl_handle_procpidmem(task))
51332 + files = get_files_struct(task);
51333 put_task_struct(task);
51334
51335 if (files) {
51336 @@ -300,11 +301,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
51337 */
51338 int proc_fd_permission(struct inode *inode, int mask)
51339 {
51340 + struct task_struct *task;
51341 int rv = generic_permission(inode, mask);
51342 - if (rv == 0)
51343 - return 0;
51344 +
51345 if (task_pid(current) == proc_pid(inode))
51346 rv = 0;
51347 +
51348 + task = get_proc_task(inode);
51349 + if (task == NULL)
51350 + return rv;
51351 +
51352 + if (gr_acl_handle_procpidmem(task))
51353 + rv = -EACCES;
51354 +
51355 + put_task_struct(task);
51356 +
51357 return rv;
51358 }
51359
51360 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
51361 index 3b22bbd..895b58c 100644
51362 --- a/fs/proc/inode.c
51363 +++ b/fs/proc/inode.c
51364 @@ -21,11 +21,17 @@
51365 #include <linux/seq_file.h>
51366 #include <linux/slab.h>
51367 #include <linux/mount.h>
51368 +#include <linux/grsecurity.h>
51369
51370 #include <asm/uaccess.h>
51371
51372 #include "internal.h"
51373
51374 +#ifdef CONFIG_PROC_SYSCTL
51375 +extern const struct inode_operations proc_sys_inode_operations;
51376 +extern const struct inode_operations proc_sys_dir_operations;
51377 +#endif
51378 +
51379 static void proc_evict_inode(struct inode *inode)
51380 {
51381 struct proc_dir_entry *de;
51382 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
51383 ns_ops = PROC_I(inode)->ns_ops;
51384 if (ns_ops && ns_ops->put)
51385 ns_ops->put(PROC_I(inode)->ns);
51386 +
51387 +#ifdef CONFIG_PROC_SYSCTL
51388 + if (inode->i_op == &proc_sys_inode_operations ||
51389 + inode->i_op == &proc_sys_dir_operations)
51390 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
51391 +#endif
51392 +
51393 }
51394
51395 static struct kmem_cache * proc_inode_cachep;
51396 @@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
51397 if (de->mode) {
51398 inode->i_mode = de->mode;
51399 inode->i_uid = de->uid;
51400 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51401 + inode->i_gid = grsec_proc_gid;
51402 +#else
51403 inode->i_gid = de->gid;
51404 +#endif
51405 }
51406 if (de->size)
51407 inode->i_size = de->size;
51408 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
51409 index 43973b0..a20e704 100644
51410 --- a/fs/proc/internal.h
51411 +++ b/fs/proc/internal.h
51412 @@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51413 struct pid *pid, struct task_struct *task);
51414 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51415 struct pid *pid, struct task_struct *task);
51416 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51417 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
51418 +#endif
51419 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
51420
51421 extern const struct file_operations proc_tid_children_operations;
51422 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
51423 index 86c67ee..cdca321 100644
51424 --- a/fs/proc/kcore.c
51425 +++ b/fs/proc/kcore.c
51426 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51427 * the addresses in the elf_phdr on our list.
51428 */
51429 start = kc_offset_to_vaddr(*fpos - elf_buflen);
51430 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
51431 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
51432 + if (tsz > buflen)
51433 tsz = buflen;
51434 -
51435 +
51436 while (buflen) {
51437 struct kcore_list *m;
51438
51439 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51440 kfree(elf_buf);
51441 } else {
51442 if (kern_addr_valid(start)) {
51443 - unsigned long n;
51444 + char *elf_buf;
51445 + mm_segment_t oldfs;
51446
51447 - n = copy_to_user(buffer, (char *)start, tsz);
51448 - /*
51449 - * We cannot distinguish between fault on source
51450 - * and fault on destination. When this happens
51451 - * we clear too and hope it will trigger the
51452 - * EFAULT again.
51453 - */
51454 - if (n) {
51455 - if (clear_user(buffer + tsz - n,
51456 - n))
51457 + elf_buf = kmalloc(tsz, GFP_KERNEL);
51458 + if (!elf_buf)
51459 + return -ENOMEM;
51460 + oldfs = get_fs();
51461 + set_fs(KERNEL_DS);
51462 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
51463 + set_fs(oldfs);
51464 + if (copy_to_user(buffer, elf_buf, tsz)) {
51465 + kfree(elf_buf);
51466 return -EFAULT;
51467 + }
51468 }
51469 + set_fs(oldfs);
51470 + kfree(elf_buf);
51471 } else {
51472 if (clear_user(buffer, tsz))
51473 return -EFAULT;
51474 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51475
51476 static int open_kcore(struct inode *inode, struct file *filp)
51477 {
51478 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
51479 + return -EPERM;
51480 +#endif
51481 if (!capable(CAP_SYS_RAWIO))
51482 return -EPERM;
51483 if (kcore_need_update)
51484 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
51485 index 80e4645..53e5fcf 100644
51486 --- a/fs/proc/meminfo.c
51487 +++ b/fs/proc/meminfo.c
51488 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
51489 vmi.used >> 10,
51490 vmi.largest_chunk >> 10
51491 #ifdef CONFIG_MEMORY_FAILURE
51492 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
51493 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
51494 #endif
51495 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
51496 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
51497 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
51498 index b1822dd..df622cb 100644
51499 --- a/fs/proc/nommu.c
51500 +++ b/fs/proc/nommu.c
51501 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
51502 if (len < 1)
51503 len = 1;
51504 seq_printf(m, "%*c", len, ' ');
51505 - seq_path(m, &file->f_path, "");
51506 + seq_path(m, &file->f_path, "\n\\");
51507 }
51508
51509 seq_putc(m, '\n');
51510 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
51511 index fe72cd0..cb9b67d 100644
51512 --- a/fs/proc/proc_net.c
51513 +++ b/fs/proc/proc_net.c
51514 @@ -23,6 +23,7 @@
51515 #include <linux/nsproxy.h>
51516 #include <net/net_namespace.h>
51517 #include <linux/seq_file.h>
51518 +#include <linux/grsecurity.h>
51519
51520 #include "internal.h"
51521
51522 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
51523 struct task_struct *task;
51524 struct nsproxy *ns;
51525 struct net *net = NULL;
51526 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51527 + const struct cred *cred = current_cred();
51528 +#endif
51529 +
51530 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51531 + if (cred->fsuid)
51532 + return net;
51533 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51534 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
51535 + return net;
51536 +#endif
51537
51538 rcu_read_lock();
51539 task = pid_task(proc_pid(dir), PIDTYPE_PID);
51540 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
51541 index a781bdf..6665284 100644
51542 --- a/fs/proc/proc_sysctl.c
51543 +++ b/fs/proc/proc_sysctl.c
51544 @@ -12,11 +12,15 @@
51545 #include <linux/module.h>
51546 #include "internal.h"
51547
51548 +extern int gr_handle_chroot_sysctl(const int op);
51549 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
51550 + const int op);
51551 +
51552 static const struct dentry_operations proc_sys_dentry_operations;
51553 static const struct file_operations proc_sys_file_operations;
51554 -static const struct inode_operations proc_sys_inode_operations;
51555 +const struct inode_operations proc_sys_inode_operations;
51556 static const struct file_operations proc_sys_dir_file_operations;
51557 -static const struct inode_operations proc_sys_dir_operations;
51558 +const struct inode_operations proc_sys_dir_operations;
51559
51560 void proc_sys_poll_notify(struct ctl_table_poll *poll)
51561 {
51562 @@ -465,6 +469,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
51563
51564 err = NULL;
51565 d_set_d_op(dentry, &proc_sys_dentry_operations);
51566 +
51567 + gr_handle_proc_create(dentry, inode);
51568 +
51569 d_add(dentry, inode);
51570
51571 out:
51572 @@ -480,18 +487,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51573 struct inode *inode = filp->f_path.dentry->d_inode;
51574 struct ctl_table_header *head = grab_header(inode);
51575 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
51576 + int op = write ? MAY_WRITE : MAY_READ;
51577 ssize_t error;
51578 size_t res;
51579
51580 if (IS_ERR(head))
51581 return PTR_ERR(head);
51582
51583 +
51584 /*
51585 * At this point we know that the sysctl was not unregistered
51586 * and won't be until we finish.
51587 */
51588 error = -EPERM;
51589 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
51590 + if (sysctl_perm(head->root, table, op))
51591 goto out;
51592
51593 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
51594 @@ -499,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51595 if (!table->proc_handler)
51596 goto out;
51597
51598 +#ifdef CONFIG_GRKERNSEC
51599 + error = -EPERM;
51600 + if (gr_handle_chroot_sysctl(op))
51601 + goto out;
51602 + dget(filp->f_path.dentry);
51603 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
51604 + dput(filp->f_path.dentry);
51605 + goto out;
51606 + }
51607 + dput(filp->f_path.dentry);
51608 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
51609 + goto out;
51610 + if (write && !capable(CAP_SYS_ADMIN))
51611 + goto out;
51612 +#endif
51613 +
51614 /* careful: calling conventions are nasty here */
51615 res = count;
51616 error = table->proc_handler(table, write, buf, &res, ppos);
51617 @@ -596,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
51618 return -ENOMEM;
51619 } else {
51620 d_set_d_op(child, &proc_sys_dentry_operations);
51621 +
51622 + gr_handle_proc_create(child, inode);
51623 +
51624 d_add(child, inode);
51625 }
51626 } else {
51627 @@ -639,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
51628 if ((*pos)++ < file->f_pos)
51629 return 0;
51630
51631 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
51632 + return 0;
51633 +
51634 if (unlikely(S_ISLNK(table->mode)))
51635 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
51636 else
51637 @@ -756,6 +787,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
51638 if (IS_ERR(head))
51639 return PTR_ERR(head);
51640
51641 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
51642 + return -ENOENT;
51643 +
51644 generic_fillattr(inode, stat);
51645 if (table)
51646 stat->mode = (stat->mode & S_IFMT) | table->mode;
51647 @@ -778,13 +812,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
51648 .llseek = generic_file_llseek,
51649 };
51650
51651 -static const struct inode_operations proc_sys_inode_operations = {
51652 +const struct inode_operations proc_sys_inode_operations = {
51653 .permission = proc_sys_permission,
51654 .setattr = proc_sys_setattr,
51655 .getattr = proc_sys_getattr,
51656 };
51657
51658 -static const struct inode_operations proc_sys_dir_operations = {
51659 +const struct inode_operations proc_sys_dir_operations = {
51660 .lookup = proc_sys_lookup,
51661 .permission = proc_sys_permission,
51662 .setattr = proc_sys_setattr,
51663 diff --git a/fs/proc/root.c b/fs/proc/root.c
51664 index 9889a92..2613b48 100644
51665 --- a/fs/proc/root.c
51666 +++ b/fs/proc/root.c
51667 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
51668 #ifdef CONFIG_PROC_DEVICETREE
51669 proc_device_tree_init();
51670 #endif
51671 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
51672 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51673 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
51674 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51675 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
51676 +#endif
51677 +#else
51678 proc_mkdir("bus", NULL);
51679 +#endif
51680 proc_sys_init();
51681 }
51682
51683 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
51684 index 90c63f9..e662cfc 100644
51685 --- a/fs/proc/task_mmu.c
51686 +++ b/fs/proc/task_mmu.c
51687 @@ -11,12 +11,19 @@
51688 #include <linux/rmap.h>
51689 #include <linux/swap.h>
51690 #include <linux/swapops.h>
51691 +#include <linux/grsecurity.h>
51692
51693 #include <asm/elf.h>
51694 #include <asm/uaccess.h>
51695 #include <asm/tlbflush.h>
51696 #include "internal.h"
51697
51698 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51699 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51700 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
51701 + _mm->pax_flags & MF_PAX_SEGMEXEC))
51702 +#endif
51703 +
51704 void task_mem(struct seq_file *m, struct mm_struct *mm)
51705 {
51706 unsigned long data, text, lib, swap;
51707 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51708 "VmExe:\t%8lu kB\n"
51709 "VmLib:\t%8lu kB\n"
51710 "VmPTE:\t%8lu kB\n"
51711 - "VmSwap:\t%8lu kB\n",
51712 - hiwater_vm << (PAGE_SHIFT-10),
51713 + "VmSwap:\t%8lu kB\n"
51714 +
51715 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51716 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
51717 +#endif
51718 +
51719 + ,hiwater_vm << (PAGE_SHIFT-10),
51720 total_vm << (PAGE_SHIFT-10),
51721 mm->locked_vm << (PAGE_SHIFT-10),
51722 mm->pinned_vm << (PAGE_SHIFT-10),
51723 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51724 data << (PAGE_SHIFT-10),
51725 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
51726 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
51727 - swap << (PAGE_SHIFT-10));
51728 + swap << (PAGE_SHIFT-10)
51729 +
51730 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51731 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51732 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
51733 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
51734 +#else
51735 + , mm->context.user_cs_base
51736 + , mm->context.user_cs_limit
51737 +#endif
51738 +#endif
51739 +
51740 + );
51741 }
51742
51743 unsigned long task_vsize(struct mm_struct *mm)
51744 @@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51745 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
51746 }
51747
51748 - /* We don't show the stack guard page in /proc/maps */
51749 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51750 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
51751 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
51752 +#else
51753 start = vma->vm_start;
51754 - if (stack_guard_page_start(vma, start))
51755 - start += PAGE_SIZE;
51756 end = vma->vm_end;
51757 - if (stack_guard_page_end(vma, end))
51758 - end -= PAGE_SIZE;
51759 +#endif
51760
51761 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
51762 start,
51763 @@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51764 flags & VM_WRITE ? 'w' : '-',
51765 flags & VM_EXEC ? 'x' : '-',
51766 flags & VM_MAYSHARE ? 's' : 'p',
51767 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51768 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
51769 +#else
51770 pgoff,
51771 +#endif
51772 MAJOR(dev), MINOR(dev), ino, &len);
51773
51774 /*
51775 @@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51776 */
51777 if (file) {
51778 pad_len_spaces(m, len);
51779 - seq_path(m, &file->f_path, "\n");
51780 + seq_path(m, &file->f_path, "\n\\");
51781 goto done;
51782 }
51783
51784 @@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51785 * Thread stack in /proc/PID/task/TID/maps or
51786 * the main process stack.
51787 */
51788 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
51789 - vma->vm_end >= mm->start_stack)) {
51790 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
51791 + (vma->vm_start <= mm->start_stack &&
51792 + vma->vm_end >= mm->start_stack)) {
51793 name = "[stack]";
51794 } else {
51795 /* Thread stack in /proc/PID/maps */
51796 @@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
51797 struct proc_maps_private *priv = m->private;
51798 struct task_struct *task = priv->task;
51799
51800 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51801 + if (current->exec_id != m->exec_id) {
51802 + gr_log_badprocpid("maps");
51803 + return 0;
51804 + }
51805 +#endif
51806 +
51807 show_map_vma(m, vma, is_pid);
51808
51809 if (m->count < m->size) /* vma is copied successfully */
51810 @@ -538,12 +574,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51811 .private = &mss,
51812 };
51813
51814 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51815 + if (current->exec_id != m->exec_id) {
51816 + gr_log_badprocpid("smaps");
51817 + return 0;
51818 + }
51819 +#endif
51820 memset(&mss, 0, sizeof mss);
51821 - mss.vma = vma;
51822 - /* mmap_sem is held in m_start */
51823 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51824 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51825 -
51826 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51827 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
51828 +#endif
51829 + mss.vma = vma;
51830 + /* mmap_sem is held in m_start */
51831 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51832 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51833 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51834 + }
51835 +#endif
51836 show_map_vma(m, vma, is_pid);
51837
51838 seq_printf(m,
51839 @@ -561,7 +608,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51840 "KernelPageSize: %8lu kB\n"
51841 "MMUPageSize: %8lu kB\n"
51842 "Locked: %8lu kB\n",
51843 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51844 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
51845 +#else
51846 (vma->vm_end - vma->vm_start) >> 10,
51847 +#endif
51848 mss.resident >> 10,
51849 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
51850 mss.shared_clean >> 10,
51851 @@ -1211,6 +1262,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51852 int n;
51853 char buffer[50];
51854
51855 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51856 + if (current->exec_id != m->exec_id) {
51857 + gr_log_badprocpid("numa_maps");
51858 + return 0;
51859 + }
51860 +#endif
51861 +
51862 if (!mm)
51863 return 0;
51864
51865 @@ -1228,11 +1286,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51866 mpol_to_str(buffer, sizeof(buffer), pol, 0);
51867 mpol_cond_put(pol);
51868
51869 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51870 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
51871 +#else
51872 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
51873 +#endif
51874
51875 if (file) {
51876 seq_printf(m, " file=");
51877 - seq_path(m, &file->f_path, "\n\t= ");
51878 + seq_path(m, &file->f_path, "\n\t\\= ");
51879 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
51880 seq_printf(m, " heap");
51881 } else {
51882 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
51883 index 1ccfa53..0848f95 100644
51884 --- a/fs/proc/task_nommu.c
51885 +++ b/fs/proc/task_nommu.c
51886 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51887 else
51888 bytes += kobjsize(mm);
51889
51890 - if (current->fs && current->fs->users > 1)
51891 + if (current->fs && atomic_read(&current->fs->users) > 1)
51892 sbytes += kobjsize(current->fs);
51893 else
51894 bytes += kobjsize(current->fs);
51895 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
51896
51897 if (file) {
51898 pad_len_spaces(m, len);
51899 - seq_path(m, &file->f_path, "");
51900 + seq_path(m, &file->f_path, "\n\\");
51901 } else if (mm) {
51902 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
51903
51904 diff --git a/fs/pstore/ftrace.c b/fs/pstore/ftrace.c
51905 index 2d57e1a..43b1280 100644
51906 --- a/fs/pstore/ftrace.c
51907 +++ b/fs/pstore/ftrace.c
51908 @@ -28,7 +28,9 @@
51909 #include "internal.h"
51910
51911 static void notrace pstore_ftrace_call(unsigned long ip,
51912 - unsigned long parent_ip)
51913 + unsigned long parent_ip,
51914 + struct ftrace_ops *op,
51915 + struct pt_regs *regs)
51916 {
51917 unsigned long flags;
51918 struct pstore_ftrace_record rec = {};
51919 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
51920 index 16e8abb..2dcf914 100644
51921 --- a/fs/quota/netlink.c
51922 +++ b/fs/quota/netlink.c
51923 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
51924 void quota_send_warning(struct kqid qid, dev_t dev,
51925 const char warntype)
51926 {
51927 - static atomic_t seq;
51928 + static atomic_unchecked_t seq;
51929 struct sk_buff *skb;
51930 void *msg_head;
51931 int ret;
51932 @@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
51933 "VFS: Not enough memory to send quota warning.\n");
51934 return;
51935 }
51936 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
51937 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
51938 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
51939 if (!msg_head) {
51940 printk(KERN_ERR
51941 diff --git a/fs/read_write.c b/fs/read_write.c
51942 index d065348..8e2b43d 100644
51943 --- a/fs/read_write.c
51944 +++ b/fs/read_write.c
51945 @@ -935,6 +935,8 @@ ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, size_t count,
51946 if (retval > 0) {
51947 add_rchar(current, retval);
51948 add_wchar(current, retval);
51949 + fsnotify_access(in.file);
51950 + fsnotify_modify(out.file);
51951 }
51952
51953 inc_syscr(current);
51954 diff --git a/fs/readdir.c b/fs/readdir.c
51955 index 5e69ef5..e5d9099 100644
51956 --- a/fs/readdir.c
51957 +++ b/fs/readdir.c
51958 @@ -17,6 +17,7 @@
51959 #include <linux/security.h>
51960 #include <linux/syscalls.h>
51961 #include <linux/unistd.h>
51962 +#include <linux/namei.h>
51963
51964 #include <asm/uaccess.h>
51965
51966 @@ -67,6 +68,7 @@ struct old_linux_dirent {
51967
51968 struct readdir_callback {
51969 struct old_linux_dirent __user * dirent;
51970 + struct file * file;
51971 int result;
51972 };
51973
51974 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
51975 buf->result = -EOVERFLOW;
51976 return -EOVERFLOW;
51977 }
51978 +
51979 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51980 + return 0;
51981 +
51982 buf->result++;
51983 dirent = buf->dirent;
51984 if (!access_ok(VERIFY_WRITE, dirent,
51985 @@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
51986
51987 buf.result = 0;
51988 buf.dirent = dirent;
51989 + buf.file = f.file;
51990
51991 error = vfs_readdir(f.file, fillonedir, &buf);
51992 if (buf.result)
51993 @@ -139,6 +146,7 @@ struct linux_dirent {
51994 struct getdents_callback {
51995 struct linux_dirent __user * current_dir;
51996 struct linux_dirent __user * previous;
51997 + struct file * file;
51998 int count;
51999 int error;
52000 };
52001 @@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
52002 buf->error = -EOVERFLOW;
52003 return -EOVERFLOW;
52004 }
52005 +
52006 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52007 + return 0;
52008 +
52009 dirent = buf->previous;
52010 if (dirent) {
52011 if (__put_user(offset, &dirent->d_off))
52012 @@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
52013 buf.previous = NULL;
52014 buf.count = count;
52015 buf.error = 0;
52016 + buf.file = f.file;
52017
52018 error = vfs_readdir(f.file, filldir, &buf);
52019 if (error >= 0)
52020 @@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
52021 struct getdents_callback64 {
52022 struct linux_dirent64 __user * current_dir;
52023 struct linux_dirent64 __user * previous;
52024 + struct file *file;
52025 int count;
52026 int error;
52027 };
52028 @@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
52029 buf->error = -EINVAL; /* only used if we fail.. */
52030 if (reclen > buf->count)
52031 return -EINVAL;
52032 +
52033 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52034 + return 0;
52035 +
52036 dirent = buf->previous;
52037 if (dirent) {
52038 if (__put_user(offset, &dirent->d_off))
52039 @@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
52040
52041 buf.current_dir = dirent;
52042 buf.previous = NULL;
52043 + buf.file = f.file;
52044 buf.count = count;
52045 buf.error = 0;
52046
52047 @@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
52048 error = buf.error;
52049 lastdirent = buf.previous;
52050 if (lastdirent) {
52051 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
52052 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
52053 if (__put_user(d_off, &lastdirent->d_off))
52054 error = -EFAULT;
52055 else
52056 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
52057 index 2b7882b..1c5ef48 100644
52058 --- a/fs/reiserfs/do_balan.c
52059 +++ b/fs/reiserfs/do_balan.c
52060 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
52061 return;
52062 }
52063
52064 - atomic_inc(&(fs_generation(tb->tb_sb)));
52065 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
52066 do_balance_starts(tb);
52067
52068 /* balance leaf returns 0 except if combining L R and S into
52069 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
52070 index e60e870..f40ac16 100644
52071 --- a/fs/reiserfs/procfs.c
52072 +++ b/fs/reiserfs/procfs.c
52073 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
52074 "SMALL_TAILS " : "NO_TAILS ",
52075 replay_only(sb) ? "REPLAY_ONLY " : "",
52076 convert_reiserfs(sb) ? "CONV " : "",
52077 - atomic_read(&r->s_generation_counter),
52078 + atomic_read_unchecked(&r->s_generation_counter),
52079 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
52080 SF(s_do_balance), SF(s_unneeded_left_neighbor),
52081 SF(s_good_search_by_key_reada), SF(s_bmaps),
52082 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
52083 index 33215f5..c5d427a 100644
52084 --- a/fs/reiserfs/reiserfs.h
52085 +++ b/fs/reiserfs/reiserfs.h
52086 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
52087 /* Comment? -Hans */
52088 wait_queue_head_t s_wait;
52089 /* To be obsoleted soon by per buffer seals.. -Hans */
52090 - atomic_t s_generation_counter; // increased by one every time the
52091 + atomic_unchecked_t s_generation_counter; // increased by one every time the
52092 // tree gets re-balanced
52093 unsigned long s_properties; /* File system properties. Currently holds
52094 on-disk FS format */
52095 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
52096 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
52097
52098 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
52099 -#define get_generation(s) atomic_read (&fs_generation(s))
52100 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
52101 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
52102 #define __fs_changed(gen,s) (gen != get_generation (s))
52103 #define fs_changed(gen,s) \
52104 diff --git a/fs/select.c b/fs/select.c
52105 index 2ef72d9..f213b17 100644
52106 --- a/fs/select.c
52107 +++ b/fs/select.c
52108 @@ -20,6 +20,7 @@
52109 #include <linux/export.h>
52110 #include <linux/slab.h>
52111 #include <linux/poll.h>
52112 +#include <linux/security.h>
52113 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
52114 #include <linux/file.h>
52115 #include <linux/fdtable.h>
52116 @@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
52117 struct poll_list *walk = head;
52118 unsigned long todo = nfds;
52119
52120 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
52121 if (nfds > rlimit(RLIMIT_NOFILE))
52122 return -EINVAL;
52123
52124 diff --git a/fs/seq_file.c b/fs/seq_file.c
52125 index 99dffab..e4fcb71 100644
52126 --- a/fs/seq_file.c
52127 +++ b/fs/seq_file.c
52128 @@ -10,6 +10,7 @@
52129 #include <linux/seq_file.h>
52130 #include <linux/slab.h>
52131 #include <linux/cred.h>
52132 +#include <linux/sched.h>
52133
52134 #include <asm/uaccess.h>
52135 #include <asm/page.h>
52136 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
52137 #ifdef CONFIG_USER_NS
52138 p->user_ns = file->f_cred->user_ns;
52139 #endif
52140 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52141 + p->exec_id = current->exec_id;
52142 +#endif
52143
52144 /*
52145 * Wrappers around seq_open(e.g. swaps_open) need to be
52146 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52147 return 0;
52148 }
52149 if (!m->buf) {
52150 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52151 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52152 if (!m->buf)
52153 return -ENOMEM;
52154 }
52155 @@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52156 Eoverflow:
52157 m->op->stop(m, p);
52158 kfree(m->buf);
52159 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52160 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52161 return !m->buf ? -ENOMEM : -EAGAIN;
52162 }
52163
52164 @@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52165
52166 /* grab buffer if we didn't have one */
52167 if (!m->buf) {
52168 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52169 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52170 if (!m->buf)
52171 goto Enomem;
52172 }
52173 @@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52174 goto Fill;
52175 m->op->stop(m, p);
52176 kfree(m->buf);
52177 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52178 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52179 if (!m->buf)
52180 goto Enomem;
52181 m->count = 0;
52182 @@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
52183 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
52184 void *data)
52185 {
52186 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
52187 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
52188 int res = -ENOMEM;
52189
52190 if (op) {
52191 diff --git a/fs/splice.c b/fs/splice.c
52192 index 48c7bd1..d0740e4 100644
52193 --- a/fs/splice.c
52194 +++ b/fs/splice.c
52195 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52196 pipe_lock(pipe);
52197
52198 for (;;) {
52199 - if (!pipe->readers) {
52200 + if (!atomic_read(&pipe->readers)) {
52201 send_sig(SIGPIPE, current, 0);
52202 if (!ret)
52203 ret = -EPIPE;
52204 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52205 do_wakeup = 0;
52206 }
52207
52208 - pipe->waiting_writers++;
52209 + atomic_inc(&pipe->waiting_writers);
52210 pipe_wait(pipe);
52211 - pipe->waiting_writers--;
52212 + atomic_dec(&pipe->waiting_writers);
52213 }
52214
52215 pipe_unlock(pipe);
52216 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
52217 old_fs = get_fs();
52218 set_fs(get_ds());
52219 /* The cast to a user pointer is valid due to the set_fs() */
52220 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
52221 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
52222 set_fs(old_fs);
52223
52224 return res;
52225 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
52226 old_fs = get_fs();
52227 set_fs(get_ds());
52228 /* The cast to a user pointer is valid due to the set_fs() */
52229 - res = vfs_write(file, (const char __user *)buf, count, &pos);
52230 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
52231 set_fs(old_fs);
52232
52233 return res;
52234 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
52235 goto err;
52236
52237 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
52238 - vec[i].iov_base = (void __user *) page_address(page);
52239 + vec[i].iov_base = (void __force_user *) page_address(page);
52240 vec[i].iov_len = this_len;
52241 spd.pages[i] = page;
52242 spd.nr_pages++;
52243 @@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
52244 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
52245 {
52246 while (!pipe->nrbufs) {
52247 - if (!pipe->writers)
52248 + if (!atomic_read(&pipe->writers))
52249 return 0;
52250
52251 - if (!pipe->waiting_writers && sd->num_spliced)
52252 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
52253 return 0;
52254
52255 if (sd->flags & SPLICE_F_NONBLOCK)
52256 @@ -1192,7 +1192,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
52257 * out of the pipe right after the splice_to_pipe(). So set
52258 * PIPE_READERS appropriately.
52259 */
52260 - pipe->readers = 1;
52261 + atomic_set(&pipe->readers, 1);
52262
52263 current->splice_pipe = pipe;
52264 }
52265 @@ -1741,9 +1741,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52266 ret = -ERESTARTSYS;
52267 break;
52268 }
52269 - if (!pipe->writers)
52270 + if (!atomic_read(&pipe->writers))
52271 break;
52272 - if (!pipe->waiting_writers) {
52273 + if (!atomic_read(&pipe->waiting_writers)) {
52274 if (flags & SPLICE_F_NONBLOCK) {
52275 ret = -EAGAIN;
52276 break;
52277 @@ -1775,7 +1775,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52278 pipe_lock(pipe);
52279
52280 while (pipe->nrbufs >= pipe->buffers) {
52281 - if (!pipe->readers) {
52282 + if (!atomic_read(&pipe->readers)) {
52283 send_sig(SIGPIPE, current, 0);
52284 ret = -EPIPE;
52285 break;
52286 @@ -1788,9 +1788,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
52287 ret = -ERESTARTSYS;
52288 break;
52289 }
52290 - pipe->waiting_writers++;
52291 + atomic_inc(&pipe->waiting_writers);
52292 pipe_wait(pipe);
52293 - pipe->waiting_writers--;
52294 + atomic_dec(&pipe->waiting_writers);
52295 }
52296
52297 pipe_unlock(pipe);
52298 @@ -1826,14 +1826,14 @@ retry:
52299 pipe_double_lock(ipipe, opipe);
52300
52301 do {
52302 - if (!opipe->readers) {
52303 + if (!atomic_read(&opipe->readers)) {
52304 send_sig(SIGPIPE, current, 0);
52305 if (!ret)
52306 ret = -EPIPE;
52307 break;
52308 }
52309
52310 - if (!ipipe->nrbufs && !ipipe->writers)
52311 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
52312 break;
52313
52314 /*
52315 @@ -1930,7 +1930,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
52316 pipe_double_lock(ipipe, opipe);
52317
52318 do {
52319 - if (!opipe->readers) {
52320 + if (!atomic_read(&opipe->readers)) {
52321 send_sig(SIGPIPE, current, 0);
52322 if (!ret)
52323 ret = -EPIPE;
52324 @@ -1975,7 +1975,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
52325 * return EAGAIN if we have the potential of some data in the
52326 * future, otherwise just return 0
52327 */
52328 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
52329 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
52330 ret = -EAGAIN;
52331
52332 pipe_unlock(ipipe);
52333 diff --git a/fs/stat.c b/fs/stat.c
52334 index eae4946..6198f55 100644
52335 --- a/fs/stat.c
52336 +++ b/fs/stat.c
52337 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
52338 stat->gid = inode->i_gid;
52339 stat->rdev = inode->i_rdev;
52340 stat->size = i_size_read(inode);
52341 - stat->atime = inode->i_atime;
52342 - stat->mtime = inode->i_mtime;
52343 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
52344 + stat->atime = inode->i_ctime;
52345 + stat->mtime = inode->i_ctime;
52346 + } else {
52347 + stat->atime = inode->i_atime;
52348 + stat->mtime = inode->i_mtime;
52349 + }
52350 stat->ctime = inode->i_ctime;
52351 stat->blksize = (1 << inode->i_blkbits);
52352 stat->blocks = inode->i_blocks;
52353 @@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
52354 if (retval)
52355 return retval;
52356
52357 - if (inode->i_op->getattr)
52358 - return inode->i_op->getattr(mnt, dentry, stat);
52359 + if (inode->i_op->getattr) {
52360 + retval = inode->i_op->getattr(mnt, dentry, stat);
52361 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
52362 + stat->atime = stat->ctime;
52363 + stat->mtime = stat->ctime;
52364 + }
52365 + return retval;
52366 + }
52367
52368 generic_fillattr(inode, stat);
52369 return 0;
52370 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
52371 index 2fbdff6..5530a61 100644
52372 --- a/fs/sysfs/dir.c
52373 +++ b/fs/sysfs/dir.c
52374 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
52375 struct sysfs_dirent *sd;
52376 int rc;
52377
52378 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
52379 + const char *parent_name = parent_sd->s_name;
52380 +
52381 + mode = S_IFDIR | S_IRWXU;
52382 +
52383 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
52384 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
52385 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
52386 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
52387 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
52388 +#endif
52389 +
52390 /* allocate */
52391 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
52392 if (!sd)
52393 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
52394 index 00012e3..8392349 100644
52395 --- a/fs/sysfs/file.c
52396 +++ b/fs/sysfs/file.c
52397 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
52398
52399 struct sysfs_open_dirent {
52400 atomic_t refcnt;
52401 - atomic_t event;
52402 + atomic_unchecked_t event;
52403 wait_queue_head_t poll;
52404 struct list_head buffers; /* goes through sysfs_buffer.list */
52405 };
52406 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
52407 if (!sysfs_get_active(attr_sd))
52408 return -ENODEV;
52409
52410 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
52411 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
52412 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
52413
52414 sysfs_put_active(attr_sd);
52415 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
52416 return -ENOMEM;
52417
52418 atomic_set(&new_od->refcnt, 0);
52419 - atomic_set(&new_od->event, 1);
52420 + atomic_set_unchecked(&new_od->event, 1);
52421 init_waitqueue_head(&new_od->poll);
52422 INIT_LIST_HEAD(&new_od->buffers);
52423 goto retry;
52424 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
52425
52426 sysfs_put_active(attr_sd);
52427
52428 - if (buffer->event != atomic_read(&od->event))
52429 + if (buffer->event != atomic_read_unchecked(&od->event))
52430 goto trigger;
52431
52432 return DEFAULT_POLLMASK;
52433 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
52434
52435 od = sd->s_attr.open;
52436 if (od) {
52437 - atomic_inc(&od->event);
52438 + atomic_inc_unchecked(&od->event);
52439 wake_up_interruptible(&od->poll);
52440 }
52441
52442 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
52443 index 3c9eb56..9dea5be 100644
52444 --- a/fs/sysfs/symlink.c
52445 +++ b/fs/sysfs/symlink.c
52446 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
52447
52448 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
52449 {
52450 - char *page = nd_get_link(nd);
52451 + const char *page = nd_get_link(nd);
52452 if (!IS_ERR(page))
52453 free_page((unsigned long)page);
52454 }
52455 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
52456 index c175b4d..8f36a16 100644
52457 --- a/fs/udf/misc.c
52458 +++ b/fs/udf/misc.c
52459 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
52460
52461 u8 udf_tag_checksum(const struct tag *t)
52462 {
52463 - u8 *data = (u8 *)t;
52464 + const u8 *data = (const u8 *)t;
52465 u8 checksum = 0;
52466 int i;
52467 for (i = 0; i < sizeof(struct tag); ++i)
52468 diff --git a/fs/utimes.c b/fs/utimes.c
52469 index bb0696a..552054b 100644
52470 --- a/fs/utimes.c
52471 +++ b/fs/utimes.c
52472 @@ -1,6 +1,7 @@
52473 #include <linux/compiler.h>
52474 #include <linux/file.h>
52475 #include <linux/fs.h>
52476 +#include <linux/security.h>
52477 #include <linux/linkage.h>
52478 #include <linux/mount.h>
52479 #include <linux/namei.h>
52480 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
52481 goto mnt_drop_write_and_out;
52482 }
52483 }
52484 +
52485 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
52486 + error = -EACCES;
52487 + goto mnt_drop_write_and_out;
52488 + }
52489 +
52490 mutex_lock(&inode->i_mutex);
52491 error = notify_change(path->dentry, &newattrs);
52492 mutex_unlock(&inode->i_mutex);
52493 diff --git a/fs/xattr.c b/fs/xattr.c
52494 index e21c119..21dfc7c 100644
52495 --- a/fs/xattr.c
52496 +++ b/fs/xattr.c
52497 @@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
52498 * Extended attribute SET operations
52499 */
52500 static long
52501 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
52502 +setxattr(struct path *path, const char __user *name, const void __user *value,
52503 size_t size, int flags)
52504 {
52505 int error;
52506 @@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
52507 posix_acl_fix_xattr_from_user(kvalue, size);
52508 }
52509
52510 - error = vfs_setxattr(d, kname, kvalue, size, flags);
52511 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
52512 + error = -EACCES;
52513 + goto out;
52514 + }
52515 +
52516 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
52517 out:
52518 if (vvalue)
52519 vfree(vvalue);
52520 @@ -376,7 +381,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
52521 return error;
52522 error = mnt_want_write(path.mnt);
52523 if (!error) {
52524 - error = setxattr(path.dentry, name, value, size, flags);
52525 + error = setxattr(&path, name, value, size, flags);
52526 mnt_drop_write(path.mnt);
52527 }
52528 path_put(&path);
52529 @@ -395,7 +400,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
52530 return error;
52531 error = mnt_want_write(path.mnt);
52532 if (!error) {
52533 - error = setxattr(path.dentry, name, value, size, flags);
52534 + error = setxattr(&path, name, value, size, flags);
52535 mnt_drop_write(path.mnt);
52536 }
52537 path_put(&path);
52538 @@ -406,16 +411,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
52539 const void __user *,value, size_t, size, int, flags)
52540 {
52541 struct fd f = fdget(fd);
52542 - struct dentry *dentry;
52543 int error = -EBADF;
52544
52545 if (!f.file)
52546 return error;
52547 - dentry = f.file->f_path.dentry;
52548 - audit_inode(NULL, dentry, 0);
52549 + audit_inode(NULL, f.file->f_path.dentry, 0);
52550 error = mnt_want_write_file(f.file);
52551 if (!error) {
52552 - error = setxattr(dentry, name, value, size, flags);
52553 + error = setxattr(&f.file->f_path, name, value, size, flags);
52554 mnt_drop_write_file(f.file);
52555 }
52556 fdput(f);
52557 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
52558 index 9fbea87..6b19972 100644
52559 --- a/fs/xattr_acl.c
52560 +++ b/fs/xattr_acl.c
52561 @@ -76,8 +76,8 @@ struct posix_acl *
52562 posix_acl_from_xattr(struct user_namespace *user_ns,
52563 const void *value, size_t size)
52564 {
52565 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
52566 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
52567 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
52568 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
52569 int count;
52570 struct posix_acl *acl;
52571 struct posix_acl_entry *acl_e;
52572 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
52573 index 83d0cf3..2ef526b 100644
52574 --- a/fs/xfs/xfs_bmap.c
52575 +++ b/fs/xfs/xfs_bmap.c
52576 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
52577 int nmap,
52578 int ret_nmap);
52579 #else
52580 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
52581 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
52582 #endif /* DEBUG */
52583
52584 STATIC int
52585 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
52586 index 1b9fc3e..e1bdde0 100644
52587 --- a/fs/xfs/xfs_dir2_sf.c
52588 +++ b/fs/xfs/xfs_dir2_sf.c
52589 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
52590 }
52591
52592 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
52593 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52594 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
52595 + char name[sfep->namelen];
52596 + memcpy(name, sfep->name, sfep->namelen);
52597 + if (filldir(dirent, name, sfep->namelen,
52598 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
52599 + *offset = off & 0x7fffffff;
52600 + return 0;
52601 + }
52602 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52603 off & 0x7fffffff, ino, DT_UNKNOWN)) {
52604 *offset = off & 0x7fffffff;
52605 return 0;
52606 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
52607 index c1df3c6..f987db6 100644
52608 --- a/fs/xfs/xfs_ioctl.c
52609 +++ b/fs/xfs/xfs_ioctl.c
52610 @@ -126,7 +126,7 @@ xfs_find_handle(
52611 }
52612
52613 error = -EFAULT;
52614 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
52615 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
52616 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
52617 goto out_put;
52618
52619 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
52620 index 4e00cf0..3374374 100644
52621 --- a/fs/xfs/xfs_iops.c
52622 +++ b/fs/xfs/xfs_iops.c
52623 @@ -394,7 +394,7 @@ xfs_vn_put_link(
52624 struct nameidata *nd,
52625 void *p)
52626 {
52627 - char *s = nd_get_link(nd);
52628 + const char *s = nd_get_link(nd);
52629
52630 if (!IS_ERR(s))
52631 kfree(s);
52632 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
52633 new file mode 100644
52634 index 0000000..92247e4
52635 --- /dev/null
52636 +++ b/grsecurity/Kconfig
52637 @@ -0,0 +1,1021 @@
52638 +#
52639 +# grecurity configuration
52640 +#
52641 +menu "Memory Protections"
52642 +depends on GRKERNSEC
52643 +
52644 +config GRKERNSEC_KMEM
52645 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
52646 + default y if GRKERNSEC_CONFIG_AUTO
52647 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
52648 + help
52649 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
52650 + be written to or read from to modify or leak the contents of the running
52651 + kernel. /dev/port will also not be allowed to be opened and support
52652 + for /dev/cpu/*/msr will be removed. If you have module
52653 + support disabled, enabling this will close up five ways that are
52654 + currently used to insert malicious code into the running kernel.
52655 +
52656 + Even with all these features enabled, we still highly recommend that
52657 + you use the RBAC system, as it is still possible for an attacker to
52658 + modify the running kernel through privileged I/O granted by ioperm/iopl.
52659 +
52660 + If you are not using XFree86, you may be able to stop this additional
52661 + case by enabling the 'Disable privileged I/O' option. Though nothing
52662 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
52663 + but only to video memory, which is the only writing we allow in this
52664 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
52665 + not be allowed to mprotect it with PROT_WRITE later.
52666 + Enabling this feature will prevent the "cpupower" and "powertop" tools
52667 + from working.
52668 +
52669 + It is highly recommended that you say Y here if you meet all the
52670 + conditions above.
52671 +
52672 +config GRKERNSEC_VM86
52673 + bool "Restrict VM86 mode"
52674 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52675 + depends on X86_32
52676 +
52677 + help
52678 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
52679 + make use of a special execution mode on 32bit x86 processors called
52680 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
52681 + video cards and will still work with this option enabled. The purpose
52682 + of the option is to prevent exploitation of emulation errors in
52683 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
52684 + Nearly all users should be able to enable this option.
52685 +
52686 +config GRKERNSEC_IO
52687 + bool "Disable privileged I/O"
52688 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52689 + depends on X86
52690 + select RTC_CLASS
52691 + select RTC_INTF_DEV
52692 + select RTC_DRV_CMOS
52693 +
52694 + help
52695 + If you say Y here, all ioperm and iopl calls will return an error.
52696 + Ioperm and iopl can be used to modify the running kernel.
52697 + Unfortunately, some programs need this access to operate properly,
52698 + the most notable of which are XFree86 and hwclock. hwclock can be
52699 + remedied by having RTC support in the kernel, so real-time
52700 + clock support is enabled if this option is enabled, to ensure
52701 + that hwclock operates correctly. XFree86 still will not
52702 + operate correctly with this option enabled, so DO NOT CHOOSE Y
52703 + IF YOU USE XFree86. If you use XFree86 and you still want to
52704 + protect your kernel against modification, use the RBAC system.
52705 +
52706 +config GRKERNSEC_JIT_HARDEN
52707 + bool "Harden BPF JIT against spray attacks"
52708 + default y if GRKERNSEC_CONFIG_AUTO
52709 + depends on BPF_JIT
52710 + help
52711 + If you say Y here, the native code generated by the kernel's Berkeley
52712 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
52713 + attacks that attempt to fit attacker-beneficial instructions in
52714 + 32bit immediate fields of JIT-generated native instructions. The
52715 + attacker will generally aim to cause an unintended instruction sequence
52716 + of JIT-generated native code to execute by jumping into the middle of
52717 + a generated instruction. This feature effectively randomizes the 32bit
52718 + immediate constants present in the generated code to thwart such attacks.
52719 +
52720 + If you're using KERNEXEC, it's recommended that you enable this option
52721 + to supplement the hardening of the kernel.
52722 +
52723 +config GRKERNSEC_RAND_THREADSTACK
52724 + bool "Insert random gaps between thread stacks"
52725 + default y if GRKERNSEC_CONFIG_AUTO
52726 + depends on PAX_RANDMMAP && !PPC
52727 + help
52728 + If you say Y here, a random-sized gap will be enforced between allocated
52729 + thread stacks. Glibc's NPTL and other threading libraries that
52730 + pass MAP_STACK to the kernel for thread stack allocation are supported.
52731 + The implementation currently provides 8 bits of entropy for the gap.
52732 +
52733 + Many distributions do not compile threaded remote services with the
52734 + -fstack-check argument to GCC, causing the variable-sized stack-based
52735 + allocator, alloca(), to not probe the stack on allocation. This
52736 + permits an unbounded alloca() to skip over any guard page and potentially
52737 + modify another thread's stack reliably. An enforced random gap
52738 + reduces the reliability of such an attack and increases the chance
52739 + that such a read/write to another thread's stack instead lands in
52740 + an unmapped area, causing a crash and triggering grsecurity's
52741 + anti-bruteforcing logic.
52742 +
52743 +config GRKERNSEC_PROC_MEMMAP
52744 + bool "Harden ASLR against information leaks and entropy reduction"
52745 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
52746 + depends on PAX_NOEXEC || PAX_ASLR
52747 + help
52748 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
52749 + give no information about the addresses of its mappings if
52750 + PaX features that rely on random addresses are enabled on the task.
52751 + In addition to sanitizing this information and disabling other
52752 + dangerous sources of information, this option causes reads of sensitive
52753 + /proc/<pid> entries where the file descriptor was opened in a different
52754 + task than the one performing the read. Such attempts are logged.
52755 + This option also limits argv/env strings for suid/sgid binaries
52756 + to 512KB to prevent a complete exhaustion of the stack entropy provided
52757 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
52758 + binaries to prevent alternative mmap layouts from being abused.
52759 +
52760 + If you use PaX it is essential that you say Y here as it closes up
52761 + several holes that make full ASLR useless locally.
52762 +
52763 +config GRKERNSEC_BRUTE
52764 + bool "Deter exploit bruteforcing"
52765 + default y if GRKERNSEC_CONFIG_AUTO
52766 + help
52767 + If you say Y here, attempts to bruteforce exploits against forking
52768 + daemons such as apache or sshd, as well as against suid/sgid binaries
52769 + will be deterred. When a child of a forking daemon is killed by PaX
52770 + or crashes due to an illegal instruction or other suspicious signal,
52771 + the parent process will be delayed 30 seconds upon every subsequent
52772 + fork until the administrator is able to assess the situation and
52773 + restart the daemon.
52774 + In the suid/sgid case, the attempt is logged, the user has all their
52775 + processes terminated, and they are prevented from executing any further
52776 + processes for 15 minutes.
52777 + It is recommended that you also enable signal logging in the auditing
52778 + section so that logs are generated when a process triggers a suspicious
52779 + signal.
52780 + If the sysctl option is enabled, a sysctl option with name
52781 + "deter_bruteforce" is created.
52782 +
52783 +
52784 +config GRKERNSEC_MODHARDEN
52785 + bool "Harden module auto-loading"
52786 + default y if GRKERNSEC_CONFIG_AUTO
52787 + depends on MODULES
52788 + help
52789 + If you say Y here, module auto-loading in response to use of some
52790 + feature implemented by an unloaded module will be restricted to
52791 + root users. Enabling this option helps defend against attacks
52792 + by unprivileged users who abuse the auto-loading behavior to
52793 + cause a vulnerable module to load that is then exploited.
52794 +
52795 + If this option prevents a legitimate use of auto-loading for a
52796 + non-root user, the administrator can execute modprobe manually
52797 + with the exact name of the module mentioned in the alert log.
52798 + Alternatively, the administrator can add the module to the list
52799 + of modules loaded at boot by modifying init scripts.
52800 +
52801 + Modification of init scripts will most likely be needed on
52802 + Ubuntu servers with encrypted home directory support enabled,
52803 + as the first non-root user logging in will cause the ecb(aes),
52804 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
52805 +
52806 +config GRKERNSEC_HIDESYM
52807 + bool "Hide kernel symbols"
52808 + default y if GRKERNSEC_CONFIG_AUTO
52809 + select PAX_USERCOPY_SLABS
52810 + help
52811 + If you say Y here, getting information on loaded modules, and
52812 + displaying all kernel symbols through a syscall will be restricted
52813 + to users with CAP_SYS_MODULE. For software compatibility reasons,
52814 + /proc/kallsyms will be restricted to the root user. The RBAC
52815 + system can hide that entry even from root.
52816 +
52817 + This option also prevents leaking of kernel addresses through
52818 + several /proc entries.
52819 +
52820 + Note that this option is only effective provided the following
52821 + conditions are met:
52822 + 1) The kernel using grsecurity is not precompiled by some distribution
52823 + 2) You have also enabled GRKERNSEC_DMESG
52824 + 3) You are using the RBAC system and hiding other files such as your
52825 + kernel image and System.map. Alternatively, enabling this option
52826 + causes the permissions on /boot, /lib/modules, and the kernel
52827 + source directory to change at compile time to prevent
52828 + reading by non-root users.
52829 + If the above conditions are met, this option will aid in providing a
52830 + useful protection against local kernel exploitation of overflows
52831 + and arbitrary read/write vulnerabilities.
52832 +
52833 +config GRKERNSEC_KERN_LOCKOUT
52834 + bool "Active kernel exploit response"
52835 + default y if GRKERNSEC_CONFIG_AUTO
52836 + depends on X86 || ARM || PPC || SPARC
52837 + help
52838 + If you say Y here, when a PaX alert is triggered due to suspicious
52839 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
52840 + or an OOPS occurs due to bad memory accesses, instead of just
52841 + terminating the offending process (and potentially allowing
52842 + a subsequent exploit from the same user), we will take one of two
52843 + actions:
52844 + If the user was root, we will panic the system
52845 + If the user was non-root, we will log the attempt, terminate
52846 + all processes owned by the user, then prevent them from creating
52847 + any new processes until the system is restarted
52848 + This deters repeated kernel exploitation/bruteforcing attempts
52849 + and is useful for later forensics.
52850 +
52851 +endmenu
52852 +menu "Role Based Access Control Options"
52853 +depends on GRKERNSEC
52854 +
52855 +config GRKERNSEC_RBAC_DEBUG
52856 + bool
52857 +
52858 +config GRKERNSEC_NO_RBAC
52859 + bool "Disable RBAC system"
52860 + help
52861 + If you say Y here, the /dev/grsec device will be removed from the kernel,
52862 + preventing the RBAC system from being enabled. You should only say Y
52863 + here if you have no intention of using the RBAC system, so as to prevent
52864 + an attacker with root access from misusing the RBAC system to hide files
52865 + and processes when loadable module support and /dev/[k]mem have been
52866 + locked down.
52867 +
52868 +config GRKERNSEC_ACL_HIDEKERN
52869 + bool "Hide kernel processes"
52870 + help
52871 + If you say Y here, all kernel threads will be hidden to all
52872 + processes but those whose subject has the "view hidden processes"
52873 + flag.
52874 +
52875 +config GRKERNSEC_ACL_MAXTRIES
52876 + int "Maximum tries before password lockout"
52877 + default 3
52878 + help
52879 + This option enforces the maximum number of times a user can attempt
52880 + to authorize themselves with the grsecurity RBAC system before being
52881 + denied the ability to attempt authorization again for a specified time.
52882 + The lower the number, the harder it will be to brute-force a password.
52883 +
52884 +config GRKERNSEC_ACL_TIMEOUT
52885 + int "Time to wait after max password tries, in seconds"
52886 + default 30
52887 + help
52888 + This option specifies the time the user must wait after attempting to
52889 + authorize to the RBAC system with the maximum number of invalid
52890 + passwords. The higher the number, the harder it will be to brute-force
52891 + a password.
52892 +
52893 +endmenu
52894 +menu "Filesystem Protections"
52895 +depends on GRKERNSEC
52896 +
52897 +config GRKERNSEC_PROC
52898 + bool "Proc restrictions"
52899 + default y if GRKERNSEC_CONFIG_AUTO
52900 + help
52901 + If you say Y here, the permissions of the /proc filesystem
52902 + will be altered to enhance system security and privacy. You MUST
52903 + choose either a user only restriction or a user and group restriction.
52904 + Depending upon the option you choose, you can either restrict users to
52905 + see only the processes they themselves run, or choose a group that can
52906 + view all processes and files normally restricted to root if you choose
52907 + the "restrict to user only" option. NOTE: If you're running identd or
52908 + ntpd as a non-root user, you will have to run it as the group you
52909 + specify here.
52910 +
52911 +config GRKERNSEC_PROC_USER
52912 + bool "Restrict /proc to user only"
52913 + depends on GRKERNSEC_PROC
52914 + help
52915 + If you say Y here, non-root users will only be able to view their own
52916 + processes, and restricts them from viewing network-related information,
52917 + and viewing kernel symbol and module information.
52918 +
52919 +config GRKERNSEC_PROC_USERGROUP
52920 + bool "Allow special group"
52921 + default y if GRKERNSEC_CONFIG_AUTO
52922 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
52923 + help
52924 + If you say Y here, you will be able to select a group that will be
52925 + able to view all processes and network-related information. If you've
52926 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
52927 + remain hidden. This option is useful if you want to run identd as
52928 + a non-root user. The group you select may also be chosen at boot time
52929 + via "grsec_proc_gid=" on the kernel commandline.
52930 +
52931 +config GRKERNSEC_PROC_GID
52932 + int "GID for special group"
52933 + depends on GRKERNSEC_PROC_USERGROUP
52934 + default 1001
52935 +
52936 +config GRKERNSEC_PROC_ADD
52937 + bool "Additional restrictions"
52938 + default y if GRKERNSEC_CONFIG_AUTO
52939 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
52940 + help
52941 + If you say Y here, additional restrictions will be placed on
52942 + /proc that keep normal users from viewing device information and
52943 + slabinfo information that could be useful for exploits.
52944 +
52945 +config GRKERNSEC_LINK
52946 + bool "Linking restrictions"
52947 + default y if GRKERNSEC_CONFIG_AUTO
52948 + help
52949 + If you say Y here, /tmp race exploits will be prevented, since users
52950 + will no longer be able to follow symlinks owned by other users in
52951 + world-writable +t directories (e.g. /tmp), unless the owner of the
52952 + symlink is the owner of the directory. users will also not be
52953 + able to hardlink to files they do not own. If the sysctl option is
52954 + enabled, a sysctl option with name "linking_restrictions" is created.
52955 +
52956 +config GRKERNSEC_SYMLINKOWN
52957 + bool "Kernel-enforced SymlinksIfOwnerMatch"
52958 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
52959 + help
52960 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
52961 + that prevents it from being used as a security feature. As Apache
52962 + verifies the symlink by performing a stat() against the target of
52963 + the symlink before it is followed, an attacker can setup a symlink
52964 + to point to a same-owned file, then replace the symlink with one
52965 + that targets another user's file just after Apache "validates" the
52966 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
52967 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
52968 + will be in place for the group you specify. If the sysctl option
52969 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
52970 + created.
52971 +
52972 +config GRKERNSEC_SYMLINKOWN_GID
52973 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
52974 + depends on GRKERNSEC_SYMLINKOWN
52975 + default 1006
52976 + help
52977 + Setting this GID determines what group kernel-enforced
52978 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
52979 + is enabled, a sysctl option with name "symlinkown_gid" is created.
52980 +
52981 +config GRKERNSEC_FIFO
52982 + bool "FIFO restrictions"
52983 + default y if GRKERNSEC_CONFIG_AUTO
52984 + help
52985 + If you say Y here, users will not be able to write to FIFOs they don't
52986 + own in world-writable +t directories (e.g. /tmp), unless the owner of
52987 + the FIFO is the same owner of the directory it's held in. If the sysctl
52988 + option is enabled, a sysctl option with name "fifo_restrictions" is
52989 + created.
52990 +
52991 +config GRKERNSEC_SYSFS_RESTRICT
52992 + bool "Sysfs/debugfs restriction"
52993 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52994 + depends on SYSFS
52995 + help
52996 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
52997 + any filesystem normally mounted under it (e.g. debugfs) will be
52998 + mostly accessible only by root. These filesystems generally provide access
52999 + to hardware and debug information that isn't appropriate for unprivileged
53000 + users of the system. Sysfs and debugfs have also become a large source
53001 + of new vulnerabilities, ranging from infoleaks to local compromise.
53002 + There has been very little oversight with an eye toward security involved
53003 + in adding new exporters of information to these filesystems, so their
53004 + use is discouraged.
53005 + For reasons of compatibility, a few directories have been whitelisted
53006 + for access by non-root users:
53007 + /sys/fs/selinux
53008 + /sys/fs/fuse
53009 + /sys/devices/system/cpu
53010 +
53011 +config GRKERNSEC_ROFS
53012 + bool "Runtime read-only mount protection"
53013 + help
53014 + If you say Y here, a sysctl option with name "romount_protect" will
53015 + be created. By setting this option to 1 at runtime, filesystems
53016 + will be protected in the following ways:
53017 + * No new writable mounts will be allowed
53018 + * Existing read-only mounts won't be able to be remounted read/write
53019 + * Write operations will be denied on all block devices
53020 + This option acts independently of grsec_lock: once it is set to 1,
53021 + it cannot be turned off. Therefore, please be mindful of the resulting
53022 + behavior if this option is enabled in an init script on a read-only
53023 + filesystem. This feature is mainly intended for secure embedded systems.
53024 +
53025 +config GRKERNSEC_DEVICE_SIDECHANNEL
53026 + bool "Eliminate stat/notify-based device sidechannels"
53027 + default y if GRKERNSEC_CONFIG_AUTO
53028 + help
53029 + If you say Y here, timing analyses on block or character
53030 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
53031 + will be thwarted for unprivileged users. If a process without
53032 + CAP_MKNOD stats such a device, the last access and last modify times
53033 + will match the device's create time. No access or modify events
53034 + will be triggered through inotify/dnotify/fanotify for such devices.
53035 + This feature will prevent attacks that may at a minimum
53036 + allow an attacker to determine the administrator's password length.
53037 +
53038 +config GRKERNSEC_CHROOT
53039 + bool "Chroot jail restrictions"
53040 + default y if GRKERNSEC_CONFIG_AUTO
53041 + help
53042 + If you say Y here, you will be able to choose several options that will
53043 + make breaking out of a chrooted jail much more difficult. If you
53044 + encounter no software incompatibilities with the following options, it
53045 + is recommended that you enable each one.
53046 +
53047 +config GRKERNSEC_CHROOT_MOUNT
53048 + bool "Deny mounts"
53049 + default y if GRKERNSEC_CONFIG_AUTO
53050 + depends on GRKERNSEC_CHROOT
53051 + help
53052 + If you say Y here, processes inside a chroot will not be able to
53053 + mount or remount filesystems. If the sysctl option is enabled, a
53054 + sysctl option with name "chroot_deny_mount" is created.
53055 +
53056 +config GRKERNSEC_CHROOT_DOUBLE
53057 + bool "Deny double-chroots"
53058 + default y if GRKERNSEC_CONFIG_AUTO
53059 + depends on GRKERNSEC_CHROOT
53060 + help
53061 + If you say Y here, processes inside a chroot will not be able to chroot
53062 + again outside the chroot. This is a widely used method of breaking
53063 + out of a chroot jail and should not be allowed. If the sysctl
53064 + option is enabled, a sysctl option with name
53065 + "chroot_deny_chroot" is created.
53066 +
53067 +config GRKERNSEC_CHROOT_PIVOT
53068 + bool "Deny pivot_root in chroot"
53069 + default y if GRKERNSEC_CONFIG_AUTO
53070 + depends on GRKERNSEC_CHROOT
53071 + help
53072 + If you say Y here, processes inside a chroot will not be able to use
53073 + a function called pivot_root() that was introduced in Linux 2.3.41. It
53074 + works similar to chroot in that it changes the root filesystem. This
53075 + function could be misused in a chrooted process to attempt to break out
53076 + of the chroot, and therefore should not be allowed. If the sysctl
53077 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
53078 + created.
53079 +
53080 +config GRKERNSEC_CHROOT_CHDIR
53081 + bool "Enforce chdir(\"/\") on all chroots"
53082 + default y if GRKERNSEC_CONFIG_AUTO
53083 + depends on GRKERNSEC_CHROOT
53084 + help
53085 + If you say Y here, the current working directory of all newly-chrooted
53086 + applications will be set to the the root directory of the chroot.
53087 + The man page on chroot(2) states:
53088 + Note that this call does not change the current working
53089 + directory, so that `.' can be outside the tree rooted at
53090 + `/'. In particular, the super-user can escape from a
53091 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
53092 +
53093 + It is recommended that you say Y here, since it's not known to break
53094 + any software. If the sysctl option is enabled, a sysctl option with
53095 + name "chroot_enforce_chdir" is created.
53096 +
53097 +config GRKERNSEC_CHROOT_CHMOD
53098 + bool "Deny (f)chmod +s"
53099 + default y if GRKERNSEC_CONFIG_AUTO
53100 + depends on GRKERNSEC_CHROOT
53101 + help
53102 + If you say Y here, processes inside a chroot will not be able to chmod
53103 + or fchmod files to make them have suid or sgid bits. This protects
53104 + against another published method of breaking a chroot. If the sysctl
53105 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
53106 + created.
53107 +
53108 +config GRKERNSEC_CHROOT_FCHDIR
53109 + bool "Deny fchdir out of chroot"
53110 + default y if GRKERNSEC_CONFIG_AUTO
53111 + depends on GRKERNSEC_CHROOT
53112 + help
53113 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
53114 + to a file descriptor of the chrooting process that points to a directory
53115 + outside the filesystem will be stopped. If the sysctl option
53116 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
53117 +
53118 +config GRKERNSEC_CHROOT_MKNOD
53119 + bool "Deny mknod"
53120 + default y if GRKERNSEC_CONFIG_AUTO
53121 + depends on GRKERNSEC_CHROOT
53122 + help
53123 + If you say Y here, processes inside a chroot will not be allowed to
53124 + mknod. The problem with using mknod inside a chroot is that it
53125 + would allow an attacker to create a device entry that is the same
53126 + as one on the physical root of your system, which could range from
53127 + anything from the console device to a device for your harddrive (which
53128 + they could then use to wipe the drive or steal data). It is recommended
53129 + that you say Y here, unless you run into software incompatibilities.
53130 + If the sysctl option is enabled, a sysctl option with name
53131 + "chroot_deny_mknod" is created.
53132 +
53133 +config GRKERNSEC_CHROOT_SHMAT
53134 + bool "Deny shmat() out of chroot"
53135 + default y if GRKERNSEC_CONFIG_AUTO
53136 + depends on GRKERNSEC_CHROOT
53137 + help
53138 + If you say Y here, processes inside a chroot will not be able to attach
53139 + to shared memory segments that were created outside of the chroot jail.
53140 + It is recommended that you say Y here. If the sysctl option is enabled,
53141 + a sysctl option with name "chroot_deny_shmat" is created.
53142 +
53143 +config GRKERNSEC_CHROOT_UNIX
53144 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
53145 + default y if GRKERNSEC_CONFIG_AUTO
53146 + depends on GRKERNSEC_CHROOT
53147 + help
53148 + If you say Y here, processes inside a chroot will not be able to
53149 + connect to abstract (meaning not belonging to a filesystem) Unix
53150 + domain sockets that were bound outside of a chroot. It is recommended
53151 + that you say Y here. If the sysctl option is enabled, a sysctl option
53152 + with name "chroot_deny_unix" is created.
53153 +
53154 +config GRKERNSEC_CHROOT_FINDTASK
53155 + bool "Protect outside processes"
53156 + default y if GRKERNSEC_CONFIG_AUTO
53157 + depends on GRKERNSEC_CHROOT
53158 + help
53159 + If you say Y here, processes inside a chroot will not be able to
53160 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
53161 + getsid, or view any process outside of the chroot. If the sysctl
53162 + option is enabled, a sysctl option with name "chroot_findtask" is
53163 + created.
53164 +
53165 +config GRKERNSEC_CHROOT_NICE
53166 + bool "Restrict priority changes"
53167 + default y if GRKERNSEC_CONFIG_AUTO
53168 + depends on GRKERNSEC_CHROOT
53169 + help
53170 + If you say Y here, processes inside a chroot will not be able to raise
53171 + the priority of processes in the chroot, or alter the priority of
53172 + processes outside the chroot. This provides more security than simply
53173 + removing CAP_SYS_NICE from the process' capability set. If the
53174 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
53175 + is created.
53176 +
53177 +config GRKERNSEC_CHROOT_SYSCTL
53178 + bool "Deny sysctl writes"
53179 + default y if GRKERNSEC_CONFIG_AUTO
53180 + depends on GRKERNSEC_CHROOT
53181 + help
53182 + If you say Y here, an attacker in a chroot will not be able to
53183 + write to sysctl entries, either by sysctl(2) or through a /proc
53184 + interface. It is strongly recommended that you say Y here. If the
53185 + sysctl option is enabled, a sysctl option with name
53186 + "chroot_deny_sysctl" is created.
53187 +
53188 +config GRKERNSEC_CHROOT_CAPS
53189 + bool "Capability restrictions"
53190 + default y if GRKERNSEC_CONFIG_AUTO
53191 + depends on GRKERNSEC_CHROOT
53192 + help
53193 + If you say Y here, the capabilities on all processes within a
53194 + chroot jail will be lowered to stop module insertion, raw i/o,
53195 + system and net admin tasks, rebooting the system, modifying immutable
53196 + files, modifying IPC owned by another, and changing the system time.
53197 + This is left an option because it can break some apps. Disable this
53198 + if your chrooted apps are having problems performing those kinds of
53199 + tasks. If the sysctl option is enabled, a sysctl option with
53200 + name "chroot_caps" is created.
53201 +
53202 +endmenu
53203 +menu "Kernel Auditing"
53204 +depends on GRKERNSEC
53205 +
53206 +config GRKERNSEC_AUDIT_GROUP
53207 + bool "Single group for auditing"
53208 + help
53209 + If you say Y here, the exec and chdir logging features will only operate
53210 + on a group you specify. This option is recommended if you only want to
53211 + watch certain users instead of having a large amount of logs from the
53212 + entire system. If the sysctl option is enabled, a sysctl option with
53213 + name "audit_group" is created.
53214 +
53215 +config GRKERNSEC_AUDIT_GID
53216 + int "GID for auditing"
53217 + depends on GRKERNSEC_AUDIT_GROUP
53218 + default 1007
53219 +
53220 +config GRKERNSEC_EXECLOG
53221 + bool "Exec logging"
53222 + help
53223 + If you say Y here, all execve() calls will be logged (since the
53224 + other exec*() calls are frontends to execve(), all execution
53225 + will be logged). Useful for shell-servers that like to keep track
53226 + of their users. If the sysctl option is enabled, a sysctl option with
53227 + name "exec_logging" is created.
53228 + WARNING: This option when enabled will produce a LOT of logs, especially
53229 + on an active system.
53230 +
53231 +config GRKERNSEC_RESLOG
53232 + bool "Resource logging"
53233 + default y if GRKERNSEC_CONFIG_AUTO
53234 + help
53235 + If you say Y here, all attempts to overstep resource limits will
53236 + be logged with the resource name, the requested size, and the current
53237 + limit. It is highly recommended that you say Y here. If the sysctl
53238 + option is enabled, a sysctl option with name "resource_logging" is
53239 + created. If the RBAC system is enabled, the sysctl value is ignored.
53240 +
53241 +config GRKERNSEC_CHROOT_EXECLOG
53242 + bool "Log execs within chroot"
53243 + help
53244 + If you say Y here, all executions inside a chroot jail will be logged
53245 + to syslog. This can cause a large amount of logs if certain
53246 + applications (eg. djb's daemontools) are installed on the system, and
53247 + is therefore left as an option. If the sysctl option is enabled, a
53248 + sysctl option with name "chroot_execlog" is created.
53249 +
53250 +config GRKERNSEC_AUDIT_PTRACE
53251 + bool "Ptrace logging"
53252 + help
53253 + If you say Y here, all attempts to attach to a process via ptrace
53254 + will be logged. If the sysctl option is enabled, a sysctl option
53255 + with name "audit_ptrace" is created.
53256 +
53257 +config GRKERNSEC_AUDIT_CHDIR
53258 + bool "Chdir logging"
53259 + help
53260 + If you say Y here, all chdir() calls will be logged. If the sysctl
53261 + option is enabled, a sysctl option with name "audit_chdir" is created.
53262 +
53263 +config GRKERNSEC_AUDIT_MOUNT
53264 + bool "(Un)Mount logging"
53265 + help
53266 + If you say Y here, all mounts and unmounts will be logged. If the
53267 + sysctl option is enabled, a sysctl option with name "audit_mount" is
53268 + created.
53269 +
53270 +config GRKERNSEC_SIGNAL
53271 + bool "Signal logging"
53272 + default y if GRKERNSEC_CONFIG_AUTO
53273 + help
53274 + If you say Y here, certain important signals will be logged, such as
53275 + SIGSEGV, which will as a result inform you of when a error in a program
53276 + occurred, which in some cases could mean a possible exploit attempt.
53277 + If the sysctl option is enabled, a sysctl option with name
53278 + "signal_logging" is created.
53279 +
53280 +config GRKERNSEC_FORKFAIL
53281 + bool "Fork failure logging"
53282 + help
53283 + If you say Y here, all failed fork() attempts will be logged.
53284 + This could suggest a fork bomb, or someone attempting to overstep
53285 + their process limit. If the sysctl option is enabled, a sysctl option
53286 + with name "forkfail_logging" is created.
53287 +
53288 +config GRKERNSEC_TIME
53289 + bool "Time change logging"
53290 + default y if GRKERNSEC_CONFIG_AUTO
53291 + help
53292 + If you say Y here, any changes of the system clock will be logged.
53293 + If the sysctl option is enabled, a sysctl option with name
53294 + "timechange_logging" is created.
53295 +
53296 +config GRKERNSEC_PROC_IPADDR
53297 + bool "/proc/<pid>/ipaddr support"
53298 + default y if GRKERNSEC_CONFIG_AUTO
53299 + help
53300 + If you say Y here, a new entry will be added to each /proc/<pid>
53301 + directory that contains the IP address of the person using the task.
53302 + The IP is carried across local TCP and AF_UNIX stream sockets.
53303 + This information can be useful for IDS/IPSes to perform remote response
53304 + to a local attack. The entry is readable by only the owner of the
53305 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
53306 + the RBAC system), and thus does not create privacy concerns.
53307 +
53308 +config GRKERNSEC_RWXMAP_LOG
53309 + bool 'Denied RWX mmap/mprotect logging'
53310 + default y if GRKERNSEC_CONFIG_AUTO
53311 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
53312 + help
53313 + If you say Y here, calls to mmap() and mprotect() with explicit
53314 + usage of PROT_WRITE and PROT_EXEC together will be logged when
53315 + denied by the PAX_MPROTECT feature. If the sysctl option is
53316 + enabled, a sysctl option with name "rwxmap_logging" is created.
53317 +
53318 +config GRKERNSEC_AUDIT_TEXTREL
53319 + bool 'ELF text relocations logging (READ HELP)'
53320 + depends on PAX_MPROTECT
53321 + help
53322 + If you say Y here, text relocations will be logged with the filename
53323 + of the offending library or binary. The purpose of the feature is
53324 + to help Linux distribution developers get rid of libraries and
53325 + binaries that need text relocations which hinder the future progress
53326 + of PaX. Only Linux distribution developers should say Y here, and
53327 + never on a production machine, as this option creates an information
53328 + leak that could aid an attacker in defeating the randomization of
53329 + a single memory region. If the sysctl option is enabled, a sysctl
53330 + option with name "audit_textrel" is created.
53331 +
53332 +endmenu
53333 +
53334 +menu "Executable Protections"
53335 +depends on GRKERNSEC
53336 +
53337 +config GRKERNSEC_DMESG
53338 + bool "Dmesg(8) restriction"
53339 + default y if GRKERNSEC_CONFIG_AUTO
53340 + help
53341 + If you say Y here, non-root users will not be able to use dmesg(8)
53342 + to view the contents of the kernel's circular log buffer.
53343 + The kernel's log buffer often contains kernel addresses and other
53344 + identifying information useful to an attacker in fingerprinting a
53345 + system for a targeted exploit.
53346 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
53347 + created.
53348 +
53349 +config GRKERNSEC_HARDEN_PTRACE
53350 + bool "Deter ptrace-based process snooping"
53351 + default y if GRKERNSEC_CONFIG_AUTO
53352 + help
53353 + If you say Y here, TTY sniffers and other malicious monitoring
53354 + programs implemented through ptrace will be defeated. If you
53355 + have been using the RBAC system, this option has already been
53356 + enabled for several years for all users, with the ability to make
53357 + fine-grained exceptions.
53358 +
53359 + This option only affects the ability of non-root users to ptrace
53360 + processes that are not a descendent of the ptracing process.
53361 + This means that strace ./binary and gdb ./binary will still work,
53362 + but attaching to arbitrary processes will not. If the sysctl
53363 + option is enabled, a sysctl option with name "harden_ptrace" is
53364 + created.
53365 +
53366 +config GRKERNSEC_PTRACE_READEXEC
53367 + bool "Require read access to ptrace sensitive binaries"
53368 + default y if GRKERNSEC_CONFIG_AUTO
53369 + help
53370 + If you say Y here, unprivileged users will not be able to ptrace unreadable
53371 + binaries. This option is useful in environments that
53372 + remove the read bits (e.g. file mode 4711) from suid binaries to
53373 + prevent infoleaking of their contents. This option adds
53374 + consistency to the use of that file mode, as the binary could normally
53375 + be read out when run without privileges while ptracing.
53376 +
53377 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
53378 + is created.
53379 +
53380 +config GRKERNSEC_SETXID
53381 + bool "Enforce consistent multithreaded privileges"
53382 + default y if GRKERNSEC_CONFIG_AUTO
53383 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
53384 + help
53385 + If you say Y here, a change from a root uid to a non-root uid
53386 + in a multithreaded application will cause the resulting uids,
53387 + gids, supplementary groups, and capabilities in that thread
53388 + to be propagated to the other threads of the process. In most
53389 + cases this is unnecessary, as glibc will emulate this behavior
53390 + on behalf of the application. Other libcs do not act in the
53391 + same way, allowing the other threads of the process to continue
53392 + running with root privileges. If the sysctl option is enabled,
53393 + a sysctl option with name "consistent_setxid" is created.
53394 +
53395 +config GRKERNSEC_TPE
53396 + bool "Trusted Path Execution (TPE)"
53397 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
53398 + help
53399 + If you say Y here, you will be able to choose a gid to add to the
53400 + supplementary groups of users you want to mark as "untrusted."
53401 + These users will not be able to execute any files that are not in
53402 + root-owned directories writable only by root. If the sysctl option
53403 + is enabled, a sysctl option with name "tpe" is created.
53404 +
53405 +config GRKERNSEC_TPE_ALL
53406 + bool "Partially restrict all non-root users"
53407 + depends on GRKERNSEC_TPE
53408 + help
53409 + If you say Y here, all non-root users will be covered under
53410 + a weaker TPE restriction. This is separate from, and in addition to,
53411 + the main TPE options that you have selected elsewhere. Thus, if a
53412 + "trusted" GID is chosen, this restriction applies to even that GID.
53413 + Under this restriction, all non-root users will only be allowed to
53414 + execute files in directories they own that are not group or
53415 + world-writable, or in directories owned by root and writable only by
53416 + root. If the sysctl option is enabled, a sysctl option with name
53417 + "tpe_restrict_all" is created.
53418 +
53419 +config GRKERNSEC_TPE_INVERT
53420 + bool "Invert GID option"
53421 + depends on GRKERNSEC_TPE
53422 + help
53423 + If you say Y here, the group you specify in the TPE configuration will
53424 + decide what group TPE restrictions will be *disabled* for. This
53425 + option is useful if you want TPE restrictions to be applied to most
53426 + users on the system. If the sysctl option is enabled, a sysctl option
53427 + with name "tpe_invert" is created. Unlike other sysctl options, this
53428 + entry will default to on for backward-compatibility.
53429 +
53430 +config GRKERNSEC_TPE_GID
53431 + int
53432 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
53433 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
53434 +
53435 +config GRKERNSEC_TPE_UNTRUSTED_GID
53436 + int "GID for TPE-untrusted users"
53437 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
53438 + default 1005
53439 + help
53440 + Setting this GID determines what group TPE restrictions will be
53441 + *enabled* for. If the sysctl option is enabled, a sysctl option
53442 + with name "tpe_gid" is created.
53443 +
53444 +config GRKERNSEC_TPE_TRUSTED_GID
53445 + int "GID for TPE-trusted users"
53446 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
53447 + default 1005
53448 + help
53449 + Setting this GID determines what group TPE restrictions will be
53450 + *disabled* for. If the sysctl option is enabled, a sysctl option
53451 + with name "tpe_gid" is created.
53452 +
53453 +endmenu
53454 +menu "Network Protections"
53455 +depends on GRKERNSEC
53456 +
53457 +config GRKERNSEC_RANDNET
53458 + bool "Larger entropy pools"
53459 + default y if GRKERNSEC_CONFIG_AUTO
53460 + help
53461 + If you say Y here, the entropy pools used for many features of Linux
53462 + and grsecurity will be doubled in size. Since several grsecurity
53463 + features use additional randomness, it is recommended that you say Y
53464 + here. Saying Y here has a similar effect as modifying
53465 + /proc/sys/kernel/random/poolsize.
53466 +
53467 +config GRKERNSEC_BLACKHOLE
53468 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
53469 + default y if GRKERNSEC_CONFIG_AUTO
53470 + depends on NET
53471 + help
53472 + If you say Y here, neither TCP resets nor ICMP
53473 + destination-unreachable packets will be sent in response to packets
53474 + sent to ports for which no associated listening process exists.
53475 + This feature supports both IPV4 and IPV6 and exempts the
53476 + loopback interface from blackholing. Enabling this feature
53477 + makes a host more resilient to DoS attacks and reduces network
53478 + visibility against scanners.
53479 +
53480 + The blackhole feature as-implemented is equivalent to the FreeBSD
53481 + blackhole feature, as it prevents RST responses to all packets, not
53482 + just SYNs. Under most application behavior this causes no
53483 + problems, but applications (like haproxy) may not close certain
53484 + connections in a way that cleanly terminates them on the remote
53485 + end, leaving the remote host in LAST_ACK state. Because of this
53486 + side-effect and to prevent intentional LAST_ACK DoSes, this
53487 + feature also adds automatic mitigation against such attacks.
53488 + The mitigation drastically reduces the amount of time a socket
53489 + can spend in LAST_ACK state. If you're using haproxy and not
53490 + all servers it connects to have this option enabled, consider
53491 + disabling this feature on the haproxy host.
53492 +
53493 + If the sysctl option is enabled, two sysctl options with names
53494 + "ip_blackhole" and "lastack_retries" will be created.
53495 + While "ip_blackhole" takes the standard zero/non-zero on/off
53496 + toggle, "lastack_retries" uses the same kinds of values as
53497 + "tcp_retries1" and "tcp_retries2". The default value of 4
53498 + prevents a socket from lasting more than 45 seconds in LAST_ACK
53499 + state.
53500 +
53501 +config GRKERNSEC_NO_SIMULT_CONNECT
53502 + bool "Disable TCP Simultaneous Connect"
53503 + default y if GRKERNSEC_CONFIG_AUTO
53504 + depends on NET
53505 + help
53506 + If you say Y here, a feature by Willy Tarreau will be enabled that
53507 + removes a weakness in Linux's strict implementation of TCP that
53508 + allows two clients to connect to each other without either entering
53509 + a listening state. The weakness allows an attacker to easily prevent
53510 + a client from connecting to a known server provided the source port
53511 + for the connection is guessed correctly.
53512 +
53513 + As the weakness could be used to prevent an antivirus or IPS from
53514 + fetching updates, or prevent an SSL gateway from fetching a CRL,
53515 + it should be eliminated by enabling this option. Though Linux is
53516 + one of few operating systems supporting simultaneous connect, it
53517 + has no legitimate use in practice and is rarely supported by firewalls.
53518 +
53519 +config GRKERNSEC_SOCKET
53520 + bool "Socket restrictions"
53521 + depends on NET
53522 + help
53523 + If you say Y here, you will be able to choose from several options.
53524 + If you assign a GID on your system and add it to the supplementary
53525 + groups of users you want to restrict socket access to, this patch
53526 + will perform up to three things, based on the option(s) you choose.
53527 +
53528 +config GRKERNSEC_SOCKET_ALL
53529 + bool "Deny any sockets to group"
53530 + depends on GRKERNSEC_SOCKET
53531 + help
53532 + If you say Y here, you will be able to choose a GID of whose users will
53533 + be unable to connect to other hosts from your machine or run server
53534 + applications from your machine. If the sysctl option is enabled, a
53535 + sysctl option with name "socket_all" is created.
53536 +
53537 +config GRKERNSEC_SOCKET_ALL_GID
53538 + int "GID to deny all sockets for"
53539 + depends on GRKERNSEC_SOCKET_ALL
53540 + default 1004
53541 + help
53542 + Here you can choose the GID to disable socket access for. Remember to
53543 + add the users you want socket access disabled for to the GID
53544 + specified here. If the sysctl option is enabled, a sysctl option
53545 + with name "socket_all_gid" is created.
53546 +
53547 +config GRKERNSEC_SOCKET_CLIENT
53548 + bool "Deny client sockets to group"
53549 + depends on GRKERNSEC_SOCKET
53550 + help
53551 + If you say Y here, you will be able to choose a GID of whose users will
53552 + be unable to connect to other hosts from your machine, but will be
53553 + able to run servers. If this option is enabled, all users in the group
53554 + you specify will have to use passive mode when initiating ftp transfers
53555 + from the shell on your machine. If the sysctl option is enabled, a
53556 + sysctl option with name "socket_client" is created.
53557 +
53558 +config GRKERNSEC_SOCKET_CLIENT_GID
53559 + int "GID to deny client sockets for"
53560 + depends on GRKERNSEC_SOCKET_CLIENT
53561 + default 1003
53562 + help
53563 + Here you can choose the GID to disable client socket access for.
53564 + Remember to add the users you want client socket access disabled for to
53565 + the GID specified here. If the sysctl option is enabled, a sysctl
53566 + option with name "socket_client_gid" is created.
53567 +
53568 +config GRKERNSEC_SOCKET_SERVER
53569 + bool "Deny server sockets to group"
53570 + depends on GRKERNSEC_SOCKET
53571 + help
53572 + If you say Y here, you will be able to choose a GID of whose users will
53573 + be unable to run server applications from your machine. If the sysctl
53574 + option is enabled, a sysctl option with name "socket_server" is created.
53575 +
53576 +config GRKERNSEC_SOCKET_SERVER_GID
53577 + int "GID to deny server sockets for"
53578 + depends on GRKERNSEC_SOCKET_SERVER
53579 + default 1002
53580 + help
53581 + Here you can choose the GID to disable server socket access for.
53582 + Remember to add the users you want server socket access disabled for to
53583 + the GID specified here. If the sysctl option is enabled, a sysctl
53584 + option with name "socket_server_gid" is created.
53585 +
53586 +endmenu
53587 +menu "Sysctl Support"
53588 +depends on GRKERNSEC && SYSCTL
53589 +
53590 +config GRKERNSEC_SYSCTL
53591 + bool "Sysctl support"
53592 + default y if GRKERNSEC_CONFIG_AUTO
53593 + help
53594 + If you say Y here, you will be able to change the options that
53595 + grsecurity runs with at bootup, without having to recompile your
53596 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
53597 + to enable (1) or disable (0) various features. All the sysctl entries
53598 + are mutable until the "grsec_lock" entry is set to a non-zero value.
53599 + All features enabled in the kernel configuration are disabled at boot
53600 + if you do not say Y to the "Turn on features by default" option.
53601 + All options should be set at startup, and the grsec_lock entry should
53602 + be set to a non-zero value after all the options are set.
53603 + *THIS IS EXTREMELY IMPORTANT*
53604 +
53605 +config GRKERNSEC_SYSCTL_DISTRO
53606 + bool "Extra sysctl support for distro makers (READ HELP)"
53607 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
53608 + help
53609 + If you say Y here, additional sysctl options will be created
53610 + for features that affect processes running as root. Therefore,
53611 + it is critical when using this option that the grsec_lock entry be
53612 + enabled after boot. Only distros with prebuilt kernel packages
53613 + with this option enabled that can ensure grsec_lock is enabled
53614 + after boot should use this option.
53615 + *Failure to set grsec_lock after boot makes all grsec features
53616 + this option covers useless*
53617 +
53618 + Currently this option creates the following sysctl entries:
53619 + "Disable Privileged I/O": "disable_priv_io"
53620 +
53621 +config GRKERNSEC_SYSCTL_ON
53622 + bool "Turn on features by default"
53623 + default y if GRKERNSEC_CONFIG_AUTO
53624 + depends on GRKERNSEC_SYSCTL
53625 + help
53626 + If you say Y here, instead of having all features enabled in the
53627 + kernel configuration disabled at boot time, the features will be
53628 + enabled at boot time. It is recommended you say Y here unless
53629 + there is some reason you would want all sysctl-tunable features to
53630 + be disabled by default. As mentioned elsewhere, it is important
53631 + to enable the grsec_lock entry once you have finished modifying
53632 + the sysctl entries.
53633 +
53634 +endmenu
53635 +menu "Logging Options"
53636 +depends on GRKERNSEC
53637 +
53638 +config GRKERNSEC_FLOODTIME
53639 + int "Seconds in between log messages (minimum)"
53640 + default 10
53641 + help
53642 + This option allows you to enforce the number of seconds between
53643 + grsecurity log messages. The default should be suitable for most
53644 + people, however, if you choose to change it, choose a value small enough
53645 + to allow informative logs to be produced, but large enough to
53646 + prevent flooding.
53647 +
53648 +config GRKERNSEC_FLOODBURST
53649 + int "Number of messages in a burst (maximum)"
53650 + default 6
53651 + help
53652 + This option allows you to choose the maximum number of messages allowed
53653 + within the flood time interval you chose in a separate option. The
53654 + default should be suitable for most people, however if you find that
53655 + many of your logs are being interpreted as flooding, you may want to
53656 + raise this value.
53657 +
53658 +endmenu
53659 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
53660 new file mode 100644
53661 index 0000000..1b9afa9
53662 --- /dev/null
53663 +++ b/grsecurity/Makefile
53664 @@ -0,0 +1,38 @@
53665 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
53666 +# during 2001-2009 it has been completely redesigned by Brad Spengler
53667 +# into an RBAC system
53668 +#
53669 +# All code in this directory and various hooks inserted throughout the kernel
53670 +# are copyright Brad Spengler - Open Source Security, Inc., and released
53671 +# under the GPL v2 or higher
53672 +
53673 +KBUILD_CFLAGS += -Werror
53674 +
53675 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
53676 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
53677 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
53678 +
53679 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
53680 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
53681 + gracl_learn.o grsec_log.o
53682 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
53683 +
53684 +ifdef CONFIG_NET
53685 +obj-y += grsec_sock.o
53686 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
53687 +endif
53688 +
53689 +ifndef CONFIG_GRKERNSEC
53690 +obj-y += grsec_disabled.o
53691 +endif
53692 +
53693 +ifdef CONFIG_GRKERNSEC_HIDESYM
53694 +extra-y := grsec_hidesym.o
53695 +$(obj)/grsec_hidesym.o:
53696 + @-chmod -f 500 /boot
53697 + @-chmod -f 500 /lib/modules
53698 + @-chmod -f 500 /lib64/modules
53699 + @-chmod -f 500 /lib32/modules
53700 + @-chmod -f 700 .
53701 + @echo ' grsec: protected kernel image paths'
53702 +endif
53703 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
53704 new file mode 100644
53705 index 0000000..960766a
53706 --- /dev/null
53707 +++ b/grsecurity/gracl.c
53708 @@ -0,0 +1,4003 @@
53709 +#include <linux/kernel.h>
53710 +#include <linux/module.h>
53711 +#include <linux/sched.h>
53712 +#include <linux/mm.h>
53713 +#include <linux/file.h>
53714 +#include <linux/fs.h>
53715 +#include <linux/namei.h>
53716 +#include <linux/mount.h>
53717 +#include <linux/tty.h>
53718 +#include <linux/proc_fs.h>
53719 +#include <linux/lglock.h>
53720 +#include <linux/slab.h>
53721 +#include <linux/vmalloc.h>
53722 +#include <linux/types.h>
53723 +#include <linux/sysctl.h>
53724 +#include <linux/netdevice.h>
53725 +#include <linux/ptrace.h>
53726 +#include <linux/gracl.h>
53727 +#include <linux/gralloc.h>
53728 +#include <linux/security.h>
53729 +#include <linux/grinternal.h>
53730 +#include <linux/pid_namespace.h>
53731 +#include <linux/stop_machine.h>
53732 +#include <linux/fdtable.h>
53733 +#include <linux/percpu.h>
53734 +#include <linux/lglock.h>
53735 +#include "../fs/mount.h"
53736 +
53737 +#include <asm/uaccess.h>
53738 +#include <asm/errno.h>
53739 +#include <asm/mman.h>
53740 +
53741 +extern struct lglock vfsmount_lock;
53742 +
53743 +static struct acl_role_db acl_role_set;
53744 +static struct name_db name_set;
53745 +static struct inodev_db inodev_set;
53746 +
53747 +/* for keeping track of userspace pointers used for subjects, so we
53748 + can share references in the kernel as well
53749 +*/
53750 +
53751 +static struct path real_root;
53752 +
53753 +static struct acl_subj_map_db subj_map_set;
53754 +
53755 +static struct acl_role_label *default_role;
53756 +
53757 +static struct acl_role_label *role_list;
53758 +
53759 +static u16 acl_sp_role_value;
53760 +
53761 +extern char *gr_shared_page[4];
53762 +static DEFINE_MUTEX(gr_dev_mutex);
53763 +DEFINE_RWLOCK(gr_inode_lock);
53764 +
53765 +struct gr_arg *gr_usermode;
53766 +
53767 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
53768 +
53769 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
53770 +extern void gr_clear_learn_entries(void);
53771 +
53772 +unsigned char *gr_system_salt;
53773 +unsigned char *gr_system_sum;
53774 +
53775 +static struct sprole_pw **acl_special_roles = NULL;
53776 +static __u16 num_sprole_pws = 0;
53777 +
53778 +static struct acl_role_label *kernel_role = NULL;
53779 +
53780 +static unsigned int gr_auth_attempts = 0;
53781 +static unsigned long gr_auth_expires = 0UL;
53782 +
53783 +#ifdef CONFIG_NET
53784 +extern struct vfsmount *sock_mnt;
53785 +#endif
53786 +
53787 +extern struct vfsmount *pipe_mnt;
53788 +extern struct vfsmount *shm_mnt;
53789 +#ifdef CONFIG_HUGETLBFS
53790 +extern struct vfsmount *hugetlbfs_vfsmount;
53791 +#endif
53792 +
53793 +static struct acl_object_label *fakefs_obj_rw;
53794 +static struct acl_object_label *fakefs_obj_rwx;
53795 +
53796 +extern int gr_init_uidset(void);
53797 +extern void gr_free_uidset(void);
53798 +extern void gr_remove_uid(uid_t uid);
53799 +extern int gr_find_uid(uid_t uid);
53800 +
53801 +__inline__ int
53802 +gr_acl_is_enabled(void)
53803 +{
53804 + return (gr_status & GR_READY);
53805 +}
53806 +
53807 +#ifdef CONFIG_BTRFS_FS
53808 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
53809 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
53810 +#endif
53811 +
53812 +static inline dev_t __get_dev(const struct dentry *dentry)
53813 +{
53814 +#ifdef CONFIG_BTRFS_FS
53815 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
53816 + return get_btrfs_dev_from_inode(dentry->d_inode);
53817 + else
53818 +#endif
53819 + return dentry->d_inode->i_sb->s_dev;
53820 +}
53821 +
53822 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
53823 +{
53824 + return __get_dev(dentry);
53825 +}
53826 +
53827 +static char gr_task_roletype_to_char(struct task_struct *task)
53828 +{
53829 + switch (task->role->roletype &
53830 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
53831 + GR_ROLE_SPECIAL)) {
53832 + case GR_ROLE_DEFAULT:
53833 + return 'D';
53834 + case GR_ROLE_USER:
53835 + return 'U';
53836 + case GR_ROLE_GROUP:
53837 + return 'G';
53838 + case GR_ROLE_SPECIAL:
53839 + return 'S';
53840 + }
53841 +
53842 + return 'X';
53843 +}
53844 +
53845 +char gr_roletype_to_char(void)
53846 +{
53847 + return gr_task_roletype_to_char(current);
53848 +}
53849 +
53850 +__inline__ int
53851 +gr_acl_tpe_check(void)
53852 +{
53853 + if (unlikely(!(gr_status & GR_READY)))
53854 + return 0;
53855 + if (current->role->roletype & GR_ROLE_TPE)
53856 + return 1;
53857 + else
53858 + return 0;
53859 +}
53860 +
53861 +int
53862 +gr_handle_rawio(const struct inode *inode)
53863 +{
53864 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
53865 + if (inode && S_ISBLK(inode->i_mode) &&
53866 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
53867 + !capable(CAP_SYS_RAWIO))
53868 + return 1;
53869 +#endif
53870 + return 0;
53871 +}
53872 +
53873 +static int
53874 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
53875 +{
53876 + if (likely(lena != lenb))
53877 + return 0;
53878 +
53879 + return !memcmp(a, b, lena);
53880 +}
53881 +
53882 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
53883 +{
53884 + *buflen -= namelen;
53885 + if (*buflen < 0)
53886 + return -ENAMETOOLONG;
53887 + *buffer -= namelen;
53888 + memcpy(*buffer, str, namelen);
53889 + return 0;
53890 +}
53891 +
53892 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
53893 +{
53894 + return prepend(buffer, buflen, name->name, name->len);
53895 +}
53896 +
53897 +static int prepend_path(const struct path *path, struct path *root,
53898 + char **buffer, int *buflen)
53899 +{
53900 + struct dentry *dentry = path->dentry;
53901 + struct vfsmount *vfsmnt = path->mnt;
53902 + struct mount *mnt = real_mount(vfsmnt);
53903 + bool slash = false;
53904 + int error = 0;
53905 +
53906 + while (dentry != root->dentry || vfsmnt != root->mnt) {
53907 + struct dentry * parent;
53908 +
53909 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
53910 + /* Global root? */
53911 + if (!mnt_has_parent(mnt)) {
53912 + goto out;
53913 + }
53914 + dentry = mnt->mnt_mountpoint;
53915 + mnt = mnt->mnt_parent;
53916 + vfsmnt = &mnt->mnt;
53917 + continue;
53918 + }
53919 + parent = dentry->d_parent;
53920 + prefetch(parent);
53921 + spin_lock(&dentry->d_lock);
53922 + error = prepend_name(buffer, buflen, &dentry->d_name);
53923 + spin_unlock(&dentry->d_lock);
53924 + if (!error)
53925 + error = prepend(buffer, buflen, "/", 1);
53926 + if (error)
53927 + break;
53928 +
53929 + slash = true;
53930 + dentry = parent;
53931 + }
53932 +
53933 +out:
53934 + if (!error && !slash)
53935 + error = prepend(buffer, buflen, "/", 1);
53936 +
53937 + return error;
53938 +}
53939 +
53940 +/* this must be called with vfsmount_lock and rename_lock held */
53941 +
53942 +static char *__our_d_path(const struct path *path, struct path *root,
53943 + char *buf, int buflen)
53944 +{
53945 + char *res = buf + buflen;
53946 + int error;
53947 +
53948 + prepend(&res, &buflen, "\0", 1);
53949 + error = prepend_path(path, root, &res, &buflen);
53950 + if (error)
53951 + return ERR_PTR(error);
53952 +
53953 + return res;
53954 +}
53955 +
53956 +static char *
53957 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
53958 +{
53959 + char *retval;
53960 +
53961 + retval = __our_d_path(path, root, buf, buflen);
53962 + if (unlikely(IS_ERR(retval)))
53963 + retval = strcpy(buf, "<path too long>");
53964 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
53965 + retval[1] = '\0';
53966 +
53967 + return retval;
53968 +}
53969 +
53970 +static char *
53971 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53972 + char *buf, int buflen)
53973 +{
53974 + struct path path;
53975 + char *res;
53976 +
53977 + path.dentry = (struct dentry *)dentry;
53978 + path.mnt = (struct vfsmount *)vfsmnt;
53979 +
53980 + /* we can use real_root.dentry, real_root.mnt, because this is only called
53981 + by the RBAC system */
53982 + res = gen_full_path(&path, &real_root, buf, buflen);
53983 +
53984 + return res;
53985 +}
53986 +
53987 +static char *
53988 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53989 + char *buf, int buflen)
53990 +{
53991 + char *res;
53992 + struct path path;
53993 + struct path root;
53994 + struct task_struct *reaper = init_pid_ns.child_reaper;
53995 +
53996 + path.dentry = (struct dentry *)dentry;
53997 + path.mnt = (struct vfsmount *)vfsmnt;
53998 +
53999 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
54000 + get_fs_root(reaper->fs, &root);
54001 +
54002 + write_seqlock(&rename_lock);
54003 + br_read_lock(&vfsmount_lock);
54004 + res = gen_full_path(&path, &root, buf, buflen);
54005 + br_read_unlock(&vfsmount_lock);
54006 + write_sequnlock(&rename_lock);
54007 +
54008 + path_put(&root);
54009 + return res;
54010 +}
54011 +
54012 +static char *
54013 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
54014 +{
54015 + char *ret;
54016 + write_seqlock(&rename_lock);
54017 + br_read_lock(&vfsmount_lock);
54018 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
54019 + PAGE_SIZE);
54020 + br_read_unlock(&vfsmount_lock);
54021 + write_sequnlock(&rename_lock);
54022 + return ret;
54023 +}
54024 +
54025 +static char *
54026 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
54027 +{
54028 + char *ret;
54029 + char *buf;
54030 + int buflen;
54031 +
54032 + write_seqlock(&rename_lock);
54033 + br_read_lock(&vfsmount_lock);
54034 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54035 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
54036 + buflen = (int)(ret - buf);
54037 + if (buflen >= 5)
54038 + prepend(&ret, &buflen, "/proc", 5);
54039 + else
54040 + ret = strcpy(buf, "<path too long>");
54041 + br_read_unlock(&vfsmount_lock);
54042 + write_sequnlock(&rename_lock);
54043 + return ret;
54044 +}
54045 +
54046 +char *
54047 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
54048 +{
54049 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
54050 + PAGE_SIZE);
54051 +}
54052 +
54053 +char *
54054 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
54055 +{
54056 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54057 + PAGE_SIZE);
54058 +}
54059 +
54060 +char *
54061 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
54062 +{
54063 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
54064 + PAGE_SIZE);
54065 +}
54066 +
54067 +char *
54068 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
54069 +{
54070 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
54071 + PAGE_SIZE);
54072 +}
54073 +
54074 +char *
54075 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
54076 +{
54077 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
54078 + PAGE_SIZE);
54079 +}
54080 +
54081 +__inline__ __u32
54082 +to_gr_audit(const __u32 reqmode)
54083 +{
54084 + /* masks off auditable permission flags, then shifts them to create
54085 + auditing flags, and adds the special case of append auditing if
54086 + we're requesting write */
54087 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
54088 +}
54089 +
54090 +struct acl_subject_label *
54091 +lookup_subject_map(const struct acl_subject_label *userp)
54092 +{
54093 + unsigned int index = gr_shash(userp, subj_map_set.s_size);
54094 + struct subject_map *match;
54095 +
54096 + match = subj_map_set.s_hash[index];
54097 +
54098 + while (match && match->user != userp)
54099 + match = match->next;
54100 +
54101 + if (match != NULL)
54102 + return match->kernel;
54103 + else
54104 + return NULL;
54105 +}
54106 +
54107 +static void
54108 +insert_subj_map_entry(struct subject_map *subjmap)
54109 +{
54110 + unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
54111 + struct subject_map **curr;
54112 +
54113 + subjmap->prev = NULL;
54114 +
54115 + curr = &subj_map_set.s_hash[index];
54116 + if (*curr != NULL)
54117 + (*curr)->prev = subjmap;
54118 +
54119 + subjmap->next = *curr;
54120 + *curr = subjmap;
54121 +
54122 + return;
54123 +}
54124 +
54125 +static struct acl_role_label *
54126 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
54127 + const gid_t gid)
54128 +{
54129 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
54130 + struct acl_role_label *match;
54131 + struct role_allowed_ip *ipp;
54132 + unsigned int x;
54133 + u32 curr_ip = task->signal->curr_ip;
54134 +
54135 + task->signal->saved_ip = curr_ip;
54136 +
54137 + match = acl_role_set.r_hash[index];
54138 +
54139 + while (match) {
54140 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
54141 + for (x = 0; x < match->domain_child_num; x++) {
54142 + if (match->domain_children[x] == uid)
54143 + goto found;
54144 + }
54145 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
54146 + break;
54147 + match = match->next;
54148 + }
54149 +found:
54150 + if (match == NULL) {
54151 + try_group:
54152 + index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
54153 + match = acl_role_set.r_hash[index];
54154 +
54155 + while (match) {
54156 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
54157 + for (x = 0; x < match->domain_child_num; x++) {
54158 + if (match->domain_children[x] == gid)
54159 + goto found2;
54160 + }
54161 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
54162 + break;
54163 + match = match->next;
54164 + }
54165 +found2:
54166 + if (match == NULL)
54167 + match = default_role;
54168 + if (match->allowed_ips == NULL)
54169 + return match;
54170 + else {
54171 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54172 + if (likely
54173 + ((ntohl(curr_ip) & ipp->netmask) ==
54174 + (ntohl(ipp->addr) & ipp->netmask)))
54175 + return match;
54176 + }
54177 + match = default_role;
54178 + }
54179 + } else if (match->allowed_ips == NULL) {
54180 + return match;
54181 + } else {
54182 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54183 + if (likely
54184 + ((ntohl(curr_ip) & ipp->netmask) ==
54185 + (ntohl(ipp->addr) & ipp->netmask)))
54186 + return match;
54187 + }
54188 + goto try_group;
54189 + }
54190 +
54191 + return match;
54192 +}
54193 +
54194 +struct acl_subject_label *
54195 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
54196 + const struct acl_role_label *role)
54197 +{
54198 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54199 + struct acl_subject_label *match;
54200 +
54201 + match = role->subj_hash[index];
54202 +
54203 + while (match && (match->inode != ino || match->device != dev ||
54204 + (match->mode & GR_DELETED))) {
54205 + match = match->next;
54206 + }
54207 +
54208 + if (match && !(match->mode & GR_DELETED))
54209 + return match;
54210 + else
54211 + return NULL;
54212 +}
54213 +
54214 +struct acl_subject_label *
54215 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
54216 + const struct acl_role_label *role)
54217 +{
54218 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54219 + struct acl_subject_label *match;
54220 +
54221 + match = role->subj_hash[index];
54222 +
54223 + while (match && (match->inode != ino || match->device != dev ||
54224 + !(match->mode & GR_DELETED))) {
54225 + match = match->next;
54226 + }
54227 +
54228 + if (match && (match->mode & GR_DELETED))
54229 + return match;
54230 + else
54231 + return NULL;
54232 +}
54233 +
54234 +static struct acl_object_label *
54235 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
54236 + const struct acl_subject_label *subj)
54237 +{
54238 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54239 + struct acl_object_label *match;
54240 +
54241 + match = subj->obj_hash[index];
54242 +
54243 + while (match && (match->inode != ino || match->device != dev ||
54244 + (match->mode & GR_DELETED))) {
54245 + match = match->next;
54246 + }
54247 +
54248 + if (match && !(match->mode & GR_DELETED))
54249 + return match;
54250 + else
54251 + return NULL;
54252 +}
54253 +
54254 +static struct acl_object_label *
54255 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
54256 + const struct acl_subject_label *subj)
54257 +{
54258 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
54259 + struct acl_object_label *match;
54260 +
54261 + match = subj->obj_hash[index];
54262 +
54263 + while (match && (match->inode != ino || match->device != dev ||
54264 + !(match->mode & GR_DELETED))) {
54265 + match = match->next;
54266 + }
54267 +
54268 + if (match && (match->mode & GR_DELETED))
54269 + return match;
54270 +
54271 + match = subj->obj_hash[index];
54272 +
54273 + while (match && (match->inode != ino || match->device != dev ||
54274 + (match->mode & GR_DELETED))) {
54275 + match = match->next;
54276 + }
54277 +
54278 + if (match && !(match->mode & GR_DELETED))
54279 + return match;
54280 + else
54281 + return NULL;
54282 +}
54283 +
54284 +static struct name_entry *
54285 +lookup_name_entry(const char *name)
54286 +{
54287 + unsigned int len = strlen(name);
54288 + unsigned int key = full_name_hash(name, len);
54289 + unsigned int index = key % name_set.n_size;
54290 + struct name_entry *match;
54291 +
54292 + match = name_set.n_hash[index];
54293 +
54294 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
54295 + match = match->next;
54296 +
54297 + return match;
54298 +}
54299 +
54300 +static struct name_entry *
54301 +lookup_name_entry_create(const char *name)
54302 +{
54303 + unsigned int len = strlen(name);
54304 + unsigned int key = full_name_hash(name, len);
54305 + unsigned int index = key % name_set.n_size;
54306 + struct name_entry *match;
54307 +
54308 + match = name_set.n_hash[index];
54309 +
54310 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
54311 + !match->deleted))
54312 + match = match->next;
54313 +
54314 + if (match && match->deleted)
54315 + return match;
54316 +
54317 + match = name_set.n_hash[index];
54318 +
54319 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
54320 + match->deleted))
54321 + match = match->next;
54322 +
54323 + if (match && !match->deleted)
54324 + return match;
54325 + else
54326 + return NULL;
54327 +}
54328 +
54329 +static struct inodev_entry *
54330 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
54331 +{
54332 + unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
54333 + struct inodev_entry *match;
54334 +
54335 + match = inodev_set.i_hash[index];
54336 +
54337 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
54338 + match = match->next;
54339 +
54340 + return match;
54341 +}
54342 +
54343 +static void
54344 +insert_inodev_entry(struct inodev_entry *entry)
54345 +{
54346 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
54347 + inodev_set.i_size);
54348 + struct inodev_entry **curr;
54349 +
54350 + entry->prev = NULL;
54351 +
54352 + curr = &inodev_set.i_hash[index];
54353 + if (*curr != NULL)
54354 + (*curr)->prev = entry;
54355 +
54356 + entry->next = *curr;
54357 + *curr = entry;
54358 +
54359 + return;
54360 +}
54361 +
54362 +static void
54363 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
54364 +{
54365 + unsigned int index =
54366 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
54367 + struct acl_role_label **curr;
54368 + struct acl_role_label *tmp, *tmp2;
54369 +
54370 + curr = &acl_role_set.r_hash[index];
54371 +
54372 + /* simple case, slot is empty, just set it to our role */
54373 + if (*curr == NULL) {
54374 + *curr = role;
54375 + } else {
54376 + /* example:
54377 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
54378 + 2 -> 3
54379 + */
54380 + /* first check to see if we can already be reached via this slot */
54381 + tmp = *curr;
54382 + while (tmp && tmp != role)
54383 + tmp = tmp->next;
54384 + if (tmp == role) {
54385 + /* we don't need to add ourselves to this slot's chain */
54386 + return;
54387 + }
54388 + /* we need to add ourselves to this chain, two cases */
54389 + if (role->next == NULL) {
54390 + /* simple case, append the current chain to our role */
54391 + role->next = *curr;
54392 + *curr = role;
54393 + } else {
54394 + /* 1 -> 2 -> 3 -> 4
54395 + 2 -> 3 -> 4
54396 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
54397 + */
54398 + /* trickier case: walk our role's chain until we find
54399 + the role for the start of the current slot's chain */
54400 + tmp = role;
54401 + tmp2 = *curr;
54402 + while (tmp->next && tmp->next != tmp2)
54403 + tmp = tmp->next;
54404 + if (tmp->next == tmp2) {
54405 + /* from example above, we found 3, so just
54406 + replace this slot's chain with ours */
54407 + *curr = role;
54408 + } else {
54409 + /* we didn't find a subset of our role's chain
54410 + in the current slot's chain, so append their
54411 + chain to ours, and set us as the first role in
54412 + the slot's chain
54413 +
54414 + we could fold this case with the case above,
54415 + but making it explicit for clarity
54416 + */
54417 + tmp->next = tmp2;
54418 + *curr = role;
54419 + }
54420 + }
54421 + }
54422 +
54423 + return;
54424 +}
54425 +
54426 +static void
54427 +insert_acl_role_label(struct acl_role_label *role)
54428 +{
54429 + int i;
54430 +
54431 + if (role_list == NULL) {
54432 + role_list = role;
54433 + role->prev = NULL;
54434 + } else {
54435 + role->prev = role_list;
54436 + role_list = role;
54437 + }
54438 +
54439 + /* used for hash chains */
54440 + role->next = NULL;
54441 +
54442 + if (role->roletype & GR_ROLE_DOMAIN) {
54443 + for (i = 0; i < role->domain_child_num; i++)
54444 + __insert_acl_role_label(role, role->domain_children[i]);
54445 + } else
54446 + __insert_acl_role_label(role, role->uidgid);
54447 +}
54448 +
54449 +static int
54450 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
54451 +{
54452 + struct name_entry **curr, *nentry;
54453 + struct inodev_entry *ientry;
54454 + unsigned int len = strlen(name);
54455 + unsigned int key = full_name_hash(name, len);
54456 + unsigned int index = key % name_set.n_size;
54457 +
54458 + curr = &name_set.n_hash[index];
54459 +
54460 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
54461 + curr = &((*curr)->next);
54462 +
54463 + if (*curr != NULL)
54464 + return 1;
54465 +
54466 + nentry = acl_alloc(sizeof (struct name_entry));
54467 + if (nentry == NULL)
54468 + return 0;
54469 + ientry = acl_alloc(sizeof (struct inodev_entry));
54470 + if (ientry == NULL)
54471 + return 0;
54472 + ientry->nentry = nentry;
54473 +
54474 + nentry->key = key;
54475 + nentry->name = name;
54476 + nentry->inode = inode;
54477 + nentry->device = device;
54478 + nentry->len = len;
54479 + nentry->deleted = deleted;
54480 +
54481 + nentry->prev = NULL;
54482 + curr = &name_set.n_hash[index];
54483 + if (*curr != NULL)
54484 + (*curr)->prev = nentry;
54485 + nentry->next = *curr;
54486 + *curr = nentry;
54487 +
54488 + /* insert us into the table searchable by inode/dev */
54489 + insert_inodev_entry(ientry);
54490 +
54491 + return 1;
54492 +}
54493 +
54494 +static void
54495 +insert_acl_obj_label(struct acl_object_label *obj,
54496 + struct acl_subject_label *subj)
54497 +{
54498 + unsigned int index =
54499 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
54500 + struct acl_object_label **curr;
54501 +
54502 +
54503 + obj->prev = NULL;
54504 +
54505 + curr = &subj->obj_hash[index];
54506 + if (*curr != NULL)
54507 + (*curr)->prev = obj;
54508 +
54509 + obj->next = *curr;
54510 + *curr = obj;
54511 +
54512 + return;
54513 +}
54514 +
54515 +static void
54516 +insert_acl_subj_label(struct acl_subject_label *obj,
54517 + struct acl_role_label *role)
54518 +{
54519 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
54520 + struct acl_subject_label **curr;
54521 +
54522 + obj->prev = NULL;
54523 +
54524 + curr = &role->subj_hash[index];
54525 + if (*curr != NULL)
54526 + (*curr)->prev = obj;
54527 +
54528 + obj->next = *curr;
54529 + *curr = obj;
54530 +
54531 + return;
54532 +}
54533 +
54534 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
54535 +
54536 +static void *
54537 +create_table(__u32 * len, int elementsize)
54538 +{
54539 + unsigned int table_sizes[] = {
54540 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
54541 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
54542 + 4194301, 8388593, 16777213, 33554393, 67108859
54543 + };
54544 + void *newtable = NULL;
54545 + unsigned int pwr = 0;
54546 +
54547 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
54548 + table_sizes[pwr] <= *len)
54549 + pwr++;
54550 +
54551 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
54552 + return newtable;
54553 +
54554 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
54555 + newtable =
54556 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
54557 + else
54558 + newtable = vmalloc(table_sizes[pwr] * elementsize);
54559 +
54560 + *len = table_sizes[pwr];
54561 +
54562 + return newtable;
54563 +}
54564 +
54565 +static int
54566 +init_variables(const struct gr_arg *arg)
54567 +{
54568 + struct task_struct *reaper = init_pid_ns.child_reaper;
54569 + unsigned int stacksize;
54570 +
54571 + subj_map_set.s_size = arg->role_db.num_subjects;
54572 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
54573 + name_set.n_size = arg->role_db.num_objects;
54574 + inodev_set.i_size = arg->role_db.num_objects;
54575 +
54576 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
54577 + !name_set.n_size || !inodev_set.i_size)
54578 + return 1;
54579 +
54580 + if (!gr_init_uidset())
54581 + return 1;
54582 +
54583 + /* set up the stack that holds allocation info */
54584 +
54585 + stacksize = arg->role_db.num_pointers + 5;
54586 +
54587 + if (!acl_alloc_stack_init(stacksize))
54588 + return 1;
54589 +
54590 + /* grab reference for the real root dentry and vfsmount */
54591 + get_fs_root(reaper->fs, &real_root);
54592 +
54593 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54594 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
54595 +#endif
54596 +
54597 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
54598 + if (fakefs_obj_rw == NULL)
54599 + return 1;
54600 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
54601 +
54602 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
54603 + if (fakefs_obj_rwx == NULL)
54604 + return 1;
54605 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
54606 +
54607 + subj_map_set.s_hash =
54608 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
54609 + acl_role_set.r_hash =
54610 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
54611 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
54612 + inodev_set.i_hash =
54613 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
54614 +
54615 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
54616 + !name_set.n_hash || !inodev_set.i_hash)
54617 + return 1;
54618 +
54619 + memset(subj_map_set.s_hash, 0,
54620 + sizeof(struct subject_map *) * subj_map_set.s_size);
54621 + memset(acl_role_set.r_hash, 0,
54622 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
54623 + memset(name_set.n_hash, 0,
54624 + sizeof (struct name_entry *) * name_set.n_size);
54625 + memset(inodev_set.i_hash, 0,
54626 + sizeof (struct inodev_entry *) * inodev_set.i_size);
54627 +
54628 + return 0;
54629 +}
54630 +
54631 +/* free information not needed after startup
54632 + currently contains user->kernel pointer mappings for subjects
54633 +*/
54634 +
54635 +static void
54636 +free_init_variables(void)
54637 +{
54638 + __u32 i;
54639 +
54640 + if (subj_map_set.s_hash) {
54641 + for (i = 0; i < subj_map_set.s_size; i++) {
54642 + if (subj_map_set.s_hash[i]) {
54643 + kfree(subj_map_set.s_hash[i]);
54644 + subj_map_set.s_hash[i] = NULL;
54645 + }
54646 + }
54647 +
54648 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
54649 + PAGE_SIZE)
54650 + kfree(subj_map_set.s_hash);
54651 + else
54652 + vfree(subj_map_set.s_hash);
54653 + }
54654 +
54655 + return;
54656 +}
54657 +
54658 +static void
54659 +free_variables(void)
54660 +{
54661 + struct acl_subject_label *s;
54662 + struct acl_role_label *r;
54663 + struct task_struct *task, *task2;
54664 + unsigned int x;
54665 +
54666 + gr_clear_learn_entries();
54667 +
54668 + read_lock(&tasklist_lock);
54669 + do_each_thread(task2, task) {
54670 + task->acl_sp_role = 0;
54671 + task->acl_role_id = 0;
54672 + task->acl = NULL;
54673 + task->role = NULL;
54674 + } while_each_thread(task2, task);
54675 + read_unlock(&tasklist_lock);
54676 +
54677 + /* release the reference to the real root dentry and vfsmount */
54678 + path_put(&real_root);
54679 + memset(&real_root, 0, sizeof(real_root));
54680 +
54681 + /* free all object hash tables */
54682 +
54683 + FOR_EACH_ROLE_START(r)
54684 + if (r->subj_hash == NULL)
54685 + goto next_role;
54686 + FOR_EACH_SUBJECT_START(r, s, x)
54687 + if (s->obj_hash == NULL)
54688 + break;
54689 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54690 + kfree(s->obj_hash);
54691 + else
54692 + vfree(s->obj_hash);
54693 + FOR_EACH_SUBJECT_END(s, x)
54694 + FOR_EACH_NESTED_SUBJECT_START(r, s)
54695 + if (s->obj_hash == NULL)
54696 + break;
54697 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54698 + kfree(s->obj_hash);
54699 + else
54700 + vfree(s->obj_hash);
54701 + FOR_EACH_NESTED_SUBJECT_END(s)
54702 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
54703 + kfree(r->subj_hash);
54704 + else
54705 + vfree(r->subj_hash);
54706 + r->subj_hash = NULL;
54707 +next_role:
54708 + FOR_EACH_ROLE_END(r)
54709 +
54710 + acl_free_all();
54711 +
54712 + if (acl_role_set.r_hash) {
54713 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
54714 + PAGE_SIZE)
54715 + kfree(acl_role_set.r_hash);
54716 + else
54717 + vfree(acl_role_set.r_hash);
54718 + }
54719 + if (name_set.n_hash) {
54720 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
54721 + PAGE_SIZE)
54722 + kfree(name_set.n_hash);
54723 + else
54724 + vfree(name_set.n_hash);
54725 + }
54726 +
54727 + if (inodev_set.i_hash) {
54728 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
54729 + PAGE_SIZE)
54730 + kfree(inodev_set.i_hash);
54731 + else
54732 + vfree(inodev_set.i_hash);
54733 + }
54734 +
54735 + gr_free_uidset();
54736 +
54737 + memset(&name_set, 0, sizeof (struct name_db));
54738 + memset(&inodev_set, 0, sizeof (struct inodev_db));
54739 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
54740 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
54741 +
54742 + default_role = NULL;
54743 + kernel_role = NULL;
54744 + role_list = NULL;
54745 +
54746 + return;
54747 +}
54748 +
54749 +static __u32
54750 +count_user_objs(struct acl_object_label *userp)
54751 +{
54752 + struct acl_object_label o_tmp;
54753 + __u32 num = 0;
54754 +
54755 + while (userp) {
54756 + if (copy_from_user(&o_tmp, userp,
54757 + sizeof (struct acl_object_label)))
54758 + break;
54759 +
54760 + userp = o_tmp.prev;
54761 + num++;
54762 + }
54763 +
54764 + return num;
54765 +}
54766 +
54767 +static struct acl_subject_label *
54768 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
54769 +
54770 +static int
54771 +copy_user_glob(struct acl_object_label *obj)
54772 +{
54773 + struct acl_object_label *g_tmp, **guser;
54774 + unsigned int len;
54775 + char *tmp;
54776 +
54777 + if (obj->globbed == NULL)
54778 + return 0;
54779 +
54780 + guser = &obj->globbed;
54781 + while (*guser) {
54782 + g_tmp = (struct acl_object_label *)
54783 + acl_alloc(sizeof (struct acl_object_label));
54784 + if (g_tmp == NULL)
54785 + return -ENOMEM;
54786 +
54787 + if (copy_from_user(g_tmp, *guser,
54788 + sizeof (struct acl_object_label)))
54789 + return -EFAULT;
54790 +
54791 + len = strnlen_user(g_tmp->filename, PATH_MAX);
54792 +
54793 + if (!len || len >= PATH_MAX)
54794 + return -EINVAL;
54795 +
54796 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54797 + return -ENOMEM;
54798 +
54799 + if (copy_from_user(tmp, g_tmp->filename, len))
54800 + return -EFAULT;
54801 + tmp[len-1] = '\0';
54802 + g_tmp->filename = tmp;
54803 +
54804 + *guser = g_tmp;
54805 + guser = &(g_tmp->next);
54806 + }
54807 +
54808 + return 0;
54809 +}
54810 +
54811 +static int
54812 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
54813 + struct acl_role_label *role)
54814 +{
54815 + struct acl_object_label *o_tmp;
54816 + unsigned int len;
54817 + int ret;
54818 + char *tmp;
54819 +
54820 + while (userp) {
54821 + if ((o_tmp = (struct acl_object_label *)
54822 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
54823 + return -ENOMEM;
54824 +
54825 + if (copy_from_user(o_tmp, userp,
54826 + sizeof (struct acl_object_label)))
54827 + return -EFAULT;
54828 +
54829 + userp = o_tmp->prev;
54830 +
54831 + len = strnlen_user(o_tmp->filename, PATH_MAX);
54832 +
54833 + if (!len || len >= PATH_MAX)
54834 + return -EINVAL;
54835 +
54836 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54837 + return -ENOMEM;
54838 +
54839 + if (copy_from_user(tmp, o_tmp->filename, len))
54840 + return -EFAULT;
54841 + tmp[len-1] = '\0';
54842 + o_tmp->filename = tmp;
54843 +
54844 + insert_acl_obj_label(o_tmp, subj);
54845 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
54846 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
54847 + return -ENOMEM;
54848 +
54849 + ret = copy_user_glob(o_tmp);
54850 + if (ret)
54851 + return ret;
54852 +
54853 + if (o_tmp->nested) {
54854 + int already_copied;
54855 +
54856 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
54857 + if (IS_ERR(o_tmp->nested))
54858 + return PTR_ERR(o_tmp->nested);
54859 +
54860 + /* insert into nested subject list if we haven't copied this one yet
54861 + to prevent duplicate entries */
54862 + if (!already_copied) {
54863 + o_tmp->nested->next = role->hash->first;
54864 + role->hash->first = o_tmp->nested;
54865 + }
54866 + }
54867 + }
54868 +
54869 + return 0;
54870 +}
54871 +
54872 +static __u32
54873 +count_user_subjs(struct acl_subject_label *userp)
54874 +{
54875 + struct acl_subject_label s_tmp;
54876 + __u32 num = 0;
54877 +
54878 + while (userp) {
54879 + if (copy_from_user(&s_tmp, userp,
54880 + sizeof (struct acl_subject_label)))
54881 + break;
54882 +
54883 + userp = s_tmp.prev;
54884 + }
54885 +
54886 + return num;
54887 +}
54888 +
54889 +static int
54890 +copy_user_allowedips(struct acl_role_label *rolep)
54891 +{
54892 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
54893 +
54894 + ruserip = rolep->allowed_ips;
54895 +
54896 + while (ruserip) {
54897 + rlast = rtmp;
54898 +
54899 + if ((rtmp = (struct role_allowed_ip *)
54900 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
54901 + return -ENOMEM;
54902 +
54903 + if (copy_from_user(rtmp, ruserip,
54904 + sizeof (struct role_allowed_ip)))
54905 + return -EFAULT;
54906 +
54907 + ruserip = rtmp->prev;
54908 +
54909 + if (!rlast) {
54910 + rtmp->prev = NULL;
54911 + rolep->allowed_ips = rtmp;
54912 + } else {
54913 + rlast->next = rtmp;
54914 + rtmp->prev = rlast;
54915 + }
54916 +
54917 + if (!ruserip)
54918 + rtmp->next = NULL;
54919 + }
54920 +
54921 + return 0;
54922 +}
54923 +
54924 +static int
54925 +copy_user_transitions(struct acl_role_label *rolep)
54926 +{
54927 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
54928 +
54929 + unsigned int len;
54930 + char *tmp;
54931 +
54932 + rusertp = rolep->transitions;
54933 +
54934 + while (rusertp) {
54935 + rlast = rtmp;
54936 +
54937 + if ((rtmp = (struct role_transition *)
54938 + acl_alloc(sizeof (struct role_transition))) == NULL)
54939 + return -ENOMEM;
54940 +
54941 + if (copy_from_user(rtmp, rusertp,
54942 + sizeof (struct role_transition)))
54943 + return -EFAULT;
54944 +
54945 + rusertp = rtmp->prev;
54946 +
54947 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
54948 +
54949 + if (!len || len >= GR_SPROLE_LEN)
54950 + return -EINVAL;
54951 +
54952 + if ((tmp = (char *) acl_alloc(len)) == NULL)
54953 + return -ENOMEM;
54954 +
54955 + if (copy_from_user(tmp, rtmp->rolename, len))
54956 + return -EFAULT;
54957 + tmp[len-1] = '\0';
54958 + rtmp->rolename = tmp;
54959 +
54960 + if (!rlast) {
54961 + rtmp->prev = NULL;
54962 + rolep->transitions = rtmp;
54963 + } else {
54964 + rlast->next = rtmp;
54965 + rtmp->prev = rlast;
54966 + }
54967 +
54968 + if (!rusertp)
54969 + rtmp->next = NULL;
54970 + }
54971 +
54972 + return 0;
54973 +}
54974 +
54975 +static struct acl_subject_label *
54976 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
54977 +{
54978 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
54979 + unsigned int len;
54980 + char *tmp;
54981 + __u32 num_objs;
54982 + struct acl_ip_label **i_tmp, *i_utmp2;
54983 + struct gr_hash_struct ghash;
54984 + struct subject_map *subjmap;
54985 + unsigned int i_num;
54986 + int err;
54987 +
54988 + if (already_copied != NULL)
54989 + *already_copied = 0;
54990 +
54991 + s_tmp = lookup_subject_map(userp);
54992 +
54993 + /* we've already copied this subject into the kernel, just return
54994 + the reference to it, and don't copy it over again
54995 + */
54996 + if (s_tmp) {
54997 + if (already_copied != NULL)
54998 + *already_copied = 1;
54999 + return(s_tmp);
55000 + }
55001 +
55002 + if ((s_tmp = (struct acl_subject_label *)
55003 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
55004 + return ERR_PTR(-ENOMEM);
55005 +
55006 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
55007 + if (subjmap == NULL)
55008 + return ERR_PTR(-ENOMEM);
55009 +
55010 + subjmap->user = userp;
55011 + subjmap->kernel = s_tmp;
55012 + insert_subj_map_entry(subjmap);
55013 +
55014 + if (copy_from_user(s_tmp, userp,
55015 + sizeof (struct acl_subject_label)))
55016 + return ERR_PTR(-EFAULT);
55017 +
55018 + len = strnlen_user(s_tmp->filename, PATH_MAX);
55019 +
55020 + if (!len || len >= PATH_MAX)
55021 + return ERR_PTR(-EINVAL);
55022 +
55023 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55024 + return ERR_PTR(-ENOMEM);
55025 +
55026 + if (copy_from_user(tmp, s_tmp->filename, len))
55027 + return ERR_PTR(-EFAULT);
55028 + tmp[len-1] = '\0';
55029 + s_tmp->filename = tmp;
55030 +
55031 + if (!strcmp(s_tmp->filename, "/"))
55032 + role->root_label = s_tmp;
55033 +
55034 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
55035 + return ERR_PTR(-EFAULT);
55036 +
55037 + /* copy user and group transition tables */
55038 +
55039 + if (s_tmp->user_trans_num) {
55040 + uid_t *uidlist;
55041 +
55042 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
55043 + if (uidlist == NULL)
55044 + return ERR_PTR(-ENOMEM);
55045 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
55046 + return ERR_PTR(-EFAULT);
55047 +
55048 + s_tmp->user_transitions = uidlist;
55049 + }
55050 +
55051 + if (s_tmp->group_trans_num) {
55052 + gid_t *gidlist;
55053 +
55054 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
55055 + if (gidlist == NULL)
55056 + return ERR_PTR(-ENOMEM);
55057 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
55058 + return ERR_PTR(-EFAULT);
55059 +
55060 + s_tmp->group_transitions = gidlist;
55061 + }
55062 +
55063 + /* set up object hash table */
55064 + num_objs = count_user_objs(ghash.first);
55065 +
55066 + s_tmp->obj_hash_size = num_objs;
55067 + s_tmp->obj_hash =
55068 + (struct acl_object_label **)
55069 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
55070 +
55071 + if (!s_tmp->obj_hash)
55072 + return ERR_PTR(-ENOMEM);
55073 +
55074 + memset(s_tmp->obj_hash, 0,
55075 + s_tmp->obj_hash_size *
55076 + sizeof (struct acl_object_label *));
55077 +
55078 + /* add in objects */
55079 + err = copy_user_objs(ghash.first, s_tmp, role);
55080 +
55081 + if (err)
55082 + return ERR_PTR(err);
55083 +
55084 + /* set pointer for parent subject */
55085 + if (s_tmp->parent_subject) {
55086 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
55087 +
55088 + if (IS_ERR(s_tmp2))
55089 + return s_tmp2;
55090 +
55091 + s_tmp->parent_subject = s_tmp2;
55092 + }
55093 +
55094 + /* add in ip acls */
55095 +
55096 + if (!s_tmp->ip_num) {
55097 + s_tmp->ips = NULL;
55098 + goto insert;
55099 + }
55100 +
55101 + i_tmp =
55102 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
55103 + sizeof (struct acl_ip_label *));
55104 +
55105 + if (!i_tmp)
55106 + return ERR_PTR(-ENOMEM);
55107 +
55108 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
55109 + *(i_tmp + i_num) =
55110 + (struct acl_ip_label *)
55111 + acl_alloc(sizeof (struct acl_ip_label));
55112 + if (!*(i_tmp + i_num))
55113 + return ERR_PTR(-ENOMEM);
55114 +
55115 + if (copy_from_user
55116 + (&i_utmp2, s_tmp->ips + i_num,
55117 + sizeof (struct acl_ip_label *)))
55118 + return ERR_PTR(-EFAULT);
55119 +
55120 + if (copy_from_user
55121 + (*(i_tmp + i_num), i_utmp2,
55122 + sizeof (struct acl_ip_label)))
55123 + return ERR_PTR(-EFAULT);
55124 +
55125 + if ((*(i_tmp + i_num))->iface == NULL)
55126 + continue;
55127 +
55128 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
55129 + if (!len || len >= IFNAMSIZ)
55130 + return ERR_PTR(-EINVAL);
55131 + tmp = acl_alloc(len);
55132 + if (tmp == NULL)
55133 + return ERR_PTR(-ENOMEM);
55134 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
55135 + return ERR_PTR(-EFAULT);
55136 + (*(i_tmp + i_num))->iface = tmp;
55137 + }
55138 +
55139 + s_tmp->ips = i_tmp;
55140 +
55141 +insert:
55142 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
55143 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
55144 + return ERR_PTR(-ENOMEM);
55145 +
55146 + return s_tmp;
55147 +}
55148 +
55149 +static int
55150 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
55151 +{
55152 + struct acl_subject_label s_pre;
55153 + struct acl_subject_label * ret;
55154 + int err;
55155 +
55156 + while (userp) {
55157 + if (copy_from_user(&s_pre, userp,
55158 + sizeof (struct acl_subject_label)))
55159 + return -EFAULT;
55160 +
55161 + ret = do_copy_user_subj(userp, role, NULL);
55162 +
55163 + err = PTR_ERR(ret);
55164 + if (IS_ERR(ret))
55165 + return err;
55166 +
55167 + insert_acl_subj_label(ret, role);
55168 +
55169 + userp = s_pre.prev;
55170 + }
55171 +
55172 + return 0;
55173 +}
55174 +
55175 +static int
55176 +copy_user_acl(struct gr_arg *arg)
55177 +{
55178 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
55179 + struct acl_subject_label *subj_list;
55180 + struct sprole_pw *sptmp;
55181 + struct gr_hash_struct *ghash;
55182 + uid_t *domainlist;
55183 + unsigned int r_num;
55184 + unsigned int len;
55185 + char *tmp;
55186 + int err = 0;
55187 + __u16 i;
55188 + __u32 num_subjs;
55189 +
55190 + /* we need a default and kernel role */
55191 + if (arg->role_db.num_roles < 2)
55192 + return -EINVAL;
55193 +
55194 + /* copy special role authentication info from userspace */
55195 +
55196 + num_sprole_pws = arg->num_sprole_pws;
55197 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
55198 +
55199 + if (!acl_special_roles && num_sprole_pws)
55200 + return -ENOMEM;
55201 +
55202 + for (i = 0; i < num_sprole_pws; i++) {
55203 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
55204 + if (!sptmp)
55205 + return -ENOMEM;
55206 + if (copy_from_user(sptmp, arg->sprole_pws + i,
55207 + sizeof (struct sprole_pw)))
55208 + return -EFAULT;
55209 +
55210 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
55211 +
55212 + if (!len || len >= GR_SPROLE_LEN)
55213 + return -EINVAL;
55214 +
55215 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55216 + return -ENOMEM;
55217 +
55218 + if (copy_from_user(tmp, sptmp->rolename, len))
55219 + return -EFAULT;
55220 +
55221 + tmp[len-1] = '\0';
55222 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55223 + printk(KERN_ALERT "Copying special role %s\n", tmp);
55224 +#endif
55225 + sptmp->rolename = tmp;
55226 + acl_special_roles[i] = sptmp;
55227 + }
55228 +
55229 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
55230 +
55231 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
55232 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
55233 +
55234 + if (!r_tmp)
55235 + return -ENOMEM;
55236 +
55237 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
55238 + sizeof (struct acl_role_label *)))
55239 + return -EFAULT;
55240 +
55241 + if (copy_from_user(r_tmp, r_utmp2,
55242 + sizeof (struct acl_role_label)))
55243 + return -EFAULT;
55244 +
55245 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
55246 +
55247 + if (!len || len >= PATH_MAX)
55248 + return -EINVAL;
55249 +
55250 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55251 + return -ENOMEM;
55252 +
55253 + if (copy_from_user(tmp, r_tmp->rolename, len))
55254 + return -EFAULT;
55255 +
55256 + tmp[len-1] = '\0';
55257 + r_tmp->rolename = tmp;
55258 +
55259 + if (!strcmp(r_tmp->rolename, "default")
55260 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
55261 + default_role = r_tmp;
55262 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
55263 + kernel_role = r_tmp;
55264 + }
55265 +
55266 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
55267 + return -ENOMEM;
55268 +
55269 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
55270 + return -EFAULT;
55271 +
55272 + r_tmp->hash = ghash;
55273 +
55274 + num_subjs = count_user_subjs(r_tmp->hash->first);
55275 +
55276 + r_tmp->subj_hash_size = num_subjs;
55277 + r_tmp->subj_hash =
55278 + (struct acl_subject_label **)
55279 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
55280 +
55281 + if (!r_tmp->subj_hash)
55282 + return -ENOMEM;
55283 +
55284 + err = copy_user_allowedips(r_tmp);
55285 + if (err)
55286 + return err;
55287 +
55288 + /* copy domain info */
55289 + if (r_tmp->domain_children != NULL) {
55290 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
55291 + if (domainlist == NULL)
55292 + return -ENOMEM;
55293 +
55294 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
55295 + return -EFAULT;
55296 +
55297 + r_tmp->domain_children = domainlist;
55298 + }
55299 +
55300 + err = copy_user_transitions(r_tmp);
55301 + if (err)
55302 + return err;
55303 +
55304 + memset(r_tmp->subj_hash, 0,
55305 + r_tmp->subj_hash_size *
55306 + sizeof (struct acl_subject_label *));
55307 +
55308 + /* acquire the list of subjects, then NULL out
55309 + the list prior to parsing the subjects for this role,
55310 + as during this parsing the list is replaced with a list
55311 + of *nested* subjects for the role
55312 + */
55313 + subj_list = r_tmp->hash->first;
55314 +
55315 + /* set nested subject list to null */
55316 + r_tmp->hash->first = NULL;
55317 +
55318 + err = copy_user_subjs(subj_list, r_tmp);
55319 +
55320 + if (err)
55321 + return err;
55322 +
55323 + insert_acl_role_label(r_tmp);
55324 + }
55325 +
55326 + if (default_role == NULL || kernel_role == NULL)
55327 + return -EINVAL;
55328 +
55329 + return err;
55330 +}
55331 +
55332 +static int
55333 +gracl_init(struct gr_arg *args)
55334 +{
55335 + int error = 0;
55336 +
55337 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
55338 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
55339 +
55340 + if (init_variables(args)) {
55341 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
55342 + error = -ENOMEM;
55343 + free_variables();
55344 + goto out;
55345 + }
55346 +
55347 + error = copy_user_acl(args);
55348 + free_init_variables();
55349 + if (error) {
55350 + free_variables();
55351 + goto out;
55352 + }
55353 +
55354 + if ((error = gr_set_acls(0))) {
55355 + free_variables();
55356 + goto out;
55357 + }
55358 +
55359 + pax_open_kernel();
55360 + gr_status |= GR_READY;
55361 + pax_close_kernel();
55362 +
55363 + out:
55364 + return error;
55365 +}
55366 +
55367 +/* derived from glibc fnmatch() 0: match, 1: no match*/
55368 +
55369 +static int
55370 +glob_match(const char *p, const char *n)
55371 +{
55372 + char c;
55373 +
55374 + while ((c = *p++) != '\0') {
55375 + switch (c) {
55376 + case '?':
55377 + if (*n == '\0')
55378 + return 1;
55379 + else if (*n == '/')
55380 + return 1;
55381 + break;
55382 + case '\\':
55383 + if (*n != c)
55384 + return 1;
55385 + break;
55386 + case '*':
55387 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
55388 + if (*n == '/')
55389 + return 1;
55390 + else if (c == '?') {
55391 + if (*n == '\0')
55392 + return 1;
55393 + else
55394 + ++n;
55395 + }
55396 + }
55397 + if (c == '\0') {
55398 + return 0;
55399 + } else {
55400 + const char *endp;
55401 +
55402 + if ((endp = strchr(n, '/')) == NULL)
55403 + endp = n + strlen(n);
55404 +
55405 + if (c == '[') {
55406 + for (--p; n < endp; ++n)
55407 + if (!glob_match(p, n))
55408 + return 0;
55409 + } else if (c == '/') {
55410 + while (*n != '\0' && *n != '/')
55411 + ++n;
55412 + if (*n == '/' && !glob_match(p, n + 1))
55413 + return 0;
55414 + } else {
55415 + for (--p; n < endp; ++n)
55416 + if (*n == c && !glob_match(p, n))
55417 + return 0;
55418 + }
55419 +
55420 + return 1;
55421 + }
55422 + case '[':
55423 + {
55424 + int not;
55425 + char cold;
55426 +
55427 + if (*n == '\0' || *n == '/')
55428 + return 1;
55429 +
55430 + not = (*p == '!' || *p == '^');
55431 + if (not)
55432 + ++p;
55433 +
55434 + c = *p++;
55435 + for (;;) {
55436 + unsigned char fn = (unsigned char)*n;
55437 +
55438 + if (c == '\0')
55439 + return 1;
55440 + else {
55441 + if (c == fn)
55442 + goto matched;
55443 + cold = c;
55444 + c = *p++;
55445 +
55446 + if (c == '-' && *p != ']') {
55447 + unsigned char cend = *p++;
55448 +
55449 + if (cend == '\0')
55450 + return 1;
55451 +
55452 + if (cold <= fn && fn <= cend)
55453 + goto matched;
55454 +
55455 + c = *p++;
55456 + }
55457 + }
55458 +
55459 + if (c == ']')
55460 + break;
55461 + }
55462 + if (!not)
55463 + return 1;
55464 + break;
55465 + matched:
55466 + while (c != ']') {
55467 + if (c == '\0')
55468 + return 1;
55469 +
55470 + c = *p++;
55471 + }
55472 + if (not)
55473 + return 1;
55474 + }
55475 + break;
55476 + default:
55477 + if (c != *n)
55478 + return 1;
55479 + }
55480 +
55481 + ++n;
55482 + }
55483 +
55484 + if (*n == '\0')
55485 + return 0;
55486 +
55487 + if (*n == '/')
55488 + return 0;
55489 +
55490 + return 1;
55491 +}
55492 +
55493 +static struct acl_object_label *
55494 +chk_glob_label(struct acl_object_label *globbed,
55495 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
55496 +{
55497 + struct acl_object_label *tmp;
55498 +
55499 + if (*path == NULL)
55500 + *path = gr_to_filename_nolock(dentry, mnt);
55501 +
55502 + tmp = globbed;
55503 +
55504 + while (tmp) {
55505 + if (!glob_match(tmp->filename, *path))
55506 + return tmp;
55507 + tmp = tmp->next;
55508 + }
55509 +
55510 + return NULL;
55511 +}
55512 +
55513 +static struct acl_object_label *
55514 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
55515 + const ino_t curr_ino, const dev_t curr_dev,
55516 + const struct acl_subject_label *subj, char **path, const int checkglob)
55517 +{
55518 + struct acl_subject_label *tmpsubj;
55519 + struct acl_object_label *retval;
55520 + struct acl_object_label *retval2;
55521 +
55522 + tmpsubj = (struct acl_subject_label *) subj;
55523 + read_lock(&gr_inode_lock);
55524 + do {
55525 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
55526 + if (retval) {
55527 + if (checkglob && retval->globbed) {
55528 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
55529 + if (retval2)
55530 + retval = retval2;
55531 + }
55532 + break;
55533 + }
55534 + } while ((tmpsubj = tmpsubj->parent_subject));
55535 + read_unlock(&gr_inode_lock);
55536 +
55537 + return retval;
55538 +}
55539 +
55540 +static __inline__ struct acl_object_label *
55541 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
55542 + struct dentry *curr_dentry,
55543 + const struct acl_subject_label *subj, char **path, const int checkglob)
55544 +{
55545 + int newglob = checkglob;
55546 + ino_t inode;
55547 + dev_t device;
55548 +
55549 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
55550 + as we don't want a / * rule to match instead of the / object
55551 + don't do this for create lookups that call this function though, since they're looking up
55552 + on the parent and thus need globbing checks on all paths
55553 + */
55554 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
55555 + newglob = GR_NO_GLOB;
55556 +
55557 + spin_lock(&curr_dentry->d_lock);
55558 + inode = curr_dentry->d_inode->i_ino;
55559 + device = __get_dev(curr_dentry);
55560 + spin_unlock(&curr_dentry->d_lock);
55561 +
55562 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
55563 +}
55564 +
55565 +static struct acl_object_label *
55566 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55567 + const struct acl_subject_label *subj, char *path, const int checkglob)
55568 +{
55569 + struct dentry *dentry = (struct dentry *) l_dentry;
55570 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55571 + struct mount *real_mnt = real_mount(mnt);
55572 + struct acl_object_label *retval;
55573 + struct dentry *parent;
55574 +
55575 + write_seqlock(&rename_lock);
55576 + br_read_lock(&vfsmount_lock);
55577 +
55578 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
55579 +#ifdef CONFIG_NET
55580 + mnt == sock_mnt ||
55581 +#endif
55582 +#ifdef CONFIG_HUGETLBFS
55583 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
55584 +#endif
55585 + /* ignore Eric Biederman */
55586 + IS_PRIVATE(l_dentry->d_inode))) {
55587 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
55588 + goto out;
55589 + }
55590 +
55591 + for (;;) {
55592 + if (dentry == real_root.dentry && mnt == real_root.mnt)
55593 + break;
55594 +
55595 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55596 + if (!mnt_has_parent(real_mnt))
55597 + break;
55598 +
55599 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55600 + if (retval != NULL)
55601 + goto out;
55602 +
55603 + dentry = real_mnt->mnt_mountpoint;
55604 + real_mnt = real_mnt->mnt_parent;
55605 + mnt = &real_mnt->mnt;
55606 + continue;
55607 + }
55608 +
55609 + parent = dentry->d_parent;
55610 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55611 + if (retval != NULL)
55612 + goto out;
55613 +
55614 + dentry = parent;
55615 + }
55616 +
55617 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55618 +
55619 + /* real_root is pinned so we don't have to hold a reference */
55620 + if (retval == NULL)
55621 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
55622 +out:
55623 + br_read_unlock(&vfsmount_lock);
55624 + write_sequnlock(&rename_lock);
55625 +
55626 + BUG_ON(retval == NULL);
55627 +
55628 + return retval;
55629 +}
55630 +
55631 +static __inline__ struct acl_object_label *
55632 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55633 + const struct acl_subject_label *subj)
55634 +{
55635 + char *path = NULL;
55636 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
55637 +}
55638 +
55639 +static __inline__ struct acl_object_label *
55640 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55641 + const struct acl_subject_label *subj)
55642 +{
55643 + char *path = NULL;
55644 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
55645 +}
55646 +
55647 +static __inline__ struct acl_object_label *
55648 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55649 + const struct acl_subject_label *subj, char *path)
55650 +{
55651 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
55652 +}
55653 +
55654 +static struct acl_subject_label *
55655 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55656 + const struct acl_role_label *role)
55657 +{
55658 + struct dentry *dentry = (struct dentry *) l_dentry;
55659 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55660 + struct mount *real_mnt = real_mount(mnt);
55661 + struct acl_subject_label *retval;
55662 + struct dentry *parent;
55663 +
55664 + write_seqlock(&rename_lock);
55665 + br_read_lock(&vfsmount_lock);
55666 +
55667 + for (;;) {
55668 + if (dentry == real_root.dentry && mnt == real_root.mnt)
55669 + break;
55670 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55671 + if (!mnt_has_parent(real_mnt))
55672 + break;
55673 +
55674 + spin_lock(&dentry->d_lock);
55675 + read_lock(&gr_inode_lock);
55676 + retval =
55677 + lookup_acl_subj_label(dentry->d_inode->i_ino,
55678 + __get_dev(dentry), role);
55679 + read_unlock(&gr_inode_lock);
55680 + spin_unlock(&dentry->d_lock);
55681 + if (retval != NULL)
55682 + goto out;
55683 +
55684 + dentry = real_mnt->mnt_mountpoint;
55685 + real_mnt = real_mnt->mnt_parent;
55686 + mnt = &real_mnt->mnt;
55687 + continue;
55688 + }
55689 +
55690 + spin_lock(&dentry->d_lock);
55691 + read_lock(&gr_inode_lock);
55692 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55693 + __get_dev(dentry), role);
55694 + read_unlock(&gr_inode_lock);
55695 + parent = dentry->d_parent;
55696 + spin_unlock(&dentry->d_lock);
55697 +
55698 + if (retval != NULL)
55699 + goto out;
55700 +
55701 + dentry = parent;
55702 + }
55703 +
55704 + spin_lock(&dentry->d_lock);
55705 + read_lock(&gr_inode_lock);
55706 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55707 + __get_dev(dentry), role);
55708 + read_unlock(&gr_inode_lock);
55709 + spin_unlock(&dentry->d_lock);
55710 +
55711 + if (unlikely(retval == NULL)) {
55712 + /* real_root is pinned, we don't need to hold a reference */
55713 + read_lock(&gr_inode_lock);
55714 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
55715 + __get_dev(real_root.dentry), role);
55716 + read_unlock(&gr_inode_lock);
55717 + }
55718 +out:
55719 + br_read_unlock(&vfsmount_lock);
55720 + write_sequnlock(&rename_lock);
55721 +
55722 + BUG_ON(retval == NULL);
55723 +
55724 + return retval;
55725 +}
55726 +
55727 +static void
55728 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
55729 +{
55730 + struct task_struct *task = current;
55731 + const struct cred *cred = current_cred();
55732 +
55733 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
55734 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55735 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55736 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
55737 +
55738 + return;
55739 +}
55740 +
55741 +static void
55742 +gr_log_learn_id_change(const char type, const unsigned int real,
55743 + const unsigned int effective, const unsigned int fs)
55744 +{
55745 + struct task_struct *task = current;
55746 + const struct cred *cred = current_cred();
55747 +
55748 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
55749 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55750 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55751 + type, real, effective, fs, &task->signal->saved_ip);
55752 +
55753 + return;
55754 +}
55755 +
55756 +__u32
55757 +gr_search_file(const struct dentry * dentry, const __u32 mode,
55758 + const struct vfsmount * mnt)
55759 +{
55760 + __u32 retval = mode;
55761 + struct acl_subject_label *curracl;
55762 + struct acl_object_label *currobj;
55763 +
55764 + if (unlikely(!(gr_status & GR_READY)))
55765 + return (mode & ~GR_AUDITS);
55766 +
55767 + curracl = current->acl;
55768 +
55769 + currobj = chk_obj_label(dentry, mnt, curracl);
55770 + retval = currobj->mode & mode;
55771 +
55772 + /* if we're opening a specified transfer file for writing
55773 + (e.g. /dev/initctl), then transfer our role to init
55774 + */
55775 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
55776 + current->role->roletype & GR_ROLE_PERSIST)) {
55777 + struct task_struct *task = init_pid_ns.child_reaper;
55778 +
55779 + if (task->role != current->role) {
55780 + task->acl_sp_role = 0;
55781 + task->acl_role_id = current->acl_role_id;
55782 + task->role = current->role;
55783 + rcu_read_lock();
55784 + read_lock(&grsec_exec_file_lock);
55785 + gr_apply_subject_to_task(task);
55786 + read_unlock(&grsec_exec_file_lock);
55787 + rcu_read_unlock();
55788 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
55789 + }
55790 + }
55791 +
55792 + if (unlikely
55793 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
55794 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
55795 + __u32 new_mode = mode;
55796 +
55797 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55798 +
55799 + retval = new_mode;
55800 +
55801 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
55802 + new_mode |= GR_INHERIT;
55803 +
55804 + if (!(mode & GR_NOLEARN))
55805 + gr_log_learn(dentry, mnt, new_mode);
55806 + }
55807 +
55808 + return retval;
55809 +}
55810 +
55811 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
55812 + const struct dentry *parent,
55813 + const struct vfsmount *mnt)
55814 +{
55815 + struct name_entry *match;
55816 + struct acl_object_label *matchpo;
55817 + struct acl_subject_label *curracl;
55818 + char *path;
55819 +
55820 + if (unlikely(!(gr_status & GR_READY)))
55821 + return NULL;
55822 +
55823 + preempt_disable();
55824 + path = gr_to_filename_rbac(new_dentry, mnt);
55825 + match = lookup_name_entry_create(path);
55826 +
55827 + curracl = current->acl;
55828 +
55829 + if (match) {
55830 + read_lock(&gr_inode_lock);
55831 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
55832 + read_unlock(&gr_inode_lock);
55833 +
55834 + if (matchpo) {
55835 + preempt_enable();
55836 + return matchpo;
55837 + }
55838 + }
55839 +
55840 + // lookup parent
55841 +
55842 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
55843 +
55844 + preempt_enable();
55845 + return matchpo;
55846 +}
55847 +
55848 +__u32
55849 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
55850 + const struct vfsmount * mnt, const __u32 mode)
55851 +{
55852 + struct acl_object_label *matchpo;
55853 + __u32 retval;
55854 +
55855 + if (unlikely(!(gr_status & GR_READY)))
55856 + return (mode & ~GR_AUDITS);
55857 +
55858 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
55859 +
55860 + retval = matchpo->mode & mode;
55861 +
55862 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
55863 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
55864 + __u32 new_mode = mode;
55865 +
55866 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55867 +
55868 + gr_log_learn(new_dentry, mnt, new_mode);
55869 + return new_mode;
55870 + }
55871 +
55872 + return retval;
55873 +}
55874 +
55875 +__u32
55876 +gr_check_link(const struct dentry * new_dentry,
55877 + const struct dentry * parent_dentry,
55878 + const struct vfsmount * parent_mnt,
55879 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
55880 +{
55881 + struct acl_object_label *obj;
55882 + __u32 oldmode, newmode;
55883 + __u32 needmode;
55884 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
55885 + GR_DELETE | GR_INHERIT;
55886 +
55887 + if (unlikely(!(gr_status & GR_READY)))
55888 + return (GR_CREATE | GR_LINK);
55889 +
55890 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
55891 + oldmode = obj->mode;
55892 +
55893 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
55894 + newmode = obj->mode;
55895 +
55896 + needmode = newmode & checkmodes;
55897 +
55898 + // old name for hardlink must have at least the permissions of the new name
55899 + if ((oldmode & needmode) != needmode)
55900 + goto bad;
55901 +
55902 + // if old name had restrictions/auditing, make sure the new name does as well
55903 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
55904 +
55905 + // don't allow hardlinking of suid/sgid/fcapped files without permission
55906 + if (is_privileged_binary(old_dentry))
55907 + needmode |= GR_SETID;
55908 +
55909 + if ((newmode & needmode) != needmode)
55910 + goto bad;
55911 +
55912 + // enforce minimum permissions
55913 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
55914 + return newmode;
55915 +bad:
55916 + needmode = oldmode;
55917 + if (is_privileged_binary(old_dentry))
55918 + needmode |= GR_SETID;
55919 +
55920 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
55921 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
55922 + return (GR_CREATE | GR_LINK);
55923 + } else if (newmode & GR_SUPPRESS)
55924 + return GR_SUPPRESS;
55925 + else
55926 + return 0;
55927 +}
55928 +
55929 +int
55930 +gr_check_hidden_task(const struct task_struct *task)
55931 +{
55932 + if (unlikely(!(gr_status & GR_READY)))
55933 + return 0;
55934 +
55935 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
55936 + return 1;
55937 +
55938 + return 0;
55939 +}
55940 +
55941 +int
55942 +gr_check_protected_task(const struct task_struct *task)
55943 +{
55944 + if (unlikely(!(gr_status & GR_READY) || !task))
55945 + return 0;
55946 +
55947 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55948 + task->acl != current->acl)
55949 + return 1;
55950 +
55951 + return 0;
55952 +}
55953 +
55954 +int
55955 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
55956 +{
55957 + struct task_struct *p;
55958 + int ret = 0;
55959 +
55960 + if (unlikely(!(gr_status & GR_READY) || !pid))
55961 + return ret;
55962 +
55963 + read_lock(&tasklist_lock);
55964 + do_each_pid_task(pid, type, p) {
55965 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55966 + p->acl != current->acl) {
55967 + ret = 1;
55968 + goto out;
55969 + }
55970 + } while_each_pid_task(pid, type, p);
55971 +out:
55972 + read_unlock(&tasklist_lock);
55973 +
55974 + return ret;
55975 +}
55976 +
55977 +void
55978 +gr_copy_label(struct task_struct *tsk)
55979 +{
55980 + tsk->signal->used_accept = 0;
55981 + tsk->acl_sp_role = 0;
55982 + tsk->acl_role_id = current->acl_role_id;
55983 + tsk->acl = current->acl;
55984 + tsk->role = current->role;
55985 + tsk->signal->curr_ip = current->signal->curr_ip;
55986 + tsk->signal->saved_ip = current->signal->saved_ip;
55987 + if (current->exec_file)
55988 + get_file(current->exec_file);
55989 + tsk->exec_file = current->exec_file;
55990 + tsk->is_writable = current->is_writable;
55991 + if (unlikely(current->signal->used_accept)) {
55992 + current->signal->curr_ip = 0;
55993 + current->signal->saved_ip = 0;
55994 + }
55995 +
55996 + return;
55997 +}
55998 +
55999 +static void
56000 +gr_set_proc_res(struct task_struct *task)
56001 +{
56002 + struct acl_subject_label *proc;
56003 + unsigned short i;
56004 +
56005 + proc = task->acl;
56006 +
56007 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
56008 + return;
56009 +
56010 + for (i = 0; i < RLIM_NLIMITS; i++) {
56011 + if (!(proc->resmask & (1 << i)))
56012 + continue;
56013 +
56014 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
56015 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
56016 + }
56017 +
56018 + return;
56019 +}
56020 +
56021 +extern int __gr_process_user_ban(struct user_struct *user);
56022 +
56023 +int
56024 +gr_check_user_change(int real, int effective, int fs)
56025 +{
56026 + unsigned int i;
56027 + __u16 num;
56028 + uid_t *uidlist;
56029 + int curuid;
56030 + int realok = 0;
56031 + int effectiveok = 0;
56032 + int fsok = 0;
56033 +
56034 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56035 + struct user_struct *user;
56036 +
56037 + if (real == -1)
56038 + goto skipit;
56039 +
56040 + user = find_user(real);
56041 + if (user == NULL)
56042 + goto skipit;
56043 +
56044 + if (__gr_process_user_ban(user)) {
56045 + /* for find_user */
56046 + free_uid(user);
56047 + return 1;
56048 + }
56049 +
56050 + /* for find_user */
56051 + free_uid(user);
56052 +
56053 +skipit:
56054 +#endif
56055 +
56056 + if (unlikely(!(gr_status & GR_READY)))
56057 + return 0;
56058 +
56059 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56060 + gr_log_learn_id_change('u', real, effective, fs);
56061 +
56062 + num = current->acl->user_trans_num;
56063 + uidlist = current->acl->user_transitions;
56064 +
56065 + if (uidlist == NULL)
56066 + return 0;
56067 +
56068 + if (real == -1)
56069 + realok = 1;
56070 + if (effective == -1)
56071 + effectiveok = 1;
56072 + if (fs == -1)
56073 + fsok = 1;
56074 +
56075 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
56076 + for (i = 0; i < num; i++) {
56077 + curuid = (int)uidlist[i];
56078 + if (real == curuid)
56079 + realok = 1;
56080 + if (effective == curuid)
56081 + effectiveok = 1;
56082 + if (fs == curuid)
56083 + fsok = 1;
56084 + }
56085 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
56086 + for (i = 0; i < num; i++) {
56087 + curuid = (int)uidlist[i];
56088 + if (real == curuid)
56089 + break;
56090 + if (effective == curuid)
56091 + break;
56092 + if (fs == curuid)
56093 + break;
56094 + }
56095 + /* not in deny list */
56096 + if (i == num) {
56097 + realok = 1;
56098 + effectiveok = 1;
56099 + fsok = 1;
56100 + }
56101 + }
56102 +
56103 + if (realok && effectiveok && fsok)
56104 + return 0;
56105 + else {
56106 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56107 + return 1;
56108 + }
56109 +}
56110 +
56111 +int
56112 +gr_check_group_change(int real, int effective, int fs)
56113 +{
56114 + unsigned int i;
56115 + __u16 num;
56116 + gid_t *gidlist;
56117 + int curgid;
56118 + int realok = 0;
56119 + int effectiveok = 0;
56120 + int fsok = 0;
56121 +
56122 + if (unlikely(!(gr_status & GR_READY)))
56123 + return 0;
56124 +
56125 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56126 + gr_log_learn_id_change('g', real, effective, fs);
56127 +
56128 + num = current->acl->group_trans_num;
56129 + gidlist = current->acl->group_transitions;
56130 +
56131 + if (gidlist == NULL)
56132 + return 0;
56133 +
56134 + if (real == -1)
56135 + realok = 1;
56136 + if (effective == -1)
56137 + effectiveok = 1;
56138 + if (fs == -1)
56139 + fsok = 1;
56140 +
56141 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
56142 + for (i = 0; i < num; i++) {
56143 + curgid = (int)gidlist[i];
56144 + if (real == curgid)
56145 + realok = 1;
56146 + if (effective == curgid)
56147 + effectiveok = 1;
56148 + if (fs == curgid)
56149 + fsok = 1;
56150 + }
56151 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
56152 + for (i = 0; i < num; i++) {
56153 + curgid = (int)gidlist[i];
56154 + if (real == curgid)
56155 + break;
56156 + if (effective == curgid)
56157 + break;
56158 + if (fs == curgid)
56159 + break;
56160 + }
56161 + /* not in deny list */
56162 + if (i == num) {
56163 + realok = 1;
56164 + effectiveok = 1;
56165 + fsok = 1;
56166 + }
56167 + }
56168 +
56169 + if (realok && effectiveok && fsok)
56170 + return 0;
56171 + else {
56172 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56173 + return 1;
56174 + }
56175 +}
56176 +
56177 +extern int gr_acl_is_capable(const int cap);
56178 +
56179 +void
56180 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
56181 +{
56182 + struct acl_role_label *role = task->role;
56183 + struct acl_subject_label *subj = NULL;
56184 + struct acl_object_label *obj;
56185 + struct file *filp;
56186 +
56187 + if (unlikely(!(gr_status & GR_READY)))
56188 + return;
56189 +
56190 + filp = task->exec_file;
56191 +
56192 + /* kernel process, we'll give them the kernel role */
56193 + if (unlikely(!filp)) {
56194 + task->role = kernel_role;
56195 + task->acl = kernel_role->root_label;
56196 + return;
56197 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
56198 + role = lookup_acl_role_label(task, uid, gid);
56199 +
56200 + /* don't change the role if we're not a privileged process */
56201 + if (role && task->role != role &&
56202 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
56203 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
56204 + return;
56205 +
56206 + /* perform subject lookup in possibly new role
56207 + we can use this result below in the case where role == task->role
56208 + */
56209 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
56210 +
56211 + /* if we changed uid/gid, but result in the same role
56212 + and are using inheritance, don't lose the inherited subject
56213 + if current subject is other than what normal lookup
56214 + would result in, we arrived via inheritance, don't
56215 + lose subject
56216 + */
56217 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
56218 + (subj == task->acl)))
56219 + task->acl = subj;
56220 +
56221 + task->role = role;
56222 +
56223 + task->is_writable = 0;
56224 +
56225 + /* ignore additional mmap checks for processes that are writable
56226 + by the default ACL */
56227 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56228 + if (unlikely(obj->mode & GR_WRITE))
56229 + task->is_writable = 1;
56230 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
56231 + if (unlikely(obj->mode & GR_WRITE))
56232 + task->is_writable = 1;
56233 +
56234 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56235 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56236 +#endif
56237 +
56238 + gr_set_proc_res(task);
56239 +
56240 + return;
56241 +}
56242 +
56243 +int
56244 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
56245 + const int unsafe_flags)
56246 +{
56247 + struct task_struct *task = current;
56248 + struct acl_subject_label *newacl;
56249 + struct acl_object_label *obj;
56250 + __u32 retmode;
56251 +
56252 + if (unlikely(!(gr_status & GR_READY)))
56253 + return 0;
56254 +
56255 + newacl = chk_subj_label(dentry, mnt, task->role);
56256 +
56257 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
56258 + did an exec
56259 + */
56260 + rcu_read_lock();
56261 + read_lock(&tasklist_lock);
56262 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
56263 + (task->parent->acl->mode & GR_POVERRIDE))) {
56264 + read_unlock(&tasklist_lock);
56265 + rcu_read_unlock();
56266 + goto skip_check;
56267 + }
56268 + read_unlock(&tasklist_lock);
56269 + rcu_read_unlock();
56270 +
56271 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
56272 + !(task->role->roletype & GR_ROLE_GOD) &&
56273 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
56274 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
56275 + if (unsafe_flags & LSM_UNSAFE_SHARE)
56276 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
56277 + else
56278 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
56279 + return -EACCES;
56280 + }
56281 +
56282 +skip_check:
56283 +
56284 + obj = chk_obj_label(dentry, mnt, task->acl);
56285 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
56286 +
56287 + if (!(task->acl->mode & GR_INHERITLEARN) &&
56288 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
56289 + if (obj->nested)
56290 + task->acl = obj->nested;
56291 + else
56292 + task->acl = newacl;
56293 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
56294 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
56295 +
56296 + task->is_writable = 0;
56297 +
56298 + /* ignore additional mmap checks for processes that are writable
56299 + by the default ACL */
56300 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
56301 + if (unlikely(obj->mode & GR_WRITE))
56302 + task->is_writable = 1;
56303 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
56304 + if (unlikely(obj->mode & GR_WRITE))
56305 + task->is_writable = 1;
56306 +
56307 + gr_set_proc_res(task);
56308 +
56309 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56310 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56311 +#endif
56312 + return 0;
56313 +}
56314 +
56315 +/* always called with valid inodev ptr */
56316 +static void
56317 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
56318 +{
56319 + struct acl_object_label *matchpo;
56320 + struct acl_subject_label *matchps;
56321 + struct acl_subject_label *subj;
56322 + struct acl_role_label *role;
56323 + unsigned int x;
56324 +
56325 + FOR_EACH_ROLE_START(role)
56326 + FOR_EACH_SUBJECT_START(role, subj, x)
56327 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
56328 + matchpo->mode |= GR_DELETED;
56329 + FOR_EACH_SUBJECT_END(subj,x)
56330 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
56331 + /* nested subjects aren't in the role's subj_hash table */
56332 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
56333 + matchpo->mode |= GR_DELETED;
56334 + FOR_EACH_NESTED_SUBJECT_END(subj)
56335 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
56336 + matchps->mode |= GR_DELETED;
56337 + FOR_EACH_ROLE_END(role)
56338 +
56339 + inodev->nentry->deleted = 1;
56340 +
56341 + return;
56342 +}
56343 +
56344 +void
56345 +gr_handle_delete(const ino_t ino, const dev_t dev)
56346 +{
56347 + struct inodev_entry *inodev;
56348 +
56349 + if (unlikely(!(gr_status & GR_READY)))
56350 + return;
56351 +
56352 + write_lock(&gr_inode_lock);
56353 + inodev = lookup_inodev_entry(ino, dev);
56354 + if (inodev != NULL)
56355 + do_handle_delete(inodev, ino, dev);
56356 + write_unlock(&gr_inode_lock);
56357 +
56358 + return;
56359 +}
56360 +
56361 +static void
56362 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
56363 + const ino_t newinode, const dev_t newdevice,
56364 + struct acl_subject_label *subj)
56365 +{
56366 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
56367 + struct acl_object_label *match;
56368 +
56369 + match = subj->obj_hash[index];
56370 +
56371 + while (match && (match->inode != oldinode ||
56372 + match->device != olddevice ||
56373 + !(match->mode & GR_DELETED)))
56374 + match = match->next;
56375 +
56376 + if (match && (match->inode == oldinode)
56377 + && (match->device == olddevice)
56378 + && (match->mode & GR_DELETED)) {
56379 + if (match->prev == NULL) {
56380 + subj->obj_hash[index] = match->next;
56381 + if (match->next != NULL)
56382 + match->next->prev = NULL;
56383 + } else {
56384 + match->prev->next = match->next;
56385 + if (match->next != NULL)
56386 + match->next->prev = match->prev;
56387 + }
56388 + match->prev = NULL;
56389 + match->next = NULL;
56390 + match->inode = newinode;
56391 + match->device = newdevice;
56392 + match->mode &= ~GR_DELETED;
56393 +
56394 + insert_acl_obj_label(match, subj);
56395 + }
56396 +
56397 + return;
56398 +}
56399 +
56400 +static void
56401 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
56402 + const ino_t newinode, const dev_t newdevice,
56403 + struct acl_role_label *role)
56404 +{
56405 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
56406 + struct acl_subject_label *match;
56407 +
56408 + match = role->subj_hash[index];
56409 +
56410 + while (match && (match->inode != oldinode ||
56411 + match->device != olddevice ||
56412 + !(match->mode & GR_DELETED)))
56413 + match = match->next;
56414 +
56415 + if (match && (match->inode == oldinode)
56416 + && (match->device == olddevice)
56417 + && (match->mode & GR_DELETED)) {
56418 + if (match->prev == NULL) {
56419 + role->subj_hash[index] = match->next;
56420 + if (match->next != NULL)
56421 + match->next->prev = NULL;
56422 + } else {
56423 + match->prev->next = match->next;
56424 + if (match->next != NULL)
56425 + match->next->prev = match->prev;
56426 + }
56427 + match->prev = NULL;
56428 + match->next = NULL;
56429 + match->inode = newinode;
56430 + match->device = newdevice;
56431 + match->mode &= ~GR_DELETED;
56432 +
56433 + insert_acl_subj_label(match, role);
56434 + }
56435 +
56436 + return;
56437 +}
56438 +
56439 +static void
56440 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
56441 + const ino_t newinode, const dev_t newdevice)
56442 +{
56443 + unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
56444 + struct inodev_entry *match;
56445 +
56446 + match = inodev_set.i_hash[index];
56447 +
56448 + while (match && (match->nentry->inode != oldinode ||
56449 + match->nentry->device != olddevice || !match->nentry->deleted))
56450 + match = match->next;
56451 +
56452 + if (match && (match->nentry->inode == oldinode)
56453 + && (match->nentry->device == olddevice) &&
56454 + match->nentry->deleted) {
56455 + if (match->prev == NULL) {
56456 + inodev_set.i_hash[index] = match->next;
56457 + if (match->next != NULL)
56458 + match->next->prev = NULL;
56459 + } else {
56460 + match->prev->next = match->next;
56461 + if (match->next != NULL)
56462 + match->next->prev = match->prev;
56463 + }
56464 + match->prev = NULL;
56465 + match->next = NULL;
56466 + match->nentry->inode = newinode;
56467 + match->nentry->device = newdevice;
56468 + match->nentry->deleted = 0;
56469 +
56470 + insert_inodev_entry(match);
56471 + }
56472 +
56473 + return;
56474 +}
56475 +
56476 +static void
56477 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
56478 +{
56479 + struct acl_subject_label *subj;
56480 + struct acl_role_label *role;
56481 + unsigned int x;
56482 +
56483 + FOR_EACH_ROLE_START(role)
56484 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
56485 +
56486 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
56487 + if ((subj->inode == ino) && (subj->device == dev)) {
56488 + subj->inode = ino;
56489 + subj->device = dev;
56490 + }
56491 + /* nested subjects aren't in the role's subj_hash table */
56492 + update_acl_obj_label(matchn->inode, matchn->device,
56493 + ino, dev, subj);
56494 + FOR_EACH_NESTED_SUBJECT_END(subj)
56495 + FOR_EACH_SUBJECT_START(role, subj, x)
56496 + update_acl_obj_label(matchn->inode, matchn->device,
56497 + ino, dev, subj);
56498 + FOR_EACH_SUBJECT_END(subj,x)
56499 + FOR_EACH_ROLE_END(role)
56500 +
56501 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
56502 +
56503 + return;
56504 +}
56505 +
56506 +static void
56507 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
56508 + const struct vfsmount *mnt)
56509 +{
56510 + ino_t ino = dentry->d_inode->i_ino;
56511 + dev_t dev = __get_dev(dentry);
56512 +
56513 + __do_handle_create(matchn, ino, dev);
56514 +
56515 + return;
56516 +}
56517 +
56518 +void
56519 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
56520 +{
56521 + struct name_entry *matchn;
56522 +
56523 + if (unlikely(!(gr_status & GR_READY)))
56524 + return;
56525 +
56526 + preempt_disable();
56527 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
56528 +
56529 + if (unlikely((unsigned long)matchn)) {
56530 + write_lock(&gr_inode_lock);
56531 + do_handle_create(matchn, dentry, mnt);
56532 + write_unlock(&gr_inode_lock);
56533 + }
56534 + preempt_enable();
56535 +
56536 + return;
56537 +}
56538 +
56539 +void
56540 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56541 +{
56542 + struct name_entry *matchn;
56543 +
56544 + if (unlikely(!(gr_status & GR_READY)))
56545 + return;
56546 +
56547 + preempt_disable();
56548 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
56549 +
56550 + if (unlikely((unsigned long)matchn)) {
56551 + write_lock(&gr_inode_lock);
56552 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
56553 + write_unlock(&gr_inode_lock);
56554 + }
56555 + preempt_enable();
56556 +
56557 + return;
56558 +}
56559 +
56560 +void
56561 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
56562 + struct dentry *old_dentry,
56563 + struct dentry *new_dentry,
56564 + struct vfsmount *mnt, const __u8 replace)
56565 +{
56566 + struct name_entry *matchn;
56567 + struct inodev_entry *inodev;
56568 + struct inode *inode = new_dentry->d_inode;
56569 + ino_t old_ino = old_dentry->d_inode->i_ino;
56570 + dev_t old_dev = __get_dev(old_dentry);
56571 +
56572 + /* vfs_rename swaps the name and parent link for old_dentry and
56573 + new_dentry
56574 + at this point, old_dentry has the new name, parent link, and inode
56575 + for the renamed file
56576 + if a file is being replaced by a rename, new_dentry has the inode
56577 + and name for the replaced file
56578 + */
56579 +
56580 + if (unlikely(!(gr_status & GR_READY)))
56581 + return;
56582 +
56583 + preempt_disable();
56584 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
56585 +
56586 + /* we wouldn't have to check d_inode if it weren't for
56587 + NFS silly-renaming
56588 + */
56589 +
56590 + write_lock(&gr_inode_lock);
56591 + if (unlikely(replace && inode)) {
56592 + ino_t new_ino = inode->i_ino;
56593 + dev_t new_dev = __get_dev(new_dentry);
56594 +
56595 + inodev = lookup_inodev_entry(new_ino, new_dev);
56596 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
56597 + do_handle_delete(inodev, new_ino, new_dev);
56598 + }
56599 +
56600 + inodev = lookup_inodev_entry(old_ino, old_dev);
56601 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
56602 + do_handle_delete(inodev, old_ino, old_dev);
56603 +
56604 + if (unlikely((unsigned long)matchn))
56605 + do_handle_create(matchn, old_dentry, mnt);
56606 +
56607 + write_unlock(&gr_inode_lock);
56608 + preempt_enable();
56609 +
56610 + return;
56611 +}
56612 +
56613 +static int
56614 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
56615 + unsigned char **sum)
56616 +{
56617 + struct acl_role_label *r;
56618 + struct role_allowed_ip *ipp;
56619 + struct role_transition *trans;
56620 + unsigned int i;
56621 + int found = 0;
56622 + u32 curr_ip = current->signal->curr_ip;
56623 +
56624 + current->signal->saved_ip = curr_ip;
56625 +
56626 + /* check transition table */
56627 +
56628 + for (trans = current->role->transitions; trans; trans = trans->next) {
56629 + if (!strcmp(rolename, trans->rolename)) {
56630 + found = 1;
56631 + break;
56632 + }
56633 + }
56634 +
56635 + if (!found)
56636 + return 0;
56637 +
56638 + /* handle special roles that do not require authentication
56639 + and check ip */
56640 +
56641 + FOR_EACH_ROLE_START(r)
56642 + if (!strcmp(rolename, r->rolename) &&
56643 + (r->roletype & GR_ROLE_SPECIAL)) {
56644 + found = 0;
56645 + if (r->allowed_ips != NULL) {
56646 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
56647 + if ((ntohl(curr_ip) & ipp->netmask) ==
56648 + (ntohl(ipp->addr) & ipp->netmask))
56649 + found = 1;
56650 + }
56651 + } else
56652 + found = 2;
56653 + if (!found)
56654 + return 0;
56655 +
56656 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
56657 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
56658 + *salt = NULL;
56659 + *sum = NULL;
56660 + return 1;
56661 + }
56662 + }
56663 + FOR_EACH_ROLE_END(r)
56664 +
56665 + for (i = 0; i < num_sprole_pws; i++) {
56666 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
56667 + *salt = acl_special_roles[i]->salt;
56668 + *sum = acl_special_roles[i]->sum;
56669 + return 1;
56670 + }
56671 + }
56672 +
56673 + return 0;
56674 +}
56675 +
56676 +static void
56677 +assign_special_role(char *rolename)
56678 +{
56679 + struct acl_object_label *obj;
56680 + struct acl_role_label *r;
56681 + struct acl_role_label *assigned = NULL;
56682 + struct task_struct *tsk;
56683 + struct file *filp;
56684 +
56685 + FOR_EACH_ROLE_START(r)
56686 + if (!strcmp(rolename, r->rolename) &&
56687 + (r->roletype & GR_ROLE_SPECIAL)) {
56688 + assigned = r;
56689 + break;
56690 + }
56691 + FOR_EACH_ROLE_END(r)
56692 +
56693 + if (!assigned)
56694 + return;
56695 +
56696 + read_lock(&tasklist_lock);
56697 + read_lock(&grsec_exec_file_lock);
56698 +
56699 + tsk = current->real_parent;
56700 + if (tsk == NULL)
56701 + goto out_unlock;
56702 +
56703 + filp = tsk->exec_file;
56704 + if (filp == NULL)
56705 + goto out_unlock;
56706 +
56707 + tsk->is_writable = 0;
56708 +
56709 + tsk->acl_sp_role = 1;
56710 + tsk->acl_role_id = ++acl_sp_role_value;
56711 + tsk->role = assigned;
56712 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
56713 +
56714 + /* ignore additional mmap checks for processes that are writable
56715 + by the default ACL */
56716 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56717 + if (unlikely(obj->mode & GR_WRITE))
56718 + tsk->is_writable = 1;
56719 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
56720 + if (unlikely(obj->mode & GR_WRITE))
56721 + tsk->is_writable = 1;
56722 +
56723 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56724 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
56725 +#endif
56726 +
56727 +out_unlock:
56728 + read_unlock(&grsec_exec_file_lock);
56729 + read_unlock(&tasklist_lock);
56730 + return;
56731 +}
56732 +
56733 +int gr_check_secure_terminal(struct task_struct *task)
56734 +{
56735 + struct task_struct *p, *p2, *p3;
56736 + struct files_struct *files;
56737 + struct fdtable *fdt;
56738 + struct file *our_file = NULL, *file;
56739 + int i;
56740 +
56741 + if (task->signal->tty == NULL)
56742 + return 1;
56743 +
56744 + files = get_files_struct(task);
56745 + if (files != NULL) {
56746 + rcu_read_lock();
56747 + fdt = files_fdtable(files);
56748 + for (i=0; i < fdt->max_fds; i++) {
56749 + file = fcheck_files(files, i);
56750 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
56751 + get_file(file);
56752 + our_file = file;
56753 + }
56754 + }
56755 + rcu_read_unlock();
56756 + put_files_struct(files);
56757 + }
56758 +
56759 + if (our_file == NULL)
56760 + return 1;
56761 +
56762 + read_lock(&tasklist_lock);
56763 + do_each_thread(p2, p) {
56764 + files = get_files_struct(p);
56765 + if (files == NULL ||
56766 + (p->signal && p->signal->tty == task->signal->tty)) {
56767 + if (files != NULL)
56768 + put_files_struct(files);
56769 + continue;
56770 + }
56771 + rcu_read_lock();
56772 + fdt = files_fdtable(files);
56773 + for (i=0; i < fdt->max_fds; i++) {
56774 + file = fcheck_files(files, i);
56775 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
56776 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
56777 + p3 = task;
56778 + while (p3->pid > 0) {
56779 + if (p3 == p)
56780 + break;
56781 + p3 = p3->real_parent;
56782 + }
56783 + if (p3 == p)
56784 + break;
56785 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
56786 + gr_handle_alertkill(p);
56787 + rcu_read_unlock();
56788 + put_files_struct(files);
56789 + read_unlock(&tasklist_lock);
56790 + fput(our_file);
56791 + return 0;
56792 + }
56793 + }
56794 + rcu_read_unlock();
56795 + put_files_struct(files);
56796 + } while_each_thread(p2, p);
56797 + read_unlock(&tasklist_lock);
56798 +
56799 + fput(our_file);
56800 + return 1;
56801 +}
56802 +
56803 +static int gr_rbac_disable(void *unused)
56804 +{
56805 + pax_open_kernel();
56806 + gr_status &= ~GR_READY;
56807 + pax_close_kernel();
56808 +
56809 + return 0;
56810 +}
56811 +
56812 +ssize_t
56813 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
56814 +{
56815 + struct gr_arg_wrapper uwrap;
56816 + unsigned char *sprole_salt = NULL;
56817 + unsigned char *sprole_sum = NULL;
56818 + int error = sizeof (struct gr_arg_wrapper);
56819 + int error2 = 0;
56820 +
56821 + mutex_lock(&gr_dev_mutex);
56822 +
56823 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
56824 + error = -EPERM;
56825 + goto out;
56826 + }
56827 +
56828 + if (count != sizeof (struct gr_arg_wrapper)) {
56829 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
56830 + error = -EINVAL;
56831 + goto out;
56832 + }
56833 +
56834 +
56835 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
56836 + gr_auth_expires = 0;
56837 + gr_auth_attempts = 0;
56838 + }
56839 +
56840 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
56841 + error = -EFAULT;
56842 + goto out;
56843 + }
56844 +
56845 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
56846 + error = -EINVAL;
56847 + goto out;
56848 + }
56849 +
56850 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
56851 + error = -EFAULT;
56852 + goto out;
56853 + }
56854 +
56855 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56856 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56857 + time_after(gr_auth_expires, get_seconds())) {
56858 + error = -EBUSY;
56859 + goto out;
56860 + }
56861 +
56862 + /* if non-root trying to do anything other than use a special role,
56863 + do not attempt authentication, do not count towards authentication
56864 + locking
56865 + */
56866 +
56867 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
56868 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56869 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
56870 + error = -EPERM;
56871 + goto out;
56872 + }
56873 +
56874 + /* ensure pw and special role name are null terminated */
56875 +
56876 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
56877 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
56878 +
56879 + /* Okay.
56880 + * We have our enough of the argument structure..(we have yet
56881 + * to copy_from_user the tables themselves) . Copy the tables
56882 + * only if we need them, i.e. for loading operations. */
56883 +
56884 + switch (gr_usermode->mode) {
56885 + case GR_STATUS:
56886 + if (gr_status & GR_READY) {
56887 + error = 1;
56888 + if (!gr_check_secure_terminal(current))
56889 + error = 3;
56890 + } else
56891 + error = 2;
56892 + goto out;
56893 + case GR_SHUTDOWN:
56894 + if ((gr_status & GR_READY)
56895 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56896 + stop_machine(gr_rbac_disable, NULL, NULL);
56897 + free_variables();
56898 + memset(gr_usermode, 0, sizeof (struct gr_arg));
56899 + memset(gr_system_salt, 0, GR_SALT_LEN);
56900 + memset(gr_system_sum, 0, GR_SHA_LEN);
56901 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
56902 + } else if (gr_status & GR_READY) {
56903 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
56904 + error = -EPERM;
56905 + } else {
56906 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
56907 + error = -EAGAIN;
56908 + }
56909 + break;
56910 + case GR_ENABLE:
56911 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
56912 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
56913 + else {
56914 + if (gr_status & GR_READY)
56915 + error = -EAGAIN;
56916 + else
56917 + error = error2;
56918 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
56919 + }
56920 + break;
56921 + case GR_RELOAD:
56922 + if (!(gr_status & GR_READY)) {
56923 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
56924 + error = -EAGAIN;
56925 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56926 + stop_machine(gr_rbac_disable, NULL, NULL);
56927 + free_variables();
56928 + error2 = gracl_init(gr_usermode);
56929 + if (!error2)
56930 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
56931 + else {
56932 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56933 + error = error2;
56934 + }
56935 + } else {
56936 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56937 + error = -EPERM;
56938 + }
56939 + break;
56940 + case GR_SEGVMOD:
56941 + if (unlikely(!(gr_status & GR_READY))) {
56942 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
56943 + error = -EAGAIN;
56944 + break;
56945 + }
56946 +
56947 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56948 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
56949 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
56950 + struct acl_subject_label *segvacl;
56951 + segvacl =
56952 + lookup_acl_subj_label(gr_usermode->segv_inode,
56953 + gr_usermode->segv_device,
56954 + current->role);
56955 + if (segvacl) {
56956 + segvacl->crashes = 0;
56957 + segvacl->expires = 0;
56958 + }
56959 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
56960 + gr_remove_uid(gr_usermode->segv_uid);
56961 + }
56962 + } else {
56963 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
56964 + error = -EPERM;
56965 + }
56966 + break;
56967 + case GR_SPROLE:
56968 + case GR_SPROLEPAM:
56969 + if (unlikely(!(gr_status & GR_READY))) {
56970 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
56971 + error = -EAGAIN;
56972 + break;
56973 + }
56974 +
56975 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
56976 + current->role->expires = 0;
56977 + current->role->auth_attempts = 0;
56978 + }
56979 +
56980 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56981 + time_after(current->role->expires, get_seconds())) {
56982 + error = -EBUSY;
56983 + goto out;
56984 + }
56985 +
56986 + if (lookup_special_role_auth
56987 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
56988 + && ((!sprole_salt && !sprole_sum)
56989 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
56990 + char *p = "";
56991 + assign_special_role(gr_usermode->sp_role);
56992 + read_lock(&tasklist_lock);
56993 + if (current->real_parent)
56994 + p = current->real_parent->role->rolename;
56995 + read_unlock(&tasklist_lock);
56996 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
56997 + p, acl_sp_role_value);
56998 + } else {
56999 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
57000 + error = -EPERM;
57001 + if(!(current->role->auth_attempts++))
57002 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
57003 +
57004 + goto out;
57005 + }
57006 + break;
57007 + case GR_UNSPROLE:
57008 + if (unlikely(!(gr_status & GR_READY))) {
57009 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
57010 + error = -EAGAIN;
57011 + break;
57012 + }
57013 +
57014 + if (current->role->roletype & GR_ROLE_SPECIAL) {
57015 + char *p = "";
57016 + int i = 0;
57017 +
57018 + read_lock(&tasklist_lock);
57019 + if (current->real_parent) {
57020 + p = current->real_parent->role->rolename;
57021 + i = current->real_parent->acl_role_id;
57022 + }
57023 + read_unlock(&tasklist_lock);
57024 +
57025 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
57026 + gr_set_acls(1);
57027 + } else {
57028 + error = -EPERM;
57029 + goto out;
57030 + }
57031 + break;
57032 + default:
57033 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
57034 + error = -EINVAL;
57035 + break;
57036 + }
57037 +
57038 + if (error != -EPERM)
57039 + goto out;
57040 +
57041 + if(!(gr_auth_attempts++))
57042 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
57043 +
57044 + out:
57045 + mutex_unlock(&gr_dev_mutex);
57046 + return error;
57047 +}
57048 +
57049 +/* must be called with
57050 + rcu_read_lock();
57051 + read_lock(&tasklist_lock);
57052 + read_lock(&grsec_exec_file_lock);
57053 +*/
57054 +int gr_apply_subject_to_task(struct task_struct *task)
57055 +{
57056 + struct acl_object_label *obj;
57057 + char *tmpname;
57058 + struct acl_subject_label *tmpsubj;
57059 + struct file *filp;
57060 + struct name_entry *nmatch;
57061 +
57062 + filp = task->exec_file;
57063 + if (filp == NULL)
57064 + return 0;
57065 +
57066 + /* the following is to apply the correct subject
57067 + on binaries running when the RBAC system
57068 + is enabled, when the binaries have been
57069 + replaced or deleted since their execution
57070 + -----
57071 + when the RBAC system starts, the inode/dev
57072 + from exec_file will be one the RBAC system
57073 + is unaware of. It only knows the inode/dev
57074 + of the present file on disk, or the absence
57075 + of it.
57076 + */
57077 + preempt_disable();
57078 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
57079 +
57080 + nmatch = lookup_name_entry(tmpname);
57081 + preempt_enable();
57082 + tmpsubj = NULL;
57083 + if (nmatch) {
57084 + if (nmatch->deleted)
57085 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
57086 + else
57087 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
57088 + if (tmpsubj != NULL)
57089 + task->acl = tmpsubj;
57090 + }
57091 + if (tmpsubj == NULL)
57092 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
57093 + task->role);
57094 + if (task->acl) {
57095 + task->is_writable = 0;
57096 + /* ignore additional mmap checks for processes that are writable
57097 + by the default ACL */
57098 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57099 + if (unlikely(obj->mode & GR_WRITE))
57100 + task->is_writable = 1;
57101 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
57102 + if (unlikely(obj->mode & GR_WRITE))
57103 + task->is_writable = 1;
57104 +
57105 + gr_set_proc_res(task);
57106 +
57107 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57108 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57109 +#endif
57110 + } else {
57111 + return 1;
57112 + }
57113 +
57114 + return 0;
57115 +}
57116 +
57117 +int
57118 +gr_set_acls(const int type)
57119 +{
57120 + struct task_struct *task, *task2;
57121 + struct acl_role_label *role = current->role;
57122 + __u16 acl_role_id = current->acl_role_id;
57123 + const struct cred *cred;
57124 + int ret;
57125 +
57126 + rcu_read_lock();
57127 + read_lock(&tasklist_lock);
57128 + read_lock(&grsec_exec_file_lock);
57129 + do_each_thread(task2, task) {
57130 + /* check to see if we're called from the exit handler,
57131 + if so, only replace ACLs that have inherited the admin
57132 + ACL */
57133 +
57134 + if (type && (task->role != role ||
57135 + task->acl_role_id != acl_role_id))
57136 + continue;
57137 +
57138 + task->acl_role_id = 0;
57139 + task->acl_sp_role = 0;
57140 +
57141 + if (task->exec_file) {
57142 + cred = __task_cred(task);
57143 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
57144 + ret = gr_apply_subject_to_task(task);
57145 + if (ret) {
57146 + read_unlock(&grsec_exec_file_lock);
57147 + read_unlock(&tasklist_lock);
57148 + rcu_read_unlock();
57149 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
57150 + return ret;
57151 + }
57152 + } else {
57153 + // it's a kernel process
57154 + task->role = kernel_role;
57155 + task->acl = kernel_role->root_label;
57156 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
57157 + task->acl->mode &= ~GR_PROCFIND;
57158 +#endif
57159 + }
57160 + } while_each_thread(task2, task);
57161 + read_unlock(&grsec_exec_file_lock);
57162 + read_unlock(&tasklist_lock);
57163 + rcu_read_unlock();
57164 +
57165 + return 0;
57166 +}
57167 +
57168 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
57169 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
57170 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
57171 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
57172 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
57173 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
57174 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
57175 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
57176 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
57177 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
57178 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
57179 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
57180 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
57181 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
57182 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
57183 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
57184 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
57185 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
57186 +};
57187 +
57188 +void
57189 +gr_learn_resource(const struct task_struct *task,
57190 + const int res, const unsigned long wanted, const int gt)
57191 +{
57192 + struct acl_subject_label *acl;
57193 + const struct cred *cred;
57194 +
57195 + if (unlikely((gr_status & GR_READY) &&
57196 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
57197 + goto skip_reslog;
57198 +
57199 + gr_log_resource(task, res, wanted, gt);
57200 +skip_reslog:
57201 +
57202 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
57203 + return;
57204 +
57205 + acl = task->acl;
57206 +
57207 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
57208 + !(acl->resmask & (1 << (unsigned short) res))))
57209 + return;
57210 +
57211 + if (wanted >= acl->res[res].rlim_cur) {
57212 + unsigned long res_add;
57213 +
57214 + res_add = wanted + res_learn_bumps[res];
57215 +
57216 + acl->res[res].rlim_cur = res_add;
57217 +
57218 + if (wanted > acl->res[res].rlim_max)
57219 + acl->res[res].rlim_max = res_add;
57220 +
57221 + /* only log the subject filename, since resource logging is supported for
57222 + single-subject learning only */
57223 + rcu_read_lock();
57224 + cred = __task_cred(task);
57225 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57226 + task->role->roletype, cred->uid, cred->gid, acl->filename,
57227 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
57228 + "", (unsigned long) res, &task->signal->saved_ip);
57229 + rcu_read_unlock();
57230 + }
57231 +
57232 + return;
57233 +}
57234 +EXPORT_SYMBOL(gr_learn_resource);
57235 +#endif
57236 +
57237 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
57238 +void
57239 +pax_set_initial_flags(struct linux_binprm *bprm)
57240 +{
57241 + struct task_struct *task = current;
57242 + struct acl_subject_label *proc;
57243 + unsigned long flags;
57244 +
57245 + if (unlikely(!(gr_status & GR_READY)))
57246 + return;
57247 +
57248 + flags = pax_get_flags(task);
57249 +
57250 + proc = task->acl;
57251 +
57252 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
57253 + flags &= ~MF_PAX_PAGEEXEC;
57254 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
57255 + flags &= ~MF_PAX_SEGMEXEC;
57256 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
57257 + flags &= ~MF_PAX_RANDMMAP;
57258 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
57259 + flags &= ~MF_PAX_EMUTRAMP;
57260 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
57261 + flags &= ~MF_PAX_MPROTECT;
57262 +
57263 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
57264 + flags |= MF_PAX_PAGEEXEC;
57265 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
57266 + flags |= MF_PAX_SEGMEXEC;
57267 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
57268 + flags |= MF_PAX_RANDMMAP;
57269 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
57270 + flags |= MF_PAX_EMUTRAMP;
57271 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
57272 + flags |= MF_PAX_MPROTECT;
57273 +
57274 + pax_set_flags(task, flags);
57275 +
57276 + return;
57277 +}
57278 +#endif
57279 +
57280 +int
57281 +gr_handle_proc_ptrace(struct task_struct *task)
57282 +{
57283 + struct file *filp;
57284 + struct task_struct *tmp = task;
57285 + struct task_struct *curtemp = current;
57286 + __u32 retmode;
57287 +
57288 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
57289 + if (unlikely(!(gr_status & GR_READY)))
57290 + return 0;
57291 +#endif
57292 +
57293 + read_lock(&tasklist_lock);
57294 + read_lock(&grsec_exec_file_lock);
57295 + filp = task->exec_file;
57296 +
57297 + while (tmp->pid > 0) {
57298 + if (tmp == curtemp)
57299 + break;
57300 + tmp = tmp->real_parent;
57301 + }
57302 +
57303 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
57304 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
57305 + read_unlock(&grsec_exec_file_lock);
57306 + read_unlock(&tasklist_lock);
57307 + return 1;
57308 + }
57309 +
57310 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57311 + if (!(gr_status & GR_READY)) {
57312 + read_unlock(&grsec_exec_file_lock);
57313 + read_unlock(&tasklist_lock);
57314 + return 0;
57315 + }
57316 +#endif
57317 +
57318 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
57319 + read_unlock(&grsec_exec_file_lock);
57320 + read_unlock(&tasklist_lock);
57321 +
57322 + if (retmode & GR_NOPTRACE)
57323 + return 1;
57324 +
57325 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
57326 + && (current->acl != task->acl || (current->acl != current->role->root_label
57327 + && current->pid != task->pid)))
57328 + return 1;
57329 +
57330 + return 0;
57331 +}
57332 +
57333 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
57334 +{
57335 + if (unlikely(!(gr_status & GR_READY)))
57336 + return;
57337 +
57338 + if (!(current->role->roletype & GR_ROLE_GOD))
57339 + return;
57340 +
57341 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
57342 + p->role->rolename, gr_task_roletype_to_char(p),
57343 + p->acl->filename);
57344 +}
57345 +
57346 +int
57347 +gr_handle_ptrace(struct task_struct *task, const long request)
57348 +{
57349 + struct task_struct *tmp = task;
57350 + struct task_struct *curtemp = current;
57351 + __u32 retmode;
57352 +
57353 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
57354 + if (unlikely(!(gr_status & GR_READY)))
57355 + return 0;
57356 +#endif
57357 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
57358 + read_lock(&tasklist_lock);
57359 + while (tmp->pid > 0) {
57360 + if (tmp == curtemp)
57361 + break;
57362 + tmp = tmp->real_parent;
57363 + }
57364 +
57365 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
57366 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
57367 + read_unlock(&tasklist_lock);
57368 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57369 + return 1;
57370 + }
57371 + read_unlock(&tasklist_lock);
57372 + }
57373 +
57374 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57375 + if (!(gr_status & GR_READY))
57376 + return 0;
57377 +#endif
57378 +
57379 + read_lock(&grsec_exec_file_lock);
57380 + if (unlikely(!task->exec_file)) {
57381 + read_unlock(&grsec_exec_file_lock);
57382 + return 0;
57383 + }
57384 +
57385 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
57386 + read_unlock(&grsec_exec_file_lock);
57387 +
57388 + if (retmode & GR_NOPTRACE) {
57389 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57390 + return 1;
57391 + }
57392 +
57393 + if (retmode & GR_PTRACERD) {
57394 + switch (request) {
57395 + case PTRACE_SEIZE:
57396 + case PTRACE_POKETEXT:
57397 + case PTRACE_POKEDATA:
57398 + case PTRACE_POKEUSR:
57399 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
57400 + case PTRACE_SETREGS:
57401 + case PTRACE_SETFPREGS:
57402 +#endif
57403 +#ifdef CONFIG_X86
57404 + case PTRACE_SETFPXREGS:
57405 +#endif
57406 +#ifdef CONFIG_ALTIVEC
57407 + case PTRACE_SETVRREGS:
57408 +#endif
57409 + return 1;
57410 + default:
57411 + return 0;
57412 + }
57413 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
57414 + !(current->role->roletype & GR_ROLE_GOD) &&
57415 + (current->acl != task->acl)) {
57416 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57417 + return 1;
57418 + }
57419 +
57420 + return 0;
57421 +}
57422 +
57423 +static int is_writable_mmap(const struct file *filp)
57424 +{
57425 + struct task_struct *task = current;
57426 + struct acl_object_label *obj, *obj2;
57427 +
57428 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
57429 + !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))) {
57430 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57431 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
57432 + task->role->root_label);
57433 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
57434 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
57435 + return 1;
57436 + }
57437 + }
57438 + return 0;
57439 +}
57440 +
57441 +int
57442 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
57443 +{
57444 + __u32 mode;
57445 +
57446 + if (unlikely(!file || !(prot & PROT_EXEC)))
57447 + return 1;
57448 +
57449 + if (is_writable_mmap(file))
57450 + return 0;
57451 +
57452 + mode =
57453 + gr_search_file(file->f_path.dentry,
57454 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
57455 + file->f_path.mnt);
57456 +
57457 + if (!gr_tpe_allow(file))
57458 + return 0;
57459 +
57460 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
57461 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57462 + return 0;
57463 + } else if (unlikely(!(mode & GR_EXEC))) {
57464 + return 0;
57465 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
57466 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57467 + return 1;
57468 + }
57469 +
57470 + return 1;
57471 +}
57472 +
57473 +int
57474 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57475 +{
57476 + __u32 mode;
57477 +
57478 + if (unlikely(!file || !(prot & PROT_EXEC)))
57479 + return 1;
57480 +
57481 + if (is_writable_mmap(file))
57482 + return 0;
57483 +
57484 + mode =
57485 + gr_search_file(file->f_path.dentry,
57486 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
57487 + file->f_path.mnt);
57488 +
57489 + if (!gr_tpe_allow(file))
57490 + return 0;
57491 +
57492 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
57493 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57494 + return 0;
57495 + } else if (unlikely(!(mode & GR_EXEC))) {
57496 + return 0;
57497 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
57498 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57499 + return 1;
57500 + }
57501 +
57502 + return 1;
57503 +}
57504 +
57505 +void
57506 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57507 +{
57508 + unsigned long runtime;
57509 + unsigned long cputime;
57510 + unsigned int wday, cday;
57511 + __u8 whr, chr;
57512 + __u8 wmin, cmin;
57513 + __u8 wsec, csec;
57514 + struct timespec timeval;
57515 +
57516 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
57517 + !(task->acl->mode & GR_PROCACCT)))
57518 + return;
57519 +
57520 + do_posix_clock_monotonic_gettime(&timeval);
57521 + runtime = timeval.tv_sec - task->start_time.tv_sec;
57522 + wday = runtime / (3600 * 24);
57523 + runtime -= wday * (3600 * 24);
57524 + whr = runtime / 3600;
57525 + runtime -= whr * 3600;
57526 + wmin = runtime / 60;
57527 + runtime -= wmin * 60;
57528 + wsec = runtime;
57529 +
57530 + cputime = (task->utime + task->stime) / HZ;
57531 + cday = cputime / (3600 * 24);
57532 + cputime -= cday * (3600 * 24);
57533 + chr = cputime / 3600;
57534 + cputime -= chr * 3600;
57535 + cmin = cputime / 60;
57536 + cputime -= cmin * 60;
57537 + csec = cputime;
57538 +
57539 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
57540 +
57541 + return;
57542 +}
57543 +
57544 +void gr_set_kernel_label(struct task_struct *task)
57545 +{
57546 + if (gr_status & GR_READY) {
57547 + task->role = kernel_role;
57548 + task->acl = kernel_role->root_label;
57549 + }
57550 + return;
57551 +}
57552 +
57553 +#ifdef CONFIG_TASKSTATS
57554 +int gr_is_taskstats_denied(int pid)
57555 +{
57556 + struct task_struct *task;
57557 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57558 + const struct cred *cred;
57559 +#endif
57560 + int ret = 0;
57561 +
57562 + /* restrict taskstats viewing to un-chrooted root users
57563 + who have the 'view' subject flag if the RBAC system is enabled
57564 + */
57565 +
57566 + rcu_read_lock();
57567 + read_lock(&tasklist_lock);
57568 + task = find_task_by_vpid(pid);
57569 + if (task) {
57570 +#ifdef CONFIG_GRKERNSEC_CHROOT
57571 + if (proc_is_chrooted(task))
57572 + ret = -EACCES;
57573 +#endif
57574 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57575 + cred = __task_cred(task);
57576 +#ifdef CONFIG_GRKERNSEC_PROC_USER
57577 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
57578 + ret = -EACCES;
57579 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57580 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
57581 + ret = -EACCES;
57582 +#endif
57583 +#endif
57584 + if (gr_status & GR_READY) {
57585 + if (!(task->acl->mode & GR_VIEW))
57586 + ret = -EACCES;
57587 + }
57588 + } else
57589 + ret = -ENOENT;
57590 +
57591 + read_unlock(&tasklist_lock);
57592 + rcu_read_unlock();
57593 +
57594 + return ret;
57595 +}
57596 +#endif
57597 +
57598 +/* AUXV entries are filled via a descendant of search_binary_handler
57599 + after we've already applied the subject for the target
57600 +*/
57601 +int gr_acl_enable_at_secure(void)
57602 +{
57603 + if (unlikely(!(gr_status & GR_READY)))
57604 + return 0;
57605 +
57606 + if (current->acl->mode & GR_ATSECURE)
57607 + return 1;
57608 +
57609 + return 0;
57610 +}
57611 +
57612 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
57613 +{
57614 + struct task_struct *task = current;
57615 + struct dentry *dentry = file->f_path.dentry;
57616 + struct vfsmount *mnt = file->f_path.mnt;
57617 + struct acl_object_label *obj, *tmp;
57618 + struct acl_subject_label *subj;
57619 + unsigned int bufsize;
57620 + int is_not_root;
57621 + char *path;
57622 + dev_t dev = __get_dev(dentry);
57623 +
57624 + if (unlikely(!(gr_status & GR_READY)))
57625 + return 1;
57626 +
57627 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
57628 + return 1;
57629 +
57630 + /* ignore Eric Biederman */
57631 + if (IS_PRIVATE(dentry->d_inode))
57632 + return 1;
57633 +
57634 + subj = task->acl;
57635 + read_lock(&gr_inode_lock);
57636 + do {
57637 + obj = lookup_acl_obj_label(ino, dev, subj);
57638 + if (obj != NULL) {
57639 + read_unlock(&gr_inode_lock);
57640 + return (obj->mode & GR_FIND) ? 1 : 0;
57641 + }
57642 + } while ((subj = subj->parent_subject));
57643 + read_unlock(&gr_inode_lock);
57644 +
57645 + /* this is purely an optimization since we're looking for an object
57646 + for the directory we're doing a readdir on
57647 + if it's possible for any globbed object to match the entry we're
57648 + filling into the directory, then the object we find here will be
57649 + an anchor point with attached globbed objects
57650 + */
57651 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
57652 + if (obj->globbed == NULL)
57653 + return (obj->mode & GR_FIND) ? 1 : 0;
57654 +
57655 + is_not_root = ((obj->filename[0] == '/') &&
57656 + (obj->filename[1] == '\0')) ? 0 : 1;
57657 + bufsize = PAGE_SIZE - namelen - is_not_root;
57658 +
57659 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
57660 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
57661 + return 1;
57662 +
57663 + preempt_disable();
57664 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57665 + bufsize);
57666 +
57667 + bufsize = strlen(path);
57668 +
57669 + /* if base is "/", don't append an additional slash */
57670 + if (is_not_root)
57671 + *(path + bufsize) = '/';
57672 + memcpy(path + bufsize + is_not_root, name, namelen);
57673 + *(path + bufsize + namelen + is_not_root) = '\0';
57674 +
57675 + tmp = obj->globbed;
57676 + while (tmp) {
57677 + if (!glob_match(tmp->filename, path)) {
57678 + preempt_enable();
57679 + return (tmp->mode & GR_FIND) ? 1 : 0;
57680 + }
57681 + tmp = tmp->next;
57682 + }
57683 + preempt_enable();
57684 + return (obj->mode & GR_FIND) ? 1 : 0;
57685 +}
57686 +
57687 +void gr_put_exec_file(struct task_struct *task)
57688 +{
57689 + struct file *filp;
57690 +
57691 + write_lock(&grsec_exec_file_lock);
57692 + filp = task->exec_file;
57693 + task->exec_file = NULL;
57694 + write_unlock(&grsec_exec_file_lock);
57695 +
57696 + if (filp)
57697 + fput(filp);
57698 +
57699 + return;
57700 +}
57701 +
57702 +
57703 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
57704 +EXPORT_SYMBOL(gr_acl_is_enabled);
57705 +#endif
57706 +EXPORT_SYMBOL(gr_set_kernel_label);
57707 +#ifdef CONFIG_SECURITY
57708 +EXPORT_SYMBOL(gr_check_user_change);
57709 +EXPORT_SYMBOL(gr_check_group_change);
57710 +#endif
57711 +
57712 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
57713 new file mode 100644
57714 index 0000000..34fefda
57715 --- /dev/null
57716 +++ b/grsecurity/gracl_alloc.c
57717 @@ -0,0 +1,105 @@
57718 +#include <linux/kernel.h>
57719 +#include <linux/mm.h>
57720 +#include <linux/slab.h>
57721 +#include <linux/vmalloc.h>
57722 +#include <linux/gracl.h>
57723 +#include <linux/grsecurity.h>
57724 +
57725 +static unsigned long alloc_stack_next = 1;
57726 +static unsigned long alloc_stack_size = 1;
57727 +static void **alloc_stack;
57728 +
57729 +static __inline__ int
57730 +alloc_pop(void)
57731 +{
57732 + if (alloc_stack_next == 1)
57733 + return 0;
57734 +
57735 + kfree(alloc_stack[alloc_stack_next - 2]);
57736 +
57737 + alloc_stack_next--;
57738 +
57739 + return 1;
57740 +}
57741 +
57742 +static __inline__ int
57743 +alloc_push(void *buf)
57744 +{
57745 + if (alloc_stack_next >= alloc_stack_size)
57746 + return 1;
57747 +
57748 + alloc_stack[alloc_stack_next - 1] = buf;
57749 +
57750 + alloc_stack_next++;
57751 +
57752 + return 0;
57753 +}
57754 +
57755 +void *
57756 +acl_alloc(unsigned long len)
57757 +{
57758 + void *ret = NULL;
57759 +
57760 + if (!len || len > PAGE_SIZE)
57761 + goto out;
57762 +
57763 + ret = kmalloc(len, GFP_KERNEL);
57764 +
57765 + if (ret) {
57766 + if (alloc_push(ret)) {
57767 + kfree(ret);
57768 + ret = NULL;
57769 + }
57770 + }
57771 +
57772 +out:
57773 + return ret;
57774 +}
57775 +
57776 +void *
57777 +acl_alloc_num(unsigned long num, unsigned long len)
57778 +{
57779 + if (!len || (num > (PAGE_SIZE / len)))
57780 + return NULL;
57781 +
57782 + return acl_alloc(num * len);
57783 +}
57784 +
57785 +void
57786 +acl_free_all(void)
57787 +{
57788 + if (gr_acl_is_enabled() || !alloc_stack)
57789 + return;
57790 +
57791 + while (alloc_pop()) ;
57792 +
57793 + if (alloc_stack) {
57794 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
57795 + kfree(alloc_stack);
57796 + else
57797 + vfree(alloc_stack);
57798 + }
57799 +
57800 + alloc_stack = NULL;
57801 + alloc_stack_size = 1;
57802 + alloc_stack_next = 1;
57803 +
57804 + return;
57805 +}
57806 +
57807 +int
57808 +acl_alloc_stack_init(unsigned long size)
57809 +{
57810 + if ((size * sizeof (void *)) <= PAGE_SIZE)
57811 + alloc_stack =
57812 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
57813 + else
57814 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
57815 +
57816 + alloc_stack_size = size;
57817 +
57818 + if (!alloc_stack)
57819 + return 0;
57820 + else
57821 + return 1;
57822 +}
57823 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
57824 new file mode 100644
57825 index 0000000..6d21049
57826 --- /dev/null
57827 +++ b/grsecurity/gracl_cap.c
57828 @@ -0,0 +1,110 @@
57829 +#include <linux/kernel.h>
57830 +#include <linux/module.h>
57831 +#include <linux/sched.h>
57832 +#include <linux/gracl.h>
57833 +#include <linux/grsecurity.h>
57834 +#include <linux/grinternal.h>
57835 +
57836 +extern const char *captab_log[];
57837 +extern int captab_log_entries;
57838 +
57839 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57840 +{
57841 + struct acl_subject_label *curracl;
57842 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57843 + kernel_cap_t cap_audit = __cap_empty_set;
57844 +
57845 + if (!gr_acl_is_enabled())
57846 + return 1;
57847 +
57848 + curracl = task->acl;
57849 +
57850 + cap_drop = curracl->cap_lower;
57851 + cap_mask = curracl->cap_mask;
57852 + cap_audit = curracl->cap_invert_audit;
57853 +
57854 + while ((curracl = curracl->parent_subject)) {
57855 + /* if the cap isn't specified in the current computed mask but is specified in the
57856 + current level subject, and is lowered in the current level subject, then add
57857 + it to the set of dropped capabilities
57858 + otherwise, add the current level subject's mask to the current computed mask
57859 + */
57860 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57861 + cap_raise(cap_mask, cap);
57862 + if (cap_raised(curracl->cap_lower, cap))
57863 + cap_raise(cap_drop, cap);
57864 + if (cap_raised(curracl->cap_invert_audit, cap))
57865 + cap_raise(cap_audit, cap);
57866 + }
57867 + }
57868 +
57869 + if (!cap_raised(cap_drop, cap)) {
57870 + if (cap_raised(cap_audit, cap))
57871 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
57872 + return 1;
57873 + }
57874 +
57875 + curracl = task->acl;
57876 +
57877 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
57878 + && cap_raised(cred->cap_effective, cap)) {
57879 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57880 + task->role->roletype, cred->uid,
57881 + cred->gid, task->exec_file ?
57882 + gr_to_filename(task->exec_file->f_path.dentry,
57883 + task->exec_file->f_path.mnt) : curracl->filename,
57884 + curracl->filename, 0UL,
57885 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
57886 + return 1;
57887 + }
57888 +
57889 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
57890 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
57891 +
57892 + return 0;
57893 +}
57894 +
57895 +int
57896 +gr_acl_is_capable(const int cap)
57897 +{
57898 + return gr_task_acl_is_capable(current, current_cred(), cap);
57899 +}
57900 +
57901 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
57902 +{
57903 + struct acl_subject_label *curracl;
57904 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57905 +
57906 + if (!gr_acl_is_enabled())
57907 + return 1;
57908 +
57909 + curracl = task->acl;
57910 +
57911 + cap_drop = curracl->cap_lower;
57912 + cap_mask = curracl->cap_mask;
57913 +
57914 + while ((curracl = curracl->parent_subject)) {
57915 + /* if the cap isn't specified in the current computed mask but is specified in the
57916 + current level subject, and is lowered in the current level subject, then add
57917 + it to the set of dropped capabilities
57918 + otherwise, add the current level subject's mask to the current computed mask
57919 + */
57920 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57921 + cap_raise(cap_mask, cap);
57922 + if (cap_raised(curracl->cap_lower, cap))
57923 + cap_raise(cap_drop, cap);
57924 + }
57925 + }
57926 +
57927 + if (!cap_raised(cap_drop, cap))
57928 + return 1;
57929 +
57930 + return 0;
57931 +}
57932 +
57933 +int
57934 +gr_acl_is_capable_nolog(const int cap)
57935 +{
57936 + return gr_task_acl_is_capable_nolog(current, cap);
57937 +}
57938 +
57939 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
57940 new file mode 100644
57941 index 0000000..a340c17
57942 --- /dev/null
57943 +++ b/grsecurity/gracl_fs.c
57944 @@ -0,0 +1,431 @@
57945 +#include <linux/kernel.h>
57946 +#include <linux/sched.h>
57947 +#include <linux/types.h>
57948 +#include <linux/fs.h>
57949 +#include <linux/file.h>
57950 +#include <linux/stat.h>
57951 +#include <linux/grsecurity.h>
57952 +#include <linux/grinternal.h>
57953 +#include <linux/gracl.h>
57954 +
57955 +umode_t
57956 +gr_acl_umask(void)
57957 +{
57958 + if (unlikely(!gr_acl_is_enabled()))
57959 + return 0;
57960 +
57961 + return current->role->umask;
57962 +}
57963 +
57964 +__u32
57965 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57966 + const struct vfsmount * mnt)
57967 +{
57968 + __u32 mode;
57969 +
57970 + if (unlikely(!dentry->d_inode))
57971 + return GR_FIND;
57972 +
57973 + mode =
57974 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
57975 +
57976 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
57977 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57978 + return mode;
57979 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
57980 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57981 + return 0;
57982 + } else if (unlikely(!(mode & GR_FIND)))
57983 + return 0;
57984 +
57985 + return GR_FIND;
57986 +}
57987 +
57988 +__u32
57989 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57990 + int acc_mode)
57991 +{
57992 + __u32 reqmode = GR_FIND;
57993 + __u32 mode;
57994 +
57995 + if (unlikely(!dentry->d_inode))
57996 + return reqmode;
57997 +
57998 + if (acc_mode & MAY_APPEND)
57999 + reqmode |= GR_APPEND;
58000 + else if (acc_mode & MAY_WRITE)
58001 + reqmode |= GR_WRITE;
58002 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
58003 + reqmode |= GR_READ;
58004 +
58005 + mode =
58006 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58007 + mnt);
58008 +
58009 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58010 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
58011 + reqmode & GR_READ ? " reading" : "",
58012 + reqmode & GR_WRITE ? " writing" : reqmode &
58013 + GR_APPEND ? " appending" : "");
58014 + return reqmode;
58015 + } else
58016 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58017 + {
58018 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
58019 + reqmode & GR_READ ? " reading" : "",
58020 + reqmode & GR_WRITE ? " writing" : reqmode &
58021 + GR_APPEND ? " appending" : "");
58022 + return 0;
58023 + } else if (unlikely((mode & reqmode) != reqmode))
58024 + return 0;
58025 +
58026 + return reqmode;
58027 +}
58028 +
58029 +__u32
58030 +gr_acl_handle_creat(const struct dentry * dentry,
58031 + const struct dentry * p_dentry,
58032 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58033 + const int imode)
58034 +{
58035 + __u32 reqmode = GR_WRITE | GR_CREATE;
58036 + __u32 mode;
58037 +
58038 + if (acc_mode & MAY_APPEND)
58039 + reqmode |= GR_APPEND;
58040 + // if a directory was required or the directory already exists, then
58041 + // don't count this open as a read
58042 + if ((acc_mode & MAY_READ) &&
58043 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
58044 + reqmode |= GR_READ;
58045 + if ((open_flags & O_CREAT) &&
58046 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
58047 + reqmode |= GR_SETID;
58048 +
58049 + mode =
58050 + gr_check_create(dentry, p_dentry, p_mnt,
58051 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
58052 +
58053 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58054 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
58055 + reqmode & GR_READ ? " reading" : "",
58056 + reqmode & GR_WRITE ? " writing" : reqmode &
58057 + GR_APPEND ? " appending" : "");
58058 + return reqmode;
58059 + } else
58060 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58061 + {
58062 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
58063 + reqmode & GR_READ ? " reading" : "",
58064 + reqmode & GR_WRITE ? " writing" : reqmode &
58065 + GR_APPEND ? " appending" : "");
58066 + return 0;
58067 + } else if (unlikely((mode & reqmode) != reqmode))
58068 + return 0;
58069 +
58070 + return reqmode;
58071 +}
58072 +
58073 +__u32
58074 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
58075 + const int fmode)
58076 +{
58077 + __u32 mode, reqmode = GR_FIND;
58078 +
58079 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
58080 + reqmode |= GR_EXEC;
58081 + if (fmode & S_IWOTH)
58082 + reqmode |= GR_WRITE;
58083 + if (fmode & S_IROTH)
58084 + reqmode |= GR_READ;
58085 +
58086 + mode =
58087 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58088 + mnt);
58089 +
58090 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58091 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58092 + reqmode & GR_READ ? " reading" : "",
58093 + reqmode & GR_WRITE ? " writing" : "",
58094 + reqmode & GR_EXEC ? " executing" : "");
58095 + return reqmode;
58096 + } else
58097 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58098 + {
58099 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58100 + reqmode & GR_READ ? " reading" : "",
58101 + reqmode & GR_WRITE ? " writing" : "",
58102 + reqmode & GR_EXEC ? " executing" : "");
58103 + return 0;
58104 + } else if (unlikely((mode & reqmode) != reqmode))
58105 + return 0;
58106 +
58107 + return reqmode;
58108 +}
58109 +
58110 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
58111 +{
58112 + __u32 mode;
58113 +
58114 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
58115 +
58116 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58117 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
58118 + return mode;
58119 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58120 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
58121 + return 0;
58122 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
58123 + return 0;
58124 +
58125 + return (reqmode);
58126 +}
58127 +
58128 +__u32
58129 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58130 +{
58131 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
58132 +}
58133 +
58134 +__u32
58135 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
58136 +{
58137 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
58138 +}
58139 +
58140 +__u32
58141 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
58142 +{
58143 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
58144 +}
58145 +
58146 +__u32
58147 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
58148 +{
58149 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
58150 +}
58151 +
58152 +__u32
58153 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
58154 + umode_t *modeptr)
58155 +{
58156 + umode_t mode;
58157 +
58158 + *modeptr &= ~gr_acl_umask();
58159 + mode = *modeptr;
58160 +
58161 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
58162 + return 1;
58163 +
58164 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
58165 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
58166 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
58167 + GR_CHMOD_ACL_MSG);
58168 + } else {
58169 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
58170 + }
58171 +}
58172 +
58173 +__u32
58174 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
58175 +{
58176 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
58177 +}
58178 +
58179 +__u32
58180 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
58181 +{
58182 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
58183 +}
58184 +
58185 +__u32
58186 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
58187 +{
58188 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
58189 +}
58190 +
58191 +__u32
58192 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
58193 +{
58194 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
58195 + GR_UNIXCONNECT_ACL_MSG);
58196 +}
58197 +
58198 +/* hardlinks require at minimum create and link permission,
58199 + any additional privilege required is based on the
58200 + privilege of the file being linked to
58201 +*/
58202 +__u32
58203 +gr_acl_handle_link(const struct dentry * new_dentry,
58204 + const struct dentry * parent_dentry,
58205 + const struct vfsmount * parent_mnt,
58206 + const struct dentry * old_dentry,
58207 + const struct vfsmount * old_mnt, const struct filename *to)
58208 +{
58209 + __u32 mode;
58210 + __u32 needmode = GR_CREATE | GR_LINK;
58211 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
58212 +
58213 + mode =
58214 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
58215 + old_mnt);
58216 +
58217 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
58218 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58219 + return mode;
58220 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58221 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58222 + return 0;
58223 + } else if (unlikely((mode & needmode) != needmode))
58224 + return 0;
58225 +
58226 + return 1;
58227 +}
58228 +
58229 +__u32
58230 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58231 + const struct dentry * parent_dentry,
58232 + const struct vfsmount * parent_mnt, const struct filename *from)
58233 +{
58234 + __u32 needmode = GR_WRITE | GR_CREATE;
58235 + __u32 mode;
58236 +
58237 + mode =
58238 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
58239 + GR_CREATE | GR_AUDIT_CREATE |
58240 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
58241 +
58242 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
58243 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
58244 + return mode;
58245 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58246 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
58247 + return 0;
58248 + } else if (unlikely((mode & needmode) != needmode))
58249 + return 0;
58250 +
58251 + return (GR_WRITE | GR_CREATE);
58252 +}
58253 +
58254 +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)
58255 +{
58256 + __u32 mode;
58257 +
58258 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
58259 +
58260 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58261 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
58262 + return mode;
58263 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58264 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
58265 + return 0;
58266 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
58267 + return 0;
58268 +
58269 + return (reqmode);
58270 +}
58271 +
58272 +__u32
58273 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58274 + const struct dentry * parent_dentry,
58275 + const struct vfsmount * parent_mnt,
58276 + const int mode)
58277 +{
58278 + __u32 reqmode = GR_WRITE | GR_CREATE;
58279 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
58280 + reqmode |= GR_SETID;
58281 +
58282 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
58283 + reqmode, GR_MKNOD_ACL_MSG);
58284 +}
58285 +
58286 +__u32
58287 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
58288 + const struct dentry *parent_dentry,
58289 + const struct vfsmount *parent_mnt)
58290 +{
58291 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
58292 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
58293 +}
58294 +
58295 +#define RENAME_CHECK_SUCCESS(old, new) \
58296 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
58297 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
58298 +
58299 +int
58300 +gr_acl_handle_rename(struct dentry *new_dentry,
58301 + struct dentry *parent_dentry,
58302 + const struct vfsmount *parent_mnt,
58303 + struct dentry *old_dentry,
58304 + struct inode *old_parent_inode,
58305 + struct vfsmount *old_mnt, const struct filename *newname)
58306 +{
58307 + __u32 comp1, comp2;
58308 + int error = 0;
58309 +
58310 + if (unlikely(!gr_acl_is_enabled()))
58311 + return 0;
58312 +
58313 + if (!new_dentry->d_inode) {
58314 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
58315 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
58316 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
58317 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
58318 + GR_DELETE | GR_AUDIT_DELETE |
58319 + GR_AUDIT_READ | GR_AUDIT_WRITE |
58320 + GR_SUPPRESS, old_mnt);
58321 + } else {
58322 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
58323 + GR_CREATE | GR_DELETE |
58324 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
58325 + GR_AUDIT_READ | GR_AUDIT_WRITE |
58326 + GR_SUPPRESS, parent_mnt);
58327 + comp2 =
58328 + gr_search_file(old_dentry,
58329 + GR_READ | GR_WRITE | GR_AUDIT_READ |
58330 + GR_DELETE | GR_AUDIT_DELETE |
58331 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
58332 + }
58333 +
58334 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
58335 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
58336 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
58337 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
58338 + && !(comp2 & GR_SUPPRESS)) {
58339 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
58340 + error = -EACCES;
58341 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
58342 + error = -EACCES;
58343 +
58344 + return error;
58345 +}
58346 +
58347 +void
58348 +gr_acl_handle_exit(void)
58349 +{
58350 + u16 id;
58351 + char *rolename;
58352 +
58353 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
58354 + !(current->role->roletype & GR_ROLE_PERSIST))) {
58355 + id = current->acl_role_id;
58356 + rolename = current->role->rolename;
58357 + gr_set_acls(1);
58358 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
58359 + }
58360 +
58361 + gr_put_exec_file(current);
58362 + return;
58363 +}
58364 +
58365 +int
58366 +gr_acl_handle_procpidmem(const struct task_struct *task)
58367 +{
58368 + if (unlikely(!gr_acl_is_enabled()))
58369 + return 0;
58370 +
58371 + if (task != current && task->acl->mode & GR_PROTPROCFD)
58372 + return -EACCES;
58373 +
58374 + return 0;
58375 +}
58376 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
58377 new file mode 100644
58378 index 0000000..58800a7
58379 --- /dev/null
58380 +++ b/grsecurity/gracl_ip.c
58381 @@ -0,0 +1,384 @@
58382 +#include <linux/kernel.h>
58383 +#include <asm/uaccess.h>
58384 +#include <asm/errno.h>
58385 +#include <net/sock.h>
58386 +#include <linux/file.h>
58387 +#include <linux/fs.h>
58388 +#include <linux/net.h>
58389 +#include <linux/in.h>
58390 +#include <linux/skbuff.h>
58391 +#include <linux/ip.h>
58392 +#include <linux/udp.h>
58393 +#include <linux/types.h>
58394 +#include <linux/sched.h>
58395 +#include <linux/netdevice.h>
58396 +#include <linux/inetdevice.h>
58397 +#include <linux/gracl.h>
58398 +#include <linux/grsecurity.h>
58399 +#include <linux/grinternal.h>
58400 +
58401 +#define GR_BIND 0x01
58402 +#define GR_CONNECT 0x02
58403 +#define GR_INVERT 0x04
58404 +#define GR_BINDOVERRIDE 0x08
58405 +#define GR_CONNECTOVERRIDE 0x10
58406 +#define GR_SOCK_FAMILY 0x20
58407 +
58408 +static const char * gr_protocols[IPPROTO_MAX] = {
58409 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
58410 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
58411 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
58412 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
58413 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
58414 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
58415 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
58416 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
58417 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
58418 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
58419 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
58420 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
58421 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
58422 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
58423 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
58424 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
58425 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
58426 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
58427 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
58428 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
58429 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
58430 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
58431 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
58432 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
58433 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
58434 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
58435 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
58436 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
58437 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
58438 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
58439 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
58440 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
58441 + };
58442 +
58443 +static const char * gr_socktypes[SOCK_MAX] = {
58444 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
58445 + "unknown:7", "unknown:8", "unknown:9", "packet"
58446 + };
58447 +
58448 +static const char * gr_sockfamilies[AF_MAX+1] = {
58449 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
58450 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
58451 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
58452 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
58453 + };
58454 +
58455 +const char *
58456 +gr_proto_to_name(unsigned char proto)
58457 +{
58458 + return gr_protocols[proto];
58459 +}
58460 +
58461 +const char *
58462 +gr_socktype_to_name(unsigned char type)
58463 +{
58464 + return gr_socktypes[type];
58465 +}
58466 +
58467 +const char *
58468 +gr_sockfamily_to_name(unsigned char family)
58469 +{
58470 + return gr_sockfamilies[family];
58471 +}
58472 +
58473 +int
58474 +gr_search_socket(const int domain, const int type, const int protocol)
58475 +{
58476 + struct acl_subject_label *curr;
58477 + const struct cred *cred = current_cred();
58478 +
58479 + if (unlikely(!gr_acl_is_enabled()))
58480 + goto exit;
58481 +
58482 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
58483 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
58484 + goto exit; // let the kernel handle it
58485 +
58486 + curr = current->acl;
58487 +
58488 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
58489 + /* the family is allowed, if this is PF_INET allow it only if
58490 + the extra sock type/protocol checks pass */
58491 + if (domain == PF_INET)
58492 + goto inet_check;
58493 + goto exit;
58494 + } else {
58495 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58496 + __u32 fakeip = 0;
58497 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58498 + current->role->roletype, cred->uid,
58499 + cred->gid, current->exec_file ?
58500 + gr_to_filename(current->exec_file->f_path.dentry,
58501 + current->exec_file->f_path.mnt) :
58502 + curr->filename, curr->filename,
58503 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
58504 + &current->signal->saved_ip);
58505 + goto exit;
58506 + }
58507 + goto exit_fail;
58508 + }
58509 +
58510 +inet_check:
58511 + /* the rest of this checking is for IPv4 only */
58512 + if (!curr->ips)
58513 + goto exit;
58514 +
58515 + if ((curr->ip_type & (1 << type)) &&
58516 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
58517 + goto exit;
58518 +
58519 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58520 + /* we don't place acls on raw sockets , and sometimes
58521 + dgram/ip sockets are opened for ioctl and not
58522 + bind/connect, so we'll fake a bind learn log */
58523 + if (type == SOCK_RAW || type == SOCK_PACKET) {
58524 + __u32 fakeip = 0;
58525 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58526 + current->role->roletype, cred->uid,
58527 + cred->gid, current->exec_file ?
58528 + gr_to_filename(current->exec_file->f_path.dentry,
58529 + current->exec_file->f_path.mnt) :
58530 + curr->filename, curr->filename,
58531 + &fakeip, 0, type,
58532 + protocol, GR_CONNECT, &current->signal->saved_ip);
58533 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
58534 + __u32 fakeip = 0;
58535 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58536 + current->role->roletype, cred->uid,
58537 + cred->gid, current->exec_file ?
58538 + gr_to_filename(current->exec_file->f_path.dentry,
58539 + current->exec_file->f_path.mnt) :
58540 + curr->filename, curr->filename,
58541 + &fakeip, 0, type,
58542 + protocol, GR_BIND, &current->signal->saved_ip);
58543 + }
58544 + /* we'll log when they use connect or bind */
58545 + goto exit;
58546 + }
58547 +
58548 +exit_fail:
58549 + if (domain == PF_INET)
58550 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
58551 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
58552 + else
58553 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
58554 + gr_socktype_to_name(type), protocol);
58555 +
58556 + return 0;
58557 +exit:
58558 + return 1;
58559 +}
58560 +
58561 +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)
58562 +{
58563 + if ((ip->mode & mode) &&
58564 + (ip_port >= ip->low) &&
58565 + (ip_port <= ip->high) &&
58566 + ((ntohl(ip_addr) & our_netmask) ==
58567 + (ntohl(our_addr) & our_netmask))
58568 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
58569 + && (ip->type & (1 << type))) {
58570 + if (ip->mode & GR_INVERT)
58571 + return 2; // specifically denied
58572 + else
58573 + return 1; // allowed
58574 + }
58575 +
58576 + return 0; // not specifically allowed, may continue parsing
58577 +}
58578 +
58579 +static int
58580 +gr_search_connectbind(const int full_mode, struct sock *sk,
58581 + struct sockaddr_in *addr, const int type)
58582 +{
58583 + char iface[IFNAMSIZ] = {0};
58584 + struct acl_subject_label *curr;
58585 + struct acl_ip_label *ip;
58586 + struct inet_sock *isk;
58587 + struct net_device *dev;
58588 + struct in_device *idev;
58589 + unsigned long i;
58590 + int ret;
58591 + int mode = full_mode & (GR_BIND | GR_CONNECT);
58592 + __u32 ip_addr = 0;
58593 + __u32 our_addr;
58594 + __u32 our_netmask;
58595 + char *p;
58596 + __u16 ip_port = 0;
58597 + const struct cred *cred = current_cred();
58598 +
58599 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
58600 + return 0;
58601 +
58602 + curr = current->acl;
58603 + isk = inet_sk(sk);
58604 +
58605 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
58606 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
58607 + addr->sin_addr.s_addr = curr->inaddr_any_override;
58608 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
58609 + struct sockaddr_in saddr;
58610 + int err;
58611 +
58612 + saddr.sin_family = AF_INET;
58613 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
58614 + saddr.sin_port = isk->inet_sport;
58615 +
58616 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58617 + if (err)
58618 + return err;
58619 +
58620 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58621 + if (err)
58622 + return err;
58623 + }
58624 +
58625 + if (!curr->ips)
58626 + return 0;
58627 +
58628 + ip_addr = addr->sin_addr.s_addr;
58629 + ip_port = ntohs(addr->sin_port);
58630 +
58631 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58632 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58633 + current->role->roletype, cred->uid,
58634 + cred->gid, current->exec_file ?
58635 + gr_to_filename(current->exec_file->f_path.dentry,
58636 + current->exec_file->f_path.mnt) :
58637 + curr->filename, curr->filename,
58638 + &ip_addr, ip_port, type,
58639 + sk->sk_protocol, mode, &current->signal->saved_ip);
58640 + return 0;
58641 + }
58642 +
58643 + for (i = 0; i < curr->ip_num; i++) {
58644 + ip = *(curr->ips + i);
58645 + if (ip->iface != NULL) {
58646 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
58647 + p = strchr(iface, ':');
58648 + if (p != NULL)
58649 + *p = '\0';
58650 + dev = dev_get_by_name(sock_net(sk), iface);
58651 + if (dev == NULL)
58652 + continue;
58653 + idev = in_dev_get(dev);
58654 + if (idev == NULL) {
58655 + dev_put(dev);
58656 + continue;
58657 + }
58658 + rcu_read_lock();
58659 + for_ifa(idev) {
58660 + if (!strcmp(ip->iface, ifa->ifa_label)) {
58661 + our_addr = ifa->ifa_address;
58662 + our_netmask = 0xffffffff;
58663 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58664 + if (ret == 1) {
58665 + rcu_read_unlock();
58666 + in_dev_put(idev);
58667 + dev_put(dev);
58668 + return 0;
58669 + } else if (ret == 2) {
58670 + rcu_read_unlock();
58671 + in_dev_put(idev);
58672 + dev_put(dev);
58673 + goto denied;
58674 + }
58675 + }
58676 + } endfor_ifa(idev);
58677 + rcu_read_unlock();
58678 + in_dev_put(idev);
58679 + dev_put(dev);
58680 + } else {
58681 + our_addr = ip->addr;
58682 + our_netmask = ip->netmask;
58683 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58684 + if (ret == 1)
58685 + return 0;
58686 + else if (ret == 2)
58687 + goto denied;
58688 + }
58689 + }
58690 +
58691 +denied:
58692 + if (mode == GR_BIND)
58693 + 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));
58694 + else if (mode == GR_CONNECT)
58695 + 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));
58696 +
58697 + return -EACCES;
58698 +}
58699 +
58700 +int
58701 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
58702 +{
58703 + /* always allow disconnection of dgram sockets with connect */
58704 + if (addr->sin_family == AF_UNSPEC)
58705 + return 0;
58706 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
58707 +}
58708 +
58709 +int
58710 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
58711 +{
58712 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
58713 +}
58714 +
58715 +int gr_search_listen(struct socket *sock)
58716 +{
58717 + struct sock *sk = sock->sk;
58718 + struct sockaddr_in addr;
58719 +
58720 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58721 + addr.sin_port = inet_sk(sk)->inet_sport;
58722 +
58723 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58724 +}
58725 +
58726 +int gr_search_accept(struct socket *sock)
58727 +{
58728 + struct sock *sk = sock->sk;
58729 + struct sockaddr_in addr;
58730 +
58731 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58732 + addr.sin_port = inet_sk(sk)->inet_sport;
58733 +
58734 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58735 +}
58736 +
58737 +int
58738 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
58739 +{
58740 + if (addr)
58741 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
58742 + else {
58743 + struct sockaddr_in sin;
58744 + const struct inet_sock *inet = inet_sk(sk);
58745 +
58746 + sin.sin_addr.s_addr = inet->inet_daddr;
58747 + sin.sin_port = inet->inet_dport;
58748 +
58749 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58750 + }
58751 +}
58752 +
58753 +int
58754 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
58755 +{
58756 + struct sockaddr_in sin;
58757 +
58758 + if (unlikely(skb->len < sizeof (struct udphdr)))
58759 + return 0; // skip this packet
58760 +
58761 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
58762 + sin.sin_port = udp_hdr(skb)->source;
58763 +
58764 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58765 +}
58766 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
58767 new file mode 100644
58768 index 0000000..25f54ef
58769 --- /dev/null
58770 +++ b/grsecurity/gracl_learn.c
58771 @@ -0,0 +1,207 @@
58772 +#include <linux/kernel.h>
58773 +#include <linux/mm.h>
58774 +#include <linux/sched.h>
58775 +#include <linux/poll.h>
58776 +#include <linux/string.h>
58777 +#include <linux/file.h>
58778 +#include <linux/types.h>
58779 +#include <linux/vmalloc.h>
58780 +#include <linux/grinternal.h>
58781 +
58782 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
58783 + size_t count, loff_t *ppos);
58784 +extern int gr_acl_is_enabled(void);
58785 +
58786 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
58787 +static int gr_learn_attached;
58788 +
58789 +/* use a 512k buffer */
58790 +#define LEARN_BUFFER_SIZE (512 * 1024)
58791 +
58792 +static DEFINE_SPINLOCK(gr_learn_lock);
58793 +static DEFINE_MUTEX(gr_learn_user_mutex);
58794 +
58795 +/* we need to maintain two buffers, so that the kernel context of grlearn
58796 + uses a semaphore around the userspace copying, and the other kernel contexts
58797 + use a spinlock when copying into the buffer, since they cannot sleep
58798 +*/
58799 +static char *learn_buffer;
58800 +static char *learn_buffer_user;
58801 +static int learn_buffer_len;
58802 +static int learn_buffer_user_len;
58803 +
58804 +static ssize_t
58805 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
58806 +{
58807 + DECLARE_WAITQUEUE(wait, current);
58808 + ssize_t retval = 0;
58809 +
58810 + add_wait_queue(&learn_wait, &wait);
58811 + set_current_state(TASK_INTERRUPTIBLE);
58812 + do {
58813 + mutex_lock(&gr_learn_user_mutex);
58814 + spin_lock(&gr_learn_lock);
58815 + if (learn_buffer_len)
58816 + break;
58817 + spin_unlock(&gr_learn_lock);
58818 + mutex_unlock(&gr_learn_user_mutex);
58819 + if (file->f_flags & O_NONBLOCK) {
58820 + retval = -EAGAIN;
58821 + goto out;
58822 + }
58823 + if (signal_pending(current)) {
58824 + retval = -ERESTARTSYS;
58825 + goto out;
58826 + }
58827 +
58828 + schedule();
58829 + } while (1);
58830 +
58831 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
58832 + learn_buffer_user_len = learn_buffer_len;
58833 + retval = learn_buffer_len;
58834 + learn_buffer_len = 0;
58835 +
58836 + spin_unlock(&gr_learn_lock);
58837 +
58838 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
58839 + retval = -EFAULT;
58840 +
58841 + mutex_unlock(&gr_learn_user_mutex);
58842 +out:
58843 + set_current_state(TASK_RUNNING);
58844 + remove_wait_queue(&learn_wait, &wait);
58845 + return retval;
58846 +}
58847 +
58848 +static unsigned int
58849 +poll_learn(struct file * file, poll_table * wait)
58850 +{
58851 + poll_wait(file, &learn_wait, wait);
58852 +
58853 + if (learn_buffer_len)
58854 + return (POLLIN | POLLRDNORM);
58855 +
58856 + return 0;
58857 +}
58858 +
58859 +void
58860 +gr_clear_learn_entries(void)
58861 +{
58862 + char *tmp;
58863 +
58864 + mutex_lock(&gr_learn_user_mutex);
58865 + spin_lock(&gr_learn_lock);
58866 + tmp = learn_buffer;
58867 + learn_buffer = NULL;
58868 + spin_unlock(&gr_learn_lock);
58869 + if (tmp)
58870 + vfree(tmp);
58871 + if (learn_buffer_user != NULL) {
58872 + vfree(learn_buffer_user);
58873 + learn_buffer_user = NULL;
58874 + }
58875 + learn_buffer_len = 0;
58876 + mutex_unlock(&gr_learn_user_mutex);
58877 +
58878 + return;
58879 +}
58880 +
58881 +void
58882 +gr_add_learn_entry(const char *fmt, ...)
58883 +{
58884 + va_list args;
58885 + unsigned int len;
58886 +
58887 + if (!gr_learn_attached)
58888 + return;
58889 +
58890 + spin_lock(&gr_learn_lock);
58891 +
58892 + /* leave a gap at the end so we know when it's "full" but don't have to
58893 + compute the exact length of the string we're trying to append
58894 + */
58895 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
58896 + spin_unlock(&gr_learn_lock);
58897 + wake_up_interruptible(&learn_wait);
58898 + return;
58899 + }
58900 + if (learn_buffer == NULL) {
58901 + spin_unlock(&gr_learn_lock);
58902 + return;
58903 + }
58904 +
58905 + va_start(args, fmt);
58906 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
58907 + va_end(args);
58908 +
58909 + learn_buffer_len += len + 1;
58910 +
58911 + spin_unlock(&gr_learn_lock);
58912 + wake_up_interruptible(&learn_wait);
58913 +
58914 + return;
58915 +}
58916 +
58917 +static int
58918 +open_learn(struct inode *inode, struct file *file)
58919 +{
58920 + if (file->f_mode & FMODE_READ && gr_learn_attached)
58921 + return -EBUSY;
58922 + if (file->f_mode & FMODE_READ) {
58923 + int retval = 0;
58924 + mutex_lock(&gr_learn_user_mutex);
58925 + if (learn_buffer == NULL)
58926 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
58927 + if (learn_buffer_user == NULL)
58928 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
58929 + if (learn_buffer == NULL) {
58930 + retval = -ENOMEM;
58931 + goto out_error;
58932 + }
58933 + if (learn_buffer_user == NULL) {
58934 + retval = -ENOMEM;
58935 + goto out_error;
58936 + }
58937 + learn_buffer_len = 0;
58938 + learn_buffer_user_len = 0;
58939 + gr_learn_attached = 1;
58940 +out_error:
58941 + mutex_unlock(&gr_learn_user_mutex);
58942 + return retval;
58943 + }
58944 + return 0;
58945 +}
58946 +
58947 +static int
58948 +close_learn(struct inode *inode, struct file *file)
58949 +{
58950 + if (file->f_mode & FMODE_READ) {
58951 + char *tmp = NULL;
58952 + mutex_lock(&gr_learn_user_mutex);
58953 + spin_lock(&gr_learn_lock);
58954 + tmp = learn_buffer;
58955 + learn_buffer = NULL;
58956 + spin_unlock(&gr_learn_lock);
58957 + if (tmp)
58958 + vfree(tmp);
58959 + if (learn_buffer_user != NULL) {
58960 + vfree(learn_buffer_user);
58961 + learn_buffer_user = NULL;
58962 + }
58963 + learn_buffer_len = 0;
58964 + learn_buffer_user_len = 0;
58965 + gr_learn_attached = 0;
58966 + mutex_unlock(&gr_learn_user_mutex);
58967 + }
58968 +
58969 + return 0;
58970 +}
58971 +
58972 +const struct file_operations grsec_fops = {
58973 + .read = read_learn,
58974 + .write = write_grsec_handler,
58975 + .open = open_learn,
58976 + .release = close_learn,
58977 + .poll = poll_learn,
58978 +};
58979 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
58980 new file mode 100644
58981 index 0000000..39645c9
58982 --- /dev/null
58983 +++ b/grsecurity/gracl_res.c
58984 @@ -0,0 +1,68 @@
58985 +#include <linux/kernel.h>
58986 +#include <linux/sched.h>
58987 +#include <linux/gracl.h>
58988 +#include <linux/grinternal.h>
58989 +
58990 +static const char *restab_log[] = {
58991 + [RLIMIT_CPU] = "RLIMIT_CPU",
58992 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
58993 + [RLIMIT_DATA] = "RLIMIT_DATA",
58994 + [RLIMIT_STACK] = "RLIMIT_STACK",
58995 + [RLIMIT_CORE] = "RLIMIT_CORE",
58996 + [RLIMIT_RSS] = "RLIMIT_RSS",
58997 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
58998 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
58999 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
59000 + [RLIMIT_AS] = "RLIMIT_AS",
59001 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
59002 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
59003 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
59004 + [RLIMIT_NICE] = "RLIMIT_NICE",
59005 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
59006 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
59007 + [GR_CRASH_RES] = "RLIMIT_CRASH"
59008 +};
59009 +
59010 +void
59011 +gr_log_resource(const struct task_struct *task,
59012 + const int res, const unsigned long wanted, const int gt)
59013 +{
59014 + const struct cred *cred;
59015 + unsigned long rlim;
59016 +
59017 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
59018 + return;
59019 +
59020 + // not yet supported resource
59021 + if (unlikely(!restab_log[res]))
59022 + return;
59023 +
59024 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
59025 + rlim = task_rlimit_max(task, res);
59026 + else
59027 + rlim = task_rlimit(task, res);
59028 +
59029 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
59030 + return;
59031 +
59032 + rcu_read_lock();
59033 + cred = __task_cred(task);
59034 +
59035 + if (res == RLIMIT_NPROC &&
59036 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
59037 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
59038 + goto out_rcu_unlock;
59039 + else if (res == RLIMIT_MEMLOCK &&
59040 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
59041 + goto out_rcu_unlock;
59042 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
59043 + goto out_rcu_unlock;
59044 + rcu_read_unlock();
59045 +
59046 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
59047 +
59048 + return;
59049 +out_rcu_unlock:
59050 + rcu_read_unlock();
59051 + return;
59052 +}
59053 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
59054 new file mode 100644
59055 index 0000000..25197e9
59056 --- /dev/null
59057 +++ b/grsecurity/gracl_segv.c
59058 @@ -0,0 +1,299 @@
59059 +#include <linux/kernel.h>
59060 +#include <linux/mm.h>
59061 +#include <asm/uaccess.h>
59062 +#include <asm/errno.h>
59063 +#include <asm/mman.h>
59064 +#include <net/sock.h>
59065 +#include <linux/file.h>
59066 +#include <linux/fs.h>
59067 +#include <linux/net.h>
59068 +#include <linux/in.h>
59069 +#include <linux/slab.h>
59070 +#include <linux/types.h>
59071 +#include <linux/sched.h>
59072 +#include <linux/timer.h>
59073 +#include <linux/gracl.h>
59074 +#include <linux/grsecurity.h>
59075 +#include <linux/grinternal.h>
59076 +
59077 +static struct crash_uid *uid_set;
59078 +static unsigned short uid_used;
59079 +static DEFINE_SPINLOCK(gr_uid_lock);
59080 +extern rwlock_t gr_inode_lock;
59081 +extern struct acl_subject_label *
59082 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
59083 + struct acl_role_label *role);
59084 +
59085 +#ifdef CONFIG_BTRFS_FS
59086 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
59087 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
59088 +#endif
59089 +
59090 +static inline dev_t __get_dev(const struct dentry *dentry)
59091 +{
59092 +#ifdef CONFIG_BTRFS_FS
59093 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
59094 + return get_btrfs_dev_from_inode(dentry->d_inode);
59095 + else
59096 +#endif
59097 + return dentry->d_inode->i_sb->s_dev;
59098 +}
59099 +
59100 +int
59101 +gr_init_uidset(void)
59102 +{
59103 + uid_set =
59104 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
59105 + uid_used = 0;
59106 +
59107 + return uid_set ? 1 : 0;
59108 +}
59109 +
59110 +void
59111 +gr_free_uidset(void)
59112 +{
59113 + if (uid_set)
59114 + kfree(uid_set);
59115 +
59116 + return;
59117 +}
59118 +
59119 +int
59120 +gr_find_uid(const uid_t uid)
59121 +{
59122 + struct crash_uid *tmp = uid_set;
59123 + uid_t buid;
59124 + int low = 0, high = uid_used - 1, mid;
59125 +
59126 + while (high >= low) {
59127 + mid = (low + high) >> 1;
59128 + buid = tmp[mid].uid;
59129 + if (buid == uid)
59130 + return mid;
59131 + if (buid > uid)
59132 + high = mid - 1;
59133 + if (buid < uid)
59134 + low = mid + 1;
59135 + }
59136 +
59137 + return -1;
59138 +}
59139 +
59140 +static __inline__ void
59141 +gr_insertsort(void)
59142 +{
59143 + unsigned short i, j;
59144 + struct crash_uid index;
59145 +
59146 + for (i = 1; i < uid_used; i++) {
59147 + index = uid_set[i];
59148 + j = i;
59149 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
59150 + uid_set[j] = uid_set[j - 1];
59151 + j--;
59152 + }
59153 + uid_set[j] = index;
59154 + }
59155 +
59156 + return;
59157 +}
59158 +
59159 +static __inline__ void
59160 +gr_insert_uid(const uid_t uid, const unsigned long expires)
59161 +{
59162 + int loc;
59163 +
59164 + if (uid_used == GR_UIDTABLE_MAX)
59165 + return;
59166 +
59167 + loc = gr_find_uid(uid);
59168 +
59169 + if (loc >= 0) {
59170 + uid_set[loc].expires = expires;
59171 + return;
59172 + }
59173 +
59174 + uid_set[uid_used].uid = uid;
59175 + uid_set[uid_used].expires = expires;
59176 + uid_used++;
59177 +
59178 + gr_insertsort();
59179 +
59180 + return;
59181 +}
59182 +
59183 +void
59184 +gr_remove_uid(const unsigned short loc)
59185 +{
59186 + unsigned short i;
59187 +
59188 + for (i = loc + 1; i < uid_used; i++)
59189 + uid_set[i - 1] = uid_set[i];
59190 +
59191 + uid_used--;
59192 +
59193 + return;
59194 +}
59195 +
59196 +int
59197 +gr_check_crash_uid(const uid_t uid)
59198 +{
59199 + int loc;
59200 + int ret = 0;
59201 +
59202 + if (unlikely(!gr_acl_is_enabled()))
59203 + return 0;
59204 +
59205 + spin_lock(&gr_uid_lock);
59206 + loc = gr_find_uid(uid);
59207 +
59208 + if (loc < 0)
59209 + goto out_unlock;
59210 +
59211 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
59212 + gr_remove_uid(loc);
59213 + else
59214 + ret = 1;
59215 +
59216 +out_unlock:
59217 + spin_unlock(&gr_uid_lock);
59218 + return ret;
59219 +}
59220 +
59221 +static __inline__ int
59222 +proc_is_setxid(const struct cred *cred)
59223 +{
59224 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
59225 + !uid_eq(cred->uid, cred->fsuid))
59226 + return 1;
59227 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
59228 + !uid_eq(cred->gid, cred->fsgid))
59229 + return 1;
59230 +
59231 + return 0;
59232 +}
59233 +
59234 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
59235 +
59236 +void
59237 +gr_handle_crash(struct task_struct *task, const int sig)
59238 +{
59239 + struct acl_subject_label *curr;
59240 + struct task_struct *tsk, *tsk2;
59241 + const struct cred *cred;
59242 + const struct cred *cred2;
59243 +
59244 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
59245 + return;
59246 +
59247 + if (unlikely(!gr_acl_is_enabled()))
59248 + return;
59249 +
59250 + curr = task->acl;
59251 +
59252 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
59253 + return;
59254 +
59255 + if (time_before_eq(curr->expires, get_seconds())) {
59256 + curr->expires = 0;
59257 + curr->crashes = 0;
59258 + }
59259 +
59260 + curr->crashes++;
59261 +
59262 + if (!curr->expires)
59263 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
59264 +
59265 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
59266 + time_after(curr->expires, get_seconds())) {
59267 + rcu_read_lock();
59268 + cred = __task_cred(task);
59269 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
59270 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
59271 + spin_lock(&gr_uid_lock);
59272 + gr_insert_uid(cred->uid, curr->expires);
59273 + spin_unlock(&gr_uid_lock);
59274 + curr->expires = 0;
59275 + curr->crashes = 0;
59276 + read_lock(&tasklist_lock);
59277 + do_each_thread(tsk2, tsk) {
59278 + cred2 = __task_cred(tsk);
59279 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
59280 + gr_fake_force_sig(SIGKILL, tsk);
59281 + } while_each_thread(tsk2, tsk);
59282 + read_unlock(&tasklist_lock);
59283 + } else {
59284 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
59285 + read_lock(&tasklist_lock);
59286 + read_lock(&grsec_exec_file_lock);
59287 + do_each_thread(tsk2, tsk) {
59288 + if (likely(tsk != task)) {
59289 + // if this thread has the same subject as the one that triggered
59290 + // RES_CRASH and it's the same binary, kill it
59291 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
59292 + gr_fake_force_sig(SIGKILL, tsk);
59293 + }
59294 + } while_each_thread(tsk2, tsk);
59295 + read_unlock(&grsec_exec_file_lock);
59296 + read_unlock(&tasklist_lock);
59297 + }
59298 + rcu_read_unlock();
59299 + }
59300 +
59301 + return;
59302 +}
59303 +
59304 +int
59305 +gr_check_crash_exec(const struct file *filp)
59306 +{
59307 + struct acl_subject_label *curr;
59308 +
59309 + if (unlikely(!gr_acl_is_enabled()))
59310 + return 0;
59311 +
59312 + read_lock(&gr_inode_lock);
59313 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
59314 + __get_dev(filp->f_path.dentry),
59315 + current->role);
59316 + read_unlock(&gr_inode_lock);
59317 +
59318 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
59319 + (!curr->crashes && !curr->expires))
59320 + return 0;
59321 +
59322 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
59323 + time_after(curr->expires, get_seconds()))
59324 + return 1;
59325 + else if (time_before_eq(curr->expires, get_seconds())) {
59326 + curr->crashes = 0;
59327 + curr->expires = 0;
59328 + }
59329 +
59330 + return 0;
59331 +}
59332 +
59333 +void
59334 +gr_handle_alertkill(struct task_struct *task)
59335 +{
59336 + struct acl_subject_label *curracl;
59337 + __u32 curr_ip;
59338 + struct task_struct *p, *p2;
59339 +
59340 + if (unlikely(!gr_acl_is_enabled()))
59341 + return;
59342 +
59343 + curracl = task->acl;
59344 + curr_ip = task->signal->curr_ip;
59345 +
59346 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
59347 + read_lock(&tasklist_lock);
59348 + do_each_thread(p2, p) {
59349 + if (p->signal->curr_ip == curr_ip)
59350 + gr_fake_force_sig(SIGKILL, p);
59351 + } while_each_thread(p2, p);
59352 + read_unlock(&tasklist_lock);
59353 + } else if (curracl->mode & GR_KILLPROC)
59354 + gr_fake_force_sig(SIGKILL, task);
59355 +
59356 + return;
59357 +}
59358 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
59359 new file mode 100644
59360 index 0000000..9d83a69
59361 --- /dev/null
59362 +++ b/grsecurity/gracl_shm.c
59363 @@ -0,0 +1,40 @@
59364 +#include <linux/kernel.h>
59365 +#include <linux/mm.h>
59366 +#include <linux/sched.h>
59367 +#include <linux/file.h>
59368 +#include <linux/ipc.h>
59369 +#include <linux/gracl.h>
59370 +#include <linux/grsecurity.h>
59371 +#include <linux/grinternal.h>
59372 +
59373 +int
59374 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59375 + const time_t shm_createtime, const uid_t cuid, const int shmid)
59376 +{
59377 + struct task_struct *task;
59378 +
59379 + if (!gr_acl_is_enabled())
59380 + return 1;
59381 +
59382 + rcu_read_lock();
59383 + read_lock(&tasklist_lock);
59384 +
59385 + task = find_task_by_vpid(shm_cprid);
59386 +
59387 + if (unlikely(!task))
59388 + task = find_task_by_vpid(shm_lapid);
59389 +
59390 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
59391 + (task->pid == shm_lapid)) &&
59392 + (task->acl->mode & GR_PROTSHM) &&
59393 + (task->acl != current->acl))) {
59394 + read_unlock(&tasklist_lock);
59395 + rcu_read_unlock();
59396 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
59397 + return 0;
59398 + }
59399 + read_unlock(&tasklist_lock);
59400 + rcu_read_unlock();
59401 +
59402 + return 1;
59403 +}
59404 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
59405 new file mode 100644
59406 index 0000000..bc0be01
59407 --- /dev/null
59408 +++ b/grsecurity/grsec_chdir.c
59409 @@ -0,0 +1,19 @@
59410 +#include <linux/kernel.h>
59411 +#include <linux/sched.h>
59412 +#include <linux/fs.h>
59413 +#include <linux/file.h>
59414 +#include <linux/grsecurity.h>
59415 +#include <linux/grinternal.h>
59416 +
59417 +void
59418 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
59419 +{
59420 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59421 + if ((grsec_enable_chdir && grsec_enable_group &&
59422 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
59423 + !grsec_enable_group)) {
59424 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
59425 + }
59426 +#endif
59427 + return;
59428 +}
59429 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
59430 new file mode 100644
59431 index 0000000..70fe0ae
59432 --- /dev/null
59433 +++ b/grsecurity/grsec_chroot.c
59434 @@ -0,0 +1,357 @@
59435 +#include <linux/kernel.h>
59436 +#include <linux/module.h>
59437 +#include <linux/sched.h>
59438 +#include <linux/file.h>
59439 +#include <linux/fs.h>
59440 +#include <linux/mount.h>
59441 +#include <linux/types.h>
59442 +#include "../fs/mount.h"
59443 +#include <linux/grsecurity.h>
59444 +#include <linux/grinternal.h>
59445 +
59446 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
59447 +{
59448 +#ifdef CONFIG_GRKERNSEC
59449 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
59450 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
59451 + task->gr_is_chrooted = 1;
59452 + else
59453 + task->gr_is_chrooted = 0;
59454 +
59455 + task->gr_chroot_dentry = path->dentry;
59456 +#endif
59457 + return;
59458 +}
59459 +
59460 +void gr_clear_chroot_entries(struct task_struct *task)
59461 +{
59462 +#ifdef CONFIG_GRKERNSEC
59463 + task->gr_is_chrooted = 0;
59464 + task->gr_chroot_dentry = NULL;
59465 +#endif
59466 + return;
59467 +}
59468 +
59469 +int
59470 +gr_handle_chroot_unix(const pid_t pid)
59471 +{
59472 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59473 + struct task_struct *p;
59474 +
59475 + if (unlikely(!grsec_enable_chroot_unix))
59476 + return 1;
59477 +
59478 + if (likely(!proc_is_chrooted(current)))
59479 + return 1;
59480 +
59481 + rcu_read_lock();
59482 + read_lock(&tasklist_lock);
59483 + p = find_task_by_vpid_unrestricted(pid);
59484 + if (unlikely(p && !have_same_root(current, p))) {
59485 + read_unlock(&tasklist_lock);
59486 + rcu_read_unlock();
59487 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
59488 + return 0;
59489 + }
59490 + read_unlock(&tasklist_lock);
59491 + rcu_read_unlock();
59492 +#endif
59493 + return 1;
59494 +}
59495 +
59496 +int
59497 +gr_handle_chroot_nice(void)
59498 +{
59499 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59500 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
59501 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
59502 + return -EPERM;
59503 + }
59504 +#endif
59505 + return 0;
59506 +}
59507 +
59508 +int
59509 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
59510 +{
59511 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59512 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
59513 + && proc_is_chrooted(current)) {
59514 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
59515 + return -EACCES;
59516 + }
59517 +#endif
59518 + return 0;
59519 +}
59520 +
59521 +int
59522 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
59523 +{
59524 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59525 + struct task_struct *p;
59526 + int ret = 0;
59527 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
59528 + return ret;
59529 +
59530 + read_lock(&tasklist_lock);
59531 + do_each_pid_task(pid, type, p) {
59532 + if (!have_same_root(current, p)) {
59533 + ret = 1;
59534 + goto out;
59535 + }
59536 + } while_each_pid_task(pid, type, p);
59537 +out:
59538 + read_unlock(&tasklist_lock);
59539 + return ret;
59540 +#endif
59541 + return 0;
59542 +}
59543 +
59544 +int
59545 +gr_pid_is_chrooted(struct task_struct *p)
59546 +{
59547 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59548 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
59549 + return 0;
59550 +
59551 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
59552 + !have_same_root(current, p)) {
59553 + return 1;
59554 + }
59555 +#endif
59556 + return 0;
59557 +}
59558 +
59559 +EXPORT_SYMBOL(gr_pid_is_chrooted);
59560 +
59561 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
59562 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
59563 +{
59564 + struct path path, currentroot;
59565 + int ret = 0;
59566 +
59567 + path.dentry = (struct dentry *)u_dentry;
59568 + path.mnt = (struct vfsmount *)u_mnt;
59569 + get_fs_root(current->fs, &currentroot);
59570 + if (path_is_under(&path, &currentroot))
59571 + ret = 1;
59572 + path_put(&currentroot);
59573 +
59574 + return ret;
59575 +}
59576 +#endif
59577 +
59578 +int
59579 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
59580 +{
59581 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59582 + if (!grsec_enable_chroot_fchdir)
59583 + return 1;
59584 +
59585 + if (!proc_is_chrooted(current))
59586 + return 1;
59587 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
59588 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
59589 + return 0;
59590 + }
59591 +#endif
59592 + return 1;
59593 +}
59594 +
59595 +int
59596 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59597 + const time_t shm_createtime)
59598 +{
59599 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59600 + struct task_struct *p;
59601 + time_t starttime;
59602 +
59603 + if (unlikely(!grsec_enable_chroot_shmat))
59604 + return 1;
59605 +
59606 + if (likely(!proc_is_chrooted(current)))
59607 + return 1;
59608 +
59609 + rcu_read_lock();
59610 + read_lock(&tasklist_lock);
59611 +
59612 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
59613 + starttime = p->start_time.tv_sec;
59614 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
59615 + if (have_same_root(current, p)) {
59616 + goto allow;
59617 + } else {
59618 + read_unlock(&tasklist_lock);
59619 + rcu_read_unlock();
59620 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59621 + return 0;
59622 + }
59623 + }
59624 + /* creator exited, pid reuse, fall through to next check */
59625 + }
59626 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
59627 + if (unlikely(!have_same_root(current, p))) {
59628 + read_unlock(&tasklist_lock);
59629 + rcu_read_unlock();
59630 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59631 + return 0;
59632 + }
59633 + }
59634 +
59635 +allow:
59636 + read_unlock(&tasklist_lock);
59637 + rcu_read_unlock();
59638 +#endif
59639 + return 1;
59640 +}
59641 +
59642 +void
59643 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
59644 +{
59645 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59646 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
59647 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
59648 +#endif
59649 + return;
59650 +}
59651 +
59652 +int
59653 +gr_handle_chroot_mknod(const struct dentry *dentry,
59654 + const struct vfsmount *mnt, const int mode)
59655 +{
59656 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59657 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
59658 + proc_is_chrooted(current)) {
59659 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
59660 + return -EPERM;
59661 + }
59662 +#endif
59663 + return 0;
59664 +}
59665 +
59666 +int
59667 +gr_handle_chroot_mount(const struct dentry *dentry,
59668 + const struct vfsmount *mnt, const char *dev_name)
59669 +{
59670 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59671 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
59672 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
59673 + return -EPERM;
59674 + }
59675 +#endif
59676 + return 0;
59677 +}
59678 +
59679 +int
59680 +gr_handle_chroot_pivot(void)
59681 +{
59682 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59683 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
59684 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
59685 + return -EPERM;
59686 + }
59687 +#endif
59688 + return 0;
59689 +}
59690 +
59691 +int
59692 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
59693 +{
59694 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59695 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
59696 + !gr_is_outside_chroot(dentry, mnt)) {
59697 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
59698 + return -EPERM;
59699 + }
59700 +#endif
59701 + return 0;
59702 +}
59703 +
59704 +extern const char *captab_log[];
59705 +extern int captab_log_entries;
59706 +
59707 +int
59708 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
59709 +{
59710 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59711 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59712 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59713 + if (cap_raised(chroot_caps, cap)) {
59714 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
59715 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
59716 + }
59717 + return 0;
59718 + }
59719 + }
59720 +#endif
59721 + return 1;
59722 +}
59723 +
59724 +int
59725 +gr_chroot_is_capable(const int cap)
59726 +{
59727 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59728 + return gr_task_chroot_is_capable(current, current_cred(), cap);
59729 +#endif
59730 + return 1;
59731 +}
59732 +
59733 +int
59734 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
59735 +{
59736 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59737 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59738 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59739 + if (cap_raised(chroot_caps, cap)) {
59740 + return 0;
59741 + }
59742 + }
59743 +#endif
59744 + return 1;
59745 +}
59746 +
59747 +int
59748 +gr_chroot_is_capable_nolog(const int cap)
59749 +{
59750 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59751 + return gr_task_chroot_is_capable_nolog(current, cap);
59752 +#endif
59753 + return 1;
59754 +}
59755 +
59756 +int
59757 +gr_handle_chroot_sysctl(const int op)
59758 +{
59759 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59760 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
59761 + proc_is_chrooted(current))
59762 + return -EACCES;
59763 +#endif
59764 + return 0;
59765 +}
59766 +
59767 +void
59768 +gr_handle_chroot_chdir(struct path *path)
59769 +{
59770 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59771 + if (grsec_enable_chroot_chdir)
59772 + set_fs_pwd(current->fs, path);
59773 +#endif
59774 + return;
59775 +}
59776 +
59777 +int
59778 +gr_handle_chroot_chmod(const struct dentry *dentry,
59779 + const struct vfsmount *mnt, const int mode)
59780 +{
59781 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59782 + /* allow chmod +s on directories, but not files */
59783 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
59784 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
59785 + proc_is_chrooted(current)) {
59786 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
59787 + return -EPERM;
59788 + }
59789 +#endif
59790 + return 0;
59791 +}
59792 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
59793 new file mode 100644
59794 index 0000000..e6796b3
59795 --- /dev/null
59796 +++ b/grsecurity/grsec_disabled.c
59797 @@ -0,0 +1,434 @@
59798 +#include <linux/kernel.h>
59799 +#include <linux/module.h>
59800 +#include <linux/sched.h>
59801 +#include <linux/file.h>
59802 +#include <linux/fs.h>
59803 +#include <linux/kdev_t.h>
59804 +#include <linux/net.h>
59805 +#include <linux/in.h>
59806 +#include <linux/ip.h>
59807 +#include <linux/skbuff.h>
59808 +#include <linux/sysctl.h>
59809 +
59810 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59811 +void
59812 +pax_set_initial_flags(struct linux_binprm *bprm)
59813 +{
59814 + return;
59815 +}
59816 +#endif
59817 +
59818 +#ifdef CONFIG_SYSCTL
59819 +__u32
59820 +gr_handle_sysctl(const struct ctl_table * table, const int op)
59821 +{
59822 + return 0;
59823 +}
59824 +#endif
59825 +
59826 +#ifdef CONFIG_TASKSTATS
59827 +int gr_is_taskstats_denied(int pid)
59828 +{
59829 + return 0;
59830 +}
59831 +#endif
59832 +
59833 +int
59834 +gr_acl_is_enabled(void)
59835 +{
59836 + return 0;
59837 +}
59838 +
59839 +void
59840 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
59841 +{
59842 + return;
59843 +}
59844 +
59845 +int
59846 +gr_handle_rawio(const struct inode *inode)
59847 +{
59848 + return 0;
59849 +}
59850 +
59851 +void
59852 +gr_acl_handle_psacct(struct task_struct *task, const long code)
59853 +{
59854 + return;
59855 +}
59856 +
59857 +int
59858 +gr_handle_ptrace(struct task_struct *task, const long request)
59859 +{
59860 + return 0;
59861 +}
59862 +
59863 +int
59864 +gr_handle_proc_ptrace(struct task_struct *task)
59865 +{
59866 + return 0;
59867 +}
59868 +
59869 +int
59870 +gr_set_acls(const int type)
59871 +{
59872 + return 0;
59873 +}
59874 +
59875 +int
59876 +gr_check_hidden_task(const struct task_struct *tsk)
59877 +{
59878 + return 0;
59879 +}
59880 +
59881 +int
59882 +gr_check_protected_task(const struct task_struct *task)
59883 +{
59884 + return 0;
59885 +}
59886 +
59887 +int
59888 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59889 +{
59890 + return 0;
59891 +}
59892 +
59893 +void
59894 +gr_copy_label(struct task_struct *tsk)
59895 +{
59896 + return;
59897 +}
59898 +
59899 +void
59900 +gr_set_pax_flags(struct task_struct *task)
59901 +{
59902 + return;
59903 +}
59904 +
59905 +int
59906 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59907 + const int unsafe_share)
59908 +{
59909 + return 0;
59910 +}
59911 +
59912 +void
59913 +gr_handle_delete(const ino_t ino, const dev_t dev)
59914 +{
59915 + return;
59916 +}
59917 +
59918 +void
59919 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
59920 +{
59921 + return;
59922 +}
59923 +
59924 +void
59925 +gr_handle_crash(struct task_struct *task, const int sig)
59926 +{
59927 + return;
59928 +}
59929 +
59930 +int
59931 +gr_check_crash_exec(const struct file *filp)
59932 +{
59933 + return 0;
59934 +}
59935 +
59936 +int
59937 +gr_check_crash_uid(const uid_t uid)
59938 +{
59939 + return 0;
59940 +}
59941 +
59942 +void
59943 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59944 + struct dentry *old_dentry,
59945 + struct dentry *new_dentry,
59946 + struct vfsmount *mnt, const __u8 replace)
59947 +{
59948 + return;
59949 +}
59950 +
59951 +int
59952 +gr_search_socket(const int family, const int type, const int protocol)
59953 +{
59954 + return 1;
59955 +}
59956 +
59957 +int
59958 +gr_search_connectbind(const int mode, const struct socket *sock,
59959 + const struct sockaddr_in *addr)
59960 +{
59961 + return 0;
59962 +}
59963 +
59964 +void
59965 +gr_handle_alertkill(struct task_struct *task)
59966 +{
59967 + return;
59968 +}
59969 +
59970 +__u32
59971 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
59972 +{
59973 + return 1;
59974 +}
59975 +
59976 +__u32
59977 +gr_acl_handle_hidden_file(const struct dentry * dentry,
59978 + const struct vfsmount * mnt)
59979 +{
59980 + return 1;
59981 +}
59982 +
59983 +__u32
59984 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
59985 + int acc_mode)
59986 +{
59987 + return 1;
59988 +}
59989 +
59990 +__u32
59991 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
59992 +{
59993 + return 1;
59994 +}
59995 +
59996 +__u32
59997 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
59998 +{
59999 + return 1;
60000 +}
60001 +
60002 +int
60003 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
60004 + unsigned int *vm_flags)
60005 +{
60006 + return 1;
60007 +}
60008 +
60009 +__u32
60010 +gr_acl_handle_truncate(const struct dentry * dentry,
60011 + const struct vfsmount * mnt)
60012 +{
60013 + return 1;
60014 +}
60015 +
60016 +__u32
60017 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
60018 +{
60019 + return 1;
60020 +}
60021 +
60022 +__u32
60023 +gr_acl_handle_access(const struct dentry * dentry,
60024 + const struct vfsmount * mnt, const int fmode)
60025 +{
60026 + return 1;
60027 +}
60028 +
60029 +__u32
60030 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
60031 + umode_t *mode)
60032 +{
60033 + return 1;
60034 +}
60035 +
60036 +__u32
60037 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
60038 +{
60039 + return 1;
60040 +}
60041 +
60042 +__u32
60043 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
60044 +{
60045 + return 1;
60046 +}
60047 +
60048 +void
60049 +grsecurity_init(void)
60050 +{
60051 + return;
60052 +}
60053 +
60054 +umode_t gr_acl_umask(void)
60055 +{
60056 + return 0;
60057 +}
60058 +
60059 +__u32
60060 +gr_acl_handle_mknod(const struct dentry * new_dentry,
60061 + const struct dentry * parent_dentry,
60062 + const struct vfsmount * parent_mnt,
60063 + const int mode)
60064 +{
60065 + return 1;
60066 +}
60067 +
60068 +__u32
60069 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
60070 + const struct dentry * parent_dentry,
60071 + const struct vfsmount * parent_mnt)
60072 +{
60073 + return 1;
60074 +}
60075 +
60076 +__u32
60077 +gr_acl_handle_symlink(const struct dentry * new_dentry,
60078 + const struct dentry * parent_dentry,
60079 + const struct vfsmount * parent_mnt, const struct filename *from)
60080 +{
60081 + return 1;
60082 +}
60083 +
60084 +__u32
60085 +gr_acl_handle_link(const struct dentry * new_dentry,
60086 + const struct dentry * parent_dentry,
60087 + const struct vfsmount * parent_mnt,
60088 + const struct dentry * old_dentry,
60089 + const struct vfsmount * old_mnt, const struct filename *to)
60090 +{
60091 + return 1;
60092 +}
60093 +
60094 +int
60095 +gr_acl_handle_rename(const struct dentry *new_dentry,
60096 + const struct dentry *parent_dentry,
60097 + const struct vfsmount *parent_mnt,
60098 + const struct dentry *old_dentry,
60099 + const struct inode *old_parent_inode,
60100 + const struct vfsmount *old_mnt, const struct filename *newname)
60101 +{
60102 + return 0;
60103 +}
60104 +
60105 +int
60106 +gr_acl_handle_filldir(const struct file *file, const char *name,
60107 + const int namelen, const ino_t ino)
60108 +{
60109 + return 1;
60110 +}
60111 +
60112 +int
60113 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60114 + const time_t shm_createtime, const uid_t cuid, const int shmid)
60115 +{
60116 + return 1;
60117 +}
60118 +
60119 +int
60120 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
60121 +{
60122 + return 0;
60123 +}
60124 +
60125 +int
60126 +gr_search_accept(const struct socket *sock)
60127 +{
60128 + return 0;
60129 +}
60130 +
60131 +int
60132 +gr_search_listen(const struct socket *sock)
60133 +{
60134 + return 0;
60135 +}
60136 +
60137 +int
60138 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
60139 +{
60140 + return 0;
60141 +}
60142 +
60143 +__u32
60144 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
60145 +{
60146 + return 1;
60147 +}
60148 +
60149 +__u32
60150 +gr_acl_handle_creat(const struct dentry * dentry,
60151 + const struct dentry * p_dentry,
60152 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
60153 + const int imode)
60154 +{
60155 + return 1;
60156 +}
60157 +
60158 +void
60159 +gr_acl_handle_exit(void)
60160 +{
60161 + return;
60162 +}
60163 +
60164 +int
60165 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
60166 +{
60167 + return 1;
60168 +}
60169 +
60170 +void
60171 +gr_set_role_label(const uid_t uid, const gid_t gid)
60172 +{
60173 + return;
60174 +}
60175 +
60176 +int
60177 +gr_acl_handle_procpidmem(const struct task_struct *task)
60178 +{
60179 + return 0;
60180 +}
60181 +
60182 +int
60183 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
60184 +{
60185 + return 0;
60186 +}
60187 +
60188 +int
60189 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
60190 +{
60191 + return 0;
60192 +}
60193 +
60194 +void
60195 +gr_set_kernel_label(struct task_struct *task)
60196 +{
60197 + return;
60198 +}
60199 +
60200 +int
60201 +gr_check_user_change(int real, int effective, int fs)
60202 +{
60203 + return 0;
60204 +}
60205 +
60206 +int
60207 +gr_check_group_change(int real, int effective, int fs)
60208 +{
60209 + return 0;
60210 +}
60211 +
60212 +int gr_acl_enable_at_secure(void)
60213 +{
60214 + return 0;
60215 +}
60216 +
60217 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
60218 +{
60219 + return dentry->d_inode->i_sb->s_dev;
60220 +}
60221 +
60222 +void gr_put_exec_file(struct task_struct *task)
60223 +{
60224 + return;
60225 +}
60226 +
60227 +EXPORT_SYMBOL(gr_set_kernel_label);
60228 +#ifdef CONFIG_SECURITY
60229 +EXPORT_SYMBOL(gr_check_user_change);
60230 +EXPORT_SYMBOL(gr_check_group_change);
60231 +#endif
60232 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
60233 new file mode 100644
60234 index 0000000..abfa971
60235 --- /dev/null
60236 +++ b/grsecurity/grsec_exec.c
60237 @@ -0,0 +1,174 @@
60238 +#include <linux/kernel.h>
60239 +#include <linux/sched.h>
60240 +#include <linux/file.h>
60241 +#include <linux/binfmts.h>
60242 +#include <linux/fs.h>
60243 +#include <linux/types.h>
60244 +#include <linux/grdefs.h>
60245 +#include <linux/grsecurity.h>
60246 +#include <linux/grinternal.h>
60247 +#include <linux/capability.h>
60248 +#include <linux/module.h>
60249 +
60250 +#include <asm/uaccess.h>
60251 +
60252 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60253 +static char gr_exec_arg_buf[132];
60254 +static DEFINE_MUTEX(gr_exec_arg_mutex);
60255 +#endif
60256 +
60257 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
60258 +
60259 +void
60260 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
60261 +{
60262 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60263 + char *grarg = gr_exec_arg_buf;
60264 + unsigned int i, x, execlen = 0;
60265 + char c;
60266 +
60267 + if (!((grsec_enable_execlog && grsec_enable_group &&
60268 + in_group_p(grsec_audit_gid))
60269 + || (grsec_enable_execlog && !grsec_enable_group)))
60270 + return;
60271 +
60272 + mutex_lock(&gr_exec_arg_mutex);
60273 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
60274 +
60275 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
60276 + const char __user *p;
60277 + unsigned int len;
60278 +
60279 + p = get_user_arg_ptr(argv, i);
60280 + if (IS_ERR(p))
60281 + goto log;
60282 +
60283 + len = strnlen_user(p, 128 - execlen);
60284 + if (len > 128 - execlen)
60285 + len = 128 - execlen;
60286 + else if (len > 0)
60287 + len--;
60288 + if (copy_from_user(grarg + execlen, p, len))
60289 + goto log;
60290 +
60291 + /* rewrite unprintable characters */
60292 + for (x = 0; x < len; x++) {
60293 + c = *(grarg + execlen + x);
60294 + if (c < 32 || c > 126)
60295 + *(grarg + execlen + x) = ' ';
60296 + }
60297 +
60298 + execlen += len;
60299 + *(grarg + execlen) = ' ';
60300 + *(grarg + execlen + 1) = '\0';
60301 + execlen++;
60302 + }
60303 +
60304 + log:
60305 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
60306 + bprm->file->f_path.mnt, grarg);
60307 + mutex_unlock(&gr_exec_arg_mutex);
60308 +#endif
60309 + return;
60310 +}
60311 +
60312 +#ifdef CONFIG_GRKERNSEC
60313 +extern int gr_acl_is_capable(const int cap);
60314 +extern int gr_acl_is_capable_nolog(const int cap);
60315 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60316 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
60317 +extern int gr_chroot_is_capable(const int cap);
60318 +extern int gr_chroot_is_capable_nolog(const int cap);
60319 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
60320 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
60321 +#endif
60322 +
60323 +const char *captab_log[] = {
60324 + "CAP_CHOWN",
60325 + "CAP_DAC_OVERRIDE",
60326 + "CAP_DAC_READ_SEARCH",
60327 + "CAP_FOWNER",
60328 + "CAP_FSETID",
60329 + "CAP_KILL",
60330 + "CAP_SETGID",
60331 + "CAP_SETUID",
60332 + "CAP_SETPCAP",
60333 + "CAP_LINUX_IMMUTABLE",
60334 + "CAP_NET_BIND_SERVICE",
60335 + "CAP_NET_BROADCAST",
60336 + "CAP_NET_ADMIN",
60337 + "CAP_NET_RAW",
60338 + "CAP_IPC_LOCK",
60339 + "CAP_IPC_OWNER",
60340 + "CAP_SYS_MODULE",
60341 + "CAP_SYS_RAWIO",
60342 + "CAP_SYS_CHROOT",
60343 + "CAP_SYS_PTRACE",
60344 + "CAP_SYS_PACCT",
60345 + "CAP_SYS_ADMIN",
60346 + "CAP_SYS_BOOT",
60347 + "CAP_SYS_NICE",
60348 + "CAP_SYS_RESOURCE",
60349 + "CAP_SYS_TIME",
60350 + "CAP_SYS_TTY_CONFIG",
60351 + "CAP_MKNOD",
60352 + "CAP_LEASE",
60353 + "CAP_AUDIT_WRITE",
60354 + "CAP_AUDIT_CONTROL",
60355 + "CAP_SETFCAP",
60356 + "CAP_MAC_OVERRIDE",
60357 + "CAP_MAC_ADMIN",
60358 + "CAP_SYSLOG",
60359 + "CAP_WAKE_ALARM"
60360 +};
60361 +
60362 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
60363 +
60364 +int gr_is_capable(const int cap)
60365 +{
60366 +#ifdef CONFIG_GRKERNSEC
60367 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
60368 + return 1;
60369 + return 0;
60370 +#else
60371 + return 1;
60372 +#endif
60373 +}
60374 +
60375 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60376 +{
60377 +#ifdef CONFIG_GRKERNSEC
60378 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
60379 + return 1;
60380 + return 0;
60381 +#else
60382 + return 1;
60383 +#endif
60384 +}
60385 +
60386 +int gr_is_capable_nolog(const int cap)
60387 +{
60388 +#ifdef CONFIG_GRKERNSEC
60389 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
60390 + return 1;
60391 + return 0;
60392 +#else
60393 + return 1;
60394 +#endif
60395 +}
60396 +
60397 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
60398 +{
60399 +#ifdef CONFIG_GRKERNSEC
60400 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
60401 + return 1;
60402 + return 0;
60403 +#else
60404 + return 1;
60405 +#endif
60406 +}
60407 +
60408 +EXPORT_SYMBOL(gr_is_capable);
60409 +EXPORT_SYMBOL(gr_is_capable_nolog);
60410 +EXPORT_SYMBOL(gr_task_is_capable);
60411 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
60412 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
60413 new file mode 100644
60414 index 0000000..d3ee748
60415 --- /dev/null
60416 +++ b/grsecurity/grsec_fifo.c
60417 @@ -0,0 +1,24 @@
60418 +#include <linux/kernel.h>
60419 +#include <linux/sched.h>
60420 +#include <linux/fs.h>
60421 +#include <linux/file.h>
60422 +#include <linux/grinternal.h>
60423 +
60424 +int
60425 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
60426 + const struct dentry *dir, const int flag, const int acc_mode)
60427 +{
60428 +#ifdef CONFIG_GRKERNSEC_FIFO
60429 + const struct cred *cred = current_cred();
60430 +
60431 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
60432 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
60433 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
60434 + (cred->fsuid != dentry->d_inode->i_uid)) {
60435 + if (!inode_permission(dentry->d_inode, acc_mode))
60436 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
60437 + return -EACCES;
60438 + }
60439 +#endif
60440 + return 0;
60441 +}
60442 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
60443 new file mode 100644
60444 index 0000000..8ca18bf
60445 --- /dev/null
60446 +++ b/grsecurity/grsec_fork.c
60447 @@ -0,0 +1,23 @@
60448 +#include <linux/kernel.h>
60449 +#include <linux/sched.h>
60450 +#include <linux/grsecurity.h>
60451 +#include <linux/grinternal.h>
60452 +#include <linux/errno.h>
60453 +
60454 +void
60455 +gr_log_forkfail(const int retval)
60456 +{
60457 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60458 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
60459 + switch (retval) {
60460 + case -EAGAIN:
60461 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
60462 + break;
60463 + case -ENOMEM:
60464 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
60465 + break;
60466 + }
60467 + }
60468 +#endif
60469 + return;
60470 +}
60471 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
60472 new file mode 100644
60473 index 0000000..05a6015
60474 --- /dev/null
60475 +++ b/grsecurity/grsec_init.c
60476 @@ -0,0 +1,283 @@
60477 +#include <linux/kernel.h>
60478 +#include <linux/sched.h>
60479 +#include <linux/mm.h>
60480 +#include <linux/gracl.h>
60481 +#include <linux/slab.h>
60482 +#include <linux/vmalloc.h>
60483 +#include <linux/percpu.h>
60484 +#include <linux/module.h>
60485 +
60486 +int grsec_enable_ptrace_readexec;
60487 +int grsec_enable_setxid;
60488 +int grsec_enable_symlinkown;
60489 +int grsec_symlinkown_gid;
60490 +int grsec_enable_brute;
60491 +int grsec_enable_link;
60492 +int grsec_enable_dmesg;
60493 +int grsec_enable_harden_ptrace;
60494 +int grsec_enable_fifo;
60495 +int grsec_enable_execlog;
60496 +int grsec_enable_signal;
60497 +int grsec_enable_forkfail;
60498 +int grsec_enable_audit_ptrace;
60499 +int grsec_enable_time;
60500 +int grsec_enable_audit_textrel;
60501 +int grsec_enable_group;
60502 +int grsec_audit_gid;
60503 +int grsec_enable_chdir;
60504 +int grsec_enable_mount;
60505 +int grsec_enable_rofs;
60506 +int grsec_enable_chroot_findtask;
60507 +int grsec_enable_chroot_mount;
60508 +int grsec_enable_chroot_shmat;
60509 +int grsec_enable_chroot_fchdir;
60510 +int grsec_enable_chroot_double;
60511 +int grsec_enable_chroot_pivot;
60512 +int grsec_enable_chroot_chdir;
60513 +int grsec_enable_chroot_chmod;
60514 +int grsec_enable_chroot_mknod;
60515 +int grsec_enable_chroot_nice;
60516 +int grsec_enable_chroot_execlog;
60517 +int grsec_enable_chroot_caps;
60518 +int grsec_enable_chroot_sysctl;
60519 +int grsec_enable_chroot_unix;
60520 +int grsec_enable_tpe;
60521 +int grsec_tpe_gid;
60522 +int grsec_enable_blackhole;
60523 +#ifdef CONFIG_IPV6_MODULE
60524 +EXPORT_SYMBOL(grsec_enable_blackhole);
60525 +#endif
60526 +int grsec_lastack_retries;
60527 +int grsec_enable_tpe_all;
60528 +int grsec_enable_tpe_invert;
60529 +int grsec_enable_socket_all;
60530 +int grsec_socket_all_gid;
60531 +int grsec_enable_socket_client;
60532 +int grsec_socket_client_gid;
60533 +int grsec_enable_socket_server;
60534 +int grsec_socket_server_gid;
60535 +int grsec_resource_logging;
60536 +int grsec_disable_privio;
60537 +int grsec_enable_log_rwxmaps;
60538 +int grsec_lock;
60539 +
60540 +DEFINE_SPINLOCK(grsec_alert_lock);
60541 +unsigned long grsec_alert_wtime = 0;
60542 +unsigned long grsec_alert_fyet = 0;
60543 +
60544 +DEFINE_SPINLOCK(grsec_audit_lock);
60545 +
60546 +DEFINE_RWLOCK(grsec_exec_file_lock);
60547 +
60548 +char *gr_shared_page[4];
60549 +
60550 +char *gr_alert_log_fmt;
60551 +char *gr_audit_log_fmt;
60552 +char *gr_alert_log_buf;
60553 +char *gr_audit_log_buf;
60554 +
60555 +extern struct gr_arg *gr_usermode;
60556 +extern unsigned char *gr_system_salt;
60557 +extern unsigned char *gr_system_sum;
60558 +
60559 +void __init
60560 +grsecurity_init(void)
60561 +{
60562 + int j;
60563 + /* create the per-cpu shared pages */
60564 +
60565 +#ifdef CONFIG_X86
60566 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
60567 +#endif
60568 +
60569 + for (j = 0; j < 4; j++) {
60570 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
60571 + if (gr_shared_page[j] == NULL) {
60572 + panic("Unable to allocate grsecurity shared page");
60573 + return;
60574 + }
60575 + }
60576 +
60577 + /* allocate log buffers */
60578 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
60579 + if (!gr_alert_log_fmt) {
60580 + panic("Unable to allocate grsecurity alert log format buffer");
60581 + return;
60582 + }
60583 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
60584 + if (!gr_audit_log_fmt) {
60585 + panic("Unable to allocate grsecurity audit log format buffer");
60586 + return;
60587 + }
60588 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60589 + if (!gr_alert_log_buf) {
60590 + panic("Unable to allocate grsecurity alert log buffer");
60591 + return;
60592 + }
60593 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60594 + if (!gr_audit_log_buf) {
60595 + panic("Unable to allocate grsecurity audit log buffer");
60596 + return;
60597 + }
60598 +
60599 + /* allocate memory for authentication structure */
60600 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
60601 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
60602 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
60603 +
60604 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
60605 + panic("Unable to allocate grsecurity authentication structure");
60606 + return;
60607 + }
60608 +
60609 +
60610 +#ifdef CONFIG_GRKERNSEC_IO
60611 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
60612 + grsec_disable_privio = 1;
60613 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60614 + grsec_disable_privio = 1;
60615 +#else
60616 + grsec_disable_privio = 0;
60617 +#endif
60618 +#endif
60619 +
60620 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60621 + /* for backward compatibility, tpe_invert always defaults to on if
60622 + enabled in the kernel
60623 + */
60624 + grsec_enable_tpe_invert = 1;
60625 +#endif
60626 +
60627 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60628 +#ifndef CONFIG_GRKERNSEC_SYSCTL
60629 + grsec_lock = 1;
60630 +#endif
60631 +
60632 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60633 + grsec_enable_audit_textrel = 1;
60634 +#endif
60635 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60636 + grsec_enable_log_rwxmaps = 1;
60637 +#endif
60638 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60639 + grsec_enable_group = 1;
60640 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
60641 +#endif
60642 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60643 + grsec_enable_ptrace_readexec = 1;
60644 +#endif
60645 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60646 + grsec_enable_chdir = 1;
60647 +#endif
60648 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60649 + grsec_enable_harden_ptrace = 1;
60650 +#endif
60651 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60652 + grsec_enable_mount = 1;
60653 +#endif
60654 +#ifdef CONFIG_GRKERNSEC_LINK
60655 + grsec_enable_link = 1;
60656 +#endif
60657 +#ifdef CONFIG_GRKERNSEC_BRUTE
60658 + grsec_enable_brute = 1;
60659 +#endif
60660 +#ifdef CONFIG_GRKERNSEC_DMESG
60661 + grsec_enable_dmesg = 1;
60662 +#endif
60663 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60664 + grsec_enable_blackhole = 1;
60665 + grsec_lastack_retries = 4;
60666 +#endif
60667 +#ifdef CONFIG_GRKERNSEC_FIFO
60668 + grsec_enable_fifo = 1;
60669 +#endif
60670 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60671 + grsec_enable_execlog = 1;
60672 +#endif
60673 +#ifdef CONFIG_GRKERNSEC_SETXID
60674 + grsec_enable_setxid = 1;
60675 +#endif
60676 +#ifdef CONFIG_GRKERNSEC_SIGNAL
60677 + grsec_enable_signal = 1;
60678 +#endif
60679 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60680 + grsec_enable_forkfail = 1;
60681 +#endif
60682 +#ifdef CONFIG_GRKERNSEC_TIME
60683 + grsec_enable_time = 1;
60684 +#endif
60685 +#ifdef CONFIG_GRKERNSEC_RESLOG
60686 + grsec_resource_logging = 1;
60687 +#endif
60688 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60689 + grsec_enable_chroot_findtask = 1;
60690 +#endif
60691 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60692 + grsec_enable_chroot_unix = 1;
60693 +#endif
60694 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60695 + grsec_enable_chroot_mount = 1;
60696 +#endif
60697 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60698 + grsec_enable_chroot_fchdir = 1;
60699 +#endif
60700 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60701 + grsec_enable_chroot_shmat = 1;
60702 +#endif
60703 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60704 + grsec_enable_audit_ptrace = 1;
60705 +#endif
60706 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60707 + grsec_enable_chroot_double = 1;
60708 +#endif
60709 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60710 + grsec_enable_chroot_pivot = 1;
60711 +#endif
60712 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60713 + grsec_enable_chroot_chdir = 1;
60714 +#endif
60715 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60716 + grsec_enable_chroot_chmod = 1;
60717 +#endif
60718 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60719 + grsec_enable_chroot_mknod = 1;
60720 +#endif
60721 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60722 + grsec_enable_chroot_nice = 1;
60723 +#endif
60724 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60725 + grsec_enable_chroot_execlog = 1;
60726 +#endif
60727 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60728 + grsec_enable_chroot_caps = 1;
60729 +#endif
60730 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60731 + grsec_enable_chroot_sysctl = 1;
60732 +#endif
60733 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60734 + grsec_enable_symlinkown = 1;
60735 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
60736 +#endif
60737 +#ifdef CONFIG_GRKERNSEC_TPE
60738 + grsec_enable_tpe = 1;
60739 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
60740 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60741 + grsec_enable_tpe_all = 1;
60742 +#endif
60743 +#endif
60744 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60745 + grsec_enable_socket_all = 1;
60746 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
60747 +#endif
60748 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60749 + grsec_enable_socket_client = 1;
60750 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
60751 +#endif
60752 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60753 + grsec_enable_socket_server = 1;
60754 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
60755 +#endif
60756 +#endif
60757 +
60758 + return;
60759 +}
60760 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
60761 new file mode 100644
60762 index 0000000..6095407
60763 --- /dev/null
60764 +++ b/grsecurity/grsec_link.c
60765 @@ -0,0 +1,58 @@
60766 +#include <linux/kernel.h>
60767 +#include <linux/sched.h>
60768 +#include <linux/fs.h>
60769 +#include <linux/file.h>
60770 +#include <linux/grinternal.h>
60771 +
60772 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
60773 +{
60774 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60775 + const struct inode *link_inode = link->dentry->d_inode;
60776 +
60777 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
60778 + /* ignore root-owned links, e.g. /proc/self */
60779 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
60780 + !uid_eq(link_inode->i_uid, target->i_uid)) {
60781 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
60782 + return 1;
60783 + }
60784 +#endif
60785 + return 0;
60786 +}
60787 +
60788 +int
60789 +gr_handle_follow_link(const struct inode *parent,
60790 + const struct inode *inode,
60791 + const struct dentry *dentry, const struct vfsmount *mnt)
60792 +{
60793 +#ifdef CONFIG_GRKERNSEC_LINK
60794 + const struct cred *cred = current_cred();
60795 +
60796 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
60797 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
60798 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
60799 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
60800 + return -EACCES;
60801 + }
60802 +#endif
60803 + return 0;
60804 +}
60805 +
60806 +int
60807 +gr_handle_hardlink(const struct dentry *dentry,
60808 + const struct vfsmount *mnt,
60809 + struct inode *inode, const int mode, const struct filename *to)
60810 +{
60811 +#ifdef CONFIG_GRKERNSEC_LINK
60812 + const struct cred *cred = current_cred();
60813 +
60814 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
60815 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
60816 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
60817 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
60818 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
60819 + return -EPERM;
60820 + }
60821 +#endif
60822 + return 0;
60823 +}
60824 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
60825 new file mode 100644
60826 index 0000000..7bd6c2b
60827 --- /dev/null
60828 +++ b/grsecurity/grsec_log.c
60829 @@ -0,0 +1,329 @@
60830 +#include <linux/kernel.h>
60831 +#include <linux/sched.h>
60832 +#include <linux/file.h>
60833 +#include <linux/tty.h>
60834 +#include <linux/fs.h>
60835 +#include <linux/grinternal.h>
60836 +
60837 +#ifdef CONFIG_TREE_PREEMPT_RCU
60838 +#define DISABLE_PREEMPT() preempt_disable()
60839 +#define ENABLE_PREEMPT() preempt_enable()
60840 +#else
60841 +#define DISABLE_PREEMPT()
60842 +#define ENABLE_PREEMPT()
60843 +#endif
60844 +
60845 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
60846 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
60847 +
60848 +#define BEGIN_LOCKS(x) \
60849 + DISABLE_PREEMPT(); \
60850 + rcu_read_lock(); \
60851 + read_lock(&tasklist_lock); \
60852 + read_lock(&grsec_exec_file_lock); \
60853 + if (x != GR_DO_AUDIT) \
60854 + spin_lock(&grsec_alert_lock); \
60855 + else \
60856 + spin_lock(&grsec_audit_lock)
60857 +
60858 +#define END_LOCKS(x) \
60859 + if (x != GR_DO_AUDIT) \
60860 + spin_unlock(&grsec_alert_lock); \
60861 + else \
60862 + spin_unlock(&grsec_audit_lock); \
60863 + read_unlock(&grsec_exec_file_lock); \
60864 + read_unlock(&tasklist_lock); \
60865 + rcu_read_unlock(); \
60866 + ENABLE_PREEMPT(); \
60867 + if (x == GR_DONT_AUDIT) \
60868 + gr_handle_alertkill(current)
60869 +
60870 +enum {
60871 + FLOODING,
60872 + NO_FLOODING
60873 +};
60874 +
60875 +extern char *gr_alert_log_fmt;
60876 +extern char *gr_audit_log_fmt;
60877 +extern char *gr_alert_log_buf;
60878 +extern char *gr_audit_log_buf;
60879 +
60880 +static int gr_log_start(int audit)
60881 +{
60882 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
60883 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
60884 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60885 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
60886 + unsigned long curr_secs = get_seconds();
60887 +
60888 + if (audit == GR_DO_AUDIT)
60889 + goto set_fmt;
60890 +
60891 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
60892 + grsec_alert_wtime = curr_secs;
60893 + grsec_alert_fyet = 0;
60894 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
60895 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
60896 + grsec_alert_fyet++;
60897 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
60898 + grsec_alert_wtime = curr_secs;
60899 + grsec_alert_fyet++;
60900 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
60901 + return FLOODING;
60902 + }
60903 + else return FLOODING;
60904 +
60905 +set_fmt:
60906 +#endif
60907 + memset(buf, 0, PAGE_SIZE);
60908 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
60909 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
60910 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60911 + } else if (current->signal->curr_ip) {
60912 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
60913 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
60914 + } else if (gr_acl_is_enabled()) {
60915 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
60916 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60917 + } else {
60918 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
60919 + strcpy(buf, fmt);
60920 + }
60921 +
60922 + return NO_FLOODING;
60923 +}
60924 +
60925 +static void gr_log_middle(int audit, const char *msg, va_list ap)
60926 + __attribute__ ((format (printf, 2, 0)));
60927 +
60928 +static void gr_log_middle(int audit, const char *msg, va_list ap)
60929 +{
60930 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60931 + unsigned int len = strlen(buf);
60932 +
60933 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60934 +
60935 + return;
60936 +}
60937 +
60938 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
60939 + __attribute__ ((format (printf, 2, 3)));
60940 +
60941 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
60942 +{
60943 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60944 + unsigned int len = strlen(buf);
60945 + va_list ap;
60946 +
60947 + va_start(ap, msg);
60948 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60949 + va_end(ap);
60950 +
60951 + return;
60952 +}
60953 +
60954 +static void gr_log_end(int audit, int append_default)
60955 +{
60956 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60957 + if (append_default) {
60958 + struct task_struct *task = current;
60959 + struct task_struct *parent = task->real_parent;
60960 + const struct cred *cred = __task_cred(task);
60961 + const struct cred *pcred = __task_cred(parent);
60962 + unsigned int len = strlen(buf);
60963 +
60964 + 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));
60965 + }
60966 +
60967 + printk("%s\n", buf);
60968 +
60969 + return;
60970 +}
60971 +
60972 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
60973 +{
60974 + int logtype;
60975 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
60976 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
60977 + void *voidptr = NULL;
60978 + int num1 = 0, num2 = 0;
60979 + unsigned long ulong1 = 0, ulong2 = 0;
60980 + struct dentry *dentry = NULL;
60981 + struct vfsmount *mnt = NULL;
60982 + struct file *file = NULL;
60983 + struct task_struct *task = NULL;
60984 + const struct cred *cred, *pcred;
60985 + va_list ap;
60986 +
60987 + BEGIN_LOCKS(audit);
60988 + logtype = gr_log_start(audit);
60989 + if (logtype == FLOODING) {
60990 + END_LOCKS(audit);
60991 + return;
60992 + }
60993 + va_start(ap, argtypes);
60994 + switch (argtypes) {
60995 + case GR_TTYSNIFF:
60996 + task = va_arg(ap, struct task_struct *);
60997 + 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));
60998 + break;
60999 + case GR_SYSCTL_HIDDEN:
61000 + str1 = va_arg(ap, char *);
61001 + gr_log_middle_varargs(audit, msg, result, str1);
61002 + break;
61003 + case GR_RBAC:
61004 + dentry = va_arg(ap, struct dentry *);
61005 + mnt = va_arg(ap, struct vfsmount *);
61006 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
61007 + break;
61008 + case GR_RBAC_STR:
61009 + dentry = va_arg(ap, struct dentry *);
61010 + mnt = va_arg(ap, struct vfsmount *);
61011 + str1 = va_arg(ap, char *);
61012 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
61013 + break;
61014 + case GR_STR_RBAC:
61015 + str1 = va_arg(ap, char *);
61016 + dentry = va_arg(ap, struct dentry *);
61017 + mnt = va_arg(ap, struct vfsmount *);
61018 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
61019 + break;
61020 + case GR_RBAC_MODE2:
61021 + dentry = va_arg(ap, struct dentry *);
61022 + mnt = va_arg(ap, struct vfsmount *);
61023 + str1 = va_arg(ap, char *);
61024 + str2 = va_arg(ap, char *);
61025 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
61026 + break;
61027 + case GR_RBAC_MODE3:
61028 + dentry = va_arg(ap, struct dentry *);
61029 + mnt = va_arg(ap, struct vfsmount *);
61030 + str1 = va_arg(ap, char *);
61031 + str2 = va_arg(ap, char *);
61032 + str3 = va_arg(ap, char *);
61033 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
61034 + break;
61035 + case GR_FILENAME:
61036 + dentry = va_arg(ap, struct dentry *);
61037 + mnt = va_arg(ap, struct vfsmount *);
61038 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
61039 + break;
61040 + case GR_STR_FILENAME:
61041 + str1 = va_arg(ap, char *);
61042 + dentry = va_arg(ap, struct dentry *);
61043 + mnt = va_arg(ap, struct vfsmount *);
61044 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
61045 + break;
61046 + case GR_FILENAME_STR:
61047 + dentry = va_arg(ap, struct dentry *);
61048 + mnt = va_arg(ap, struct vfsmount *);
61049 + str1 = va_arg(ap, char *);
61050 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
61051 + break;
61052 + case GR_FILENAME_TWO_INT:
61053 + dentry = va_arg(ap, struct dentry *);
61054 + mnt = va_arg(ap, struct vfsmount *);
61055 + num1 = va_arg(ap, int);
61056 + num2 = va_arg(ap, int);
61057 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
61058 + break;
61059 + case GR_FILENAME_TWO_INT_STR:
61060 + dentry = va_arg(ap, struct dentry *);
61061 + mnt = va_arg(ap, struct vfsmount *);
61062 + num1 = va_arg(ap, int);
61063 + num2 = va_arg(ap, int);
61064 + str1 = va_arg(ap, char *);
61065 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
61066 + break;
61067 + case GR_TEXTREL:
61068 + file = va_arg(ap, struct file *);
61069 + ulong1 = va_arg(ap, unsigned long);
61070 + ulong2 = va_arg(ap, unsigned long);
61071 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
61072 + break;
61073 + case GR_PTRACE:
61074 + task = va_arg(ap, struct task_struct *);
61075 + 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));
61076 + break;
61077 + case GR_RESOURCE:
61078 + task = va_arg(ap, struct task_struct *);
61079 + cred = __task_cred(task);
61080 + pcred = __task_cred(task->real_parent);
61081 + ulong1 = va_arg(ap, unsigned long);
61082 + str1 = va_arg(ap, char *);
61083 + ulong2 = va_arg(ap, unsigned long);
61084 + 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));
61085 + break;
61086 + case GR_CAP:
61087 + task = va_arg(ap, struct task_struct *);
61088 + cred = __task_cred(task);
61089 + pcred = __task_cred(task->real_parent);
61090 + str1 = va_arg(ap, char *);
61091 + 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));
61092 + break;
61093 + case GR_SIG:
61094 + str1 = va_arg(ap, char *);
61095 + voidptr = va_arg(ap, void *);
61096 + gr_log_middle_varargs(audit, msg, str1, voidptr);
61097 + break;
61098 + case GR_SIG2:
61099 + task = va_arg(ap, struct task_struct *);
61100 + cred = __task_cred(task);
61101 + pcred = __task_cred(task->real_parent);
61102 + num1 = va_arg(ap, int);
61103 + 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));
61104 + break;
61105 + case GR_CRASH1:
61106 + task = va_arg(ap, struct task_struct *);
61107 + cred = __task_cred(task);
61108 + pcred = __task_cred(task->real_parent);
61109 + ulong1 = va_arg(ap, unsigned long);
61110 + 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);
61111 + break;
61112 + case GR_CRASH2:
61113 + task = va_arg(ap, struct task_struct *);
61114 + cred = __task_cred(task);
61115 + pcred = __task_cred(task->real_parent);
61116 + ulong1 = va_arg(ap, unsigned long);
61117 + 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);
61118 + break;
61119 + case GR_RWXMAP:
61120 + file = va_arg(ap, struct file *);
61121 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
61122 + break;
61123 + case GR_PSACCT:
61124 + {
61125 + unsigned int wday, cday;
61126 + __u8 whr, chr;
61127 + __u8 wmin, cmin;
61128 + __u8 wsec, csec;
61129 + char cur_tty[64] = { 0 };
61130 + char parent_tty[64] = { 0 };
61131 +
61132 + task = va_arg(ap, struct task_struct *);
61133 + wday = va_arg(ap, unsigned int);
61134 + cday = va_arg(ap, unsigned int);
61135 + whr = va_arg(ap, int);
61136 + chr = va_arg(ap, int);
61137 + wmin = va_arg(ap, int);
61138 + cmin = va_arg(ap, int);
61139 + wsec = va_arg(ap, int);
61140 + csec = va_arg(ap, int);
61141 + ulong1 = va_arg(ap, unsigned long);
61142 + cred = __task_cred(task);
61143 + pcred = __task_cred(task->real_parent);
61144 +
61145 + 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));
61146 + }
61147 + break;
61148 + default:
61149 + gr_log_middle(audit, msg, ap);
61150 + }
61151 + va_end(ap);
61152 + // these don't need DEFAULTSECARGS printed on the end
61153 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
61154 + gr_log_end(audit, 0);
61155 + else
61156 + gr_log_end(audit, 1);
61157 + END_LOCKS(audit);
61158 +}
61159 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
61160 new file mode 100644
61161 index 0000000..f536303
61162 --- /dev/null
61163 +++ b/grsecurity/grsec_mem.c
61164 @@ -0,0 +1,40 @@
61165 +#include <linux/kernel.h>
61166 +#include <linux/sched.h>
61167 +#include <linux/mm.h>
61168 +#include <linux/mman.h>
61169 +#include <linux/grinternal.h>
61170 +
61171 +void
61172 +gr_handle_ioperm(void)
61173 +{
61174 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
61175 + return;
61176 +}
61177 +
61178 +void
61179 +gr_handle_iopl(void)
61180 +{
61181 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
61182 + return;
61183 +}
61184 +
61185 +void
61186 +gr_handle_mem_readwrite(u64 from, u64 to)
61187 +{
61188 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
61189 + return;
61190 +}
61191 +
61192 +void
61193 +gr_handle_vm86(void)
61194 +{
61195 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
61196 + return;
61197 +}
61198 +
61199 +void
61200 +gr_log_badprocpid(const char *entry)
61201 +{
61202 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
61203 + return;
61204 +}
61205 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
61206 new file mode 100644
61207 index 0000000..2131422
61208 --- /dev/null
61209 +++ b/grsecurity/grsec_mount.c
61210 @@ -0,0 +1,62 @@
61211 +#include <linux/kernel.h>
61212 +#include <linux/sched.h>
61213 +#include <linux/mount.h>
61214 +#include <linux/grsecurity.h>
61215 +#include <linux/grinternal.h>
61216 +
61217 +void
61218 +gr_log_remount(const char *devname, const int retval)
61219 +{
61220 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61221 + if (grsec_enable_mount && (retval >= 0))
61222 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
61223 +#endif
61224 + return;
61225 +}
61226 +
61227 +void
61228 +gr_log_unmount(const char *devname, const int retval)
61229 +{
61230 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61231 + if (grsec_enable_mount && (retval >= 0))
61232 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
61233 +#endif
61234 + return;
61235 +}
61236 +
61237 +void
61238 +gr_log_mount(const char *from, const char *to, const int retval)
61239 +{
61240 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61241 + if (grsec_enable_mount && (retval >= 0))
61242 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
61243 +#endif
61244 + return;
61245 +}
61246 +
61247 +int
61248 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
61249 +{
61250 +#ifdef CONFIG_GRKERNSEC_ROFS
61251 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
61252 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
61253 + return -EPERM;
61254 + } else
61255 + return 0;
61256 +#endif
61257 + return 0;
61258 +}
61259 +
61260 +int
61261 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
61262 +{
61263 +#ifdef CONFIG_GRKERNSEC_ROFS
61264 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
61265 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
61266 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
61267 + return -EPERM;
61268 + } else
61269 + return 0;
61270 +#endif
61271 + return 0;
61272 +}
61273 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
61274 new file mode 100644
61275 index 0000000..a3b12a0
61276 --- /dev/null
61277 +++ b/grsecurity/grsec_pax.c
61278 @@ -0,0 +1,36 @@
61279 +#include <linux/kernel.h>
61280 +#include <linux/sched.h>
61281 +#include <linux/mm.h>
61282 +#include <linux/file.h>
61283 +#include <linux/grinternal.h>
61284 +#include <linux/grsecurity.h>
61285 +
61286 +void
61287 +gr_log_textrel(struct vm_area_struct * vma)
61288 +{
61289 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61290 + if (grsec_enable_audit_textrel)
61291 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
61292 +#endif
61293 + return;
61294 +}
61295 +
61296 +void
61297 +gr_log_rwxmmap(struct file *file)
61298 +{
61299 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61300 + if (grsec_enable_log_rwxmaps)
61301 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
61302 +#endif
61303 + return;
61304 +}
61305 +
61306 +void
61307 +gr_log_rwxmprotect(struct file *file)
61308 +{
61309 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61310 + if (grsec_enable_log_rwxmaps)
61311 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
61312 +#endif
61313 + return;
61314 +}
61315 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
61316 new file mode 100644
61317 index 0000000..f7f29aa
61318 --- /dev/null
61319 +++ b/grsecurity/grsec_ptrace.c
61320 @@ -0,0 +1,30 @@
61321 +#include <linux/kernel.h>
61322 +#include <linux/sched.h>
61323 +#include <linux/grinternal.h>
61324 +#include <linux/security.h>
61325 +
61326 +void
61327 +gr_audit_ptrace(struct task_struct *task)
61328 +{
61329 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61330 + if (grsec_enable_audit_ptrace)
61331 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
61332 +#endif
61333 + return;
61334 +}
61335 +
61336 +int
61337 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
61338 +{
61339 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61340 + const struct dentry *dentry = file->f_path.dentry;
61341 + const struct vfsmount *mnt = file->f_path.mnt;
61342 +
61343 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
61344 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
61345 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
61346 + return -EACCES;
61347 + }
61348 +#endif
61349 + return 0;
61350 +}
61351 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
61352 new file mode 100644
61353 index 0000000..5c00416
61354 --- /dev/null
61355 +++ b/grsecurity/grsec_sig.c
61356 @@ -0,0 +1,222 @@
61357 +#include <linux/kernel.h>
61358 +#include <linux/sched.h>
61359 +#include <linux/delay.h>
61360 +#include <linux/grsecurity.h>
61361 +#include <linux/grinternal.h>
61362 +#include <linux/hardirq.h>
61363 +
61364 +char *signames[] = {
61365 + [SIGSEGV] = "Segmentation fault",
61366 + [SIGILL] = "Illegal instruction",
61367 + [SIGABRT] = "Abort",
61368 + [SIGBUS] = "Invalid alignment/Bus error"
61369 +};
61370 +
61371 +void
61372 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
61373 +{
61374 +#ifdef CONFIG_GRKERNSEC_SIGNAL
61375 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
61376 + (sig == SIGABRT) || (sig == SIGBUS))) {
61377 + if (t->pid == current->pid) {
61378 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
61379 + } else {
61380 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
61381 + }
61382 + }
61383 +#endif
61384 + return;
61385 +}
61386 +
61387 +int
61388 +gr_handle_signal(const struct task_struct *p, const int sig)
61389 +{
61390 +#ifdef CONFIG_GRKERNSEC
61391 + /* ignore the 0 signal for protected task checks */
61392 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
61393 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
61394 + return -EPERM;
61395 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
61396 + return -EPERM;
61397 + }
61398 +#endif
61399 + return 0;
61400 +}
61401 +
61402 +#ifdef CONFIG_GRKERNSEC
61403 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
61404 +
61405 +int gr_fake_force_sig(int sig, struct task_struct *t)
61406 +{
61407 + unsigned long int flags;
61408 + int ret, blocked, ignored;
61409 + struct k_sigaction *action;
61410 +
61411 + spin_lock_irqsave(&t->sighand->siglock, flags);
61412 + action = &t->sighand->action[sig-1];
61413 + ignored = action->sa.sa_handler == SIG_IGN;
61414 + blocked = sigismember(&t->blocked, sig);
61415 + if (blocked || ignored) {
61416 + action->sa.sa_handler = SIG_DFL;
61417 + if (blocked) {
61418 + sigdelset(&t->blocked, sig);
61419 + recalc_sigpending_and_wake(t);
61420 + }
61421 + }
61422 + if (action->sa.sa_handler == SIG_DFL)
61423 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
61424 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
61425 +
61426 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
61427 +
61428 + return ret;
61429 +}
61430 +#endif
61431 +
61432 +#ifdef CONFIG_GRKERNSEC_BRUTE
61433 +#define GR_USER_BAN_TIME (15 * 60)
61434 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
61435 +
61436 +static int __get_dumpable(unsigned long mm_flags)
61437 +{
61438 + int ret;
61439 +
61440 + ret = mm_flags & MMF_DUMPABLE_MASK;
61441 + return (ret >= 2) ? 2 : ret;
61442 +}
61443 +#endif
61444 +
61445 +void gr_handle_brute_attach(unsigned long mm_flags)
61446 +{
61447 +#ifdef CONFIG_GRKERNSEC_BRUTE
61448 + struct task_struct *p = current;
61449 + kuid_t uid = GLOBAL_ROOT_UID;
61450 + int daemon = 0;
61451 +
61452 + if (!grsec_enable_brute)
61453 + return;
61454 +
61455 + rcu_read_lock();
61456 + read_lock(&tasklist_lock);
61457 + read_lock(&grsec_exec_file_lock);
61458 + if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
61459 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
61460 + p->real_parent->brute = 1;
61461 + daemon = 1;
61462 + } else {
61463 + const struct cred *cred = __task_cred(p), *cred2;
61464 + struct task_struct *tsk, *tsk2;
61465 +
61466 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
61467 + struct user_struct *user;
61468 +
61469 + uid = cred->uid;
61470 +
61471 + /* this is put upon execution past expiration */
61472 + user = find_user(uid);
61473 + if (user == NULL)
61474 + goto unlock;
61475 + user->banned = 1;
61476 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
61477 + if (user->ban_expires == ~0UL)
61478 + user->ban_expires--;
61479 +
61480 + do_each_thread(tsk2, tsk) {
61481 + cred2 = __task_cred(tsk);
61482 + if (tsk != p && uid_eq(cred2->uid, uid))
61483 + gr_fake_force_sig(SIGKILL, tsk);
61484 + } while_each_thread(tsk2, tsk);
61485 + }
61486 + }
61487 +unlock:
61488 + read_unlock(&grsec_exec_file_lock);
61489 + read_unlock(&tasklist_lock);
61490 + rcu_read_unlock();
61491 +
61492 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
61493 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
61494 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
61495 + else if (daemon)
61496 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
61497 +
61498 +#endif
61499 + return;
61500 +}
61501 +
61502 +void gr_handle_brute_check(void)
61503 +{
61504 +#ifdef CONFIG_GRKERNSEC_BRUTE
61505 + struct task_struct *p = current;
61506 +
61507 + if (unlikely(p->brute)) {
61508 + if (!grsec_enable_brute)
61509 + p->brute = 0;
61510 + else if (time_before(get_seconds(), p->brute_expires))
61511 + msleep(30 * 1000);
61512 + }
61513 +#endif
61514 + return;
61515 +}
61516 +
61517 +void gr_handle_kernel_exploit(void)
61518 +{
61519 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
61520 + const struct cred *cred;
61521 + struct task_struct *tsk, *tsk2;
61522 + struct user_struct *user;
61523 + kuid_t uid;
61524 +
61525 + if (in_irq() || in_serving_softirq() || in_nmi())
61526 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
61527 +
61528 + uid = current_uid();
61529 +
61530 + if (uid_eq(uid, GLOBAL_ROOT_UID))
61531 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
61532 + else {
61533 + /* kill all the processes of this user, hold a reference
61534 + to their creds struct, and prevent them from creating
61535 + another process until system reset
61536 + */
61537 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
61538 + from_kuid_munged(&init_user_ns, uid));
61539 + /* we intentionally leak this ref */
61540 + user = get_uid(current->cred->user);
61541 + if (user) {
61542 + user->banned = 1;
61543 + user->ban_expires = ~0UL;
61544 + }
61545 +
61546 + read_lock(&tasklist_lock);
61547 + do_each_thread(tsk2, tsk) {
61548 + cred = __task_cred(tsk);
61549 + if (uid_eq(cred->uid, uid))
61550 + gr_fake_force_sig(SIGKILL, tsk);
61551 + } while_each_thread(tsk2, tsk);
61552 + read_unlock(&tasklist_lock);
61553 + }
61554 +#endif
61555 +}
61556 +
61557 +int __gr_process_user_ban(struct user_struct *user)
61558 +{
61559 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61560 + if (unlikely(user->banned)) {
61561 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
61562 + user->banned = 0;
61563 + user->ban_expires = 0;
61564 + free_uid(user);
61565 + } else
61566 + return -EPERM;
61567 + }
61568 +#endif
61569 + return 0;
61570 +}
61571 +
61572 +int gr_process_user_ban(void)
61573 +{
61574 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61575 + return __gr_process_user_ban(current->cred->user);
61576 +#endif
61577 + return 0;
61578 +}
61579 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
61580 new file mode 100644
61581 index 0000000..4030d57
61582 --- /dev/null
61583 +++ b/grsecurity/grsec_sock.c
61584 @@ -0,0 +1,244 @@
61585 +#include <linux/kernel.h>
61586 +#include <linux/module.h>
61587 +#include <linux/sched.h>
61588 +#include <linux/file.h>
61589 +#include <linux/net.h>
61590 +#include <linux/in.h>
61591 +#include <linux/ip.h>
61592 +#include <net/sock.h>
61593 +#include <net/inet_sock.h>
61594 +#include <linux/grsecurity.h>
61595 +#include <linux/grinternal.h>
61596 +#include <linux/gracl.h>
61597 +
61598 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
61599 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
61600 +
61601 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
61602 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
61603 +
61604 +#ifdef CONFIG_UNIX_MODULE
61605 +EXPORT_SYMBOL(gr_acl_handle_unix);
61606 +EXPORT_SYMBOL(gr_acl_handle_mknod);
61607 +EXPORT_SYMBOL(gr_handle_chroot_unix);
61608 +EXPORT_SYMBOL(gr_handle_create);
61609 +#endif
61610 +
61611 +#ifdef CONFIG_GRKERNSEC
61612 +#define gr_conn_table_size 32749
61613 +struct conn_table_entry {
61614 + struct conn_table_entry *next;
61615 + struct signal_struct *sig;
61616 +};
61617 +
61618 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
61619 +DEFINE_SPINLOCK(gr_conn_table_lock);
61620 +
61621 +extern const char * gr_socktype_to_name(unsigned char type);
61622 +extern const char * gr_proto_to_name(unsigned char proto);
61623 +extern const char * gr_sockfamily_to_name(unsigned char family);
61624 +
61625 +static __inline__ int
61626 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
61627 +{
61628 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
61629 +}
61630 +
61631 +static __inline__ int
61632 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
61633 + __u16 sport, __u16 dport)
61634 +{
61635 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
61636 + sig->gr_sport == sport && sig->gr_dport == dport))
61637 + return 1;
61638 + else
61639 + return 0;
61640 +}
61641 +
61642 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
61643 +{
61644 + struct conn_table_entry **match;
61645 + unsigned int index;
61646 +
61647 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61648 + sig->gr_sport, sig->gr_dport,
61649 + gr_conn_table_size);
61650 +
61651 + newent->sig = sig;
61652 +
61653 + match = &gr_conn_table[index];
61654 + newent->next = *match;
61655 + *match = newent;
61656 +
61657 + return;
61658 +}
61659 +
61660 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
61661 +{
61662 + struct conn_table_entry *match, *last = NULL;
61663 + unsigned int index;
61664 +
61665 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61666 + sig->gr_sport, sig->gr_dport,
61667 + gr_conn_table_size);
61668 +
61669 + match = gr_conn_table[index];
61670 + while (match && !conn_match(match->sig,
61671 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
61672 + sig->gr_dport)) {
61673 + last = match;
61674 + match = match->next;
61675 + }
61676 +
61677 + if (match) {
61678 + if (last)
61679 + last->next = match->next;
61680 + else
61681 + gr_conn_table[index] = NULL;
61682 + kfree(match);
61683 + }
61684 +
61685 + return;
61686 +}
61687 +
61688 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
61689 + __u16 sport, __u16 dport)
61690 +{
61691 + struct conn_table_entry *match;
61692 + unsigned int index;
61693 +
61694 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
61695 +
61696 + match = gr_conn_table[index];
61697 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
61698 + match = match->next;
61699 +
61700 + if (match)
61701 + return match->sig;
61702 + else
61703 + return NULL;
61704 +}
61705 +
61706 +#endif
61707 +
61708 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
61709 +{
61710 +#ifdef CONFIG_GRKERNSEC
61711 + struct signal_struct *sig = task->signal;
61712 + struct conn_table_entry *newent;
61713 +
61714 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
61715 + if (newent == NULL)
61716 + return;
61717 + /* no bh lock needed since we are called with bh disabled */
61718 + spin_lock(&gr_conn_table_lock);
61719 + gr_del_task_from_ip_table_nolock(sig);
61720 + sig->gr_saddr = inet->inet_rcv_saddr;
61721 + sig->gr_daddr = inet->inet_daddr;
61722 + sig->gr_sport = inet->inet_sport;
61723 + sig->gr_dport = inet->inet_dport;
61724 + gr_add_to_task_ip_table_nolock(sig, newent);
61725 + spin_unlock(&gr_conn_table_lock);
61726 +#endif
61727 + return;
61728 +}
61729 +
61730 +void gr_del_task_from_ip_table(struct task_struct *task)
61731 +{
61732 +#ifdef CONFIG_GRKERNSEC
61733 + spin_lock_bh(&gr_conn_table_lock);
61734 + gr_del_task_from_ip_table_nolock(task->signal);
61735 + spin_unlock_bh(&gr_conn_table_lock);
61736 +#endif
61737 + return;
61738 +}
61739 +
61740 +void
61741 +gr_attach_curr_ip(const struct sock *sk)
61742 +{
61743 +#ifdef CONFIG_GRKERNSEC
61744 + struct signal_struct *p, *set;
61745 + const struct inet_sock *inet = inet_sk(sk);
61746 +
61747 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
61748 + return;
61749 +
61750 + set = current->signal;
61751 +
61752 + spin_lock_bh(&gr_conn_table_lock);
61753 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
61754 + inet->inet_dport, inet->inet_sport);
61755 + if (unlikely(p != NULL)) {
61756 + set->curr_ip = p->curr_ip;
61757 + set->used_accept = 1;
61758 + gr_del_task_from_ip_table_nolock(p);
61759 + spin_unlock_bh(&gr_conn_table_lock);
61760 + return;
61761 + }
61762 + spin_unlock_bh(&gr_conn_table_lock);
61763 +
61764 + set->curr_ip = inet->inet_daddr;
61765 + set->used_accept = 1;
61766 +#endif
61767 + return;
61768 +}
61769 +
61770 +int
61771 +gr_handle_sock_all(const int family, const int type, const int protocol)
61772 +{
61773 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61774 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
61775 + (family != AF_UNIX)) {
61776 + if (family == AF_INET)
61777 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
61778 + else
61779 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
61780 + return -EACCES;
61781 + }
61782 +#endif
61783 + return 0;
61784 +}
61785 +
61786 +int
61787 +gr_handle_sock_server(const struct sockaddr *sck)
61788 +{
61789 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61790 + if (grsec_enable_socket_server &&
61791 + in_group_p(grsec_socket_server_gid) &&
61792 + sck && (sck->sa_family != AF_UNIX) &&
61793 + (sck->sa_family != AF_LOCAL)) {
61794 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61795 + return -EACCES;
61796 + }
61797 +#endif
61798 + return 0;
61799 +}
61800 +
61801 +int
61802 +gr_handle_sock_server_other(const struct sock *sck)
61803 +{
61804 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61805 + if (grsec_enable_socket_server &&
61806 + in_group_p(grsec_socket_server_gid) &&
61807 + sck && (sck->sk_family != AF_UNIX) &&
61808 + (sck->sk_family != AF_LOCAL)) {
61809 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61810 + return -EACCES;
61811 + }
61812 +#endif
61813 + return 0;
61814 +}
61815 +
61816 +int
61817 +gr_handle_sock_client(const struct sockaddr *sck)
61818 +{
61819 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61820 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
61821 + sck && (sck->sa_family != AF_UNIX) &&
61822 + (sck->sa_family != AF_LOCAL)) {
61823 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
61824 + return -EACCES;
61825 + }
61826 +#endif
61827 + return 0;
61828 +}
61829 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
61830 new file mode 100644
61831 index 0000000..f55ef0f
61832 --- /dev/null
61833 +++ b/grsecurity/grsec_sysctl.c
61834 @@ -0,0 +1,469 @@
61835 +#include <linux/kernel.h>
61836 +#include <linux/sched.h>
61837 +#include <linux/sysctl.h>
61838 +#include <linux/grsecurity.h>
61839 +#include <linux/grinternal.h>
61840 +
61841 +int
61842 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
61843 +{
61844 +#ifdef CONFIG_GRKERNSEC_SYSCTL
61845 + if (dirname == NULL || name == NULL)
61846 + return 0;
61847 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
61848 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
61849 + return -EACCES;
61850 + }
61851 +#endif
61852 + return 0;
61853 +}
61854 +
61855 +#ifdef CONFIG_GRKERNSEC_ROFS
61856 +static int __maybe_unused one = 1;
61857 +#endif
61858 +
61859 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
61860 +struct ctl_table grsecurity_table[] = {
61861 +#ifdef CONFIG_GRKERNSEC_SYSCTL
61862 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
61863 +#ifdef CONFIG_GRKERNSEC_IO
61864 + {
61865 + .procname = "disable_priv_io",
61866 + .data = &grsec_disable_privio,
61867 + .maxlen = sizeof(int),
61868 + .mode = 0600,
61869 + .proc_handler = &proc_dointvec,
61870 + },
61871 +#endif
61872 +#endif
61873 +#ifdef CONFIG_GRKERNSEC_LINK
61874 + {
61875 + .procname = "linking_restrictions",
61876 + .data = &grsec_enable_link,
61877 + .maxlen = sizeof(int),
61878 + .mode = 0600,
61879 + .proc_handler = &proc_dointvec,
61880 + },
61881 +#endif
61882 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61883 + {
61884 + .procname = "enforce_symlinksifowner",
61885 + .data = &grsec_enable_symlinkown,
61886 + .maxlen = sizeof(int),
61887 + .mode = 0600,
61888 + .proc_handler = &proc_dointvec,
61889 + },
61890 + {
61891 + .procname = "symlinkown_gid",
61892 + .data = &grsec_symlinkown_gid,
61893 + .maxlen = sizeof(int),
61894 + .mode = 0600,
61895 + .proc_handler = &proc_dointvec,
61896 + },
61897 +#endif
61898 +#ifdef CONFIG_GRKERNSEC_BRUTE
61899 + {
61900 + .procname = "deter_bruteforce",
61901 + .data = &grsec_enable_brute,
61902 + .maxlen = sizeof(int),
61903 + .mode = 0600,
61904 + .proc_handler = &proc_dointvec,
61905 + },
61906 +#endif
61907 +#ifdef CONFIG_GRKERNSEC_FIFO
61908 + {
61909 + .procname = "fifo_restrictions",
61910 + .data = &grsec_enable_fifo,
61911 + .maxlen = sizeof(int),
61912 + .mode = 0600,
61913 + .proc_handler = &proc_dointvec,
61914 + },
61915 +#endif
61916 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61917 + {
61918 + .procname = "ptrace_readexec",
61919 + .data = &grsec_enable_ptrace_readexec,
61920 + .maxlen = sizeof(int),
61921 + .mode = 0600,
61922 + .proc_handler = &proc_dointvec,
61923 + },
61924 +#endif
61925 +#ifdef CONFIG_GRKERNSEC_SETXID
61926 + {
61927 + .procname = "consistent_setxid",
61928 + .data = &grsec_enable_setxid,
61929 + .maxlen = sizeof(int),
61930 + .mode = 0600,
61931 + .proc_handler = &proc_dointvec,
61932 + },
61933 +#endif
61934 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
61935 + {
61936 + .procname = "ip_blackhole",
61937 + .data = &grsec_enable_blackhole,
61938 + .maxlen = sizeof(int),
61939 + .mode = 0600,
61940 + .proc_handler = &proc_dointvec,
61941 + },
61942 + {
61943 + .procname = "lastack_retries",
61944 + .data = &grsec_lastack_retries,
61945 + .maxlen = sizeof(int),
61946 + .mode = 0600,
61947 + .proc_handler = &proc_dointvec,
61948 + },
61949 +#endif
61950 +#ifdef CONFIG_GRKERNSEC_EXECLOG
61951 + {
61952 + .procname = "exec_logging",
61953 + .data = &grsec_enable_execlog,
61954 + .maxlen = sizeof(int),
61955 + .mode = 0600,
61956 + .proc_handler = &proc_dointvec,
61957 + },
61958 +#endif
61959 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61960 + {
61961 + .procname = "rwxmap_logging",
61962 + .data = &grsec_enable_log_rwxmaps,
61963 + .maxlen = sizeof(int),
61964 + .mode = 0600,
61965 + .proc_handler = &proc_dointvec,
61966 + },
61967 +#endif
61968 +#ifdef CONFIG_GRKERNSEC_SIGNAL
61969 + {
61970 + .procname = "signal_logging",
61971 + .data = &grsec_enable_signal,
61972 + .maxlen = sizeof(int),
61973 + .mode = 0600,
61974 + .proc_handler = &proc_dointvec,
61975 + },
61976 +#endif
61977 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
61978 + {
61979 + .procname = "forkfail_logging",
61980 + .data = &grsec_enable_forkfail,
61981 + .maxlen = sizeof(int),
61982 + .mode = 0600,
61983 + .proc_handler = &proc_dointvec,
61984 + },
61985 +#endif
61986 +#ifdef CONFIG_GRKERNSEC_TIME
61987 + {
61988 + .procname = "timechange_logging",
61989 + .data = &grsec_enable_time,
61990 + .maxlen = sizeof(int),
61991 + .mode = 0600,
61992 + .proc_handler = &proc_dointvec,
61993 + },
61994 +#endif
61995 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61996 + {
61997 + .procname = "chroot_deny_shmat",
61998 + .data = &grsec_enable_chroot_shmat,
61999 + .maxlen = sizeof(int),
62000 + .mode = 0600,
62001 + .proc_handler = &proc_dointvec,
62002 + },
62003 +#endif
62004 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62005 + {
62006 + .procname = "chroot_deny_unix",
62007 + .data = &grsec_enable_chroot_unix,
62008 + .maxlen = sizeof(int),
62009 + .mode = 0600,
62010 + .proc_handler = &proc_dointvec,
62011 + },
62012 +#endif
62013 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
62014 + {
62015 + .procname = "chroot_deny_mount",
62016 + .data = &grsec_enable_chroot_mount,
62017 + .maxlen = sizeof(int),
62018 + .mode = 0600,
62019 + .proc_handler = &proc_dointvec,
62020 + },
62021 +#endif
62022 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62023 + {
62024 + .procname = "chroot_deny_fchdir",
62025 + .data = &grsec_enable_chroot_fchdir,
62026 + .maxlen = sizeof(int),
62027 + .mode = 0600,
62028 + .proc_handler = &proc_dointvec,
62029 + },
62030 +#endif
62031 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62032 + {
62033 + .procname = "chroot_deny_chroot",
62034 + .data = &grsec_enable_chroot_double,
62035 + .maxlen = sizeof(int),
62036 + .mode = 0600,
62037 + .proc_handler = &proc_dointvec,
62038 + },
62039 +#endif
62040 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62041 + {
62042 + .procname = "chroot_deny_pivot",
62043 + .data = &grsec_enable_chroot_pivot,
62044 + .maxlen = sizeof(int),
62045 + .mode = 0600,
62046 + .proc_handler = &proc_dointvec,
62047 + },
62048 +#endif
62049 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62050 + {
62051 + .procname = "chroot_enforce_chdir",
62052 + .data = &grsec_enable_chroot_chdir,
62053 + .maxlen = sizeof(int),
62054 + .mode = 0600,
62055 + .proc_handler = &proc_dointvec,
62056 + },
62057 +#endif
62058 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62059 + {
62060 + .procname = "chroot_deny_chmod",
62061 + .data = &grsec_enable_chroot_chmod,
62062 + .maxlen = sizeof(int),
62063 + .mode = 0600,
62064 + .proc_handler = &proc_dointvec,
62065 + },
62066 +#endif
62067 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62068 + {
62069 + .procname = "chroot_deny_mknod",
62070 + .data = &grsec_enable_chroot_mknod,
62071 + .maxlen = sizeof(int),
62072 + .mode = 0600,
62073 + .proc_handler = &proc_dointvec,
62074 + },
62075 +#endif
62076 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62077 + {
62078 + .procname = "chroot_restrict_nice",
62079 + .data = &grsec_enable_chroot_nice,
62080 + .maxlen = sizeof(int),
62081 + .mode = 0600,
62082 + .proc_handler = &proc_dointvec,
62083 + },
62084 +#endif
62085 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62086 + {
62087 + .procname = "chroot_execlog",
62088 + .data = &grsec_enable_chroot_execlog,
62089 + .maxlen = sizeof(int),
62090 + .mode = 0600,
62091 + .proc_handler = &proc_dointvec,
62092 + },
62093 +#endif
62094 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62095 + {
62096 + .procname = "chroot_caps",
62097 + .data = &grsec_enable_chroot_caps,
62098 + .maxlen = sizeof(int),
62099 + .mode = 0600,
62100 + .proc_handler = &proc_dointvec,
62101 + },
62102 +#endif
62103 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62104 + {
62105 + .procname = "chroot_deny_sysctl",
62106 + .data = &grsec_enable_chroot_sysctl,
62107 + .maxlen = sizeof(int),
62108 + .mode = 0600,
62109 + .proc_handler = &proc_dointvec,
62110 + },
62111 +#endif
62112 +#ifdef CONFIG_GRKERNSEC_TPE
62113 + {
62114 + .procname = "tpe",
62115 + .data = &grsec_enable_tpe,
62116 + .maxlen = sizeof(int),
62117 + .mode = 0600,
62118 + .proc_handler = &proc_dointvec,
62119 + },
62120 + {
62121 + .procname = "tpe_gid",
62122 + .data = &grsec_tpe_gid,
62123 + .maxlen = sizeof(int),
62124 + .mode = 0600,
62125 + .proc_handler = &proc_dointvec,
62126 + },
62127 +#endif
62128 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62129 + {
62130 + .procname = "tpe_invert",
62131 + .data = &grsec_enable_tpe_invert,
62132 + .maxlen = sizeof(int),
62133 + .mode = 0600,
62134 + .proc_handler = &proc_dointvec,
62135 + },
62136 +#endif
62137 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
62138 + {
62139 + .procname = "tpe_restrict_all",
62140 + .data = &grsec_enable_tpe_all,
62141 + .maxlen = sizeof(int),
62142 + .mode = 0600,
62143 + .proc_handler = &proc_dointvec,
62144 + },
62145 +#endif
62146 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62147 + {
62148 + .procname = "socket_all",
62149 + .data = &grsec_enable_socket_all,
62150 + .maxlen = sizeof(int),
62151 + .mode = 0600,
62152 + .proc_handler = &proc_dointvec,
62153 + },
62154 + {
62155 + .procname = "socket_all_gid",
62156 + .data = &grsec_socket_all_gid,
62157 + .maxlen = sizeof(int),
62158 + .mode = 0600,
62159 + .proc_handler = &proc_dointvec,
62160 + },
62161 +#endif
62162 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62163 + {
62164 + .procname = "socket_client",
62165 + .data = &grsec_enable_socket_client,
62166 + .maxlen = sizeof(int),
62167 + .mode = 0600,
62168 + .proc_handler = &proc_dointvec,
62169 + },
62170 + {
62171 + .procname = "socket_client_gid",
62172 + .data = &grsec_socket_client_gid,
62173 + .maxlen = sizeof(int),
62174 + .mode = 0600,
62175 + .proc_handler = &proc_dointvec,
62176 + },
62177 +#endif
62178 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62179 + {
62180 + .procname = "socket_server",
62181 + .data = &grsec_enable_socket_server,
62182 + .maxlen = sizeof(int),
62183 + .mode = 0600,
62184 + .proc_handler = &proc_dointvec,
62185 + },
62186 + {
62187 + .procname = "socket_server_gid",
62188 + .data = &grsec_socket_server_gid,
62189 + .maxlen = sizeof(int),
62190 + .mode = 0600,
62191 + .proc_handler = &proc_dointvec,
62192 + },
62193 +#endif
62194 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
62195 + {
62196 + .procname = "audit_group",
62197 + .data = &grsec_enable_group,
62198 + .maxlen = sizeof(int),
62199 + .mode = 0600,
62200 + .proc_handler = &proc_dointvec,
62201 + },
62202 + {
62203 + .procname = "audit_gid",
62204 + .data = &grsec_audit_gid,
62205 + .maxlen = sizeof(int),
62206 + .mode = 0600,
62207 + .proc_handler = &proc_dointvec,
62208 + },
62209 +#endif
62210 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62211 + {
62212 + .procname = "audit_chdir",
62213 + .data = &grsec_enable_chdir,
62214 + .maxlen = sizeof(int),
62215 + .mode = 0600,
62216 + .proc_handler = &proc_dointvec,
62217 + },
62218 +#endif
62219 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62220 + {
62221 + .procname = "audit_mount",
62222 + .data = &grsec_enable_mount,
62223 + .maxlen = sizeof(int),
62224 + .mode = 0600,
62225 + .proc_handler = &proc_dointvec,
62226 + },
62227 +#endif
62228 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
62229 + {
62230 + .procname = "audit_textrel",
62231 + .data = &grsec_enable_audit_textrel,
62232 + .maxlen = sizeof(int),
62233 + .mode = 0600,
62234 + .proc_handler = &proc_dointvec,
62235 + },
62236 +#endif
62237 +#ifdef CONFIG_GRKERNSEC_DMESG
62238 + {
62239 + .procname = "dmesg",
62240 + .data = &grsec_enable_dmesg,
62241 + .maxlen = sizeof(int),
62242 + .mode = 0600,
62243 + .proc_handler = &proc_dointvec,
62244 + },
62245 +#endif
62246 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62247 + {
62248 + .procname = "chroot_findtask",
62249 + .data = &grsec_enable_chroot_findtask,
62250 + .maxlen = sizeof(int),
62251 + .mode = 0600,
62252 + .proc_handler = &proc_dointvec,
62253 + },
62254 +#endif
62255 +#ifdef CONFIG_GRKERNSEC_RESLOG
62256 + {
62257 + .procname = "resource_logging",
62258 + .data = &grsec_resource_logging,
62259 + .maxlen = sizeof(int),
62260 + .mode = 0600,
62261 + .proc_handler = &proc_dointvec,
62262 + },
62263 +#endif
62264 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62265 + {
62266 + .procname = "audit_ptrace",
62267 + .data = &grsec_enable_audit_ptrace,
62268 + .maxlen = sizeof(int),
62269 + .mode = 0600,
62270 + .proc_handler = &proc_dointvec,
62271 + },
62272 +#endif
62273 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62274 + {
62275 + .procname = "harden_ptrace",
62276 + .data = &grsec_enable_harden_ptrace,
62277 + .maxlen = sizeof(int),
62278 + .mode = 0600,
62279 + .proc_handler = &proc_dointvec,
62280 + },
62281 +#endif
62282 + {
62283 + .procname = "grsec_lock",
62284 + .data = &grsec_lock,
62285 + .maxlen = sizeof(int),
62286 + .mode = 0600,
62287 + .proc_handler = &proc_dointvec,
62288 + },
62289 +#endif
62290 +#ifdef CONFIG_GRKERNSEC_ROFS
62291 + {
62292 + .procname = "romount_protect",
62293 + .data = &grsec_enable_rofs,
62294 + .maxlen = sizeof(int),
62295 + .mode = 0600,
62296 + .proc_handler = &proc_dointvec_minmax,
62297 + .extra1 = &one,
62298 + .extra2 = &one,
62299 + },
62300 +#endif
62301 + { }
62302 +};
62303 +#endif
62304 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
62305 new file mode 100644
62306 index 0000000..0dc13c3
62307 --- /dev/null
62308 +++ b/grsecurity/grsec_time.c
62309 @@ -0,0 +1,16 @@
62310 +#include <linux/kernel.h>
62311 +#include <linux/sched.h>
62312 +#include <linux/grinternal.h>
62313 +#include <linux/module.h>
62314 +
62315 +void
62316 +gr_log_timechange(void)
62317 +{
62318 +#ifdef CONFIG_GRKERNSEC_TIME
62319 + if (grsec_enable_time)
62320 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
62321 +#endif
62322 + return;
62323 +}
62324 +
62325 +EXPORT_SYMBOL(gr_log_timechange);
62326 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
62327 new file mode 100644
62328 index 0000000..07e0dc0
62329 --- /dev/null
62330 +++ b/grsecurity/grsec_tpe.c
62331 @@ -0,0 +1,73 @@
62332 +#include <linux/kernel.h>
62333 +#include <linux/sched.h>
62334 +#include <linux/file.h>
62335 +#include <linux/fs.h>
62336 +#include <linux/grinternal.h>
62337 +
62338 +extern int gr_acl_tpe_check(void);
62339 +
62340 +int
62341 +gr_tpe_allow(const struct file *file)
62342 +{
62343 +#ifdef CONFIG_GRKERNSEC
62344 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
62345 + const struct cred *cred = current_cred();
62346 + char *msg = NULL;
62347 + char *msg2 = NULL;
62348 +
62349 + // never restrict root
62350 + if (!cred->uid)
62351 + return 1;
62352 +
62353 + if (grsec_enable_tpe) {
62354 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62355 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
62356 + msg = "not being in trusted group";
62357 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
62358 + msg = "being in untrusted group";
62359 +#else
62360 + if (in_group_p(grsec_tpe_gid))
62361 + msg = "being in untrusted group";
62362 +#endif
62363 + }
62364 + if (!msg && gr_acl_tpe_check())
62365 + msg = "being in untrusted role";
62366 +
62367 + // not in any affected group/role
62368 + if (!msg)
62369 + goto next_check;
62370 +
62371 + if (inode->i_uid)
62372 + msg2 = "file in non-root-owned directory";
62373 + else if (inode->i_mode & S_IWOTH)
62374 + msg2 = "file in world-writable directory";
62375 + else if (inode->i_mode & S_IWGRP)
62376 + msg2 = "file in group-writable directory";
62377 +
62378 + if (msg && msg2) {
62379 + char fullmsg[70] = {0};
62380 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
62381 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
62382 + return 0;
62383 + }
62384 + msg = NULL;
62385 +next_check:
62386 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
62387 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
62388 + return 1;
62389 +
62390 + if (inode->i_uid && (inode->i_uid != cred->uid))
62391 + msg = "directory not owned by user";
62392 + else if (inode->i_mode & S_IWOTH)
62393 + msg = "file in world-writable directory";
62394 + else if (inode->i_mode & S_IWGRP)
62395 + msg = "file in group-writable directory";
62396 +
62397 + if (msg) {
62398 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
62399 + return 0;
62400 + }
62401 +#endif
62402 +#endif
62403 + return 1;
62404 +}
62405 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
62406 new file mode 100644
62407 index 0000000..9f7b1ac
62408 --- /dev/null
62409 +++ b/grsecurity/grsum.c
62410 @@ -0,0 +1,61 @@
62411 +#include <linux/err.h>
62412 +#include <linux/kernel.h>
62413 +#include <linux/sched.h>
62414 +#include <linux/mm.h>
62415 +#include <linux/scatterlist.h>
62416 +#include <linux/crypto.h>
62417 +#include <linux/gracl.h>
62418 +
62419 +
62420 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
62421 +#error "crypto and sha256 must be built into the kernel"
62422 +#endif
62423 +
62424 +int
62425 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
62426 +{
62427 + char *p;
62428 + struct crypto_hash *tfm;
62429 + struct hash_desc desc;
62430 + struct scatterlist sg;
62431 + unsigned char temp_sum[GR_SHA_LEN];
62432 + volatile int retval = 0;
62433 + volatile int dummy = 0;
62434 + unsigned int i;
62435 +
62436 + sg_init_table(&sg, 1);
62437 +
62438 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
62439 + if (IS_ERR(tfm)) {
62440 + /* should never happen, since sha256 should be built in */
62441 + return 1;
62442 + }
62443 +
62444 + desc.tfm = tfm;
62445 + desc.flags = 0;
62446 +
62447 + crypto_hash_init(&desc);
62448 +
62449 + p = salt;
62450 + sg_set_buf(&sg, p, GR_SALT_LEN);
62451 + crypto_hash_update(&desc, &sg, sg.length);
62452 +
62453 + p = entry->pw;
62454 + sg_set_buf(&sg, p, strlen(p));
62455 +
62456 + crypto_hash_update(&desc, &sg, sg.length);
62457 +
62458 + crypto_hash_final(&desc, temp_sum);
62459 +
62460 + memset(entry->pw, 0, GR_PW_LEN);
62461 +
62462 + for (i = 0; i < GR_SHA_LEN; i++)
62463 + if (sum[i] != temp_sum[i])
62464 + retval = 1;
62465 + else
62466 + dummy = 1; // waste a cycle
62467 +
62468 + crypto_free_hash(tfm);
62469 +
62470 + return retval;
62471 +}
62472 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
62473 index 77ff547..181834f 100644
62474 --- a/include/asm-generic/4level-fixup.h
62475 +++ b/include/asm-generic/4level-fixup.h
62476 @@ -13,8 +13,10 @@
62477 #define pmd_alloc(mm, pud, address) \
62478 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
62479 NULL: pmd_offset(pud, address))
62480 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
62481
62482 #define pud_alloc(mm, pgd, address) (pgd)
62483 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
62484 #define pud_offset(pgd, start) (pgd)
62485 #define pud_none(pud) 0
62486 #define pud_bad(pud) 0
62487 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
62488 index b7babf0..04ad282 100644
62489 --- a/include/asm-generic/atomic-long.h
62490 +++ b/include/asm-generic/atomic-long.h
62491 @@ -22,6 +22,12 @@
62492
62493 typedef atomic64_t atomic_long_t;
62494
62495 +#ifdef CONFIG_PAX_REFCOUNT
62496 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
62497 +#else
62498 +typedef atomic64_t atomic_long_unchecked_t;
62499 +#endif
62500 +
62501 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
62502
62503 static inline long atomic_long_read(atomic_long_t *l)
62504 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62505 return (long)atomic64_read(v);
62506 }
62507
62508 +#ifdef CONFIG_PAX_REFCOUNT
62509 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62510 +{
62511 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62512 +
62513 + return (long)atomic64_read_unchecked(v);
62514 +}
62515 +#endif
62516 +
62517 static inline void atomic_long_set(atomic_long_t *l, long i)
62518 {
62519 atomic64_t *v = (atomic64_t *)l;
62520 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62521 atomic64_set(v, i);
62522 }
62523
62524 +#ifdef CONFIG_PAX_REFCOUNT
62525 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62526 +{
62527 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62528 +
62529 + atomic64_set_unchecked(v, i);
62530 +}
62531 +#endif
62532 +
62533 static inline void atomic_long_inc(atomic_long_t *l)
62534 {
62535 atomic64_t *v = (atomic64_t *)l;
62536 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62537 atomic64_inc(v);
62538 }
62539
62540 +#ifdef CONFIG_PAX_REFCOUNT
62541 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62542 +{
62543 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62544 +
62545 + atomic64_inc_unchecked(v);
62546 +}
62547 +#endif
62548 +
62549 static inline void atomic_long_dec(atomic_long_t *l)
62550 {
62551 atomic64_t *v = (atomic64_t *)l;
62552 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62553 atomic64_dec(v);
62554 }
62555
62556 +#ifdef CONFIG_PAX_REFCOUNT
62557 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62558 +{
62559 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62560 +
62561 + atomic64_dec_unchecked(v);
62562 +}
62563 +#endif
62564 +
62565 static inline void atomic_long_add(long i, atomic_long_t *l)
62566 {
62567 atomic64_t *v = (atomic64_t *)l;
62568 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62569 atomic64_add(i, v);
62570 }
62571
62572 +#ifdef CONFIG_PAX_REFCOUNT
62573 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62574 +{
62575 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62576 +
62577 + atomic64_add_unchecked(i, v);
62578 +}
62579 +#endif
62580 +
62581 static inline void atomic_long_sub(long i, atomic_long_t *l)
62582 {
62583 atomic64_t *v = (atomic64_t *)l;
62584 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62585 atomic64_sub(i, v);
62586 }
62587
62588 +#ifdef CONFIG_PAX_REFCOUNT
62589 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62590 +{
62591 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62592 +
62593 + atomic64_sub_unchecked(i, v);
62594 +}
62595 +#endif
62596 +
62597 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62598 {
62599 atomic64_t *v = (atomic64_t *)l;
62600 @@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62601 return (long)atomic64_add_return(i, v);
62602 }
62603
62604 +#ifdef CONFIG_PAX_REFCOUNT
62605 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62606 +{
62607 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62608 +
62609 + return (long)atomic64_add_return_unchecked(i, v);
62610 +}
62611 +#endif
62612 +
62613 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62614 {
62615 atomic64_t *v = (atomic64_t *)l;
62616 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62617 return (long)atomic64_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 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62624 +
62625 + return (long)atomic64_inc_return_unchecked(v);
62626 +}
62627 +#endif
62628 +
62629 static inline long atomic_long_dec_return(atomic_long_t *l)
62630 {
62631 atomic64_t *v = (atomic64_t *)l;
62632 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62633
62634 typedef atomic_t atomic_long_t;
62635
62636 +#ifdef CONFIG_PAX_REFCOUNT
62637 +typedef atomic_unchecked_t atomic_long_unchecked_t;
62638 +#else
62639 +typedef atomic_t atomic_long_unchecked_t;
62640 +#endif
62641 +
62642 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
62643 static inline long atomic_long_read(atomic_long_t *l)
62644 {
62645 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62646 return (long)atomic_read(v);
62647 }
62648
62649 +#ifdef CONFIG_PAX_REFCOUNT
62650 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62651 +{
62652 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62653 +
62654 + return (long)atomic_read_unchecked(v);
62655 +}
62656 +#endif
62657 +
62658 static inline void atomic_long_set(atomic_long_t *l, long i)
62659 {
62660 atomic_t *v = (atomic_t *)l;
62661 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62662 atomic_set(v, i);
62663 }
62664
62665 +#ifdef CONFIG_PAX_REFCOUNT
62666 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62667 +{
62668 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62669 +
62670 + atomic_set_unchecked(v, i);
62671 +}
62672 +#endif
62673 +
62674 static inline void atomic_long_inc(atomic_long_t *l)
62675 {
62676 atomic_t *v = (atomic_t *)l;
62677 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62678 atomic_inc(v);
62679 }
62680
62681 +#ifdef CONFIG_PAX_REFCOUNT
62682 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62683 +{
62684 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62685 +
62686 + atomic_inc_unchecked(v);
62687 +}
62688 +#endif
62689 +
62690 static inline void atomic_long_dec(atomic_long_t *l)
62691 {
62692 atomic_t *v = (atomic_t *)l;
62693 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62694 atomic_dec(v);
62695 }
62696
62697 +#ifdef CONFIG_PAX_REFCOUNT
62698 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62699 +{
62700 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62701 +
62702 + atomic_dec_unchecked(v);
62703 +}
62704 +#endif
62705 +
62706 static inline void atomic_long_add(long i, atomic_long_t *l)
62707 {
62708 atomic_t *v = (atomic_t *)l;
62709 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62710 atomic_add(i, v);
62711 }
62712
62713 +#ifdef CONFIG_PAX_REFCOUNT
62714 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62715 +{
62716 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62717 +
62718 + atomic_add_unchecked(i, v);
62719 +}
62720 +#endif
62721 +
62722 static inline void atomic_long_sub(long i, atomic_long_t *l)
62723 {
62724 atomic_t *v = (atomic_t *)l;
62725 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62726 atomic_sub(i, v);
62727 }
62728
62729 +#ifdef CONFIG_PAX_REFCOUNT
62730 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62731 +{
62732 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62733 +
62734 + atomic_sub_unchecked(i, v);
62735 +}
62736 +#endif
62737 +
62738 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62739 {
62740 atomic_t *v = (atomic_t *)l;
62741 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62742 return (long)atomic_add_return(i, v);
62743 }
62744
62745 +#ifdef CONFIG_PAX_REFCOUNT
62746 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62747 +{
62748 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62749 +
62750 + return (long)atomic_add_return_unchecked(i, v);
62751 +}
62752 +
62753 +#endif
62754 +
62755 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62756 {
62757 atomic_t *v = (atomic_t *)l;
62758 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62759 return (long)atomic_inc_return(v);
62760 }
62761
62762 +#ifdef CONFIG_PAX_REFCOUNT
62763 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62764 +{
62765 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62766 +
62767 + return (long)atomic_inc_return_unchecked(v);
62768 +}
62769 +#endif
62770 +
62771 static inline long atomic_long_dec_return(atomic_long_t *l)
62772 {
62773 atomic_t *v = (atomic_t *)l;
62774 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62775
62776 #endif /* BITS_PER_LONG == 64 */
62777
62778 +#ifdef CONFIG_PAX_REFCOUNT
62779 +static inline void pax_refcount_needs_these_functions(void)
62780 +{
62781 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
62782 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
62783 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
62784 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
62785 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
62786 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
62787 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
62788 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
62789 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
62790 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
62791 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
62792 +#ifdef CONFIG_X86
62793 + atomic_clear_mask_unchecked(0, NULL);
62794 + atomic_set_mask_unchecked(0, NULL);
62795 +#endif
62796 +
62797 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
62798 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
62799 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
62800 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
62801 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
62802 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
62803 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
62804 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
62805 +}
62806 +#else
62807 +#define atomic_read_unchecked(v) atomic_read(v)
62808 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
62809 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
62810 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
62811 +#define atomic_inc_unchecked(v) atomic_inc(v)
62812 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
62813 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
62814 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
62815 +#define atomic_dec_unchecked(v) atomic_dec(v)
62816 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
62817 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
62818 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
62819 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
62820 +
62821 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
62822 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
62823 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
62824 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
62825 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
62826 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
62827 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
62828 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
62829 +#endif
62830 +
62831 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
62832 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
62833 index 1ced641..c896ee8 100644
62834 --- a/include/asm-generic/atomic.h
62835 +++ b/include/asm-generic/atomic.h
62836 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
62837 * Atomically clears the bits set in @mask from @v
62838 */
62839 #ifndef atomic_clear_mask
62840 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
62841 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
62842 {
62843 unsigned long flags;
62844
62845 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
62846 index b18ce4f..2ee2843 100644
62847 --- a/include/asm-generic/atomic64.h
62848 +++ b/include/asm-generic/atomic64.h
62849 @@ -16,6 +16,8 @@ typedef struct {
62850 long long counter;
62851 } atomic64_t;
62852
62853 +typedef atomic64_t atomic64_unchecked_t;
62854 +
62855 #define ATOMIC64_INIT(i) { (i) }
62856
62857 extern long long atomic64_read(const atomic64_t *v);
62858 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
62859 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
62860 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
62861
62862 +#define atomic64_read_unchecked(v) atomic64_read(v)
62863 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
62864 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
62865 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
62866 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
62867 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
62868 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
62869 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
62870 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
62871 +
62872 #endif /* _ASM_GENERIC_ATOMIC64_H */
62873 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
62874 index 1bfcfe5..e04c5c9 100644
62875 --- a/include/asm-generic/cache.h
62876 +++ b/include/asm-generic/cache.h
62877 @@ -6,7 +6,7 @@
62878 * cache lines need to provide their own cache.h.
62879 */
62880
62881 -#define L1_CACHE_SHIFT 5
62882 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
62883 +#define L1_CACHE_SHIFT 5UL
62884 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
62885
62886 #endif /* __ASM_GENERIC_CACHE_H */
62887 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
62888 index 0d68a1e..b74a761 100644
62889 --- a/include/asm-generic/emergency-restart.h
62890 +++ b/include/asm-generic/emergency-restart.h
62891 @@ -1,7 +1,7 @@
62892 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
62893 #define _ASM_GENERIC_EMERGENCY_RESTART_H
62894
62895 -static inline void machine_emergency_restart(void)
62896 +static inline __noreturn void machine_emergency_restart(void)
62897 {
62898 machine_restart(NULL);
62899 }
62900 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
62901 index 90f99c7..00ce236 100644
62902 --- a/include/asm-generic/kmap_types.h
62903 +++ b/include/asm-generic/kmap_types.h
62904 @@ -2,9 +2,9 @@
62905 #define _ASM_GENERIC_KMAP_TYPES_H
62906
62907 #ifdef __WITH_KM_FENCE
62908 -# define KM_TYPE_NR 41
62909 +# define KM_TYPE_NR 42
62910 #else
62911 -# define KM_TYPE_NR 20
62912 +# define KM_TYPE_NR 21
62913 #endif
62914
62915 #endif
62916 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
62917 index 9ceb03b..62b0b8f 100644
62918 --- a/include/asm-generic/local.h
62919 +++ b/include/asm-generic/local.h
62920 @@ -23,24 +23,37 @@ typedef struct
62921 atomic_long_t a;
62922 } local_t;
62923
62924 +typedef struct {
62925 + atomic_long_unchecked_t a;
62926 +} local_unchecked_t;
62927 +
62928 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
62929
62930 #define local_read(l) atomic_long_read(&(l)->a)
62931 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
62932 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
62933 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
62934 #define local_inc(l) atomic_long_inc(&(l)->a)
62935 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
62936 #define local_dec(l) atomic_long_dec(&(l)->a)
62937 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
62938 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
62939 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
62940 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
62941 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
62942
62943 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
62944 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
62945 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
62946 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
62947 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
62948 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
62949 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
62950 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
62951 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
62952
62953 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62954 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62955 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
62956 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
62957 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
62958 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
62959 index 725612b..9cc513a 100644
62960 --- a/include/asm-generic/pgtable-nopmd.h
62961 +++ b/include/asm-generic/pgtable-nopmd.h
62962 @@ -1,14 +1,19 @@
62963 #ifndef _PGTABLE_NOPMD_H
62964 #define _PGTABLE_NOPMD_H
62965
62966 -#ifndef __ASSEMBLY__
62967 -
62968 #include <asm-generic/pgtable-nopud.h>
62969
62970 -struct mm_struct;
62971 -
62972 #define __PAGETABLE_PMD_FOLDED
62973
62974 +#define PMD_SHIFT PUD_SHIFT
62975 +#define PTRS_PER_PMD 1
62976 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
62977 +#define PMD_MASK (~(PMD_SIZE-1))
62978 +
62979 +#ifndef __ASSEMBLY__
62980 +
62981 +struct mm_struct;
62982 +
62983 /*
62984 * Having the pmd type consist of a pud gets the size right, and allows
62985 * us to conceptually access the pud entry that this pmd is folded into
62986 @@ -16,11 +21,6 @@ struct mm_struct;
62987 */
62988 typedef struct { pud_t pud; } pmd_t;
62989
62990 -#define PMD_SHIFT PUD_SHIFT
62991 -#define PTRS_PER_PMD 1
62992 -#define PMD_SIZE (1UL << PMD_SHIFT)
62993 -#define PMD_MASK (~(PMD_SIZE-1))
62994 -
62995 /*
62996 * The "pud_xxx()" functions here are trivial for a folded two-level
62997 * setup: the pmd is never bad, and a pmd always exists (as it's folded
62998 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
62999 index 810431d..0ec4804f 100644
63000 --- a/include/asm-generic/pgtable-nopud.h
63001 +++ b/include/asm-generic/pgtable-nopud.h
63002 @@ -1,10 +1,15 @@
63003 #ifndef _PGTABLE_NOPUD_H
63004 #define _PGTABLE_NOPUD_H
63005
63006 -#ifndef __ASSEMBLY__
63007 -
63008 #define __PAGETABLE_PUD_FOLDED
63009
63010 +#define PUD_SHIFT PGDIR_SHIFT
63011 +#define PTRS_PER_PUD 1
63012 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
63013 +#define PUD_MASK (~(PUD_SIZE-1))
63014 +
63015 +#ifndef __ASSEMBLY__
63016 +
63017 /*
63018 * Having the pud type consist of a pgd gets the size right, and allows
63019 * us to conceptually access the pgd entry that this pud is folded into
63020 @@ -12,11 +17,6 @@
63021 */
63022 typedef struct { pgd_t pgd; } pud_t;
63023
63024 -#define PUD_SHIFT PGDIR_SHIFT
63025 -#define PTRS_PER_PUD 1
63026 -#define PUD_SIZE (1UL << PUD_SHIFT)
63027 -#define PUD_MASK (~(PUD_SIZE-1))
63028 -
63029 /*
63030 * The "pgd_xxx()" functions here are trivial for a folded two-level
63031 * setup: the pud is never bad, and a pud always exists (as it's folded
63032 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
63033 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
63034
63035 #define pgd_populate(mm, pgd, pud) do { } while (0)
63036 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
63037 /*
63038 * (puds are folded into pgds so this doesn't get actually called,
63039 * but the define is needed for a generic inline function.)
63040 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
63041 index b36ce40..019426d 100644
63042 --- a/include/asm-generic/pgtable.h
63043 +++ b/include/asm-generic/pgtable.h
63044 @@ -554,6 +554,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
63045 #endif
63046 }
63047
63048 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
63049 +static inline unsigned long pax_open_kernel(void) { return 0; }
63050 +#endif
63051 +
63052 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
63053 +static inline unsigned long pax_close_kernel(void) { return 0; }
63054 +#endif
63055 +
63056 #endif /* CONFIG_MMU */
63057
63058 #endif /* !__ASSEMBLY__ */
63059 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
63060 index d1ea7ce..b1ebf2a 100644
63061 --- a/include/asm-generic/vmlinux.lds.h
63062 +++ b/include/asm-generic/vmlinux.lds.h
63063 @@ -218,6 +218,7 @@
63064 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
63065 VMLINUX_SYMBOL(__start_rodata) = .; \
63066 *(.rodata) *(.rodata.*) \
63067 + *(.data..read_only) \
63068 *(__vermagic) /* Kernel version magic */ \
63069 . = ALIGN(8); \
63070 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
63071 @@ -725,17 +726,18 @@
63072 * section in the linker script will go there too. @phdr should have
63073 * a leading colon.
63074 *
63075 - * Note that this macros defines __per_cpu_load as an absolute symbol.
63076 + * Note that this macros defines per_cpu_load as an absolute symbol.
63077 * If there is no need to put the percpu section at a predetermined
63078 * address, use PERCPU_SECTION.
63079 */
63080 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
63081 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
63082 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
63083 + per_cpu_load = .; \
63084 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
63085 - LOAD_OFFSET) { \
63086 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
63087 PERCPU_INPUT(cacheline) \
63088 } phdr \
63089 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
63090 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
63091
63092 /**
63093 * PERCPU_SECTION - define output section for percpu area, simple version
63094 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
63095 index 418d270..bfd2794 100644
63096 --- a/include/crypto/algapi.h
63097 +++ b/include/crypto/algapi.h
63098 @@ -34,7 +34,7 @@ struct crypto_type {
63099 unsigned int maskclear;
63100 unsigned int maskset;
63101 unsigned int tfmsize;
63102 -};
63103 +} __do_const;
63104
63105 struct crypto_instance {
63106 struct crypto_alg alg;
63107 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
63108 index 3fd8280..2b3c415 100644
63109 --- a/include/drm/drmP.h
63110 +++ b/include/drm/drmP.h
63111 @@ -72,6 +72,7 @@
63112 #include <linux/workqueue.h>
63113 #include <linux/poll.h>
63114 #include <asm/pgalloc.h>
63115 +#include <asm/local.h>
63116 #include <drm/drm.h>
63117 #include <drm/drm_sarea.h>
63118
63119 @@ -1068,7 +1069,7 @@ struct drm_device {
63120
63121 /** \name Usage Counters */
63122 /*@{ */
63123 - int open_count; /**< Outstanding files open */
63124 + local_t open_count; /**< Outstanding files open */
63125 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
63126 atomic_t vma_count; /**< Outstanding vma areas open */
63127 int buf_use; /**< Buffers in use -- cannot alloc */
63128 @@ -1079,7 +1080,7 @@ struct drm_device {
63129 /*@{ */
63130 unsigned long counters;
63131 enum drm_stat_type types[15];
63132 - atomic_t counts[15];
63133 + atomic_unchecked_t counts[15];
63134 /*@} */
63135
63136 struct list_head filelist;
63137 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
63138 index e01cc80..6fb6f25 100644
63139 --- a/include/drm/drm_crtc_helper.h
63140 +++ b/include/drm/drm_crtc_helper.h
63141 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
63142 struct drm_connector *connector);
63143 /* disable encoder when not in use - more explicit than dpms off */
63144 void (*disable)(struct drm_encoder *encoder);
63145 -};
63146 +} __no_const;
63147
63148 /**
63149 * drm_connector_helper_funcs - helper operations for connectors
63150 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
63151 index d6d1da4..fdd1ac5 100644
63152 --- a/include/drm/ttm/ttm_memory.h
63153 +++ b/include/drm/ttm/ttm_memory.h
63154 @@ -48,7 +48,7 @@
63155
63156 struct ttm_mem_shrink {
63157 int (*do_shrink) (struct ttm_mem_shrink *);
63158 -};
63159 +} __no_const;
63160
63161 /**
63162 * struct ttm_mem_global - Global memory accounting structure.
63163 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
63164 index 22ef21c..75904ba 100644
63165 --- a/include/linux/atmdev.h
63166 +++ b/include/linux/atmdev.h
63167 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
63168 #endif
63169
63170 struct k_atm_aal_stats {
63171 -#define __HANDLE_ITEM(i) atomic_t i
63172 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63173 __AAL_STAT_ITEMS
63174 #undef __HANDLE_ITEM
63175 };
63176 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
63177 index de0628e..38f42eb 100644
63178 --- a/include/linux/binfmts.h
63179 +++ b/include/linux/binfmts.h
63180 @@ -75,6 +75,7 @@ struct linux_binfmt {
63181 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
63182 int (*load_shlib)(struct file *);
63183 int (*core_dump)(struct coredump_params *cprm);
63184 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
63185 unsigned long min_coredump; /* minimal dump size */
63186 };
63187
63188 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
63189 index 1756001..ab117ec 100644
63190 --- a/include/linux/blkdev.h
63191 +++ b/include/linux/blkdev.h
63192 @@ -1478,7 +1478,7 @@ struct block_device_operations {
63193 /* this callback is with swap_lock and sometimes page table lock held */
63194 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
63195 struct module *owner;
63196 -};
63197 +} __do_const;
63198
63199 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
63200 unsigned long);
63201 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
63202 index 7c2e030..b72475d 100644
63203 --- a/include/linux/blktrace_api.h
63204 +++ b/include/linux/blktrace_api.h
63205 @@ -23,7 +23,7 @@ struct blk_trace {
63206 struct dentry *dir;
63207 struct dentry *dropped_file;
63208 struct dentry *msg_file;
63209 - atomic_t dropped;
63210 + atomic_unchecked_t dropped;
63211 };
63212
63213 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
63214 diff --git a/include/linux/cache.h b/include/linux/cache.h
63215 index 4c57065..4307975 100644
63216 --- a/include/linux/cache.h
63217 +++ b/include/linux/cache.h
63218 @@ -16,6 +16,10 @@
63219 #define __read_mostly
63220 #endif
63221
63222 +#ifndef __read_only
63223 +#define __read_only __read_mostly
63224 +#endif
63225 +
63226 #ifndef ____cacheline_aligned
63227 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
63228 #endif
63229 diff --git a/include/linux/capability.h b/include/linux/capability.h
63230 index 98503b7..cc36d18 100644
63231 --- a/include/linux/capability.h
63232 +++ b/include/linux/capability.h
63233 @@ -211,8 +211,13 @@ extern bool capable(int cap);
63234 extern bool ns_capable(struct user_namespace *ns, int cap);
63235 extern bool nsown_capable(int cap);
63236 extern bool inode_capable(const struct inode *inode, int cap);
63237 +extern bool capable_nolog(int cap);
63238 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
63239 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
63240
63241 /* audit system wants to get cap info from files as well */
63242 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
63243
63244 +extern int is_privileged_binary(const struct dentry *dentry);
63245 +
63246 #endif /* !_LINUX_CAPABILITY_H */
63247 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
63248 index 8609d57..86e4d79 100644
63249 --- a/include/linux/cdrom.h
63250 +++ b/include/linux/cdrom.h
63251 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
63252
63253 /* driver specifications */
63254 const int capability; /* capability flags */
63255 - int n_minors; /* number of active minor devices */
63256 /* handle uniform packets for scsi type devices (scsi,atapi) */
63257 int (*generic_packet) (struct cdrom_device_info *,
63258 struct packet_command *);
63259 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
63260 index 42e55de..1cd0e66 100644
63261 --- a/include/linux/cleancache.h
63262 +++ b/include/linux/cleancache.h
63263 @@ -31,7 +31,7 @@ struct cleancache_ops {
63264 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
63265 void (*invalidate_inode)(int, struct cleancache_filekey);
63266 void (*invalidate_fs)(int);
63267 -};
63268 +} __no_const;
63269
63270 extern struct cleancache_ops
63271 cleancache_register_ops(struct cleancache_ops *ops);
63272 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
63273 index 412bc6c..c31666e 100644
63274 --- a/include/linux/compiler-gcc4.h
63275 +++ b/include/linux/compiler-gcc4.h
63276 @@ -32,6 +32,21 @@
63277 #define __linktime_error(message) __attribute__((__error__(message)))
63278
63279 #if __GNUC_MINOR__ >= 5
63280 +
63281 +#ifdef CONSTIFY_PLUGIN
63282 +#define __no_const __attribute__((no_const))
63283 +#define __do_const __attribute__((do_const))
63284 +#endif
63285 +
63286 +#ifdef SIZE_OVERFLOW_PLUGIN
63287 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
63288 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
63289 +#endif
63290 +
63291 +#ifdef LATENT_ENTROPY_PLUGIN
63292 +#define __latent_entropy __attribute__((latent_entropy))
63293 +#endif
63294 +
63295 /*
63296 * Mark a position in code as unreachable. This can be used to
63297 * suppress control flow warnings after asm blocks that transfer
63298 @@ -47,6 +62,11 @@
63299 #define __noclone __attribute__((__noclone__))
63300
63301 #endif
63302 +
63303 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
63304 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
63305 +#define __bos0(ptr) __bos((ptr), 0)
63306 +#define __bos1(ptr) __bos((ptr), 1)
63307 #endif
63308
63309 #if __GNUC_MINOR__ >= 6
63310 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
63311 index f430e41..38be90f 100644
63312 --- a/include/linux/compiler.h
63313 +++ b/include/linux/compiler.h
63314 @@ -5,31 +5,62 @@
63315
63316 #ifdef __CHECKER__
63317 # define __user __attribute__((noderef, address_space(1)))
63318 +# define __force_user __force __user
63319 # define __kernel __attribute__((address_space(0)))
63320 +# define __force_kernel __force __kernel
63321 # define __safe __attribute__((safe))
63322 # define __force __attribute__((force))
63323 # define __nocast __attribute__((nocast))
63324 # define __iomem __attribute__((noderef, address_space(2)))
63325 +# define __force_iomem __force __iomem
63326 # define __acquires(x) __attribute__((context(x,0,1)))
63327 # define __releases(x) __attribute__((context(x,1,0)))
63328 # define __acquire(x) __context__(x,1)
63329 # define __release(x) __context__(x,-1)
63330 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
63331 # define __percpu __attribute__((noderef, address_space(3)))
63332 +# define __force_percpu __force __percpu
63333 #ifdef CONFIG_SPARSE_RCU_POINTER
63334 # define __rcu __attribute__((noderef, address_space(4)))
63335 +# define __force_rcu __force __rcu
63336 #else
63337 # define __rcu
63338 +# define __force_rcu
63339 #endif
63340 extern void __chk_user_ptr(const volatile void __user *);
63341 extern void __chk_io_ptr(const volatile void __iomem *);
63342 +#elif defined(CHECKER_PLUGIN)
63343 +//# define __user
63344 +//# define __force_user
63345 +//# define __kernel
63346 +//# define __force_kernel
63347 +# define __safe
63348 +# define __force
63349 +# define __nocast
63350 +# define __iomem
63351 +# define __force_iomem
63352 +# define __chk_user_ptr(x) (void)0
63353 +# define __chk_io_ptr(x) (void)0
63354 +# define __builtin_warning(x, y...) (1)
63355 +# define __acquires(x)
63356 +# define __releases(x)
63357 +# define __acquire(x) (void)0
63358 +# define __release(x) (void)0
63359 +# define __cond_lock(x,c) (c)
63360 +# define __percpu
63361 +# define __force_percpu
63362 +# define __rcu
63363 +# define __force_rcu
63364 #else
63365 # define __user
63366 +# define __force_user
63367 # define __kernel
63368 +# define __force_kernel
63369 # define __safe
63370 # define __force
63371 # define __nocast
63372 # define __iomem
63373 +# define __force_iomem
63374 # define __chk_user_ptr(x) (void)0
63375 # define __chk_io_ptr(x) (void)0
63376 # define __builtin_warning(x, y...) (1)
63377 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
63378 # define __release(x) (void)0
63379 # define __cond_lock(x,c) (c)
63380 # define __percpu
63381 +# define __force_percpu
63382 # define __rcu
63383 +# define __force_rcu
63384 #endif
63385
63386 #ifdef __KERNEL__
63387 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63388 # define __attribute_const__ /* unimplemented */
63389 #endif
63390
63391 +#ifndef __no_const
63392 +# define __no_const
63393 +#endif
63394 +
63395 +#ifndef __do_const
63396 +# define __do_const
63397 +#endif
63398 +
63399 +#ifndef __size_overflow
63400 +# define __size_overflow(...)
63401 +#endif
63402 +
63403 +#ifndef __intentional_overflow
63404 +# define __intentional_overflow(...)
63405 +#endif
63406 +
63407 +#ifndef __latent_entropy
63408 +# define __latent_entropy
63409 +#endif
63410 +
63411 /*
63412 * Tell gcc if a function is cold. The compiler will assume any path
63413 * directly leading to the call is unlikely.
63414 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63415 #define __cold
63416 #endif
63417
63418 +#ifndef __alloc_size
63419 +#define __alloc_size(...)
63420 +#endif
63421 +
63422 +#ifndef __bos
63423 +#define __bos(ptr, arg)
63424 +#endif
63425 +
63426 +#ifndef __bos0
63427 +#define __bos0(ptr)
63428 +#endif
63429 +
63430 +#ifndef __bos1
63431 +#define __bos1(ptr)
63432 +#endif
63433 +
63434 /* Simple shorthand for a section definition */
63435 #ifndef __section
63436 # define __section(S) __attribute__ ((__section__(#S)))
63437 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63438 * use is to mediate communication between process-level code and irq/NMI
63439 * handlers, all running on the same CPU.
63440 */
63441 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
63442 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
63443 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
63444
63445 #endif /* __LINUX_COMPILER_H */
63446 diff --git a/include/linux/cred.h b/include/linux/cred.h
63447 index ebbed2c..908cc2c 100644
63448 --- a/include/linux/cred.h
63449 +++ b/include/linux/cred.h
63450 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
63451 static inline void validate_process_creds(void)
63452 {
63453 }
63454 +static inline void validate_task_creds(struct task_struct *task)
63455 +{
63456 +}
63457 #endif
63458
63459 /**
63460 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
63461 index b92eadf..b4ecdc1 100644
63462 --- a/include/linux/crypto.h
63463 +++ b/include/linux/crypto.h
63464 @@ -373,7 +373,7 @@ struct cipher_tfm {
63465 const u8 *key, unsigned int keylen);
63466 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63467 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63468 -};
63469 +} __no_const;
63470
63471 struct hash_tfm {
63472 int (*init)(struct hash_desc *desc);
63473 @@ -394,13 +394,13 @@ struct compress_tfm {
63474 int (*cot_decompress)(struct crypto_tfm *tfm,
63475 const u8 *src, unsigned int slen,
63476 u8 *dst, unsigned int *dlen);
63477 -};
63478 +} __no_const;
63479
63480 struct rng_tfm {
63481 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
63482 unsigned int dlen);
63483 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
63484 -};
63485 +} __no_const;
63486
63487 #define crt_ablkcipher crt_u.ablkcipher
63488 #define crt_aead crt_u.aead
63489 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
63490 index 7925bf0..d5143d2 100644
63491 --- a/include/linux/decompress/mm.h
63492 +++ b/include/linux/decompress/mm.h
63493 @@ -77,7 +77,7 @@ static void free(void *where)
63494 * warnings when not needed (indeed large_malloc / large_free are not
63495 * needed by inflate */
63496
63497 -#define malloc(a) kmalloc(a, GFP_KERNEL)
63498 +#define malloc(a) kmalloc((a), GFP_KERNEL)
63499 #define free(a) kfree(a)
63500
63501 #define large_malloc(a) vmalloc(a)
63502 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
63503 index 94af418..b1ca7a2 100644
63504 --- a/include/linux/dma-mapping.h
63505 +++ b/include/linux/dma-mapping.h
63506 @@ -54,7 +54,7 @@ struct dma_map_ops {
63507 u64 (*get_required_mask)(struct device *dev);
63508 #endif
63509 int is_phys;
63510 -};
63511 +} __do_const;
63512
63513 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
63514
63515 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
63516 index d3201e4..8281e63 100644
63517 --- a/include/linux/dmaengine.h
63518 +++ b/include/linux/dmaengine.h
63519 @@ -1018,9 +1018,9 @@ struct dma_pinned_list {
63520 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
63521 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
63522
63523 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63524 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63525 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
63526 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63527 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63528 struct dma_pinned_list *pinned_list, struct page *page,
63529 unsigned int offset, size_t len);
63530
63531 diff --git a/include/linux/elf.h b/include/linux/elf.h
63532 index 8c9048e..16a4665 100644
63533 --- a/include/linux/elf.h
63534 +++ b/include/linux/elf.h
63535 @@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
63536 #define elf_note elf32_note
63537 #define elf_addr_t Elf32_Off
63538 #define Elf_Half Elf32_Half
63539 +#define elf_dyn Elf32_Dyn
63540
63541 #else
63542
63543 @@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
63544 #define elf_note elf64_note
63545 #define elf_addr_t Elf64_Off
63546 #define Elf_Half Elf64_Half
63547 +#define elf_dyn Elf64_Dyn
63548
63549 #endif
63550
63551 diff --git a/include/linux/filter.h b/include/linux/filter.h
63552 index 24d251f..7afb83d 100644
63553 --- a/include/linux/filter.h
63554 +++ b/include/linux/filter.h
63555 @@ -20,6 +20,7 @@ struct compat_sock_fprog {
63556
63557 struct sk_buff;
63558 struct sock;
63559 +struct bpf_jit_work;
63560
63561 struct sk_filter
63562 {
63563 @@ -27,6 +28,9 @@ struct sk_filter
63564 unsigned int len; /* Number of filter blocks */
63565 unsigned int (*bpf_func)(const struct sk_buff *skb,
63566 const struct sock_filter *filter);
63567 +#ifdef CONFIG_BPF_JIT
63568 + struct bpf_jit_work *work;
63569 +#endif
63570 struct rcu_head rcu;
63571 struct sock_filter insns[0];
63572 };
63573 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
63574 index 3044254..9767f41 100644
63575 --- a/include/linux/frontswap.h
63576 +++ b/include/linux/frontswap.h
63577 @@ -11,7 +11,7 @@ struct frontswap_ops {
63578 int (*load)(unsigned, pgoff_t, struct page *);
63579 void (*invalidate_page)(unsigned, pgoff_t);
63580 void (*invalidate_area)(unsigned);
63581 -};
63582 +} __no_const;
63583
63584 extern bool frontswap_enabled;
63585 extern struct frontswap_ops
63586 diff --git a/include/linux/fs.h b/include/linux/fs.h
63587 index 75fe9a1..8417cac 100644
63588 --- a/include/linux/fs.h
63589 +++ b/include/linux/fs.h
63590 @@ -1543,7 +1543,8 @@ struct file_operations {
63591 int (*setlease)(struct file *, long, struct file_lock **);
63592 long (*fallocate)(struct file *file, int mode, loff_t offset,
63593 loff_t len);
63594 -};
63595 +} __do_const;
63596 +typedef struct file_operations __no_const file_operations_no_const;
63597
63598 struct inode_operations {
63599 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
63600 @@ -2667,4 +2668,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
63601 inode->i_flags |= S_NOSEC;
63602 }
63603
63604 +static inline bool is_sidechannel_device(const struct inode *inode)
63605 +{
63606 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
63607 + umode_t mode = inode->i_mode;
63608 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
63609 +#else
63610 + return false;
63611 +#endif
63612 +}
63613 +
63614 #endif /* _LINUX_FS_H */
63615 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
63616 index 003dc0f..3c4ea97 100644
63617 --- a/include/linux/fs_struct.h
63618 +++ b/include/linux/fs_struct.h
63619 @@ -6,7 +6,7 @@
63620 #include <linux/seqlock.h>
63621
63622 struct fs_struct {
63623 - int users;
63624 + atomic_t users;
63625 spinlock_t lock;
63626 seqcount_t seq;
63627 int umask;
63628 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
63629 index ce31408..b1ad003 100644
63630 --- a/include/linux/fscache-cache.h
63631 +++ b/include/linux/fscache-cache.h
63632 @@ -102,7 +102,7 @@ struct fscache_operation {
63633 fscache_operation_release_t release;
63634 };
63635
63636 -extern atomic_t fscache_op_debug_id;
63637 +extern atomic_unchecked_t fscache_op_debug_id;
63638 extern void fscache_op_work_func(struct work_struct *work);
63639
63640 extern void fscache_enqueue_operation(struct fscache_operation *);
63641 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
63642 {
63643 INIT_WORK(&op->work, fscache_op_work_func);
63644 atomic_set(&op->usage, 1);
63645 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
63646 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63647 op->processor = processor;
63648 op->release = release;
63649 INIT_LIST_HEAD(&op->pend_link);
63650 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
63651 index 0fbfb46..508eb0d 100644
63652 --- a/include/linux/fsnotify.h
63653 +++ b/include/linux/fsnotify.h
63654 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
63655 struct inode *inode = path->dentry->d_inode;
63656 __u32 mask = FS_ACCESS;
63657
63658 + if (is_sidechannel_device(inode))
63659 + return;
63660 +
63661 if (S_ISDIR(inode->i_mode))
63662 mask |= FS_ISDIR;
63663
63664 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
63665 struct inode *inode = path->dentry->d_inode;
63666 __u32 mask = FS_MODIFY;
63667
63668 + if (is_sidechannel_device(inode))
63669 + return;
63670 +
63671 if (S_ISDIR(inode->i_mode))
63672 mask |= FS_ISDIR;
63673
63674 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
63675 */
63676 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
63677 {
63678 - return kstrdup(name, GFP_KERNEL);
63679 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
63680 }
63681
63682 /*
63683 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
63684 index 642928c..93afe6a 100644
63685 --- a/include/linux/ftrace_event.h
63686 +++ b/include/linux/ftrace_event.h
63687 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
63688 extern int trace_add_event_call(struct ftrace_event_call *call);
63689 extern void trace_remove_event_call(struct ftrace_event_call *call);
63690
63691 -#define is_signed_type(type) (((type)(-1)) < 0)
63692 +#define is_signed_type(type) (((type)(-1)) < (type)1)
63693
63694 int trace_set_clr_event(const char *system, const char *event, int set);
63695
63696 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
63697 index 4f440b3..342233a 100644
63698 --- a/include/linux/genhd.h
63699 +++ b/include/linux/genhd.h
63700 @@ -190,7 +190,7 @@ struct gendisk {
63701 struct kobject *slave_dir;
63702
63703 struct timer_rand_state *random;
63704 - atomic_t sync_io; /* RAID */
63705 + atomic_unchecked_t sync_io; /* RAID */
63706 struct disk_events *ev;
63707 #ifdef CONFIG_BLK_DEV_INTEGRITY
63708 struct blk_integrity *integrity;
63709 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
63710 index d0a7967..63c4c47 100644
63711 --- a/include/linux/gfp.h
63712 +++ b/include/linux/gfp.h
63713 @@ -35,6 +35,12 @@ struct vm_area_struct;
63714 #define ___GFP_OTHER_NODE 0x800000u
63715 #define ___GFP_WRITE 0x1000000u
63716
63717 +#ifdef CONFIG_PAX_USERCOPY_SLABS
63718 +#define ___GFP_USERCOPY 0x2000000u
63719 +#else
63720 +#define ___GFP_USERCOPY 0
63721 +#endif
63722 +
63723 /*
63724 * GFP bitmasks..
63725 *
63726 @@ -89,6 +95,7 @@ struct vm_area_struct;
63727 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
63728 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
63729 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
63730 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
63731
63732 /*
63733 * This may seem redundant, but it's a way of annotating false positives vs.
63734 @@ -96,7 +103,7 @@ struct vm_area_struct;
63735 */
63736 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
63737
63738 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
63739 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
63740 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
63741
63742 /* This equals 0, but use constants in case they ever change */
63743 @@ -150,6 +157,8 @@ struct vm_area_struct;
63744 /* 4GB DMA on some platforms */
63745 #define GFP_DMA32 __GFP_DMA32
63746
63747 +#define GFP_USERCOPY __GFP_USERCOPY
63748 +
63749 /* Convert GFP flags to their corresponding migrate type */
63750 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
63751 {
63752 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
63753 new file mode 100644
63754 index 0000000..ebe6d72
63755 --- /dev/null
63756 +++ b/include/linux/gracl.h
63757 @@ -0,0 +1,319 @@
63758 +#ifndef GR_ACL_H
63759 +#define GR_ACL_H
63760 +
63761 +#include <linux/grdefs.h>
63762 +#include <linux/resource.h>
63763 +#include <linux/capability.h>
63764 +#include <linux/dcache.h>
63765 +#include <asm/resource.h>
63766 +
63767 +/* Major status information */
63768 +
63769 +#define GR_VERSION "grsecurity 2.9.1"
63770 +#define GRSECURITY_VERSION 0x2901
63771 +
63772 +enum {
63773 + GR_SHUTDOWN = 0,
63774 + GR_ENABLE = 1,
63775 + GR_SPROLE = 2,
63776 + GR_RELOAD = 3,
63777 + GR_SEGVMOD = 4,
63778 + GR_STATUS = 5,
63779 + GR_UNSPROLE = 6,
63780 + GR_PASSSET = 7,
63781 + GR_SPROLEPAM = 8,
63782 +};
63783 +
63784 +/* Password setup definitions
63785 + * kernel/grhash.c */
63786 +enum {
63787 + GR_PW_LEN = 128,
63788 + GR_SALT_LEN = 16,
63789 + GR_SHA_LEN = 32,
63790 +};
63791 +
63792 +enum {
63793 + GR_SPROLE_LEN = 64,
63794 +};
63795 +
63796 +enum {
63797 + GR_NO_GLOB = 0,
63798 + GR_REG_GLOB,
63799 + GR_CREATE_GLOB
63800 +};
63801 +
63802 +#define GR_NLIMITS 32
63803 +
63804 +/* Begin Data Structures */
63805 +
63806 +struct sprole_pw {
63807 + unsigned char *rolename;
63808 + unsigned char salt[GR_SALT_LEN];
63809 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
63810 +};
63811 +
63812 +struct name_entry {
63813 + __u32 key;
63814 + ino_t inode;
63815 + dev_t device;
63816 + char *name;
63817 + __u16 len;
63818 + __u8 deleted;
63819 + struct name_entry *prev;
63820 + struct name_entry *next;
63821 +};
63822 +
63823 +struct inodev_entry {
63824 + struct name_entry *nentry;
63825 + struct inodev_entry *prev;
63826 + struct inodev_entry *next;
63827 +};
63828 +
63829 +struct acl_role_db {
63830 + struct acl_role_label **r_hash;
63831 + __u32 r_size;
63832 +};
63833 +
63834 +struct inodev_db {
63835 + struct inodev_entry **i_hash;
63836 + __u32 i_size;
63837 +};
63838 +
63839 +struct name_db {
63840 + struct name_entry **n_hash;
63841 + __u32 n_size;
63842 +};
63843 +
63844 +struct crash_uid {
63845 + uid_t uid;
63846 + unsigned long expires;
63847 +};
63848 +
63849 +struct gr_hash_struct {
63850 + void **table;
63851 + void **nametable;
63852 + void *first;
63853 + __u32 table_size;
63854 + __u32 used_size;
63855 + int type;
63856 +};
63857 +
63858 +/* Userspace Grsecurity ACL data structures */
63859 +
63860 +struct acl_subject_label {
63861 + char *filename;
63862 + ino_t inode;
63863 + dev_t device;
63864 + __u32 mode;
63865 + kernel_cap_t cap_mask;
63866 + kernel_cap_t cap_lower;
63867 + kernel_cap_t cap_invert_audit;
63868 +
63869 + struct rlimit res[GR_NLIMITS];
63870 + __u32 resmask;
63871 +
63872 + __u8 user_trans_type;
63873 + __u8 group_trans_type;
63874 + uid_t *user_transitions;
63875 + gid_t *group_transitions;
63876 + __u16 user_trans_num;
63877 + __u16 group_trans_num;
63878 +
63879 + __u32 sock_families[2];
63880 + __u32 ip_proto[8];
63881 + __u32 ip_type;
63882 + struct acl_ip_label **ips;
63883 + __u32 ip_num;
63884 + __u32 inaddr_any_override;
63885 +
63886 + __u32 crashes;
63887 + unsigned long expires;
63888 +
63889 + struct acl_subject_label *parent_subject;
63890 + struct gr_hash_struct *hash;
63891 + struct acl_subject_label *prev;
63892 + struct acl_subject_label *next;
63893 +
63894 + struct acl_object_label **obj_hash;
63895 + __u32 obj_hash_size;
63896 + __u16 pax_flags;
63897 +};
63898 +
63899 +struct role_allowed_ip {
63900 + __u32 addr;
63901 + __u32 netmask;
63902 +
63903 + struct role_allowed_ip *prev;
63904 + struct role_allowed_ip *next;
63905 +};
63906 +
63907 +struct role_transition {
63908 + char *rolename;
63909 +
63910 + struct role_transition *prev;
63911 + struct role_transition *next;
63912 +};
63913 +
63914 +struct acl_role_label {
63915 + char *rolename;
63916 + uid_t uidgid;
63917 + __u16 roletype;
63918 +
63919 + __u16 auth_attempts;
63920 + unsigned long expires;
63921 +
63922 + struct acl_subject_label *root_label;
63923 + struct gr_hash_struct *hash;
63924 +
63925 + struct acl_role_label *prev;
63926 + struct acl_role_label *next;
63927 +
63928 + struct role_transition *transitions;
63929 + struct role_allowed_ip *allowed_ips;
63930 + uid_t *domain_children;
63931 + __u16 domain_child_num;
63932 +
63933 + umode_t umask;
63934 +
63935 + struct acl_subject_label **subj_hash;
63936 + __u32 subj_hash_size;
63937 +};
63938 +
63939 +struct user_acl_role_db {
63940 + struct acl_role_label **r_table;
63941 + __u32 num_pointers; /* Number of allocations to track */
63942 + __u32 num_roles; /* Number of roles */
63943 + __u32 num_domain_children; /* Number of domain children */
63944 + __u32 num_subjects; /* Number of subjects */
63945 + __u32 num_objects; /* Number of objects */
63946 +};
63947 +
63948 +struct acl_object_label {
63949 + char *filename;
63950 + ino_t inode;
63951 + dev_t device;
63952 + __u32 mode;
63953 +
63954 + struct acl_subject_label *nested;
63955 + struct acl_object_label *globbed;
63956 +
63957 + /* next two structures not used */
63958 +
63959 + struct acl_object_label *prev;
63960 + struct acl_object_label *next;
63961 +};
63962 +
63963 +struct acl_ip_label {
63964 + char *iface;
63965 + __u32 addr;
63966 + __u32 netmask;
63967 + __u16 low, high;
63968 + __u8 mode;
63969 + __u32 type;
63970 + __u32 proto[8];
63971 +
63972 + /* next two structures not used */
63973 +
63974 + struct acl_ip_label *prev;
63975 + struct acl_ip_label *next;
63976 +};
63977 +
63978 +struct gr_arg {
63979 + struct user_acl_role_db role_db;
63980 + unsigned char pw[GR_PW_LEN];
63981 + unsigned char salt[GR_SALT_LEN];
63982 + unsigned char sum[GR_SHA_LEN];
63983 + unsigned char sp_role[GR_SPROLE_LEN];
63984 + struct sprole_pw *sprole_pws;
63985 + dev_t segv_device;
63986 + ino_t segv_inode;
63987 + uid_t segv_uid;
63988 + __u16 num_sprole_pws;
63989 + __u16 mode;
63990 +};
63991 +
63992 +struct gr_arg_wrapper {
63993 + struct gr_arg *arg;
63994 + __u32 version;
63995 + __u32 size;
63996 +};
63997 +
63998 +struct subject_map {
63999 + struct acl_subject_label *user;
64000 + struct acl_subject_label *kernel;
64001 + struct subject_map *prev;
64002 + struct subject_map *next;
64003 +};
64004 +
64005 +struct acl_subj_map_db {
64006 + struct subject_map **s_hash;
64007 + __u32 s_size;
64008 +};
64009 +
64010 +/* End Data Structures Section */
64011 +
64012 +/* Hash functions generated by empirical testing by Brad Spengler
64013 + Makes good use of the low bits of the inode. Generally 0-1 times
64014 + in loop for successful match. 0-3 for unsuccessful match.
64015 + Shift/add algorithm with modulus of table size and an XOR*/
64016 +
64017 +static __inline__ unsigned int
64018 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
64019 +{
64020 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
64021 +}
64022 +
64023 + static __inline__ unsigned int
64024 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
64025 +{
64026 + return ((const unsigned long)userp % sz);
64027 +}
64028 +
64029 +static __inline__ unsigned int
64030 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
64031 +{
64032 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
64033 +}
64034 +
64035 +static __inline__ unsigned int
64036 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
64037 +{
64038 + return full_name_hash((const unsigned char *)name, len) % sz;
64039 +}
64040 +
64041 +#define FOR_EACH_ROLE_START(role) \
64042 + role = role_list; \
64043 + while (role) {
64044 +
64045 +#define FOR_EACH_ROLE_END(role) \
64046 + role = role->prev; \
64047 + }
64048 +
64049 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
64050 + subj = NULL; \
64051 + iter = 0; \
64052 + while (iter < role->subj_hash_size) { \
64053 + if (subj == NULL) \
64054 + subj = role->subj_hash[iter]; \
64055 + if (subj == NULL) { \
64056 + iter++; \
64057 + continue; \
64058 + }
64059 +
64060 +#define FOR_EACH_SUBJECT_END(subj,iter) \
64061 + subj = subj->next; \
64062 + if (subj == NULL) \
64063 + iter++; \
64064 + }
64065 +
64066 +
64067 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
64068 + subj = role->hash->first; \
64069 + while (subj != NULL) {
64070 +
64071 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
64072 + subj = subj->next; \
64073 + }
64074 +
64075 +#endif
64076 +
64077 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
64078 new file mode 100644
64079 index 0000000..323ecf2
64080 --- /dev/null
64081 +++ b/include/linux/gralloc.h
64082 @@ -0,0 +1,9 @@
64083 +#ifndef __GRALLOC_H
64084 +#define __GRALLOC_H
64085 +
64086 +void acl_free_all(void);
64087 +int acl_alloc_stack_init(unsigned long size);
64088 +void *acl_alloc(unsigned long len);
64089 +void *acl_alloc_num(unsigned long num, unsigned long len);
64090 +
64091 +#endif
64092 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
64093 new file mode 100644
64094 index 0000000..be66033
64095 --- /dev/null
64096 +++ b/include/linux/grdefs.h
64097 @@ -0,0 +1,140 @@
64098 +#ifndef GRDEFS_H
64099 +#define GRDEFS_H
64100 +
64101 +/* Begin grsecurity status declarations */
64102 +
64103 +enum {
64104 + GR_READY = 0x01,
64105 + GR_STATUS_INIT = 0x00 // disabled state
64106 +};
64107 +
64108 +/* Begin ACL declarations */
64109 +
64110 +/* Role flags */
64111 +
64112 +enum {
64113 + GR_ROLE_USER = 0x0001,
64114 + GR_ROLE_GROUP = 0x0002,
64115 + GR_ROLE_DEFAULT = 0x0004,
64116 + GR_ROLE_SPECIAL = 0x0008,
64117 + GR_ROLE_AUTH = 0x0010,
64118 + GR_ROLE_NOPW = 0x0020,
64119 + GR_ROLE_GOD = 0x0040,
64120 + GR_ROLE_LEARN = 0x0080,
64121 + GR_ROLE_TPE = 0x0100,
64122 + GR_ROLE_DOMAIN = 0x0200,
64123 + GR_ROLE_PAM = 0x0400,
64124 + GR_ROLE_PERSIST = 0x0800
64125 +};
64126 +
64127 +/* ACL Subject and Object mode flags */
64128 +enum {
64129 + GR_DELETED = 0x80000000
64130 +};
64131 +
64132 +/* ACL Object-only mode flags */
64133 +enum {
64134 + GR_READ = 0x00000001,
64135 + GR_APPEND = 0x00000002,
64136 + GR_WRITE = 0x00000004,
64137 + GR_EXEC = 0x00000008,
64138 + GR_FIND = 0x00000010,
64139 + GR_INHERIT = 0x00000020,
64140 + GR_SETID = 0x00000040,
64141 + GR_CREATE = 0x00000080,
64142 + GR_DELETE = 0x00000100,
64143 + GR_LINK = 0x00000200,
64144 + GR_AUDIT_READ = 0x00000400,
64145 + GR_AUDIT_APPEND = 0x00000800,
64146 + GR_AUDIT_WRITE = 0x00001000,
64147 + GR_AUDIT_EXEC = 0x00002000,
64148 + GR_AUDIT_FIND = 0x00004000,
64149 + GR_AUDIT_INHERIT= 0x00008000,
64150 + GR_AUDIT_SETID = 0x00010000,
64151 + GR_AUDIT_CREATE = 0x00020000,
64152 + GR_AUDIT_DELETE = 0x00040000,
64153 + GR_AUDIT_LINK = 0x00080000,
64154 + GR_PTRACERD = 0x00100000,
64155 + GR_NOPTRACE = 0x00200000,
64156 + GR_SUPPRESS = 0x00400000,
64157 + GR_NOLEARN = 0x00800000,
64158 + GR_INIT_TRANSFER= 0x01000000
64159 +};
64160 +
64161 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
64162 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
64163 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
64164 +
64165 +/* ACL subject-only mode flags */
64166 +enum {
64167 + GR_KILL = 0x00000001,
64168 + GR_VIEW = 0x00000002,
64169 + GR_PROTECTED = 0x00000004,
64170 + GR_LEARN = 0x00000008,
64171 + GR_OVERRIDE = 0x00000010,
64172 + /* just a placeholder, this mode is only used in userspace */
64173 + GR_DUMMY = 0x00000020,
64174 + GR_PROTSHM = 0x00000040,
64175 + GR_KILLPROC = 0x00000080,
64176 + GR_KILLIPPROC = 0x00000100,
64177 + /* just a placeholder, this mode is only used in userspace */
64178 + GR_NOTROJAN = 0x00000200,
64179 + GR_PROTPROCFD = 0x00000400,
64180 + GR_PROCACCT = 0x00000800,
64181 + GR_RELAXPTRACE = 0x00001000,
64182 + //GR_NESTED = 0x00002000,
64183 + GR_INHERITLEARN = 0x00004000,
64184 + GR_PROCFIND = 0x00008000,
64185 + GR_POVERRIDE = 0x00010000,
64186 + GR_KERNELAUTH = 0x00020000,
64187 + GR_ATSECURE = 0x00040000,
64188 + GR_SHMEXEC = 0x00080000
64189 +};
64190 +
64191 +enum {
64192 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
64193 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
64194 + GR_PAX_ENABLE_MPROTECT = 0x0004,
64195 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
64196 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
64197 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
64198 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
64199 + GR_PAX_DISABLE_MPROTECT = 0x0400,
64200 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
64201 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
64202 +};
64203 +
64204 +enum {
64205 + GR_ID_USER = 0x01,
64206 + GR_ID_GROUP = 0x02,
64207 +};
64208 +
64209 +enum {
64210 + GR_ID_ALLOW = 0x01,
64211 + GR_ID_DENY = 0x02,
64212 +};
64213 +
64214 +#define GR_CRASH_RES 31
64215 +#define GR_UIDTABLE_MAX 500
64216 +
64217 +/* begin resource learning section */
64218 +enum {
64219 + GR_RLIM_CPU_BUMP = 60,
64220 + GR_RLIM_FSIZE_BUMP = 50000,
64221 + GR_RLIM_DATA_BUMP = 10000,
64222 + GR_RLIM_STACK_BUMP = 1000,
64223 + GR_RLIM_CORE_BUMP = 10000,
64224 + GR_RLIM_RSS_BUMP = 500000,
64225 + GR_RLIM_NPROC_BUMP = 1,
64226 + GR_RLIM_NOFILE_BUMP = 5,
64227 + GR_RLIM_MEMLOCK_BUMP = 50000,
64228 + GR_RLIM_AS_BUMP = 500000,
64229 + GR_RLIM_LOCKS_BUMP = 2,
64230 + GR_RLIM_SIGPENDING_BUMP = 5,
64231 + GR_RLIM_MSGQUEUE_BUMP = 10000,
64232 + GR_RLIM_NICE_BUMP = 1,
64233 + GR_RLIM_RTPRIO_BUMP = 1,
64234 + GR_RLIM_RTTIME_BUMP = 1000000
64235 +};
64236 +
64237 +#endif
64238 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
64239 new file mode 100644
64240 index 0000000..baa6e96
64241 --- /dev/null
64242 +++ b/include/linux/grinternal.h
64243 @@ -0,0 +1,215 @@
64244 +#ifndef __GRINTERNAL_H
64245 +#define __GRINTERNAL_H
64246 +
64247 +#ifdef CONFIG_GRKERNSEC
64248 +
64249 +#include <linux/fs.h>
64250 +#include <linux/mnt_namespace.h>
64251 +#include <linux/nsproxy.h>
64252 +#include <linux/gracl.h>
64253 +#include <linux/grdefs.h>
64254 +#include <linux/grmsg.h>
64255 +
64256 +void gr_add_learn_entry(const char *fmt, ...)
64257 + __attribute__ ((format (printf, 1, 2)));
64258 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
64259 + const struct vfsmount *mnt);
64260 +__u32 gr_check_create(const struct dentry *new_dentry,
64261 + const struct dentry *parent,
64262 + const struct vfsmount *mnt, const __u32 mode);
64263 +int gr_check_protected_task(const struct task_struct *task);
64264 +__u32 to_gr_audit(const __u32 reqmode);
64265 +int gr_set_acls(const int type);
64266 +int gr_apply_subject_to_task(struct task_struct *task);
64267 +int gr_acl_is_enabled(void);
64268 +char gr_roletype_to_char(void);
64269 +
64270 +void gr_handle_alertkill(struct task_struct *task);
64271 +char *gr_to_filename(const struct dentry *dentry,
64272 + const struct vfsmount *mnt);
64273 +char *gr_to_filename1(const struct dentry *dentry,
64274 + const struct vfsmount *mnt);
64275 +char *gr_to_filename2(const struct dentry *dentry,
64276 + const struct vfsmount *mnt);
64277 +char *gr_to_filename3(const struct dentry *dentry,
64278 + const struct vfsmount *mnt);
64279 +
64280 +extern int grsec_enable_ptrace_readexec;
64281 +extern int grsec_enable_harden_ptrace;
64282 +extern int grsec_enable_link;
64283 +extern int grsec_enable_fifo;
64284 +extern int grsec_enable_execve;
64285 +extern int grsec_enable_shm;
64286 +extern int grsec_enable_execlog;
64287 +extern int grsec_enable_signal;
64288 +extern int grsec_enable_audit_ptrace;
64289 +extern int grsec_enable_forkfail;
64290 +extern int grsec_enable_time;
64291 +extern int grsec_enable_rofs;
64292 +extern int grsec_enable_chroot_shmat;
64293 +extern int grsec_enable_chroot_mount;
64294 +extern int grsec_enable_chroot_double;
64295 +extern int grsec_enable_chroot_pivot;
64296 +extern int grsec_enable_chroot_chdir;
64297 +extern int grsec_enable_chroot_chmod;
64298 +extern int grsec_enable_chroot_mknod;
64299 +extern int grsec_enable_chroot_fchdir;
64300 +extern int grsec_enable_chroot_nice;
64301 +extern int grsec_enable_chroot_execlog;
64302 +extern int grsec_enable_chroot_caps;
64303 +extern int grsec_enable_chroot_sysctl;
64304 +extern int grsec_enable_chroot_unix;
64305 +extern int grsec_enable_symlinkown;
64306 +extern int grsec_symlinkown_gid;
64307 +extern int grsec_enable_tpe;
64308 +extern int grsec_tpe_gid;
64309 +extern int grsec_enable_tpe_all;
64310 +extern int grsec_enable_tpe_invert;
64311 +extern int grsec_enable_socket_all;
64312 +extern int grsec_socket_all_gid;
64313 +extern int grsec_enable_socket_client;
64314 +extern int grsec_socket_client_gid;
64315 +extern int grsec_enable_socket_server;
64316 +extern int grsec_socket_server_gid;
64317 +extern int grsec_audit_gid;
64318 +extern int grsec_enable_group;
64319 +extern int grsec_enable_audit_textrel;
64320 +extern int grsec_enable_log_rwxmaps;
64321 +extern int grsec_enable_mount;
64322 +extern int grsec_enable_chdir;
64323 +extern int grsec_resource_logging;
64324 +extern int grsec_enable_blackhole;
64325 +extern int grsec_lastack_retries;
64326 +extern int grsec_enable_brute;
64327 +extern int grsec_lock;
64328 +
64329 +extern spinlock_t grsec_alert_lock;
64330 +extern unsigned long grsec_alert_wtime;
64331 +extern unsigned long grsec_alert_fyet;
64332 +
64333 +extern spinlock_t grsec_audit_lock;
64334 +
64335 +extern rwlock_t grsec_exec_file_lock;
64336 +
64337 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
64338 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
64339 + (tsk)->exec_file->f_vfsmnt) : "/")
64340 +
64341 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
64342 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
64343 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
64344 +
64345 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
64346 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
64347 + (tsk)->exec_file->f_vfsmnt) : "/")
64348 +
64349 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
64350 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
64351 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
64352 +
64353 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
64354 +
64355 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
64356 +
64357 +#define GR_CHROOT_CAPS {{ \
64358 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
64359 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
64360 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
64361 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
64362 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
64363 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
64364 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
64365 +
64366 +#define security_learn(normal_msg,args...) \
64367 +({ \
64368 + read_lock(&grsec_exec_file_lock); \
64369 + gr_add_learn_entry(normal_msg "\n", ## args); \
64370 + read_unlock(&grsec_exec_file_lock); \
64371 +})
64372 +
64373 +enum {
64374 + GR_DO_AUDIT,
64375 + GR_DONT_AUDIT,
64376 + /* used for non-audit messages that we shouldn't kill the task on */
64377 + GR_DONT_AUDIT_GOOD
64378 +};
64379 +
64380 +enum {
64381 + GR_TTYSNIFF,
64382 + GR_RBAC,
64383 + GR_RBAC_STR,
64384 + GR_STR_RBAC,
64385 + GR_RBAC_MODE2,
64386 + GR_RBAC_MODE3,
64387 + GR_FILENAME,
64388 + GR_SYSCTL_HIDDEN,
64389 + GR_NOARGS,
64390 + GR_ONE_INT,
64391 + GR_ONE_INT_TWO_STR,
64392 + GR_ONE_STR,
64393 + GR_STR_INT,
64394 + GR_TWO_STR_INT,
64395 + GR_TWO_INT,
64396 + GR_TWO_U64,
64397 + GR_THREE_INT,
64398 + GR_FIVE_INT_TWO_STR,
64399 + GR_TWO_STR,
64400 + GR_THREE_STR,
64401 + GR_FOUR_STR,
64402 + GR_STR_FILENAME,
64403 + GR_FILENAME_STR,
64404 + GR_FILENAME_TWO_INT,
64405 + GR_FILENAME_TWO_INT_STR,
64406 + GR_TEXTREL,
64407 + GR_PTRACE,
64408 + GR_RESOURCE,
64409 + GR_CAP,
64410 + GR_SIG,
64411 + GR_SIG2,
64412 + GR_CRASH1,
64413 + GR_CRASH2,
64414 + GR_PSACCT,
64415 + GR_RWXMAP
64416 +};
64417 +
64418 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
64419 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
64420 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
64421 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
64422 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
64423 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
64424 +#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)
64425 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
64426 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
64427 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
64428 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
64429 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
64430 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
64431 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
64432 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
64433 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
64434 +#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)
64435 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
64436 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
64437 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
64438 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
64439 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
64440 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
64441 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
64442 +#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)
64443 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
64444 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
64445 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
64446 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
64447 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
64448 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
64449 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
64450 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
64451 +#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)
64452 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
64453 +
64454 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
64455 +
64456 +#endif
64457 +
64458 +#endif
64459 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
64460 new file mode 100644
64461 index 0000000..2bd4c8d
64462 --- /dev/null
64463 +++ b/include/linux/grmsg.h
64464 @@ -0,0 +1,111 @@
64465 +#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"
64466 +#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"
64467 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
64468 +#define GR_STOPMOD_MSG "denied modification of module state by "
64469 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
64470 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
64471 +#define GR_IOPERM_MSG "denied use of ioperm() by "
64472 +#define GR_IOPL_MSG "denied use of iopl() by "
64473 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
64474 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
64475 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
64476 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
64477 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
64478 +#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"
64479 +#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"
64480 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
64481 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
64482 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
64483 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
64484 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
64485 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
64486 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
64487 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
64488 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
64489 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
64490 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
64491 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
64492 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
64493 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
64494 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
64495 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
64496 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
64497 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
64498 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
64499 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
64500 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
64501 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
64502 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
64503 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
64504 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
64505 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
64506 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
64507 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
64508 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
64509 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
64510 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
64511 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
64512 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
64513 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
64514 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
64515 +#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"
64516 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
64517 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
64518 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
64519 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
64520 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
64521 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
64522 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
64523 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
64524 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
64525 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
64526 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
64527 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
64528 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
64529 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
64530 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
64531 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
64532 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
64533 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
64534 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
64535 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
64536 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
64537 +#define GR_NICE_CHROOT_MSG "denied priority change by "
64538 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
64539 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
64540 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
64541 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
64542 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
64543 +#define GR_TIME_MSG "time set by "
64544 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
64545 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
64546 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
64547 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
64548 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
64549 +#define GR_BIND_MSG "denied bind() by "
64550 +#define GR_CONNECT_MSG "denied connect() by "
64551 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
64552 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
64553 +#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"
64554 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
64555 +#define GR_CAP_ACL_MSG "use of %s denied for "
64556 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
64557 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
64558 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
64559 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
64560 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
64561 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
64562 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
64563 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
64564 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
64565 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
64566 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
64567 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
64568 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
64569 +#define GR_VM86_MSG "denied use of vm86 by "
64570 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
64571 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
64572 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
64573 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
64574 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
64575 +#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 "
64576 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
64577 new file mode 100644
64578 index 0000000..c5e5913
64579 --- /dev/null
64580 +++ b/include/linux/grsecurity.h
64581 @@ -0,0 +1,257 @@
64582 +#ifndef GR_SECURITY_H
64583 +#define GR_SECURITY_H
64584 +#include <linux/fs.h>
64585 +#include <linux/fs_struct.h>
64586 +#include <linux/binfmts.h>
64587 +#include <linux/gracl.h>
64588 +
64589 +/* notify of brain-dead configs */
64590 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64591 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
64592 +#endif
64593 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
64594 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
64595 +#endif
64596 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
64597 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
64598 +#endif
64599 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
64600 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
64601 +#endif
64602 +
64603 +#include <linux/compat.h>
64604 +
64605 +struct user_arg_ptr {
64606 +#ifdef CONFIG_COMPAT
64607 + bool is_compat;
64608 +#endif
64609 + union {
64610 + const char __user *const __user *native;
64611 +#ifdef CONFIG_COMPAT
64612 + const compat_uptr_t __user *compat;
64613 +#endif
64614 + } ptr;
64615 +};
64616 +
64617 +void gr_handle_brute_attach(unsigned long mm_flags);
64618 +void gr_handle_brute_check(void);
64619 +void gr_handle_kernel_exploit(void);
64620 +int gr_process_user_ban(void);
64621 +
64622 +char gr_roletype_to_char(void);
64623 +
64624 +int gr_acl_enable_at_secure(void);
64625 +
64626 +int gr_check_user_change(int real, int effective, int fs);
64627 +int gr_check_group_change(int real, int effective, int fs);
64628 +
64629 +void gr_del_task_from_ip_table(struct task_struct *p);
64630 +
64631 +int gr_pid_is_chrooted(struct task_struct *p);
64632 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
64633 +int gr_handle_chroot_nice(void);
64634 +int gr_handle_chroot_sysctl(const int op);
64635 +int gr_handle_chroot_setpriority(struct task_struct *p,
64636 + const int niceval);
64637 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
64638 +int gr_handle_chroot_chroot(const struct dentry *dentry,
64639 + const struct vfsmount *mnt);
64640 +void gr_handle_chroot_chdir(struct path *path);
64641 +int gr_handle_chroot_chmod(const struct dentry *dentry,
64642 + const struct vfsmount *mnt, const int mode);
64643 +int gr_handle_chroot_mknod(const struct dentry *dentry,
64644 + const struct vfsmount *mnt, const int mode);
64645 +int gr_handle_chroot_mount(const struct dentry *dentry,
64646 + const struct vfsmount *mnt,
64647 + const char *dev_name);
64648 +int gr_handle_chroot_pivot(void);
64649 +int gr_handle_chroot_unix(const pid_t pid);
64650 +
64651 +int gr_handle_rawio(const struct inode *inode);
64652 +
64653 +void gr_handle_ioperm(void);
64654 +void gr_handle_iopl(void);
64655 +
64656 +umode_t gr_acl_umask(void);
64657 +
64658 +int gr_tpe_allow(const struct file *file);
64659 +
64660 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
64661 +void gr_clear_chroot_entries(struct task_struct *task);
64662 +
64663 +void gr_log_forkfail(const int retval);
64664 +void gr_log_timechange(void);
64665 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
64666 +void gr_log_chdir(const struct dentry *dentry,
64667 + const struct vfsmount *mnt);
64668 +void gr_log_chroot_exec(const struct dentry *dentry,
64669 + const struct vfsmount *mnt);
64670 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
64671 +void gr_log_remount(const char *devname, const int retval);
64672 +void gr_log_unmount(const char *devname, const int retval);
64673 +void gr_log_mount(const char *from, const char *to, const int retval);
64674 +void gr_log_textrel(struct vm_area_struct *vma);
64675 +void gr_log_rwxmmap(struct file *file);
64676 +void gr_log_rwxmprotect(struct file *file);
64677 +
64678 +int gr_handle_follow_link(const struct inode *parent,
64679 + const struct inode *inode,
64680 + const struct dentry *dentry,
64681 + const struct vfsmount *mnt);
64682 +int gr_handle_fifo(const struct dentry *dentry,
64683 + const struct vfsmount *mnt,
64684 + const struct dentry *dir, const int flag,
64685 + const int acc_mode);
64686 +int gr_handle_hardlink(const struct dentry *dentry,
64687 + const struct vfsmount *mnt,
64688 + struct inode *inode,
64689 + const int mode, const struct filename *to);
64690 +
64691 +int gr_is_capable(const int cap);
64692 +int gr_is_capable_nolog(const int cap);
64693 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64694 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
64695 +
64696 +void gr_copy_label(struct task_struct *tsk);
64697 +void gr_handle_crash(struct task_struct *task, const int sig);
64698 +int gr_handle_signal(const struct task_struct *p, const int sig);
64699 +int gr_check_crash_uid(const uid_t uid);
64700 +int gr_check_protected_task(const struct task_struct *task);
64701 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
64702 +int gr_acl_handle_mmap(const struct file *file,
64703 + const unsigned long prot);
64704 +int gr_acl_handle_mprotect(const struct file *file,
64705 + const unsigned long prot);
64706 +int gr_check_hidden_task(const struct task_struct *tsk);
64707 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
64708 + const struct vfsmount *mnt);
64709 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
64710 + const struct vfsmount *mnt);
64711 +__u32 gr_acl_handle_access(const struct dentry *dentry,
64712 + const struct vfsmount *mnt, const int fmode);
64713 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
64714 + const struct vfsmount *mnt, umode_t *mode);
64715 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
64716 + const struct vfsmount *mnt);
64717 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
64718 + const struct vfsmount *mnt);
64719 +int gr_handle_ptrace(struct task_struct *task, const long request);
64720 +int gr_handle_proc_ptrace(struct task_struct *task);
64721 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
64722 + const struct vfsmount *mnt);
64723 +int gr_check_crash_exec(const struct file *filp);
64724 +int gr_acl_is_enabled(void);
64725 +void gr_set_kernel_label(struct task_struct *task);
64726 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
64727 + const gid_t gid);
64728 +int gr_set_proc_label(const struct dentry *dentry,
64729 + const struct vfsmount *mnt,
64730 + const int unsafe_flags);
64731 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
64732 + const struct vfsmount *mnt);
64733 +__u32 gr_acl_handle_open(const struct dentry *dentry,
64734 + const struct vfsmount *mnt, int acc_mode);
64735 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
64736 + const struct dentry *p_dentry,
64737 + const struct vfsmount *p_mnt,
64738 + int open_flags, int acc_mode, const int imode);
64739 +void gr_handle_create(const struct dentry *dentry,
64740 + const struct vfsmount *mnt);
64741 +void gr_handle_proc_create(const struct dentry *dentry,
64742 + const struct inode *inode);
64743 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
64744 + const struct dentry *parent_dentry,
64745 + const struct vfsmount *parent_mnt,
64746 + const int mode);
64747 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
64748 + const struct dentry *parent_dentry,
64749 + const struct vfsmount *parent_mnt);
64750 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
64751 + const struct vfsmount *mnt);
64752 +void gr_handle_delete(const ino_t ino, const dev_t dev);
64753 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
64754 + const struct vfsmount *mnt);
64755 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
64756 + const struct dentry *parent_dentry,
64757 + const struct vfsmount *parent_mnt,
64758 + const struct filename *from);
64759 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
64760 + const struct dentry *parent_dentry,
64761 + const struct vfsmount *parent_mnt,
64762 + const struct dentry *old_dentry,
64763 + const struct vfsmount *old_mnt, const struct filename *to);
64764 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
64765 +int gr_acl_handle_rename(struct dentry *new_dentry,
64766 + struct dentry *parent_dentry,
64767 + const struct vfsmount *parent_mnt,
64768 + struct dentry *old_dentry,
64769 + struct inode *old_parent_inode,
64770 + struct vfsmount *old_mnt, const struct filename *newname);
64771 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64772 + struct dentry *old_dentry,
64773 + struct dentry *new_dentry,
64774 + struct vfsmount *mnt, const __u8 replace);
64775 +__u32 gr_check_link(const struct dentry *new_dentry,
64776 + const struct dentry *parent_dentry,
64777 + const struct vfsmount *parent_mnt,
64778 + const struct dentry *old_dentry,
64779 + const struct vfsmount *old_mnt);
64780 +int gr_acl_handle_filldir(const struct file *file, const char *name,
64781 + const unsigned int namelen, const ino_t ino);
64782 +
64783 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
64784 + const struct vfsmount *mnt);
64785 +void gr_acl_handle_exit(void);
64786 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
64787 +int gr_acl_handle_procpidmem(const struct task_struct *task);
64788 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
64789 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
64790 +void gr_audit_ptrace(struct task_struct *task);
64791 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
64792 +void gr_put_exec_file(struct task_struct *task);
64793 +
64794 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
64795 +
64796 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
64797 +extern void gr_learn_resource(const struct task_struct *task, const int res,
64798 + const unsigned long wanted, const int gt);
64799 +#else
64800 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
64801 + const unsigned long wanted, const int gt)
64802 +{
64803 +}
64804 +#endif
64805 +
64806 +#ifdef CONFIG_GRKERNSEC_RESLOG
64807 +extern void gr_log_resource(const struct task_struct *task, const int res,
64808 + const unsigned long wanted, const int gt);
64809 +#else
64810 +static inline void gr_log_resource(const struct task_struct *task, const int res,
64811 + const unsigned long wanted, const int gt)
64812 +{
64813 +}
64814 +#endif
64815 +
64816 +#ifdef CONFIG_GRKERNSEC
64817 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
64818 +void gr_handle_vm86(void);
64819 +void gr_handle_mem_readwrite(u64 from, u64 to);
64820 +
64821 +void gr_log_badprocpid(const char *entry);
64822 +
64823 +extern int grsec_enable_dmesg;
64824 +extern int grsec_disable_privio;
64825 +
64826 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64827 +extern int grsec_proc_gid;
64828 +#endif
64829 +
64830 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64831 +extern int grsec_enable_chroot_findtask;
64832 +#endif
64833 +#ifdef CONFIG_GRKERNSEC_SETXID
64834 +extern int grsec_enable_setxid;
64835 +#endif
64836 +#endif
64837 +
64838 +#endif
64839 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
64840 new file mode 100644
64841 index 0000000..e7ffaaf
64842 --- /dev/null
64843 +++ b/include/linux/grsock.h
64844 @@ -0,0 +1,19 @@
64845 +#ifndef __GRSOCK_H
64846 +#define __GRSOCK_H
64847 +
64848 +extern void gr_attach_curr_ip(const struct sock *sk);
64849 +extern int gr_handle_sock_all(const int family, const int type,
64850 + const int protocol);
64851 +extern int gr_handle_sock_server(const struct sockaddr *sck);
64852 +extern int gr_handle_sock_server_other(const struct sock *sck);
64853 +extern int gr_handle_sock_client(const struct sockaddr *sck);
64854 +extern int gr_search_connect(struct socket * sock,
64855 + struct sockaddr_in * addr);
64856 +extern int gr_search_bind(struct socket * sock,
64857 + struct sockaddr_in * addr);
64858 +extern int gr_search_listen(struct socket * sock);
64859 +extern int gr_search_accept(struct socket * sock);
64860 +extern int gr_search_socket(const int domain, const int type,
64861 + const int protocol);
64862 +
64863 +#endif
64864 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
64865 index ef788b5..ac41b7b 100644
64866 --- a/include/linux/highmem.h
64867 +++ b/include/linux/highmem.h
64868 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
64869 kunmap_atomic(kaddr);
64870 }
64871
64872 +static inline void sanitize_highpage(struct page *page)
64873 +{
64874 + void *kaddr;
64875 + unsigned long flags;
64876 +
64877 + local_irq_save(flags);
64878 + kaddr = kmap_atomic(page);
64879 + clear_page(kaddr);
64880 + kunmap_atomic(kaddr);
64881 + local_irq_restore(flags);
64882 +}
64883 +
64884 static inline void zero_user_segments(struct page *page,
64885 unsigned start1, unsigned end1,
64886 unsigned start2, unsigned end2)
64887 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
64888 index 800de22..7a2fa46 100644
64889 --- a/include/linux/i2c.h
64890 +++ b/include/linux/i2c.h
64891 @@ -367,6 +367,7 @@ struct i2c_algorithm {
64892 /* To determine what the adapter supports */
64893 u32 (*functionality) (struct i2c_adapter *);
64894 };
64895 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
64896
64897 /*
64898 * i2c_adapter is the structure used to identify a physical i2c bus along
64899 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
64900 index d23c3c2..eb63c81 100644
64901 --- a/include/linux/i2o.h
64902 +++ b/include/linux/i2o.h
64903 @@ -565,7 +565,7 @@ struct i2o_controller {
64904 struct i2o_device *exec; /* Executive */
64905 #if BITS_PER_LONG == 64
64906 spinlock_t context_list_lock; /* lock for context_list */
64907 - atomic_t context_list_counter; /* needed for unique contexts */
64908 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
64909 struct list_head context_list; /* list of context id's
64910 and pointers */
64911 #endif
64912 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
64913 index aff7ad8..3942bbd 100644
64914 --- a/include/linux/if_pppox.h
64915 +++ b/include/linux/if_pppox.h
64916 @@ -76,7 +76,7 @@ struct pppox_proto {
64917 int (*ioctl)(struct socket *sock, unsigned int cmd,
64918 unsigned long arg);
64919 struct module *owner;
64920 -};
64921 +} __do_const;
64922
64923 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
64924 extern void unregister_pppox_proto(int proto_num);
64925 diff --git a/include/linux/init.h b/include/linux/init.h
64926 index e59041e..df0a975 100644
64927 --- a/include/linux/init.h
64928 +++ b/include/linux/init.h
64929 @@ -39,9 +39,36 @@
64930 * Also note, that this data cannot be "const".
64931 */
64932
64933 +#ifdef MODULE
64934 +#define add_init_latent_entropy
64935 +#define add_devinit_latent_entropy
64936 +#define add_cpuinit_latent_entropy
64937 +#define add_meminit_latent_entropy
64938 +#else
64939 +#define add_init_latent_entropy __latent_entropy
64940 +
64941 +#ifdef CONFIG_HOTPLUG
64942 +#define add_devinit_latent_entropy
64943 +#else
64944 +#define add_devinit_latent_entropy __latent_entropy
64945 +#endif
64946 +
64947 +#ifdef CONFIG_HOTPLUG_CPU
64948 +#define add_cpuinit_latent_entropy
64949 +#else
64950 +#define add_cpuinit_latent_entropy __latent_entropy
64951 +#endif
64952 +
64953 +#ifdef CONFIG_MEMORY_HOTPLUG
64954 +#define add_meminit_latent_entropy
64955 +#else
64956 +#define add_meminit_latent_entropy __latent_entropy
64957 +#endif
64958 +#endif
64959 +
64960 /* These are for everybody (although not all archs will actually
64961 discard it in modules) */
64962 -#define __init __section(.init.text) __cold notrace
64963 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
64964 #define __initdata __section(.init.data)
64965 #define __initconst __constsection(.init.rodata)
64966 #define __exitdata __section(.exit.data)
64967 @@ -94,7 +121,7 @@
64968 #define __exit __section(.exit.text) __exitused __cold notrace
64969
64970 /* Used for HOTPLUG */
64971 -#define __devinit __section(.devinit.text) __cold notrace
64972 +#define __devinit __section(.devinit.text) __cold notrace add_devinit_latent_entropy
64973 #define __devinitdata __section(.devinit.data)
64974 #define __devinitconst __constsection(.devinit.rodata)
64975 #define __devexit __section(.devexit.text) __exitused __cold notrace
64976 @@ -102,7 +129,7 @@
64977 #define __devexitconst __constsection(.devexit.rodata)
64978
64979 /* Used for HOTPLUG_CPU */
64980 -#define __cpuinit __section(.cpuinit.text) __cold notrace
64981 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
64982 #define __cpuinitdata __section(.cpuinit.data)
64983 #define __cpuinitconst __constsection(.cpuinit.rodata)
64984 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
64985 @@ -110,7 +137,7 @@
64986 #define __cpuexitconst __constsection(.cpuexit.rodata)
64987
64988 /* Used for MEMORY_HOTPLUG */
64989 -#define __meminit __section(.meminit.text) __cold notrace
64990 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
64991 #define __meminitdata __section(.meminit.data)
64992 #define __meminitconst __constsection(.meminit.rodata)
64993 #define __memexit __section(.memexit.text) __exitused __cold notrace
64994 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
64995 index 6d087c5..401cab8 100644
64996 --- a/include/linux/init_task.h
64997 +++ b/include/linux/init_task.h
64998 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
64999
65000 #define INIT_TASK_COMM "swapper"
65001
65002 +#ifdef CONFIG_X86
65003 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
65004 +#else
65005 +#define INIT_TASK_THREAD_INFO
65006 +#endif
65007 +
65008 /*
65009 * INIT_TASK is used to set up the first task table, touch at
65010 * your own risk!. Base=0, limit=0x1fffff (=2MB)
65011 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
65012 RCU_POINTER_INITIALIZER(cred, &init_cred), \
65013 .comm = INIT_TASK_COMM, \
65014 .thread = INIT_THREAD, \
65015 + INIT_TASK_THREAD_INFO \
65016 .fs = &init_fs, \
65017 .files = &init_files, \
65018 .signal = &init_signals, \
65019 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
65020 index 5e4e617..eee383d 100644
65021 --- a/include/linux/interrupt.h
65022 +++ b/include/linux/interrupt.h
65023 @@ -435,7 +435,7 @@ enum
65024 /* map softirq index to softirq name. update 'softirq_to_name' in
65025 * kernel/softirq.c when adding a new softirq.
65026 */
65027 -extern char *softirq_to_name[NR_SOFTIRQS];
65028 +extern const char * const softirq_to_name[NR_SOFTIRQS];
65029
65030 /* softirq mask and active fields moved to irq_cpustat_t in
65031 * asm/hardirq.h to get better cache usage. KAO
65032 @@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
65033
65034 struct softirq_action
65035 {
65036 - void (*action)(struct softirq_action *);
65037 + void (*action)(void);
65038 };
65039
65040 asmlinkage void do_softirq(void);
65041 asmlinkage void __do_softirq(void);
65042 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
65043 +extern void open_softirq(int nr, void (*action)(void));
65044 extern void softirq_init(void);
65045 extern void __raise_softirq_irqoff(unsigned int nr);
65046
65047 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
65048 index 6883e19..06992b1 100644
65049 --- a/include/linux/kallsyms.h
65050 +++ b/include/linux/kallsyms.h
65051 @@ -15,7 +15,8 @@
65052
65053 struct module;
65054
65055 -#ifdef CONFIG_KALLSYMS
65056 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
65057 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65058 /* Lookup the address for a symbol. Returns 0 if not found. */
65059 unsigned long kallsyms_lookup_name(const char *name);
65060
65061 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
65062 /* Stupid that this does nothing, but I didn't create this mess. */
65063 #define __print_symbol(fmt, addr)
65064 #endif /*CONFIG_KALLSYMS*/
65065 +#else /* when included by kallsyms.c, vsnprintf.c, or
65066 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
65067 +extern void __print_symbol(const char *fmt, unsigned long address);
65068 +extern int sprint_backtrace(char *buffer, unsigned long address);
65069 +extern int sprint_symbol(char *buffer, unsigned long address);
65070 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
65071 +const char *kallsyms_lookup(unsigned long addr,
65072 + unsigned long *symbolsize,
65073 + unsigned long *offset,
65074 + char **modname, char *namebuf);
65075 +#endif
65076
65077 /* This macro allows us to keep printk typechecking */
65078 static __printf(1, 2)
65079 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
65080 index 4dff0c6..1ca9b72 100644
65081 --- a/include/linux/kgdb.h
65082 +++ b/include/linux/kgdb.h
65083 @@ -53,7 +53,7 @@ extern int kgdb_connected;
65084 extern int kgdb_io_module_registered;
65085
65086 extern atomic_t kgdb_setting_breakpoint;
65087 -extern atomic_t kgdb_cpu_doing_single_step;
65088 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
65089
65090 extern struct task_struct *kgdb_usethread;
65091 extern struct task_struct *kgdb_contthread;
65092 @@ -255,7 +255,7 @@ struct kgdb_arch {
65093 void (*correct_hw_break)(void);
65094
65095 void (*enable_nmi)(bool on);
65096 -};
65097 +} __do_const;
65098
65099 /**
65100 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
65101 @@ -280,7 +280,7 @@ struct kgdb_io {
65102 void (*pre_exception) (void);
65103 void (*post_exception) (void);
65104 int is_console;
65105 -};
65106 +} __do_const;
65107
65108 extern struct kgdb_arch arch_kgdb_ops;
65109
65110 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
65111 index 5398d58..5883a34 100644
65112 --- a/include/linux/kmod.h
65113 +++ b/include/linux/kmod.h
65114 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
65115 * usually useless though. */
65116 extern __printf(2, 3)
65117 int __request_module(bool wait, const char *name, ...);
65118 +extern __printf(3, 4)
65119 +int ___request_module(bool wait, char *param_name, const char *name, ...);
65120 #define request_module(mod...) __request_module(true, mod)
65121 #define request_module_nowait(mod...) __request_module(false, mod)
65122 #define try_then_request_module(x, mod...) \
65123 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
65124 index 1e57449..4fede7b 100644
65125 --- a/include/linux/kobject.h
65126 +++ b/include/linux/kobject.h
65127 @@ -111,7 +111,7 @@ struct kobj_type {
65128 struct attribute **default_attrs;
65129 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
65130 const void *(*namespace)(struct kobject *kobj);
65131 -};
65132 +} __do_const;
65133
65134 struct kobj_uevent_env {
65135 char *envp[UEVENT_NUM_ENVP];
65136 diff --git a/include/linux/kref.h b/include/linux/kref.h
65137 index 65af688..0592677 100644
65138 --- a/include/linux/kref.h
65139 +++ b/include/linux/kref.h
65140 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
65141 static inline int kref_sub(struct kref *kref, unsigned int count,
65142 void (*release)(struct kref *kref))
65143 {
65144 - WARN_ON(release == NULL);
65145 + BUG_ON(release == NULL);
65146
65147 if (atomic_sub_and_test((int) count, &kref->refcount)) {
65148 release(kref);
65149 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
65150 index ecc5543..0e96bcc 100644
65151 --- a/include/linux/kvm_host.h
65152 +++ b/include/linux/kvm_host.h
65153 @@ -403,7 +403,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
65154 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
65155 void vcpu_put(struct kvm_vcpu *vcpu);
65156
65157 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65158 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65159 struct module *module);
65160 void kvm_exit(void);
65161
65162 @@ -558,7 +558,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
65163 struct kvm_guest_debug *dbg);
65164 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
65165
65166 -int kvm_arch_init(void *opaque);
65167 +int kvm_arch_init(const void *opaque);
65168 void kvm_arch_exit(void);
65169
65170 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
65171 diff --git a/include/linux/libata.h b/include/linux/libata.h
65172 index 1e36c63..0c5046e 100644
65173 --- a/include/linux/libata.h
65174 +++ b/include/linux/libata.h
65175 @@ -915,7 +915,7 @@ struct ata_port_operations {
65176 * fields must be pointers.
65177 */
65178 const struct ata_port_operations *inherits;
65179 -};
65180 +} __do_const;
65181
65182 struct ata_port_info {
65183 unsigned long flags;
65184 diff --git a/include/linux/list.h b/include/linux/list.h
65185 index cc6d2aa..71febca 100644
65186 --- a/include/linux/list.h
65187 +++ b/include/linux/list.h
65188 @@ -112,6 +112,9 @@ extern void __list_del_entry(struct list_head *entry);
65189 extern void list_del(struct list_head *entry);
65190 #endif
65191
65192 +extern void pax_list_add_tail(struct list_head *new, struct list_head *head);
65193 +extern void pax_list_del(struct list_head *entry);
65194 +
65195 /**
65196 * list_replace - replace old entry by new one
65197 * @old : the element to be replaced
65198 diff --git a/include/linux/mm.h b/include/linux/mm.h
65199 index 280dae5..39046ec 100644
65200 --- a/include/linux/mm.h
65201 +++ b/include/linux/mm.h
65202 @@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
65203 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
65204 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
65205 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
65206 +
65207 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
65208 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
65209 +#endif
65210 +
65211 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
65212
65213 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
65214 @@ -1039,34 +1044,6 @@ int set_page_dirty(struct page *page);
65215 int set_page_dirty_lock(struct page *page);
65216 int clear_page_dirty_for_io(struct page *page);
65217
65218 -/* Is the vma a continuation of the stack vma above it? */
65219 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
65220 -{
65221 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
65222 -}
65223 -
65224 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
65225 - unsigned long addr)
65226 -{
65227 - return (vma->vm_flags & VM_GROWSDOWN) &&
65228 - (vma->vm_start == addr) &&
65229 - !vma_growsdown(vma->vm_prev, addr);
65230 -}
65231 -
65232 -/* Is the vma a continuation of the stack vma below it? */
65233 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
65234 -{
65235 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
65236 -}
65237 -
65238 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
65239 - unsigned long addr)
65240 -{
65241 - return (vma->vm_flags & VM_GROWSUP) &&
65242 - (vma->vm_end == addr) &&
65243 - !vma_growsup(vma->vm_next, addr);
65244 -}
65245 -
65246 extern pid_t
65247 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
65248
65249 @@ -1166,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
65250 }
65251 #endif
65252
65253 +#ifdef CONFIG_MMU
65254 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
65255 +#else
65256 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
65257 +{
65258 + return __pgprot(0);
65259 +}
65260 +#endif
65261 +
65262 int vma_wants_writenotify(struct vm_area_struct *vma);
65263
65264 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
65265 @@ -1184,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
65266 {
65267 return 0;
65268 }
65269 +
65270 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
65271 + unsigned long address)
65272 +{
65273 + return 0;
65274 +}
65275 #else
65276 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
65277 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
65278 #endif
65279
65280 #ifdef __PAGETABLE_PMD_FOLDED
65281 @@ -1194,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
65282 {
65283 return 0;
65284 }
65285 +
65286 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
65287 + unsigned long address)
65288 +{
65289 + return 0;
65290 +}
65291 #else
65292 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
65293 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
65294 #endif
65295
65296 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
65297 @@ -1213,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
65298 NULL: pud_offset(pgd, address);
65299 }
65300
65301 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
65302 +{
65303 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
65304 + NULL: pud_offset(pgd, address);
65305 +}
65306 +
65307 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
65308 {
65309 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
65310 NULL: pmd_offset(pud, address);
65311 }
65312 +
65313 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
65314 +{
65315 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
65316 + NULL: pmd_offset(pud, address);
65317 +}
65318 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
65319
65320 #if USE_SPLIT_PTLOCKS
65321 @@ -1447,6 +1459,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
65322 unsigned long, unsigned long,
65323 unsigned long, unsigned long);
65324 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
65325 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
65326
65327 /* These take the mm semaphore themselves */
65328 extern unsigned long vm_brk(unsigned long, unsigned long);
65329 @@ -1510,6 +1523,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
65330 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
65331 struct vm_area_struct **pprev);
65332
65333 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
65334 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
65335 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
65336 +
65337 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
65338 NULL if none. Assume start_addr < end_addr. */
65339 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
65340 @@ -1538,15 +1555,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
65341 return vma;
65342 }
65343
65344 -#ifdef CONFIG_MMU
65345 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
65346 -#else
65347 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
65348 -{
65349 - return __pgprot(0);
65350 -}
65351 -#endif
65352 -
65353 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
65354 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
65355 unsigned long pfn, unsigned long size, pgprot_t);
65356 @@ -1652,7 +1660,7 @@ extern int unpoison_memory(unsigned long pfn);
65357 extern int sysctl_memory_failure_early_kill;
65358 extern int sysctl_memory_failure_recovery;
65359 extern void shake_page(struct page *p, int access);
65360 -extern atomic_long_t mce_bad_pages;
65361 +extern atomic_long_unchecked_t mce_bad_pages;
65362 extern int soft_offline_page(struct page *page, int flags);
65363
65364 extern void dump_page(struct page *page);
65365 @@ -1683,5 +1691,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
65366 static inline bool page_is_guard(struct page *page) { return false; }
65367 #endif /* CONFIG_DEBUG_PAGEALLOC */
65368
65369 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
65370 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
65371 +#else
65372 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
65373 +#endif
65374 +
65375 #endif /* __KERNEL__ */
65376 #endif /* _LINUX_MM_H */
65377 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
65378 index 31f8a3a..499f1db 100644
65379 --- a/include/linux/mm_types.h
65380 +++ b/include/linux/mm_types.h
65381 @@ -275,6 +275,8 @@ struct vm_area_struct {
65382 #ifdef CONFIG_NUMA
65383 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
65384 #endif
65385 +
65386 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
65387 };
65388
65389 struct core_thread {
65390 @@ -348,7 +350,7 @@ struct mm_struct {
65391 unsigned long def_flags;
65392 unsigned long nr_ptes; /* Page table pages */
65393 unsigned long start_code, end_code, start_data, end_data;
65394 - unsigned long start_brk, brk, start_stack;
65395 + unsigned long brk_gap, start_brk, brk, start_stack;
65396 unsigned long arg_start, arg_end, env_start, env_end;
65397
65398 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
65399 @@ -399,6 +401,24 @@ struct mm_struct {
65400 struct cpumask cpumask_allocation;
65401 #endif
65402 struct uprobes_state uprobes_state;
65403 +
65404 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65405 + unsigned long pax_flags;
65406 +#endif
65407 +
65408 +#ifdef CONFIG_PAX_DLRESOLVE
65409 + unsigned long call_dl_resolve;
65410 +#endif
65411 +
65412 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
65413 + unsigned long call_syscall;
65414 +#endif
65415 +
65416 +#ifdef CONFIG_PAX_ASLR
65417 + unsigned long delta_mmap; /* randomized offset */
65418 + unsigned long delta_stack; /* randomized offset */
65419 +#endif
65420 +
65421 };
65422
65423 static inline void mm_init_cpumask(struct mm_struct *mm)
65424 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
65425 index c5d5278..f0b68c8 100644
65426 --- a/include/linux/mmiotrace.h
65427 +++ b/include/linux/mmiotrace.h
65428 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
65429 /* Called from ioremap.c */
65430 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
65431 void __iomem *addr);
65432 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
65433 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
65434
65435 /* For anyone to insert markers. Remember trailing newline. */
65436 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
65437 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
65438 {
65439 }
65440
65441 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
65442 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
65443 {
65444 }
65445
65446 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
65447 index a23923b..073fee4 100644
65448 --- a/include/linux/mmzone.h
65449 +++ b/include/linux/mmzone.h
65450 @@ -421,7 +421,7 @@ struct zone {
65451 unsigned long flags; /* zone flags, see below */
65452
65453 /* Zone statistics */
65454 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65455 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65456
65457 /*
65458 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
65459 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
65460 index fed3def..7cc3f93 100644
65461 --- a/include/linux/mod_devicetable.h
65462 +++ b/include/linux/mod_devicetable.h
65463 @@ -12,7 +12,7 @@
65464 typedef unsigned long kernel_ulong_t;
65465 #endif
65466
65467 -#define PCI_ANY_ID (~0)
65468 +#define PCI_ANY_ID ((__u16)~0)
65469
65470 struct pci_device_id {
65471 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
65472 @@ -139,7 +139,7 @@ struct usb_device_id {
65473 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
65474 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
65475
65476 -#define HID_ANY_ID (~0)
65477 +#define HID_ANY_ID (~0U)
65478 #define HID_BUS_ANY 0xffff
65479 #define HID_GROUP_ANY 0x0000
65480
65481 diff --git a/include/linux/module.h b/include/linux/module.h
65482 index 1375ee3..d631af0 100644
65483 --- a/include/linux/module.h
65484 +++ b/include/linux/module.h
65485 @@ -17,9 +17,11 @@
65486 #include <linux/moduleparam.h>
65487 #include <linux/tracepoint.h>
65488 #include <linux/export.h>
65489 +#include <linux/fs.h>
65490
65491 #include <linux/percpu.h>
65492 #include <asm/module.h>
65493 +#include <asm/pgtable.h>
65494
65495 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
65496 #define MODULE_SIG_STRING "~Module signature appended~\n"
65497 @@ -281,19 +283,16 @@ struct module
65498 int (*init)(void);
65499
65500 /* If this is non-NULL, vfree after init() returns */
65501 - void *module_init;
65502 + void *module_init_rx, *module_init_rw;
65503
65504 /* Here is the actual code + data, vfree'd on unload. */
65505 - void *module_core;
65506 + void *module_core_rx, *module_core_rw;
65507
65508 /* Here are the sizes of the init and core sections */
65509 - unsigned int init_size, core_size;
65510 + unsigned int init_size_rw, core_size_rw;
65511
65512 /* The size of the executable code in each section. */
65513 - unsigned int init_text_size, core_text_size;
65514 -
65515 - /* Size of RO sections of the module (text+rodata) */
65516 - unsigned int init_ro_size, core_ro_size;
65517 + unsigned int init_size_rx, core_size_rx;
65518
65519 /* Arch-specific module values */
65520 struct mod_arch_specific arch;
65521 @@ -349,6 +348,10 @@ struct module
65522 #ifdef CONFIG_EVENT_TRACING
65523 struct ftrace_event_call **trace_events;
65524 unsigned int num_trace_events;
65525 + struct file_operations trace_id;
65526 + struct file_operations trace_enable;
65527 + struct file_operations trace_format;
65528 + struct file_operations trace_filter;
65529 #endif
65530 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
65531 unsigned int num_ftrace_callsites;
65532 @@ -396,16 +399,46 @@ bool is_module_address(unsigned long addr);
65533 bool is_module_percpu_address(unsigned long addr);
65534 bool is_module_text_address(unsigned long addr);
65535
65536 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
65537 +{
65538 +
65539 +#ifdef CONFIG_PAX_KERNEXEC
65540 + if (ktla_ktva(addr) >= (unsigned long)start &&
65541 + ktla_ktva(addr) < (unsigned long)start + size)
65542 + return 1;
65543 +#endif
65544 +
65545 + return ((void *)addr >= start && (void *)addr < start + size);
65546 +}
65547 +
65548 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
65549 +{
65550 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
65551 +}
65552 +
65553 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
65554 +{
65555 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
65556 +}
65557 +
65558 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
65559 +{
65560 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
65561 +}
65562 +
65563 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
65564 +{
65565 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
65566 +}
65567 +
65568 static inline int within_module_core(unsigned long addr, struct module *mod)
65569 {
65570 - return (unsigned long)mod->module_core <= addr &&
65571 - addr < (unsigned long)mod->module_core + mod->core_size;
65572 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
65573 }
65574
65575 static inline int within_module_init(unsigned long addr, struct module *mod)
65576 {
65577 - return (unsigned long)mod->module_init <= addr &&
65578 - addr < (unsigned long)mod->module_init + mod->init_size;
65579 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
65580 }
65581
65582 /* Search for module by name: must hold module_mutex. */
65583 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
65584 index 560ca53..5ee8d73 100644
65585 --- a/include/linux/moduleloader.h
65586 +++ b/include/linux/moduleloader.h
65587 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
65588
65589 /* Allocator used for allocating struct module, core sections and init
65590 sections. Returns NULL on failure. */
65591 -void *module_alloc(unsigned long size);
65592 +void *module_alloc(unsigned long size) __size_overflow(1);
65593 +
65594 +#ifdef CONFIG_PAX_KERNEXEC
65595 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
65596 +#else
65597 +#define module_alloc_exec(x) module_alloc(x)
65598 +#endif
65599
65600 /* Free memory returned from module_alloc. */
65601 void module_free(struct module *mod, void *module_region);
65602
65603 +#ifdef CONFIG_PAX_KERNEXEC
65604 +void module_free_exec(struct module *mod, void *module_region);
65605 +#else
65606 +#define module_free_exec(x, y) module_free((x), (y))
65607 +#endif
65608 +
65609 /*
65610 * Apply the given relocation to the (simplified) ELF. Return -error
65611 * or 0.
65612 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
65613 unsigned int relsec,
65614 struct module *me)
65615 {
65616 +#ifdef CONFIG_MODULES
65617 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65618 +#endif
65619 return -ENOEXEC;
65620 }
65621 #endif
65622 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
65623 unsigned int relsec,
65624 struct module *me)
65625 {
65626 +#ifdef CONFIG_MODULES
65627 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65628 +#endif
65629 return -ENOEXEC;
65630 }
65631 #endif
65632 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
65633 index d6a5806..7c13347 100644
65634 --- a/include/linux/moduleparam.h
65635 +++ b/include/linux/moduleparam.h
65636 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
65637 * @len is usually just sizeof(string).
65638 */
65639 #define module_param_string(name, string, len, perm) \
65640 - static const struct kparam_string __param_string_##name \
65641 + static const struct kparam_string __param_string_##name __used \
65642 = { len, string }; \
65643 __module_param_call(MODULE_PARAM_PREFIX, name, \
65644 &param_ops_string, \
65645 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
65646 */
65647 #define module_param_array_named(name, array, type, nump, perm) \
65648 param_check_##type(name, &(array)[0]); \
65649 - static const struct kparam_array __param_arr_##name \
65650 + static const struct kparam_array __param_arr_##name __used \
65651 = { .max = ARRAY_SIZE(array), .num = nump, \
65652 .ops = &param_ops_##type, \
65653 .elemsize = sizeof(array[0]), .elem = array }; \
65654 diff --git a/include/linux/namei.h b/include/linux/namei.h
65655 index 4bf19d8..5268cea 100644
65656 --- a/include/linux/namei.h
65657 +++ b/include/linux/namei.h
65658 @@ -18,7 +18,7 @@ struct nameidata {
65659 unsigned seq;
65660 int last_type;
65661 unsigned depth;
65662 - char *saved_names[MAX_NESTED_LINKS + 1];
65663 + const char *saved_names[MAX_NESTED_LINKS + 1];
65664 };
65665
65666 /*
65667 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
65668
65669 extern void nd_jump_link(struct nameidata *nd, struct path *path);
65670
65671 -static inline void nd_set_link(struct nameidata *nd, char *path)
65672 +static inline void nd_set_link(struct nameidata *nd, const char *path)
65673 {
65674 nd->saved_names[nd->depth] = path;
65675 }
65676
65677 -static inline char *nd_get_link(struct nameidata *nd)
65678 +static inline const char *nd_get_link(const struct nameidata *nd)
65679 {
65680 return nd->saved_names[nd->depth];
65681 }
65682 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
65683 index 825fb7e..24cdd41 100644
65684 --- a/include/linux/netdevice.h
65685 +++ b/include/linux/netdevice.h
65686 @@ -1002,6 +1002,7 @@ struct net_device_ops {
65687 struct net_device *dev,
65688 int idx);
65689 };
65690 +typedef struct net_device_ops __no_const net_device_ops_no_const;
65691
65692 /*
65693 * The DEVICE structure.
65694 @@ -1062,7 +1063,7 @@ struct net_device {
65695 int iflink;
65696
65697 struct net_device_stats stats;
65698 - atomic_long_t rx_dropped; /* dropped packets by core network
65699 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
65700 * Do not use this in drivers.
65701 */
65702
65703 diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
65704 index 7958e84..ed74d7a 100644
65705 --- a/include/linux/netfilter/ipset/ip_set.h
65706 +++ b/include/linux/netfilter/ipset/ip_set.h
65707 @@ -98,7 +98,7 @@ struct ip_set_type_variant {
65708 /* Return true if "b" set is the same as "a"
65709 * according to the create set parameters */
65710 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
65711 -};
65712 +} __do_const;
65713
65714 /* The core set type structure */
65715 struct ip_set_type {
65716 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
65717 index 4966dde..7d8ce06 100644
65718 --- a/include/linux/netfilter/nfnetlink.h
65719 +++ b/include/linux/netfilter/nfnetlink.h
65720 @@ -16,7 +16,7 @@ struct nfnl_callback {
65721 const struct nlattr * const cda[]);
65722 const struct nla_policy *policy; /* netlink attribute policy */
65723 const u_int16_t attr_count; /* number of nlattr's */
65724 -};
65725 +} __do_const;
65726
65727 struct nfnetlink_subsystem {
65728 const char *name;
65729 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
65730 new file mode 100644
65731 index 0000000..33f4af8
65732 --- /dev/null
65733 +++ b/include/linux/netfilter/xt_gradm.h
65734 @@ -0,0 +1,9 @@
65735 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
65736 +#define _LINUX_NETFILTER_XT_GRADM_H 1
65737 +
65738 +struct xt_gradm_mtinfo {
65739 + __u16 flags;
65740 + __u16 invflags;
65741 +};
65742 +
65743 +#endif
65744 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
65745 index d65746e..62e72c2 100644
65746 --- a/include/linux/notifier.h
65747 +++ b/include/linux/notifier.h
65748 @@ -51,7 +51,8 @@ struct notifier_block {
65749 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
65750 struct notifier_block __rcu *next;
65751 int priority;
65752 -};
65753 +} __do_const;
65754 +typedef struct notifier_block __no_const notifier_block_no_const;
65755
65756 struct atomic_notifier_head {
65757 spinlock_t lock;
65758 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
65759 index a4c5624..79d6d88 100644
65760 --- a/include/linux/oprofile.h
65761 +++ b/include/linux/oprofile.h
65762 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
65763 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
65764 char const * name, ulong * val);
65765
65766 -/** Create a file for read-only access to an atomic_t. */
65767 +/** Create a file for read-only access to an atomic_unchecked_t. */
65768 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
65769 - char const * name, atomic_t * val);
65770 + char const * name, atomic_unchecked_t * val);
65771
65772 /** create a directory */
65773 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
65774 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
65775 index 6bfb2faa..1204767 100644
65776 --- a/include/linux/perf_event.h
65777 +++ b/include/linux/perf_event.h
65778 @@ -328,8 +328,8 @@ struct perf_event {
65779
65780 enum perf_event_active_state state;
65781 unsigned int attach_state;
65782 - local64_t count;
65783 - atomic64_t child_count;
65784 + local64_t count; /* PaX: fix it one day */
65785 + atomic64_unchecked_t child_count;
65786
65787 /*
65788 * These are the total time in nanoseconds that the event
65789 @@ -380,8 +380,8 @@ struct perf_event {
65790 * These accumulate total time (in nanoseconds) that children
65791 * events have been enabled and running, respectively.
65792 */
65793 - atomic64_t child_total_time_enabled;
65794 - atomic64_t child_total_time_running;
65795 + atomic64_unchecked_t child_total_time_enabled;
65796 + atomic64_unchecked_t child_total_time_running;
65797
65798 /*
65799 * Protect attach/detach and child_list:
65800 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
65801 index ad1a427..6419649 100644
65802 --- a/include/linux/pipe_fs_i.h
65803 +++ b/include/linux/pipe_fs_i.h
65804 @@ -45,9 +45,9 @@ struct pipe_buffer {
65805 struct pipe_inode_info {
65806 wait_queue_head_t wait;
65807 unsigned int nrbufs, curbuf, buffers;
65808 - unsigned int readers;
65809 - unsigned int writers;
65810 - unsigned int waiting_writers;
65811 + atomic_t readers;
65812 + atomic_t writers;
65813 + atomic_t waiting_writers;
65814 unsigned int r_counter;
65815 unsigned int w_counter;
65816 struct page *tmp_page;
65817 diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
65818 index 5f28cae..3d23723 100644
65819 --- a/include/linux/platform_data/usb-ehci-s5p.h
65820 +++ b/include/linux/platform_data/usb-ehci-s5p.h
65821 @@ -14,7 +14,7 @@
65822 struct s5p_ehci_platdata {
65823 int (*phy_init)(struct platform_device *pdev, int type);
65824 int (*phy_exit)(struct platform_device *pdev, int type);
65825 -};
65826 +} __no_const;
65827
65828 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
65829
65830 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
65831 index f271860..6b3bec5 100644
65832 --- a/include/linux/pm_runtime.h
65833 +++ b/include/linux/pm_runtime.h
65834 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
65835
65836 static inline void pm_runtime_mark_last_busy(struct device *dev)
65837 {
65838 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
65839 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
65840 }
65841
65842 #else /* !CONFIG_PM_RUNTIME */
65843 diff --git a/include/linux/poison.h b/include/linux/poison.h
65844 index 2110a81..13a11bb 100644
65845 --- a/include/linux/poison.h
65846 +++ b/include/linux/poison.h
65847 @@ -19,8 +19,8 @@
65848 * under normal circumstances, used to verify that nobody uses
65849 * non-initialized list entries.
65850 */
65851 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
65852 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
65853 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
65854 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
65855
65856 /********** include/linux/timer.h **********/
65857 /*
65858 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
65859 index 4a496eb..d9c5659 100644
65860 --- a/include/linux/power/smartreflex.h
65861 +++ b/include/linux/power/smartreflex.h
65862 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
65863 int (*notify)(struct omap_sr *sr, u32 status);
65864 u8 notify_flags;
65865 u8 class_type;
65866 -};
65867 +} __do_const;
65868
65869 /**
65870 * struct omap_sr_nvalue_table - Smartreflex n-target value info
65871 diff --git a/include/linux/printk.h b/include/linux/printk.h
65872 index 9afc01e..92c32e8 100644
65873 --- a/include/linux/printk.h
65874 +++ b/include/linux/printk.h
65875 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
65876 extern int printk_needs_cpu(int cpu);
65877 extern void printk_tick(void);
65878
65879 +extern int kptr_restrict;
65880 +
65881 #ifdef CONFIG_PRINTK
65882 asmlinkage __printf(5, 0)
65883 int vprintk_emit(int facility, int level,
65884 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
65885
65886 extern int printk_delay_msec;
65887 extern int dmesg_restrict;
65888 -extern int kptr_restrict;
65889
65890 void log_buf_kexec_setup(void);
65891 void __init setup_log_buf(int early);
65892 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
65893 index 3fd2e87..75db910 100644
65894 --- a/include/linux/proc_fs.h
65895 +++ b/include/linux/proc_fs.h
65896 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
65897 return proc_create_data(name, mode, parent, proc_fops, NULL);
65898 }
65899
65900 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
65901 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
65902 +{
65903 +#ifdef CONFIG_GRKERNSEC_PROC_USER
65904 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
65905 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65906 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
65907 +#else
65908 + return proc_create_data(name, mode, parent, proc_fops, NULL);
65909 +#endif
65910 +}
65911 +
65912 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
65913 umode_t mode, struct proc_dir_entry *base,
65914 read_proc_t *read_proc, void * data)
65915 diff --git a/include/linux/random.h b/include/linux/random.h
65916 index 6330ed4..419c6c3 100644
65917 --- a/include/linux/random.h
65918 +++ b/include/linux/random.h
65919 @@ -30,12 +30,17 @@ void srandom32(u32 seed);
65920
65921 u32 prandom32(struct rnd_state *);
65922
65923 +static inline unsigned long pax_get_random_long(void)
65924 +{
65925 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
65926 +}
65927 +
65928 /*
65929 * Handle minimum values for seeds
65930 */
65931 static inline u32 __seed(u32 x, u32 m)
65932 {
65933 - return (x < m) ? x + m : x;
65934 + return (x <= m) ? x + m + 1 : x;
65935 }
65936
65937 /**
65938 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
65939 index 23b3630..e1bc12b 100644
65940 --- a/include/linux/reboot.h
65941 +++ b/include/linux/reboot.h
65942 @@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
65943 * Architecture-specific implementations of sys_reboot commands.
65944 */
65945
65946 -extern void machine_restart(char *cmd);
65947 -extern void machine_halt(void);
65948 -extern void machine_power_off(void);
65949 +extern void machine_restart(char *cmd) __noreturn;
65950 +extern void machine_halt(void) __noreturn;
65951 +extern void machine_power_off(void) __noreturn;
65952
65953 extern void machine_shutdown(void);
65954 struct pt_regs;
65955 @@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
65956 */
65957
65958 extern void kernel_restart_prepare(char *cmd);
65959 -extern void kernel_restart(char *cmd);
65960 -extern void kernel_halt(void);
65961 -extern void kernel_power_off(void);
65962 +extern void kernel_restart(char *cmd) __noreturn;
65963 +extern void kernel_halt(void) __noreturn;
65964 +extern void kernel_power_off(void) __noreturn;
65965
65966 extern int C_A_D; /* for sysctl */
65967 void ctrl_alt_del(void);
65968 @@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
65969 * Emergency restart, callable from an interrupt handler.
65970 */
65971
65972 -extern void emergency_restart(void);
65973 +extern void emergency_restart(void) __noreturn;
65974 #include <asm/emergency-restart.h>
65975
65976 #endif /* _LINUX_REBOOT_H */
65977 diff --git a/include/linux/regset.h b/include/linux/regset.h
65978 index 8e0c9fe..fdb64bc 100644
65979 --- a/include/linux/regset.h
65980 +++ b/include/linux/regset.h
65981 @@ -161,7 +161,7 @@ struct user_regset {
65982 unsigned int align;
65983 unsigned int bias;
65984 unsigned int core_note_type;
65985 -};
65986 +} __do_const;
65987
65988 /**
65989 * struct user_regset_view - available regsets
65990 diff --git a/include/linux/relay.h b/include/linux/relay.h
65991 index 91cacc3..b55ff74 100644
65992 --- a/include/linux/relay.h
65993 +++ b/include/linux/relay.h
65994 @@ -160,7 +160,7 @@ struct rchan_callbacks
65995 * The callback should return 0 if successful, negative if not.
65996 */
65997 int (*remove_buf_file)(struct dentry *dentry);
65998 -};
65999 +} __no_const;
66000
66001 /*
66002 * CONFIG_RELAY kernel API, kernel/relay.c
66003 diff --git a/include/linux/rio.h b/include/linux/rio.h
66004 index a3e7842..d973ca6 100644
66005 --- a/include/linux/rio.h
66006 +++ b/include/linux/rio.h
66007 @@ -339,7 +339,7 @@ struct rio_ops {
66008 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
66009 u64 rstart, u32 size, u32 flags);
66010 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
66011 -};
66012 +} __no_const;
66013
66014 #define RIO_RESOURCE_MEM 0x00000100
66015 #define RIO_RESOURCE_DOORBELL 0x00000200
66016 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
66017 index bfe1f47..6a33ee3 100644
66018 --- a/include/linux/rmap.h
66019 +++ b/include/linux/rmap.h
66020 @@ -134,8 +134,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
66021 void anon_vma_init(void); /* create anon_vma_cachep */
66022 int anon_vma_prepare(struct vm_area_struct *);
66023 void unlink_anon_vmas(struct vm_area_struct *);
66024 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
66025 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
66026 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
66027 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
66028
66029 static inline void anon_vma_merge(struct vm_area_struct *vma,
66030 struct vm_area_struct *next)
66031 diff --git a/include/linux/sched.h b/include/linux/sched.h
66032 index 3e63925..6c93b17 100644
66033 --- a/include/linux/sched.h
66034 +++ b/include/linux/sched.h
66035 @@ -61,6 +61,7 @@ struct bio_list;
66036 struct fs_struct;
66037 struct perf_event_context;
66038 struct blk_plug;
66039 +struct linux_binprm;
66040
66041 /*
66042 * List of flags we want to share for kernel threads,
66043 @@ -344,10 +345,23 @@ struct user_namespace;
66044 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
66045
66046 extern int sysctl_max_map_count;
66047 +extern unsigned long sysctl_heap_stack_gap;
66048
66049 #include <linux/aio.h>
66050
66051 #ifdef CONFIG_MMU
66052 +
66053 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
66054 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
66055 +#else
66056 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
66057 +{
66058 + return 0;
66059 +}
66060 +#endif
66061 +
66062 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
66063 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
66064 extern void arch_pick_mmap_layout(struct mm_struct *mm);
66065 extern unsigned long
66066 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
66067 @@ -614,6 +628,17 @@ struct signal_struct {
66068 #ifdef CONFIG_TASKSTATS
66069 struct taskstats *stats;
66070 #endif
66071 +
66072 +#ifdef CONFIG_GRKERNSEC
66073 + u32 curr_ip;
66074 + u32 saved_ip;
66075 + u32 gr_saddr;
66076 + u32 gr_daddr;
66077 + u16 gr_sport;
66078 + u16 gr_dport;
66079 + u8 used_accept:1;
66080 +#endif
66081 +
66082 #ifdef CONFIG_AUDIT
66083 unsigned audit_tty;
66084 struct tty_audit_buf *tty_audit_buf;
66085 @@ -691,6 +716,11 @@ struct user_struct {
66086 struct key *session_keyring; /* UID's default session keyring */
66087 #endif
66088
66089 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66090 + unsigned int banned;
66091 + unsigned long ban_expires;
66092 +#endif
66093 +
66094 /* Hash table maintenance information */
66095 struct hlist_node uidhash_node;
66096 kuid_t uid;
66097 @@ -1312,8 +1342,8 @@ struct task_struct {
66098 struct list_head thread_group;
66099
66100 struct completion *vfork_done; /* for vfork() */
66101 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
66102 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66103 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
66104 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66105
66106 cputime_t utime, stime, utimescaled, stimescaled;
66107 cputime_t gtime;
66108 @@ -1329,11 +1359,6 @@ struct task_struct {
66109 struct task_cputime cputime_expires;
66110 struct list_head cpu_timers[3];
66111
66112 -/* process credentials */
66113 - const struct cred __rcu *real_cred; /* objective and real subjective task
66114 - * credentials (COW) */
66115 - const struct cred __rcu *cred; /* effective (overridable) subjective task
66116 - * credentials (COW) */
66117 char comm[TASK_COMM_LEN]; /* executable name excluding path
66118 - access with [gs]et_task_comm (which lock
66119 it with task_lock())
66120 @@ -1350,6 +1375,10 @@ struct task_struct {
66121 #endif
66122 /* CPU-specific state of this task */
66123 struct thread_struct thread;
66124 +/* thread_info moved to task_struct */
66125 +#ifdef CONFIG_X86
66126 + struct thread_info tinfo;
66127 +#endif
66128 /* filesystem information */
66129 struct fs_struct *fs;
66130 /* open file information */
66131 @@ -1423,6 +1452,10 @@ struct task_struct {
66132 gfp_t lockdep_reclaim_gfp;
66133 #endif
66134
66135 +/* process credentials */
66136 + const struct cred __rcu *real_cred; /* objective and real subjective task
66137 + * credentials (COW) */
66138 +
66139 /* journalling filesystem info */
66140 void *journal_info;
66141
66142 @@ -1461,6 +1494,10 @@ struct task_struct {
66143 /* cg_list protected by css_set_lock and tsk->alloc_lock */
66144 struct list_head cg_list;
66145 #endif
66146 +
66147 + const struct cred __rcu *cred; /* effective (overridable) subjective task
66148 + * credentials (COW) */
66149 +
66150 #ifdef CONFIG_FUTEX
66151 struct robust_list_head __user *robust_list;
66152 #ifdef CONFIG_COMPAT
66153 @@ -1548,8 +1585,74 @@ struct task_struct {
66154 #ifdef CONFIG_UPROBES
66155 struct uprobe_task *utask;
66156 #endif
66157 +
66158 +#ifdef CONFIG_GRKERNSEC
66159 + /* grsecurity */
66160 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66161 + u64 exec_id;
66162 +#endif
66163 +#ifdef CONFIG_GRKERNSEC_SETXID
66164 + const struct cred *delayed_cred;
66165 +#endif
66166 + struct dentry *gr_chroot_dentry;
66167 + struct acl_subject_label *acl;
66168 + struct acl_role_label *role;
66169 + struct file *exec_file;
66170 + unsigned long brute_expires;
66171 + u16 acl_role_id;
66172 + /* is this the task that authenticated to the special role */
66173 + u8 acl_sp_role;
66174 + u8 is_writable;
66175 + u8 brute;
66176 + u8 gr_is_chrooted;
66177 +#endif
66178 +
66179 };
66180
66181 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
66182 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
66183 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
66184 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
66185 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
66186 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
66187 +
66188 +#ifdef CONFIG_PAX_SOFTMODE
66189 +extern int pax_softmode;
66190 +#endif
66191 +
66192 +extern int pax_check_flags(unsigned long *);
66193 +
66194 +/* if tsk != current then task_lock must be held on it */
66195 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66196 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
66197 +{
66198 + if (likely(tsk->mm))
66199 + return tsk->mm->pax_flags;
66200 + else
66201 + return 0UL;
66202 +}
66203 +
66204 +/* if tsk != current then task_lock must be held on it */
66205 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
66206 +{
66207 + if (likely(tsk->mm)) {
66208 + tsk->mm->pax_flags = flags;
66209 + return 0;
66210 + }
66211 + return -EINVAL;
66212 +}
66213 +#endif
66214 +
66215 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
66216 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
66217 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
66218 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
66219 +#endif
66220 +
66221 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
66222 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
66223 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
66224 +
66225 /* Future-safe accessor for struct task_struct's cpus_allowed. */
66226 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
66227
66228 @@ -2092,7 +2195,9 @@ void yield(void);
66229 extern struct exec_domain default_exec_domain;
66230
66231 union thread_union {
66232 +#ifndef CONFIG_X86
66233 struct thread_info thread_info;
66234 +#endif
66235 unsigned long stack[THREAD_SIZE/sizeof(long)];
66236 };
66237
66238 @@ -2125,6 +2230,7 @@ extern struct pid_namespace init_pid_ns;
66239 */
66240
66241 extern struct task_struct *find_task_by_vpid(pid_t nr);
66242 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
66243 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
66244 struct pid_namespace *ns);
66245
66246 @@ -2281,7 +2387,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
66247 extern void exit_itimers(struct signal_struct *);
66248 extern void flush_itimer_signals(void);
66249
66250 -extern void do_group_exit(int);
66251 +extern __noreturn void do_group_exit(int);
66252
66253 extern void daemonize(const char *, ...);
66254 extern int allow_signal(int);
66255 @@ -2485,9 +2591,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
66256
66257 #endif
66258
66259 -static inline int object_is_on_stack(void *obj)
66260 +static inline int object_starts_on_stack(void *obj)
66261 {
66262 - void *stack = task_stack_page(current);
66263 + const void *stack = task_stack_page(current);
66264
66265 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
66266 }
66267 diff --git a/include/linux/security.h b/include/linux/security.h
66268 index 05e88bd..5cda002 100644
66269 --- a/include/linux/security.h
66270 +++ b/include/linux/security.h
66271 @@ -26,6 +26,7 @@
66272 #include <linux/capability.h>
66273 #include <linux/slab.h>
66274 #include <linux/err.h>
66275 +#include <linux/grsecurity.h>
66276
66277 struct linux_binprm;
66278 struct cred;
66279 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
66280 index 68a04a3..866e6a1 100644
66281 --- a/include/linux/seq_file.h
66282 +++ b/include/linux/seq_file.h
66283 @@ -26,6 +26,9 @@ struct seq_file {
66284 struct mutex lock;
66285 const struct seq_operations *op;
66286 int poll_event;
66287 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66288 + u64 exec_id;
66289 +#endif
66290 #ifdef CONFIG_USER_NS
66291 struct user_namespace *user_ns;
66292 #endif
66293 @@ -38,6 +41,7 @@ struct seq_operations {
66294 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
66295 int (*show) (struct seq_file *m, void *v);
66296 };
66297 +typedef struct seq_operations __no_const seq_operations_no_const;
66298
66299 #define SEQ_SKIP 1
66300
66301 diff --git a/include/linux/shm.h b/include/linux/shm.h
66302 index bcf8a6a..4d0af77 100644
66303 --- a/include/linux/shm.h
66304 +++ b/include/linux/shm.h
66305 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
66306
66307 /* The task created the shm object. NULL if the task is dead. */
66308 struct task_struct *shm_creator;
66309 +#ifdef CONFIG_GRKERNSEC
66310 + time_t shm_createtime;
66311 + pid_t shm_lapid;
66312 +#endif
66313 };
66314
66315 /* shm_mode upper byte flags */
66316 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
66317 index 6a2c34e..a1f320f 100644
66318 --- a/include/linux/skbuff.h
66319 +++ b/include/linux/skbuff.h
66320 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
66321 extern struct sk_buff *__alloc_skb(unsigned int size,
66322 gfp_t priority, int flags, int node);
66323 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
66324 -static inline struct sk_buff *alloc_skb(unsigned int size,
66325 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
66326 gfp_t priority)
66327 {
66328 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
66329 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
66330 */
66331 static inline int skb_queue_empty(const struct sk_buff_head *list)
66332 {
66333 - return list->next == (struct sk_buff *)list;
66334 + return list->next == (const struct sk_buff *)list;
66335 }
66336
66337 /**
66338 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
66339 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
66340 const struct sk_buff *skb)
66341 {
66342 - return skb->next == (struct sk_buff *)list;
66343 + return skb->next == (const struct sk_buff *)list;
66344 }
66345
66346 /**
66347 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
66348 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
66349 const struct sk_buff *skb)
66350 {
66351 - return skb->prev == (struct sk_buff *)list;
66352 + return skb->prev == (const struct sk_buff *)list;
66353 }
66354
66355 /**
66356 @@ -1626,7 +1626,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
66357 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
66358 */
66359 #ifndef NET_SKB_PAD
66360 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
66361 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
66362 #endif
66363
66364 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
66365 @@ -2204,7 +2204,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
66366 int noblock, int *err);
66367 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
66368 struct poll_table_struct *wait);
66369 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
66370 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
66371 int offset, struct iovec *to,
66372 int size);
66373 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
66374 diff --git a/include/linux/slab.h b/include/linux/slab.h
66375 index 83d1a14..e23d723 100644
66376 --- a/include/linux/slab.h
66377 +++ b/include/linux/slab.h
66378 @@ -11,12 +11,20 @@
66379
66380 #include <linux/gfp.h>
66381 #include <linux/types.h>
66382 +#include <linux/err.h>
66383
66384 /*
66385 * Flags to pass to kmem_cache_create().
66386 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
66387 */
66388 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
66389 +
66390 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66391 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
66392 +#else
66393 +#define SLAB_USERCOPY 0x00000000UL
66394 +#endif
66395 +
66396 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
66397 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
66398 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
66399 @@ -87,10 +95,13 @@
66400 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
66401 * Both make kfree a no-op.
66402 */
66403 -#define ZERO_SIZE_PTR ((void *)16)
66404 +#define ZERO_SIZE_PTR \
66405 +({ \
66406 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
66407 + (void *)(-MAX_ERRNO-1L); \
66408 +})
66409
66410 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
66411 - (unsigned long)ZERO_SIZE_PTR)
66412 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
66413
66414 /*
66415 * Common fields provided in kmem_cache by all slab allocators
66416 @@ -110,7 +121,7 @@ struct kmem_cache {
66417 unsigned int align; /* Alignment as calculated */
66418 unsigned long flags; /* Active flags on the slab */
66419 const char *name; /* Slab name for sysfs */
66420 - int refcount; /* Use counter */
66421 + atomic_t refcount; /* Use counter */
66422 void (*ctor)(void *); /* Called on object slot creation */
66423 struct list_head list; /* List of all slab caches on the system */
66424 };
66425 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
66426 void kfree(const void *);
66427 void kzfree(const void *);
66428 size_t ksize(const void *);
66429 +const char *check_heap_object(const void *ptr, unsigned long n);
66430 +bool is_usercopy_object(const void *ptr);
66431
66432 /*
66433 * Allocator specific definitions. These are mainly used to establish optimized
66434 @@ -264,8 +277,18 @@ size_t ksize(const void *);
66435 * for general use, and so are not documented here. For a full list of
66436 * potential flags, always refer to linux/gfp.h.
66437 */
66438 +
66439 +extern void kmalloc_array_error(void)
66440 +#if defined(CONFIG_GCOV_KERNEL) && defined(CONFIG_PAX_SIZE_OVERFLOW)
66441 +__compiletime_warning("kmalloc_array called with swapped arguments?");
66442 +#else
66443 +__compiletime_error("kmalloc_array called with swapped arguments?");
66444 +#endif
66445 +
66446 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
66447 {
66448 + if (__builtin_constant_p(n) && !__builtin_constant_p(size))
66449 + kmalloc_array_error();
66450 if (size != 0 && n > SIZE_MAX / size)
66451 return NULL;
66452 return __kmalloc(n * size, flags);
66453 @@ -323,7 +346,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
66454 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66455 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66456 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66457 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66458 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
66459 #define kmalloc_track_caller(size, flags) \
66460 __kmalloc_track_caller(size, flags, _RET_IP_)
66461 #else
66462 @@ -343,7 +366,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66463 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66464 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66465 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66466 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
66467 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
66468 #define kmalloc_node_track_caller(size, flags, node) \
66469 __kmalloc_node_track_caller(size, flags, node, \
66470 _RET_IP_)
66471 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
66472 index cc290f0..0ba60931 100644
66473 --- a/include/linux/slab_def.h
66474 +++ b/include/linux/slab_def.h
66475 @@ -52,7 +52,7 @@ struct kmem_cache {
66476 /* 4) cache creation/removal */
66477 const char *name;
66478 struct list_head list;
66479 - int refcount;
66480 + atomic_t refcount;
66481 int object_size;
66482 int align;
66483
66484 @@ -68,10 +68,10 @@ struct kmem_cache {
66485 unsigned long node_allocs;
66486 unsigned long node_frees;
66487 unsigned long node_overflow;
66488 - atomic_t allochit;
66489 - atomic_t allocmiss;
66490 - atomic_t freehit;
66491 - atomic_t freemiss;
66492 + atomic_unchecked_t allochit;
66493 + atomic_unchecked_t allocmiss;
66494 + atomic_unchecked_t freehit;
66495 + atomic_unchecked_t freemiss;
66496
66497 /*
66498 * If debugging is enabled, then the allocator can add additional
66499 @@ -104,11 +104,16 @@ struct cache_sizes {
66500 #ifdef CONFIG_ZONE_DMA
66501 struct kmem_cache *cs_dmacachep;
66502 #endif
66503 +
66504 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66505 + struct kmem_cache *cs_usercopycachep;
66506 +#endif
66507 +
66508 };
66509 extern struct cache_sizes malloc_sizes[];
66510
66511 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66512 -void *__kmalloc(size_t size, gfp_t flags);
66513 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
66514
66515 #ifdef CONFIG_TRACING
66516 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
66517 @@ -145,6 +150,13 @@ found:
66518 cachep = malloc_sizes[i].cs_dmacachep;
66519 else
66520 #endif
66521 +
66522 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66523 + if (flags & GFP_USERCOPY)
66524 + cachep = malloc_sizes[i].cs_usercopycachep;
66525 + else
66526 +#endif
66527 +
66528 cachep = malloc_sizes[i].cs_cachep;
66529
66530 ret = kmem_cache_alloc_trace(cachep, flags, size);
66531 @@ -155,7 +167,7 @@ found:
66532 }
66533
66534 #ifdef CONFIG_NUMA
66535 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
66536 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66537 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66538
66539 #ifdef CONFIG_TRACING
66540 @@ -198,6 +210,13 @@ found:
66541 cachep = malloc_sizes[i].cs_dmacachep;
66542 else
66543 #endif
66544 +
66545 +#ifdef CONFIG_PAX_USERCOPY_SLABS
66546 + if (flags & GFP_USERCOPY)
66547 + cachep = malloc_sizes[i].cs_usercopycachep;
66548 + else
66549 +#endif
66550 +
66551 cachep = malloc_sizes[i].cs_cachep;
66552
66553 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
66554 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
66555 index f28e14a..7831211 100644
66556 --- a/include/linux/slob_def.h
66557 +++ b/include/linux/slob_def.h
66558 @@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
66559 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
66560 }
66561
66562 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
66563 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66564
66565 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
66566 {
66567 @@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66568 return __kmalloc_node(size, flags, NUMA_NO_NODE);
66569 }
66570
66571 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
66572 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
66573 {
66574 return kmalloc(size, flags);
66575 }
66576 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
66577 index df448ad..b99e7f6 100644
66578 --- a/include/linux/slub_def.h
66579 +++ b/include/linux/slub_def.h
66580 @@ -91,7 +91,7 @@ struct kmem_cache {
66581 struct kmem_cache_order_objects max;
66582 struct kmem_cache_order_objects min;
66583 gfp_t allocflags; /* gfp flags to use on each alloc */
66584 - int refcount; /* Refcount for slab cache destroy */
66585 + atomic_t refcount; /* Refcount for slab cache destroy */
66586 void (*ctor)(void *);
66587 int inuse; /* Offset to metadata */
66588 int align; /* Alignment */
66589 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
66590 * Sorry that the following has to be that ugly but some versions of GCC
66591 * have trouble with constant propagation and loops.
66592 */
66593 -static __always_inline int kmalloc_index(size_t size)
66594 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
66595 {
66596 if (!size)
66597 return 0;
66598 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
66599 }
66600
66601 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66602 -void *__kmalloc(size_t size, gfp_t flags);
66603 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
66604
66605 static __always_inline void *
66606 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
66607 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
66608 }
66609 #endif
66610
66611 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
66612 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
66613 {
66614 unsigned int order = get_order(size);
66615 return kmalloc_order_trace(size, flags, order);
66616 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66617 }
66618
66619 #ifdef CONFIG_NUMA
66620 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
66621 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66622 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66623
66624 #ifdef CONFIG_TRACING
66625 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
66626 index 680f9a3..f13aeb0 100644
66627 --- a/include/linux/sonet.h
66628 +++ b/include/linux/sonet.h
66629 @@ -7,7 +7,7 @@
66630 #include <uapi/linux/sonet.h>
66631
66632 struct k_sonet_stats {
66633 -#define __HANDLE_ITEM(i) atomic_t i
66634 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
66635 __SONET_ITEMS
66636 #undef __HANDLE_ITEM
66637 };
66638 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
66639 index 34206b8..f019e06 100644
66640 --- a/include/linux/sunrpc/clnt.h
66641 +++ b/include/linux/sunrpc/clnt.h
66642 @@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
66643 {
66644 switch (sap->sa_family) {
66645 case AF_INET:
66646 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
66647 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
66648 case AF_INET6:
66649 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
66650 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
66651 }
66652 return 0;
66653 }
66654 @@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
66655 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
66656 const struct sockaddr *src)
66657 {
66658 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
66659 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
66660 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
66661
66662 dsin->sin_family = ssin->sin_family;
66663 @@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
66664 if (sa->sa_family != AF_INET6)
66665 return 0;
66666
66667 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
66668 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
66669 }
66670
66671 #endif /* __KERNEL__ */
66672 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
66673 index 0b8e3e6..33e0a01 100644
66674 --- a/include/linux/sunrpc/svc_rdma.h
66675 +++ b/include/linux/sunrpc/svc_rdma.h
66676 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
66677 extern unsigned int svcrdma_max_requests;
66678 extern unsigned int svcrdma_max_req_size;
66679
66680 -extern atomic_t rdma_stat_recv;
66681 -extern atomic_t rdma_stat_read;
66682 -extern atomic_t rdma_stat_write;
66683 -extern atomic_t rdma_stat_sq_starve;
66684 -extern atomic_t rdma_stat_rq_starve;
66685 -extern atomic_t rdma_stat_rq_poll;
66686 -extern atomic_t rdma_stat_rq_prod;
66687 -extern atomic_t rdma_stat_sq_poll;
66688 -extern atomic_t rdma_stat_sq_prod;
66689 +extern atomic_unchecked_t rdma_stat_recv;
66690 +extern atomic_unchecked_t rdma_stat_read;
66691 +extern atomic_unchecked_t rdma_stat_write;
66692 +extern atomic_unchecked_t rdma_stat_sq_starve;
66693 +extern atomic_unchecked_t rdma_stat_rq_starve;
66694 +extern atomic_unchecked_t rdma_stat_rq_poll;
66695 +extern atomic_unchecked_t rdma_stat_rq_prod;
66696 +extern atomic_unchecked_t rdma_stat_sq_poll;
66697 +extern atomic_unchecked_t rdma_stat_sq_prod;
66698
66699 #define RPCRDMA_VERSION 1
66700
66701 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
66702 index cd844a6..3ca3592 100644
66703 --- a/include/linux/sysctl.h
66704 +++ b/include/linux/sysctl.h
66705 @@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
66706
66707 extern int proc_dostring(struct ctl_table *, int,
66708 void __user *, size_t *, loff_t *);
66709 +extern int proc_dostring_modpriv(struct ctl_table *, int,
66710 + void __user *, size_t *, loff_t *);
66711 extern int proc_dointvec(struct ctl_table *, int,
66712 void __user *, size_t *, loff_t *);
66713 extern int proc_dointvec_minmax(struct ctl_table *, int,
66714 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
66715 index 7faf933..eb6f5e3 100644
66716 --- a/include/linux/sysrq.h
66717 +++ b/include/linux/sysrq.h
66718 @@ -36,7 +36,7 @@ struct sysrq_key_op {
66719 char *help_msg;
66720 char *action_msg;
66721 int enable_mask;
66722 -};
66723 +} __do_const;
66724
66725 #ifdef CONFIG_MAGIC_SYSRQ
66726
66727 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
66728 index ccc1899..b1aaceb 100644
66729 --- a/include/linux/thread_info.h
66730 +++ b/include/linux/thread_info.h
66731 @@ -146,6 +146,15 @@ static inline bool test_and_clear_restore_sigmask(void)
66732 #error "no set_restore_sigmask() provided and default one won't work"
66733 #endif
66734
66735 +extern void __check_object_size(const void *ptr, unsigned long n, bool to);
66736 +static inline void check_object_size(const void *ptr, unsigned long n, bool to)
66737 +{
66738 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
66739 + if (!__builtin_constant_p(n))
66740 +#endif
66741 + __check_object_size(ptr, n, to);
66742 +}
66743 +
66744 #endif /* __KERNEL__ */
66745
66746 #endif /* _LINUX_THREAD_INFO_H */
66747 diff --git a/include/linux/tty.h b/include/linux/tty.h
66748 index f0b4eb4..1c4854e 100644
66749 --- a/include/linux/tty.h
66750 +++ b/include/linux/tty.h
66751 @@ -192,7 +192,7 @@ struct tty_port {
66752 const struct tty_port_operations *ops; /* Port operations */
66753 spinlock_t lock; /* Lock protecting tty field */
66754 int blocked_open; /* Waiting to open */
66755 - int count; /* Usage count */
66756 + atomic_t count; /* Usage count */
66757 wait_queue_head_t open_wait; /* Open waiters */
66758 wait_queue_head_t close_wait; /* Close waiters */
66759 wait_queue_head_t delta_msr_wait; /* Modem status change */
66760 @@ -513,7 +513,7 @@ extern int tty_port_open(struct tty_port *port,
66761 struct tty_struct *tty, struct file *filp);
66762 static inline int tty_port_users(struct tty_port *port)
66763 {
66764 - return port->count + port->blocked_open;
66765 + return atomic_read(&port->count) + port->blocked_open;
66766 }
66767
66768 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
66769 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
66770 index dd976cf..e272742 100644
66771 --- a/include/linux/tty_driver.h
66772 +++ b/include/linux/tty_driver.h
66773 @@ -284,7 +284,7 @@ struct tty_operations {
66774 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
66775 #endif
66776 const struct file_operations *proc_fops;
66777 -};
66778 +} __do_const;
66779
66780 struct tty_driver {
66781 int magic; /* magic number for this structure */
66782 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
66783 index fb79dd8d..07d4773 100644
66784 --- a/include/linux/tty_ldisc.h
66785 +++ b/include/linux/tty_ldisc.h
66786 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
66787
66788 struct module *owner;
66789
66790 - int refcount;
66791 + atomic_t refcount;
66792 };
66793
66794 struct tty_ldisc {
66795 diff --git a/include/linux/types.h b/include/linux/types.h
66796 index 1cc0e4b..0d50edf 100644
66797 --- a/include/linux/types.h
66798 +++ b/include/linux/types.h
66799 @@ -175,10 +175,26 @@ typedef struct {
66800 int counter;
66801 } atomic_t;
66802
66803 +#ifdef CONFIG_PAX_REFCOUNT
66804 +typedef struct {
66805 + int counter;
66806 +} atomic_unchecked_t;
66807 +#else
66808 +typedef atomic_t atomic_unchecked_t;
66809 +#endif
66810 +
66811 #ifdef CONFIG_64BIT
66812 typedef struct {
66813 long counter;
66814 } atomic64_t;
66815 +
66816 +#ifdef CONFIG_PAX_REFCOUNT
66817 +typedef struct {
66818 + long counter;
66819 +} atomic64_unchecked_t;
66820 +#else
66821 +typedef atomic64_t atomic64_unchecked_t;
66822 +#endif
66823 #endif
66824
66825 struct list_head {
66826 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
66827 index 5ca0951..ab496a5 100644
66828 --- a/include/linux/uaccess.h
66829 +++ b/include/linux/uaccess.h
66830 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
66831 long ret; \
66832 mm_segment_t old_fs = get_fs(); \
66833 \
66834 - set_fs(KERNEL_DS); \
66835 pagefault_disable(); \
66836 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
66837 - pagefault_enable(); \
66838 + set_fs(KERNEL_DS); \
66839 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
66840 set_fs(old_fs); \
66841 + pagefault_enable(); \
66842 ret; \
66843 })
66844
66845 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
66846 index 99c1b4d..bb94261 100644
66847 --- a/include/linux/unaligned/access_ok.h
66848 +++ b/include/linux/unaligned/access_ok.h
66849 @@ -6,32 +6,32 @@
66850
66851 static inline u16 get_unaligned_le16(const void *p)
66852 {
66853 - return le16_to_cpup((__le16 *)p);
66854 + return le16_to_cpup((const __le16 *)p);
66855 }
66856
66857 static inline u32 get_unaligned_le32(const void *p)
66858 {
66859 - return le32_to_cpup((__le32 *)p);
66860 + return le32_to_cpup((const __le32 *)p);
66861 }
66862
66863 static inline u64 get_unaligned_le64(const void *p)
66864 {
66865 - return le64_to_cpup((__le64 *)p);
66866 + return le64_to_cpup((const __le64 *)p);
66867 }
66868
66869 static inline u16 get_unaligned_be16(const void *p)
66870 {
66871 - return be16_to_cpup((__be16 *)p);
66872 + return be16_to_cpup((const __be16 *)p);
66873 }
66874
66875 static inline u32 get_unaligned_be32(const void *p)
66876 {
66877 - return be32_to_cpup((__be32 *)p);
66878 + return be32_to_cpup((const __be32 *)p);
66879 }
66880
66881 static inline u64 get_unaligned_be64(const void *p)
66882 {
66883 - return be64_to_cpup((__be64 *)p);
66884 + return be64_to_cpup((const __be64 *)p);
66885 }
66886
66887 static inline void put_unaligned_le16(u16 val, void *p)
66888 diff --git a/include/linux/usb.h b/include/linux/usb.h
66889 index 10278d1..e21ec3c 100644
66890 --- a/include/linux/usb.h
66891 +++ b/include/linux/usb.h
66892 @@ -551,7 +551,7 @@ struct usb_device {
66893 int maxchild;
66894
66895 u32 quirks;
66896 - atomic_t urbnum;
66897 + atomic_unchecked_t urbnum;
66898
66899 unsigned long active_duration;
66900
66901 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
66902 index c5d36c6..108f4f9 100644
66903 --- a/include/linux/usb/renesas_usbhs.h
66904 +++ b/include/linux/usb/renesas_usbhs.h
66905 @@ -39,7 +39,7 @@ enum {
66906 */
66907 struct renesas_usbhs_driver_callback {
66908 int (*notify_hotplug)(struct platform_device *pdev);
66909 -};
66910 +} __no_const;
66911
66912 /*
66913 * callback functions for platform
66914 diff --git a/include/linux/usb/usbnet.h b/include/linux/usb/usbnet.h
66915 index ddbbb7d..9134611 100644
66916 --- a/include/linux/usb/usbnet.h
66917 +++ b/include/linux/usb/usbnet.h
66918 @@ -33,6 +33,7 @@ struct usbnet {
66919 wait_queue_head_t *wait;
66920 struct mutex phy_mutex;
66921 unsigned char suspend_count;
66922 + unsigned char pkt_cnt, pkt_err;
66923
66924 /* i/o info: pipes etc */
66925 unsigned in, out;
66926 @@ -69,6 +70,8 @@ struct usbnet {
66927 # define EVENT_DEV_ASLEEP 6
66928 # define EVENT_DEV_OPEN 7
66929 # define EVENT_DEVICE_REPORT_IDLE 8
66930 +# define EVENT_NO_RUNTIME_PM 9
66931 +# define EVENT_RX_KILL 10
66932 };
66933
66934 static inline struct usb_driver *driver_of(struct usb_interface *intf)
66935 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
66936 index 6f8fbcf..8259001 100644
66937 --- a/include/linux/vermagic.h
66938 +++ b/include/linux/vermagic.h
66939 @@ -25,9 +25,35 @@
66940 #define MODULE_ARCH_VERMAGIC ""
66941 #endif
66942
66943 +#ifdef CONFIG_PAX_REFCOUNT
66944 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
66945 +#else
66946 +#define MODULE_PAX_REFCOUNT ""
66947 +#endif
66948 +
66949 +#ifdef CONSTIFY_PLUGIN
66950 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
66951 +#else
66952 +#define MODULE_CONSTIFY_PLUGIN ""
66953 +#endif
66954 +
66955 +#ifdef STACKLEAK_PLUGIN
66956 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
66957 +#else
66958 +#define MODULE_STACKLEAK_PLUGIN ""
66959 +#endif
66960 +
66961 +#ifdef CONFIG_GRKERNSEC
66962 +#define MODULE_GRSEC "GRSEC "
66963 +#else
66964 +#define MODULE_GRSEC ""
66965 +#endif
66966 +
66967 #define VERMAGIC_STRING \
66968 UTS_RELEASE " " \
66969 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
66970 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
66971 - MODULE_ARCH_VERMAGIC
66972 + MODULE_ARCH_VERMAGIC \
66973 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
66974 + MODULE_GRSEC
66975
66976 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
66977 index 6071e91..ca6a489 100644
66978 --- a/include/linux/vmalloc.h
66979 +++ b/include/linux/vmalloc.h
66980 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
66981 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
66982 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
66983 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
66984 +
66985 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
66986 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
66987 +#endif
66988 +
66989 /* bits [20..32] reserved for arch specific ioremap internals */
66990
66991 /*
66992 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
66993 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
66994 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
66995 unsigned long start, unsigned long end, gfp_t gfp_mask,
66996 - pgprot_t prot, int node, const void *caller);
66997 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
66998 extern void vfree(const void *addr);
66999
67000 extern void *vmap(struct page **pages, unsigned int count,
67001 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
67002 extern void free_vm_area(struct vm_struct *area);
67003
67004 /* for /dev/kmem */
67005 -extern long vread(char *buf, char *addr, unsigned long count);
67006 -extern long vwrite(char *buf, char *addr, unsigned long count);
67007 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
67008 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
67009
67010 /*
67011 * Internals. Dont't use..
67012 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
67013 index 92a86b2..1d9eb3c 100644
67014 --- a/include/linux/vmstat.h
67015 +++ b/include/linux/vmstat.h
67016 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
67017 /*
67018 * Zone based page accounting with per cpu differentials.
67019 */
67020 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67021 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67022
67023 static inline void zone_page_state_add(long x, struct zone *zone,
67024 enum zone_stat_item item)
67025 {
67026 - atomic_long_add(x, &zone->vm_stat[item]);
67027 - atomic_long_add(x, &vm_stat[item]);
67028 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
67029 + atomic_long_add_unchecked(x, &vm_stat[item]);
67030 }
67031
67032 static inline unsigned long global_page_state(enum zone_stat_item item)
67033 {
67034 - long x = atomic_long_read(&vm_stat[item]);
67035 + long x = atomic_long_read_unchecked(&vm_stat[item]);
67036 #ifdef CONFIG_SMP
67037 if (x < 0)
67038 x = 0;
67039 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
67040 static inline unsigned long zone_page_state(struct zone *zone,
67041 enum zone_stat_item item)
67042 {
67043 - long x = atomic_long_read(&zone->vm_stat[item]);
67044 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
67045 #ifdef CONFIG_SMP
67046 if (x < 0)
67047 x = 0;
67048 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
67049 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
67050 enum zone_stat_item item)
67051 {
67052 - long x = atomic_long_read(&zone->vm_stat[item]);
67053 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
67054
67055 #ifdef CONFIG_SMP
67056 int cpu;
67057 @@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
67058
67059 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
67060 {
67061 - atomic_long_inc(&zone->vm_stat[item]);
67062 - atomic_long_inc(&vm_stat[item]);
67063 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
67064 + atomic_long_inc_unchecked(&vm_stat[item]);
67065 }
67066
67067 static inline void __inc_zone_page_state(struct page *page,
67068 @@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
67069
67070 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
67071 {
67072 - atomic_long_dec(&zone->vm_stat[item]);
67073 - atomic_long_dec(&vm_stat[item]);
67074 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
67075 + atomic_long_dec_unchecked(&vm_stat[item]);
67076 }
67077
67078 static inline void __dec_zone_page_state(struct page *page,
67079 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
67080 index 95d1c91..6798cca 100644
67081 --- a/include/media/v4l2-dev.h
67082 +++ b/include/media/v4l2-dev.h
67083 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
67084 int (*mmap) (struct file *, struct vm_area_struct *);
67085 int (*open) (struct file *);
67086 int (*release) (struct file *);
67087 -};
67088 +} __do_const;
67089
67090 /*
67091 * Newer version of video_device, handled by videodev2.c
67092 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
67093 index e48b571..7e40de4 100644
67094 --- a/include/media/v4l2-ioctl.h
67095 +++ b/include/media/v4l2-ioctl.h
67096 @@ -282,7 +282,6 @@ struct v4l2_ioctl_ops {
67097 bool valid_prio, int cmd, void *arg);
67098 };
67099
67100 -
67101 /* v4l debugging and diagnostics */
67102
67103 /* Debug bitmask flags to be used on V4L2 */
67104 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
67105 index 9e5425b..8136ffc 100644
67106 --- a/include/net/caif/cfctrl.h
67107 +++ b/include/net/caif/cfctrl.h
67108 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
67109 void (*radioset_rsp)(void);
67110 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
67111 struct cflayer *client_layer);
67112 -};
67113 +} __no_const;
67114
67115 /* Link Setup Parameters for CAIF-Links. */
67116 struct cfctrl_link_param {
67117 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
67118 struct cfctrl {
67119 struct cfsrvl serv;
67120 struct cfctrl_rsp res;
67121 - atomic_t req_seq_no;
67122 - atomic_t rsp_seq_no;
67123 + atomic_unchecked_t req_seq_no;
67124 + atomic_unchecked_t rsp_seq_no;
67125 struct list_head list;
67126 /* Protects from simultaneous access to first_req list */
67127 spinlock_t info_list_lock;
67128 diff --git a/include/net/flow.h b/include/net/flow.h
67129 index 628e11b..4c475df 100644
67130 --- a/include/net/flow.h
67131 +++ b/include/net/flow.h
67132 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
67133
67134 extern void flow_cache_flush(void);
67135 extern void flow_cache_flush_deferred(void);
67136 -extern atomic_t flow_cache_genid;
67137 +extern atomic_unchecked_t flow_cache_genid;
67138
67139 #endif
67140 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
67141 index e5062c9..48a9a4b 100644
67142 --- a/include/net/gro_cells.h
67143 +++ b/include/net/gro_cells.h
67144 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
67145 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
67146
67147 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
67148 - atomic_long_inc(&dev->rx_dropped);
67149 + atomic_long_inc_unchecked(&dev->rx_dropped);
67150 kfree_skb(skb);
67151 return;
67152 }
67153 @@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
67154 int i;
67155
67156 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
67157 - gcells->cells = kcalloc(sizeof(struct gro_cell),
67158 - gcells->gro_cells_mask + 1,
67159 + gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
67160 + sizeof(struct gro_cell),
67161 GFP_KERNEL);
67162 if (!gcells->cells)
67163 return -ENOMEM;
67164 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
67165 index 1832927..ce39aea 100644
67166 --- a/include/net/inet_connection_sock.h
67167 +++ b/include/net/inet_connection_sock.h
67168 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
67169 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
67170 int (*bind_conflict)(const struct sock *sk,
67171 const struct inet_bind_bucket *tb, bool relax);
67172 -};
67173 +} __do_const;
67174
67175 /** inet_connection_sock - INET connection oriented sock
67176 *
67177 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
67178 index 53f464d..ba76aaa 100644
67179 --- a/include/net/inetpeer.h
67180 +++ b/include/net/inetpeer.h
67181 @@ -47,8 +47,8 @@ struct inet_peer {
67182 */
67183 union {
67184 struct {
67185 - atomic_t rid; /* Frag reception counter */
67186 - atomic_t ip_id_count; /* IP ID for the next packet */
67187 + atomic_unchecked_t rid; /* Frag reception counter */
67188 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
67189 };
67190 struct rcu_head rcu;
67191 struct inet_peer *gc_next;
67192 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
67193 more++;
67194 inet_peer_refcheck(p);
67195 do {
67196 - old = atomic_read(&p->ip_id_count);
67197 + old = atomic_read_unchecked(&p->ip_id_count);
67198 new = old + more;
67199 if (!new)
67200 new = 1;
67201 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
67202 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
67203 return new;
67204 }
67205
67206 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
67207 index 9497be1..5a4fafe 100644
67208 --- a/include/net/ip_fib.h
67209 +++ b/include/net/ip_fib.h
67210 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
67211
67212 #define FIB_RES_SADDR(net, res) \
67213 ((FIB_RES_NH(res).nh_saddr_genid == \
67214 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
67215 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
67216 FIB_RES_NH(res).nh_saddr : \
67217 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
67218 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
67219 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
67220 index ee75ccd..2cc2b95 100644
67221 --- a/include/net/ip_vs.h
67222 +++ b/include/net/ip_vs.h
67223 @@ -510,7 +510,7 @@ struct ip_vs_conn {
67224 struct ip_vs_conn *control; /* Master control connection */
67225 atomic_t n_control; /* Number of controlled ones */
67226 struct ip_vs_dest *dest; /* real server */
67227 - atomic_t in_pkts; /* incoming packet counter */
67228 + atomic_unchecked_t in_pkts; /* incoming packet counter */
67229
67230 /* packet transmitter for different forwarding methods. If it
67231 mangles the packet, it must return NF_DROP or better NF_STOLEN,
67232 @@ -648,7 +648,7 @@ struct ip_vs_dest {
67233 __be16 port; /* port number of the server */
67234 union nf_inet_addr addr; /* IP address of the server */
67235 volatile unsigned int flags; /* dest status flags */
67236 - atomic_t conn_flags; /* flags to copy to conn */
67237 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
67238 atomic_t weight; /* server weight */
67239
67240 atomic_t refcnt; /* reference counter */
67241 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
67242 index 80ffde3..968b0f4 100644
67243 --- a/include/net/irda/ircomm_tty.h
67244 +++ b/include/net/irda/ircomm_tty.h
67245 @@ -35,6 +35,7 @@
67246 #include <linux/termios.h>
67247 #include <linux/timer.h>
67248 #include <linux/tty.h> /* struct tty_struct */
67249 +#include <asm/local.h>
67250
67251 #include <net/irda/irias_object.h>
67252 #include <net/irda/ircomm_core.h>
67253 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
67254 index cc7c197..9f2da2a 100644
67255 --- a/include/net/iucv/af_iucv.h
67256 +++ b/include/net/iucv/af_iucv.h
67257 @@ -141,7 +141,7 @@ struct iucv_sock {
67258 struct iucv_sock_list {
67259 struct hlist_head head;
67260 rwlock_t lock;
67261 - atomic_t autobind_name;
67262 + atomic_unchecked_t autobind_name;
67263 };
67264
67265 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
67266 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
67267 index 0dab173..1b76af0 100644
67268 --- a/include/net/neighbour.h
67269 +++ b/include/net/neighbour.h
67270 @@ -123,7 +123,7 @@ struct neigh_ops {
67271 void (*error_report)(struct neighbour *, struct sk_buff *);
67272 int (*output)(struct neighbour *, struct sk_buff *);
67273 int (*connected_output)(struct neighbour *, struct sk_buff *);
67274 -};
67275 +} __do_const;
67276
67277 struct pneigh_entry {
67278 struct pneigh_entry *next;
67279 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
67280 index 95e6466..251016d 100644
67281 --- a/include/net/net_namespace.h
67282 +++ b/include/net/net_namespace.h
67283 @@ -110,7 +110,7 @@ struct net {
67284 #endif
67285 struct netns_ipvs *ipvs;
67286 struct sock *diag_nlsk;
67287 - atomic_t rt_genid;
67288 + atomic_unchecked_t rt_genid;
67289 };
67290
67291 /*
67292 @@ -320,12 +320,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
67293
67294 static inline int rt_genid(struct net *net)
67295 {
67296 - return atomic_read(&net->rt_genid);
67297 + return atomic_read_unchecked(&net->rt_genid);
67298 }
67299
67300 static inline void rt_genid_bump(struct net *net)
67301 {
67302 - atomic_inc(&net->rt_genid);
67303 + atomic_inc_unchecked(&net->rt_genid);
67304 }
67305
67306 #endif /* __NET_NET_NAMESPACE_H */
67307 diff --git a/include/net/netdma.h b/include/net/netdma.h
67308 index 8ba8ce2..99b7fff 100644
67309 --- a/include/net/netdma.h
67310 +++ b/include/net/netdma.h
67311 @@ -24,7 +24,7 @@
67312 #include <linux/dmaengine.h>
67313 #include <linux/skbuff.h>
67314
67315 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
67316 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
67317 struct sk_buff *skb, int offset, struct iovec *to,
67318 size_t len, struct dma_pinned_list *pinned_list);
67319
67320 diff --git a/include/net/netfilter/nf_queue.h b/include/net/netfilter/nf_queue.h
67321 index 252fd10..aa1421f 100644
67322 --- a/include/net/netfilter/nf_queue.h
67323 +++ b/include/net/netfilter/nf_queue.h
67324 @@ -22,7 +22,7 @@ struct nf_queue_handler {
67325 int (*outfn)(struct nf_queue_entry *entry,
67326 unsigned int queuenum);
67327 char *name;
67328 -};
67329 +} __do_const;
67330
67331 extern int nf_register_queue_handler(u_int8_t pf,
67332 const struct nf_queue_handler *qh);
67333 diff --git a/include/net/netlink.h b/include/net/netlink.h
67334 index 9690b0f..87aded7 100644
67335 --- a/include/net/netlink.h
67336 +++ b/include/net/netlink.h
67337 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
67338 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
67339 {
67340 if (mark)
67341 - skb_trim(skb, (unsigned char *) mark - skb->data);
67342 + skb_trim(skb, (const unsigned char *) mark - skb->data);
67343 }
67344
67345 /**
67346 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
67347 index 2ae2b83..dbdc85e 100644
67348 --- a/include/net/netns/ipv4.h
67349 +++ b/include/net/netns/ipv4.h
67350 @@ -64,7 +64,7 @@ struct netns_ipv4 {
67351 kgid_t sysctl_ping_group_range[2];
67352 long sysctl_tcp_mem[3];
67353
67354 - atomic_t dev_addr_genid;
67355 + atomic_unchecked_t dev_addr_genid;
67356
67357 #ifdef CONFIG_IP_MROUTE
67358 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
67359 diff --git a/include/net/protocol.h b/include/net/protocol.h
67360 index 929528c..c84d4f6 100644
67361 --- a/include/net/protocol.h
67362 +++ b/include/net/protocol.h
67363 @@ -48,7 +48,7 @@ struct net_protocol {
67364 int (*gro_complete)(struct sk_buff *skb);
67365 unsigned int no_policy:1,
67366 netns_ok:1;
67367 -};
67368 +} __do_const;
67369
67370 #if IS_ENABLED(CONFIG_IPV6)
67371 struct inet6_protocol {
67372 @@ -69,7 +69,7 @@ struct inet6_protocol {
67373 int (*gro_complete)(struct sk_buff *skb);
67374
67375 unsigned int flags; /* INET6_PROTO_xxx */
67376 -};
67377 +} __do_const;
67378
67379 #define INET6_PROTO_NOPOLICY 0x1
67380 #define INET6_PROTO_FINAL 0x2
67381 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
67382 index 9c6414f..fbd0524 100644
67383 --- a/include/net/sctp/sctp.h
67384 +++ b/include/net/sctp/sctp.h
67385 @@ -318,9 +318,9 @@ do { \
67386
67387 #else /* SCTP_DEBUG */
67388
67389 -#define SCTP_DEBUG_PRINTK(whatever...)
67390 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
67391 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
67392 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
67393 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
67394 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
67395 #define SCTP_ENABLE_DEBUG
67396 #define SCTP_DISABLE_DEBUG
67397 #define SCTP_ASSERT(expr, str, func)
67398 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
67399 index 64158aa..b65533c 100644
67400 --- a/include/net/sctp/structs.h
67401 +++ b/include/net/sctp/structs.h
67402 @@ -496,7 +496,7 @@ struct sctp_af {
67403 int sockaddr_len;
67404 sa_family_t sa_family;
67405 struct list_head list;
67406 -};
67407 +} __do_const;
67408
67409 struct sctp_af *sctp_get_af_specific(sa_family_t);
67410 int sctp_register_af(struct sctp_af *);
67411 @@ -516,7 +516,7 @@ struct sctp_pf {
67412 struct sctp_association *asoc);
67413 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
67414 struct sctp_af *af;
67415 -};
67416 +} __do_const;
67417
67418
67419 /* Structure to track chunk fragments that have been acked, but peer
67420 diff --git a/include/net/sock.h b/include/net/sock.h
67421 index c945fba..e162e56 100644
67422 --- a/include/net/sock.h
67423 +++ b/include/net/sock.h
67424 @@ -304,7 +304,7 @@ struct sock {
67425 #ifdef CONFIG_RPS
67426 __u32 sk_rxhash;
67427 #endif
67428 - atomic_t sk_drops;
67429 + atomic_unchecked_t sk_drops;
67430 int sk_rcvbuf;
67431
67432 struct sk_filter __rcu *sk_filter;
67433 @@ -1763,7 +1763,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
67434 }
67435
67436 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
67437 - char __user *from, char *to,
67438 + char __user *from, unsigned char *to,
67439 int copy, int offset)
67440 {
67441 if (skb->ip_summed == CHECKSUM_NONE) {
67442 @@ -2022,7 +2022,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
67443 }
67444 }
67445
67446 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67447 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67448
67449 /**
67450 * sk_page_frag - return an appropriate page_frag
67451 diff --git a/include/net/tcp.h b/include/net/tcp.h
67452 index 4af45e3..af97861 100644
67453 --- a/include/net/tcp.h
67454 +++ b/include/net/tcp.h
67455 @@ -531,7 +531,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
67456 extern void tcp_xmit_retransmit_queue(struct sock *);
67457 extern void tcp_simple_retransmit(struct sock *);
67458 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
67459 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67460 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67461
67462 extern void tcp_send_probe0(struct sock *);
67463 extern void tcp_send_partial(struct sock *);
67464 @@ -702,8 +702,8 @@ struct tcp_skb_cb {
67465 struct inet6_skb_parm h6;
67466 #endif
67467 } header; /* For incoming frames */
67468 - __u32 seq; /* Starting sequence number */
67469 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
67470 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
67471 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
67472 __u32 when; /* used to compute rtt's */
67473 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
67474
67475 @@ -717,7 +717,7 @@ struct tcp_skb_cb {
67476
67477 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
67478 /* 1 byte hole */
67479 - __u32 ack_seq; /* Sequence number ACK'd */
67480 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
67481 };
67482
67483 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
67484 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
67485 index 63445ed..74ef61d 100644
67486 --- a/include/net/xfrm.h
67487 +++ b/include/net/xfrm.h
67488 @@ -423,7 +423,7 @@ struct xfrm_mode {
67489 struct module *owner;
67490 unsigned int encap;
67491 int flags;
67492 -};
67493 +} __do_const;
67494
67495 /* Flags for xfrm_mode. */
67496 enum {
67497 @@ -514,7 +514,7 @@ struct xfrm_policy {
67498 struct timer_list timer;
67499
67500 struct flow_cache_object flo;
67501 - atomic_t genid;
67502 + atomic_unchecked_t genid;
67503 u32 priority;
67504 u32 index;
67505 struct xfrm_mark mark;
67506 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
67507 index 1a046b1..ee0bef0 100644
67508 --- a/include/rdma/iw_cm.h
67509 +++ b/include/rdma/iw_cm.h
67510 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
67511 int backlog);
67512
67513 int (*destroy_listen)(struct iw_cm_id *cm_id);
67514 -};
67515 +} __no_const;
67516
67517 /**
67518 * iw_create_cm_id - Create an IW CM identifier.
67519 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
67520 index 399162b..b337f1a 100644
67521 --- a/include/scsi/libfc.h
67522 +++ b/include/scsi/libfc.h
67523 @@ -762,6 +762,7 @@ struct libfc_function_template {
67524 */
67525 void (*disc_stop_final) (struct fc_lport *);
67526 };
67527 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
67528
67529 /**
67530 * struct fc_disc - Discovery context
67531 @@ -866,7 +867,7 @@ struct fc_lport {
67532 struct fc_vport *vport;
67533
67534 /* Operational Information */
67535 - struct libfc_function_template tt;
67536 + libfc_function_template_no_const tt;
67537 u8 link_up;
67538 u8 qfull;
67539 enum fc_lport_state state;
67540 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
67541 index 55367b0..d97bd2a 100644
67542 --- a/include/scsi/scsi_device.h
67543 +++ b/include/scsi/scsi_device.h
67544 @@ -169,9 +169,9 @@ struct scsi_device {
67545 unsigned int max_device_blocked; /* what device_blocked counts down from */
67546 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
67547
67548 - atomic_t iorequest_cnt;
67549 - atomic_t iodone_cnt;
67550 - atomic_t ioerr_cnt;
67551 + atomic_unchecked_t iorequest_cnt;
67552 + atomic_unchecked_t iodone_cnt;
67553 + atomic_unchecked_t ioerr_cnt;
67554
67555 struct device sdev_gendev,
67556 sdev_dev;
67557 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
67558 index b797e8f..8e2c3aa 100644
67559 --- a/include/scsi/scsi_transport_fc.h
67560 +++ b/include/scsi/scsi_transport_fc.h
67561 @@ -751,7 +751,8 @@ struct fc_function_template {
67562 unsigned long show_host_system_hostname:1;
67563
67564 unsigned long disable_target_scan:1;
67565 -};
67566 +} __do_const;
67567 +typedef struct fc_function_template __no_const fc_function_template_no_const;
67568
67569
67570 /**
67571 diff --git a/include/sound/soc.h b/include/sound/soc.h
67572 index 91244a0..89ca1a7 100644
67573 --- a/include/sound/soc.h
67574 +++ b/include/sound/soc.h
67575 @@ -769,7 +769,7 @@ struct snd_soc_codec_driver {
67576 /* probe ordering - for components with runtime dependencies */
67577 int probe_order;
67578 int remove_order;
67579 -};
67580 +} __do_const;
67581
67582 /* SoC platform interface */
67583 struct snd_soc_platform_driver {
67584 @@ -815,7 +815,7 @@ struct snd_soc_platform_driver {
67585 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
67586 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
67587 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
67588 -};
67589 +} __do_const;
67590
67591 struct snd_soc_platform {
67592 const char *name;
67593 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
67594 index fca8bbe..c0242ea 100644
67595 --- a/include/target/target_core_base.h
67596 +++ b/include/target/target_core_base.h
67597 @@ -760,7 +760,7 @@ struct se_device {
67598 spinlock_t stats_lock;
67599 /* Active commands on this virtual SE device */
67600 atomic_t simple_cmds;
67601 - atomic_t dev_ordered_id;
67602 + atomic_unchecked_t dev_ordered_id;
67603 atomic_t dev_ordered_sync;
67604 atomic_t dev_qf_count;
67605 struct se_obj dev_obj;
67606 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
67607 new file mode 100644
67608 index 0000000..fb634b7
67609 --- /dev/null
67610 +++ b/include/trace/events/fs.h
67611 @@ -0,0 +1,53 @@
67612 +#undef TRACE_SYSTEM
67613 +#define TRACE_SYSTEM fs
67614 +
67615 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
67616 +#define _TRACE_FS_H
67617 +
67618 +#include <linux/fs.h>
67619 +#include <linux/tracepoint.h>
67620 +
67621 +TRACE_EVENT(do_sys_open,
67622 +
67623 + TP_PROTO(const char *filename, int flags, int mode),
67624 +
67625 + TP_ARGS(filename, flags, mode),
67626 +
67627 + TP_STRUCT__entry(
67628 + __string( filename, filename )
67629 + __field( int, flags )
67630 + __field( int, mode )
67631 + ),
67632 +
67633 + TP_fast_assign(
67634 + __assign_str(filename, filename);
67635 + __entry->flags = flags;
67636 + __entry->mode = mode;
67637 + ),
67638 +
67639 + TP_printk("\"%s\" %x %o",
67640 + __get_str(filename), __entry->flags, __entry->mode)
67641 +);
67642 +
67643 +TRACE_EVENT(open_exec,
67644 +
67645 + TP_PROTO(const char *filename),
67646 +
67647 + TP_ARGS(filename),
67648 +
67649 + TP_STRUCT__entry(
67650 + __string( filename, filename )
67651 + ),
67652 +
67653 + TP_fast_assign(
67654 + __assign_str(filename, filename);
67655 + ),
67656 +
67657 + TP_printk("\"%s\"",
67658 + __get_str(filename))
67659 +);
67660 +
67661 +#endif /* _TRACE_FS_H */
67662 +
67663 +/* This part must be outside protection */
67664 +#include <trace/define_trace.h>
67665 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
67666 index 1c09820..7f5ec79 100644
67667 --- a/include/trace/events/irq.h
67668 +++ b/include/trace/events/irq.h
67669 @@ -36,7 +36,7 @@ struct softirq_action;
67670 */
67671 TRACE_EVENT(irq_handler_entry,
67672
67673 - TP_PROTO(int irq, struct irqaction *action),
67674 + TP_PROTO(int irq, const struct irqaction *action),
67675
67676 TP_ARGS(irq, action),
67677
67678 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
67679 */
67680 TRACE_EVENT(irq_handler_exit,
67681
67682 - TP_PROTO(int irq, struct irqaction *action, int ret),
67683 + TP_PROTO(int irq, const struct irqaction *action, int ret),
67684
67685 TP_ARGS(irq, action, ret),
67686
67687 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
67688 index 7caf44c..23c6f27 100644
67689 --- a/include/uapi/linux/a.out.h
67690 +++ b/include/uapi/linux/a.out.h
67691 @@ -39,6 +39,14 @@ enum machine_type {
67692 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
67693 };
67694
67695 +/* Constants for the N_FLAGS field */
67696 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67697 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
67698 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
67699 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
67700 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67701 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67702 +
67703 #if !defined (N_MAGIC)
67704 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
67705 #endif
67706 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
67707 index d876736..b36014e 100644
67708 --- a/include/uapi/linux/byteorder/little_endian.h
67709 +++ b/include/uapi/linux/byteorder/little_endian.h
67710 @@ -42,51 +42,51 @@
67711
67712 static inline __le64 __cpu_to_le64p(const __u64 *p)
67713 {
67714 - return (__force __le64)*p;
67715 + return (__force const __le64)*p;
67716 }
67717 static inline __u64 __le64_to_cpup(const __le64 *p)
67718 {
67719 - return (__force __u64)*p;
67720 + return (__force const __u64)*p;
67721 }
67722 static inline __le32 __cpu_to_le32p(const __u32 *p)
67723 {
67724 - return (__force __le32)*p;
67725 + return (__force const __le32)*p;
67726 }
67727 static inline __u32 __le32_to_cpup(const __le32 *p)
67728 {
67729 - return (__force __u32)*p;
67730 + return (__force const __u32)*p;
67731 }
67732 static inline __le16 __cpu_to_le16p(const __u16 *p)
67733 {
67734 - return (__force __le16)*p;
67735 + return (__force const __le16)*p;
67736 }
67737 static inline __u16 __le16_to_cpup(const __le16 *p)
67738 {
67739 - return (__force __u16)*p;
67740 + return (__force const __u16)*p;
67741 }
67742 static inline __be64 __cpu_to_be64p(const __u64 *p)
67743 {
67744 - return (__force __be64)__swab64p(p);
67745 + return (__force const __be64)__swab64p(p);
67746 }
67747 static inline __u64 __be64_to_cpup(const __be64 *p)
67748 {
67749 - return __swab64p((__u64 *)p);
67750 + return __swab64p((const __u64 *)p);
67751 }
67752 static inline __be32 __cpu_to_be32p(const __u32 *p)
67753 {
67754 - return (__force __be32)__swab32p(p);
67755 + return (__force const __be32)__swab32p(p);
67756 }
67757 static inline __u32 __be32_to_cpup(const __be32 *p)
67758 {
67759 - return __swab32p((__u32 *)p);
67760 + return __swab32p((const __u32 *)p);
67761 }
67762 static inline __be16 __cpu_to_be16p(const __u16 *p)
67763 {
67764 - return (__force __be16)__swab16p(p);
67765 + return (__force const __be16)__swab16p(p);
67766 }
67767 static inline __u16 __be16_to_cpup(const __be16 *p)
67768 {
67769 - return __swab16p((__u16 *)p);
67770 + return __swab16p((const __u16 *)p);
67771 }
67772 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
67773 #define __le64_to_cpus(x) do { (void)(x); } while (0)
67774 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
67775 index 126a817..d522bd1 100644
67776 --- a/include/uapi/linux/elf.h
67777 +++ b/include/uapi/linux/elf.h
67778 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
67779 #define PT_GNU_EH_FRAME 0x6474e550
67780
67781 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
67782 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
67783 +
67784 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
67785 +
67786 +/* Constants for the e_flags field */
67787 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67788 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
67789 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
67790 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
67791 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67792 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67793
67794 /*
67795 * Extended Numbering
67796 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
67797 #define DT_DEBUG 21
67798 #define DT_TEXTREL 22
67799 #define DT_JMPREL 23
67800 +#define DT_FLAGS 30
67801 + #define DF_TEXTREL 0x00000004
67802 #define DT_ENCODING 32
67803 #define OLD_DT_LOOS 0x60000000
67804 #define DT_LOOS 0x6000000d
67805 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
67806 #define PF_W 0x2
67807 #define PF_X 0x1
67808
67809 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
67810 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
67811 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
67812 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
67813 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
67814 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
67815 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
67816 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
67817 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
67818 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
67819 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
67820 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
67821 +
67822 typedef struct elf32_phdr{
67823 Elf32_Word p_type;
67824 Elf32_Off p_offset;
67825 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
67826 #define EI_OSABI 7
67827 #define EI_PAD 8
67828
67829 +#define EI_PAX 14
67830 +
67831 #define ELFMAG0 0x7f /* EI_MAG */
67832 #define ELFMAG1 'E'
67833 #define ELFMAG2 'L'
67834 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
67835 index aa169c4..6a2771d 100644
67836 --- a/include/uapi/linux/personality.h
67837 +++ b/include/uapi/linux/personality.h
67838 @@ -30,6 +30,7 @@ enum {
67839 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
67840 ADDR_NO_RANDOMIZE | \
67841 ADDR_COMPAT_LAYOUT | \
67842 + ADDR_LIMIT_3GB | \
67843 MMAP_PAGE_ZERO)
67844
67845 /*
67846 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
67847 index 7530e74..e714828 100644
67848 --- a/include/uapi/linux/screen_info.h
67849 +++ b/include/uapi/linux/screen_info.h
67850 @@ -43,7 +43,8 @@ struct screen_info {
67851 __u16 pages; /* 0x32 */
67852 __u16 vesa_attributes; /* 0x34 */
67853 __u32 capabilities; /* 0x36 */
67854 - __u8 _reserved[6]; /* 0x3a */
67855 + __u16 vesapm_size; /* 0x3a */
67856 + __u8 _reserved[4]; /* 0x3c */
67857 } __attribute__((packed));
67858
67859 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
67860 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
67861 index 6d67213..8dab561 100644
67862 --- a/include/uapi/linux/sysctl.h
67863 +++ b/include/uapi/linux/sysctl.h
67864 @@ -155,7 +155,11 @@ enum
67865 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
67866 };
67867
67868 -
67869 +#ifdef CONFIG_PAX_SOFTMODE
67870 +enum {
67871 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
67872 +};
67873 +#endif
67874
67875 /* CTL_VM names: */
67876 enum
67877 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
67878 index 26607bd..588b65f 100644
67879 --- a/include/uapi/linux/xattr.h
67880 +++ b/include/uapi/linux/xattr.h
67881 @@ -60,5 +60,9 @@
67882 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
67883 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
67884
67885 +/* User namespace */
67886 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
67887 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
67888 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
67889
67890 #endif /* _UAPI_LINUX_XATTR_H */
67891 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
67892 index f9466fa..f4e2b81 100644
67893 --- a/include/video/udlfb.h
67894 +++ b/include/video/udlfb.h
67895 @@ -53,10 +53,10 @@ struct dlfb_data {
67896 u32 pseudo_palette[256];
67897 int blank_mode; /*one of FB_BLANK_ */
67898 /* blit-only rendering path metrics, exposed through sysfs */
67899 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67900 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
67901 - atomic_t bytes_sent; /* to usb, after compression including overhead */
67902 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
67903 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67904 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
67905 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
67906 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
67907 };
67908
67909 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
67910 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
67911 index 0993a22..32ba2fe 100644
67912 --- a/include/video/uvesafb.h
67913 +++ b/include/video/uvesafb.h
67914 @@ -177,6 +177,7 @@ struct uvesafb_par {
67915 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
67916 u8 pmi_setpal; /* PMI for palette changes */
67917 u16 *pmi_base; /* protected mode interface location */
67918 + u8 *pmi_code; /* protected mode code location */
67919 void *pmi_start;
67920 void *pmi_pal;
67921 u8 *vbe_state_orig; /*
67922 diff --git a/init/Kconfig b/init/Kconfig
67923 index 6fdd6e3..5b01610 100644
67924 --- a/init/Kconfig
67925 +++ b/init/Kconfig
67926 @@ -925,6 +925,7 @@ endif # CGROUPS
67927
67928 config CHECKPOINT_RESTORE
67929 bool "Checkpoint/restore support" if EXPERT
67930 + depends on !GRKERNSEC
67931 default n
67932 help
67933 Enables additional kernel features in a sake of checkpoint/restore.
67934 @@ -1016,6 +1017,8 @@ config UIDGID_CONVERTED
67935 depends on OCFS2_FS = n
67936 depends on XFS_FS = n
67937
67938 + depends on GRKERNSEC = n
67939 +
67940 config UIDGID_STRICT_TYPE_CHECKS
67941 bool "Require conversions between uid/gids and their internal representation"
67942 depends on UIDGID_CONVERTED
67943 @@ -1405,7 +1408,7 @@ config SLUB_DEBUG
67944
67945 config COMPAT_BRK
67946 bool "Disable heap randomization"
67947 - default y
67948 + default n
67949 help
67950 Randomizing heap placement makes heap exploits harder, but it
67951 also breaks ancient binaries (including anything libc5 based).
67952 @@ -1648,7 +1651,7 @@ config INIT_ALL_POSSIBLE
67953 config STOP_MACHINE
67954 bool
67955 default y
67956 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
67957 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
67958 help
67959 Need stop_machine() primitive.
67960
67961 diff --git a/init/Makefile b/init/Makefile
67962 index 7bc47ee..6da2dc7 100644
67963 --- a/init/Makefile
67964 +++ b/init/Makefile
67965 @@ -2,6 +2,9 @@
67966 # Makefile for the linux kernel.
67967 #
67968
67969 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
67970 +asflags-y := $(GCC_PLUGINS_AFLAGS)
67971 +
67972 obj-y := main.o version.o mounts.o
67973 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
67974 obj-y += noinitramfs.o
67975 diff --git a/init/do_mounts.c b/init/do_mounts.c
67976 index f8a6642..4e5ee1b 100644
67977 --- a/init/do_mounts.c
67978 +++ b/init/do_mounts.c
67979 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
67980 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
67981 {
67982 struct super_block *s;
67983 - int err = sys_mount(name, "/root", fs, flags, data);
67984 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
67985 if (err)
67986 return err;
67987
67988 - sys_chdir("/root");
67989 + sys_chdir((const char __force_user *)"/root");
67990 s = current->fs->pwd.dentry->d_sb;
67991 ROOT_DEV = s->s_dev;
67992 printk(KERN_INFO
67993 @@ -461,18 +461,18 @@ void __init change_floppy(char *fmt, ...)
67994 va_start(args, fmt);
67995 vsprintf(buf, fmt, args);
67996 va_end(args);
67997 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
67998 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
67999 if (fd >= 0) {
68000 sys_ioctl(fd, FDEJECT, 0);
68001 sys_close(fd);
68002 }
68003 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
68004 - fd = sys_open("/dev/console", O_RDWR, 0);
68005 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
68006 if (fd >= 0) {
68007 sys_ioctl(fd, TCGETS, (long)&termios);
68008 termios.c_lflag &= ~ICANON;
68009 sys_ioctl(fd, TCSETSF, (long)&termios);
68010 - sys_read(fd, &c, 1);
68011 + sys_read(fd, (char __user *)&c, 1);
68012 termios.c_lflag |= ICANON;
68013 sys_ioctl(fd, TCSETSF, (long)&termios);
68014 sys_close(fd);
68015 @@ -566,6 +566,6 @@ void __init prepare_namespace(void)
68016 mount_root();
68017 out:
68018 devtmpfs_mount("dev");
68019 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
68020 - sys_chroot(".");
68021 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
68022 + sys_chroot((const char __force_user *)".");
68023 }
68024 diff --git a/init/do_mounts.h b/init/do_mounts.h
68025 index f5b978a..69dbfe8 100644
68026 --- a/init/do_mounts.h
68027 +++ b/init/do_mounts.h
68028 @@ -15,15 +15,15 @@ extern int root_mountflags;
68029
68030 static inline int create_dev(char *name, dev_t dev)
68031 {
68032 - sys_unlink(name);
68033 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
68034 + sys_unlink((char __force_user *)name);
68035 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
68036 }
68037
68038 #if BITS_PER_LONG == 32
68039 static inline u32 bstat(char *name)
68040 {
68041 struct stat64 stat;
68042 - if (sys_stat64(name, &stat) != 0)
68043 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
68044 return 0;
68045 if (!S_ISBLK(stat.st_mode))
68046 return 0;
68047 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
68048 static inline u32 bstat(char *name)
68049 {
68050 struct stat stat;
68051 - if (sys_newstat(name, &stat) != 0)
68052 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
68053 return 0;
68054 if (!S_ISBLK(stat.st_mode))
68055 return 0;
68056 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
68057 index f9acf71..1e19144 100644
68058 --- a/init/do_mounts_initrd.c
68059 +++ b/init/do_mounts_initrd.c
68060 @@ -58,8 +58,8 @@ static void __init handle_initrd(void)
68061 create_dev("/dev/root.old", Root_RAM0);
68062 /* mount initrd on rootfs' /root */
68063 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
68064 - sys_mkdir("/old", 0700);
68065 - sys_chdir("/old");
68066 + sys_mkdir((const char __force_user *)"/old", 0700);
68067 + sys_chdir((const char __force_user *)"/old");
68068
68069 /*
68070 * In case that a resume from disk is carried out by linuxrc or one of
68071 @@ -73,31 +73,31 @@ static void __init handle_initrd(void)
68072 current->flags &= ~PF_FREEZER_SKIP;
68073
68074 /* move initrd to rootfs' /old */
68075 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
68076 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
68077 /* switch root and cwd back to / of rootfs */
68078 - sys_chroot("..");
68079 + sys_chroot((const char __force_user *)"..");
68080
68081 if (new_decode_dev(real_root_dev) == Root_RAM0) {
68082 - sys_chdir("/old");
68083 + sys_chdir((const char __force_user *)"/old");
68084 return;
68085 }
68086
68087 - sys_chdir("/");
68088 + sys_chdir((const char __force_user *)"/");
68089 ROOT_DEV = new_decode_dev(real_root_dev);
68090 mount_root();
68091
68092 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
68093 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
68094 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
68095 if (!error)
68096 printk("okay\n");
68097 else {
68098 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
68099 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
68100 if (error == -ENOENT)
68101 printk("/initrd does not exist. Ignored.\n");
68102 else
68103 printk("failed\n");
68104 printk(KERN_NOTICE "Unmounting old root\n");
68105 - sys_umount("/old", MNT_DETACH);
68106 + sys_umount((char __force_user *)"/old", MNT_DETACH);
68107 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
68108 if (fd < 0) {
68109 error = fd;
68110 @@ -120,11 +120,11 @@ int __init initrd_load(void)
68111 * mounted in the normal path.
68112 */
68113 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
68114 - sys_unlink("/initrd.image");
68115 + sys_unlink((const char __force_user *)"/initrd.image");
68116 handle_initrd();
68117 return 1;
68118 }
68119 }
68120 - sys_unlink("/initrd.image");
68121 + sys_unlink((const char __force_user *)"/initrd.image");
68122 return 0;
68123 }
68124 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
68125 index 8cb6db5..d729f50 100644
68126 --- a/init/do_mounts_md.c
68127 +++ b/init/do_mounts_md.c
68128 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
68129 partitioned ? "_d" : "", minor,
68130 md_setup_args[ent].device_names);
68131
68132 - fd = sys_open(name, 0, 0);
68133 + fd = sys_open((char __force_user *)name, 0, 0);
68134 if (fd < 0) {
68135 printk(KERN_ERR "md: open failed - cannot start "
68136 "array %s\n", name);
68137 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
68138 * array without it
68139 */
68140 sys_close(fd);
68141 - fd = sys_open(name, 0, 0);
68142 + fd = sys_open((char __force_user *)name, 0, 0);
68143 sys_ioctl(fd, BLKRRPART, 0);
68144 }
68145 sys_close(fd);
68146 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
68147
68148 wait_for_device_probe();
68149
68150 - fd = sys_open("/dev/md0", 0, 0);
68151 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
68152 if (fd >= 0) {
68153 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
68154 sys_close(fd);
68155 diff --git a/init/init_task.c b/init/init_task.c
68156 index 8b2f399..f0797c9 100644
68157 --- a/init/init_task.c
68158 +++ b/init/init_task.c
68159 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
68160 * Initial thread structure. Alignment of this is handled by a special
68161 * linker map entry.
68162 */
68163 +#ifdef CONFIG_X86
68164 +union thread_union init_thread_union __init_task_data;
68165 +#else
68166 union thread_union init_thread_union __init_task_data =
68167 { INIT_THREAD_INFO(init_task) };
68168 +#endif
68169 diff --git a/init/initramfs.c b/init/initramfs.c
68170 index 84c6bf1..8899338 100644
68171 --- a/init/initramfs.c
68172 +++ b/init/initramfs.c
68173 @@ -84,7 +84,7 @@ static void __init free_hash(void)
68174 }
68175 }
68176
68177 -static long __init do_utime(char *filename, time_t mtime)
68178 +static long __init do_utime(char __force_user *filename, time_t mtime)
68179 {
68180 struct timespec t[2];
68181
68182 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
68183 struct dir_entry *de, *tmp;
68184 list_for_each_entry_safe(de, tmp, &dir_list, list) {
68185 list_del(&de->list);
68186 - do_utime(de->name, de->mtime);
68187 + do_utime((char __force_user *)de->name, de->mtime);
68188 kfree(de->name);
68189 kfree(de);
68190 }
68191 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
68192 if (nlink >= 2) {
68193 char *old = find_link(major, minor, ino, mode, collected);
68194 if (old)
68195 - return (sys_link(old, collected) < 0) ? -1 : 1;
68196 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
68197 }
68198 return 0;
68199 }
68200 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
68201 {
68202 struct stat st;
68203
68204 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
68205 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
68206 if (S_ISDIR(st.st_mode))
68207 - sys_rmdir(path);
68208 + sys_rmdir((char __force_user *)path);
68209 else
68210 - sys_unlink(path);
68211 + sys_unlink((char __force_user *)path);
68212 }
68213 }
68214
68215 @@ -315,7 +315,7 @@ static int __init do_name(void)
68216 int openflags = O_WRONLY|O_CREAT;
68217 if (ml != 1)
68218 openflags |= O_TRUNC;
68219 - wfd = sys_open(collected, openflags, mode);
68220 + wfd = sys_open((char __force_user *)collected, openflags, mode);
68221
68222 if (wfd >= 0) {
68223 sys_fchown(wfd, uid, gid);
68224 @@ -327,17 +327,17 @@ static int __init do_name(void)
68225 }
68226 }
68227 } else if (S_ISDIR(mode)) {
68228 - sys_mkdir(collected, mode);
68229 - sys_chown(collected, uid, gid);
68230 - sys_chmod(collected, mode);
68231 + sys_mkdir((char __force_user *)collected, mode);
68232 + sys_chown((char __force_user *)collected, uid, gid);
68233 + sys_chmod((char __force_user *)collected, mode);
68234 dir_add(collected, mtime);
68235 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
68236 S_ISFIFO(mode) || S_ISSOCK(mode)) {
68237 if (maybe_link() == 0) {
68238 - sys_mknod(collected, mode, rdev);
68239 - sys_chown(collected, uid, gid);
68240 - sys_chmod(collected, mode);
68241 - do_utime(collected, mtime);
68242 + sys_mknod((char __force_user *)collected, mode, rdev);
68243 + sys_chown((char __force_user *)collected, uid, gid);
68244 + sys_chmod((char __force_user *)collected, mode);
68245 + do_utime((char __force_user *)collected, mtime);
68246 }
68247 }
68248 return 0;
68249 @@ -346,15 +346,15 @@ static int __init do_name(void)
68250 static int __init do_copy(void)
68251 {
68252 if (count >= body_len) {
68253 - sys_write(wfd, victim, body_len);
68254 + sys_write(wfd, (char __force_user *)victim, body_len);
68255 sys_close(wfd);
68256 - do_utime(vcollected, mtime);
68257 + do_utime((char __force_user *)vcollected, mtime);
68258 kfree(vcollected);
68259 eat(body_len);
68260 state = SkipIt;
68261 return 0;
68262 } else {
68263 - sys_write(wfd, victim, count);
68264 + sys_write(wfd, (char __force_user *)victim, count);
68265 body_len -= count;
68266 eat(count);
68267 return 1;
68268 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
68269 {
68270 collected[N_ALIGN(name_len) + body_len] = '\0';
68271 clean_path(collected, 0);
68272 - sys_symlink(collected + N_ALIGN(name_len), collected);
68273 - sys_lchown(collected, uid, gid);
68274 - do_utime(collected, mtime);
68275 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
68276 + sys_lchown((char __force_user *)collected, uid, gid);
68277 + do_utime((char __force_user *)collected, mtime);
68278 state = SkipIt;
68279 next_state = Reset;
68280 return 0;
68281 diff --git a/init/main.c b/init/main.c
68282 index 857166f..9df1d8e 100644
68283 --- a/init/main.c
68284 +++ b/init/main.c
68285 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
68286 extern void tc_init(void);
68287 #endif
68288
68289 +extern void grsecurity_init(void);
68290 +
68291 /*
68292 * Debug helper: via this flag we know that we are in 'early bootup code'
68293 * where only the boot processor is running with IRQ disabled. This means
68294 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
68295
68296 __setup("reset_devices", set_reset_devices);
68297
68298 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68299 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
68300 +static int __init setup_grsec_proc_gid(char *str)
68301 +{
68302 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
68303 + return 1;
68304 +}
68305 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
68306 +#endif
68307 +
68308 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
68309 +extern char pax_enter_kernel_user[];
68310 +extern char pax_exit_kernel_user[];
68311 +extern pgdval_t clone_pgd_mask;
68312 +#endif
68313 +
68314 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
68315 +static int __init setup_pax_nouderef(char *str)
68316 +{
68317 +#ifdef CONFIG_X86_32
68318 + unsigned int cpu;
68319 + struct desc_struct *gdt;
68320 +
68321 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
68322 + gdt = get_cpu_gdt_table(cpu);
68323 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
68324 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
68325 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
68326 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
68327 + }
68328 + loadsegment(ds, __KERNEL_DS);
68329 + loadsegment(es, __KERNEL_DS);
68330 + loadsegment(ss, __KERNEL_DS);
68331 +#else
68332 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
68333 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
68334 + clone_pgd_mask = ~(pgdval_t)0UL;
68335 +#endif
68336 +
68337 + return 0;
68338 +}
68339 +early_param("pax_nouderef", setup_pax_nouderef);
68340 +#endif
68341 +
68342 +#ifdef CONFIG_PAX_SOFTMODE
68343 +int pax_softmode;
68344 +
68345 +static int __init setup_pax_softmode(char *str)
68346 +{
68347 + get_option(&str, &pax_softmode);
68348 + return 1;
68349 +}
68350 +__setup("pax_softmode=", setup_pax_softmode);
68351 +#endif
68352 +
68353 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
68354 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
68355 static const char *panic_later, *panic_param;
68356 @@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
68357 {
68358 int count = preempt_count();
68359 int ret;
68360 + const char *msg1 = "", *msg2 = "";
68361
68362 if (initcall_debug)
68363 ret = do_one_initcall_debug(fn);
68364 @@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
68365 sprintf(msgbuf, "error code %d ", ret);
68366
68367 if (preempt_count() != count) {
68368 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
68369 + msg1 = " preemption imbalance";
68370 preempt_count() = count;
68371 }
68372 if (irqs_disabled()) {
68373 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
68374 + msg2 = " disabled interrupts";
68375 local_irq_enable();
68376 }
68377 - if (msgbuf[0]) {
68378 - printk("initcall %pF returned with %s\n", fn, msgbuf);
68379 + if (msgbuf[0] || *msg1 || *msg2) {
68380 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
68381 }
68382
68383 return ret;
68384 @@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
68385 "late",
68386 };
68387
68388 +#ifdef CONFIG_PAX_LATENT_ENTROPY
68389 +u64 latent_entropy;
68390 +#endif
68391 +
68392 static void __init do_initcall_level(int level)
68393 {
68394 extern const struct kernel_param __start___param[], __stop___param[];
68395 @@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
68396 level, level,
68397 &repair_env_string);
68398
68399 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
68400 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
68401 do_one_initcall(*fn);
68402 +
68403 +#ifdef CONFIG_PAX_LATENT_ENTROPY
68404 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
68405 +#endif
68406 +
68407 + }
68408 }
68409
68410 static void __init do_initcalls(void)
68411 @@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
68412 {
68413 initcall_t *fn;
68414
68415 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
68416 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
68417 do_one_initcall(*fn);
68418 +
68419 +#ifdef CONFIG_PAX_LATENT_ENTROPY
68420 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
68421 +#endif
68422 +
68423 + }
68424 }
68425
68426 static int run_init_process(const char *init_filename)
68427 @@ -876,7 +950,7 @@ static noinline void __init kernel_init_freeable(void)
68428 do_basic_setup();
68429
68430 /* Open the /dev/console on the rootfs, this should never fail */
68431 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
68432 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
68433 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
68434
68435 (void) sys_dup(0);
68436 @@ -889,11 +963,13 @@ static noinline void __init kernel_init_freeable(void)
68437 if (!ramdisk_execute_command)
68438 ramdisk_execute_command = "/init";
68439
68440 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
68441 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
68442 ramdisk_execute_command = NULL;
68443 prepare_namespace();
68444 }
68445
68446 + grsecurity_init();
68447 +
68448 /*
68449 * Ok, we have completed the initial bootup, and
68450 * we're essentially up and running. Get rid of the
68451 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
68452 index 71a3ca1..cc330ee 100644
68453 --- a/ipc/mqueue.c
68454 +++ b/ipc/mqueue.c
68455 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
68456 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
68457 info->attr.mq_msgsize);
68458
68459 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
68460 spin_lock(&mq_lock);
68461 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
68462 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
68463 diff --git a/ipc/msg.c b/ipc/msg.c
68464 index a71af5a..a90a110 100644
68465 --- a/ipc/msg.c
68466 +++ b/ipc/msg.c
68467 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
68468 return security_msg_queue_associate(msq, msgflg);
68469 }
68470
68471 +static struct ipc_ops msg_ops = {
68472 + .getnew = newque,
68473 + .associate = msg_security,
68474 + .more_checks = NULL
68475 +};
68476 +
68477 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
68478 {
68479 struct ipc_namespace *ns;
68480 - struct ipc_ops msg_ops;
68481 struct ipc_params msg_params;
68482
68483 ns = current->nsproxy->ipc_ns;
68484
68485 - msg_ops.getnew = newque;
68486 - msg_ops.associate = msg_security;
68487 - msg_ops.more_checks = NULL;
68488 -
68489 msg_params.key = key;
68490 msg_params.flg = msgflg;
68491
68492 diff --git a/ipc/sem.c b/ipc/sem.c
68493 index 58d31f1..cce7a55 100644
68494 --- a/ipc/sem.c
68495 +++ b/ipc/sem.c
68496 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
68497 return 0;
68498 }
68499
68500 +static struct ipc_ops sem_ops = {
68501 + .getnew = newary,
68502 + .associate = sem_security,
68503 + .more_checks = sem_more_checks
68504 +};
68505 +
68506 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68507 {
68508 struct ipc_namespace *ns;
68509 - struct ipc_ops sem_ops;
68510 struct ipc_params sem_params;
68511
68512 ns = current->nsproxy->ipc_ns;
68513 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68514 if (nsems < 0 || nsems > ns->sc_semmsl)
68515 return -EINVAL;
68516
68517 - sem_ops.getnew = newary;
68518 - sem_ops.associate = sem_security;
68519 - sem_ops.more_checks = sem_more_checks;
68520 -
68521 sem_params.key = key;
68522 sem_params.flg = semflg;
68523 sem_params.u.nsems = nsems;
68524 diff --git a/ipc/shm.c b/ipc/shm.c
68525 index dff40c9..9450e27 100644
68526 --- a/ipc/shm.c
68527 +++ b/ipc/shm.c
68528 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
68529 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
68530 #endif
68531
68532 +#ifdef CONFIG_GRKERNSEC
68533 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68534 + const time_t shm_createtime, const uid_t cuid,
68535 + const int shmid);
68536 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68537 + const time_t shm_createtime);
68538 +#endif
68539 +
68540 void shm_init_ns(struct ipc_namespace *ns)
68541 {
68542 ns->shm_ctlmax = SHMMAX;
68543 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
68544 shp->shm_lprid = 0;
68545 shp->shm_atim = shp->shm_dtim = 0;
68546 shp->shm_ctim = get_seconds();
68547 +#ifdef CONFIG_GRKERNSEC
68548 + {
68549 + struct timespec timeval;
68550 + do_posix_clock_monotonic_gettime(&timeval);
68551 +
68552 + shp->shm_createtime = timeval.tv_sec;
68553 + }
68554 +#endif
68555 shp->shm_segsz = size;
68556 shp->shm_nattch = 0;
68557 shp->shm_file = file;
68558 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
68559 return 0;
68560 }
68561
68562 +static struct ipc_ops shm_ops = {
68563 + .getnew = newseg,
68564 + .associate = shm_security,
68565 + .more_checks = shm_more_checks
68566 +};
68567 +
68568 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
68569 {
68570 struct ipc_namespace *ns;
68571 - struct ipc_ops shm_ops;
68572 struct ipc_params shm_params;
68573
68574 ns = current->nsproxy->ipc_ns;
68575
68576 - shm_ops.getnew = newseg;
68577 - shm_ops.associate = shm_security;
68578 - shm_ops.more_checks = shm_more_checks;
68579 -
68580 shm_params.key = key;
68581 shm_params.flg = shmflg;
68582 shm_params.u.size = size;
68583 @@ -1003,6 +1020,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68584 f_mode = FMODE_READ | FMODE_WRITE;
68585 }
68586 if (shmflg & SHM_EXEC) {
68587 +
68588 +#ifdef CONFIG_PAX_MPROTECT
68589 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
68590 + goto out;
68591 +#endif
68592 +
68593 prot |= PROT_EXEC;
68594 acc_mode |= S_IXUGO;
68595 }
68596 @@ -1026,9 +1049,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68597 if (err)
68598 goto out_unlock;
68599
68600 +#ifdef CONFIG_GRKERNSEC
68601 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
68602 + shp->shm_perm.cuid, shmid) ||
68603 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
68604 + err = -EACCES;
68605 + goto out_unlock;
68606 + }
68607 +#endif
68608 +
68609 path = shp->shm_file->f_path;
68610 path_get(&path);
68611 shp->shm_nattch++;
68612 +#ifdef CONFIG_GRKERNSEC
68613 + shp->shm_lapid = current->pid;
68614 +#endif
68615 size = i_size_read(path.dentry->d_inode);
68616 shm_unlock(shp);
68617
68618 diff --git a/kernel/acct.c b/kernel/acct.c
68619 index 051e071..15e0920 100644
68620 --- a/kernel/acct.c
68621 +++ b/kernel/acct.c
68622 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
68623 */
68624 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
68625 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
68626 - file->f_op->write(file, (char *)&ac,
68627 + file->f_op->write(file, (char __force_user *)&ac,
68628 sizeof(acct_t), &file->f_pos);
68629 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
68630 set_fs(fs);
68631 diff --git a/kernel/audit.c b/kernel/audit.c
68632 index 40414e9..c920b72 100644
68633 --- a/kernel/audit.c
68634 +++ b/kernel/audit.c
68635 @@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
68636 3) suppressed due to audit_rate_limit
68637 4) suppressed due to audit_backlog_limit
68638 */
68639 -static atomic_t audit_lost = ATOMIC_INIT(0);
68640 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
68641
68642 /* The netlink socket. */
68643 static struct sock *audit_sock;
68644 @@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
68645 unsigned long now;
68646 int print;
68647
68648 - atomic_inc(&audit_lost);
68649 + atomic_inc_unchecked(&audit_lost);
68650
68651 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
68652
68653 @@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
68654 printk(KERN_WARNING
68655 "audit: audit_lost=%d audit_rate_limit=%d "
68656 "audit_backlog_limit=%d\n",
68657 - atomic_read(&audit_lost),
68658 + atomic_read_unchecked(&audit_lost),
68659 audit_rate_limit,
68660 audit_backlog_limit);
68661 audit_panic(message);
68662 @@ -677,7 +677,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
68663 status_set.pid = audit_pid;
68664 status_set.rate_limit = audit_rate_limit;
68665 status_set.backlog_limit = audit_backlog_limit;
68666 - status_set.lost = atomic_read(&audit_lost);
68667 + status_set.lost = atomic_read_unchecked(&audit_lost);
68668 status_set.backlog = skb_queue_len(&audit_skb_queue);
68669 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
68670 &status_set, sizeof(status_set));
68671 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
68672 index 157e989..b28b365 100644
68673 --- a/kernel/auditsc.c
68674 +++ b/kernel/auditsc.c
68675 @@ -2352,7 +2352,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
68676 }
68677
68678 /* global counter which is incremented every time something logs in */
68679 -static atomic_t session_id = ATOMIC_INIT(0);
68680 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
68681
68682 /**
68683 * audit_set_loginuid - set current task's audit_context loginuid
68684 @@ -2376,7 +2376,7 @@ int audit_set_loginuid(kuid_t loginuid)
68685 return -EPERM;
68686 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
68687
68688 - sessionid = atomic_inc_return(&session_id);
68689 + sessionid = atomic_inc_return_unchecked(&session_id);
68690 if (context && context->in_syscall) {
68691 struct audit_buffer *ab;
68692
68693 diff --git a/kernel/capability.c b/kernel/capability.c
68694 index 493d972..ea17248 100644
68695 --- a/kernel/capability.c
68696 +++ b/kernel/capability.c
68697 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
68698 * before modification is attempted and the application
68699 * fails.
68700 */
68701 + if (tocopy > ARRAY_SIZE(kdata))
68702 + return -EFAULT;
68703 +
68704 if (copy_to_user(dataptr, kdata, tocopy
68705 * sizeof(struct __user_cap_data_struct))) {
68706 return -EFAULT;
68707 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
68708 int ret;
68709
68710 rcu_read_lock();
68711 - ret = security_capable(__task_cred(t), ns, cap);
68712 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
68713 + gr_task_is_capable(t, __task_cred(t), cap);
68714 rcu_read_unlock();
68715
68716 - return (ret == 0);
68717 + return ret;
68718 }
68719
68720 /**
68721 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
68722 int ret;
68723
68724 rcu_read_lock();
68725 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
68726 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
68727 rcu_read_unlock();
68728
68729 - return (ret == 0);
68730 + return ret;
68731 }
68732
68733 /**
68734 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
68735 BUG();
68736 }
68737
68738 - if (security_capable(current_cred(), ns, cap) == 0) {
68739 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
68740 current->flags |= PF_SUPERPRIV;
68741 return true;
68742 }
68743 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
68744 }
68745 EXPORT_SYMBOL(ns_capable);
68746
68747 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
68748 +{
68749 + if (unlikely(!cap_valid(cap))) {
68750 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
68751 + BUG();
68752 + }
68753 +
68754 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
68755 + current->flags |= PF_SUPERPRIV;
68756 + return true;
68757 + }
68758 + return false;
68759 +}
68760 +EXPORT_SYMBOL(ns_capable_nolog);
68761 +
68762 /**
68763 * capable - Determine if the current task has a superior capability in effect
68764 * @cap: The capability to be tested for
68765 @@ -408,6 +427,12 @@ bool capable(int cap)
68766 }
68767 EXPORT_SYMBOL(capable);
68768
68769 +bool capable_nolog(int cap)
68770 +{
68771 + return ns_capable_nolog(&init_user_ns, cap);
68772 +}
68773 +EXPORT_SYMBOL(capable_nolog);
68774 +
68775 /**
68776 * nsown_capable - Check superior capability to one's own user_ns
68777 * @cap: The capability in question
68778 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
68779
68780 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68781 }
68782 +
68783 +bool inode_capable_nolog(const struct inode *inode, int cap)
68784 +{
68785 + struct user_namespace *ns = current_user_ns();
68786 +
68787 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68788 +}
68789 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
68790 index ad99830..992d8a7 100644
68791 --- a/kernel/cgroup.c
68792 +++ b/kernel/cgroup.c
68793 @@ -5514,7 +5514,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
68794 struct css_set *cg = link->cg;
68795 struct task_struct *task;
68796 int count = 0;
68797 - seq_printf(seq, "css_set %p\n", cg);
68798 + seq_printf(seq, "css_set %pK\n", cg);
68799 list_for_each_entry(task, &cg->tasks, cg_list) {
68800 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
68801 seq_puts(seq, " ...\n");
68802 diff --git a/kernel/compat.c b/kernel/compat.c
68803 index c28a306..b4d0cf3 100644
68804 --- a/kernel/compat.c
68805 +++ b/kernel/compat.c
68806 @@ -13,6 +13,7 @@
68807
68808 #include <linux/linkage.h>
68809 #include <linux/compat.h>
68810 +#include <linux/module.h>
68811 #include <linux/errno.h>
68812 #include <linux/time.h>
68813 #include <linux/signal.h>
68814 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
68815 mm_segment_t oldfs;
68816 long ret;
68817
68818 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
68819 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
68820 oldfs = get_fs();
68821 set_fs(KERNEL_DS);
68822 ret = hrtimer_nanosleep_restart(restart);
68823 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
68824 oldfs = get_fs();
68825 set_fs(KERNEL_DS);
68826 ret = hrtimer_nanosleep(&tu,
68827 - rmtp ? (struct timespec __user *)&rmt : NULL,
68828 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
68829 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
68830 set_fs(oldfs);
68831
68832 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
68833 mm_segment_t old_fs = get_fs();
68834
68835 set_fs(KERNEL_DS);
68836 - ret = sys_sigpending((old_sigset_t __user *) &s);
68837 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
68838 set_fs(old_fs);
68839 if (ret == 0)
68840 ret = put_user(s, set);
68841 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
68842 mm_segment_t old_fs = get_fs();
68843
68844 set_fs(KERNEL_DS);
68845 - ret = sys_old_getrlimit(resource, &r);
68846 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
68847 set_fs(old_fs);
68848
68849 if (!ret) {
68850 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
68851 mm_segment_t old_fs = get_fs();
68852
68853 set_fs(KERNEL_DS);
68854 - ret = sys_getrusage(who, (struct rusage __user *) &r);
68855 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
68856 set_fs(old_fs);
68857
68858 if (ret)
68859 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
68860 set_fs (KERNEL_DS);
68861 ret = sys_wait4(pid,
68862 (stat_addr ?
68863 - (unsigned int __user *) &status : NULL),
68864 - options, (struct rusage __user *) &r);
68865 + (unsigned int __force_user *) &status : NULL),
68866 + options, (struct rusage __force_user *) &r);
68867 set_fs (old_fs);
68868
68869 if (ret > 0) {
68870 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
68871 memset(&info, 0, sizeof(info));
68872
68873 set_fs(KERNEL_DS);
68874 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
68875 - uru ? (struct rusage __user *)&ru : NULL);
68876 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
68877 + uru ? (struct rusage __force_user *)&ru : NULL);
68878 set_fs(old_fs);
68879
68880 if ((ret < 0) || (info.si_signo == 0))
68881 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
68882 oldfs = get_fs();
68883 set_fs(KERNEL_DS);
68884 err = sys_timer_settime(timer_id, flags,
68885 - (struct itimerspec __user *) &newts,
68886 - (struct itimerspec __user *) &oldts);
68887 + (struct itimerspec __force_user *) &newts,
68888 + (struct itimerspec __force_user *) &oldts);
68889 set_fs(oldfs);
68890 if (!err && old && put_compat_itimerspec(old, &oldts))
68891 return -EFAULT;
68892 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
68893 oldfs = get_fs();
68894 set_fs(KERNEL_DS);
68895 err = sys_timer_gettime(timer_id,
68896 - (struct itimerspec __user *) &ts);
68897 + (struct itimerspec __force_user *) &ts);
68898 set_fs(oldfs);
68899 if (!err && put_compat_itimerspec(setting, &ts))
68900 return -EFAULT;
68901 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
68902 oldfs = get_fs();
68903 set_fs(KERNEL_DS);
68904 err = sys_clock_settime(which_clock,
68905 - (struct timespec __user *) &ts);
68906 + (struct timespec __force_user *) &ts);
68907 set_fs(oldfs);
68908 return err;
68909 }
68910 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
68911 oldfs = get_fs();
68912 set_fs(KERNEL_DS);
68913 err = sys_clock_gettime(which_clock,
68914 - (struct timespec __user *) &ts);
68915 + (struct timespec __force_user *) &ts);
68916 set_fs(oldfs);
68917 if (!err && put_compat_timespec(&ts, tp))
68918 return -EFAULT;
68919 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
68920
68921 oldfs = get_fs();
68922 set_fs(KERNEL_DS);
68923 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
68924 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
68925 set_fs(oldfs);
68926
68927 err = compat_put_timex(utp, &txc);
68928 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
68929 oldfs = get_fs();
68930 set_fs(KERNEL_DS);
68931 err = sys_clock_getres(which_clock,
68932 - (struct timespec __user *) &ts);
68933 + (struct timespec __force_user *) &ts);
68934 set_fs(oldfs);
68935 if (!err && tp && put_compat_timespec(&ts, tp))
68936 return -EFAULT;
68937 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
68938 long err;
68939 mm_segment_t oldfs;
68940 struct timespec tu;
68941 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
68942 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
68943
68944 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
68945 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
68946 oldfs = get_fs();
68947 set_fs(KERNEL_DS);
68948 err = clock_nanosleep_restart(restart);
68949 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
68950 oldfs = get_fs();
68951 set_fs(KERNEL_DS);
68952 err = sys_clock_nanosleep(which_clock, flags,
68953 - (struct timespec __user *) &in,
68954 - (struct timespec __user *) &out);
68955 + (struct timespec __force_user *) &in,
68956 + (struct timespec __force_user *) &out);
68957 set_fs(oldfs);
68958
68959 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
68960 diff --git a/kernel/configs.c b/kernel/configs.c
68961 index 42e8fa0..9e7406b 100644
68962 --- a/kernel/configs.c
68963 +++ b/kernel/configs.c
68964 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
68965 struct proc_dir_entry *entry;
68966
68967 /* create the current config file */
68968 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
68969 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
68970 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
68971 + &ikconfig_file_ops);
68972 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68973 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
68974 + &ikconfig_file_ops);
68975 +#endif
68976 +#else
68977 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
68978 &ikconfig_file_ops);
68979 +#endif
68980 +
68981 if (!entry)
68982 return -ENOMEM;
68983
68984 diff --git a/kernel/cred.c b/kernel/cred.c
68985 index 48cea3d..3476734 100644
68986 --- a/kernel/cred.c
68987 +++ b/kernel/cred.c
68988 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
68989 validate_creds(cred);
68990 alter_cred_subscribers(cred, -1);
68991 put_cred(cred);
68992 +
68993 +#ifdef CONFIG_GRKERNSEC_SETXID
68994 + cred = (struct cred *) tsk->delayed_cred;
68995 + if (cred != NULL) {
68996 + tsk->delayed_cred = NULL;
68997 + validate_creds(cred);
68998 + alter_cred_subscribers(cred, -1);
68999 + put_cred(cred);
69000 + }
69001 +#endif
69002 }
69003
69004 /**
69005 @@ -469,7 +479,7 @@ error_put:
69006 * Always returns 0 thus allowing this function to be tail-called at the end
69007 * of, say, sys_setgid().
69008 */
69009 -int commit_creds(struct cred *new)
69010 +static int __commit_creds(struct cred *new)
69011 {
69012 struct task_struct *task = current;
69013 const struct cred *old = task->real_cred;
69014 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
69015
69016 get_cred(new); /* we will require a ref for the subj creds too */
69017
69018 + gr_set_role_label(task, new->uid, new->gid);
69019 +
69020 /* dumpability changes */
69021 if (!uid_eq(old->euid, new->euid) ||
69022 !gid_eq(old->egid, new->egid) ||
69023 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
69024 put_cred(old);
69025 return 0;
69026 }
69027 +#ifdef CONFIG_GRKERNSEC_SETXID
69028 +extern int set_user(struct cred *new);
69029 +
69030 +void gr_delayed_cred_worker(void)
69031 +{
69032 + const struct cred *new = current->delayed_cred;
69033 + struct cred *ncred;
69034 +
69035 + current->delayed_cred = NULL;
69036 +
69037 + if (current_uid() && new != NULL) {
69038 + // from doing get_cred on it when queueing this
69039 + put_cred(new);
69040 + return;
69041 + } else if (new == NULL)
69042 + return;
69043 +
69044 + ncred = prepare_creds();
69045 + if (!ncred)
69046 + goto die;
69047 + // uids
69048 + ncred->uid = new->uid;
69049 + ncred->euid = new->euid;
69050 + ncred->suid = new->suid;
69051 + ncred->fsuid = new->fsuid;
69052 + // gids
69053 + ncred->gid = new->gid;
69054 + ncred->egid = new->egid;
69055 + ncred->sgid = new->sgid;
69056 + ncred->fsgid = new->fsgid;
69057 + // groups
69058 + if (set_groups(ncred, new->group_info) < 0) {
69059 + abort_creds(ncred);
69060 + goto die;
69061 + }
69062 + // caps
69063 + ncred->securebits = new->securebits;
69064 + ncred->cap_inheritable = new->cap_inheritable;
69065 + ncred->cap_permitted = new->cap_permitted;
69066 + ncred->cap_effective = new->cap_effective;
69067 + ncred->cap_bset = new->cap_bset;
69068 +
69069 + if (set_user(ncred)) {
69070 + abort_creds(ncred);
69071 + goto die;
69072 + }
69073 +
69074 + // from doing get_cred on it when queueing this
69075 + put_cred(new);
69076 +
69077 + __commit_creds(ncred);
69078 + return;
69079 +die:
69080 + // from doing get_cred on it when queueing this
69081 + put_cred(new);
69082 + do_group_exit(SIGKILL);
69083 +}
69084 +#endif
69085 +
69086 +int commit_creds(struct cred *new)
69087 +{
69088 +#ifdef CONFIG_GRKERNSEC_SETXID
69089 + int ret;
69090 + int schedule_it = 0;
69091 + struct task_struct *t;
69092 +
69093 + /* we won't get called with tasklist_lock held for writing
69094 + and interrupts disabled as the cred struct in that case is
69095 + init_cred
69096 + */
69097 + if (grsec_enable_setxid && !current_is_single_threaded() &&
69098 + !current_uid() && new->uid) {
69099 + schedule_it = 1;
69100 + }
69101 + ret = __commit_creds(new);
69102 + if (schedule_it) {
69103 + rcu_read_lock();
69104 + read_lock(&tasklist_lock);
69105 + for (t = next_thread(current); t != current;
69106 + t = next_thread(t)) {
69107 + if (t->delayed_cred == NULL) {
69108 + t->delayed_cred = get_cred(new);
69109 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
69110 + set_tsk_need_resched(t);
69111 + }
69112 + }
69113 + read_unlock(&tasklist_lock);
69114 + rcu_read_unlock();
69115 + }
69116 + return ret;
69117 +#else
69118 + return __commit_creds(new);
69119 +#endif
69120 +}
69121 +
69122 EXPORT_SYMBOL(commit_creds);
69123
69124 /**
69125 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
69126 index 9a61738..c5c8f3a 100644
69127 --- a/kernel/debug/debug_core.c
69128 +++ b/kernel/debug/debug_core.c
69129 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
69130 */
69131 static atomic_t masters_in_kgdb;
69132 static atomic_t slaves_in_kgdb;
69133 -static atomic_t kgdb_break_tasklet_var;
69134 +static atomic_unchecked_t kgdb_break_tasklet_var;
69135 atomic_t kgdb_setting_breakpoint;
69136
69137 struct task_struct *kgdb_usethread;
69138 @@ -132,7 +132,7 @@ int kgdb_single_step;
69139 static pid_t kgdb_sstep_pid;
69140
69141 /* to keep track of the CPU which is doing the single stepping*/
69142 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69143 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69144
69145 /*
69146 * If you are debugging a problem where roundup (the collection of
69147 @@ -540,7 +540,7 @@ return_normal:
69148 * kernel will only try for the value of sstep_tries before
69149 * giving up and continuing on.
69150 */
69151 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
69152 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
69153 (kgdb_info[cpu].task &&
69154 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
69155 atomic_set(&kgdb_active, -1);
69156 @@ -634,8 +634,8 @@ cpu_master_loop:
69157 }
69158
69159 kgdb_restore:
69160 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
69161 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
69162 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
69163 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
69164 if (kgdb_info[sstep_cpu].task)
69165 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
69166 else
69167 @@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
69168 static void kgdb_tasklet_bpt(unsigned long ing)
69169 {
69170 kgdb_breakpoint();
69171 - atomic_set(&kgdb_break_tasklet_var, 0);
69172 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
69173 }
69174
69175 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
69176
69177 void kgdb_schedule_breakpoint(void)
69178 {
69179 - if (atomic_read(&kgdb_break_tasklet_var) ||
69180 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
69181 atomic_read(&kgdb_active) != -1 ||
69182 atomic_read(&kgdb_setting_breakpoint))
69183 return;
69184 - atomic_inc(&kgdb_break_tasklet_var);
69185 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
69186 tasklet_schedule(&kgdb_tasklet_breakpoint);
69187 }
69188 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
69189 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
69190 index 8875254..7cf4928 100644
69191 --- a/kernel/debug/kdb/kdb_main.c
69192 +++ b/kernel/debug/kdb/kdb_main.c
69193 @@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
69194 continue;
69195
69196 kdb_printf("%-20s%8u 0x%p ", mod->name,
69197 - mod->core_size, (void *)mod);
69198 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
69199 #ifdef CONFIG_MODULE_UNLOAD
69200 kdb_printf("%4ld ", module_refcount(mod));
69201 #endif
69202 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
69203 kdb_printf(" (Loading)");
69204 else
69205 kdb_printf(" (Live)");
69206 - kdb_printf(" 0x%p", mod->module_core);
69207 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
69208
69209 #ifdef CONFIG_MODULE_UNLOAD
69210 {
69211 diff --git a/kernel/events/core.c b/kernel/events/core.c
69212 index dbccf83..8c66482 100644
69213 --- a/kernel/events/core.c
69214 +++ b/kernel/events/core.c
69215 @@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
69216 return 0;
69217 }
69218
69219 -static atomic64_t perf_event_id;
69220 +static atomic64_unchecked_t perf_event_id;
69221
69222 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
69223 enum event_type_t event_type);
69224 @@ -2668,7 +2668,7 @@ static void __perf_event_read(void *info)
69225
69226 static inline u64 perf_event_count(struct perf_event *event)
69227 {
69228 - return local64_read(&event->count) + atomic64_read(&event->child_count);
69229 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
69230 }
69231
69232 static u64 perf_event_read(struct perf_event *event)
69233 @@ -2998,9 +2998,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
69234 mutex_lock(&event->child_mutex);
69235 total += perf_event_read(event);
69236 *enabled += event->total_time_enabled +
69237 - atomic64_read(&event->child_total_time_enabled);
69238 + atomic64_read_unchecked(&event->child_total_time_enabled);
69239 *running += event->total_time_running +
69240 - atomic64_read(&event->child_total_time_running);
69241 + atomic64_read_unchecked(&event->child_total_time_running);
69242
69243 list_for_each_entry(child, &event->child_list, child_list) {
69244 total += perf_event_read(child);
69245 @@ -3403,10 +3403,10 @@ void perf_event_update_userpage(struct perf_event *event)
69246 userpg->offset -= local64_read(&event->hw.prev_count);
69247
69248 userpg->time_enabled = enabled +
69249 - atomic64_read(&event->child_total_time_enabled);
69250 + atomic64_read_unchecked(&event->child_total_time_enabled);
69251
69252 userpg->time_running = running +
69253 - atomic64_read(&event->child_total_time_running);
69254 + atomic64_read_unchecked(&event->child_total_time_running);
69255
69256 arch_perf_update_userpage(userpg, now);
69257
69258 @@ -3965,11 +3965,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
69259 values[n++] = perf_event_count(event);
69260 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
69261 values[n++] = enabled +
69262 - atomic64_read(&event->child_total_time_enabled);
69263 + atomic64_read_unchecked(&event->child_total_time_enabled);
69264 }
69265 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
69266 values[n++] = running +
69267 - atomic64_read(&event->child_total_time_running);
69268 + atomic64_read_unchecked(&event->child_total_time_running);
69269 }
69270 if (read_format & PERF_FORMAT_ID)
69271 values[n++] = primary_event_id(event);
69272 @@ -4712,12 +4712,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
69273 * need to add enough zero bytes after the string to handle
69274 * the 64bit alignment we do later.
69275 */
69276 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
69277 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
69278 if (!buf) {
69279 name = strncpy(tmp, "//enomem", sizeof(tmp));
69280 goto got_name;
69281 }
69282 - name = d_path(&file->f_path, buf, PATH_MAX);
69283 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
69284 if (IS_ERR(name)) {
69285 name = strncpy(tmp, "//toolong", sizeof(tmp));
69286 goto got_name;
69287 @@ -6156,7 +6156,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
69288 event->parent = parent_event;
69289
69290 event->ns = get_pid_ns(current->nsproxy->pid_ns);
69291 - event->id = atomic64_inc_return(&perf_event_id);
69292 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
69293
69294 event->state = PERF_EVENT_STATE_INACTIVE;
69295
69296 @@ -6774,10 +6774,10 @@ static void sync_child_event(struct perf_event *child_event,
69297 /*
69298 * Add back the child's count to the parent's count:
69299 */
69300 - atomic64_add(child_val, &parent_event->child_count);
69301 - atomic64_add(child_event->total_time_enabled,
69302 + atomic64_add_unchecked(child_val, &parent_event->child_count);
69303 + atomic64_add_unchecked(child_event->total_time_enabled,
69304 &parent_event->child_total_time_enabled);
69305 - atomic64_add(child_event->total_time_running,
69306 + atomic64_add_unchecked(child_event->total_time_running,
69307 &parent_event->child_total_time_running);
69308
69309 /*
69310 diff --git a/kernel/exit.c b/kernel/exit.c
69311 index 346616c..f103b28 100644
69312 --- a/kernel/exit.c
69313 +++ b/kernel/exit.c
69314 @@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
69315 struct task_struct *leader;
69316 int zap_leader;
69317 repeat:
69318 +#ifdef CONFIG_NET
69319 + gr_del_task_from_ip_table(p);
69320 +#endif
69321 +
69322 /* don't need to get the RCU readlock here - the process is dead and
69323 * can't be modifying its own credentials. But shut RCU-lockdep up */
69324 rcu_read_lock();
69325 @@ -394,7 +398,7 @@ int allow_signal(int sig)
69326 * know it'll be handled, so that they don't get converted to
69327 * SIGKILL or just silently dropped.
69328 */
69329 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
69330 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
69331 recalc_sigpending();
69332 spin_unlock_irq(&current->sighand->siglock);
69333 return 0;
69334 @@ -430,6 +434,9 @@ void daemonize(const char *name, ...)
69335 vsnprintf(current->comm, sizeof(current->comm), name, args);
69336 va_end(args);
69337
69338 + gr_put_exec_file(current);
69339 + gr_set_kernel_label(current);
69340 +
69341 /*
69342 * If we were started as result of loading a module, close all of the
69343 * user space pages. We don't need them, and if we didn't close them
69344 @@ -812,6 +819,8 @@ void do_exit(long code)
69345 struct task_struct *tsk = current;
69346 int group_dead;
69347
69348 + set_fs(USER_DS);
69349 +
69350 profile_task_exit(tsk);
69351
69352 WARN_ON(blk_needs_flush_plug(tsk));
69353 @@ -828,7 +837,6 @@ void do_exit(long code)
69354 * mm_release()->clear_child_tid() from writing to a user-controlled
69355 * kernel address.
69356 */
69357 - set_fs(USER_DS);
69358
69359 ptrace_event(PTRACE_EVENT_EXIT, code);
69360
69361 @@ -887,6 +895,9 @@ void do_exit(long code)
69362 tsk->exit_code = code;
69363 taskstats_exit(tsk, group_dead);
69364
69365 + gr_acl_handle_psacct(tsk, code);
69366 + gr_acl_handle_exit();
69367 +
69368 exit_mm(tsk);
69369
69370 if (group_dead)
69371 @@ -1007,7 +1018,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
69372 * Take down every thread in the group. This is called by fatal signals
69373 * as well as by sys_exit_group (below).
69374 */
69375 -void
69376 +__noreturn void
69377 do_group_exit(int exit_code)
69378 {
69379 struct signal_struct *sig = current->signal;
69380 diff --git a/kernel/fork.c b/kernel/fork.c
69381 index acc4cb6..b524cb5 100644
69382 --- a/kernel/fork.c
69383 +++ b/kernel/fork.c
69384 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
69385 *stackend = STACK_END_MAGIC; /* for overflow detection */
69386
69387 #ifdef CONFIG_CC_STACKPROTECTOR
69388 - tsk->stack_canary = get_random_int();
69389 + tsk->stack_canary = pax_get_random_long();
69390 #endif
69391
69392 /*
69393 @@ -344,13 +344,81 @@ free_tsk:
69394 }
69395
69396 #ifdef CONFIG_MMU
69397 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
69398 +{
69399 + struct vm_area_struct *tmp;
69400 + unsigned long charge;
69401 + struct mempolicy *pol;
69402 + struct file *file;
69403 +
69404 + charge = 0;
69405 + if (mpnt->vm_flags & VM_ACCOUNT) {
69406 + unsigned long len = vma_pages(mpnt);
69407 +
69408 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
69409 + goto fail_nomem;
69410 + charge = len;
69411 + }
69412 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69413 + if (!tmp)
69414 + goto fail_nomem;
69415 + *tmp = *mpnt;
69416 + tmp->vm_mm = mm;
69417 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
69418 + pol = mpol_dup(vma_policy(mpnt));
69419 + if (IS_ERR(pol))
69420 + goto fail_nomem_policy;
69421 + vma_set_policy(tmp, pol);
69422 + if (anon_vma_fork(tmp, mpnt))
69423 + goto fail_nomem_anon_vma_fork;
69424 + tmp->vm_flags &= ~VM_LOCKED;
69425 + tmp->vm_next = tmp->vm_prev = NULL;
69426 + tmp->vm_mirror = NULL;
69427 + file = tmp->vm_file;
69428 + if (file) {
69429 + struct inode *inode = file->f_path.dentry->d_inode;
69430 + struct address_space *mapping = file->f_mapping;
69431 +
69432 + get_file(file);
69433 + if (tmp->vm_flags & VM_DENYWRITE)
69434 + atomic_dec(&inode->i_writecount);
69435 + mutex_lock(&mapping->i_mmap_mutex);
69436 + if (tmp->vm_flags & VM_SHARED)
69437 + mapping->i_mmap_writable++;
69438 + flush_dcache_mmap_lock(mapping);
69439 + /* insert tmp into the share list, just after mpnt */
69440 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69441 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
69442 + else
69443 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
69444 + flush_dcache_mmap_unlock(mapping);
69445 + mutex_unlock(&mapping->i_mmap_mutex);
69446 + }
69447 +
69448 + /*
69449 + * Clear hugetlb-related page reserves for children. This only
69450 + * affects MAP_PRIVATE mappings. Faults generated by the child
69451 + * are not guaranteed to succeed, even if read-only
69452 + */
69453 + if (is_vm_hugetlb_page(tmp))
69454 + reset_vma_resv_huge_pages(tmp);
69455 +
69456 + return tmp;
69457 +
69458 +fail_nomem_anon_vma_fork:
69459 + mpol_put(pol);
69460 +fail_nomem_policy:
69461 + kmem_cache_free(vm_area_cachep, tmp);
69462 +fail_nomem:
69463 + vm_unacct_memory(charge);
69464 + return NULL;
69465 +}
69466 +
69467 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69468 {
69469 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
69470 struct rb_node **rb_link, *rb_parent;
69471 int retval;
69472 - unsigned long charge;
69473 - struct mempolicy *pol;
69474
69475 down_write(&oldmm->mmap_sem);
69476 flush_cache_dup_mm(oldmm);
69477 @@ -363,8 +431,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69478 mm->locked_vm = 0;
69479 mm->mmap = NULL;
69480 mm->mmap_cache = NULL;
69481 - mm->free_area_cache = oldmm->mmap_base;
69482 - mm->cached_hole_size = ~0UL;
69483 + mm->free_area_cache = oldmm->free_area_cache;
69484 + mm->cached_hole_size = oldmm->cached_hole_size;
69485 mm->map_count = 0;
69486 cpumask_clear(mm_cpumask(mm));
69487 mm->mm_rb = RB_ROOT;
69488 @@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69489
69490 prev = NULL;
69491 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
69492 - struct file *file;
69493 -
69494 if (mpnt->vm_flags & VM_DONTCOPY) {
69495 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
69496 -vma_pages(mpnt));
69497 continue;
69498 }
69499 - charge = 0;
69500 - if (mpnt->vm_flags & VM_ACCOUNT) {
69501 - unsigned long len = vma_pages(mpnt);
69502 -
69503 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
69504 - goto fail_nomem;
69505 - charge = len;
69506 - }
69507 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69508 - if (!tmp)
69509 - goto fail_nomem;
69510 - *tmp = *mpnt;
69511 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
69512 - pol = mpol_dup(vma_policy(mpnt));
69513 - retval = PTR_ERR(pol);
69514 - if (IS_ERR(pol))
69515 - goto fail_nomem_policy;
69516 - vma_set_policy(tmp, pol);
69517 - tmp->vm_mm = mm;
69518 - if (anon_vma_fork(tmp, mpnt))
69519 - goto fail_nomem_anon_vma_fork;
69520 - tmp->vm_flags &= ~VM_LOCKED;
69521 - tmp->vm_next = tmp->vm_prev = NULL;
69522 - file = tmp->vm_file;
69523 - if (file) {
69524 - struct inode *inode = file->f_path.dentry->d_inode;
69525 - struct address_space *mapping = file->f_mapping;
69526 -
69527 - get_file(file);
69528 - if (tmp->vm_flags & VM_DENYWRITE)
69529 - atomic_dec(&inode->i_writecount);
69530 - mutex_lock(&mapping->i_mmap_mutex);
69531 - if (tmp->vm_flags & VM_SHARED)
69532 - mapping->i_mmap_writable++;
69533 - flush_dcache_mmap_lock(mapping);
69534 - /* insert tmp into the share list, just after mpnt */
69535 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69536 - vma_nonlinear_insert(tmp,
69537 - &mapping->i_mmap_nonlinear);
69538 - else
69539 - vma_interval_tree_insert_after(tmp, mpnt,
69540 - &mapping->i_mmap);
69541 - flush_dcache_mmap_unlock(mapping);
69542 - mutex_unlock(&mapping->i_mmap_mutex);
69543 + tmp = dup_vma(mm, oldmm, mpnt);
69544 + if (!tmp) {
69545 + retval = -ENOMEM;
69546 + goto out;
69547 }
69548
69549 /*
69550 @@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69551 if (retval)
69552 goto out;
69553 }
69554 +
69555 +#ifdef CONFIG_PAX_SEGMEXEC
69556 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
69557 + struct vm_area_struct *mpnt_m;
69558 +
69559 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
69560 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
69561 +
69562 + if (!mpnt->vm_mirror)
69563 + continue;
69564 +
69565 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
69566 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
69567 + mpnt->vm_mirror = mpnt_m;
69568 + } else {
69569 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
69570 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
69571 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
69572 + mpnt->vm_mirror->vm_mirror = mpnt;
69573 + }
69574 + }
69575 + BUG_ON(mpnt_m);
69576 + }
69577 +#endif
69578 +
69579 /* a new mm has just been created */
69580 arch_dup_mmap(oldmm, mm);
69581 retval = 0;
69582 @@ -470,14 +521,6 @@ out:
69583 flush_tlb_mm(oldmm);
69584 up_write(&oldmm->mmap_sem);
69585 return retval;
69586 -fail_nomem_anon_vma_fork:
69587 - mpol_put(pol);
69588 -fail_nomem_policy:
69589 - kmem_cache_free(vm_area_cachep, tmp);
69590 -fail_nomem:
69591 - retval = -ENOMEM;
69592 - vm_unacct_memory(charge);
69593 - goto out;
69594 }
69595
69596 static inline int mm_alloc_pgd(struct mm_struct *mm)
69597 @@ -692,8 +735,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
69598 return ERR_PTR(err);
69599
69600 mm = get_task_mm(task);
69601 - if (mm && mm != current->mm &&
69602 - !ptrace_may_access(task, mode)) {
69603 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
69604 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
69605 mmput(mm);
69606 mm = ERR_PTR(-EACCES);
69607 }
69608 @@ -912,13 +955,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
69609 spin_unlock(&fs->lock);
69610 return -EAGAIN;
69611 }
69612 - fs->users++;
69613 + atomic_inc(&fs->users);
69614 spin_unlock(&fs->lock);
69615 return 0;
69616 }
69617 tsk->fs = copy_fs_struct(fs);
69618 if (!tsk->fs)
69619 return -ENOMEM;
69620 + /* Carry through gr_chroot_dentry and is_chrooted instead
69621 + of recomputing it here. Already copied when the task struct
69622 + is duplicated. This allows pivot_root to not be treated as
69623 + a chroot
69624 + */
69625 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
69626 +
69627 return 0;
69628 }
69629
69630 @@ -1183,6 +1233,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69631 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
69632 #endif
69633 retval = -EAGAIN;
69634 +
69635 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
69636 +
69637 if (atomic_read(&p->real_cred->user->processes) >=
69638 task_rlimit(p, RLIMIT_NPROC)) {
69639 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
69640 @@ -1422,6 +1475,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69641 goto bad_fork_free_pid;
69642 }
69643
69644 + /* synchronizes with gr_set_acls()
69645 + we need to call this past the point of no return for fork()
69646 + */
69647 + gr_copy_label(p);
69648 +
69649 if (clone_flags & CLONE_THREAD) {
69650 current->signal->nr_threads++;
69651 atomic_inc(&current->signal->live);
69652 @@ -1505,6 +1563,8 @@ bad_fork_cleanup_count:
69653 bad_fork_free:
69654 free_task(p);
69655 fork_out:
69656 + gr_log_forkfail(retval);
69657 +
69658 return ERR_PTR(retval);
69659 }
69660
69661 @@ -1605,6 +1665,8 @@ long do_fork(unsigned long clone_flags,
69662 if (clone_flags & CLONE_PARENT_SETTID)
69663 put_user(nr, parent_tidptr);
69664
69665 + gr_handle_brute_check();
69666 +
69667 if (clone_flags & CLONE_VFORK) {
69668 p->vfork_done = &vfork;
69669 init_completion(&vfork);
69670 @@ -1714,7 +1776,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
69671 return 0;
69672
69673 /* don't need lock here; in the worst case we'll do useless copy */
69674 - if (fs->users == 1)
69675 + if (atomic_read(&fs->users) == 1)
69676 return 0;
69677
69678 *new_fsp = copy_fs_struct(fs);
69679 @@ -1803,7 +1865,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
69680 fs = current->fs;
69681 spin_lock(&fs->lock);
69682 current->fs = new_fs;
69683 - if (--fs->users)
69684 + gr_set_chroot_entries(current, &current->fs->root);
69685 + if (atomic_dec_return(&fs->users))
69686 new_fs = NULL;
69687 else
69688 new_fs = fs;
69689 diff --git a/kernel/futex.c b/kernel/futex.c
69690 index 19eb089..b8c65ea 100644
69691 --- a/kernel/futex.c
69692 +++ b/kernel/futex.c
69693 @@ -54,6 +54,7 @@
69694 #include <linux/mount.h>
69695 #include <linux/pagemap.h>
69696 #include <linux/syscalls.h>
69697 +#include <linux/ptrace.h>
69698 #include <linux/signal.h>
69699 #include <linux/export.h>
69700 #include <linux/magic.h>
69701 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
69702 struct page *page, *page_head;
69703 int err, ro = 0;
69704
69705 +#ifdef CONFIG_PAX_SEGMEXEC
69706 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
69707 + return -EFAULT;
69708 +#endif
69709 +
69710 /*
69711 * The futex address must be "naturally" aligned.
69712 */
69713 @@ -2733,6 +2739,7 @@ static int __init futex_init(void)
69714 {
69715 u32 curval;
69716 int i;
69717 + mm_segment_t oldfs;
69718
69719 /*
69720 * This will fail and we want it. Some arch implementations do
69721 @@ -2744,8 +2751,11 @@ static int __init futex_init(void)
69722 * implementation, the non-functional ones will return
69723 * -ENOSYS.
69724 */
69725 + oldfs = get_fs();
69726 + set_fs(USER_DS);
69727 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
69728 futex_cmpxchg_enabled = 1;
69729 + set_fs(oldfs);
69730
69731 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
69732 plist_head_init(&futex_queues[i].chain);
69733 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
69734 index 9b22d03..6295b62 100644
69735 --- a/kernel/gcov/base.c
69736 +++ b/kernel/gcov/base.c
69737 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
69738 }
69739
69740 #ifdef CONFIG_MODULES
69741 -static inline int within(void *addr, void *start, unsigned long size)
69742 -{
69743 - return ((addr >= start) && (addr < start + size));
69744 -}
69745 -
69746 /* Update list and generate events when modules are unloaded. */
69747 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69748 void *data)
69749 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69750 prev = NULL;
69751 /* Remove entries located in module from linked list. */
69752 for (info = gcov_info_head; info; info = info->next) {
69753 - if (within(info, mod->module_core, mod->core_size)) {
69754 + if (within_module_core_rw((unsigned long)info, mod)) {
69755 if (prev)
69756 prev->next = info->next;
69757 else
69758 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
69759 index 6db7a5e..25b6648 100644
69760 --- a/kernel/hrtimer.c
69761 +++ b/kernel/hrtimer.c
69762 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
69763 local_irq_restore(flags);
69764 }
69765
69766 -static void run_hrtimer_softirq(struct softirq_action *h)
69767 +static void run_hrtimer_softirq(void)
69768 {
69769 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
69770
69771 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
69772 index 60f48fa..7f3a770 100644
69773 --- a/kernel/jump_label.c
69774 +++ b/kernel/jump_label.c
69775 @@ -13,6 +13,7 @@
69776 #include <linux/sort.h>
69777 #include <linux/err.h>
69778 #include <linux/static_key.h>
69779 +#include <linux/mm.h>
69780
69781 #ifdef HAVE_JUMP_LABEL
69782
69783 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
69784
69785 size = (((unsigned long)stop - (unsigned long)start)
69786 / sizeof(struct jump_entry));
69787 + pax_open_kernel();
69788 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
69789 + pax_close_kernel();
69790 }
69791
69792 static void jump_label_update(struct static_key *key, int enable);
69793 @@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
69794 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
69795 struct jump_entry *iter;
69796
69797 + pax_open_kernel();
69798 for (iter = iter_start; iter < iter_stop; iter++) {
69799 if (within_module_init(iter->code, mod))
69800 iter->code = 0;
69801 }
69802 + pax_close_kernel();
69803 }
69804
69805 static int
69806 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
69807 index 2169fee..45c017a 100644
69808 --- a/kernel/kallsyms.c
69809 +++ b/kernel/kallsyms.c
69810 @@ -11,6 +11,9 @@
69811 * Changed the compression method from stem compression to "table lookup"
69812 * compression (see scripts/kallsyms.c for a more complete description)
69813 */
69814 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69815 +#define __INCLUDED_BY_HIDESYM 1
69816 +#endif
69817 #include <linux/kallsyms.h>
69818 #include <linux/module.h>
69819 #include <linux/init.h>
69820 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
69821
69822 static inline int is_kernel_inittext(unsigned long addr)
69823 {
69824 + if (system_state != SYSTEM_BOOTING)
69825 + return 0;
69826 +
69827 if (addr >= (unsigned long)_sinittext
69828 && addr <= (unsigned long)_einittext)
69829 return 1;
69830 return 0;
69831 }
69832
69833 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69834 +#ifdef CONFIG_MODULES
69835 +static inline int is_module_text(unsigned long addr)
69836 +{
69837 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
69838 + return 1;
69839 +
69840 + addr = ktla_ktva(addr);
69841 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
69842 +}
69843 +#else
69844 +static inline int is_module_text(unsigned long addr)
69845 +{
69846 + return 0;
69847 +}
69848 +#endif
69849 +#endif
69850 +
69851 static inline int is_kernel_text(unsigned long addr)
69852 {
69853 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
69854 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
69855
69856 static inline int is_kernel(unsigned long addr)
69857 {
69858 +
69859 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69860 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
69861 + return 1;
69862 +
69863 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
69864 +#else
69865 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
69866 +#endif
69867 +
69868 return 1;
69869 return in_gate_area_no_mm(addr);
69870 }
69871
69872 static int is_ksym_addr(unsigned long addr)
69873 {
69874 +
69875 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69876 + if (is_module_text(addr))
69877 + return 0;
69878 +#endif
69879 +
69880 if (all_var)
69881 return is_kernel(addr);
69882
69883 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
69884
69885 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
69886 {
69887 - iter->name[0] = '\0';
69888 iter->nameoff = get_symbol_offset(new_pos);
69889 iter->pos = new_pos;
69890 }
69891 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
69892 {
69893 struct kallsym_iter *iter = m->private;
69894
69895 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69896 + if (current_uid())
69897 + return 0;
69898 +#endif
69899 +
69900 /* Some debugging symbols have no name. Ignore them. */
69901 if (!iter->name[0])
69902 return 0;
69903 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
69904 */
69905 type = iter->exported ? toupper(iter->type) :
69906 tolower(iter->type);
69907 +
69908 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
69909 type, iter->name, iter->module_name);
69910 } else
69911 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
69912 struct kallsym_iter *iter;
69913 int ret;
69914
69915 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
69916 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
69917 if (!iter)
69918 return -ENOMEM;
69919 reset_iter(iter, 0);
69920 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
69921 index 30b7b22..c726387 100644
69922 --- a/kernel/kcmp.c
69923 +++ b/kernel/kcmp.c
69924 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
69925 struct task_struct *task1, *task2;
69926 int ret;
69927
69928 +#ifdef CONFIG_GRKERNSEC
69929 + return -ENOSYS;
69930 +#endif
69931 +
69932 rcu_read_lock();
69933
69934 /*
69935 diff --git a/kernel/kexec.c b/kernel/kexec.c
69936 index 5e4bd78..00c5b91 100644
69937 --- a/kernel/kexec.c
69938 +++ b/kernel/kexec.c
69939 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
69940 unsigned long flags)
69941 {
69942 struct compat_kexec_segment in;
69943 - struct kexec_segment out, __user *ksegments;
69944 + struct kexec_segment out;
69945 + struct kexec_segment __user *ksegments;
69946 unsigned long i, result;
69947
69948 /* Don't allow clients that don't understand the native
69949 diff --git a/kernel/kmod.c b/kernel/kmod.c
69950 index 1c317e3..4a92a55 100644
69951 --- a/kernel/kmod.c
69952 +++ b/kernel/kmod.c
69953 @@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
69954 kfree(info->argv);
69955 }
69956
69957 -static int call_modprobe(char *module_name, int wait)
69958 +static int call_modprobe(char *module_name, char *module_param, int wait)
69959 {
69960 static char *envp[] = {
69961 "HOME=/",
69962 @@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
69963 NULL
69964 };
69965
69966 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
69967 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
69968 if (!argv)
69969 goto out;
69970
69971 @@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
69972 argv[1] = "-q";
69973 argv[2] = "--";
69974 argv[3] = module_name; /* check free_modprobe_argv() */
69975 - argv[4] = NULL;
69976 + argv[4] = module_param;
69977 + argv[5] = NULL;
69978
69979 return call_usermodehelper_fns(modprobe_path, argv, envp,
69980 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
69981 @@ -120,9 +121,8 @@ out:
69982 * If module auto-loading support is disabled then this function
69983 * becomes a no-operation.
69984 */
69985 -int __request_module(bool wait, const char *fmt, ...)
69986 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
69987 {
69988 - va_list args;
69989 char module_name[MODULE_NAME_LEN];
69990 unsigned int max_modprobes;
69991 int ret;
69992 @@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
69993 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
69994 static int kmod_loop_msg;
69995
69996 - va_start(args, fmt);
69997 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
69998 - va_end(args);
69999 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
70000 if (ret >= MODULE_NAME_LEN)
70001 return -ENAMETOOLONG;
70002
70003 @@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
70004 if (ret)
70005 return ret;
70006
70007 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70008 + if (!current_uid()) {
70009 + /* hack to workaround consolekit/udisks stupidity */
70010 + read_lock(&tasklist_lock);
70011 + if (!strcmp(current->comm, "mount") &&
70012 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
70013 + read_unlock(&tasklist_lock);
70014 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
70015 + return -EPERM;
70016 + }
70017 + read_unlock(&tasklist_lock);
70018 + }
70019 +#endif
70020 +
70021 /* If modprobe needs a service that is in a module, we get a recursive
70022 * loop. Limit the number of running kmod threads to max_threads/2 or
70023 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
70024 @@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
70025
70026 trace_module_request(module_name, wait, _RET_IP_);
70027
70028 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
70029 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
70030
70031 atomic_dec(&kmod_concurrent);
70032 return ret;
70033 }
70034 +
70035 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
70036 +{
70037 + va_list args;
70038 + int ret;
70039 +
70040 + va_start(args, fmt);
70041 + ret = ____request_module(wait, module_param, fmt, args);
70042 + va_end(args);
70043 +
70044 + return ret;
70045 +}
70046 +
70047 +int __request_module(bool wait, const char *fmt, ...)
70048 +{
70049 + va_list args;
70050 + int ret;
70051 +
70052 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70053 + if (current_uid()) {
70054 + char module_param[MODULE_NAME_LEN];
70055 +
70056 + memset(module_param, 0, sizeof(module_param));
70057 +
70058 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
70059 +
70060 + va_start(args, fmt);
70061 + ret = ____request_module(wait, module_param, fmt, args);
70062 + va_end(args);
70063 +
70064 + return ret;
70065 + }
70066 +#endif
70067 +
70068 + va_start(args, fmt);
70069 + ret = ____request_module(wait, NULL, fmt, args);
70070 + va_end(args);
70071 +
70072 + return ret;
70073 +}
70074 +
70075 EXPORT_SYMBOL(__request_module);
70076 #endif /* CONFIG_MODULES */
70077
70078 @@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
70079 *
70080 * Thus the __user pointer cast is valid here.
70081 */
70082 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
70083 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
70084
70085 /*
70086 * If ret is 0, either ____call_usermodehelper failed and the
70087 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
70088 index 098f396..fe85ff1 100644
70089 --- a/kernel/kprobes.c
70090 +++ b/kernel/kprobes.c
70091 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
70092 * kernel image and loaded module images reside. This is required
70093 * so x86_64 can correctly handle the %rip-relative fixups.
70094 */
70095 - kip->insns = module_alloc(PAGE_SIZE);
70096 + kip->insns = module_alloc_exec(PAGE_SIZE);
70097 if (!kip->insns) {
70098 kfree(kip);
70099 return NULL;
70100 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
70101 */
70102 if (!list_is_singular(&kip->list)) {
70103 list_del(&kip->list);
70104 - module_free(NULL, kip->insns);
70105 + module_free_exec(NULL, kip->insns);
70106 kfree(kip);
70107 }
70108 return 1;
70109 @@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
70110 {
70111 int i, err = 0;
70112 unsigned long offset = 0, size = 0;
70113 - char *modname, namebuf[128];
70114 + char *modname, namebuf[KSYM_NAME_LEN];
70115 const char *symbol_name;
70116 void *addr;
70117 struct kprobe_blackpoint *kb;
70118 @@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
70119 kprobe_type = "k";
70120
70121 if (sym)
70122 - seq_printf(pi, "%p %s %s+0x%x %s ",
70123 + seq_printf(pi, "%pK %s %s+0x%x %s ",
70124 p->addr, kprobe_type, sym, offset,
70125 (modname ? modname : " "));
70126 else
70127 - seq_printf(pi, "%p %s %p ",
70128 + seq_printf(pi, "%pK %s %pK ",
70129 p->addr, kprobe_type, p->addr);
70130
70131 if (!pp)
70132 @@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
70133 const char *sym = NULL;
70134 unsigned int i = *(loff_t *) v;
70135 unsigned long offset = 0;
70136 - char *modname, namebuf[128];
70137 + char *modname, namebuf[KSYM_NAME_LEN];
70138
70139 head = &kprobe_table[i];
70140 preempt_disable();
70141 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
70142 index 4e316e1..5501eef 100644
70143 --- a/kernel/ksysfs.c
70144 +++ b/kernel/ksysfs.c
70145 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
70146 {
70147 if (count+1 > UEVENT_HELPER_PATH_LEN)
70148 return -ENOENT;
70149 + if (!capable(CAP_SYS_ADMIN))
70150 + return -EPERM;
70151 memcpy(uevent_helper, buf, count);
70152 uevent_helper[count] = '\0';
70153 if (count && uevent_helper[count-1] == '\n')
70154 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
70155 index 7981e5b..7f2105c 100644
70156 --- a/kernel/lockdep.c
70157 +++ b/kernel/lockdep.c
70158 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
70159 end = (unsigned long) &_end,
70160 addr = (unsigned long) obj;
70161
70162 +#ifdef CONFIG_PAX_KERNEXEC
70163 + start = ktla_ktva(start);
70164 +#endif
70165 +
70166 /*
70167 * static variable?
70168 */
70169 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
70170 if (!static_obj(lock->key)) {
70171 debug_locks_off();
70172 printk("INFO: trying to register non-static key.\n");
70173 + printk("lock:%pS key:%pS.\n", lock, lock->key);
70174 printk("the code is fine but needs lockdep annotation.\n");
70175 printk("turning off the locking correctness validator.\n");
70176 dump_stack();
70177 @@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
70178 if (!class)
70179 return 0;
70180 }
70181 - atomic_inc((atomic_t *)&class->ops);
70182 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
70183 if (very_verbose(class)) {
70184 printk("\nacquire class [%p] %s", class->key, class->name);
70185 if (class->name_version > 1)
70186 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
70187 index 91c32a0..7b88d63 100644
70188 --- a/kernel/lockdep_proc.c
70189 +++ b/kernel/lockdep_proc.c
70190 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
70191
70192 static void print_name(struct seq_file *m, struct lock_class *class)
70193 {
70194 - char str[128];
70195 + char str[KSYM_NAME_LEN];
70196 const char *name = class->name;
70197
70198 if (!name) {
70199 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
70200 return 0;
70201 }
70202
70203 - seq_printf(m, "%p", class->key);
70204 + seq_printf(m, "%pK", class->key);
70205 #ifdef CONFIG_DEBUG_LOCKDEP
70206 seq_printf(m, " OPS:%8ld", class->ops);
70207 #endif
70208 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
70209
70210 list_for_each_entry(entry, &class->locks_after, entry) {
70211 if (entry->distance == 1) {
70212 - seq_printf(m, " -> [%p] ", entry->class->key);
70213 + seq_printf(m, " -> [%pK] ", entry->class->key);
70214 print_name(m, entry->class);
70215 seq_puts(m, "\n");
70216 }
70217 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
70218 if (!class->key)
70219 continue;
70220
70221 - seq_printf(m, "[%p] ", class->key);
70222 + seq_printf(m, "[%pK] ", class->key);
70223 print_name(m, class);
70224 seq_puts(m, "\n");
70225 }
70226 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70227 if (!i)
70228 seq_line(m, '-', 40-namelen, namelen);
70229
70230 - snprintf(ip, sizeof(ip), "[<%p>]",
70231 + snprintf(ip, sizeof(ip), "[<%pK>]",
70232 (void *)class->contention_point[i]);
70233 seq_printf(m, "%40s %14lu %29s %pS\n",
70234 name, stats->contention_point[i],
70235 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
70236 if (!i)
70237 seq_line(m, '-', 40-namelen, namelen);
70238
70239 - snprintf(ip, sizeof(ip), "[<%p>]",
70240 + snprintf(ip, sizeof(ip), "[<%pK>]",
70241 (void *)class->contending_point[i]);
70242 seq_printf(m, "%40s %14lu %29s %pS\n",
70243 name, stats->contending_point[i],
70244 diff --git a/kernel/module.c b/kernel/module.c
70245 index 3e544f4..34c3008 100644
70246 --- a/kernel/module.c
70247 +++ b/kernel/module.c
70248 @@ -59,6 +59,7 @@
70249 #include <linux/pfn.h>
70250 #include <linux/bsearch.h>
70251 #include <linux/fips.h>
70252 +#include <linux/grsecurity.h>
70253 #include "module-internal.h"
70254
70255 #define CREATE_TRACE_POINTS
70256 @@ -153,7 +154,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
70257
70258 /* Bounds of module allocation, for speeding __module_address.
70259 * Protected by module_mutex. */
70260 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
70261 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
70262 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
70263
70264 int register_module_notifier(struct notifier_block * nb)
70265 {
70266 @@ -319,7 +321,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70267 return true;
70268
70269 list_for_each_entry_rcu(mod, &modules, list) {
70270 - struct symsearch arr[] = {
70271 + struct symsearch modarr[] = {
70272 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
70273 NOT_GPL_ONLY, false },
70274 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
70275 @@ -344,7 +346,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
70276 if (mod->state == MODULE_STATE_UNFORMED)
70277 continue;
70278
70279 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
70280 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
70281 return true;
70282 }
70283 return false;
70284 @@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
70285 static int percpu_modalloc(struct module *mod,
70286 unsigned long size, unsigned long align)
70287 {
70288 - if (align > PAGE_SIZE) {
70289 + if (align-1 >= PAGE_SIZE) {
70290 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
70291 mod->name, align, PAGE_SIZE);
70292 align = PAGE_SIZE;
70293 @@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
70294 static ssize_t show_coresize(struct module_attribute *mattr,
70295 struct module_kobject *mk, char *buffer)
70296 {
70297 - return sprintf(buffer, "%u\n", mk->mod->core_size);
70298 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
70299 }
70300
70301 static struct module_attribute modinfo_coresize =
70302 @@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
70303 static ssize_t show_initsize(struct module_attribute *mattr,
70304 struct module_kobject *mk, char *buffer)
70305 {
70306 - return sprintf(buffer, "%u\n", mk->mod->init_size);
70307 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
70308 }
70309
70310 static struct module_attribute modinfo_initsize =
70311 @@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
70312 */
70313 #ifdef CONFIG_SYSFS
70314
70315 -#ifdef CONFIG_KALLSYMS
70316 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70317 static inline bool sect_empty(const Elf_Shdr *sect)
70318 {
70319 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
70320 @@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
70321
70322 static void unset_module_core_ro_nx(struct module *mod)
70323 {
70324 - set_page_attributes(mod->module_core + mod->core_text_size,
70325 - mod->module_core + mod->core_size,
70326 + set_page_attributes(mod->module_core_rw,
70327 + mod->module_core_rw + mod->core_size_rw,
70328 set_memory_x);
70329 - set_page_attributes(mod->module_core,
70330 - mod->module_core + mod->core_ro_size,
70331 + set_page_attributes(mod->module_core_rx,
70332 + mod->module_core_rx + mod->core_size_rx,
70333 set_memory_rw);
70334 }
70335
70336 static void unset_module_init_ro_nx(struct module *mod)
70337 {
70338 - set_page_attributes(mod->module_init + mod->init_text_size,
70339 - mod->module_init + mod->init_size,
70340 + set_page_attributes(mod->module_init_rw,
70341 + mod->module_init_rw + mod->init_size_rw,
70342 set_memory_x);
70343 - set_page_attributes(mod->module_init,
70344 - mod->module_init + mod->init_ro_size,
70345 + set_page_attributes(mod->module_init_rx,
70346 + mod->module_init_rx + mod->init_size_rx,
70347 set_memory_rw);
70348 }
70349
70350 @@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
70351 list_for_each_entry_rcu(mod, &modules, list) {
70352 if (mod->state == MODULE_STATE_UNFORMED)
70353 continue;
70354 - if ((mod->module_core) && (mod->core_text_size)) {
70355 - set_page_attributes(mod->module_core,
70356 - mod->module_core + mod->core_text_size,
70357 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
70358 + set_page_attributes(mod->module_core_rx,
70359 + mod->module_core_rx + mod->core_size_rx,
70360 set_memory_rw);
70361 }
70362 - if ((mod->module_init) && (mod->init_text_size)) {
70363 - set_page_attributes(mod->module_init,
70364 - mod->module_init + mod->init_text_size,
70365 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
70366 + set_page_attributes(mod->module_init_rx,
70367 + mod->module_init_rx + mod->init_size_rx,
70368 set_memory_rw);
70369 }
70370 }
70371 @@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
70372 list_for_each_entry_rcu(mod, &modules, list) {
70373 if (mod->state == MODULE_STATE_UNFORMED)
70374 continue;
70375 - if ((mod->module_core) && (mod->core_text_size)) {
70376 - set_page_attributes(mod->module_core,
70377 - mod->module_core + mod->core_text_size,
70378 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
70379 + set_page_attributes(mod->module_core_rx,
70380 + mod->module_core_rx + mod->core_size_rx,
70381 set_memory_ro);
70382 }
70383 - if ((mod->module_init) && (mod->init_text_size)) {
70384 - set_page_attributes(mod->module_init,
70385 - mod->module_init + mod->init_text_size,
70386 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
70387 + set_page_attributes(mod->module_init_rx,
70388 + mod->module_init_rx + mod->init_size_rx,
70389 set_memory_ro);
70390 }
70391 }
70392 @@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
70393
70394 /* This may be NULL, but that's OK */
70395 unset_module_init_ro_nx(mod);
70396 - module_free(mod, mod->module_init);
70397 + module_free(mod, mod->module_init_rw);
70398 + module_free_exec(mod, mod->module_init_rx);
70399 kfree(mod->args);
70400 percpu_modfree(mod);
70401
70402 /* Free lock-classes: */
70403 - lockdep_free_key_range(mod->module_core, mod->core_size);
70404 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
70405 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
70406
70407 /* Finally, free the core (containing the module structure) */
70408 unset_module_core_ro_nx(mod);
70409 - module_free(mod, mod->module_core);
70410 + module_free_exec(mod, mod->module_core_rx);
70411 + module_free(mod, mod->module_core_rw);
70412
70413 #ifdef CONFIG_MPU
70414 update_protections(current->mm);
70415 @@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70416 int ret = 0;
70417 const struct kernel_symbol *ksym;
70418
70419 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70420 + int is_fs_load = 0;
70421 + int register_filesystem_found = 0;
70422 + char *p;
70423 +
70424 + p = strstr(mod->args, "grsec_modharden_fs");
70425 + if (p) {
70426 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
70427 + /* copy \0 as well */
70428 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
70429 + is_fs_load = 1;
70430 + }
70431 +#endif
70432 +
70433 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
70434 const char *name = info->strtab + sym[i].st_name;
70435
70436 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70437 + /* it's a real shame this will never get ripped and copied
70438 + upstream! ;(
70439 + */
70440 + if (is_fs_load && !strcmp(name, "register_filesystem"))
70441 + register_filesystem_found = 1;
70442 +#endif
70443 +
70444 switch (sym[i].st_shndx) {
70445 case SHN_COMMON:
70446 /* We compiled with -fno-common. These are not
70447 @@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70448 ksym = resolve_symbol_wait(mod, info, name);
70449 /* Ok if resolved. */
70450 if (ksym && !IS_ERR(ksym)) {
70451 + pax_open_kernel();
70452 sym[i].st_value = ksym->value;
70453 + pax_close_kernel();
70454 break;
70455 }
70456
70457 @@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70458 secbase = (unsigned long)mod_percpu(mod);
70459 else
70460 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
70461 + pax_open_kernel();
70462 sym[i].st_value += secbase;
70463 + pax_close_kernel();
70464 break;
70465 }
70466 }
70467
70468 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70469 + if (is_fs_load && !register_filesystem_found) {
70470 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
70471 + ret = -EPERM;
70472 + }
70473 +#endif
70474 +
70475 return ret;
70476 }
70477
70478 @@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
70479 || s->sh_entsize != ~0UL
70480 || strstarts(sname, ".init"))
70481 continue;
70482 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
70483 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70484 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
70485 + else
70486 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
70487 pr_debug("\t%s\n", sname);
70488 }
70489 - switch (m) {
70490 - case 0: /* executable */
70491 - mod->core_size = debug_align(mod->core_size);
70492 - mod->core_text_size = mod->core_size;
70493 - break;
70494 - case 1: /* RO: text and ro-data */
70495 - mod->core_size = debug_align(mod->core_size);
70496 - mod->core_ro_size = mod->core_size;
70497 - break;
70498 - case 3: /* whole core */
70499 - mod->core_size = debug_align(mod->core_size);
70500 - break;
70501 - }
70502 }
70503
70504 pr_debug("Init section allocation order:\n");
70505 @@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
70506 || s->sh_entsize != ~0UL
70507 || !strstarts(sname, ".init"))
70508 continue;
70509 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
70510 - | INIT_OFFSET_MASK);
70511 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70512 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
70513 + else
70514 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
70515 + s->sh_entsize |= INIT_OFFSET_MASK;
70516 pr_debug("\t%s\n", sname);
70517 }
70518 - switch (m) {
70519 - case 0: /* executable */
70520 - mod->init_size = debug_align(mod->init_size);
70521 - mod->init_text_size = mod->init_size;
70522 - break;
70523 - case 1: /* RO: text and ro-data */
70524 - mod->init_size = debug_align(mod->init_size);
70525 - mod->init_ro_size = mod->init_size;
70526 - break;
70527 - case 3: /* whole init */
70528 - mod->init_size = debug_align(mod->init_size);
70529 - break;
70530 - }
70531 }
70532 }
70533
70534 @@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70535
70536 /* Put symbol section at end of init part of module. */
70537 symsect->sh_flags |= SHF_ALLOC;
70538 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
70539 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
70540 info->index.sym) | INIT_OFFSET_MASK;
70541 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
70542
70543 @@ -2326,13 +2344,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70544 }
70545
70546 /* Append room for core symbols at end of core part. */
70547 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
70548 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
70549 - mod->core_size += strtab_size;
70550 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
70551 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
70552 + mod->core_size_rx += strtab_size;
70553
70554 /* Put string table section at end of init part of module. */
70555 strsect->sh_flags |= SHF_ALLOC;
70556 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
70557 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
70558 info->index.str) | INIT_OFFSET_MASK;
70559 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
70560 }
70561 @@ -2350,12 +2368,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70562 /* Make sure we get permanent strtab: don't use info->strtab. */
70563 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
70564
70565 + pax_open_kernel();
70566 +
70567 /* Set types up while we still have access to sections. */
70568 for (i = 0; i < mod->num_symtab; i++)
70569 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
70570
70571 - mod->core_symtab = dst = mod->module_core + info->symoffs;
70572 - mod->core_strtab = s = mod->module_core + info->stroffs;
70573 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
70574 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
70575 src = mod->symtab;
70576 *s++ = 0;
70577 for (ndst = i = 0; i < mod->num_symtab; i++) {
70578 @@ -2368,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70579 }
70580 }
70581 mod->core_num_syms = ndst;
70582 +
70583 + pax_close_kernel();
70584 }
70585 #else
70586 static inline void layout_symtab(struct module *mod, struct load_info *info)
70587 @@ -2401,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
70588 return size == 0 ? NULL : vmalloc_exec(size);
70589 }
70590
70591 -static void *module_alloc_update_bounds(unsigned long size)
70592 +static void *module_alloc_update_bounds_rw(unsigned long size)
70593 {
70594 void *ret = module_alloc(size);
70595
70596 if (ret) {
70597 mutex_lock(&module_mutex);
70598 /* Update module bounds. */
70599 - if ((unsigned long)ret < module_addr_min)
70600 - module_addr_min = (unsigned long)ret;
70601 - if ((unsigned long)ret + size > module_addr_max)
70602 - module_addr_max = (unsigned long)ret + size;
70603 + if ((unsigned long)ret < module_addr_min_rw)
70604 + module_addr_min_rw = (unsigned long)ret;
70605 + if ((unsigned long)ret + size > module_addr_max_rw)
70606 + module_addr_max_rw = (unsigned long)ret + size;
70607 + mutex_unlock(&module_mutex);
70608 + }
70609 + return ret;
70610 +}
70611 +
70612 +static void *module_alloc_update_bounds_rx(unsigned long size)
70613 +{
70614 + void *ret = module_alloc_exec(size);
70615 +
70616 + if (ret) {
70617 + mutex_lock(&module_mutex);
70618 + /* Update module bounds. */
70619 + if ((unsigned long)ret < module_addr_min_rx)
70620 + module_addr_min_rx = (unsigned long)ret;
70621 + if ((unsigned long)ret + size > module_addr_max_rx)
70622 + module_addr_max_rx = (unsigned long)ret + size;
70623 mutex_unlock(&module_mutex);
70624 }
70625 return ret;
70626 @@ -2630,8 +2668,14 @@ static struct module *setup_load_info(struct load_info *info)
70627 static int check_modinfo(struct module *mod, struct load_info *info)
70628 {
70629 const char *modmagic = get_modinfo(info, "vermagic");
70630 + const char *license = get_modinfo(info, "license");
70631 int err;
70632
70633 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
70634 + if (!license || !license_is_gpl_compatible(license))
70635 + return -ENOEXEC;
70636 +#endif
70637 +
70638 /* This is allowed: modprobe --force will invalidate it. */
70639 if (!modmagic) {
70640 err = try_to_force_load(mod, "bad vermagic");
70641 @@ -2654,7 +2698,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
70642 }
70643
70644 /* Set up license info based on the info section */
70645 - set_license(mod, get_modinfo(info, "license"));
70646 + set_license(mod, license);
70647
70648 return 0;
70649 }
70650 @@ -2748,7 +2792,7 @@ static int move_module(struct module *mod, struct load_info *info)
70651 void *ptr;
70652
70653 /* Do the allocs. */
70654 - ptr = module_alloc_update_bounds(mod->core_size);
70655 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
70656 /*
70657 * The pointer to this block is stored in the module structure
70658 * which is inside the block. Just mark it as not being a
70659 @@ -2758,10 +2802,10 @@ static int move_module(struct module *mod, struct load_info *info)
70660 if (!ptr)
70661 return -ENOMEM;
70662
70663 - memset(ptr, 0, mod->core_size);
70664 - mod->module_core = ptr;
70665 + memset(ptr, 0, mod->core_size_rw);
70666 + mod->module_core_rw = ptr;
70667
70668 - ptr = module_alloc_update_bounds(mod->init_size);
70669 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
70670 /*
70671 * The pointer to this block is stored in the module structure
70672 * which is inside the block. This block doesn't need to be
70673 @@ -2769,12 +2813,39 @@ static int move_module(struct module *mod, struct load_info *info)
70674 * after the module is initialized.
70675 */
70676 kmemleak_ignore(ptr);
70677 - if (!ptr && mod->init_size) {
70678 - module_free(mod, mod->module_core);
70679 + if (!ptr && mod->init_size_rw) {
70680 + module_free(mod, mod->module_core_rw);
70681 return -ENOMEM;
70682 }
70683 - memset(ptr, 0, mod->init_size);
70684 - mod->module_init = ptr;
70685 + memset(ptr, 0, mod->init_size_rw);
70686 + mod->module_init_rw = ptr;
70687 +
70688 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
70689 + kmemleak_not_leak(ptr);
70690 + if (!ptr) {
70691 + module_free(mod, mod->module_init_rw);
70692 + module_free(mod, mod->module_core_rw);
70693 + return -ENOMEM;
70694 + }
70695 +
70696 + pax_open_kernel();
70697 + memset(ptr, 0, mod->core_size_rx);
70698 + pax_close_kernel();
70699 + mod->module_core_rx = ptr;
70700 +
70701 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
70702 + kmemleak_ignore(ptr);
70703 + if (!ptr && mod->init_size_rx) {
70704 + module_free_exec(mod, mod->module_core_rx);
70705 + module_free(mod, mod->module_init_rw);
70706 + module_free(mod, mod->module_core_rw);
70707 + return -ENOMEM;
70708 + }
70709 +
70710 + pax_open_kernel();
70711 + memset(ptr, 0, mod->init_size_rx);
70712 + pax_close_kernel();
70713 + mod->module_init_rx = ptr;
70714
70715 /* Transfer each section which specifies SHF_ALLOC */
70716 pr_debug("final section addresses:\n");
70717 @@ -2785,16 +2856,45 @@ static int move_module(struct module *mod, struct load_info *info)
70718 if (!(shdr->sh_flags & SHF_ALLOC))
70719 continue;
70720
70721 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
70722 - dest = mod->module_init
70723 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70724 - else
70725 - dest = mod->module_core + shdr->sh_entsize;
70726 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
70727 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70728 + dest = mod->module_init_rw
70729 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70730 + else
70731 + dest = mod->module_init_rx
70732 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70733 + } else {
70734 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70735 + dest = mod->module_core_rw + shdr->sh_entsize;
70736 + else
70737 + dest = mod->module_core_rx + shdr->sh_entsize;
70738 + }
70739 +
70740 + if (shdr->sh_type != SHT_NOBITS) {
70741 +
70742 +#ifdef CONFIG_PAX_KERNEXEC
70743 +#ifdef CONFIG_X86_64
70744 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
70745 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
70746 +#endif
70747 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
70748 + pax_open_kernel();
70749 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70750 + pax_close_kernel();
70751 + } else
70752 +#endif
70753
70754 - if (shdr->sh_type != SHT_NOBITS)
70755 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70756 + }
70757 /* Update sh_addr to point to copy in image. */
70758 - shdr->sh_addr = (unsigned long)dest;
70759 +
70760 +#ifdef CONFIG_PAX_KERNEXEC
70761 + if (shdr->sh_flags & SHF_EXECINSTR)
70762 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
70763 + else
70764 +#endif
70765 +
70766 + shdr->sh_addr = (unsigned long)dest;
70767 pr_debug("\t0x%lx %s\n",
70768 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
70769 }
70770 @@ -2849,12 +2949,12 @@ static void flush_module_icache(const struct module *mod)
70771 * Do it before processing of module parameters, so the module
70772 * can provide parameter accessor functions of its own.
70773 */
70774 - if (mod->module_init)
70775 - flush_icache_range((unsigned long)mod->module_init,
70776 - (unsigned long)mod->module_init
70777 - + mod->init_size);
70778 - flush_icache_range((unsigned long)mod->module_core,
70779 - (unsigned long)mod->module_core + mod->core_size);
70780 + if (mod->module_init_rx)
70781 + flush_icache_range((unsigned long)mod->module_init_rx,
70782 + (unsigned long)mod->module_init_rx
70783 + + mod->init_size_rx);
70784 + flush_icache_range((unsigned long)mod->module_core_rx,
70785 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
70786
70787 set_fs(old_fs);
70788 }
70789 @@ -2924,8 +3024,10 @@ out:
70790 static void module_deallocate(struct module *mod, struct load_info *info)
70791 {
70792 percpu_modfree(mod);
70793 - module_free(mod, mod->module_init);
70794 - module_free(mod, mod->module_core);
70795 + module_free_exec(mod, mod->module_init_rx);
70796 + module_free_exec(mod, mod->module_core_rx);
70797 + module_free(mod, mod->module_init_rw);
70798 + module_free(mod, mod->module_core_rw);
70799 }
70800
70801 int __weak module_finalize(const Elf_Ehdr *hdr,
70802 @@ -2938,7 +3040,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
70803 static int post_relocation(struct module *mod, const struct load_info *info)
70804 {
70805 /* Sort exception table now relocations are done. */
70806 + pax_open_kernel();
70807 sort_extable(mod->extable, mod->extable + mod->num_exentries);
70808 + pax_close_kernel();
70809
70810 /* Copy relocated percpu area over. */
70811 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
70812 @@ -3036,9 +3140,38 @@ again:
70813 if (err)
70814 goto free_unload;
70815
70816 + /* Now copy in args */
70817 + mod->args = strndup_user(uargs, ~0UL >> 1);
70818 + if (IS_ERR(mod->args)) {
70819 + err = PTR_ERR(mod->args);
70820 + goto free_unload;
70821 + }
70822 +
70823 /* Set up MODINFO_ATTR fields */
70824 setup_modinfo(mod, &info);
70825
70826 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70827 + {
70828 + char *p, *p2;
70829 +
70830 + if (strstr(mod->args, "grsec_modharden_netdev")) {
70831 + 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);
70832 + err = -EPERM;
70833 + goto free_modinfo;
70834 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
70835 + p += sizeof("grsec_modharden_normal") - 1;
70836 + p2 = strstr(p, "_");
70837 + if (p2) {
70838 + *p2 = '\0';
70839 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
70840 + *p2 = '_';
70841 + }
70842 + err = -EPERM;
70843 + goto free_modinfo;
70844 + }
70845 + }
70846 +#endif
70847 +
70848 /* Fix up syms, so that st_value is a pointer to location. */
70849 err = simplify_symbols(mod, &info);
70850 if (err < 0)
70851 @@ -3104,11 +3237,11 @@ again:
70852 mutex_unlock(&module_mutex);
70853 dynamic_debug_remove(info.debug);
70854 synchronize_sched();
70855 - kfree(mod->args);
70856 free_arch_cleanup:
70857 module_arch_cleanup(mod);
70858 free_modinfo:
70859 free_modinfo(mod);
70860 + kfree(mod->args);
70861 free_unload:
70862 module_unload_free(mod);
70863 unlink_mod:
70864 @@ -3155,16 +3288,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70865 MODULE_STATE_COMING, mod);
70866
70867 /* Set RO and NX regions for core */
70868 - set_section_ro_nx(mod->module_core,
70869 - mod->core_text_size,
70870 - mod->core_ro_size,
70871 - mod->core_size);
70872 + set_section_ro_nx(mod->module_core_rx,
70873 + mod->core_size_rx,
70874 + mod->core_size_rx,
70875 + mod->core_size_rx);
70876
70877 /* Set RO and NX regions for init */
70878 - set_section_ro_nx(mod->module_init,
70879 - mod->init_text_size,
70880 - mod->init_ro_size,
70881 - mod->init_size);
70882 + set_section_ro_nx(mod->module_init_rx,
70883 + mod->init_size_rx,
70884 + mod->init_size_rx,
70885 + mod->init_size_rx);
70886
70887 do_mod_ctors(mod);
70888 /* Start the module */
70889 @@ -3209,11 +3342,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70890 mod->strtab = mod->core_strtab;
70891 #endif
70892 unset_module_init_ro_nx(mod);
70893 - module_free(mod, mod->module_init);
70894 - mod->module_init = NULL;
70895 - mod->init_size = 0;
70896 - mod->init_ro_size = 0;
70897 - mod->init_text_size = 0;
70898 + module_free(mod, mod->module_init_rw);
70899 + module_free_exec(mod, mod->module_init_rx);
70900 + mod->module_init_rw = NULL;
70901 + mod->module_init_rx = NULL;
70902 + mod->init_size_rw = 0;
70903 + mod->init_size_rx = 0;
70904 mutex_unlock(&module_mutex);
70905 wake_up_all(&module_wq);
70906
70907 @@ -3245,10 +3379,16 @@ static const char *get_ksymbol(struct module *mod,
70908 unsigned long nextval;
70909
70910 /* At worse, next value is at end of module */
70911 - if (within_module_init(addr, mod))
70912 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
70913 + if (within_module_init_rx(addr, mod))
70914 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
70915 + else if (within_module_init_rw(addr, mod))
70916 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
70917 + else if (within_module_core_rx(addr, mod))
70918 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
70919 + else if (within_module_core_rw(addr, mod))
70920 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
70921 else
70922 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
70923 + return NULL;
70924
70925 /* Scan for closest preceding symbol, and next symbol. (ELF
70926 starts real symbols at 1). */
70927 @@ -3501,7 +3641,7 @@ static int m_show(struct seq_file *m, void *p)
70928 return 0;
70929
70930 seq_printf(m, "%s %u",
70931 - mod->name, mod->init_size + mod->core_size);
70932 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
70933 print_unload_info(m, mod);
70934
70935 /* Informative for users. */
70936 @@ -3510,7 +3650,7 @@ static int m_show(struct seq_file *m, void *p)
70937 mod->state == MODULE_STATE_COMING ? "Loading":
70938 "Live");
70939 /* Used by oprofile and other similar tools. */
70940 - seq_printf(m, " 0x%pK", mod->module_core);
70941 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
70942
70943 /* Taints info */
70944 if (mod->taints)
70945 @@ -3546,7 +3686,17 @@ static const struct file_operations proc_modules_operations = {
70946
70947 static int __init proc_modules_init(void)
70948 {
70949 +#ifndef CONFIG_GRKERNSEC_HIDESYM
70950 +#ifdef CONFIG_GRKERNSEC_PROC_USER
70951 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70952 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70953 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
70954 +#else
70955 proc_create("modules", 0, NULL, &proc_modules_operations);
70956 +#endif
70957 +#else
70958 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70959 +#endif
70960 return 0;
70961 }
70962 module_init(proc_modules_init);
70963 @@ -3607,14 +3757,14 @@ struct module *__module_address(unsigned long addr)
70964 {
70965 struct module *mod;
70966
70967 - if (addr < module_addr_min || addr > module_addr_max)
70968 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
70969 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
70970 return NULL;
70971
70972 list_for_each_entry_rcu(mod, &modules, list) {
70973 if (mod->state == MODULE_STATE_UNFORMED)
70974 continue;
70975 - if (within_module_core(addr, mod)
70976 - || within_module_init(addr, mod))
70977 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
70978 return mod;
70979 }
70980 return NULL;
70981 @@ -3649,11 +3799,20 @@ bool is_module_text_address(unsigned long addr)
70982 */
70983 struct module *__module_text_address(unsigned long addr)
70984 {
70985 - struct module *mod = __module_address(addr);
70986 + struct module *mod;
70987 +
70988 +#ifdef CONFIG_X86_32
70989 + addr = ktla_ktva(addr);
70990 +#endif
70991 +
70992 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
70993 + return NULL;
70994 +
70995 + mod = __module_address(addr);
70996 +
70997 if (mod) {
70998 /* Make sure it's within the text section. */
70999 - if (!within(addr, mod->module_init, mod->init_text_size)
71000 - && !within(addr, mod->module_core, mod->core_text_size))
71001 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
71002 mod = NULL;
71003 }
71004 return mod;
71005 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
71006 index 7e3443f..b2a1e6b 100644
71007 --- a/kernel/mutex-debug.c
71008 +++ b/kernel/mutex-debug.c
71009 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
71010 }
71011
71012 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71013 - struct thread_info *ti)
71014 + struct task_struct *task)
71015 {
71016 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
71017
71018 /* Mark the current thread as blocked on the lock: */
71019 - ti->task->blocked_on = waiter;
71020 + task->blocked_on = waiter;
71021 }
71022
71023 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71024 - struct thread_info *ti)
71025 + struct task_struct *task)
71026 {
71027 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
71028 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
71029 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
71030 - ti->task->blocked_on = NULL;
71031 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
71032 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
71033 + task->blocked_on = NULL;
71034
71035 list_del_init(&waiter->list);
71036 waiter->task = NULL;
71037 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
71038 index 0799fd3..d06ae3b 100644
71039 --- a/kernel/mutex-debug.h
71040 +++ b/kernel/mutex-debug.h
71041 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
71042 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
71043 extern void debug_mutex_add_waiter(struct mutex *lock,
71044 struct mutex_waiter *waiter,
71045 - struct thread_info *ti);
71046 + struct task_struct *task);
71047 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71048 - struct thread_info *ti);
71049 + struct task_struct *task);
71050 extern void debug_mutex_unlock(struct mutex *lock);
71051 extern void debug_mutex_init(struct mutex *lock, const char *name,
71052 struct lock_class_key *key);
71053 diff --git a/kernel/mutex.c b/kernel/mutex.c
71054 index a307cc9..27fd2e9 100644
71055 --- a/kernel/mutex.c
71056 +++ b/kernel/mutex.c
71057 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71058 spin_lock_mutex(&lock->wait_lock, flags);
71059
71060 debug_mutex_lock_common(lock, &waiter);
71061 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
71062 + debug_mutex_add_waiter(lock, &waiter, task);
71063
71064 /* add waiting tasks to the end of the waitqueue (FIFO): */
71065 list_add_tail(&waiter.list, &lock->wait_list);
71066 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71067 * TASK_UNINTERRUPTIBLE case.)
71068 */
71069 if (unlikely(signal_pending_state(state, task))) {
71070 - mutex_remove_waiter(lock, &waiter,
71071 - task_thread_info(task));
71072 + mutex_remove_waiter(lock, &waiter, task);
71073 mutex_release(&lock->dep_map, 1, ip);
71074 spin_unlock_mutex(&lock->wait_lock, flags);
71075
71076 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71077 done:
71078 lock_acquired(&lock->dep_map, ip);
71079 /* got the lock - rejoice! */
71080 - mutex_remove_waiter(lock, &waiter, current_thread_info());
71081 + mutex_remove_waiter(lock, &waiter, task);
71082 mutex_set_owner(lock);
71083
71084 /* set it to 0 if there are no waiters left: */
71085 diff --git a/kernel/notifier.c b/kernel/notifier.c
71086 index 2d5cc4c..d9ea600 100644
71087 --- a/kernel/notifier.c
71088 +++ b/kernel/notifier.c
71089 @@ -5,6 +5,7 @@
71090 #include <linux/rcupdate.h>
71091 #include <linux/vmalloc.h>
71092 #include <linux/reboot.h>
71093 +#include <linux/mm.h>
71094
71095 /*
71096 * Notifier list for kernel code which wants to be called
71097 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
71098 while ((*nl) != NULL) {
71099 if (n->priority > (*nl)->priority)
71100 break;
71101 - nl = &((*nl)->next);
71102 + nl = (struct notifier_block **)&((*nl)->next);
71103 }
71104 - n->next = *nl;
71105 + pax_open_kernel();
71106 + *(const void **)&n->next = *nl;
71107 rcu_assign_pointer(*nl, n);
71108 + pax_close_kernel();
71109 return 0;
71110 }
71111
71112 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
71113 return 0;
71114 if (n->priority > (*nl)->priority)
71115 break;
71116 - nl = &((*nl)->next);
71117 + nl = (struct notifier_block **)&((*nl)->next);
71118 }
71119 - n->next = *nl;
71120 + pax_open_kernel();
71121 + *(const void **)&n->next = *nl;
71122 rcu_assign_pointer(*nl, n);
71123 + pax_close_kernel();
71124 return 0;
71125 }
71126
71127 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
71128 {
71129 while ((*nl) != NULL) {
71130 if ((*nl) == n) {
71131 + pax_open_kernel();
71132 rcu_assign_pointer(*nl, n->next);
71133 + pax_close_kernel();
71134 return 0;
71135 }
71136 - nl = &((*nl)->next);
71137 + nl = (struct notifier_block **)&((*nl)->next);
71138 }
71139 return -ENOENT;
71140 }
71141 diff --git a/kernel/panic.c b/kernel/panic.c
71142 index e1b2822..5edc1d9 100644
71143 --- a/kernel/panic.c
71144 +++ b/kernel/panic.c
71145 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
71146 const char *board;
71147
71148 printk(KERN_WARNING "------------[ cut here ]------------\n");
71149 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
71150 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
71151 board = dmi_get_system_info(DMI_PRODUCT_NAME);
71152 if (board)
71153 printk(KERN_WARNING "Hardware name: %s\n", board);
71154 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
71155 */
71156 void __stack_chk_fail(void)
71157 {
71158 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
71159 + dump_stack();
71160 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
71161 __builtin_return_address(0));
71162 }
71163 EXPORT_SYMBOL(__stack_chk_fail);
71164 diff --git a/kernel/pid.c b/kernel/pid.c
71165 index aebd4f5..1693c13 100644
71166 --- a/kernel/pid.c
71167 +++ b/kernel/pid.c
71168 @@ -33,6 +33,7 @@
71169 #include <linux/rculist.h>
71170 #include <linux/bootmem.h>
71171 #include <linux/hash.h>
71172 +#include <linux/security.h>
71173 #include <linux/pid_namespace.h>
71174 #include <linux/init_task.h>
71175 #include <linux/syscalls.h>
71176 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
71177
71178 int pid_max = PID_MAX_DEFAULT;
71179
71180 -#define RESERVED_PIDS 300
71181 +#define RESERVED_PIDS 500
71182
71183 int pid_max_min = RESERVED_PIDS + 1;
71184 int pid_max_max = PID_MAX_LIMIT;
71185 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
71186 */
71187 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
71188 {
71189 + struct task_struct *task;
71190 +
71191 rcu_lockdep_assert(rcu_read_lock_held(),
71192 "find_task_by_pid_ns() needs rcu_read_lock()"
71193 " protection");
71194 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71195 +
71196 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
71197 +
71198 + if (gr_pid_is_chrooted(task))
71199 + return NULL;
71200 +
71201 + return task;
71202 }
71203
71204 struct task_struct *find_task_by_vpid(pid_t vnr)
71205 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
71206 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
71207 }
71208
71209 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
71210 +{
71211 + rcu_lockdep_assert(rcu_read_lock_held(),
71212 + "find_task_by_pid_ns() needs rcu_read_lock()"
71213 + " protection");
71214 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
71215 +}
71216 +
71217 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
71218 {
71219 struct pid *pid;
71220 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
71221 index 125cb67..2e5c8ad 100644
71222 --- a/kernel/posix-cpu-timers.c
71223 +++ b/kernel/posix-cpu-timers.c
71224 @@ -6,9 +6,11 @@
71225 #include <linux/posix-timers.h>
71226 #include <linux/errno.h>
71227 #include <linux/math64.h>
71228 +#include <linux/security.h>
71229 #include <asm/uaccess.h>
71230 #include <linux/kernel_stat.h>
71231 #include <trace/events/timer.h>
71232 +#include <linux/random.h>
71233
71234 /*
71235 * Called after updating RLIMIT_CPU to run cpu timer and update
71236 @@ -494,6 +496,8 @@ static void cleanup_timers(struct list_head *head,
71237 */
71238 void posix_cpu_timers_exit(struct task_struct *tsk)
71239 {
71240 + add_device_randomness((const void*) &tsk->se.sum_exec_runtime,
71241 + sizeof(unsigned long long));
71242 cleanup_timers(tsk->cpu_timers,
71243 tsk->utime, tsk->stime, tsk->se.sum_exec_runtime);
71244
71245 @@ -1578,14 +1582,14 @@ struct k_clock clock_posix_cpu = {
71246
71247 static __init int init_posix_cpu_timers(void)
71248 {
71249 - struct k_clock process = {
71250 + static struct k_clock process = {
71251 .clock_getres = process_cpu_clock_getres,
71252 .clock_get = process_cpu_clock_get,
71253 .timer_create = process_cpu_timer_create,
71254 .nsleep = process_cpu_nsleep,
71255 .nsleep_restart = process_cpu_nsleep_restart,
71256 };
71257 - struct k_clock thread = {
71258 + static struct k_clock thread = {
71259 .clock_getres = thread_cpu_clock_getres,
71260 .clock_get = thread_cpu_clock_get,
71261 .timer_create = thread_cpu_timer_create,
71262 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
71263 index 69185ae..cc2847a 100644
71264 --- a/kernel/posix-timers.c
71265 +++ b/kernel/posix-timers.c
71266 @@ -43,6 +43,7 @@
71267 #include <linux/idr.h>
71268 #include <linux/posix-clock.h>
71269 #include <linux/posix-timers.h>
71270 +#include <linux/grsecurity.h>
71271 #include <linux/syscalls.h>
71272 #include <linux/wait.h>
71273 #include <linux/workqueue.h>
71274 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
71275 * which we beg off on and pass to do_sys_settimeofday().
71276 */
71277
71278 -static struct k_clock posix_clocks[MAX_CLOCKS];
71279 +static struct k_clock *posix_clocks[MAX_CLOCKS];
71280
71281 /*
71282 * These ones are defined below.
71283 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
71284 */
71285 static __init int init_posix_timers(void)
71286 {
71287 - struct k_clock clock_realtime = {
71288 + static struct k_clock clock_realtime = {
71289 .clock_getres = hrtimer_get_res,
71290 .clock_get = posix_clock_realtime_get,
71291 .clock_set = posix_clock_realtime_set,
71292 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
71293 .timer_get = common_timer_get,
71294 .timer_del = common_timer_del,
71295 };
71296 - struct k_clock clock_monotonic = {
71297 + static struct k_clock clock_monotonic = {
71298 .clock_getres = hrtimer_get_res,
71299 .clock_get = posix_ktime_get_ts,
71300 .nsleep = common_nsleep,
71301 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
71302 .timer_get = common_timer_get,
71303 .timer_del = common_timer_del,
71304 };
71305 - struct k_clock clock_monotonic_raw = {
71306 + static struct k_clock clock_monotonic_raw = {
71307 .clock_getres = hrtimer_get_res,
71308 .clock_get = posix_get_monotonic_raw,
71309 };
71310 - struct k_clock clock_realtime_coarse = {
71311 + static struct k_clock clock_realtime_coarse = {
71312 .clock_getres = posix_get_coarse_res,
71313 .clock_get = posix_get_realtime_coarse,
71314 };
71315 - struct k_clock clock_monotonic_coarse = {
71316 + static struct k_clock clock_monotonic_coarse = {
71317 .clock_getres = posix_get_coarse_res,
71318 .clock_get = posix_get_monotonic_coarse,
71319 };
71320 - struct k_clock clock_boottime = {
71321 + static struct k_clock clock_boottime = {
71322 .clock_getres = hrtimer_get_res,
71323 .clock_get = posix_get_boottime,
71324 .nsleep = common_nsleep,
71325 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
71326 return;
71327 }
71328
71329 - posix_clocks[clock_id] = *new_clock;
71330 + posix_clocks[clock_id] = new_clock;
71331 }
71332 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
71333
71334 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
71335 return (id & CLOCKFD_MASK) == CLOCKFD ?
71336 &clock_posix_dynamic : &clock_posix_cpu;
71337
71338 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
71339 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
71340 return NULL;
71341 - return &posix_clocks[id];
71342 + return posix_clocks[id];
71343 }
71344
71345 static int common_timer_create(struct k_itimer *new_timer)
71346 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
71347 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
71348 return -EFAULT;
71349
71350 + /* only the CLOCK_REALTIME clock can be set, all other clocks
71351 + have their clock_set fptr set to a nosettime dummy function
71352 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
71353 + call common_clock_set, which calls do_sys_settimeofday, which
71354 + we hook
71355 + */
71356 +
71357 return kc->clock_set(which_clock, &new_tp);
71358 }
71359
71360 diff --git a/kernel/power/process.c b/kernel/power/process.c
71361 index 87da817..30ddd13 100644
71362 --- a/kernel/power/process.c
71363 +++ b/kernel/power/process.c
71364 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
71365 u64 elapsed_csecs64;
71366 unsigned int elapsed_csecs;
71367 bool wakeup = false;
71368 + bool timedout = false;
71369
71370 do_gettimeofday(&start);
71371
71372 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
71373
71374 while (true) {
71375 todo = 0;
71376 + if (time_after(jiffies, end_time))
71377 + timedout = true;
71378 read_lock(&tasklist_lock);
71379 do_each_thread(g, p) {
71380 if (p == current || !freeze_task(p))
71381 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
71382 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
71383 * transition can't race with task state testing here.
71384 */
71385 - if (!task_is_stopped_or_traced(p) &&
71386 - !freezer_should_skip(p))
71387 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
71388 todo++;
71389 + if (timedout) {
71390 + printk(KERN_ERR "Task refusing to freeze:\n");
71391 + sched_show_task(p);
71392 + }
71393 + }
71394 } while_each_thread(g, p);
71395 read_unlock(&tasklist_lock);
71396
71397 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
71398 todo += wq_busy;
71399 }
71400
71401 - if (!todo || time_after(jiffies, end_time))
71402 + if (!todo || timedout)
71403 break;
71404
71405 if (pm_wakeup_pending()) {
71406 diff --git a/kernel/printk.c b/kernel/printk.c
71407 index f8e0b5a..dda2a5c 100644
71408 --- a/kernel/printk.c
71409 +++ b/kernel/printk.c
71410 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
71411 if (from_file && type != SYSLOG_ACTION_OPEN)
71412 return 0;
71413
71414 +#ifdef CONFIG_GRKERNSEC_DMESG
71415 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
71416 + return -EPERM;
71417 +#endif
71418 +
71419 if (syslog_action_restricted(type)) {
71420 if (capable(CAP_SYSLOG))
71421 return 0;
71422 diff --git a/kernel/profile.c b/kernel/profile.c
71423 index 76b8e77..a2930e8 100644
71424 --- a/kernel/profile.c
71425 +++ b/kernel/profile.c
71426 @@ -39,7 +39,7 @@ struct profile_hit {
71427 /* Oprofile timer tick hook */
71428 static int (*timer_hook)(struct pt_regs *) __read_mostly;
71429
71430 -static atomic_t *prof_buffer;
71431 +static atomic_unchecked_t *prof_buffer;
71432 static unsigned long prof_len, prof_shift;
71433
71434 int prof_on __read_mostly;
71435 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
71436 hits[i].pc = 0;
71437 continue;
71438 }
71439 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71440 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71441 hits[i].hits = hits[i].pc = 0;
71442 }
71443 }
71444 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71445 * Add the current hit(s) and flush the write-queue out
71446 * to the global buffer:
71447 */
71448 - atomic_add(nr_hits, &prof_buffer[pc]);
71449 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
71450 for (i = 0; i < NR_PROFILE_HIT; ++i) {
71451 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71452 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71453 hits[i].pc = hits[i].hits = 0;
71454 }
71455 out:
71456 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71457 {
71458 unsigned long pc;
71459 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
71460 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71461 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71462 }
71463 #endif /* !CONFIG_SMP */
71464
71465 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
71466 return -EFAULT;
71467 buf++; p++; count--; read++;
71468 }
71469 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
71470 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
71471 if (copy_to_user(buf, (void *)pnt, count))
71472 return -EFAULT;
71473 read += count;
71474 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
71475 }
71476 #endif
71477 profile_discard_flip_buffers();
71478 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
71479 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
71480 return count;
71481 }
71482
71483 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
71484 index fbea91d..9bf15e8 100644
71485 --- a/kernel/ptrace.c
71486 +++ b/kernel/ptrace.c
71487 @@ -319,7 +319,7 @@ static int ptrace_attach(struct task_struct *task, long request,
71488
71489 if (seize)
71490 flags |= PT_SEIZED;
71491 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
71492 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
71493 flags |= PT_PTRACE_CAP;
71494 task->ptrace = flags;
71495
71496 @@ -526,7 +526,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
71497 break;
71498 return -EIO;
71499 }
71500 - if (copy_to_user(dst, buf, retval))
71501 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
71502 return -EFAULT;
71503 copied += retval;
71504 src += retval;
71505 @@ -711,7 +711,7 @@ int ptrace_request(struct task_struct *child, long request,
71506 bool seized = child->ptrace & PT_SEIZED;
71507 int ret = -EIO;
71508 siginfo_t siginfo, *si;
71509 - void __user *datavp = (void __user *) data;
71510 + void __user *datavp = (__force void __user *) data;
71511 unsigned long __user *datalp = datavp;
71512 unsigned long flags;
71513
71514 @@ -913,14 +913,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
71515 goto out;
71516 }
71517
71518 + if (gr_handle_ptrace(child, request)) {
71519 + ret = -EPERM;
71520 + goto out_put_task_struct;
71521 + }
71522 +
71523 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71524 ret = ptrace_attach(child, request, addr, data);
71525 /*
71526 * Some architectures need to do book-keeping after
71527 * a ptrace attach.
71528 */
71529 - if (!ret)
71530 + if (!ret) {
71531 arch_ptrace_attach(child);
71532 + gr_audit_ptrace(child);
71533 + }
71534 goto out_put_task_struct;
71535 }
71536
71537 @@ -948,7 +955,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
71538 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
71539 if (copied != sizeof(tmp))
71540 return -EIO;
71541 - return put_user(tmp, (unsigned long __user *)data);
71542 + return put_user(tmp, (__force unsigned long __user *)data);
71543 }
71544
71545 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
71546 @@ -1058,14 +1065,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
71547 goto out;
71548 }
71549
71550 + if (gr_handle_ptrace(child, request)) {
71551 + ret = -EPERM;
71552 + goto out_put_task_struct;
71553 + }
71554 +
71555 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71556 ret = ptrace_attach(child, request, addr, data);
71557 /*
71558 * Some architectures need to do book-keeping after
71559 * a ptrace attach.
71560 */
71561 - if (!ret)
71562 + if (!ret) {
71563 arch_ptrace_attach(child);
71564 + gr_audit_ptrace(child);
71565 + }
71566 goto out_put_task_struct;
71567 }
71568
71569 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
71570 index e4c6a59..c86621a 100644
71571 --- a/kernel/rcutiny.c
71572 +++ b/kernel/rcutiny.c
71573 @@ -46,7 +46,7 @@
71574 struct rcu_ctrlblk;
71575 static void invoke_rcu_callbacks(void);
71576 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
71577 -static void rcu_process_callbacks(struct softirq_action *unused);
71578 +static void rcu_process_callbacks(void);
71579 static void __call_rcu(struct rcu_head *head,
71580 void (*func)(struct rcu_head *rcu),
71581 struct rcu_ctrlblk *rcp);
71582 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
71583 rcu_is_callbacks_kthread()));
71584 }
71585
71586 -static void rcu_process_callbacks(struct softirq_action *unused)
71587 +static void rcu_process_callbacks(void)
71588 {
71589 __rcu_process_callbacks(&rcu_sched_ctrlblk);
71590 __rcu_process_callbacks(&rcu_bh_ctrlblk);
71591 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
71592 index 3d01902..afbf46e 100644
71593 --- a/kernel/rcutiny_plugin.h
71594 +++ b/kernel/rcutiny_plugin.h
71595 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
71596 have_rcu_kthread_work = morework;
71597 local_irq_restore(flags);
71598 if (work)
71599 - rcu_process_callbacks(NULL);
71600 + rcu_process_callbacks();
71601 schedule_timeout_interruptible(1); /* Leave CPU for others. */
71602 }
71603
71604 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
71605 index aaa7b9f..055ff1e 100644
71606 --- a/kernel/rcutorture.c
71607 +++ b/kernel/rcutorture.c
71608 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
71609 { 0 };
71610 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
71611 { 0 };
71612 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71613 -static atomic_t n_rcu_torture_alloc;
71614 -static atomic_t n_rcu_torture_alloc_fail;
71615 -static atomic_t n_rcu_torture_free;
71616 -static atomic_t n_rcu_torture_mberror;
71617 -static atomic_t n_rcu_torture_error;
71618 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71619 +static atomic_unchecked_t n_rcu_torture_alloc;
71620 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
71621 +static atomic_unchecked_t n_rcu_torture_free;
71622 +static atomic_unchecked_t n_rcu_torture_mberror;
71623 +static atomic_unchecked_t n_rcu_torture_error;
71624 static long n_rcu_torture_barrier_error;
71625 static long n_rcu_torture_boost_ktrerror;
71626 static long n_rcu_torture_boost_rterror;
71627 @@ -272,11 +272,11 @@ rcu_torture_alloc(void)
71628
71629 spin_lock_bh(&rcu_torture_lock);
71630 if (list_empty(&rcu_torture_freelist)) {
71631 - atomic_inc(&n_rcu_torture_alloc_fail);
71632 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
71633 spin_unlock_bh(&rcu_torture_lock);
71634 return NULL;
71635 }
71636 - atomic_inc(&n_rcu_torture_alloc);
71637 + atomic_inc_unchecked(&n_rcu_torture_alloc);
71638 p = rcu_torture_freelist.next;
71639 list_del_init(p);
71640 spin_unlock_bh(&rcu_torture_lock);
71641 @@ -289,7 +289,7 @@ rcu_torture_alloc(void)
71642 static void
71643 rcu_torture_free(struct rcu_torture *p)
71644 {
71645 - atomic_inc(&n_rcu_torture_free);
71646 + atomic_inc_unchecked(&n_rcu_torture_free);
71647 spin_lock_bh(&rcu_torture_lock);
71648 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
71649 spin_unlock_bh(&rcu_torture_lock);
71650 @@ -410,7 +410,7 @@ rcu_torture_cb(struct rcu_head *p)
71651 i = rp->rtort_pipe_count;
71652 if (i > RCU_TORTURE_PIPE_LEN)
71653 i = RCU_TORTURE_PIPE_LEN;
71654 - atomic_inc(&rcu_torture_wcount[i]);
71655 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
71656 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71657 rp->rtort_mbtest = 0;
71658 rcu_torture_free(rp);
71659 @@ -459,7 +459,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
71660 i = rp->rtort_pipe_count;
71661 if (i > RCU_TORTURE_PIPE_LEN)
71662 i = RCU_TORTURE_PIPE_LEN;
71663 - atomic_inc(&rcu_torture_wcount[i]);
71664 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
71665 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71666 rp->rtort_mbtest = 0;
71667 list_del(&rp->rtort_free);
71668 @@ -1002,7 +1002,7 @@ rcu_torture_writer(void *arg)
71669 i = old_rp->rtort_pipe_count;
71670 if (i > RCU_TORTURE_PIPE_LEN)
71671 i = RCU_TORTURE_PIPE_LEN;
71672 - atomic_inc(&rcu_torture_wcount[i]);
71673 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
71674 old_rp->rtort_pipe_count++;
71675 cur_ops->deferred_free(old_rp);
71676 }
71677 @@ -1087,7 +1087,7 @@ static void rcu_torture_timer(unsigned long unused)
71678 }
71679 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71680 if (p->rtort_mbtest == 0)
71681 - atomic_inc(&n_rcu_torture_mberror);
71682 + atomic_inc_unchecked(&n_rcu_torture_mberror);
71683 spin_lock(&rand_lock);
71684 cur_ops->read_delay(&rand);
71685 n_rcu_torture_timers++;
71686 @@ -1151,7 +1151,7 @@ rcu_torture_reader(void *arg)
71687 }
71688 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71689 if (p->rtort_mbtest == 0)
71690 - atomic_inc(&n_rcu_torture_mberror);
71691 + atomic_inc_unchecked(&n_rcu_torture_mberror);
71692 cur_ops->read_delay(&rand);
71693 preempt_disable();
71694 pipe_count = p->rtort_pipe_count;
71695 @@ -1210,11 +1210,11 @@ rcu_torture_printk(char *page)
71696 rcu_torture_current,
71697 rcu_torture_current_version,
71698 list_empty(&rcu_torture_freelist),
71699 - atomic_read(&n_rcu_torture_alloc),
71700 - atomic_read(&n_rcu_torture_alloc_fail),
71701 - atomic_read(&n_rcu_torture_free));
71702 + atomic_read_unchecked(&n_rcu_torture_alloc),
71703 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
71704 + atomic_read_unchecked(&n_rcu_torture_free));
71705 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
71706 - atomic_read(&n_rcu_torture_mberror),
71707 + atomic_read_unchecked(&n_rcu_torture_mberror),
71708 n_rcu_torture_boost_ktrerror,
71709 n_rcu_torture_boost_rterror);
71710 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
71711 @@ -1233,14 +1233,14 @@ rcu_torture_printk(char *page)
71712 n_barrier_attempts,
71713 n_rcu_torture_barrier_error);
71714 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
71715 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
71716 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
71717 n_rcu_torture_barrier_error != 0 ||
71718 n_rcu_torture_boost_ktrerror != 0 ||
71719 n_rcu_torture_boost_rterror != 0 ||
71720 n_rcu_torture_boost_failure != 0 ||
71721 i > 1) {
71722 cnt += sprintf(&page[cnt], "!!! ");
71723 - atomic_inc(&n_rcu_torture_error);
71724 + atomic_inc_unchecked(&n_rcu_torture_error);
71725 WARN_ON_ONCE(1);
71726 }
71727 cnt += sprintf(&page[cnt], "Reader Pipe: ");
71728 @@ -1254,7 +1254,7 @@ rcu_torture_printk(char *page)
71729 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
71730 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71731 cnt += sprintf(&page[cnt], " %d",
71732 - atomic_read(&rcu_torture_wcount[i]));
71733 + atomic_read_unchecked(&rcu_torture_wcount[i]));
71734 }
71735 cnt += sprintf(&page[cnt], "\n");
71736 if (cur_ops->stats)
71737 @@ -1938,7 +1938,7 @@ rcu_torture_cleanup(void)
71738
71739 if (cur_ops->cleanup)
71740 cur_ops->cleanup();
71741 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71742 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71743 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
71744 else if (n_online_successes != n_online_attempts ||
71745 n_offline_successes != n_offline_attempts)
71746 @@ -2007,18 +2007,18 @@ rcu_torture_init(void)
71747
71748 rcu_torture_current = NULL;
71749 rcu_torture_current_version = 0;
71750 - atomic_set(&n_rcu_torture_alloc, 0);
71751 - atomic_set(&n_rcu_torture_alloc_fail, 0);
71752 - atomic_set(&n_rcu_torture_free, 0);
71753 - atomic_set(&n_rcu_torture_mberror, 0);
71754 - atomic_set(&n_rcu_torture_error, 0);
71755 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
71756 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
71757 + atomic_set_unchecked(&n_rcu_torture_free, 0);
71758 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
71759 + atomic_set_unchecked(&n_rcu_torture_error, 0);
71760 n_rcu_torture_barrier_error = 0;
71761 n_rcu_torture_boost_ktrerror = 0;
71762 n_rcu_torture_boost_rterror = 0;
71763 n_rcu_torture_boost_failure = 0;
71764 n_rcu_torture_boosts = 0;
71765 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
71766 - atomic_set(&rcu_torture_wcount[i], 0);
71767 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
71768 for_each_possible_cpu(cpu) {
71769 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71770 per_cpu(rcu_torture_count, cpu)[i] = 0;
71771 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
71772 index 2682295..0f2297e 100644
71773 --- a/kernel/rcutree.c
71774 +++ b/kernel/rcutree.c
71775 @@ -348,9 +348,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
71776 rcu_prepare_for_idle(smp_processor_id());
71777 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71778 smp_mb__before_atomic_inc(); /* See above. */
71779 - atomic_inc(&rdtp->dynticks);
71780 + atomic_inc_unchecked(&rdtp->dynticks);
71781 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
71782 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71783 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71784
71785 /*
71786 * It is illegal to enter an extended quiescent state while
71787 @@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
71788 int user)
71789 {
71790 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
71791 - atomic_inc(&rdtp->dynticks);
71792 + atomic_inc_unchecked(&rdtp->dynticks);
71793 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71794 smp_mb__after_atomic_inc(); /* See above. */
71795 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71796 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71797 rcu_cleanup_after_idle(smp_processor_id());
71798 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
71799 if (!user && !is_idle_task(current)) {
71800 @@ -670,14 +670,14 @@ void rcu_nmi_enter(void)
71801 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
71802
71803 if (rdtp->dynticks_nmi_nesting == 0 &&
71804 - (atomic_read(&rdtp->dynticks) & 0x1))
71805 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
71806 return;
71807 rdtp->dynticks_nmi_nesting++;
71808 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
71809 - atomic_inc(&rdtp->dynticks);
71810 + atomic_inc_unchecked(&rdtp->dynticks);
71811 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71812 smp_mb__after_atomic_inc(); /* See above. */
71813 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71814 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71815 }
71816
71817 /**
71818 @@ -696,9 +696,9 @@ void rcu_nmi_exit(void)
71819 return;
71820 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71821 smp_mb__before_atomic_inc(); /* See above. */
71822 - atomic_inc(&rdtp->dynticks);
71823 + atomic_inc_unchecked(&rdtp->dynticks);
71824 smp_mb__after_atomic_inc(); /* Force delay to next write. */
71825 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71826 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71827 }
71828
71829 /**
71830 @@ -712,7 +712,7 @@ int rcu_is_cpu_idle(void)
71831 int ret;
71832
71833 preempt_disable();
71834 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71835 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71836 preempt_enable();
71837 return ret;
71838 }
71839 @@ -795,7 +795,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
71840 */
71841 static int dyntick_save_progress_counter(struct rcu_data *rdp)
71842 {
71843 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
71844 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71845 return (rdp->dynticks_snap & 0x1) == 0;
71846 }
71847
71848 @@ -810,7 +810,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
71849 unsigned int curr;
71850 unsigned int snap;
71851
71852 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
71853 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71854 snap = (unsigned int)rdp->dynticks_snap;
71855
71856 /*
71857 @@ -858,10 +858,10 @@ static int jiffies_till_stall_check(void)
71858 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
71859 */
71860 if (till_stall_check < 3) {
71861 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
71862 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
71863 till_stall_check = 3;
71864 } else if (till_stall_check > 300) {
71865 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
71866 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
71867 till_stall_check = 300;
71868 }
71869 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
71870 @@ -1589,7 +1589,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
71871 rsp->qlen += rdp->qlen;
71872 rdp->n_cbs_orphaned += rdp->qlen;
71873 rdp->qlen_lazy = 0;
71874 - ACCESS_ONCE(rdp->qlen) = 0;
71875 + ACCESS_ONCE_RW(rdp->qlen) = 0;
71876 }
71877
71878 /*
71879 @@ -1831,7 +1831,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
71880 }
71881 smp_mb(); /* List handling before counting for rcu_barrier(). */
71882 rdp->qlen_lazy -= count_lazy;
71883 - ACCESS_ONCE(rdp->qlen) -= count;
71884 + ACCESS_ONCE_RW(rdp->qlen) -= count;
71885 rdp->n_cbs_invoked += count;
71886
71887 /* Reinstate batch limit if we have worked down the excess. */
71888 @@ -2024,7 +2024,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
71889 /*
71890 * Do RCU core processing for the current CPU.
71891 */
71892 -static void rcu_process_callbacks(struct softirq_action *unused)
71893 +static void rcu_process_callbacks(void)
71894 {
71895 struct rcu_state *rsp;
71896
71897 @@ -2136,7 +2136,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
71898 local_irq_restore(flags);
71899 return;
71900 }
71901 - ACCESS_ONCE(rdp->qlen)++;
71902 + ACCESS_ONCE_RW(rdp->qlen)++;
71903 if (lazy)
71904 rdp->qlen_lazy++;
71905 else
71906 @@ -2250,8 +2250,8 @@ void synchronize_rcu_bh(void)
71907 }
71908 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
71909
71910 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
71911 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
71912 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
71913 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
71914
71915 static int synchronize_sched_expedited_cpu_stop(void *data)
71916 {
71917 @@ -2312,7 +2312,7 @@ void synchronize_sched_expedited(void)
71918 int firstsnap, s, snap, trycount = 0;
71919
71920 /* Note that atomic_inc_return() implies full memory barrier. */
71921 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
71922 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
71923 get_online_cpus();
71924 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
71925
71926 @@ -2334,7 +2334,7 @@ void synchronize_sched_expedited(void)
71927 }
71928
71929 /* Check to see if someone else did our work for us. */
71930 - s = atomic_read(&sync_sched_expedited_done);
71931 + s = atomic_read_unchecked(&sync_sched_expedited_done);
71932 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
71933 smp_mb(); /* ensure test happens before caller kfree */
71934 return;
71935 @@ -2349,7 +2349,7 @@ void synchronize_sched_expedited(void)
71936 * grace period works for us.
71937 */
71938 get_online_cpus();
71939 - snap = atomic_read(&sync_sched_expedited_started);
71940 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
71941 smp_mb(); /* ensure read is before try_stop_cpus(). */
71942 }
71943
71944 @@ -2360,12 +2360,12 @@ void synchronize_sched_expedited(void)
71945 * than we did beat us to the punch.
71946 */
71947 do {
71948 - s = atomic_read(&sync_sched_expedited_done);
71949 + s = atomic_read_unchecked(&sync_sched_expedited_done);
71950 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
71951 smp_mb(); /* ensure test happens before caller kfree */
71952 break;
71953 }
71954 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
71955 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
71956
71957 put_online_cpus();
71958 }
71959 @@ -2539,7 +2539,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71960 * ACCESS_ONCE() to prevent the compiler from speculating
71961 * the increment to precede the early-exit check.
71962 */
71963 - ACCESS_ONCE(rsp->n_barrier_done)++;
71964 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71965 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
71966 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
71967 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
71968 @@ -2581,7 +2581,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71969
71970 /* Increment ->n_barrier_done to prevent duplicate work. */
71971 smp_mb(); /* Keep increment after above mechanism. */
71972 - ACCESS_ONCE(rsp->n_barrier_done)++;
71973 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71974 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
71975 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
71976 smp_mb(); /* Keep increment before caller's subsequent code. */
71977 @@ -2626,10 +2626,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
71978 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
71979 init_callback_list(rdp);
71980 rdp->qlen_lazy = 0;
71981 - ACCESS_ONCE(rdp->qlen) = 0;
71982 + ACCESS_ONCE_RW(rdp->qlen) = 0;
71983 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
71984 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
71985 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
71986 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
71987 #ifdef CONFIG_RCU_USER_QS
71988 WARN_ON_ONCE(rdp->dynticks->in_user);
71989 #endif
71990 @@ -2664,8 +2664,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
71991 rdp->blimit = blimit;
71992 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
71993 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
71994 - atomic_set(&rdp->dynticks->dynticks,
71995 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
71996 + atomic_set_unchecked(&rdp->dynticks->dynticks,
71997 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
71998 rcu_prepare_for_idle_init(cpu);
71999 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
72000
72001 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
72002 index a240f03..d469618 100644
72003 --- a/kernel/rcutree.h
72004 +++ b/kernel/rcutree.h
72005 @@ -86,7 +86,7 @@ struct rcu_dynticks {
72006 long long dynticks_nesting; /* Track irq/process nesting level. */
72007 /* Process level is worth LLONG_MAX/2. */
72008 int dynticks_nmi_nesting; /* Track NMI nesting level. */
72009 - atomic_t dynticks; /* Even value for idle, else odd. */
72010 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
72011 #ifdef CONFIG_RCU_FAST_NO_HZ
72012 int dyntick_drain; /* Prepare-for-idle state variable. */
72013 unsigned long dyntick_holdoff;
72014 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
72015 index f921154..34c4873 100644
72016 --- a/kernel/rcutree_plugin.h
72017 +++ b/kernel/rcutree_plugin.h
72018 @@ -865,7 +865,7 @@ void synchronize_rcu_expedited(void)
72019
72020 /* Clean up and exit. */
72021 smp_mb(); /* ensure expedited GP seen before counter increment. */
72022 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
72023 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
72024 unlock_mb_ret:
72025 mutex_unlock(&sync_rcu_preempt_exp_mutex);
72026 mb_ret:
72027 @@ -2040,7 +2040,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
72028 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
72029 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
72030 cpu, ticks_value, ticks_title,
72031 - atomic_read(&rdtp->dynticks) & 0xfff,
72032 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
72033 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
72034 fast_no_hz);
72035 }
72036 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
72037 index 693513b..b9f1d63 100644
72038 --- a/kernel/rcutree_trace.c
72039 +++ b/kernel/rcutree_trace.c
72040 @@ -92,7 +92,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
72041 rdp->completed, rdp->gpnum,
72042 rdp->passed_quiesce, rdp->qs_pending);
72043 seq_printf(m, " dt=%d/%llx/%d df=%lu",
72044 - atomic_read(&rdp->dynticks->dynticks),
72045 + atomic_read_unchecked(&rdp->dynticks->dynticks),
72046 rdp->dynticks->dynticks_nesting,
72047 rdp->dynticks->dynticks_nmi_nesting,
72048 rdp->dynticks_fqs);
72049 @@ -154,7 +154,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
72050 rdp->completed, rdp->gpnum,
72051 rdp->passed_quiesce, rdp->qs_pending);
72052 seq_printf(m, ",%d,%llx,%d,%lu",
72053 - atomic_read(&rdp->dynticks->dynticks),
72054 + atomic_read_unchecked(&rdp->dynticks->dynticks),
72055 rdp->dynticks->dynticks_nesting,
72056 rdp->dynticks->dynticks_nmi_nesting,
72057 rdp->dynticks_fqs);
72058 diff --git a/kernel/resource.c b/kernel/resource.c
72059 index 73f35d4..4684fc4 100644
72060 --- a/kernel/resource.c
72061 +++ b/kernel/resource.c
72062 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
72063
72064 static int __init ioresources_init(void)
72065 {
72066 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
72067 +#ifdef CONFIG_GRKERNSEC_PROC_USER
72068 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
72069 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
72070 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72071 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
72072 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
72073 +#endif
72074 +#else
72075 proc_create("ioports", 0, NULL, &proc_ioports_operations);
72076 proc_create("iomem", 0, NULL, &proc_iomem_operations);
72077 +#endif
72078 return 0;
72079 }
72080 __initcall(ioresources_init);
72081 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
72082 index 98ec494..4241d6d 100644
72083 --- a/kernel/rtmutex-tester.c
72084 +++ b/kernel/rtmutex-tester.c
72085 @@ -20,7 +20,7 @@
72086 #define MAX_RT_TEST_MUTEXES 8
72087
72088 static spinlock_t rttest_lock;
72089 -static atomic_t rttest_event;
72090 +static atomic_unchecked_t rttest_event;
72091
72092 struct test_thread_data {
72093 int opcode;
72094 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72095
72096 case RTTEST_LOCKCONT:
72097 td->mutexes[td->opdata] = 1;
72098 - td->event = atomic_add_return(1, &rttest_event);
72099 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72100 return 0;
72101
72102 case RTTEST_RESET:
72103 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72104 return 0;
72105
72106 case RTTEST_RESETEVENT:
72107 - atomic_set(&rttest_event, 0);
72108 + atomic_set_unchecked(&rttest_event, 0);
72109 return 0;
72110
72111 default:
72112 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72113 return ret;
72114
72115 td->mutexes[id] = 1;
72116 - td->event = atomic_add_return(1, &rttest_event);
72117 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72118 rt_mutex_lock(&mutexes[id]);
72119 - td->event = atomic_add_return(1, &rttest_event);
72120 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72121 td->mutexes[id] = 4;
72122 return 0;
72123
72124 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72125 return ret;
72126
72127 td->mutexes[id] = 1;
72128 - td->event = atomic_add_return(1, &rttest_event);
72129 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72130 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
72131 - td->event = atomic_add_return(1, &rttest_event);
72132 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72133 td->mutexes[id] = ret ? 0 : 4;
72134 return ret ? -EINTR : 0;
72135
72136 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
72137 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
72138 return ret;
72139
72140 - td->event = atomic_add_return(1, &rttest_event);
72141 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72142 rt_mutex_unlock(&mutexes[id]);
72143 - td->event = atomic_add_return(1, &rttest_event);
72144 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72145 td->mutexes[id] = 0;
72146 return 0;
72147
72148 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72149 break;
72150
72151 td->mutexes[dat] = 2;
72152 - td->event = atomic_add_return(1, &rttest_event);
72153 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72154 break;
72155
72156 default:
72157 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72158 return;
72159
72160 td->mutexes[dat] = 3;
72161 - td->event = atomic_add_return(1, &rttest_event);
72162 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72163 break;
72164
72165 case RTTEST_LOCKNOWAIT:
72166 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
72167 return;
72168
72169 td->mutexes[dat] = 1;
72170 - td->event = atomic_add_return(1, &rttest_event);
72171 + td->event = atomic_add_return_unchecked(1, &rttest_event);
72172 return;
72173
72174 default:
72175 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
72176 index 15f60d0..7e50319 100644
72177 --- a/kernel/sched/auto_group.c
72178 +++ b/kernel/sched/auto_group.c
72179 @@ -11,7 +11,7 @@
72180
72181 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
72182 static struct autogroup autogroup_default;
72183 -static atomic_t autogroup_seq_nr;
72184 +static atomic_unchecked_t autogroup_seq_nr;
72185
72186 void __init autogroup_init(struct task_struct *init_task)
72187 {
72188 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
72189
72190 kref_init(&ag->kref);
72191 init_rwsem(&ag->lock);
72192 - ag->id = atomic_inc_return(&autogroup_seq_nr);
72193 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
72194 ag->tg = tg;
72195 #ifdef CONFIG_RT_GROUP_SCHED
72196 /*
72197 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
72198 index c529d00..d00b4f3 100644
72199 --- a/kernel/sched/core.c
72200 +++ b/kernel/sched/core.c
72201 @@ -3563,6 +3563,8 @@ int can_nice(const struct task_struct *p, const int nice)
72202 /* convert nice value [19,-20] to rlimit style value [1,40] */
72203 int nice_rlim = 20 - nice;
72204
72205 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
72206 +
72207 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
72208 capable(CAP_SYS_NICE));
72209 }
72210 @@ -3596,7 +3598,8 @@ SYSCALL_DEFINE1(nice, int, increment)
72211 if (nice > 19)
72212 nice = 19;
72213
72214 - if (increment < 0 && !can_nice(current, nice))
72215 + if (increment < 0 && (!can_nice(current, nice) ||
72216 + gr_handle_chroot_nice()))
72217 return -EPERM;
72218
72219 retval = security_task_setnice(current, nice);
72220 @@ -3750,6 +3753,7 @@ recheck:
72221 unsigned long rlim_rtprio =
72222 task_rlimit(p, RLIMIT_RTPRIO);
72223
72224 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
72225 /* can't set/change the rt policy */
72226 if (policy != p->policy && !rlim_rtprio)
72227 return -EPERM;
72228 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
72229 index 6b800a1..0c36227 100644
72230 --- a/kernel/sched/fair.c
72231 +++ b/kernel/sched/fair.c
72232 @@ -4890,7 +4890,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
72233 * run_rebalance_domains is triggered when needed from the scheduler tick.
72234 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
72235 */
72236 -static void run_rebalance_domains(struct softirq_action *h)
72237 +static void run_rebalance_domains(void)
72238 {
72239 int this_cpu = smp_processor_id();
72240 struct rq *this_rq = cpu_rq(this_cpu);
72241 diff --git a/kernel/signal.c b/kernel/signal.c
72242 index 57dde52..2c561f0 100644
72243 --- a/kernel/signal.c
72244 +++ b/kernel/signal.c
72245 @@ -49,12 +49,12 @@ static struct kmem_cache *sigqueue_cachep;
72246
72247 int print_fatal_signals __read_mostly;
72248
72249 -static void __user *sig_handler(struct task_struct *t, int sig)
72250 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
72251 {
72252 return t->sighand->action[sig - 1].sa.sa_handler;
72253 }
72254
72255 -static int sig_handler_ignored(void __user *handler, int sig)
72256 +static int sig_handler_ignored(__sighandler_t handler, int sig)
72257 {
72258 /* Is it explicitly or implicitly ignored? */
72259 return handler == SIG_IGN ||
72260 @@ -63,7 +63,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
72261
72262 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
72263 {
72264 - void __user *handler;
72265 + __sighandler_t handler;
72266
72267 handler = sig_handler(t, sig);
72268
72269 @@ -367,6 +367,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
72270 atomic_inc(&user->sigpending);
72271 rcu_read_unlock();
72272
72273 + if (!override_rlimit)
72274 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
72275 +
72276 if (override_rlimit ||
72277 atomic_read(&user->sigpending) <=
72278 task_rlimit(t, RLIMIT_SIGPENDING)) {
72279 @@ -491,7 +494,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
72280
72281 int unhandled_signal(struct task_struct *tsk, int sig)
72282 {
72283 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
72284 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
72285 if (is_global_init(tsk))
72286 return 1;
72287 if (handler != SIG_IGN && handler != SIG_DFL)
72288 @@ -811,6 +814,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
72289 }
72290 }
72291
72292 + /* allow glibc communication via tgkill to other threads in our
72293 + thread group */
72294 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
72295 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
72296 + && gr_handle_signal(t, sig))
72297 + return -EPERM;
72298 +
72299 return security_task_kill(t, info, sig, 0);
72300 }
72301
72302 @@ -1192,7 +1202,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
72303 return send_signal(sig, info, p, 1);
72304 }
72305
72306 -static int
72307 +int
72308 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72309 {
72310 return send_signal(sig, info, t, 0);
72311 @@ -1229,6 +1239,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72312 unsigned long int flags;
72313 int ret, blocked, ignored;
72314 struct k_sigaction *action;
72315 + int is_unhandled = 0;
72316
72317 spin_lock_irqsave(&t->sighand->siglock, flags);
72318 action = &t->sighand->action[sig-1];
72319 @@ -1243,9 +1254,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
72320 }
72321 if (action->sa.sa_handler == SIG_DFL)
72322 t->signal->flags &= ~SIGNAL_UNKILLABLE;
72323 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
72324 + is_unhandled = 1;
72325 ret = specific_send_sig_info(sig, info, t);
72326 spin_unlock_irqrestore(&t->sighand->siglock, flags);
72327
72328 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
72329 + normal operation */
72330 + if (is_unhandled) {
72331 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
72332 + gr_handle_crash(t, sig);
72333 + }
72334 +
72335 return ret;
72336 }
72337
72338 @@ -1312,8 +1332,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
72339 ret = check_kill_permission(sig, info, p);
72340 rcu_read_unlock();
72341
72342 - if (!ret && sig)
72343 + if (!ret && sig) {
72344 ret = do_send_sig_info(sig, info, p, true);
72345 + if (!ret)
72346 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
72347 + }
72348
72349 return ret;
72350 }
72351 @@ -2863,7 +2886,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
72352 int error = -ESRCH;
72353
72354 rcu_read_lock();
72355 - p = find_task_by_vpid(pid);
72356 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72357 + /* allow glibc communication via tgkill to other threads in our
72358 + thread group */
72359 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
72360 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
72361 + p = find_task_by_vpid_unrestricted(pid);
72362 + else
72363 +#endif
72364 + p = find_task_by_vpid(pid);
72365 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
72366 error = check_kill_permission(sig, info, p);
72367 /*
72368 diff --git a/kernel/softirq.c b/kernel/softirq.c
72369 index cc96bdc..8bb9750 100644
72370 --- a/kernel/softirq.c
72371 +++ b/kernel/softirq.c
72372 @@ -57,7 +57,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
72373
72374 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
72375
72376 -char *softirq_to_name[NR_SOFTIRQS] = {
72377 +const char * const softirq_to_name[NR_SOFTIRQS] = {
72378 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
72379 "TASKLET", "SCHED", "HRTIMER", "RCU"
72380 };
72381 @@ -244,7 +244,7 @@ restart:
72382 kstat_incr_softirqs_this_cpu(vec_nr);
72383
72384 trace_softirq_entry(vec_nr);
72385 - h->action(h);
72386 + h->action();
72387 trace_softirq_exit(vec_nr);
72388 if (unlikely(prev_count != preempt_count())) {
72389 printk(KERN_ERR "huh, entered softirq %u %s %p"
72390 @@ -391,9 +391,11 @@ void __raise_softirq_irqoff(unsigned int nr)
72391 or_softirq_pending(1UL << nr);
72392 }
72393
72394 -void open_softirq(int nr, void (*action)(struct softirq_action *))
72395 +void open_softirq(int nr, void (*action)(void))
72396 {
72397 - softirq_vec[nr].action = action;
72398 + pax_open_kernel();
72399 + *(void **)&softirq_vec[nr].action = action;
72400 + pax_close_kernel();
72401 }
72402
72403 /*
72404 @@ -447,7 +449,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
72405
72406 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
72407
72408 -static void tasklet_action(struct softirq_action *a)
72409 +static void tasklet_action(void)
72410 {
72411 struct tasklet_struct *list;
72412
72413 @@ -482,7 +484,7 @@ static void tasklet_action(struct softirq_action *a)
72414 }
72415 }
72416
72417 -static void tasklet_hi_action(struct softirq_action *a)
72418 +static void tasklet_hi_action(void)
72419 {
72420 struct tasklet_struct *list;
72421
72422 diff --git a/kernel/srcu.c b/kernel/srcu.c
72423 index 97c465e..d83f3bb 100644
72424 --- a/kernel/srcu.c
72425 +++ b/kernel/srcu.c
72426 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
72427 preempt_disable();
72428 idx = rcu_dereference_index_check(sp->completed,
72429 rcu_read_lock_sched_held()) & 0x1;
72430 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
72431 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
72432 smp_mb(); /* B */ /* Avoid leaking the critical section. */
72433 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
72434 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
72435 preempt_enable();
72436 return idx;
72437 }
72438 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
72439 {
72440 preempt_disable();
72441 smp_mb(); /* C */ /* Avoid leaking the critical section. */
72442 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72443 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72444 preempt_enable();
72445 }
72446 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
72447 diff --git a/kernel/sys.c b/kernel/sys.c
72448 index e6e0ece..1f2e413 100644
72449 --- a/kernel/sys.c
72450 +++ b/kernel/sys.c
72451 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
72452 error = -EACCES;
72453 goto out;
72454 }
72455 +
72456 + if (gr_handle_chroot_setpriority(p, niceval)) {
72457 + error = -EACCES;
72458 + goto out;
72459 + }
72460 +
72461 no_nice = security_task_setnice(p, niceval);
72462 if (no_nice) {
72463 error = no_nice;
72464 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
72465 goto error;
72466 }
72467
72468 + if (gr_check_group_change(new->gid, new->egid, -1))
72469 + goto error;
72470 +
72471 if (rgid != (gid_t) -1 ||
72472 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
72473 new->sgid = new->egid;
72474 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
72475 old = current_cred();
72476
72477 retval = -EPERM;
72478 +
72479 + if (gr_check_group_change(kgid, kgid, kgid))
72480 + goto error;
72481 +
72482 if (nsown_capable(CAP_SETGID))
72483 new->gid = new->egid = new->sgid = new->fsgid = kgid;
72484 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
72485 @@ -647,7 +660,7 @@ error:
72486 /*
72487 * change the user struct in a credentials set to match the new UID
72488 */
72489 -static int set_user(struct cred *new)
72490 +int set_user(struct cred *new)
72491 {
72492 struct user_struct *new_user;
72493
72494 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
72495 goto error;
72496 }
72497
72498 + if (gr_check_user_change(new->uid, new->euid, -1))
72499 + goto error;
72500 +
72501 if (!uid_eq(new->uid, old->uid)) {
72502 retval = set_user(new);
72503 if (retval < 0)
72504 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
72505 old = current_cred();
72506
72507 retval = -EPERM;
72508 +
72509 + if (gr_check_crash_uid(kuid))
72510 + goto error;
72511 + if (gr_check_user_change(kuid, kuid, kuid))
72512 + goto error;
72513 +
72514 if (nsown_capable(CAP_SETUID)) {
72515 new->suid = new->uid = kuid;
72516 if (!uid_eq(kuid, old->uid)) {
72517 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
72518 goto error;
72519 }
72520
72521 + if (gr_check_user_change(kruid, keuid, -1))
72522 + goto error;
72523 +
72524 if (ruid != (uid_t) -1) {
72525 new->uid = kruid;
72526 if (!uid_eq(kruid, old->uid)) {
72527 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
72528 goto error;
72529 }
72530
72531 + if (gr_check_group_change(krgid, kegid, -1))
72532 + goto error;
72533 +
72534 if (rgid != (gid_t) -1)
72535 new->gid = krgid;
72536 if (egid != (gid_t) -1)
72537 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72538 if (!uid_valid(kuid))
72539 return old_fsuid;
72540
72541 + if (gr_check_user_change(-1, -1, kuid))
72542 + goto error;
72543 +
72544 new = prepare_creds();
72545 if (!new)
72546 return old_fsuid;
72547 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72548 }
72549 }
72550
72551 +error:
72552 abort_creds(new);
72553 return old_fsuid;
72554
72555 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
72556 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
72557 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
72558 nsown_capable(CAP_SETGID)) {
72559 + if (gr_check_group_change(-1, -1, kgid))
72560 + goto error;
72561 +
72562 if (!gid_eq(kgid, old->fsgid)) {
72563 new->fsgid = kgid;
72564 goto change_okay;
72565 }
72566 }
72567
72568 +error:
72569 abort_creds(new);
72570 return old_fsgid;
72571
72572 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
72573 return -EFAULT;
72574
72575 down_read(&uts_sem);
72576 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
72577 + error = __copy_to_user(name->sysname, &utsname()->sysname,
72578 __OLD_UTS_LEN);
72579 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
72580 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
72581 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
72582 __OLD_UTS_LEN);
72583 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
72584 - error |= __copy_to_user(&name->release, &utsname()->release,
72585 + error |= __copy_to_user(name->release, &utsname()->release,
72586 __OLD_UTS_LEN);
72587 error |= __put_user(0, name->release + __OLD_UTS_LEN);
72588 - error |= __copy_to_user(&name->version, &utsname()->version,
72589 + error |= __copy_to_user(name->version, &utsname()->version,
72590 __OLD_UTS_LEN);
72591 error |= __put_user(0, name->version + __OLD_UTS_LEN);
72592 - error |= __copy_to_user(&name->machine, &utsname()->machine,
72593 + error |= __copy_to_user(name->machine, &utsname()->machine,
72594 __OLD_UTS_LEN);
72595 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
72596 up_read(&uts_sem);
72597 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
72598 error = get_dumpable(me->mm);
72599 break;
72600 case PR_SET_DUMPABLE:
72601 - if (arg2 < 0 || arg2 > 1) {
72602 + if (arg2 > 1) {
72603 error = -EINVAL;
72604 break;
72605 }
72606 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
72607 index 26f65ea..df8e5ad 100644
72608 --- a/kernel/sysctl.c
72609 +++ b/kernel/sysctl.c
72610 @@ -92,7 +92,6 @@
72611
72612
72613 #if defined(CONFIG_SYSCTL)
72614 -
72615 /* External variables not in a header file. */
72616 extern int sysctl_overcommit_memory;
72617 extern int sysctl_overcommit_ratio;
72618 @@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
72619 void __user *buffer, size_t *lenp, loff_t *ppos);
72620 #endif
72621
72622 -#ifdef CONFIG_PRINTK
72623 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72624 void __user *buffer, size_t *lenp, loff_t *ppos);
72625 -#endif
72626
72627 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
72628 void __user *buffer, size_t *lenp, loff_t *ppos);
72629 @@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
72630
72631 #endif
72632
72633 +extern struct ctl_table grsecurity_table[];
72634 +
72635 static struct ctl_table kern_table[];
72636 static struct ctl_table vm_table[];
72637 static struct ctl_table fs_table[];
72638 @@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
72639 int sysctl_legacy_va_layout;
72640 #endif
72641
72642 +#ifdef CONFIG_PAX_SOFTMODE
72643 +static ctl_table pax_table[] = {
72644 + {
72645 + .procname = "softmode",
72646 + .data = &pax_softmode,
72647 + .maxlen = sizeof(unsigned int),
72648 + .mode = 0600,
72649 + .proc_handler = &proc_dointvec,
72650 + },
72651 +
72652 + { }
72653 +};
72654 +#endif
72655 +
72656 /* The default sysctl tables: */
72657
72658 static struct ctl_table sysctl_base_table[] = {
72659 @@ -266,6 +279,22 @@ static int max_extfrag_threshold = 1000;
72660 #endif
72661
72662 static struct ctl_table kern_table[] = {
72663 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
72664 + {
72665 + .procname = "grsecurity",
72666 + .mode = 0500,
72667 + .child = grsecurity_table,
72668 + },
72669 +#endif
72670 +
72671 +#ifdef CONFIG_PAX_SOFTMODE
72672 + {
72673 + .procname = "pax",
72674 + .mode = 0500,
72675 + .child = pax_table,
72676 + },
72677 +#endif
72678 +
72679 {
72680 .procname = "sched_child_runs_first",
72681 .data = &sysctl_sched_child_runs_first,
72682 @@ -552,7 +581,7 @@ static struct ctl_table kern_table[] = {
72683 .data = &modprobe_path,
72684 .maxlen = KMOD_PATH_LEN,
72685 .mode = 0644,
72686 - .proc_handler = proc_dostring,
72687 + .proc_handler = proc_dostring_modpriv,
72688 },
72689 {
72690 .procname = "modules_disabled",
72691 @@ -719,16 +748,20 @@ static struct ctl_table kern_table[] = {
72692 .extra1 = &zero,
72693 .extra2 = &one,
72694 },
72695 +#endif
72696 {
72697 .procname = "kptr_restrict",
72698 .data = &kptr_restrict,
72699 .maxlen = sizeof(int),
72700 .mode = 0644,
72701 .proc_handler = proc_dointvec_minmax_sysadmin,
72702 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72703 + .extra1 = &two,
72704 +#else
72705 .extra1 = &zero,
72706 +#endif
72707 .extra2 = &two,
72708 },
72709 -#endif
72710 {
72711 .procname = "ngroups_max",
72712 .data = &ngroups_max,
72713 @@ -1225,6 +1258,13 @@ static struct ctl_table vm_table[] = {
72714 .proc_handler = proc_dointvec_minmax,
72715 .extra1 = &zero,
72716 },
72717 + {
72718 + .procname = "heap_stack_gap",
72719 + .data = &sysctl_heap_stack_gap,
72720 + .maxlen = sizeof(sysctl_heap_stack_gap),
72721 + .mode = 0644,
72722 + .proc_handler = proc_doulongvec_minmax,
72723 + },
72724 #else
72725 {
72726 .procname = "nr_trim_pages",
72727 @@ -1675,6 +1715,16 @@ int proc_dostring(struct ctl_table *table, int write,
72728 buffer, lenp, ppos);
72729 }
72730
72731 +int proc_dostring_modpriv(struct ctl_table *table, int write,
72732 + void __user *buffer, size_t *lenp, loff_t *ppos)
72733 +{
72734 + if (write && !capable(CAP_SYS_MODULE))
72735 + return -EPERM;
72736 +
72737 + return _proc_do_string(table->data, table->maxlen, write,
72738 + buffer, lenp, ppos);
72739 +}
72740 +
72741 static size_t proc_skip_spaces(char **buf)
72742 {
72743 size_t ret;
72744 @@ -1780,6 +1830,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
72745 len = strlen(tmp);
72746 if (len > *size)
72747 len = *size;
72748 + if (len > sizeof(tmp))
72749 + len = sizeof(tmp);
72750 if (copy_to_user(*buf, tmp, len))
72751 return -EFAULT;
72752 *size -= len;
72753 @@ -1972,7 +2024,6 @@ static int proc_taint(struct ctl_table *table, int write,
72754 return err;
72755 }
72756
72757 -#ifdef CONFIG_PRINTK
72758 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72759 void __user *buffer, size_t *lenp, loff_t *ppos)
72760 {
72761 @@ -1981,7 +2032,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72762
72763 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
72764 }
72765 -#endif
72766
72767 struct do_proc_dointvec_minmax_conv_param {
72768 int *min;
72769 @@ -2128,8 +2178,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
72770 *i = val;
72771 } else {
72772 val = convdiv * (*i) / convmul;
72773 - if (!first)
72774 + if (!first) {
72775 err = proc_put_char(&buffer, &left, '\t');
72776 + if (err)
72777 + break;
72778 + }
72779 err = proc_put_long(&buffer, &left, val, false);
72780 if (err)
72781 break;
72782 @@ -2521,6 +2574,12 @@ int proc_dostring(struct ctl_table *table, int write,
72783 return -ENOSYS;
72784 }
72785
72786 +int proc_dostring_modpriv(struct ctl_table *table, int write,
72787 + void __user *buffer, size_t *lenp, loff_t *ppos)
72788 +{
72789 + return -ENOSYS;
72790 +}
72791 +
72792 int proc_dointvec(struct ctl_table *table, int write,
72793 void __user *buffer, size_t *lenp, loff_t *ppos)
72794 {
72795 @@ -2577,5 +2636,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
72796 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
72797 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
72798 EXPORT_SYMBOL(proc_dostring);
72799 +EXPORT_SYMBOL(proc_dostring_modpriv);
72800 EXPORT_SYMBOL(proc_doulongvec_minmax);
72801 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
72802 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
72803 index 65bdcf1..21eb831 100644
72804 --- a/kernel/sysctl_binary.c
72805 +++ b/kernel/sysctl_binary.c
72806 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
72807 int i;
72808
72809 set_fs(KERNEL_DS);
72810 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72811 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72812 set_fs(old_fs);
72813 if (result < 0)
72814 goto out_kfree;
72815 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
72816 }
72817
72818 set_fs(KERNEL_DS);
72819 - result = vfs_write(file, buffer, str - buffer, &pos);
72820 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72821 set_fs(old_fs);
72822 if (result < 0)
72823 goto out_kfree;
72824 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
72825 int i;
72826
72827 set_fs(KERNEL_DS);
72828 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72829 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72830 set_fs(old_fs);
72831 if (result < 0)
72832 goto out_kfree;
72833 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
72834 }
72835
72836 set_fs(KERNEL_DS);
72837 - result = vfs_write(file, buffer, str - buffer, &pos);
72838 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72839 set_fs(old_fs);
72840 if (result < 0)
72841 goto out_kfree;
72842 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
72843 int i;
72844
72845 set_fs(KERNEL_DS);
72846 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72847 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72848 set_fs(old_fs);
72849 if (result < 0)
72850 goto out;
72851 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72852 __le16 dnaddr;
72853
72854 set_fs(KERNEL_DS);
72855 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72856 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72857 set_fs(old_fs);
72858 if (result < 0)
72859 goto out;
72860 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72861 le16_to_cpu(dnaddr) & 0x3ff);
72862
72863 set_fs(KERNEL_DS);
72864 - result = vfs_write(file, buf, len, &pos);
72865 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
72866 set_fs(old_fs);
72867 if (result < 0)
72868 goto out;
72869 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
72870 index 145bb4d..b2aa969 100644
72871 --- a/kernel/taskstats.c
72872 +++ b/kernel/taskstats.c
72873 @@ -28,9 +28,12 @@
72874 #include <linux/fs.h>
72875 #include <linux/file.h>
72876 #include <linux/pid_namespace.h>
72877 +#include <linux/grsecurity.h>
72878 #include <net/genetlink.h>
72879 #include <linux/atomic.h>
72880
72881 +extern int gr_is_taskstats_denied(int pid);
72882 +
72883 /*
72884 * Maximum length of a cpumask that can be specified in
72885 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
72886 @@ -570,6 +573,9 @@ err:
72887
72888 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
72889 {
72890 + if (gr_is_taskstats_denied(current->pid))
72891 + return -EACCES;
72892 +
72893 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
72894 return cmd_attr_register_cpumask(info);
72895 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
72896 diff --git a/kernel/time.c b/kernel/time.c
72897 index d226c6a..c7c0960 100644
72898 --- a/kernel/time.c
72899 +++ b/kernel/time.c
72900 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
72901 return error;
72902
72903 if (tz) {
72904 + /* we log in do_settimeofday called below, so don't log twice
72905 + */
72906 + if (!tv)
72907 + gr_log_timechange();
72908 +
72909 sys_tz = *tz;
72910 update_vsyscall_tz();
72911 if (firsttime) {
72912 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
72913 index f11d83b..d016d91 100644
72914 --- a/kernel/time/alarmtimer.c
72915 +++ b/kernel/time/alarmtimer.c
72916 @@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
72917 struct platform_device *pdev;
72918 int error = 0;
72919 int i;
72920 - struct k_clock alarm_clock = {
72921 + static struct k_clock alarm_clock = {
72922 .clock_getres = alarm_clock_getres,
72923 .clock_get = alarm_clock_get,
72924 .timer_create = alarm_timer_create,
72925 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
72926 index f113755..ec24223 100644
72927 --- a/kernel/time/tick-broadcast.c
72928 +++ b/kernel/time/tick-broadcast.c
72929 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
72930 * then clear the broadcast bit.
72931 */
72932 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
72933 - int cpu = smp_processor_id();
72934 + cpu = smp_processor_id();
72935
72936 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
72937 tick_broadcast_clear_oneshot(cpu);
72938 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
72939 index e424970..4c7962b 100644
72940 --- a/kernel/time/timekeeping.c
72941 +++ b/kernel/time/timekeeping.c
72942 @@ -15,6 +15,7 @@
72943 #include <linux/init.h>
72944 #include <linux/mm.h>
72945 #include <linux/sched.h>
72946 +#include <linux/grsecurity.h>
72947 #include <linux/syscore_ops.h>
72948 #include <linux/clocksource.h>
72949 #include <linux/jiffies.h>
72950 @@ -368,6 +369,8 @@ int do_settimeofday(const struct timespec *tv)
72951 if (!timespec_valid_strict(tv))
72952 return -EINVAL;
72953
72954 + gr_log_timechange();
72955 +
72956 write_seqlock_irqsave(&tk->lock, flags);
72957
72958 timekeeping_forward_now(tk);
72959 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
72960 index af5a7e9..715611a 100644
72961 --- a/kernel/time/timer_list.c
72962 +++ b/kernel/time/timer_list.c
72963 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
72964
72965 static void print_name_offset(struct seq_file *m, void *sym)
72966 {
72967 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72968 + SEQ_printf(m, "<%p>", NULL);
72969 +#else
72970 char symname[KSYM_NAME_LEN];
72971
72972 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
72973 SEQ_printf(m, "<%pK>", sym);
72974 else
72975 SEQ_printf(m, "%s", symname);
72976 +#endif
72977 }
72978
72979 static void
72980 @@ -112,7 +116,11 @@ next_one:
72981 static void
72982 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
72983 {
72984 +#ifdef CONFIG_GRKERNSEC_HIDESYM
72985 + SEQ_printf(m, " .base: %p\n", NULL);
72986 +#else
72987 SEQ_printf(m, " .base: %pK\n", base);
72988 +#endif
72989 SEQ_printf(m, " .index: %d\n",
72990 base->index);
72991 SEQ_printf(m, " .resolution: %Lu nsecs\n",
72992 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
72993 {
72994 struct proc_dir_entry *pe;
72995
72996 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
72997 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
72998 +#else
72999 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
73000 +#endif
73001 if (!pe)
73002 return -ENOMEM;
73003 return 0;
73004 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
73005 index 0b537f2..40d6c20 100644
73006 --- a/kernel/time/timer_stats.c
73007 +++ b/kernel/time/timer_stats.c
73008 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
73009 static unsigned long nr_entries;
73010 static struct entry entries[MAX_ENTRIES];
73011
73012 -static atomic_t overflow_count;
73013 +static atomic_unchecked_t overflow_count;
73014
73015 /*
73016 * The entries are in a hash-table, for fast lookup:
73017 @@ -140,7 +140,7 @@ static void reset_entries(void)
73018 nr_entries = 0;
73019 memset(entries, 0, sizeof(entries));
73020 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
73021 - atomic_set(&overflow_count, 0);
73022 + atomic_set_unchecked(&overflow_count, 0);
73023 }
73024
73025 static struct entry *alloc_entry(void)
73026 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
73027 if (likely(entry))
73028 entry->count++;
73029 else
73030 - atomic_inc(&overflow_count);
73031 + atomic_inc_unchecked(&overflow_count);
73032
73033 out_unlock:
73034 raw_spin_unlock_irqrestore(lock, flags);
73035 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
73036
73037 static void print_name_offset(struct seq_file *m, unsigned long addr)
73038 {
73039 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73040 + seq_printf(m, "<%p>", NULL);
73041 +#else
73042 char symname[KSYM_NAME_LEN];
73043
73044 if (lookup_symbol_name(addr, symname) < 0)
73045 - seq_printf(m, "<%p>", (void *)addr);
73046 + seq_printf(m, "<%pK>", (void *)addr);
73047 else
73048 seq_printf(m, "%s", symname);
73049 +#endif
73050 }
73051
73052 static int tstats_show(struct seq_file *m, void *v)
73053 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
73054
73055 seq_puts(m, "Timer Stats Version: v0.2\n");
73056 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
73057 - if (atomic_read(&overflow_count))
73058 + if (atomic_read_unchecked(&overflow_count))
73059 seq_printf(m, "Overflow: %d entries\n",
73060 - atomic_read(&overflow_count));
73061 + atomic_read_unchecked(&overflow_count));
73062
73063 for (i = 0; i < nr_entries; i++) {
73064 entry = entries + i;
73065 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
73066 {
73067 struct proc_dir_entry *pe;
73068
73069 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
73070 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
73071 +#else
73072 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
73073 +#endif
73074 if (!pe)
73075 return -ENOMEM;
73076 return 0;
73077 diff --git a/kernel/timer.c b/kernel/timer.c
73078 index 367d008..46857a0 100644
73079 --- a/kernel/timer.c
73080 +++ b/kernel/timer.c
73081 @@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
73082 /*
73083 * This function runs timers and the timer-tq in bottom half context.
73084 */
73085 -static void run_timer_softirq(struct softirq_action *h)
73086 +static void run_timer_softirq(void)
73087 {
73088 struct tvec_base *base = __this_cpu_read(tvec_bases);
73089
73090 @@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
73091 return NOTIFY_OK;
73092 }
73093
73094 -static struct notifier_block __cpuinitdata timers_nb = {
73095 +static struct notifier_block __cpuinitconst timers_nb = {
73096 .notifier_call = timer_cpu_notify,
73097 };
73098
73099 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
73100 index c0bd030..62a1927 100644
73101 --- a/kernel/trace/blktrace.c
73102 +++ b/kernel/trace/blktrace.c
73103 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
73104 struct blk_trace *bt = filp->private_data;
73105 char buf[16];
73106
73107 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
73108 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
73109
73110 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
73111 }
73112 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
73113 return 1;
73114
73115 bt = buf->chan->private_data;
73116 - atomic_inc(&bt->dropped);
73117 + atomic_inc_unchecked(&bt->dropped);
73118 return 0;
73119 }
73120
73121 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
73122
73123 bt->dir = dir;
73124 bt->dev = dev;
73125 - atomic_set(&bt->dropped, 0);
73126 + atomic_set_unchecked(&bt->dropped, 0);
73127
73128 ret = -EIO;
73129 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
73130 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
73131 index 356bc2f..7c94fc0 100644
73132 --- a/kernel/trace/ftrace.c
73133 +++ b/kernel/trace/ftrace.c
73134 @@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
73135 if (unlikely(ftrace_disabled))
73136 return 0;
73137
73138 + ret = ftrace_arch_code_modify_prepare();
73139 + FTRACE_WARN_ON(ret);
73140 + if (ret)
73141 + return 0;
73142 +
73143 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
73144 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
73145 if (ret) {
73146 ftrace_bug(ret, ip);
73147 - return 0;
73148 }
73149 - return 1;
73150 + return ret ? 0 : 1;
73151 }
73152
73153 /*
73154 @@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
73155
73156 int
73157 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
73158 - void *data)
73159 + void *data)
73160 {
73161 struct ftrace_func_probe *entry;
73162 struct ftrace_page *pg;
73163 @@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
73164 if (!count)
73165 return 0;
73166
73167 + pax_open_kernel();
73168 sort(start, count, sizeof(*start),
73169 ftrace_cmp_ips, ftrace_swap_ips);
73170 + pax_close_kernel();
73171
73172 start_pg = ftrace_allocate_pages(count);
73173 if (!start_pg)
73174 @@ -4541,8 +4548,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
73175 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
73176
73177 static int ftrace_graph_active;
73178 -static struct notifier_block ftrace_suspend_notifier;
73179 -
73180 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
73181 {
73182 return 0;
73183 @@ -4686,6 +4691,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
73184 return NOTIFY_DONE;
73185 }
73186
73187 +static struct notifier_block ftrace_suspend_notifier = {
73188 + .notifier_call = ftrace_suspend_notifier_call
73189 +};
73190 +
73191 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
73192 trace_func_graph_ent_t entryfunc)
73193 {
73194 @@ -4699,7 +4708,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
73195 goto out;
73196 }
73197
73198 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
73199 register_pm_notifier(&ftrace_suspend_notifier);
73200
73201 ftrace_graph_active++;
73202 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
73203 index 4cb5e51..e7e05d9 100644
73204 --- a/kernel/trace/ring_buffer.c
73205 +++ b/kernel/trace/ring_buffer.c
73206 @@ -346,9 +346,9 @@ struct buffer_data_page {
73207 */
73208 struct buffer_page {
73209 struct list_head list; /* list of buffer pages */
73210 - local_t write; /* index for next write */
73211 + local_unchecked_t write; /* index for next write */
73212 unsigned read; /* index for next read */
73213 - local_t entries; /* entries on this page */
73214 + local_unchecked_t entries; /* entries on this page */
73215 unsigned long real_end; /* real end of data */
73216 struct buffer_data_page *page; /* Actual data page */
73217 };
73218 @@ -460,8 +460,8 @@ struct ring_buffer_per_cpu {
73219 unsigned long lost_events;
73220 unsigned long last_overrun;
73221 local_t entries_bytes;
73222 - local_t commit_overrun;
73223 - local_t overrun;
73224 + local_unchecked_t commit_overrun;
73225 + local_unchecked_t overrun;
73226 local_t entries;
73227 local_t committing;
73228 local_t commits;
73229 @@ -860,8 +860,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
73230 *
73231 * We add a counter to the write field to denote this.
73232 */
73233 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
73234 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
73235 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
73236 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
73237
73238 /*
73239 * Just make sure we have seen our old_write and synchronize
73240 @@ -889,8 +889,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
73241 * cmpxchg to only update if an interrupt did not already
73242 * do it for us. If the cmpxchg fails, we don't care.
73243 */
73244 - (void)local_cmpxchg(&next_page->write, old_write, val);
73245 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
73246 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
73247 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
73248
73249 /*
73250 * No need to worry about races with clearing out the commit.
73251 @@ -1249,12 +1249,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
73252
73253 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
73254 {
73255 - return local_read(&bpage->entries) & RB_WRITE_MASK;
73256 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
73257 }
73258
73259 static inline unsigned long rb_page_write(struct buffer_page *bpage)
73260 {
73261 - return local_read(&bpage->write) & RB_WRITE_MASK;
73262 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
73263 }
73264
73265 static int
73266 @@ -1349,7 +1349,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
73267 * bytes consumed in ring buffer from here.
73268 * Increment overrun to account for the lost events.
73269 */
73270 - local_add(page_entries, &cpu_buffer->overrun);
73271 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
73272 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
73273 }
73274
73275 @@ -1905,7 +1905,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
73276 * it is our responsibility to update
73277 * the counters.
73278 */
73279 - local_add(entries, &cpu_buffer->overrun);
73280 + local_add_unchecked(entries, &cpu_buffer->overrun);
73281 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
73282
73283 /*
73284 @@ -2055,7 +2055,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73285 if (tail == BUF_PAGE_SIZE)
73286 tail_page->real_end = 0;
73287
73288 - local_sub(length, &tail_page->write);
73289 + local_sub_unchecked(length, &tail_page->write);
73290 return;
73291 }
73292
73293 @@ -2090,7 +2090,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73294 rb_event_set_padding(event);
73295
73296 /* Set the write back to the previous setting */
73297 - local_sub(length, &tail_page->write);
73298 + local_sub_unchecked(length, &tail_page->write);
73299 return;
73300 }
73301
73302 @@ -2102,7 +2102,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
73303
73304 /* Set write to end of buffer */
73305 length = (tail + length) - BUF_PAGE_SIZE;
73306 - local_sub(length, &tail_page->write);
73307 + local_sub_unchecked(length, &tail_page->write);
73308 }
73309
73310 /*
73311 @@ -2128,7 +2128,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
73312 * about it.
73313 */
73314 if (unlikely(next_page == commit_page)) {
73315 - local_inc(&cpu_buffer->commit_overrun);
73316 + local_inc_unchecked(&cpu_buffer->commit_overrun);
73317 goto out_reset;
73318 }
73319
73320 @@ -2182,7 +2182,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
73321 cpu_buffer->tail_page) &&
73322 (cpu_buffer->commit_page ==
73323 cpu_buffer->reader_page))) {
73324 - local_inc(&cpu_buffer->commit_overrun);
73325 + local_inc_unchecked(&cpu_buffer->commit_overrun);
73326 goto out_reset;
73327 }
73328 }
73329 @@ -2230,7 +2230,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
73330 length += RB_LEN_TIME_EXTEND;
73331
73332 tail_page = cpu_buffer->tail_page;
73333 - write = local_add_return(length, &tail_page->write);
73334 + write = local_add_return_unchecked(length, &tail_page->write);
73335
73336 /* set write to only the index of the write */
73337 write &= RB_WRITE_MASK;
73338 @@ -2247,7 +2247,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
73339 kmemcheck_annotate_bitfield(event, bitfield);
73340 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
73341
73342 - local_inc(&tail_page->entries);
73343 + local_inc_unchecked(&tail_page->entries);
73344
73345 /*
73346 * If this is the first commit on the page, then update
73347 @@ -2280,7 +2280,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
73348
73349 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
73350 unsigned long write_mask =
73351 - local_read(&bpage->write) & ~RB_WRITE_MASK;
73352 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
73353 unsigned long event_length = rb_event_length(event);
73354 /*
73355 * This is on the tail page. It is possible that
73356 @@ -2290,7 +2290,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
73357 */
73358 old_index += write_mask;
73359 new_index += write_mask;
73360 - index = local_cmpxchg(&bpage->write, old_index, new_index);
73361 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
73362 if (index == old_index) {
73363 /* update counters */
73364 local_sub(event_length, &cpu_buffer->entries_bytes);
73365 @@ -2629,7 +2629,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
73366
73367 /* Do the likely case first */
73368 if (likely(bpage->page == (void *)addr)) {
73369 - local_dec(&bpage->entries);
73370 + local_dec_unchecked(&bpage->entries);
73371 return;
73372 }
73373
73374 @@ -2641,7 +2641,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
73375 start = bpage;
73376 do {
73377 if (bpage->page == (void *)addr) {
73378 - local_dec(&bpage->entries);
73379 + local_dec_unchecked(&bpage->entries);
73380 return;
73381 }
73382 rb_inc_page(cpu_buffer, &bpage);
73383 @@ -2923,7 +2923,7 @@ static inline unsigned long
73384 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
73385 {
73386 return local_read(&cpu_buffer->entries) -
73387 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
73388 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
73389 }
73390
73391 /**
73392 @@ -3011,7 +3011,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
73393 return 0;
73394
73395 cpu_buffer = buffer->buffers[cpu];
73396 - ret = local_read(&cpu_buffer->overrun);
73397 + ret = local_read_unchecked(&cpu_buffer->overrun);
73398
73399 return ret;
73400 }
73401 @@ -3032,7 +3032,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
73402 return 0;
73403
73404 cpu_buffer = buffer->buffers[cpu];
73405 - ret = local_read(&cpu_buffer->commit_overrun);
73406 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
73407
73408 return ret;
73409 }
73410 @@ -3077,7 +3077,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
73411 /* if you care about this being correct, lock the buffer */
73412 for_each_buffer_cpu(buffer, cpu) {
73413 cpu_buffer = buffer->buffers[cpu];
73414 - overruns += local_read(&cpu_buffer->overrun);
73415 + overruns += local_read_unchecked(&cpu_buffer->overrun);
73416 }
73417
73418 return overruns;
73419 @@ -3253,8 +3253,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
73420 /*
73421 * Reset the reader page to size zero.
73422 */
73423 - local_set(&cpu_buffer->reader_page->write, 0);
73424 - local_set(&cpu_buffer->reader_page->entries, 0);
73425 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
73426 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
73427 local_set(&cpu_buffer->reader_page->page->commit, 0);
73428 cpu_buffer->reader_page->real_end = 0;
73429
73430 @@ -3288,7 +3288,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
73431 * want to compare with the last_overrun.
73432 */
73433 smp_mb();
73434 - overwrite = local_read(&(cpu_buffer->overrun));
73435 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
73436
73437 /*
73438 * Here's the tricky part.
73439 @@ -3858,8 +3858,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73440
73441 cpu_buffer->head_page
73442 = list_entry(cpu_buffer->pages, struct buffer_page, list);
73443 - local_set(&cpu_buffer->head_page->write, 0);
73444 - local_set(&cpu_buffer->head_page->entries, 0);
73445 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
73446 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
73447 local_set(&cpu_buffer->head_page->page->commit, 0);
73448
73449 cpu_buffer->head_page->read = 0;
73450 @@ -3869,14 +3869,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73451
73452 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
73453 INIT_LIST_HEAD(&cpu_buffer->new_pages);
73454 - local_set(&cpu_buffer->reader_page->write, 0);
73455 - local_set(&cpu_buffer->reader_page->entries, 0);
73456 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
73457 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
73458 local_set(&cpu_buffer->reader_page->page->commit, 0);
73459 cpu_buffer->reader_page->read = 0;
73460
73461 - local_set(&cpu_buffer->commit_overrun, 0);
73462 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
73463 local_set(&cpu_buffer->entries_bytes, 0);
73464 - local_set(&cpu_buffer->overrun, 0);
73465 + local_set_unchecked(&cpu_buffer->overrun, 0);
73466 local_set(&cpu_buffer->entries, 0);
73467 local_set(&cpu_buffer->committing, 0);
73468 local_set(&cpu_buffer->commits, 0);
73469 @@ -4279,8 +4279,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
73470 rb_init_page(bpage);
73471 bpage = reader->page;
73472 reader->page = *data_page;
73473 - local_set(&reader->write, 0);
73474 - local_set(&reader->entries, 0);
73475 + local_set_unchecked(&reader->write, 0);
73476 + local_set_unchecked(&reader->entries, 0);
73477 reader->read = 0;
73478 *data_page = bpage;
73479
73480 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
73481 index 31e4f55..62da00f 100644
73482 --- a/kernel/trace/trace.c
73483 +++ b/kernel/trace/trace.c
73484 @@ -4436,10 +4436,9 @@ static const struct file_operations tracing_dyn_info_fops = {
73485 };
73486 #endif
73487
73488 -static struct dentry *d_tracer;
73489 -
73490 struct dentry *tracing_init_dentry(void)
73491 {
73492 + static struct dentry *d_tracer;
73493 static int once;
73494
73495 if (d_tracer)
73496 @@ -4459,10 +4458,9 @@ struct dentry *tracing_init_dentry(void)
73497 return d_tracer;
73498 }
73499
73500 -static struct dentry *d_percpu;
73501 -
73502 struct dentry *tracing_dentry_percpu(void)
73503 {
73504 + static struct dentry *d_percpu;
73505 static int once;
73506 struct dentry *d_tracer;
73507
73508 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
73509 index d608d09..7eddcb1 100644
73510 --- a/kernel/trace/trace_events.c
73511 +++ b/kernel/trace/trace_events.c
73512 @@ -1320,10 +1320,6 @@ static LIST_HEAD(ftrace_module_file_list);
73513 struct ftrace_module_file_ops {
73514 struct list_head list;
73515 struct module *mod;
73516 - struct file_operations id;
73517 - struct file_operations enable;
73518 - struct file_operations format;
73519 - struct file_operations filter;
73520 };
73521
73522 static struct ftrace_module_file_ops *
73523 @@ -1344,17 +1340,12 @@ trace_create_file_ops(struct module *mod)
73524
73525 file_ops->mod = mod;
73526
73527 - file_ops->id = ftrace_event_id_fops;
73528 - file_ops->id.owner = mod;
73529 -
73530 - file_ops->enable = ftrace_enable_fops;
73531 - file_ops->enable.owner = mod;
73532 -
73533 - file_ops->filter = ftrace_event_filter_fops;
73534 - file_ops->filter.owner = mod;
73535 -
73536 - file_ops->format = ftrace_event_format_fops;
73537 - file_ops->format.owner = mod;
73538 + pax_open_kernel();
73539 + *(void **)&mod->trace_id.owner = mod;
73540 + *(void **)&mod->trace_enable.owner = mod;
73541 + *(void **)&mod->trace_filter.owner = mod;
73542 + *(void **)&mod->trace_format.owner = mod;
73543 + pax_close_kernel();
73544
73545 list_add(&file_ops->list, &ftrace_module_file_list);
73546
73547 @@ -1378,8 +1369,8 @@ static void trace_module_add_events(struct module *mod)
73548
73549 for_each_event(call, start, end) {
73550 __trace_add_event_call(*call, mod,
73551 - &file_ops->id, &file_ops->enable,
73552 - &file_ops->filter, &file_ops->format);
73553 + &mod->trace_id, &mod->trace_enable,
73554 + &mod->trace_filter, &mod->trace_format);
73555 }
73556 }
73557
73558 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
73559 index fd3c8aa..5f324a6 100644
73560 --- a/kernel/trace/trace_mmiotrace.c
73561 +++ b/kernel/trace/trace_mmiotrace.c
73562 @@ -24,7 +24,7 @@ struct header_iter {
73563 static struct trace_array *mmio_trace_array;
73564 static bool overrun_detected;
73565 static unsigned long prev_overruns;
73566 -static atomic_t dropped_count;
73567 +static atomic_unchecked_t dropped_count;
73568
73569 static void mmio_reset_data(struct trace_array *tr)
73570 {
73571 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
73572
73573 static unsigned long count_overruns(struct trace_iterator *iter)
73574 {
73575 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
73576 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
73577 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
73578
73579 if (over > prev_overruns)
73580 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
73581 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
73582 sizeof(*entry), 0, pc);
73583 if (!event) {
73584 - atomic_inc(&dropped_count);
73585 + atomic_inc_unchecked(&dropped_count);
73586 return;
73587 }
73588 entry = ring_buffer_event_data(event);
73589 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
73590 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
73591 sizeof(*entry), 0, pc);
73592 if (!event) {
73593 - atomic_inc(&dropped_count);
73594 + atomic_inc_unchecked(&dropped_count);
73595 return;
73596 }
73597 entry = ring_buffer_event_data(event);
73598 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
73599 index 123b189..1e9e2a6 100644
73600 --- a/kernel/trace/trace_output.c
73601 +++ b/kernel/trace/trace_output.c
73602 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
73603
73604 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
73605 if (!IS_ERR(p)) {
73606 - p = mangle_path(s->buffer + s->len, p, "\n");
73607 + p = mangle_path(s->buffer + s->len, p, "\n\\");
73608 if (p) {
73609 s->len = p - s->buffer;
73610 return 1;
73611 @@ -824,14 +824,16 @@ int register_ftrace_event(struct trace_event *event)
73612 goto out;
73613 }
73614
73615 + pax_open_kernel();
73616 if (event->funcs->trace == NULL)
73617 - event->funcs->trace = trace_nop_print;
73618 + *(void **)&event->funcs->trace = trace_nop_print;
73619 if (event->funcs->raw == NULL)
73620 - event->funcs->raw = trace_nop_print;
73621 + *(void **)&event->funcs->raw = trace_nop_print;
73622 if (event->funcs->hex == NULL)
73623 - event->funcs->hex = trace_nop_print;
73624 + *(void **)&event->funcs->hex = trace_nop_print;
73625 if (event->funcs->binary == NULL)
73626 - event->funcs->binary = trace_nop_print;
73627 + *(void **)&event->funcs->binary = trace_nop_print;
73628 + pax_close_kernel();
73629
73630 key = event->type & (EVENT_HASHSIZE - 1);
73631
73632 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
73633 index 0c1b1657..95337e9 100644
73634 --- a/kernel/trace/trace_stack.c
73635 +++ b/kernel/trace/trace_stack.c
73636 @@ -53,7 +53,7 @@ static inline void check_stack(void)
73637 return;
73638
73639 /* we do not handle interrupt stacks yet */
73640 - if (!object_is_on_stack(&this_size))
73641 + if (!object_starts_on_stack(&this_size))
73642 return;
73643
73644 local_irq_save(flags);
73645 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
73646 index 28e9d6c9..50381bd 100644
73647 --- a/lib/Kconfig.debug
73648 +++ b/lib/Kconfig.debug
73649 @@ -1278,6 +1278,7 @@ config LATENCYTOP
73650 depends on DEBUG_KERNEL
73651 depends on STACKTRACE_SUPPORT
73652 depends on PROC_FS
73653 + depends on !GRKERNSEC_HIDESYM
73654 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
73655 select KALLSYMS
73656 select KALLSYMS_ALL
73657 @@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
73658
73659 config PROVIDE_OHCI1394_DMA_INIT
73660 bool "Remote debugging over FireWire early on boot"
73661 - depends on PCI && X86
73662 + depends on PCI && X86 && !GRKERNSEC
73663 help
73664 If you want to debug problems which hang or crash the kernel early
73665 on boot and the crashing machine has a FireWire port, you can use
73666 @@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
73667
73668 config FIREWIRE_OHCI_REMOTE_DMA
73669 bool "Remote debugging over FireWire with firewire-ohci"
73670 - depends on FIREWIRE_OHCI
73671 + depends on FIREWIRE_OHCI && !GRKERNSEC
73672 help
73673 This option lets you use the FireWire bus for remote debugging
73674 with help of the firewire-ohci driver. It enables unfiltered
73675 diff --git a/lib/Makefile b/lib/Makefile
73676 index a08b791..a3ff1eb 100644
73677 --- a/lib/Makefile
73678 +++ b/lib/Makefile
73679 @@ -46,7 +46,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
73680
73681 obj-$(CONFIG_BTREE) += btree.o
73682 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
73683 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
73684 +obj-y += list_debug.o
73685 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
73686
73687 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
73688 diff --git a/lib/bitmap.c b/lib/bitmap.c
73689 index 06fdfa1..97c5c7d 100644
73690 --- a/lib/bitmap.c
73691 +++ b/lib/bitmap.c
73692 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
73693 {
73694 int c, old_c, totaldigits, ndigits, nchunks, nbits;
73695 u32 chunk;
73696 - const char __user __force *ubuf = (const char __user __force *)buf;
73697 + const char __user *ubuf = (const char __force_user *)buf;
73698
73699 bitmap_zero(maskp, nmaskbits);
73700
73701 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
73702 {
73703 if (!access_ok(VERIFY_READ, ubuf, ulen))
73704 return -EFAULT;
73705 - return __bitmap_parse((const char __force *)ubuf,
73706 + return __bitmap_parse((const char __force_kernel *)ubuf,
73707 ulen, 1, maskp, nmaskbits);
73708
73709 }
73710 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
73711 {
73712 unsigned a, b;
73713 int c, old_c, totaldigits;
73714 - const char __user __force *ubuf = (const char __user __force *)buf;
73715 + const char __user *ubuf = (const char __force_user *)buf;
73716 int exp_digit, in_range;
73717
73718 totaldigits = c = 0;
73719 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
73720 {
73721 if (!access_ok(VERIFY_READ, ubuf, ulen))
73722 return -EFAULT;
73723 - return __bitmap_parselist((const char __force *)ubuf,
73724 + return __bitmap_parselist((const char __force_kernel *)ubuf,
73725 ulen, 1, maskp, nmaskbits);
73726 }
73727 EXPORT_SYMBOL(bitmap_parselist_user);
73728 diff --git a/lib/bug.c b/lib/bug.c
73729 index d0cdf14..4d07bd2 100644
73730 --- a/lib/bug.c
73731 +++ b/lib/bug.c
73732 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
73733 return BUG_TRAP_TYPE_NONE;
73734
73735 bug = find_bug(bugaddr);
73736 + if (!bug)
73737 + return BUG_TRAP_TYPE_NONE;
73738
73739 file = NULL;
73740 line = 0;
73741 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
73742 index d11808c..dc2d6f8 100644
73743 --- a/lib/debugobjects.c
73744 +++ b/lib/debugobjects.c
73745 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
73746 if (limit > 4)
73747 return;
73748
73749 - is_on_stack = object_is_on_stack(addr);
73750 + is_on_stack = object_starts_on_stack(addr);
73751 if (is_on_stack == onstack)
73752 return;
73753
73754 diff --git a/lib/devres.c b/lib/devres.c
73755 index 80b9c76..9e32279 100644
73756 --- a/lib/devres.c
73757 +++ b/lib/devres.c
73758 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
73759 void devm_iounmap(struct device *dev, void __iomem *addr)
73760 {
73761 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
73762 - (void *)addr));
73763 + (void __force *)addr));
73764 iounmap(addr);
73765 }
73766 EXPORT_SYMBOL(devm_iounmap);
73767 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
73768 {
73769 ioport_unmap(addr);
73770 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
73771 - devm_ioport_map_match, (void *)addr));
73772 + devm_ioport_map_match, (void __force *)addr));
73773 }
73774 EXPORT_SYMBOL(devm_ioport_unmap);
73775
73776 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
73777 index d84beb9..da44791 100644
73778 --- a/lib/dma-debug.c
73779 +++ b/lib/dma-debug.c
73780 @@ -754,7 +754,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
73781
73782 void dma_debug_add_bus(struct bus_type *bus)
73783 {
73784 - struct notifier_block *nb;
73785 + notifier_block_no_const *nb;
73786
73787 if (global_disable)
73788 return;
73789 @@ -919,7 +919,7 @@ out:
73790
73791 static void check_for_stack(struct device *dev, void *addr)
73792 {
73793 - if (object_is_on_stack(addr))
73794 + if (object_starts_on_stack(addr))
73795 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
73796 "stack [addr=%p]\n", addr);
73797 }
73798 diff --git a/lib/inflate.c b/lib/inflate.c
73799 index 013a761..c28f3fc 100644
73800 --- a/lib/inflate.c
73801 +++ b/lib/inflate.c
73802 @@ -269,7 +269,7 @@ static void free(void *where)
73803 malloc_ptr = free_mem_ptr;
73804 }
73805 #else
73806 -#define malloc(a) kmalloc(a, GFP_KERNEL)
73807 +#define malloc(a) kmalloc((a), GFP_KERNEL)
73808 #define free(a) kfree(a)
73809 #endif
73810
73811 diff --git a/lib/ioremap.c b/lib/ioremap.c
73812 index 0c9216c..863bd89 100644
73813 --- a/lib/ioremap.c
73814 +++ b/lib/ioremap.c
73815 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
73816 unsigned long next;
73817
73818 phys_addr -= addr;
73819 - pmd = pmd_alloc(&init_mm, pud, addr);
73820 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
73821 if (!pmd)
73822 return -ENOMEM;
73823 do {
73824 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
73825 unsigned long next;
73826
73827 phys_addr -= addr;
73828 - pud = pud_alloc(&init_mm, pgd, addr);
73829 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
73830 if (!pud)
73831 return -ENOMEM;
73832 do {
73833 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
73834 index bd2bea9..6b3c95e 100644
73835 --- a/lib/is_single_threaded.c
73836 +++ b/lib/is_single_threaded.c
73837 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
73838 struct task_struct *p, *t;
73839 bool ret;
73840
73841 + if (!mm)
73842 + return true;
73843 +
73844 if (atomic_read(&task->signal->live) != 1)
73845 return false;
73846
73847 diff --git a/lib/list_debug.c b/lib/list_debug.c
73848 index c24c2f7..3fc5da0 100644
73849 --- a/lib/list_debug.c
73850 +++ b/lib/list_debug.c
73851 @@ -11,7 +11,9 @@
73852 #include <linux/bug.h>
73853 #include <linux/kernel.h>
73854 #include <linux/rculist.h>
73855 +#include <linux/mm.h>
73856
73857 +#ifdef CONFIG_DEBUG_LIST
73858 /*
73859 * Insert a new entry between two known consecutive entries.
73860 *
73861 @@ -19,21 +21,32 @@
73862 * the prev/next entries already!
73863 */
73864
73865 -void __list_add(struct list_head *new,
73866 - struct list_head *prev,
73867 - struct list_head *next)
73868 +static bool __list_add_debug(struct list_head *new,
73869 + struct list_head *prev,
73870 + struct list_head *next)
73871 {
73872 - WARN(next->prev != prev,
73873 + if (WARN(next->prev != prev,
73874 "list_add corruption. next->prev should be "
73875 "prev (%p), but was %p. (next=%p).\n",
73876 - prev, next->prev, next);
73877 - WARN(prev->next != next,
73878 + prev, next->prev, next) ||
73879 + WARN(prev->next != next,
73880 "list_add corruption. prev->next should be "
73881 "next (%p), but was %p. (prev=%p).\n",
73882 - next, prev->next, prev);
73883 - WARN(new == prev || new == next,
73884 + next, prev->next, prev) ||
73885 + WARN(new == prev || new == next,
73886 "list_add double add: new=%p, prev=%p, next=%p.\n",
73887 - new, prev, next);
73888 + new, prev, next))
73889 + return false;
73890 + return true;
73891 +}
73892 +
73893 +void __list_add(struct list_head *new,
73894 + struct list_head *prev,
73895 + struct list_head *next)
73896 +{
73897 + if (!__list_add_debug(new, prev, next))
73898 + return;
73899 +
73900 next->prev = new;
73901 new->next = next;
73902 new->prev = prev;
73903 @@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
73904 }
73905 EXPORT_SYMBOL(__list_add);
73906
73907 -void __list_del_entry(struct list_head *entry)
73908 +static bool __list_del_entry_debug(struct list_head *entry)
73909 {
73910 struct list_head *prev, *next;
73911
73912 @@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
73913 WARN(next->prev != entry,
73914 "list_del corruption. next->prev should be %p, "
73915 "but was %p\n", entry, next->prev))
73916 + return false;
73917 + return true;
73918 +}
73919 +
73920 +void __list_del_entry(struct list_head *entry)
73921 +{
73922 + if (!__list_del_entry_debug(entry))
73923 return;
73924
73925 - __list_del(prev, next);
73926 + __list_del(entry->prev, entry->next);
73927 }
73928 EXPORT_SYMBOL(__list_del_entry);
73929
73930 @@ -86,15 +106,54 @@ EXPORT_SYMBOL(list_del);
73931 void __list_add_rcu(struct list_head *new,
73932 struct list_head *prev, struct list_head *next)
73933 {
73934 - WARN(next->prev != prev,
73935 + if (WARN(next->prev != prev,
73936 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
73937 - prev, next->prev, next);
73938 - WARN(prev->next != next,
73939 + prev, next->prev, next) ||
73940 + WARN(prev->next != next,
73941 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
73942 - next, prev->next, prev);
73943 + next, prev->next, prev))
73944 + return;
73945 +
73946 new->next = next;
73947 new->prev = prev;
73948 rcu_assign_pointer(list_next_rcu(prev), new);
73949 next->prev = new;
73950 }
73951 EXPORT_SYMBOL(__list_add_rcu);
73952 +#endif
73953 +
73954 +void pax_list_add_tail(struct list_head *new, struct list_head *head)
73955 +{
73956 + struct list_head *prev, *next;
73957 +
73958 + prev = head->prev;
73959 + next = head;
73960 +
73961 +#ifdef CONFIG_DEBUG_LIST
73962 + if (!__list_add_debug(new, prev, next))
73963 + return;
73964 +#endif
73965 +
73966 + pax_open_kernel();
73967 + next->prev = new;
73968 + new->next = next;
73969 + new->prev = prev;
73970 + prev->next = new;
73971 + pax_close_kernel();
73972 +}
73973 +EXPORT_SYMBOL(pax_list_add_tail);
73974 +
73975 +void pax_list_del(struct list_head *entry)
73976 +{
73977 +#ifdef CONFIG_DEBUG_LIST
73978 + if (!__list_del_entry_debug(entry))
73979 + return;
73980 +#endif
73981 +
73982 + pax_open_kernel();
73983 + __list_del(entry->prev, entry->next);
73984 + entry->next = LIST_POISON1;
73985 + entry->prev = LIST_POISON2;
73986 + pax_close_kernel();
73987 +}
73988 +EXPORT_SYMBOL(pax_list_del);
73989 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
73990 index e796429..6e38f9f 100644
73991 --- a/lib/radix-tree.c
73992 +++ b/lib/radix-tree.c
73993 @@ -92,7 +92,7 @@ struct radix_tree_preload {
73994 int nr;
73995 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
73996 };
73997 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
73998 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
73999
74000 static inline void *ptr_to_indirect(void *ptr)
74001 {
74002 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
74003 index bb2b201..46abaf9 100644
74004 --- a/lib/strncpy_from_user.c
74005 +++ b/lib/strncpy_from_user.c
74006 @@ -21,7 +21,7 @@
74007 */
74008 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
74009 {
74010 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
74011 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
74012 long res = 0;
74013
74014 /*
74015 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
74016 index a28df52..3d55877 100644
74017 --- a/lib/strnlen_user.c
74018 +++ b/lib/strnlen_user.c
74019 @@ -26,7 +26,7 @@
74020 */
74021 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
74022 {
74023 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
74024 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
74025 long align, res = 0;
74026 unsigned long c;
74027
74028 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
74029 index 39c99fe..18f060b 100644
74030 --- a/lib/vsprintf.c
74031 +++ b/lib/vsprintf.c
74032 @@ -16,6 +16,9 @@
74033 * - scnprintf and vscnprintf
74034 */
74035
74036 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74037 +#define __INCLUDED_BY_HIDESYM 1
74038 +#endif
74039 #include <stdarg.h>
74040 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
74041 #include <linux/types.h>
74042 @@ -533,7 +536,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
74043 char sym[KSYM_SYMBOL_LEN];
74044 if (ext == 'B')
74045 sprint_backtrace(sym, value);
74046 - else if (ext != 'f' && ext != 's')
74047 + else if (ext != 'f' && ext != 's' && ext != 'a')
74048 sprint_symbol(sym, value);
74049 else
74050 sprint_symbol_no_offset(sym, value);
74051 @@ -966,7 +969,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
74052 return number(buf, end, *(const netdev_features_t *)addr, spec);
74053 }
74054
74055 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74056 +int kptr_restrict __read_mostly = 2;
74057 +#else
74058 int kptr_restrict __read_mostly;
74059 +#endif
74060
74061 /*
74062 * Show a '%p' thing. A kernel extension is that the '%p' is followed
74063 @@ -980,6 +987,8 @@ int kptr_restrict __read_mostly;
74064 * - 'S' For symbolic direct pointers with offset
74065 * - 's' For symbolic direct pointers without offset
74066 * - 'B' For backtraced symbolic direct pointers with offset
74067 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
74068 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
74069 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
74070 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
74071 * - 'M' For a 6-byte MAC address, it prints the address in the
74072 @@ -1035,12 +1044,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74073
74074 if (!ptr && *fmt != 'K') {
74075 /*
74076 - * Print (null) with the same width as a pointer so it makes
74077 + * Print (nil) with the same width as a pointer so it makes
74078 * tabular output look nice.
74079 */
74080 if (spec.field_width == -1)
74081 spec.field_width = default_width;
74082 - return string(buf, end, "(null)", spec);
74083 + return string(buf, end, "(nil)", spec);
74084 }
74085
74086 switch (*fmt) {
74087 @@ -1050,6 +1059,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74088 /* Fallthrough */
74089 case 'S':
74090 case 's':
74091 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74092 + break;
74093 +#else
74094 + return symbol_string(buf, end, ptr, spec, *fmt);
74095 +#endif
74096 + case 'A':
74097 + case 'a':
74098 case 'B':
74099 return symbol_string(buf, end, ptr, spec, *fmt);
74100 case 'R':
74101 @@ -1090,6 +1106,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74102 va_end(va);
74103 return buf;
74104 }
74105 + case 'P':
74106 + break;
74107 case 'K':
74108 /*
74109 * %pK cannot be used in IRQ context because its test
74110 @@ -1113,6 +1131,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
74111 }
74112 break;
74113 }
74114 +
74115 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74116 + /* 'P' = approved pointers to copy to userland,
74117 + as in the /proc/kallsyms case, as we make it display nothing
74118 + for non-root users, and the real contents for root users
74119 + Also ignore 'K' pointers, since we force their NULLing for non-root users
74120 + above
74121 + */
74122 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
74123 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
74124 + dump_stack();
74125 + ptr = NULL;
74126 + }
74127 +#endif
74128 +
74129 spec.flags |= SMALL;
74130 if (spec.field_width == -1) {
74131 spec.field_width = default_width;
74132 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
74133 typeof(type) value; \
74134 if (sizeof(type) == 8) { \
74135 args = PTR_ALIGN(args, sizeof(u32)); \
74136 - *(u32 *)&value = *(u32 *)args; \
74137 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
74138 + *(u32 *)&value = *(const u32 *)args; \
74139 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
74140 } else { \
74141 args = PTR_ALIGN(args, sizeof(type)); \
74142 - value = *(typeof(type) *)args; \
74143 + value = *(const typeof(type) *)args; \
74144 } \
74145 args += sizeof(type); \
74146 value; \
74147 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
74148 case FORMAT_TYPE_STR: {
74149 const char *str_arg = args;
74150 args += strlen(str_arg) + 1;
74151 - str = string(str, end, (char *)str_arg, spec);
74152 + str = string(str, end, str_arg, spec);
74153 break;
74154 }
74155
74156 diff --git a/localversion-grsec b/localversion-grsec
74157 new file mode 100644
74158 index 0000000..7cd6065
74159 --- /dev/null
74160 +++ b/localversion-grsec
74161 @@ -0,0 +1 @@
74162 +-grsec
74163 diff --git a/mm/Kconfig b/mm/Kconfig
74164 index a3f8ddd..f31e92e 100644
74165 --- a/mm/Kconfig
74166 +++ b/mm/Kconfig
74167 @@ -252,10 +252,10 @@ config KSM
74168 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
74169
74170 config DEFAULT_MMAP_MIN_ADDR
74171 - int "Low address space to protect from user allocation"
74172 + int "Low address space to protect from user allocation"
74173 depends on MMU
74174 - default 4096
74175 - help
74176 + default 65536
74177 + help
74178 This is the portion of low virtual memory which should be protected
74179 from userspace allocation. Keeping a user from writing to low pages
74180 can help reduce the impact of kernel NULL pointer bugs.
74181 @@ -286,7 +286,7 @@ config MEMORY_FAILURE
74182
74183 config HWPOISON_INJECT
74184 tristate "HWPoison pages injector"
74185 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
74186 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
74187 select PROC_PAGE_MONITOR
74188
74189 config NOMMU_INITIAL_TRIM_EXCESS
74190 diff --git a/mm/filemap.c b/mm/filemap.c
74191 index 83efee7..3f99381 100644
74192 --- a/mm/filemap.c
74193 +++ b/mm/filemap.c
74194 @@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
74195 struct address_space *mapping = file->f_mapping;
74196
74197 if (!mapping->a_ops->readpage)
74198 - return -ENOEXEC;
74199 + return -ENODEV;
74200 file_accessed(file);
74201 vma->vm_ops = &generic_file_vm_ops;
74202 return 0;
74203 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
74204 *pos = i_size_read(inode);
74205
74206 if (limit != RLIM_INFINITY) {
74207 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
74208 if (*pos >= limit) {
74209 send_sig(SIGXFSZ, current, 0);
74210 return -EFBIG;
74211 diff --git a/mm/fremap.c b/mm/fremap.c
74212 index a0aaf0e..20325c3 100644
74213 --- a/mm/fremap.c
74214 +++ b/mm/fremap.c
74215 @@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
74216 retry:
74217 vma = find_vma(mm, start);
74218
74219 +#ifdef CONFIG_PAX_SEGMEXEC
74220 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
74221 + goto out;
74222 +#endif
74223 +
74224 /*
74225 * Make sure the vma is shared, that it supports prefaulting,
74226 * and that the remapped range is valid and fully within
74227 diff --git a/mm/highmem.c b/mm/highmem.c
74228 index 09fc744..3936897 100644
74229 --- a/mm/highmem.c
74230 +++ b/mm/highmem.c
74231 @@ -138,9 +138,10 @@ static void flush_all_zero_pkmaps(void)
74232 * So no dangers, even with speculative execution.
74233 */
74234 page = pte_page(pkmap_page_table[i]);
74235 + pax_open_kernel();
74236 pte_clear(&init_mm, (unsigned long)page_address(page),
74237 &pkmap_page_table[i]);
74238 -
74239 + pax_close_kernel();
74240 set_page_address(page, NULL);
74241 need_flush = 1;
74242 }
74243 @@ -199,9 +200,11 @@ start:
74244 }
74245 }
74246 vaddr = PKMAP_ADDR(last_pkmap_nr);
74247 +
74248 + pax_open_kernel();
74249 set_pte_at(&init_mm, vaddr,
74250 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
74251 -
74252 + pax_close_kernel();
74253 pkmap_count[last_pkmap_nr] = 1;
74254 set_page_address(page, (void *)vaddr);
74255
74256 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
74257 index 40f17c3..c1cc011 100644
74258 --- a/mm/huge_memory.c
74259 +++ b/mm/huge_memory.c
74260 @@ -710,7 +710,7 @@ out:
74261 * run pte_offset_map on the pmd, if an huge pmd could
74262 * materialize from under us from a different thread.
74263 */
74264 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
74265 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
74266 return VM_FAULT_OOM;
74267 /* if an huge pmd materialized from under us just retry later */
74268 if (unlikely(pmd_trans_huge(*pmd)))
74269 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
74270 index b969ed4..10e3e37 100644
74271 --- a/mm/hugetlb.c
74272 +++ b/mm/hugetlb.c
74273 @@ -2509,6 +2509,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
74274 return 1;
74275 }
74276
74277 +#ifdef CONFIG_PAX_SEGMEXEC
74278 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
74279 +{
74280 + struct mm_struct *mm = vma->vm_mm;
74281 + struct vm_area_struct *vma_m;
74282 + unsigned long address_m;
74283 + pte_t *ptep_m;
74284 +
74285 + vma_m = pax_find_mirror_vma(vma);
74286 + if (!vma_m)
74287 + return;
74288 +
74289 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74290 + address_m = address + SEGMEXEC_TASK_SIZE;
74291 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
74292 + get_page(page_m);
74293 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
74294 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
74295 +}
74296 +#endif
74297 +
74298 /*
74299 * Hugetlb_cow() should be called with page lock of the original hugepage held.
74300 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
74301 @@ -2627,6 +2648,11 @@ retry_avoidcopy:
74302 make_huge_pte(vma, new_page, 1));
74303 page_remove_rmap(old_page);
74304 hugepage_add_new_anon_rmap(new_page, vma, address);
74305 +
74306 +#ifdef CONFIG_PAX_SEGMEXEC
74307 + pax_mirror_huge_pte(vma, address, new_page);
74308 +#endif
74309 +
74310 /* Make the old page be freed below */
74311 new_page = old_page;
74312 }
74313 @@ -2786,6 +2812,10 @@ retry:
74314 && (vma->vm_flags & VM_SHARED)));
74315 set_huge_pte_at(mm, address, ptep, new_pte);
74316
74317 +#ifdef CONFIG_PAX_SEGMEXEC
74318 + pax_mirror_huge_pte(vma, address, page);
74319 +#endif
74320 +
74321 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
74322 /* Optimization, do the COW without a second fault */
74323 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
74324 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74325 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
74326 struct hstate *h = hstate_vma(vma);
74327
74328 +#ifdef CONFIG_PAX_SEGMEXEC
74329 + struct vm_area_struct *vma_m;
74330 +#endif
74331 +
74332 address &= huge_page_mask(h);
74333
74334 ptep = huge_pte_offset(mm, address);
74335 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74336 VM_FAULT_SET_HINDEX(hstate_index(h));
74337 }
74338
74339 +#ifdef CONFIG_PAX_SEGMEXEC
74340 + vma_m = pax_find_mirror_vma(vma);
74341 + if (vma_m) {
74342 + unsigned long address_m;
74343 +
74344 + if (vma->vm_start > vma_m->vm_start) {
74345 + address_m = address;
74346 + address -= SEGMEXEC_TASK_SIZE;
74347 + vma = vma_m;
74348 + h = hstate_vma(vma);
74349 + } else
74350 + address_m = address + SEGMEXEC_TASK_SIZE;
74351 +
74352 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
74353 + return VM_FAULT_OOM;
74354 + address_m &= HPAGE_MASK;
74355 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
74356 + }
74357 +#endif
74358 +
74359 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
74360 if (!ptep)
74361 return VM_FAULT_OOM;
74362 diff --git a/mm/internal.h b/mm/internal.h
74363 index 3c5197d..08d0065 100644
74364 --- a/mm/internal.h
74365 +++ b/mm/internal.h
74366 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
74367 * in mm/page_alloc.c
74368 */
74369 extern void __free_pages_bootmem(struct page *page, unsigned int order);
74370 +extern void free_compound_page(struct page *page);
74371 extern void prep_compound_page(struct page *page, unsigned long order);
74372 #ifdef CONFIG_MEMORY_FAILURE
74373 extern bool is_free_buddy_page(struct page *page);
74374 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
74375 index a217cc5..44b2b35 100644
74376 --- a/mm/kmemleak.c
74377 +++ b/mm/kmemleak.c
74378 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
74379
74380 for (i = 0; i < object->trace_len; i++) {
74381 void *ptr = (void *)object->trace[i];
74382 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
74383 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
74384 }
74385 }
74386
74387 @@ -1852,7 +1852,7 @@ static int __init kmemleak_late_init(void)
74388 return -ENOMEM;
74389 }
74390
74391 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
74392 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
74393 &kmemleak_fops);
74394 if (!dentry)
74395 pr_warning("Failed to create the debugfs kmemleak file\n");
74396 diff --git a/mm/maccess.c b/mm/maccess.c
74397 index d53adf9..03a24bf 100644
74398 --- a/mm/maccess.c
74399 +++ b/mm/maccess.c
74400 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
74401 set_fs(KERNEL_DS);
74402 pagefault_disable();
74403 ret = __copy_from_user_inatomic(dst,
74404 - (__force const void __user *)src, size);
74405 + (const void __force_user *)src, size);
74406 pagefault_enable();
74407 set_fs(old_fs);
74408
74409 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
74410
74411 set_fs(KERNEL_DS);
74412 pagefault_disable();
74413 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
74414 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
74415 pagefault_enable();
74416 set_fs(old_fs);
74417
74418 diff --git a/mm/madvise.c b/mm/madvise.c
74419 index 03dfa5c..b032917 100644
74420 --- a/mm/madvise.c
74421 +++ b/mm/madvise.c
74422 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
74423 pgoff_t pgoff;
74424 unsigned long new_flags = vma->vm_flags;
74425
74426 +#ifdef CONFIG_PAX_SEGMEXEC
74427 + struct vm_area_struct *vma_m;
74428 +#endif
74429 +
74430 switch (behavior) {
74431 case MADV_NORMAL:
74432 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
74433 @@ -123,6 +127,13 @@ success:
74434 /*
74435 * vm_flags is protected by the mmap_sem held in write mode.
74436 */
74437 +
74438 +#ifdef CONFIG_PAX_SEGMEXEC
74439 + vma_m = pax_find_mirror_vma(vma);
74440 + if (vma_m)
74441 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
74442 +#endif
74443 +
74444 vma->vm_flags = new_flags;
74445
74446 out:
74447 @@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74448 struct vm_area_struct ** prev,
74449 unsigned long start, unsigned long end)
74450 {
74451 +
74452 +#ifdef CONFIG_PAX_SEGMEXEC
74453 + struct vm_area_struct *vma_m;
74454 +#endif
74455 +
74456 *prev = vma;
74457 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
74458 return -EINVAL;
74459 @@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74460 zap_page_range(vma, start, end - start, &details);
74461 } else
74462 zap_page_range(vma, start, end - start, NULL);
74463 +
74464 +#ifdef CONFIG_PAX_SEGMEXEC
74465 + vma_m = pax_find_mirror_vma(vma);
74466 + if (vma_m) {
74467 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
74468 + struct zap_details details = {
74469 + .nonlinear_vma = vma_m,
74470 + .last_index = ULONG_MAX,
74471 + };
74472 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
74473 + } else
74474 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
74475 + }
74476 +#endif
74477 +
74478 return 0;
74479 }
74480
74481 @@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
74482 if (end < start)
74483 goto out;
74484
74485 +#ifdef CONFIG_PAX_SEGMEXEC
74486 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74487 + if (end > SEGMEXEC_TASK_SIZE)
74488 + goto out;
74489 + } else
74490 +#endif
74491 +
74492 + if (end > TASK_SIZE)
74493 + goto out;
74494 +
74495 error = 0;
74496 if (end == start)
74497 goto out;
74498 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
74499 index 8b20278..05dac18 100644
74500 --- a/mm/memory-failure.c
74501 +++ b/mm/memory-failure.c
74502 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
74503
74504 int sysctl_memory_failure_recovery __read_mostly = 1;
74505
74506 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74507 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74508
74509 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
74510
74511 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
74512 pfn, t->comm, t->pid);
74513 si.si_signo = SIGBUS;
74514 si.si_errno = 0;
74515 - si.si_addr = (void *)addr;
74516 + si.si_addr = (void __user *)addr;
74517 #ifdef __ARCH_SI_TRAPNO
74518 si.si_trapno = trapno;
74519 #endif
74520 @@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74521 }
74522
74523 nr_pages = 1 << compound_trans_order(hpage);
74524 - atomic_long_add(nr_pages, &mce_bad_pages);
74525 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
74526
74527 /*
74528 * We need/can do nothing about count=0 pages.
74529 @@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74530 if (!PageHWPoison(hpage)
74531 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
74532 || (p != hpage && TestSetPageHWPoison(hpage))) {
74533 - atomic_long_sub(nr_pages, &mce_bad_pages);
74534 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74535 return 0;
74536 }
74537 set_page_hwpoison_huge_page(hpage);
74538 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74539 }
74540 if (hwpoison_filter(p)) {
74541 if (TestClearPageHWPoison(p))
74542 - atomic_long_sub(nr_pages, &mce_bad_pages);
74543 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74544 unlock_page(hpage);
74545 put_page(hpage);
74546 return 0;
74547 @@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
74548 return 0;
74549 }
74550 if (TestClearPageHWPoison(p))
74551 - atomic_long_sub(nr_pages, &mce_bad_pages);
74552 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74553 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
74554 return 0;
74555 }
74556 @@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
74557 */
74558 if (TestClearPageHWPoison(page)) {
74559 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
74560 - atomic_long_sub(nr_pages, &mce_bad_pages);
74561 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74562 freeit = 1;
74563 if (PageHuge(page))
74564 clear_page_hwpoison_huge_page(page);
74565 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
74566 }
74567 done:
74568 if (!PageHWPoison(hpage))
74569 - atomic_long_add(1 << compound_trans_order(hpage),
74570 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
74571 &mce_bad_pages);
74572 set_page_hwpoison_huge_page(hpage);
74573 dequeue_hwpoisoned_huge_page(hpage);
74574 @@ -1582,7 +1582,7 @@ int soft_offline_page(struct page *page, int flags)
74575 return ret;
74576
74577 done:
74578 - atomic_long_add(1, &mce_bad_pages);
74579 + atomic_long_add_unchecked(1, &mce_bad_pages);
74580 SetPageHWPoison(page);
74581 /* keep elevated page count for bad page */
74582 return ret;
74583 diff --git a/mm/memory.c b/mm/memory.c
74584 index f2973b2..fd020a7 100644
74585 --- a/mm/memory.c
74586 +++ b/mm/memory.c
74587 @@ -431,6 +431,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74588 free_pte_range(tlb, pmd, addr);
74589 } while (pmd++, addr = next, addr != end);
74590
74591 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
74592 start &= PUD_MASK;
74593 if (start < floor)
74594 return;
74595 @@ -445,6 +446,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74596 pmd = pmd_offset(pud, start);
74597 pud_clear(pud);
74598 pmd_free_tlb(tlb, pmd, start);
74599 +#endif
74600 +
74601 }
74602
74603 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74604 @@ -464,6 +467,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74605 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
74606 } while (pud++, addr = next, addr != end);
74607
74608 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
74609 start &= PGDIR_MASK;
74610 if (start < floor)
74611 return;
74612 @@ -478,6 +482,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74613 pud = pud_offset(pgd, start);
74614 pgd_clear(pgd);
74615 pud_free_tlb(tlb, pud, start);
74616 +#endif
74617 +
74618 }
74619
74620 /*
74621 @@ -1626,12 +1632,6 @@ no_page_table:
74622 return page;
74623 }
74624
74625 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
74626 -{
74627 - return stack_guard_page_start(vma, addr) ||
74628 - stack_guard_page_end(vma, addr+PAGE_SIZE);
74629 -}
74630 -
74631 /**
74632 * __get_user_pages() - pin user pages in memory
74633 * @tsk: task_struct of target task
74634 @@ -1704,10 +1704,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74635 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
74636 i = 0;
74637
74638 - do {
74639 + while (nr_pages) {
74640 struct vm_area_struct *vma;
74641
74642 - vma = find_extend_vma(mm, start);
74643 + vma = find_vma(mm, start);
74644 if (!vma && in_gate_area(mm, start)) {
74645 unsigned long pg = start & PAGE_MASK;
74646 pgd_t *pgd;
74647 @@ -1755,7 +1755,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74648 goto next_page;
74649 }
74650
74651 - if (!vma ||
74652 + if (!vma || start < vma->vm_start ||
74653 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
74654 !(vm_flags & vma->vm_flags))
74655 return i ? : -EFAULT;
74656 @@ -1782,11 +1782,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74657 int ret;
74658 unsigned int fault_flags = 0;
74659
74660 - /* For mlock, just skip the stack guard page. */
74661 - if (foll_flags & FOLL_MLOCK) {
74662 - if (stack_guard_page(vma, start))
74663 - goto next_page;
74664 - }
74665 if (foll_flags & FOLL_WRITE)
74666 fault_flags |= FAULT_FLAG_WRITE;
74667 if (nonblocking)
74668 @@ -1860,7 +1855,7 @@ next_page:
74669 start += PAGE_SIZE;
74670 nr_pages--;
74671 } while (nr_pages && start < vma->vm_end);
74672 - } while (nr_pages);
74673 + }
74674 return i;
74675 }
74676 EXPORT_SYMBOL(__get_user_pages);
74677 @@ -2067,6 +2062,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
74678 page_add_file_rmap(page);
74679 set_pte_at(mm, addr, pte, mk_pte(page, prot));
74680
74681 +#ifdef CONFIG_PAX_SEGMEXEC
74682 + pax_mirror_file_pte(vma, addr, page, ptl);
74683 +#endif
74684 +
74685 retval = 0;
74686 pte_unmap_unlock(pte, ptl);
74687 return retval;
74688 @@ -2111,9 +2110,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
74689 if (!page_count(page))
74690 return -EINVAL;
74691 if (!(vma->vm_flags & VM_MIXEDMAP)) {
74692 +
74693 +#ifdef CONFIG_PAX_SEGMEXEC
74694 + struct vm_area_struct *vma_m;
74695 +#endif
74696 +
74697 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
74698 BUG_ON(vma->vm_flags & VM_PFNMAP);
74699 vma->vm_flags |= VM_MIXEDMAP;
74700 +
74701 +#ifdef CONFIG_PAX_SEGMEXEC
74702 + vma_m = pax_find_mirror_vma(vma);
74703 + if (vma_m)
74704 + vma_m->vm_flags |= VM_MIXEDMAP;
74705 +#endif
74706 +
74707 }
74708 return insert_page(vma, addr, page, vma->vm_page_prot);
74709 }
74710 @@ -2196,6 +2207,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
74711 unsigned long pfn)
74712 {
74713 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
74714 + BUG_ON(vma->vm_mirror);
74715
74716 if (addr < vma->vm_start || addr >= vma->vm_end)
74717 return -EFAULT;
74718 @@ -2396,7 +2408,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
74719
74720 BUG_ON(pud_huge(*pud));
74721
74722 - pmd = pmd_alloc(mm, pud, addr);
74723 + pmd = (mm == &init_mm) ?
74724 + pmd_alloc_kernel(mm, pud, addr) :
74725 + pmd_alloc(mm, pud, addr);
74726 if (!pmd)
74727 return -ENOMEM;
74728 do {
74729 @@ -2416,7 +2430,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
74730 unsigned long next;
74731 int err;
74732
74733 - pud = pud_alloc(mm, pgd, addr);
74734 + pud = (mm == &init_mm) ?
74735 + pud_alloc_kernel(mm, pgd, addr) :
74736 + pud_alloc(mm, pgd, addr);
74737 if (!pud)
74738 return -ENOMEM;
74739 do {
74740 @@ -2504,6 +2520,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
74741 copy_user_highpage(dst, src, va, vma);
74742 }
74743
74744 +#ifdef CONFIG_PAX_SEGMEXEC
74745 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
74746 +{
74747 + struct mm_struct *mm = vma->vm_mm;
74748 + spinlock_t *ptl;
74749 + pte_t *pte, entry;
74750 +
74751 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
74752 + entry = *pte;
74753 + if (!pte_present(entry)) {
74754 + if (!pte_none(entry)) {
74755 + BUG_ON(pte_file(entry));
74756 + free_swap_and_cache(pte_to_swp_entry(entry));
74757 + pte_clear_not_present_full(mm, address, pte, 0);
74758 + }
74759 + } else {
74760 + struct page *page;
74761 +
74762 + flush_cache_page(vma, address, pte_pfn(entry));
74763 + entry = ptep_clear_flush(vma, address, pte);
74764 + BUG_ON(pte_dirty(entry));
74765 + page = vm_normal_page(vma, address, entry);
74766 + if (page) {
74767 + update_hiwater_rss(mm);
74768 + if (PageAnon(page))
74769 + dec_mm_counter_fast(mm, MM_ANONPAGES);
74770 + else
74771 + dec_mm_counter_fast(mm, MM_FILEPAGES);
74772 + page_remove_rmap(page);
74773 + page_cache_release(page);
74774 + }
74775 + }
74776 + pte_unmap_unlock(pte, ptl);
74777 +}
74778 +
74779 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
74780 + *
74781 + * the ptl of the lower mapped page is held on entry and is not released on exit
74782 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
74783 + */
74784 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74785 +{
74786 + struct mm_struct *mm = vma->vm_mm;
74787 + unsigned long address_m;
74788 + spinlock_t *ptl_m;
74789 + struct vm_area_struct *vma_m;
74790 + pmd_t *pmd_m;
74791 + pte_t *pte_m, entry_m;
74792 +
74793 + BUG_ON(!page_m || !PageAnon(page_m));
74794 +
74795 + vma_m = pax_find_mirror_vma(vma);
74796 + if (!vma_m)
74797 + return;
74798 +
74799 + BUG_ON(!PageLocked(page_m));
74800 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74801 + address_m = address + SEGMEXEC_TASK_SIZE;
74802 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74803 + pte_m = pte_offset_map(pmd_m, address_m);
74804 + ptl_m = pte_lockptr(mm, pmd_m);
74805 + if (ptl != ptl_m) {
74806 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74807 + if (!pte_none(*pte_m))
74808 + goto out;
74809 + }
74810 +
74811 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74812 + page_cache_get(page_m);
74813 + page_add_anon_rmap(page_m, vma_m, address_m);
74814 + inc_mm_counter_fast(mm, MM_ANONPAGES);
74815 + set_pte_at(mm, address_m, pte_m, entry_m);
74816 + update_mmu_cache(vma_m, address_m, entry_m);
74817 +out:
74818 + if (ptl != ptl_m)
74819 + spin_unlock(ptl_m);
74820 + pte_unmap(pte_m);
74821 + unlock_page(page_m);
74822 +}
74823 +
74824 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74825 +{
74826 + struct mm_struct *mm = vma->vm_mm;
74827 + unsigned long address_m;
74828 + spinlock_t *ptl_m;
74829 + struct vm_area_struct *vma_m;
74830 + pmd_t *pmd_m;
74831 + pte_t *pte_m, entry_m;
74832 +
74833 + BUG_ON(!page_m || PageAnon(page_m));
74834 +
74835 + vma_m = pax_find_mirror_vma(vma);
74836 + if (!vma_m)
74837 + return;
74838 +
74839 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74840 + address_m = address + SEGMEXEC_TASK_SIZE;
74841 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74842 + pte_m = pte_offset_map(pmd_m, address_m);
74843 + ptl_m = pte_lockptr(mm, pmd_m);
74844 + if (ptl != ptl_m) {
74845 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74846 + if (!pte_none(*pte_m))
74847 + goto out;
74848 + }
74849 +
74850 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74851 + page_cache_get(page_m);
74852 + page_add_file_rmap(page_m);
74853 + inc_mm_counter_fast(mm, MM_FILEPAGES);
74854 + set_pte_at(mm, address_m, pte_m, entry_m);
74855 + update_mmu_cache(vma_m, address_m, entry_m);
74856 +out:
74857 + if (ptl != ptl_m)
74858 + spin_unlock(ptl_m);
74859 + pte_unmap(pte_m);
74860 +}
74861 +
74862 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
74863 +{
74864 + struct mm_struct *mm = vma->vm_mm;
74865 + unsigned long address_m;
74866 + spinlock_t *ptl_m;
74867 + struct vm_area_struct *vma_m;
74868 + pmd_t *pmd_m;
74869 + pte_t *pte_m, entry_m;
74870 +
74871 + vma_m = pax_find_mirror_vma(vma);
74872 + if (!vma_m)
74873 + return;
74874 +
74875 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74876 + address_m = address + SEGMEXEC_TASK_SIZE;
74877 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74878 + pte_m = pte_offset_map(pmd_m, address_m);
74879 + ptl_m = pte_lockptr(mm, pmd_m);
74880 + if (ptl != ptl_m) {
74881 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74882 + if (!pte_none(*pte_m))
74883 + goto out;
74884 + }
74885 +
74886 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
74887 + set_pte_at(mm, address_m, pte_m, entry_m);
74888 +out:
74889 + if (ptl != ptl_m)
74890 + spin_unlock(ptl_m);
74891 + pte_unmap(pte_m);
74892 +}
74893 +
74894 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
74895 +{
74896 + struct page *page_m;
74897 + pte_t entry;
74898 +
74899 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
74900 + goto out;
74901 +
74902 + entry = *pte;
74903 + page_m = vm_normal_page(vma, address, entry);
74904 + if (!page_m)
74905 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
74906 + else if (PageAnon(page_m)) {
74907 + if (pax_find_mirror_vma(vma)) {
74908 + pte_unmap_unlock(pte, ptl);
74909 + lock_page(page_m);
74910 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
74911 + if (pte_same(entry, *pte))
74912 + pax_mirror_anon_pte(vma, address, page_m, ptl);
74913 + else
74914 + unlock_page(page_m);
74915 + }
74916 + } else
74917 + pax_mirror_file_pte(vma, address, page_m, ptl);
74918 +
74919 +out:
74920 + pte_unmap_unlock(pte, ptl);
74921 +}
74922 +#endif
74923 +
74924 /*
74925 * This routine handles present pages, when users try to write
74926 * to a shared page. It is done by copying the page to a new address
74927 @@ -2720,6 +2916,12 @@ gotten:
74928 */
74929 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74930 if (likely(pte_same(*page_table, orig_pte))) {
74931 +
74932 +#ifdef CONFIG_PAX_SEGMEXEC
74933 + if (pax_find_mirror_vma(vma))
74934 + BUG_ON(!trylock_page(new_page));
74935 +#endif
74936 +
74937 if (old_page) {
74938 if (!PageAnon(old_page)) {
74939 dec_mm_counter_fast(mm, MM_FILEPAGES);
74940 @@ -2771,6 +2973,10 @@ gotten:
74941 page_remove_rmap(old_page);
74942 }
74943
74944 +#ifdef CONFIG_PAX_SEGMEXEC
74945 + pax_mirror_anon_pte(vma, address, new_page, ptl);
74946 +#endif
74947 +
74948 /* Free the old page.. */
74949 new_page = old_page;
74950 ret |= VM_FAULT_WRITE;
74951 @@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74952 swap_free(entry);
74953 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
74954 try_to_free_swap(page);
74955 +
74956 +#ifdef CONFIG_PAX_SEGMEXEC
74957 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
74958 +#endif
74959 +
74960 unlock_page(page);
74961 if (swapcache) {
74962 /*
74963 @@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74964
74965 /* No need to invalidate - it was non-present before */
74966 update_mmu_cache(vma, address, page_table);
74967 +
74968 +#ifdef CONFIG_PAX_SEGMEXEC
74969 + pax_mirror_anon_pte(vma, address, page, ptl);
74970 +#endif
74971 +
74972 unlock:
74973 pte_unmap_unlock(page_table, ptl);
74974 out:
74975 @@ -3093,40 +3309,6 @@ out_release:
74976 }
74977
74978 /*
74979 - * This is like a special single-page "expand_{down|up}wards()",
74980 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
74981 - * doesn't hit another vma.
74982 - */
74983 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
74984 -{
74985 - address &= PAGE_MASK;
74986 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
74987 - struct vm_area_struct *prev = vma->vm_prev;
74988 -
74989 - /*
74990 - * Is there a mapping abutting this one below?
74991 - *
74992 - * That's only ok if it's the same stack mapping
74993 - * that has gotten split..
74994 - */
74995 - if (prev && prev->vm_end == address)
74996 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
74997 -
74998 - expand_downwards(vma, address - PAGE_SIZE);
74999 - }
75000 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
75001 - struct vm_area_struct *next = vma->vm_next;
75002 -
75003 - /* As VM_GROWSDOWN but s/below/above/ */
75004 - if (next && next->vm_start == address + PAGE_SIZE)
75005 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
75006 -
75007 - expand_upwards(vma, address + PAGE_SIZE);
75008 - }
75009 - return 0;
75010 -}
75011 -
75012 -/*
75013 * We enter with non-exclusive mmap_sem (to exclude vma changes,
75014 * but allow concurrent faults), and pte mapped but not yet locked.
75015 * We return with mmap_sem still held, but pte unmapped and unlocked.
75016 @@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
75017 unsigned long address, pte_t *page_table, pmd_t *pmd,
75018 unsigned int flags)
75019 {
75020 - struct page *page;
75021 + struct page *page = NULL;
75022 spinlock_t *ptl;
75023 pte_t entry;
75024
75025 - pte_unmap(page_table);
75026 -
75027 - /* Check if we need to add a guard page to the stack */
75028 - if (check_stack_guard_page(vma, address) < 0)
75029 - return VM_FAULT_SIGBUS;
75030 -
75031 - /* Use the zero-page for reads */
75032 if (!(flags & FAULT_FLAG_WRITE)) {
75033 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
75034 vma->vm_page_prot));
75035 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
75036 + ptl = pte_lockptr(mm, pmd);
75037 + spin_lock(ptl);
75038 if (!pte_none(*page_table))
75039 goto unlock;
75040 goto setpte;
75041 }
75042
75043 /* Allocate our own private page. */
75044 + pte_unmap(page_table);
75045 +
75046 if (unlikely(anon_vma_prepare(vma)))
75047 goto oom;
75048 page = alloc_zeroed_user_highpage_movable(vma, address);
75049 @@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
75050 if (!pte_none(*page_table))
75051 goto release;
75052
75053 +#ifdef CONFIG_PAX_SEGMEXEC
75054 + if (pax_find_mirror_vma(vma))
75055 + BUG_ON(!trylock_page(page));
75056 +#endif
75057 +
75058 inc_mm_counter_fast(mm, MM_ANONPAGES);
75059 page_add_new_anon_rmap(page, vma, address);
75060 setpte:
75061 @@ -3181,6 +3364,12 @@ setpte:
75062
75063 /* No need to invalidate - it was non-present before */
75064 update_mmu_cache(vma, address, page_table);
75065 +
75066 +#ifdef CONFIG_PAX_SEGMEXEC
75067 + if (page)
75068 + pax_mirror_anon_pte(vma, address, page, ptl);
75069 +#endif
75070 +
75071 unlock:
75072 pte_unmap_unlock(page_table, ptl);
75073 return 0;
75074 @@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75075 */
75076 /* Only go through if we didn't race with anybody else... */
75077 if (likely(pte_same(*page_table, orig_pte))) {
75078 +
75079 +#ifdef CONFIG_PAX_SEGMEXEC
75080 + if (anon && pax_find_mirror_vma(vma))
75081 + BUG_ON(!trylock_page(page));
75082 +#endif
75083 +
75084 flush_icache_page(vma, page);
75085 entry = mk_pte(page, vma->vm_page_prot);
75086 if (flags & FAULT_FLAG_WRITE)
75087 @@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75088
75089 /* no need to invalidate: a not-present page won't be cached */
75090 update_mmu_cache(vma, address, page_table);
75091 +
75092 +#ifdef CONFIG_PAX_SEGMEXEC
75093 + if (anon)
75094 + pax_mirror_anon_pte(vma, address, page, ptl);
75095 + else
75096 + pax_mirror_file_pte(vma, address, page, ptl);
75097 +#endif
75098 +
75099 } else {
75100 if (cow_page)
75101 mem_cgroup_uncharge_page(cow_page);
75102 @@ -3497,6 +3700,12 @@ int handle_pte_fault(struct mm_struct *mm,
75103 if (flags & FAULT_FLAG_WRITE)
75104 flush_tlb_fix_spurious_fault(vma, address);
75105 }
75106 +
75107 +#ifdef CONFIG_PAX_SEGMEXEC
75108 + pax_mirror_pte(vma, address, pte, pmd, ptl);
75109 + return 0;
75110 +#endif
75111 +
75112 unlock:
75113 pte_unmap_unlock(pte, ptl);
75114 return 0;
75115 @@ -3513,6 +3722,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75116 pmd_t *pmd;
75117 pte_t *pte;
75118
75119 +#ifdef CONFIG_PAX_SEGMEXEC
75120 + struct vm_area_struct *vma_m;
75121 +#endif
75122 +
75123 __set_current_state(TASK_RUNNING);
75124
75125 count_vm_event(PGFAULT);
75126 @@ -3524,6 +3737,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75127 if (unlikely(is_vm_hugetlb_page(vma)))
75128 return hugetlb_fault(mm, vma, address, flags);
75129
75130 +#ifdef CONFIG_PAX_SEGMEXEC
75131 + vma_m = pax_find_mirror_vma(vma);
75132 + if (vma_m) {
75133 + unsigned long address_m;
75134 + pgd_t *pgd_m;
75135 + pud_t *pud_m;
75136 + pmd_t *pmd_m;
75137 +
75138 + if (vma->vm_start > vma_m->vm_start) {
75139 + address_m = address;
75140 + address -= SEGMEXEC_TASK_SIZE;
75141 + vma = vma_m;
75142 + } else
75143 + address_m = address + SEGMEXEC_TASK_SIZE;
75144 +
75145 + pgd_m = pgd_offset(mm, address_m);
75146 + pud_m = pud_alloc(mm, pgd_m, address_m);
75147 + if (!pud_m)
75148 + return VM_FAULT_OOM;
75149 + pmd_m = pmd_alloc(mm, pud_m, address_m);
75150 + if (!pmd_m)
75151 + return VM_FAULT_OOM;
75152 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
75153 + return VM_FAULT_OOM;
75154 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
75155 + }
75156 +#endif
75157 +
75158 retry:
75159 pgd = pgd_offset(mm, address);
75160 pud = pud_alloc(mm, pgd, address);
75161 @@ -3565,7 +3806,7 @@ retry:
75162 * run pte_offset_map on the pmd, if an huge pmd could
75163 * materialize from under us from a different thread.
75164 */
75165 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
75166 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
75167 return VM_FAULT_OOM;
75168 /* if an huge pmd materialized from under us just retry later */
75169 if (unlikely(pmd_trans_huge(*pmd)))
75170 @@ -3602,6 +3843,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75171 spin_unlock(&mm->page_table_lock);
75172 return 0;
75173 }
75174 +
75175 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75176 +{
75177 + pud_t *new = pud_alloc_one(mm, address);
75178 + if (!new)
75179 + return -ENOMEM;
75180 +
75181 + smp_wmb(); /* See comment in __pte_alloc */
75182 +
75183 + spin_lock(&mm->page_table_lock);
75184 + if (pgd_present(*pgd)) /* Another has populated it */
75185 + pud_free(mm, new);
75186 + else
75187 + pgd_populate_kernel(mm, pgd, new);
75188 + spin_unlock(&mm->page_table_lock);
75189 + return 0;
75190 +}
75191 #endif /* __PAGETABLE_PUD_FOLDED */
75192
75193 #ifndef __PAGETABLE_PMD_FOLDED
75194 @@ -3632,6 +3890,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
75195 spin_unlock(&mm->page_table_lock);
75196 return 0;
75197 }
75198 +
75199 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
75200 +{
75201 + pmd_t *new = pmd_alloc_one(mm, address);
75202 + if (!new)
75203 + return -ENOMEM;
75204 +
75205 + smp_wmb(); /* See comment in __pte_alloc */
75206 +
75207 + spin_lock(&mm->page_table_lock);
75208 +#ifndef __ARCH_HAS_4LEVEL_HACK
75209 + if (pud_present(*pud)) /* Another has populated it */
75210 + pmd_free(mm, new);
75211 + else
75212 + pud_populate_kernel(mm, pud, new);
75213 +#else
75214 + if (pgd_present(*pud)) /* Another has populated it */
75215 + pmd_free(mm, new);
75216 + else
75217 + pgd_populate_kernel(mm, pud, new);
75218 +#endif /* __ARCH_HAS_4LEVEL_HACK */
75219 + spin_unlock(&mm->page_table_lock);
75220 + return 0;
75221 +}
75222 #endif /* __PAGETABLE_PMD_FOLDED */
75223
75224 int make_pages_present(unsigned long addr, unsigned long end)
75225 @@ -3669,7 +3951,7 @@ static int __init gate_vma_init(void)
75226 gate_vma.vm_start = FIXADDR_USER_START;
75227 gate_vma.vm_end = FIXADDR_USER_END;
75228 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
75229 - gate_vma.vm_page_prot = __P101;
75230 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
75231
75232 return 0;
75233 }
75234 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
75235 index 002c281..9429765 100644
75236 --- a/mm/mempolicy.c
75237 +++ b/mm/mempolicy.c
75238 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
75239 unsigned long vmstart;
75240 unsigned long vmend;
75241
75242 +#ifdef CONFIG_PAX_SEGMEXEC
75243 + struct vm_area_struct *vma_m;
75244 +#endif
75245 +
75246 vma = find_vma(mm, start);
75247 if (!vma || vma->vm_start > start)
75248 return -EFAULT;
75249 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
75250 if (err)
75251 goto out;
75252 }
75253 +
75254 err = vma_replace_policy(vma, new_pol);
75255 if (err)
75256 goto out;
75257 +
75258 +#ifdef CONFIG_PAX_SEGMEXEC
75259 + vma_m = pax_find_mirror_vma(vma);
75260 + if (vma_m) {
75261 + err = vma_replace_policy(vma_m, new_pol);
75262 + if (err)
75263 + goto out;
75264 + }
75265 +#endif
75266 +
75267 }
75268
75269 out:
75270 @@ -1150,6 +1165,17 @@ static long do_mbind(unsigned long start, unsigned long len,
75271
75272 if (end < start)
75273 return -EINVAL;
75274 +
75275 +#ifdef CONFIG_PAX_SEGMEXEC
75276 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
75277 + if (end > SEGMEXEC_TASK_SIZE)
75278 + return -EINVAL;
75279 + } else
75280 +#endif
75281 +
75282 + if (end > TASK_SIZE)
75283 + return -EINVAL;
75284 +
75285 if (end == start)
75286 return 0;
75287
75288 @@ -1373,8 +1399,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
75289 */
75290 tcred = __task_cred(task);
75291 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
75292 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
75293 - !capable(CAP_SYS_NICE)) {
75294 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
75295 rcu_read_unlock();
75296 err = -EPERM;
75297 goto out_put;
75298 @@ -1405,6 +1430,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
75299 goto out;
75300 }
75301
75302 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
75303 + if (mm != current->mm &&
75304 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
75305 + mmput(mm);
75306 + err = -EPERM;
75307 + goto out;
75308 + }
75309 +#endif
75310 +
75311 err = do_migrate_pages(mm, old, new,
75312 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
75313
75314 diff --git a/mm/migrate.c b/mm/migrate.c
75315 index 346d32d..d7adff2 100644
75316 --- a/mm/migrate.c
75317 +++ b/mm/migrate.c
75318 @@ -1352,8 +1352,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
75319 */
75320 tcred = __task_cred(task);
75321 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
75322 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
75323 - !capable(CAP_SYS_NICE)) {
75324 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
75325 rcu_read_unlock();
75326 err = -EPERM;
75327 goto out;
75328 diff --git a/mm/mlock.c b/mm/mlock.c
75329 index f0b9ce5..da8d069 100644
75330 --- a/mm/mlock.c
75331 +++ b/mm/mlock.c
75332 @@ -13,6 +13,7 @@
75333 #include <linux/pagemap.h>
75334 #include <linux/mempolicy.h>
75335 #include <linux/syscalls.h>
75336 +#include <linux/security.h>
75337 #include <linux/sched.h>
75338 #include <linux/export.h>
75339 #include <linux/rmap.h>
75340 @@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
75341 {
75342 unsigned long nstart, end, tmp;
75343 struct vm_area_struct * vma, * prev;
75344 - int error;
75345 + int error = 0;
75346
75347 VM_BUG_ON(start & ~PAGE_MASK);
75348 VM_BUG_ON(len != PAGE_ALIGN(len));
75349 @@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
75350 return -EINVAL;
75351 if (end == start)
75352 return 0;
75353 + if (end > TASK_SIZE)
75354 + return -EINVAL;
75355 +
75356 vma = find_vma(current->mm, start);
75357 if (!vma || vma->vm_start > start)
75358 return -ENOMEM;
75359 @@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
75360 for (nstart = start ; ; ) {
75361 vm_flags_t newflags;
75362
75363 +#ifdef CONFIG_PAX_SEGMEXEC
75364 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
75365 + break;
75366 +#endif
75367 +
75368 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
75369
75370 newflags = vma->vm_flags | VM_LOCKED;
75371 @@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
75372 lock_limit >>= PAGE_SHIFT;
75373
75374 /* check against resource limits */
75375 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
75376 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
75377 error = do_mlock(start, len, 1);
75378 up_write(&current->mm->mmap_sem);
75379 @@ -517,17 +527,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
75380 static int do_mlockall(int flags)
75381 {
75382 struct vm_area_struct * vma, * prev = NULL;
75383 - unsigned int def_flags = 0;
75384
75385 if (flags & MCL_FUTURE)
75386 - def_flags = VM_LOCKED;
75387 - current->mm->def_flags = def_flags;
75388 + current->mm->def_flags |= VM_LOCKED;
75389 + else
75390 + current->mm->def_flags &= ~VM_LOCKED;
75391 if (flags == MCL_FUTURE)
75392 goto out;
75393
75394 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
75395 vm_flags_t newflags;
75396
75397 +#ifdef CONFIG_PAX_SEGMEXEC
75398 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
75399 + break;
75400 +#endif
75401 +
75402 + BUG_ON(vma->vm_end > TASK_SIZE);
75403 newflags = vma->vm_flags | VM_LOCKED;
75404 if (!(flags & MCL_CURRENT))
75405 newflags &= ~VM_LOCKED;
75406 @@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
75407 lock_limit >>= PAGE_SHIFT;
75408
75409 ret = -ENOMEM;
75410 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
75411 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
75412 capable(CAP_IPC_LOCK))
75413 ret = do_mlockall(flags);
75414 diff --git a/mm/mmap.c b/mm/mmap.c
75415 index 9a796c4..e2c9724 100644
75416 --- a/mm/mmap.c
75417 +++ b/mm/mmap.c
75418 @@ -31,6 +31,7 @@
75419 #include <linux/audit.h>
75420 #include <linux/khugepaged.h>
75421 #include <linux/uprobes.h>
75422 +#include <linux/random.h>
75423
75424 #include <asm/uaccess.h>
75425 #include <asm/cacheflush.h>
75426 @@ -47,6 +48,16 @@
75427 #define arch_rebalance_pgtables(addr, len) (addr)
75428 #endif
75429
75430 +static inline void verify_mm_writelocked(struct mm_struct *mm)
75431 +{
75432 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
75433 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
75434 + up_read(&mm->mmap_sem);
75435 + BUG();
75436 + }
75437 +#endif
75438 +}
75439 +
75440 static void unmap_region(struct mm_struct *mm,
75441 struct vm_area_struct *vma, struct vm_area_struct *prev,
75442 unsigned long start, unsigned long end);
75443 @@ -66,22 +77,32 @@ static void unmap_region(struct mm_struct *mm,
75444 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
75445 *
75446 */
75447 -pgprot_t protection_map[16] = {
75448 +pgprot_t protection_map[16] __read_only = {
75449 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
75450 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
75451 };
75452
75453 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
75454 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
75455 {
75456 - return __pgprot(pgprot_val(protection_map[vm_flags &
75457 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
75458 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
75459 pgprot_val(arch_vm_get_page_prot(vm_flags)));
75460 +
75461 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75462 + if (!(__supported_pte_mask & _PAGE_NX) &&
75463 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
75464 + (vm_flags & (VM_READ | VM_WRITE)))
75465 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
75466 +#endif
75467 +
75468 + return prot;
75469 }
75470 EXPORT_SYMBOL(vm_get_page_prot);
75471
75472 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
75473 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
75474 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
75475 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
75476 /*
75477 * Make sure vm_committed_as in one cacheline and not cacheline shared with
75478 * other variables. It can be updated by several CPUs frequently.
75479 @@ -223,6 +244,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
75480 struct vm_area_struct *next = vma->vm_next;
75481
75482 might_sleep();
75483 + BUG_ON(vma->vm_mirror);
75484 if (vma->vm_ops && vma->vm_ops->close)
75485 vma->vm_ops->close(vma);
75486 if (vma->vm_file)
75487 @@ -266,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
75488 * not page aligned -Ram Gupta
75489 */
75490 rlim = rlimit(RLIMIT_DATA);
75491 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
75492 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
75493 (mm->end_data - mm->start_data) > rlim)
75494 goto out;
75495 @@ -736,6 +759,12 @@ static int
75496 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
75497 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75498 {
75499 +
75500 +#ifdef CONFIG_PAX_SEGMEXEC
75501 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
75502 + return 0;
75503 +#endif
75504 +
75505 if (is_mergeable_vma(vma, file, vm_flags) &&
75506 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75507 if (vma->vm_pgoff == vm_pgoff)
75508 @@ -755,6 +784,12 @@ static int
75509 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75510 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75511 {
75512 +
75513 +#ifdef CONFIG_PAX_SEGMEXEC
75514 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
75515 + return 0;
75516 +#endif
75517 +
75518 if (is_mergeable_vma(vma, file, vm_flags) &&
75519 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75520 pgoff_t vm_pglen;
75521 @@ -797,13 +832,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75522 struct vm_area_struct *vma_merge(struct mm_struct *mm,
75523 struct vm_area_struct *prev, unsigned long addr,
75524 unsigned long end, unsigned long vm_flags,
75525 - struct anon_vma *anon_vma, struct file *file,
75526 + struct anon_vma *anon_vma, struct file *file,
75527 pgoff_t pgoff, struct mempolicy *policy)
75528 {
75529 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
75530 struct vm_area_struct *area, *next;
75531 int err;
75532
75533 +#ifdef CONFIG_PAX_SEGMEXEC
75534 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
75535 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
75536 +
75537 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
75538 +#endif
75539 +
75540 /*
75541 * We later require that vma->vm_flags == vm_flags,
75542 * so this tests vma->vm_flags & VM_SPECIAL, too.
75543 @@ -819,6 +861,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75544 if (next && next->vm_end == end) /* cases 6, 7, 8 */
75545 next = next->vm_next;
75546
75547 +#ifdef CONFIG_PAX_SEGMEXEC
75548 + if (prev)
75549 + prev_m = pax_find_mirror_vma(prev);
75550 + if (area)
75551 + area_m = pax_find_mirror_vma(area);
75552 + if (next)
75553 + next_m = pax_find_mirror_vma(next);
75554 +#endif
75555 +
75556 /*
75557 * Can it merge with the predecessor?
75558 */
75559 @@ -838,9 +889,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75560 /* cases 1, 6 */
75561 err = vma_adjust(prev, prev->vm_start,
75562 next->vm_end, prev->vm_pgoff, NULL);
75563 - } else /* cases 2, 5, 7 */
75564 +
75565 +#ifdef CONFIG_PAX_SEGMEXEC
75566 + if (!err && prev_m)
75567 + err = vma_adjust(prev_m, prev_m->vm_start,
75568 + next_m->vm_end, prev_m->vm_pgoff, NULL);
75569 +#endif
75570 +
75571 + } else { /* cases 2, 5, 7 */
75572 err = vma_adjust(prev, prev->vm_start,
75573 end, prev->vm_pgoff, NULL);
75574 +
75575 +#ifdef CONFIG_PAX_SEGMEXEC
75576 + if (!err && prev_m)
75577 + err = vma_adjust(prev_m, prev_m->vm_start,
75578 + end_m, prev_m->vm_pgoff, NULL);
75579 +#endif
75580 +
75581 + }
75582 if (err)
75583 return NULL;
75584 khugepaged_enter_vma_merge(prev);
75585 @@ -854,12 +920,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75586 mpol_equal(policy, vma_policy(next)) &&
75587 can_vma_merge_before(next, vm_flags,
75588 anon_vma, file, pgoff+pglen)) {
75589 - if (prev && addr < prev->vm_end) /* case 4 */
75590 + if (prev && addr < prev->vm_end) { /* case 4 */
75591 err = vma_adjust(prev, prev->vm_start,
75592 addr, prev->vm_pgoff, NULL);
75593 - else /* cases 3, 8 */
75594 +
75595 +#ifdef CONFIG_PAX_SEGMEXEC
75596 + if (!err && prev_m)
75597 + err = vma_adjust(prev_m, prev_m->vm_start,
75598 + addr_m, prev_m->vm_pgoff, NULL);
75599 +#endif
75600 +
75601 + } else { /* cases 3, 8 */
75602 err = vma_adjust(area, addr, next->vm_end,
75603 next->vm_pgoff - pglen, NULL);
75604 +
75605 +#ifdef CONFIG_PAX_SEGMEXEC
75606 + if (!err && area_m)
75607 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
75608 + next_m->vm_pgoff - pglen, NULL);
75609 +#endif
75610 +
75611 + }
75612 if (err)
75613 return NULL;
75614 khugepaged_enter_vma_merge(area);
75615 @@ -968,16 +1049,13 @@ none:
75616 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
75617 struct file *file, long pages)
75618 {
75619 - const unsigned long stack_flags
75620 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
75621 -
75622 mm->total_vm += pages;
75623
75624 if (file) {
75625 mm->shared_vm += pages;
75626 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
75627 mm->exec_vm += pages;
75628 - } else if (flags & stack_flags)
75629 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
75630 mm->stack_vm += pages;
75631 }
75632 #endif /* CONFIG_PROC_FS */
75633 @@ -1013,7 +1091,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75634 * (the exception is when the underlying filesystem is noexec
75635 * mounted, in which case we dont add PROT_EXEC.)
75636 */
75637 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
75638 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
75639 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
75640 prot |= PROT_EXEC;
75641
75642 @@ -1039,7 +1117,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75643 /* Obtain the address to map to. we verify (or select) it and ensure
75644 * that it represents a valid section of the address space.
75645 */
75646 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
75647 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
75648 if (addr & ~PAGE_MASK)
75649 return addr;
75650
75651 @@ -1050,6 +1128,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75652 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
75653 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
75654
75655 +#ifdef CONFIG_PAX_MPROTECT
75656 + if (mm->pax_flags & MF_PAX_MPROTECT) {
75657 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
75658 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
75659 + gr_log_rwxmmap(file);
75660 +
75661 +#ifdef CONFIG_PAX_EMUPLT
75662 + vm_flags &= ~VM_EXEC;
75663 +#else
75664 + return -EPERM;
75665 +#endif
75666 +
75667 + }
75668 +
75669 + if (!(vm_flags & VM_EXEC))
75670 + vm_flags &= ~VM_MAYEXEC;
75671 +#else
75672 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
75673 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
75674 +#endif
75675 + else
75676 + vm_flags &= ~VM_MAYWRITE;
75677 + }
75678 +#endif
75679 +
75680 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75681 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
75682 + vm_flags &= ~VM_PAGEEXEC;
75683 +#endif
75684 +
75685 if (flags & MAP_LOCKED)
75686 if (!can_do_mlock())
75687 return -EPERM;
75688 @@ -1061,6 +1169,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75689 locked += mm->locked_vm;
75690 lock_limit = rlimit(RLIMIT_MEMLOCK);
75691 lock_limit >>= PAGE_SHIFT;
75692 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
75693 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
75694 return -EAGAIN;
75695 }
75696 @@ -1127,6 +1236,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75697 }
75698 }
75699
75700 + if (!gr_acl_handle_mmap(file, prot))
75701 + return -EACCES;
75702 +
75703 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
75704 }
75705
75706 @@ -1203,7 +1315,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
75707 vm_flags_t vm_flags = vma->vm_flags;
75708
75709 /* If it was private or non-writable, the write bit is already clear */
75710 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
75711 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
75712 return 0;
75713
75714 /* The backer wishes to know when pages are first written to? */
75715 @@ -1252,13 +1364,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
75716 unsigned long charged = 0;
75717 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
75718
75719 +#ifdef CONFIG_PAX_SEGMEXEC
75720 + struct vm_area_struct *vma_m = NULL;
75721 +#endif
75722 +
75723 + /*
75724 + * mm->mmap_sem is required to protect against another thread
75725 + * changing the mappings in case we sleep.
75726 + */
75727 + verify_mm_writelocked(mm);
75728 +
75729 /* Clear old maps */
75730 error = -ENOMEM;
75731 -munmap_back:
75732 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
75733 if (do_munmap(mm, addr, len))
75734 return -ENOMEM;
75735 - goto munmap_back;
75736 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
75737 }
75738
75739 /* Check against address space limit. */
75740 @@ -1307,6 +1428,16 @@ munmap_back:
75741 goto unacct_error;
75742 }
75743
75744 +#ifdef CONFIG_PAX_SEGMEXEC
75745 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
75746 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
75747 + if (!vma_m) {
75748 + error = -ENOMEM;
75749 + goto free_vma;
75750 + }
75751 + }
75752 +#endif
75753 +
75754 vma->vm_mm = mm;
75755 vma->vm_start = addr;
75756 vma->vm_end = addr + len;
75757 @@ -1331,6 +1462,13 @@ munmap_back:
75758 if (error)
75759 goto unmap_and_free_vma;
75760
75761 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75762 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
75763 + vma->vm_flags |= VM_PAGEEXEC;
75764 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
75765 + }
75766 +#endif
75767 +
75768 /* Can addr have changed??
75769 *
75770 * Answer: Yes, several device drivers can do it in their
75771 @@ -1365,6 +1503,11 @@ munmap_back:
75772 vma_link(mm, vma, prev, rb_link, rb_parent);
75773 file = vma->vm_file;
75774
75775 +#ifdef CONFIG_PAX_SEGMEXEC
75776 + if (vma_m)
75777 + BUG_ON(pax_mirror_vma(vma_m, vma));
75778 +#endif
75779 +
75780 /* Once vma denies write, undo our temporary denial count */
75781 if (correct_wcount)
75782 atomic_inc(&inode->i_writecount);
75783 @@ -1372,6 +1515,7 @@ out:
75784 perf_event_mmap(vma);
75785
75786 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
75787 + track_exec_limit(mm, addr, addr + len, vm_flags);
75788 if (vm_flags & VM_LOCKED) {
75789 if (!mlock_vma_pages_range(vma, addr, addr + len))
75790 mm->locked_vm += (len >> PAGE_SHIFT);
75791 @@ -1393,6 +1537,12 @@ unmap_and_free_vma:
75792 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
75793 charged = 0;
75794 free_vma:
75795 +
75796 +#ifdef CONFIG_PAX_SEGMEXEC
75797 + if (vma_m)
75798 + kmem_cache_free(vm_area_cachep, vma_m);
75799 +#endif
75800 +
75801 kmem_cache_free(vm_area_cachep, vma);
75802 unacct_error:
75803 if (charged)
75804 @@ -1400,6 +1550,62 @@ unacct_error:
75805 return error;
75806 }
75807
75808 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
75809 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
75810 +{
75811 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
75812 + return (random32() & 0xFF) << PAGE_SHIFT;
75813 +
75814 + return 0;
75815 +}
75816 +#endif
75817 +
75818 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
75819 +{
75820 + if (!vma) {
75821 +#ifdef CONFIG_STACK_GROWSUP
75822 + if (addr > sysctl_heap_stack_gap)
75823 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
75824 + else
75825 + vma = find_vma(current->mm, 0);
75826 + if (vma && (vma->vm_flags & VM_GROWSUP))
75827 + return false;
75828 +#endif
75829 + return true;
75830 + }
75831 +
75832 + if (addr + len > vma->vm_start)
75833 + return false;
75834 +
75835 + if (vma->vm_flags & VM_GROWSDOWN)
75836 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
75837 +#ifdef CONFIG_STACK_GROWSUP
75838 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
75839 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
75840 +#endif
75841 + else if (offset)
75842 + return offset <= vma->vm_start - addr - len;
75843 +
75844 + return true;
75845 +}
75846 +
75847 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
75848 +{
75849 + if (vma->vm_start < len)
75850 + return -ENOMEM;
75851 +
75852 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
75853 + if (offset <= vma->vm_start - len)
75854 + return vma->vm_start - len - offset;
75855 + else
75856 + return -ENOMEM;
75857 + }
75858 +
75859 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
75860 + return vma->vm_start - len - sysctl_heap_stack_gap;
75861 + return -ENOMEM;
75862 +}
75863 +
75864 /* Get an address range which is currently unmapped.
75865 * For shmat() with addr=0.
75866 *
75867 @@ -1419,6 +1625,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
75868 struct mm_struct *mm = current->mm;
75869 struct vm_area_struct *vma;
75870 unsigned long start_addr;
75871 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
75872
75873 if (len > TASK_SIZE)
75874 return -ENOMEM;
75875 @@ -1426,18 +1633,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
75876 if (flags & MAP_FIXED)
75877 return addr;
75878
75879 +#ifdef CONFIG_PAX_RANDMMAP
75880 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75881 +#endif
75882 +
75883 if (addr) {
75884 addr = PAGE_ALIGN(addr);
75885 - vma = find_vma(mm, addr);
75886 - if (TASK_SIZE - len >= addr &&
75887 - (!vma || addr + len <= vma->vm_start))
75888 - return addr;
75889 + if (TASK_SIZE - len >= addr) {
75890 + vma = find_vma(mm, addr);
75891 + if (check_heap_stack_gap(vma, addr, len, offset))
75892 + return addr;
75893 + }
75894 }
75895 if (len > mm->cached_hole_size) {
75896 - start_addr = addr = mm->free_area_cache;
75897 + start_addr = addr = mm->free_area_cache;
75898 } else {
75899 - start_addr = addr = TASK_UNMAPPED_BASE;
75900 - mm->cached_hole_size = 0;
75901 + start_addr = addr = mm->mmap_base;
75902 + mm->cached_hole_size = 0;
75903 }
75904
75905 full_search:
75906 @@ -1448,34 +1660,40 @@ full_search:
75907 * Start a new search - just in case we missed
75908 * some holes.
75909 */
75910 - if (start_addr != TASK_UNMAPPED_BASE) {
75911 - addr = TASK_UNMAPPED_BASE;
75912 - start_addr = addr;
75913 + if (start_addr != mm->mmap_base) {
75914 + start_addr = addr = mm->mmap_base;
75915 mm->cached_hole_size = 0;
75916 goto full_search;
75917 }
75918 return -ENOMEM;
75919 }
75920 - if (!vma || addr + len <= vma->vm_start) {
75921 - /*
75922 - * Remember the place where we stopped the search:
75923 - */
75924 - mm->free_area_cache = addr + len;
75925 - return addr;
75926 - }
75927 + if (check_heap_stack_gap(vma, addr, len, offset))
75928 + break;
75929 if (addr + mm->cached_hole_size < vma->vm_start)
75930 mm->cached_hole_size = vma->vm_start - addr;
75931 addr = vma->vm_end;
75932 }
75933 +
75934 + /*
75935 + * Remember the place where we stopped the search:
75936 + */
75937 + mm->free_area_cache = addr + len;
75938 + return addr;
75939 }
75940 #endif
75941
75942 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
75943 {
75944 +
75945 +#ifdef CONFIG_PAX_SEGMEXEC
75946 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
75947 + return;
75948 +#endif
75949 +
75950 /*
75951 * Is this a new hole at the lowest possible address?
75952 */
75953 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
75954 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
75955 mm->free_area_cache = addr;
75956 }
75957
75958 @@ -1491,7 +1709,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75959 {
75960 struct vm_area_struct *vma;
75961 struct mm_struct *mm = current->mm;
75962 - unsigned long addr = addr0, start_addr;
75963 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
75964 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
75965
75966 /* requested length too big for entire address space */
75967 if (len > TASK_SIZE)
75968 @@ -1500,13 +1719,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75969 if (flags & MAP_FIXED)
75970 return addr;
75971
75972 +#ifdef CONFIG_PAX_RANDMMAP
75973 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75974 +#endif
75975 +
75976 /* requesting a specific address */
75977 if (addr) {
75978 addr = PAGE_ALIGN(addr);
75979 - vma = find_vma(mm, addr);
75980 - if (TASK_SIZE - len >= addr &&
75981 - (!vma || addr + len <= vma->vm_start))
75982 - return addr;
75983 + if (TASK_SIZE - len >= addr) {
75984 + vma = find_vma(mm, addr);
75985 + if (check_heap_stack_gap(vma, addr, len, offset))
75986 + return addr;
75987 + }
75988 }
75989
75990 /* check if free_area_cache is useful for us */
75991 @@ -1530,7 +1754,7 @@ try_again:
75992 * return with success:
75993 */
75994 vma = find_vma(mm, addr);
75995 - if (!vma || addr+len <= vma->vm_start)
75996 + if (check_heap_stack_gap(vma, addr, len, offset))
75997 /* remember the address as a hint for next time */
75998 return (mm->free_area_cache = addr);
75999
76000 @@ -1539,8 +1763,8 @@ try_again:
76001 mm->cached_hole_size = vma->vm_start - addr;
76002
76003 /* try just below the current vma->vm_start */
76004 - addr = vma->vm_start-len;
76005 - } while (len < vma->vm_start);
76006 + addr = skip_heap_stack_gap(vma, len, offset);
76007 + } while (!IS_ERR_VALUE(addr));
76008
76009 fail:
76010 /*
76011 @@ -1563,13 +1787,21 @@ fail:
76012 * can happen with large stack limits and large mmap()
76013 * allocations.
76014 */
76015 + mm->mmap_base = TASK_UNMAPPED_BASE;
76016 +
76017 +#ifdef CONFIG_PAX_RANDMMAP
76018 + if (mm->pax_flags & MF_PAX_RANDMMAP)
76019 + mm->mmap_base += mm->delta_mmap;
76020 +#endif
76021 +
76022 + mm->free_area_cache = mm->mmap_base;
76023 mm->cached_hole_size = ~0UL;
76024 - mm->free_area_cache = TASK_UNMAPPED_BASE;
76025 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
76026 /*
76027 * Restore the topdown base:
76028 */
76029 - mm->free_area_cache = mm->mmap_base;
76030 + mm->mmap_base = base;
76031 + mm->free_area_cache = base;
76032 mm->cached_hole_size = ~0UL;
76033
76034 return addr;
76035 @@ -1578,6 +1810,12 @@ fail:
76036
76037 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
76038 {
76039 +
76040 +#ifdef CONFIG_PAX_SEGMEXEC
76041 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
76042 + return;
76043 +#endif
76044 +
76045 /*
76046 * Is this a new hole at the highest possible address?
76047 */
76048 @@ -1585,8 +1823,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
76049 mm->free_area_cache = addr;
76050
76051 /* dont allow allocations above current base */
76052 - if (mm->free_area_cache > mm->mmap_base)
76053 + if (mm->free_area_cache > mm->mmap_base) {
76054 mm->free_area_cache = mm->mmap_base;
76055 + mm->cached_hole_size = ~0UL;
76056 + }
76057 }
76058
76059 unsigned long
76060 @@ -1685,6 +1925,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
76061 return vma;
76062 }
76063
76064 +#ifdef CONFIG_PAX_SEGMEXEC
76065 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
76066 +{
76067 + struct vm_area_struct *vma_m;
76068 +
76069 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
76070 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
76071 + BUG_ON(vma->vm_mirror);
76072 + return NULL;
76073 + }
76074 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
76075 + vma_m = vma->vm_mirror;
76076 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
76077 + BUG_ON(vma->vm_file != vma_m->vm_file);
76078 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
76079 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
76080 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
76081 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
76082 + return vma_m;
76083 +}
76084 +#endif
76085 +
76086 /*
76087 * Verify that the stack growth is acceptable and
76088 * update accounting. This is shared with both the
76089 @@ -1701,6 +1963,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76090 return -ENOMEM;
76091
76092 /* Stack limit test */
76093 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
76094 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
76095 return -ENOMEM;
76096
76097 @@ -1711,6 +1974,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76098 locked = mm->locked_vm + grow;
76099 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
76100 limit >>= PAGE_SHIFT;
76101 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76102 if (locked > limit && !capable(CAP_IPC_LOCK))
76103 return -ENOMEM;
76104 }
76105 @@ -1740,37 +2004,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
76106 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
76107 * vma is the last one with address > vma->vm_end. Have to extend vma.
76108 */
76109 +#ifndef CONFIG_IA64
76110 +static
76111 +#endif
76112 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
76113 {
76114 int error;
76115 + bool locknext;
76116
76117 if (!(vma->vm_flags & VM_GROWSUP))
76118 return -EFAULT;
76119
76120 + /* Also guard against wrapping around to address 0. */
76121 + if (address < PAGE_ALIGN(address+1))
76122 + address = PAGE_ALIGN(address+1);
76123 + else
76124 + return -ENOMEM;
76125 +
76126 /*
76127 * We must make sure the anon_vma is allocated
76128 * so that the anon_vma locking is not a noop.
76129 */
76130 if (unlikely(anon_vma_prepare(vma)))
76131 return -ENOMEM;
76132 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
76133 + if (locknext && anon_vma_prepare(vma->vm_next))
76134 + return -ENOMEM;
76135 vma_lock_anon_vma(vma);
76136 + if (locknext)
76137 + vma_lock_anon_vma(vma->vm_next);
76138
76139 /*
76140 * vma->vm_start/vm_end cannot change under us because the caller
76141 * is required to hold the mmap_sem in read mode. We need the
76142 - * anon_vma lock to serialize against concurrent expand_stacks.
76143 - * Also guard against wrapping around to address 0.
76144 + * anon_vma locks to serialize against concurrent expand_stacks
76145 + * and expand_upwards.
76146 */
76147 - if (address < PAGE_ALIGN(address+4))
76148 - address = PAGE_ALIGN(address+4);
76149 - else {
76150 - vma_unlock_anon_vma(vma);
76151 - return -ENOMEM;
76152 - }
76153 error = 0;
76154
76155 /* Somebody else might have raced and expanded it already */
76156 - if (address > vma->vm_end) {
76157 + 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)
76158 + error = -ENOMEM;
76159 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
76160 unsigned long size, grow;
76161
76162 size = address - vma->vm_start;
76163 @@ -1787,6 +2062,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
76164 }
76165 }
76166 }
76167 + if (locknext)
76168 + vma_unlock_anon_vma(vma->vm_next);
76169 vma_unlock_anon_vma(vma);
76170 khugepaged_enter_vma_merge(vma);
76171 validate_mm(vma->vm_mm);
76172 @@ -1801,6 +2078,8 @@ int expand_downwards(struct vm_area_struct *vma,
76173 unsigned long address)
76174 {
76175 int error;
76176 + bool lockprev = false;
76177 + struct vm_area_struct *prev;
76178
76179 /*
76180 * We must make sure the anon_vma is allocated
76181 @@ -1814,6 +2093,15 @@ int expand_downwards(struct vm_area_struct *vma,
76182 if (error)
76183 return error;
76184
76185 + prev = vma->vm_prev;
76186 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
76187 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
76188 +#endif
76189 + if (lockprev && anon_vma_prepare(prev))
76190 + return -ENOMEM;
76191 + if (lockprev)
76192 + vma_lock_anon_vma(prev);
76193 +
76194 vma_lock_anon_vma(vma);
76195
76196 /*
76197 @@ -1823,9 +2111,17 @@ int expand_downwards(struct vm_area_struct *vma,
76198 */
76199
76200 /* Somebody else might have raced and expanded it already */
76201 - if (address < vma->vm_start) {
76202 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
76203 + error = -ENOMEM;
76204 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
76205 unsigned long size, grow;
76206
76207 +#ifdef CONFIG_PAX_SEGMEXEC
76208 + struct vm_area_struct *vma_m;
76209 +
76210 + vma_m = pax_find_mirror_vma(vma);
76211 +#endif
76212 +
76213 size = vma->vm_end - address;
76214 grow = (vma->vm_start - address) >> PAGE_SHIFT;
76215
76216 @@ -1837,6 +2133,17 @@ int expand_downwards(struct vm_area_struct *vma,
76217 vma->vm_start = address;
76218 vma->vm_pgoff -= grow;
76219 anon_vma_interval_tree_post_update_vma(vma);
76220 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
76221 +
76222 +#ifdef CONFIG_PAX_SEGMEXEC
76223 + if (vma_m) {
76224 + anon_vma_interval_tree_pre_update_vma(vma_m);
76225 + vma_m->vm_start -= grow << PAGE_SHIFT;
76226 + vma_m->vm_pgoff -= grow;
76227 + anon_vma_interval_tree_post_update_vma(vma_m);
76228 + }
76229 +#endif
76230 +
76231 perf_event_mmap(vma);
76232 }
76233 }
76234 @@ -1914,6 +2221,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
76235 do {
76236 long nrpages = vma_pages(vma);
76237
76238 +#ifdef CONFIG_PAX_SEGMEXEC
76239 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
76240 + vma = remove_vma(vma);
76241 + continue;
76242 + }
76243 +#endif
76244 +
76245 if (vma->vm_flags & VM_ACCOUNT)
76246 nr_accounted += nrpages;
76247 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
76248 @@ -1959,6 +2273,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
76249 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
76250 vma->vm_prev = NULL;
76251 do {
76252 +
76253 +#ifdef CONFIG_PAX_SEGMEXEC
76254 + if (vma->vm_mirror) {
76255 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
76256 + vma->vm_mirror->vm_mirror = NULL;
76257 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
76258 + vma->vm_mirror = NULL;
76259 + }
76260 +#endif
76261 +
76262 rb_erase(&vma->vm_rb, &mm->mm_rb);
76263 mm->map_count--;
76264 tail_vma = vma;
76265 @@ -1987,14 +2311,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76266 struct vm_area_struct *new;
76267 int err = -ENOMEM;
76268
76269 +#ifdef CONFIG_PAX_SEGMEXEC
76270 + struct vm_area_struct *vma_m, *new_m = NULL;
76271 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
76272 +#endif
76273 +
76274 if (is_vm_hugetlb_page(vma) && (addr &
76275 ~(huge_page_mask(hstate_vma(vma)))))
76276 return -EINVAL;
76277
76278 +#ifdef CONFIG_PAX_SEGMEXEC
76279 + vma_m = pax_find_mirror_vma(vma);
76280 +#endif
76281 +
76282 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
76283 if (!new)
76284 goto out_err;
76285
76286 +#ifdef CONFIG_PAX_SEGMEXEC
76287 + if (vma_m) {
76288 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
76289 + if (!new_m) {
76290 + kmem_cache_free(vm_area_cachep, new);
76291 + goto out_err;
76292 + }
76293 + }
76294 +#endif
76295 +
76296 /* most fields are the same, copy all, and then fixup */
76297 *new = *vma;
76298
76299 @@ -2007,6 +2350,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76300 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
76301 }
76302
76303 +#ifdef CONFIG_PAX_SEGMEXEC
76304 + if (vma_m) {
76305 + *new_m = *vma_m;
76306 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
76307 + new_m->vm_mirror = new;
76308 + new->vm_mirror = new_m;
76309 +
76310 + if (new_below)
76311 + new_m->vm_end = addr_m;
76312 + else {
76313 + new_m->vm_start = addr_m;
76314 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
76315 + }
76316 + }
76317 +#endif
76318 +
76319 pol = mpol_dup(vma_policy(vma));
76320 if (IS_ERR(pol)) {
76321 err = PTR_ERR(pol);
76322 @@ -2029,6 +2388,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76323 else
76324 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
76325
76326 +#ifdef CONFIG_PAX_SEGMEXEC
76327 + if (!err && vma_m) {
76328 + if (anon_vma_clone(new_m, vma_m))
76329 + goto out_free_mpol;
76330 +
76331 + mpol_get(pol);
76332 + vma_set_policy(new_m, pol);
76333 +
76334 + if (new_m->vm_file)
76335 + get_file(new_m->vm_file);
76336 +
76337 + if (new_m->vm_ops && new_m->vm_ops->open)
76338 + new_m->vm_ops->open(new_m);
76339 +
76340 + if (new_below)
76341 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
76342 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
76343 + else
76344 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
76345 +
76346 + if (err) {
76347 + if (new_m->vm_ops && new_m->vm_ops->close)
76348 + new_m->vm_ops->close(new_m);
76349 + if (new_m->vm_file)
76350 + fput(new_m->vm_file);
76351 + mpol_put(pol);
76352 + }
76353 + }
76354 +#endif
76355 +
76356 /* Success. */
76357 if (!err)
76358 return 0;
76359 @@ -2038,10 +2427,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76360 new->vm_ops->close(new);
76361 if (new->vm_file)
76362 fput(new->vm_file);
76363 - unlink_anon_vmas(new);
76364 out_free_mpol:
76365 mpol_put(pol);
76366 out_free_vma:
76367 +
76368 +#ifdef CONFIG_PAX_SEGMEXEC
76369 + if (new_m) {
76370 + unlink_anon_vmas(new_m);
76371 + kmem_cache_free(vm_area_cachep, new_m);
76372 + }
76373 +#endif
76374 +
76375 + unlink_anon_vmas(new);
76376 kmem_cache_free(vm_area_cachep, new);
76377 out_err:
76378 return err;
76379 @@ -2054,6 +2451,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
76380 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76381 unsigned long addr, int new_below)
76382 {
76383 +
76384 +#ifdef CONFIG_PAX_SEGMEXEC
76385 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76386 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
76387 + if (mm->map_count >= sysctl_max_map_count-1)
76388 + return -ENOMEM;
76389 + } else
76390 +#endif
76391 +
76392 if (mm->map_count >= sysctl_max_map_count)
76393 return -ENOMEM;
76394
76395 @@ -2065,11 +2471,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76396 * work. This now handles partial unmappings.
76397 * Jeremy Fitzhardinge <jeremy@goop.org>
76398 */
76399 +#ifdef CONFIG_PAX_SEGMEXEC
76400 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76401 {
76402 + int ret = __do_munmap(mm, start, len);
76403 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
76404 + return ret;
76405 +
76406 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
76407 +}
76408 +
76409 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76410 +#else
76411 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76412 +#endif
76413 +{
76414 unsigned long end;
76415 struct vm_area_struct *vma, *prev, *last;
76416
76417 + /*
76418 + * mm->mmap_sem is required to protect against another thread
76419 + * changing the mappings in case we sleep.
76420 + */
76421 + verify_mm_writelocked(mm);
76422 +
76423 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
76424 return -EINVAL;
76425
76426 @@ -2144,6 +2569,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
76427 /* Fix up all other VM information */
76428 remove_vma_list(mm, vma);
76429
76430 + track_exec_limit(mm, start, end, 0UL);
76431 +
76432 return 0;
76433 }
76434
76435 @@ -2152,6 +2579,13 @@ int vm_munmap(unsigned long start, size_t len)
76436 int ret;
76437 struct mm_struct *mm = current->mm;
76438
76439 +
76440 +#ifdef CONFIG_PAX_SEGMEXEC
76441 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
76442 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
76443 + return -EINVAL;
76444 +#endif
76445 +
76446 down_write(&mm->mmap_sem);
76447 ret = do_munmap(mm, start, len);
76448 up_write(&mm->mmap_sem);
76449 @@ -2165,16 +2599,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
76450 return vm_munmap(addr, len);
76451 }
76452
76453 -static inline void verify_mm_writelocked(struct mm_struct *mm)
76454 -{
76455 -#ifdef CONFIG_DEBUG_VM
76456 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76457 - WARN_ON(1);
76458 - up_read(&mm->mmap_sem);
76459 - }
76460 -#endif
76461 -}
76462 -
76463 /*
76464 * this is really a simplified "do_mmap". it only handles
76465 * anonymous maps. eventually we may be able to do some
76466 @@ -2188,6 +2612,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76467 struct rb_node ** rb_link, * rb_parent;
76468 pgoff_t pgoff = addr >> PAGE_SHIFT;
76469 int error;
76470 + unsigned long charged;
76471
76472 len = PAGE_ALIGN(len);
76473 if (!len)
76474 @@ -2195,16 +2620,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76475
76476 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
76477
76478 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
76479 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
76480 + flags &= ~VM_EXEC;
76481 +
76482 +#ifdef CONFIG_PAX_MPROTECT
76483 + if (mm->pax_flags & MF_PAX_MPROTECT)
76484 + flags &= ~VM_MAYEXEC;
76485 +#endif
76486 +
76487 + }
76488 +#endif
76489 +
76490 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
76491 if (error & ~PAGE_MASK)
76492 return error;
76493
76494 + charged = len >> PAGE_SHIFT;
76495 +
76496 /*
76497 * mlock MCL_FUTURE?
76498 */
76499 if (mm->def_flags & VM_LOCKED) {
76500 unsigned long locked, lock_limit;
76501 - locked = len >> PAGE_SHIFT;
76502 + locked = charged;
76503 locked += mm->locked_vm;
76504 lock_limit = rlimit(RLIMIT_MEMLOCK);
76505 lock_limit >>= PAGE_SHIFT;
76506 @@ -2221,21 +2660,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76507 /*
76508 * Clear old maps. this also does some error checking for us
76509 */
76510 - munmap_back:
76511 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
76512 if (do_munmap(mm, addr, len))
76513 return -ENOMEM;
76514 - goto munmap_back;
76515 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
76516 }
76517
76518 /* Check against address space limits *after* clearing old maps... */
76519 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
76520 + if (!may_expand_vm(mm, charged))
76521 return -ENOMEM;
76522
76523 if (mm->map_count > sysctl_max_map_count)
76524 return -ENOMEM;
76525
76526 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
76527 + if (security_vm_enough_memory_mm(mm, charged))
76528 return -ENOMEM;
76529
76530 /* Can we just expand an old private anonymous mapping? */
76531 @@ -2249,7 +2687,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76532 */
76533 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76534 if (!vma) {
76535 - vm_unacct_memory(len >> PAGE_SHIFT);
76536 + vm_unacct_memory(charged);
76537 return -ENOMEM;
76538 }
76539
76540 @@ -2263,11 +2701,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76541 vma_link(mm, vma, prev, rb_link, rb_parent);
76542 out:
76543 perf_event_mmap(vma);
76544 - mm->total_vm += len >> PAGE_SHIFT;
76545 + mm->total_vm += charged;
76546 if (flags & VM_LOCKED) {
76547 if (!mlock_vma_pages_range(vma, addr, addr + len))
76548 - mm->locked_vm += (len >> PAGE_SHIFT);
76549 + mm->locked_vm += charged;
76550 }
76551 + track_exec_limit(mm, addr, addr + len, flags);
76552 return addr;
76553 }
76554
76555 @@ -2325,6 +2764,7 @@ void exit_mmap(struct mm_struct *mm)
76556 while (vma) {
76557 if (vma->vm_flags & VM_ACCOUNT)
76558 nr_accounted += vma_pages(vma);
76559 + vma->vm_mirror = NULL;
76560 vma = remove_vma(vma);
76561 }
76562 vm_unacct_memory(nr_accounted);
76563 @@ -2341,6 +2781,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
76564 struct vm_area_struct *prev;
76565 struct rb_node **rb_link, *rb_parent;
76566
76567 +#ifdef CONFIG_PAX_SEGMEXEC
76568 + struct vm_area_struct *vma_m = NULL;
76569 +#endif
76570 +
76571 + if (security_mmap_addr(vma->vm_start))
76572 + return -EPERM;
76573 +
76574 /*
76575 * The vm_pgoff of a purely anonymous vma should be irrelevant
76576 * until its first write fault, when page's anon_vma and index
76577 @@ -2364,7 +2811,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
76578 security_vm_enough_memory_mm(mm, vma_pages(vma)))
76579 return -ENOMEM;
76580
76581 +#ifdef CONFIG_PAX_SEGMEXEC
76582 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
76583 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76584 + if (!vma_m)
76585 + return -ENOMEM;
76586 + }
76587 +#endif
76588 +
76589 vma_link(mm, vma, prev, rb_link, rb_parent);
76590 +
76591 +#ifdef CONFIG_PAX_SEGMEXEC
76592 + if (vma_m)
76593 + BUG_ON(pax_mirror_vma(vma_m, vma));
76594 +#endif
76595 +
76596 return 0;
76597 }
76598
76599 @@ -2384,6 +2845,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
76600 struct mempolicy *pol;
76601 bool faulted_in_anon_vma = true;
76602
76603 + BUG_ON(vma->vm_mirror);
76604 +
76605 /*
76606 * If anonymous vma has not yet been faulted, update new pgoff
76607 * to match new location, to increase its chance of merging.
76608 @@ -2450,6 +2913,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
76609 return NULL;
76610 }
76611
76612 +#ifdef CONFIG_PAX_SEGMEXEC
76613 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
76614 +{
76615 + struct vm_area_struct *prev_m;
76616 + struct rb_node **rb_link_m, *rb_parent_m;
76617 + struct mempolicy *pol_m;
76618 +
76619 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
76620 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
76621 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
76622 + *vma_m = *vma;
76623 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
76624 + if (anon_vma_clone(vma_m, vma))
76625 + return -ENOMEM;
76626 + pol_m = vma_policy(vma_m);
76627 + mpol_get(pol_m);
76628 + vma_set_policy(vma_m, pol_m);
76629 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
76630 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
76631 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
76632 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
76633 + if (vma_m->vm_file)
76634 + get_file(vma_m->vm_file);
76635 + if (vma_m->vm_ops && vma_m->vm_ops->open)
76636 + vma_m->vm_ops->open(vma_m);
76637 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
76638 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
76639 + vma_m->vm_mirror = vma;
76640 + vma->vm_mirror = vma_m;
76641 + return 0;
76642 +}
76643 +#endif
76644 +
76645 /*
76646 * Return true if the calling process may expand its vm space by the passed
76647 * number of pages
76648 @@ -2461,6 +2957,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
76649
76650 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
76651
76652 +#ifdef CONFIG_PAX_RANDMMAP
76653 + if (mm->pax_flags & MF_PAX_RANDMMAP)
76654 + cur -= mm->brk_gap;
76655 +#endif
76656 +
76657 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
76658 if (cur + npages > lim)
76659 return 0;
76660 return 1;
76661 @@ -2531,6 +3033,22 @@ int install_special_mapping(struct mm_struct *mm,
76662 vma->vm_start = addr;
76663 vma->vm_end = addr + len;
76664
76665 +#ifdef CONFIG_PAX_MPROTECT
76666 + if (mm->pax_flags & MF_PAX_MPROTECT) {
76667 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
76668 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
76669 + return -EPERM;
76670 + if (!(vm_flags & VM_EXEC))
76671 + vm_flags &= ~VM_MAYEXEC;
76672 +#else
76673 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76674 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76675 +#endif
76676 + else
76677 + vm_flags &= ~VM_MAYWRITE;
76678 + }
76679 +#endif
76680 +
76681 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
76682 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76683
76684 diff --git a/mm/mprotect.c b/mm/mprotect.c
76685 index a409926..8b32e6d 100644
76686 --- a/mm/mprotect.c
76687 +++ b/mm/mprotect.c
76688 @@ -23,10 +23,17 @@
76689 #include <linux/mmu_notifier.h>
76690 #include <linux/migrate.h>
76691 #include <linux/perf_event.h>
76692 +
76693 +#ifdef CONFIG_PAX_MPROTECT
76694 +#include <linux/elf.h>
76695 +#include <linux/binfmts.h>
76696 +#endif
76697 +
76698 #include <asm/uaccess.h>
76699 #include <asm/pgtable.h>
76700 #include <asm/cacheflush.h>
76701 #include <asm/tlbflush.h>
76702 +#include <asm/mmu_context.h>
76703
76704 #ifndef pgprot_modify
76705 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
76706 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
76707 flush_tlb_range(vma, start, end);
76708 }
76709
76710 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76711 +/* called while holding the mmap semaphor for writing except stack expansion */
76712 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
76713 +{
76714 + unsigned long oldlimit, newlimit = 0UL;
76715 +
76716 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
76717 + return;
76718 +
76719 + spin_lock(&mm->page_table_lock);
76720 + oldlimit = mm->context.user_cs_limit;
76721 + if ((prot & VM_EXEC) && oldlimit < end)
76722 + /* USER_CS limit moved up */
76723 + newlimit = end;
76724 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
76725 + /* USER_CS limit moved down */
76726 + newlimit = start;
76727 +
76728 + if (newlimit) {
76729 + mm->context.user_cs_limit = newlimit;
76730 +
76731 +#ifdef CONFIG_SMP
76732 + wmb();
76733 + cpus_clear(mm->context.cpu_user_cs_mask);
76734 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
76735 +#endif
76736 +
76737 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
76738 + }
76739 + spin_unlock(&mm->page_table_lock);
76740 + if (newlimit == end) {
76741 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
76742 +
76743 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
76744 + if (is_vm_hugetlb_page(vma))
76745 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
76746 + else
76747 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
76748 + }
76749 +}
76750 +#endif
76751 +
76752 int
76753 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76754 unsigned long start, unsigned long end, unsigned long newflags)
76755 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76756 int error;
76757 int dirty_accountable = 0;
76758
76759 +#ifdef CONFIG_PAX_SEGMEXEC
76760 + struct vm_area_struct *vma_m = NULL;
76761 + unsigned long start_m, end_m;
76762 +
76763 + start_m = start + SEGMEXEC_TASK_SIZE;
76764 + end_m = end + SEGMEXEC_TASK_SIZE;
76765 +#endif
76766 +
76767 if (newflags == oldflags) {
76768 *pprev = vma;
76769 return 0;
76770 }
76771
76772 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
76773 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
76774 +
76775 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
76776 + return -ENOMEM;
76777 +
76778 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
76779 + return -ENOMEM;
76780 + }
76781 +
76782 /*
76783 * If we make a private mapping writable we increase our commit;
76784 * but (without finer accounting) cannot reduce our commit if we
76785 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76786 }
76787 }
76788
76789 +#ifdef CONFIG_PAX_SEGMEXEC
76790 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
76791 + if (start != vma->vm_start) {
76792 + error = split_vma(mm, vma, start, 1);
76793 + if (error)
76794 + goto fail;
76795 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
76796 + *pprev = (*pprev)->vm_next;
76797 + }
76798 +
76799 + if (end != vma->vm_end) {
76800 + error = split_vma(mm, vma, end, 0);
76801 + if (error)
76802 + goto fail;
76803 + }
76804 +
76805 + if (pax_find_mirror_vma(vma)) {
76806 + error = __do_munmap(mm, start_m, end_m - start_m);
76807 + if (error)
76808 + goto fail;
76809 + } else {
76810 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76811 + if (!vma_m) {
76812 + error = -ENOMEM;
76813 + goto fail;
76814 + }
76815 + vma->vm_flags = newflags;
76816 + error = pax_mirror_vma(vma_m, vma);
76817 + if (error) {
76818 + vma->vm_flags = oldflags;
76819 + goto fail;
76820 + }
76821 + }
76822 + }
76823 +#endif
76824 +
76825 /*
76826 * First try to merge with previous and/or next vma.
76827 */
76828 @@ -204,9 +307,21 @@ success:
76829 * vm_flags and vm_page_prot are protected by the mmap_sem
76830 * held in write mode.
76831 */
76832 +
76833 +#ifdef CONFIG_PAX_SEGMEXEC
76834 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
76835 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
76836 +#endif
76837 +
76838 vma->vm_flags = newflags;
76839 +
76840 +#ifdef CONFIG_PAX_MPROTECT
76841 + if (mm->binfmt && mm->binfmt->handle_mprotect)
76842 + mm->binfmt->handle_mprotect(vma, newflags);
76843 +#endif
76844 +
76845 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
76846 - vm_get_page_prot(newflags));
76847 + vm_get_page_prot(vma->vm_flags));
76848
76849 if (vma_wants_writenotify(vma)) {
76850 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
76851 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76852 end = start + len;
76853 if (end <= start)
76854 return -ENOMEM;
76855 +
76856 +#ifdef CONFIG_PAX_SEGMEXEC
76857 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
76858 + if (end > SEGMEXEC_TASK_SIZE)
76859 + return -EINVAL;
76860 + } else
76861 +#endif
76862 +
76863 + if (end > TASK_SIZE)
76864 + return -EINVAL;
76865 +
76866 if (!arch_validate_prot(prot))
76867 return -EINVAL;
76868
76869 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76870 /*
76871 * Does the application expect PROT_READ to imply PROT_EXEC:
76872 */
76873 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76874 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76875 prot |= PROT_EXEC;
76876
76877 vm_flags = calc_vm_prot_bits(prot);
76878 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76879 if (start > vma->vm_start)
76880 prev = vma;
76881
76882 +#ifdef CONFIG_PAX_MPROTECT
76883 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
76884 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
76885 +#endif
76886 +
76887 for (nstart = start ; ; ) {
76888 unsigned long newflags;
76889
76890 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76891
76892 /* newflags >> 4 shift VM_MAY% in place of VM_% */
76893 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
76894 + if (prot & (PROT_WRITE | PROT_EXEC))
76895 + gr_log_rwxmprotect(vma->vm_file);
76896 +
76897 + error = -EACCES;
76898 + goto out;
76899 + }
76900 +
76901 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
76902 error = -EACCES;
76903 goto out;
76904 }
76905 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76906 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
76907 if (error)
76908 goto out;
76909 +
76910 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
76911 +
76912 nstart = tmp;
76913
76914 if (nstart < prev->vm_end)
76915 diff --git a/mm/mremap.c b/mm/mremap.c
76916 index 1b61c2d..1cc0e3c 100644
76917 --- a/mm/mremap.c
76918 +++ b/mm/mremap.c
76919 @@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
76920 continue;
76921 pte = ptep_get_and_clear(mm, old_addr, old_pte);
76922 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
76923 +
76924 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76925 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
76926 + pte = pte_exprotect(pte);
76927 +#endif
76928 +
76929 set_pte_at(mm, new_addr, new_pte, pte);
76930 }
76931
76932 @@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
76933 if (is_vm_hugetlb_page(vma))
76934 goto Einval;
76935
76936 +#ifdef CONFIG_PAX_SEGMEXEC
76937 + if (pax_find_mirror_vma(vma))
76938 + goto Einval;
76939 +#endif
76940 +
76941 /* We can't remap across vm area boundaries */
76942 if (old_len > vma->vm_end - addr)
76943 goto Efault;
76944 @@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
76945 unsigned long ret = -EINVAL;
76946 unsigned long charged = 0;
76947 unsigned long map_flags;
76948 + unsigned long pax_task_size = TASK_SIZE;
76949
76950 if (new_addr & ~PAGE_MASK)
76951 goto out;
76952
76953 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
76954 +#ifdef CONFIG_PAX_SEGMEXEC
76955 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
76956 + pax_task_size = SEGMEXEC_TASK_SIZE;
76957 +#endif
76958 +
76959 + pax_task_size -= PAGE_SIZE;
76960 +
76961 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
76962 goto out;
76963
76964 /* Check if the location we're moving into overlaps the
76965 * old location at all, and fail if it does.
76966 */
76967 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
76968 - goto out;
76969 -
76970 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
76971 + if (addr + old_len > new_addr && new_addr + new_len > addr)
76972 goto out;
76973
76974 ret = do_munmap(mm, new_addr, new_len);
76975 @@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76976 struct vm_area_struct *vma;
76977 unsigned long ret = -EINVAL;
76978 unsigned long charged = 0;
76979 + unsigned long pax_task_size = TASK_SIZE;
76980
76981 down_write(&current->mm->mmap_sem);
76982
76983 @@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76984 if (!new_len)
76985 goto out;
76986
76987 +#ifdef CONFIG_PAX_SEGMEXEC
76988 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
76989 + pax_task_size = SEGMEXEC_TASK_SIZE;
76990 +#endif
76991 +
76992 + pax_task_size -= PAGE_SIZE;
76993 +
76994 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
76995 + old_len > pax_task_size || addr > pax_task_size-old_len)
76996 + goto out;
76997 +
76998 if (flags & MREMAP_FIXED) {
76999 if (flags & MREMAP_MAYMOVE)
77000 ret = mremap_to(addr, old_len, new_addr, new_len);
77001 @@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77002 addr + new_len);
77003 }
77004 ret = addr;
77005 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
77006 goto out;
77007 }
77008 }
77009 @@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
77010 goto out;
77011 }
77012
77013 + map_flags = vma->vm_flags;
77014 ret = move_vma(vma, addr, old_len, new_len, new_addr);
77015 + if (!(ret & ~PAGE_MASK)) {
77016 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
77017 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
77018 + }
77019 }
77020 out:
77021 if (ret & ~PAGE_MASK)
77022 diff --git a/mm/nommu.c b/mm/nommu.c
77023 index 45131b4..c521665 100644
77024 --- a/mm/nommu.c
77025 +++ b/mm/nommu.c
77026 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
77027 int sysctl_overcommit_ratio = 50; /* default is 50% */
77028 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
77029 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
77030 -int heap_stack_gap = 0;
77031
77032 atomic_long_t mmap_pages_allocated;
77033
77034 @@ -824,15 +823,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
77035 EXPORT_SYMBOL(find_vma);
77036
77037 /*
77038 - * find a VMA
77039 - * - we don't extend stack VMAs under NOMMU conditions
77040 - */
77041 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
77042 -{
77043 - return find_vma(mm, addr);
77044 -}
77045 -
77046 -/*
77047 * expand a stack to a given address
77048 * - not supported under NOMMU conditions
77049 */
77050 @@ -1540,6 +1530,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77051
77052 /* most fields are the same, copy all, and then fixup */
77053 *new = *vma;
77054 + INIT_LIST_HEAD(&new->anon_vma_chain);
77055 *region = *vma->vm_region;
77056 new->vm_region = region;
77057
77058 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
77059 index ceb4168..d7774f2 100644
77060 --- a/mm/page_alloc.c
77061 +++ b/mm/page_alloc.c
77062 @@ -340,7 +340,7 @@ out:
77063 * This usage means that zero-order pages may not be compound.
77064 */
77065
77066 -static void free_compound_page(struct page *page)
77067 +void free_compound_page(struct page *page)
77068 {
77069 __free_pages_ok(page, compound_order(page));
77070 }
77071 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
77072 int i;
77073 int bad = 0;
77074
77075 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
77076 + unsigned long index = 1UL << order;
77077 +#endif
77078 +
77079 trace_mm_page_free(page, order);
77080 kmemcheck_free_shadow(page, order);
77081
77082 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
77083 debug_check_no_obj_freed(page_address(page),
77084 PAGE_SIZE << order);
77085 }
77086 +
77087 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
77088 + for (; index; --index)
77089 + sanitize_highpage(page + index - 1);
77090 +#endif
77091 +
77092 arch_free_page(page, order);
77093 kernel_map_pages(page, 1 << order, 0);
77094
77095 @@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
77096 arch_alloc_page(page, order);
77097 kernel_map_pages(page, 1 << order, 1);
77098
77099 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
77100 if (gfp_flags & __GFP_ZERO)
77101 prep_zero_page(page, order, gfp_flags);
77102 +#endif
77103
77104 if (order && (gfp_flags & __GFP_COMP))
77105 prep_compound_page(page, order);
77106 @@ -3684,7 +3696,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
77107 unsigned long pfn;
77108
77109 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
77110 +#ifdef CONFIG_X86_32
77111 + /* boot failures in VMware 8 on 32bit vanilla since
77112 + this change */
77113 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
77114 +#else
77115 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
77116 +#endif
77117 return 1;
77118 }
77119 return 0;
77120 diff --git a/mm/percpu.c b/mm/percpu.c
77121 index ddc5efb..f632d2c 100644
77122 --- a/mm/percpu.c
77123 +++ b/mm/percpu.c
77124 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
77125 static unsigned int pcpu_high_unit_cpu __read_mostly;
77126
77127 /* the address of the first chunk which starts with the kernel static area */
77128 -void *pcpu_base_addr __read_mostly;
77129 +void *pcpu_base_addr __read_only;
77130 EXPORT_SYMBOL_GPL(pcpu_base_addr);
77131
77132 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
77133 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
77134 index 926b466..b23df53 100644
77135 --- a/mm/process_vm_access.c
77136 +++ b/mm/process_vm_access.c
77137 @@ -13,6 +13,7 @@
77138 #include <linux/uio.h>
77139 #include <linux/sched.h>
77140 #include <linux/highmem.h>
77141 +#include <linux/security.h>
77142 #include <linux/ptrace.h>
77143 #include <linux/slab.h>
77144 #include <linux/syscalls.h>
77145 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
77146 size_t iov_l_curr_offset = 0;
77147 ssize_t iov_len;
77148
77149 + return -ENOSYS; // PaX: until properly audited
77150 +
77151 /*
77152 * Work out how many pages of struct pages we're going to need
77153 * when eventually calling get_user_pages
77154 */
77155 for (i = 0; i < riovcnt; i++) {
77156 iov_len = rvec[i].iov_len;
77157 - if (iov_len > 0) {
77158 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
77159 - + iov_len)
77160 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
77161 - / PAGE_SIZE + 1;
77162 - nr_pages = max(nr_pages, nr_pages_iov);
77163 - }
77164 + if (iov_len <= 0)
77165 + continue;
77166 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
77167 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
77168 + nr_pages = max(nr_pages, nr_pages_iov);
77169 }
77170
77171 if (nr_pages == 0)
77172 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
77173 goto free_proc_pages;
77174 }
77175
77176 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
77177 + rc = -EPERM;
77178 + goto put_task_struct;
77179 + }
77180 +
77181 mm = mm_access(task, PTRACE_MODE_ATTACH);
77182 if (!mm || IS_ERR(mm)) {
77183 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
77184 diff --git a/mm/rmap.c b/mm/rmap.c
77185 index 2ee1ef0..2e175ba 100644
77186 --- a/mm/rmap.c
77187 +++ b/mm/rmap.c
77188 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77189 struct anon_vma *anon_vma = vma->anon_vma;
77190 struct anon_vma_chain *avc;
77191
77192 +#ifdef CONFIG_PAX_SEGMEXEC
77193 + struct anon_vma_chain *avc_m = NULL;
77194 +#endif
77195 +
77196 might_sleep();
77197 if (unlikely(!anon_vma)) {
77198 struct mm_struct *mm = vma->vm_mm;
77199 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77200 if (!avc)
77201 goto out_enomem;
77202
77203 +#ifdef CONFIG_PAX_SEGMEXEC
77204 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
77205 + if (!avc_m)
77206 + goto out_enomem_free_avc;
77207 +#endif
77208 +
77209 anon_vma = find_mergeable_anon_vma(vma);
77210 allocated = NULL;
77211 if (!anon_vma) {
77212 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77213 /* page_table_lock to protect against threads */
77214 spin_lock(&mm->page_table_lock);
77215 if (likely(!vma->anon_vma)) {
77216 +
77217 +#ifdef CONFIG_PAX_SEGMEXEC
77218 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
77219 +
77220 + if (vma_m) {
77221 + BUG_ON(vma_m->anon_vma);
77222 + vma_m->anon_vma = anon_vma;
77223 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
77224 + avc_m = NULL;
77225 + }
77226 +#endif
77227 +
77228 vma->anon_vma = anon_vma;
77229 anon_vma_chain_link(vma, avc, anon_vma);
77230 allocated = NULL;
77231 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
77232
77233 if (unlikely(allocated))
77234 put_anon_vma(allocated);
77235 +
77236 +#ifdef CONFIG_PAX_SEGMEXEC
77237 + if (unlikely(avc_m))
77238 + anon_vma_chain_free(avc_m);
77239 +#endif
77240 +
77241 if (unlikely(avc))
77242 anon_vma_chain_free(avc);
77243 }
77244 return 0;
77245
77246 out_enomem_free_avc:
77247 +
77248 +#ifdef CONFIG_PAX_SEGMEXEC
77249 + if (avc_m)
77250 + anon_vma_chain_free(avc_m);
77251 +#endif
77252 +
77253 anon_vma_chain_free(avc);
77254 out_enomem:
77255 return -ENOMEM;
77256 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
77257 * Attach the anon_vmas from src to dst.
77258 * Returns 0 on success, -ENOMEM on failure.
77259 */
77260 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
77261 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
77262 {
77263 struct anon_vma_chain *avc, *pavc;
77264 struct anon_vma *root = NULL;
77265 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
77266 * the corresponding VMA in the parent process is attached to.
77267 * Returns 0 on success, non-zero on failure.
77268 */
77269 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
77270 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
77271 {
77272 struct anon_vma_chain *avc;
77273 struct anon_vma *anon_vma;
77274 diff --git a/mm/shmem.c b/mm/shmem.c
77275 index 50c5b8f..0bc87f7 100644
77276 --- a/mm/shmem.c
77277 +++ b/mm/shmem.c
77278 @@ -31,7 +31,7 @@
77279 #include <linux/export.h>
77280 #include <linux/swap.h>
77281
77282 -static struct vfsmount *shm_mnt;
77283 +struct vfsmount *shm_mnt;
77284
77285 #ifdef CONFIG_SHMEM
77286 /*
77287 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
77288 #define BOGO_DIRENT_SIZE 20
77289
77290 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
77291 -#define SHORT_SYMLINK_LEN 128
77292 +#define SHORT_SYMLINK_LEN 64
77293
77294 /*
77295 * shmem_fallocate and shmem_writepage communicate via inode->i_private
77296 @@ -2112,6 +2112,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
77297 static int shmem_xattr_validate(const char *name)
77298 {
77299 struct { const char *prefix; size_t len; } arr[] = {
77300 +
77301 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77302 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
77303 +#endif
77304 +
77305 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
77306 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
77307 };
77308 @@ -2167,6 +2172,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
77309 if (err)
77310 return err;
77311
77312 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77313 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
77314 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
77315 + return -EOPNOTSUPP;
77316 + if (size > 8)
77317 + return -EINVAL;
77318 + }
77319 +#endif
77320 +
77321 return simple_xattr_set(&info->xattrs, name, value, size, flags);
77322 }
77323
77324 @@ -2466,8 +2480,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
77325 int err = -ENOMEM;
77326
77327 /* Round up to L1_CACHE_BYTES to resist false sharing */
77328 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
77329 - L1_CACHE_BYTES), GFP_KERNEL);
77330 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
77331 if (!sbinfo)
77332 return -ENOMEM;
77333
77334 diff --git a/mm/slab.c b/mm/slab.c
77335 index 33d3363..3851c61 100644
77336 --- a/mm/slab.c
77337 +++ b/mm/slab.c
77338 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
77339
77340 /* Legal flag mask for kmem_cache_create(). */
77341 #if DEBUG
77342 -# define CREATE_MASK (SLAB_RED_ZONE | \
77343 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
77344 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
77345 SLAB_CACHE_DMA | \
77346 SLAB_STORE_USER | \
77347 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
77348 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
77349 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
77350 #else
77351 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
77352 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
77353 SLAB_CACHE_DMA | \
77354 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
77355 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
77356 @@ -322,7 +322,7 @@ struct kmem_list3 {
77357 * Need this for bootstrapping a per node allocator.
77358 */
77359 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
77360 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
77361 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
77362 #define CACHE_CACHE 0
77363 #define SIZE_AC MAX_NUMNODES
77364 #define SIZE_L3 (2 * MAX_NUMNODES)
77365 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
77366 if ((x)->max_freeable < i) \
77367 (x)->max_freeable = i; \
77368 } while (0)
77369 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
77370 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
77371 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
77372 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
77373 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
77374 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
77375 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
77376 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
77377 #else
77378 #define STATS_INC_ACTIVE(x) do { } while (0)
77379 #define STATS_DEC_ACTIVE(x) do { } while (0)
77380 @@ -534,7 +534,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
77381 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
77382 */
77383 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
77384 - const struct slab *slab, void *obj)
77385 + const struct slab *slab, const void *obj)
77386 {
77387 u32 offset = (obj - slab->s_mem);
77388 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
77389 @@ -555,12 +555,13 @@ EXPORT_SYMBOL(malloc_sizes);
77390 struct cache_names {
77391 char *name;
77392 char *name_dma;
77393 + char *name_usercopy;
77394 };
77395
77396 static struct cache_names __initdata cache_names[] = {
77397 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
77398 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
77399 #include <linux/kmalloc_sizes.h>
77400 - {NULL,}
77401 + {NULL}
77402 #undef CACHE
77403 };
77404
77405 @@ -721,6 +722,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
77406 if (unlikely(gfpflags & GFP_DMA))
77407 return csizep->cs_dmacachep;
77408 #endif
77409 +
77410 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77411 + if (unlikely(gfpflags & GFP_USERCOPY))
77412 + return csizep->cs_usercopycachep;
77413 +#endif
77414 +
77415 return csizep->cs_cachep;
77416 }
77417
77418 @@ -1676,7 +1683,7 @@ void __init kmem_cache_init(void)
77419 sizes[INDEX_AC].cs_cachep->size = sizes[INDEX_AC].cs_size;
77420 sizes[INDEX_AC].cs_cachep->object_size = sizes[INDEX_AC].cs_size;
77421 sizes[INDEX_AC].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77422 - __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77423 + __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77424 list_add(&sizes[INDEX_AC].cs_cachep->list, &slab_caches);
77425
77426 if (INDEX_AC != INDEX_L3) {
77427 @@ -1685,7 +1692,7 @@ void __init kmem_cache_init(void)
77428 sizes[INDEX_L3].cs_cachep->size = sizes[INDEX_L3].cs_size;
77429 sizes[INDEX_L3].cs_cachep->object_size = sizes[INDEX_L3].cs_size;
77430 sizes[INDEX_L3].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77431 - __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77432 + __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77433 list_add(&sizes[INDEX_L3].cs_cachep->list, &slab_caches);
77434 }
77435
77436 @@ -1705,7 +1712,7 @@ void __init kmem_cache_init(void)
77437 sizes->cs_cachep->size = sizes->cs_size;
77438 sizes->cs_cachep->object_size = sizes->cs_size;
77439 sizes->cs_cachep->align = ARCH_KMALLOC_MINALIGN;
77440 - __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77441 + __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77442 list_add(&sizes->cs_cachep->list, &slab_caches);
77443 }
77444 #ifdef CONFIG_ZONE_DMA
77445 @@ -1718,6 +1725,17 @@ void __init kmem_cache_init(void)
77446 ARCH_KMALLOC_FLAGS|SLAB_CACHE_DMA| SLAB_PANIC);
77447 list_add(&sizes->cs_dmacachep->list, &slab_caches);
77448 #endif
77449 +
77450 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77451 + sizes->cs_usercopycachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
77452 + sizes->cs_usercopycachep->name = names->name_usercopy;
77453 + sizes->cs_usercopycachep->size = sizes->cs_size;
77454 + sizes->cs_usercopycachep->object_size = sizes->cs_size;
77455 + sizes->cs_usercopycachep->align = ARCH_KMALLOC_MINALIGN;
77456 + __kmem_cache_create(sizes->cs_usercopycachep, ARCH_KMALLOC_FLAGS| SLAB_PANIC|SLAB_USERCOPY);
77457 + list_add(&sizes->cs_usercopycachep->list, &slab_caches);
77458 +#endif
77459 +
77460 sizes++;
77461 names++;
77462 }
77463 @@ -4405,10 +4423,10 @@ static int s_show(struct seq_file *m, void *p)
77464 }
77465 /* cpu stats */
77466 {
77467 - unsigned long allochit = atomic_read(&cachep->allochit);
77468 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
77469 - unsigned long freehit = atomic_read(&cachep->freehit);
77470 - unsigned long freemiss = atomic_read(&cachep->freemiss);
77471 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
77472 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
77473 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
77474 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
77475
77476 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
77477 allochit, allocmiss, freehit, freemiss);
77478 @@ -4667,13 +4685,71 @@ static int __init slab_proc_init(void)
77479 {
77480 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
77481 #ifdef CONFIG_DEBUG_SLAB_LEAK
77482 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
77483 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
77484 #endif
77485 return 0;
77486 }
77487 module_init(slab_proc_init);
77488 #endif
77489
77490 +bool is_usercopy_object(const void *ptr)
77491 +{
77492 + struct page *page;
77493 + struct kmem_cache *cachep;
77494 +
77495 + if (ZERO_OR_NULL_PTR(ptr))
77496 + return false;
77497 +
77498 + if (!slab_is_available())
77499 + return false;
77500 +
77501 + if (!virt_addr_valid(ptr))
77502 + return false;
77503 +
77504 + page = virt_to_head_page(ptr);
77505 +
77506 + if (!PageSlab(page))
77507 + return false;
77508 +
77509 + cachep = page->slab_cache;
77510 + return cachep->flags & SLAB_USERCOPY;
77511 +}
77512 +
77513 +#ifdef CONFIG_PAX_USERCOPY
77514 +const char *check_heap_object(const void *ptr, unsigned long n)
77515 +{
77516 + struct page *page;
77517 + struct kmem_cache *cachep;
77518 + struct slab *slabp;
77519 + unsigned int objnr;
77520 + unsigned long offset;
77521 +
77522 + if (ZERO_OR_NULL_PTR(ptr))
77523 + return "<null>";
77524 +
77525 + if (!virt_addr_valid(ptr))
77526 + return NULL;
77527 +
77528 + page = virt_to_head_page(ptr);
77529 +
77530 + if (!PageSlab(page))
77531 + return NULL;
77532 +
77533 + cachep = page->slab_cache;
77534 + if (!(cachep->flags & SLAB_USERCOPY))
77535 + return cachep->name;
77536 +
77537 + slabp = page->slab_page;
77538 + objnr = obj_to_index(cachep, slabp, ptr);
77539 + BUG_ON(objnr >= cachep->num);
77540 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
77541 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
77542 + return NULL;
77543 +
77544 + return cachep->name;
77545 +}
77546 +#endif
77547 +
77548 /**
77549 * ksize - get the actual amount of memory allocated for a given object
77550 * @objp: Pointer to the object
77551 diff --git a/mm/slab_common.c b/mm/slab_common.c
77552 index 069a24e6..226a310 100644
77553 --- a/mm/slab_common.c
77554 +++ b/mm/slab_common.c
77555 @@ -127,7 +127,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align
77556 err = __kmem_cache_create(s, flags);
77557 if (!err) {
77558
77559 - s->refcount = 1;
77560 + atomic_set(&s->refcount, 1);
77561 list_add(&s->list, &slab_caches);
77562
77563 } else {
77564 @@ -163,8 +163,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
77565 {
77566 get_online_cpus();
77567 mutex_lock(&slab_mutex);
77568 - s->refcount--;
77569 - if (!s->refcount) {
77570 + if (atomic_dec_and_test(&s->refcount)) {
77571 list_del(&s->list);
77572
77573 if (!__kmem_cache_shutdown(s)) {
77574 diff --git a/mm/slob.c b/mm/slob.c
77575 index 1e921c5..1ce12c2 100644
77576 --- a/mm/slob.c
77577 +++ b/mm/slob.c
77578 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
77579 /*
77580 * Return the size of a slob block.
77581 */
77582 -static slobidx_t slob_units(slob_t *s)
77583 +static slobidx_t slob_units(const slob_t *s)
77584 {
77585 if (s->units > 0)
77586 return s->units;
77587 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
77588 /*
77589 * Return the next free slob block pointer after this one.
77590 */
77591 -static slob_t *slob_next(slob_t *s)
77592 +static slob_t *slob_next(const slob_t *s)
77593 {
77594 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
77595 slobidx_t next;
77596 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
77597 /*
77598 * Returns true if s is the last free block in its page.
77599 */
77600 -static int slob_last(slob_t *s)
77601 +static int slob_last(const slob_t *s)
77602 {
77603 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
77604 }
77605
77606 -static void *slob_new_pages(gfp_t gfp, int order, int node)
77607 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
77608 {
77609 - void *page;
77610 + struct page *page;
77611
77612 #ifdef CONFIG_NUMA
77613 if (node != NUMA_NO_NODE)
77614 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
77615 if (!page)
77616 return NULL;
77617
77618 - return page_address(page);
77619 + __SetPageSlab(page);
77620 + return page;
77621 }
77622
77623 -static void slob_free_pages(void *b, int order)
77624 +static void slob_free_pages(struct page *sp, int order)
77625 {
77626 if (current->reclaim_state)
77627 current->reclaim_state->reclaimed_slab += 1 << order;
77628 - free_pages((unsigned long)b, order);
77629 + __ClearPageSlab(sp);
77630 + reset_page_mapcount(sp);
77631 + sp->private = 0;
77632 + __free_pages(sp, order);
77633 }
77634
77635 /*
77636 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
77637
77638 /* Not enough space: must allocate a new page */
77639 if (!b) {
77640 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
77641 - if (!b)
77642 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
77643 + if (!sp)
77644 return NULL;
77645 - sp = virt_to_page(b);
77646 - __SetPageSlab(sp);
77647 + b = page_address(sp);
77648
77649 spin_lock_irqsave(&slob_lock, flags);
77650 sp->units = SLOB_UNITS(PAGE_SIZE);
77651 sp->freelist = b;
77652 + sp->private = 0;
77653 INIT_LIST_HEAD(&sp->list);
77654 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
77655 set_slob_page_free(sp, slob_list);
77656 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
77657 if (slob_page_free(sp))
77658 clear_slob_page_free(sp);
77659 spin_unlock_irqrestore(&slob_lock, flags);
77660 - __ClearPageSlab(sp);
77661 - reset_page_mapcount(sp);
77662 - slob_free_pages(b, 0);
77663 + slob_free_pages(sp, 0);
77664 return;
77665 }
77666
77667 @@ -426,11 +428,10 @@ out:
77668 */
77669
77670 static __always_inline void *
77671 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77672 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
77673 {
77674 - unsigned int *m;
77675 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77676 - void *ret;
77677 + slob_t *m;
77678 + void *ret = NULL;
77679
77680 gfp &= gfp_allowed_mask;
77681
77682 @@ -444,20 +445,23 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77683
77684 if (!m)
77685 return NULL;
77686 - *m = size;
77687 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
77688 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
77689 + m[0].units = size;
77690 + m[1].units = align;
77691 ret = (void *)m + align;
77692
77693 trace_kmalloc_node(caller, ret,
77694 size, size + align, gfp, node);
77695 } else {
77696 unsigned int order = get_order(size);
77697 + struct page *page;
77698
77699 if (likely(order))
77700 gfp |= __GFP_COMP;
77701 - ret = slob_new_pages(gfp, order, node);
77702 - if (ret) {
77703 - struct page *page;
77704 - page = virt_to_page(ret);
77705 + page = slob_new_pages(gfp, order, node);
77706 + if (page) {
77707 + ret = page_address(page);
77708 page->private = size;
77709 }
77710
77711 @@ -465,7 +469,17 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77712 size, PAGE_SIZE << order, gfp, node);
77713 }
77714
77715 - kmemleak_alloc(ret, size, 1, gfp);
77716 + return ret;
77717 +}
77718 +
77719 +static __always_inline void *
77720 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77721 +{
77722 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77723 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
77724 +
77725 + if (!ZERO_OR_NULL_PTR(ret))
77726 + kmemleak_alloc(ret, size, 1, gfp);
77727 return ret;
77728 }
77729
77730 @@ -501,15 +515,91 @@ void kfree(const void *block)
77731 kmemleak_free(block);
77732
77733 sp = virt_to_page(block);
77734 - if (PageSlab(sp)) {
77735 + VM_BUG_ON(!PageSlab(sp));
77736 + if (!sp->private) {
77737 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77738 - unsigned int *m = (unsigned int *)(block - align);
77739 - slob_free(m, *m + align);
77740 - } else
77741 + slob_t *m = (slob_t *)(block - align);
77742 + slob_free(m, m[0].units + align);
77743 + } else {
77744 + __ClearPageSlab(sp);
77745 + reset_page_mapcount(sp);
77746 + sp->private = 0;
77747 put_page(sp);
77748 + }
77749 }
77750 EXPORT_SYMBOL(kfree);
77751
77752 +bool is_usercopy_object(const void *ptr)
77753 +{
77754 + if (!slab_is_available())
77755 + return false;
77756 +
77757 + // PAX: TODO
77758 +
77759 + return false;
77760 +}
77761 +
77762 +#ifdef CONFIG_PAX_USERCOPY
77763 +const char *check_heap_object(const void *ptr, unsigned long n)
77764 +{
77765 + struct page *page;
77766 + const slob_t *free;
77767 + const void *base;
77768 + unsigned long flags;
77769 +
77770 + if (ZERO_OR_NULL_PTR(ptr))
77771 + return "<null>";
77772 +
77773 + if (!virt_addr_valid(ptr))
77774 + return NULL;
77775 +
77776 + page = virt_to_head_page(ptr);
77777 + if (!PageSlab(page))
77778 + return NULL;
77779 +
77780 + if (page->private) {
77781 + base = page;
77782 + if (base <= ptr && n <= page->private - (ptr - base))
77783 + return NULL;
77784 + return "<slob>";
77785 + }
77786 +
77787 + /* some tricky double walking to find the chunk */
77788 + spin_lock_irqsave(&slob_lock, flags);
77789 + base = (void *)((unsigned long)ptr & PAGE_MASK);
77790 + free = page->freelist;
77791 +
77792 + while (!slob_last(free) && (void *)free <= ptr) {
77793 + base = free + slob_units(free);
77794 + free = slob_next(free);
77795 + }
77796 +
77797 + while (base < (void *)free) {
77798 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
77799 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
77800 + int offset;
77801 +
77802 + if (ptr < base + align)
77803 + break;
77804 +
77805 + offset = ptr - base - align;
77806 + if (offset >= m) {
77807 + base += size;
77808 + continue;
77809 + }
77810 +
77811 + if (n > m - offset)
77812 + break;
77813 +
77814 + spin_unlock_irqrestore(&slob_lock, flags);
77815 + return NULL;
77816 + }
77817 +
77818 + spin_unlock_irqrestore(&slob_lock, flags);
77819 + return "<slob>";
77820 +}
77821 +#endif
77822 +
77823 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
77824 size_t ksize(const void *block)
77825 {
77826 @@ -520,10 +610,11 @@ size_t ksize(const void *block)
77827 return 0;
77828
77829 sp = virt_to_page(block);
77830 - if (PageSlab(sp)) {
77831 + VM_BUG_ON(!PageSlab(sp));
77832 + if (!sp->private) {
77833 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77834 - unsigned int *m = (unsigned int *)(block - align);
77835 - return SLOB_UNITS(*m) * SLOB_UNIT;
77836 + slob_t *m = (slob_t *)(block - align);
77837 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
77838 } else
77839 return sp->private;
77840 }
77841 @@ -550,23 +641,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
77842
77843 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
77844 {
77845 - void *b;
77846 + void *b = NULL;
77847
77848 flags &= gfp_allowed_mask;
77849
77850 lockdep_trace_alloc(flags);
77851
77852 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77853 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
77854 +#else
77855 if (c->size < PAGE_SIZE) {
77856 b = slob_alloc(c->size, flags, c->align, node);
77857 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
77858 SLOB_UNITS(c->size) * SLOB_UNIT,
77859 flags, node);
77860 } else {
77861 - b = slob_new_pages(flags, get_order(c->size), node);
77862 + struct page *sp;
77863 +
77864 + sp = slob_new_pages(flags, get_order(c->size), node);
77865 + if (sp) {
77866 + b = page_address(sp);
77867 + sp->private = c->size;
77868 + }
77869 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
77870 PAGE_SIZE << get_order(c->size),
77871 flags, node);
77872 }
77873 +#endif
77874
77875 if (c->ctor)
77876 c->ctor(b);
77877 @@ -578,10 +679,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
77878
77879 static void __kmem_cache_free(void *b, int size)
77880 {
77881 - if (size < PAGE_SIZE)
77882 + struct page *sp;
77883 +
77884 + sp = virt_to_page(b);
77885 + BUG_ON(!PageSlab(sp));
77886 + if (!sp->private)
77887 slob_free(b, size);
77888 else
77889 - slob_free_pages(b, get_order(size));
77890 + slob_free_pages(sp, get_order(size));
77891 }
77892
77893 static void kmem_rcu_free(struct rcu_head *head)
77894 @@ -594,17 +699,31 @@ static void kmem_rcu_free(struct rcu_head *head)
77895
77896 void kmem_cache_free(struct kmem_cache *c, void *b)
77897 {
77898 + int size = c->size;
77899 +
77900 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77901 + if (size + c->align < PAGE_SIZE) {
77902 + size += c->align;
77903 + b -= c->align;
77904 + }
77905 +#endif
77906 +
77907 kmemleak_free_recursive(b, c->flags);
77908 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
77909 struct slob_rcu *slob_rcu;
77910 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
77911 - slob_rcu->size = c->size;
77912 + slob_rcu = b + (size - sizeof(struct slob_rcu));
77913 + slob_rcu->size = size;
77914 call_rcu(&slob_rcu->head, kmem_rcu_free);
77915 } else {
77916 - __kmem_cache_free(b, c->size);
77917 + __kmem_cache_free(b, size);
77918 }
77919
77920 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77921 + trace_kfree(_RET_IP_, b);
77922 +#else
77923 trace_kmem_cache_free(_RET_IP_, b);
77924 +#endif
77925 +
77926 }
77927 EXPORT_SYMBOL(kmem_cache_free);
77928
77929 diff --git a/mm/slub.c b/mm/slub.c
77930 index 321afab..9595170 100644
77931 --- a/mm/slub.c
77932 +++ b/mm/slub.c
77933 @@ -201,7 +201,7 @@ struct track {
77934
77935 enum track_item { TRACK_ALLOC, TRACK_FREE };
77936
77937 -#ifdef CONFIG_SYSFS
77938 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77939 static int sysfs_slab_add(struct kmem_cache *);
77940 static int sysfs_slab_alias(struct kmem_cache *, const char *);
77941 static void sysfs_slab_remove(struct kmem_cache *);
77942 @@ -521,7 +521,7 @@ static void print_track(const char *s, struct track *t)
77943 if (!t->addr)
77944 return;
77945
77946 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
77947 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
77948 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
77949 #ifdef CONFIG_STACKTRACE
77950 {
77951 @@ -2623,6 +2623,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
77952
77953 page = virt_to_head_page(x);
77954
77955 + BUG_ON(!PageSlab(page));
77956 +
77957 if (kmem_cache_debug(s) && page->slab != s) {
77958 pr_err("kmem_cache_free: Wrong slab cache. %s but object"
77959 " is from %s\n", page->slab->name, s->name);
77960 @@ -2663,7 +2665,7 @@ static int slub_min_objects;
77961 * Merge control. If this is set then no merging of slab caches will occur.
77962 * (Could be removed. This was introduced to pacify the merge skeptics.)
77963 */
77964 -static int slub_nomerge;
77965 +static int slub_nomerge = 1;
77966
77967 /*
77968 * Calculate the order of allocation given an slab object size.
77969 @@ -3225,6 +3227,10 @@ EXPORT_SYMBOL(kmalloc_caches);
77970 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
77971 #endif
77972
77973 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77974 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
77975 +#endif
77976 +
77977 static int __init setup_slub_min_order(char *str)
77978 {
77979 get_option(&str, &slub_min_order);
77980 @@ -3279,7 +3285,7 @@ static struct kmem_cache *__init create_kmalloc_cache(const char *name,
77981 if (kmem_cache_open(s, flags))
77982 goto panic;
77983
77984 - s->refcount = 1;
77985 + atomic_set(&s->refcount, 1);
77986 list_add(&s->list, &slab_caches);
77987 return s;
77988
77989 @@ -3343,6 +3349,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
77990 return kmalloc_dma_caches[index];
77991
77992 #endif
77993 +
77994 +#ifdef CONFIG_PAX_USERCOPY_SLABS
77995 + if (flags & SLAB_USERCOPY)
77996 + return kmalloc_usercopy_caches[index];
77997 +
77998 +#endif
77999 +
78000 return kmalloc_caches[index];
78001 }
78002
78003 @@ -3411,6 +3424,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
78004 EXPORT_SYMBOL(__kmalloc_node);
78005 #endif
78006
78007 +bool is_usercopy_object(const void *ptr)
78008 +{
78009 + struct page *page;
78010 + struct kmem_cache *s;
78011 +
78012 + if (ZERO_OR_NULL_PTR(ptr))
78013 + return false;
78014 +
78015 + if (!slab_is_available())
78016 + return false;
78017 +
78018 + if (!virt_addr_valid(ptr))
78019 + return false;
78020 +
78021 + page = virt_to_head_page(ptr);
78022 +
78023 + if (!PageSlab(page))
78024 + return false;
78025 +
78026 + s = page->slab;
78027 + return s->flags & SLAB_USERCOPY;
78028 +}
78029 +
78030 +#ifdef CONFIG_PAX_USERCOPY
78031 +const char *check_heap_object(const void *ptr, unsigned long n)
78032 +{
78033 + struct page *page;
78034 + struct kmem_cache *s;
78035 + unsigned long offset;
78036 +
78037 + if (ZERO_OR_NULL_PTR(ptr))
78038 + return "<null>";
78039 +
78040 + if (!virt_addr_valid(ptr))
78041 + return NULL;
78042 +
78043 + page = virt_to_head_page(ptr);
78044 +
78045 + if (!PageSlab(page))
78046 + return NULL;
78047 +
78048 + s = page->slab;
78049 + if (!(s->flags & SLAB_USERCOPY))
78050 + return s->name;
78051 +
78052 + offset = (ptr - page_address(page)) % s->size;
78053 + if (offset <= s->object_size && n <= s->object_size - offset)
78054 + return NULL;
78055 +
78056 + return s->name;
78057 +}
78058 +#endif
78059 +
78060 size_t ksize(const void *object)
78061 {
78062 struct page *page;
78063 @@ -3685,7 +3751,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
78064 int node;
78065
78066 list_add(&s->list, &slab_caches);
78067 - s->refcount = -1;
78068 + atomic_set(&s->refcount, -1);
78069
78070 for_each_node_state(node, N_NORMAL_MEMORY) {
78071 struct kmem_cache_node *n = get_node(s, node);
78072 @@ -3808,17 +3874,17 @@ void __init kmem_cache_init(void)
78073
78074 /* Caches that are not of the two-to-the-power-of size */
78075 if (KMALLOC_MIN_SIZE <= 32) {
78076 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
78077 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
78078 caches++;
78079 }
78080
78081 if (KMALLOC_MIN_SIZE <= 64) {
78082 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
78083 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
78084 caches++;
78085 }
78086
78087 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
78088 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
78089 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
78090 caches++;
78091 }
78092
78093 @@ -3860,6 +3926,22 @@ void __init kmem_cache_init(void)
78094 }
78095 }
78096 #endif
78097 +
78098 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78099 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
78100 + struct kmem_cache *s = kmalloc_caches[i];
78101 +
78102 + if (s && s->size) {
78103 + char *name = kasprintf(GFP_NOWAIT,
78104 + "usercopy-kmalloc-%d", s->object_size);
78105 +
78106 + BUG_ON(!name);
78107 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
78108 + s->object_size, SLAB_USERCOPY);
78109 + }
78110 + }
78111 +#endif
78112 +
78113 printk(KERN_INFO
78114 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
78115 " CPUs=%d, Nodes=%d\n",
78116 @@ -3886,7 +3968,7 @@ static int slab_unmergeable(struct kmem_cache *s)
78117 /*
78118 * We may have set a slab to be unmergeable during bootstrap.
78119 */
78120 - if (s->refcount < 0)
78121 + if (atomic_read(&s->refcount) < 0)
78122 return 1;
78123
78124 return 0;
78125 @@ -3940,7 +4022,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
78126
78127 s = find_mergeable(size, align, flags, name, ctor);
78128 if (s) {
78129 - s->refcount++;
78130 + atomic_inc(&s->refcount);
78131 /*
78132 * Adjust the object sizes so that we clear
78133 * the complete object on kzalloc.
78134 @@ -3949,7 +4031,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
78135 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
78136
78137 if (sysfs_slab_alias(s, name)) {
78138 - s->refcount--;
78139 + atomic_dec(&s->refcount);
78140 s = NULL;
78141 }
78142 }
78143 @@ -4064,7 +4146,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
78144 }
78145 #endif
78146
78147 -#ifdef CONFIG_SYSFS
78148 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78149 static int count_inuse(struct page *page)
78150 {
78151 return page->inuse;
78152 @@ -4451,12 +4533,12 @@ static void resiliency_test(void)
78153 validate_slab_cache(kmalloc_caches[9]);
78154 }
78155 #else
78156 -#ifdef CONFIG_SYSFS
78157 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78158 static void resiliency_test(void) {};
78159 #endif
78160 #endif
78161
78162 -#ifdef CONFIG_SYSFS
78163 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78164 enum slab_stat_type {
78165 SL_ALL, /* All slabs */
78166 SL_PARTIAL, /* Only partially allocated slabs */
78167 @@ -4700,7 +4782,7 @@ SLAB_ATTR_RO(ctor);
78168
78169 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
78170 {
78171 - return sprintf(buf, "%d\n", s->refcount - 1);
78172 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
78173 }
78174 SLAB_ATTR_RO(aliases);
78175
78176 @@ -5262,6 +5344,7 @@ static char *create_unique_id(struct kmem_cache *s)
78177 return name;
78178 }
78179
78180 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78181 static int sysfs_slab_add(struct kmem_cache *s)
78182 {
78183 int err;
78184 @@ -5324,6 +5407,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
78185 kobject_del(&s->kobj);
78186 kobject_put(&s->kobj);
78187 }
78188 +#endif
78189
78190 /*
78191 * Need to buffer aliases during bootup until sysfs becomes
78192 @@ -5337,6 +5421,7 @@ struct saved_alias {
78193
78194 static struct saved_alias *alias_list;
78195
78196 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
78197 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78198 {
78199 struct saved_alias *al;
78200 @@ -5359,6 +5444,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
78201 alias_list = al;
78202 return 0;
78203 }
78204 +#endif
78205
78206 static int __init slab_sysfs_init(void)
78207 {
78208 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
78209 index 1b7e22a..3fcd4f3 100644
78210 --- a/mm/sparse-vmemmap.c
78211 +++ b/mm/sparse-vmemmap.c
78212 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
78213 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
78214 if (!p)
78215 return NULL;
78216 - pud_populate(&init_mm, pud, p);
78217 + pud_populate_kernel(&init_mm, pud, p);
78218 }
78219 return pud;
78220 }
78221 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
78222 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
78223 if (!p)
78224 return NULL;
78225 - pgd_populate(&init_mm, pgd, p);
78226 + pgd_populate_kernel(&init_mm, pgd, p);
78227 }
78228 return pgd;
78229 }
78230 diff --git a/mm/swap.c b/mm/swap.c
78231 index 6310dc2..3662b3f 100644
78232 --- a/mm/swap.c
78233 +++ b/mm/swap.c
78234 @@ -30,6 +30,7 @@
78235 #include <linux/backing-dev.h>
78236 #include <linux/memcontrol.h>
78237 #include <linux/gfp.h>
78238 +#include <linux/hugetlb.h>
78239
78240 #include "internal.h"
78241
78242 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
78243
78244 __page_cache_release(page);
78245 dtor = get_compound_page_dtor(page);
78246 + if (!PageHuge(page))
78247 + BUG_ON(dtor != free_compound_page);
78248 (*dtor)(page);
78249 }
78250
78251 diff --git a/mm/swapfile.c b/mm/swapfile.c
78252 index f91a255..9dcac21 100644
78253 --- a/mm/swapfile.c
78254 +++ b/mm/swapfile.c
78255 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
78256
78257 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
78258 /* Activity counter to indicate that a swapon or swapoff has occurred */
78259 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
78260 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
78261
78262 static inline unsigned char swap_count(unsigned char ent)
78263 {
78264 @@ -1601,7 +1601,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
78265 }
78266 filp_close(swap_file, NULL);
78267 err = 0;
78268 - atomic_inc(&proc_poll_event);
78269 + atomic_inc_unchecked(&proc_poll_event);
78270 wake_up_interruptible(&proc_poll_wait);
78271
78272 out_dput:
78273 @@ -1618,8 +1618,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
78274
78275 poll_wait(file, &proc_poll_wait, wait);
78276
78277 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
78278 - seq->poll_event = atomic_read(&proc_poll_event);
78279 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
78280 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
78281 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
78282 }
78283
78284 @@ -1717,7 +1717,7 @@ static int swaps_open(struct inode *inode, struct file *file)
78285 return ret;
78286
78287 seq = file->private_data;
78288 - seq->poll_event = atomic_read(&proc_poll_event);
78289 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
78290 return 0;
78291 }
78292
78293 @@ -2059,7 +2059,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
78294 (frontswap_map) ? "FS" : "");
78295
78296 mutex_unlock(&swapon_mutex);
78297 - atomic_inc(&proc_poll_event);
78298 + atomic_inc_unchecked(&proc_poll_event);
78299 wake_up_interruptible(&proc_poll_wait);
78300
78301 if (S_ISREG(inode->i_mode))
78302 diff --git a/mm/util.c b/mm/util.c
78303 index dc3036c..b6c7c9d 100644
78304 --- a/mm/util.c
78305 +++ b/mm/util.c
78306 @@ -292,6 +292,12 @@ done:
78307 void arch_pick_mmap_layout(struct mm_struct *mm)
78308 {
78309 mm->mmap_base = TASK_UNMAPPED_BASE;
78310 +
78311 +#ifdef CONFIG_PAX_RANDMMAP
78312 + if (mm->pax_flags & MF_PAX_RANDMMAP)
78313 + mm->mmap_base += mm->delta_mmap;
78314 +#endif
78315 +
78316 mm->get_unmapped_area = arch_get_unmapped_area;
78317 mm->unmap_area = arch_unmap_area;
78318 }
78319 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
78320 index 78e0830..bc6bbd8 100644
78321 --- a/mm/vmalloc.c
78322 +++ b/mm/vmalloc.c
78323 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
78324
78325 pte = pte_offset_kernel(pmd, addr);
78326 do {
78327 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
78328 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
78329 +
78330 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78331 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
78332 + BUG_ON(!pte_exec(*pte));
78333 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
78334 + continue;
78335 + }
78336 +#endif
78337 +
78338 + {
78339 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
78340 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
78341 + }
78342 } while (pte++, addr += PAGE_SIZE, addr != end);
78343 }
78344
78345 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
78346 pte = pte_alloc_kernel(pmd, addr);
78347 if (!pte)
78348 return -ENOMEM;
78349 +
78350 + pax_open_kernel();
78351 do {
78352 struct page *page = pages[*nr];
78353
78354 - if (WARN_ON(!pte_none(*pte)))
78355 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78356 + if (pgprot_val(prot) & _PAGE_NX)
78357 +#endif
78358 +
78359 + if (!pte_none(*pte)) {
78360 + pax_close_kernel();
78361 + WARN_ON(1);
78362 return -EBUSY;
78363 - if (WARN_ON(!page))
78364 + }
78365 + if (!page) {
78366 + pax_close_kernel();
78367 + WARN_ON(1);
78368 return -ENOMEM;
78369 + }
78370 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
78371 (*nr)++;
78372 } while (pte++, addr += PAGE_SIZE, addr != end);
78373 + pax_close_kernel();
78374 return 0;
78375 }
78376
78377 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
78378 pmd_t *pmd;
78379 unsigned long next;
78380
78381 - pmd = pmd_alloc(&init_mm, pud, addr);
78382 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
78383 if (!pmd)
78384 return -ENOMEM;
78385 do {
78386 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
78387 pud_t *pud;
78388 unsigned long next;
78389
78390 - pud = pud_alloc(&init_mm, pgd, addr);
78391 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
78392 if (!pud)
78393 return -ENOMEM;
78394 do {
78395 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
78396 * and fall back on vmalloc() if that fails. Others
78397 * just put it in the vmalloc space.
78398 */
78399 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
78400 +#ifdef CONFIG_MODULES
78401 +#ifdef MODULES_VADDR
78402 unsigned long addr = (unsigned long)x;
78403 if (addr >= MODULES_VADDR && addr < MODULES_END)
78404 return 1;
78405 #endif
78406 +
78407 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
78408 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
78409 + return 1;
78410 +#endif
78411 +
78412 +#endif
78413 +
78414 return is_vmalloc_addr(x);
78415 }
78416
78417 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
78418
78419 if (!pgd_none(*pgd)) {
78420 pud_t *pud = pud_offset(pgd, addr);
78421 +#ifdef CONFIG_X86
78422 + if (!pud_large(*pud))
78423 +#endif
78424 if (!pud_none(*pud)) {
78425 pmd_t *pmd = pmd_offset(pud, addr);
78426 +#ifdef CONFIG_X86
78427 + if (!pmd_large(*pmd))
78428 +#endif
78429 if (!pmd_none(*pmd)) {
78430 pte_t *ptep, pte;
78431
78432 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
78433 * Allocate a region of KVA of the specified size and alignment, within the
78434 * vstart and vend.
78435 */
78436 -static struct vmap_area *alloc_vmap_area(unsigned long size,
78437 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
78438 unsigned long align,
78439 unsigned long vstart, unsigned long vend,
78440 int node, gfp_t gfp_mask)
78441 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
78442 struct vm_struct *area;
78443
78444 BUG_ON(in_interrupt());
78445 +
78446 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78447 + if (flags & VM_KERNEXEC) {
78448 + if (start != VMALLOC_START || end != VMALLOC_END)
78449 + return NULL;
78450 + start = (unsigned long)MODULES_EXEC_VADDR;
78451 + end = (unsigned long)MODULES_EXEC_END;
78452 + }
78453 +#endif
78454 +
78455 if (flags & VM_IOREMAP) {
78456 int bit = fls(size);
78457
78458 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
78459 if (count > totalram_pages)
78460 return NULL;
78461
78462 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78463 + if (!(pgprot_val(prot) & _PAGE_NX))
78464 + flags |= VM_KERNEXEC;
78465 +#endif
78466 +
78467 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
78468 __builtin_return_address(0));
78469 if (!area)
78470 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
78471 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
78472 goto fail;
78473
78474 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78475 + if (!(pgprot_val(prot) & _PAGE_NX))
78476 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
78477 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
78478 + else
78479 +#endif
78480 +
78481 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
78482 start, end, node, gfp_mask, caller);
78483 if (!area)
78484 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
78485 * For tight control over page level allocator and protection flags
78486 * use __vmalloc() instead.
78487 */
78488 -
78489 void *vmalloc_exec(unsigned long size)
78490 {
78491 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
78492 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
78493 -1, __builtin_return_address(0));
78494 }
78495
78496 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
78497 unsigned long uaddr = vma->vm_start;
78498 unsigned long usize = vma->vm_end - vma->vm_start;
78499
78500 + BUG_ON(vma->vm_mirror);
78501 +
78502 if ((PAGE_SIZE-1) & (unsigned long)addr)
78503 return -EINVAL;
78504
78505 @@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
78506 v->addr, v->addr + v->size, v->size);
78507
78508 if (v->caller)
78509 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78510 + seq_printf(m, " %pK", v->caller);
78511 +#else
78512 seq_printf(m, " %pS", v->caller);
78513 +#endif
78514
78515 if (v->nr_pages)
78516 seq_printf(m, " pages=%d", v->nr_pages);
78517 diff --git a/mm/vmstat.c b/mm/vmstat.c
78518 index c737057..a49753a 100644
78519 --- a/mm/vmstat.c
78520 +++ b/mm/vmstat.c
78521 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
78522 *
78523 * vm_stat contains the global counters
78524 */
78525 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78526 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78527 EXPORT_SYMBOL(vm_stat);
78528
78529 #ifdef CONFIG_SMP
78530 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
78531 v = p->vm_stat_diff[i];
78532 p->vm_stat_diff[i] = 0;
78533 local_irq_restore(flags);
78534 - atomic_long_add(v, &zone->vm_stat[i]);
78535 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78536 global_diff[i] += v;
78537 #ifdef CONFIG_NUMA
78538 /* 3 seconds idle till flush */
78539 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
78540
78541 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
78542 if (global_diff[i])
78543 - atomic_long_add(global_diff[i], &vm_stat[i]);
78544 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
78545 }
78546
78547 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78548 @@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78549 if (pset->vm_stat_diff[i]) {
78550 int v = pset->vm_stat_diff[i];
78551 pset->vm_stat_diff[i] = 0;
78552 - atomic_long_add(v, &zone->vm_stat[i]);
78553 - atomic_long_add(v, &vm_stat[i]);
78554 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78555 + atomic_long_add_unchecked(v, &vm_stat[i]);
78556 }
78557 }
78558 #endif
78559 @@ -1224,10 +1224,20 @@ static int __init setup_vmstat(void)
78560 start_cpu_timer(cpu);
78561 #endif
78562 #ifdef CONFIG_PROC_FS
78563 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
78564 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
78565 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
78566 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
78567 + {
78568 + mode_t gr_mode = S_IRUGO;
78569 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
78570 + gr_mode = S_IRUSR;
78571 +#endif
78572 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
78573 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
78574 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78575 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
78576 +#else
78577 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
78578 +#endif
78579 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
78580 + }
78581 #endif
78582 return 0;
78583 }
78584 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
78585 index ee07072..593e3fd 100644
78586 --- a/net/8021q/vlan.c
78587 +++ b/net/8021q/vlan.c
78588 @@ -484,7 +484,7 @@ out:
78589 return NOTIFY_DONE;
78590 }
78591
78592 -static struct notifier_block vlan_notifier_block __read_mostly = {
78593 +static struct notifier_block vlan_notifier_block = {
78594 .notifier_call = vlan_device_event,
78595 };
78596
78597 @@ -559,8 +559,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
78598 err = -EPERM;
78599 if (!capable(CAP_NET_ADMIN))
78600 break;
78601 - if ((args.u.name_type >= 0) &&
78602 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
78603 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
78604 struct vlan_net *vn;
78605
78606 vn = net_generic(net, vlan_net_id);
78607 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
78608 index 02efb25..41541a9 100644
78609 --- a/net/9p/trans_fd.c
78610 +++ b/net/9p/trans_fd.c
78611 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
78612 oldfs = get_fs();
78613 set_fs(get_ds());
78614 /* The cast to a user pointer is valid due to the set_fs() */
78615 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
78616 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
78617 set_fs(oldfs);
78618
78619 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
78620 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
78621 index 876fbe8..8bbea9f 100644
78622 --- a/net/atm/atm_misc.c
78623 +++ b/net/atm/atm_misc.c
78624 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
78625 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
78626 return 1;
78627 atm_return(vcc, truesize);
78628 - atomic_inc(&vcc->stats->rx_drop);
78629 + atomic_inc_unchecked(&vcc->stats->rx_drop);
78630 return 0;
78631 }
78632 EXPORT_SYMBOL(atm_charge);
78633 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
78634 }
78635 }
78636 atm_return(vcc, guess);
78637 - atomic_inc(&vcc->stats->rx_drop);
78638 + atomic_inc_unchecked(&vcc->stats->rx_drop);
78639 return NULL;
78640 }
78641 EXPORT_SYMBOL(atm_alloc_charge);
78642 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
78643
78644 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78645 {
78646 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78647 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78648 __SONET_ITEMS
78649 #undef __HANDLE_ITEM
78650 }
78651 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
78652
78653 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78654 {
78655 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78656 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
78657 __SONET_ITEMS
78658 #undef __HANDLE_ITEM
78659 }
78660 diff --git a/net/atm/lec.h b/net/atm/lec.h
78661 index a86aff9..3a0d6f6 100644
78662 --- a/net/atm/lec.h
78663 +++ b/net/atm/lec.h
78664 @@ -48,7 +48,7 @@ struct lane2_ops {
78665 const u8 *tlvs, u32 sizeoftlvs);
78666 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
78667 const u8 *tlvs, u32 sizeoftlvs);
78668 -};
78669 +} __no_const;
78670
78671 /*
78672 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
78673 diff --git a/net/atm/proc.c b/net/atm/proc.c
78674 index 0d020de..011c7bb 100644
78675 --- a/net/atm/proc.c
78676 +++ b/net/atm/proc.c
78677 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
78678 const struct k_atm_aal_stats *stats)
78679 {
78680 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
78681 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
78682 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
78683 - atomic_read(&stats->rx_drop));
78684 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
78685 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
78686 + atomic_read_unchecked(&stats->rx_drop));
78687 }
78688
78689 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
78690 diff --git a/net/atm/resources.c b/net/atm/resources.c
78691 index 0447d5d..3cf4728 100644
78692 --- a/net/atm/resources.c
78693 +++ b/net/atm/resources.c
78694 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
78695 static void copy_aal_stats(struct k_atm_aal_stats *from,
78696 struct atm_aal_stats *to)
78697 {
78698 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78699 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78700 __AAL_STAT_ITEMS
78701 #undef __HANDLE_ITEM
78702 }
78703 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
78704 static void subtract_aal_stats(struct k_atm_aal_stats *from,
78705 struct atm_aal_stats *to)
78706 {
78707 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78708 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
78709 __AAL_STAT_ITEMS
78710 #undef __HANDLE_ITEM
78711 }
78712 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
78713 index c6fcc76..1270d14 100644
78714 --- a/net/batman-adv/bat_iv_ogm.c
78715 +++ b/net/batman-adv/bat_iv_ogm.c
78716 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
78717
78718 /* randomize initial seqno to avoid collision */
78719 get_random_bytes(&random_seqno, sizeof(random_seqno));
78720 - atomic_set(&hard_iface->seqno, random_seqno);
78721 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
78722
78723 hard_iface->packet_len = BATADV_OGM_HLEN;
78724 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
78725 @@ -608,9 +608,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
78726 batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
78727
78728 /* change sequence number to network order */
78729 - seqno = (uint32_t)atomic_read(&hard_iface->seqno);
78730 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->seqno);
78731 batadv_ogm_packet->seqno = htonl(seqno);
78732 - atomic_inc(&hard_iface->seqno);
78733 + atomic_inc_unchecked(&hard_iface->seqno);
78734
78735 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
78736 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
78737 @@ -1015,7 +1015,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
78738 return;
78739
78740 /* could be changed by schedule_own_packet() */
78741 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
78742 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
78743
78744 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
78745 has_directlink_flag = 1;
78746 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
78747 index d112fd6..686a447 100644
78748 --- a/net/batman-adv/hard-interface.c
78749 +++ b/net/batman-adv/hard-interface.c
78750 @@ -327,7 +327,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
78751 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
78752 dev_add_pack(&hard_iface->batman_adv_ptype);
78753
78754 - atomic_set(&hard_iface->frag_seqno, 1);
78755 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
78756 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
78757 hard_iface->net_dev->name);
78758
78759 @@ -450,7 +450,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
78760 /* This can't be called via a bat_priv callback because
78761 * we have no bat_priv yet.
78762 */
78763 - atomic_set(&hard_iface->seqno, 1);
78764 + atomic_set_unchecked(&hard_iface->seqno, 1);
78765 hard_iface->packet_buff = NULL;
78766
78767 return hard_iface;
78768 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
78769 index ce0684a..4a0cbf1 100644
78770 --- a/net/batman-adv/soft-interface.c
78771 +++ b/net/batman-adv/soft-interface.c
78772 @@ -234,7 +234,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
78773 primary_if->net_dev->dev_addr, ETH_ALEN);
78774
78775 /* set broadcast sequence number */
78776 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
78777 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
78778 bcast_packet->seqno = htonl(seqno);
78779
78780 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
78781 @@ -427,7 +427,7 @@ struct net_device *batadv_softif_create(const char *name)
78782 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
78783
78784 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
78785 - atomic_set(&bat_priv->bcast_seqno, 1);
78786 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
78787 atomic_set(&bat_priv->tt.vn, 0);
78788 atomic_set(&bat_priv->tt.local_changes, 0);
78789 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
78790 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
78791 index ac1e07a..4c846e2 100644
78792 --- a/net/batman-adv/types.h
78793 +++ b/net/batman-adv/types.h
78794 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
78795 int16_t if_num;
78796 char if_status;
78797 struct net_device *net_dev;
78798 - atomic_t seqno;
78799 - atomic_t frag_seqno;
78800 + atomic_unchecked_t seqno;
78801 + atomic_unchecked_t frag_seqno;
78802 unsigned char *packet_buff;
78803 int packet_len;
78804 struct kobject *hardif_obj;
78805 @@ -244,7 +244,7 @@ struct batadv_priv {
78806 atomic_t orig_interval; /* uint */
78807 atomic_t hop_penalty; /* uint */
78808 atomic_t log_level; /* uint */
78809 - atomic_t bcast_seqno;
78810 + atomic_unchecked_t bcast_seqno;
78811 atomic_t bcast_queue_left;
78812 atomic_t batman_queue_left;
78813 char num_ifaces;
78814 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
78815 index f397232..3206a33 100644
78816 --- a/net/batman-adv/unicast.c
78817 +++ b/net/batman-adv/unicast.c
78818 @@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
78819 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
78820 frag2->flags = large_tail;
78821
78822 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
78823 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
78824 frag1->seqno = htons(seqno - 1);
78825 frag2->seqno = htons(seqno);
78826
78827 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
78828 index 07f0739..3c42e34 100644
78829 --- a/net/bluetooth/hci_sock.c
78830 +++ b/net/bluetooth/hci_sock.c
78831 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
78832 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
78833 }
78834
78835 - len = min_t(unsigned int, len, sizeof(uf));
78836 + len = min((size_t)len, sizeof(uf));
78837 if (copy_from_user(&uf, optval, len)) {
78838 err = -EFAULT;
78839 break;
78840 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
78841 index a91239d..d7ed533 100644
78842 --- a/net/bluetooth/l2cap_core.c
78843 +++ b/net/bluetooth/l2cap_core.c
78844 @@ -3183,8 +3183,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
78845 break;
78846
78847 case L2CAP_CONF_RFC:
78848 - if (olen == sizeof(rfc))
78849 - memcpy(&rfc, (void *)val, olen);
78850 + if (olen != sizeof(rfc))
78851 + break;
78852 +
78853 + memcpy(&rfc, (void *)val, olen);
78854
78855 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
78856 rfc.mode != chan->mode)
78857 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
78858 index 083f2bf..799f9448 100644
78859 --- a/net/bluetooth/l2cap_sock.c
78860 +++ b/net/bluetooth/l2cap_sock.c
78861 @@ -471,7 +471,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78862 struct sock *sk = sock->sk;
78863 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
78864 struct l2cap_options opts;
78865 - int len, err = 0;
78866 + int err = 0;
78867 + size_t len = optlen;
78868 u32 opt;
78869
78870 BT_DBG("sk %p", sk);
78871 @@ -493,7 +494,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78872 opts.max_tx = chan->max_tx;
78873 opts.txwin_size = chan->tx_win;
78874
78875 - len = min_t(unsigned int, sizeof(opts), optlen);
78876 + len = min(sizeof(opts), len);
78877 if (copy_from_user((char *) &opts, optval, len)) {
78878 err = -EFAULT;
78879 break;
78880 @@ -571,7 +572,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78881 struct bt_security sec;
78882 struct bt_power pwr;
78883 struct l2cap_conn *conn;
78884 - int len, err = 0;
78885 + int err = 0;
78886 + size_t len = optlen;
78887 u32 opt;
78888
78889 BT_DBG("sk %p", sk);
78890 @@ -594,7 +596,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78891
78892 sec.level = BT_SECURITY_LOW;
78893
78894 - len = min_t(unsigned int, sizeof(sec), optlen);
78895 + len = min(sizeof(sec), len);
78896 if (copy_from_user((char *) &sec, optval, len)) {
78897 err = -EFAULT;
78898 break;
78899 @@ -691,7 +693,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78900
78901 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
78902
78903 - len = min_t(unsigned int, sizeof(pwr), optlen);
78904 + len = min(sizeof(pwr), len);
78905 if (copy_from_user((char *) &pwr, optval, len)) {
78906 err = -EFAULT;
78907 break;
78908 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
78909 index 868a909..d044bc3 100644
78910 --- a/net/bluetooth/rfcomm/sock.c
78911 +++ b/net/bluetooth/rfcomm/sock.c
78912 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78913 struct sock *sk = sock->sk;
78914 struct bt_security sec;
78915 int err = 0;
78916 - size_t len;
78917 + size_t len = optlen;
78918 u32 opt;
78919
78920 BT_DBG("sk %p", sk);
78921 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78922
78923 sec.level = BT_SECURITY_LOW;
78924
78925 - len = min_t(unsigned int, sizeof(sec), optlen);
78926 + len = min(sizeof(sec), len);
78927 if (copy_from_user((char *) &sec, optval, len)) {
78928 err = -EFAULT;
78929 break;
78930 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
78931 index ccc2487..921073d 100644
78932 --- a/net/bluetooth/rfcomm/tty.c
78933 +++ b/net/bluetooth/rfcomm/tty.c
78934 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
78935 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
78936
78937 spin_lock_irqsave(&dev->port.lock, flags);
78938 - if (dev->port.count > 0) {
78939 + if (atomic_read(&dev->port.count) > 0) {
78940 spin_unlock_irqrestore(&dev->port.lock, flags);
78941 return;
78942 }
78943 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
78944 return -ENODEV;
78945
78946 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
78947 - dev->channel, dev->port.count);
78948 + dev->channel, atomic_read(&dev->port.count));
78949
78950 spin_lock_irqsave(&dev->port.lock, flags);
78951 - if (++dev->port.count > 1) {
78952 + if (atomic_inc_return(&dev->port.count) > 1) {
78953 spin_unlock_irqrestore(&dev->port.lock, flags);
78954 return 0;
78955 }
78956 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
78957 return;
78958
78959 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
78960 - dev->port.count);
78961 + atomic_read(&dev->port.count));
78962
78963 spin_lock_irqsave(&dev->port.lock, flags);
78964 - if (!--dev->port.count) {
78965 + if (!atomic_dec_return(&dev->port.count)) {
78966 spin_unlock_irqrestore(&dev->port.lock, flags);
78967 if (dev->tty_dev->parent)
78968 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
78969 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
78970 index 5fe2ff3..121d696 100644
78971 --- a/net/bridge/netfilter/ebtables.c
78972 +++ b/net/bridge/netfilter/ebtables.c
78973 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78974 tmp.valid_hooks = t->table->valid_hooks;
78975 }
78976 mutex_unlock(&ebt_mutex);
78977 - if (copy_to_user(user, &tmp, *len) != 0){
78978 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
78979 BUGPRINT("c2u Didn't work\n");
78980 ret = -EFAULT;
78981 break;
78982 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78983 goto out;
78984 tmp.valid_hooks = t->valid_hooks;
78985
78986 - if (copy_to_user(user, &tmp, *len) != 0) {
78987 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78988 ret = -EFAULT;
78989 break;
78990 }
78991 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78992 tmp.entries_size = t->table->entries_size;
78993 tmp.valid_hooks = t->table->valid_hooks;
78994
78995 - if (copy_to_user(user, &tmp, *len) != 0) {
78996 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78997 ret = -EFAULT;
78998 break;
78999 }
79000 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
79001 index 44f270f..1f5602d 100644
79002 --- a/net/caif/cfctrl.c
79003 +++ b/net/caif/cfctrl.c
79004 @@ -10,6 +10,7 @@
79005 #include <linux/spinlock.h>
79006 #include <linux/slab.h>
79007 #include <linux/pkt_sched.h>
79008 +#include <linux/sched.h>
79009 #include <net/caif/caif_layer.h>
79010 #include <net/caif/cfpkt.h>
79011 #include <net/caif/cfctrl.h>
79012 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
79013 memset(&dev_info, 0, sizeof(dev_info));
79014 dev_info.id = 0xff;
79015 cfsrvl_init(&this->serv, 0, &dev_info, false);
79016 - atomic_set(&this->req_seq_no, 1);
79017 - atomic_set(&this->rsp_seq_no, 1);
79018 + atomic_set_unchecked(&this->req_seq_no, 1);
79019 + atomic_set_unchecked(&this->rsp_seq_no, 1);
79020 this->serv.layer.receive = cfctrl_recv;
79021 sprintf(this->serv.layer.name, "ctrl");
79022 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
79023 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
79024 struct cfctrl_request_info *req)
79025 {
79026 spin_lock_bh(&ctrl->info_list_lock);
79027 - atomic_inc(&ctrl->req_seq_no);
79028 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
79029 + atomic_inc_unchecked(&ctrl->req_seq_no);
79030 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
79031 list_add_tail(&req->list, &ctrl->list);
79032 spin_unlock_bh(&ctrl->info_list_lock);
79033 }
79034 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
79035 if (p != first)
79036 pr_warn("Requests are not received in order\n");
79037
79038 - atomic_set(&ctrl->rsp_seq_no,
79039 + atomic_set_unchecked(&ctrl->rsp_seq_no,
79040 p->sequence_no);
79041 list_del(&p->list);
79042 goto out;
79043 diff --git a/net/can/af_can.c b/net/can/af_can.c
79044 index ddac1ee..3ee0a78 100644
79045 --- a/net/can/af_can.c
79046 +++ b/net/can/af_can.c
79047 @@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
79048 };
79049
79050 /* notifier block for netdevice event */
79051 -static struct notifier_block can_netdev_notifier __read_mostly = {
79052 +static struct notifier_block can_netdev_notifier = {
79053 .notifier_call = can_notifier,
79054 };
79055
79056 diff --git a/net/can/gw.c b/net/can/gw.c
79057 index 1f5c978..ef714c7 100644
79058 --- a/net/can/gw.c
79059 +++ b/net/can/gw.c
79060 @@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
79061 MODULE_ALIAS("can-gw");
79062
79063 static HLIST_HEAD(cgw_list);
79064 -static struct notifier_block notifier;
79065
79066 static struct kmem_cache *cgw_cache __read_mostly;
79067
79068 @@ -887,6 +886,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
79069 return err;
79070 }
79071
79072 +static struct notifier_block notifier = {
79073 + .notifier_call = cgw_notifier
79074 +};
79075 +
79076 static __init int cgw_module_init(void)
79077 {
79078 printk(banner);
79079 @@ -898,7 +901,6 @@ static __init int cgw_module_init(void)
79080 return -ENOMEM;
79081
79082 /* set notifier */
79083 - notifier.notifier_call = cgw_notifier;
79084 register_netdevice_notifier(&notifier);
79085
79086 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
79087 diff --git a/net/compat.c b/net/compat.c
79088 index 79ae884..17c5c09 100644
79089 --- a/net/compat.c
79090 +++ b/net/compat.c
79091 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
79092 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
79093 __get_user(kmsg->msg_flags, &umsg->msg_flags))
79094 return -EFAULT;
79095 - kmsg->msg_name = compat_ptr(tmp1);
79096 - kmsg->msg_iov = compat_ptr(tmp2);
79097 - kmsg->msg_control = compat_ptr(tmp3);
79098 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
79099 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
79100 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
79101 return 0;
79102 }
79103
79104 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79105
79106 if (kern_msg->msg_namelen) {
79107 if (mode == VERIFY_READ) {
79108 - int err = move_addr_to_kernel(kern_msg->msg_name,
79109 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
79110 kern_msg->msg_namelen,
79111 kern_address);
79112 if (err < 0)
79113 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79114 kern_msg->msg_name = NULL;
79115
79116 tot_len = iov_from_user_compat_to_kern(kern_iov,
79117 - (struct compat_iovec __user *)kern_msg->msg_iov,
79118 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
79119 kern_msg->msg_iovlen);
79120 if (tot_len >= 0)
79121 kern_msg->msg_iov = kern_iov;
79122 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
79123
79124 #define CMSG_COMPAT_FIRSTHDR(msg) \
79125 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
79126 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
79127 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
79128 (struct compat_cmsghdr __user *)NULL)
79129
79130 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
79131 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
79132 (ucmlen) <= (unsigned long) \
79133 ((mhdr)->msg_controllen - \
79134 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
79135 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
79136
79137 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
79138 struct compat_cmsghdr __user *cmsg, int cmsg_len)
79139 {
79140 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
79141 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
79142 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
79143 msg->msg_controllen)
79144 return NULL;
79145 return (struct compat_cmsghdr __user *)ptr;
79146 @@ -219,7 +219,7 @@ Efault:
79147
79148 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
79149 {
79150 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79151 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79152 struct compat_cmsghdr cmhdr;
79153 struct compat_timeval ctv;
79154 struct compat_timespec cts[3];
79155 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
79156
79157 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
79158 {
79159 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
79160 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
79161 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
79162 int fdnum = scm->fp->count;
79163 struct file **fp = scm->fp->fp;
79164 @@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
79165 return -EFAULT;
79166 old_fs = get_fs();
79167 set_fs(KERNEL_DS);
79168 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
79169 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
79170 set_fs(old_fs);
79171
79172 return err;
79173 @@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
79174 len = sizeof(ktime);
79175 old_fs = get_fs();
79176 set_fs(KERNEL_DS);
79177 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
79178 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
79179 set_fs(old_fs);
79180
79181 if (!err) {
79182 @@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79183 case MCAST_JOIN_GROUP:
79184 case MCAST_LEAVE_GROUP:
79185 {
79186 - struct compat_group_req __user *gr32 = (void *)optval;
79187 + struct compat_group_req __user *gr32 = (void __user *)optval;
79188 struct group_req __user *kgr =
79189 compat_alloc_user_space(sizeof(struct group_req));
79190 u32 interface;
79191 @@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79192 case MCAST_BLOCK_SOURCE:
79193 case MCAST_UNBLOCK_SOURCE:
79194 {
79195 - struct compat_group_source_req __user *gsr32 = (void *)optval;
79196 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
79197 struct group_source_req __user *kgsr = compat_alloc_user_space(
79198 sizeof(struct group_source_req));
79199 u32 interface;
79200 @@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
79201 }
79202 case MCAST_MSFILTER:
79203 {
79204 - struct compat_group_filter __user *gf32 = (void *)optval;
79205 + struct compat_group_filter __user *gf32 = (void __user *)optval;
79206 struct group_filter __user *kgf;
79207 u32 interface, fmode, numsrc;
79208
79209 @@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
79210 char __user *optval, int __user *optlen,
79211 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
79212 {
79213 - struct compat_group_filter __user *gf32 = (void *)optval;
79214 + struct compat_group_filter __user *gf32 = (void __user *)optval;
79215 struct group_filter __user *kgf;
79216 int __user *koptlen;
79217 u32 interface, fmode, numsrc;
79218 @@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
79219
79220 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
79221 return -EINVAL;
79222 - if (copy_from_user(a, args, nas[call]))
79223 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
79224 return -EFAULT;
79225 a0 = a[0];
79226 a1 = a[1];
79227 diff --git a/net/core/datagram.c b/net/core/datagram.c
79228 index 0337e2b..f82d4a3 100644
79229 --- a/net/core/datagram.c
79230 +++ b/net/core/datagram.c
79231 @@ -187,7 +187,7 @@ struct sk_buff *__skb_recv_datagram(struct sock *sk, unsigned int flags,
79232 skb_queue_walk(queue, skb) {
79233 *peeked = skb->peeked;
79234 if (flags & MSG_PEEK) {
79235 - if (*off >= skb->len) {
79236 + if (*off >= skb->len && skb->len) {
79237 *off -= skb->len;
79238 continue;
79239 }
79240 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
79241 }
79242
79243 kfree_skb(skb);
79244 - atomic_inc(&sk->sk_drops);
79245 + atomic_inc_unchecked(&sk->sk_drops);
79246 sk_mem_reclaim_partial(sk);
79247
79248 return err;
79249 diff --git a/net/core/dev.c b/net/core/dev.c
79250 index 3470794..eb5008c 100644
79251 --- a/net/core/dev.c
79252 +++ b/net/core/dev.c
79253 @@ -1162,9 +1162,13 @@ void dev_load(struct net *net, const char *name)
79254 if (no_module && capable(CAP_NET_ADMIN))
79255 no_module = request_module("netdev-%s", name);
79256 if (no_module && capable(CAP_SYS_MODULE)) {
79257 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
79258 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
79259 +#else
79260 if (!request_module("%s", name))
79261 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
79262 name);
79263 +#endif
79264 }
79265 }
79266 EXPORT_SYMBOL(dev_load);
79267 @@ -1627,7 +1631,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
79268 {
79269 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
79270 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
79271 - atomic_long_inc(&dev->rx_dropped);
79272 + atomic_long_inc_unchecked(&dev->rx_dropped);
79273 kfree_skb(skb);
79274 return NET_RX_DROP;
79275 }
79276 @@ -1637,7 +1641,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
79277 nf_reset(skb);
79278
79279 if (unlikely(!is_skb_forwardable(dev, skb))) {
79280 - atomic_long_inc(&dev->rx_dropped);
79281 + atomic_long_inc_unchecked(&dev->rx_dropped);
79282 kfree_skb(skb);
79283 return NET_RX_DROP;
79284 }
79285 @@ -2093,7 +2097,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
79286
79287 struct dev_gso_cb {
79288 void (*destructor)(struct sk_buff *skb);
79289 -};
79290 +} __no_const;
79291
79292 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
79293
79294 @@ -2955,7 +2959,7 @@ enqueue:
79295
79296 local_irq_restore(flags);
79297
79298 - atomic_long_inc(&skb->dev->rx_dropped);
79299 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
79300 kfree_skb(skb);
79301 return NET_RX_DROP;
79302 }
79303 @@ -3027,7 +3031,7 @@ int netif_rx_ni(struct sk_buff *skb)
79304 }
79305 EXPORT_SYMBOL(netif_rx_ni);
79306
79307 -static void net_tx_action(struct softirq_action *h)
79308 +static void net_tx_action(void)
79309 {
79310 struct softnet_data *sd = &__get_cpu_var(softnet_data);
79311
79312 @@ -3358,7 +3362,7 @@ ncls:
79313 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
79314 } else {
79315 drop:
79316 - atomic_long_inc(&skb->dev->rx_dropped);
79317 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
79318 kfree_skb(skb);
79319 /* Jamal, now you will not able to escape explaining
79320 * me how you were going to use this. :-)
79321 @@ -3944,7 +3948,7 @@ void netif_napi_del(struct napi_struct *napi)
79322 }
79323 EXPORT_SYMBOL(netif_napi_del);
79324
79325 -static void net_rx_action(struct softirq_action *h)
79326 +static void net_rx_action(void)
79327 {
79328 struct softnet_data *sd = &__get_cpu_var(softnet_data);
79329 unsigned long time_limit = jiffies + 2;
79330 @@ -4423,8 +4427,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
79331 else
79332 seq_printf(seq, "%04x", ntohs(pt->type));
79333
79334 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79335 + seq_printf(seq, " %-8s %p\n",
79336 + pt->dev ? pt->dev->name : "", NULL);
79337 +#else
79338 seq_printf(seq, " %-8s %pF\n",
79339 pt->dev ? pt->dev->name : "", pt->func);
79340 +#endif
79341 }
79342
79343 return 0;
79344 @@ -5987,7 +5996,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
79345 } else {
79346 netdev_stats_to_stats64(storage, &dev->stats);
79347 }
79348 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
79349 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
79350 return storage;
79351 }
79352 EXPORT_SYMBOL(dev_get_stats);
79353 diff --git a/net/core/flow.c b/net/core/flow.c
79354 index e318c7e..168b1d0 100644
79355 --- a/net/core/flow.c
79356 +++ b/net/core/flow.c
79357 @@ -61,7 +61,7 @@ struct flow_cache {
79358 struct timer_list rnd_timer;
79359 };
79360
79361 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
79362 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
79363 EXPORT_SYMBOL(flow_cache_genid);
79364 static struct flow_cache flow_cache_global;
79365 static struct kmem_cache *flow_cachep __read_mostly;
79366 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
79367
79368 static int flow_entry_valid(struct flow_cache_entry *fle)
79369 {
79370 - if (atomic_read(&flow_cache_genid) != fle->genid)
79371 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
79372 return 0;
79373 if (fle->object && !fle->object->ops->check(fle->object))
79374 return 0;
79375 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
79376 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
79377 fcp->hash_count++;
79378 }
79379 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
79380 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
79381 flo = fle->object;
79382 if (!flo)
79383 goto ret_object;
79384 @@ -280,7 +280,7 @@ nocache:
79385 }
79386 flo = resolver(net, key, family, dir, flo, ctx);
79387 if (fle) {
79388 - fle->genid = atomic_read(&flow_cache_genid);
79389 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
79390 if (!IS_ERR(flo))
79391 fle->object = flo;
79392 else
79393 diff --git a/net/core/iovec.c b/net/core/iovec.c
79394 index 7e7aeb0..2a998cb 100644
79395 --- a/net/core/iovec.c
79396 +++ b/net/core/iovec.c
79397 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
79398 if (m->msg_namelen) {
79399 if (mode == VERIFY_READ) {
79400 void __user *namep;
79401 - namep = (void __user __force *) m->msg_name;
79402 + namep = (void __force_user *) m->msg_name;
79403 err = move_addr_to_kernel(namep, m->msg_namelen,
79404 address);
79405 if (err < 0)
79406 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
79407 }
79408
79409 size = m->msg_iovlen * sizeof(struct iovec);
79410 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
79411 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
79412 return -EFAULT;
79413
79414 m->msg_iov = iov;
79415 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
79416 index fad649a..f2fdac4 100644
79417 --- a/net/core/rtnetlink.c
79418 +++ b/net/core/rtnetlink.c
79419 @@ -198,14 +198,16 @@ int __rtnl_register(int protocol, int msgtype,
79420 rtnl_msg_handlers[protocol] = tab;
79421 }
79422
79423 + pax_open_kernel();
79424 if (doit)
79425 - tab[msgindex].doit = doit;
79426 + *(void **)&tab[msgindex].doit = doit;
79427
79428 if (dumpit)
79429 - tab[msgindex].dumpit = dumpit;
79430 + *(void **)&tab[msgindex].dumpit = dumpit;
79431
79432 if (calcit)
79433 - tab[msgindex].calcit = calcit;
79434 + *(void **)&tab[msgindex].calcit = calcit;
79435 + pax_close_kernel();
79436
79437 return 0;
79438 }
79439 @@ -248,8 +250,10 @@ int rtnl_unregister(int protocol, int msgtype)
79440 if (rtnl_msg_handlers[protocol] == NULL)
79441 return -ENOENT;
79442
79443 - rtnl_msg_handlers[protocol][msgindex].doit = NULL;
79444 - rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
79445 + pax_open_kernel();
79446 + *(void **)&rtnl_msg_handlers[protocol][msgindex].doit = NULL;
79447 + *(void **)&rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
79448 + pax_close_kernel();
79449
79450 return 0;
79451 }
79452 diff --git a/net/core/scm.c b/net/core/scm.c
79453 index ab57084..0190c8f 100644
79454 --- a/net/core/scm.c
79455 +++ b/net/core/scm.c
79456 @@ -223,7 +223,7 @@ EXPORT_SYMBOL(__scm_send);
79457 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79458 {
79459 struct cmsghdr __user *cm
79460 - = (__force struct cmsghdr __user *)msg->msg_control;
79461 + = (struct cmsghdr __force_user *)msg->msg_control;
79462 struct cmsghdr cmhdr;
79463 int cmlen = CMSG_LEN(len);
79464 int err;
79465 @@ -246,7 +246,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79466 err = -EFAULT;
79467 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
79468 goto out;
79469 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
79470 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
79471 goto out;
79472 cmlen = CMSG_SPACE(len);
79473 if (msg->msg_controllen < cmlen)
79474 @@ -262,7 +262,7 @@ EXPORT_SYMBOL(put_cmsg);
79475 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79476 {
79477 struct cmsghdr __user *cm
79478 - = (__force struct cmsghdr __user*)msg->msg_control;
79479 + = (struct cmsghdr __force_user *)msg->msg_control;
79480
79481 int fdmax = 0;
79482 int fdnum = scm->fp->count;
79483 @@ -282,7 +282,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79484 if (fdnum < fdmax)
79485 fdmax = fdnum;
79486
79487 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
79488 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
79489 i++, cmfptr++)
79490 {
79491 struct socket *sock;
79492 diff --git a/net/core/sock.c b/net/core/sock.c
79493 index 8a146cf..ee08914d 100644
79494 --- a/net/core/sock.c
79495 +++ b/net/core/sock.c
79496 @@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79497 struct sk_buff_head *list = &sk->sk_receive_queue;
79498
79499 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
79500 - atomic_inc(&sk->sk_drops);
79501 + atomic_inc_unchecked(&sk->sk_drops);
79502 trace_sock_rcvqueue_full(sk, skb);
79503 return -ENOMEM;
79504 }
79505 @@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79506 return err;
79507
79508 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
79509 - atomic_inc(&sk->sk_drops);
79510 + atomic_inc_unchecked(&sk->sk_drops);
79511 return -ENOBUFS;
79512 }
79513
79514 @@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79515 skb_dst_force(skb);
79516
79517 spin_lock_irqsave(&list->lock, flags);
79518 - skb->dropcount = atomic_read(&sk->sk_drops);
79519 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
79520 __skb_queue_tail(list, skb);
79521 spin_unlock_irqrestore(&list->lock, flags);
79522
79523 @@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79524 skb->dev = NULL;
79525
79526 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
79527 - atomic_inc(&sk->sk_drops);
79528 + atomic_inc_unchecked(&sk->sk_drops);
79529 goto discard_and_relse;
79530 }
79531 if (nested)
79532 @@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79533 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
79534 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
79535 bh_unlock_sock(sk);
79536 - atomic_inc(&sk->sk_drops);
79537 + atomic_inc_unchecked(&sk->sk_drops);
79538 goto discard_and_relse;
79539 }
79540
79541 @@ -875,12 +875,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79542 struct timeval tm;
79543 } v;
79544
79545 - int lv = sizeof(int);
79546 - int len;
79547 + unsigned int lv = sizeof(int);
79548 + unsigned int len;
79549
79550 if (get_user(len, optlen))
79551 return -EFAULT;
79552 - if (len < 0)
79553 + if (len > INT_MAX)
79554 return -EINVAL;
79555
79556 memset(&v, 0, sizeof(v));
79557 @@ -1028,11 +1028,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79558
79559 case SO_PEERNAME:
79560 {
79561 - char address[128];
79562 + char address[_K_SS_MAXSIZE];
79563
79564 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
79565 return -ENOTCONN;
79566 - if (lv < len)
79567 + if (lv < len || sizeof address < len)
79568 return -EINVAL;
79569 if (copy_to_user(optval, address, len))
79570 return -EFAULT;
79571 @@ -1080,7 +1080,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79572
79573 if (len > lv)
79574 len = lv;
79575 - if (copy_to_user(optval, &v, len))
79576 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
79577 return -EFAULT;
79578 lenout:
79579 if (put_user(len, optlen))
79580 @@ -2212,7 +2212,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
79581 */
79582 smp_wmb();
79583 atomic_set(&sk->sk_refcnt, 1);
79584 - atomic_set(&sk->sk_drops, 0);
79585 + atomic_set_unchecked(&sk->sk_drops, 0);
79586 }
79587 EXPORT_SYMBOL(sock_init_data);
79588
79589 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
79590 index 602cd63..05c6c60 100644
79591 --- a/net/core/sock_diag.c
79592 +++ b/net/core/sock_diag.c
79593 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
79594
79595 int sock_diag_check_cookie(void *sk, __u32 *cookie)
79596 {
79597 +#ifndef CONFIG_GRKERNSEC_HIDESYM
79598 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
79599 cookie[1] != INET_DIAG_NOCOOKIE) &&
79600 ((u32)(unsigned long)sk != cookie[0] ||
79601 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
79602 return -ESTALE;
79603 else
79604 +#endif
79605 return 0;
79606 }
79607 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
79608
79609 void sock_diag_save_cookie(void *sk, __u32 *cookie)
79610 {
79611 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79612 + cookie[0] = 0;
79613 + cookie[1] = 0;
79614 +#else
79615 cookie[0] = (u32)(unsigned long)sk;
79616 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
79617 +#endif
79618 }
79619 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
79620
79621 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
79622 index a55eecc..dd8428c 100644
79623 --- a/net/decnet/sysctl_net_decnet.c
79624 +++ b/net/decnet/sysctl_net_decnet.c
79625 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
79626
79627 if (len > *lenp) len = *lenp;
79628
79629 - if (copy_to_user(buffer, addr, len))
79630 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
79631 return -EFAULT;
79632
79633 *lenp = len;
79634 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
79635
79636 if (len > *lenp) len = *lenp;
79637
79638 - if (copy_to_user(buffer, devname, len))
79639 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
79640 return -EFAULT;
79641
79642 *lenp = len;
79643 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
79644 index 2a6abc1..c379ba7 100644
79645 --- a/net/ipv4/devinet.c
79646 +++ b/net/ipv4/devinet.c
79647 @@ -822,9 +822,9 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg)
79648 if (!ifa) {
79649 ret = -ENOBUFS;
79650 ifa = inet_alloc_ifa();
79651 + if (!ifa)
79652 + break;
79653 INIT_HLIST_NODE(&ifa->hash);
79654 - if (!ifa)
79655 - break;
79656 if (colon)
79657 memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ);
79658 else
79659 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
79660 index 825c608..750ff29 100644
79661 --- a/net/ipv4/fib_frontend.c
79662 +++ b/net/ipv4/fib_frontend.c
79663 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
79664 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79665 fib_sync_up(dev);
79666 #endif
79667 - atomic_inc(&net->ipv4.dev_addr_genid);
79668 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79669 rt_cache_flush(dev_net(dev));
79670 break;
79671 case NETDEV_DOWN:
79672 fib_del_ifaddr(ifa, NULL);
79673 - atomic_inc(&net->ipv4.dev_addr_genid);
79674 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79675 if (ifa->ifa_dev->ifa_list == NULL) {
79676 /* Last address was deleted from this interface.
79677 * Disable IP.
79678 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
79679 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79680 fib_sync_up(dev);
79681 #endif
79682 - atomic_inc(&net->ipv4.dev_addr_genid);
79683 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79684 rt_cache_flush(net);
79685 break;
79686 case NETDEV_DOWN:
79687 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
79688 index 71b125c..f4c70b0 100644
79689 --- a/net/ipv4/fib_semantics.c
79690 +++ b/net/ipv4/fib_semantics.c
79691 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
79692 nh->nh_saddr = inet_select_addr(nh->nh_dev,
79693 nh->nh_gw,
79694 nh->nh_parent->fib_scope);
79695 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
79696 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
79697
79698 return nh->nh_saddr;
79699 }
79700 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
79701 index 7880af9..70f92a3 100644
79702 --- a/net/ipv4/inet_hashtables.c
79703 +++ b/net/ipv4/inet_hashtables.c
79704 @@ -18,12 +18,15 @@
79705 #include <linux/sched.h>
79706 #include <linux/slab.h>
79707 #include <linux/wait.h>
79708 +#include <linux/security.h>
79709
79710 #include <net/inet_connection_sock.h>
79711 #include <net/inet_hashtables.h>
79712 #include <net/secure_seq.h>
79713 #include <net/ip.h>
79714
79715 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
79716 +
79717 /*
79718 * Allocate and initialize a new local port bind bucket.
79719 * The bindhash mutex for snum's hash chain must be held here.
79720 @@ -530,6 +533,8 @@ ok:
79721 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
79722 spin_unlock(&head->lock);
79723
79724 + gr_update_task_in_ip_table(current, inet_sk(sk));
79725 +
79726 if (tw) {
79727 inet_twsk_deschedule(tw, death_row);
79728 while (twrefcnt) {
79729 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
79730 index 000e3d2..5472da3 100644
79731 --- a/net/ipv4/inetpeer.c
79732 +++ b/net/ipv4/inetpeer.c
79733 @@ -503,8 +503,8 @@ relookup:
79734 if (p) {
79735 p->daddr = *daddr;
79736 atomic_set(&p->refcnt, 1);
79737 - atomic_set(&p->rid, 0);
79738 - atomic_set(&p->ip_id_count,
79739 + atomic_set_unchecked(&p->rid, 0);
79740 + atomic_set_unchecked(&p->ip_id_count,
79741 (daddr->family == AF_INET) ?
79742 secure_ip_id(daddr->addr.a4) :
79743 secure_ipv6_id(daddr->addr.a6));
79744 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
79745 index 8d5cc75..821fd11 100644
79746 --- a/net/ipv4/ip_fragment.c
79747 +++ b/net/ipv4/ip_fragment.c
79748 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
79749 return 0;
79750
79751 start = qp->rid;
79752 - end = atomic_inc_return(&peer->rid);
79753 + end = atomic_inc_return_unchecked(&peer->rid);
79754 qp->rid = end;
79755
79756 rc = qp->q.fragments && (end - start) > max;
79757 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
79758 index e95d72b..5268ac0 100644
79759 --- a/net/ipv4/ip_sockglue.c
79760 +++ b/net/ipv4/ip_sockglue.c
79761 @@ -1151,7 +1151,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79762 len = min_t(unsigned int, len, opt->optlen);
79763 if (put_user(len, optlen))
79764 return -EFAULT;
79765 - if (copy_to_user(optval, opt->__data, len))
79766 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
79767 + copy_to_user(optval, opt->__data, len))
79768 return -EFAULT;
79769 return 0;
79770 }
79771 @@ -1282,7 +1283,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79772 if (sk->sk_type != SOCK_STREAM)
79773 return -ENOPROTOOPT;
79774
79775 - msg.msg_control = optval;
79776 + msg.msg_control = (void __force_kernel *)optval;
79777 msg.msg_controllen = len;
79778 msg.msg_flags = flags;
79779
79780 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
79781 index 798358b..73570b7 100644
79782 --- a/net/ipv4/ipconfig.c
79783 +++ b/net/ipv4/ipconfig.c
79784 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
79785
79786 mm_segment_t oldfs = get_fs();
79787 set_fs(get_ds());
79788 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79789 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79790 set_fs(oldfs);
79791 return res;
79792 }
79793 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
79794
79795 mm_segment_t oldfs = get_fs();
79796 set_fs(get_ds());
79797 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79798 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79799 set_fs(oldfs);
79800 return res;
79801 }
79802 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
79803
79804 mm_segment_t oldfs = get_fs();
79805 set_fs(get_ds());
79806 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
79807 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
79808 set_fs(oldfs);
79809 return res;
79810 }
79811 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
79812 index 97e61ea..cac1bbb 100644
79813 --- a/net/ipv4/netfilter/arp_tables.c
79814 +++ b/net/ipv4/netfilter/arp_tables.c
79815 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
79816 #endif
79817
79818 static int get_info(struct net *net, void __user *user,
79819 - const int *len, int compat)
79820 + int len, int compat)
79821 {
79822 char name[XT_TABLE_MAXNAMELEN];
79823 struct xt_table *t;
79824 int ret;
79825
79826 - if (*len != sizeof(struct arpt_getinfo)) {
79827 - duprintf("length %u != %Zu\n", *len,
79828 + if (len != sizeof(struct arpt_getinfo)) {
79829 + duprintf("length %u != %Zu\n", len,
79830 sizeof(struct arpt_getinfo));
79831 return -EINVAL;
79832 }
79833 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
79834 info.size = private->size;
79835 strcpy(info.name, name);
79836
79837 - if (copy_to_user(user, &info, *len) != 0)
79838 + if (copy_to_user(user, &info, len) != 0)
79839 ret = -EFAULT;
79840 else
79841 ret = 0;
79842 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
79843
79844 switch (cmd) {
79845 case ARPT_SO_GET_INFO:
79846 - ret = get_info(sock_net(sk), user, len, 1);
79847 + ret = get_info(sock_net(sk), user, *len, 1);
79848 break;
79849 case ARPT_SO_GET_ENTRIES:
79850 ret = compat_get_entries(sock_net(sk), user, len);
79851 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
79852
79853 switch (cmd) {
79854 case ARPT_SO_GET_INFO:
79855 - ret = get_info(sock_net(sk), user, len, 0);
79856 + ret = get_info(sock_net(sk), user, *len, 0);
79857 break;
79858
79859 case ARPT_SO_GET_ENTRIES:
79860 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
79861 index 170b1fd..6105b91 100644
79862 --- a/net/ipv4/netfilter/ip_tables.c
79863 +++ b/net/ipv4/netfilter/ip_tables.c
79864 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
79865 #endif
79866
79867 static int get_info(struct net *net, void __user *user,
79868 - const int *len, int compat)
79869 + int len, int compat)
79870 {
79871 char name[XT_TABLE_MAXNAMELEN];
79872 struct xt_table *t;
79873 int ret;
79874
79875 - if (*len != sizeof(struct ipt_getinfo)) {
79876 - duprintf("length %u != %zu\n", *len,
79877 + if (len != sizeof(struct ipt_getinfo)) {
79878 + duprintf("length %u != %zu\n", len,
79879 sizeof(struct ipt_getinfo));
79880 return -EINVAL;
79881 }
79882 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
79883 info.size = private->size;
79884 strcpy(info.name, name);
79885
79886 - if (copy_to_user(user, &info, *len) != 0)
79887 + if (copy_to_user(user, &info, len) != 0)
79888 ret = -EFAULT;
79889 else
79890 ret = 0;
79891 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79892
79893 switch (cmd) {
79894 case IPT_SO_GET_INFO:
79895 - ret = get_info(sock_net(sk), user, len, 1);
79896 + ret = get_info(sock_net(sk), user, *len, 1);
79897 break;
79898 case IPT_SO_GET_ENTRIES:
79899 ret = compat_get_entries(sock_net(sk), user, len);
79900 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79901
79902 switch (cmd) {
79903 case IPT_SO_GET_INFO:
79904 - ret = get_info(sock_net(sk), user, len, 0);
79905 + ret = get_info(sock_net(sk), user, *len, 0);
79906 break;
79907
79908 case IPT_SO_GET_ENTRIES:
79909 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
79910 index 6f9c072..38ea6c6 100644
79911 --- a/net/ipv4/ping.c
79912 +++ b/net/ipv4/ping.c
79913 @@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
79914 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
79915 0, sock_i_ino(sp),
79916 atomic_read(&sp->sk_refcnt), sp,
79917 - atomic_read(&sp->sk_drops), len);
79918 + atomic_read_unchecked(&sp->sk_drops), len);
79919 }
79920
79921 static int ping_seq_show(struct seq_file *seq, void *v)
79922 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
79923 index 6f08991..55867ad 100644
79924 --- a/net/ipv4/raw.c
79925 +++ b/net/ipv4/raw.c
79926 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
79927 int raw_rcv(struct sock *sk, struct sk_buff *skb)
79928 {
79929 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
79930 - atomic_inc(&sk->sk_drops);
79931 + atomic_inc_unchecked(&sk->sk_drops);
79932 kfree_skb(skb);
79933 return NET_RX_DROP;
79934 }
79935 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
79936
79937 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
79938 {
79939 + struct icmp_filter filter;
79940 +
79941 if (optlen > sizeof(struct icmp_filter))
79942 optlen = sizeof(struct icmp_filter);
79943 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
79944 + if (copy_from_user(&filter, optval, optlen))
79945 return -EFAULT;
79946 + raw_sk(sk)->filter = filter;
79947 return 0;
79948 }
79949
79950 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
79951 {
79952 int len, ret = -EFAULT;
79953 + struct icmp_filter filter;
79954
79955 if (get_user(len, optlen))
79956 goto out;
79957 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
79958 if (len > sizeof(struct icmp_filter))
79959 len = sizeof(struct icmp_filter);
79960 ret = -EFAULT;
79961 - if (put_user(len, optlen) ||
79962 - copy_to_user(optval, &raw_sk(sk)->filter, len))
79963 + filter = raw_sk(sk)->filter;
79964 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
79965 goto out;
79966 ret = 0;
79967 out: return ret;
79968 @@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
79969 0, 0L, 0,
79970 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
79971 0, sock_i_ino(sp),
79972 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
79973 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
79974 }
79975
79976 static int raw_seq_show(struct seq_file *seq, void *v)
79977 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
79978 index 0fdfe4c..e7ea542 100644
79979 --- a/net/ipv4/route.c
79980 +++ b/net/ipv4/route.c
79981 @@ -2579,7 +2579,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
79982
79983 static __net_init int rt_genid_init(struct net *net)
79984 {
79985 - atomic_set(&net->rt_genid, 0);
79986 + atomic_set_unchecked(&net->rt_genid, 0);
79987 get_random_bytes(&net->ipv4.dev_addr_genid,
79988 sizeof(net->ipv4.dev_addr_genid));
79989 return 0;
79990 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
79991 index beabc80..48a6a10 100644
79992 --- a/net/ipv4/tcp_input.c
79993 +++ b/net/ipv4/tcp_input.c
79994 @@ -4709,7 +4709,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
79995 * simplifies code)
79996 */
79997 static void
79998 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
79999 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
80000 struct sk_buff *head, struct sk_buff *tail,
80001 u32 start, u32 end)
80002 {
80003 @@ -5541,6 +5541,9 @@ slow_path:
80004 if (len < (th->doff << 2) || tcp_checksum_complete_user(sk, skb))
80005 goto csum_error;
80006
80007 + if (!th->ack)
80008 + goto discard;
80009 +
80010 /*
80011 * Standard slow path.
80012 */
80013 @@ -5549,7 +5552,7 @@ slow_path:
80014 return 0;
80015
80016 step5:
80017 - if (th->ack && tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
80018 + if (tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
80019 goto discard;
80020
80021 /* ts_recent update must be made after we are sure that the packet
80022 @@ -5840,6 +5843,7 @@ discard:
80023 tcp_paws_reject(&tp->rx_opt, 0))
80024 goto discard_and_undo;
80025
80026 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
80027 if (th->syn) {
80028 /* We see SYN without ACK. It is attempt of
80029 * simultaneous connect with crossed SYNs.
80030 @@ -5890,6 +5894,7 @@ discard:
80031 goto discard;
80032 #endif
80033 }
80034 +#endif
80035 /* "fifth, if neither of the SYN or RST bits is set then
80036 * drop the segment and return."
80037 */
80038 @@ -5934,7 +5939,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
80039 goto discard;
80040
80041 if (th->syn) {
80042 - if (th->fin)
80043 + if (th->fin || th->urg || th->psh)
80044 goto discard;
80045 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
80046 return 1;
80047 @@ -5981,11 +5986,15 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
80048 if (tcp_check_req(sk, skb, req, NULL, true) == NULL)
80049 goto discard;
80050 }
80051 +
80052 + if (!th->ack)
80053 + goto discard;
80054 +
80055 if (!tcp_validate_incoming(sk, skb, th, 0))
80056 return 0;
80057
80058 /* step 5: check the ACK field */
80059 - if (th->ack) {
80060 + if (true) {
80061 int acceptable = tcp_ack(sk, skb, FLAG_SLOWPATH) > 0;
80062
80063 switch (sk->sk_state) {
80064 @@ -6135,8 +6144,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
80065 }
80066 break;
80067 }
80068 - } else
80069 - goto discard;
80070 + }
80071
80072 /* ts_recent update must be made after we are sure that the packet
80073 * is in window.
80074 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
80075 index e637770..364ff02 100644
80076 --- a/net/ipv4/tcp_ipv4.c
80077 +++ b/net/ipv4/tcp_ipv4.c
80078 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
80079 EXPORT_SYMBOL(sysctl_tcp_low_latency);
80080
80081
80082 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80083 +extern int grsec_enable_blackhole;
80084 +#endif
80085 +
80086 #ifdef CONFIG_TCP_MD5SIG
80087 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
80088 __be32 daddr, __be32 saddr, const struct tcphdr *th);
80089 @@ -1898,6 +1902,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
80090 return 0;
80091
80092 reset:
80093 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80094 + if (!grsec_enable_blackhole)
80095 +#endif
80096 tcp_v4_send_reset(rsk, skb);
80097 discard:
80098 kfree_skb(skb);
80099 @@ -1998,12 +2005,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
80100 TCP_SKB_CB(skb)->sacked = 0;
80101
80102 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80103 - if (!sk)
80104 + if (!sk) {
80105 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80106 + ret = 1;
80107 +#endif
80108 goto no_tcp_socket;
80109 -
80110 + }
80111 process:
80112 - if (sk->sk_state == TCP_TIME_WAIT)
80113 + if (sk->sk_state == TCP_TIME_WAIT) {
80114 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80115 + ret = 2;
80116 +#endif
80117 goto do_time_wait;
80118 + }
80119
80120 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
80121 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
80122 @@ -2054,6 +2068,10 @@ no_tcp_socket:
80123 bad_packet:
80124 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80125 } else {
80126 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80127 + if (!grsec_enable_blackhole || (ret == 1 &&
80128 + (skb->dev->flags & IFF_LOOPBACK)))
80129 +#endif
80130 tcp_v4_send_reset(NULL, skb);
80131 }
80132
80133 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
80134 index a7302d9..e3ec754 100644
80135 --- a/net/ipv4/tcp_minisocks.c
80136 +++ b/net/ipv4/tcp_minisocks.c
80137 @@ -27,6 +27,10 @@
80138 #include <net/inet_common.h>
80139 #include <net/xfrm.h>
80140
80141 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80142 +extern int grsec_enable_blackhole;
80143 +#endif
80144 +
80145 int sysctl_tcp_syncookies __read_mostly = 1;
80146 EXPORT_SYMBOL(sysctl_tcp_syncookies);
80147
80148 @@ -742,7 +746,10 @@ embryonic_reset:
80149 * avoid becoming vulnerable to outside attack aiming at
80150 * resetting legit local connections.
80151 */
80152 - req->rsk_ops->send_reset(sk, skb);
80153 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80154 + if (!grsec_enable_blackhole)
80155 +#endif
80156 + req->rsk_ops->send_reset(sk, skb);
80157 } else if (fastopen) { /* received a valid RST pkt */
80158 reqsk_fastopen_remove(sk, req, true);
80159 tcp_reset(sk);
80160 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
80161 index 4526fe6..1a34e43 100644
80162 --- a/net/ipv4/tcp_probe.c
80163 +++ b/net/ipv4/tcp_probe.c
80164 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
80165 if (cnt + width >= len)
80166 break;
80167
80168 - if (copy_to_user(buf + cnt, tbuf, width))
80169 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
80170 return -EFAULT;
80171 cnt += width;
80172 }
80173 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
80174 index d47c1b4..b0584de 100644
80175 --- a/net/ipv4/tcp_timer.c
80176 +++ b/net/ipv4/tcp_timer.c
80177 @@ -22,6 +22,10 @@
80178 #include <linux/gfp.h>
80179 #include <net/tcp.h>
80180
80181 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80182 +extern int grsec_lastack_retries;
80183 +#endif
80184 +
80185 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
80186 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
80187 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
80188 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
80189 }
80190 }
80191
80192 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80193 + if ((sk->sk_state == TCP_LAST_ACK) &&
80194 + (grsec_lastack_retries > 0) &&
80195 + (grsec_lastack_retries < retry_until))
80196 + retry_until = grsec_lastack_retries;
80197 +#endif
80198 +
80199 if (retransmits_timed_out(sk, retry_until,
80200 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
80201 /* Has it gone just too far? */
80202 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
80203 index 1f4d405..3524677 100644
80204 --- a/net/ipv4/udp.c
80205 +++ b/net/ipv4/udp.c
80206 @@ -87,6 +87,7 @@
80207 #include <linux/types.h>
80208 #include <linux/fcntl.h>
80209 #include <linux/module.h>
80210 +#include <linux/security.h>
80211 #include <linux/socket.h>
80212 #include <linux/sockios.h>
80213 #include <linux/igmp.h>
80214 @@ -111,6 +112,10 @@
80215 #include <trace/events/skb.h>
80216 #include "udp_impl.h"
80217
80218 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80219 +extern int grsec_enable_blackhole;
80220 +#endif
80221 +
80222 struct udp_table udp_table __read_mostly;
80223 EXPORT_SYMBOL(udp_table);
80224
80225 @@ -569,6 +574,9 @@ found:
80226 return s;
80227 }
80228
80229 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
80230 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
80231 +
80232 /*
80233 * This routine is called by the ICMP module when it gets some
80234 * sort of error condition. If err < 0 then the socket should
80235 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
80236 dport = usin->sin_port;
80237 if (dport == 0)
80238 return -EINVAL;
80239 +
80240 + err = gr_search_udp_sendmsg(sk, usin);
80241 + if (err)
80242 + return err;
80243 } else {
80244 if (sk->sk_state != TCP_ESTABLISHED)
80245 return -EDESTADDRREQ;
80246 +
80247 + err = gr_search_udp_sendmsg(sk, NULL);
80248 + if (err)
80249 + return err;
80250 +
80251 daddr = inet->inet_daddr;
80252 dport = inet->inet_dport;
80253 /* Open fast path for connected socket.
80254 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
80255 udp_lib_checksum_complete(skb)) {
80256 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80257 IS_UDPLITE(sk));
80258 - atomic_inc(&sk->sk_drops);
80259 + atomic_inc_unchecked(&sk->sk_drops);
80260 __skb_unlink(skb, rcvq);
80261 __skb_queue_tail(&list_kill, skb);
80262 }
80263 @@ -1194,6 +1211,10 @@ try_again:
80264 if (!skb)
80265 goto out;
80266
80267 + err = gr_search_udp_recvmsg(sk, skb);
80268 + if (err)
80269 + goto out_free;
80270 +
80271 ulen = skb->len - sizeof(struct udphdr);
80272 copied = len;
80273 if (copied > ulen)
80274 @@ -1227,7 +1248,7 @@ try_again:
80275 if (unlikely(err)) {
80276 trace_kfree_skb(skb, udp_recvmsg);
80277 if (!peeked) {
80278 - atomic_inc(&sk->sk_drops);
80279 + atomic_inc_unchecked(&sk->sk_drops);
80280 UDP_INC_STATS_USER(sock_net(sk),
80281 UDP_MIB_INERRORS, is_udplite);
80282 }
80283 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80284
80285 drop:
80286 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
80287 - atomic_inc(&sk->sk_drops);
80288 + atomic_inc_unchecked(&sk->sk_drops);
80289 kfree_skb(skb);
80290 return -1;
80291 }
80292 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
80293 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
80294
80295 if (!skb1) {
80296 - atomic_inc(&sk->sk_drops);
80297 + atomic_inc_unchecked(&sk->sk_drops);
80298 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80299 IS_UDPLITE(sk));
80300 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80301 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80302 goto csum_error;
80303
80304 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80305 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80306 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80307 +#endif
80308 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
80309
80310 /*
80311 @@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
80312 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
80313 0, sock_i_ino(sp),
80314 atomic_read(&sp->sk_refcnt), sp,
80315 - atomic_read(&sp->sk_drops), len);
80316 + atomic_read_unchecked(&sp->sk_drops), len);
80317 }
80318
80319 int udp4_seq_show(struct seq_file *seq, void *v)
80320 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
80321 index a468a36..b50ffde 100644
80322 --- a/net/ipv6/addrconf.c
80323 +++ b/net/ipv6/addrconf.c
80324 @@ -2121,7 +2121,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
80325 p.iph.ihl = 5;
80326 p.iph.protocol = IPPROTO_IPV6;
80327 p.iph.ttl = 64;
80328 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
80329 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
80330
80331 if (ops->ndo_do_ioctl) {
80332 mm_segment_t oldfs = get_fs();
80333 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
80334 index a23350c..899c62c 100644
80335 --- a/net/ipv6/ip6_gre.c
80336 +++ b/net/ipv6/ip6_gre.c
80337 @@ -1353,7 +1353,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
80338 }
80339
80340
80341 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
80342 +static struct inet6_protocol ip6gre_protocol = {
80343 .handler = ip6gre_rcv,
80344 .err_handler = ip6gre_err,
80345 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
80346 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
80347 index e02faed..9780f28 100644
80348 --- a/net/ipv6/ipv6_sockglue.c
80349 +++ b/net/ipv6/ipv6_sockglue.c
80350 @@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
80351 if (sk->sk_type != SOCK_STREAM)
80352 return -ENOPROTOOPT;
80353
80354 - msg.msg_control = optval;
80355 + msg.msg_control = (void __force_kernel *)optval;
80356 msg.msg_controllen = len;
80357 msg.msg_flags = flags;
80358
80359 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
80360 index d7cb045..8c0ded6 100644
80361 --- a/net/ipv6/netfilter/ip6_tables.c
80362 +++ b/net/ipv6/netfilter/ip6_tables.c
80363 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
80364 #endif
80365
80366 static int get_info(struct net *net, void __user *user,
80367 - const int *len, int compat)
80368 + int len, int compat)
80369 {
80370 char name[XT_TABLE_MAXNAMELEN];
80371 struct xt_table *t;
80372 int ret;
80373
80374 - if (*len != sizeof(struct ip6t_getinfo)) {
80375 - duprintf("length %u != %zu\n", *len,
80376 + if (len != sizeof(struct ip6t_getinfo)) {
80377 + duprintf("length %u != %zu\n", len,
80378 sizeof(struct ip6t_getinfo));
80379 return -EINVAL;
80380 }
80381 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
80382 info.size = private->size;
80383 strcpy(info.name, name);
80384
80385 - if (copy_to_user(user, &info, *len) != 0)
80386 + if (copy_to_user(user, &info, len) != 0)
80387 ret = -EFAULT;
80388 else
80389 ret = 0;
80390 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80391
80392 switch (cmd) {
80393 case IP6T_SO_GET_INFO:
80394 - ret = get_info(sock_net(sk), user, len, 1);
80395 + ret = get_info(sock_net(sk), user, *len, 1);
80396 break;
80397 case IP6T_SO_GET_ENTRIES:
80398 ret = compat_get_entries(sock_net(sk), user, len);
80399 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80400
80401 switch (cmd) {
80402 case IP6T_SO_GET_INFO:
80403 - ret = get_info(sock_net(sk), user, len, 0);
80404 + ret = get_info(sock_net(sk), user, *len, 0);
80405 break;
80406
80407 case IP6T_SO_GET_ENTRIES:
80408 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
80409 index d8e95c7..81422bc 100644
80410 --- a/net/ipv6/raw.c
80411 +++ b/net/ipv6/raw.c
80412 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
80413 {
80414 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
80415 skb_checksum_complete(skb)) {
80416 - atomic_inc(&sk->sk_drops);
80417 + atomic_inc_unchecked(&sk->sk_drops);
80418 kfree_skb(skb);
80419 return NET_RX_DROP;
80420 }
80421 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80422 struct raw6_sock *rp = raw6_sk(sk);
80423
80424 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
80425 - atomic_inc(&sk->sk_drops);
80426 + atomic_inc_unchecked(&sk->sk_drops);
80427 kfree_skb(skb);
80428 return NET_RX_DROP;
80429 }
80430 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
80431
80432 if (inet->hdrincl) {
80433 if (skb_checksum_complete(skb)) {
80434 - atomic_inc(&sk->sk_drops);
80435 + atomic_inc_unchecked(&sk->sk_drops);
80436 kfree_skb(skb);
80437 return NET_RX_DROP;
80438 }
80439 @@ -604,7 +604,7 @@ out:
80440 return err;
80441 }
80442
80443 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
80444 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
80445 struct flowi6 *fl6, struct dst_entry **dstp,
80446 unsigned int flags)
80447 {
80448 @@ -916,12 +916,15 @@ do_confirm:
80449 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
80450 char __user *optval, int optlen)
80451 {
80452 + struct icmp6_filter filter;
80453 +
80454 switch (optname) {
80455 case ICMPV6_FILTER:
80456 if (optlen > sizeof(struct icmp6_filter))
80457 optlen = sizeof(struct icmp6_filter);
80458 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
80459 + if (copy_from_user(&filter, optval, optlen))
80460 return -EFAULT;
80461 + raw6_sk(sk)->filter = filter;
80462 return 0;
80463 default:
80464 return -ENOPROTOOPT;
80465 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80466 char __user *optval, int __user *optlen)
80467 {
80468 int len;
80469 + struct icmp6_filter filter;
80470
80471 switch (optname) {
80472 case ICMPV6_FILTER:
80473 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80474 len = sizeof(struct icmp6_filter);
80475 if (put_user(len, optlen))
80476 return -EFAULT;
80477 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
80478 + filter = raw6_sk(sk)->filter;
80479 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
80480 return -EFAULT;
80481 return 0;
80482 default:
80483 @@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80484 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
80485 0,
80486 sock_i_ino(sp),
80487 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80488 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
80489 }
80490
80491 static int raw6_seq_show(struct seq_file *seq, void *v)
80492 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
80493 index 73f2a6b..f8049a1 100644
80494 --- a/net/ipv6/tcp_ipv6.c
80495 +++ b/net/ipv6/tcp_ipv6.c
80496 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
80497 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
80498 }
80499
80500 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80501 +extern int grsec_enable_blackhole;
80502 +#endif
80503 +
80504 static void tcp_v6_hash(struct sock *sk)
80505 {
80506 if (sk->sk_state != TCP_CLOSE) {
80507 @@ -1525,6 +1529,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
80508 return 0;
80509
80510 reset:
80511 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80512 + if (!grsec_enable_blackhole)
80513 +#endif
80514 tcp_v6_send_reset(sk, skb);
80515 discard:
80516 if (opt_skb)
80517 @@ -1606,12 +1613,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
80518 TCP_SKB_CB(skb)->sacked = 0;
80519
80520 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80521 - if (!sk)
80522 + if (!sk) {
80523 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80524 + ret = 1;
80525 +#endif
80526 goto no_tcp_socket;
80527 + }
80528
80529 process:
80530 - if (sk->sk_state == TCP_TIME_WAIT)
80531 + if (sk->sk_state == TCP_TIME_WAIT) {
80532 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80533 + ret = 2;
80534 +#endif
80535 goto do_time_wait;
80536 + }
80537
80538 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
80539 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
80540 @@ -1660,6 +1675,10 @@ no_tcp_socket:
80541 bad_packet:
80542 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80543 } else {
80544 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80545 + if (!grsec_enable_blackhole || (ret == 1 &&
80546 + (skb->dev->flags & IFF_LOOPBACK)))
80547 +#endif
80548 tcp_v6_send_reset(NULL, skb);
80549 }
80550
80551 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
80552 index fc99972..69397e8 100644
80553 --- a/net/ipv6/udp.c
80554 +++ b/net/ipv6/udp.c
80555 @@ -51,6 +51,10 @@
80556 #include <trace/events/skb.h>
80557 #include "udp_impl.h"
80558
80559 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80560 +extern int grsec_enable_blackhole;
80561 +#endif
80562 +
80563 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
80564 {
80565 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
80566 @@ -395,7 +399,7 @@ try_again:
80567 if (unlikely(err)) {
80568 trace_kfree_skb(skb, udpv6_recvmsg);
80569 if (!peeked) {
80570 - atomic_inc(&sk->sk_drops);
80571 + atomic_inc_unchecked(&sk->sk_drops);
80572 if (is_udp4)
80573 UDP_INC_STATS_USER(sock_net(sk),
80574 UDP_MIB_INERRORS,
80575 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80576 return rc;
80577 drop:
80578 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
80579 - atomic_inc(&sk->sk_drops);
80580 + atomic_inc_unchecked(&sk->sk_drops);
80581 kfree_skb(skb);
80582 return -1;
80583 }
80584 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
80585 if (likely(skb1 == NULL))
80586 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
80587 if (!skb1) {
80588 - atomic_inc(&sk->sk_drops);
80589 + atomic_inc_unchecked(&sk->sk_drops);
80590 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80591 IS_UDPLITE(sk));
80592 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80593 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80594 goto discard;
80595
80596 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80597 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80598 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80599 +#endif
80600 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
80601
80602 kfree_skb(skb);
80603 @@ -1473,7 +1480,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
80604 0,
80605 sock_i_ino(sp),
80606 atomic_read(&sp->sk_refcnt), sp,
80607 - atomic_read(&sp->sk_drops));
80608 + atomic_read_unchecked(&sp->sk_drops));
80609 }
80610
80611 int udp6_seq_show(struct seq_file *seq, void *v)
80612 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
80613 index 496ce2c..f79fac8 100644
80614 --- a/net/irda/ircomm/ircomm_tty.c
80615 +++ b/net/irda/ircomm/ircomm_tty.c
80616 @@ -311,12 +311,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80617 add_wait_queue(&port->open_wait, &wait);
80618
80619 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
80620 - __FILE__, __LINE__, tty->driver->name, port->count);
80621 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80622
80623 spin_lock_irqsave(&port->lock, flags);
80624 if (!tty_hung_up_p(filp)) {
80625 extra_count = 1;
80626 - port->count--;
80627 + atomic_dec(&port->count);
80628 }
80629 spin_unlock_irqrestore(&port->lock, flags);
80630 port->blocked_open++;
80631 @@ -352,7 +352,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80632 }
80633
80634 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
80635 - __FILE__, __LINE__, tty->driver->name, port->count);
80636 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80637
80638 schedule();
80639 }
80640 @@ -363,13 +363,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80641 if (extra_count) {
80642 /* ++ is not atomic, so this should be protected - Jean II */
80643 spin_lock_irqsave(&port->lock, flags);
80644 - port->count++;
80645 + atomic_inc(&port->count);
80646 spin_unlock_irqrestore(&port->lock, flags);
80647 }
80648 port->blocked_open--;
80649
80650 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
80651 - __FILE__, __LINE__, tty->driver->name, port->count);
80652 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80653
80654 if (!retval)
80655 port->flags |= ASYNC_NORMAL_ACTIVE;
80656 @@ -443,12 +443,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
80657
80658 /* ++ is not atomic, so this should be protected - Jean II */
80659 spin_lock_irqsave(&self->port.lock, flags);
80660 - self->port.count++;
80661 + atomic_inc(&self->port.count);
80662 spin_unlock_irqrestore(&self->port.lock, flags);
80663 tty_port_tty_set(&self->port, tty);
80664
80665 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
80666 - self->line, self->port.count);
80667 + self->line, atomic_read(&self->port.count));
80668
80669 /* Not really used by us, but lets do it anyway */
80670 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
80671 @@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
80672 tty_kref_put(port->tty);
80673 }
80674 port->tty = NULL;
80675 - port->count = 0;
80676 + atomic_set(&port->count, 0);
80677 spin_unlock_irqrestore(&port->lock, flags);
80678
80679 wake_up_interruptible(&port->open_wait);
80680 @@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
80681 seq_putc(m, '\n');
80682
80683 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
80684 - seq_printf(m, "Open count: %d\n", self->port.count);
80685 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
80686 seq_printf(m, "Max data size: %d\n", self->max_data_size);
80687 seq_printf(m, "Max header size: %d\n", self->max_header_size);
80688
80689 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
80690 index cd6f7a9..e63fe89 100644
80691 --- a/net/iucv/af_iucv.c
80692 +++ b/net/iucv/af_iucv.c
80693 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
80694
80695 write_lock_bh(&iucv_sk_list.lock);
80696
80697 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
80698 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80699 while (__iucv_get_sock_by_name(name)) {
80700 sprintf(name, "%08x",
80701 - atomic_inc_return(&iucv_sk_list.autobind_name));
80702 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80703 }
80704
80705 write_unlock_bh(&iucv_sk_list.lock);
80706 diff --git a/net/key/af_key.c b/net/key/af_key.c
80707 index 08897a3..0b812ab 100644
80708 --- a/net/key/af_key.c
80709 +++ b/net/key/af_key.c
80710 @@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
80711 static u32 get_acqseq(void)
80712 {
80713 u32 res;
80714 - static atomic_t acqseq;
80715 + static atomic_unchecked_t acqseq;
80716
80717 do {
80718 - res = atomic_inc_return(&acqseq);
80719 + res = atomic_inc_return_unchecked(&acqseq);
80720 } while (!res);
80721 return res;
80722 }
80723 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
80724 index 494da7f..6ce2ffd 100644
80725 --- a/net/mac80211/cfg.c
80726 +++ b/net/mac80211/cfg.c
80727 @@ -2604,7 +2604,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
80728 else
80729 local->probe_req_reg--;
80730
80731 - if (!local->open_count)
80732 + if (!local_read(&local->open_count))
80733 break;
80734
80735 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
80736 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
80737 index 493e2e8..be76574 100644
80738 --- a/net/mac80211/ieee80211_i.h
80739 +++ b/net/mac80211/ieee80211_i.h
80740 @@ -28,6 +28,7 @@
80741 #include <net/ieee80211_radiotap.h>
80742 #include <net/cfg80211.h>
80743 #include <net/mac80211.h>
80744 +#include <asm/local.h>
80745 #include "key.h"
80746 #include "sta_info.h"
80747 #include "debug.h"
80748 @@ -852,7 +853,7 @@ struct ieee80211_local {
80749 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
80750 spinlock_t queue_stop_reason_lock;
80751
80752 - int open_count;
80753 + local_t open_count;
80754 int monitors, cooked_mntrs;
80755 /* number of interfaces with corresponding FIF_ flags */
80756 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
80757 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
80758 index 0f5af91..4dba9e7 100644
80759 --- a/net/mac80211/iface.c
80760 +++ b/net/mac80211/iface.c
80761 @@ -465,7 +465,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80762 break;
80763 }
80764
80765 - if (local->open_count == 0) {
80766 + if (local_read(&local->open_count) == 0) {
80767 res = drv_start(local);
80768 if (res)
80769 goto err_del_bss;
80770 @@ -508,7 +508,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80771 break;
80772 }
80773
80774 - if (local->monitors == 0 && local->open_count == 0) {
80775 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
80776 res = ieee80211_add_virtual_monitor(local);
80777 if (res)
80778 goto err_stop;
80779 @@ -616,7 +616,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80780 mutex_unlock(&local->mtx);
80781
80782 if (coming_up)
80783 - local->open_count++;
80784 + local_inc(&local->open_count);
80785
80786 if (hw_reconf_flags)
80787 ieee80211_hw_config(local, hw_reconf_flags);
80788 @@ -630,7 +630,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80789 err_del_interface:
80790 drv_remove_interface(local, sdata);
80791 err_stop:
80792 - if (!local->open_count)
80793 + if (!local_read(&local->open_count))
80794 drv_stop(local);
80795 err_del_bss:
80796 sdata->bss = NULL;
80797 @@ -762,7 +762,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80798 }
80799
80800 if (going_down)
80801 - local->open_count--;
80802 + local_dec(&local->open_count);
80803
80804 switch (sdata->vif.type) {
80805 case NL80211_IFTYPE_AP_VLAN:
80806 @@ -818,7 +818,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80807
80808 ieee80211_recalc_ps(local, -1);
80809
80810 - if (local->open_count == 0) {
80811 + if (local_read(&local->open_count) == 0) {
80812 if (local->ops->napi_poll)
80813 napi_disable(&local->napi);
80814 ieee80211_clear_tx_pending(local);
80815 @@ -850,7 +850,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80816 }
80817 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
80818
80819 - if (local->monitors == local->open_count && local->monitors > 0)
80820 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
80821 ieee80211_add_virtual_monitor(local);
80822 }
80823
80824 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
80825 index f57f597..e0a7c03 100644
80826 --- a/net/mac80211/main.c
80827 +++ b/net/mac80211/main.c
80828 @@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
80829 local->hw.conf.power_level = power;
80830 }
80831
80832 - if (changed && local->open_count) {
80833 + if (changed && local_read(&local->open_count)) {
80834 ret = drv_config(local, changed);
80835 /*
80836 * Goal:
80837 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
80838 index 5c572e7..ecf75ce 100644
80839 --- a/net/mac80211/pm.c
80840 +++ b/net/mac80211/pm.c
80841 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80842 struct ieee80211_sub_if_data *sdata;
80843 struct sta_info *sta;
80844
80845 - if (!local->open_count)
80846 + if (!local_read(&local->open_count))
80847 goto suspend;
80848
80849 ieee80211_scan_cancel(local);
80850 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80851 cancel_work_sync(&local->dynamic_ps_enable_work);
80852 del_timer_sync(&local->dynamic_ps_timer);
80853
80854 - local->wowlan = wowlan && local->open_count;
80855 + local->wowlan = wowlan && local_read(&local->open_count);
80856 if (local->wowlan) {
80857 int err = drv_suspend(local, wowlan);
80858 if (err < 0) {
80859 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80860 drv_remove_interface(local, sdata);
80861
80862 /* stop hardware - this must stop RX */
80863 - if (local->open_count)
80864 + if (local_read(&local->open_count))
80865 ieee80211_stop_device(local);
80866
80867 suspend:
80868 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
80869 index 3313c11..bec9f17 100644
80870 --- a/net/mac80211/rate.c
80871 +++ b/net/mac80211/rate.c
80872 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
80873
80874 ASSERT_RTNL();
80875
80876 - if (local->open_count)
80877 + if (local_read(&local->open_count))
80878 return -EBUSY;
80879
80880 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
80881 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
80882 index c97a065..ff61928 100644
80883 --- a/net/mac80211/rc80211_pid_debugfs.c
80884 +++ b/net/mac80211/rc80211_pid_debugfs.c
80885 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
80886
80887 spin_unlock_irqrestore(&events->lock, status);
80888
80889 - if (copy_to_user(buf, pb, p))
80890 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
80891 return -EFAULT;
80892
80893 return p;
80894 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
80895 index 0151ae3..26709d3 100644
80896 --- a/net/mac80211/util.c
80897 +++ b/net/mac80211/util.c
80898 @@ -1332,7 +1332,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
80899 }
80900 #endif
80901 /* everything else happens only if HW was up & running */
80902 - if (!local->open_count)
80903 + if (!local_read(&local->open_count))
80904 goto wake_up;
80905
80906 /*
80907 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
80908 index 49e96df..63a51c3 100644
80909 --- a/net/netfilter/Kconfig
80910 +++ b/net/netfilter/Kconfig
80911 @@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
80912
80913 To compile it as a module, choose M here. If unsure, say N.
80914
80915 +config NETFILTER_XT_MATCH_GRADM
80916 + tristate '"gradm" match support'
80917 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
80918 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
80919 + ---help---
80920 + The gradm match allows to match on grsecurity RBAC being enabled.
80921 + It is useful when iptables rules are applied early on bootup to
80922 + prevent connections to the machine (except from a trusted host)
80923 + while the RBAC system is disabled.
80924 +
80925 config NETFILTER_XT_MATCH_HASHLIMIT
80926 tristate '"hashlimit" match support'
80927 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
80928 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
80929 index 3259697..54d5393 100644
80930 --- a/net/netfilter/Makefile
80931 +++ b/net/netfilter/Makefile
80932 @@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
80933 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
80934 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
80935 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
80936 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
80937 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
80938 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
80939 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
80940 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
80941 index 1548df9..98ad9b4 100644
80942 --- a/net/netfilter/ipvs/ip_vs_conn.c
80943 +++ b/net/netfilter/ipvs/ip_vs_conn.c
80944 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
80945 /* Increase the refcnt counter of the dest */
80946 atomic_inc(&dest->refcnt);
80947
80948 - conn_flags = atomic_read(&dest->conn_flags);
80949 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
80950 if (cp->protocol != IPPROTO_UDP)
80951 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
80952 flags = cp->flags;
80953 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
80954 atomic_set(&cp->refcnt, 1);
80955
80956 atomic_set(&cp->n_control, 0);
80957 - atomic_set(&cp->in_pkts, 0);
80958 + atomic_set_unchecked(&cp->in_pkts, 0);
80959
80960 atomic_inc(&ipvs->conn_count);
80961 if (flags & IP_VS_CONN_F_NO_CPORT)
80962 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
80963
80964 /* Don't drop the entry if its number of incoming packets is not
80965 located in [0, 8] */
80966 - i = atomic_read(&cp->in_pkts);
80967 + i = atomic_read_unchecked(&cp->in_pkts);
80968 if (i > 8 || i < 0) return 0;
80969
80970 if (!todrop_rate[i]) return 0;
80971 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
80972 index 58918e2..4d177a9 100644
80973 --- a/net/netfilter/ipvs/ip_vs_core.c
80974 +++ b/net/netfilter/ipvs/ip_vs_core.c
80975 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
80976 ret = cp->packet_xmit(skb, cp, pd->pp);
80977 /* do not touch skb anymore */
80978
80979 - atomic_inc(&cp->in_pkts);
80980 + atomic_inc_unchecked(&cp->in_pkts);
80981 ip_vs_conn_put(cp);
80982 return ret;
80983 }
80984 @@ -1681,7 +1681,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
80985 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
80986 pkts = sysctl_sync_threshold(ipvs);
80987 else
80988 - pkts = atomic_add_return(1, &cp->in_pkts);
80989 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80990
80991 if (ipvs->sync_state & IP_VS_STATE_MASTER)
80992 ip_vs_sync_conn(net, cp, pkts);
80993 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
80994 index c4ee437..a774a74 100644
80995 --- a/net/netfilter/ipvs/ip_vs_ctl.c
80996 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
80997 @@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
80998 ip_vs_rs_hash(ipvs, dest);
80999 write_unlock_bh(&ipvs->rs_lock);
81000 }
81001 - atomic_set(&dest->conn_flags, conn_flags);
81002 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
81003
81004 /* bind the service */
81005 if (!dest->svc) {
81006 @@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81007 " %-7s %-6d %-10d %-10d\n",
81008 &dest->addr.in6,
81009 ntohs(dest->port),
81010 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81011 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81012 atomic_read(&dest->weight),
81013 atomic_read(&dest->activeconns),
81014 atomic_read(&dest->inactconns));
81015 @@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
81016 "%-7s %-6d %-10d %-10d\n",
81017 ntohl(dest->addr.ip),
81018 ntohs(dest->port),
81019 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
81020 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
81021 atomic_read(&dest->weight),
81022 atomic_read(&dest->activeconns),
81023 atomic_read(&dest->inactconns));
81024 @@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
81025
81026 entry.addr = dest->addr.ip;
81027 entry.port = dest->port;
81028 - entry.conn_flags = atomic_read(&dest->conn_flags);
81029 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
81030 entry.weight = atomic_read(&dest->weight);
81031 entry.u_threshold = dest->u_threshold;
81032 entry.l_threshold = dest->l_threshold;
81033 @@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
81034 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
81035 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
81036 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
81037 - (atomic_read(&dest->conn_flags) &
81038 + (atomic_read_unchecked(&dest->conn_flags) &
81039 IP_VS_CONN_F_FWD_MASK)) ||
81040 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
81041 atomic_read(&dest->weight)) ||
81042 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
81043 index effa10c..9058928 100644
81044 --- a/net/netfilter/ipvs/ip_vs_sync.c
81045 +++ b/net/netfilter/ipvs/ip_vs_sync.c
81046 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
81047 cp = cp->control;
81048 if (cp) {
81049 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
81050 - pkts = atomic_add_return(1, &cp->in_pkts);
81051 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81052 else
81053 pkts = sysctl_sync_threshold(ipvs);
81054 ip_vs_sync_conn(net, cp->control, pkts);
81055 @@ -758,7 +758,7 @@ control:
81056 if (!cp)
81057 return;
81058 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
81059 - pkts = atomic_add_return(1, &cp->in_pkts);
81060 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
81061 else
81062 pkts = sysctl_sync_threshold(ipvs);
81063 goto sloop;
81064 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
81065
81066 if (opt)
81067 memcpy(&cp->in_seq, opt, sizeof(*opt));
81068 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
81069 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
81070 cp->state = state;
81071 cp->old_state = cp->state;
81072 /*
81073 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
81074 index cc4c809..50f8fe5 100644
81075 --- a/net/netfilter/ipvs/ip_vs_xmit.c
81076 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
81077 @@ -1202,7 +1202,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
81078 else
81079 rc = NF_ACCEPT;
81080 /* do not touch skb anymore */
81081 - atomic_inc(&cp->in_pkts);
81082 + atomic_inc_unchecked(&cp->in_pkts);
81083 goto out;
81084 }
81085
81086 @@ -1323,7 +1323,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
81087 else
81088 rc = NF_ACCEPT;
81089 /* do not touch skb anymore */
81090 - atomic_inc(&cp->in_pkts);
81091 + atomic_inc_unchecked(&cp->in_pkts);
81092 goto out;
81093 }
81094
81095 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
81096 index ec02168..f0caab6 100644
81097 --- a/net/netfilter/nf_conntrack_core.c
81098 +++ b/net/netfilter/nf_conntrack_core.c
81099 @@ -1533,6 +1533,10 @@ err_extend:
81100 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
81101 #define DYING_NULLS_VAL ((1<<30)+1)
81102
81103 +#ifdef CONFIG_GRKERNSEC_HIDESYM
81104 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
81105 +#endif
81106 +
81107 static int nf_conntrack_init_net(struct net *net)
81108 {
81109 int ret;
81110 @@ -1546,7 +1550,11 @@ static int nf_conntrack_init_net(struct net *net)
81111 goto err_stat;
81112 }
81113
81114 +#ifdef CONFIG_GRKERNSEC_HIDESYM
81115 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
81116 +#else
81117 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
81118 +#endif
81119 if (!net->ct.slabname) {
81120 ret = -ENOMEM;
81121 goto err_slabname;
81122 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
81123 index 92fd8ec..3f6ea4b 100644
81124 --- a/net/netfilter/nfnetlink_log.c
81125 +++ b/net/netfilter/nfnetlink_log.c
81126 @@ -72,7 +72,7 @@ struct nfulnl_instance {
81127 };
81128
81129 static DEFINE_SPINLOCK(instances_lock);
81130 -static atomic_t global_seq;
81131 +static atomic_unchecked_t global_seq;
81132
81133 #define INSTANCE_BUCKETS 16
81134 static struct hlist_head instance_table[INSTANCE_BUCKETS];
81135 @@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
81136 /* global sequence number */
81137 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
81138 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
81139 - htonl(atomic_inc_return(&global_seq))))
81140 + htonl(atomic_inc_return_unchecked(&global_seq))))
81141 goto nla_put_failure;
81142
81143 if (data_len) {
81144 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
81145 new file mode 100644
81146 index 0000000..c566332
81147 --- /dev/null
81148 +++ b/net/netfilter/xt_gradm.c
81149 @@ -0,0 +1,51 @@
81150 +/*
81151 + * gradm match for netfilter
81152 + * Copyright © Zbigniew Krzystolik, 2010
81153 + *
81154 + * This program is free software; you can redistribute it and/or modify
81155 + * it under the terms of the GNU General Public License; either version
81156 + * 2 or 3 as published by the Free Software Foundation.
81157 + */
81158 +#include <linux/module.h>
81159 +#include <linux/moduleparam.h>
81160 +#include <linux/skbuff.h>
81161 +#include <linux/netfilter/x_tables.h>
81162 +#include <linux/grsecurity.h>
81163 +#include <linux/netfilter/xt_gradm.h>
81164 +
81165 +static bool
81166 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
81167 +{
81168 + const struct xt_gradm_mtinfo *info = par->matchinfo;
81169 + bool retval = false;
81170 + if (gr_acl_is_enabled())
81171 + retval = true;
81172 + return retval ^ info->invflags;
81173 +}
81174 +
81175 +static struct xt_match gradm_mt_reg __read_mostly = {
81176 + .name = "gradm",
81177 + .revision = 0,
81178 + .family = NFPROTO_UNSPEC,
81179 + .match = gradm_mt,
81180 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
81181 + .me = THIS_MODULE,
81182 +};
81183 +
81184 +static int __init gradm_mt_init(void)
81185 +{
81186 + return xt_register_match(&gradm_mt_reg);
81187 +}
81188 +
81189 +static void __exit gradm_mt_exit(void)
81190 +{
81191 + xt_unregister_match(&gradm_mt_reg);
81192 +}
81193 +
81194 +module_init(gradm_mt_init);
81195 +module_exit(gradm_mt_exit);
81196 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
81197 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
81198 +MODULE_LICENSE("GPL");
81199 +MODULE_ALIAS("ipt_gradm");
81200 +MODULE_ALIAS("ip6t_gradm");
81201 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
81202 index 4fe4fb4..87a89e5 100644
81203 --- a/net/netfilter/xt_statistic.c
81204 +++ b/net/netfilter/xt_statistic.c
81205 @@ -19,7 +19,7 @@
81206 #include <linux/module.h>
81207
81208 struct xt_statistic_priv {
81209 - atomic_t count;
81210 + atomic_unchecked_t count;
81211 } ____cacheline_aligned_in_smp;
81212
81213 MODULE_LICENSE("GPL");
81214 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
81215 break;
81216 case XT_STATISTIC_MODE_NTH:
81217 do {
81218 - oval = atomic_read(&info->master->count);
81219 + oval = atomic_read_unchecked(&info->master->count);
81220 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
81221 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
81222 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
81223 if (nval == 0)
81224 ret = !ret;
81225 break;
81226 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
81227 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
81228 if (info->master == NULL)
81229 return -ENOMEM;
81230 - atomic_set(&info->master->count, info->u.nth.count);
81231 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
81232
81233 return 0;
81234 }
81235 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
81236 index 4da797f..eb1df70 100644
81237 --- a/net/netlink/af_netlink.c
81238 +++ b/net/netlink/af_netlink.c
81239 @@ -782,7 +782,7 @@ static void netlink_overrun(struct sock *sk)
81240 sk->sk_error_report(sk);
81241 }
81242 }
81243 - atomic_inc(&sk->sk_drops);
81244 + atomic_inc_unchecked(&sk->sk_drops);
81245 }
81246
81247 static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
81248 @@ -2068,7 +2068,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
81249 sk_wmem_alloc_get(s),
81250 nlk->cb,
81251 atomic_read(&s->sk_refcnt),
81252 - atomic_read(&s->sk_drops),
81253 + atomic_read_unchecked(&s->sk_drops),
81254 sock_i_ino(s)
81255 );
81256
81257 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
81258 index 7261eb8..44e8ac6 100644
81259 --- a/net/netrom/af_netrom.c
81260 +++ b/net/netrom/af_netrom.c
81261 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
81262 struct sock *sk = sock->sk;
81263 struct nr_sock *nr = nr_sk(sk);
81264
81265 + memset(sax, 0, sizeof(*sax));
81266 lock_sock(sk);
81267 if (peer != 0) {
81268 if (sk->sk_state != TCP_ESTABLISHED) {
81269 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
81270 *uaddr_len = sizeof(struct full_sockaddr_ax25);
81271 } else {
81272 sax->fsa_ax25.sax25_family = AF_NETROM;
81273 - sax->fsa_ax25.sax25_ndigis = 0;
81274 sax->fsa_ax25.sax25_call = nr->source_addr;
81275 *uaddr_len = sizeof(struct sockaddr_ax25);
81276 }
81277 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
81278 index 5db6316..c9bf90e 100644
81279 --- a/net/packet/af_packet.c
81280 +++ b/net/packet/af_packet.c
81281 @@ -1578,7 +1578,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
81282
81283 spin_lock(&sk->sk_receive_queue.lock);
81284 po->stats.tp_packets++;
81285 - skb->dropcount = atomic_read(&sk->sk_drops);
81286 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
81287 __skb_queue_tail(&sk->sk_receive_queue, skb);
81288 spin_unlock(&sk->sk_receive_queue.lock);
81289 sk->sk_data_ready(sk, skb->len);
81290 @@ -1587,7 +1587,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
81291 drop_n_acct:
81292 spin_lock(&sk->sk_receive_queue.lock);
81293 po->stats.tp_drops++;
81294 - atomic_inc(&sk->sk_drops);
81295 + atomic_inc_unchecked(&sk->sk_drops);
81296 spin_unlock(&sk->sk_receive_queue.lock);
81297
81298 drop_n_restore:
81299 @@ -2539,6 +2539,7 @@ out:
81300
81301 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
81302 {
81303 + struct sock_extended_err ee;
81304 struct sock_exterr_skb *serr;
81305 struct sk_buff *skb, *skb2;
81306 int copied, err;
81307 @@ -2560,8 +2561,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
81308 sock_recv_timestamp(msg, sk, skb);
81309
81310 serr = SKB_EXT_ERR(skb);
81311 + ee = serr->ee;
81312 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
81313 - sizeof(serr->ee), &serr->ee);
81314 + sizeof ee, &ee);
81315
81316 msg->msg_flags |= MSG_ERRQUEUE;
81317 err = copied;
81318 @@ -3173,7 +3175,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
81319 case PACKET_HDRLEN:
81320 if (len > sizeof(int))
81321 len = sizeof(int);
81322 - if (copy_from_user(&val, optval, len))
81323 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
81324 return -EFAULT;
81325 switch (val) {
81326 case TPACKET_V1:
81327 @@ -3212,7 +3214,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
81328 len = lv;
81329 if (put_user(len, optlen))
81330 return -EFAULT;
81331 - if (copy_to_user(optval, data, len))
81332 + if (len > sizeof(st) || copy_to_user(optval, data, len))
81333 return -EFAULT;
81334 return 0;
81335 }
81336 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
81337 index 5a940db..f0b9c12 100644
81338 --- a/net/phonet/af_phonet.c
81339 +++ b/net/phonet/af_phonet.c
81340 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
81341 {
81342 struct phonet_protocol *pp;
81343
81344 - if (protocol >= PHONET_NPROTO)
81345 + if (protocol < 0 || protocol >= PHONET_NPROTO)
81346 return NULL;
81347
81348 rcu_read_lock();
81349 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
81350 {
81351 int err = 0;
81352
81353 - if (protocol >= PHONET_NPROTO)
81354 + if (protocol < 0 || protocol >= PHONET_NPROTO)
81355 return -EINVAL;
81356
81357 err = proto_register(pp->prot, 1);
81358 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
81359 index 576f22c..bc7a71b 100644
81360 --- a/net/phonet/pep.c
81361 +++ b/net/phonet/pep.c
81362 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
81363
81364 case PNS_PEP_CTRL_REQ:
81365 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
81366 - atomic_inc(&sk->sk_drops);
81367 + atomic_inc_unchecked(&sk->sk_drops);
81368 break;
81369 }
81370 __skb_pull(skb, 4);
81371 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
81372 }
81373
81374 if (pn->rx_credits == 0) {
81375 - atomic_inc(&sk->sk_drops);
81376 + atomic_inc_unchecked(&sk->sk_drops);
81377 err = -ENOBUFS;
81378 break;
81379 }
81380 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
81381 }
81382
81383 if (pn->rx_credits == 0) {
81384 - atomic_inc(&sk->sk_drops);
81385 + atomic_inc_unchecked(&sk->sk_drops);
81386 err = NET_RX_DROP;
81387 break;
81388 }
81389 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
81390 index b7e9827..c264c85 100644
81391 --- a/net/phonet/socket.c
81392 +++ b/net/phonet/socket.c
81393 @@ -615,7 +615,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
81394 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
81395 sock_i_ino(sk),
81396 atomic_read(&sk->sk_refcnt), sk,
81397 - atomic_read(&sk->sk_drops), &len);
81398 + atomic_read_unchecked(&sk->sk_drops), &len);
81399 }
81400 seq_printf(seq, "%*s\n", 127 - len, "");
81401 return 0;
81402 diff --git a/net/rds/cong.c b/net/rds/cong.c
81403 index e5b65ac..f3b6fb7 100644
81404 --- a/net/rds/cong.c
81405 +++ b/net/rds/cong.c
81406 @@ -78,7 +78,7 @@
81407 * finds that the saved generation number is smaller than the global generation
81408 * number, it wakes up the process.
81409 */
81410 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
81411 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
81412
81413 /*
81414 * Congestion monitoring
81415 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
81416 rdsdebug("waking map %p for %pI4\n",
81417 map, &map->m_addr);
81418 rds_stats_inc(s_cong_update_received);
81419 - atomic_inc(&rds_cong_generation);
81420 + atomic_inc_unchecked(&rds_cong_generation);
81421 if (waitqueue_active(&map->m_waitq))
81422 wake_up(&map->m_waitq);
81423 if (waitqueue_active(&rds_poll_waitq))
81424 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
81425
81426 int rds_cong_updated_since(unsigned long *recent)
81427 {
81428 - unsigned long gen = atomic_read(&rds_cong_generation);
81429 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
81430
81431 if (likely(*recent == gen))
81432 return 0;
81433 diff --git a/net/rds/ib.h b/net/rds/ib.h
81434 index 8d2b3d5..227ec5b 100644
81435 --- a/net/rds/ib.h
81436 +++ b/net/rds/ib.h
81437 @@ -128,7 +128,7 @@ struct rds_ib_connection {
81438 /* sending acks */
81439 unsigned long i_ack_flags;
81440 #ifdef KERNEL_HAS_ATOMIC64
81441 - atomic64_t i_ack_next; /* next ACK to send */
81442 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
81443 #else
81444 spinlock_t i_ack_lock; /* protect i_ack_next */
81445 u64 i_ack_next; /* next ACK to send */
81446 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
81447 index a1e1162..265e129 100644
81448 --- a/net/rds/ib_cm.c
81449 +++ b/net/rds/ib_cm.c
81450 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
81451 /* Clear the ACK state */
81452 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
81453 #ifdef KERNEL_HAS_ATOMIC64
81454 - atomic64_set(&ic->i_ack_next, 0);
81455 + atomic64_set_unchecked(&ic->i_ack_next, 0);
81456 #else
81457 ic->i_ack_next = 0;
81458 #endif
81459 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
81460 index 8d19491..05a3e65 100644
81461 --- a/net/rds/ib_recv.c
81462 +++ b/net/rds/ib_recv.c
81463 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
81464 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
81465 int ack_required)
81466 {
81467 - atomic64_set(&ic->i_ack_next, seq);
81468 + atomic64_set_unchecked(&ic->i_ack_next, seq);
81469 if (ack_required) {
81470 smp_mb__before_clear_bit();
81471 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81472 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
81473 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81474 smp_mb__after_clear_bit();
81475
81476 - return atomic64_read(&ic->i_ack_next);
81477 + return atomic64_read_unchecked(&ic->i_ack_next);
81478 }
81479 #endif
81480
81481 diff --git a/net/rds/iw.h b/net/rds/iw.h
81482 index 04ce3b1..48119a6 100644
81483 --- a/net/rds/iw.h
81484 +++ b/net/rds/iw.h
81485 @@ -134,7 +134,7 @@ struct rds_iw_connection {
81486 /* sending acks */
81487 unsigned long i_ack_flags;
81488 #ifdef KERNEL_HAS_ATOMIC64
81489 - atomic64_t i_ack_next; /* next ACK to send */
81490 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
81491 #else
81492 spinlock_t i_ack_lock; /* protect i_ack_next */
81493 u64 i_ack_next; /* next ACK to send */
81494 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
81495 index a91e1db..cf3053f 100644
81496 --- a/net/rds/iw_cm.c
81497 +++ b/net/rds/iw_cm.c
81498 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
81499 /* Clear the ACK state */
81500 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
81501 #ifdef KERNEL_HAS_ATOMIC64
81502 - atomic64_set(&ic->i_ack_next, 0);
81503 + atomic64_set_unchecked(&ic->i_ack_next, 0);
81504 #else
81505 ic->i_ack_next = 0;
81506 #endif
81507 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
81508 index 4503335..db566b4 100644
81509 --- a/net/rds/iw_recv.c
81510 +++ b/net/rds/iw_recv.c
81511 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
81512 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
81513 int ack_required)
81514 {
81515 - atomic64_set(&ic->i_ack_next, seq);
81516 + atomic64_set_unchecked(&ic->i_ack_next, seq);
81517 if (ack_required) {
81518 smp_mb__before_clear_bit();
81519 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81520 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
81521 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
81522 smp_mb__after_clear_bit();
81523
81524 - return atomic64_read(&ic->i_ack_next);
81525 + return atomic64_read_unchecked(&ic->i_ack_next);
81526 }
81527 #endif
81528
81529 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
81530 index edac9ef..16bcb98 100644
81531 --- a/net/rds/tcp.c
81532 +++ b/net/rds/tcp.c
81533 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
81534 int val = 1;
81535
81536 set_fs(KERNEL_DS);
81537 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
81538 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
81539 sizeof(val));
81540 set_fs(oldfs);
81541 }
81542 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
81543 index 81cf5a4..b5826ff 100644
81544 --- a/net/rds/tcp_send.c
81545 +++ b/net/rds/tcp_send.c
81546 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
81547
81548 oldfs = get_fs();
81549 set_fs(KERNEL_DS);
81550 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
81551 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
81552 sizeof(val));
81553 set_fs(oldfs);
81554 }
81555 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
81556 index 05996d0..5a1dfe0 100644
81557 --- a/net/rxrpc/af_rxrpc.c
81558 +++ b/net/rxrpc/af_rxrpc.c
81559 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
81560 __be32 rxrpc_epoch;
81561
81562 /* current debugging ID */
81563 -atomic_t rxrpc_debug_id;
81564 +atomic_unchecked_t rxrpc_debug_id;
81565
81566 /* count of skbs currently in use */
81567 atomic_t rxrpc_n_skbs;
81568 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
81569 index e4d9cbc..b229649 100644
81570 --- a/net/rxrpc/ar-ack.c
81571 +++ b/net/rxrpc/ar-ack.c
81572 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
81573
81574 _enter("{%d,%d,%d,%d},",
81575 call->acks_hard, call->acks_unacked,
81576 - atomic_read(&call->sequence),
81577 + atomic_read_unchecked(&call->sequence),
81578 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
81579
81580 stop = 0;
81581 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
81582
81583 /* each Tx packet has a new serial number */
81584 sp->hdr.serial =
81585 - htonl(atomic_inc_return(&call->conn->serial));
81586 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
81587
81588 hdr = (struct rxrpc_header *) txb->head;
81589 hdr->serial = sp->hdr.serial;
81590 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
81591 */
81592 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
81593 {
81594 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
81595 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
81596 }
81597
81598 /*
81599 @@ -629,7 +629,7 @@ process_further:
81600
81601 latest = ntohl(sp->hdr.serial);
81602 hard = ntohl(ack.firstPacket);
81603 - tx = atomic_read(&call->sequence);
81604 + tx = atomic_read_unchecked(&call->sequence);
81605
81606 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
81607 latest,
81608 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
81609 goto maybe_reschedule;
81610
81611 send_ACK_with_skew:
81612 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
81613 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
81614 ntohl(ack.serial));
81615 send_ACK:
81616 mtu = call->conn->trans->peer->if_mtu;
81617 @@ -1173,7 +1173,7 @@ send_ACK:
81618 ackinfo.rxMTU = htonl(5692);
81619 ackinfo.jumbo_max = htonl(4);
81620
81621 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
81622 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
81623 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
81624 ntohl(hdr.serial),
81625 ntohs(ack.maxSkew),
81626 @@ -1191,7 +1191,7 @@ send_ACK:
81627 send_message:
81628 _debug("send message");
81629
81630 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
81631 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
81632 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
81633 send_message_2:
81634
81635 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
81636 index a3bbb36..3341fb9 100644
81637 --- a/net/rxrpc/ar-call.c
81638 +++ b/net/rxrpc/ar-call.c
81639 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
81640 spin_lock_init(&call->lock);
81641 rwlock_init(&call->state_lock);
81642 atomic_set(&call->usage, 1);
81643 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
81644 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81645 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
81646
81647 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
81648 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
81649 index 4106ca9..a338d7a 100644
81650 --- a/net/rxrpc/ar-connection.c
81651 +++ b/net/rxrpc/ar-connection.c
81652 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
81653 rwlock_init(&conn->lock);
81654 spin_lock_init(&conn->state_lock);
81655 atomic_set(&conn->usage, 1);
81656 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
81657 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81658 conn->avail_calls = RXRPC_MAXCALLS;
81659 conn->size_align = 4;
81660 conn->header_size = sizeof(struct rxrpc_header);
81661 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
81662 index e7ed43a..6afa140 100644
81663 --- a/net/rxrpc/ar-connevent.c
81664 +++ b/net/rxrpc/ar-connevent.c
81665 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
81666
81667 len = iov[0].iov_len + iov[1].iov_len;
81668
81669 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
81670 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
81671 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
81672
81673 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
81674 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
81675 index 529572f..c758ca7 100644
81676 --- a/net/rxrpc/ar-input.c
81677 +++ b/net/rxrpc/ar-input.c
81678 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
81679 /* track the latest serial number on this connection for ACK packet
81680 * information */
81681 serial = ntohl(sp->hdr.serial);
81682 - hi_serial = atomic_read(&call->conn->hi_serial);
81683 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
81684 while (serial > hi_serial)
81685 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
81686 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
81687 serial);
81688
81689 /* request ACK generation for any ACK or DATA packet that requests
81690 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
81691 index a693aca..81e7293 100644
81692 --- a/net/rxrpc/ar-internal.h
81693 +++ b/net/rxrpc/ar-internal.h
81694 @@ -272,8 +272,8 @@ struct rxrpc_connection {
81695 int error; /* error code for local abort */
81696 int debug_id; /* debug ID for printks */
81697 unsigned int call_counter; /* call ID counter */
81698 - atomic_t serial; /* packet serial number counter */
81699 - atomic_t hi_serial; /* highest serial number received */
81700 + atomic_unchecked_t serial; /* packet serial number counter */
81701 + atomic_unchecked_t hi_serial; /* highest serial number received */
81702 u8 avail_calls; /* number of calls available */
81703 u8 size_align; /* data size alignment (for security) */
81704 u8 header_size; /* rxrpc + security header size */
81705 @@ -346,7 +346,7 @@ struct rxrpc_call {
81706 spinlock_t lock;
81707 rwlock_t state_lock; /* lock for state transition */
81708 atomic_t usage;
81709 - atomic_t sequence; /* Tx data packet sequence counter */
81710 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
81711 u32 abort_code; /* local/remote abort code */
81712 enum { /* current state of call */
81713 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
81714 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
81715 */
81716 extern atomic_t rxrpc_n_skbs;
81717 extern __be32 rxrpc_epoch;
81718 -extern atomic_t rxrpc_debug_id;
81719 +extern atomic_unchecked_t rxrpc_debug_id;
81720 extern struct workqueue_struct *rxrpc_workqueue;
81721
81722 /*
81723 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
81724 index 87f7135..74d3703 100644
81725 --- a/net/rxrpc/ar-local.c
81726 +++ b/net/rxrpc/ar-local.c
81727 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
81728 spin_lock_init(&local->lock);
81729 rwlock_init(&local->services_lock);
81730 atomic_set(&local->usage, 1);
81731 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
81732 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81733 memcpy(&local->srx, srx, sizeof(*srx));
81734 }
81735
81736 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
81737 index e1ac183..b43e10e 100644
81738 --- a/net/rxrpc/ar-output.c
81739 +++ b/net/rxrpc/ar-output.c
81740 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
81741 sp->hdr.cid = call->cid;
81742 sp->hdr.callNumber = call->call_id;
81743 sp->hdr.seq =
81744 - htonl(atomic_inc_return(&call->sequence));
81745 + htonl(atomic_inc_return_unchecked(&call->sequence));
81746 sp->hdr.serial =
81747 - htonl(atomic_inc_return(&conn->serial));
81748 + htonl(atomic_inc_return_unchecked(&conn->serial));
81749 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
81750 sp->hdr.userStatus = 0;
81751 sp->hdr.securityIndex = conn->security_ix;
81752 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
81753 index bebaa43..2644591 100644
81754 --- a/net/rxrpc/ar-peer.c
81755 +++ b/net/rxrpc/ar-peer.c
81756 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
81757 INIT_LIST_HEAD(&peer->error_targets);
81758 spin_lock_init(&peer->lock);
81759 atomic_set(&peer->usage, 1);
81760 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
81761 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81762 memcpy(&peer->srx, srx, sizeof(*srx));
81763
81764 rxrpc_assess_MTU_size(peer);
81765 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
81766 index 38047f7..9f48511 100644
81767 --- a/net/rxrpc/ar-proc.c
81768 +++ b/net/rxrpc/ar-proc.c
81769 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
81770 atomic_read(&conn->usage),
81771 rxrpc_conn_states[conn->state],
81772 key_serial(conn->key),
81773 - atomic_read(&conn->serial),
81774 - atomic_read(&conn->hi_serial));
81775 + atomic_read_unchecked(&conn->serial),
81776 + atomic_read_unchecked(&conn->hi_serial));
81777
81778 return 0;
81779 }
81780 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
81781 index 92df566..87ec1bf 100644
81782 --- a/net/rxrpc/ar-transport.c
81783 +++ b/net/rxrpc/ar-transport.c
81784 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
81785 spin_lock_init(&trans->client_lock);
81786 rwlock_init(&trans->conn_lock);
81787 atomic_set(&trans->usage, 1);
81788 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
81789 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
81790
81791 if (peer->srx.transport.family == AF_INET) {
81792 switch (peer->srx.transport_type) {
81793 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
81794 index f226709..0e735a8 100644
81795 --- a/net/rxrpc/rxkad.c
81796 +++ b/net/rxrpc/rxkad.c
81797 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
81798
81799 len = iov[0].iov_len + iov[1].iov_len;
81800
81801 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
81802 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
81803 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
81804
81805 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
81806 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
81807
81808 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
81809
81810 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
81811 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
81812 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
81813
81814 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
81815 diff --git a/net/sctp/auth.c b/net/sctp/auth.c
81816 index 159b9bc..d8420ae 100644
81817 --- a/net/sctp/auth.c
81818 +++ b/net/sctp/auth.c
81819 @@ -71,7 +71,7 @@ void sctp_auth_key_put(struct sctp_auth_bytes *key)
81820 return;
81821
81822 if (atomic_dec_and_test(&key->refcnt)) {
81823 - kfree(key);
81824 + kzfree(key);
81825 SCTP_DBG_OBJCNT_DEC(keys);
81826 }
81827 }
81828 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
81829 index ea14cb4..834e8e4 100644
81830 --- a/net/sctp/ipv6.c
81831 +++ b/net/sctp/ipv6.c
81832 @@ -1037,7 +1037,7 @@ void sctp_v6_pf_init(void)
81833
81834 void sctp_v6_pf_exit(void)
81835 {
81836 - list_del(&sctp_af_inet6.list);
81837 + pax_list_del((struct list_head *)&sctp_af_inet6.list);
81838 }
81839
81840 /* Initialize IPv6 support and register with socket layer. */
81841 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
81842 index 9966e7b..540c575 100644
81843 --- a/net/sctp/proc.c
81844 +++ b/net/sctp/proc.c
81845 @@ -328,7 +328,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
81846 seq_printf(seq,
81847 "%8pK %8pK %-3d %-3d %-2d %-4d "
81848 "%4d %8d %8d %7d %5lu %-5d %5d ",
81849 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
81850 + assoc, sk,
81851 + sctp_sk(sk)->type, sk->sk_state,
81852 assoc->state, hash,
81853 assoc->assoc_id,
81854 assoc->sndbuf_used,
81855 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
81856 index 2d51842..150ba5c 100644
81857 --- a/net/sctp/protocol.c
81858 +++ b/net/sctp/protocol.c
81859 @@ -834,8 +834,10 @@ int sctp_register_af(struct sctp_af *af)
81860 return 0;
81861 }
81862
81863 - INIT_LIST_HEAD(&af->list);
81864 - list_add_tail(&af->list, &sctp_address_families);
81865 + pax_open_kernel();
81866 + INIT_LIST_HEAD((struct list_head *)&af->list);
81867 + pax_close_kernel();
81868 + pax_list_add_tail((struct list_head *)&af->list, &sctp_address_families);
81869 return 1;
81870 }
81871
81872 @@ -1122,7 +1124,7 @@ static void sctp_v4_pf_init(void)
81873
81874 static void sctp_v4_pf_exit(void)
81875 {
81876 - list_del(&sctp_af_inet.list);
81877 + pax_list_del((struct list_head *)&sctp_af_inet.list);
81878 }
81879
81880 static int sctp_v4_protosw_init(void)
81881 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
81882 index 9261d9a..0a6ae623 100644
81883 --- a/net/sctp/socket.c
81884 +++ b/net/sctp/socket.c
81885 @@ -4661,6 +4661,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
81886 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
81887 if (space_left < addrlen)
81888 return -ENOMEM;
81889 + if (addrlen > sizeof(temp) || addrlen < 0)
81890 + return -EFAULT;
81891 if (copy_to_user(to, &temp, addrlen))
81892 return -EFAULT;
81893 to += addrlen;
81894 diff --git a/net/socket.c b/net/socket.c
81895 index d92c490..b4bc863 100644
81896 --- a/net/socket.c
81897 +++ b/net/socket.c
81898 @@ -89,6 +89,7 @@
81899 #include <linux/magic.h>
81900 #include <linux/slab.h>
81901 #include <linux/xattr.h>
81902 +#include <linux/in.h>
81903
81904 #include <asm/uaccess.h>
81905 #include <asm/unistd.h>
81906 @@ -106,6 +107,8 @@
81907 #include <linux/sockios.h>
81908 #include <linux/atalk.h>
81909
81910 +#include <linux/grsock.h>
81911 +
81912 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
81913 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
81914 unsigned long nr_segs, loff_t pos);
81915 @@ -322,7 +325,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
81916 &sockfs_dentry_operations, SOCKFS_MAGIC);
81917 }
81918
81919 -static struct vfsmount *sock_mnt __read_mostly;
81920 +struct vfsmount *sock_mnt __read_mostly;
81921
81922 static struct file_system_type sock_fs_type = {
81923 .name = "sockfs",
81924 @@ -1276,6 +1279,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
81925 return -EAFNOSUPPORT;
81926 if (type < 0 || type >= SOCK_MAX)
81927 return -EINVAL;
81928 + if (protocol < 0)
81929 + return -EINVAL;
81930
81931 /* Compatibility.
81932
81933 @@ -1407,6 +1412,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
81934 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
81935 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
81936
81937 + if(!gr_search_socket(family, type, protocol)) {
81938 + retval = -EACCES;
81939 + goto out;
81940 + }
81941 +
81942 + if (gr_handle_sock_all(family, type, protocol)) {
81943 + retval = -EACCES;
81944 + goto out;
81945 + }
81946 +
81947 retval = sock_create(family, type, protocol, &sock);
81948 if (retval < 0)
81949 goto out;
81950 @@ -1534,6 +1549,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
81951 if (sock) {
81952 err = move_addr_to_kernel(umyaddr, addrlen, &address);
81953 if (err >= 0) {
81954 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
81955 + err = -EACCES;
81956 + goto error;
81957 + }
81958 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
81959 + if (err)
81960 + goto error;
81961 +
81962 err = security_socket_bind(sock,
81963 (struct sockaddr *)&address,
81964 addrlen);
81965 @@ -1542,6 +1565,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
81966 (struct sockaddr *)
81967 &address, addrlen);
81968 }
81969 +error:
81970 fput_light(sock->file, fput_needed);
81971 }
81972 return err;
81973 @@ -1565,10 +1589,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
81974 if ((unsigned int)backlog > somaxconn)
81975 backlog = somaxconn;
81976
81977 + if (gr_handle_sock_server_other(sock->sk)) {
81978 + err = -EPERM;
81979 + goto error;
81980 + }
81981 +
81982 + err = gr_search_listen(sock);
81983 + if (err)
81984 + goto error;
81985 +
81986 err = security_socket_listen(sock, backlog);
81987 if (!err)
81988 err = sock->ops->listen(sock, backlog);
81989
81990 +error:
81991 fput_light(sock->file, fput_needed);
81992 }
81993 return err;
81994 @@ -1612,6 +1646,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
81995 newsock->type = sock->type;
81996 newsock->ops = sock->ops;
81997
81998 + if (gr_handle_sock_server_other(sock->sk)) {
81999 + err = -EPERM;
82000 + sock_release(newsock);
82001 + goto out_put;
82002 + }
82003 +
82004 + err = gr_search_accept(sock);
82005 + if (err) {
82006 + sock_release(newsock);
82007 + goto out_put;
82008 + }
82009 +
82010 /*
82011 * We don't need try_module_get here, as the listening socket (sock)
82012 * has the protocol module (sock->ops->owner) held.
82013 @@ -1657,6 +1703,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
82014 fd_install(newfd, newfile);
82015 err = newfd;
82016
82017 + gr_attach_curr_ip(newsock->sk);
82018 +
82019 out_put:
82020 fput_light(sock->file, fput_needed);
82021 out:
82022 @@ -1689,6 +1737,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
82023 int, addrlen)
82024 {
82025 struct socket *sock;
82026 + struct sockaddr *sck;
82027 struct sockaddr_storage address;
82028 int err, fput_needed;
82029
82030 @@ -1699,6 +1748,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
82031 if (err < 0)
82032 goto out_put;
82033
82034 + sck = (struct sockaddr *)&address;
82035 +
82036 + if (gr_handle_sock_client(sck)) {
82037 + err = -EACCES;
82038 + goto out_put;
82039 + }
82040 +
82041 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
82042 + if (err)
82043 + goto out_put;
82044 +
82045 err =
82046 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
82047 if (err)
82048 @@ -2053,7 +2113,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
82049 * checking falls down on this.
82050 */
82051 if (copy_from_user(ctl_buf,
82052 - (void __user __force *)msg_sys->msg_control,
82053 + (void __force_user *)msg_sys->msg_control,
82054 ctl_len))
82055 goto out_freectl;
82056 msg_sys->msg_control = ctl_buf;
82057 @@ -2221,7 +2281,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
82058 * kernel msghdr to use the kernel address space)
82059 */
82060
82061 - uaddr = (__force void __user *)msg_sys->msg_name;
82062 + uaddr = (void __force_user *)msg_sys->msg_name;
82063 uaddr_len = COMPAT_NAMELEN(msg);
82064 if (MSG_CMSG_COMPAT & flags) {
82065 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
82066 @@ -2844,7 +2904,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
82067 }
82068
82069 ifr = compat_alloc_user_space(buf_size);
82070 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
82071 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
82072
82073 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
82074 return -EFAULT;
82075 @@ -2868,12 +2928,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
82076 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
82077
82078 if (copy_in_user(rxnfc, compat_rxnfc,
82079 - (void *)(&rxnfc->fs.m_ext + 1) -
82080 - (void *)rxnfc) ||
82081 + (void __user *)(&rxnfc->fs.m_ext + 1) -
82082 + (void __user *)rxnfc) ||
82083 copy_in_user(&rxnfc->fs.ring_cookie,
82084 &compat_rxnfc->fs.ring_cookie,
82085 - (void *)(&rxnfc->fs.location + 1) -
82086 - (void *)&rxnfc->fs.ring_cookie) ||
82087 + (void __user *)(&rxnfc->fs.location + 1) -
82088 + (void __user *)&rxnfc->fs.ring_cookie) ||
82089 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
82090 sizeof(rxnfc->rule_cnt)))
82091 return -EFAULT;
82092 @@ -2885,12 +2945,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
82093
82094 if (convert_out) {
82095 if (copy_in_user(compat_rxnfc, rxnfc,
82096 - (const void *)(&rxnfc->fs.m_ext + 1) -
82097 - (const void *)rxnfc) ||
82098 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
82099 + (const void __user *)rxnfc) ||
82100 copy_in_user(&compat_rxnfc->fs.ring_cookie,
82101 &rxnfc->fs.ring_cookie,
82102 - (const void *)(&rxnfc->fs.location + 1) -
82103 - (const void *)&rxnfc->fs.ring_cookie) ||
82104 + (const void __user *)(&rxnfc->fs.location + 1) -
82105 + (const void __user *)&rxnfc->fs.ring_cookie) ||
82106 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
82107 sizeof(rxnfc->rule_cnt)))
82108 return -EFAULT;
82109 @@ -2960,7 +3020,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
82110 old_fs = get_fs();
82111 set_fs(KERNEL_DS);
82112 err = dev_ioctl(net, cmd,
82113 - (struct ifreq __user __force *) &kifr);
82114 + (struct ifreq __force_user *) &kifr);
82115 set_fs(old_fs);
82116
82117 return err;
82118 @@ -3069,7 +3129,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
82119
82120 old_fs = get_fs();
82121 set_fs(KERNEL_DS);
82122 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
82123 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
82124 set_fs(old_fs);
82125
82126 if (cmd == SIOCGIFMAP && !err) {
82127 @@ -3174,7 +3234,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
82128 ret |= __get_user(rtdev, &(ur4->rt_dev));
82129 if (rtdev) {
82130 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
82131 - r4.rt_dev = (char __user __force *)devname;
82132 + r4.rt_dev = (char __force_user *)devname;
82133 devname[15] = 0;
82134 } else
82135 r4.rt_dev = NULL;
82136 @@ -3400,8 +3460,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
82137 int __user *uoptlen;
82138 int err;
82139
82140 - uoptval = (char __user __force *) optval;
82141 - uoptlen = (int __user __force *) optlen;
82142 + uoptval = (char __force_user *) optval;
82143 + uoptlen = (int __force_user *) optlen;
82144
82145 set_fs(KERNEL_DS);
82146 if (level == SOL_SOCKET)
82147 @@ -3421,7 +3481,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
82148 char __user *uoptval;
82149 int err;
82150
82151 - uoptval = (char __user __force *) optval;
82152 + uoptval = (char __force_user *) optval;
82153
82154 set_fs(KERNEL_DS);
82155 if (level == SOL_SOCKET)
82156 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
82157 index 7865b44..174662e 100644
82158 --- a/net/sunrpc/sched.c
82159 +++ b/net/sunrpc/sched.c
82160 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
82161 #ifdef RPC_DEBUG
82162 static void rpc_task_set_debuginfo(struct rpc_task *task)
82163 {
82164 - static atomic_t rpc_pid;
82165 + static atomic_unchecked_t rpc_pid;
82166
82167 - task->tk_pid = atomic_inc_return(&rpc_pid);
82168 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
82169 }
82170 #else
82171 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
82172 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
82173 index 8343737..677025e 100644
82174 --- a/net/sunrpc/xprtrdma/svc_rdma.c
82175 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
82176 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
82177 static unsigned int min_max_inline = 4096;
82178 static unsigned int max_max_inline = 65536;
82179
82180 -atomic_t rdma_stat_recv;
82181 -atomic_t rdma_stat_read;
82182 -atomic_t rdma_stat_write;
82183 -atomic_t rdma_stat_sq_starve;
82184 -atomic_t rdma_stat_rq_starve;
82185 -atomic_t rdma_stat_rq_poll;
82186 -atomic_t rdma_stat_rq_prod;
82187 -atomic_t rdma_stat_sq_poll;
82188 -atomic_t rdma_stat_sq_prod;
82189 +atomic_unchecked_t rdma_stat_recv;
82190 +atomic_unchecked_t rdma_stat_read;
82191 +atomic_unchecked_t rdma_stat_write;
82192 +atomic_unchecked_t rdma_stat_sq_starve;
82193 +atomic_unchecked_t rdma_stat_rq_starve;
82194 +atomic_unchecked_t rdma_stat_rq_poll;
82195 +atomic_unchecked_t rdma_stat_rq_prod;
82196 +atomic_unchecked_t rdma_stat_sq_poll;
82197 +atomic_unchecked_t rdma_stat_sq_prod;
82198
82199 /* Temporary NFS request map and context caches */
82200 struct kmem_cache *svc_rdma_map_cachep;
82201 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
82202 len -= *ppos;
82203 if (len > *lenp)
82204 len = *lenp;
82205 - if (len && copy_to_user(buffer, str_buf, len))
82206 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
82207 return -EFAULT;
82208 *lenp = len;
82209 *ppos += len;
82210 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
82211 {
82212 .procname = "rdma_stat_read",
82213 .data = &rdma_stat_read,
82214 - .maxlen = sizeof(atomic_t),
82215 + .maxlen = sizeof(atomic_unchecked_t),
82216 .mode = 0644,
82217 .proc_handler = read_reset_stat,
82218 },
82219 {
82220 .procname = "rdma_stat_recv",
82221 .data = &rdma_stat_recv,
82222 - .maxlen = sizeof(atomic_t),
82223 + .maxlen = sizeof(atomic_unchecked_t),
82224 .mode = 0644,
82225 .proc_handler = read_reset_stat,
82226 },
82227 {
82228 .procname = "rdma_stat_write",
82229 .data = &rdma_stat_write,
82230 - .maxlen = sizeof(atomic_t),
82231 + .maxlen = sizeof(atomic_unchecked_t),
82232 .mode = 0644,
82233 .proc_handler = read_reset_stat,
82234 },
82235 {
82236 .procname = "rdma_stat_sq_starve",
82237 .data = &rdma_stat_sq_starve,
82238 - .maxlen = sizeof(atomic_t),
82239 + .maxlen = sizeof(atomic_unchecked_t),
82240 .mode = 0644,
82241 .proc_handler = read_reset_stat,
82242 },
82243 {
82244 .procname = "rdma_stat_rq_starve",
82245 .data = &rdma_stat_rq_starve,
82246 - .maxlen = sizeof(atomic_t),
82247 + .maxlen = sizeof(atomic_unchecked_t),
82248 .mode = 0644,
82249 .proc_handler = read_reset_stat,
82250 },
82251 {
82252 .procname = "rdma_stat_rq_poll",
82253 .data = &rdma_stat_rq_poll,
82254 - .maxlen = sizeof(atomic_t),
82255 + .maxlen = sizeof(atomic_unchecked_t),
82256 .mode = 0644,
82257 .proc_handler = read_reset_stat,
82258 },
82259 {
82260 .procname = "rdma_stat_rq_prod",
82261 .data = &rdma_stat_rq_prod,
82262 - .maxlen = sizeof(atomic_t),
82263 + .maxlen = sizeof(atomic_unchecked_t),
82264 .mode = 0644,
82265 .proc_handler = read_reset_stat,
82266 },
82267 {
82268 .procname = "rdma_stat_sq_poll",
82269 .data = &rdma_stat_sq_poll,
82270 - .maxlen = sizeof(atomic_t),
82271 + .maxlen = sizeof(atomic_unchecked_t),
82272 .mode = 0644,
82273 .proc_handler = read_reset_stat,
82274 },
82275 {
82276 .procname = "rdma_stat_sq_prod",
82277 .data = &rdma_stat_sq_prod,
82278 - .maxlen = sizeof(atomic_t),
82279 + .maxlen = sizeof(atomic_unchecked_t),
82280 .mode = 0644,
82281 .proc_handler = read_reset_stat,
82282 },
82283 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
82284 index 41cb63b..c4a1489 100644
82285 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
82286 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
82287 @@ -501,7 +501,7 @@ next_sge:
82288 svc_rdma_put_context(ctxt, 0);
82289 goto out;
82290 }
82291 - atomic_inc(&rdma_stat_read);
82292 + atomic_inc_unchecked(&rdma_stat_read);
82293
82294 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
82295 chl_map->ch[ch_no].count -= read_wr.num_sge;
82296 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
82297 dto_q);
82298 list_del_init(&ctxt->dto_q);
82299 } else {
82300 - atomic_inc(&rdma_stat_rq_starve);
82301 + atomic_inc_unchecked(&rdma_stat_rq_starve);
82302 clear_bit(XPT_DATA, &xprt->xpt_flags);
82303 ctxt = NULL;
82304 }
82305 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
82306 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
82307 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
82308 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
82309 - atomic_inc(&rdma_stat_recv);
82310 + atomic_inc_unchecked(&rdma_stat_recv);
82311
82312 /* Build up the XDR from the receive buffers. */
82313 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
82314 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
82315 index 42eb7ba..c887c45 100644
82316 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
82317 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
82318 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
82319 write_wr.wr.rdma.remote_addr = to;
82320
82321 /* Post It */
82322 - atomic_inc(&rdma_stat_write);
82323 + atomic_inc_unchecked(&rdma_stat_write);
82324 if (svc_rdma_send(xprt, &write_wr))
82325 goto err;
82326 return 0;
82327 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
82328 index 62e4f9b..dd3f2d7 100644
82329 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
82330 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
82331 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
82332 return;
82333
82334 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
82335 - atomic_inc(&rdma_stat_rq_poll);
82336 + atomic_inc_unchecked(&rdma_stat_rq_poll);
82337
82338 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
82339 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
82340 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
82341 }
82342
82343 if (ctxt)
82344 - atomic_inc(&rdma_stat_rq_prod);
82345 + atomic_inc_unchecked(&rdma_stat_rq_prod);
82346
82347 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
82348 /*
82349 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
82350 return;
82351
82352 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
82353 - atomic_inc(&rdma_stat_sq_poll);
82354 + atomic_inc_unchecked(&rdma_stat_sq_poll);
82355 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
82356 if (wc.status != IB_WC_SUCCESS)
82357 /* Close the transport */
82358 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
82359 }
82360
82361 if (ctxt)
82362 - atomic_inc(&rdma_stat_sq_prod);
82363 + atomic_inc_unchecked(&rdma_stat_sq_prod);
82364 }
82365
82366 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
82367 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
82368 spin_lock_bh(&xprt->sc_lock);
82369 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
82370 spin_unlock_bh(&xprt->sc_lock);
82371 - atomic_inc(&rdma_stat_sq_starve);
82372 + atomic_inc_unchecked(&rdma_stat_sq_starve);
82373
82374 /* See if we can opportunistically reap SQ WR to make room */
82375 sq_cq_reap(xprt);
82376 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
82377 index e3a6e37..be2ea77 100644
82378 --- a/net/sysctl_net.c
82379 +++ b/net/sysctl_net.c
82380 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
82381 struct ctl_table *table)
82382 {
82383 /* Allow network administrator to have same access as root. */
82384 - if (capable(CAP_NET_ADMIN)) {
82385 + if (capable_nolog(CAP_NET_ADMIN)) {
82386 int mode = (table->mode >> 6) & 7;
82387 return (mode << 6) | (mode << 3) | mode;
82388 }
82389 diff --git a/net/tipc/link.c b/net/tipc/link.c
82390 index a79c755..eca357d 100644
82391 --- a/net/tipc/link.c
82392 +++ b/net/tipc/link.c
82393 @@ -1169,7 +1169,7 @@ static int link_send_sections_long(struct tipc_port *sender,
82394 struct tipc_msg fragm_hdr;
82395 struct sk_buff *buf, *buf_chain, *prev;
82396 u32 fragm_crs, fragm_rest, hsz, sect_rest;
82397 - const unchar *sect_crs;
82398 + const unchar __user *sect_crs;
82399 int curr_sect;
82400 u32 fragm_no;
82401
82402 @@ -1210,7 +1210,7 @@ again:
82403
82404 if (!sect_rest) {
82405 sect_rest = msg_sect[++curr_sect].iov_len;
82406 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
82407 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
82408 }
82409
82410 if (sect_rest < fragm_rest)
82411 @@ -1229,7 +1229,7 @@ error:
82412 }
82413 } else
82414 skb_copy_to_linear_data_offset(buf, fragm_crs,
82415 - sect_crs, sz);
82416 + (const void __force_kernel *)sect_crs, sz);
82417 sect_crs += sz;
82418 sect_rest -= sz;
82419 fragm_crs += sz;
82420 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
82421 index f2db8a8..9245aa4 100644
82422 --- a/net/tipc/msg.c
82423 +++ b/net/tipc/msg.c
82424 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
82425 msg_sect[cnt].iov_len);
82426 else
82427 skb_copy_to_linear_data_offset(*buf, pos,
82428 - msg_sect[cnt].iov_base,
82429 + (const void __force_kernel *)msg_sect[cnt].iov_base,
82430 msg_sect[cnt].iov_len);
82431 pos += msg_sect[cnt].iov_len;
82432 }
82433 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
82434 index 0f7d0d0..00f89bf 100644
82435 --- a/net/tipc/subscr.c
82436 +++ b/net/tipc/subscr.c
82437 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
82438 {
82439 struct iovec msg_sect;
82440
82441 - msg_sect.iov_base = (void *)&sub->evt;
82442 + msg_sect.iov_base = (void __force_user *)&sub->evt;
82443 msg_sect.iov_len = sizeof(struct tipc_event);
82444
82445 sub->evt.event = htohl(event, sub->swap);
82446 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
82447 index 5b5c876..3127bf7 100644
82448 --- a/net/unix/af_unix.c
82449 +++ b/net/unix/af_unix.c
82450 @@ -786,6 +786,12 @@ static struct sock *unix_find_other(struct net *net,
82451 err = -ECONNREFUSED;
82452 if (!S_ISSOCK(inode->i_mode))
82453 goto put_fail;
82454 +
82455 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
82456 + err = -EACCES;
82457 + goto put_fail;
82458 + }
82459 +
82460 u = unix_find_socket_byinode(inode);
82461 if (!u)
82462 goto put_fail;
82463 @@ -806,6 +812,13 @@ static struct sock *unix_find_other(struct net *net,
82464 if (u) {
82465 struct dentry *dentry;
82466 dentry = unix_sk(u)->path.dentry;
82467 +
82468 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
82469 + err = -EPERM;
82470 + sock_put(u);
82471 + goto fail;
82472 + }
82473 +
82474 if (dentry)
82475 touch_atime(&unix_sk(u)->path);
82476 } else
82477 @@ -839,12 +852,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
82478 */
82479 err = security_path_mknod(&path, dentry, mode, 0);
82480 if (!err) {
82481 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
82482 + err = -EACCES;
82483 + goto out;
82484 + }
82485 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
82486 if (!err) {
82487 res->mnt = mntget(path.mnt);
82488 res->dentry = dget(dentry);
82489 + gr_handle_create(dentry, path.mnt);
82490 }
82491 }
82492 +out:
82493 done_path_create(&path, dentry);
82494 return err;
82495 }
82496 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
82497 index c8717c1..08539f5 100644
82498 --- a/net/wireless/wext-core.c
82499 +++ b/net/wireless/wext-core.c
82500 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
82501 */
82502
82503 /* Support for very large requests */
82504 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
82505 - (user_length > descr->max_tokens)) {
82506 + if (user_length > descr->max_tokens) {
82507 /* Allow userspace to GET more than max so
82508 * we can support any size GET requests.
82509 * There is still a limit : -ENOMEM.
82510 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
82511 }
82512 }
82513
82514 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
82515 - /*
82516 - * If this is a GET, but not NOMAX, it means that the extra
82517 - * data is not bounded by userspace, but by max_tokens. Thus
82518 - * set the length to max_tokens. This matches the extra data
82519 - * allocation.
82520 - * The driver should fill it with the number of tokens it
82521 - * provided, and it may check iwp->length rather than having
82522 - * knowledge of max_tokens. If the driver doesn't change the
82523 - * iwp->length, this ioctl just copies back max_token tokens
82524 - * filled with zeroes. Hopefully the driver isn't claiming
82525 - * them to be valid data.
82526 - */
82527 - iwp->length = descr->max_tokens;
82528 - }
82529 -
82530 err = handler(dev, info, (union iwreq_data *) iwp, extra);
82531
82532 iwp->length += essid_compat;
82533 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
82534 index 41eabc4..8d4e6d6 100644
82535 --- a/net/xfrm/xfrm_policy.c
82536 +++ b/net/xfrm/xfrm_policy.c
82537 @@ -317,7 +317,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
82538 {
82539 policy->walk.dead = 1;
82540
82541 - atomic_inc(&policy->genid);
82542 + atomic_inc_unchecked(&policy->genid);
82543
82544 if (del_timer(&policy->timer))
82545 xfrm_pol_put(policy);
82546 @@ -601,7 +601,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
82547 hlist_add_head(&policy->bydst, chain);
82548 xfrm_pol_hold(policy);
82549 net->xfrm.policy_count[dir]++;
82550 - atomic_inc(&flow_cache_genid);
82551 + atomic_inc_unchecked(&flow_cache_genid);
82552 rt_genid_bump(net);
82553 if (delpol)
82554 __xfrm_policy_unlink(delpol, dir);
82555 @@ -1550,7 +1550,7 @@ free_dst:
82556 goto out;
82557 }
82558
82559 -static int inline
82560 +static inline int
82561 xfrm_dst_alloc_copy(void **target, const void *src, int size)
82562 {
82563 if (!*target) {
82564 @@ -1562,7 +1562,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
82565 return 0;
82566 }
82567
82568 -static int inline
82569 +static inline int
82570 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
82571 {
82572 #ifdef CONFIG_XFRM_SUB_POLICY
82573 @@ -1574,7 +1574,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
82574 #endif
82575 }
82576
82577 -static int inline
82578 +static inline int
82579 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
82580 {
82581 #ifdef CONFIG_XFRM_SUB_POLICY
82582 @@ -1668,7 +1668,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
82583
82584 xdst->num_pols = num_pols;
82585 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
82586 - xdst->policy_genid = atomic_read(&pols[0]->genid);
82587 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
82588
82589 return xdst;
82590 }
82591 @@ -2369,7 +2369,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
82592 if (xdst->xfrm_genid != dst->xfrm->genid)
82593 return 0;
82594 if (xdst->num_pols > 0 &&
82595 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
82596 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
82597 return 0;
82598
82599 mtu = dst_mtu(dst->child);
82600 @@ -2896,7 +2896,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
82601 sizeof(pol->xfrm_vec[i].saddr));
82602 pol->xfrm_vec[i].encap_family = mp->new_family;
82603 /* flush bundles */
82604 - atomic_inc(&pol->genid);
82605 + atomic_inc_unchecked(&pol->genid);
82606 }
82607 }
82608
82609 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
82610 index 3459692..eefb515 100644
82611 --- a/net/xfrm/xfrm_state.c
82612 +++ b/net/xfrm/xfrm_state.c
82613 @@ -278,7 +278,9 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
82614 if (!try_module_get(afinfo->owner))
82615 goto out;
82616
82617 - mode->afinfo = afinfo;
82618 + pax_open_kernel();
82619 + *(void **)&mode->afinfo = afinfo;
82620 + pax_close_kernel();
82621 modemap[mode->encap] = mode;
82622 err = 0;
82623
82624 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
82625 index 0e801c3..5c8ad3b 100644
82626 --- a/scripts/Makefile.build
82627 +++ b/scripts/Makefile.build
82628 @@ -111,7 +111,7 @@ endif
82629 endif
82630
82631 # Do not include host rules unless needed
82632 -ifneq ($(hostprogs-y)$(hostprogs-m),)
82633 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
82634 include scripts/Makefile.host
82635 endif
82636
82637 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
82638 index 686cb0d..9d653bf 100644
82639 --- a/scripts/Makefile.clean
82640 +++ b/scripts/Makefile.clean
82641 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
82642 __clean-files := $(extra-y) $(always) \
82643 $(targets) $(clean-files) \
82644 $(host-progs) \
82645 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
82646 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
82647 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
82648
82649 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
82650
82651 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
82652 index 1ac414f..38575f7 100644
82653 --- a/scripts/Makefile.host
82654 +++ b/scripts/Makefile.host
82655 @@ -31,6 +31,8 @@
82656 # Note: Shared libraries consisting of C++ files are not supported
82657
82658 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
82659 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
82660 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
82661
82662 # C code
82663 # Executables compiled from a single .c file
82664 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
82665 # Shared libaries (only .c supported)
82666 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
82667 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
82668 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
82669 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
82670 # Remove .so files from "xxx-objs"
82671 host-cobjs := $(filter-out %.so,$(host-cobjs))
82672 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
82673
82674 -#Object (.o) files used by the shared libaries
82675 +# Object (.o) files used by the shared libaries
82676 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
82677 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
82678
82679 # output directory for programs/.o files
82680 # hostprogs-y := tools/build may have been specified. Retrieve directory
82681 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
82682 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
82683 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
82684 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
82685 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
82686 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
82687 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
82688 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
82689
82690 obj-dirs += $(host-objdirs)
82691 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
82692 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
82693 $(call if_changed_dep,host-cshobjs)
82694
82695 +# Compile .c file, create position independent .o file
82696 +# host-cxxshobjs -> .o
82697 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
82698 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
82699 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
82700 + $(call if_changed_dep,host-cxxshobjs)
82701 +
82702 # Link a shared library, based on position independent .o files
82703 # *.o -> .so shared library (host-cshlib)
82704 quiet_cmd_host-cshlib = HOSTLLD -shared $@
82705 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
82706 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
82707 $(call if_changed,host-cshlib)
82708
82709 +# Link a shared library, based on position independent .o files
82710 +# *.o -> .so shared library (host-cxxshlib)
82711 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
82712 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
82713 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
82714 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
82715 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
82716 + $(call if_changed,host-cxxshlib)
82717 +
82718 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
82719 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
82720 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
82721
82722 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
82723 index cb1f50c..cef2a7c 100644
82724 --- a/scripts/basic/fixdep.c
82725 +++ b/scripts/basic/fixdep.c
82726 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
82727 /*
82728 * Lookup a value in the configuration string.
82729 */
82730 -static int is_defined_config(const char *name, int len, unsigned int hash)
82731 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
82732 {
82733 struct item *aux;
82734
82735 @@ -211,10 +211,10 @@ static void clear_config(void)
82736 /*
82737 * Record the use of a CONFIG_* word.
82738 */
82739 -static void use_config(const char *m, int slen)
82740 +static void use_config(const char *m, unsigned int slen)
82741 {
82742 unsigned int hash = strhash(m, slen);
82743 - int c, i;
82744 + unsigned int c, i;
82745
82746 if (is_defined_config(m, slen, hash))
82747 return;
82748 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
82749
82750 static void parse_config_file(const char *map, size_t len)
82751 {
82752 - const int *end = (const int *) (map + len);
82753 + const unsigned int *end = (const unsigned int *) (map + len);
82754 /* start at +1, so that p can never be < map */
82755 - const int *m = (const int *) map + 1;
82756 + const unsigned int *m = (const unsigned int *) map + 1;
82757 const char *p, *q;
82758
82759 for (; m < end; m++) {
82760 @@ -406,7 +406,7 @@ static void print_deps(void)
82761 static void traps(void)
82762 {
82763 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
82764 - int *p = (int *)test;
82765 + unsigned int *p = (unsigned int *)test;
82766
82767 if (*p != INT_CONF) {
82768 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
82769 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
82770 new file mode 100644
82771 index 0000000..008ac1a
82772 --- /dev/null
82773 +++ b/scripts/gcc-plugin.sh
82774 @@ -0,0 +1,17 @@
82775 +#!/bin/bash
82776 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
82777 +#include "gcc-plugin.h"
82778 +#include "tree.h"
82779 +#include "tm.h"
82780 +#include "rtl.h"
82781 +#ifdef ENABLE_BUILD_WITH_CXX
82782 +#warning $2
82783 +#else
82784 +#warning $1
82785 +#endif
82786 +EOF`
82787 +if [ $? -eq 0 ]
82788 +then
82789 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
82790 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
82791 +fi
82792 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
82793 index b3d907e..a4782ab 100644
82794 --- a/scripts/link-vmlinux.sh
82795 +++ b/scripts/link-vmlinux.sh
82796 @@ -152,7 +152,7 @@ else
82797 fi;
82798
82799 # final build of init/
82800 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
82801 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
82802
82803 kallsymso=""
82804 kallsyms_vmlinux=""
82805 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
82806 index df4fc23..0ea719d 100644
82807 --- a/scripts/mod/file2alias.c
82808 +++ b/scripts/mod/file2alias.c
82809 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
82810 unsigned long size, unsigned long id_size,
82811 void *symval)
82812 {
82813 - int i;
82814 + unsigned int i;
82815
82816 if (size % id_size || size < id_size) {
82817 if (cross_build != 0)
82818 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
82819 /* USB is special because the bcdDevice can be matched against a numeric range */
82820 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
82821 static void do_usb_entry(struct usb_device_id *id,
82822 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
82823 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
82824 unsigned char range_lo, unsigned char range_hi,
82825 unsigned char max, struct module *mod)
82826 {
82827 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
82828 {
82829 unsigned int devlo, devhi;
82830 unsigned char chi, clo, max;
82831 - int ndigits;
82832 + unsigned int ndigits;
82833
82834 id->match_flags = TO_NATIVE(id->match_flags);
82835 id->idVendor = TO_NATIVE(id->idVendor);
82836 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
82837 for (i = 0; i < count; i++) {
82838 const char *id = (char *)devs[i].id;
82839 char acpi_id[sizeof(devs[0].id)];
82840 - int j;
82841 + unsigned int j;
82842
82843 buf_printf(&mod->dev_table_buf,
82844 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
82845 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
82846
82847 for (j = 0; j < PNP_MAX_DEVICES; j++) {
82848 const char *id = (char *)card->devs[j].id;
82849 - int i2, j2;
82850 + unsigned int i2, j2;
82851 int dup = 0;
82852
82853 if (!id[0])
82854 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
82855 /* add an individual alias for every device entry */
82856 if (!dup) {
82857 char acpi_id[sizeof(card->devs[0].id)];
82858 - int k;
82859 + unsigned int k;
82860
82861 buf_printf(&mod->dev_table_buf,
82862 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
82863 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
82864 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
82865 char *alias)
82866 {
82867 - int i, j;
82868 + unsigned int i, j;
82869
82870 sprintf(alias, "dmi*");
82871
82872 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
82873 index 0d93856..e828363 100644
82874 --- a/scripts/mod/modpost.c
82875 +++ b/scripts/mod/modpost.c
82876 @@ -933,6 +933,7 @@ enum mismatch {
82877 ANY_INIT_TO_ANY_EXIT,
82878 ANY_EXIT_TO_ANY_INIT,
82879 EXPORT_TO_INIT_EXIT,
82880 + DATA_TO_TEXT
82881 };
82882
82883 struct sectioncheck {
82884 @@ -1047,6 +1048,12 @@ const struct sectioncheck sectioncheck[] = {
82885 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
82886 .mismatch = EXPORT_TO_INIT_EXIT,
82887 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
82888 +},
82889 +/* Do not reference code from writable data */
82890 +{
82891 + .fromsec = { DATA_SECTIONS, NULL },
82892 + .tosec = { TEXT_SECTIONS, NULL },
82893 + .mismatch = DATA_TO_TEXT
82894 }
82895 };
82896
82897 @@ -1169,10 +1176,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
82898 continue;
82899 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
82900 continue;
82901 - if (sym->st_value == addr)
82902 - return sym;
82903 /* Find a symbol nearby - addr are maybe negative */
82904 d = sym->st_value - addr;
82905 + if (d == 0)
82906 + return sym;
82907 if (d < 0)
82908 d = addr - sym->st_value;
82909 if (d < distance) {
82910 @@ -1451,6 +1458,14 @@ static void report_sec_mismatch(const char *modname,
82911 tosym, prl_to, prl_to, tosym);
82912 free(prl_to);
82913 break;
82914 + case DATA_TO_TEXT:
82915 +#if 0
82916 + fprintf(stderr,
82917 + "The %s %s:%s references\n"
82918 + "the %s %s:%s%s\n",
82919 + from, fromsec, fromsym, to, tosec, tosym, to_p);
82920 +#endif
82921 + break;
82922 }
82923 fprintf(stderr, "\n");
82924 }
82925 @@ -1685,7 +1700,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
82926 static void check_sec_ref(struct module *mod, const char *modname,
82927 struct elf_info *elf)
82928 {
82929 - int i;
82930 + unsigned int i;
82931 Elf_Shdr *sechdrs = elf->sechdrs;
82932
82933 /* Walk through all sections */
82934 @@ -1783,7 +1798,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
82935 va_end(ap);
82936 }
82937
82938 -void buf_write(struct buffer *buf, const char *s, int len)
82939 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
82940 {
82941 if (buf->size - buf->pos < len) {
82942 buf->size += len + SZ;
82943 @@ -2001,7 +2016,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
82944 if (fstat(fileno(file), &st) < 0)
82945 goto close_write;
82946
82947 - if (st.st_size != b->pos)
82948 + if (st.st_size != (off_t)b->pos)
82949 goto close_write;
82950
82951 tmp = NOFAIL(malloc(b->pos));
82952 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
82953 index 51207e4..f7d603d 100644
82954 --- a/scripts/mod/modpost.h
82955 +++ b/scripts/mod/modpost.h
82956 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
82957
82958 struct buffer {
82959 char *p;
82960 - int pos;
82961 - int size;
82962 + unsigned int pos;
82963 + unsigned int size;
82964 };
82965
82966 void __attribute__((format(printf, 2, 3)))
82967 buf_printf(struct buffer *buf, const char *fmt, ...);
82968
82969 void
82970 -buf_write(struct buffer *buf, const char *s, int len);
82971 +buf_write(struct buffer *buf, const char *s, unsigned int len);
82972
82973 struct module {
82974 struct module *next;
82975 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
82976 index 9dfcd6d..099068e 100644
82977 --- a/scripts/mod/sumversion.c
82978 +++ b/scripts/mod/sumversion.c
82979 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
82980 goto out;
82981 }
82982
82983 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
82984 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
82985 warn("writing sum in %s failed: %s\n",
82986 filename, strerror(errno));
82987 goto out;
82988 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
82989 index 5c11312..72742b5 100644
82990 --- a/scripts/pnmtologo.c
82991 +++ b/scripts/pnmtologo.c
82992 @@ -237,14 +237,14 @@ static void write_header(void)
82993 fprintf(out, " * Linux logo %s\n", logoname);
82994 fputs(" */\n\n", out);
82995 fputs("#include <linux/linux_logo.h>\n\n", out);
82996 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
82997 + fprintf(out, "static unsigned char %s_data[] = {\n",
82998 logoname);
82999 }
83000
83001 static void write_footer(void)
83002 {
83003 fputs("\n};\n\n", out);
83004 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
83005 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
83006 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
83007 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
83008 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
83009 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
83010 fputs("\n};\n\n", out);
83011
83012 /* write logo clut */
83013 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
83014 + fprintf(out, "static unsigned char %s_clut[] = {\n",
83015 logoname);
83016 write_hex_cnt = 0;
83017 for (i = 0; i < logo_clutsize; i++) {
83018 diff --git a/security/Kconfig b/security/Kconfig
83019 index e9c6ac7..01c698c 100644
83020 --- a/security/Kconfig
83021 +++ b/security/Kconfig
83022 @@ -4,6 +4,902 @@
83023
83024 menu "Security options"
83025
83026 +menu "Grsecurity"
83027 +
83028 + config ARCH_TRACK_EXEC_LIMIT
83029 + bool
83030 +
83031 + config PAX_KERNEXEC_PLUGIN
83032 + bool
83033 +
83034 + config PAX_PER_CPU_PGD
83035 + bool
83036 +
83037 + config TASK_SIZE_MAX_SHIFT
83038 + int
83039 + depends on X86_64
83040 + default 47 if !PAX_PER_CPU_PGD
83041 + default 42 if PAX_PER_CPU_PGD
83042 +
83043 + config PAX_ENABLE_PAE
83044 + bool
83045 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
83046 +
83047 + config PAX_USERCOPY_SLABS
83048 + bool
83049 +
83050 +config GRKERNSEC
83051 + bool "Grsecurity"
83052 + select CRYPTO
83053 + select CRYPTO_SHA256
83054 + select PROC_FS
83055 + select STOP_MACHINE
83056 + help
83057 + If you say Y here, you will be able to configure many features
83058 + that will enhance the security of your system. It is highly
83059 + recommended that you say Y here and read through the help
83060 + for each option so that you fully understand the features and
83061 + can evaluate their usefulness for your machine.
83062 +
83063 +choice
83064 + prompt "Configuration Method"
83065 + depends on GRKERNSEC
83066 + default GRKERNSEC_CONFIG_CUSTOM
83067 + help
83068 +
83069 +config GRKERNSEC_CONFIG_AUTO
83070 + bool "Automatic"
83071 + help
83072 + If you choose this configuration method, you'll be able to answer a small
83073 + number of simple questions about how you plan to use this kernel.
83074 + The settings of grsecurity and PaX will be automatically configured for
83075 + the highest commonly-used settings within the provided constraints.
83076 +
83077 + If you require additional configuration, custom changes can still be made
83078 + from the "custom configuration" menu.
83079 +
83080 +config GRKERNSEC_CONFIG_CUSTOM
83081 + bool "Custom"
83082 + help
83083 + If you choose this configuration method, you'll be able to configure all
83084 + grsecurity and PaX settings manually. Via this method, no options are
83085 + automatically enabled.
83086 +
83087 +endchoice
83088 +
83089 +choice
83090 + prompt "Usage Type"
83091 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
83092 + default GRKERNSEC_CONFIG_SERVER
83093 + help
83094 +
83095 +config GRKERNSEC_CONFIG_SERVER
83096 + bool "Server"
83097 + help
83098 + Choose this option if you plan to use this kernel on a server.
83099 +
83100 +config GRKERNSEC_CONFIG_DESKTOP
83101 + bool "Desktop"
83102 + help
83103 + Choose this option if you plan to use this kernel on a desktop.
83104 +
83105 +endchoice
83106 +
83107 +choice
83108 + prompt "Virtualization Type"
83109 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
83110 + default GRKERNSEC_CONFIG_VIRT_NONE
83111 + help
83112 +
83113 +config GRKERNSEC_CONFIG_VIRT_NONE
83114 + bool "None"
83115 + help
83116 + Choose this option if this kernel will be run on bare metal.
83117 +
83118 +config GRKERNSEC_CONFIG_VIRT_GUEST
83119 + bool "Guest"
83120 + help
83121 + Choose this option if this kernel will be run as a VM guest.
83122 +
83123 +config GRKERNSEC_CONFIG_VIRT_HOST
83124 + bool "Host"
83125 + help
83126 + Choose this option if this kernel will be run as a VM host.
83127 +
83128 +endchoice
83129 +
83130 +choice
83131 + prompt "Virtualization Hardware"
83132 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
83133 + help
83134 +
83135 +config GRKERNSEC_CONFIG_VIRT_EPT
83136 + bool "EPT/RVI Processor Support"
83137 + depends on X86
83138 + help
83139 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
83140 + hardware virtualization. This allows for additional kernel hardening protections
83141 + to operate without additional performance impact.
83142 +
83143 + To see if your Intel processor supports EPT, see:
83144 + http://ark.intel.com/Products/VirtualizationTechnology
83145 + (Most Core i3/5/7 support EPT)
83146 +
83147 + To see if your AMD processor supports RVI, see:
83148 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
83149 +
83150 +config GRKERNSEC_CONFIG_VIRT_SOFT
83151 + bool "First-gen/No Hardware Virtualization"
83152 + help
83153 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
83154 + support hardware virtualization or doesn't support the EPT/RVI extensions.
83155 +
83156 +endchoice
83157 +
83158 +choice
83159 + prompt "Virtualization Software"
83160 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
83161 + help
83162 +
83163 +config GRKERNSEC_CONFIG_VIRT_XEN
83164 + bool "Xen"
83165 + help
83166 + Choose this option if this kernel is running as a Xen guest or host.
83167 +
83168 +config GRKERNSEC_CONFIG_VIRT_VMWARE
83169 + bool "VMWare"
83170 + help
83171 + Choose this option if this kernel is running as a VMWare guest or host.
83172 +
83173 +config GRKERNSEC_CONFIG_VIRT_KVM
83174 + bool "KVM"
83175 + help
83176 + Choose this option if this kernel is running as a KVM guest or host.
83177 +
83178 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
83179 + bool "VirtualBox"
83180 + help
83181 + Choose this option if this kernel is running as a VirtualBox guest or host.
83182 +
83183 +endchoice
83184 +
83185 +choice
83186 + prompt "Required Priorities"
83187 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
83188 + default GRKERNSEC_CONFIG_PRIORITY_PERF
83189 + help
83190 +
83191 +config GRKERNSEC_CONFIG_PRIORITY_PERF
83192 + bool "Performance"
83193 + help
83194 + Choose this option if performance is of highest priority for this deployment
83195 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
83196 + and freed memory sanitizing will be disabled.
83197 +
83198 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
83199 + bool "Security"
83200 + help
83201 + Choose this option if security is of highest priority for this deployment of
83202 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
83203 + be enabled for this kernel. In a worst-case scenario, these features can
83204 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
83205 +
83206 +endchoice
83207 +
83208 +menu "Default Special Groups"
83209 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
83210 +
83211 +config GRKERNSEC_PROC_GID
83212 + int "GID exempted from /proc restrictions"
83213 + default 1001
83214 + help
83215 + Setting this GID determines which group will be exempted from
83216 + grsecurity's /proc restrictions, allowing users of the specified
83217 + group to view network statistics and the existence of other users'
83218 + processes on the system. This GID may also be chosen at boot time
83219 + via "grsec_proc_gid=" on the kernel commandline.
83220 +
83221 +config GRKERNSEC_TPE_UNTRUSTED_GID
83222 + int "GID for TPE-untrusted users"
83223 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
83224 + default 1005
83225 + help
83226 + Setting this GID determines which group untrusted users should
83227 + be added to. These users will be placed under grsecurity's Trusted Path
83228 + Execution mechanism, preventing them from executing their own binaries.
83229 + The users will only be able to execute binaries in directories owned and
83230 + writable only by the root user. If the sysctl option is enabled, a sysctl
83231 + option with name "tpe_gid" is created.
83232 +
83233 +config GRKERNSEC_TPE_TRUSTED_GID
83234 + int "GID for TPE-trusted users"
83235 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
83236 + default 1005
83237 + help
83238 + Setting this GID determines what group TPE restrictions will be
83239 + *disabled* for. If the sysctl option is enabled, a sysctl option
83240 + with name "tpe_gid" is created.
83241 +
83242 +config GRKERNSEC_SYMLINKOWN_GID
83243 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
83244 + depends on GRKERNSEC_CONFIG_SERVER
83245 + default 1006
83246 + help
83247 + Setting this GID determines what group kernel-enforced
83248 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
83249 + is enabled, a sysctl option with name "symlinkown_gid" is created.
83250 +
83251 +
83252 +endmenu
83253 +
83254 +menu "Customize Configuration"
83255 +depends on GRKERNSEC
83256 +
83257 +menu "PaX"
83258 +
83259 +config PAX
83260 + bool "Enable various PaX features"
83261 + default y if GRKERNSEC_CONFIG_AUTO
83262 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
83263 + help
83264 + This allows you to enable various PaX features. PaX adds
83265 + intrusion prevention mechanisms to the kernel that reduce
83266 + the risks posed by exploitable memory corruption bugs.
83267 +
83268 +menu "PaX Control"
83269 + depends on PAX
83270 +
83271 +config PAX_SOFTMODE
83272 + bool 'Support soft mode'
83273 + help
83274 + Enabling this option will allow you to run PaX in soft mode, that
83275 + is, PaX features will not be enforced by default, only on executables
83276 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
83277 + support as they are the only way to mark executables for soft mode use.
83278 +
83279 + Soft mode can be activated by using the "pax_softmode=1" kernel command
83280 + line option on boot. Furthermore you can control various PaX features
83281 + at runtime via the entries in /proc/sys/kernel/pax.
83282 +
83283 +config PAX_EI_PAX
83284 + bool 'Use legacy ELF header marking'
83285 + default y if GRKERNSEC_CONFIG_AUTO
83286 + help
83287 + Enabling this option will allow you to control PaX features on
83288 + a per executable basis via the 'chpax' utility available at
83289 + http://pax.grsecurity.net/. The control flags will be read from
83290 + an otherwise reserved part of the ELF header. This marking has
83291 + numerous drawbacks (no support for soft-mode, toolchain does not
83292 + know about the non-standard use of the ELF header) therefore it
83293 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
83294 + support.
83295 +
83296 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
83297 + support as well, they will override the legacy EI_PAX marks.
83298 +
83299 + If you enable none of the marking options then all applications
83300 + will run with PaX enabled on them by default.
83301 +
83302 +config PAX_PT_PAX_FLAGS
83303 + bool 'Use ELF program header marking'
83304 + default y if GRKERNSEC_CONFIG_AUTO
83305 + help
83306 + Enabling this option will allow you to control PaX features on
83307 + a per executable basis via the 'paxctl' utility available at
83308 + http://pax.grsecurity.net/. The control flags will be read from
83309 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
83310 + has the benefits of supporting both soft mode and being fully
83311 + integrated into the toolchain (the binutils patch is available
83312 + from http://pax.grsecurity.net).
83313 +
83314 + Note that if you enable the legacy EI_PAX marking support as well,
83315 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
83316 +
83317 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
83318 + must make sure that the marks are the same if a binary has both marks.
83319 +
83320 + If you enable none of the marking options then all applications
83321 + will run with PaX enabled on them by default.
83322 +
83323 +config PAX_XATTR_PAX_FLAGS
83324 + bool 'Use filesystem extended attributes marking'
83325 + default y if GRKERNSEC_CONFIG_AUTO
83326 + select CIFS_XATTR if CIFS
83327 + select EXT2_FS_XATTR if EXT2_FS
83328 + select EXT3_FS_XATTR if EXT3_FS
83329 + select EXT4_FS_XATTR if EXT4_FS
83330 + select JFFS2_FS_XATTR if JFFS2_FS
83331 + select REISERFS_FS_XATTR if REISERFS_FS
83332 + select SQUASHFS_XATTR if SQUASHFS
83333 + select TMPFS_XATTR if TMPFS
83334 + select UBIFS_FS_XATTR if UBIFS_FS
83335 + help
83336 + Enabling this option will allow you to control PaX features on
83337 + a per executable basis via the 'setfattr' utility. The control
83338 + flags will be read from the user.pax.flags extended attribute of
83339 + the file. This marking has the benefit of supporting binary-only
83340 + applications that self-check themselves (e.g., skype) and would
83341 + not tolerate chpax/paxctl changes. The main drawback is that
83342 + extended attributes are not supported by some filesystems (e.g.,
83343 + isofs, udf, vfat) so copying files through such filesystems will
83344 + lose the extended attributes and these PaX markings.
83345 +
83346 + Note that if you enable the legacy EI_PAX marking support as well,
83347 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
83348 +
83349 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
83350 + must make sure that the marks are the same if a binary has both marks.
83351 +
83352 + If you enable none of the marking options then all applications
83353 + will run with PaX enabled on them by default.
83354 +
83355 +choice
83356 + prompt 'MAC system integration'
83357 + default PAX_HAVE_ACL_FLAGS
83358 + help
83359 + Mandatory Access Control systems have the option of controlling
83360 + PaX flags on a per executable basis, choose the method supported
83361 + by your particular system.
83362 +
83363 + - "none": if your MAC system does not interact with PaX,
83364 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
83365 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
83366 +
83367 + NOTE: this option is for developers/integrators only.
83368 +
83369 + config PAX_NO_ACL_FLAGS
83370 + bool 'none'
83371 +
83372 + config PAX_HAVE_ACL_FLAGS
83373 + bool 'direct'
83374 +
83375 + config PAX_HOOK_ACL_FLAGS
83376 + bool 'hook'
83377 +endchoice
83378 +
83379 +endmenu
83380 +
83381 +menu "Non-executable pages"
83382 + depends on PAX
83383 +
83384 +config PAX_NOEXEC
83385 + bool "Enforce non-executable pages"
83386 + default y if GRKERNSEC_CONFIG_AUTO
83387 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
83388 + help
83389 + By design some architectures do not allow for protecting memory
83390 + pages against execution or even if they do, Linux does not make
83391 + use of this feature. In practice this means that if a page is
83392 + readable (such as the stack or heap) it is also executable.
83393 +
83394 + There is a well known exploit technique that makes use of this
83395 + fact and a common programming mistake where an attacker can
83396 + introduce code of his choice somewhere in the attacked program's
83397 + memory (typically the stack or the heap) and then execute it.
83398 +
83399 + If the attacked program was running with different (typically
83400 + higher) privileges than that of the attacker, then he can elevate
83401 + his own privilege level (e.g. get a root shell, write to files for
83402 + which he does not have write access to, etc).
83403 +
83404 + Enabling this option will let you choose from various features
83405 + that prevent the injection and execution of 'foreign' code in
83406 + a program.
83407 +
83408 + This will also break programs that rely on the old behaviour and
83409 + expect that dynamically allocated memory via the malloc() family
83410 + of functions is executable (which it is not). Notable examples
83411 + are the XFree86 4.x server, the java runtime and wine.
83412 +
83413 +config PAX_PAGEEXEC
83414 + bool "Paging based non-executable pages"
83415 + default y if GRKERNSEC_CONFIG_AUTO
83416 + 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)
83417 + select S390_SWITCH_AMODE if S390
83418 + select S390_EXEC_PROTECT if S390
83419 + select ARCH_TRACK_EXEC_LIMIT if X86_32
83420 + help
83421 + This implementation is based on the paging feature of the CPU.
83422 + On i386 without hardware non-executable bit support there is a
83423 + variable but usually low performance impact, however on Intel's
83424 + P4 core based CPUs it is very high so you should not enable this
83425 + for kernels meant to be used on such CPUs.
83426 +
83427 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
83428 + with hardware non-executable bit support there is no performance
83429 + impact, on ppc the impact is negligible.
83430 +
83431 + Note that several architectures require various emulations due to
83432 + badly designed userland ABIs, this will cause a performance impact
83433 + but will disappear as soon as userland is fixed. For example, ppc
83434 + userland MUST have been built with secure-plt by a recent toolchain.
83435 +
83436 +config PAX_SEGMEXEC
83437 + bool "Segmentation based non-executable pages"
83438 + default y if GRKERNSEC_CONFIG_AUTO
83439 + depends on PAX_NOEXEC && X86_32
83440 + help
83441 + This implementation is based on the segmentation feature of the
83442 + CPU and has a very small performance impact, however applications
83443 + will be limited to a 1.5 GB address space instead of the normal
83444 + 3 GB.
83445 +
83446 +config PAX_EMUTRAMP
83447 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
83448 + default y if PARISC
83449 + help
83450 + There are some programs and libraries that for one reason or
83451 + another attempt to execute special small code snippets from
83452 + non-executable memory pages. Most notable examples are the
83453 + signal handler return code generated by the kernel itself and
83454 + the GCC trampolines.
83455 +
83456 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
83457 + such programs will no longer work under your kernel.
83458 +
83459 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
83460 + utilities to enable trampoline emulation for the affected programs
83461 + yet still have the protection provided by the non-executable pages.
83462 +
83463 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
83464 + your system will not even boot.
83465 +
83466 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
83467 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
83468 + for the affected files.
83469 +
83470 + NOTE: enabling this feature *may* open up a loophole in the
83471 + protection provided by non-executable pages that an attacker
83472 + could abuse. Therefore the best solution is to not have any
83473 + files on your system that would require this option. This can
83474 + be achieved by not using libc5 (which relies on the kernel
83475 + signal handler return code) and not using or rewriting programs
83476 + that make use of the nested function implementation of GCC.
83477 + Skilled users can just fix GCC itself so that it implements
83478 + nested function calls in a way that does not interfere with PaX.
83479 +
83480 +config PAX_EMUSIGRT
83481 + bool "Automatically emulate sigreturn trampolines"
83482 + depends on PAX_EMUTRAMP && PARISC
83483 + default y
83484 + help
83485 + Enabling this option will have the kernel automatically detect
83486 + and emulate signal return trampolines executing on the stack
83487 + that would otherwise lead to task termination.
83488 +
83489 + This solution is intended as a temporary one for users with
83490 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
83491 + Modula-3 runtime, etc) or executables linked to such, basically
83492 + everything that does not specify its own SA_RESTORER function in
83493 + normal executable memory like glibc 2.1+ does.
83494 +
83495 + On parisc you MUST enable this option, otherwise your system will
83496 + not even boot.
83497 +
83498 + NOTE: this feature cannot be disabled on a per executable basis
83499 + and since it *does* open up a loophole in the protection provided
83500 + by non-executable pages, the best solution is to not have any
83501 + files on your system that would require this option.
83502 +
83503 +config PAX_MPROTECT
83504 + bool "Restrict mprotect()"
83505 + default y if GRKERNSEC_CONFIG_AUTO
83506 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
83507 + help
83508 + Enabling this option will prevent programs from
83509 + - changing the executable status of memory pages that were
83510 + not originally created as executable,
83511 + - making read-only executable pages writable again,
83512 + - creating executable pages from anonymous memory,
83513 + - making read-only-after-relocations (RELRO) data pages writable again.
83514 +
83515 + You should say Y here to complete the protection provided by
83516 + the enforcement of non-executable pages.
83517 +
83518 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
83519 + this feature on a per file basis.
83520 +
83521 +config PAX_MPROTECT_COMPAT
83522 + bool "Use legacy/compat protection demoting (read help)"
83523 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
83524 + depends on PAX_MPROTECT
83525 + help
83526 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
83527 + by sending the proper error code to the application. For some broken
83528 + userland, this can cause problems with Python or other applications. The
83529 + current implementation however allows for applications like clamav to
83530 + detect if JIT compilation/execution is allowed and to fall back gracefully
83531 + to an interpreter-based mode if it does not. While we encourage everyone
83532 + to use the current implementation as-is and push upstream to fix broken
83533 + userland (note that the RWX logging option can assist with this), in some
83534 + environments this may not be possible. Having to disable MPROTECT
83535 + completely on certain binaries reduces the security benefit of PaX,
83536 + so this option is provided for those environments to revert to the old
83537 + behavior.
83538 +
83539 +config PAX_ELFRELOCS
83540 + bool "Allow ELF text relocations (read help)"
83541 + depends on PAX_MPROTECT
83542 + default n
83543 + help
83544 + Non-executable pages and mprotect() restrictions are effective
83545 + in preventing the introduction of new executable code into an
83546 + attacked task's address space. There remain only two venues
83547 + for this kind of attack: if the attacker can execute already
83548 + existing code in the attacked task then he can either have it
83549 + create and mmap() a file containing his code or have it mmap()
83550 + an already existing ELF library that does not have position
83551 + independent code in it and use mprotect() on it to make it
83552 + writable and copy his code there. While protecting against
83553 + the former approach is beyond PaX, the latter can be prevented
83554 + by having only PIC ELF libraries on one's system (which do not
83555 + need to relocate their code). If you are sure this is your case,
83556 + as is the case with all modern Linux distributions, then leave
83557 + this option disabled. You should say 'n' here.
83558 +
83559 +config PAX_ETEXECRELOCS
83560 + bool "Allow ELF ET_EXEC text relocations"
83561 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
83562 + select PAX_ELFRELOCS
83563 + default y
83564 + help
83565 + On some architectures there are incorrectly created applications
83566 + that require text relocations and would not work without enabling
83567 + this option. If you are an alpha, ia64 or parisc user, you should
83568 + enable this option and disable it once you have made sure that
83569 + none of your applications need it.
83570 +
83571 +config PAX_EMUPLT
83572 + bool "Automatically emulate ELF PLT"
83573 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
83574 + default y
83575 + help
83576 + Enabling this option will have the kernel automatically detect
83577 + and emulate the Procedure Linkage Table entries in ELF files.
83578 + On some architectures such entries are in writable memory, and
83579 + become non-executable leading to task termination. Therefore
83580 + it is mandatory that you enable this option on alpha, parisc,
83581 + sparc and sparc64, otherwise your system would not even boot.
83582 +
83583 + NOTE: this feature *does* open up a loophole in the protection
83584 + provided by the non-executable pages, therefore the proper
83585 + solution is to modify the toolchain to produce a PLT that does
83586 + not need to be writable.
83587 +
83588 +config PAX_DLRESOLVE
83589 + bool 'Emulate old glibc resolver stub'
83590 + depends on PAX_EMUPLT && SPARC
83591 + default n
83592 + help
83593 + This option is needed if userland has an old glibc (before 2.4)
83594 + that puts a 'save' instruction into the runtime generated resolver
83595 + stub that needs special emulation.
83596 +
83597 +config PAX_KERNEXEC
83598 + bool "Enforce non-executable kernel pages"
83599 + 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))
83600 + depends on (X86 || ARM_LPAE) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
83601 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
83602 + select PAX_KERNEXEC_PLUGIN if X86_64
83603 + help
83604 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
83605 + that is, enabling this option will make it harder to inject
83606 + and execute 'foreign' code in kernel memory itself.
83607 +
83608 +choice
83609 + prompt "Return Address Instrumentation Method"
83610 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
83611 + depends on PAX_KERNEXEC_PLUGIN
83612 + help
83613 + Select the method used to instrument function pointer dereferences.
83614 + Note that binary modules cannot be instrumented by this approach.
83615 +
83616 + Note that the implementation requires a gcc with plugin support,
83617 + i.e., gcc 4.5 or newer. You may need to install the supporting
83618 + headers explicitly in addition to the normal gcc package.
83619 +
83620 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
83621 + bool "bts"
83622 + help
83623 + This method is compatible with binary only modules but has
83624 + a higher runtime overhead.
83625 +
83626 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
83627 + bool "or"
83628 + depends on !PARAVIRT
83629 + help
83630 + This method is incompatible with binary only modules but has
83631 + a lower runtime overhead.
83632 +endchoice
83633 +
83634 +config PAX_KERNEXEC_PLUGIN_METHOD
83635 + string
83636 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
83637 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
83638 + default ""
83639 +
83640 +config PAX_KERNEXEC_MODULE_TEXT
83641 + int "Minimum amount of memory reserved for module code"
83642 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
83643 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
83644 + depends on PAX_KERNEXEC && X86_32 && MODULES
83645 + help
83646 + Due to implementation details the kernel must reserve a fixed
83647 + amount of memory for module code at compile time that cannot be
83648 + changed at runtime. Here you can specify the minimum amount
83649 + in MB that will be reserved. Due to the same implementation
83650 + details this size will always be rounded up to the next 2/4 MB
83651 + boundary (depends on PAE) so the actually available memory for
83652 + module code will usually be more than this minimum.
83653 +
83654 + The default 4 MB should be enough for most users but if you have
83655 + an excessive number of modules (e.g., most distribution configs
83656 + compile many drivers as modules) or use huge modules such as
83657 + nvidia's kernel driver, you will need to adjust this amount.
83658 + A good rule of thumb is to look at your currently loaded kernel
83659 + modules and add up their sizes.
83660 +
83661 +endmenu
83662 +
83663 +menu "Address Space Layout Randomization"
83664 + depends on PAX
83665 +
83666 +config PAX_ASLR
83667 + bool "Address Space Layout Randomization"
83668 + default y if GRKERNSEC_CONFIG_AUTO
83669 + help
83670 + Many if not most exploit techniques rely on the knowledge of
83671 + certain addresses in the attacked program. The following options
83672 + will allow the kernel to apply a certain amount of randomization
83673 + to specific parts of the program thereby forcing an attacker to
83674 + guess them in most cases. Any failed guess will most likely crash
83675 + the attacked program which allows the kernel to detect such attempts
83676 + and react on them. PaX itself provides no reaction mechanisms,
83677 + instead it is strongly encouraged that you make use of Nergal's
83678 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
83679 + (http://www.grsecurity.net/) built-in crash detection features or
83680 + develop one yourself.
83681 +
83682 + By saying Y here you can choose to randomize the following areas:
83683 + - top of the task's kernel stack
83684 + - top of the task's userland stack
83685 + - base address for mmap() requests that do not specify one
83686 + (this includes all libraries)
83687 + - base address of the main executable
83688 +
83689 + It is strongly recommended to say Y here as address space layout
83690 + randomization has negligible impact on performance yet it provides
83691 + a very effective protection.
83692 +
83693 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
83694 + this feature on a per file basis.
83695 +
83696 +config PAX_RANDKSTACK
83697 + bool "Randomize kernel stack base"
83698 + default y if GRKERNSEC_CONFIG_AUTO
83699 + depends on X86_TSC && X86
83700 + help
83701 + By saying Y here the kernel will randomize every task's kernel
83702 + stack on every system call. This will not only force an attacker
83703 + to guess it but also prevent him from making use of possible
83704 + leaked information about it.
83705 +
83706 + Since the kernel stack is a rather scarce resource, randomization
83707 + may cause unexpected stack overflows, therefore you should very
83708 + carefully test your system. Note that once enabled in the kernel
83709 + configuration, this feature cannot be disabled on a per file basis.
83710 +
83711 +config PAX_RANDUSTACK
83712 + bool "Randomize user stack base"
83713 + default y if GRKERNSEC_CONFIG_AUTO
83714 + depends on PAX_ASLR
83715 + help
83716 + By saying Y here the kernel will randomize every task's userland
83717 + stack. The randomization is done in two steps where the second
83718 + one may apply a big amount of shift to the top of the stack and
83719 + cause problems for programs that want to use lots of memory (more
83720 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
83721 + For this reason the second step can be controlled by 'chpax' or
83722 + 'paxctl' on a per file basis.
83723 +
83724 +config PAX_RANDMMAP
83725 + bool "Randomize mmap() base"
83726 + default y if GRKERNSEC_CONFIG_AUTO
83727 + depends on PAX_ASLR
83728 + help
83729 + By saying Y here the kernel will use a randomized base address for
83730 + mmap() requests that do not specify one themselves. As a result
83731 + all dynamically loaded libraries will appear at random addresses
83732 + and therefore be harder to exploit by a technique where an attacker
83733 + attempts to execute library code for his purposes (e.g. spawn a
83734 + shell from an exploited program that is running at an elevated
83735 + privilege level).
83736 +
83737 + Furthermore, if a program is relinked as a dynamic ELF file, its
83738 + base address will be randomized as well, completing the full
83739 + randomization of the address space layout. Attacking such programs
83740 + becomes a guess game. You can find an example of doing this at
83741 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
83742 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
83743 +
83744 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
83745 + feature on a per file basis.
83746 +
83747 +endmenu
83748 +
83749 +menu "Miscellaneous hardening features"
83750 +
83751 +config PAX_MEMORY_SANITIZE
83752 + bool "Sanitize all freed memory"
83753 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
83754 + depends on !HIBERNATION
83755 + help
83756 + By saying Y here the kernel will erase memory pages as soon as they
83757 + are freed. This in turn reduces the lifetime of data stored in the
83758 + pages, making it less likely that sensitive information such as
83759 + passwords, cryptographic secrets, etc stay in memory for too long.
83760 +
83761 + This is especially useful for programs whose runtime is short, long
83762 + lived processes and the kernel itself benefit from this as long as
83763 + they operate on whole memory pages and ensure timely freeing of pages
83764 + that may hold sensitive information.
83765 +
83766 + The tradeoff is performance impact, on a single CPU system kernel
83767 + compilation sees a 3% slowdown, other systems and workloads may vary
83768 + and you are advised to test this feature on your expected workload
83769 + before deploying it.
83770 +
83771 + Note that this feature does not protect data stored in live pages,
83772 + e.g., process memory swapped to disk may stay there for a long time.
83773 +
83774 +config PAX_MEMORY_STACKLEAK
83775 + bool "Sanitize kernel stack"
83776 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
83777 + depends on X86
83778 + help
83779 + By saying Y here the kernel will erase the kernel stack before it
83780 + returns from a system call. This in turn reduces the information
83781 + that a kernel stack leak bug can reveal.
83782 +
83783 + Note that such a bug can still leak information that was put on
83784 + the stack by the current system call (the one eventually triggering
83785 + the bug) but traces of earlier system calls on the kernel stack
83786 + cannot leak anymore.
83787 +
83788 + The tradeoff is performance impact: on a single CPU system kernel
83789 + compilation sees a 1% slowdown, other systems and workloads may vary
83790 + and you are advised to test this feature on your expected workload
83791 + before deploying it.
83792 +
83793 + Note that the full feature requires a gcc with plugin support,
83794 + i.e., gcc 4.5 or newer. You may need to install the supporting
83795 + headers explicitly in addition to the normal gcc package. Using
83796 + older gcc versions means that functions with large enough stack
83797 + frames may leave uninitialized memory behind that may be exposed
83798 + to a later syscall leaking the stack.
83799 +
83800 +config PAX_MEMORY_UDEREF
83801 + bool "Prevent invalid userland pointer dereference"
83802 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
83803 + depends on X86 && !UML_X86 && !XEN
83804 + select PAX_PER_CPU_PGD if X86_64
83805 + help
83806 + By saying Y here the kernel will be prevented from dereferencing
83807 + userland pointers in contexts where the kernel expects only kernel
83808 + pointers. This is both a useful runtime debugging feature and a
83809 + security measure that prevents exploiting a class of kernel bugs.
83810 +
83811 + The tradeoff is that some virtualization solutions may experience
83812 + a huge slowdown and therefore you should not enable this feature
83813 + for kernels meant to run in such environments. Whether a given VM
83814 + solution is affected or not is best determined by simply trying it
83815 + out, the performance impact will be obvious right on boot as this
83816 + mechanism engages from very early on. A good rule of thumb is that
83817 + VMs running on CPUs without hardware virtualization support (i.e.,
83818 + the majority of IA-32 CPUs) will likely experience the slowdown.
83819 +
83820 +config PAX_REFCOUNT
83821 + bool "Prevent various kernel object reference counter overflows"
83822 + default y if GRKERNSEC_CONFIG_AUTO
83823 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
83824 + help
83825 + By saying Y here the kernel will detect and prevent overflowing
83826 + various (but not all) kinds of object reference counters. Such
83827 + overflows can normally occur due to bugs only and are often, if
83828 + not always, exploitable.
83829 +
83830 + The tradeoff is that data structures protected by an overflowed
83831 + refcount will never be freed and therefore will leak memory. Note
83832 + that this leak also happens even without this protection but in
83833 + that case the overflow can eventually trigger the freeing of the
83834 + data structure while it is still being used elsewhere, resulting
83835 + in the exploitable situation that this feature prevents.
83836 +
83837 + Since this has a negligible performance impact, you should enable
83838 + this feature.
83839 +
83840 +config PAX_USERCOPY
83841 + bool "Harden heap object copies between kernel and userland"
83842 + default y if GRKERNSEC_CONFIG_AUTO
83843 + depends on ARM || IA64 || PPC || SPARC || X86
83844 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
83845 + select PAX_USERCOPY_SLABS
83846 + help
83847 + By saying Y here the kernel will enforce the size of heap objects
83848 + when they are copied in either direction between the kernel and
83849 + userland, even if only a part of the heap object is copied.
83850 +
83851 + Specifically, this checking prevents information leaking from the
83852 + kernel heap during kernel to userland copies (if the kernel heap
83853 + object is otherwise fully initialized) and prevents kernel heap
83854 + overflows during userland to kernel copies.
83855 +
83856 + Note that the current implementation provides the strictest bounds
83857 + checks for the SLUB allocator.
83858 +
83859 + Enabling this option also enables per-slab cache protection against
83860 + data in a given cache being copied into/out of via userland
83861 + accessors. Though the whitelist of regions will be reduced over
83862 + time, it notably protects important data structures like task structs.
83863 +
83864 + If frame pointers are enabled on x86, this option will also restrict
83865 + copies into and out of the kernel stack to local variables within a
83866 + single frame.
83867 +
83868 + Since this has a negligible performance impact, you should enable
83869 + this feature.
83870 +
83871 +
83872 +config PAX_USERCOPY_DEBUG
83873 + bool
83874 + depends on X86 && PAX_USERCOPY
83875 + default n
83876 +
83877 +config PAX_SIZE_OVERFLOW
83878 + bool "Prevent various integer overflows in function size parameters"
83879 + default y if GRKERNSEC_CONFIG_AUTO
83880 + depends on X86
83881 + help
83882 + By saying Y here the kernel recomputes expressions of function
83883 + arguments marked by a size_overflow attribute with double integer
83884 + precision (DImode/TImode for 32/64 bit integer types).
83885 +
83886 + The recomputed argument is checked against TYPE_MAX and an event
83887 + is logged on overflow and the triggering process is killed.
83888 +
83889 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
83890 +
83891 + Note that the implementation requires a gcc with plugin support,
83892 + i.e., gcc 4.5 or newer. You may need to install the supporting
83893 + headers explicitly in addition to the normal gcc package.
83894 +
83895 +config PAX_LATENT_ENTROPY
83896 + bool "Generate some entropy during boot"
83897 + default y if GRKERNSEC_CONFIG_AUTO
83898 + help
83899 + By saying Y here the kernel will instrument early boot code to
83900 + extract some entropy from both original and artificially created
83901 + program state. This will help especially embedded systems where
83902 + there is little 'natural' source of entropy normally. The cost
83903 + is some slowdown of the boot process.
83904 +
83905 + Note that the implementation requires a gcc with plugin support,
83906 + i.e., gcc 4.5 or newer. You may need to install the supporting
83907 + headers explicitly in addition to the normal gcc package.
83908 +
83909 + Note that entropy extracted this way is not cryptographically
83910 + secure!
83911 +
83912 +endmenu
83913 +
83914 +endmenu
83915 +
83916 +source grsecurity/Kconfig
83917 +
83918 +endmenu
83919 +
83920 +endmenu
83921 +
83922 source security/keys/Kconfig
83923
83924 config SECURITY_DMESG_RESTRICT
83925 @@ -103,7 +999,7 @@ config INTEL_TXT
83926 config LSM_MMAP_MIN_ADDR
83927 int "Low address space for LSM to protect from user allocation"
83928 depends on SECURITY && SECURITY_SELINUX
83929 - default 32768 if ARM
83930 + default 32768 if ALPHA || ARM || PARISC || SPARC32
83931 default 65536
83932 help
83933 This is the portion of low virtual memory which should be protected
83934 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
83935 index 8c2a7f6..b133ac9 100644
83936 --- a/security/apparmor/lsm.c
83937 +++ b/security/apparmor/lsm.c
83938 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
83939 return error;
83940 }
83941
83942 -static struct security_operations apparmor_ops = {
83943 +static struct security_operations apparmor_ops __read_only = {
83944 .name = "apparmor",
83945
83946 .ptrace_access_check = apparmor_ptrace_access_check,
83947 diff --git a/security/commoncap.c b/security/commoncap.c
83948 index 6dbae46..d5611fd 100644
83949 --- a/security/commoncap.c
83950 +++ b/security/commoncap.c
83951 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
83952 return 0;
83953 }
83954
83955 +/* returns:
83956 + 1 for suid privilege
83957 + 2 for sgid privilege
83958 + 3 for fscap privilege
83959 +*/
83960 +int is_privileged_binary(const struct dentry *dentry)
83961 +{
83962 + struct cpu_vfs_cap_data capdata;
83963 + struct inode *inode = dentry->d_inode;
83964 +
83965 + if (!inode || S_ISDIR(inode->i_mode))
83966 + return 0;
83967 +
83968 + if (inode->i_mode & S_ISUID)
83969 + return 1;
83970 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
83971 + return 2;
83972 +
83973 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
83974 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
83975 + return 3;
83976 + }
83977 +
83978 + return 0;
83979 +}
83980 +
83981 /*
83982 * Attempt to get the on-exec apply capability sets for an executable file from
83983 * its xattrs and, if present, apply them to the proposed credentials being
83984 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
83985 const struct cred *cred = current_cred();
83986 kuid_t root_uid = make_kuid(cred->user_ns, 0);
83987
83988 + if (gr_acl_enable_at_secure())
83989 + return 1;
83990 +
83991 if (!uid_eq(cred->uid, root_uid)) {
83992 if (bprm->cap_effective)
83993 return 1;
83994 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
83995 index 6ee8826..6350060 100644
83996 --- a/security/integrity/ima/ima.h
83997 +++ b/security/integrity/ima/ima.h
83998 @@ -96,8 +96,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
83999 extern spinlock_t ima_queue_lock;
84000
84001 struct ima_h_table {
84002 - atomic_long_t len; /* number of stored measurements in the list */
84003 - atomic_long_t violations;
84004 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
84005 + atomic_long_unchecked_t violations;
84006 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
84007 };
84008 extern struct ima_h_table ima_htable;
84009 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
84010 index b356884..fd9676e 100644
84011 --- a/security/integrity/ima/ima_api.c
84012 +++ b/security/integrity/ima/ima_api.c
84013 @@ -79,7 +79,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
84014 int result;
84015
84016 /* can overflow, only indicator */
84017 - atomic_long_inc(&ima_htable.violations);
84018 + atomic_long_inc_unchecked(&ima_htable.violations);
84019
84020 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
84021 if (!entry) {
84022 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
84023 index 38477c9..87a60c7 100644
84024 --- a/security/integrity/ima/ima_fs.c
84025 +++ b/security/integrity/ima/ima_fs.c
84026 @@ -28,12 +28,12 @@
84027 static int valid_policy = 1;
84028 #define TMPBUFLEN 12
84029 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
84030 - loff_t *ppos, atomic_long_t *val)
84031 + loff_t *ppos, atomic_long_unchecked_t *val)
84032 {
84033 char tmpbuf[TMPBUFLEN];
84034 ssize_t len;
84035
84036 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
84037 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
84038 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
84039 }
84040
84041 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
84042 index 55a6271..ad829c3 100644
84043 --- a/security/integrity/ima/ima_queue.c
84044 +++ b/security/integrity/ima/ima_queue.c
84045 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
84046 INIT_LIST_HEAD(&qe->later);
84047 list_add_tail_rcu(&qe->later, &ima_measurements);
84048
84049 - atomic_long_inc(&ima_htable.len);
84050 + atomic_long_inc_unchecked(&ima_htable.len);
84051 key = ima_hash_key(entry->digest);
84052 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
84053 return 0;
84054 diff --git a/security/keys/compat.c b/security/keys/compat.c
84055 index 1c26176..64a1ba2 100644
84056 --- a/security/keys/compat.c
84057 +++ b/security/keys/compat.c
84058 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
84059 if (ret == 0)
84060 goto no_payload_free;
84061
84062 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
84063 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
84064
84065 if (iov != iovstack)
84066 kfree(iov);
84067 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
84068 index 5d34b4e..2456674 100644
84069 --- a/security/keys/keyctl.c
84070 +++ b/security/keys/keyctl.c
84071 @@ -986,7 +986,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
84072 /*
84073 * Copy the iovec data from userspace
84074 */
84075 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
84076 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
84077 unsigned ioc)
84078 {
84079 for (; ioc > 0; ioc--) {
84080 @@ -1008,7 +1008,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
84081 * If successful, 0 will be returned.
84082 */
84083 long keyctl_instantiate_key_common(key_serial_t id,
84084 - const struct iovec *payload_iov,
84085 + const struct iovec __user *payload_iov,
84086 unsigned ioc,
84087 size_t plen,
84088 key_serial_t ringid)
84089 @@ -1103,7 +1103,7 @@ long keyctl_instantiate_key(key_serial_t id,
84090 [0].iov_len = plen
84091 };
84092
84093 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
84094 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
84095 }
84096
84097 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
84098 @@ -1136,7 +1136,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
84099 if (ret == 0)
84100 goto no_payload_free;
84101
84102 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
84103 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
84104
84105 if (iov != iovstack)
84106 kfree(iov);
84107 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
84108 index 6e42df1..aba52bd 100644
84109 --- a/security/keys/keyring.c
84110 +++ b/security/keys/keyring.c
84111 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
84112 ret = -EFAULT;
84113
84114 for (loop = 0; loop < klist->nkeys; loop++) {
84115 + key_serial_t serial;
84116 key = rcu_deref_link_locked(klist, loop,
84117 keyring);
84118 + serial = key->serial;
84119
84120 tmp = sizeof(key_serial_t);
84121 if (tmp > buflen)
84122 tmp = buflen;
84123
84124 - if (copy_to_user(buffer,
84125 - &key->serial,
84126 - tmp) != 0)
84127 + if (copy_to_user(buffer, &serial, tmp))
84128 goto error;
84129
84130 buflen -= tmp;
84131 diff --git a/security/min_addr.c b/security/min_addr.c
84132 index f728728..6457a0c 100644
84133 --- a/security/min_addr.c
84134 +++ b/security/min_addr.c
84135 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
84136 */
84137 static void update_mmap_min_addr(void)
84138 {
84139 +#ifndef SPARC
84140 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
84141 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
84142 mmap_min_addr = dac_mmap_min_addr;
84143 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
84144 #else
84145 mmap_min_addr = dac_mmap_min_addr;
84146 #endif
84147 +#endif
84148 }
84149
84150 /*
84151 diff --git a/security/security.c b/security/security.c
84152 index 8dcd4ae..1124de7 100644
84153 --- a/security/security.c
84154 +++ b/security/security.c
84155 @@ -20,6 +20,7 @@
84156 #include <linux/ima.h>
84157 #include <linux/evm.h>
84158 #include <linux/fsnotify.h>
84159 +#include <linux/mm.h>
84160 #include <linux/mman.h>
84161 #include <linux/mount.h>
84162 #include <linux/personality.h>
84163 @@ -32,8 +33,8 @@
84164 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
84165 CONFIG_DEFAULT_SECURITY;
84166
84167 -static struct security_operations *security_ops;
84168 -static struct security_operations default_security_ops = {
84169 +static struct security_operations *security_ops __read_only;
84170 +static struct security_operations default_security_ops __read_only = {
84171 .name = "default",
84172 };
84173
84174 @@ -74,7 +75,9 @@ int __init security_init(void)
84175
84176 void reset_security_ops(void)
84177 {
84178 + pax_open_kernel();
84179 security_ops = &default_security_ops;
84180 + pax_close_kernel();
84181 }
84182
84183 /* Save user chosen LSM */
84184 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
84185 index 61a5336..27215d8 100644
84186 --- a/security/selinux/hooks.c
84187 +++ b/security/selinux/hooks.c
84188 @@ -95,8 +95,6 @@
84189
84190 #define NUM_SEL_MNT_OPTS 5
84191
84192 -extern struct security_operations *security_ops;
84193 -
84194 /* SECMARK reference count */
84195 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
84196
84197 @@ -5476,7 +5474,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
84198
84199 #endif
84200
84201 -static struct security_operations selinux_ops = {
84202 +static struct security_operations selinux_ops __read_only = {
84203 .name = "selinux",
84204
84205 .ptrace_access_check = selinux_ptrace_access_check,
84206 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
84207 index 65f67cb..3f141ef 100644
84208 --- a/security/selinux/include/xfrm.h
84209 +++ b/security/selinux/include/xfrm.h
84210 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
84211
84212 static inline void selinux_xfrm_notify_policyload(void)
84213 {
84214 - atomic_inc(&flow_cache_genid);
84215 + atomic_inc_unchecked(&flow_cache_genid);
84216 rt_genid_bump(&init_net);
84217 }
84218 #else
84219 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
84220 index 38be92c..21f49ee 100644
84221 --- a/security/smack/smack_lsm.c
84222 +++ b/security/smack/smack_lsm.c
84223 @@ -3398,7 +3398,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
84224 return 0;
84225 }
84226
84227 -struct security_operations smack_ops = {
84228 +struct security_operations smack_ops __read_only = {
84229 .name = "smack",
84230
84231 .ptrace_access_check = smack_ptrace_access_check,
84232 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
84233 index a2ee362..5754f34 100644
84234 --- a/security/tomoyo/tomoyo.c
84235 +++ b/security/tomoyo/tomoyo.c
84236 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
84237 * tomoyo_security_ops is a "struct security_operations" which is used for
84238 * registering TOMOYO.
84239 */
84240 -static struct security_operations tomoyo_security_ops = {
84241 +static struct security_operations tomoyo_security_ops __read_only = {
84242 .name = "tomoyo",
84243 .cred_alloc_blank = tomoyo_cred_alloc_blank,
84244 .cred_prepare = tomoyo_cred_prepare,
84245 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
84246 index 20ef514..4182bed 100644
84247 --- a/security/yama/Kconfig
84248 +++ b/security/yama/Kconfig
84249 @@ -1,6 +1,6 @@
84250 config SECURITY_YAMA
84251 bool "Yama support"
84252 - depends on SECURITY
84253 + depends on SECURITY && !GRKERNSEC
84254 select SECURITYFS
84255 select SECURITY_PATH
84256 default n
84257 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
84258 index 4cedc69..e59d8a3 100644
84259 --- a/sound/aoa/codecs/onyx.c
84260 +++ b/sound/aoa/codecs/onyx.c
84261 @@ -54,7 +54,7 @@ struct onyx {
84262 spdif_locked:1,
84263 analog_locked:1,
84264 original_mute:2;
84265 - int open_count;
84266 + local_t open_count;
84267 struct codec_info *codec_info;
84268
84269 /* mutex serializes concurrent access to the device
84270 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
84271 struct onyx *onyx = cii->codec_data;
84272
84273 mutex_lock(&onyx->mutex);
84274 - onyx->open_count++;
84275 + local_inc(&onyx->open_count);
84276 mutex_unlock(&onyx->mutex);
84277
84278 return 0;
84279 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
84280 struct onyx *onyx = cii->codec_data;
84281
84282 mutex_lock(&onyx->mutex);
84283 - onyx->open_count--;
84284 - if (!onyx->open_count)
84285 + if (local_dec_and_test(&onyx->open_count))
84286 onyx->spdif_locked = onyx->analog_locked = 0;
84287 mutex_unlock(&onyx->mutex);
84288
84289 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
84290 index ffd2025..df062c9 100644
84291 --- a/sound/aoa/codecs/onyx.h
84292 +++ b/sound/aoa/codecs/onyx.h
84293 @@ -11,6 +11,7 @@
84294 #include <linux/i2c.h>
84295 #include <asm/pmac_low_i2c.h>
84296 #include <asm/prom.h>
84297 +#include <asm/local.h>
84298
84299 /* PCM3052 register definitions */
84300
84301 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
84302 index 4c1cc51..16040040 100644
84303 --- a/sound/core/oss/pcm_oss.c
84304 +++ b/sound/core/oss/pcm_oss.c
84305 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
84306 if (in_kernel) {
84307 mm_segment_t fs;
84308 fs = snd_enter_user();
84309 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
84310 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
84311 snd_leave_user(fs);
84312 } else {
84313 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
84314 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
84315 }
84316 if (ret != -EPIPE && ret != -ESTRPIPE)
84317 break;
84318 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
84319 if (in_kernel) {
84320 mm_segment_t fs;
84321 fs = snd_enter_user();
84322 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
84323 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
84324 snd_leave_user(fs);
84325 } else {
84326 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
84327 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
84328 }
84329 if (ret == -EPIPE) {
84330 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
84331 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
84332 struct snd_pcm_plugin_channel *channels;
84333 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
84334 if (!in_kernel) {
84335 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
84336 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
84337 return -EFAULT;
84338 buf = runtime->oss.buffer;
84339 }
84340 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
84341 }
84342 } else {
84343 tmp = snd_pcm_oss_write2(substream,
84344 - (const char __force *)buf,
84345 + (const char __force_kernel *)buf,
84346 runtime->oss.period_bytes, 0);
84347 if (tmp <= 0)
84348 goto err;
84349 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
84350 struct snd_pcm_runtime *runtime = substream->runtime;
84351 snd_pcm_sframes_t frames, frames1;
84352 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
84353 - char __user *final_dst = (char __force __user *)buf;
84354 + char __user *final_dst = (char __force_user *)buf;
84355 if (runtime->oss.plugin_first) {
84356 struct snd_pcm_plugin_channel *channels;
84357 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
84358 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
84359 xfer += tmp;
84360 runtime->oss.buffer_used -= tmp;
84361 } else {
84362 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
84363 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
84364 runtime->oss.period_bytes, 0);
84365 if (tmp <= 0)
84366 goto err;
84367 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
84368 size1);
84369 size1 /= runtime->channels; /* frames */
84370 fs = snd_enter_user();
84371 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
84372 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
84373 snd_leave_user(fs);
84374 }
84375 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
84376 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
84377 index 91cdf943..4085161 100644
84378 --- a/sound/core/pcm_compat.c
84379 +++ b/sound/core/pcm_compat.c
84380 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
84381 int err;
84382
84383 fs = snd_enter_user();
84384 - err = snd_pcm_delay(substream, &delay);
84385 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
84386 snd_leave_user(fs);
84387 if (err < 0)
84388 return err;
84389 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
84390 index f9ddecf..e27404d 100644
84391 --- a/sound/core/pcm_native.c
84392 +++ b/sound/core/pcm_native.c
84393 @@ -2804,11 +2804,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
84394 switch (substream->stream) {
84395 case SNDRV_PCM_STREAM_PLAYBACK:
84396 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
84397 - (void __user *)arg);
84398 + (void __force_user *)arg);
84399 break;
84400 case SNDRV_PCM_STREAM_CAPTURE:
84401 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
84402 - (void __user *)arg);
84403 + (void __force_user *)arg);
84404 break;
84405 default:
84406 result = -EINVAL;
84407 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
84408 index 60e8fc1..786abcb 100644
84409 --- a/sound/core/seq/seq_device.c
84410 +++ b/sound/core/seq/seq_device.c
84411 @@ -64,7 +64,7 @@ struct ops_list {
84412 int argsize; /* argument size */
84413
84414 /* operators */
84415 - struct snd_seq_dev_ops ops;
84416 + struct snd_seq_dev_ops *ops;
84417
84418 /* registred devices */
84419 struct list_head dev_list; /* list of devices */
84420 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
84421
84422 mutex_lock(&ops->reg_mutex);
84423 /* copy driver operators */
84424 - ops->ops = *entry;
84425 + ops->ops = entry;
84426 ops->driver |= DRIVER_LOADED;
84427 ops->argsize = argsize;
84428
84429 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
84430 dev->name, ops->id, ops->argsize, dev->argsize);
84431 return -EINVAL;
84432 }
84433 - if (ops->ops.init_device(dev) >= 0) {
84434 + if (ops->ops->init_device(dev) >= 0) {
84435 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
84436 ops->num_init_devices++;
84437 } else {
84438 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
84439 dev->name, ops->id, ops->argsize, dev->argsize);
84440 return -EINVAL;
84441 }
84442 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
84443 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
84444 dev->status = SNDRV_SEQ_DEVICE_FREE;
84445 dev->driver_data = NULL;
84446 ops->num_init_devices--;
84447 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
84448 index 2d5514b..3afae9c 100644
84449 --- a/sound/drivers/mts64.c
84450 +++ b/sound/drivers/mts64.c
84451 @@ -29,6 +29,7 @@
84452 #include <sound/initval.h>
84453 #include <sound/rawmidi.h>
84454 #include <sound/control.h>
84455 +#include <asm/local.h>
84456
84457 #define CARD_NAME "Miditerminal 4140"
84458 #define DRIVER_NAME "MTS64"
84459 @@ -67,7 +68,7 @@ struct mts64 {
84460 struct pardevice *pardev;
84461 int pardev_claimed;
84462
84463 - int open_count;
84464 + local_t open_count;
84465 int current_midi_output_port;
84466 int current_midi_input_port;
84467 u8 mode[MTS64_NUM_INPUT_PORTS];
84468 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
84469 {
84470 struct mts64 *mts = substream->rmidi->private_data;
84471
84472 - if (mts->open_count == 0) {
84473 + if (local_read(&mts->open_count) == 0) {
84474 /* We don't need a spinlock here, because this is just called
84475 if the device has not been opened before.
84476 So there aren't any IRQs from the device */
84477 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
84478
84479 msleep(50);
84480 }
84481 - ++(mts->open_count);
84482 + local_inc(&mts->open_count);
84483
84484 return 0;
84485 }
84486 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
84487 struct mts64 *mts = substream->rmidi->private_data;
84488 unsigned long flags;
84489
84490 - --(mts->open_count);
84491 - if (mts->open_count == 0) {
84492 + if (local_dec_return(&mts->open_count) == 0) {
84493 /* We need the spinlock_irqsave here because we can still
84494 have IRQs at this point */
84495 spin_lock_irqsave(&mts->lock, flags);
84496 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
84497
84498 msleep(500);
84499
84500 - } else if (mts->open_count < 0)
84501 - mts->open_count = 0;
84502 + } else if (local_read(&mts->open_count) < 0)
84503 + local_set(&mts->open_count, 0);
84504
84505 return 0;
84506 }
84507 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
84508 index b953fb4..1999c01 100644
84509 --- a/sound/drivers/opl4/opl4_lib.c
84510 +++ b/sound/drivers/opl4/opl4_lib.c
84511 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
84512 MODULE_DESCRIPTION("OPL4 driver");
84513 MODULE_LICENSE("GPL");
84514
84515 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
84516 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
84517 {
84518 int timeout = 10;
84519 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
84520 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
84521 index 8364855..59f2e2b 100644
84522 --- a/sound/drivers/portman2x4.c
84523 +++ b/sound/drivers/portman2x4.c
84524 @@ -48,6 +48,7 @@
84525 #include <sound/initval.h>
84526 #include <sound/rawmidi.h>
84527 #include <sound/control.h>
84528 +#include <asm/local.h>
84529
84530 #define CARD_NAME "Portman 2x4"
84531 #define DRIVER_NAME "portman"
84532 @@ -85,7 +86,7 @@ struct portman {
84533 struct pardevice *pardev;
84534 int pardev_claimed;
84535
84536 - int open_count;
84537 + local_t open_count;
84538 int mode[PORTMAN_NUM_INPUT_PORTS];
84539 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
84540 };
84541 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
84542 index ea995af..f1bfa37 100644
84543 --- a/sound/firewire/amdtp.c
84544 +++ b/sound/firewire/amdtp.c
84545 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
84546 ptr = s->pcm_buffer_pointer + data_blocks;
84547 if (ptr >= pcm->runtime->buffer_size)
84548 ptr -= pcm->runtime->buffer_size;
84549 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
84550 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
84551
84552 s->pcm_period_pointer += data_blocks;
84553 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
84554 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
84555 */
84556 void amdtp_out_stream_update(struct amdtp_out_stream *s)
84557 {
84558 - ACCESS_ONCE(s->source_node_id_field) =
84559 + ACCESS_ONCE_RW(s->source_node_id_field) =
84560 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
84561 }
84562 EXPORT_SYMBOL(amdtp_out_stream_update);
84563 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
84564 index b680c5e..061b7a0 100644
84565 --- a/sound/firewire/amdtp.h
84566 +++ b/sound/firewire/amdtp.h
84567 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
84568 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
84569 struct snd_pcm_substream *pcm)
84570 {
84571 - ACCESS_ONCE(s->pcm) = pcm;
84572 + ACCESS_ONCE_RW(s->pcm) = pcm;
84573 }
84574
84575 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
84576 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
84577 index d428ffe..751ef78 100644
84578 --- a/sound/firewire/isight.c
84579 +++ b/sound/firewire/isight.c
84580 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
84581 ptr += count;
84582 if (ptr >= runtime->buffer_size)
84583 ptr -= runtime->buffer_size;
84584 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
84585 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
84586
84587 isight->period_counter += count;
84588 if (isight->period_counter >= runtime->period_size) {
84589 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
84590 if (err < 0)
84591 return err;
84592
84593 - ACCESS_ONCE(isight->pcm_active) = true;
84594 + ACCESS_ONCE_RW(isight->pcm_active) = true;
84595
84596 return 0;
84597 }
84598 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
84599 {
84600 struct isight *isight = substream->private_data;
84601
84602 - ACCESS_ONCE(isight->pcm_active) = false;
84603 + ACCESS_ONCE_RW(isight->pcm_active) = false;
84604
84605 mutex_lock(&isight->mutex);
84606 isight_stop_streaming(isight);
84607 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
84608
84609 switch (cmd) {
84610 case SNDRV_PCM_TRIGGER_START:
84611 - ACCESS_ONCE(isight->pcm_running) = true;
84612 + ACCESS_ONCE_RW(isight->pcm_running) = true;
84613 break;
84614 case SNDRV_PCM_TRIGGER_STOP:
84615 - ACCESS_ONCE(isight->pcm_running) = false;
84616 + ACCESS_ONCE_RW(isight->pcm_running) = false;
84617 break;
84618 default:
84619 return -EINVAL;
84620 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
84621 index b2b3c01..e1c1e1f 100644
84622 --- a/sound/oss/sb_audio.c
84623 +++ b/sound/oss/sb_audio.c
84624 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
84625 buf16 = (signed short *)(localbuf + localoffs);
84626 while (c)
84627 {
84628 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
84629 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
84630 if (copy_from_user(lbuf8,
84631 userbuf+useroffs + p,
84632 locallen))
84633 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
84634 index 7d8803a..559f8d0 100644
84635 --- a/sound/oss/swarm_cs4297a.c
84636 +++ b/sound/oss/swarm_cs4297a.c
84637 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
84638 {
84639 struct cs4297a_state *s;
84640 u32 pwr, id;
84641 - mm_segment_t fs;
84642 int rval;
84643 #ifndef CONFIG_BCM_CS4297A_CSWARM
84644 u64 cfg;
84645 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
84646 if (!rval) {
84647 char *sb1250_duart_present;
84648
84649 +#if 0
84650 + mm_segment_t fs;
84651 fs = get_fs();
84652 set_fs(KERNEL_DS);
84653 -#if 0
84654 val = SOUND_MASK_LINE;
84655 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
84656 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
84657 val = initvol[i].vol;
84658 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
84659 }
84660 + set_fs(fs);
84661 // cs4297a_write_ac97(s, 0x18, 0x0808);
84662 #else
84663 // cs4297a_write_ac97(s, 0x5e, 0x180);
84664 cs4297a_write_ac97(s, 0x02, 0x0808);
84665 cs4297a_write_ac97(s, 0x18, 0x0808);
84666 #endif
84667 - set_fs(fs);
84668
84669 list_add(&s->list, &cs4297a_devs);
84670
84671 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
84672 index 4631a23..001ae57 100644
84673 --- a/sound/pci/ymfpci/ymfpci.h
84674 +++ b/sound/pci/ymfpci/ymfpci.h
84675 @@ -358,7 +358,7 @@ struct snd_ymfpci {
84676 spinlock_t reg_lock;
84677 spinlock_t voice_lock;
84678 wait_queue_head_t interrupt_sleep;
84679 - atomic_t interrupt_sleep_count;
84680 + atomic_unchecked_t interrupt_sleep_count;
84681 struct snd_info_entry *proc_entry;
84682 const struct firmware *dsp_microcode;
84683 const struct firmware *controller_microcode;
84684 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
84685 index 3a6f03f..bc5c86c 100644
84686 --- a/sound/pci/ymfpci/ymfpci_main.c
84687 +++ b/sound/pci/ymfpci/ymfpci_main.c
84688 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
84689 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
84690 break;
84691 }
84692 - if (atomic_read(&chip->interrupt_sleep_count)) {
84693 - atomic_set(&chip->interrupt_sleep_count, 0);
84694 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
84695 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
84696 wake_up(&chip->interrupt_sleep);
84697 }
84698 __end:
84699 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
84700 continue;
84701 init_waitqueue_entry(&wait, current);
84702 add_wait_queue(&chip->interrupt_sleep, &wait);
84703 - atomic_inc(&chip->interrupt_sleep_count);
84704 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
84705 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
84706 remove_wait_queue(&chip->interrupt_sleep, &wait);
84707 }
84708 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
84709 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
84710 spin_unlock(&chip->reg_lock);
84711
84712 - if (atomic_read(&chip->interrupt_sleep_count)) {
84713 - atomic_set(&chip->interrupt_sleep_count, 0);
84714 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
84715 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
84716 wake_up(&chip->interrupt_sleep);
84717 }
84718 }
84719 @@ -2420,7 +2420,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
84720 spin_lock_init(&chip->reg_lock);
84721 spin_lock_init(&chip->voice_lock);
84722 init_waitqueue_head(&chip->interrupt_sleep);
84723 - atomic_set(&chip->interrupt_sleep_count, 0);
84724 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
84725 chip->card = card;
84726 chip->pci = pci;
84727 chip->irq = -1;
84728 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
84729 new file mode 100644
84730 index 0000000..50f2f2f
84731 --- /dev/null
84732 +++ b/tools/gcc/.gitignore
84733 @@ -0,0 +1 @@
84734 +size_overflow_hash.h
84735 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
84736 new file mode 100644
84737 index 0000000..1d09b7e
84738 --- /dev/null
84739 +++ b/tools/gcc/Makefile
84740 @@ -0,0 +1,43 @@
84741 +#CC := gcc
84742 +#PLUGIN_SOURCE_FILES := pax_plugin.c
84743 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
84744 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
84745 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
84746 +
84747 +ifeq ($(PLUGINCC),$(HOSTCC))
84748 +HOSTLIBS := hostlibs
84749 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
84750 +else
84751 +HOSTLIBS := hostcxxlibs
84752 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
84753 +endif
84754 +
84755 +$(HOSTLIBS)-y := constify_plugin.so
84756 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
84757 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
84758 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
84759 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
84760 +$(HOSTLIBS)-y += colorize_plugin.so
84761 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
84762 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
84763 +
84764 +always := $($(HOSTLIBS)-y)
84765 +
84766 +constify_plugin-objs := constify_plugin.o
84767 +stackleak_plugin-objs := stackleak_plugin.o
84768 +kallocstat_plugin-objs := kallocstat_plugin.o
84769 +kernexec_plugin-objs := kernexec_plugin.o
84770 +checker_plugin-objs := checker_plugin.o
84771 +colorize_plugin-objs := colorize_plugin.o
84772 +size_overflow_plugin-objs := size_overflow_plugin.o
84773 +latent_entropy_plugin-objs := latent_entropy_plugin.o
84774 +
84775 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
84776 +
84777 +quiet_cmd_build_size_overflow_hash = GENHASH $@
84778 + cmd_build_size_overflow_hash = \
84779 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
84780 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
84781 + $(call if_changed,build_size_overflow_hash)
84782 +
84783 +targets += size_overflow_hash.h
84784 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
84785 new file mode 100644
84786 index 0000000..d41b5af
84787 --- /dev/null
84788 +++ b/tools/gcc/checker_plugin.c
84789 @@ -0,0 +1,171 @@
84790 +/*
84791 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
84792 + * Licensed under the GPL v2
84793 + *
84794 + * Note: the choice of the license means that the compilation process is
84795 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84796 + * but for the kernel it doesn't matter since it doesn't link against
84797 + * any of the gcc libraries
84798 + *
84799 + * gcc plugin to implement various sparse (source code checker) features
84800 + *
84801 + * TODO:
84802 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
84803 + *
84804 + * BUGS:
84805 + * - none known
84806 + */
84807 +#include "gcc-plugin.h"
84808 +#include "config.h"
84809 +#include "system.h"
84810 +#include "coretypes.h"
84811 +#include "tree.h"
84812 +#include "tree-pass.h"
84813 +#include "flags.h"
84814 +#include "intl.h"
84815 +#include "toplev.h"
84816 +#include "plugin.h"
84817 +//#include "expr.h" where are you...
84818 +#include "diagnostic.h"
84819 +#include "plugin-version.h"
84820 +#include "tm.h"
84821 +#include "function.h"
84822 +#include "basic-block.h"
84823 +#include "gimple.h"
84824 +#include "rtl.h"
84825 +#include "emit-rtl.h"
84826 +#include "tree-flow.h"
84827 +#include "target.h"
84828 +
84829 +extern void c_register_addr_space (const char *str, addr_space_t as);
84830 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
84831 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
84832 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
84833 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
84834 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
84835 +
84836 +extern void print_gimple_stmt(FILE *, gimple, int, int);
84837 +extern rtx emit_move_insn(rtx x, rtx y);
84838 +
84839 +int plugin_is_GPL_compatible;
84840 +
84841 +static struct plugin_info checker_plugin_info = {
84842 + .version = "201111150100",
84843 +};
84844 +
84845 +#define ADDR_SPACE_KERNEL 0
84846 +#define ADDR_SPACE_FORCE_KERNEL 1
84847 +#define ADDR_SPACE_USER 2
84848 +#define ADDR_SPACE_FORCE_USER 3
84849 +#define ADDR_SPACE_IOMEM 0
84850 +#define ADDR_SPACE_FORCE_IOMEM 0
84851 +#define ADDR_SPACE_PERCPU 0
84852 +#define ADDR_SPACE_FORCE_PERCPU 0
84853 +#define ADDR_SPACE_RCU 0
84854 +#define ADDR_SPACE_FORCE_RCU 0
84855 +
84856 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
84857 +{
84858 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
84859 +}
84860 +
84861 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
84862 +{
84863 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
84864 +}
84865 +
84866 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
84867 +{
84868 + return default_addr_space_valid_pointer_mode(mode, as);
84869 +}
84870 +
84871 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
84872 +{
84873 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
84874 +}
84875 +
84876 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
84877 +{
84878 + return default_addr_space_legitimize_address(x, oldx, mode, as);
84879 +}
84880 +
84881 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
84882 +{
84883 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
84884 + return true;
84885 +
84886 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
84887 + return true;
84888 +
84889 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
84890 + return true;
84891 +
84892 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
84893 + return true;
84894 +
84895 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
84896 + return true;
84897 +
84898 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
84899 + return true;
84900 +
84901 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
84902 + return true;
84903 +
84904 + return subset == superset;
84905 +}
84906 +
84907 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
84908 +{
84909 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
84910 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
84911 +
84912 + return op;
84913 +}
84914 +
84915 +static void register_checker_address_spaces(void *event_data, void *data)
84916 +{
84917 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
84918 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
84919 + c_register_addr_space("__user", ADDR_SPACE_USER);
84920 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
84921 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
84922 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
84923 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
84924 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
84925 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
84926 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
84927 +
84928 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
84929 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
84930 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
84931 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
84932 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
84933 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
84934 + targetm.addr_space.convert = checker_addr_space_convert;
84935 +}
84936 +
84937 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84938 +{
84939 + const char * const plugin_name = plugin_info->base_name;
84940 + const int argc = plugin_info->argc;
84941 + const struct plugin_argument * const argv = plugin_info->argv;
84942 + int i;
84943 +
84944 + if (!plugin_default_version_check(version, &gcc_version)) {
84945 + error(G_("incompatible gcc/plugin versions"));
84946 + return 1;
84947 + }
84948 +
84949 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
84950 +
84951 + for (i = 0; i < argc; ++i)
84952 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
84953 +
84954 + if (TARGET_64BIT == 0)
84955 + return 0;
84956 +
84957 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
84958 +
84959 + return 0;
84960 +}
84961 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
84962 new file mode 100644
84963 index 0000000..414fe5e
84964 --- /dev/null
84965 +++ b/tools/gcc/colorize_plugin.c
84966 @@ -0,0 +1,151 @@
84967 +/*
84968 + * Copyright 2012-2013 by PaX Team <pageexec@freemail.hu>
84969 + * Licensed under the GPL v2
84970 + *
84971 + * Note: the choice of the license means that the compilation process is
84972 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
84973 + * but for the kernel it doesn't matter since it doesn't link against
84974 + * any of the gcc libraries
84975 + *
84976 + * gcc plugin to colorize diagnostic output
84977 + *
84978 + */
84979 +
84980 +#include "gcc-plugin.h"
84981 +#include "config.h"
84982 +#include "system.h"
84983 +#include "coretypes.h"
84984 +#include "tree.h"
84985 +#include "tree-pass.h"
84986 +#include "flags.h"
84987 +#include "intl.h"
84988 +#include "toplev.h"
84989 +#include "plugin.h"
84990 +#include "diagnostic.h"
84991 +#include "plugin-version.h"
84992 +#include "tm.h"
84993 +
84994 +int plugin_is_GPL_compatible;
84995 +
84996 +static struct plugin_info colorize_plugin_info = {
84997 + .version = "201302112000",
84998 + .help = NULL,
84999 +};
85000 +
85001 +#define GREEN "\033[32m\033[2m"
85002 +#define LIGHTGREEN "\033[32m\033[1m"
85003 +#define YELLOW "\033[33m\033[2m"
85004 +#define LIGHTYELLOW "\033[33m\033[1m"
85005 +#define RED "\033[31m\033[2m"
85006 +#define LIGHTRED "\033[31m\033[1m"
85007 +#define BLUE "\033[34m\033[2m"
85008 +#define LIGHTBLUE "\033[34m\033[1m"
85009 +#define BRIGHT "\033[m\033[1m"
85010 +#define NORMAL "\033[m"
85011 +
85012 +static diagnostic_starter_fn old_starter;
85013 +static diagnostic_finalizer_fn old_finalizer;
85014 +
85015 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
85016 +{
85017 + const char *color;
85018 + char *newprefix;
85019 +
85020 + switch (diagnostic->kind) {
85021 + case DK_NOTE:
85022 + color = LIGHTBLUE;
85023 + break;
85024 +
85025 + case DK_PEDWARN:
85026 + case DK_WARNING:
85027 + color = LIGHTYELLOW;
85028 + break;
85029 +
85030 + case DK_ERROR:
85031 + case DK_FATAL:
85032 + case DK_ICE:
85033 + case DK_PERMERROR:
85034 + case DK_SORRY:
85035 + color = LIGHTRED;
85036 + break;
85037 +
85038 + default:
85039 + color = NORMAL;
85040 + }
85041 +
85042 + old_starter(context, diagnostic);
85043 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
85044 + return;
85045 + pp_destroy_prefix(context->printer);
85046 + pp_set_prefix(context->printer, newprefix);
85047 +}
85048 +
85049 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
85050 +{
85051 + old_finalizer(context, diagnostic);
85052 +}
85053 +
85054 +static void colorize_arm(void)
85055 +{
85056 + old_starter = diagnostic_starter(global_dc);
85057 + old_finalizer = diagnostic_finalizer(global_dc);
85058 +
85059 + diagnostic_starter(global_dc) = start_colorize;
85060 + diagnostic_finalizer(global_dc) = finalize_colorize;
85061 +}
85062 +
85063 +static unsigned int execute_colorize_rearm(void)
85064 +{
85065 + if (diagnostic_starter(global_dc) == start_colorize)
85066 + return 0;
85067 +
85068 + colorize_arm();
85069 + return 0;
85070 +}
85071 +
85072 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
85073 + .pass = {
85074 + .type = SIMPLE_IPA_PASS,
85075 + .name = "colorize_rearm",
85076 +#if BUILDING_GCC_VERSION >= 4008
85077 + .optinfo_flags = OPTGROUP_NONE,
85078 +#endif
85079 + .gate = NULL,
85080 + .execute = execute_colorize_rearm,
85081 + .sub = NULL,
85082 + .next = NULL,
85083 + .static_pass_number = 0,
85084 + .tv_id = TV_NONE,
85085 + .properties_required = 0,
85086 + .properties_provided = 0,
85087 + .properties_destroyed = 0,
85088 + .todo_flags_start = 0,
85089 + .todo_flags_finish = 0
85090 + }
85091 +};
85092 +
85093 +static void colorize_start_unit(void *gcc_data, void *user_data)
85094 +{
85095 + colorize_arm();
85096 +}
85097 +
85098 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85099 +{
85100 + const char * const plugin_name = plugin_info->base_name;
85101 + struct register_pass_info colorize_rearm_pass_info = {
85102 + .pass = &pass_ipa_colorize_rearm.pass,
85103 + .reference_pass_name = "*free_lang_data",
85104 + .ref_pass_instance_number = 1,
85105 + .pos_op = PASS_POS_INSERT_AFTER
85106 + };
85107 +
85108 + if (!plugin_default_version_check(version, &gcc_version)) {
85109 + error(G_("incompatible gcc/plugin versions"));
85110 + return 1;
85111 + }
85112 +
85113 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
85114 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
85115 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
85116 + return 0;
85117 +}
85118 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
85119 new file mode 100644
85120 index 0000000..c415c9d
85121 --- /dev/null
85122 +++ b/tools/gcc/constify_plugin.c
85123 @@ -0,0 +1,359 @@
85124 +/*
85125 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
85126 + * Copyright 2011-2013 by PaX Team <pageexec@freemail.hu>
85127 + * Licensed under the GPL v2, or (at your option) v3
85128 + *
85129 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
85130 + *
85131 + * Homepage:
85132 + * http://www.grsecurity.net/~ephox/const_plugin/
85133 + *
85134 + * Usage:
85135 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
85136 + * $ gcc -fplugin=constify_plugin.so test.c -O2
85137 + */
85138 +
85139 +#include "gcc-plugin.h"
85140 +#include "config.h"
85141 +#include "system.h"
85142 +#include "coretypes.h"
85143 +#include "tree.h"
85144 +#include "tree-pass.h"
85145 +#include "flags.h"
85146 +#include "intl.h"
85147 +#include "toplev.h"
85148 +#include "plugin.h"
85149 +#include "diagnostic.h"
85150 +#include "plugin-version.h"
85151 +#include "tm.h"
85152 +#include "function.h"
85153 +#include "basic-block.h"
85154 +#include "gimple.h"
85155 +#include "rtl.h"
85156 +#include "emit-rtl.h"
85157 +#include "tree-flow.h"
85158 +
85159 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
85160 +
85161 +int plugin_is_GPL_compatible;
85162 +
85163 +static struct plugin_info const_plugin_info = {
85164 + .version = "201302112000",
85165 + .help = "no-constify\tturn off constification\n",
85166 +};
85167 +
85168 +static tree get_field_type(tree field)
85169 +{
85170 + return strip_array_types(TREE_TYPE(field));
85171 +}
85172 +
85173 +static bool walk_struct(tree node);
85174 +static void deconstify_tree(tree node);
85175 +
85176 +static void deconstify_type(tree type)
85177 +{
85178 + tree field;
85179 +
85180 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
85181 + tree fieldtype = get_field_type(field);
85182 +
85183 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
85184 + continue;
85185 + if (!TYPE_READONLY(fieldtype))
85186 + continue;
85187 + if (!walk_struct(fieldtype))
85188 + continue;
85189 +
85190 + deconstify_tree(field);
85191 + TREE_READONLY(field) = 0;
85192 + }
85193 + TYPE_READONLY(type) = 0;
85194 + C_TYPE_FIELDS_READONLY(type) = 0;
85195 +}
85196 +
85197 +static void deconstify_tree(tree node)
85198 +{
85199 + tree old_type, new_type, field;
85200 +
85201 +// TREE_READONLY(node) = 0;
85202 + old_type = TREE_TYPE(node);
85203 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
85204 + node = old_type;
85205 + old_type = TREE_TYPE(old_type);
85206 + }
85207 +
85208 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
85209 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
85210 +
85211 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
85212 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
85213 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
85214 + DECL_FIELD_CONTEXT(field) = new_type;
85215 +
85216 + deconstify_type(new_type);
85217 +
85218 + TREE_TYPE(node) = new_type;
85219 +}
85220 +
85221 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
85222 +{
85223 + tree type;
85224 +
85225 + *no_add_attrs = true;
85226 + if (TREE_CODE(*node) == FUNCTION_DECL) {
85227 + error("%qE attribute does not apply to functions", name);
85228 + return NULL_TREE;
85229 + }
85230 +
85231 + if (TREE_CODE(*node) == VAR_DECL) {
85232 + error("%qE attribute does not apply to variables", name);
85233 + return NULL_TREE;
85234 + }
85235 +
85236 + if (TYPE_P(*node)) {
85237 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
85238 + *no_add_attrs = false;
85239 + else
85240 + error("%qE attribute applies to struct and union types only", name);
85241 + return NULL_TREE;
85242 + }
85243 +
85244 + type = TREE_TYPE(*node);
85245 +
85246 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
85247 + error("%qE attribute applies to struct and union types only", name);
85248 + return NULL_TREE;
85249 + }
85250 +
85251 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
85252 + error("%qE attribute is already applied to the type", name);
85253 + return NULL_TREE;
85254 + }
85255 +
85256 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
85257 + error("%qE attribute used on type that is not constified", name);
85258 + return NULL_TREE;
85259 + }
85260 +
85261 + if (TREE_CODE(*node) == TYPE_DECL) {
85262 + deconstify_tree(*node);
85263 + return NULL_TREE;
85264 + }
85265 +
85266 + return NULL_TREE;
85267 +}
85268 +
85269 +static void constify_type(tree type)
85270 +{
85271 + TYPE_READONLY(type) = 1;
85272 + C_TYPE_FIELDS_READONLY(type) = 1;
85273 +}
85274 +
85275 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
85276 +{
85277 + *no_add_attrs = true;
85278 + if (!TYPE_P(*node)) {
85279 + error("%qE attribute applies to types only", name);
85280 + return NULL_TREE;
85281 + }
85282 +
85283 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
85284 + error("%qE attribute applies to struct and union types only", name);
85285 + return NULL_TREE;
85286 + }
85287 +
85288 + *no_add_attrs = false;
85289 + constify_type(*node);
85290 + return NULL_TREE;
85291 +}
85292 +
85293 +static struct attribute_spec no_const_attr = {
85294 + .name = "no_const",
85295 + .min_length = 0,
85296 + .max_length = 0,
85297 + .decl_required = false,
85298 + .type_required = false,
85299 + .function_type_required = false,
85300 + .handler = handle_no_const_attribute,
85301 +#if BUILDING_GCC_VERSION >= 4007
85302 + .affects_type_identity = true
85303 +#endif
85304 +};
85305 +
85306 +static struct attribute_spec do_const_attr = {
85307 + .name = "do_const",
85308 + .min_length = 0,
85309 + .max_length = 0,
85310 + .decl_required = false,
85311 + .type_required = false,
85312 + .function_type_required = false,
85313 + .handler = handle_do_const_attribute,
85314 +#if BUILDING_GCC_VERSION >= 4007
85315 + .affects_type_identity = true
85316 +#endif
85317 +};
85318 +
85319 +static void register_attributes(void *event_data, void *data)
85320 +{
85321 + register_attribute(&no_const_attr);
85322 + register_attribute(&do_const_attr);
85323 +}
85324 +
85325 +static bool is_fptr(tree field)
85326 +{
85327 + tree ptr = get_field_type(field);
85328 +
85329 + if (TREE_CODE(ptr) != POINTER_TYPE)
85330 + return false;
85331 +
85332 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
85333 +}
85334 +
85335 +static bool walk_struct(tree node)
85336 +{
85337 + tree field;
85338 +
85339 + if (TYPE_FIELDS(node) == NULL_TREE)
85340 + return false;
85341 +
85342 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node)))
85343 + return true;
85344 +
85345 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
85346 + gcc_assert(!TYPE_READONLY(node));
85347 + deconstify_type(node);
85348 + return false;
85349 + }
85350 +
85351 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
85352 + tree type = get_field_type(field);
85353 + enum tree_code code = TREE_CODE(type);
85354 +
85355 + if (node == type)
85356 + return false;
85357 + if (code == RECORD_TYPE || code == UNION_TYPE) {
85358 + if (!(walk_struct(type)))
85359 + return false;
85360 + } else if (!is_fptr(field) && !TREE_READONLY(field))
85361 + return false;
85362 + }
85363 + return true;
85364 +}
85365 +
85366 +static void finish_type(void *event_data, void *data)
85367 +{
85368 + tree type = (tree)event_data;
85369 +
85370 + if (type == NULL_TREE || type == error_mark_node)
85371 + return;
85372 +
85373 + if (TYPE_READONLY(type))
85374 + return;
85375 +
85376 + if (walk_struct(type))
85377 + constify_type(type);
85378 + else
85379 + deconstify_type(type);
85380 +}
85381 +
85382 +static unsigned int check_local_variables(void)
85383 +{
85384 + unsigned int ret = 0;
85385 + tree var;
85386 +
85387 +#if BUILDING_GCC_VERSION == 4005
85388 + tree vars;
85389 +#else
85390 + unsigned int i;
85391 +#endif
85392 +
85393 +#if BUILDING_GCC_VERSION == 4005
85394 + for (vars = cfun->local_decls; vars; vars = TREE_CHAIN(vars)) {
85395 + var = TREE_VALUE(vars);
85396 +#else
85397 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
85398 +#endif
85399 + tree type = TREE_TYPE(var);
85400 +
85401 + gcc_assert(DECL_P(var));
85402 + if (is_global_var(var))
85403 + continue;
85404 +
85405 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
85406 + continue;
85407 +
85408 + if (!TYPE_READONLY(type))
85409 + continue;
85410 +
85411 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
85412 +// continue;
85413 +
85414 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
85415 + continue;
85416 +
85417 + if (walk_struct(type)) {
85418 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
85419 + ret = 1;
85420 + }
85421 + }
85422 + return ret;
85423 +}
85424 +
85425 +struct gimple_opt_pass pass_local_variable = {
85426 + {
85427 + .type = GIMPLE_PASS,
85428 + .name = "check_local_variables",
85429 +#if BUILDING_GCC_VERSION >= 4008
85430 + .optinfo_flags = OPTGROUP_NONE,
85431 +#endif
85432 + .gate = NULL,
85433 + .execute = check_local_variables,
85434 + .sub = NULL,
85435 + .next = NULL,
85436 + .static_pass_number = 0,
85437 + .tv_id = TV_NONE,
85438 + .properties_required = 0,
85439 + .properties_provided = 0,
85440 + .properties_destroyed = 0,
85441 + .todo_flags_start = 0,
85442 + .todo_flags_finish = 0
85443 + }
85444 +};
85445 +
85446 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85447 +{
85448 + const char * const plugin_name = plugin_info->base_name;
85449 + const int argc = plugin_info->argc;
85450 + const struct plugin_argument * const argv = plugin_info->argv;
85451 + int i;
85452 + bool constify = true;
85453 +
85454 + struct register_pass_info local_variable_pass_info = {
85455 + .pass = &pass_local_variable.pass,
85456 + .reference_pass_name = "ssa",
85457 + .ref_pass_instance_number = 1,
85458 + .pos_op = PASS_POS_INSERT_BEFORE
85459 + };
85460 +
85461 + if (!plugin_default_version_check(version, &gcc_version)) {
85462 + error(G_("incompatible gcc/plugin versions"));
85463 + return 1;
85464 + }
85465 +
85466 + for (i = 0; i < argc; ++i) {
85467 + if (!(strcmp(argv[i].key, "no-constify"))) {
85468 + constify = false;
85469 + continue;
85470 + }
85471 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
85472 + }
85473 +
85474 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
85475 + if (constify) {
85476 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
85477 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
85478 + }
85479 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
85480 +
85481 + return 0;
85482 +}
85483 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
85484 new file mode 100644
85485 index 0000000..e518932
85486 --- /dev/null
85487 +++ b/tools/gcc/generate_size_overflow_hash.sh
85488 @@ -0,0 +1,94 @@
85489 +#!/bin/bash
85490 +
85491 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
85492 +
85493 +header1="size_overflow_hash.h"
85494 +database="size_overflow_hash.data"
85495 +n=65536
85496 +
85497 +usage() {
85498 +cat <<EOF
85499 +usage: $0 options
85500 +OPTIONS:
85501 + -h|--help help
85502 + -o header file
85503 + -d database file
85504 + -n hash array size
85505 +EOF
85506 + return 0
85507 +}
85508 +
85509 +while true
85510 +do
85511 + case "$1" in
85512 + -h|--help) usage && exit 0;;
85513 + -n) n=$2; shift 2;;
85514 + -o) header1="$2"; shift 2;;
85515 + -d) database="$2"; shift 2;;
85516 + --) shift 1; break ;;
85517 + *) break ;;
85518 + esac
85519 +done
85520 +
85521 +create_defines() {
85522 + for i in `seq 0 31`
85523 + do
85524 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
85525 + done
85526 + echo >> "$header1"
85527 +}
85528 +
85529 +create_structs() {
85530 + rm -f "$header1"
85531 +
85532 + create_defines
85533 +
85534 + cat "$database" | while read data
85535 + do
85536 + data_array=($data)
85537 + struct_hash_name="${data_array[0]}"
85538 + funcn="${data_array[1]}"
85539 + params="${data_array[2]}"
85540 + next="${data_array[4]}"
85541 +
85542 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
85543 +
85544 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
85545 + echo -en "\t.param\t= " >> "$header1"
85546 + line=
85547 + for param_num in ${params//-/ };
85548 + do
85549 + line="${line}PARAM"$param_num"|"
85550 + done
85551 +
85552 + echo -e "${line%?},\n};\n" >> "$header1"
85553 + done
85554 +}
85555 +
85556 +create_headers() {
85557 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
85558 +}
85559 +
85560 +create_array_elements() {
85561 + index=0
85562 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
85563 + do
85564 + data_array=($data)
85565 + i="${data_array[3]}"
85566 + hash="${data_array[0]}"
85567 + while [[ $index -lt $i ]]
85568 + do
85569 + echo -e "\t["$index"]\t= NULL," >> "$header1"
85570 + index=$(($index + 1))
85571 + done
85572 + index=$(($index + 1))
85573 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
85574 + done
85575 + echo '};' >> $header1
85576 +}
85577 +
85578 +create_structs
85579 +create_headers
85580 +create_array_elements
85581 +
85582 +exit 0
85583 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
85584 new file mode 100644
85585 index 0000000..568b360
85586 --- /dev/null
85587 +++ b/tools/gcc/kallocstat_plugin.c
85588 @@ -0,0 +1,170 @@
85589 +/*
85590 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
85591 + * Licensed under the GPL v2
85592 + *
85593 + * Note: the choice of the license means that the compilation process is
85594 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85595 + * but for the kernel it doesn't matter since it doesn't link against
85596 + * any of the gcc libraries
85597 + *
85598 + * gcc plugin to find the distribution of k*alloc sizes
85599 + *
85600 + * TODO:
85601 + *
85602 + * BUGS:
85603 + * - none known
85604 + */
85605 +#include "gcc-plugin.h"
85606 +#include "config.h"
85607 +#include "system.h"
85608 +#include "coretypes.h"
85609 +#include "tree.h"
85610 +#include "tree-pass.h"
85611 +#include "flags.h"
85612 +#include "intl.h"
85613 +#include "toplev.h"
85614 +#include "plugin.h"
85615 +//#include "expr.h" where are you...
85616 +#include "diagnostic.h"
85617 +#include "plugin-version.h"
85618 +#include "tm.h"
85619 +#include "function.h"
85620 +#include "basic-block.h"
85621 +#include "gimple.h"
85622 +#include "rtl.h"
85623 +#include "emit-rtl.h"
85624 +
85625 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85626 +
85627 +int plugin_is_GPL_compatible;
85628 +
85629 +static const char * const kalloc_functions[] = {
85630 + "__kmalloc",
85631 + "kmalloc",
85632 + "kmalloc_large",
85633 + "kmalloc_node",
85634 + "kmalloc_order",
85635 + "kmalloc_order_trace",
85636 + "kmalloc_slab",
85637 + "kzalloc",
85638 + "kzalloc_node",
85639 +};
85640 +
85641 +static struct plugin_info kallocstat_plugin_info = {
85642 + .version = "201302112000",
85643 +};
85644 +
85645 +static unsigned int execute_kallocstat(void);
85646 +
85647 +static struct gimple_opt_pass kallocstat_pass = {
85648 + .pass = {
85649 + .type = GIMPLE_PASS,
85650 + .name = "kallocstat",
85651 +#if BUILDING_GCC_VERSION >= 4008
85652 + .optinfo_flags = OPTGROUP_NONE,
85653 +#endif
85654 + .gate = NULL,
85655 + .execute = execute_kallocstat,
85656 + .sub = NULL,
85657 + .next = NULL,
85658 + .static_pass_number = 0,
85659 + .tv_id = TV_NONE,
85660 + .properties_required = 0,
85661 + .properties_provided = 0,
85662 + .properties_destroyed = 0,
85663 + .todo_flags_start = 0,
85664 + .todo_flags_finish = 0
85665 + }
85666 +};
85667 +
85668 +static bool is_kalloc(const char *fnname)
85669 +{
85670 + size_t i;
85671 +
85672 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
85673 + if (!strcmp(fnname, kalloc_functions[i]))
85674 + return true;
85675 + return false;
85676 +}
85677 +
85678 +static unsigned int execute_kallocstat(void)
85679 +{
85680 + basic_block bb;
85681 +
85682 + // 1. loop through BBs and GIMPLE statements
85683 + FOR_EACH_BB(bb) {
85684 + gimple_stmt_iterator gsi;
85685 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85686 + // gimple match:
85687 + tree fndecl, size;
85688 + gimple call_stmt;
85689 + const char *fnname;
85690 +
85691 + // is it a call
85692 + call_stmt = gsi_stmt(gsi);
85693 + if (!is_gimple_call(call_stmt))
85694 + continue;
85695 + fndecl = gimple_call_fndecl(call_stmt);
85696 + if (fndecl == NULL_TREE)
85697 + continue;
85698 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
85699 + continue;
85700 +
85701 + // is it a call to k*alloc
85702 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
85703 + if (!is_kalloc(fnname))
85704 + continue;
85705 +
85706 + // is the size arg the result of a simple const assignment
85707 + size = gimple_call_arg(call_stmt, 0);
85708 + while (true) {
85709 + gimple def_stmt;
85710 + expanded_location xloc;
85711 + size_t size_val;
85712 +
85713 + if (TREE_CODE(size) != SSA_NAME)
85714 + break;
85715 + def_stmt = SSA_NAME_DEF_STMT(size);
85716 + if (!def_stmt || !is_gimple_assign(def_stmt))
85717 + break;
85718 + if (gimple_num_ops(def_stmt) != 2)
85719 + break;
85720 + size = gimple_assign_rhs1(def_stmt);
85721 + if (!TREE_CONSTANT(size))
85722 + continue;
85723 + xloc = expand_location(gimple_location(def_stmt));
85724 + if (!xloc.file)
85725 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
85726 + size_val = TREE_INT_CST_LOW(size);
85727 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
85728 + break;
85729 + }
85730 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
85731 +//debug_tree(gimple_call_fn(call_stmt));
85732 +//print_node(stderr, "pax", fndecl, 4);
85733 + }
85734 + }
85735 +
85736 + return 0;
85737 +}
85738 +
85739 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
85740 +{
85741 + const char * const plugin_name = plugin_info->base_name;
85742 + struct register_pass_info kallocstat_pass_info = {
85743 + .pass = &kallocstat_pass.pass,
85744 + .reference_pass_name = "ssa",
85745 + .ref_pass_instance_number = 1,
85746 + .pos_op = PASS_POS_INSERT_AFTER
85747 + };
85748 +
85749 + if (!plugin_default_version_check(version, &gcc_version)) {
85750 + error(G_("incompatible gcc/plugin versions"));
85751 + return 1;
85752 + }
85753 +
85754 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
85755 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
85756 +
85757 + return 0;
85758 +}
85759 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
85760 new file mode 100644
85761 index 0000000..0408e06
85762 --- /dev/null
85763 +++ b/tools/gcc/kernexec_plugin.c
85764 @@ -0,0 +1,465 @@
85765 +/*
85766 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
85767 + * Licensed under the GPL v2
85768 + *
85769 + * Note: the choice of the license means that the compilation process is
85770 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
85771 + * but for the kernel it doesn't matter since it doesn't link against
85772 + * any of the gcc libraries
85773 + *
85774 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
85775 + *
85776 + * TODO:
85777 + *
85778 + * BUGS:
85779 + * - none known
85780 + */
85781 +#include "gcc-plugin.h"
85782 +#include "config.h"
85783 +#include "system.h"
85784 +#include "coretypes.h"
85785 +#include "tree.h"
85786 +#include "tree-pass.h"
85787 +#include "flags.h"
85788 +#include "intl.h"
85789 +#include "toplev.h"
85790 +#include "plugin.h"
85791 +//#include "expr.h" where are you...
85792 +#include "diagnostic.h"
85793 +#include "plugin-version.h"
85794 +#include "tm.h"
85795 +#include "function.h"
85796 +#include "basic-block.h"
85797 +#include "gimple.h"
85798 +#include "rtl.h"
85799 +#include "emit-rtl.h"
85800 +#include "tree-flow.h"
85801 +
85802 +extern void print_gimple_stmt(FILE *, gimple, int, int);
85803 +extern rtx emit_move_insn(rtx x, rtx y);
85804 +
85805 +#if BUILDING_GCC_VERSION <= 4006
85806 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
85807 +#endif
85808 +
85809 +#if BUILDING_GCC_VERSION >= 4008
85810 +#define TODO_dump_func 0
85811 +#endif
85812 +
85813 +int plugin_is_GPL_compatible;
85814 +
85815 +static struct plugin_info kernexec_plugin_info = {
85816 + .version = "201302112000",
85817 + .help = "method=[bts|or]\tinstrumentation method\n"
85818 +};
85819 +
85820 +static unsigned int execute_kernexec_reload(void);
85821 +static unsigned int execute_kernexec_fptr(void);
85822 +static unsigned int execute_kernexec_retaddr(void);
85823 +static bool kernexec_cmodel_check(void);
85824 +
85825 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
85826 +static void (*kernexec_instrument_retaddr)(rtx);
85827 +
85828 +static struct gimple_opt_pass kernexec_reload_pass = {
85829 + .pass = {
85830 + .type = GIMPLE_PASS,
85831 + .name = "kernexec_reload",
85832 +#if BUILDING_GCC_VERSION >= 4008
85833 + .optinfo_flags = OPTGROUP_NONE,
85834 +#endif
85835 + .gate = kernexec_cmodel_check,
85836 + .execute = execute_kernexec_reload,
85837 + .sub = NULL,
85838 + .next = NULL,
85839 + .static_pass_number = 0,
85840 + .tv_id = TV_NONE,
85841 + .properties_required = 0,
85842 + .properties_provided = 0,
85843 + .properties_destroyed = 0,
85844 + .todo_flags_start = 0,
85845 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
85846 + }
85847 +};
85848 +
85849 +static struct gimple_opt_pass kernexec_fptr_pass = {
85850 + .pass = {
85851 + .type = GIMPLE_PASS,
85852 + .name = "kernexec_fptr",
85853 +#if BUILDING_GCC_VERSION >= 4008
85854 + .optinfo_flags = OPTGROUP_NONE,
85855 +#endif
85856 + .gate = kernexec_cmodel_check,
85857 + .execute = execute_kernexec_fptr,
85858 + .sub = NULL,
85859 + .next = NULL,
85860 + .static_pass_number = 0,
85861 + .tv_id = TV_NONE,
85862 + .properties_required = 0,
85863 + .properties_provided = 0,
85864 + .properties_destroyed = 0,
85865 + .todo_flags_start = 0,
85866 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
85867 + }
85868 +};
85869 +
85870 +static struct rtl_opt_pass kernexec_retaddr_pass = {
85871 + .pass = {
85872 + .type = RTL_PASS,
85873 + .name = "kernexec_retaddr",
85874 +#if BUILDING_GCC_VERSION >= 4008
85875 + .optinfo_flags = OPTGROUP_NONE,
85876 +#endif
85877 + .gate = kernexec_cmodel_check,
85878 + .execute = execute_kernexec_retaddr,
85879 + .sub = NULL,
85880 + .next = NULL,
85881 + .static_pass_number = 0,
85882 + .tv_id = TV_NONE,
85883 + .properties_required = 0,
85884 + .properties_provided = 0,
85885 + .properties_destroyed = 0,
85886 + .todo_flags_start = 0,
85887 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
85888 + }
85889 +};
85890 +
85891 +static bool kernexec_cmodel_check(void)
85892 +{
85893 + tree section;
85894 +
85895 + if (ix86_cmodel != CM_KERNEL)
85896 + return false;
85897 +
85898 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
85899 + if (!section || !TREE_VALUE(section))
85900 + return true;
85901 +
85902 + section = TREE_VALUE(TREE_VALUE(section));
85903 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
85904 + return true;
85905 +
85906 + return false;
85907 +}
85908 +
85909 +/*
85910 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
85911 + */
85912 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
85913 +{
85914 + gimple asm_movabs_stmt;
85915 +
85916 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
85917 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
85918 + gimple_asm_set_volatile(asm_movabs_stmt, true);
85919 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
85920 + update_stmt(asm_movabs_stmt);
85921 +}
85922 +
85923 +/*
85924 + * find all asm() stmts that clobber r10 and add a reload of r10
85925 + */
85926 +static unsigned int execute_kernexec_reload(void)
85927 +{
85928 + basic_block bb;
85929 +
85930 + // 1. loop through BBs and GIMPLE statements
85931 + FOR_EACH_BB(bb) {
85932 + gimple_stmt_iterator gsi;
85933 +
85934 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
85935 + // gimple match: __asm__ ("" : : : "r10");
85936 + gimple asm_stmt;
85937 + size_t nclobbers;
85938 +
85939 + // is it an asm ...
85940 + asm_stmt = gsi_stmt(gsi);
85941 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
85942 + continue;
85943 +
85944 + // ... clobbering r10
85945 + nclobbers = gimple_asm_nclobbers(asm_stmt);
85946 + while (nclobbers--) {
85947 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
85948 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
85949 + continue;
85950 + kernexec_reload_fptr_mask(&gsi);
85951 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
85952 + break;
85953 + }
85954 + }
85955 + }
85956 +
85957 + return 0;
85958 +}
85959 +
85960 +/*
85961 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
85962 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
85963 + */
85964 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
85965 +{
85966 + gimple assign_intptr, assign_new_fptr, call_stmt;
85967 + tree intptr, old_fptr, new_fptr, kernexec_mask;
85968 +
85969 + call_stmt = gsi_stmt(*gsi);
85970 + old_fptr = gimple_call_fn(call_stmt);
85971 +
85972 + // create temporary unsigned long variable used for bitops and cast fptr to it
85973 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
85974 +#if BUILDING_GCC_VERSION <= 4007
85975 + add_referenced_var(intptr);
85976 + mark_sym_for_renaming(intptr);
85977 +#endif
85978 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
85979 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
85980 + update_stmt(assign_intptr);
85981 +
85982 + // apply logical or to temporary unsigned long and bitmask
85983 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
85984 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
85985 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
85986 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
85987 + update_stmt(assign_intptr);
85988 +
85989 + // cast temporary unsigned long back to a temporary fptr variable
85990 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
85991 +#if BUILDING_GCC_VERSION <= 4007
85992 + add_referenced_var(new_fptr);
85993 + mark_sym_for_renaming(new_fptr);
85994 +#endif
85995 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
85996 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
85997 + update_stmt(assign_new_fptr);
85998 +
85999 + // replace call stmt fn with the new fptr
86000 + gimple_call_set_fn(call_stmt, new_fptr);
86001 + update_stmt(call_stmt);
86002 +}
86003 +
86004 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
86005 +{
86006 + gimple asm_or_stmt, call_stmt;
86007 + tree old_fptr, new_fptr, input, output;
86008 +#if BUILDING_GCC_VERSION <= 4007
86009 + VEC(tree, gc) *inputs = NULL;
86010 + VEC(tree, gc) *outputs = NULL;
86011 +#else
86012 + vec<tree, va_gc> *inputs = NULL;
86013 + vec<tree, va_gc> *outputs = NULL;
86014 +#endif
86015 +
86016 + call_stmt = gsi_stmt(*gsi);
86017 + old_fptr = gimple_call_fn(call_stmt);
86018 +
86019 + // create temporary fptr variable
86020 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
86021 +#if BUILDING_GCC_VERSION <= 4007
86022 + add_referenced_var(new_fptr);
86023 + mark_sym_for_renaming(new_fptr);
86024 +#endif
86025 +
86026 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
86027 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
86028 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
86029 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
86030 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
86031 +#if BUILDING_GCC_VERSION <= 4007
86032 + VEC_safe_push(tree, gc, inputs, input);
86033 + VEC_safe_push(tree, gc, outputs, output);
86034 +#else
86035 + vec_safe_push(inputs, input);
86036 + vec_safe_push(outputs, output);
86037 +#endif
86038 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
86039 + gimple_asm_set_volatile(asm_or_stmt, true);
86040 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
86041 + update_stmt(asm_or_stmt);
86042 +
86043 + // replace call stmt fn with the new fptr
86044 + gimple_call_set_fn(call_stmt, new_fptr);
86045 + update_stmt(call_stmt);
86046 +}
86047 +
86048 +/*
86049 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
86050 + */
86051 +static unsigned int execute_kernexec_fptr(void)
86052 +{
86053 + basic_block bb;
86054 +
86055 + // 1. loop through BBs and GIMPLE statements
86056 + FOR_EACH_BB(bb) {
86057 + gimple_stmt_iterator gsi;
86058 +
86059 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86060 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
86061 + tree fn;
86062 + gimple call_stmt;
86063 +
86064 + // is it a call ...
86065 + call_stmt = gsi_stmt(gsi);
86066 + if (!is_gimple_call(call_stmt))
86067 + continue;
86068 + fn = gimple_call_fn(call_stmt);
86069 + if (TREE_CODE(fn) == ADDR_EXPR)
86070 + continue;
86071 + if (TREE_CODE(fn) != SSA_NAME)
86072 + gcc_unreachable();
86073 +
86074 + // ... through a function pointer
86075 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
86076 + fn = SSA_NAME_VAR(fn);
86077 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
86078 + debug_tree(fn);
86079 + gcc_unreachable();
86080 + }
86081 + }
86082 + fn = TREE_TYPE(fn);
86083 + if (TREE_CODE(fn) != POINTER_TYPE)
86084 + continue;
86085 + fn = TREE_TYPE(fn);
86086 + if (TREE_CODE(fn) != FUNCTION_TYPE)
86087 + continue;
86088 +
86089 + kernexec_instrument_fptr(&gsi);
86090 +
86091 +//debug_tree(gimple_call_fn(call_stmt));
86092 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
86093 + }
86094 + }
86095 +
86096 + return 0;
86097 +}
86098 +
86099 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
86100 +static void kernexec_instrument_retaddr_bts(rtx insn)
86101 +{
86102 + rtx btsq;
86103 + rtvec argvec, constraintvec, labelvec;
86104 + int line;
86105 +
86106 + // create asm volatile("btsq $63,(%%rsp)":::)
86107 + argvec = rtvec_alloc(0);
86108 + constraintvec = rtvec_alloc(0);
86109 + labelvec = rtvec_alloc(0);
86110 + line = expand_location(RTL_LOCATION(insn)).line;
86111 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
86112 + MEM_VOLATILE_P(btsq) = 1;
86113 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
86114 + emit_insn_before(btsq, insn);
86115 +}
86116 +
86117 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
86118 +static void kernexec_instrument_retaddr_or(rtx insn)
86119 +{
86120 + rtx orq;
86121 + rtvec argvec, constraintvec, labelvec;
86122 + int line;
86123 +
86124 + // create asm volatile("orq %%r10,(%%rsp)":::)
86125 + argvec = rtvec_alloc(0);
86126 + constraintvec = rtvec_alloc(0);
86127 + labelvec = rtvec_alloc(0);
86128 + line = expand_location(RTL_LOCATION(insn)).line;
86129 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
86130 + MEM_VOLATILE_P(orq) = 1;
86131 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
86132 + emit_insn_before(orq, insn);
86133 +}
86134 +
86135 +/*
86136 + * find all asm level function returns and forcibly set the highest bit of the return address
86137 + */
86138 +static unsigned int execute_kernexec_retaddr(void)
86139 +{
86140 + rtx insn;
86141 +
86142 + // 1. find function returns
86143 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
86144 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
86145 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
86146 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
86147 + rtx body;
86148 +
86149 + // is it a retn
86150 + if (!JUMP_P(insn))
86151 + continue;
86152 + body = PATTERN(insn);
86153 + if (GET_CODE(body) == PARALLEL)
86154 + body = XVECEXP(body, 0, 0);
86155 + if (!ANY_RETURN_P(body))
86156 + continue;
86157 + kernexec_instrument_retaddr(insn);
86158 + }
86159 +
86160 +// print_simple_rtl(stderr, get_insns());
86161 +// print_rtl(stderr, get_insns());
86162 +
86163 + return 0;
86164 +}
86165 +
86166 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86167 +{
86168 + const char * const plugin_name = plugin_info->base_name;
86169 + const int argc = plugin_info->argc;
86170 + const struct plugin_argument * const argv = plugin_info->argv;
86171 + int i;
86172 + struct register_pass_info kernexec_reload_pass_info = {
86173 + .pass = &kernexec_reload_pass.pass,
86174 + .reference_pass_name = "ssa",
86175 + .ref_pass_instance_number = 1,
86176 + .pos_op = PASS_POS_INSERT_AFTER
86177 + };
86178 + struct register_pass_info kernexec_fptr_pass_info = {
86179 + .pass = &kernexec_fptr_pass.pass,
86180 + .reference_pass_name = "ssa",
86181 + .ref_pass_instance_number = 1,
86182 + .pos_op = PASS_POS_INSERT_AFTER
86183 + };
86184 + struct register_pass_info kernexec_retaddr_pass_info = {
86185 + .pass = &kernexec_retaddr_pass.pass,
86186 + .reference_pass_name = "pro_and_epilogue",
86187 + .ref_pass_instance_number = 1,
86188 + .pos_op = PASS_POS_INSERT_AFTER
86189 + };
86190 +
86191 + if (!plugin_default_version_check(version, &gcc_version)) {
86192 + error(G_("incompatible gcc/plugin versions"));
86193 + return 1;
86194 + }
86195 +
86196 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
86197 +
86198 + if (TARGET_64BIT == 0)
86199 + return 0;
86200 +
86201 + for (i = 0; i < argc; ++i) {
86202 + if (!strcmp(argv[i].key, "method")) {
86203 + if (!argv[i].value) {
86204 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86205 + continue;
86206 + }
86207 + if (!strcmp(argv[i].value, "bts")) {
86208 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
86209 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
86210 + } else if (!strcmp(argv[i].value, "or")) {
86211 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
86212 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
86213 + fix_register("r10", 1, 1);
86214 + } else
86215 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
86216 + continue;
86217 + }
86218 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86219 + }
86220 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
86221 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
86222 +
86223 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
86224 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
86225 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
86226 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
86227 +
86228 + return 0;
86229 +}
86230 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
86231 new file mode 100644
86232 index 0000000..1276616
86233 --- /dev/null
86234 +++ b/tools/gcc/latent_entropy_plugin.c
86235 @@ -0,0 +1,321 @@
86236 +/*
86237 + * Copyright 2012-2013 by the PaX Team <pageexec@freemail.hu>
86238 + * Licensed under the GPL v2
86239 + *
86240 + * Note: the choice of the license means that the compilation process is
86241 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
86242 + * but for the kernel it doesn't matter since it doesn't link against
86243 + * any of the gcc libraries
86244 + *
86245 + * gcc plugin to help generate a little bit of entropy from program state,
86246 + * used during boot in the kernel
86247 + *
86248 + * TODO:
86249 + * - add ipa pass to identify not explicitly marked candidate functions
86250 + * - mix in more program state (function arguments/return values, loop variables, etc)
86251 + * - more instrumentation control via attribute parameters
86252 + *
86253 + * BUGS:
86254 + * - LTO needs -flto-partition=none for now
86255 + */
86256 +#include "gcc-plugin.h"
86257 +#include "config.h"
86258 +#include "system.h"
86259 +#include "coretypes.h"
86260 +#include "tree.h"
86261 +#include "tree-pass.h"
86262 +#include "flags.h"
86263 +#include "intl.h"
86264 +#include "toplev.h"
86265 +#include "plugin.h"
86266 +//#include "expr.h" where are you...
86267 +#include "diagnostic.h"
86268 +#include "plugin-version.h"
86269 +#include "tm.h"
86270 +#include "function.h"
86271 +#include "basic-block.h"
86272 +#include "gimple.h"
86273 +#include "rtl.h"
86274 +#include "emit-rtl.h"
86275 +#include "tree-flow.h"
86276 +
86277 +#if BUILDING_GCC_VERSION >= 4008
86278 +#define TODO_dump_func 0
86279 +#endif
86280 +
86281 +int plugin_is_GPL_compatible;
86282 +
86283 +static tree latent_entropy_decl;
86284 +
86285 +static struct plugin_info latent_entropy_plugin_info = {
86286 + .version = "201302112000",
86287 + .help = NULL
86288 +};
86289 +
86290 +static unsigned int execute_latent_entropy(void);
86291 +static bool gate_latent_entropy(void);
86292 +
86293 +static struct gimple_opt_pass latent_entropy_pass = {
86294 + .pass = {
86295 + .type = GIMPLE_PASS,
86296 + .name = "latent_entropy",
86297 +#if BUILDING_GCC_VERSION >= 4008
86298 + .optinfo_flags = OPTGROUP_NONE,
86299 +#endif
86300 + .gate = gate_latent_entropy,
86301 + .execute = execute_latent_entropy,
86302 + .sub = NULL,
86303 + .next = NULL,
86304 + .static_pass_number = 0,
86305 + .tv_id = TV_NONE,
86306 + .properties_required = PROP_gimple_leh | PROP_cfg,
86307 + .properties_provided = 0,
86308 + .properties_destroyed = 0,
86309 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
86310 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
86311 + }
86312 +};
86313 +
86314 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
86315 +{
86316 + if (TREE_CODE(*node) != FUNCTION_DECL) {
86317 + *no_add_attrs = true;
86318 + error("%qE attribute only applies to functions", name);
86319 + }
86320 + return NULL_TREE;
86321 +}
86322 +
86323 +static struct attribute_spec latent_entropy_attr = {
86324 + .name = "latent_entropy",
86325 + .min_length = 0,
86326 + .max_length = 0,
86327 + .decl_required = true,
86328 + .type_required = false,
86329 + .function_type_required = false,
86330 + .handler = handle_latent_entropy_attribute,
86331 +#if BUILDING_GCC_VERSION >= 4007
86332 + .affects_type_identity = false
86333 +#endif
86334 +};
86335 +
86336 +static void register_attributes(void *event_data, void *data)
86337 +{
86338 + register_attribute(&latent_entropy_attr);
86339 +}
86340 +
86341 +static bool gate_latent_entropy(void)
86342 +{
86343 + tree latent_entropy_attr;
86344 +
86345 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
86346 + return latent_entropy_attr != NULL_TREE;
86347 +}
86348 +
86349 +static unsigned HOST_WIDE_INT seed;
86350 +static unsigned HOST_WIDE_INT get_random_const(void)
86351 +{
86352 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
86353 + return seed;
86354 +}
86355 +
86356 +static enum tree_code get_op(tree *rhs)
86357 +{
86358 + static enum tree_code op;
86359 + unsigned HOST_WIDE_INT random_const;
86360 +
86361 + random_const = get_random_const();
86362 +
86363 + switch (op) {
86364 + case BIT_XOR_EXPR:
86365 + op = PLUS_EXPR;
86366 + break;
86367 +
86368 + case PLUS_EXPR:
86369 + if (rhs) {
86370 + op = LROTATE_EXPR;
86371 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
86372 + break;
86373 + }
86374 +
86375 + case LROTATE_EXPR:
86376 + default:
86377 + op = BIT_XOR_EXPR;
86378 + break;
86379 + }
86380 + if (rhs)
86381 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
86382 + return op;
86383 +}
86384 +
86385 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
86386 +{
86387 + gimple_stmt_iterator gsi;
86388 + gimple assign;
86389 + tree addxorrol, rhs;
86390 + enum tree_code op;
86391 +
86392 + op = get_op(&rhs);
86393 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
86394 + assign = gimple_build_assign(local_entropy, addxorrol);
86395 +#if BUILDING_GCC_VERSION <= 4007
86396 + find_referenced_vars_in(assign);
86397 +#endif
86398 +//debug_bb(bb);
86399 + gsi = gsi_after_labels(bb);
86400 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
86401 + update_stmt(assign);
86402 +}
86403 +
86404 +static void perturb_latent_entropy(basic_block bb, tree rhs)
86405 +{
86406 + gimple_stmt_iterator gsi;
86407 + gimple assign;
86408 + tree addxorrol, temp;
86409 +
86410 + // 1. create temporary copy of latent_entropy
86411 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
86412 +#if BUILDING_GCC_VERSION <= 4007
86413 + add_referenced_var(temp);
86414 + mark_sym_for_renaming(temp);
86415 +#endif
86416 +
86417 + // 2. read...
86418 + assign = gimple_build_assign(temp, latent_entropy_decl);
86419 +#if BUILDING_GCC_VERSION <= 4007
86420 + find_referenced_vars_in(assign);
86421 +#endif
86422 + gsi = gsi_after_labels(bb);
86423 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86424 + update_stmt(assign);
86425 +
86426 + // 3. ...modify...
86427 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
86428 + assign = gimple_build_assign(temp, addxorrol);
86429 +#if BUILDING_GCC_VERSION <= 4007
86430 + find_referenced_vars_in(assign);
86431 +#endif
86432 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86433 + update_stmt(assign);
86434 +
86435 + // 4. ...write latent_entropy
86436 + assign = gimple_build_assign(latent_entropy_decl, temp);
86437 +#if BUILDING_GCC_VERSION <= 4007
86438 + find_referenced_vars_in(assign);
86439 +#endif
86440 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86441 + update_stmt(assign);
86442 +}
86443 +
86444 +static unsigned int execute_latent_entropy(void)
86445 +{
86446 + basic_block bb;
86447 + gimple assign;
86448 + gimple_stmt_iterator gsi;
86449 + tree local_entropy;
86450 +
86451 + if (!latent_entropy_decl) {
86452 + struct varpool_node *node;
86453 +
86454 +#if BUILDING_GCC_VERSION <= 4007
86455 + for (node = varpool_nodes; node; node = node->next) {
86456 + tree var = node->decl;
86457 +#else
86458 + FOR_EACH_VARIABLE(node) {
86459 + tree var = node->symbol.decl;
86460 +#endif
86461 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
86462 + continue;
86463 + latent_entropy_decl = var;
86464 +// debug_tree(var);
86465 + break;
86466 + }
86467 + if (!latent_entropy_decl) {
86468 +// debug_tree(current_function_decl);
86469 + return 0;
86470 + }
86471 + }
86472 +
86473 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
86474 +
86475 + // 1. create local entropy variable
86476 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
86477 +#if BUILDING_GCC_VERSION <= 4007
86478 + add_referenced_var(local_entropy);
86479 + mark_sym_for_renaming(local_entropy);
86480 +#endif
86481 +
86482 + // 2. initialize local entropy variable
86483 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
86484 + if (dom_info_available_p(CDI_DOMINATORS))
86485 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
86486 + gsi = gsi_start_bb(bb);
86487 +
86488 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
86489 +// gimple_set_location(assign, loc);
86490 +#if BUILDING_GCC_VERSION <= 4007
86491 + find_referenced_vars_in(assign);
86492 +#endif
86493 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
86494 + update_stmt(assign);
86495 + bb = bb->next_bb;
86496 +
86497 + // 3. instrument each BB with an operation on the local entropy variable
86498 + while (bb != EXIT_BLOCK_PTR) {
86499 + perturb_local_entropy(bb, local_entropy);
86500 + bb = bb->next_bb;
86501 + };
86502 +
86503 + // 4. mix local entropy into the global entropy variable
86504 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
86505 + return 0;
86506 +}
86507 +
86508 +static void start_unit_callback(void *gcc_data, void *user_data)
86509 +{
86510 +#if BUILDING_GCC_VERSION >= 4007
86511 + seed = get_random_seed(false);
86512 +#else
86513 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
86514 + seed *= seed;
86515 +#endif
86516 +
86517 + if (in_lto_p)
86518 + return;
86519 +
86520 + // extern u64 latent_entropy
86521 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
86522 +
86523 + TREE_STATIC(latent_entropy_decl) = 1;
86524 + TREE_PUBLIC(latent_entropy_decl) = 1;
86525 + TREE_USED(latent_entropy_decl) = 1;
86526 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
86527 + DECL_EXTERNAL(latent_entropy_decl) = 1;
86528 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
86529 + DECL_INITIAL(latent_entropy_decl) = NULL;
86530 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
86531 +// varpool_finalize_decl(latent_entropy_decl);
86532 +// varpool_mark_needed_node(latent_entropy_decl);
86533 +}
86534 +
86535 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86536 +{
86537 + const char * const plugin_name = plugin_info->base_name;
86538 + struct register_pass_info latent_entropy_pass_info = {
86539 + .pass = &latent_entropy_pass.pass,
86540 + .reference_pass_name = "optimized",
86541 + .ref_pass_instance_number = 1,
86542 + .pos_op = PASS_POS_INSERT_BEFORE
86543 + };
86544 +
86545 + if (!plugin_default_version_check(version, &gcc_version)) {
86546 + error(G_("incompatible gcc/plugin versions"));
86547 + return 1;
86548 + }
86549 +
86550 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
86551 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
86552 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
86553 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
86554 +
86555 + return 0;
86556 +}
86557 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
86558 new file mode 100644
86559 index 0000000..5921fd7
86560 --- /dev/null
86561 +++ b/tools/gcc/size_overflow_hash.data
86562 @@ -0,0 +1,3713 @@
86563 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
86564 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
86565 +batadv_orig_node_del_if_4 batadv_orig_node_del_if 2 4 NULL
86566 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
86567 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
86568 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
86569 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
86570 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
86571 +diva_os_malloc_16406 diva_os_malloc 2 16406 NULL
86572 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
86573 +xfs_dir2_leaf_getdents_23841 xfs_dir2_leaf_getdents 3 23841 NULL
86574 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
86575 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
86576 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
86577 +create_log_8225 create_log 2 8225 NULL
86578 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
86579 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
86580 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
86581 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
86582 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
86583 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
86584 +padzero_55 padzero 1 55 &sel_read_policyvers_55
86585 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
86586 +alloc_wr_24635 alloc_wr 1-2 24635 NULL
86587 +read_file_blob_57406 read_file_blob 3 57406 NULL
86588 +add_rx_skb_8257 add_rx_skb 3 8257 NULL
86589 +enclosure_register_57412 enclosure_register 3 57412 NULL
86590 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
86591 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
86592 +gre_manip_pkt_57416 gre_manip_pkt 4 57416 NULL
86593 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
86594 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
86595 +DepcaSignature_80 DepcaSignature 2 80 NULL nohasharray
86596 +crypto_authenc_setkey_80 crypto_authenc_setkey 3 80 &DepcaSignature_80
86597 +init_cdev_8274 init_cdev 1 8274 NULL
86598 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
86599 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL nohasharray
86600 +alloc_ftrace_hash_57431 alloc_ftrace_hash 1 57431 &compat_keyctl_instantiate_key_iov_57431
86601 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
86602 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
86603 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
86604 +load_msg_95 load_msg 2 95 NULL
86605 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
86606 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
86607 +acpi_tb_check_xsdt_21862 acpi_tb_check_xsdt 1 21862 NULL
86608 +sys_pselect6_57449 sys_pselect6 1 57449 NULL
86609 +biovec_create_pools_9575 biovec_create_pools 2 9575 NULL
86610 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
86611 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
86612 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
86613 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
86614 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
86615 +send_midi_async_57463 send_midi_async 3 57463 NULL
86616 +sisusb_clear_vram_57466 sisusb_clear_vram 3-2 57466 NULL
86617 +ath6kl_usb_post_recv_transfers_32892 ath6kl_usb_post_recv_transfers 2 32892 NULL
86618 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL nohasharray
86619 +sep_lock_user_pages_57470 sep_lock_user_pages 2-3 57470 &ieee80211_if_read_flags_57470
86620 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
86621 +construct_key_and_link_8321 construct_key_and_link 4 8321 NULL
86622 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
86623 +init_q_132 init_q 4 132 NULL
86624 +roccat_read_41093 roccat_read 3 41093 NULL nohasharray
86625 +nvme_map_user_pages_41093 nvme_map_user_pages 3-4 41093 &roccat_read_41093
86626 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
86627 +unifi_net_data_malloc_24716 unifi_net_data_malloc 3 24716 NULL
86628 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
86629 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
86630 +uio_read_49300 uio_read 3 49300 NULL
86631 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
86632 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL
86633 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
86634 +firmwareUpload_32794 firmwareUpload 3 32794 NULL
86635 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
86636 +play_iframe_8219 play_iframe 3 8219 NULL
86637 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
86638 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
86639 +ath_rxbuf_alloc_24745 ath_rxbuf_alloc 2 24745 NULL
86640 +nvme_create_queue_170 nvme_create_queue 3 170 NULL
86641 +init_tag_map_57515 init_tag_map 3 57515 NULL
86642 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL
86643 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-3-4 49330 NULL
86644 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
86645 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
86646 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
86647 +DoC_Probe_57534 DoC_Probe 1 57534 NULL
86648 +cfpkt_setlen_49343 cfpkt_setlen 2 49343 NULL
86649 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
86650 +mI_alloc_skb_24770 mI_alloc_skb 1 24770 NULL
86651 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
86652 +virtblk_add_req_197 virtblk_add_req 2-3 197 NULL
86653 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
86654 +rds_tcp_data_recv_53476 rds_tcp_data_recv 3 53476 NULL
86655 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
86656 +skb_make_writable_24783 skb_make_writable 2 24783 NULL
86657 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
86658 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
86659 +cache_read_24790 cache_read 3 24790 NULL
86660 +px_raw_event_49371 px_raw_event 4 49371 NULL
86661 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
86662 +compat_filldir_32999 compat_filldir 3 32999 NULL
86663 +hci_si_event_1404 hci_si_event 3 1404 NULL
86664 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
86665 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
86666 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
86667 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
86668 +applesmc_create_nodes_49392 applesmc_create_nodes 2 49392 NULL
86669 +snd_usb_ctl_msg_8436 snd_usb_ctl_msg 8 8436 NULL
86670 +comedi_buf_alloc_24822 comedi_buf_alloc 3 24822 NULL
86671 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
86672 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
86673 +tun_alloc_skb_41216 tun_alloc_skb 2-4-3 41216 NULL
86674 +proc_scsi_write_proc_267 proc_scsi_write_proc 3 267 NULL
86675 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
86676 +sk_stream_alloc_skb_57622 sk_stream_alloc_skb 2 57622 NULL
86677 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
86678 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
86679 +mfd_add_devices_16668 mfd_add_devices 4 16668 NULL
86680 +packet_recv_error_16669 packet_recv_error 3 16669 NULL
86681 +osdmap_set_max_osd_57630 osdmap_set_max_osd 2 57630 NULL nohasharray
86682 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 &osdmap_set_max_osd_57630
86683 +mem_read_57631 mem_read 3 57631 NULL
86684 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
86685 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
86686 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
86687 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
86688 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
86689 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
86690 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
86691 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
86692 +queues_read_24877 queues_read 3 24877 NULL
86693 +__fprog_create_41263 __fprog_create 2 41263 NULL
86694 +syslog_print_307 syslog_print 2 307 NULL
86695 +platform_device_add_data_310 platform_device_add_data 3 310 NULL
86696 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
86697 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
86698 +sys_mq_timedsend_57661 sys_mq_timedsend 3 57661 NULL
86699 +r3964_write_57662 r3964_write 4 57662 NULL
86700 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
86701 +savu_sysfs_read_49473 savu_sysfs_read 6 49473 NULL
86702 +dn_nsp_do_disc_49474 dn_nsp_do_disc 6-2 49474 NULL
86703 +alloc_context_41283 alloc_context 1 41283 NULL
86704 +__lgwrite_57669 __lgwrite 4 57669 NULL
86705 +ath9k_wmi_cmd_327 ath9k_wmi_cmd 4 327 NULL
86706 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
86707 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
86708 +alloc_pg_vec_8533 alloc_pg_vec 2 8533 NULL
86709 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
86710 +ieee80211_fragment_33112 ieee80211_fragment 4 33112 NULL
86711 +arch_gnttab_map_shared_41306 arch_gnttab_map_shared 3 41306 NULL
86712 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
86713 +write_node_33121 write_node 4 33121 NULL
86714 +vring_new_virtqueue_54673 vring_new_virtqueue 2 54673 NULL
86715 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
86716 +profile_remove_8556 profile_remove 3 8556 NULL
86717 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
86718 +iscsi_recv_pdu_16755 iscsi_recv_pdu 4 16755 NULL
86719 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
86720 +cmtp_send_interopmsg_376 cmtp_send_interopmsg 7 376 NULL
86721 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
86722 +mga_ioremap_8571 mga_ioremap 1-2 8571 NULL
86723 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
86724 +sys_rt_sigpending_24961 sys_rt_sigpending 2 24961 NULL
86725 +tower_write_8580 tower_write 3 8580 NULL
86726 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
86727 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 NULL nohasharray
86728 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 &compat_sys_set_mempolicy_57742
86729 +jbd2_alloc_41359 jbd2_alloc 1 41359 NULL
86730 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
86731 +nf_nat_sdp_port_24977 nf_nat_sdp_port 7 24977 NULL
86732 +smk_write_access_49561 smk_write_access 3 49561 NULL
86733 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
86734 +kmp_init_41373 kmp_init 2 41373 NULL
86735 +context_alloc_24645 context_alloc 3 24645 NULL
86736 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
86737 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
86738 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
86739 +tipc_send2name_16809 tipc_send2name 6 16809 NULL
86740 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
86741 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
86742 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
86743 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
86744 +dm_vcalloc_16814 dm_vcalloc 1-2 16814 NULL
86745 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
86746 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
86747 +pp_read_33210 pp_read 3 33210 NULL
86748 +sys_flistxattr_41407 sys_flistxattr 3 41407 NULL
86749 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
86750 +ivtv_read_57796 ivtv_read 3 57796 NULL
86751 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
86752 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
86753 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
86754 +heap_init_49617 heap_init 2 49617 NULL
86755 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
86756 +ieee80211_send_probe_req_38307 ieee80211_send_probe_req 6-4 38307 NULL
86757 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
86758 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
86759 +_alloc_get_attr_desc_470 _alloc_get_attr_desc 2 470 NULL
86760 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
86761 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
86762 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
86763 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 4-6 41442 NULL
86764 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
86765 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
86766 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
86767 +st_write_16874 st_write 3 16874 NULL
86768 +copy_to_user_57835 copy_to_user 3 57835 NULL
86769 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
86770 +pidlist_resize_496 pidlist_resize 2 496 NULL
86771 +flash_read_57843 flash_read 3 57843 NULL
86772 +read_vbt_r0_503 read_vbt_r0 1 503 NULL
86773 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
86774 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
86775 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
86776 +arcfb_write_8702 arcfb_write 3 8702 NULL
86777 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
86778 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
86779 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
86780 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
86781 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
86782 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
86783 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
86784 +cxio_hal_init_rhdl_resource_25104 cxio_hal_init_rhdl_resource 1 25104 NULL
86785 +sock_wmalloc_16472 sock_wmalloc 2 16472 NULL
86786 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
86787 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
86788 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
86789 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
86790 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
86791 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
86792 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
86793 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
86794 +sys_gethostname_49698 sys_gethostname 2 49698 NULL
86795 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
86796 +ieee80211_rx_mgmt_probe_resp_6918 ieee80211_rx_mgmt_probe_resp 3 6918 NULL
86797 +devres_alloc_551 devres_alloc 2 551 NULL
86798 +ldisc_receive_41516 ldisc_receive 4 41516 NULL
86799 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
86800 +ip_append_data_16942 ip_append_data 5-6 16942 NULL
86801 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
86802 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
86803 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
86804 +emi26_writememory_57908 emi26_writememory 4 57908 NULL
86805 +start_isoc_chain_565 start_isoc_chain 2 565 NULL
86806 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
86807 +gsm_mux_rx_netchar_33336 gsm_mux_rx_netchar 3 33336 NULL
86808 +brcmu_pkt_buf_get_skb_5556 brcmu_pkt_buf_get_skb 1 5556 NULL
86809 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
86810 +sys_prctl_8766 sys_prctl 4 8766 NULL
86811 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
86812 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
86813 +compat_sys_preadv_583 compat_sys_preadv 3 583 NULL
86814 +sys_fsetxattr_49736 sys_fsetxattr 4 49736 NULL
86815 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
86816 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
86817 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
86818 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
86819 +sys_fgetxattr_25166 sys_fgetxattr 4 25166 NULL
86820 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
86821 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
86822 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
86823 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
86824 +ath6kl_buf_alloc_57304 ath6kl_buf_alloc 1 57304 NULL
86825 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
86826 +gserial_setup_41558 gserial_setup 2 41558 NULL
86827 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
86828 +rx_57944 rx 4 57944 NULL
86829 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
86830 +nci_skb_alloc_49757 nci_skb_alloc 2 49757 NULL
86831 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
86832 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
86833 +sctp_ulpevent_new_33377 sctp_ulpevent_new 1 33377 NULL
86834 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
86835 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
86836 +isku_sysfs_write_49767 isku_sysfs_write 6 49767 NULL
86837 +i915_cache_sharing_write_57961 i915_cache_sharing_write 3 57961 NULL
86838 +batadv_receive_client_update_packet_41578 batadv_receive_client_update_packet 3 41578 NULL
86839 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
86840 +handle_response_icmp_39574 handle_response_icmp 7 39574 NULL
86841 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
86842 +hfc_empty_fifo_57972 hfc_empty_fifo 2 57972 NULL
86843 +ceph_dns_resolve_name_62488 ceph_dns_resolve_name 2 62488 NULL
86844 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
86845 +icmpv6_manip_pkt_8833 icmpv6_manip_pkt 4 8833 NULL
86846 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
86847 +read_file_rx_chainmask_41605 read_file_rx_chainmask 3 41605 NULL
86848 +vmw_du_crtc_cursor_set_28479 vmw_du_crtc_cursor_set 4-5 28479 NULL
86849 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
86850 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
86851 +a2mp_send_41615 a2mp_send 4 41615 NULL
86852 +ceph_copy_user_to_page_vector_656 ceph_copy_user_to_page_vector 4-3 656 NULL
86853 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
86854 +arch_gnttab_map_status_49812 arch_gnttab_map_status 3 49812 NULL
86855 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
86856 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
86857 +tcf_csum_ipv6_udp_25241 tcf_csum_ipv6_udp 4 25241 NULL
86858 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
86859 +macvtap_alloc_skb_50629 macvtap_alloc_skb 2-4-3 50629 NULL
86860 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
86861 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6 49829 NULL
86862 +add_uuid_49831 add_uuid 4 49831 NULL
86863 +send_pages_8872 send_pages 3 8872 NULL
86864 +ath6kl_fwlog_block_read_49836 ath6kl_fwlog_block_read 3 49836 NULL
86865 +__btrfs_map_block_49839 __btrfs_map_block 3 49839 NULL
86866 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
86867 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
86868 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
86869 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
86870 +__kmalloc_reserve_17080 __kmalloc_reserve 1 17080 NULL
86871 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
86872 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
86873 +vfs_writev_25278 vfs_writev 3 25278 NULL
86874 +rtl8169_try_rx_copy_705 rtl8169_try_rx_copy 3 705 NULL
86875 +alloc_async_14208 alloc_async 1 14208 NULL
86876 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
86877 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
86878 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
86879 +create_entry_33479 create_entry 2 33479 NULL
86880 +mce_async_out_58056 mce_async_out 3 58056 NULL
86881 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
86882 +sys_preadv_17100 sys_preadv 3 17100 NULL
86883 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
86884 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
86885 +netxen_nic_hw_write_wx_128M_33488 netxen_nic_hw_write_wx_128M 2 33488 NULL
86886 +aac_src_ioremap_41688 aac_src_ioremap 2 41688 NULL
86887 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
86888 +res_counter_read_33499 res_counter_read 4 33499 NULL
86889 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
86890 +cm4040_write_58079 cm4040_write 3 58079 NULL
86891 +fb_read_33506 fb_read 3 33506 NULL
86892 +help_25316 help 5 25316 NULL nohasharray
86893 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 &help_25316
86894 +rfcomm_wmalloc_58090 rfcomm_wmalloc 2 58090 NULL
86895 +mwifiex_get_common_rates_17131 mwifiex_get_common_rates 3 17131 NULL
86896 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
86897 +ddp_set_map_751 ddp_set_map 4 751 NULL
86898 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
86899 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
86900 +dvb_video_write_754 dvb_video_write 3 754 NULL
86901 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
86902 +osd_req_add_get_attr_list_49278 osd_req_add_get_attr_list 3 49278 NULL
86903 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
86904 +bdx_tx_db_init_41719 bdx_tx_db_init 2 41719 NULL
86905 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
86906 +udi_log_event_58105 udi_log_event 3 58105 NULL
86907 +sys_pwritev_41722 sys_pwritev 3 41722 NULL
86908 +l2cap_sock_alloc_skb_cb_33532 l2cap_sock_alloc_skb_cb 2 33532 NULL
86909 +ib_send_cm_mra_60202 ib_send_cm_mra 4 60202 NULL nohasharray
86910 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 &ib_send_cm_mra_60202
86911 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
86912 +__copy_from_user_inatomic_nocache_49921 __copy_from_user_inatomic_nocache 3 49921 NULL
86913 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL
86914 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
86915 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
86916 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
86917 +vol_cdev_read_8968 vol_cdev_read 3 8968 NULL nohasharray
86918 +seq_open_net_8968 seq_open_net 4 8968 &vol_cdev_read_8968
86919 +sep_read_17161 sep_read 3 17161 NULL
86920 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
86921 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
86922 +dup_array_33551 dup_array 3 33551 NULL
86923 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
86924 +solo_enc_read_33553 solo_enc_read 3 33553 NULL
86925 +fillonedir_41746 fillonedir 3 41746 NULL
86926 +init_bch_64130 init_bch 1-2 64130 NULL
86927 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
86928 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
86929 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
86930 +btrfs_alloc_free_block_8986 btrfs_alloc_free_block 3 8986 NULL
86931 +savemem_58129 savemem 3 58129 NULL
86932 +batadv_tt_realloc_packet_buff_49960 batadv_tt_realloc_packet_buff 4 49960 NULL
86933 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
86934 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
86935 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
86936 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL
86937 +if_writecmd_815 if_writecmd 2 815 NULL
86938 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
86939 +read_fifo_826 read_fifo 3 826 NULL
86940 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
86941 +scsi_execute_33596 scsi_execute 5 33596 NULL
86942 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
86943 +ms_rw_17220 ms_rw 3-4 17220 NULL
86944 +read_tree_block_841 read_tree_block 3 841 NULL
86945 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
86946 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
86947 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
86948 +__pskb_copy_9038 __pskb_copy 2 9038 NULL
86949 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
86950 +asix_write_cmd_58192 asix_write_cmd 5 58192 NULL
86951 +um_idi_read_850 um_idi_read 3 850 NULL
86952 +__module_alloc_50004 __module_alloc 1 50004 NULL
86953 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
86954 +ts_read_44687 ts_read 3 44687 NULL
86955 +nci_send_cmd_58206 nci_send_cmd 3 58206 NULL
86956 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
86957 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
86958 +provide_user_output_41105 provide_user_output 3 41105 NULL
86959 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
86960 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
86961 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
86962 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
86963 +alloc_ep_17269 alloc_ep 1 17269 NULL
86964 +ath6kl_wmi_beginscan_cmd_25462 ath6kl_wmi_beginscan_cmd 8 25462 NULL
86965 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 NULL
86966 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
86967 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
86968 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
86969 +alloc_ebda_hpc_50046 alloc_ebda_hpc 1-2 50046 NULL
86970 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
86971 +create_queues_9088 create_queues 2-3 9088 NULL
86972 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
86973 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
86974 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
86975 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
86976 +rbd_alloc_coll_33678 rbd_alloc_coll 1 33678 NULL
86977 +read_file_debug_58256 read_file_debug 3 58256 NULL
86978 +skb_pad_17302 skb_pad 2 17302 NULL
86979 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
86980 +btmrvl_hsstate_read_920 btmrvl_hsstate_read 3 920 NULL
86981 +profile_load_58267 profile_load 3 58267 NULL
86982 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
86983 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4 25502 NULL
86984 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
86985 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
86986 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
86987 +pcpu_get_vm_areas_50085 pcpu_get_vm_areas 3 50085 NULL
86988 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
86989 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
86990 +sys_keyctl_33708 sys_keyctl 4 33708 NULL nohasharray
86991 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 &sys_keyctl_33708
86992 +ata_host_alloc_pinfo_17325 ata_host_alloc_pinfo 3 17325 NULL
86993 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
86994 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
86995 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
86996 +get_packet_41914 get_packet 3 41914 NULL
86997 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
86998 +ceph_get_direct_page_vector_41917 ceph_get_direct_page_vector 2 41917 NULL
86999 +read_file_slot_50111 read_file_slot 3 50111 NULL
87000 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
87001 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
87002 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
87003 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
87004 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
87005 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
87006 +copy_items_50140 copy_items 6 50140 NULL
87007 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
87008 +pcim_iomap_58334 pcim_iomap 3 58334 NULL
87009 +diva_init_dma_map_58336 diva_init_dma_map 3 58336 NULL
87010 +map_addr_56144 map_addr 7 56144 NULL
87011 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
87012 +btmrvl_psstate_read_50683 btmrvl_psstate_read 3 50683 NULL
87013 +hdlcdev_rx_997 hdlcdev_rx 3 997 NULL
87014 +portnames_read_41958 portnames_read 3 41958 NULL
87015 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 4 41959 NULL
87016 +hashtab_create_33769 hashtab_create 3 33769 NULL
87017 +alloc_group_attrs_9194 alloc_group_attrs 2 9194 NULL nohasharray
87018 +altera_swap_ir_9194 altera_swap_ir 2 9194 &alloc_group_attrs_9194
87019 +vmalloc_to_sg_58354 vmalloc_to_sg 2 58354 NULL
87020 +aac_nark_ioremap_50163 aac_nark_ioremap 2 50163 NULL nohasharray
87021 +kmalloc_node_50163 kmalloc_node 1 50163 &aac_nark_ioremap_50163
87022 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
87023 +odev_update_50169 odev_update 2 50169 NULL
87024 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL
87025 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
87026 +__devres_alloc_25598 __devres_alloc 2 25598 NULL
87027 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
87028 +netpoll_send_udp_58955 netpoll_send_udp 3 58955 NULL
87029 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
87030 +ib_send_cm_drep_50186 ib_send_cm_drep 3 50186 NULL
87031 +do_write_orph_node_64343 do_write_orph_node 2 64343 NULL
87032 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
87033 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
87034 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
87035 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
87036 +lguest_map_42008 lguest_map 1-2 42008 NULL
87037 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
87038 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
87039 +pool_allocate_42012 pool_allocate 3 42012 NULL
87040 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
87041 +sctp_make_init_58401 sctp_make_init 4 58401 NULL
87042 +ieee80211_skb_resize_50211 ieee80211_skb_resize 3 50211 NULL
87043 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
87044 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
87045 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
87046 +udplite_manip_pkt_33832 udplite_manip_pkt 4 33832 NULL
87047 +tcf_csum_ipv4_icmp_9258 tcf_csum_ipv4_icmp 3 9258 NULL
87048 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
87049 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
87050 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
87051 +sparse_early_usemaps_alloc_node_9269 sparse_early_usemaps_alloc_node 4 9269 NULL
87052 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
87053 +iscsi_offload_mesg_58425 iscsi_offload_mesg 5 58425 NULL
87054 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
87055 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
87056 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
87057 +nfs_pgarray_set_1085 nfs_pgarray_set 2 1085 NULL
87058 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
87059 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
87060 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
87061 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
87062 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
87063 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
87064 +__alloc_session_17485 __alloc_session 2-1 17485 NULL
87065 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
87066 +pm860x_bulk_write_43875 pm860x_bulk_write 3 43875 NULL
87067 +afs_extract_data_50261 afs_extract_data 5 50261 NULL
87068 +config_proc_write_33878 config_proc_write 3 33878 NULL
87069 +capabilities_read_58457 capabilities_read 3 58457 NULL
87070 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
87071 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
87072 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
87073 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
87074 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
87075 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
87076 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
87077 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
87078 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
87079 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
87080 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
87081 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
87082 +batadv_bla_is_backbone_gw_58488 batadv_bla_is_backbone_gw 3 58488 NULL
87083 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
87084 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
87085 +sel_write_context_25726 sel_write_context 3 25726 NULL nohasharray
87086 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 &sel_write_context_25726
87087 +sysfs_read_file_42113 sysfs_read_file 3 42113 NULL
87088 +mcs_unwrap_fir_25733 mcs_unwrap_fir 3 25733 NULL
87089 +vme_user_write_15587 vme_user_write 3 15587 NULL
87090 +xlog_do_log_recovery_17550 xlog_do_log_recovery 3 17550 NULL
87091 +__copy_to_user_17551 __copy_to_user 3 17551 NULL
87092 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
87093 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
87094 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
87095 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
87096 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
87097 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
87098 +v9fs_alloc_rdir_buf_42150 v9fs_alloc_rdir_buf 2 42150 NULL
87099 +roccat_common2_send_with_status_50343 roccat_common2_send_with_status 4 50343 NULL
87100 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
87101 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
87102 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
87103 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
87104 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
87105 +read_9397 read 3 9397 NULL
87106 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
87107 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
87108 +printer_write_60276 printer_write 3 60276 NULL
87109 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
87110 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
87111 +rts51x_write_mem_17598 rts51x_write_mem 4 17598 NULL
87112 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
87113 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
87114 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
87115 +osst_execute_17607 osst_execute 7-6 17607 NULL
87116 +nf_nat_sip_expect_9418 nf_nat_sip_expect 8 9418 NULL
87117 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
87118 +ipw_packet_received_skb_1230 ipw_packet_received_skb 2 1230 NULL
87119 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
87120 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
87121 +sys32_rt_sigpending_25814 sys32_rt_sigpending 2 25814 NULL
87122 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
87123 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
87124 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
87125 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
87126 +xip_file_read_58592 xip_file_read 3 58592 NULL
87127 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
87128 +kmalloc_array_9444 kmalloc_array 1-2 9444 NULL
87129 +__ntfs_malloc_34022 __ntfs_malloc 1 34022 NULL
87130 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
87131 +mcs_unwrap_mir_9455 mcs_unwrap_mir 3 9455 NULL
87132 +ppp_write_34034 ppp_write 3 34034 NULL
87133 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
87134 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
87135 +tty_insert_flip_string_34042 tty_insert_flip_string 3 34042 NULL
87136 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
87137 +batadv_tt_prepare_packet_buff_1280 batadv_tt_prepare_packet_buff 4 1280 NULL
87138 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
87139 +module_alloc_update_bounds_rx_58634 module_alloc_update_bounds_rx 1 58634 NULL nohasharray
87140 +efi_ioremap_58634 efi_ioremap 1-2 58634 &module_alloc_update_bounds_rx_58634
87141 +btmrvl_hsmode_write_42252 btmrvl_hsmode_write 3 42252 NULL
87142 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
87143 +dsp_tone_hw_message_17678 dsp_tone_hw_message 3 17678 NULL
87144 +netxen_nic_map_indirect_address_128M_42257 netxen_nic_map_indirect_address_128M 2 42257 NULL
87145 +ulog_alloc_skb_23427 ulog_alloc_skb 1 23427 NULL
87146 +__alloc_preds_9492 __alloc_preds 2 9492 NULL
87147 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
87148 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
87149 +read_file_ant_diversity_34071 read_file_ant_diversity 3 34071 NULL
87150 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
87151 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
87152 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
87153 +savu_sysfs_write_42273 savu_sysfs_write 6 42273 NULL
87154 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 NULL
87155 +lp_write_9511 lp_write 3 9511 NULL
87156 +__einj_error_trigger_17707 __einj_error_trigger 1 17707 NULL nohasharray
87157 +venus_rename_17707 venus_rename 5-4 17707 &__einj_error_trigger_17707
87158 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
87159 +nfs_readdir_make_qstr_12509 nfs_readdir_make_qstr 3 12509 NULL
87160 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
87161 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
87162 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
87163 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
87164 +read_file_dma_9530 read_file_dma 3 9530 NULL
87165 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
87166 +rcname_read_25919 rcname_read 3 25919 NULL
87167 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
87168 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
87169 +tps6586x_writes_58689 tps6586x_writes 3 58689 NULL
87170 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
87171 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
87172 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
87173 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
87174 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
87175 +key_flags_read_25931 key_flags_read 3 25931 NULL
87176 +audit_log_n_untrustedstring_9548 audit_log_n_untrustedstring 3 9548 NULL
87177 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
87178 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
87179 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
87180 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
87181 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
87182 +fw_node_create_9559 fw_node_create 2 9559 NULL
87183 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
87184 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
87185 +kobj_map_9566 kobj_map 2-3 9566 NULL
87186 +snd_pcm_plug_alloc_42339 snd_pcm_plug_alloc 2 42339 NULL
87187 +acpi_map_58725 acpi_map 1-2 58725 NULL
87188 +brcmf_usb_attach_17766 brcmf_usb_attach 2-3 17766 NULL
87189 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
87190 +fwnet_receive_packet_50537 fwnet_receive_packet 9 50537 NULL
87191 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
87192 +ieee80211_tdls_mgmt_9581 ieee80211_tdls_mgmt 8 9581 NULL
87193 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
87194 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
87195 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
87196 +file_read_actor_1401 file_read_actor 4 1401 NULL
87197 +av7110_ipack_init_46655 av7110_ipack_init 2 46655 NULL
87198 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
87199 +ubifs_leb_change_17789 ubifs_leb_change 4 17789 NULL
87200 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
87201 +do_sync_9604 do_sync 1 9604 NULL
87202 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5 9605 NULL
87203 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
87204 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
87205 +__do_config_autodelink_58763 __do_config_autodelink 3 58763 NULL
87206 +sctp_sf_abort_violation_1420 sctp_sf_abort_violation 7 1420 NULL
87207 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
87208 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
87209 +lpfc_sli_probe_sriov_nr_virtfn_26004 lpfc_sli_probe_sriov_nr_virtfn 2 26004 NULL
87210 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
87211 +fat_readpages_50582 fat_readpages 4 50582 NULL nohasharray
87212 +pep_reply_50582 pep_reply 5 50582 &fat_readpages_50582
87213 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
87214 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
87215 +_snd_pcm_lib_alloc_vmalloc_buffer_17820 _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 NULL
87216 +xfs_readdir_41200 xfs_readdir 3 41200 NULL
87217 +sge_rx_50594 sge_rx 3 50594 NULL
87218 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
87219 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
87220 +skb_padto_50759 skb_padto 2 50759 NULL
87221 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
87222 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
87223 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
87224 +isku_sysfs_read_58806 isku_sysfs_read 6 58806 NULL
87225 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
87226 +uvc_alloc_buffers_9656 uvc_alloc_buffers 2-3 9656 NULL
87227 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
87228 +ep_read_58813 ep_read 3 58813 NULL
87229 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
87230 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
87231 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
87232 +pci_enable_sriov_35745 pci_enable_sriov 2 35745 NULL
87233 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
87234 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
87235 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
87236 +dns_query_9676 dns_query 3 9676 NULL
87237 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
87238 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
87239 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
87240 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL
87241 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
87242 +command_write_58841 command_write 3 58841 NULL
87243 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
87244 +dev_config_8506 dev_config 3 8506 NULL
87245 +compat_sys_pwritev_17886 compat_sys_pwritev 3 17886 NULL
87246 +sys_readv_50664 sys_readv 3 50664 NULL
87247 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
87248 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
87249 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
87250 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
87251 +recover_head_17904 recover_head 3 17904 NULL
87252 +dccp_feat_register_sp_17914 dccp_feat_register_sp 5 17914 NULL
87253 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
87254 +brcmf_sdbrcm_bus_txctl_42492 brcmf_sdbrcm_bus_txctl 3 42492 NULL
87255 +srp_iu_pool_alloc_17920 srp_iu_pool_alloc 2 17920 NULL
87256 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
87257 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
87258 +cs553x_init_one_58886 cs553x_init_one 3 58886 NULL
87259 +ddb_input_read_9743 ddb_input_read 3 9743 NULL
87260 +skb_cow_26138 skb_cow 2 26138 NULL
87261 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
87262 +snd_emux_create_port_42533 snd_emux_create_port 3 42533 NULL
87263 +do_sigpending_9766 do_sigpending 2 9766 NULL
87264 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
87265 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
87266 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
87267 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
87268 +copy_oldmem_page_26164 copy_oldmem_page 3-1 26164 NULL
87269 +i915_ring_stop_read_42549 i915_ring_stop_read 3 42549 NULL nohasharray
87270 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 &i915_ring_stop_read_42549
87271 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 NULL
87272 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
87273 +fc_frame_alloc_1596 fc_frame_alloc 2 1596 NULL
87274 +rngapi_reset_34366 rngapi_reset 3 34366 NULL nohasharray
87275 +p54_alloc_skb_34366 p54_alloc_skb 3 34366 &rngapi_reset_34366
87276 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
87277 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
87278 +solo_v4l2_read_59247 solo_v4l2_read 3 59247 NULL
87279 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
87280 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
87281 +reiserfs_resize_34377 reiserfs_resize 2 34377 NULL
87282 +get_registers_26187 get_registers 3 26187 NULL
87283 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
87284 +ttm_bo_fbdev_io_9805 ttm_bo_fbdev_io 4 9805 NULL
87285 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
87286 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
87287 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
87288 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3 27332 NULL
87289 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
87290 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
87291 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL nohasharray
87292 +pipe_handler_request_50774 pipe_handler_request 5 50774 &tm6000_read_write_usb_50774
87293 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
87294 +mce_write_26201 mce_write 3 26201 NULL
87295 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
87296 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
87297 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
87298 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
87299 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
87300 +__pskb_pull_42602 __pskb_pull 2 42602 NULL
87301 +sctp_make_heartbeat_ack_34411 sctp_make_heartbeat_ack 4 34411 NULL
87302 +tpm_write_50798 tpm_write 3 50798 NULL
87303 +btmrvl_hsmode_read_1647 btmrvl_hsmode_read 3 1647 NULL
87304 +tun_do_read_50800 tun_do_read 4 50800 NULL
87305 +handle_rx_packet_58993 handle_rx_packet 3 58993 NULL
87306 +write_flush_50803 write_flush 3 50803 NULL
87307 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
87308 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
87309 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
87310 +dvb_play_50814 dvb_play 3 50814 NULL
87311 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
87312 +sys_move_pages_42626 sys_move_pages 2 42626 NULL
87313 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
87314 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
87315 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
87316 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
87317 +dma_attach_50831 dma_attach 6-7 50831 NULL
87318 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
87319 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
87320 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
87321 +packet_came_18072 packet_came 3 18072 NULL
87322 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
87323 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
87324 +sctp_make_abort_34459 sctp_make_abort 3 34459 NULL
87325 +_regmap_raw_write_42652 _regmap_raw_write 4 42652 NULL
87326 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
87327 +get_vm_area_18080 get_vm_area 1 18080 NULL
87328 +dvb_dvr_set_buffer_size_9840 dvb_dvr_set_buffer_size 2 9840 NULL
87329 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
87330 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
87331 +self_check_write_50856 self_check_write 5 50856 NULL
87332 +line6_dumpreq_init_34473 line6_dumpreq_init 3 34473 NULL
87333 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
87334 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
87335 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
87336 +l2tp_xmit_skb_42672 l2tp_xmit_skb 3 42672 NULL
87337 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
87338 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
87339 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
87340 +sis190_try_rx_copy_57069 sis190_try_rx_copy 3 57069 NULL
87341 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
87342 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
87343 +vb2_read_42703 vb2_read 3 42703 NULL
87344 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
87345 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
87346 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
87347 +snd_pcm_plugin_alloc_12580 snd_pcm_plugin_alloc 2 12580 NULL
87348 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
87349 +read_file_misc_9948 read_file_misc 3 9948 NULL
87350 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
87351 +set_rxd_buffer_pointer_9950 set_rxd_buffer_pointer 8 9950 NULL
87352 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
87353 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
87354 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL
87355 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
87356 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
87357 +cosa_write_1774 cosa_write 3 1774 NULL
87358 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
87359 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4 34547 NULL
87360 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
87361 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
87362 +bnx2fc_cmd_mgr_alloc_24873 bnx2fc_cmd_mgr_alloc 3-2 24873 NULL
87363 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
87364 +ath6kl_usb_submit_ctrl_out_9978 ath6kl_usb_submit_ctrl_out 6 9978 NULL
87365 +dup_to_netobj_26363 dup_to_netobj 3 26363 NULL
87366 +sock_bindtodevice_50942 sock_bindtodevice 3 50942 NULL
87367 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
87368 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
87369 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
87370 +mld_newpack_50950 mld_newpack 2 50950 NULL
87371 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL
87372 +i915_ring_stop_write_59010 i915_ring_stop_write 3 59010 NULL
87373 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
87374 +cfpkt_create_18197 cfpkt_create 1 18197 NULL
87375 +velocity_rx_copy_34583 velocity_rx_copy 2 34583 NULL
87376 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
87377 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
87378 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4 37428 NULL
87379 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
87380 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
87381 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
87382 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
87383 +handle_request_10024 handle_request 9 10024 NULL
87384 +__tty_alloc_driver_53799 __tty_alloc_driver 1 53799 NULL
87385 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
87386 +timeout_write_50991 timeout_write 3 50991 NULL
87387 +batadv_orig_hash_add_if_10033 batadv_orig_hash_add_if 2 10033 NULL
87388 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
87389 +ip_vs_create_timeout_table_64478 ip_vs_create_timeout_table 2 64478 NULL
87390 +proc_write_51003 proc_write 3 51003 NULL
87391 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
87392 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
87393 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
87394 +set_arg_42824 set_arg 3 42824 NULL
87395 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
87396 +fast_rx_path_59214 fast_rx_path 3 59214 NULL
87397 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
87398 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
87399 +audit_log_n_string_31705 audit_log_n_string 3 31705 NULL
87400 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
87401 +pstore_mkfile_50830 pstore_mkfile 5 50830 NULL
87402 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
87403 +hidp_queue_report_1881 hidp_queue_report 3 1881 NULL
87404 +dt3155_read_59226 dt3155_read 3 59226 NULL
87405 +xfs_buf_read_uncached_42844 xfs_buf_read_uncached 3 42844 NULL
87406 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
87407 +dump_midi_51040 dump_midi 3 51040 NULL
87408 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
87409 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
87410 +nf_nat_mangle_udp_packet_34661 nf_nat_mangle_udp_packet 8-6 34661 NULL
87411 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
87412 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
87413 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 NULL
87414 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
87415 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
87416 +em28xx_v4l2_read_16701 em28xx_v4l2_read 3 16701 NULL
87417 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
87418 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
87419 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
87420 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
87421 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 NULL
87422 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
87423 +pskb_expand_head_42881 pskb_expand_head 2-3 42881 NULL
87424 +ip6ip6_err_18308 ip6ip6_err 5 18308 NULL
87425 +read_vmcore_26501 read_vmcore 3 26501 NULL
87426 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
87427 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
87428 +tipc_port_recv_sections_42890 tipc_port_recv_sections 4 42890 NULL
87429 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 3-4 26507 NULL
87430 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
87431 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
87432 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
87433 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
87434 +SendTxCommandPacket_42901 SendTxCommandPacket 3 42901 NULL
87435 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
87436 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
87437 +ath6kl_wmi_send_probe_response_cmd_31728 ath6kl_wmi_send_probe_response_cmd 6 31728 NULL
87438 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
87439 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
87440 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
87441 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
87442 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
87443 +rds_message_inc_copy_to_user_26540 rds_message_inc_copy_to_user 3 26540 NULL
87444 +iscsi_nop_out_rsp_51117 iscsi_nop_out_rsp 4 51117 NULL
87445 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
87446 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
87447 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
87448 +sctp_make_datafrag_empty_34737 sctp_make_datafrag_empty 3 34737 NULL
87449 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
87450 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
87451 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
87452 +fd_copyout_59323 fd_copyout 3 59323 NULL
87453 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
87454 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
87455 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
87456 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
87457 +diva_alloc_dma_map_23798 diva_alloc_dma_map 2 23798 NULL
87458 +solos_param_store_34755 solos_param_store 4 34755 NULL
87459 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
87460 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
87461 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
87462 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
87463 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
87464 +ib_send_cm_rtu_63138 ib_send_cm_rtu 3 63138 NULL
87465 +compat_sys_pwritev64_51151 compat_sys_pwritev64 3 51151 NULL
87466 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL nohasharray
87467 +batadv_receive_server_sync_packet_26577 batadv_receive_server_sync_packet 3 26577 &rts51x_read_mem_26577
87468 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
87469 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
87470 +batadv_tt_commit_changes_2008 batadv_tt_commit_changes 4 2008 NULL
87471 +sep_prepare_input_dma_table_2009 sep_prepare_input_dma_table 2-3 2009 NULL
87472 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
87473 +ubifs_write_node_11258 ubifs_write_node 5-3 11258 NULL
87474 +reada_tree_block_flagged_18402 reada_tree_block_flagged 3 18402 NULL
87475 +iscsi_if_send_reply_52219 iscsi_if_send_reply 7 52219 NULL
87476 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
87477 +__copy_in_user_34790 __copy_in_user 3 34790 NULL
87478 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
87479 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL
87480 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
87481 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
87482 +devm_ioremap_nocache_2036 devm_ioremap_nocache 2-3 2036 NULL
87483 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
87484 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
87485 +batadv_orig_node_add_if_18433 batadv_orig_node_add_if 2 18433 NULL
87486 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
87487 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
87488 +nfc_alloc_recv_skb_10244 nfc_alloc_recv_skb 1 10244 NULL
87489 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
87490 +mangle_sdp_packet_30381 mangle_sdp_packet 10 30381 NULL
87491 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
87492 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
87493 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
87494 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
87495 +subbuf_read_actor_2071 subbuf_read_actor 3 2071 NULL
87496 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
87497 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
87498 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
87499 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
87500 +receive_DataRequest_9904 receive_DataRequest 3 9904 NULL
87501 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
87502 +tipc_send_51238 tipc_send 4 51238 NULL
87503 +drm_property_create_51239 drm_property_create 4 51239 NULL
87504 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
87505 +squashfs_read_data_59440 squashfs_read_data 6 59440 NULL
87506 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
87507 +audit_expand_2098 audit_expand 2 2098 NULL
87508 +st_read_51251 st_read 3 51251 NULL
87509 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
87510 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
87511 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
87512 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
87513 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
87514 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
87515 +rtsx_read_cfg_seq_48139 rtsx_read_cfg_seq 5-3 48139 NULL
87516 +__find_xattr_2117 __find_xattr 6 2117 NULL nohasharray
87517 +enable_read_2117 enable_read 3 2117 &__find_xattr_2117
87518 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
87519 +pcf50633_write_block_2124 pcf50633_write_block 3 2124 NULL
87520 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
87521 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
87522 +c4_add_card_54968 c4_add_card 3 54968 NULL
87523 +rtllib_authentication_req_26713 rtllib_authentication_req 3 26713 NULL
87524 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
87525 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
87526 +fd_do_readv_51297 fd_do_readv 3 51297 NULL
87527 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 5-6-9 18530 NULL
87528 +nfc_hci_send_cmd_async_26723 nfc_hci_send_cmd_async 5 26723 NULL
87529 +mlx4_init_icm_table_2151 mlx4_init_icm_table 5-4 2151 NULL
87530 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
87531 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
87532 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
87533 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
87534 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
87535 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
87536 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
87537 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
87538 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
87539 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
87540 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
87541 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
87542 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
87543 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
87544 +set_bypass_pwoff_pfs_27669 set_bypass_pwoff_pfs 3 27669 NULL
87545 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
87546 +srp_ring_alloc_26760 srp_ring_alloc 2 26760 NULL
87547 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
87548 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
87549 +ntfs_malloc_nofs_nofail_63631 ntfs_malloc_nofs_nofail 1 63631 NULL
87550 +cosa_net_setup_rx_38594 cosa_net_setup_rx 2 38594 NULL
87551 +skb_gro_header_slow_34958 skb_gro_header_slow 2 34958 NULL
87552 +debug_output_18575 debug_output 3 18575 NULL
87553 +Realloc_34961 Realloc 2 34961 NULL
87554 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
87555 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
87556 +_rtl92s_firmware_downloadcode_14021 _rtl92s_firmware_downloadcode 3 14021 NULL
87557 +__netdev_alloc_skb_18595 __netdev_alloc_skb 2 18595 NULL
87558 +slabinfo_write_18600 slabinfo_write 3 18600 NULL
87559 +ssb_bus_ssbbus_register_2217 ssb_bus_ssbbus_register 2 2217 NULL
87560 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
87561 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
87562 +vhci_write_2224 vhci_write 3 2224 NULL
87563 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
87564 +acpi_os_ioremap_49523 acpi_os_ioremap 1-2 49523 NULL
87565 +rb_alloc_3102 rb_alloc 1 3102 NULL
87566 +uf_create_device_nodes_24948 uf_create_device_nodes 2 24948 NULL
87567 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
87568 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
87569 +write_pbl_59583 write_pbl 4 59583 NULL
87570 +from_buffer_18625 from_buffer 3 18625 NULL
87571 +uio_write_43202 uio_write 3 43202 NULL
87572 +memdup_user_59590 memdup_user 2 59590 NULL
87573 +ieee80211_wx_set_gen_ie_51399 ieee80211_wx_set_gen_ie 3 51399 NULL
87574 +iso_callback_43208 iso_callback 3 43208 NULL
87575 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
87576 +smk_write_load_26829 smk_write_load 3 26829 NULL
87577 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
87578 +do_update_counters_2259 do_update_counters 4 2259 NULL
87579 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
87580 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
87581 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
87582 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
87583 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
87584 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
87585 +mtrr_write_59622 mtrr_write 3 59622 NULL
87586 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
87587 +ip_vs_icmp_xmit_59624 ip_vs_icmp_xmit 4 59624 NULL
87588 +netxen_nic_hw_read_wx_128M_26858 netxen_nic_hw_read_wx_128M 2 26858 NULL
87589 +edge_tty_recv_18667 edge_tty_recv 4 18667 NULL nohasharray
87590 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 &edge_tty_recv_18667
87591 +btmrvl_gpiogap_write_35053 btmrvl_gpiogap_write 3 35053 NULL
87592 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
87593 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
87594 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
87595 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
87596 +fixup_leb_43256 fixup_leb 3 43256 NULL
87597 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
87598 +ubifs_recover_log_leb_12079 ubifs_recover_log_leb 3 12079 NULL
87599 +ubifs_setxattr_59650 ubifs_setxattr 4 59650 NULL nohasharray
87600 +hidraw_read_59650 hidraw_read 3 59650 &ubifs_setxattr_59650
87601 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
87602 +ca91cx42_alloc_resource_10502 ca91cx42_alloc_resource 2 10502 NULL
87603 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
87604 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
87605 +evtchn_write_43278 evtchn_write 3 43278 NULL
87606 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
87607 +store_ifalias_35088 store_ifalias 4 35088 NULL
87608 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
87609 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
87610 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
87611 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
87612 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
87613 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
87614 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
87615 +get_vm_area_caller_10527 get_vm_area_caller 1 10527 NULL
87616 +capi_write_35104 capi_write 3 35104 NULL nohasharray
87617 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
87618 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
87619 +sys_semtimedop_4486 sys_semtimedop 3 4486 NULL
87620 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
87621 +osd_req_write_sg_50908 osd_req_write_sg 5 50908 NULL
87622 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
87623 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
87624 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
87625 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
87626 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
87627 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 NULL nohasharray
87628 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 &pwr_ps_enter_read_26935
87629 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
87630 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 NULL
87631 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
87632 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
87633 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
87634 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
87635 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
87636 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
87637 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
87638 +do_trimming_26952 do_trimming 3 26952 NULL
87639 +ath6kl_wmi_set_ie_cmd_37260 ath6kl_wmi_set_ie_cmd 6 37260 NULL
87640 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
87641 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
87642 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
87643 +alloc_buf_34532 alloc_buf 1 34532 NULL
87644 +sock_rmalloc_59740 sock_rmalloc 2 59740 NULL nohasharray
87645 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 &sock_rmalloc_59740
87646 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
87647 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
87648 +otp_read_10594 otp_read 2-4-5 10594 NULL
87649 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
87650 +sctp_manip_pkt_59749 sctp_manip_pkt 4 59749 NULL
87651 +icmp_manip_pkt_51560 icmp_manip_pkt 4 51560 NULL
87652 +brcmf_sdbrcm_read_control_22721 brcmf_sdbrcm_read_control 3 22721 NULL
87653 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
87654 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
87655 +roccat_common2_send_2422 roccat_common2_send 4 2422 NULL
87656 +ieee80211_auth_challenge_18810 ieee80211_auth_challenge 3 18810 NULL
87657 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
87658 +cxgb3_get_cpl_reply_skb_10620 cxgb3_get_cpl_reply_skb 2 10620 NULL
87659 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
87660 +venus_remove_59781 venus_remove 4 59781 NULL
87661 +ioremap_nocache_2439 ioremap_nocache 1-2 2439 NULL
87662 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
87663 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
87664 +tty_buffer_find_2443 tty_buffer_find 2 2443 NULL
87665 +xlog_do_recover_59789 xlog_do_recover 3 59789 NULL
87666 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
87667 +rfcomm_tty_write_51603 rfcomm_tty_write 3 51603 NULL
87668 +xenfb_write_43412 xenfb_write 3 43412 NULL
87669 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
87670 +nfs4_alloc_slots_2454 nfs4_alloc_slots 1 2454 NULL nohasharray
87671 +ath6kl_usb_bmi_write_2454 ath6kl_usb_bmi_write 3 2454 &nfs4_alloc_slots_2454
87672 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
87673 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
87674 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
87675 +gdm_wimax_netif_rx_43423 gdm_wimax_netif_rx 3 43423 &__alloc_bootmem_low_43423
87676 +rtllib_wx_set_gen_ie_59808 rtllib_wx_set_gen_ie 3 59808 NULL
87677 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
87678 +udp_manip_pkt_45467 udp_manip_pkt 4 45467 NULL
87679 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
87680 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
87681 +ni65_alloc_mem_10664 ni65_alloc_mem 3 10664 NULL
87682 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
87683 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
87684 +cmd_complete_51629 cmd_complete 6 51629 NULL
87685 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
87686 +btmrvl_txdnldready_read_413 btmrvl_txdnldready_read 3 413 NULL
87687 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
87688 +set_fd_set_35249 set_fd_set 1 35249 NULL
87689 +wiphy_new_2482 wiphy_new 2 2482 NULL
87690 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
87691 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
87692 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
87693 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
87694 +tcp_push_10680 tcp_push 3 10680 NULL
87695 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
87696 +c101_run_37279 c101_run 2 37279 NULL
87697 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
87698 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
87699 +tun_put_user_59849 tun_put_user 4 59849 NULL
87700 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
87701 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
87702 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
87703 +dm_write_2513 dm_write 3 2513 NULL
87704 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
87705 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
87706 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL
87707 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
87708 +ntfs_malloc_nofs_49572 ntfs_malloc_nofs 1 49572 NULL
87709 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
87710 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
87711 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
87712 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
87713 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
87714 +__iscsi_complete_pdu_10726 __iscsi_complete_pdu 4 10726 NULL
87715 +sfi_sysfs_install_table_51688 sfi_sysfs_install_table 1 51688 NULL
87716 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
87717 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
87718 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
87719 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
87720 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 NULL nohasharray
87721 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 &brcmf_sdio_forensic_read_35311
87722 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
87723 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL
87724 +compat_sys_msgsnd_10738 compat_sys_msgsnd 2 10738 NULL
87725 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
87726 +sel_write_access_51704 sel_write_access 3 51704 NULL
87727 +sys_syslog_10746 sys_syslog 3 10746 NULL
87728 +alloc_one_pg_vec_page_10747 alloc_one_pg_vec_page 1 10747 NULL
87729 +new_bind_ctl_35324 new_bind_ctl 2 35324 NULL
87730 +do_readlink_43518 do_readlink 2 43518 NULL
87731 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
87732 +gem_alloc_skb_51715 gem_alloc_skb 2 51715 NULL
87733 +fallback_on_nodma_alloc_35332 fallback_on_nodma_alloc 2 35332 NULL
87734 +read_file_reset_52310 read_file_reset 3 52310 NULL
87735 +pms_capture_27142 pms_capture 4 27142 NULL
87736 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
87737 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
87738 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
87739 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
87740 +msg_set_51725 msg_set 3 51725 NULL
87741 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
87742 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
87743 +hpi_alloc_control_cache_35351 hpi_alloc_control_cache 1 35351 NULL
87744 +hid_parse_report_51737 hid_parse_report 3 51737 NULL
87745 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
87746 +alc_auto_create_extra_outs_18975 alc_auto_create_extra_outs 2 18975 NULL
87747 +i2400m_net_rx_27170 i2400m_net_rx 5 27170 NULL
87748 +l3_alloc_skb_32289 l3_alloc_skb 1 32289 NULL
87749 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
87750 +ath_rx_init_43564 ath_rx_init 2 43564 NULL
87751 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 NULL nohasharray
87752 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 &il_dbgfs_rxon_flags_read_59950
87753 +sys_bind_10799 sys_bind 3 10799 NULL
87754 +_fc_frame_alloc_43568 _fc_frame_alloc 1 43568 NULL
87755 +nfcwilink_send_bts_cmd_10802 nfcwilink_send_bts_cmd 3 10802 NULL
87756 +ioremap_prot_51764 ioremap_prot 1-2 51764 NULL
87757 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
87758 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 2-3 33204 NULL
87759 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
87760 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
87761 +drm_vblank_init_11362 drm_vblank_init 2 11362 NULL
87762 +send_command_10832 send_command 4 10832 NULL
87763 +lro_gen_skb_2644 lro_gen_skb 6 2644 NULL
87764 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
87765 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
87766 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
87767 +proc_read_43614 proc_read 3 43614 NULL
87768 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
87769 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
87770 +drm_fb_helper_init_19044 drm_fb_helper_init 3-4 19044 NULL
87771 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
87772 +xlbd_reserve_minors_18365 xlbd_reserve_minors 1-2 18365 NULL
87773 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
87774 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
87775 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
87776 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
87777 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
87778 +vmalloc_15464 vmalloc 1 15464 NULL
87779 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
87780 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
87781 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
87782 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
87783 +cfpkt_add_trail_27260 cfpkt_add_trail 3 27260 NULL
87784 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
87785 +sys_sched_getaffinity_60033 sys_sched_getaffinity 2 60033 NULL
87786 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 NULL
87787 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
87788 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
87789 +adu_write_30487 adu_write 3 30487 NULL
87790 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
87791 +get_scq_10897 get_scq 2 10897 NULL
87792 +sys_process_vm_readv_19090 sys_process_vm_readv 3-5 19090 NULL nohasharray
87793 +brcmf_usbdev_qinit_19090 brcmf_usbdev_qinit 2 19090 &sys_process_vm_readv_19090
87794 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
87795 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
87796 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
87797 +load_module_60056 load_module 2 60056 NULL nohasharray
87798 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 &load_module_60056
87799 +__videobuf_alloc_cached_12740 __videobuf_alloc_cached 1 12740 NULL
87800 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
87801 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4-2 43679 NULL
87802 +ieee80211_build_probe_req_60064 ieee80211_build_probe_req 8-6 60064 NULL
87803 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
87804 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
87805 +__netdev_alloc_skb_ip_align_55067 __netdev_alloc_skb_ip_align 2 55067 NULL
87806 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
87807 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
87808 +__copy_from_user_10918 __copy_from_user 3 10918 NULL
87809 +user_read_51881 user_read 3 51881 NULL
87810 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
87811 +__xip_file_write_2733 __xip_file_write 4-3 2733 NULL
87812 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL
87813 +ath6kl_wmi_test_cmd_27312 ath6kl_wmi_test_cmd 3 27312 NULL
87814 +max77693_bulk_write_43698 max77693_bulk_write 3 43698 NULL
87815 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
87816 +hidp_send_ctrl_message_43702 hidp_send_ctrl_message 4 43702 NULL
87817 +async_setkey_35521 async_setkey 3 35521 NULL
87818 +set_dev_class_39645 set_dev_class 4 39645 NULL nohasharray
87819 +dm_exception_table_init_39645 dm_exception_table_init 2 39645 &set_dev_class_39645
87820 +cxgb4_pktgl_to_skb_61899 cxgb4_pktgl_to_skb 2 61899 NULL
87821 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
87822 +iio_read_first_n_sw_rb_51911 iio_read_first_n_sw_rb 2 51911 NULL
87823 +hid_report_raw_event_2762 hid_report_raw_event 4 2762 NULL
87824 +add_tty_40055 add_tty 1 40055 NULL nohasharray
87825 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 &add_tty_40055
87826 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
87827 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
87828 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
87829 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
87830 +ttm_bo_kmap_60118 ttm_bo_kmap 3-2 60118 NULL
87831 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
87832 +alloc_context_3194 alloc_context 1 3194 NULL
87833 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
87834 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
87835 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
87836 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
87837 +i915_min_freq_write_10981 i915_min_freq_write 3 10981 NULL
87838 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
87839 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
87840 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
87841 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
87842 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
87843 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
87844 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
87845 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
87846 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
87847 +init_state_60165 init_state 2 60165 NULL
87848 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
87849 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
87850 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3 19214 NULL
87851 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
87852 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
87853 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
87854 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
87855 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
87856 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
87857 +calc_hmac_32010 calc_hmac 3 32010 NULL
87858 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
87859 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
87860 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1 43806 NULL
87861 +kernel_readv_35617 kernel_readv 3 35617 NULL
87862 +hci_send_cmd_43810 hci_send_cmd 3 43810 NULL
87863 +sys_lgetxattr_45531 sys_lgetxattr 4 45531 NULL
87864 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
87865 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
87866 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
87867 +dccp_manip_pkt_476 dccp_manip_pkt 4 476 NULL
87868 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
87869 +set_tap_pfs_60203 set_tap_pfs 3 60203 NULL
87870 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
87871 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
87872 +carl9170_handle_mpdu_11056 carl9170_handle_mpdu 3 11056 NULL
87873 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
87874 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
87875 +vxge_rx_alloc_52024 vxge_rx_alloc 3 52024 NULL
87876 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
87877 +__ip_append_data_16864 __ip_append_data 8-9 16864 NULL
87878 +p54_download_eeprom_43842 p54_download_eeprom 4 43842 NULL
87879 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
87880 +store_debug_level_35652 store_debug_level 3 35652 NULL
87881 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
87882 +read_flush_43851 read_flush 3 43851 NULL
87883 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
87884 +cmm_write_2896 cmm_write 3 2896 NULL
87885 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
87886 +io_mapping_map_wc_19284 io_mapping_map_wc 2 19284 NULL
87887 +tunables_write_59563 tunables_write 3 59563 NULL
87888 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
87889 +rtsx_write_cfg_seq_27485 rtsx_write_cfg_seq 5-3 27485 NULL
87890 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
87891 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
87892 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
87893 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
87894 +dm_table_create_35687 dm_table_create 3 35687 NULL
87895 +qib_create_cq_27497 qib_create_cq 2 27497 NULL
87896 +nfc_hci_execute_cmd_43882 nfc_hci_execute_cmd 5 43882 NULL
87897 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
87898 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
87899 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
87900 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
87901 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
87902 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
87903 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
87904 +debug_read_19322 debug_read 3 19322 NULL
87905 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
87906 +__pskb_pull_tail_60287 __pskb_pull_tail 2 60287 NULL
87907 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
87908 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL
87909 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
87910 +dn_nsp_return_disc_60296 dn_nsp_return_disc 2 60296 NULL
87911 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
87912 +prism2_sta_send_mgmt_43916 prism2_sta_send_mgmt 5 43916 NULL
87913 +mgmt_device_found_14146 mgmt_device_found 10 14146 NULL
87914 +snd_seq_oss_readq_new_14283 snd_seq_oss_readq_new 2 14283 NULL
87915 +doc_probe_23285 doc_probe 1 23285 NULL
87916 +ppp_cp_event_2965 ppp_cp_event 6 2965 NULL
87917 +SendString_43928 SendString 3 43928 NULL
87918 +acpi_os_map_memory_11161 acpi_os_map_memory 1-2 11161 NULL
87919 +ceph_parse_server_name_60318 ceph_parse_server_name 2 60318 NULL
87920 +retry_count_read_52129 retry_count_read 3 52129 NULL
87921 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
87922 +ioat2_alloc_ring_11172 ioat2_alloc_ring 2 11172 NULL
87923 +read_zero_19366 read_zero 3 19366 NULL
87924 +bch_alloc_4593 bch_alloc 1 4593 NULL
87925 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
87926 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
87927 +libipw_alloc_txb_27579 libipw_alloc_txb 1-2-3 27579 NULL
87928 +raid5_resize_63306 raid5_resize 2 63306 NULL
87929 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
87930 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
87931 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
87932 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
87933 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
87934 +depth_write_3021 depth_write 3 3021 NULL
87935 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
87936 +read_file_stations_35795 read_file_stations 3 35795 NULL
87937 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
87938 +tipc_cfg_reply_alloc_27606 tipc_cfg_reply_alloc 1 27606 NULL
87939 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 NULL
87940 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
87941 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 5 60379 NULL
87942 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 NULL
87943 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
87944 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
87945 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
87946 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
87947 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
87948 +driver_names_read_60399 driver_names_read 3 60399 NULL
87949 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL
87950 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
87951 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
87952 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
87953 +_alloc_mISDN_skb_52232 _alloc_mISDN_skb 3 52232 NULL
87954 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
87955 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
87956 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
87957 +do_dmabuf_dirty_ldu_52241 do_dmabuf_dirty_ldu 6 52241 NULL
87958 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
87959 +rx_data_60442 rx_data 4 60442 NULL
87960 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
87961 +efivar_create_sysfs_entry_19485 efivar_create_sysfs_entry 2 19485 NULL
87962 +tcf_csum_ipv4_igmp_60446 tcf_csum_ipv4_igmp 3 60446 NULL
87963 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
87964 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
87965 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
87966 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
87967 +__tty_buffer_request_room_27700 __tty_buffer_request_room 2 27700 NULL
87968 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
87969 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
87970 +tcp_mark_head_lost_35895 tcp_mark_head_lost 2 35895 NULL
87971 +skb_realloc_headroom_19516 skb_realloc_headroom 2 19516 NULL
87972 +atm_alloc_charge_19517 atm_alloc_charge 2 19517 NULL nohasharray
87973 +dev_alloc_skb_19517 dev_alloc_skb 1 19517 &atm_alloc_charge_19517
87974 +construct_key_11329 construct_key 3 11329 NULL
87975 +evm_write_key_27715 evm_write_key 3 27715 NULL
87976 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
87977 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
87978 +filldir_55137 filldir 3 55137 NULL
87979 +igmpv3_newpack_35912 igmpv3_newpack 2 35912 NULL
87980 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
87981 +reg_w_buf_27724 reg_w_buf 3 27724 NULL
87982 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
87983 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
87984 +a4t_cs_init_27734 a4t_cs_init 3 27734 NULL
87985 +sel_write_create_11353 sel_write_create 3 11353 NULL
87986 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
87987 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
87988 +hwflags_read_52318 hwflags_read 3 52318 NULL
87989 +nfc_alloc_send_skb_3167 nfc_alloc_send_skb 4 3167 NULL
87990 +batadv_skb_head_push_11360 batadv_skb_head_push 2 11360 NULL
87991 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
87992 +vmw_gmr_bind_44130 vmw_gmr_bind 3 44130 NULL
87993 +ath_tx_init_60515 ath_tx_init 2 60515 NULL
87994 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
87995 +ntfs_rl_split_52328 ntfs_rl_split 2-4 52328 NULL
87996 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
87997 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
87998 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
87999 +nfsd_read_19568 nfsd_read 5 19568 NULL
88000 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
88001 +hysdn_sched_rx_60533 hysdn_sched_rx 3 60533 NULL
88002 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
88003 +kcalloc_27770 kcalloc 1-2 27770 NULL
88004 +shmem_pread_slow_3198 shmem_pread_slow 3 3198 NULL
88005 +bm_status_read_19583 bm_status_read 3 19583 NULL
88006 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
88007 +zd_mac_rx_38296 zd_mac_rx 3 38296 NULL
88008 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
88009 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL
88010 +acl_alloc_35979 acl_alloc 1 35979 NULL
88011 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
88012 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
88013 +str_to_user_11411 str_to_user 2 11411 NULL
88014 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
88015 +koneplus_sysfs_write_35993 koneplus_sysfs_write 6 35993 NULL
88016 +trace_options_read_11419 trace_options_read 3 11419 NULL
88017 +ttm_object_file_init_27804 ttm_object_file_init 2 27804 NULL
88018 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
88019 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
88020 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
88021 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
88022 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
88023 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
88024 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
88025 +console_store_36007 console_store 4 36007 NULL
88026 +bttv_read_11432 bttv_read 3 11432 NULL
88027 +key_key_read_3241 key_key_read 3 3241 NULL
88028 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
88029 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
88030 +__feat_register_sp_64712 __feat_register_sp 6 64712 NULL
88031 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
88032 +check_vendor_extension_3254 check_vendor_extension 1 3254 NULL
88033 +ieee80211_amsdu_to_8023s_15561 ieee80211_amsdu_to_8023s 5 15561 NULL
88034 +sys_listxattr_27833 sys_listxattr 3 27833 NULL
88035 +aac_rx_ioremap_52410 aac_rx_ioremap 2 52410 NULL
88036 +ubi_eba_write_leb_36029 ubi_eba_write_leb 5-6 36029 NULL
88037 +um_idi_write_18293 um_idi_write 3 18293 NULL
88038 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
88039 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
88040 +usbvision_rvmalloc_19655 usbvision_rvmalloc 1 19655 NULL
88041 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
88042 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
88043 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
88044 +sys_init_module_36047 sys_init_module 2 36047 NULL
88045 +read_profile_27859 read_profile 3 27859 NULL
88046 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
88047 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
88048 +enlarge_skb_44248 enlarge_skb 2 44248 NULL nohasharray
88049 +xfs_buf_readahead_map_44248 xfs_buf_readahead_map 3 44248 &enlarge_skb_44248
88050 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
88051 +refill_pool_19477 refill_pool 2 19477 NULL
88052 +ubifs_recover_leb_60639 ubifs_recover_leb 3 60639 NULL
88053 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
88054 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
88055 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
88056 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
88057 +tcp_sacktag_walk_49703 tcp_sacktag_walk 6 49703 NULL
88058 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
88059 +arvo_sysfs_write_3311 arvo_sysfs_write 6 3311 NULL
88060 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
88061 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
88062 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
88063 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
88064 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
88065 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1-2 52477 NULL
88066 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
88067 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
88068 +venus_symlink_23570 venus_symlink 4-6 23570 NULL
88069 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
88070 +aac_rkt_ioremap_3333 aac_rkt_ioremap 2 3333 NULL
88071 +sctp_make_init_ack_3335 sctp_make_init_ack 4 3335 NULL
88072 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
88073 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
88074 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
88075 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
88076 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
88077 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
88078 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
88079 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
88080 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
88081 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
88082 +ath6kl_usb_ctrl_msg_exchange_33327 ath6kl_usb_ctrl_msg_exchange 4 33327 NULL
88083 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
88084 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
88085 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
88086 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
88087 +vmalloc_exec_36132 vmalloc_exec 1 36132 NULL
88088 +init_data_container_60709 init_data_container 1 60709 NULL
88089 +p9_client_read_19750 p9_client_read 5 19750 NULL
88090 +skb_cow_data_11565 skb_cow_data 2 11565 NULL
88091 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
88092 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
88093 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
88094 +mlx4_init_cmpt_table_11569 mlx4_init_cmpt_table 3 11569 NULL
88095 +iwl_trans_txq_alloc_36147 iwl_trans_txq_alloc 3 36147 NULL
88096 +alloc_vm_area_36149 alloc_vm_area 1 36149 NULL
88097 +ubi_eba_write_leb_st_44343 ubi_eba_write_leb_st 5 44343 NULL
88098 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
88099 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
88100 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
88101 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
88102 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
88103 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
88104 +saa7146_vmalloc_build_pgtable_19780 saa7146_vmalloc_build_pgtable 2 19780 NULL
88105 +send_stream_3397 send_stream 4 3397 NULL
88106 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
88107 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
88108 +ipx_recvmsg_44366 ipx_recvmsg 4 44366 NULL
88109 +hycapi_rx_capipkt_11602 hycapi_rx_capipkt 3 11602 NULL
88110 +msix_map_region_3411 msix_map_region 3 3411 NULL
88111 +sys_kexec_load_14222 sys_kexec_load 2 14222 NULL
88112 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
88113 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
88114 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
88115 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
88116 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
88117 +opticon_write_60775 opticon_write 4 60775 NULL
88118 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
88119 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
88120 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
88121 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
88122 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
88123 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
88124 +vip_read_19832 vip_read 3 19832 NULL
88125 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
88126 +llc_shdlc_alloc_skb_11645 llc_shdlc_alloc_skb 2 11645 NULL
88127 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
88128 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
88129 +nfqnl_mangle_36226 nfqnl_mangle 4-2 36226 NULL
88130 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
88131 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
88132 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
88133 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
88134 +alloc_skb_fclone_3467 alloc_skb_fclone 1 3467 NULL
88135 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
88136 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
88137 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2 28053 NULL
88138 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
88139 +llcp_allocate_pdu_19866 llcp_allocate_pdu 3 19866 NULL
88140 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
88141 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
88142 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
88143 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
88144 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
88145 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
88146 +split_11691 split 2 11691 NULL
88147 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
88148 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
88149 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
88150 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL
88151 +__kfifo_alloc_22173 __kfifo_alloc 2-3 22173 NULL
88152 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
88153 +gdth_init_isa_28091 gdth_init_isa 1 28091 NULL
88154 +readahead_tree_block_36285 readahead_tree_block 3 36285 NULL
88155 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL nohasharray
88156 +ieee80211_wx_set_gen_ie_rsl_3521 ieee80211_wx_set_gen_ie_rsl 3 3521 &mem_tx_free_mem_blks_read_3521
88157 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
88158 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
88159 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
88160 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
88161 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
88162 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
88163 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
88164 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 NULL
88165 +tcf_csum_ipv6_icmp_11738 tcf_csum_ipv6_icmp 4 11738 NULL
88166 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
88167 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
88168 +spidev_write_44510 spidev_write 3 44510 NULL
88169 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
88170 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
88171 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
88172 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
88173 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
88174 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
88175 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
88176 +kone_receive_4690 kone_receive 4 4690 NULL
88177 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
88178 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
88179 +evtchn_read_3569 evtchn_read 3 3569 NULL
88180 +video_read_28148 video_read 3 28148 NULL
88181 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
88182 +sys_msgsnd_44537 sys_msgsnd 3 44537 NULL nohasharray
88183 +comm_write_44537 comm_write 3 44537 &sys_msgsnd_44537
88184 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
88185 +ax25_send_frame_19964 ax25_send_frame 2 19964 NULL
88186 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
88187 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
88188 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
88189 +vc_resize_3585 vc_resize 2-3 3585 NULL
88190 +gluebi_write_27905 gluebi_write 3 27905 NULL
88191 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
88192 +c4iw_reject_cr_28174 c4iw_reject_cr 3 28174 NULL
88193 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
88194 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
88195 +compat_sys_semtimedop_3606 compat_sys_semtimedop 3 3606 NULL
88196 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
88197 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
88198 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
88199 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
88200 +pti_char_write_60960 pti_char_write 3 60960 NULL
88201 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
88202 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
88203 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
88204 +read_vbt_r10_60679 read_vbt_r10 1 60679 NULL
88205 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
88206 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
88207 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL nohasharray
88208 +fwnet_pd_new_39947 fwnet_pd_new 4 39947 &error_error_frame_read_39947
88209 +snd_pcm_alloc_vmalloc_buffer_44595 snd_pcm_alloc_vmalloc_buffer 2 44595 NULL
88210 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
88211 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
88212 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
88213 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
88214 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
88215 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
88216 +cm_copy_private_data_3649 cm_copy_private_data 2 3649 NULL
88217 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
88218 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 NULL nohasharray
88219 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 &ieee80211_if_read_auto_open_plinks_38268
88220 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL
88221 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
88222 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
88223 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
88224 +cfpkt_add_body_44630 cfpkt_add_body 3 44630 NULL
88225 +nf_nat_sdp_media_11863 nf_nat_sdp_media 9 11863 NULL
88226 +alloc_extent_buffer_52824 alloc_extent_buffer 3 52824 NULL
88227 +skb_cow_head_52495 skb_cow_head 2 52495 NULL
88228 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
88229 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
88230 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
88231 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
88232 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
88233 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
88234 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
88235 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
88236 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
88237 +btmrvl_psmode_write_3703 btmrvl_psmode_write 3 3703 NULL
88238 +symtab_init_61050 symtab_init 2 61050 NULL
88239 +team_options_register_20091 team_options_register 3 20091 NULL
88240 +videobuf_pages_to_sg_3708 videobuf_pages_to_sg 2 3708 NULL
88241 +mon_bin_get_event_52863 mon_bin_get_event 4 52863 NULL
88242 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
88243 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
88244 +mpi_resize_44674 mpi_resize 2 44674 NULL
88245 +ip6_append_data_36490 ip6_append_data 4-5 36490 NULL nohasharray
88246 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
88247 +kmalloc_slab_11917 kmalloc_slab 1 11917 NULL
88248 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
88249 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
88250 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
88251 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
88252 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
88253 +xfs_trans_read_buf_map_37487 xfs_trans_read_buf_map 5 37487 NULL
88254 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
88255 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
88256 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
88257 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL
88258 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
88259 +dccp_feat_clone_sp_val_11942 dccp_feat_clone_sp_val 3 11942 NULL
88260 +pms_read_53873 pms_read 3 53873 NULL
88261 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
88262 +get_derived_key_61100 get_derived_key 4 61100 NULL
88263 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
88264 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
88265 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
88266 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
88267 +dm_read_15674 dm_read 3 15674 NULL
88268 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
88269 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
88270 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
88271 +kone_send_63435 kone_send 4 63435 NULL
88272 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
88273 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
88274 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
88275 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
88276 +__kfifo_to_user_36555 __kfifo_to_user 3 36555 NULL nohasharray
88277 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
88278 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
88279 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
88280 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
88281 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
88282 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
88283 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
88284 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
88285 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
88286 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
88287 +send_packet_52960 send_packet 4 52960 NULL
88288 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
88289 +ssb_bus_scan_36578 ssb_bus_scan 2 36578 NULL
88290 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
88291 +tipc_port_reject_sections_55229 tipc_port_reject_sections 5 55229 NULL
88292 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
88293 +set_bypass_pfs_28395 set_bypass_pfs 3 28395 NULL
88294 +put_cmsg_36589 put_cmsg 4 36589 NULL
88295 +__vmalloc_61168 __vmalloc 1 61168 NULL
88296 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
88297 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
88298 +read_file_tx_chainmask_3829 read_file_tx_chainmask 3 3829 NULL
88299 +pcnet32_realloc_rx_ring_36598 pcnet32_realloc_rx_ring 3 36598 NULL
88300 +event_oom_late_read_61175 event_oom_late_read 3 61175 NULL nohasharray
88301 +pair_device_61175 pair_device 4 61175 &event_oom_late_read_61175
88302 +sys_lsetxattr_61177 sys_lsetxattr 4 61177 NULL
88303 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
88304 +nfs4_alloc_pages_48426 nfs4_alloc_pages 1 48426 NULL
88305 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
88306 +batadv_check_management_packet_52993 batadv_check_management_packet 3 52993 NULL
88307 +tpci200_slot_map_space_3848 tpci200_slot_map_space 2 3848 NULL
88308 +regmap_bulk_write_59049 regmap_bulk_write 4 59049 NULL
88309 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
88310 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
88311 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
88312 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
88313 +cfpkt_append_61206 cfpkt_append 3 61206 NULL
88314 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
88315 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
88316 +get_fd_set_3866 get_fd_set 1 3866 NULL
88317 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
88318 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
88319 +unlink_queued_645 unlink_queued 3-4 645 NULL
88320 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
88321 +sisusb_write_44834 sisusb_write 3 44834 NULL
88322 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
88323 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
88324 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
88325 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
88326 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
88327 +uea_send_modem_cmd_3888 uea_send_modem_cmd 3 3888 NULL
88328 +h5_prepare_pkt_12085 h5_prepare_pkt 4 12085 NULL
88329 +nvram_write_3894 nvram_write 3 3894 NULL
88330 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
88331 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
88332 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
88333 +vcs_write_3910 vcs_write 3 3910 NULL
88334 +sctp_make_abort_violation_27959 sctp_make_abort_violation 4 27959 NULL
88335 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
88336 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
88337 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL
88338 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
88339 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
88340 +do_tty_write_44896 do_tty_write 5 44896 NULL
88341 +set_powered_12129 set_powered 4 12129 NULL
88342 +qib_resize_cq_53090 qib_resize_cq 2 53090 NULL
88343 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
88344 +nfs_writedata_alloc_12133 nfs_writedata_alloc 2 12133 NULL
88345 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
88346 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
88347 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
88348 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
88349 +vmw_fifo_reserve_12141 vmw_fifo_reserve 2 12141 NULL
88350 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
88351 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
88352 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
88353 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
88354 +capinc_tty_write_28539 capinc_tty_write 3 28539 NULL
88355 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
88356 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL
88357 +line6_dumpreq_initbuf_53123 line6_dumpreq_initbuf 3 53123 NULL
88358 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4 36740 NULL
88359 +gather_array_56641 gather_array 3 56641 NULL
88360 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
88361 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
88362 +dma_memcpy_to_iovec_12173 dma_memcpy_to_iovec 5 12173 NULL
88363 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
88364 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
88365 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
88366 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
88367 +regcache_rbtree_insert_to_block_58009 regcache_rbtree_insert_to_block 5 58009 NULL
88368 +do_add_counters_3992 do_add_counters 3 3992 NULL
88369 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
88370 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
88371 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
88372 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
88373 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
88374 +ip4ip6_err_36772 ip4ip6_err 5 36772 NULL
88375 +mei_write_4005 mei_write 3 4005 NULL
88376 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
88377 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
88378 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL
88379 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
88380 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
88381 +receive_copy_12216 receive_copy 3 12216 NULL
88382 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 NULL
88383 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
88384 +bcsp_prepare_pkt_12961 bcsp_prepare_pkt 3 12961 NULL
88385 +ftdi_process_packet_45005 ftdi_process_packet 5 45005 NULL
88386 +change_xattr_61390 change_xattr 5 61390 NULL
88387 +find_skb_20431 find_skb 2 20431 NULL
88388 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
88389 +fmc_send_cmd_20435 fmc_send_cmd 5 20435 NULL
88390 +tcp_fragment_20436 tcp_fragment 3 20436 NULL
88391 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
88392 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
88393 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
88394 +sys_sethostname_42962 sys_sethostname 2 42962 NULL
88395 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
88396 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
88397 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
88398 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
88399 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
88400 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
88401 +sctp_make_asconf_4078 sctp_make_asconf 3 4078 NULL
88402 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
88403 +ip_vs_icmp_xmit_v6_20464 ip_vs_icmp_xmit_v6 4 20464 NULL
88404 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
88405 +read_buf_20469 read_buf 2 20469 NULL
88406 +cm_write_36858 cm_write 3 36858 NULL
88407 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
88408 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
88409 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 NULL
88410 +sel_write_user_45060 sel_write_user 3 45060 NULL
88411 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
88412 +__dev_alloc_skb_28681 __dev_alloc_skb 1 28681 NULL
88413 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
88414 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
88415 +fast_user_write_20494 fast_user_write 5 20494 NULL
88416 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
88417 +sctp_make_fwdtsn_53265 sctp_make_fwdtsn 3 53265 NULL
88418 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
88419 +hidraw_report_event_20503 hidraw_report_event 3 20503 NULL
88420 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
88421 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
88422 +lirc_buffer_init_53282 lirc_buffer_init 3-2 53282 NULL
88423 +tipc_msg_build_12326 tipc_msg_build 4 12326 NULL
88424 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
88425 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
88426 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
88427 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
88428 +osst_read_40237 osst_read 3 40237 NULL
88429 +tm6000_read_4151 tm6000_read 3 4151 NULL
88430 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
88431 +usbdev_read_45114 usbdev_read 3 45114 NULL
88432 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
88433 +spi_execute_28736 spi_execute 5 28736 NULL
88434 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
88435 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
88436 +get_alua_req_4166 get_alua_req 3 4166 NULL
88437 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
88438 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
88439 +venus_create_20555 venus_create 4 20555 NULL
88440 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
88441 +batadv_interface_rx_53325 batadv_interface_rx 4 53325 NULL
88442 +receive_packet_12367 receive_packet 2 12367 NULL
88443 +squashfs_cache_init_41656 squashfs_cache_init 2 41656 NULL
88444 +mem_write_22232 mem_write 3 22232 NULL
88445 +read_file_bool_4180 read_file_bool 3 4180 NULL
88446 +send_to_tty_45141 send_to_tty 3 45141 NULL
88447 +fops_read_40672 fops_read 3 40672 NULL
88448 +cxio_init_resource_fifo_28764 cxio_init_resource_fifo 3 28764 NULL
88449 +write_leb_36957 write_leb 5 36957 NULL
88450 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
88451 +device_write_45156 device_write 3 45156 NULL
88452 +i915_max_freq_read_20581 i915_max_freq_read 3 20581 NULL
88453 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
88454 +sparse_early_mem_maps_alloc_node_36971 sparse_early_mem_maps_alloc_node 4 36971 NULL
88455 +batadv_tt_append_diff_20588 batadv_tt_append_diff 4 20588 NULL
88456 +dvb_net_sec_callback_28786 dvb_net_sec_callback 2 28786 NULL
88457 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
88458 +isp1760_register_628 isp1760_register 1-2 628 NULL
88459 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
88460 +lirc_write_20604 lirc_write 3 20604 NULL
88461 +sel_write_member_28800 sel_write_member 3 28800 NULL
88462 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
88463 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
88464 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
88465 +sys_msgrcv_959 sys_msgrcv 3 959 NULL
88466 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL
88467 +pskb_network_may_pull_35336 pskb_network_may_pull 2 35336 NULL
88468 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
88469 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
88470 +setxattr_37006 setxattr 4 37006 NULL
88471 +add_child_45201 add_child 4 45201 NULL
88472 +seq_open_private_61589 seq_open_private 3 61589 NULL
88473 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
88474 +__get_vm_area_61599 __get_vm_area 1 61599 NULL
88475 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
88476 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
88477 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3 20646 NULL
88478 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
88479 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
88480 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
88481 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
88482 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
88483 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL
88484 +ieee80211_rx_bss_info_61630 ieee80211_rx_bss_info 3 61630 NULL
88485 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
88486 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
88487 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
88488 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
88489 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
88490 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 4 20682 NULL
88491 +get_packet_pg_28023 get_packet_pg 4 28023 NULL
88492 +rtllib_auth_challenge_12493 rtllib_auth_challenge 3 12493 NULL
88493 +acpi_tb_parse_root_table_53455 acpi_tb_parse_root_table 1 53455 NULL
88494 +resize_stripes_61650 resize_stripes 2 61650 NULL
88495 +n2_run_53459 n2_run 3 53459 NULL
88496 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
88497 +parse_command_37079 parse_command 2 37079 NULL
88498 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
88499 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
88500 +ttm_page_pool_free_61661 ttm_page_pool_free 2 61661 NULL
88501 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
88502 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
88503 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
88504 +insert_one_name_61668 insert_one_name 7 61668 NULL
88505 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
88506 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
88507 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
88508 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
88509 +lock_loop_61681 lock_loop 1 61681 NULL
88510 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
88511 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
88512 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
88513 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
88514 +vring_add_indirect_20737 vring_add_indirect 3-4 20737 NULL
88515 +push_rx_28939 push_rx 3 28939 NULL
88516 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3 4365 NULL
88517 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
88518 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
88519 +sys_setdomainname_4373 sys_setdomainname 2 4373 NULL
88520 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
88521 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
88522 +nouveau_dmaobj_create__61730 nouveau_dmaobj_create_ 6 61730 NULL
88523 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3 28963 NULL
88524 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
88525 +aac_srcv_ioremap_6659 aac_srcv_ioremap 2 6659 NULL
88526 +ubi_leb_change_10289 ubi_leb_change 4 10289 NULL
88527 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
88528 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
88529 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
88530 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
88531 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
88532 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL
88533 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
88534 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
88535 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL
88536 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
88537 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
88538 +tstats_write_60432 tstats_write 3 60432 NULL nohasharray
88539 +kmalloc_60432 kmalloc 1 60432 &tstats_write_60432
88540 +bin_uuid_28999 bin_uuid 3 28999 NULL
88541 +sys_sendto_20809 sys_sendto 6 20809 NULL
88542 +alloc_page_cgroup_2919 alloc_page_cgroup 1 2919 NULL
88543 +set_registers_53582 set_registers 3 53582 NULL
88544 +fc_fcp_frame_alloc_12624 fc_fcp_frame_alloc 2 12624 NULL
88545 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
88546 +lane2_associate_req_45398 lane2_associate_req 4 45398 NULL
88547 +tcf_csum_ipv4_udp_30777 tcf_csum_ipv4_udp 4 30777 NULL
88548 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
88549 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2 37213 NULL
88550 +keymap_store_45406 keymap_store 4 45406 NULL
88551 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
88552 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
88553 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
88554 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
88555 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
88556 +xz_dec_init_29029 xz_dec_init 2 29029 NULL
88557 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
88558 +tcp_dma_try_early_copy_4457 tcp_dma_try_early_copy 3 4457 NULL
88559 +__do_replace_37227 __do_replace 5 37227 NULL
88560 +dn_alloc_send_pskb_4465 dn_alloc_send_pskb 2 4465 NULL
88561 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
88562 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
88563 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
88564 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
88565 +tso_fragment_29050 tso_fragment 3 29050 NULL
88566 +__alloc_pred_stack_26687 __alloc_pred_stack 2 26687 NULL
88567 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
88568 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
88569 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
88570 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
88571 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
88572 +__iio_allocate_sw_ring_buffer_4843 __iio_allocate_sw_ring_buffer 3 4843 NULL
88573 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
88574 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
88575 +intel_render_ring_init_dri_45446 intel_render_ring_init_dri 2-3 45446 NULL
88576 +udp_sendmsg_4492 udp_sendmsg 4 4492 NULL
88577 +ieee80211_probereq_get_29069 ieee80211_probereq_get 4-6 29069 NULL
88578 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
88579 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
88580 +_alloc_cdb_cont_23609 _alloc_cdb_cont 2 23609 NULL
88581 +set_link_security_4502 set_link_security 4 4502 NULL
88582 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
88583 +l1oip_socket_parse_4507 l1oip_socket_parse 4 4507 NULL
88584 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
88585 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
88586 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
88587 +srp_target_alloc_37288 srp_target_alloc 3 37288 NULL
88588 +mmio_read_40348 mmio_read 4 40348 NULL
88589 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
88590 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
88591 +compat_sys_readv_20911 compat_sys_readv 3 20911 NULL
88592 +ivtv_write_12721 ivtv_write 3 12721 NULL
88593 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4 53682 NULL
88594 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
88595 +sys_llistxattr_4532 sys_llistxattr 3 4532 NULL
88596 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
88597 +da9052_group_write_4534 da9052_group_write 3 4534 NULL
88598 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
88599 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
88600 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
88601 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
88602 +videobuf_vmalloc_to_sg_4548 videobuf_vmalloc_to_sg 2 4548 NULL
88603 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
88604 +ieee80211_rtl_auth_challenge_61897 ieee80211_rtl_auth_challenge 3 61897 NULL
88605 +send_msg_37323 send_msg 4 37323 NULL
88606 +brcmf_sdbrcm_membytes_37324 brcmf_sdbrcm_membytes 3-5 37324 NULL
88607 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
88608 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
88609 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
88610 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
88611 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
88612 +virtqueue_add_buf_59470 virtqueue_add_buf 3-4 59470 NULL
88613 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
88614 +dsp_buffer_alloc_11684 dsp_buffer_alloc 2 11684 NULL
88615 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
88616 +reshape_ring_29147 reshape_ring 2 29147 NULL
88617 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
88618 +au0828_init_isoc_61917 au0828_init_isoc 3-2 61917 NULL
88619 +copy_macs_45534 copy_macs 4 45534 NULL
88620 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
88621 +listxattr_12769 listxattr 3 12769 NULL
88622 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
88623 +wdm_write_53735 wdm_write 3 53735 NULL
88624 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
88625 +send_bulk_static_data_61932 send_bulk_static_data 3 61932 NULL
88626 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
88627 +mempool_create_29437 mempool_create 1 29437 NULL
88628 +platform_create_bundle_12785 platform_create_bundle 4-6 12785 NULL
88629 +brcmf_tx_frame_20978 brcmf_tx_frame 3 20978 NULL
88630 +sock_alloc_send_pskb_21246 sock_alloc_send_pskb 2 21246 NULL
88631 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
88632 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
88633 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
88634 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
88635 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL
88636 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
88637 +mgmt_event_12810 mgmt_event 4 12810 NULL
88638 +ntfs_rl_realloc_nofail_32173 ntfs_rl_realloc_nofail 3 32173 NULL
88639 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
88640 +ipath_create_cq_45586 ipath_create_cq 2 45586 NULL
88641 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL nohasharray
88642 +alloc_group_attrs_29203 alloc_group_attrs 3 29203 &wusb_prf_256_29203
88643 +comedi_alloc_subdevices_29207 comedi_alloc_subdevices 2 29207 NULL
88644 +rdma_set_ib_paths_45592 rdma_set_ib_paths 3 45592 NULL
88645 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
88646 +rds_iw_inc_copy_to_user_29214 rds_iw_inc_copy_to_user 3 29214 NULL
88647 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
88648 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
88649 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
88650 +virtnet_send_command_61993 virtnet_send_command 5-6 61993 NULL
88651 +sys_getxattr_37418 sys_getxattr 4 37418 NULL
88652 +regmap_raw_write_53803 regmap_raw_write 4 53803 NULL
88653 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
88654 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
88655 +t4vf_pktgl_to_skb_39005 t4vf_pktgl_to_skb 2 39005 NULL
88656 +audit_log_n_hex_45617 audit_log_n_hex 3 45617 NULL
88657 +devm_ioremap_29235 devm_ioremap 2-3 29235 NULL
88658 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
88659 +recover_peb_29238 recover_peb 6-7 29238 NULL
88660 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
88661 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
88662 +i915_gem_execbuffer_relocate_slow_25355 i915_gem_execbuffer_relocate_slow 7 25355 NULL
88663 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
88664 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
88665 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
88666 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
88667 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
88668 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
88669 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
88670 +ppp_tx_cp_62044 ppp_tx_cp 5 62044 NULL
88671 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
88672 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
88673 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
88674 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
88675 +do_pselect_62061 do_pselect 1 62061 NULL
88676 +btmrvl_gpiogap_read_4718 btmrvl_gpiogap_read 3 4718 NULL
88677 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
88678 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
88679 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
88680 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
88681 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
88682 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
88683 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
88684 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
88685 +sg_read_25799 sg_read 3 25799 NULL
88686 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
88687 +ci_ll_init_12930 ci_ll_init 3 12930 NULL
88688 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL
88689 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
88690 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
88691 +vmalloc_32_user_37519 vmalloc_32_user 1 37519 NULL
88692 +fd_do_writev_29329 fd_do_writev 3 29329 NULL
88693 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
88694 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
88695 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
88696 +dvb_ca_en50221_init_45718 dvb_ca_en50221_init 4 45718 NULL
88697 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
88698 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
88699 +new_skb_21148 new_skb 1 21148 NULL
88700 +ath6kl_mgmt_tx_21153 ath6kl_mgmt_tx 9 21153 NULL
88701 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
88702 +bm_status_write_12964 bm_status_write 3 12964 NULL
88703 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
88704 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
88705 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
88706 +ip6_ufo_append_data_4780 ip6_ufo_append_data 5-6-7 4780 NULL
88707 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL nohasharray
88708 +nf_nat_mangle_tcp_packet_37551 nf_nat_mangle_tcp_packet 6-8 37551 &sep_create_dcb_dmatables_context_37551
88709 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
88710 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3 45748 NULL nohasharray
88711 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
88712 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
88713 +gnttab_expand_15817 gnttab_expand 1 15817 NULL
88714 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
88715 +sctp_make_chunk_12986 sctp_make_chunk 4 12986 NULL
88716 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
88717 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
88718 +mthca_setup_cmd_doorbells_53954 mthca_setup_cmd_doorbells 2 53954 NULL
88719 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
88720 +video_usercopy_62151 video_usercopy 2 62151 NULL
88721 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
88722 +repair_io_failure_4815 repair_io_failure 4 4815 NULL
88723 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
88724 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
88725 +bnx2i_send_nl_mesg_53353 bnx2i_send_nl_mesg 4 53353 NULL
88726 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
88727 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
88728 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
88729 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL
88730 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
88731 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
88732 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
88733 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
88734 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
88735 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
88736 +input_ff_create_21240 input_ff_create 2 21240 NULL
88737 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
88738 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
88739 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL
88740 +amthi_read_45831 amthi_read 4 45831 NULL
88741 +cmpk_message_handle_tx_54024 cmpk_message_handle_tx 4 54024 NULL
88742 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
88743 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
88744 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
88745 +sys_ipc_4889 sys_ipc 3 4889 NULL
88746 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
88747 +smp_build_cmd_45853 smp_build_cmd 3 45853 NULL
88748 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
88749 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
88750 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
88751 +do_register_entry_29478 do_register_entry 4 29478 NULL
88752 +isdn_write_45863 isdn_write 3 45863 NULL
88753 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
88754 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
88755 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
88756 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
88757 +vmw_gmr2_bind_21305 vmw_gmr2_bind 3 21305 NULL
88758 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
88759 +_malloc_54077 _malloc 1 54077 NULL
88760 +add_res_range_21310 add_res_range 4 21310 NULL
88761 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
88762 +sys_process_vm_writev_4928 sys_process_vm_writev 3-5 4928 NULL
88763 +ntfs_rl_insert_4931 ntfs_rl_insert 2-4 4931 NULL
88764 +ip_make_skb_13129 ip_make_skb 5-6 13129 NULL
88765 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
88766 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
88767 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
88768 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL
88769 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
88770 +create_xattr_54106 create_xattr 5 54106 NULL
88771 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
88772 +ep_write_59008 ep_write 3 59008 NULL
88773 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
88774 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
88775 +devm_kzalloc_4966 devm_kzalloc 2 4966 NULL
88776 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
88777 +udf_sb_alloc_partition_maps_62313 udf_sb_alloc_partition_maps 2 62313 NULL
88778 +alloc_mr_45935 alloc_mr 1 45935 NULL
88779 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
88780 +isku_receive_54130 isku_receive 4 54130 NULL
88781 +hfcpci_empty_bfifo_62323 hfcpci_empty_bfifo 4 62323 NULL
88782 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
88783 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
88784 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
88785 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
88786 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
88787 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
88788 +i915_max_freq_write_11350 i915_max_freq_write 3 11350 NULL
88789 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
88790 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
88791 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
88792 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
88793 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
88794 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
88795 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
88796 +alloc_ldt_21972 alloc_ldt 2 21972 NULL
88797 +ipath_resize_cq_712 ipath_resize_cq 2 712 NULL
88798 +comedi_read_13199 comedi_read 3 13199 NULL
88799 +flash_write_62354 flash_write 3 62354 NULL
88800 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
88801 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
88802 +i2400m_zrealloc_2x_54166 i2400m_zrealloc_2x 3 54166 NULL nohasharray
88803 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 &i2400m_zrealloc_2x_54166
88804 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
88805 +proc_file_read_53905 proc_file_read 3 53905 NULL
88806 +mtd_device_parse_register_5024 mtd_device_parse_register 5 5024 NULL
88807 +acpi_tb_install_table_12988 acpi_tb_install_table 1 12988 NULL
88808 +set_wd_exp_mode_pfs_62372 set_wd_exp_mode_pfs 3 62372 NULL
88809 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
88810 +acpi_os_read_memory_54186 acpi_os_read_memory 1-3 54186 NULL
88811 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
88812 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
88813 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
88814 +cru_detect_11272 cru_detect 1 11272 NULL
88815 +altera_irscan_62396 altera_irscan 2 62396 NULL
88816 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
88817 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
88818 +fw_download_code_13249 fw_download_code 3 13249 NULL
88819 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
88820 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
88821 +set_ssp_62411 set_ssp 4 62411 NULL
88822 +nfc_hci_send_event_21452 nfc_hci_send_event 5 21452 NULL
88823 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
88824 +get_free_entries_46030 get_free_entries 1 46030 NULL
88825 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
88826 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
88827 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
88828 +carl9170_rx_13272 carl9170_rx 3 13272 NULL
88829 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
88830 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL
88831 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
88832 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3 5091 NULL
88833 +netdev_alloc_skb_62437 netdev_alloc_skb 2 62437 NULL
88834 +dma_memcpy_pg_to_iovec_1725 dma_memcpy_pg_to_iovec 6 1725 NULL
88835 +platform_device_add_resources_13289 platform_device_add_resources 3 13289 NULL
88836 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
88837 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
88838 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
88839 +e1000_check_copybreak_62448 e1000_check_copybreak 3 62448 NULL
88840 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
88841 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
88842 +wusb_prf_54261 wusb_prf 7 54261 NULL nohasharray
88843 +audio_write_54261 audio_write 4 54261 &wusb_prf_54261
88844 +sys_setxattr_37880 sys_setxattr 4 37880 NULL
88845 +dvb_net_sec_37884 dvb_net_sec 3 37884 NULL
88846 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
88847 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
88848 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
88849 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
88850 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL nohasharray
88851 +xz_dec_lzma2_create_36353 xz_dec_lzma2_create 2 36353 &v9fs_file_readn_36353
88852 +vfio_config_do_rw_46091 vfio_config_do_rw 3 46091 NULL
88853 +dma_skb_copy_datagram_iovec_21516 dma_skb_copy_datagram_iovec 3-5 21516 NULL
88854 +ata_host_alloc_46094 ata_host_alloc 2 46094 NULL
88855 +probes_write_29711 probes_write 3 29711 NULL
88856 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
88857 +us122l_ctl_msg_13330 us122l_ctl_msg 8 13330 NULL
88858 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
88859 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
88860 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
88861 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
88862 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL
88863 +tipc_link_send_sections_fast_37920 tipc_link_send_sections_fast 4 37920 NULL
88864 +mlx4_en_create_rx_ring_62498 mlx4_en_create_rx_ring 3 62498 NULL
88865 +emi62_writememory_29731 emi62_writememory 4 29731 NULL
88866 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
88867 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
88868 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL
88869 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
88870 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
88871 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
88872 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
88873 +pn_raw_send_54330 pn_raw_send 2 54330 NULL
88874 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
88875 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
88876 +sfi_map_memory_5183 sfi_map_memory 1-2 5183 NULL
88877 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
88878 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
88879 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
88880 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
88881 +ddp_clear_map_46152 ddp_clear_map 4 46152 NULL
88882 +cxio_hal_init_resource_29771 cxio_hal_init_resource 2-6-7 29771 NULL nohasharray
88883 +ip_vs_conn_fill_param_sync_29771 ip_vs_conn_fill_param_sync 6 29771 &cxio_hal_init_resource_29771
88884 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
88885 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
88886 +_osd_realloc_seg_54352 _osd_realloc_seg 3 54352 NULL
88887 +pipe_set_size_5204 pipe_set_size 2 5204 NULL
88888 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
88889 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
88890 +isdn_read_50021 isdn_read 3 50021 NULL
88891 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
88892 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
88893 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
88894 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
88895 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
88896 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
88897 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
88898 +ssb_ioremap_5228 ssb_ioremap 2 5228 NULL
88899 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
88900 +xlog_do_recovery_pass_21618 xlog_do_recovery_pass 3 21618 NULL
88901 +isdn_ppp_skb_push_5236 isdn_ppp_skb_push 2 5236 NULL
88902 +get_subdir_62581 get_subdir 3 62581 NULL
88903 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
88904 +sctp_abort_pkt_new_5241 sctp_abort_pkt_new 6 5241 NULL
88905 +vfs_readv_38011 vfs_readv 3 38011 NULL
88906 +keyring_read_13438 keyring_read 3 13438 NULL
88907 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL nohasharray
88908 +set_tap_pwup_pfs_13440 set_tap_pwup_pfs 3 13440 &sctp_setsockopt_peer_primary_addr_13440
88909 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
88910 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
88911 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
88912 +packet_alloc_skb_62602 packet_alloc_skb 2-5-4 62602 NULL
88913 +prism2_send_mgmt_62605 prism2_send_mgmt 4 62605 NULL nohasharray
88914 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 &prism2_send_mgmt_62605
88915 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
88916 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
88917 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
88918 +ftrace_write_29551 ftrace_write 3 29551 NULL
88919 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL
88920 +iscsi_post_host_event_13473 iscsi_post_host_event 4 13473 NULL
88921 +ems_pcmcia_add_card_62627 ems_pcmcia_add_card 2 62627 NULL
88922 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
88923 +dev_write_7708 dev_write 3 7708 NULL
88924 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
88925 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
88926 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
88927 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
88928 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
88929 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
88930 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
88931 +nf_nat_ftp_46265 nf_nat_ftp 6 46265 NULL
88932 +nfc_targets_found_29886 nfc_targets_found 3 29886 NULL
88933 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
88934 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
88935 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
88936 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
88937 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
88938 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
88939 +bm_init_13529 bm_init 2 13529 NULL
88940 +check586_29914 check586 2 29914 NULL
88941 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
88942 +pep_alloc_skb_46303 pep_alloc_skb 3 46303 NULL
88943 +reiserfs_allocate_list_bitmaps_21732 reiserfs_allocate_list_bitmaps 3 21732 NULL
88944 +ioremap_wc_62695 ioremap_wc 1-2 62695 NULL
88945 +pg_read_17276 pg_read 3 17276 NULL
88946 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
88947 +ep0_read_38095 ep0_read 3 38095 NULL
88948 +batadv_iv_ogm_queue_add_46319 batadv_iv_ogm_queue_add 3 46319 NULL
88949 +__nf_nat_mangle_tcp_packet_21744 __nf_nat_mangle_tcp_packet 8-6 21744 NULL
88950 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
88951 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
88952 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
88953 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
88954 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
88955 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
88956 +l2down_create_21755 l2down_create 4 21755 NULL
88957 +alloc_tio_13564 alloc_tio 3 13564 NULL
88958 +viacam_read_54526 viacam_read 3 54526 NULL
88959 +btrfs_mksubvol_58240 btrfs_mksubvol 3 58240 NULL
88960 +tunables_read_36385 tunables_read 3 36385 NULL
88961 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
88962 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
88963 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
88964 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4 38153 NULL
88965 +setsockopt_54539 setsockopt 5 54539 NULL
88966 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
88967 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
88968 +tty_register_device_4544 tty_register_device 2 4544 NULL
88969 +cache_write_13589 cache_write 3 13589 NULL
88970 +mpt_lan_receive_post_turbo_13592 mpt_lan_receive_post_turbo 2 13592 NULL
88971 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
88972 +key_replays_read_62746 key_replays_read 3 62746 NULL
88973 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
88974 +aac_sa_ioremap_13596 aac_sa_ioremap 2 13596 NULL nohasharray
88975 +irias_new_octseq_value_13596 irias_new_octseq_value 2 13596 &aac_sa_ioremap_13596
88976 +mwifiex_usb_submit_rx_urb_54558 mwifiex_usb_submit_rx_urb 2 54558 NULL
88977 +irias_add_octseq_attrib_29983 irias_add_octseq_attrib 4 29983 NULL
88978 +cdev_add_38176 cdev_add 2-3 38176 NULL
88979 +brcmf_sdcard_recv_buf_38179 brcmf_sdcard_recv_buf 6 38179 NULL
88980 +__ioremap_caller_21800 __ioremap_caller 1-2 21800 NULL
88981 +alloc_and_copy_ftrace_hash_29368 alloc_and_copy_ftrace_hash 1 29368 NULL
88982 +ubi_dump_flash_46381 ubi_dump_flash 4 46381 NULL
88983 +swap_cgroup_swapon_13614 swap_cgroup_swapon 2 13614 NULL
88984 +wm8994_bulk_write_13615 wm8994_bulk_write 3 13615 NULL
88985 +init_chip_wc_pat_62768 init_chip_wc_pat 2 62768 NULL
88986 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
88987 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
88988 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
88989 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
88990 +vmalloc_user_32308 vmalloc_user 1 32308 NULL
88991 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
88992 +ath6kl_wmi_startscan_cmd_33674 ath6kl_wmi_startscan_cmd 8 33674 NULL
88993 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
88994 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL
88995 +packet_snd_13634 packet_snd 3 13634 NULL
88996 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
88997 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
88998 +sfi_map_table_5462 sfi_map_table 1 5462 NULL
88999 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
89000 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
89001 +fwSendNullPacket_54618 fwSendNullPacket 2 54618 NULL
89002 +drp_wmove_30043 drp_wmove 4 30043 NULL
89003 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
89004 +cache_downcall_13666 cache_downcall 3 13666 NULL
89005 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
89006 +ubi_leb_write_5478 ubi_leb_write 4-5 5478 NULL
89007 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
89008 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
89009 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
89010 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
89011 +tty_write_5494 tty_write 3 5494 NULL
89012 +iscsi_ping_comp_event_38263 iscsi_ping_comp_event 5 38263 NULL
89013 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL
89014 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
89015 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
89016 +teiup_create_43201 teiup_create 3 43201 NULL
89017 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
89018 +filldir64_46469 filldir64 3 46469 NULL
89019 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL nohasharray
89020 +set_dis_disc_pfs_28225 set_dis_disc_pfs 3 28225 &line6_alloc_sysex_buffer_28225
89021 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
89022 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
89023 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
89024 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
89025 +tg3_run_loopback_30093 tg3_run_loopback 2 30093 NULL
89026 +spidev_message_5518 spidev_message 3 5518 NULL
89027 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
89028 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
89029 +ezusb_writememory_45976 ezusb_writememory 4 45976 NULL
89030 +evm_read_key_54674 evm_read_key 3 54674 NULL
89031 +sctp_make_op_error_space_5528 sctp_make_op_error_space 3 5528 NULL
89032 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
89033 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
89034 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
89035 +em28xx_init_isoc_62883 em28xx_init_isoc 4 62883 NULL nohasharray
89036 +aoechr_write_62883 aoechr_write 3 62883 &em28xx_init_isoc_62883
89037 +resize_info_buffer_62889 resize_info_buffer 2 62889 NULL
89038 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
89039 +u32_array_read_2219 u32_array_read 3 2219 NULL
89040 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
89041 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
89042 +sys_add_key_61288 sys_add_key 4 61288 NULL
89043 +kmsg_read_46514 kmsg_read 3 46514 NULL
89044 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
89045 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
89046 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
89047 +recv_stream_30138 recv_stream 4 30138 NULL
89048 +u_memcpya_30139 u_memcpya 2-3 30139 NULL
89049 +getdqbuf_62908 getdqbuf 1 62908 NULL
89050 +bdx_rxdb_create_46525 bdx_rxdb_create 1 46525 NULL
89051 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
89052 +_add_sg_continuation_descriptor_54721 _add_sg_continuation_descriptor 3 54721 NULL
89053 +fc_frame_alloc_fill_59394 fc_frame_alloc_fill 2 59394 NULL
89054 +fir16_create_5574 fir16_create 3 5574 NULL
89055 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
89056 +pt_write_40159 pt_write 3 40159 NULL
89057 +bioset_create_5580 bioset_create 1 5580 NULL
89058 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
89059 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
89060 +oz_ep_alloc_5587 oz_ep_alloc 2 5587 NULL
89061 +kzalloc_54740 kzalloc 1 54740 NULL
89062 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
89063 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
89064 +do_msgrcv_5590 do_msgrcv 4 5590 NULL
89065 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
89066 +link_send_sections_long_46556 link_send_sections_long 4 46556 NULL
89067 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
89068 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
89069 +batadv_iv_ogm_aggregate_new_54761 batadv_iv_ogm_aggregate_new 2 54761 NULL
89070 +ldm_frag_add_5611 ldm_frag_add 2 5611 NULL
89071 +cx25821_video_ioctl_30188 cx25821_video_ioctl 2 30188 NULL
89072 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
89073 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 NULL nohasharray
89074 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3 22001 &rxpipe_descr_host_int_trig_rx_data_read_22001
89075 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
89076 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
89077 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
89078 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
89079 +hidp_output_raw_report_5629 hidp_output_raw_report 3 5629 NULL
89080 +nfs_idmap_request_key_30208 nfs_idmap_request_key 3 30208 NULL
89081 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
89082 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
89083 +snd_ac97_pcm_assign_30218 snd_ac97_pcm_assign 2 30218 NULL
89084 +ti_recv_22027 ti_recv 4 22027 NULL
89085 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2 34135 NULL
89086 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
89087 +nfsd_write_54809 nfsd_write 6 54809 NULL
89088 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
89089 +pcnet32_realloc_tx_ring_38428 pcnet32_realloc_tx_ring 3 38428 NULL
89090 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
89091 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
89092 +get_skb_63008 get_skb 2 63008 NULL
89093 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
89094 +netlink_send_38434 netlink_send 5 38434 NULL
89095 +atalk_recvmsg_22053 atalk_recvmsg 4 22053 NULL
89096 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL nohasharray
89097 +alloc_trace_uprobe_13870 alloc_trace_uprobe 3 13870 &compat_ip_setsockopt_13870
89098 +aircable_process_packet_46639 aircable_process_packet 5 46639 NULL
89099 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
89100 +write_rio_54837 write_rio 3 54837 NULL
89101 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 NULL
89102 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
89103 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
89104 +get_arg_5694 get_arg 3 5694 NULL
89105 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
89106 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
89107 +compat_readv_30273 compat_readv 3 30273 NULL
89108 +printer_read_54851 printer_read 3 54851 NULL
89109 +mem_rw_22085 mem_rw 3 22085 NULL
89110 +i915_min_freq_read_38470 i915_min_freq_read 3 38470 NULL
89111 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
89112 +lowpan_fragment_xmit_22095 lowpan_fragment_xmit 3-4 22095 NULL
89113 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
89114 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
89115 +unlink1_63059 unlink1 3 63059 NULL
89116 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL
89117 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
89118 +__do_krealloc_54389 __do_krealloc 2 54389 NULL
89119 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
89120 +tcf_csum_ipv6_tcp_54877 tcf_csum_ipv6_tcp 4 54877 NULL
89121 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
89122 +replay_log_leb_18704 replay_log_leb 3 18704 NULL
89123 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
89124 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
89125 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
89126 +dev_names_read_38509 dev_names_read 3 38509 NULL
89127 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
89128 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 NULL
89129 +get_packet_5747 get_packet 3 5747 NULL
89130 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL
89131 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
89132 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
89133 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
89134 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
89135 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
89136 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
89137 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
89138 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
89139 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
89140 +_l2_alloc_skb_11883 _l2_alloc_skb 1 11883 NULL
89141 +resource_from_user_30341 resource_from_user 3 30341 NULL
89142 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
89143 +sound_write_5102 sound_write 3 5102 NULL
89144 +pn533_dep_link_up_22154 pn533_dep_link_up 5 22154 NULL
89145 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
89146 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
89147 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
89148 +__vmalloc_node_flags_30352 __vmalloc_node_flags 1 30352 NULL
89149 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
89150 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
89151 +com90xx_found_13974 com90xx_found 3 13974 NULL
89152 +compat_sys_writev_5784 compat_sys_writev 3 5784 NULL
89153 +qcam_read_13977 qcam_read 3 13977 NULL
89154 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
89155 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
89156 +virtblk_add_buf_wait_54943 virtblk_add_buf_wait 3-4 54943 NULL
89157 +wl12xx_cmd_build_probe_req_54946 wl12xx_cmd_build_probe_req 6-8 54946 NULL
89158 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
89159 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
89160 +generic_readlink_32654 generic_readlink 3 32654 NULL
89161 +ieee80211_bss_info_update_13991 ieee80211_bss_info_update 4 13991 NULL
89162 +sys_get_mempolicy_30379 sys_get_mempolicy 3 30379 NULL
89163 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
89164 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
89165 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
89166 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL
89167 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
89168 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
89169 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
89170 +__proc_file_read_54978 __proc_file_read 3 54978 NULL
89171 +concat_writev_21451 concat_writev 3 21451 NULL
89172 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
89173 +_queue_data_54983 _queue_data 4 54983 NULL
89174 +_sys_packet_req_46793 _sys_packet_req 4 46793 NULL
89175 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
89176 +extend_netdev_table_21453 extend_netdev_table 2 21453 NULL
89177 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
89178 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
89179 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
89180 +ixgb_check_copybreak_5847 ixgb_check_copybreak 3 5847 NULL
89181 +setup_req_5848 setup_req 3 5848 NULL
89182 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
89183 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
89184 +rds_ib_inc_copy_to_user_55007 rds_ib_inc_copy_to_user 3 55007 NULL
89185 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
89186 +rbd_create_rw_ops_55297 rbd_create_rw_ops 1 55297 NULL
89187 +compat_sys_move_pages_5861 compat_sys_move_pages 2 5861 NULL
89188 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
89189 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
89190 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
89191 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
89192 +cma_create_area_38642 cma_create_area 2 38642 NULL
89193 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
89194 +sriov_enable_59689 sriov_enable 2 59689 NULL
89195 +enable_write_30456 enable_write 3 30456 NULL
89196 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
89197 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
89198 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
89199 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
89200 +tcp_manip_pkt_16563 tcp_manip_pkt 4 16563 NULL
89201 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
89202 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
89203 +ieee80211_mgmt_tx_46860 ieee80211_mgmt_tx 9 46860 NULL
89204 +port_show_regs_5904 port_show_regs 3 5904 NULL
89205 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
89206 +ptp_read_63251 ptp_read 4 63251 NULL
89207 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
89208 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
89209 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
89210 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL
89211 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
89212 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
89213 +ttm_bo_kmap_ttm_5922 ttm_bo_kmap_ttm 3 5922 NULL
89214 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
89215 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
89216 +iscsi_iser_recv_41948 iscsi_iser_recv 4 41948 NULL
89217 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
89218 +em28xx_alloc_isoc_46892 em28xx_alloc_isoc 4 46892 NULL
89219 +read_dma_55086 read_dma 3 55086 NULL
89220 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
89221 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
89222 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
89223 +ntfs_rl_replace_14136 ntfs_rl_replace 2-4 14136 NULL
89224 +ip_send_unicast_reply_38714 ip_send_unicast_reply 6 38714 NULL
89225 +tcp_collapse_63294 tcp_collapse 6-5 63294 NULL
89226 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
89227 +isdn_ppp_ccp_xmit_reset_63297 isdn_ppp_ccp_xmit_reset 6 63297 NULL
89228 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
89229 +tipc_subseq_alloc_5957 tipc_subseq_alloc 1 5957 NULL
89230 +em_canid_change_14150 em_canid_change 3 14150 NULL
89231 +tracing_ctrl_read_46922 tracing_ctrl_read 3 46922 NULL
89232 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
89233 +fb_write_46924 fb_write 3 46924 NULL
89234 +btmrvl_curpsmode_read_46939 btmrvl_curpsmode_read 3 46939 NULL
89235 +wlcore_alloc_hw_22365 wlcore_alloc_hw 1 22365 NULL
89236 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
89237 +br_send_bpdu_29669 br_send_bpdu 3 29669 NULL
89238 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
89239 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
89240 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
89241 +udf_readpages_38761 udf_readpages 4 38761 NULL
89242 +reada_add_block_54247 reada_add_block 2 54247 NULL
89243 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
89244 +proc_info_read_63344 proc_info_read 3 63344 NULL
89245 +pep_indicate_38611 pep_indicate 5 38611 NULL
89246 +set_le_30581 set_le 4 30581 NULL
89247 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
89248 +btmrvl_psmode_read_22395 btmrvl_psmode_read 3 22395 NULL
89249 +alloc_private_22399 alloc_private 2 22399 NULL
89250 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
89251 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
89252 +zoran_write_22404 zoran_write 3 22404 NULL
89253 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL
89254 +idmouse_read_63374 idmouse_read 3 63374 NULL
89255 +queue_reply_22416 queue_reply 3 22416 NULL
89256 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
89257 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
89258 +ntfs_rl_append_6037 ntfs_rl_append 2-4 6037 NULL
89259 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
89260 +ttm_bo_io_47000 ttm_bo_io 5 47000 NULL
89261 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
89262 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
89263 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL
89264 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
89265 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
89266 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4-2 14244 NULL
89267 +snd_soc_hw_bulk_write_raw_14245 snd_soc_hw_bulk_write_raw 4 14245 NULL
89268 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL nohasharray
89269 +isdn_net_ciscohdlck_alloc_skb_55209 isdn_net_ciscohdlck_alloc_skb 2 55209 &ht40allow_map_read_55209
89270 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
89271 +sys_select_38827 sys_select 1 38827 NULL
89272 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
89273 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
89274 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2 47024 NULL
89275 +direct_entry_38836 direct_entry 3 38836 NULL
89276 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
89277 +gntdev_alloc_map_35145 gntdev_alloc_map 2 35145 NULL
89278 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
89279 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
89280 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
89281 +write_head_30481 write_head 4 30481 NULL
89282 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
89283 +set_dis_bypass_pfs_47038 set_dis_bypass_pfs 3 47038 NULL
89284 +add_numbered_child_14273 add_numbered_child 5 14273 NULL
89285 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
89286 +OS_mem_token_alloc_14276 OS_mem_token_alloc 1 14276 NULL
89287 +sep_prepare_input_output_dma_table_63429 sep_prepare_input_output_dma_table 2-4-3 63429 NULL
89288 +register_unifi_sdio_55239 register_unifi_sdio 2 55239 NULL
89289 +ath6kl_wmi_get_new_buf_52304 ath6kl_wmi_get_new_buf 1 52304 NULL
89290 +agp_remap_30665 agp_remap 2 30665 NULL
89291 +interfaces_38859 interfaces 2 38859 NULL
89292 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
89293 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
89294 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
89295 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
89296 +qc_capture_19298 qc_capture 3 19298 NULL
89297 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
89298 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
89299 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
89300 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
89301 +rtl_port_map_2385 rtl_port_map 1-2 2385 NULL
89302 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
89303 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
89304 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
89305 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
89306 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
89307 +process_bulk_data_command_38906 process_bulk_data_command 4 38906 NULL
89308 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
89309 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
89310 +read_kcore_63488 read_kcore 3 63488 NULL
89311 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
89312 +__skb_cow_39254 __skb_cow 2 39254 NULL
89313 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
89314 +__get_vm_area_node_55305 __get_vm_area_node 1 55305 NULL
89315 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
89316 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
89317 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
89318 +pskb_may_pull_22546 pskb_may_pull 2 22546 NULL
89319 +mousedev_read_47123 mousedev_read 3 47123 NULL
89320 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
89321 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
89322 +vdma_mem_alloc_6171 vdma_mem_alloc 1 6171 NULL
89323 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
89324 +ses_recv_diag_47143 ses_recv_diag 4 47143 NULL nohasharray
89325 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 &ses_recv_diag_47143
89326 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
89327 +vme_user_read_55338 vme_user_read 3 55338 NULL
89328 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL
89329 +cxio_init_resource_fifo_random_47151 cxio_init_resource_fifo_random 3 47151 NULL
89330 +persistent_ram_iomap_47156 persistent_ram_iomap 1-2 47156 NULL
89331 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
89332 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
89333 +__hidp_send_ctrl_message_28303 __hidp_send_ctrl_message 4 28303 NULL
89334 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
89335 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
89336 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
89337 +acpi_system_read_event_55362 acpi_system_read_event 3 55362 NULL
89338 +dbg_leb_write_63555 dbg_leb_write 4-5 63555 NULL nohasharray
89339 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 &dbg_leb_write_63555
89340 +snapshot_read_22601 snapshot_read 3 22601 NULL
89341 +OSDSetBlock_38986 OSDSetBlock 4-2 38986 NULL
89342 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
89343 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
89344 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
89345 +ioremap_cache_47189 ioremap_cache 1-2 47189 NULL
89346 +__send_to_port_55383 __send_to_port 3 55383 NULL
89347 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
89348 +nf_nat_ipv4_manip_pkt_55387 nf_nat_ipv4_manip_pkt 2 55387 NULL
89349 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
89350 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
89351 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
89352 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
89353 +get_nodes_39012 get_nodes 3 39012 NULL
89354 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
89355 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
89356 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
89357 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
89358 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
89359 +create_subvol_30836 create_subvol 4 30836 NULL
89360 +mthca_map_reg_5664 mthca_map_reg 2-3 5664 NULL
89361 +ci13xxx_add_device_14456 ci13xxx_add_device 3 14456 NULL
89362 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
89363 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
89364 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
89365 +read_oldmem_55658 read_oldmem 3 55658 NULL
89366 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
89367 +xenbus_file_write_6282 xenbus_file_write 3 6282 NULL
89368 +options_write_47243 options_write 3 47243 NULL
89369 +module_alloc_63630 module_alloc 1 63630 NULL
89370 +alloc_skb_55439 alloc_skb 1 55439 NULL
89371 +nf_nat_ipv6_manip_pkt_6289 nf_nat_ipv6_manip_pkt 2 6289 NULL
89372 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
89373 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
89374 +ubifs_leb_write_22679 ubifs_leb_write 4-5 22679 NULL
89375 +nf_nat_sack_adjust_6297 nf_nat_sack_adjust 2 6297 NULL
89376 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
89377 +mid_get_vbt_data_r10_6308 mid_get_vbt_data_r10 2 6308 NULL
89378 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
89379 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
89380 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
89381 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
89382 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
89383 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
89384 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
89385 +tty_audit_log_47280 tty_audit_log 8 47280 NULL
89386 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
89387 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
89388 +fc_host_post_vendor_event_30903 fc_host_post_vendor_event 3 30903 NULL
89389 +vbi_read_63673 vbi_read 3 63673 NULL
89390 +tun_get_user_39099 tun_get_user 4 39099 NULL
89391 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
89392 +alloc_tty_driver_63681 alloc_tty_driver 1 63681 NULL
89393 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
89394 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
89395 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
89396 +nfc_hci_hcp_message_tx_14534 nfc_hci_hcp_message_tx 6 14534 NULL
89397 +iommu_map_mmio_space_30919 iommu_map_mmio_space 1 30919 NULL
89398 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
89399 +dataflash_read_user_otp_14536 dataflash_read_user_otp 2-3 14536 &ep0_write_14536
89400 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
89401 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4 22735 NULL
89402 +ax25_output_22736 ax25_output 2 22736 NULL
89403 +__kfifo_to_user_r_39123 __kfifo_to_user_r 3 39123 NULL
89404 +l2cap_send_cmd_14548 l2cap_send_cmd 4 14548 NULL
89405 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
89406 +drm_vmalloc_dma_14550 drm_vmalloc_dma 1 14550 NULL
89407 +cfpkt_pad_trail_55511 cfpkt_pad_trail 2 55511 NULL nohasharray
89408 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 &cfpkt_pad_trail_55511
89409 +cmtp_add_msgpart_9252 cmtp_add_msgpart 4 9252 NULL
89410 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
89411 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
89412 +hid_input_report_32458 hid_input_report 4 32458 NULL
89413 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
89414 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
89415 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
89416 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
89417 +alloc_ring_39151 alloc_ring 2-4 39151 NULL
89418 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
89419 +create_bounce_buffer_39155 create_bounce_buffer 3 39155 NULL
89420 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
89421 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
89422 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
89423 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
89424 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
89425 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
89426 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
89427 +bt_skb_alloc_6404 bt_skb_alloc 1 6404 NULL
89428 +get_info_55681 get_info 3 55681 NULL
89429 +setkey_14987 setkey 3 14987 NULL
89430 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
89431 +init_list_set_39188 init_list_set 2-3 39188 NULL
89432 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
89433 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
89434 +l2up_create_6430 l2up_create 3 6430 NULL
89435 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
89436 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
89437 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
89438 +add_partition_55588 add_partition 2 55588 NULL
89439 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
89440 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
89441 +depth_read_31112 depth_read 3 31112 NULL
89442 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
89443 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
89444 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
89445 +profile_replace_14652 profile_replace 3 14652 NULL
89446 +vzalloc_47421 vzalloc 1 47421 NULL
89447 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
89448 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
89449 +sys_writev_28384 sys_writev 3 28384 NULL
89450 +batadv_tt_response_fill_table_39236 batadv_tt_response_fill_table 1 39236 NULL
89451 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
89452 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4 44769 NULL
89453 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
89454 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL
89455 +create_attr_set_22861 create_attr_set 1 22861 NULL
89456 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
89457 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
89458 +compat_sys_mq_timedsend_31060 compat_sys_mq_timedsend 3 31060 NULL
89459 +sel_write_load_63830 sel_write_load 3 63830 NULL
89460 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
89461 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
89462 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
89463 +dvb_dmxdev_set_buffer_size_55643 dvb_dmxdev_set_buffer_size 2 55643 NULL
89464 +tsi148_master_set_14685 tsi148_master_set 4 14685 NULL
89465 +ath6kl_wmi_set_appie_cmd_39266 ath6kl_wmi_set_appie_cmd 5 39266 NULL
89466 +probe_bios_17467 probe_bios 1 17467 NULL
89467 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
89468 +ttm_bo_ioremap_31082 ttm_bo_ioremap 2-3 31082 NULL
89469 +mei_read_6507 mei_read 3 6507 NULL
89470 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
89471 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
89472 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
89473 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
89474 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
89475 +SetArea_50835 SetArea 4 50835 NULL
89476 +tpm_read_50344 tpm_read 3 50344 NULL
89477 +newpart_47485 newpart 6 47485 NULL
89478 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
89479 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
89480 +core_sys_select_47494 core_sys_select 1 47494 NULL
89481 +read_file_disable_ani_6536 read_file_disable_ani 3 6536 NULL
89482 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
89483 +__vmalloc_node_39308 __vmalloc_node 1 39308 NULL
89484 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
89485 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
89486 +unlink_simple_47506 unlink_simple 3 47506 NULL
89487 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
89488 +wdm_read_6549 wdm_read 3 6549 NULL
89489 +init_map_ipmac_63896 init_map_ipmac 4-3 63896 NULL
89490 +tipc_multicast_49144 tipc_multicast 5 49144 NULL
89491 +nfs4_realloc_slot_table_22859 nfs4_realloc_slot_table 2 22859 NULL
89492 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
89493 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
89494 +__videobuf_alloc_uncached_55711 __videobuf_alloc_uncached 1 55711 NULL
89495 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
89496 +nfc_hci_send_cmd_55714 nfc_hci_send_cmd 5 55714 NULL
89497 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
89498 +filter_read_61692 filter_read 3 61692 NULL
89499 +mtdswap_init_55719 mtdswap_init 2 55719 NULL
89500 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
89501 +debugfs_read_62535 debugfs_read 3 62535 NULL
89502 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
89503 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL
89504 +divas_write_63901 divas_write 3 63901 NULL
89505 +alloc_sglist_22960 alloc_sglist 1-2-3 22960 NULL
89506 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
89507 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
89508 +cfpkt_split_47541 cfpkt_split 2 47541 NULL
89509 +__copy_from_user_nocache_39351 __copy_from_user_nocache 3 39351 NULL
89510 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
89511 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 3-2 55738 NULL
89512 +ipw_write_59807 ipw_write 3 59807 NULL
89513 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
89514 +tipc_send2port_63935 tipc_send2port 5 63935 NULL
89515 +do_write_log_from_user_39362 do_write_log_from_user 3 39362 NULL
89516 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
89517 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
89518 +mwifiex_cfg80211_mgmt_tx_12022 mwifiex_cfg80211_mgmt_tx 9 12022 NULL
89519 +cycx_setup_47562 cycx_setup 4 47562 NULL
89520 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
89521 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
89522 +set_local_name_55757 set_local_name 4 55757 NULL
89523 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
89524 +btrfs_init_new_buffer_55761 btrfs_init_new_buffer 4 55761 NULL
89525 +read_ldt_47570 read_ldt 2 47570 NULL
89526 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
89527 +pci_iomap_47575 pci_iomap 3 47575 NULL
89528 +acpi_ex_system_memory_space_handler_31192 acpi_ex_system_memory_space_handler 2 31192 NULL
89529 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
89530 +module_alloc_update_bounds_rw_63233 module_alloc_update_bounds_rw 1 63233 NULL
89531 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
89532 +drm_ht_create_18853 drm_ht_create 2 18853 NULL
89533 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
89534 +qlcnic_alloc_msix_entries_46160 qlcnic_alloc_msix_entries 2 46160 NULL
89535 +ieee80211_authentication_req_63973 ieee80211_authentication_req 3 63973 NULL
89536 +dn_alloc_skb_6631 dn_alloc_skb 2 6631 NULL
89537 +conf_read_55786 conf_read 3 55786 NULL
89538 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
89539 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
89540 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
89541 +virtscsi_alloc_tgt_6643 virtscsi_alloc_tgt 2 6643 NULL
89542 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
89543 +user_power_read_39414 user_power_read 3 39414 NULL
89544 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
89545 +uea_request_47613 uea_request 4 47613 NULL
89546 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
89547 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
89548 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
89549 +btrfs_find_create_tree_block_55812 btrfs_find_create_tree_block 3 55812 NULL
89550 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
89551 +lcd_write_14857 lcd_write 3 14857 NULL nohasharray
89552 +__krealloc_14857 __krealloc 2 14857 &lcd_write_14857
89553 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
89554 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
89555 +kmemdup_64015 kmemdup 2 64015 NULL
89556 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
89557 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
89558 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
89559 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
89560 +tcf_csum_skb_nextlayer_64025 tcf_csum_skb_nextlayer 3 64025 NULL
89561 +oz_events_read_47535 oz_events_read 3 47535 NULL
89562 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
89563 +resize_async_buffer_64031 resize_async_buffer 4 64031 NULL
89564 +sys_semop_39457 sys_semop 3 39457 NULL
89565 +vm_map_ram_23078 vm_map_ram 2 23078 NULL nohasharray
89566 +raw_sendmsg_23078 raw_sendmsg 4 23078 &vm_map_ram_23078
89567 +update_pmkid_2481 update_pmkid 4 2481 NULL
89568 +sriov_enable_migration_14889 sriov_enable_migration 2 14889 NULL
89569 +sep_lli_table_secure_dma_64042 sep_lli_table_secure_dma 2-3 64042 NULL
89570 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
89571 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
89572 +hysdn_rx_netpkt_16136 hysdn_rx_netpkt 3 16136 NULL
89573 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
89574 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
89575 +mpeg_read_6708 mpeg_read 3 6708 NULL
89576 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
89577 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
89578 +sky2_receive_13407 sky2_receive 2 13407 NULL
89579 +krealloc_14908 krealloc 2 14908 NULL
89580 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
89581 +bt_skb_send_alloc_6581 bt_skb_send_alloc 2 6581 NULL
89582 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
89583 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
89584 +video_proc_write_6724 video_proc_write 3 6724 NULL
89585 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
89586 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
89587 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
89588 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
89589 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
89590 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
89591 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
89592 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
89593 +command_file_write_31318 command_file_write 3 31318 NULL
89594 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
89595 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
89596 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
89597 +i915_cache_sharing_read_24775 i915_cache_sharing_read 3 24775 NULL
89598 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
89599 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
89600 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
89601 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
89602 +ca91cx42_master_set_23146 ca91cx42_master_set 4 23146 NULL
89603 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
89604 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
89605 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
89606 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
89607 +sfi_check_table_6772 sfi_check_table 1 6772 NULL
89608 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
89609 +int_proc_write_39542 int_proc_write 3 39542 NULL
89610 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
89611 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
89612 +read_file_ani_23161 read_file_ani 3 23161 NULL
89613 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
89614 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
89615 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
89616 +pp_write_39554 pp_write 3 39554 NULL
89617 +ioremap_23172 ioremap 1-2 23172 NULL
89618 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
89619 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
89620 +usblp_write_23178 usblp_write 3 23178 NULL
89621 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
89622 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
89623 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3 31374 NULL
89624 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
89625 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
89626 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
89627 +fix_unclean_leb_23188 fix_unclean_leb 3 23188 NULL
89628 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
89629 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
89630 +vmalloc_32_1135 vmalloc_32 1 1135 NULL
89631 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
89632 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
89633 +__team_options_register_63941 __team_options_register 3 63941 NULL
89634 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
89635 +ip_ufo_append_data_12775 ip_ufo_append_data 6-7-8 12775 NULL
89636 +rvmalloc_46873 rvmalloc 1 46873 NULL
89637 +vmap_15025 vmap 2 15025 NULL
89638 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
89639 +mcs7830_set_reg_31413 mcs7830_set_reg 3 31413 NULL
89640 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
89641 +tty_buffer_request_room_23228 tty_buffer_request_room 2 23228 NULL
89642 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
89643 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
89644 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
89645 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
89646 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
89647 +ttm_object_device_init_10321 ttm_object_device_init 2 10321 NULL
89648 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
89649 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
89650 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL
89651 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
89652 +ssb_bus_pcmciabus_register_56020 ssb_bus_pcmciabus_register 3 56020 NULL
89653 +fm_send_cmd_39639 fm_send_cmd 5 39639 NULL
89654 +ip6gre_err_19869 ip6gre_err 5 19869 NULL
89655 +nvme_alloc_iod_56027 nvme_alloc_iod 1 56027 NULL
89656 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
89657 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
89658 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5 15072 NULL
89659 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
89660 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
89661 +get_new_cssid_51665 get_new_cssid 2 51665 NULL
89662 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL
89663 +prism2_info_hostscanresults_39657 prism2_info_hostscanresults 3 39657 NULL
89664 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
89665 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
89666 +__videobuf_alloc_vb_5665 __videobuf_alloc_vb 1 5665 NULL
89667 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
89668 +redrat3_transmit_ir_64244 redrat3_transmit_ir 3 64244 NULL
89669 +__alloc_extent_buffer_15093 __alloc_extent_buffer 3 15093 NULL
89670 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
89671 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
89672 +alg_setkey_31485 alg_setkey 3 31485 NULL
89673 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
89674 +spi_show_regs_6911 spi_show_regs 3 6911 NULL nohasharray
89675 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 &spi_show_regs_6911
89676 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
89677 +vhci_read_47878 vhci_read 3 47878 NULL
89678 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
89679 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
89680 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
89681 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
89682 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
89683 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
89684 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
89685 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
89686 +osd_req_read_sg_47905 osd_req_read_sg 5 47905 NULL
89687 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
89688 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
89689 +timeout_read_47915 timeout_read 3 47915 NULL
89690 +hidraw_write_31536 hidraw_write 3 31536 NULL
89691 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
89692 +page_readlink_23346 page_readlink 3 23346 NULL
89693 +videobuf_dma_init_kernel_6963 videobuf_dma_init_kernel 3 6963 NULL
89694 +comedi_write_47926 comedi_write 3 47926 NULL
89695 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
89696 +dsp_write_46218 dsp_write 2 46218 NULL
89697 +kmem_zalloc_large_56128 kmem_zalloc_large 1 56128 NULL
89698 +usbvision_read_31555 usbvision_read 3 31555 NULL
89699 +pd_video_read_24510 pd_video_read 3 24510 NULL
89700 +crypto_authenc_esn_setkey_6985 crypto_authenc_esn_setkey 3 6985 NULL
89701 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
89702 +request_key_async_6990 request_key_async 4 6990 NULL
89703 +ts_write_64336 ts_write 3 64336 NULL
89704 +handle_response_55951 handle_response 5 55951 NULL
89705 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
89706 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
89707 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
89708 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
89709 +osst_write_31581 osst_write 3 31581 NULL
89710 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
89711 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
89712 +wm8350_block_write_19727 wm8350_block_write 3 19727 NULL
89713 +diva_xdi_write_63975 diva_xdi_write 4 63975 NULL
89714 +llc_alloc_frame_64366 llc_alloc_frame 4 64366 NULL
89715 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 NULL nohasharray
89716 +mempool_resize_47983 mempool_resize 2 47983 &iwl_dbgfs_ucode_tracing_read_47983
89717 +mangle_packet_18920 mangle_packet 7-9 18920 NULL
89718 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
89719 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
89720 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
89721 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
89722 +ilo_write_64378 ilo_write 3 64378 NULL
89723 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
89724 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
89725 +vzalloc_node_23424 vzalloc_node 1 23424 NULL
89726 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
89727 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
89728 +variax_alloc_sysex_buffer_15237 variax_alloc_sysex_buffer 3 15237 NULL
89729 +copy_from_user_17559 copy_from_user 3 17559 NULL
89730 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
89731 +sys_migrate_pages_39825 sys_migrate_pages 2 39825 NULL
89732 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
89733 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
89734 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
89735 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
89736 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
89737 +beiscsi_process_async_pdu_39834 beiscsi_process_async_pdu 7 39834 NULL
89738 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
89739 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
89740 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
89741 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
89742 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
89743 +cp210x_get_config_56229 cp210x_get_config 4 56229 NULL
89744 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
89745 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
89746 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
89747 +dn_nsp_send_disc_23469 dn_nsp_send_disc 2 23469 NULL
89748 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
89749 +ping_sendmsg_3782 ping_sendmsg 4 3782 NULL
89750 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
89751 +__lgread_31668 __lgread 4 31668 NULL
89752 +scrub_setup_recheck_block_56245 scrub_setup_recheck_block 4-3 56245 NULL
89753 +fd_copyin_56247 fd_copyin 3 56247 NULL
89754 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
89755 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
89756 +sys_connect_15291 sys_connect 3 15291 NULL nohasharray
89757 +xlate_dev_mem_ptr_15291 xlate_dev_mem_ptr 1 15291 &sys_connect_15291
89758 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
89759 +divasa_remap_pci_bar_23485 divasa_remap_pci_bar 3-4 23485 &linear_conf_23485
89760 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
89761 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
89762 +_usb_writeN_sync_31682 _usb_writeN_sync 4 31682 NULL
89763 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
89764 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
89765 +event_filter_read_23494 event_filter_read 3 23494 NULL
89766 +tpm_tis_init_15304 tpm_tis_init 2-3 15304 NULL
89767 +fcoe_ctlr_send_keep_alive_15308 fcoe_ctlr_send_keep_alive 3 15308 NULL
89768 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
89769 +sys_setsockopt_35320 sys_setsockopt 5 35320 NULL
89770 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
89771 +pkt_add_39897 pkt_add 3 39897 NULL
89772 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
89773 +send_mpa_reject_7135 send_mpa_reject 3 7135 NULL
89774 +sctp_make_op_error_7057 sctp_make_op_error 5-6 7057 NULL
89775 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
89776 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
89777 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
89778 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
89779 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
89780 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
89781 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
89782 +sctp_make_asconf_ack_31726 sctp_make_asconf_ack 3 31726 NULL
89783 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
89784 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
89785 +alloc_ring_15345 alloc_ring 2-4 15345 NULL
89786 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
89787 +remove_uuid_64505 remove_uuid 4 64505 NULL
89788 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3 31741 NULL
89789 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 NULL
89790 +create_table_16213 create_table 2 16213 NULL
89791 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
89792 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
89793 +dbg_leb_change_23555 dbg_leb_change 4 23555 NULL
89794 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
89795 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
89796 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
89797 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
89798 +set_discoverable_48141 set_discoverable 4 48141 NULL
89799 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
89800 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
89801 +tcp_match_skb_to_sack_23568 tcp_match_skb_to_sack 4 23568 NULL
89802 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
89803 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
89804 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3 39955 NULL
89805 +__tcp_push_pending_frames_48148 __tcp_push_pending_frames 2 48148 NULL
89806 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
89807 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
89808 +ipv6_recv_error_56347 ipv6_recv_error 3 56347 NULL
89809 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
89810 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
89811 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
89812 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
89813 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
89814 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
89815 +cfpkt_create_pfx_23594 cfpkt_create_pfx 1-2 23594 NULL
89816 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
89817 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4 56368 NULL
89818 +dev_read_56369 dev_read 3 56369 NULL
89819 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
89820 +alloc_dummy_extent_buffer_56374 alloc_dummy_extent_buffer 2 56374 NULL
89821 +diva_os_alloc_message_buffer_64568 diva_os_alloc_message_buffer 1 64568 NULL
89822 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
89823 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
89824 +init_ipath_48187 init_ipath 1 48187 NULL
89825 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
89826 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4 15423 NULL
89827 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
89828 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
89829 +sys32_ipc_7238 sys32_ipc 3 7238 NULL
89830 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
89831 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1-2 21687 NULL
89832 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
89833 +ddp_ppod_write_idata_25610 ddp_ppod_write_idata 5 25610 NULL
89834 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
89835 +nf_nat_icmpv6_reply_translation_40023 nf_nat_icmpv6_reply_translation 5 40023 NULL nohasharray
89836 +ivtvfb_write_40023 ivtvfb_write 3 40023 &nf_nat_icmpv6_reply_translation_40023
89837 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
89838 +tcp_write_xmit_64602 tcp_write_xmit 2 64602 NULL
89839 +use_pool_64607 use_pool 2 64607 NULL
89840 +__get_vm_area_caller_56416 __get_vm_area_caller 1 56416 NULL nohasharray
89841 +acpi_os_write_memory_56416 acpi_os_write_memory 1-3 56416 &__get_vm_area_caller_56416
89842 +store_msg_56417 store_msg 3 56417 NULL
89843 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
89844 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
89845 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
89846 +read_file_recv_48232 read_file_recv 3 48232 NULL
89847 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
89848 +set_tpl_pfs_27490 set_tpl_pfs 3 27490 NULL
89849 +fanotify_write_64623 fanotify_write 3 64623 NULL
89850 +batadv_add_packet_12136 batadv_add_packet 3 12136 NULL
89851 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
89852 +fl_create_56435 fl_create 5 56435 NULL
89853 +gnttab_map_56439 gnttab_map 2 56439 NULL
89854 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
89855 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
89856 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
89857 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2 56453 NULL
89858 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
89859 +set_connectable_56458 set_connectable 4 56458 NULL
89860 +a2mp_chan_alloc_skb_cb_27159 a2mp_chan_alloc_skb_cb 2 27159 NULL
89861 +nfc_hci_send_response_56462 nfc_hci_send_response 5 56462 NULL
89862 +add_port_54941 add_port 2 54941 NULL
89863 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
89864 +cx18_read_23699 cx18_read 3 23699 NULL
89865 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL
89866 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
89867 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
89868 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
89869 +ddb_output_write_31902 ddb_output_write 3 31902 NULL
89870 +send_set_info_48288 send_set_info 7 48288 NULL
89871 +sock_alloc_send_skb_23720 sock_alloc_send_skb 2 23720 NULL
89872 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
89873 +set_disc_pwup_pfs_48300 set_disc_pwup_pfs 3 48300 NULL
89874 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
89875 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
89876 +new_dir_31919 new_dir 3 31919 NULL
89877 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
89878 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
89879 +sec_bulk_write_64691 sec_bulk_write 3 64691 NULL
89880 +mgmt_control_7349 mgmt_control 3 7349 NULL
89881 +hash_setkey_48310 hash_setkey 3 48310 NULL
89882 +ql_process_mac_rx_page_15543 ql_process_mac_rx_page 4 15543 NULL
89883 +hfcpci_empty_fifo_2427 hfcpci_empty_fifo 4 2427 NULL
89884 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
89885 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
89886 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
89887 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
89888 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4 31942 NULL
89889 +ql_process_mac_rx_skb_6689 ql_process_mac_rx_skb 4 6689 NULL
89890 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
89891 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
89892 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
89893 +vb2_write_31948 vb2_write 3 31948 NULL
89894 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
89895 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
89896 +l1oip_socket_recv_56537 l1oip_socket_recv 6 56537 NULL
89897 +ip_options_get_56538 ip_options_get 4 56538 NULL
89898 +write_62671 write 3 62671 NULL
89899 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
89900 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
89901 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
89902 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
89903 +ceph_copy_page_vector_to_user_31270 ceph_copy_page_vector_to_user 3-4 31270 NULL
89904 +allocate_cnodes_5329 allocate_cnodes 1 5329 NULL
89905 +skb_add_data_48363 skb_add_data 3 48363 NULL
89906 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
89907 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
89908 +iscsi_complete_pdu_48372 iscsi_complete_pdu 4 48372 NULL
89909 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
89910 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
89911 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
89912 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
89913 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
89914 +set_dis_tap_pfs_15621 set_dis_tap_pfs 3 15621 NULL
89915 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
89916 +dsp_cmx_send_member_15625 dsp_cmx_send_member 2 15625 NULL
89917 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
89918 +system_enable_read_25815 system_enable_read 3 25815 NULL
89919 +allocate_probes_40204 allocate_probes 1 40204 NULL
89920 +sd_alloc_ctl_entry_29708 sd_alloc_ctl_entry 1 29708 NULL
89921 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
89922 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
89923 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
89924 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
89925 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
89926 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
89927 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
89928 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642
89929 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
89930 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
89931 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
89932 +fs_path_add_15648 fs_path_add 3 15648 NULL
89933 +event_filter_write_56609 event_filter_write 3 56609 NULL
89934 +xfs_buf_read_map_40226 xfs_buf_read_map 3 40226 NULL
89935 +ms_rw_multi_sector_7459 ms_rw_multi_sector 3-4 7459 NULL
89936 +xsd_read_15653 xsd_read 3 15653 NULL
89937 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
89938 +p54_init_common_23850 p54_init_common 1 23850 NULL
89939 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
89940 +vmw_cursor_update_dmabuf_32045 vmw_cursor_update_dmabuf 3-4 32045 NULL
89941 +sys_sched_setaffinity_32046 sys_sched_setaffinity 2 32046 NULL
89942 +garp_request_join_7471 garp_request_join 4 7471 NULL
89943 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
89944 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
89945 +unifi_read_14899 unifi_read 3 14899 NULL
89946 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
89947 +compat_sys_msgrcv_7482 compat_sys_msgrcv 2 7482 NULL
89948 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
89949 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
89950 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
89951 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
89952 +ipv6_recv_rxpmtu_7142 ipv6_recv_rxpmtu 3 7142 NULL
89953 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
89954 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
89955 +ieee80211_if_read_channel_type_23884 ieee80211_if_read_channel_type 3 23884 NULL
89956 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
89957 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
89958 +uf_sme_queue_message_15697 uf_sme_queue_message 3 15697 NULL
89959 +gdth_search_isa_58595 gdth_search_isa 1 58595 NULL
89960 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 NULL
89961 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
89962 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
89963 +iwch_reject_cr_23901 iwch_reject_cr 3 23901 NULL
89964 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
89965 +bio_alloc_32095 bio_alloc 2 32095 NULL
89966 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
89967 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
89968 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
89969 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL
89970 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
89971 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
89972 +ubi_io_write_data_40305 ubi_io_write_data 4-5 40305 NULL
89973 +send_control_msg_48498 send_control_msg 6 48498 NULL
89974 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
89975 +mlx4_en_create_tx_ring_48501 mlx4_en_create_tx_ring 4 48501 NULL
89976 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
89977 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
89978 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
89979 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3 56702 NULL
89980 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
89981 +batadv_tt_changes_fill_buff_40323 batadv_tt_changes_fill_buff 4 40323 NULL
89982 +__alloc_skb_23940 __alloc_skb 1 23940 NULL
89983 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
89984 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
89985 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
89986 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
89987 +alloc_tx_32143 alloc_tx 2 32143 NULL
89988 +wiimote_hid_send_48528 wiimote_hid_send 3 48528 NULL
89989 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
89990 +hsc_write_55875 hsc_write 3 55875 NULL
89991 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
89992 +do_test_15766 do_test 1 15766 NULL
89993 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
89994 +ip_recv_error_23109 ip_recv_error 3 23109 NULL
89995 +named_distribute_48544 named_distribute 4 48544 NULL
89996 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
89997 +venus_link_32165 venus_link 5 32165 NULL
89998 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
89999 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
90000 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
90001 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
90002 +set_std_nic_pfs_15792 set_std_nic_pfs 3 15792 NULL
90003 +ubifs_wbuf_write_nolock_64946 ubifs_wbuf_write_nolock 3 64946 NULL
90004 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
90005 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
90006 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
90007 +fwnet_incoming_packet_40380 fwnet_incoming_packet 3 40380 NULL
90008 +groups_alloc_7614 groups_alloc 1 7614 NULL
90009 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
90010 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
90011 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
90012 +ext_sd_execute_read_data_48589 ext_sd_execute_read_data 9 48589 NULL
90013 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
90014 +__carl9170_rx_56784 __carl9170_rx 3 56784 NULL
90015 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL
90016 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
90017 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
90018 +tcf_csum_ipv4_tcp_39713 tcf_csum_ipv4_tcp 4 39713 NULL
90019 +snapshot_write_28351 snapshot_write 3 28351 NULL
90020 +event_enable_read_7074 event_enable_read 3 7074 NULL
90021 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
90022 +do_syslog_56807 do_syslog 3 56807 NULL
90023 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
90024 +pskb_pull_65005 pskb_pull 2 65005 NULL
90025 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
90026 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
90027 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
90028 +unifi_write_65012 unifi_write 3 65012 NULL
90029 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL
90030 +nfs_readdata_alloc_65015 nfs_readdata_alloc 2 65015 NULL
90031 +ubi_io_write_15870 ubi_io_write 5-4 15870 NULL nohasharray
90032 +media_entity_init_15870 media_entity_init 2-4 15870 &ubi_io_write_15870
90033 +mtdchar_write_56831 mtdchar_write 3 56831 NULL nohasharray
90034 +ntfs_rl_realloc_56831 ntfs_rl_realloc 3 56831 &mtdchar_write_56831
90035 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
90036 +mid_get_vbt_data_r1_26170 mid_get_vbt_data_r1 2 26170 NULL
90037 +skb_copy_expand_7685 skb_copy_expand 2-3 7685 NULL nohasharray
90038 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 &skb_copy_expand_7685
90039 +if_write_51756 if_write 3 51756 NULL
90040 +insert_dent_65034 insert_dent 7 65034 NULL
90041 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
90042 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4 56847 NULL
90043 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
90044 +brcmf_sdcard_rwdata_65041 brcmf_sdcard_rwdata 5 65041 NULL
90045 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
90046 +lc_create_48662 lc_create 3 48662 NULL
90047 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
90048 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL nohasharray
90049 +sys_setgroups_48668 sys_setgroups 1 48668 &sm501_create_subdev_48668
90050 +ath9k_multi_regread_65056 ath9k_multi_regread 4 65056 NULL
90051 +brcmf_sdcard_send_buf_7713 brcmf_sdcard_send_buf 6 7713 NULL
90052 +l2cap_build_cmd_48676 l2cap_build_cmd 4 48676 NULL
90053 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
90054 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
90055 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
90056 +bnx2fc_process_l2_frame_compl_65072 bnx2fc_process_l2_frame_compl 3 65072 NULL
90057 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
90058 +persistent_ram_new_40501 persistent_ram_new 1-2 40501 NULL
90059 +ieee80211_send_auth_24121 ieee80211_send_auth 5 24121 NULL
90060 +altera_drscan_48698 altera_drscan 2 48698 NULL
90061 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
90062 +set_bypass_pwup_pfs_7742 set_bypass_pwup_pfs 3 7742 NULL
90063 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
90064 +power_read_15939 power_read 3 15939 NULL
90065 +recv_msg_48709 recv_msg 4 48709 NULL
90066 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL
90067 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
90068 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
90069 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
90070 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
90071 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
90072 +process_vm_rw_pages_15954 process_vm_rw_pages 6-5 15954 NULL
90073 +revalidate_19043 revalidate 2 19043 NULL
90074 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
90075 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 NULL
90076 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
90077 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
90078 +check_header_56930 check_header 2 56930 NULL
90079 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
90080 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
90081 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
90082 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
90083 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
90084 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
90085 +frame_alloc_15981 frame_alloc 4 15981 NULL
90086 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
90087 +nf_nat_seq_adjust_44989 nf_nat_seq_adjust 4 44989 NULL
90088 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL
90089 +adu_read_24177 adu_read 3 24177 NULL
90090 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
90091 +send_mpa_reply_32372 send_mpa_reply 3 32372 NULL
90092 +alloc_vm_area_15989 alloc_vm_area 1 15989 NULL
90093 +variax_set_raw2_32374 variax_set_raw2 4 32374 NULL
90094 +vfd_write_14717 vfd_write 3 14717 NULL
90095 +carl9170_rx_copy_data_21656 carl9170_rx_copy_data 2 21656 NULL
90096 +usbtmc_read_32377 usbtmc_read 3 32377 NULL
90097 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
90098 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
90099 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
90100 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
90101 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
90102 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
90103 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
90104 +__cxio_init_resource_fifo_23447 __cxio_init_resource_fifo 3 23447 NULL
90105 +skge_rx_get_40598 skge_rx_get 3 40598 NULL
90106 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
90107 +register_device_60015 register_device 2-3 60015 NULL
90108 +got_frame_16028 got_frame 2 16028 NULL
90109 +ssb_bus_register_65183 ssb_bus_register 3 65183 NULL
90110 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 1-2-3 24224 NULL
90111 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
90112 +scsi_register_49094 scsi_register 2 49094 NULL
90113 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
90114 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
90115 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
90116 +batadv_check_unicast_packet_10866 batadv_check_unicast_packet 2 10866 NULL
90117 +tcp_push_one_48816 tcp_push_one 2 48816 NULL
90118 +nfulnl_alloc_skb_65207 nfulnl_alloc_skb 2 65207 NULL
90119 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
90120 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
90121 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
90122 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
90123 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
90124 +svc_pool_map_alloc_arrays_47181 svc_pool_map_alloc_arrays 2 47181 NULL
90125 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
90126 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
90127 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
90128 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
90129 +compat_sys_preadv64_24283 compat_sys_preadv64 3 24283 NULL
90130 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
90131 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL
90132 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
90133 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
90134 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
90135 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
90136 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
90137 +mid_get_vbt_data_r0_10876 mid_get_vbt_data_r0 2 10876 NULL
90138 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
90139 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
90140 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 NULL nohasharray
90141 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 &dma_tx_requested_read_16110
90142 +sys_setgroups16_48882 sys_setgroups16 1 48882 NULL
90143 +kmem_zalloc_greedy_65268 kmem_zalloc_greedy 3-2 65268 NULL
90144 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
90145 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
90146 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
90147 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
90148 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
90149 +mac_drv_rx_init_48898 mac_drv_rx_init 2 48898 NULL
90150 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
90151 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
90152 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
90153 +fsm_init_16134 fsm_init 2 16134 NULL
90154 +ext_sd_execute_write_data_8175 ext_sd_execute_write_data 9 8175 NULL
90155 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
90156 +disconnect_32521 disconnect 4 32521 NULL
90157 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
90158 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
90159 +ath6kl_wmi_add_wow_pattern_cmd_12842 ath6kl_wmi_add_wow_pattern_cmd 4 12842 NULL
90160 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
90161 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
90162 +ilo_read_32531 ilo_read 3 32531 NULL
90163 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
90164 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
90165 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
90166 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
90167 +gdth_isa_probe_one_48925 gdth_isa_probe_one 1 48925 NULL
90168 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
90169 +nfc_hci_execute_cmd_async_65314 nfc_hci_execute_cmd_async 5 65314 NULL
90170 +msnd_fifo_alloc_23179 msnd_fifo_alloc 2 23179 NULL
90171 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
90172 +nfcwilink_skb_alloc_16167 nfcwilink_skb_alloc 1 16167 NULL
90173 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
90174 +remap_pci_mem_15966 remap_pci_mem 1-2 15966 NULL
90175 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
90176 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
90177 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
90178 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
90179 +card_send_command_40757 card_send_command 3 40757 NULL
90180 +sys_mbind_7990 sys_mbind 5 7990 NULL
90181 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
90182 +pg_write_40766 pg_write 3 40766 NULL
90183 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
90184 +uea_idma_write_64139 uea_idma_write 3 64139 NULL
90185 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
90186 +carl9170_rx_stream_1334 carl9170_rx_stream 3 1334 NULL
90187 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
90188 +ath_descdma_setup_12257 ath_descdma_setup 5 12257 NULL
90189 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
90190 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
90191 +batadv_orig_hash_del_if_48972 batadv_orig_hash_del_if 2 48972 NULL
90192 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
90193 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 NULL nohasharray
90194 +getxattr_24398 getxattr 4 24398 &pvr2_v4l2_ioctl_24398
90195 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
90196 +vcs_read_8017 vcs_read 3 8017 NULL
90197 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
90198 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
90199 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
90200 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
90201 +_alloc_set_attr_list_48991 _alloc_set_attr_list 4 48991 NULL
90202 +sys_set_mempolicy_32608 sys_set_mempolicy 3 32608 NULL
90203 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
90204 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
90205 +copy_and_check_19089 copy_and_check 3 19089 NULL
90206 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
90207 +netdev_alloc_skb_ip_align_40811 netdev_alloc_skb_ip_align 2 40811 NULL
90208 +i915_wedged_read_35474 i915_wedged_read 3 35474 NULL
90209 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
90210 +iser_rcv_completion_8048 iser_rcv_completion 2 8048 NULL
90211 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
90212 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
90213 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
90214 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
90215 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
90216 +smk_user_access_24440 smk_user_access 3 24440 NULL
90217 +xd_rw_49020 xd_rw 3-4 49020 NULL
90218 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
90219 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
90220 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
90221 +kvmalloc_32646 kvmalloc 1 32646 NULL
90222 +alloc_targets_8074 alloc_targets 2 8074 NULL nohasharray
90223 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 &alloc_targets_8074
90224 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
90225 +drm_calloc_large_65421 drm_calloc_large 1-2 65421 NULL
90226 +set_disc_pfs_16270 set_disc_pfs 3 16270 NULL
90227 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
90228 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
90229 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL
90230 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
90231 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
90232 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
90233 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
90234 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
90235 +pn533_init_target_frame_65438 pn533_init_target_frame 3 65438 NULL
90236 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
90237 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
90238 +i915_wedged_write_47771 i915_wedged_write 3 47771 NULL
90239 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
90240 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
90241 +l2cap_bredr_sig_cmd_49065 l2cap_bredr_sig_cmd 3 49065 NULL
90242 +tipc_buf_acquire_60437 tipc_buf_acquire 1 60437 NULL
90243 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
90244 +venus_lookup_8121 venus_lookup 4 8121 NULL
90245 +compat_writev_60063 compat_writev 3 60063 NULL
90246 +io_mapping_create_wc_1354 io_mapping_create_wc 1-2 1354 NULL
90247 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
90248 +read_file_queue_40895 read_file_queue 3 40895 NULL
90249 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
90250 +waiters_read_40902 waiters_read 3 40902 NULL
90251 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
90252 +vmalloc_node_58700 vmalloc_node 1 58700 NULL
90253 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
90254 +ath_rx_edma_init_65483 ath_rx_edma_init 2 65483 NULL
90255 +vmw_cursor_update_image_16332 vmw_cursor_update_image 3-4 16332 NULL
90256 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
90257 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
90258 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
90259 +named_prepare_buf_24532 named_prepare_buf 2 24532 NULL
90260 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
90261 +alloc_dr_65495 alloc_dr 2 65495 NULL
90262 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
90263 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
90264 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
90265 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
90266 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
90267 +rbd_add_16366 rbd_add 3 16366 NULL
90268 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
90269 +pt_read_49136 pt_read 3 49136 NULL
90270 +tsi148_alloc_resource_24563 tsi148_alloc_resource 2 24563 NULL
90271 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
90272 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
90273 +check_mirror_57342 check_mirror 1-2 57342 NULL nohasharray
90274 +usblp_read_57342 usblp_read 3 57342 &check_mirror_57342
90275 +atyfb_setup_generic_49151 atyfb_setup_generic 3 49151 NULL
90276 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
90277 new file mode 100644
90278 index 0000000..d52f2ee
90279 --- /dev/null
90280 +++ b/tools/gcc/size_overflow_plugin.c
90281 @@ -0,0 +1,1941 @@
90282 +/*
90283 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
90284 + * Licensed under the GPL v2, or (at your option) v3
90285 + *
90286 + * Homepage:
90287 + * http://www.grsecurity.net/~ephox/overflow_plugin/
90288 + *
90289 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
90290 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
90291 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
90292 + *
90293 + * Usage:
90294 + * $ 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
90295 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
90296 + */
90297 +
90298 +#include "gcc-plugin.h"
90299 +#include "config.h"
90300 +#include "system.h"
90301 +#include "coretypes.h"
90302 +#include "tree.h"
90303 +#include "tree-pass.h"
90304 +#include "intl.h"
90305 +#include "plugin-version.h"
90306 +#include "tm.h"
90307 +#include "toplev.h"
90308 +#include "function.h"
90309 +#include "tree-flow.h"
90310 +#include "plugin.h"
90311 +#include "gimple.h"
90312 +#include "c-common.h"
90313 +#include "diagnostic.h"
90314 +#include "cfgloop.h"
90315 +
90316 +#if BUILDING_GCC_VERSION >= 4007
90317 +#include "c-tree.h"
90318 +#else
90319 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
90320 +#endif
90321 +
90322 +#if BUILDING_GCC_VERSION >= 4008
90323 +#define TODO_dump_func 0
90324 +#endif
90325 +
90326 +struct size_overflow_hash {
90327 + const struct size_overflow_hash * const next;
90328 + const char * const name;
90329 + const unsigned int param;
90330 +};
90331 +
90332 +#include "size_overflow_hash.h"
90333 +
90334 +enum marked {
90335 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
90336 +};
90337 +
90338 +static unsigned int call_count = 0;
90339 +
90340 +#define __unused __attribute__((__unused__))
90341 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
90342 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
90343 +#define BEFORE_STMT true
90344 +#define AFTER_STMT false
90345 +#define CREATE_NEW_VAR NULL_TREE
90346 +#define CODES_LIMIT 32
90347 +#define MAX_PARAM 32
90348 +#define MY_STMT GF_PLF_1
90349 +#define NO_CAST_CHECK GF_PLF_2
90350 +
90351 +#if BUILDING_GCC_VERSION == 4005
90352 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
90353 +#endif
90354 +
90355 +int plugin_is_GPL_compatible;
90356 +void debug_gimple_stmt(gimple gs);
90357 +
90358 +static tree expand(struct pointer_set_t *visited, tree lhs);
90359 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
90360 +static tree report_size_overflow_decl;
90361 +static const_tree const_char_ptr_type_node;
90362 +static unsigned int handle_function(void);
90363 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
90364 +static tree get_size_overflow_type(gimple stmt, const_tree node);
90365 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
90366 +
90367 +static struct plugin_info size_overflow_plugin_info = {
90368 + .version = "20130109beta",
90369 + .help = "no-size-overflow\tturn off size overflow checking\n",
90370 +};
90371 +
90372 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
90373 +{
90374 + unsigned int arg_count;
90375 + enum tree_code code = TREE_CODE(*node);
90376 +
90377 + switch (code) {
90378 + case FUNCTION_DECL:
90379 + arg_count = type_num_arguments(TREE_TYPE(*node));
90380 + break;
90381 + case FUNCTION_TYPE:
90382 + case METHOD_TYPE:
90383 + arg_count = type_num_arguments(*node);
90384 + break;
90385 + default:
90386 + *no_add_attrs = true;
90387 + error("%s: %qE attribute only applies to functions", __func__, name);
90388 + return NULL_TREE;
90389 + }
90390 +
90391 + for (; args; args = TREE_CHAIN(args)) {
90392 + tree position = TREE_VALUE(args);
90393 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
90394 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
90395 + *no_add_attrs = true;
90396 + }
90397 + }
90398 + return NULL_TREE;
90399 +}
90400 +
90401 +static const char* get_asm_name(tree node)
90402 +{
90403 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
90404 +}
90405 +
90406 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
90407 +{
90408 + unsigned int arg_count, arg_num;
90409 + enum tree_code code = TREE_CODE(*node);
90410 +
90411 + switch (code) {
90412 + case FUNCTION_DECL:
90413 + arg_count = type_num_arguments(TREE_TYPE(*node));
90414 + break;
90415 + case FUNCTION_TYPE:
90416 + case METHOD_TYPE:
90417 + arg_count = type_num_arguments(*node);
90418 + break;
90419 + case FIELD_DECL:
90420 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
90421 + if (arg_num != 0) {
90422 + *no_add_attrs = true;
90423 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
90424 + }
90425 + return NULL_TREE;
90426 + default:
90427 + *no_add_attrs = true;
90428 + error("%qE attribute only applies to functions", name);
90429 + return NULL_TREE;
90430 + }
90431 +
90432 + for (; args; args = TREE_CHAIN(args)) {
90433 + tree position = TREE_VALUE(args);
90434 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
90435 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
90436 + *no_add_attrs = true;
90437 + }
90438 + }
90439 + return NULL_TREE;
90440 +}
90441 +
90442 +static struct attribute_spec size_overflow_attr = {
90443 + .name = "size_overflow",
90444 + .min_length = 1,
90445 + .max_length = -1,
90446 + .decl_required = true,
90447 + .type_required = false,
90448 + .function_type_required = false,
90449 + .handler = handle_size_overflow_attribute,
90450 +#if BUILDING_GCC_VERSION >= 4007
90451 + .affects_type_identity = false
90452 +#endif
90453 +};
90454 +
90455 +static struct attribute_spec intentional_overflow_attr = {
90456 + .name = "intentional_overflow",
90457 + .min_length = 1,
90458 + .max_length = -1,
90459 + .decl_required = true,
90460 + .type_required = false,
90461 + .function_type_required = false,
90462 + .handler = handle_intentional_overflow_attribute,
90463 +#if BUILDING_GCC_VERSION >= 4007
90464 + .affects_type_identity = false
90465 +#endif
90466 +};
90467 +
90468 +static void register_attributes(void __unused *event_data, void __unused *data)
90469 +{
90470 + register_attribute(&size_overflow_attr);
90471 + register_attribute(&intentional_overflow_attr);
90472 +}
90473 +
90474 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
90475 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
90476 +{
90477 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
90478 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
90479 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
90480 +
90481 + unsigned int m = 0x57559429;
90482 + unsigned int n = 0x5052acdb;
90483 + const unsigned int *key4 = (const unsigned int *)key;
90484 + unsigned int h = len;
90485 + unsigned int k = len + seed + n;
90486 + unsigned long long p;
90487 +
90488 + while (len >= 8) {
90489 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
90490 + len -= 8;
90491 + }
90492 + if (len >= 4) {
90493 + cwmixb(key4[0]) key4 += 1;
90494 + len -= 4;
90495 + }
90496 + if (len)
90497 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
90498 + cwmixb(h ^ (k + n));
90499 + return k ^ h;
90500 +
90501 +#undef cwfold
90502 +#undef cwmixa
90503 +#undef cwmixb
90504 +}
90505 +
90506 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
90507 +{
90508 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
90509 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
90510 + return fn ^ codes;
90511 +}
90512 +
90513 +static inline tree get_original_function_decl(tree fndecl)
90514 +{
90515 + if (DECL_ABSTRACT_ORIGIN(fndecl))
90516 + return DECL_ABSTRACT_ORIGIN(fndecl);
90517 + return fndecl;
90518 +}
90519 +
90520 +static inline gimple get_def_stmt(const_tree node)
90521 +{
90522 + gcc_assert(node != NULL_TREE);
90523 + gcc_assert(TREE_CODE(node) == SSA_NAME);
90524 + return SSA_NAME_DEF_STMT(node);
90525 +}
90526 +
90527 +static unsigned char get_tree_code(const_tree type)
90528 +{
90529 + switch (TREE_CODE(type)) {
90530 + case ARRAY_TYPE:
90531 + return 0;
90532 + case BOOLEAN_TYPE:
90533 + return 1;
90534 + case ENUMERAL_TYPE:
90535 + return 2;
90536 + case FUNCTION_TYPE:
90537 + return 3;
90538 + case INTEGER_TYPE:
90539 + return 4;
90540 + case POINTER_TYPE:
90541 + return 5;
90542 + case RECORD_TYPE:
90543 + return 6;
90544 + case UNION_TYPE:
90545 + return 7;
90546 + case VOID_TYPE:
90547 + return 8;
90548 + case REAL_TYPE:
90549 + return 9;
90550 + case VECTOR_TYPE:
90551 + return 10;
90552 + case REFERENCE_TYPE:
90553 + return 11;
90554 + case OFFSET_TYPE:
90555 + return 12;
90556 + case COMPLEX_TYPE:
90557 + return 13;
90558 + default:
90559 + debug_tree((tree)type);
90560 + gcc_unreachable();
90561 + }
90562 +}
90563 +
90564 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
90565 +{
90566 + gcc_assert(type != NULL_TREE);
90567 +
90568 + while (type && len < CODES_LIMIT) {
90569 + tree_codes[len] = get_tree_code(type);
90570 + len++;
90571 + type = TREE_TYPE(type);
90572 + }
90573 + return len;
90574 +}
90575 +
90576 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
90577 +{
90578 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
90579 + enum tree_code code = TREE_CODE(type);
90580 + size_t len = 0;
90581 +
90582 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
90583 +
90584 + arg = TYPE_ARG_TYPES(type);
90585 + // skip builtins __builtin_constant_p
90586 + if (!arg && DECL_BUILT_IN(fndecl))
90587 + return 0;
90588 +
90589 + if (TREE_CODE_CLASS(code) == tcc_type)
90590 + result = type;
90591 + else
90592 + result = DECL_RESULT(fndecl);
90593 +
90594 + gcc_assert(result != NULL_TREE);
90595 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
90596 +
90597 + if (arg == NULL_TREE) {
90598 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
90599 + arg_field = DECL_ARGUMENT_FLD(fndecl);
90600 + if (arg_field == NULL_TREE)
90601 + return 0;
90602 + arg = TREE_TYPE(arg_field);
90603 + len = add_type_codes(arg, tree_codes, len);
90604 + gcc_assert(len != 0);
90605 + return len;
90606 + }
90607 +
90608 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
90609 + while (arg && len < CODES_LIMIT) {
90610 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
90611 + arg = TREE_CHAIN(arg);
90612 + }
90613 +
90614 + gcc_assert(len != 0);
90615 + return len;
90616 +}
90617 +
90618 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
90619 +{
90620 + unsigned int hash;
90621 + const struct size_overflow_hash *entry;
90622 + unsigned char tree_codes[CODES_LIMIT];
90623 + size_t len;
90624 + const char *func_name = get_asm_name(fndecl);
90625 +
90626 + len = get_function_decl(fndecl, tree_codes);
90627 + if (len == 0)
90628 + return NULL;
90629 +
90630 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
90631 +
90632 + entry = size_overflow_hash[hash];
90633 + while (entry) {
90634 + if (!strcmp(entry->name, func_name))
90635 + return entry;
90636 + entry = entry->next;
90637 + }
90638 +
90639 + return NULL;
90640 +}
90641 +
90642 +static void check_arg_type(const_tree arg)
90643 +{
90644 + const_tree type = TREE_TYPE(arg);
90645 + enum tree_code code = TREE_CODE(type);
90646 +
90647 + if (code == BOOLEAN_TYPE)
90648 + return;
90649 +
90650 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
90651 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
90652 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
90653 +}
90654 +
90655 +static unsigned int find_arg_number(const_tree arg, tree func)
90656 +{
90657 + tree var;
90658 + unsigned int argnum = 1;
90659 +
90660 + if (TREE_CODE(arg) == SSA_NAME)
90661 + arg = SSA_NAME_VAR(arg);
90662 +
90663 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
90664 + if (strcmp(NAME(arg), NAME(var))) {
90665 + argnum++;
90666 + continue;
90667 + }
90668 + check_arg_type(var);
90669 + return argnum;
90670 + }
90671 + gcc_unreachable();
90672 +}
90673 +
90674 +static tree create_new_var(tree type)
90675 +{
90676 + tree new_var = create_tmp_var(type, "cicus");
90677 +
90678 +#if BUILDING_GCC_VERSION <= 4007
90679 + add_referenced_var(new_var);
90680 + mark_sym_for_renaming(new_var);
90681 +#endif
90682 + return new_var;
90683 +}
90684 +
90685 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
90686 +{
90687 + gimple assign;
90688 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
90689 + tree type = TREE_TYPE(rhs1);
90690 + tree lhs = create_new_var(type);
90691 +
90692 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
90693 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
90694 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
90695 +
90696 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
90697 + update_stmt(assign);
90698 + gimple_set_plf(assign, MY_STMT, true);
90699 + return assign;
90700 +}
90701 +
90702 +static bool is_bool(const_tree node)
90703 +{
90704 + const_tree type;
90705 +
90706 + if (node == NULL_TREE)
90707 + return false;
90708 +
90709 + type = TREE_TYPE(node);
90710 + if (!INTEGRAL_TYPE_P(type))
90711 + return false;
90712 + if (TREE_CODE(type) == BOOLEAN_TYPE)
90713 + return true;
90714 + if (TYPE_PRECISION(type) == 1)
90715 + return true;
90716 + return false;
90717 +}
90718 +
90719 +static tree cast_a_tree(tree type, tree var)
90720 +{
90721 + gcc_assert(type != NULL_TREE);
90722 + gcc_assert(var != NULL_TREE);
90723 + gcc_assert(fold_convertible_p(type, var));
90724 +
90725 + return fold_convert(type, var);
90726 +}
90727 +
90728 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
90729 +{
90730 + gimple assign;
90731 +
90732 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
90733 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
90734 + gcc_unreachable();
90735 +
90736 + if (lhs == CREATE_NEW_VAR)
90737 + lhs = create_new_var(dst_type);
90738 +
90739 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
90740 +
90741 + if (!gsi_end_p(*gsi)) {
90742 + location_t loc = gimple_location(gsi_stmt(*gsi));
90743 + gimple_set_location(assign, loc);
90744 + }
90745 +
90746 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
90747 +
90748 + if (before)
90749 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
90750 + else
90751 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
90752 + update_stmt(assign);
90753 + gimple_set_plf(assign, MY_STMT, true);
90754 +
90755 + return assign;
90756 +}
90757 +
90758 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
90759 +{
90760 + gimple assign;
90761 + gimple_stmt_iterator gsi;
90762 +
90763 + if (rhs == NULL_TREE)
90764 + return NULL_TREE;
90765 +
90766 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
90767 + return rhs;
90768 +
90769 + gsi = gsi_for_stmt(stmt);
90770 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
90771 + gimple_set_plf(assign, MY_STMT, true);
90772 + return gimple_get_lhs(assign);
90773 +}
90774 +
90775 +static tree cast_to_TI_type(gimple stmt, tree node)
90776 +{
90777 + gimple_stmt_iterator gsi;
90778 + gimple cast_stmt;
90779 + tree type = TREE_TYPE(node);
90780 +
90781 + if (types_compatible_p(type, intTI_type_node))
90782 + return node;
90783 +
90784 + gsi = gsi_for_stmt(stmt);
90785 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
90786 + gimple_set_plf(cast_stmt, MY_STMT, true);
90787 + return gimple_get_lhs(cast_stmt);
90788 +}
90789 +
90790 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
90791 +{
90792 + tree lhs;
90793 + gimple_stmt_iterator gsi;
90794 +
90795 + if (rhs1 == NULL_TREE) {
90796 + debug_gimple_stmt(oldstmt);
90797 + error("%s: rhs1 is NULL_TREE", __func__);
90798 + gcc_unreachable();
90799 + }
90800 +
90801 + switch (gimple_code(oldstmt)) {
90802 + case GIMPLE_ASM:
90803 + lhs = rhs1;
90804 + break;
90805 + case GIMPLE_CALL:
90806 + lhs = gimple_call_lhs(oldstmt);
90807 + break;
90808 + case GIMPLE_ASSIGN:
90809 + lhs = gimple_get_lhs(oldstmt);
90810 + break;
90811 + default:
90812 + debug_gimple_stmt(oldstmt);
90813 + gcc_unreachable();
90814 + }
90815 +
90816 + gsi = gsi_for_stmt(oldstmt);
90817 + pointer_set_insert(visited, oldstmt);
90818 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
90819 + basic_block next_bb, cur_bb;
90820 + const_edge e;
90821 +
90822 + gcc_assert(before == false);
90823 + gcc_assert(stmt_can_throw_internal(oldstmt));
90824 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
90825 + gcc_assert(!gsi_end_p(gsi));
90826 +
90827 + cur_bb = gimple_bb(oldstmt);
90828 + next_bb = cur_bb->next_bb;
90829 + e = find_edge(cur_bb, next_bb);
90830 + gcc_assert(e != NULL);
90831 + gcc_assert(e->flags & EDGE_FALLTHRU);
90832 +
90833 + gsi = gsi_after_labels(next_bb);
90834 + gcc_assert(!gsi_end_p(gsi));
90835 +
90836 + before = true;
90837 + oldstmt = gsi_stmt(gsi);
90838 + }
90839 +
90840 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
90841 +}
90842 +
90843 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
90844 +{
90845 + gimple stmt;
90846 + gimple_stmt_iterator gsi;
90847 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
90848 +
90849 + if (gimple_plf(oldstmt, MY_STMT))
90850 + return lhs;
90851 +
90852 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
90853 + rhs1 = gimple_assign_rhs1(oldstmt);
90854 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
90855 + }
90856 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
90857 + rhs2 = gimple_assign_rhs2(oldstmt);
90858 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
90859 + }
90860 +
90861 + stmt = gimple_copy(oldstmt);
90862 + gimple_set_location(stmt, gimple_location(oldstmt));
90863 + gimple_set_plf(stmt, MY_STMT, true);
90864 +
90865 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
90866 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
90867 +
90868 + size_overflow_type = get_size_overflow_type(oldstmt, node);
90869 +
90870 + if (is_bool(lhs))
90871 + new_var = SSA_NAME_VAR(lhs);
90872 + else
90873 + new_var = create_new_var(size_overflow_type);
90874 + new_var = make_ssa_name(new_var, stmt);
90875 + gimple_set_lhs(stmt, new_var);
90876 +
90877 + if (rhs1 != NULL_TREE)
90878 + gimple_assign_set_rhs1(stmt, rhs1);
90879 +
90880 + if (rhs2 != NULL_TREE)
90881 + gimple_assign_set_rhs2(stmt, rhs2);
90882 +#if BUILDING_GCC_VERSION >= 4007
90883 + if (rhs3 != NULL_TREE)
90884 + gimple_assign_set_rhs3(stmt, rhs3);
90885 +#endif
90886 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
90887 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
90888 +
90889 + gsi = gsi_for_stmt(oldstmt);
90890 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
90891 + update_stmt(stmt);
90892 + pointer_set_insert(visited, oldstmt);
90893 + return gimple_get_lhs(stmt);
90894 +}
90895 +
90896 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
90897 +{
90898 + basic_block bb;
90899 + gimple phi;
90900 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
90901 + gimple_seq seq;
90902 +
90903 + bb = gsi_bb(gsi);
90904 +
90905 + phi = create_phi_node(result, bb);
90906 + seq = phi_nodes(bb);
90907 + gsi = gsi_last(seq);
90908 + gsi_remove(&gsi, false);
90909 +
90910 + gsi = gsi_for_stmt(oldstmt);
90911 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
90912 + gimple_set_bb(phi, bb);
90913 + gimple_set_plf(phi, MY_STMT, true);
90914 + return phi;
90915 +}
90916 +
90917 +static basic_block create_a_first_bb(void)
90918 +{
90919 + basic_block first_bb;
90920 +
90921 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
90922 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
90923 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
90924 + return first_bb;
90925 +}
90926 +
90927 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
90928 +{
90929 + basic_block bb;
90930 + const_gimple newstmt;
90931 + gimple_stmt_iterator gsi;
90932 + bool before = BEFORE_STMT;
90933 +
90934 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
90935 + gsi = gsi_for_stmt(get_def_stmt(arg));
90936 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
90937 + return gimple_get_lhs(newstmt);
90938 + }
90939 +
90940 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
90941 + gsi = gsi_after_labels(bb);
90942 + if (bb->index == 0) {
90943 + bb = create_a_first_bb();
90944 + gsi = gsi_start_bb(bb);
90945 + }
90946 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
90947 + return gimple_get_lhs(newstmt);
90948 +}
90949 +
90950 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
90951 +{
90952 + gimple newstmt;
90953 + gimple_stmt_iterator gsi;
90954 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
90955 + gimple def_newstmt = get_def_stmt(new_rhs);
90956 +
90957 + gsi_insert = gsi_insert_after;
90958 + gsi = gsi_for_stmt(def_newstmt);
90959 +
90960 + switch (gimple_code(get_def_stmt(arg))) {
90961 + case GIMPLE_PHI:
90962 + newstmt = gimple_build_assign(new_var, new_rhs);
90963 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
90964 + gsi_insert = gsi_insert_before;
90965 + break;
90966 + case GIMPLE_ASM:
90967 + case GIMPLE_CALL:
90968 + newstmt = gimple_build_assign(new_var, new_rhs);
90969 + break;
90970 + case GIMPLE_ASSIGN:
90971 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
90972 + break;
90973 + default:
90974 + /* unknown gimple_code (handle_build_new_phi_arg) */
90975 + gcc_unreachable();
90976 + }
90977 +
90978 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
90979 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
90980 + gimple_set_plf(newstmt, MY_STMT, true);
90981 + update_stmt(newstmt);
90982 + return newstmt;
90983 +}
90984 +
90985 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
90986 +{
90987 + const_gimple newstmt;
90988 + gimple def_stmt;
90989 + tree new_rhs;
90990 +
90991 + new_rhs = expand(visited, arg);
90992 + if (new_rhs == NULL_TREE)
90993 + return NULL_TREE;
90994 +
90995 + def_stmt = get_def_stmt(new_rhs);
90996 + if (gimple_code(def_stmt) == GIMPLE_NOP)
90997 + return NULL_TREE;
90998 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
90999 +
91000 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
91001 + return gimple_get_lhs(newstmt);
91002 +}
91003 +
91004 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
91005 +{
91006 + gimple phi, oldstmt = get_def_stmt(orig_result);
91007 + tree new_result, size_overflow_type;
91008 + unsigned int i;
91009 + unsigned int n = gimple_phi_num_args(oldstmt);
91010 +
91011 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
91012 +
91013 + new_result = create_new_var(size_overflow_type);
91014 +
91015 + pointer_set_insert(visited, oldstmt);
91016 + phi = overflow_create_phi_node(oldstmt, new_result);
91017 + for (i = 0; i < n; i++) {
91018 + tree arg, lhs;
91019 +
91020 + arg = gimple_phi_arg_def(oldstmt, i);
91021 + if (is_gimple_constant(arg))
91022 + arg = cast_a_tree(size_overflow_type, arg);
91023 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
91024 + if (lhs == NULL_TREE)
91025 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
91026 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
91027 + }
91028 +
91029 + update_stmt(phi);
91030 + return gimple_phi_result(phi);
91031 +}
91032 +
91033 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
91034 +{
91035 + const_gimple assign;
91036 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
91037 + tree origtype = TREE_TYPE(orig_rhs);
91038 +
91039 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
91040 +
91041 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
91042 + return gimple_get_lhs(assign);
91043 +}
91044 +
91045 +static void change_rhs1(gimple stmt, tree new_rhs1)
91046 +{
91047 + tree assign_rhs;
91048 + const_tree rhs = gimple_assign_rhs1(stmt);
91049 +
91050 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
91051 + gimple_assign_set_rhs1(stmt, assign_rhs);
91052 + update_stmt(stmt);
91053 +}
91054 +
91055 +static bool check_mode_type(const_gimple stmt)
91056 +{
91057 + const_tree lhs = gimple_get_lhs(stmt);
91058 + const_tree lhs_type = TREE_TYPE(lhs);
91059 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
91060 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
91061 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
91062 +
91063 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
91064 + return false;
91065 +
91066 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
91067 + return false;
91068 +
91069 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast
91070 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
91071 + return false;
91072 +
91073 + return true;
91074 +}
91075 +
91076 +static bool check_undefined_integer_operation(const_gimple stmt)
91077 +{
91078 + const_gimple def_stmt;
91079 + const_tree lhs = gimple_get_lhs(stmt);
91080 + const_tree rhs1 = gimple_assign_rhs1(stmt);
91081 + const_tree rhs1_type = TREE_TYPE(rhs1);
91082 + const_tree lhs_type = TREE_TYPE(lhs);
91083 +
91084 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
91085 + return false;
91086 +
91087 + def_stmt = get_def_stmt(rhs1);
91088 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
91089 + return false;
91090 +
91091 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
91092 + return false;
91093 + return true;
91094 +}
91095 +
91096 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
91097 +{
91098 + const_tree rhs1, lhs, rhs1_type, lhs_type;
91099 + enum machine_mode lhs_mode, rhs_mode;
91100 + gimple def_stmt = get_def_stmt(no_const_rhs);
91101 +
91102 + if (!gimple_assign_cast_p(def_stmt))
91103 + return false;
91104 +
91105 + rhs1 = gimple_assign_rhs1(def_stmt);
91106 + lhs = gimple_get_lhs(def_stmt);
91107 + rhs1_type = TREE_TYPE(rhs1);
91108 + lhs_type = TREE_TYPE(lhs);
91109 + rhs_mode = TYPE_MODE(rhs1_type);
91110 + lhs_mode = TYPE_MODE(lhs_type);
91111 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
91112 + return false;
91113 +
91114 + return true;
91115 +}
91116 +
91117 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
91118 +{
91119 + tree rhs1 = gimple_assign_rhs1(stmt);
91120 + tree lhs = gimple_get_lhs(stmt);
91121 + const_tree rhs1_type = TREE_TYPE(rhs1);
91122 + const_tree lhs_type = TREE_TYPE(lhs);
91123 +
91124 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
91125 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91126 +
91127 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
91128 +}
91129 +
91130 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
91131 +{
91132 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
91133 + tree new_rhs1 = NULL_TREE;
91134 + tree rhs1 = gimple_assign_rhs1(stmt);
91135 + const_tree rhs1_type = TREE_TYPE(rhs1);
91136 + const_tree lhs_type = TREE_TYPE(lhs);
91137 +
91138 + if (gimple_plf(stmt, MY_STMT))
91139 + return lhs;
91140 +
91141 + if (TREE_CODE(rhs1_type) == POINTER_TYPE)
91142 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91143 +
91144 + new_rhs1 = expand(visited, rhs1);
91145 +
91146 + if (new_rhs1 == NULL_TREE)
91147 + return create_cast_assign(visited, stmt);
91148 +
91149 + if (gimple_plf(stmt, NO_CAST_CHECK))
91150 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
91151 +
91152 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
91153 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
91154 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
91155 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
91156 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91157 + }
91158 +
91159 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
91160 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
91161 +
91162 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
91163 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
91164 +
91165 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
91166 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
91167 +
91168 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
91169 +
91170 + change_rhs1(stmt, new_rhs1);
91171 +
91172 + if (!check_mode_type(stmt))
91173 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91174 +
91175 + size_overflow_type = get_size_overflow_type(stmt, lhs);
91176 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
91177 +
91178 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
91179 +
91180 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91181 +}
91182 +
91183 +static tree handle_unary_ops(struct pointer_set_t *visited, gimple stmt)
91184 +{
91185 + tree rhs1, lhs = gimple_get_lhs(stmt);
91186 + gimple def_stmt = get_def_stmt(lhs);
91187 +
91188 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
91189 + rhs1 = gimple_assign_rhs1(def_stmt);
91190 +
91191 + if (is_gimple_constant(rhs1))
91192 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
91193 +
91194 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
91195 + switch (TREE_CODE(rhs1)) {
91196 + case SSA_NAME:
91197 + return handle_unary_rhs(visited, def_stmt);
91198 + case ARRAY_REF:
91199 + case BIT_FIELD_REF:
91200 + case ADDR_EXPR:
91201 + case COMPONENT_REF:
91202 + case INDIRECT_REF:
91203 +#if BUILDING_GCC_VERSION >= 4006
91204 + case MEM_REF:
91205 +#endif
91206 + case TARGET_MEM_REF:
91207 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
91208 + case PARM_DECL:
91209 + case VAR_DECL:
91210 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91211 +
91212 + default:
91213 + debug_gimple_stmt(def_stmt);
91214 + debug_tree(rhs1);
91215 + gcc_unreachable();
91216 + }
91217 +}
91218 +
91219 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
91220 +{
91221 + gimple cond_stmt;
91222 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
91223 +
91224 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
91225 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
91226 + update_stmt(cond_stmt);
91227 +}
91228 +
91229 +static tree create_string_param(tree string)
91230 +{
91231 + tree i_type, a_type;
91232 + const int length = TREE_STRING_LENGTH(string);
91233 +
91234 + gcc_assert(length > 0);
91235 +
91236 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
91237 + a_type = build_array_type(char_type_node, i_type);
91238 +
91239 + TREE_TYPE(string) = a_type;
91240 + TREE_CONSTANT(string) = 1;
91241 + TREE_READONLY(string) = 1;
91242 +
91243 + return build1(ADDR_EXPR, ptr_type_node, string);
91244 +}
91245 +
91246 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
91247 +{
91248 + gimple func_stmt;
91249 + const_gimple def_stmt;
91250 + const_tree loc_line;
91251 + tree loc_file, ssa_name, current_func;
91252 + expanded_location xloc;
91253 + char *ssa_name_buf;
91254 + int len;
91255 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
91256 +
91257 + def_stmt = get_def_stmt(arg);
91258 + xloc = expand_location(gimple_location(def_stmt));
91259 +
91260 + if (!gimple_has_location(def_stmt)) {
91261 + xloc = expand_location(gimple_location(stmt));
91262 + if (!gimple_has_location(stmt))
91263 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
91264 + }
91265 +
91266 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
91267 +
91268 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
91269 + loc_file = create_string_param(loc_file);
91270 +
91271 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
91272 + current_func = create_string_param(current_func);
91273 +
91274 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
91275 + call_count++;
91276 + 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);
91277 + gcc_assert(len > 0);
91278 + ssa_name = build_string(len + 1, ssa_name_buf);
91279 + free(ssa_name_buf);
91280 + ssa_name = create_string_param(ssa_name);
91281 +
91282 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
91283 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
91284 +
91285 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
91286 +}
91287 +
91288 +static void __unused print_the_code_insertions(const_gimple stmt)
91289 +{
91290 + location_t loc = gimple_location(stmt);
91291 +
91292 + inform(loc, "Integer size_overflow check applied here.");
91293 +}
91294 +
91295 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
91296 +{
91297 + basic_block cond_bb, join_bb, bb_true;
91298 + edge e;
91299 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
91300 +
91301 + cond_bb = gimple_bb(stmt);
91302 + if (before)
91303 + gsi_prev(&gsi);
91304 + if (gsi_end_p(gsi))
91305 + e = split_block_after_labels(cond_bb);
91306 + else
91307 + e = split_block(cond_bb, gsi_stmt(gsi));
91308 + cond_bb = e->src;
91309 + join_bb = e->dest;
91310 + e->flags = EDGE_FALSE_VALUE;
91311 + e->probability = REG_BR_PROB_BASE;
91312 +
91313 + bb_true = create_empty_bb(cond_bb);
91314 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
91315 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
91316 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
91317 +
91318 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
91319 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
91320 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
91321 +
91322 + if (current_loops != NULL) {
91323 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
91324 + add_bb_to_loop(bb_true, cond_bb->loop_father);
91325 + }
91326 +
91327 + insert_cond(cond_bb, arg, cond_code, type_value);
91328 + insert_cond_result(bb_true, stmt, arg, min);
91329 +
91330 +// print_the_code_insertions(stmt);
91331 +}
91332 +
91333 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
91334 +{
91335 + const_tree rhs_type = TREE_TYPE(rhs);
91336 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
91337 +
91338 + gcc_assert(rhs_type != NULL_TREE);
91339 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
91340 + return;
91341 +
91342 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
91343 +
91344 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
91345 + // typemax (-1) < typemin (0)
91346 + if (TREE_OVERFLOW(type_max))
91347 + return;
91348 +
91349 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
91350 +
91351 + cast_rhs_type = TREE_TYPE(cast_rhs);
91352 + type_max_type = TREE_TYPE(type_max);
91353 + type_min_type = TREE_TYPE(type_min);
91354 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
91355 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
91356 +
91357 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
91358 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
91359 +}
91360 +
91361 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
91362 +{
91363 + gimple change_rhs_def_stmt;
91364 + tree lhs = gimple_get_lhs(def_stmt);
91365 + tree lhs_type = TREE_TYPE(lhs);
91366 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
91367 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
91368 +
91369 + if (change_rhs == NULL_TREE)
91370 + return get_size_overflow_type(def_stmt, lhs);
91371 +
91372 + change_rhs_def_stmt = get_def_stmt(change_rhs);
91373 +
91374 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
91375 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
91376 +
91377 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
91378 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
91379 +
91380 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
91381 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
91382 +
91383 + if (!types_compatible_p(lhs_type, rhs1_type) || !types_compatible_p(rhs1_type, rhs2_type)) {
91384 + debug_gimple_stmt(def_stmt);
91385 + gcc_unreachable();
91386 + }
91387 +
91388 + return get_size_overflow_type(def_stmt, lhs);
91389 +}
91390 +
91391 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
91392 +{
91393 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
91394 + return false;
91395 + if (!is_gimple_constant(rhs))
91396 + return false;
91397 + return true;
91398 +}
91399 +
91400 +static bool is_subtraction_special(const_gimple stmt)
91401 +{
91402 + gimple rhs1_def_stmt, rhs2_def_stmt;
91403 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
91404 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
91405 + const_tree rhs1 = gimple_assign_rhs1(stmt);
91406 + const_tree rhs2 = gimple_assign_rhs2(stmt);
91407 +
91408 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
91409 + return false;
91410 +
91411 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
91412 +
91413 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
91414 + return false;
91415 +
91416 + rhs1_def_stmt = get_def_stmt(rhs1);
91417 + rhs2_def_stmt = get_def_stmt(rhs2);
91418 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
91419 + return false;
91420 +
91421 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
91422 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
91423 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
91424 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
91425 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
91426 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
91427 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
91428 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
91429 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
91430 + return false;
91431 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
91432 + return false;
91433 +
91434 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
91435 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
91436 + return true;
91437 +}
91438 +
91439 +static tree get_def_stmt_rhs(const_tree var)
91440 +{
91441 + tree rhs1, def_stmt_rhs1;
91442 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
91443 +
91444 + def_stmt = get_def_stmt(var);
91445 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
91446 +
91447 + rhs1 = gimple_assign_rhs1(def_stmt);
91448 + rhs1_def_stmt = get_def_stmt(rhs1);
91449 + if (!gimple_assign_cast_p(rhs1_def_stmt))
91450 + return rhs1;
91451 +
91452 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
91453 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
91454 +
91455 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
91456 + case GIMPLE_CALL:
91457 + case GIMPLE_NOP:
91458 + case GIMPLE_ASM:
91459 + return def_stmt_rhs1;
91460 + case GIMPLE_ASSIGN:
91461 + return rhs1;
91462 + default:
91463 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
91464 + gcc_unreachable();
91465 + }
91466 +}
91467 +
91468 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
91469 +{
91470 + tree new_rhs1, new_rhs2;
91471 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
91472 + gimple assign, stmt = get_def_stmt(lhs);
91473 + tree rhs1 = gimple_assign_rhs1(stmt);
91474 + tree rhs2 = gimple_assign_rhs2(stmt);
91475 +
91476 + if (!is_subtraction_special(stmt))
91477 + return NULL_TREE;
91478 +
91479 + new_rhs1 = expand(visited, rhs1);
91480 + new_rhs2 = expand(visited, rhs2);
91481 +
91482 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
91483 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
91484 +
91485 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
91486 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
91487 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
91488 + }
91489 +
91490 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
91491 + new_lhs = gimple_get_lhs(assign);
91492 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
91493 +
91494 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
91495 +}
91496 +
91497 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
91498 +{
91499 + const_gimple def_stmt;
91500 +
91501 + if (TREE_CODE(rhs) != SSA_NAME)
91502 + return false;
91503 +
91504 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
91505 + return false;
91506 +
91507 + def_stmt = get_def_stmt(rhs);
91508 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
91509 + return false;
91510 +
91511 + return true;
91512 +}
91513 +
91514 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
91515 +{
91516 + tree new_rhs, size_overflow_type, orig_rhs;
91517 + void (*gimple_assign_set_rhs)(gimple, tree);
91518 + tree rhs1 = gimple_assign_rhs1(stmt);
91519 + tree rhs2 = gimple_assign_rhs2(stmt);
91520 + tree lhs = gimple_get_lhs(stmt);
91521 +
91522 + if (change_rhs == NULL_TREE)
91523 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91524 +
91525 + if (new_rhs2 == NULL_TREE) {
91526 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
91527 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
91528 + orig_rhs = rhs1;
91529 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
91530 + } else {
91531 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
91532 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
91533 + orig_rhs = rhs2;
91534 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
91535 + }
91536 +
91537 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
91538 +
91539 + if (check_overflow)
91540 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
91541 +
91542 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
91543 + gimple_assign_set_rhs(stmt, new_rhs);
91544 + update_stmt(stmt);
91545 +
91546 + return create_assign(visited, stmt, lhs, AFTER_STMT);
91547 +}
91548 +
91549 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
91550 +{
91551 + tree rhs1, rhs2, new_lhs;
91552 + gimple def_stmt = get_def_stmt(lhs);
91553 + tree new_rhs1 = NULL_TREE;
91554 + tree new_rhs2 = NULL_TREE;
91555 +
91556 + rhs1 = gimple_assign_rhs1(def_stmt);
91557 + rhs2 = gimple_assign_rhs2(def_stmt);
91558 +
91559 + /* no DImode/TImode division in the 32/64 bit kernel */
91560 + switch (gimple_assign_rhs_code(def_stmt)) {
91561 + case RDIV_EXPR:
91562 + case TRUNC_DIV_EXPR:
91563 + case CEIL_DIV_EXPR:
91564 + case FLOOR_DIV_EXPR:
91565 + case ROUND_DIV_EXPR:
91566 + case TRUNC_MOD_EXPR:
91567 + case CEIL_MOD_EXPR:
91568 + case FLOOR_MOD_EXPR:
91569 + case ROUND_MOD_EXPR:
91570 + case EXACT_DIV_EXPR:
91571 + case POINTER_PLUS_EXPR:
91572 + case BIT_AND_EXPR:
91573 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
91574 + default:
91575 + break;
91576 + }
91577 +
91578 + new_lhs = handle_integer_truncation(visited, lhs);
91579 + if (new_lhs != NULL_TREE)
91580 + return new_lhs;
91581 +
91582 + if (TREE_CODE(rhs1) == SSA_NAME)
91583 + new_rhs1 = expand(visited, rhs1);
91584 + if (TREE_CODE(rhs2) == SSA_NAME)
91585 + new_rhs2 = expand(visited, rhs2);
91586 +
91587 + if (is_a_neg_overflow(def_stmt, rhs2))
91588 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
91589 + if (is_a_neg_overflow(def_stmt, rhs1))
91590 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
91591 +
91592 + if (is_a_constant_overflow(def_stmt, rhs2))
91593 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
91594 + if (is_a_constant_overflow(def_stmt, rhs1))
91595 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
91596 +
91597 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
91598 +}
91599 +
91600 +#if BUILDING_GCC_VERSION >= 4007
91601 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
91602 +{
91603 + if (is_gimple_constant(rhs))
91604 + return cast_a_tree(size_overflow_type, rhs);
91605 + if (TREE_CODE(rhs) != SSA_NAME)
91606 + return NULL_TREE;
91607 + return expand(visited, rhs);
91608 +}
91609 +
91610 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
91611 +{
91612 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
91613 + gimple def_stmt = get_def_stmt(lhs);
91614 +
91615 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
91616 +
91617 + rhs1 = gimple_assign_rhs1(def_stmt);
91618 + rhs2 = gimple_assign_rhs2(def_stmt);
91619 + rhs3 = gimple_assign_rhs3(def_stmt);
91620 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
91621 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
91622 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
91623 +
91624 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
91625 +}
91626 +#endif
91627 +
91628 +static tree get_size_overflow_type(gimple stmt, const_tree node)
91629 +{
91630 + const_tree type;
91631 + tree new_type;
91632 +
91633 + gcc_assert(node != NULL_TREE);
91634 +
91635 + type = TREE_TYPE(node);
91636 +
91637 + if (gimple_plf(stmt, MY_STMT))
91638 + return TREE_TYPE(node);
91639 +
91640 + switch (TYPE_MODE(type)) {
91641 + case QImode:
91642 + new_type = intHI_type_node;
91643 + break;
91644 + case HImode:
91645 + new_type = intSI_type_node;
91646 + break;
91647 + case SImode:
91648 + new_type = intDI_type_node;
91649 + break;
91650 + case DImode:
91651 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
91652 + new_type = intDI_type_node;
91653 + else
91654 + new_type = intTI_type_node;
91655 + break;
91656 + default:
91657 + debug_tree((tree)node);
91658 + error("%s: unsupported gcc configuration.", __func__);
91659 + gcc_unreachable();
91660 + }
91661 +
91662 + if (TYPE_QUALS(type) != 0)
91663 + return build_qualified_type(new_type, TYPE_QUALS(type));
91664 + return new_type;
91665 +}
91666 +
91667 +static tree expand_visited(gimple def_stmt)
91668 +{
91669 + const_gimple next_stmt;
91670 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
91671 +
91672 + gsi_next(&gsi);
91673 + next_stmt = gsi_stmt(gsi);
91674 +
91675 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
91676 +
91677 + switch (gimple_code(next_stmt)) {
91678 + case GIMPLE_ASSIGN:
91679 + return gimple_get_lhs(next_stmt);
91680 + case GIMPLE_PHI:
91681 + return gimple_phi_result(next_stmt);
91682 + case GIMPLE_CALL:
91683 + return gimple_call_lhs(next_stmt);
91684 + default:
91685 + return NULL_TREE;
91686 + }
91687 +}
91688 +
91689 +static tree expand(struct pointer_set_t *visited, tree lhs)
91690 +{
91691 + gimple def_stmt;
91692 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
91693 +
91694 + if (is_gimple_constant(lhs))
91695 + return NULL_TREE;
91696 +
91697 + if (TREE_CODE(lhs) == ADDR_EXPR)
91698 + return NULL_TREE;
91699 +
91700 + if (code == REAL_TYPE)
91701 + return NULL_TREE;
91702 +
91703 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
91704 +
91705 + def_stmt = get_def_stmt(lhs);
91706 +
91707 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
91708 + return NULL_TREE;
91709 +
91710 + if (gimple_plf(def_stmt, MY_STMT))
91711 + return lhs;
91712 +
91713 + if (pointer_set_contains(visited, def_stmt))
91714 + return expand_visited(def_stmt);
91715 +
91716 + switch (gimple_code(def_stmt)) {
91717 + case GIMPLE_PHI:
91718 + return build_new_phi(visited, lhs);
91719 + case GIMPLE_CALL:
91720 + case GIMPLE_ASM:
91721 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
91722 + case GIMPLE_ASSIGN:
91723 + switch (gimple_num_ops(def_stmt)) {
91724 + case 2:
91725 + return handle_unary_ops(visited, def_stmt);
91726 + case 3:
91727 + return handle_binary_ops(visited, lhs);
91728 +#if BUILDING_GCC_VERSION >= 4007
91729 + case 4:
91730 + return handle_ternary_ops(visited, lhs);
91731 +#endif
91732 + }
91733 + default:
91734 + debug_gimple_stmt(def_stmt);
91735 + error("%s: unknown gimple code", __func__);
91736 + gcc_unreachable();
91737 + }
91738 +}
91739 +
91740 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
91741 +{
91742 + const_gimple assign;
91743 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
91744 + tree origtype = TREE_TYPE(origarg);
91745 +
91746 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
91747 +
91748 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
91749 +
91750 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
91751 + update_stmt(stmt);
91752 +}
91753 +
91754 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
91755 +{
91756 + const char *origid;
91757 + tree arg;
91758 + const_tree origarg;
91759 +
91760 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
91761 + return true;
91762 +
91763 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
91764 + while (origarg && *argnum) {
91765 + (*argnum)--;
91766 + origarg = TREE_CHAIN(origarg);
91767 + }
91768 +
91769 + gcc_assert(*argnum == 0);
91770 +
91771 + gcc_assert(origarg != NULL_TREE);
91772 + origid = NAME(origarg);
91773 + *argnum = 0;
91774 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
91775 + if (!strcmp(origid, NAME(arg)))
91776 + return true;
91777 + (*argnum)++;
91778 + }
91779 + return false;
91780 +}
91781 +
91782 +static bool skip_types(const_tree var)
91783 +{
91784 + const_tree type;
91785 +
91786 + switch (TREE_CODE(var)) {
91787 + case ADDR_EXPR:
91788 +#if BUILDING_GCC_VERSION >= 4006
91789 + case MEM_REF:
91790 +#endif
91791 + case ARRAY_REF:
91792 + case BIT_FIELD_REF:
91793 + case INDIRECT_REF:
91794 + case TARGET_MEM_REF:
91795 + case VAR_DECL:
91796 + return true;
91797 + default:
91798 + break;
91799 + }
91800 +
91801 + type = TREE_TYPE(TREE_TYPE(var));
91802 + if (!type)
91803 + return false;
91804 + switch (TREE_CODE(type)) {
91805 + case RECORD_TYPE:
91806 + return true;
91807 + default:
91808 + break;
91809 + }
91810 +
91811 + return false;
91812 +}
91813 +
91814 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
91815 +{
91816 + gimple phi = get_def_stmt(result);
91817 + unsigned int i, n = gimple_phi_num_args(phi);
91818 +
91819 + if (!phi)
91820 + return false;
91821 +
91822 + pointer_set_insert(visited, phi);
91823 + for (i = 0; i < n; i++) {
91824 + const_tree arg = gimple_phi_arg_def(phi, i);
91825 + if (pre_expand(visited, arg))
91826 + return true;
91827 + }
91828 + return false;
91829 +}
91830 +
91831 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
91832 +{
91833 + gimple def_stmt = get_def_stmt(lhs);
91834 + const_tree rhs;
91835 +
91836 + if (!def_stmt)
91837 + return false;
91838 +
91839 + rhs = gimple_assign_rhs1(def_stmt);
91840 + if (pre_expand(visited, rhs))
91841 + return true;
91842 + return false;
91843 +}
91844 +
91845 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
91846 +{
91847 + bool rhs1_found, rhs2_found;
91848 + gimple def_stmt = get_def_stmt(lhs);
91849 + const_tree rhs1, rhs2;
91850 +
91851 + if (!def_stmt)
91852 + return false;
91853 +
91854 + rhs1 = gimple_assign_rhs1(def_stmt);
91855 + rhs2 = gimple_assign_rhs2(def_stmt);
91856 + rhs1_found = pre_expand(visited, rhs1);
91857 + rhs2_found = pre_expand(visited, rhs2);
91858 +
91859 + return rhs1_found || rhs2_found;
91860 +}
91861 +
91862 +static const_tree search_field_decl(const_tree comp_ref)
91863 +{
91864 + const_tree field = NULL_TREE;
91865 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
91866 +
91867 + for (i = 0; i < len; i++) {
91868 + field = TREE_OPERAND(comp_ref, i);
91869 + if (TREE_CODE(field) == FIELD_DECL)
91870 + break;
91871 + }
91872 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
91873 + return field;
91874 +}
91875 +
91876 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
91877 +{
91878 + const_tree attr, p;
91879 +
91880 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
91881 + if (!attr || !TREE_VALUE(attr))
91882 + return MARKED_NO;
91883 +
91884 + p = TREE_VALUE(attr);
91885 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
91886 + return MARKED_NOT_INTENTIONAL;
91887 +
91888 + do {
91889 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
91890 + return MARKED_YES;
91891 + p = TREE_CHAIN(p);
91892 + } while (p);
91893 +
91894 + return MARKED_NO;
91895 +}
91896 +
91897 +static void print_missing_msg(tree func, unsigned int argnum)
91898 +{
91899 + unsigned int new_hash;
91900 + size_t len;
91901 + unsigned char tree_codes[CODES_LIMIT];
91902 + location_t loc = DECL_SOURCE_LOCATION(func);
91903 + const char *curfunc = get_asm_name(func);
91904 +
91905 + len = get_function_decl(func, tree_codes);
91906 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
91907 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
91908 +}
91909 +
91910 +static unsigned int search_missing_attribute(const_tree arg)
91911 +{
91912 + const_tree type = TREE_TYPE(arg);
91913 + tree func = get_original_function_decl(current_function_decl);
91914 + unsigned int argnum;
91915 + const struct size_overflow_hash *hash;
91916 +
91917 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
91918 +
91919 + if (TREE_CODE(type) == POINTER_TYPE)
91920 + return 0;
91921 +
91922 + argnum = find_arg_number(arg, func);
91923 + if (argnum == 0)
91924 + return 0;
91925 +
91926 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
91927 + return argnum;
91928 +
91929 + hash = get_function_hash(func);
91930 + if (!hash || !(hash->param & (1U << argnum))) {
91931 + print_missing_msg(func, argnum);
91932 + return 0;
91933 + }
91934 + return argnum;
91935 +}
91936 +
91937 +static bool is_already_marked(const_tree lhs)
91938 +{
91939 + unsigned int argnum;
91940 + const_tree fndecl;
91941 +
91942 + argnum = search_missing_attribute(lhs);
91943 + fndecl = get_original_function_decl(current_function_decl);
91944 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
91945 + return true;
91946 + return false;
91947 +}
91948 +
91949 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
91950 +{
91951 + const_gimple def_stmt;
91952 +
91953 + if (is_gimple_constant(lhs))
91954 + return false;
91955 +
91956 + if (skip_types(lhs))
91957 + return false;
91958 +
91959 + // skip char type (FIXME: only kernel)
91960 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode)
91961 + return false;
91962 +
91963 + if (TREE_CODE(lhs) == PARM_DECL)
91964 + return is_already_marked(lhs);
91965 +
91966 + if (TREE_CODE(lhs) == COMPONENT_REF) {
91967 + const_tree field, attr;
91968 +
91969 + field = search_field_decl(lhs);
91970 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
91971 + if (!attr || !TREE_VALUE(attr))
91972 + return false;
91973 + return true;
91974 + }
91975 +
91976 + def_stmt = get_def_stmt(lhs);
91977 +
91978 + if (!def_stmt)
91979 + return false;
91980 +
91981 + if (pointer_set_contains(visited, def_stmt))
91982 + return false;
91983 +
91984 + switch (gimple_code(def_stmt)) {
91985 + case GIMPLE_NOP:
91986 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
91987 + return is_already_marked(lhs);
91988 + return false;
91989 + case GIMPLE_PHI:
91990 + return walk_phi(visited, lhs);
91991 + case GIMPLE_CALL:
91992 + case GIMPLE_ASM:
91993 + return false;
91994 + case GIMPLE_ASSIGN:
91995 + switch (gimple_num_ops(def_stmt)) {
91996 + case 2:
91997 + return walk_unary_ops(visited, lhs);
91998 + case 3:
91999 + return walk_binary_ops(visited, lhs);
92000 + }
92001 + default:
92002 + debug_gimple_stmt((gimple)def_stmt);
92003 + error("%s: unknown gimple code", __func__);
92004 + gcc_unreachable();
92005 + }
92006 +}
92007 +
92008 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
92009 +{
92010 + struct pointer_set_t *visited;
92011 + bool is_found;
92012 + enum marked is_marked;
92013 + location_t loc;
92014 +
92015 + visited = pointer_set_create();
92016 + is_found = pre_expand(visited, arg);
92017 + pointer_set_destroy(visited);
92018 +
92019 + is_marked = mark_status(fndecl, argnum + 1);
92020 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
92021 + return true;
92022 +
92023 + if (is_found) {
92024 + loc = DECL_SOURCE_LOCATION(fndecl);
92025 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
92026 + return true;
92027 + }
92028 + return false;
92029 +}
92030 +
92031 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
92032 +{
92033 + struct pointer_set_t *visited;
92034 + tree arg, newarg;
92035 + bool match;
92036 +
92037 + match = get_function_arg(&argnum, fndecl);
92038 + if (!match)
92039 + return;
92040 + gcc_assert(gimple_call_num_args(stmt) > argnum);
92041 + arg = gimple_call_arg(stmt, argnum);
92042 + if (arg == NULL_TREE)
92043 + return;
92044 +
92045 + if (is_gimple_constant(arg))
92046 + return;
92047 +
92048 + if (search_attributes(fndecl, arg, argnum))
92049 + return;
92050 +
92051 + if (TREE_CODE(arg) != SSA_NAME)
92052 + return;
92053 +
92054 + check_arg_type(arg);
92055 +
92056 + visited = pointer_set_create();
92057 + newarg = expand(visited, arg);
92058 + pointer_set_destroy(visited);
92059 +
92060 + if (newarg == NULL_TREE)
92061 + return;
92062 +
92063 + change_function_arg(stmt, arg, argnum, newarg);
92064 +
92065 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
92066 +}
92067 +
92068 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
92069 +{
92070 + tree p = TREE_VALUE(attr);
92071 + do {
92072 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
92073 + p = TREE_CHAIN(p);
92074 + } while (p);
92075 +}
92076 +
92077 +static void handle_function_by_hash(gimple stmt, tree fndecl)
92078 +{
92079 + tree orig_fndecl;
92080 + unsigned int num;
92081 + const struct size_overflow_hash *hash;
92082 +
92083 + orig_fndecl = get_original_function_decl(fndecl);
92084 + if (C_DECL_IMPLICIT(orig_fndecl))
92085 + return;
92086 + hash = get_function_hash(orig_fndecl);
92087 + if (!hash)
92088 + return;
92089 +
92090 + for (num = 1; num <= MAX_PARAM; num++)
92091 + if (hash->param & (1U << num))
92092 + handle_function_arg(stmt, fndecl, num - 1);
92093 +}
92094 +
92095 +static void set_plf_false(void)
92096 +{
92097 + basic_block bb;
92098 +
92099 + FOR_ALL_BB(bb) {
92100 + gimple_stmt_iterator si;
92101 +
92102 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
92103 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
92104 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
92105 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
92106 + }
92107 +}
92108 +
92109 +static unsigned int handle_function(void)
92110 +{
92111 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
92112 +
92113 + set_plf_false();
92114 +
92115 + do {
92116 + gimple_stmt_iterator gsi;
92117 + next = bb->next_bb;
92118 +
92119 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92120 + tree fndecl, attr;
92121 + gimple stmt = gsi_stmt(gsi);
92122 +
92123 + if (!(is_gimple_call(stmt)))
92124 + continue;
92125 + fndecl = gimple_call_fndecl(stmt);
92126 + if (fndecl == NULL_TREE)
92127 + continue;
92128 + if (gimple_call_num_args(stmt) == 0)
92129 + continue;
92130 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
92131 + if (!attr || !TREE_VALUE(attr))
92132 + handle_function_by_hash(stmt, fndecl);
92133 + else
92134 + handle_function_by_attribute(stmt, attr, fndecl);
92135 + gsi = gsi_for_stmt(stmt);
92136 + next = gimple_bb(stmt)->next_bb;
92137 + }
92138 + bb = next;
92139 + } while (bb);
92140 + return 0;
92141 +}
92142 +
92143 +static struct gimple_opt_pass size_overflow_pass = {
92144 + .pass = {
92145 + .type = GIMPLE_PASS,
92146 + .name = "size_overflow",
92147 +#if BUILDING_GCC_VERSION >= 4008
92148 + .optinfo_flags = OPTGROUP_NONE,
92149 +#endif
92150 + .gate = NULL,
92151 + .execute = handle_function,
92152 + .sub = NULL,
92153 + .next = NULL,
92154 + .static_pass_number = 0,
92155 + .tv_id = TV_NONE,
92156 + .properties_required = PROP_cfg,
92157 + .properties_provided = 0,
92158 + .properties_destroyed = 0,
92159 + .todo_flags_start = 0,
92160 + .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
92161 + }
92162 +};
92163 +
92164 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
92165 +{
92166 + tree fntype;
92167 +
92168 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
92169 +
92170 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
92171 + fntype = build_function_type_list(void_type_node,
92172 + const_char_ptr_type_node,
92173 + unsigned_type_node,
92174 + const_char_ptr_type_node,
92175 + const_char_ptr_type_node,
92176 + NULL_TREE);
92177 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
92178 +
92179 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
92180 + TREE_PUBLIC(report_size_overflow_decl) = 1;
92181 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
92182 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
92183 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
92184 +}
92185 +
92186 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92187 +{
92188 + int i;
92189 + const char * const plugin_name = plugin_info->base_name;
92190 + const int argc = plugin_info->argc;
92191 + const struct plugin_argument * const argv = plugin_info->argv;
92192 + bool enable = true;
92193 +
92194 + struct register_pass_info size_overflow_pass_info = {
92195 + .pass = &size_overflow_pass.pass,
92196 + .reference_pass_name = "ssa",
92197 + .ref_pass_instance_number = 1,
92198 + .pos_op = PASS_POS_INSERT_AFTER
92199 + };
92200 +
92201 + if (!plugin_default_version_check(version, &gcc_version)) {
92202 + error(G_("incompatible gcc/plugin versions"));
92203 + return 1;
92204 + }
92205 +
92206 + for (i = 0; i < argc; ++i) {
92207 + if (!strcmp(argv[i].key, "no-size-overflow")) {
92208 + enable = false;
92209 + continue;
92210 + }
92211 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92212 + }
92213 +
92214 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
92215 + if (enable) {
92216 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
92217 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
92218 + }
92219 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
92220 +
92221 + return 0;
92222 +}
92223 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
92224 new file mode 100644
92225 index 0000000..ac2901e
92226 --- /dev/null
92227 +++ b/tools/gcc/stackleak_plugin.c
92228 @@ -0,0 +1,327 @@
92229 +/*
92230 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
92231 + * Licensed under the GPL v2
92232 + *
92233 + * Note: the choice of the license means that the compilation process is
92234 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
92235 + * but for the kernel it doesn't matter since it doesn't link against
92236 + * any of the gcc libraries
92237 + *
92238 + * gcc plugin to help implement various PaX features
92239 + *
92240 + * - track lowest stack pointer
92241 + *
92242 + * TODO:
92243 + * - initialize all local variables
92244 + *
92245 + * BUGS:
92246 + * - none known
92247 + */
92248 +#include "gcc-plugin.h"
92249 +#include "config.h"
92250 +#include "system.h"
92251 +#include "coretypes.h"
92252 +#include "tree.h"
92253 +#include "tree-pass.h"
92254 +#include "flags.h"
92255 +#include "intl.h"
92256 +#include "toplev.h"
92257 +#include "plugin.h"
92258 +//#include "expr.h" where are you...
92259 +#include "diagnostic.h"
92260 +#include "plugin-version.h"
92261 +#include "tm.h"
92262 +#include "function.h"
92263 +#include "basic-block.h"
92264 +#include "gimple.h"
92265 +#include "rtl.h"
92266 +#include "emit-rtl.h"
92267 +
92268 +#if BUILDING_GCC_VERSION >= 4008
92269 +#define TODO_dump_func 0
92270 +#endif
92271 +
92272 +extern void print_gimple_stmt(FILE *, gimple, int, int);
92273 +
92274 +int plugin_is_GPL_compatible;
92275 +
92276 +static int track_frame_size = -1;
92277 +static const char track_function[] = "pax_track_stack";
92278 +static const char check_function[] = "pax_check_alloca";
92279 +static bool init_locals;
92280 +
92281 +static struct plugin_info stackleak_plugin_info = {
92282 + .version = "201302112000",
92283 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
92284 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
92285 +};
92286 +
92287 +static bool gate_stackleak_track_stack(void);
92288 +static unsigned int execute_stackleak_tree_instrument(void);
92289 +static unsigned int execute_stackleak_final(void);
92290 +
92291 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
92292 + .pass = {
92293 + .type = GIMPLE_PASS,
92294 + .name = "stackleak_tree_instrument",
92295 +#if BUILDING_GCC_VERSION >= 4008
92296 + .optinfo_flags = OPTGROUP_NONE,
92297 +#endif
92298 + .gate = gate_stackleak_track_stack,
92299 + .execute = execute_stackleak_tree_instrument,
92300 + .sub = NULL,
92301 + .next = NULL,
92302 + .static_pass_number = 0,
92303 + .tv_id = TV_NONE,
92304 + .properties_required = PROP_gimple_leh | PROP_cfg,
92305 + .properties_provided = 0,
92306 + .properties_destroyed = 0,
92307 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
92308 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
92309 + }
92310 +};
92311 +
92312 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
92313 + .pass = {
92314 + .type = RTL_PASS,
92315 + .name = "stackleak_final",
92316 +#if BUILDING_GCC_VERSION >= 4008
92317 + .optinfo_flags = OPTGROUP_NONE,
92318 +#endif
92319 + .gate = gate_stackleak_track_stack,
92320 + .execute = execute_stackleak_final,
92321 + .sub = NULL,
92322 + .next = NULL,
92323 + .static_pass_number = 0,
92324 + .tv_id = TV_NONE,
92325 + .properties_required = 0,
92326 + .properties_provided = 0,
92327 + .properties_destroyed = 0,
92328 + .todo_flags_start = 0,
92329 + .todo_flags_finish = TODO_dump_func
92330 + }
92331 +};
92332 +
92333 +static bool gate_stackleak_track_stack(void)
92334 +{
92335 + return track_frame_size >= 0;
92336 +}
92337 +
92338 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
92339 +{
92340 + gimple check_alloca;
92341 + tree fntype, fndecl, alloca_size;
92342 +
92343 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
92344 + fndecl = build_fn_decl(check_function, fntype);
92345 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
92346 +
92347 + // insert call to void pax_check_alloca(unsigned long size)
92348 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
92349 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
92350 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
92351 +}
92352 +
92353 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
92354 +{
92355 + gimple track_stack;
92356 + tree fntype, fndecl;
92357 +
92358 + fntype = build_function_type_list(void_type_node, NULL_TREE);
92359 + fndecl = build_fn_decl(track_function, fntype);
92360 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
92361 +
92362 + // insert call to void pax_track_stack(void)
92363 + track_stack = gimple_build_call(fndecl, 0);
92364 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
92365 +}
92366 +
92367 +#if BUILDING_GCC_VERSION == 4005
92368 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
92369 +{
92370 + tree fndecl;
92371 +
92372 + if (!is_gimple_call(stmt))
92373 + return false;
92374 + fndecl = gimple_call_fndecl(stmt);
92375 + if (!fndecl)
92376 + return false;
92377 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
92378 + return false;
92379 +// print_node(stderr, "pax", fndecl, 4);
92380 + return DECL_FUNCTION_CODE(fndecl) == code;
92381 +}
92382 +#endif
92383 +
92384 +static bool is_alloca(gimple stmt)
92385 +{
92386 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
92387 + return true;
92388 +
92389 +#if BUILDING_GCC_VERSION >= 4007
92390 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
92391 + return true;
92392 +#endif
92393 +
92394 + return false;
92395 +}
92396 +
92397 +static unsigned int execute_stackleak_tree_instrument(void)
92398 +{
92399 + basic_block bb, entry_bb;
92400 + bool prologue_instrumented = false, is_leaf = true;
92401 +
92402 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
92403 +
92404 + // 1. loop through BBs and GIMPLE statements
92405 + FOR_EACH_BB(bb) {
92406 + gimple_stmt_iterator gsi;
92407 +
92408 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92409 + gimple stmt;
92410 +
92411 + stmt = gsi_stmt(gsi);
92412 +
92413 + if (is_gimple_call(stmt))
92414 + is_leaf = false;
92415 +
92416 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
92417 + if (!is_alloca(stmt))
92418 + continue;
92419 +
92420 + // 2. insert stack overflow check before each __builtin_alloca call
92421 + stackleak_check_alloca(&gsi);
92422 +
92423 + // 3. insert track call after each __builtin_alloca call
92424 + stackleak_add_instrumentation(&gsi);
92425 + if (bb == entry_bb)
92426 + prologue_instrumented = true;
92427 + }
92428 + }
92429 +
92430 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
92431 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
92432 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
92433 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
92434 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
92435 + return 0;
92436 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
92437 + return 0;
92438 +
92439 + // 4. insert track call at the beginning
92440 + if (!prologue_instrumented) {
92441 + gimple_stmt_iterator gsi;
92442 +
92443 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
92444 + if (dom_info_available_p(CDI_DOMINATORS))
92445 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
92446 + gsi = gsi_start_bb(bb);
92447 + stackleak_add_instrumentation(&gsi);
92448 + }
92449 +
92450 + return 0;
92451 +}
92452 +
92453 +static unsigned int execute_stackleak_final(void)
92454 +{
92455 + rtx insn, next;
92456 +
92457 + if (cfun->calls_alloca)
92458 + return 0;
92459 +
92460 + // keep calls only if function frame is big enough
92461 + if (get_frame_size() >= track_frame_size)
92462 + return 0;
92463 +
92464 + // 1. find pax_track_stack calls
92465 + for (insn = get_insns(); insn; insn = next) {
92466 + // 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))
92467 + rtx body;
92468 +
92469 + next = NEXT_INSN(insn);
92470 + if (!CALL_P(insn))
92471 + continue;
92472 + body = PATTERN(insn);
92473 + if (GET_CODE(body) != CALL)
92474 + continue;
92475 + body = XEXP(body, 0);
92476 + if (GET_CODE(body) != MEM)
92477 + continue;
92478 + body = XEXP(body, 0);
92479 + if (GET_CODE(body) != SYMBOL_REF)
92480 + continue;
92481 + if (strcmp(XSTR(body, 0), track_function))
92482 + continue;
92483 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
92484 + // 2. delete call
92485 + delete_insn_and_edges(insn);
92486 +#if BUILDING_GCC_VERSION >= 4007
92487 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
92488 + insn = next;
92489 + next = NEXT_INSN(insn);
92490 + delete_insn_and_edges(insn);
92491 + }
92492 +#endif
92493 + }
92494 +
92495 +// print_simple_rtl(stderr, get_insns());
92496 +// print_rtl(stderr, get_insns());
92497 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
92498 +
92499 + return 0;
92500 +}
92501 +
92502 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92503 +{
92504 + const char * const plugin_name = plugin_info->base_name;
92505 + const int argc = plugin_info->argc;
92506 + const struct plugin_argument * const argv = plugin_info->argv;
92507 + int i;
92508 + struct register_pass_info stackleak_tree_instrument_pass_info = {
92509 + .pass = &stackleak_tree_instrument_pass.pass,
92510 +// .reference_pass_name = "tree_profile",
92511 + .reference_pass_name = "optimized",
92512 + .ref_pass_instance_number = 1,
92513 + .pos_op = PASS_POS_INSERT_BEFORE
92514 + };
92515 + struct register_pass_info stackleak_final_pass_info = {
92516 + .pass = &stackleak_final_rtl_opt_pass.pass,
92517 + .reference_pass_name = "final",
92518 + .ref_pass_instance_number = 1,
92519 + .pos_op = PASS_POS_INSERT_BEFORE
92520 + };
92521 +
92522 + if (!plugin_default_version_check(version, &gcc_version)) {
92523 + error(G_("incompatible gcc/plugin versions"));
92524 + return 1;
92525 + }
92526 +
92527 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
92528 +
92529 + for (i = 0; i < argc; ++i) {
92530 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
92531 + if (!argv[i].value) {
92532 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92533 + continue;
92534 + }
92535 + track_frame_size = atoi(argv[i].value);
92536 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
92537 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
92538 + continue;
92539 + }
92540 + if (!strcmp(argv[i].key, "initialize-locals")) {
92541 + if (argv[i].value) {
92542 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
92543 + continue;
92544 + }
92545 + init_locals = true;
92546 + continue;
92547 + }
92548 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92549 + }
92550 +
92551 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
92552 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
92553 +
92554 + return 0;
92555 +}
92556 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
92557 index 6789d78..4afd019e 100644
92558 --- a/tools/perf/util/include/asm/alternative-asm.h
92559 +++ b/tools/perf/util/include/asm/alternative-asm.h
92560 @@ -5,4 +5,7 @@
92561
92562 #define altinstruction_entry #
92563
92564 + .macro pax_force_retaddr rip=0, reload=0
92565 + .endm
92566 +
92567 #endif
92568 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
92569 index 6e8fa7e..37f02a5 100644
92570 --- a/virt/kvm/kvm_main.c
92571 +++ b/virt/kvm/kvm_main.c
92572 @@ -75,12 +75,17 @@ LIST_HEAD(vm_list);
92573
92574 static cpumask_var_t cpus_hardware_enabled;
92575 static int kvm_usage_count = 0;
92576 -static atomic_t hardware_enable_failed;
92577 +static atomic_unchecked_t hardware_enable_failed;
92578
92579 struct kmem_cache *kvm_vcpu_cache;
92580 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
92581
92582 -static __read_mostly struct preempt_ops kvm_preempt_ops;
92583 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
92584 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
92585 +static struct preempt_ops kvm_preempt_ops = {
92586 + .sched_in = kvm_sched_in,
92587 + .sched_out = kvm_sched_out,
92588 +};
92589
92590 struct dentry *kvm_debugfs_dir;
92591
92592 @@ -726,7 +731,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
92593 /* We can read the guest memory with __xxx_user() later on. */
92594 if (user_alloc &&
92595 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
92596 - !access_ok(VERIFY_WRITE,
92597 + !__access_ok(VERIFY_WRITE,
92598 (void __user *)(unsigned long)mem->userspace_addr,
92599 mem->memory_size)))
92600 goto out;
92601 @@ -2450,7 +2455,7 @@ static void hardware_enable_nolock(void *junk)
92602
92603 if (r) {
92604 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
92605 - atomic_inc(&hardware_enable_failed);
92606 + atomic_inc_unchecked(&hardware_enable_failed);
92607 printk(KERN_INFO "kvm: enabling virtualization on "
92608 "CPU%d failed\n", cpu);
92609 }
92610 @@ -2504,10 +2509,10 @@ static int hardware_enable_all(void)
92611
92612 kvm_usage_count++;
92613 if (kvm_usage_count == 1) {
92614 - atomic_set(&hardware_enable_failed, 0);
92615 + atomic_set_unchecked(&hardware_enable_failed, 0);
92616 on_each_cpu(hardware_enable_nolock, NULL, 1);
92617
92618 - if (atomic_read(&hardware_enable_failed)) {
92619 + if (atomic_read_unchecked(&hardware_enable_failed)) {
92620 hardware_disable_all_nolock();
92621 r = -EBUSY;
92622 }
92623 @@ -2865,7 +2870,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
92624 kvm_arch_vcpu_put(vcpu);
92625 }
92626
92627 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92628 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92629 struct module *module)
92630 {
92631 int r;
92632 @@ -2901,7 +2906,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92633 if (!vcpu_align)
92634 vcpu_align = __alignof__(struct kvm_vcpu);
92635 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
92636 - 0, NULL);
92637 + SLAB_USERCOPY, NULL);
92638 if (!kvm_vcpu_cache) {
92639 r = -ENOMEM;
92640 goto out_free_3;
92641 @@ -2911,9 +2916,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92642 if (r)
92643 goto out_free;
92644
92645 - kvm_chardev_ops.owner = module;
92646 - kvm_vm_fops.owner = module;
92647 - kvm_vcpu_fops.owner = module;
92648 + pax_open_kernel();
92649 + *(void **)&kvm_chardev_ops.owner = module;
92650 + *(void **)&kvm_vm_fops.owner = module;
92651 + *(void **)&kvm_vcpu_fops.owner = module;
92652 + pax_close_kernel();
92653
92654 r = misc_register(&kvm_dev);
92655 if (r) {
92656 @@ -2923,9 +2930,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
92657
92658 register_syscore_ops(&kvm_syscore_ops);
92659
92660 - kvm_preempt_ops.sched_in = kvm_sched_in;
92661 - kvm_preempt_ops.sched_out = kvm_sched_out;
92662 -
92663 r = kvm_init_debug();
92664 if (r) {
92665 printk(KERN_ERR "kvm: create debugfs files failed\n");